Skip to content

Commit 816b3d2

Browse files
committed
test: migrate tar extraction to tar-stream for E2E setup
This commit replaces the `tar` package with `tar-stream` for file extraction in the e2e test utilities. The primary advantage of this change is a significant reduction in dependency size. The `tar` package is approximately 2MB on disk, whereas `tar-stream` is only ~235KB. This improves installation speed and reduces the overall disk footprint of the project. The implementation in `extractFile` has been updated to use the `tar-stream` event-based API and now includes `zlib.createGunzip()` to correctly handle compressed tarballs.
1 parent 5dc3b64 commit 816b3d2

File tree

5 files changed

+41
-21
lines changed

5 files changed

+41
-21
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@
132132
"rollup-plugin-sourcemaps2": "0.5.4",
133133
"semver": "7.7.3",
134134
"source-map-support": "0.5.21",
135-
"tar": "^7.0.0",
136135
"ts-node": "^10.9.1",
137136
"tslib": "2.8.1",
138137
"typescript": "5.9.3",

pnpm-lock.yaml

Lines changed: 13 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/legacy-cli/e2e/utils/BUILD.bazel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ ts_project(
1616
"//:node_modules/fast-glob",
1717
"//:node_modules/protractor",
1818
"//:node_modules/semver",
19-
"//:node_modules/tar",
2019
"//:node_modules/verdaccio",
2120
"//:node_modules/verdaccio-auth-memory",
21+
"//tests:node_modules/@types/tar-stream",
2222
"//tests:node_modules/rxjs",
23+
"//tests:node_modules/tar-stream",
2324
"//tests:node_modules/tree-kill",
2425
],
2526
)

tests/legacy-cli/e2e/utils/tar.ts

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
import { createReadStream } from 'node:fs';
1010
import { normalize } from 'node:path';
11-
import { Parser } from 'tar';
11+
import { createGunzip } from 'node:zlib';
12+
import { extract } from 'tar-stream';
1213

1314
/**
1415
* Extract and return the contents of a single file out of a tar file.
@@ -21,20 +22,27 @@ export function extractFile(tarball: string, filePath: string): Promise<Buffer>
2122
const normalizedFilePath = normalize(filePath);
2223

2324
return new Promise((resolve, reject) => {
24-
createReadStream(tarball)
25-
.pipe(
26-
new Parser({
27-
strict: true,
28-
filter: (p) => normalize(p) === normalizedFilePath,
29-
onReadEntry: (entry) => {
30-
const chunks: Buffer[] = [];
31-
32-
entry.on('data', (chunk) => chunks.push(chunk));
33-
entry.on('error', reject);
34-
entry.on('finish', () => resolve(Buffer.concat(chunks)));
35-
},
36-
}),
37-
)
38-
.on('close', () => reject(`${tarball} does not contain ${filePath}`));
25+
const extractor = extract();
26+
27+
extractor.on('entry', (header, stream, next) => {
28+
if (normalize(header.name) !== normalizedFilePath) {
29+
stream.resume();
30+
next();
31+
32+
return;
33+
}
34+
35+
const chunks: Buffer[] = [];
36+
stream.on('data', (chunk) => chunks.push(chunk));
37+
stream.on('error', reject);
38+
stream.on('end', () => {
39+
resolve(Buffer.concat(chunks));
40+
next();
41+
});
42+
});
43+
44+
extractor.on('finish', () => reject(new Error(`'${filePath}' not found in '${tarball}'.`)));
45+
46+
createReadStream(tarball).pipe(createGunzip()).pipe(extractor).on('error', reject);
3947
});
4048
}

tests/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
{
22
"devDependencies": {
3+
"@types/tar-stream": "3.1.4",
34
"@angular-devkit/schematics": "workspace:*",
45
"rxjs": "7.8.2",
6+
"tar-stream": "3.1.7",
57
"tree-kill": "1.2.2"
68
}
79
}

0 commit comments

Comments
 (0)