From 3843224a555d52b1a18ebbff11faf978ec239934 Mon Sep 17 00:00:00 2001 From: Lorenz Leutgeb Date: Mon, 25 Sep 2023 22:55:34 +0200 Subject: [PATCH 1/2] prefetch-yarn-deps: Fix parsing of scoped packages --- pkgs/build-support/node/fetch-yarn-deps/index.js | 13 ++++++++++--- .../node/fetch-yarn-deps/tests/default.nix | 4 ++++ .../node/fetch-yarn-deps/tests/file.lock | 9 +++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 pkgs/build-support/node/fetch-yarn-deps/tests/file.lock diff --git a/pkgs/build-support/node/fetch-yarn-deps/index.js b/pkgs/build-support/node/fetch-yarn-deps/index.js index de2a09ee9041..8dde3ef39085 100755 --- a/pkgs/build-support/node/fetch-yarn-deps/index.js +++ b/pkgs/build-support/node/fetch-yarn-deps/index.js @@ -88,10 +88,17 @@ const isGitUrl = pattern => { } const downloadPkg = (pkg, verbose) => { - const [ name, spec ] = pkg.key.split('@', 2); - if (spec.startsWith('file:')) { - console.info(`ignoring relative file:path dependency "${spec}"`) + const fileMarker = '@file:' + const split = pkg.key.split(fileMarker) + if (split.length == 2) { + console.info(`ignoring lockfile entry "${split[0]}" which points at path "${split[1]}"`) return + } else if (split.length > 2) { + throw new Error(`The lockfile entry key "${pkg.key}" contains "${fileMarker}" more than once. Processing is not implemented.`) + } + + if (pkg.resolved === undefined) { + throw new Error(`The lockfile entry with key "${pkg.key}" cannot be downloaded because it is missing the "resolved" attribute, which should contain the URL to download from. The lockfile might be invalid.`) } const [ url, hash ] = pkg.resolved.split('#') diff --git a/pkgs/build-support/node/fetch-yarn-deps/tests/default.nix b/pkgs/build-support/node/fetch-yarn-deps/tests/default.nix index 8ffe103a9548..8057d05ba72c 100644 --- a/pkgs/build-support/node/fetch-yarn-deps/tests/default.nix +++ b/pkgs/build-support/node/fetch-yarn-deps/tests/default.nix @@ -1,6 +1,10 @@ { testers, fetchYarnDeps, ... }: { + file = testers.invalidateFetcherByDrvHash fetchYarnDeps { + yarnLock = ./file.lock; + sha256 = "sha256-BPuyQVCbdpFL/iRhmarwWAmWO2NodlVCOY9JU+4pfa4="; + }; simple = testers.invalidateFetcherByDrvHash fetchYarnDeps { yarnLock = ./simple.lock; sha256 = "sha256-FRrt8BixleILmFB2ZV8RgPNLqgS+dlH5nWoPgeaaNQ8="; diff --git a/pkgs/build-support/node/fetch-yarn-deps/tests/file.lock b/pkgs/build-support/node/fetch-yarn-deps/tests/file.lock new file mode 100644 index 000000000000..4881d83a7de9 --- /dev/null +++ b/pkgs/build-support/node/fetch-yarn-deps/tests/file.lock @@ -0,0 +1,9 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +"@org/somepack@file:vendor/orgpacks/somepack/assets": + version "1.0.0" + +"otherpack@file:vendor/otherpack": + version "1.0.0" From 29cf6a0422326ba21b5be3620b61936a643ecd31 Mon Sep 17 00:00:00 2001 From: Lorenz Leutgeb Date: Tue, 26 Sep 2023 10:01:35 +0200 Subject: [PATCH 2/2] prefetch-yarn-deps: Fix access to `.resolved` ... and simplify `prefetchYarnDeps` --- pkgs/build-support/node/fetch-yarn-deps/index.js | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/pkgs/build-support/node/fetch-yarn-deps/index.js b/pkgs/build-support/node/fetch-yarn-deps/index.js index 8dde3ef39085..e60fdeb54330 100755 --- a/pkgs/build-support/node/fetch-yarn-deps/index.js +++ b/pkgs/build-support/node/fetch-yarn-deps/index.js @@ -140,19 +140,10 @@ const performParallel = tasks => { const prefetchYarnDeps = async (lockContents, verbose) => { const lockData = lockfile.parse(lockContents) - const tasks = Object.values( + await performParallel( Object.entries(lockData.object) - .map(([key, value]) => { - return { key, ...value } - }) - .reduce((out, pkg) => { - out[pkg.resolved] = pkg - return out - }, {}) + .map(([key, value]) => () => downloadPkg({ key, ...value }, verbose)) ) - .map(pkg => () => downloadPkg(pkg, verbose)) - - await performParallel(tasks) await fs.promises.writeFile('yarn.lock', lockContents) if (verbose) console.log('Done') }