forked from yarnpkg/yarn
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(install): Add --update-checksums to cli install (yarnpkg#4860)
**Summary** Fixes yarnpkg#4817. When the `--update-checksums` flag is set, yarn would know to ignore a checksum mismatch between `yarn.lock` and the repository, and instead update the yarn.lock file with the proper checksum(s). **Test plan** Added new tests. To manually check this: 1. Change one or more of the package checksums in `yarn.lock` 2. Delete node_modules (optionally also run `yarn cache clean`) 3. Run `yarn` => checksum mismatch error will be received. 4. Run `yarn --update-checksums` => will install successfully and fix the damaged checksums in `yarn.lock`
- Loading branch information
1 parent
1146b25
commit 5e3552a
Showing
13 changed files
with
101 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -732,6 +732,21 @@ test.concurrent('install should add missing deps to yarn and mirror (PR import s | |
}); | ||
}); | ||
|
||
test.concurrent('install should update checksums in yarn.lock (--update-checksums)', (): Promise<void> => { | ||
const packageRealHash = '5faad9c2c07f60dd76770f71cf025b62a63cfd4e'; | ||
const packageCacheName = `npm-abab-1.0.4-${packageRealHash}`; | ||
return runInstall({updateChecksums: true}, 'install-update-checksums', async config => { | ||
const lockFileContent = await fs.readFile(path.join(config.cwd, 'yarn.lock')); | ||
const lockFileLines = explodeLockfile(lockFileContent); | ||
const packageHashInLockfile = lockFileLines[2].replace(/(^.*#)|("$)/g, ''); | ||
const installedPackageJson = path.resolve(config.cwd, 'node_modules', 'abab', 'package.json'); | ||
const cachePackageJson = path.resolve(config.cwd, '.yarn-cache/v1/', packageCacheName, 'package.json'); | ||
expect(packageHashInLockfile).toEqual(packageRealHash); | ||
expect(await fs.exists(installedPackageJson)).toBe(true); | ||
expect(await fs.exists(cachePackageJson)).toBe(true); | ||
}); | ||
}); | ||
|
||
test.concurrent('install should update a dependency to yarn and mirror (PR import scenario 2)', (): Promise<void> => { | ||
// [email protected] is gets updated to [email protected] via | ||
// a change in package.json, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
__tests__/fixtures/install/install-update-checksums/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "install-update-checksums", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"abab": "^1.0.4", | ||
"leftpad": "^0.0.1" | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
__tests__/fixtures/install/install-update-checksums/yarn.lock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
||
abab@^1.0.4: | ||
version "1.0.4" | ||
resolved "https://registry.yarnpkg.com/abab/-/abab-1.0.4.tgz#foo" | ||
|
||
leftpad@^0.0.1: | ||
version "0.0.1" | ||
resolved "https://registry.yarnpkg.com/leftpad/-/leftpad-0.0.1.tgz#86b1a4de4face180ac545a83f1503523d8fed115" |
Binary file added
BIN
+5.14 KB
__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/abab/-/abab-1.0.4.tgz.bin
Binary file not shown.
Binary file added
BIN
+2.22 KB
__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/leftpad/-/leftpad-0.0.1.tgz.bin
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters