mirror of
https://github.com/pnpm/pnpm.git
synced 2026-04-04 23:34:58 -04:00
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 1bc6b5ac2c.
* Add changeset
---------
Co-authored-by: Zoltan Kochan <z@kochan.io>
This commit is contained in:
6
.changeset/nine-pillows-travel.md
Normal file
6
.changeset/nine-pillows-travel.md
Normal file
@@ -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).
|
||||
@@ -141,14 +141,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) {
|
||||
|
||||
@@ -761,45 +761,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 = tempy.directory()
|
||||
|
||||
{
|
||||
const { resolveFromNpm } = createResolveFromNpm({
|
||||
cacheDir,
|
||||
registries,
|
||||
})
|
||||
|
||||
await resolveFromNpm({ alias: 'is-positive', bareSpecifier: '1.0.0' }, {})
|
||||
}
|
||||
|
||||
// Wait for the cache file to be written
|
||||
await retryLoadJsonFile<any>(path.join(cacheDir, ABBREVIATED_META_DIR, 'registry.npmjs.org/is-positive.json')) // 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,
|
||||
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'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user