-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Bugfix 3752 - Artifacts disappearing when missing integrity file #4185
Merged
arcanis
merged 7 commits into
yarnpkg:master
from
jamsinclair:fix-linking-artifacts-disappearing
Aug 17, 2017
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e231914
Add method to update force property
jamsinclair 6692e5e
Update install to force script installs when integrity file missing
jamsinclair 52bed25
Update add to force script installs when integrity file missing
jamsinclair aca24f2
Add test case for retaining artifacts after add when missing integrity
jamsinclair e87d463
Add test case for retaining artifacts after install when missing inte…
jamsinclair 06421f7
Add test fixture data for missing integrity tests
jamsinclair 41d28a9
Fix lint errors
jamsinclair File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -836,6 +836,37 @@ test.concurrent('should only refer to root to satisfy peer dependency', (): Prom | |
); | ||
}); | ||
|
||
test.concurrent('should retain build artifacts after add when missing integrity file', (): Promise<void> => { | ||
return buildRun( | ||
reporters.BufferReporter, | ||
fixturesLoc, | ||
async (args, flags, config, reporter): Promise<void> => { | ||
const lockfile = await createLockfile(config.cwd); | ||
|
||
const addA = new Add(args, flags, config, reporter, lockfile); | ||
await addA.init(); | ||
|
||
const expectedArtifacts = ['foo.txt']; | ||
const integrityLoc = path.join(config.cwd, 'node_modules', constants.INTEGRITY_FILENAME); | ||
|
||
const beforeIntegrity = await fs.readJson(integrityLoc); | ||
expect(beforeIntegrity.artifacts['[email protected]']).toEqual(expectedArtifacts); | ||
|
||
await fs.unlink(integrityLoc); | ||
|
||
const lockfileAfterPreviousAdd = await Lockfile.fromDirectory(config.cwd); | ||
const addB = new Add(['file:b'], flags, config, reporter, lockfileAfterPreviousAdd); | ||
await addB.init(); | ||
|
||
const afterIntegrity = await fs.readJson(integrityLoc); | ||
expect(afterIntegrity.artifacts['[email protected]']).toEqual(expectedArtifacts); | ||
}, | ||
['file:a'], | ||
{}, | ||
'retain-build-artifacts-missing-integrity', | ||
); | ||
}); | ||
|
||
test.concurrent('should retain build artifacts after add', (): Promise<void> => { | ||
return buildRun( | ||
reporters.BufferReporter, | ||
|
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 |
---|---|---|
|
@@ -195,6 +195,24 @@ test.concurrent('install should write and read integrity file based on lockfile | |
}); | ||
}); | ||
|
||
test.concurrent('install should retain artifacts when missing integrity file', (): Promise<void> => { | ||
return runInstall({}, 'install-should-retain-artifacts-when-missing-integrity', async (config, reporter) => { | ||
const expectedArtifacts = ['foo.txt']; | ||
const integrityLoc = path.join(config.cwd, 'node_modules', constants.INTEGRITY_FILENAME); | ||
|
||
const beforeIntegrity = await fs.readJson(integrityLoc); | ||
expect(beforeIntegrity.artifacts['[email protected]']).toEqual(expectedArtifacts); | ||
|
||
await fs.unlink(integrityLoc); | ||
|
||
const reinstall = new Install({}, config, reporter, await Lockfile.fromDirectory(config.cwd)); | ||
await reinstall.init(); | ||
|
||
const afterIntegrity = await fs.readJson(integrityLoc); | ||
expect(afterIntegrity.artifacts['[email protected]']).toEqual(expectedArtifacts); | ||
}); | ||
}); | ||
|
||
test.concurrent('install should not continue if integrity check passes', (): Promise<void> => { | ||
return runInstall({}, 'lockfile-stability', async (config, reporter) => { | ||
await fs.writeFile(path.join(config.cwd, 'node_modules', 'yarn.test'), 'YARN TEST'); | ||
|
1 change: 1 addition & 0 deletions
1
__tests__/fixtures/add/retain-build-artifacts-missing-integrity/a/install.js
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 @@ | ||
require('fs').writeFileSync('foo.txt', 'foobar'); |
7 changes: 7 additions & 0 deletions
7
__tests__/fixtures/add/retain-build-artifacts-missing-integrity/a/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,7 @@ | ||
{ | ||
"name": "a", | ||
"version": "0.0.0", | ||
"scripts": { | ||
"postinstall": "node install.js" | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
__tests__/fixtures/add/retain-build-artifacts-missing-integrity/b/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,4 @@ | ||
{ | ||
"name": "b", | ||
"version": "0.0.0" | ||
} |
1 change: 1 addition & 0 deletions
1
__tests__/fixtures/add/retain-build-artifacts-missing-integrity/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 @@ | ||
{} |
1 change: 1 addition & 0 deletions
1
...ts__/fixtures/install/install-should-retain-artifacts-when-missing-integrity/a/install.js
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 @@ | ||
require('fs').writeFileSync('foo.txt', 'foobar'); |
7 changes: 7 additions & 0 deletions
7
...__/fixtures/install/install-should-retain-artifacts-when-missing-integrity/a/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,7 @@ | ||
{ | ||
"name": "a", | ||
"version": "0.0.0", | ||
"scripts": { | ||
"postinstall": "node install.js" | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...ts__/fixtures/install/install-should-retain-artifacts-when-missing-integrity/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,5 @@ | ||
{ | ||
"dependencies": { | ||
"a": "file:a" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
__tests__/fixtures/install/install-should-retain-artifacts-when-missing-integrity/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,6 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
||
"a@file:a": | ||
version "0.0.0" |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need these setters and getters?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question.
The force property was formerly only set on construction of the
PackageInstallScripts
class:https://github.com/yarnpkg/yarn/blob/master/src/cli/commands/install.js#L178
When the install bailout method runs, the
PackageInstallScripts
instance has already been created. Adding the setter, allowing overrides, seemed like a simpler solution rather than reinstantiating. Happy to hear another approach.Edit: Oh, is it all good to override properties directly,
this.scripts.force = true
? In that case could definitely remove setter 😂There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a setter is fine, it's how we already do it (
setArtifacts
), and I have the feeling it makes the code a bit safer (because JS doesn't (yet) have private variables, setters are one of the only ways to clearly state that a variable might be updated from the outside).