Skip to content

Commit b813ebe

Browse files
authored
Don't compute integrity when network restricted (#6248)
* Fixes git repositories w/ --offline * test(integrity): do not update in offline mode
1 parent 753bcac commit b813ebe

File tree

7 files changed

+25
-2
lines changed

7 files changed

+25
-2
lines changed

__tests__/commands/_helpers.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export function makeConfigFromDirectory(cwd: string, reporter: Reporter, flags:
9191
prefix: flags.prefix,
9292
production: flags.production,
9393
updateChecksums: !!flags.updateChecksums,
94+
offline: !!flags.offline,
9495
focus: !!flags.focus,
9596
enableDefaultRc: !flags.noDefaultRc,
9697
extraneousYarnrcFiles: flags.useYarnrc,

__tests__/commands/install/integration.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,11 @@ test('install should create integrity field if not present', () =>
738738
// backwards-compatibility
739739
}));
740740

741+
test('install should not create integrity field if not present and in offline mode', () =>
742+
runInstall({offline: true}, 'install-update-auth-no-offline-integrity', async config => {
743+
expect(await fs.exists(path.join(config.cwd, 'node_modules', 'abab'))).toEqual(true);
744+
}));
745+
741746
test('install should ignore existing hash if integrity is present even if it fails to authenticate it', () =>
742747
expect(runInstall({}, 'install-update-auth-bad-sha512-good-hash')).rejects.toMatchObject({
743748
message: expect.stringContaining("computed integrity doesn't match our records"),
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
yarn-offline-mirror "./offline-mirror"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "install-update-auth-no-offline-integrity",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"license": "MIT",
6+
"dependencies": {
7+
"abab": "^2.0.0"
8+
}
9+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
abab@^2.0.0:
6+
version "2.0.0"
7+
resolved "https://registry.yarnpkg.com/abab/-/abab-2.0.0.tgz#aba0ab4c5eee2d4c79d3487d85450fb2376ebb0f"

src/resolvers/registries/npm-resolver.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ export default class NpmResolver extends RegistryResolver {
207207
}
208208
}
209209
}
210-
if (shrunk && shrunk._remote && shrunk._remote.integrity) {
211-
// if the integrity field does not exist, it needs to be created
210+
if (shrunk && shrunk._remote && (shrunk._remote.integrity || this.config.offline)) {
211+
// if the integrity field does not exist and we're not network-restricted, it needs to be created
212212
return shrunk;
213213
}
214214

0 commit comments

Comments
 (0)