Skip to content

Commit cf01d65

Browse files
committed
Ensure package.json is writable in *.vsix
VSC requires the manifest file unpacked from the .vsix archive to be marked as writable (see [1]). Since generating writable artifacts is difficult in some build systems (such as Bazel), it would be helpful if vsce itself could ensure that the file mode of the manifest is correct. With this commit, the correct file mode on `package.json` is set automatically by the packaging process via a new `Processor` and yazl's `mode` argument. [1]: https://github.com/microsoft/vscode/blob/88144f6d31718288c7a2c6fb741e0646d40804cf/src/vs/platform/extensionManagement/node/extensionsScanner.ts#L144
1 parent f8869d7 commit cf01d65

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/package.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@ const MinimatchOptions: minimatch.IOptions = { dot: true };
3737

3838
export interface IInMemoryFile {
3939
path: string;
40+
mode?: number;
4041
readonly contents: Buffer | string;
4142
}
4243

4344
export interface ILocalFile {
4445
path: string;
46+
mode?: number;
4547
readonly localPath: string;
4648
}
4749

@@ -274,6 +276,18 @@ class ManifestProcessor extends BaseProcessor {
274276
}
275277
}
276278

279+
async onFile(file: IFile): Promise<IFile> {
280+
const path = util.normalize(file.path);
281+
282+
if (!/^extension\/package.json$/i.test(path)) {
283+
return Promise.resolve(file);
284+
}
285+
286+
// Ensure that package.json is writable as VS Code needs to
287+
// store metadata in the extracted file.
288+
return { ...file, mode: 0o100644 };
289+
}
290+
277291
async onEnd(): Promise<void> {
278292
if (typeof this.manifest.extensionKind === 'string') {
279293
util.log.warn(
@@ -1104,8 +1118,10 @@ function writeVsix(files: IFile[], packagePath: string): Promise<void> {
11041118
const zip = new yazl.ZipFile();
11051119
files.forEach(f =>
11061120
isInMemoryFile(f)
1107-
? zip.addBuffer(typeof f.contents === 'string' ? Buffer.from(f.contents, 'utf8') : f.contents, f.path)
1108-
: zip.addFile(f.localPath, f.path)
1121+
? zip.addBuffer(typeof f.contents === 'string' ? Buffer.from(f.contents, 'utf8') : f.contents, f.path, {
1122+
mode: f.mode,
1123+
})
1124+
: zip.addFile(f.localPath, f.path, { mode: f.mode })
11091125
);
11101126
zip.end();
11111127

0 commit comments

Comments
 (0)