Skip to content

Commit 607a3ae

Browse files
authored
fix(revert): preserve mtime when zipping with the node zipper (#539) (#558)
This reverts commit 162d9bc.
1 parent b448e43 commit 607a3ae

File tree

2 files changed

+9
-33
lines changed

2 files changed

+9
-33
lines changed

src/tests/util.test.ts

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,15 @@ describe('utils/findProjectRoot', () => {
1818
});
1919

2020
describe('utils/zip', () => {
21-
const mtime = new Date(2024, 0, 1, 0, 0, 0, 0);
22-
2321
beforeEach(() => {
2422
mockFs({
25-
'/src': mockFs.directory({
26-
mtime,
27-
items: {
28-
'test.txt': mockFs.file({
29-
mtime,
30-
content: 'lorem ipsum',
31-
}),
32-
modules: mockFs.directory({
33-
mtime,
34-
items: {
35-
'module.txt': mockFs.file({
36-
mtime,
37-
content: 'lorem ipsum 2',
38-
}),
39-
},
40-
}),
23+
'/src': {
24+
'test.txt': 'lorem ipsum',
25+
modules: {
26+
'module.txt': 'lorem ipsum 2',
4127
},
42-
}),
43-
'/dist': mockFs.directory({ mtime }),
28+
},
29+
'/dist': {},
4430
});
4531
});
4632

@@ -79,17 +65,7 @@ describe('utils/zip', () => {
7965
},
8066
];
8167

82-
// Check the mtimes are set correctly
83-
const sourceStat = fs.statSync(source);
84-
expect(sourceStat.mtime).toEqual(mtime);
85-
86-
const testStat = fs.statSync('/src/test.txt');
87-
expect(testStat.mtime).toEqual(mtime);
88-
89-
const moduleStat = fs.statSync('/src/modules/module.txt');
90-
expect(moduleStat.mtime).toEqual(mtime);
91-
92-
await expect(zip(zipPath, filesPathList, useNativeZip)).resolves.toBeUndefined();
68+
await zip(zipPath, filesPathList, useNativeZip);
9369

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

@@ -103,7 +79,7 @@ describe('utils/zip', () => {
10379
if (!useNativeZip) {
10480
const data = fs.readFileSync(zipPath);
10581
const fileHash = crypto.createHash('sha256').update(data).digest('base64');
106-
expect(fileHash).toEqual('PHu2gv7OIMv+lAOCXYPNd30X8/7EKYTuV7KYJjw3Qd4=');
82+
expect(fileHash).toEqual('iCZdyHJ7ON2LLwBIE6gQmRvBTzXBogSqJTMvHSenzGk=');
10783
}
10884
}
10985
);

src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ function nodeZip(zipPath: string, filesPathList: IFiles): Promise<void> {
112112
zipArchive.append(fs.readFileSync(file.rootPath), {
113113
name: file.localPath,
114114
mode: stats.mode,
115-
date: new Date(stats.mtime),
115+
date: new Date(0), // necessary to get the same hash when zipping the same content
116116
});
117117
});
118118

0 commit comments

Comments
 (0)