From b400da1d079780b3567b958a8032c07fd8f4905f Mon Sep 17 00:00:00 2001 From: BeniBenj Date: Tue, 10 Dec 2024 16:51:39 +0100 Subject: [PATCH] :lipstick: --- src/package.ts | 22 +++++++++++----------- src/test/package.test.ts | 34 +++++++++++++++------------------- 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/src/package.ts b/src/package.ts index bb60db51..9f5686e5 100644 --- a/src/package.ts +++ b/src/package.ts @@ -1804,21 +1804,21 @@ export function writeVsix(files: IFile[], packagePath: string): Promise { () => new Promise((c, e) => { const zip = new yazl.ZipFile(); + const zipOptions: Partial = {}; + // reproducible zip files const sde = process.env.SOURCE_DATE_EPOCH; - const epoch = sde ? parseInt(sde) : undefined; - const mtime = epoch ? new Date(epoch * 1000) : undefined; - - files.sort((a, b) => a.path.localeCompare(b.path)).forEach(f => { - let options = { - mode: f.mode, - } as any; - if (mtime) options.mtime = mtime; + if (sde) { + const epoch = parseInt(sde); + zipOptions.mtime = new Date(epoch * 1000); + files = files.sort((a, b) => a.path.localeCompare(b.path)) + } + files.forEach(f => isInMemoryFile(f) - ? zip.addBuffer(typeof f.contents === 'string' ? Buffer.from(f.contents, 'utf8') : f.contents, f.path, options) - : zip.addFile(f.localPath, f.path, options) - }); + ? zip.addBuffer(typeof f.contents === 'string' ? Buffer.from(f.contents, 'utf8') : f.contents, f.path, { ...zipOptions, mode: f.mode }) + : zip.addFile(f.localPath, f.path, { ...zipOptions, mode: f.mode }) + ); zip.end(); const zipStream = fs.createWriteStream(packagePath); diff --git a/src/test/package.test.ts b/src/test/package.test.ts index 2de654bd..6b01a159 100644 --- a/src/test/package.test.ts +++ b/src/test/package.test.ts @@ -14,8 +14,7 @@ import { versionBump, VSIX, LicenseProcessor, - printAndValidatePackagedFiles, - writeVsix, + printAndValidatePackagedFiles, pack } from '../package'; import { ManifestPackage } from '../manifest'; import * as path from 'path'; @@ -27,7 +26,6 @@ import { XMLManifest, parseXmlManifest, parseContentTypes } from '../xml'; import { flatten, log } from '../util'; import { validatePublisher } from '../validation'; import * as jsonc from 'jsonc-parser'; -import { globSync } from 'glob'; // don't warn in tests console.warn = () => null; @@ -2288,13 +2286,13 @@ describe('ManifestProcessor', () => { }); it('should not throw error for engine version with x (e.g. 1.95.x)', async () => { - const root = fixture('uuid'); - const manifest = JSON.parse(await fs.promises.readFile(path.join(root, 'package.json'), 'utf8')); - manifest.engines.vscode = '1.95.x'; // Non-strict semver, but acceptable + const root = fixture('uuid'); + const manifest = JSON.parse(await fs.promises.readFile(path.join(root, 'package.json'), 'utf8')); + manifest.engines.vscode = '1.95.x'; // Non-strict semver, but acceptable - assert.doesNotThrow(() => new ManifestProcessor(manifest, { target: 'web' })); - assert.doesNotThrow(() => new ManifestProcessor(manifest, { preRelease: true })); - }); + assert.doesNotThrow(() => new ManifestProcessor(manifest, { target: 'web' })); + assert.doesNotThrow(() => new ManifestProcessor(manifest, { preRelease: true })); + }); }); describe('MarkdownProcessor', () => { @@ -3212,27 +3210,25 @@ describe('writeVsix', function () { try { fs.cpSync(exampleProject, cwd, { recursive: true }); - const files = globSync("**", { cwd }); - - process.env["SOURCE_DATE_EPOCH"] = '1000000000'; - const createVsix = async (vsixPath: string, epoch: number) => { - files.forEach((f) => fs.utimesSync(path.join(cwd, f), epoch, epoch)); - const manifest1 = await readManifest(cwd); - const iFiles1 = await collect(manifest1, { cwd }); - await writeVsix(iFiles1, vsixPath); + process.env["SOURCE_DATE_EPOCH"] = `${epoch}`; + await pack({ cwd, packagePath: vsixPath }); } const vsix1 = testDir.name + '/vsix1.vsix'; const vsix2 = testDir.name + '/vsix2.vsix'; + const vsix3 = testDir.name + '/vsix3.vsix'; - await createVsix(vsix1, 1000000001); - await createVsix(vsix2, 1000000002); + await createVsix(vsix1, 1000000000); + await createVsix(vsix2, 1000000000); + await createVsix(vsix3, 1000000002); const vsix1bytes = fs.readFileSync(vsix1); const vsix2bytes = fs.readFileSync(vsix2); + const vsix3bytes = fs.readFileSync(vsix3); assert.deepStrictEqual(vsix1bytes, vsix2bytes); + assert.notDeepStrictEqual(vsix1bytes, vsix3bytes); } finally { testDir.removeCallback();