From 938ea1f18c22555d5b1d9577e397a13bbf8e53b6 Mon Sep 17 00:00:00 2001 From: Sam Chung Date: Mon, 12 Jan 2026 23:39:59 +1100 Subject: [PATCH] Revert "fix: try not to make network requests with prefer offline" (#10423) * Revert "fix: try not to make network requests with prefer offline (#10334)" This reverts commit 1bc6b5ac2c0808e836896b3e859bf239634ca1e6. * Add changeset --------- Co-authored-by: Zoltan Kochan --- .changeset/nine-pillows-travel.md | 6 ++++ .changeset/open-laws-pull.md | 6 ---- resolving/npm-resolver/src/pickPackage.ts | 5 ++- resolving/npm-resolver/test/index.ts | 41 ----------------------- 4 files changed, 8 insertions(+), 50 deletions(-) create mode 100644 .changeset/nine-pillows-travel.md delete mode 100644 .changeset/open-laws-pull.md diff --git a/.changeset/nine-pillows-travel.md b/.changeset/nine-pillows-travel.md new file mode 100644 index 0000000000..3f2d657a80 --- /dev/null +++ b/.changeset/nine-pillows-travel.md @@ -0,0 +1,6 @@ +--- +"@pnpm/npm-resolver": patch +pnpm: patch +--- + +Revert Try to avoid making network calls with preferOffline [#10334](https://github.com/pnpm/pnpm/pull/10334). diff --git a/.changeset/open-laws-pull.md b/.changeset/open-laws-pull.md deleted file mode 100644 index ce96e0a5c6..0000000000 --- a/.changeset/open-laws-pull.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -"@pnpm/npm-resolver": patch -pnpm: patch ---- - -Try to avoid making network calls with preferOffline [#10334](https://github.com/pnpm/pnpm/pull/10334). diff --git a/resolving/npm-resolver/src/pickPackage.ts b/resolving/npm-resolver/src/pickPackage.ts index 7946436ecc..c306e9fd31 100644 --- a/resolving/npm-resolver/src/pickPackage.ts +++ b/resolving/npm-resolver/src/pickPackage.ts @@ -142,14 +142,13 @@ export async function pickPackage ( if (ctx.offline === true || ctx.preferOffline === true || opts.pickLowestVersion) { metaCachedInStore = await limit(async () => loadMeta(pkgMirror)) - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - if (ctx.offline || ctx.preferOffline) { + if (ctx.offline) { if (metaCachedInStore != null) return { meta: metaCachedInStore, pickedPackage: _pickPackageFromMeta(metaCachedInStore), } - if (ctx.offline) throw new PnpmError('NO_OFFLINE_META', `Failed to resolve ${toRaw(spec)} in package mirror ${pkgMirror}`) + throw new PnpmError('NO_OFFLINE_META', `Failed to resolve ${toRaw(spec)} in package mirror ${pkgMirror}`) } if (metaCachedInStore != null) { diff --git a/resolving/npm-resolver/test/index.ts b/resolving/npm-resolver/test/index.ts index 25a3135ff9..5b6dde7999 100644 --- a/resolving/npm-resolver/test/index.ts +++ b/resolving/npm-resolver/test/index.ts @@ -797,47 +797,6 @@ test('when prefer offline is used, meta from store is used, where latest might b nock.cleanAll() }) -test('prefer offline does not make network requests when cached metadata exists', async () => { - nock(registries.default) - .get('/is-positive') - .reply(200, isPositiveMeta) - - const cacheDir = temporaryDirectory() - - { - const { resolveFromNpm } = createResolveFromNpm({ - storeDir: temporaryDirectory(), - cacheDir, - registries, - }) - - await resolveFromNpm({ alias: 'is-positive', bareSpecifier: '1.0.0' }, {}) - } - - // Wait for the cache file to be written - await retryLoadJsonFile(path.join(cacheDir, ABBREVIATED_META_DIR, 'registry.npmjs.org/is-positive.v8')) // eslint-disable-line @typescript-eslint/no-explicit-any - - // Clear all mocks - if a network request is made, nock will throw an error - nock.cleanAll() - nock.disableNetConnect() - - { - const { resolveFromNpm } = createResolveFromNpm({ - preferOffline: true, - storeDir: temporaryDirectory(), - cacheDir, - registries, - }) - - const resolveResult = await resolveFromNpm({ alias: 'is-positive', bareSpecifier: '1.0.0' }, {}) - expect(resolveResult!.id).toBe('is-positive@1.0.0') - expect(resolveResult!.resolution).toStrictEqual({ - integrity: 'sha512-9cI+DmhNhA8ioT/3EJFnt0s1yehnAECyIOXdT+2uQGzcEEBaj8oNmVWj33+ZjPndMIFRQh8JeJlEu1uv5/J7pQ==', - tarball: 'https://registry.npmjs.org/is-positive/-/is-positive-1.0.0.tgz', - }) - } -}) - test('error is thrown when package is not found in the registry', async () => { const notExistingPackage = 'foo'