Skip to content
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
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@
"rollup-plugin-sourcemaps2": "0.5.4",
"semver": "7.7.3",
"source-map-support": "0.5.21",
"tar": "^7.0.0",
"ts-node": "^10.9.1",
"tslib": "2.8.1",
"typescript": "5.9.3",
Expand Down
16 changes: 13 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion tests/legacy-cli/e2e/utils/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ ts_project(
"//:node_modules/fast-glob",
"//:node_modules/protractor",
"//:node_modules/semver",
"//:node_modules/tar",
"//:node_modules/verdaccio",
"//:node_modules/verdaccio-auth-memory",
"//tests:node_modules/@types/tar-stream",
"//tests:node_modules/rxjs",
"//tests:node_modules/tar-stream",
"//tests:node_modules/tree-kill",
],
)
40 changes: 24 additions & 16 deletions tests/legacy-cli/e2e/utils/tar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

import { createReadStream } from 'node:fs';
import { normalize } from 'node:path';
import { Parser } from 'tar';
import { createGunzip } from 'node:zlib';
import { extract } from 'tar-stream';

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

return new Promise((resolve, reject) => {
createReadStream(tarball)
.pipe(
new Parser({
strict: true,
filter: (p) => normalize(p) === normalizedFilePath,
onReadEntry: (entry) => {
const chunks: Buffer[] = [];

entry.on('data', (chunk) => chunks.push(chunk));
entry.on('error', reject);
entry.on('finish', () => resolve(Buffer.concat(chunks)));
},
}),
)
.on('close', () => reject(`${tarball} does not contain ${filePath}`));
const extractor = extract();

extractor.on('entry', (header, stream, next) => {
if (normalize(header.name) !== normalizedFilePath) {
stream.resume();
next();

return;
}

const chunks: Buffer[] = [];
stream.on('data', (chunk) => chunks.push(chunk));
stream.on('error', reject);
stream.on('end', () => {
resolve(Buffer.concat(chunks));
next();
});
});

extractor.on('finish', () => reject(new Error(`'${filePath}' not found in '${tarball}'.`)));

createReadStream(tarball).pipe(createGunzip()).pipe(extractor).on('error', reject);
});
}
2 changes: 2 additions & 0 deletions tests/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"devDependencies": {
"@types/tar-stream": "3.1.4",
"@angular-devkit/schematics": "workspace:*",
"rxjs": "7.8.2",
"tar-stream": "3.1.7",
"tree-kill": "1.2.2"
}
}