Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds an auto-add-integrity option #6255

Merged
merged 6 commits into from
Aug 10, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions __tests__/commands/install/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,15 @@ test('install should create integrity field if not present', () =>
// backwards-compatibility
}));

test('install should not create the integrity field if missing and auto-add-integrity is false', () =>
runInstall({}, 'install-update-auth-no-integrity-field-no-auto-add', async config => {
const lockFileContent = await fs.readFile(path.join(config.cwd, 'yarn.lock'));
const lockFileLines = explodeLockfile(lockFileContent);
expect(await fs.exists(path.join(config.cwd, 'node_modules', 'safe-buffer'))).toEqual(true);
expect(lockFileLines[2].indexOf('#893312af69b2123def71f57889001671eeb2c853')).toBeGreaterThan(0);
expect(lockFileLines.length).toEqual(3);
}));

test('install should ignore existing hash if integrity is present even if it fails to authenticate it', () =>
expect(runInstall({}, 'install-update-auth-bad-sha512-good-hash')).rejects.toMatchObject({
message: expect.stringContaining("computed integrity doesn't match our records"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
auto-add-integrity false
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "install-update-auth-no-integrity-field",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"safe-buffer": "^5.1.1"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


safe-buffer@^5.1.1:
version "5.1.1"
resolved "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz#893312af69b2123def71f57889001671eeb2c853"
5 changes: 5 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ export default class Config {
focus: boolean;
focusedWorkspaceName: string;

autoAddIntegrity: boolean;

/**
* Execute a promise produced by factory if it doesn't exist in our cache with
* the associated key.
Expand Down Expand Up @@ -368,6 +370,9 @@ export default class Config {
this.linkFileDependencies = Boolean(this.getOption('yarn-link-file-dependencies'));
this.packBuiltPackages = Boolean(this.getOption('experimental-pack-script-packages-in-mirror'));

const autoAddIntegrity = this.getOption('auto-add-integrity');
this.autoAddIntegrity = Boolean(typeof autoAddIntegrity !== 'undefined' ? autoAddIntegrity : true);

//init & create cacheFolder, tempFolder
this.cacheFolder = path.join(this._cacheRootFolder, 'v' + String(constants.CACHE_VERSION));
this.tempFolder = opts.tempFolder || path.join(this.cacheFolder, '.tmp');
Expand Down
4 changes: 2 additions & 2 deletions src/resolvers/registries/npm-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ export default class NpmResolver extends RegistryResolver {
}
}
}
if (shrunk && shrunk._remote && shrunk._remote.integrity) {
// if the integrity field does not exist, it needs to be created
if (shrunk && shrunk._remote && (shrunk._remote.integrity || !this.config.autoAddIntegrity)) {
// if the integrity field does not exist, it needs to be created unless the feature is disabled
return shrunk;
}

Expand Down