Skip to content

Commit

Permalink
💄
Browse files Browse the repository at this point in the history
  • Loading branch information
benibenj committed Dec 10, 2024
1 parent 018208d commit b400da1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 30 deletions.
22 changes: 11 additions & 11 deletions src/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1804,21 +1804,21 @@ export function writeVsix(files: IFile[], packagePath: string): Promise<void> {
() =>
new Promise((c, e) => {
const zip = new yazl.ZipFile();
const zipOptions: Partial<yazl.Options> = {};

// 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);
Expand Down
34 changes: 15 additions & 19 deletions src/test/package.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import {
versionBump,
VSIX,
LicenseProcessor,
printAndValidatePackagedFiles,
writeVsix,
printAndValidatePackagedFiles, pack
} from '../package';
import { ManifestPackage } from '../manifest';
import * as path from 'path';
Expand All @@ -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;
Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit b400da1

Please sign in to comment.