From 13d8466d7acba75835a1cb67964e3ea97cdccfcb Mon Sep 17 00:00:00 2001 From: BeniBenj Date: Mon, 4 Nov 2024 09:43:07 +0100 Subject: [PATCH 1/3] fix #1073 --- src/package.ts | 30 ++++++++++++++------ src/test/fixtures/manifestFiles/README.md | 1 + src/test/fixtures/manifestFiles/package.json | 13 +++++++-- src/test/package.test.ts | 1 + 4 files changed, 34 insertions(+), 11 deletions(-) create mode 100644 src/test/fixtures/manifestFiles/README.md diff --git a/src/package.ts b/src/package.ts index 68376c33..0626b880 100644 --- a/src/package.ts +++ b/src/package.ts @@ -33,12 +33,14 @@ const MinimatchOptions: minimatch.IOptions = { dot: true }; export interface IInMemoryFile { path: string; mode?: number; + originalPath?: string; // used to track the original path of a file that was renamed readonly contents: Buffer | string; } export interface ILocalFile { path: string; mode?: number; + originalPath?: string; // used to track the original path of a file that was renamed readonly localPath: string; } @@ -919,6 +921,7 @@ export abstract class MarkdownProcessor extends BaseProcessor { return { path: file.path, contents: Buffer.from(contents, 'utf8'), + originalPath: file.originalPath }; } @@ -981,7 +984,11 @@ export class ReadmeProcessor extends MarkdownProcessor { } override async processFile(file: IFile): Promise { - file.path = 'extension/readme.md'; + if (isInMemoryFile(file)) { + util.log.warn(`The provided readme file is in memory and will not be included in the VSIX.`); + return file; + } + file = { ...file, originalPath: file.localPath, path: 'extension/readme.md' }; return await super.processFile(file, file.path); } @@ -1005,7 +1012,11 @@ export class ChangelogProcessor extends MarkdownProcessor { } override async processFile(file: IFile): Promise { - file.path = 'extension/changelog.md'; + if (isInMemoryFile(file)) { + util.log.warn(`The provided changelog file is in memory and will not be included in the VSIX.`); + return file; + } + file = { ...file, originalPath: file.localPath, path: 'extension/changelog.md' }; return await super.processFile(file, file.path); } @@ -2037,18 +2048,19 @@ export async function printAndValidatePackagedFiles(files: IFile[], cwd: string, // 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)); - const filesIncludePatterns = manifest.files.map(includePattern => util.normalize(path.join(cwd, includePattern))); + const localPaths = files.map(f => util.normalize(f.originalPath ?? (!isInMemoryFile(f) ? f.localPath : path.join(cwd, f.path)))); + const filesIncludePatterns = manifest.files.map(includePattern => ({ absolute: util.normalize(path.join(cwd, includePattern)), relative: includePattern })); const unusedIncludePatterns = filesIncludePatterns.filter(includePattern => { + let absoluteIncludePattern = includePattern.absolute; // Check if the pattern provided by the user matches any file in the package - if (localPaths.some(localFilePath => minimatch(localFilePath, includePattern, MinimatchOptions))) { + if (localPaths.some(localFilePath => minimatch(localFilePath, absoluteIncludePattern, MinimatchOptions))) { return false; } // Check if the pattern provided by the user matches any folder in the package - if (!/(^|\/)[^/]*\*[^/]*$/.test(includePattern)) { - includePattern = (/\/$/.test(includePattern) ? `${includePattern}**` : `${includePattern}/**`); - return !localPaths.some(localFilePath => minimatch(localFilePath, includePattern, MinimatchOptions)); + if (!/(^|\/)[^/]*\*[^/]*$/.test(absoluteIncludePattern)) { + absoluteIncludePattern = (/\/$/.test(absoluteIncludePattern) ? `${absoluteIncludePattern}**` : `${absoluteIncludePattern}/**`); + return !localPaths.some(localFilePath => minimatch(localFilePath, absoluteIncludePattern, MinimatchOptions)); } // Pattern does not match any file or folder return true; @@ -2057,7 +2069,7 @@ export async function printAndValidatePackagedFiles(files: IFile[], cwd: string, if (unusedIncludePatterns.length > 0) { let message = ''; message += `The following include patterns in the ${chalk.bold('"files"')} property in package.json do not match any files packaged in the extension:\n`; - message += unusedIncludePatterns.map(p => ` - ${p}`).join('\n'); + message += unusedIncludePatterns.map(p => ` - ${p.relative}`).join('\n'); message += '\nRemove any include pattern which is not needed.\n'; message += `\n=> Run ${chalk.bold('vsce ls --tree')} to see all included files.\n`; message += `=> Use ${chalk.bold('--allow-unused-files-pattern')} to skip this check`; diff --git a/src/test/fixtures/manifestFiles/README.md b/src/test/fixtures/manifestFiles/README.md new file mode 100644 index 00000000..8318c86b --- /dev/null +++ b/src/test/fixtures/manifestFiles/README.md @@ -0,0 +1 @@ +Test \ No newline at end of file diff --git a/src/test/fixtures/manifestFiles/package.json b/src/test/fixtures/manifestFiles/package.json index 4d5e2a39..ee4afe51 100644 --- a/src/test/fixtures/manifestFiles/package.json +++ b/src/test/fixtures/manifestFiles/package.json @@ -2,6 +2,15 @@ "name": "uuid", "publisher": "joaomoreno", "version": "1.0.0", - "engines": { "vscode": "*" }, - "files": ["foo", "foo2/bar2/include.me", "*/bar3/**", "package.json", "LICENSE"] + "engines": { + "vscode": "*" + }, + "files": [ + "foo", + "foo2/bar2/include.me", + "*/bar3/**", + "package.json", + "LICENSE", + "README.md" + ] } \ No newline at end of file diff --git a/src/test/package.test.ts b/src/test/package.test.ts index 12b6cca1..a6689471 100644 --- a/src/test/package.test.ts +++ b/src/test/package.test.ts @@ -207,6 +207,7 @@ describe('collect', function () { 'extension/foo2/bar2/include.me', 'extension/foo3/bar3/hello.txt', 'extension/package.json', + 'extension/readme.md', ]); }); From b0150958945c7f85861ccb20640189c8b63434ab Mon Sep 17 00:00:00 2001 From: BeniBenj Date: Mon, 4 Nov 2024 11:12:04 +0100 Subject: [PATCH 2/3] fix test --- src/package.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/package.ts b/src/package.ts index 0626b880..f858137e 100644 --- a/src/package.ts +++ b/src/package.ts @@ -984,11 +984,7 @@ export class ReadmeProcessor extends MarkdownProcessor { } override async processFile(file: IFile): Promise { - if (isInMemoryFile(file)) { - util.log.warn(`The provided readme file is in memory and will not be included in the VSIX.`); - return file; - } - file = { ...file, originalPath: file.localPath, path: 'extension/readme.md' }; + file = { ...file, originalPath: !isInMemoryFile(file) ? file.localPath : undefined, path: 'extension/readme.md' }; return await super.processFile(file, file.path); } @@ -1016,7 +1012,7 @@ export class ChangelogProcessor extends MarkdownProcessor { util.log.warn(`The provided changelog file is in memory and will not be included in the VSIX.`); return file; } - file = { ...file, originalPath: file.localPath, path: 'extension/changelog.md' }; + file = { ...file, originalPath: !isInMemoryFile(file) ? file.localPath : undefined, path: 'extension/changelog.md' }; return await super.processFile(file, file.path); } From 6aa21493a52aaa61fb17ff5a49a7b3c961b5dc3c Mon Sep 17 00:00:00 2001 From: BeniBenj Date: Mon, 4 Nov 2024 12:13:55 +0100 Subject: [PATCH 3/3] fix test --- src/package.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/package.ts b/src/package.ts index f858137e..d27b71ca 100644 --- a/src/package.ts +++ b/src/package.ts @@ -1008,10 +1008,6 @@ export class ChangelogProcessor extends MarkdownProcessor { } override async processFile(file: IFile): Promise { - if (isInMemoryFile(file)) { - util.log.warn(`The provided changelog file is in memory and will not be included in the VSIX.`); - return file; - } file = { ...file, originalPath: !isInMemoryFile(file) ? file.localPath : undefined, path: 'extension/changelog.md' }; return await super.processFile(file, file.path); }