diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 795ec0750..759d402be 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -271,6 +271,18 @@ jobs: shell: pwsh run: pnpm run test:ci + - name: Install the minimum supported Node.js for the built CLI + if: matrix.suite == 'regular' && matrix.lane == 'linux-22' + shell: bash + run: node scripts/setup/node.mts --version 18.20.8 + + - name: Check CLI startup on Node.js 18 + if: matrix.suite == 'regular' && matrix.lane == 'linux-22' + shell: bash + run: | + test "$(node --version)" = v18.20.8 + test "$(node bin/cli.js --version)" = "$(node -p "require('./package.json').version")" + - name: Build for E2E tests if: matrix.suite == 'e2e' run: pnpm run build diff --git a/eslint.config.js b/eslint.config.js index 3bb6f4b1a..9c3c319fe 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -227,6 +227,7 @@ module.exports = [ 'src/*/*/*.test.mts', // Allow paths like src/commands/manifest/bazel/*.test.mts. 'src/*/*/*/*.test.mts', + 'test/patches/*.test.mts', 'test/unit/*.test.mts', 'test/*.mts', 'test/src/utils/*.test.mts', diff --git a/package.json b/package.json index 2f3044208..6588a7027 100644 --- a/package.json +++ b/package.json @@ -216,7 +216,7 @@ "semver": "7.7.2", "svgo": "4.1.0", "synp": "1.9.14", - "tar": "7.5.23", + "tar": "8.0.5", "taze": "21.3.0", "terminal-link": "2.1.1", "tiny-updater": "3.5.3", diff --git a/patches/@cyclonedx__cdxgen@12.9.2.patch b/patches/@cyclonedx__cdxgen@12.9.2.patch new file mode 100644 index 000000000..086b0268a --- /dev/null +++ b/patches/@cyclonedx__cdxgen@12.9.2.patch @@ -0,0 +1,117 @@ +diff --git a/lib/managers/docker.js b/lib/managers/docker.js +--- a/lib/managers/docker.js ++++ b/lib/managers/docker.js +@@ -1,6 +1,5 @@ + import { Buffer } from "node:buffer"; + import { +- createReadStream, + lstatSync, + readdirSync, + readFileSync, +@@ -8,7 +7,6 @@ + import { platform as _platform, userInfo as _userInfo, homedir } from "node:os"; + import { basename, join, resolve, win32 } from "node:path"; + import process from "node:process"; +-import stream from "node:stream/promises"; + import { URL } from "node:url"; + + import { x } from "tar"; +@@ -1481,23 +1479,18 @@ + return await safeExtractArchive( + fullImageName, + dir, +- async () => +- await stream.pipeline( +- createReadStream(fullImageName), +- x({ +- sync: false, +- preserveOwner: false, +- noMtime: true, +- noChmod: true, +- strict: !NON_STRICT_TAR_EXTRACT, +- C: dir, +- portable: true, +- unlink: true, +- onwarn: handleTarWarning, +- onReadEntry: handleAbsolutePath, +- filter: tarFilter, +- }), +- ), ++ () => ++ x({ ++ file: fullImageName, ++ preserveOwner: false, ++ noMtime: true, ++ strict: !NON_STRICT_TAR_EXTRACT, ++ cwd: dir, ++ unlink: true, ++ onwarn: handleTarWarning, ++ onEntry: handleAbsolutePath, ++ filter: tarFilter, ++ }), + "untar", + { + blockedReason: +@@ -1956,41 +1949,31 @@ + console.log(`About to export image ${fullImageName} to ${tempDir}`); + } + } +- await stream.pipeline( +- client.stream(`images/${fullImageName}/get`), +- x({ +- sync: false, +- preserveOwner: false, +- noMtime: true, +- noChmod: true, +- strict: !NON_STRICT_TAR_EXTRACT, +- C: tempDir, +- portable: true, +- unlink: true, +- onwarn: handleTarWarning, +- onReadEntry: handleAbsolutePath, +- filter: tarFilter, +- }), +- ); ++ await x({ ++ input: client.stream(`images/${fullImageName}/get`), ++ preserveOwner: false, ++ noMtime: true, ++ strict: !NON_STRICT_TAR_EXTRACT, ++ cwd: tempDir, ++ unlink: true, ++ onwarn: handleTarWarning, ++ onEntry: handleAbsolutePath, ++ filter: tarFilter, ++ }); + } catch (_err) { + if (localData?.Id) { + console.log(`Retrying with ${localData.Id}`); + try { +- await stream.pipeline( +- client.stream(`images/${localData.Id}/get`), +- x({ +- sync: true, +- preserveOwner: false, +- noMtime: true, +- noChmod: true, +- strict: !NON_STRICT_TAR_EXTRACT, +- C: tempDir, +- portable: true, +- onwarn: handleTarWarning, +- onReadEntry: handleAbsolutePath, +- filter: tarFilter, +- }), +- ); ++ await x({ ++ input: client.stream(`images/${localData.Id}/get`), ++ preserveOwner: false, ++ noMtime: true, ++ strict: !NON_STRICT_TAR_EXTRACT, ++ cwd: tempDir, ++ onwarn: handleTarWarning, ++ onEntry: handleAbsolutePath, ++ filter: tarFilter, ++ }); + } catch (_err) { + // ignore + } diff --git a/patches/@socketregistry__packageurl-js@1.7.0.patch b/patches/@socketregistry__packageurl-js@1.7.0.patch new file mode 100644 index 000000000..9385d08c5 --- /dev/null +++ b/patches/@socketregistry__packageurl-js@1.7.0.patch @@ -0,0 +1,33 @@ +diff --git a/dist/index.js b/dist/index.js +--- a/dist/index.js ++++ b/dist/index.js +@@ -1046,7 +1046,7 @@ + const ArrayPrototypeSplice = require_primordials_uncurry.uncurryThis(Array.prototype.splice); + const ArrayPrototypeToLocaleString = require_primordials_uncurry.uncurryThis(Array.prototype.toLocaleString); + const ArrayPrototypeToReversed = require_primordials_uncurry.uncurryThis(Array.prototype.toReversed); +- const ArrayPrototypeToSorted = require_primordials_uncurry.uncurryThis(Array.prototype.toSorted); ++ const ArrayPrototypeToSorted = typeof Array.prototype.toSorted === 'function' ? require_primordials_uncurry.uncurryThis(Array.prototype.toSorted) : ((values, compareFn) => ArrayPrototypeSort(ArrayFrom(values), compareFn)); + const ArrayPrototypeToSpliced = require_primordials_uncurry.uncurryThis(Array.prototype.toSpliced); + const ArrayPrototypeToString = require_primordials_uncurry.uncurryThis(Array.prototype.toString); + const ArrayPrototypeUnshift = require_primordials_uncurry.uncurryThis(Array.prototype.unshift); +diff --git a/dist/exists.js b/dist/exists.js +--- a/dist/exists.js ++++ b/dist/exists.js +@@ -1845,7 +1845,7 @@ + const ArrayPrototypeSplice = require_primordials_uncurry.uncurryThis(Array.prototype.splice); + const ArrayPrototypeToLocaleString = require_primordials_uncurry.uncurryThis(Array.prototype.toLocaleString); + const ArrayPrototypeToReversed = require_primordials_uncurry.uncurryThis(Array.prototype.toReversed); +- const ArrayPrototypeToSorted = require_primordials_uncurry.uncurryThis(Array.prototype.toSorted); ++ const ArrayPrototypeToSorted = typeof Array.prototype.toSorted === 'function' ? require_primordials_uncurry.uncurryThis(Array.prototype.toSorted) : ((values, compareFn) => ArrayPrototypeSort(ArrayFrom(values), compareFn)); + const ArrayPrototypeToSpliced = require_primordials_uncurry.uncurryThis(Array.prototype.toSpliced); + const ArrayPrototypeToString = require_primordials_uncurry.uncurryThis(Array.prototype.toString); + const ArrayPrototypeUnshift = require_primordials_uncurry.uncurryThis(Array.prototype.unshift); +@@ -14080,7 +14080,7 @@ + const ArrayPrototypeSplice = require_primordials_uncurry.uncurryThis(Array.prototype.splice); + const ArrayPrototypeToLocaleString = require_primordials_uncurry.uncurryThis(Array.prototype.toLocaleString); + const ArrayPrototypeToReversed = require_primordials_uncurry.uncurryThis(Array.prototype.toReversed); +- const ArrayPrototypeToSorted = require_primordials_uncurry.uncurryThis(Array.prototype.toSorted); ++ const ArrayPrototypeToSorted = typeof Array.prototype.toSorted === 'function' ? require_primordials_uncurry.uncurryThis(Array.prototype.toSorted) : ((values, compareFn) => ArrayPrototypeSort(ArrayFrom(values), compareFn)); + const ArrayPrototypeToSpliced = require_primordials_uncurry.uncurryThis(Array.prototype.toSpliced); + const ArrayPrototypeToString = require_primordials_uncurry.uncurryThis(Array.prototype.toString); + const ArrayPrototypeUnshift = require_primordials_uncurry.uncurryThis(Array.prototype.unshift); diff --git a/patches/@socketsecurity__sdk@4.3.0.patch b/patches/@socketsecurity__sdk@4.3.0.patch new file mode 100644 index 000000000..7472ca6f8 --- /dev/null +++ b/patches/@socketsecurity__sdk@4.3.0.patch @@ -0,0 +1,21 @@ +diff --git a/dist/index.js b/dist/index.js +--- a/dist/index.js ++++ b/dist/index.js +@@ -1937,7 +1937,7 @@ + const ArrayPrototypeSplice = require_primordials_uncurry.uncurryThis(Array.prototype.splice); + const ArrayPrototypeToLocaleString = require_primordials_uncurry.uncurryThis(Array.prototype.toLocaleString); + const ArrayPrototypeToReversed = require_primordials_uncurry.uncurryThis(Array.prototype.toReversed); +- const ArrayPrototypeToSorted = require_primordials_uncurry.uncurryThis(Array.prototype.toSorted); ++ const ArrayPrototypeToSorted = typeof Array.prototype.toSorted === 'function' ? require_primordials_uncurry.uncurryThis(Array.prototype.toSorted) : ((values, compareFn) => ArrayPrototypeSort(ArrayFrom(values), compareFn)); + const ArrayPrototypeToSpliced = require_primordials_uncurry.uncurryThis(Array.prototype.toSpliced); + const ArrayPrototypeToString = require_primordials_uncurry.uncurryThis(Array.prototype.toString); + const ArrayPrototypeUnshift = require_primordials_uncurry.uncurryThis(Array.prototype.unshift); +@@ -3981,7 +3981,7 @@ + const ArrayPrototypeSplice = require_primordials_uncurry.uncurryThis(Array.prototype.splice); + const ArrayPrototypeToLocaleString = require_primordials_uncurry.uncurryThis(Array.prototype.toLocaleString); + const ArrayPrototypeToReversed = require_primordials_uncurry.uncurryThis(Array.prototype.toReversed); +- const ArrayPrototypeToSorted = require_primordials_uncurry.uncurryThis(Array.prototype.toSorted); ++ const ArrayPrototypeToSorted = typeof Array.prototype.toSorted === 'function' ? require_primordials_uncurry.uncurryThis(Array.prototype.toSorted) : ((values, compareFn) => ArrayPrototypeSort(ArrayFrom(values), compareFn)); + const ArrayPrototypeToSpliced = require_primordials_uncurry.uncurryThis(Array.prototype.toSpliced); + const ArrayPrototypeToString = require_primordials_uncurry.uncurryThis(Array.prototype.toString); + const ArrayPrototypeUnshift = require_primordials_uncurry.uncurryThis(Array.prototype.unshift); diff --git a/patches/node-gyp@13.1.0.patch b/patches/node-gyp@13.1.0.patch new file mode 100644 index 000000000..7f5a26d99 --- /dev/null +++ b/patches/node-gyp@13.1.0.patch @@ -0,0 +1,13 @@ +diff --git a/lib/install.js b/lib/install.js +--- a/lib/install.js ++++ b/lib/install.js +@@ -231,7 +231,8 @@ + contentShasums[filename] = checksum + log.verbose('content checksum', filename, checksum) + }), +- tar.extract({ ++ async input => tar.extract({ ++ input, + strip: 1, + cwd: tarExtractDir, + filter: isValid, diff --git a/patches/pacote@22.0.1.patch b/patches/pacote@22.0.1.patch new file mode 100644 index 000000000..13b8d94bd --- /dev/null +++ b/patches/pacote@22.0.1.patch @@ -0,0 +1,132 @@ +diff --git a/lib/dir.js b/lib/dir.js +--- a/lib/dir.js ++++ b/lib/dir.js +@@ -1,6 +1,5 @@ +-const { resolve, join } = require('node:path') +-const { mkdtemp, writeFile, rm } = require('node:fs/promises') +-const { tmpdir } = require('node:os') ++const { resolve } = require('node:path') ++const { Readable } = require('node:stream') + const packlist = require('npm-packlist') + const runScript = require('@npmcli/run-script') + const tar = require('tar') +@@ -82,11 +81,8 @@ + return packlist(this.tree, { path: this.resolved, prefix, workspaces, globalIgnoreFile }) + }) + .then(async files => { +- const { options, cleanup } = await this.#tarOptions() +- const source = tar.c(options, files) +- // the strip temp file must outlive content consumption, so clean up once the stream is done +- source.once('end', cleanup) +- source.once('error', cleanup) ++ const options = await this.#tarOptions() ++ const source = Readable.fromWeb(tar.c(options, files)) + return source.on('error', er => stream.emit('error', er)).pipe(stream) + }) + .catch(er => stream.emit('error', er)) +@@ -94,7 +90,7 @@ + } + + // Build the tar create options. +- // When the packed package.json declares patchedDependencies, redirect it to a stripped copy so project-local patches never ship. ++ // When the packed package.json declares patchedDependencies, replace its archive body with a stripped copy so project-local patches never ship. + // Non-patched packs are unchanged. + async #tarOptions () { + const options = tarCreateOptions(this.package) +@@ -102,7 +98,7 @@ + // read package.json from disk after prepare so the strip reflects the actually-packed manifest. + const pkgJson = await PackageJson.load(this.resolved) + if (!('patchedDependencies' in pkgJson.content)) { +- return { options, cleanup: () => {} } ++ return options + } + + // serialize the package.json minus patchedDependencies, preserving its indent and newline. +@@ -113,30 +109,22 @@ + const newline = content[Symbol.for('newline')] + const stripped = `${JSON.stringify(content, null, indent)}\n`.replace(/\n/g, newline) + +- // write the stripped copy to a temp dir, removing it if the write itself fails. +- const dir = await mkdtemp(join(tmpdir(), 'pacote-pack-')) +- const strippedPath = join(dir, 'package.json') +- try { +- await writeFile(strippedPath, stripped) +- } catch (er) { +- /* istanbul ignore next - writing to a freshly created temp dir is not deterministically failable */ +- await rm(dir, { recursive: true, force: true }) +- /* istanbul ignore next */ +- throw er ++ const body = Buffer.from(stripped) ++ const filter = options.filter ++ options.filter = (path, stat) => { ++ // Keep hard links to the original manifest independent of the stripped entry. ++ if (path === 'package.json') { ++ stat.nlink = 1 ++ } ++ return filter(path, stat) + } +- const size = Buffer.byteLength(stripped) +- +- // point only the top-level package.json entry at the stripped copy; every other file is untouched. +- // onWriteEntry runs before the tar header and the file's hardlink check, so size and nlink here are honored. +- options.onWriteEntry = (entry) => { ++ options.onWriteEntry = entry => { + if (entry.path === 'package.json') { +- entry.absolute = strippedPath +- entry.stat.size = size +- entry.stat.nlink = 1 ++ entry.body = body ++ entry.size = body.length + } + } +- +- return { options, cleanup: () => rm(dir, { recursive: true, force: true }) } ++ return options + } + + manifest () { +diff --git a/lib/fetcher.js b/lib/fetcher.js +--- a/lib/fetcher.js ++++ b/lib/fetcher.js +@@ -385,28 +385,19 @@ + return this.#toFile(dest) + } + +- #extract (dest, tarball) { +- const extractor = tar.x(this.#tarxOptions({ cwd: dest })) +- const p = new Promise((resolve, reject) => { +- extractor.on('end', () => { +- resolve({ +- resolved: this.resolved, +- integrity: this.integrity && String(this.integrity), +- from: this.from, +- }) +- }) +- +- extractor.on('error', er => { +- log.warn('tar', er.message) +- log.silly('tar', er) +- reject(er) +- }) +- +- tarball.on('error', er => reject(er)) +- }) +- +- tarball.pipe(extractor) +- return p ++ async #extract (dest, tarball) { ++ try { ++ await tar.x({ ...this.#tarxOptions({ cwd: dest }), input: tarball }) ++ } catch (er) { ++ log.warn('tar', er.message) ++ log.silly('tar', er) ++ throw er ++ } ++ return { ++ resolved: this.resolved, ++ integrity: this.integrity && String(this.integrity), ++ from: this.from, ++ } + } + + // always ensure that entries are at least as permissive as our configured diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 33bf7b8b3..846d5b294 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -240,7 +240,7 @@ overrides: smol-toml: 1.9.1 source-map-js@>=1.0.0 <1.2.2: 1.2.3 string_decoder: 0.10.31 - tar: 7.5.23 + tar: 8.0.5 tiny-colors: 2.1.3 tiny-updater: 3.5.3 typedarray: npm:@socketregistry/typedarray@^1.0.8 @@ -253,7 +253,10 @@ overrides: packageExtensionsChecksum: sha256-t7aflKaC02sLz7XiRIHwrlU+oApOY93sNAwB8C1uD5c= patchedDependencies: + '@cyclonedx/cdxgen@12.9.2': ea8b0d76a1f95182f5ca3612360ca194dd1d34acc7d11e9179f4a809c72868d6 '@rollup/plugin-commonjs@28.0.6': 4d412c02fa3df1b1f5b29b135bd3f0997f85248ceb3a578d01e7f40fba27c21b + '@socketregistry/packageurl-js@1.7.0': d7dfd1df1887f1b1c7f7f623f4030a1a0533dc7b0ec6aafaf1936fe3ad36864a + '@socketsecurity/sdk@4.3.0': ad4358a99d126acec0aee629ee0685022eb2efe69b4490f7fa6a003dd47a13b7 '@termless/core@0.11.0': 38ffbca72f99f8532af54a935ccafb88b75d9bcbc3058745f3c66cf4b5153400 ansi-term@0.0.2: 06bb5127b7689d6ab2ea833f9617b2c3fbe9fe0048ce1c6b59b81f7e25ccbccb blessed-contrib@4.11.0: 2c9f0a87aa8ce9ed95ce201819ef3fcdb9a00f1cabe12815f586d2a3c0bff69e @@ -263,6 +266,8 @@ patchedDependencies: drawille-canvas-blessed-contrib@0.1.3: baf1e92576f78c2c86283e7a3182ddd59d52cd7e86ad9fe21d1c4ccc2274bcf3 graceful-fs@4.2.11: 17007d43dcc01ee2047730ab13eb23c41adc01ae0f24ee872b1fe69142db5200 meow@13.2.0: 00fba6d3f9a0591670dcc98f872839fd1669152891f292799bfd7fdda4d9ce36 + node-gyp@13.1.0: 367180c445d49be5842d1021bb00cbf76d9c711635eb01ab783999f37d044563 + pacote@22.0.1: 5a5c821294407145a5dc8f162997f8fe06b014ceb3d1047baa6b49dbd3e64199 string_decoder@0.10.31: 4f6ae5ec65b5537e81cd3ee7e83ae65bcc843a93cff14f147d8053e1c385ae1d tiny-updater@3.5.3: 9cbc246a7a5990a8927329f2cc1ca4e3f5a4ed00de75580c227ac120c2d7bf0e @@ -284,7 +289,7 @@ importers: version: 4.3.2(@types/node@24.3.1) '@socketregistry/packageurl-js': specifier: 1.7.0 - version: 1.7.0 + version: 1.7.0(patch_hash=d7dfd1df1887f1b1c7f7f623f4030a1a0533dc7b0ec6aafaf1936fe3ad36864a) '@socketsecurity/socket-patch': specifier: 5.1.0 version: 5.1.0 @@ -321,7 +326,7 @@ importers: version: 2.2.4 '@cyclonedx/cdxgen': specifier: 12.9.2 - version: 12.9.2(supports-color@7.2.0) + version: 12.9.2(patch_hash=ea8b0d76a1f95182f5ca3612360ca194dd1d34acc7d11e9179f4a809c72868d6)(supports-color@7.2.0) '@dotenvx/dotenvx': specifier: 1.49.0 version: 1.49.0 @@ -399,7 +404,7 @@ importers: version: 3.0.1 '@socketsecurity/sdk': specifier: 4.3.0 - version: 4.3.0 + version: 4.3.0(patch_hash=ad4358a99d126acec0aee629ee0685022eb2efe69b4490f7fa6a003dd47a13b7) '@termless/core': specifier: 0.11.0 version: 0.11.0(patch_hash=38ffbca72f99f8532af54a935ccafb88b75d9bcbc3058745f3c66cf4b5153400)(node-pty@1.2.0-beta.18) @@ -587,8 +592,8 @@ importers: specifier: 1.9.14 version: 1.9.14 tar: - specifier: 7.5.23 - version: 7.5.23 + specifier: 8.0.5 + version: 8.0.5 taze: specifier: 21.3.0 version: 21.3.0 @@ -1356,10 +1361,6 @@ packages: resolution: {integrity: sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==} engines: {node: '>=12'} - '@isaacs/fs-minipass@4.0.1': - resolution: {integrity: sha512-wgm9Ehl2jpeqP3zw/7mo3kRHFp5MEDhqAdwy1fTGkHAwnkGOVsgpvQhL8B5n1qlb01jV3n/bI0ZfZp5lWA1k4w==} - engines: {node: '>=18.0.0'} - '@isaacs/nonrecursive-glob-match@1.1.0': resolution: {integrity: sha512-GPm/Dbvk5RLmhRnxXIa7nTpK0xtl4E0wj0MslsuNiJ1FIROU+2+9lgUC/dgF7Ey4QCWhfEsgxilMRMCdHPfDfw==} @@ -3325,10 +3326,6 @@ packages: resolution: {integrity: sha512-WDrybc/gKFpTYQutKIK6UvfcuxijIZfMfXaYm8NMsPQxSYvf+13fXUJ4rztGGbJcBQ/GF55gvrZ0Bc0bj/mqvg==} engines: {node: '>=20.18.1'} - chownr@3.0.0: - resolution: {integrity: sha512-+IxzY9BZOQd/XuYPRmrvEVjF/nqj5kgT4kEq7VofrDoM1MxoRjEWkrCC3EtLi59TVawxTAn+orJwFQcrqEN1+g==} - engines: {node: '>=18'} - ci-info@4.3.1: resolution: {integrity: sha512-Wdy2Igu8OcBpI2pZePZ5oWjPC38tmDVx5WKUXKwlLYkA0ozo85sLsLvkBbBn/sZaSCMFOGZJ14fvW9t5/d7kdA==} engines: {node: '>=8'} @@ -5546,9 +5543,9 @@ packages: resolution: {integrity: sha512-g9ljZiwki/LfxmQADO3dEY1CbpmXT5Hm2fJ+QaGKwSXUylMybePR7/67YW7jOrrvjEgL1Fmz5kzyAjWVWLlucg==} engines: {node: '>=6'} - tar@7.5.23: - resolution: {integrity: sha512-lkukzdoGngZHJZXxW4S/E4Fp9ghTDlyZXrQGRNoJ/LXvDKcXUTq2sg5yQe74po7Voea6n/IN09+wE/QvJMiifA==} - engines: {node: '>=18'} + tar@8.0.5: + resolution: {integrity: sha512-iYroSHv/iVs5Bfy7uXCZVTye64oecqEETP3jvxksDcJlf8E3hreHYyhT+Qu7b+JgniditLaQbk4ZujNAnPEX9w==} + engines: {node: '>=22'} taze@21.3.0: resolution: {integrity: sha512-9l1x5+weSLJvxO0ImL8hIukVbmNSotTS0Fe47J8TRucL+3htVIzh53YRMqQldsqYXHsBH90bca3LoXN1cLV6Ng==} @@ -5983,10 +5980,6 @@ packages: yallist@4.0.0: resolution: {integrity: sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==} - yallist@5.0.0: - resolution: {integrity: sha512-YgvUTfwqyc7UXVMrB+SImsVYSmTS8X/tSrtdNZMImM+n7+QTriRXyXim0mBrTXNeqzVF0KWGgHPeiyViFFrNDw==} - engines: {node: '>=18'} - yaml@2.8.1: resolution: {integrity: sha512-lcYcMxX2PO9XMGvAJkJ3OsNMw+/7FKes7/hgerGUYWIoWu5j/+YQqcZr5JnPZWzOsEBgMbSbiSTn/dv/69Mkpw==} engines: {node: '>= 14.6'} @@ -6723,7 +6716,7 @@ snapshots: '@colors/colors@1.5.0': optional: true - '@cyclonedx/cdxgen@12.9.2(supports-color@7.2.0)': + '@cyclonedx/cdxgen@12.9.2(patch_hash=ea8b0d76a1f95182f5ca3612360ca194dd1d34acc7d11e9179f4a809c72868d6)(supports-color@7.2.0)': dependencies: '@babel/parser': 7.29.9 '@babel/traverse': 7.29.8(supports-color@7.2.0) @@ -6742,12 +6735,12 @@ snapshots: json-stringify-nice: 1.1.4 node-stream-zip: 1.16.0 npm-package-arg: 13.0.0 - packageurl-js: '@socketregistry/packageurl-js@1.7.0' + packageurl-js: '@socketregistry/packageurl-js@1.7.0(patch_hash=d7dfd1df1887f1b1c7f7f623f4030a1a0533dc7b0ec6aafaf1936fe3ad36864a)' parse-conflict-json: 5.0.1 read-package-json-fast: 5.0.0 semver: 7.7.2 ssri: 13.0.1 - tar: 7.5.23 + tar: 8.0.5 treeverse: 3.0.0 undici: 6.29.1 walk-up-path: 4.0.0 @@ -6959,10 +6952,6 @@ snapshots: wrap-ansi: 8.1.0 wrap-ansi-cjs: wrap-ansi@7.0.0 - '@isaacs/fs-minipass@4.0.1': - dependencies: - minipass: 7.1.3 - '@isaacs/nonrecursive-glob-match@1.1.0': {} '@isaacs/string-locale-compare@1.1.0': {} @@ -7138,7 +7127,7 @@ snapshots: npm-package-arg: 13.0.0 npm-pick-manifest: 12.0.0 npm-registry-fetch: 20.0.2(supports-color@7.2.0) - pacote: 22.0.1(supports-color@7.2.0) + pacote: 22.0.1(patch_hash=5a5c821294407145a5dc8f162997f8fe06b014ceb3d1047baa6b49dbd3e64199)(supports-color@7.2.0) parse-conflict-json: 6.0.0 proc-log: 7.0.0 proggy: 4.0.0 @@ -7239,7 +7228,7 @@ snapshots: dependencies: cacache: 21.0.2 json-parse-even-better-errors: 6.0.0 - pacote: 22.0.1(supports-color@7.2.0) + pacote: 22.0.1(patch_hash=5a5c821294407145a5dc8f162997f8fe06b014ceb3d1047baa6b49dbd3e64199)(supports-color@7.2.0) proc-log: 7.0.0 semver: 7.7.2 transitivePeerDependencies: @@ -7305,7 +7294,7 @@ snapshots: '@npmcli/node-gyp': 6.0.0 '@npmcli/package-json': 8.0.1 '@npmcli/promise-spawn': 10.0.1 - node-gyp: 13.1.0 + node-gyp: 13.1.0(patch_hash=367180c445d49be5842d1021bb00cbf76d9c711635eb01ab783999f37d044563) proc-log: 7.0.0 '@octokit/auth-token@6.0.0': {} @@ -7990,7 +7979,7 @@ snapshots: '@socketregistry/isarray@1.0.8': {} - '@socketregistry/packageurl-js@1.7.0': {} + '@socketregistry/packageurl-js@1.7.0(patch_hash=d7dfd1df1887f1b1c7f7f623f4030a1a0533dc7b0ec6aafaf1936fe3ad36864a)': {} '@socketregistry/path-parse@1.0.8': {} @@ -8008,7 +7997,7 @@ snapshots: pony-cause: 2.1.11 yaml: 2.8.1 - '@socketsecurity/sdk@4.3.0': {} + '@socketsecurity/sdk@4.3.0(patch_hash=ad4358a99d126acec0aee629ee0685022eb2efe69b4490f7fa6a003dd47a13b7)': {} '@socketsecurity/socket-patch-android-arm64@5.1.0': optional: true @@ -8754,8 +8743,6 @@ snapshots: undici: 6.29.1 whatwg-mimetype: 4.0.0 - chownr@3.0.0: {} - ci-info@4.3.1: {} clean-regexp@1.0.0: @@ -10381,7 +10368,7 @@ snapshots: node-fetch-native@1.6.7: {} - node-gyp@13.1.0: + node-gyp@13.1.0(patch_hash=367180c445d49be5842d1021bb00cbf76d9c711635eb01ab783999f37d044563): dependencies: env-paths: 2.2.1 exponential-backoff: 3.1.3 @@ -10389,7 +10376,7 @@ snapshots: nopt: 10.0.1 proc-log: 7.0.0 semver: 7.7.2 - tar: 7.5.23 + tar: 8.0.5 tinyglobby: 0.2.17 undici: 6.29.1 which: 7.0.0 @@ -10660,7 +10647,7 @@ snapshots: package-manager-detector@1.9.0: {} - pacote@22.0.1(supports-color@7.2.0): + pacote@22.0.1(patch_hash=5a5c821294407145a5dc8f162997f8fe06b014ceb3d1047baa6b49dbd3e64199)(supports-color@7.2.0): dependencies: '@gar/promise-retry': 1.0.3 '@npmcli/git': 8.0.0 @@ -10678,7 +10665,7 @@ snapshots: proc-log: 7.0.0 sigstore: 4.1.1(supports-color@7.2.0) ssri: 14.0.0 - tar: 7.5.23 + tar: 8.0.5 transitivePeerDependencies: - kerberos - supports-color @@ -11245,13 +11232,7 @@ snapshots: tapable@2.3.0: {} - tar@7.5.23: - dependencies: - '@isaacs/fs-minipass': 4.0.1 - chownr: 3.0.0 - minipass: 7.1.3 - minizlib: 3.1.0 - yallist: 5.0.0 + tar@8.0.5: {} taze@21.3.0: dependencies: @@ -11665,8 +11646,6 @@ snapshots: yallist@4.0.0: {} - yallist@5.0.0: {} - yaml@2.8.1: {} yargs-parser@21.1.1: {} diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 1a8ea92dc..a2620bc6f 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -12,6 +12,7 @@ minimumReleaseAgeExclude: - "@vitest/mocker@5.1.1" - "@vitest/spy@5.1.1" - vitest@5.1.1 + - tar@8.0.5 packageExtensions: "@actions/cache@6.3.0": dependencies: @@ -75,7 +76,7 @@ overrides: "smol-toml": "1.9.1" "source-map-js@>=1.0.0 <1.2.2": "1.2.3" "string_decoder": "0.10.31" - "tar": "7.5.23" + "tar": "8.0.5" "tiny-colors": "$yoctocolors-cjs" "tiny-updater": "3.5.3" "typedarray": "npm:@socketregistry/typedarray@^1.0.8" @@ -85,6 +86,11 @@ overrides: "yaml": "2.8.1" "yargs-parser": "$yargs-parser" patchedDependencies: + "@socketregistry/packageurl-js@1.7.0": "patches/@socketregistry__packageurl-js@1.7.0.patch" + "@socketsecurity/sdk@4.3.0": "patches/@socketsecurity__sdk@4.3.0.patch" + "@cyclonedx/cdxgen@12.9.2": "patches/@cyclonedx__cdxgen@12.9.2.patch" + "node-gyp@13.1.0": "patches/node-gyp@13.1.0.patch" + "pacote@22.0.1": "patches/pacote@22.0.1.patch" "@termless/core@0.11.0": "patches/@termless__core@0.11.0.patch" "graceful-fs@4.2.11": "patches/graceful-fs@4.2.11.patch" "string_decoder@0.10.31": "patches/string_decoder@0.10.31.patch" diff --git a/src/utils/coana/release.mts b/src/utils/coana/release.mts index 1dca8ff7a..3f71a3df2 100644 --- a/src/utils/coana/release.mts +++ b/src/utils/coana/release.mts @@ -13,11 +13,10 @@ */ import { createHash } from 'node:crypto' -import { Readable, Transform } from 'node:stream' -import { pipeline } from 'node:stream/promises' +import { Readable } from 'node:stream' import semver from 'semver' -import { x as extractTar } from 'tar' +import { extract as extractTar } from 'tar' import { getDefaultOrgSlug } from '../../commands/ci/fetch-default-org-slug.mts' import constants, { @@ -180,34 +179,29 @@ async function downloadComponent( } const hash = createHash('sha256') let received = 0 - await pipeline( - Readable.from(response.body), - new Transform({ - transform(chunk: Buffer, _encoding, callback) { - received += chunk.length - if (received > component.size) { - callback( - new Error( - `The Coana CLI tarball is larger than the expected ${component.size} bytes`, - ), - ) - return - } - hash.update(chunk) - callback(null, chunk) - }, - }), - extractTar({ - cwd: destDir, - filter: (_path, entry) => - 'type' in entry && - (entry.type === 'Directory' || entry.type === 'File'), - // Run as root, tar would otherwise give the shared cache the archive's - // owners. - preserveOwner: false, - strict: true, - }), - ) + const body = Readable.from(response.body) + async function* receiveArchive(): AsyncGenerator { + for await (const chunk of body as AsyncIterable) { + received += chunk.length + if (received > component.size) { + throw new Error( + `The Coana CLI tarball is larger than the expected ${component.size} bytes`, + ) + } + hash.update(chunk) + yield chunk + } + } + await extractTar({ + input: receiveArchive(), + cwd: destDir, + filter: (_path, entry) => + entry.type === 'Directory' || entry.type === 'File', + // Run as root, tar would otherwise give the shared cache the archive's + // owners. + preserveOwner: false, + strict: true, + }) const sha256 = hash.digest('hex') if (received !== component.size || sha256 !== component.sha256) { throw new Error( diff --git a/test/patches/packageurl-node18.test.mts b/test/patches/packageurl-node18.test.mts new file mode 100644 index 000000000..73e63fac4 --- /dev/null +++ b/test/patches/packageurl-node18.test.mts @@ -0,0 +1,36 @@ +import { spawnSync } from 'node:child_process' + +import { describe, expect, it } from 'vitest' + +describe('Node 18 dependency startup compatibility', () => { + it('loads the package URL and SDK dependencies without Array.prototype.toSorted', () => { + const result = spawnSync( + process.execPath, + [ + '--input-type=module', + '-e', + ` + Object.defineProperty(Array.prototype, 'toSorted', { + configurable: true, + value: undefined, + }) + const { PackageURL } = await import('@socketregistry/packageurl-js') + await import('@socketsecurity/sdk') + const purl = new PackageURL('npm', '', 'example', '1.0.0', { + z: 'last', + a: 'first', + }) + if (purl.toString() !== 'pkg:npm/example@1.0.0?a=first&z=last') { + throw new Error('PackageURL qualifiers were not sorted') + } + if (Array.prototype.toSorted !== undefined) { + throw new Error('The compatibility fallback modified the global') + } + `, + ], + { encoding: 'utf8' }, + ) + + expect(result.status, result.stderr).toBe(0) + }) +}) diff --git a/test/patches/pacote.test.mts b/test/patches/pacote.test.mts new file mode 100644 index 000000000..9bcc8ba4f --- /dev/null +++ b/test/patches/pacote.test.mts @@ -0,0 +1,38 @@ +import { mkdir, readFile, writeFile } from 'node:fs/promises' +import { createRequire } from 'node:module' +import path from 'node:path' + +import { expect, it } from 'vitest' + +import { withTmpDir } from '../../src/utils/fs.mts' + +const require = createRequire(import.meta.url) +const Arborist = require('@npmcli/arborist') +const pacote = createRequire(require.resolve('@npmcli/arborist'))('pacote') + +it('packs and extracts a local package without shipping its local patches', async () => { + await withTmpDir('socket-pacote-', async dir => { + const source = path.join(dir, 'source') + const archive = path.join(dir, 'package.tgz') + const extracted = path.join(dir, 'extracted') + const published = { name: 'fixture', version: '1.0.0', description: 'café' } + const local = { ...published, patchedDependencies: { dep: 'dep.patch' } } + await mkdir(source) + await writeFile(path.join(source, 'package.json'), JSON.stringify(local)) + await writeFile(path.join(source, 'index.js'), 'module.exports = 42\n') + + const options = { Arborist, cache: path.join(dir, 'cache'), offline: true } + await pacote.tarball.file(source, archive, options) + await pacote.extract(archive, extracted, options) + + expect( + JSON.parse(await readFile(path.join(extracted, 'package.json'), 'utf8')), + ).toEqual(published) + expect(await readFile(path.join(extracted, 'index.js'), 'utf8')).toBe( + 'module.exports = 42\n', + ) + expect( + JSON.parse(await readFile(path.join(source, 'package.json'), 'utf8')), + ).toEqual(local) + }) +})