Skip to content

Commit 6bfaac3

Browse files
jamsinclairarcanis
authored andcommitted
Bugfix 3752 - Artifacts disappearing when missing integrity file (#4185)
* Add method to update force property * Update install to force script installs when integrity file missing * Update add to force script installs when integrity file missing * Add test case for retaining artifacts after add when missing integrity * Add test case for retaining artifacts after install when missing integrity * Add test fixture data for missing integrity tests * Fix lint errors
1 parent 034f461 commit 6bfaac3

File tree

13 files changed

+107
-2
lines changed

13 files changed

+107
-2
lines changed

__tests__/commands/add.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,37 @@ test.concurrent('should only refer to root to satisfy peer dependency', (): Prom
848848
);
849849
});
850850

851+
test.concurrent('should retain build artifacts after add when missing integrity file', (): Promise<void> => {
852+
return buildRun(
853+
reporters.BufferReporter,
854+
fixturesLoc,
855+
async (args, flags, config, reporter): Promise<void> => {
856+
const lockfile = await createLockfile(config.cwd);
857+
858+
const addA = new Add(args, flags, config, reporter, lockfile);
859+
await addA.init();
860+
861+
const expectedArtifacts = ['foo.txt'];
862+
const integrityLoc = path.join(config.cwd, 'node_modules', constants.INTEGRITY_FILENAME);
863+
864+
const beforeIntegrity = await fs.readJson(integrityLoc);
865+
expect(beforeIntegrity.artifacts['[email protected]']).toEqual(expectedArtifacts);
866+
867+
await fs.unlink(integrityLoc);
868+
869+
const lockfileAfterPreviousAdd = await Lockfile.fromDirectory(config.cwd);
870+
const addB = new Add(['file:b'], flags, config, reporter, lockfileAfterPreviousAdd);
871+
await addB.init();
872+
873+
const afterIntegrity = await fs.readJson(integrityLoc);
874+
expect(afterIntegrity.artifacts['[email protected]']).toEqual(expectedArtifacts);
875+
},
876+
['file:a'],
877+
{},
878+
'retain-build-artifacts-missing-integrity',
879+
);
880+
});
881+
851882
test.concurrent('should retain build artifacts after add', (): Promise<void> => {
852883
return buildRun(
853884
reporters.BufferReporter,

__tests__/commands/install/lockfiles.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,24 @@ test.concurrent('install should write and read integrity file based on lockfile
195195
});
196196
});
197197

198+
test.concurrent('install should retain artifacts when missing integrity file', (): Promise<void> => {
199+
return runInstall({}, 'install-should-retain-artifacts-when-missing-integrity', async (config, reporter) => {
200+
const expectedArtifacts = ['foo.txt'];
201+
const integrityLoc = path.join(config.cwd, 'node_modules', constants.INTEGRITY_FILENAME);
202+
203+
const beforeIntegrity = await fs.readJson(integrityLoc);
204+
expect(beforeIntegrity.artifacts['[email protected]']).toEqual(expectedArtifacts);
205+
206+
await fs.unlink(integrityLoc);
207+
208+
const reinstall = new Install({}, config, reporter, await Lockfile.fromDirectory(config.cwd));
209+
await reinstall.init();
210+
211+
const afterIntegrity = await fs.readJson(integrityLoc);
212+
expect(afterIntegrity.artifacts['[email protected]']).toEqual(expectedArtifacts);
213+
});
214+
});
215+
198216
test.concurrent('install should not continue if integrity check passes', (): Promise<void> => {
199217
return runInstall({}, 'lockfile-stability', async (config, reporter) => {
200218
await fs.writeFile(path.join(config.cwd, 'node_modules', 'yarn.test'), 'YARN TEST');
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require('fs').writeFileSync('foo.txt', 'foobar');
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "a",
3+
"version": "0.0.0",
4+
"scripts": {
5+
"postinstall": "node install.js"
6+
}
7+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "b",
3+
"version": "0.0.0"
4+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require('fs').writeFileSync('foo.txt', 'foobar');
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "a",
3+
"version": "0.0.0",
4+
"scripts": {
5+
"postinstall": "node install.js"
6+
}
7+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dependencies": {
3+
"a": "file:a"
4+
}
5+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
"a@file:a":
6+
version "0.0.0"

0 commit comments

Comments
 (0)