Skip to content

Commit

Permalink
Make follow-symlinks optional
Browse files Browse the repository at this point in the history
This new behavior fixes packaging with symlinks to directories in
extensions. We make it optional in case someone wants to keep the
intermediate behavior.
  • Loading branch information
deribaucourt committed Oct 9, 2024
1 parent 3cd6ca0 commit 51e122a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
13 changes: 10 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
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 @@ -1613,11 +1618,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, follow: 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 @@ -1647,11 +1653,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 @@ -1666,7 +1673,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 @@ -1758,7 +1765,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 @@ -1931,6 +1938,7 @@ export interface IListFilesOptions {
readonly dependencies?: boolean;
readonly prepublish?: boolean;
readonly readmePath?: string;
readonly followSymlinks?: boolean;
}

/**
Expand All @@ -1944,7 +1952,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 @@ -1954,6 +1962,7 @@ interface ILSOptions {
readonly ignoreFile?: string;
readonly dependencies?: boolean;
readonly readmePath?: string;
readonly followSymlinks?: boolean;
}

/**
Expand Down Expand Up @@ -2008,7 +2017,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 @@ -352,4 +357,4 @@ export async function getPAT(publisher: string, options: IPublishOptions | IUnpu
}

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

0 comments on commit 51e122a

Please sign in to comment.