Skip to content
Open
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
6 changes: 3 additions & 3 deletions .github/workflows/npm_release_cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:

- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 22.14.0
node-version: 22.23.5
registry-url: "https://registry.npmjs.org"

- name: Setup
Expand Down Expand Up @@ -142,7 +142,7 @@ jobs:

- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 22.14.0
node-version: 22.23.5
registry-url: "https://registry.npmjs.org"

- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
Expand Down Expand Up @@ -198,7 +198,7 @@ jobs:

- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 22.14.0
node-version: 22.23.5

- name: Setup
run: npm i --ignore-scripts --legacy-peer-deps --no-package-lock
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
fail-fast: false
matrix:
os: [ ubuntu-latest ]
node-version: [ '20.x', '22.x', '24.x' ]
node-version: [ '22.x', '24.x' ]
include:
# A darwin leg is what covers the iOS-specific suites - they are gated
# on the platform and never execute anywhere else. One version is
Expand Down
2 changes: 1 addition & 1 deletion lib/definitions/pacote-service.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ declare global {
}

interface IPacoteExtractOptions {
filter?: (path: string, stat: tar.FileStat) => boolean;
filter?: (path: string, entry: tar.ReadEntry) => boolean;
}
}
69 changes: 26 additions & 43 deletions lib/services/pacote-service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as pacote from "pacote";
import * as tar from "tar";
import * as path from "path";
import { PassThrough } from "stream";
import * as _ from "lodash";
import { cache } from "../common/decorators";
import { INpmConfigService, INodePackageManager } from "../declarations";
Expand Down Expand Up @@ -57,60 +56,44 @@ export class PacoteService implements IPacoteService {
destinationDirectory: string,
options?: IPacoteExtractOptions,
): Promise<void> {
// strip: Remove the specified number of leading path elements. Pathnames with fewer elements will be silently skipped. More info: https://github.com/npm/node-tar/blob/e89c4d37519b1c20133a9f49d5f6b85fa34c203b/README.md
// C: Create an archive
this.$logger.trace(
`Calling pacoteService.extractPackage for packageName: '${packageName}', destinationDir: '${destinationDirectory}' and options: ${options}`,
);
const extractOptions = { strip: 1, C: destinationDirectory };
if (options) {
_.extend(extractOptions, options);
}
// strip: 1 drops the leading `package/` directory of an npm tarball
const extractOptions = {
strip: 1,
cwd: destinationDirectory,
...options,
};

packageName = this.getRealPackageName(packageName);
const pacoteOptions = await this.getPacoteBaseOptions();

return new Promise<void>(async (resolve, reject) => {
let source: Uint8Array;
try {
source = await pacote.tarball(packageName, pacoteOptions);
} catch (err) {
this.$logger.trace(
`Calling pacoteService.extractPackage for packageName: '${packageName}', destinationDir: '${destinationDirectory}' and options: ${options}`,
`Error while fetching the tarball of ${packageName}. Error is ${err}`,
);
throw err;
}

const source = await pacote
.tarball(packageName, pacoteOptions)
.catch((err: Error) => {
this.$logger.trace(
`Error in source while trying to extract stream from ${packageName}. Error is ${err}`,
);
reject(err);
});

this.$logger.trace(
`Extracting tarball with options: ${JSON.stringify(extractOptions, null, 2)}`,
);
try {
await tar.x({ ...extractOptions, input: source });
} catch (err) {
this.$logger.trace(
`Creating extract tar stream with options: ${JSON.stringify(
extractOptions,
null,
2,
)}`,
`Error while extracting the tarball of ${packageName}. Error is ${err}`,
);
const destination = tar.x(extractOptions);
// Initiate the source
const sourceStream = new PassThrough();
sourceStream.end(source);
sourceStream.pipe(destination);

destination.on("error", (err: Error) => {
this.$logger.trace(
`Error in destination while trying to extract stream from ${packageName}. Error is ${err}`,
);
reject(err);
});

destination.on("finish", () => {
this.$logger.trace(
`Successfully extracted '${packageName}' to ${destinationDirectory}`,
);
resolve();
});
});
throw err;
}

this.$logger.trace(
`Successfully extracted '${packageName}' to ${destinationDirectory}`,
);
}

private async getPacoteBaseOptions(): Promise<IPacoteBaseOptions> {
Expand Down
Loading
Loading