Skip to content

Commit 9ee863f

Browse files
committed
address pr feedback
1 parent 3e3a75d commit 9ee863f

16 files changed

Lines changed: 116 additions & 154 deletions

File tree

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,7 @@ jobs:
9595
- name: Rush test (rush-lib)
9696
run: node ${{ github.workspace }}/repo-a/apps/rush/lib/start-dev.js test --verbose --production --timeline
9797
working-directory: repo-b
98+
99+
- name: Rush test (rush-lib) again to verify build cache hits
100+
run: node ${{ github.workspace }}/repo-a/apps/rush/lib/start-dev.js test --verbose --production --timeline
101+
working-directory: repo-b

apps/zipsync/eslint.config.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ module.exports = [
1313
parserOptions: {
1414
tsconfigRootDir: __dirname
1515
}
16-
},
17-
rules: {
18-
'no-console': 'off'
1916
}
2017
}
2118
];

apps/zipsync/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@
2121
"@rushstack/node-core-library": "workspace:*",
2222
"@rushstack/terminal": "workspace:*",
2323
"@rushstack/ts-command-line": "workspace:*",
24-
"semver": "~7.5.4",
2524
"typescript": "~5.8.2",
2625
"@rushstack/lookup-by-path": "workspace:*"
2726
},
2827
"devDependencies": {
2928
"@rushstack/heft": "workspace:*",
30-
"@types/semver": "7.5.0",
3129
"eslint": "~9.25.1",
3230
"local-node-rig": "workspace:*"
3331
}

apps/zipsync/src/ZipSyncCommandLineParser.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import type {
1010
CommandLineChoiceParameter
1111
} from '@rushstack/ts-command-line/lib/index';
1212
import { InternalError } from '@rushstack/node-core-library/lib/InternalError';
13-
import { Colorize } from '@rushstack/terminal/lib/Colorize';
1413
import type { ConsoleTerminalProvider } from '@rushstack/terminal/lib/ConsoleTerminalProvider';
1514
import type { ITerminal } from '@rushstack/terminal/lib/ITerminal';
1615

@@ -110,11 +109,7 @@ export class ZipSyncCommandLineParser extends CommandLineParser {
110109
compression: (this._compressionParameter.value as 'store' | 'deflate' | 'auto' | undefined) ?? 'auto'
111110
});
112111
} catch (error) {
113-
if (this._debugParameter.value) {
114-
console.error('\n' + error.stack);
115-
} else {
116-
console.error('\n' + Colorize.red('ERROR: ' + error.message.trim()));
117-
}
112+
this._terminal.writeErrorLine('\n' + error.stack);
118113
}
119114
}
120115
}

apps/zipsync/src/benchmark.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
22
// See LICENSE in the project root for license information.
3+
/* eslint-disable no-console */
34

45
import { execSync } from 'child_process';
56
import { tmpdir } from 'os';

