Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into pr/andrewlayer/1061
Browse files Browse the repository at this point in the history
  • Loading branch information
benibenj committed Oct 15, 2024
2 parents 3b13c0d + 51ed6ba commit c857f08
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
15 changes: 11 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function main(task: Promise<any>): void {

task.catch(fatal).then(() => {
if (latestVersion && semver.gt(latestVersion, pkg.version)) {
log.info(`The latest version of ${pkg.name} is ${latestVersion} and you have ${pkg.version}.\nUpdate it now: npm install -g ${pkg.name}`);
log.warn(`The latest version of ${pkg.name} is ${latestVersion} and you have ${pkg.version}.\nUpdate it now: npm install -g ${pkg.name}`);
} else {
token.cancel();
}
Expand Down Expand Up @@ -75,8 +75,9 @@ module.exports = function (argv: string[]): void {
.option('--dependencies', 'Enable dependency detection via npm or yarn', undefined)
.option('--no-dependencies', 'Disable dependency detection via npm or yarn', undefined)
.option('--readme-path <path>', 'Path to README file (defaults to README.md)')
.action(({ tree, yarn, packagedDependencies, ignoreFile, dependencies, readmePath }) =>
main(ls({ tree, useYarn: yarn, packagedDependencies, ignoreFile, dependencies, readmePath }))
.option('--follow-symlinks', 'Recurse into symlinked directories instead of treating them as files')
.action(({ tree, yarn, packagedDependencies, ignoreFile, dependencies, readmePath, followSymlinks }) =>
main(ls({ tree, useYarn: yarn, packagedDependencies, ignoreFile, dependencies, readmePath, followSymlinks }))
);

program
Expand Down Expand Up @@ -119,6 +120,7 @@ module.exports = function (argv: string[]): void {
.option('--allow-unused-files-pattern', 'Allow include patterns for the files field in package.json that does not match any file')
.option('--skip-license', 'Allow packaging without license file')
.option('--sign-tool <path>', 'Path to the VSIX signing tool. Will be invoked with two arguments: `SIGNTOOL <path/to/extension.signature.manifest> <path/to/extension.signature.p7s>`.')
.option('--follow-symlinks', 'Recurse into symlinked directories instead of treating them as files')
.action(
(
version,
Expand Down Expand Up @@ -147,6 +149,7 @@ module.exports = function (argv: string[]): void {
allowUnusedFilesPattern,
skipLicense,
signTool,
followSymlinks,
}
) =>
main(
Expand Down Expand Up @@ -176,6 +179,7 @@ module.exports = function (argv: string[]): void {
allowUnusedFilesPattern,
skipLicense,
signTool,
followSymlinks,
})
)
);
Expand Down Expand Up @@ -229,6 +233,7 @@ module.exports = function (argv: string[]): void {
.option('--allow-unused-files-pattern', 'Allow include patterns for the files field in package.json that does not match any file')
.option('--skip-duplicate', 'Fail silently if version already exists on the marketplace')
.option('--skip-license', 'Allow publishing without license file')
.option('--follow-symlinks', 'Recurse into symlinked directories instead of treating them as files')
.action(
(
version,
Expand Down Expand Up @@ -263,6 +268,7 @@ module.exports = function (argv: string[]): void {
skipDuplicate,
skipLicense,
signTool,
followSymlinks,
}
) =>
main(
Expand Down Expand Up @@ -297,7 +303,8 @@ module.exports = function (argv: string[]): void {
allowUnusedFilesPattern,
skipDuplicate,
skipLicense,
signTool
signTool,
followSymlinks
})
)
);
Expand Down
25 changes: 17 additions & 8 deletions src/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,16 @@ export interface IPackageOptions {
* `target` is set. For example, if `target` is `linux-x64` and there are
* folders named `win32-x64`, `darwin-arm64` or `web`, the files inside
* those folders will be ignored.
*
*
* @default false
*/
readonly ignoreOtherTargetFolders?: boolean;

/**
* Recurse into symlinked directories instead of treating them as files.
*/
readonly followSymlinks?: boolean;

readonly commitMessage?: string;
readonly gitTagVersion?: boolean;
readonly updatePackageJson?: boolean;
Expand Down Expand Up @@ -1630,11 +1635,12 @@ const defaultIgnore = [
async function collectAllFiles(
cwd: string,
dependencies: 'npm' | 'yarn' | 'none' | undefined,
dependencyEntryPoints?: string[]
dependencyEntryPoints?: string[],
followSymlinks:boolean = true
): Promise<string[]> {
const deps = await getDependencies(cwd, dependencies, dependencyEntryPoints);
const promises = deps.map(dep =>
glob('**', { cwd: dep, nodir: true, dot: true, ignore: 'node_modules/**' }).then(files =>
glob('**', { cwd: dep, nodir: true, follow: followSymlinks, dot: true, ignore: 'node_modules/**' }).then(files =>
files.map(f => path.relative(cwd, path.join(dep, f))).map(f => f.replace(/\\/g, '/'))
)
);
Expand Down Expand Up @@ -1664,11 +1670,12 @@ function collectFiles(
ignoreFile?: string,
manifestFileIncludes?: string[],
readmePath?: string,
followSymlinks:boolean = false
): Promise<string[]> {
readmePath = readmePath ?? 'README.md';
const notIgnored = ['!package.json', `!${readmePath}`];

return collectAllFiles(cwd, dependencies, dependencyEntryPoints).then(files => {
return collectAllFiles(cwd, dependencies, dependencyEntryPoints, followSymlinks).then(files => {
files = files.filter(f => !/\r$/m.test(f));

return (
Expand All @@ -1683,7 +1690,7 @@ function collectFiles(
manifestFileIncludes ?
// include all files in manifestFileIncludes and ignore the rest
Promise.resolve(manifestFileIncludes.map(file => `!${file}`).concat(['**']).join('\n\r')) :
// "files" property not used in package.json
// "files" property not used in package.json
Promise.resolve('')
)

Expand Down Expand Up @@ -1775,7 +1782,7 @@ export function collect(manifest: ManifestPackage, options: IPackageOptions = {}
const ignoreFile = options.ignoreFile || undefined;
const processors = createDefaultProcessors(manifest, options);

return collectFiles(cwd, getDependenciesOption(options), packagedDependencies, ignoreFile, manifest.files, options.readmePath).then(fileNames => {
return collectFiles(cwd, getDependenciesOption(options), packagedDependencies, ignoreFile, manifest.files, options.readmePath, options.followSymlinks).then(fileNames => {
const files = fileNames.map(f => ({ path: util.filePathToVsixPath(f), localPath: path.join(cwd, f) }));

return processFiles(processors, files);
Expand Down Expand Up @@ -1948,6 +1955,7 @@ export interface IListFilesOptions {
readonly dependencies?: boolean;
readonly prepublish?: boolean;
readonly readmePath?: string;
readonly followSymlinks?: boolean;
}

/**
Expand All @@ -1961,7 +1969,7 @@ export async function listFiles(options: IListFilesOptions = {}): Promise<string
await prepublish(cwd, manifest, options.useYarn);
}

return await collectFiles(cwd, getDependenciesOption(options), options.packagedDependencies, options.ignoreFile, manifest.files, options.readmePath);
return await collectFiles(cwd, getDependenciesOption(options), options.packagedDependencies, options.ignoreFile, manifest.files, options.readmePath, options.followSymlinks);
}

interface ILSOptions {
Expand All @@ -1971,6 +1979,7 @@ interface ILSOptions {
readonly ignoreFile?: string;
readonly dependencies?: boolean;
readonly readmePath?: string;
readonly followSymlinks?: boolean;
}

/**
Expand Down Expand Up @@ -2025,7 +2034,7 @@ export async function printAndValidatePackagedFiles(files: IFile[], cwd: string,
util.log.error(message);
process.exit(1);
}
// Throw an error if the extension uses the files property in package.json and
// Throw an error if the extension uses the files property in package.json and
// the package does not include at least one file for each include pattern
else if (manifest.files !== undefined && manifest.files.length > 0 && !options.allowUnusedFilesPattern) {
const localPaths = (files.filter(f => !isInMemoryFile(f)) as ILocalFile[]).map(f => util.normalize(f.localPath));
Expand Down
7 changes: 6 additions & 1 deletion src/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ export interface IPublishOptions {
readonly dependencyEntryPoints?: string[];
readonly ignoreFile?: string;

/**
* Recurse into symlinked directories instead of treating them as files
*/
readonly followSymlinks?: boolean;

/**
* The Personal Access Token to use.
*
Expand Down Expand Up @@ -356,4 +361,4 @@ export async function getPAT(publisher: string, options: IPublishOptions | IUnpu
}

return (await getPublisher(publisher)).pat;
}
}

0 comments on commit c857f08

Please sign in to comment.