Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "fix: preserve mtime when zipping with the node zipper (#539)" #558

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 8 additions & 32 deletions src/tests/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,15 @@ describe('utils/findProjectRoot', () => {
});

describe('utils/zip', () => {
const mtime = new Date(2024, 0, 1, 0, 0, 0, 0);

beforeEach(() => {
mockFs({
'/src': mockFs.directory({
mtime,
items: {
'test.txt': mockFs.file({
mtime,
content: 'lorem ipsum',
}),
modules: mockFs.directory({
mtime,
items: {
'module.txt': mockFs.file({
mtime,
content: 'lorem ipsum 2',
}),
},
}),
'/src': {
'test.txt': 'lorem ipsum',
modules: {
'module.txt': 'lorem ipsum 2',
},
}),
'/dist': mockFs.directory({ mtime }),
},
'/dist': {},
});
});

Expand Down Expand Up @@ -79,17 +65,7 @@ describe('utils/zip', () => {
},
];

// Check the mtimes are set correctly
const sourceStat = fs.statSync(source);
expect(sourceStat.mtime).toEqual(mtime);

const testStat = fs.statSync('/src/test.txt');
expect(testStat.mtime).toEqual(mtime);

const moduleStat = fs.statSync('/src/modules/module.txt');
expect(moduleStat.mtime).toEqual(mtime);

await expect(zip(zipPath, filesPathList, useNativeZip)).resolves.toBeUndefined();
await zip(zipPath, filesPathList, useNativeZip);

expect(fs.existsSync(zipPath)).toEqual(true);

Expand All @@ -103,7 +79,7 @@ describe('utils/zip', () => {
if (!useNativeZip) {
const data = fs.readFileSync(zipPath);
const fileHash = crypto.createHash('sha256').update(data).digest('base64');
expect(fileHash).toEqual('PHu2gv7OIMv+lAOCXYPNd30X8/7EKYTuV7KYJjw3Qd4=');
expect(fileHash).toEqual('iCZdyHJ7ON2LLwBIE6gQmRvBTzXBogSqJTMvHSenzGk=');
}
}
);
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function nodeZip(zipPath: string, filesPathList: IFiles): Promise<void> {
zipArchive.append(fs.readFileSync(file.rootPath), {
name: file.localPath,
mode: stats.mode,
date: new Date(stats.mtime),
date: new Date(0), // necessary to get the same hash when zipping the same content
});
});

Expand Down
Loading