apps/zipsync/src/crc32.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as zlib from 'zlib';
77
describe('crc32', () => {
88
it('fallbackCrc32 should match zlib.crc32', () => {
99
if (!zlib.crc32) {
10+
// eslint-disable-next-line no-console
1011
console.log('Skipping test because zlib.crc32 is not available in this Node.js version');
1112
return;
1213
}

apps/zipsync/src/crc32.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
22
// See LICENSE in the project root for license information.
33

4-
import * as zlib from 'zlib';
4+
import * as zlib from 'node:zlib';
55

66
let crcTable: Uint32Array | undefined;
77

@@ -35,11 +35,5 @@ export function fallbackCrc32(data: Buffer<ArrayBufferLike>, value: number = 0):
3535
return value;
3636
}
3737

38-
export function crc32Builder(data: Buffer<ArrayBufferLike>, value: number = 0): number {
39-
if (zlib.crc32) {
40-
return zlib.crc32(data, value);
41-
} else {
42-
// Fallback implementation for Node.js versions older than 20
43-
return fallbackCrc32(data, value);
44-
}
45-
}
38+
export const crc32Builder: (data: Buffer<ArrayBufferLike>, value?: number) => number =
39+
zlib.crc32 ?? fallbackCrc32;

apps/zipsync/src/start.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
22
// See LICENSE in the project root for license information.
33

4-
import { version } from '../package.json';
54
import { ConsoleTerminalProvider } from '@rushstack/terminal/lib/ConsoleTerminalProvider';
65
import { Terminal } from '@rushstack/terminal/lib/Terminal';
76

7+
import { version } from '../package.json';
88
import { ZipSyncCommandLineParser } from './ZipSyncCommandLineParser';
99

1010
const toolVersion: string = version;

apps/zipsync/src/zipSync.ts

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
22
// See LICENSE in the project root for license information.
33

4+
import * as fs from 'node:fs';
5+
import * as path from 'node:path';
6+
import * as crypto from 'node:crypto';
7+
import * as zlib from 'node:zlib';
48
import type { ITerminal } from '@rushstack/terminal/lib/ITerminal';
5-
import * as fs from 'fs';
6-
import * as path from 'path';
7-
import * as crypto from 'crypto';
8-
import * as zlib from 'zlib';
99
import { type IReadonlyPathTrieNode, LookupByPath } from '@rushstack/lookup-by-path/lib/LookupByPath';
1010
import { crc32Builder } from './crc32';
1111
import { DISPOSE_SYMBOL, getDisposableFileHandle, type IDisposableFileHandle } from './disposableFileHandle';
@@ -24,7 +24,8 @@ import {
2424
type ZipMetaCompressionMethod,
2525
type IEndOfCentralDirectory,
2626
type ICentralDirectoryHeaderParseResult,
27-
type IFileEntry
27+
type IFileEntry,
28+
dosDateTime
2829
} from './zipUtils';
2930

3031
const METADATA_FILENAME: string = '__zipsync_metadata__.json';
@@ -192,7 +193,13 @@ export function zipSync<T extends IZipSyncOptions>(
192193
}
193194
currentOffset += offset;
194195
}
196+
function writeChunksToZip(chunks: Uint8Array[]): void {
197+
for (const chunk of chunks) {
198+
writeChunkToZip(chunk);
199+
}
200+
}
195201

202+
const dosDateTimeNow: { time: number; date: number } = dosDateTime(new Date());
196203
function writeFileEntry(relativePath: string): IFileEntry {
197204
function isLikelyAlreadyCompressed(filename: string): boolean {
198205
return LIKELY_COMPRESSED_EXTENSION_REGEX.test(filename.toLowerCase());
@@ -244,10 +251,11 @@ export function zipSync<T extends IZipSyncOptions>(
244251
crc32: 0,
245252
sha1Hash: '',
246253
localHeaderOffset: currentOffset,
247-
compressionMethod
254+
compressionMethod,
255+
dosDateTime: dosDateTimeNow
248256
};
249257

250-
writeChunkToZip(writeLocalFileHeader(entry));
258+
writeChunksToZip(writeLocalFileHeader(entry));
251259

252260
const sha1HashBuilder: crypto.Hash = crypto.createHash('sha1');
253261
let crc32: number = 0;
@@ -350,10 +358,11 @@ export function zipSync<T extends IZipSyncOptions>(
350358
crc32: crc32Builder(metadataBuffer),
351359
sha1Hash: calculateSHA1(metadataBuffer),
352360
localHeaderOffset: currentOffset,
353-
compressionMethod: metadataCompressionMethod
361+
compressionMethod: metadataCompressionMethod,
362+
dosDateTime: dosDateTimeNow
354363
};
355364

356-
writeChunkToZip(writeLocalFileHeader(metadataEntry));
365+
writeChunksToZip(writeLocalFileHeader(metadataEntry));
357366
writeChunkToZip(metadataData, metadataCompressedSize);
358367
writeChunkToZip(writeDataDescriptor(metadataEntry));
359368

@@ -371,26 +380,15 @@ export function zipSync<T extends IZipSyncOptions>(
371380

372381
markStart('pack.write.centralDirectory');
373382
const centralDirOffset: number = currentOffset;
374-
let centralDirSize: number = 0;
375-
376383
for (const entry of entries) {
377-
const centralHeader: Buffer = writeCentralDirectoryHeader(entry);
378-
fs.writeSync(zipFile, centralHeader);
379-
centralDirSize += centralHeader.length;
384+
writeChunksToZip(writeCentralDirectoryHeader(entry));
380385
}
381-
terminal.writeDebugLine(
382-
`Central directory written (offset=${centralDirOffset}, size=${centralDirSize})`
383-
);
386+
const centralDirSize: number = currentOffset - centralDirOffset;
384387
markEnd('pack.write.centralDirectory');
385388

386389
// Write end of central directory
387390
markStart('pack.write.eocd');
388-
const endOfCentralDir: Buffer = writeEndOfCentralDirectory(
389-
centralDirOffset,
390-
centralDirSize,
391-
entries.length
392-
);
393-
fs.writeSync(zipFile, endOfCentralDir);
391+
writeChunkToZip(writeEndOfCentralDirectory(centralDirOffset, centralDirSize, entries.length));
394392
terminal.writeDebugLine('EOCD record written');
395393
markEnd('pack.write.eocd');
396394
} finally {

0 commit comments

Comments
 (0)