Skip to content

Bugfix 3306: Check top level patterns during integrity check #3811

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

Merged
merged 1 commit into from Jul 5, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 10 additions & 0 deletions __tests__/commands/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,3 +340,13 @@ test.concurrent('should ignore bundled dependencies', async (): Promise<void> =>
},
);
});

test.concurrent('--integrity should throw an error if top level patterns do not match', async (): Promise<void> => {
let integrityError = false;
try {
await runCheck([], {integrity: true}, 'integrity-top-level-patters');
} catch (err) {
integrityError = true;
}
expect(integrityError).toEqual(true);
});
12 changes: 12 additions & 0 deletions __tests__/commands/install/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -892,3 +892,15 @@ test.skip('unbound transitive dependencies should not conflict with top level de
);
});
});

test.concurrent('top level patterns should match after install', (): Promise<void> => {
return runInstall({}, 'top-level-pattern-check', async (config, reporter) => {
let integrityError = false;
try {
await check(config, reporter, {integrity: true}, []);
} catch (err) {
integrityError = true;
}
expect(integrityError).toBe(false);
});
});

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"left-pad": "^1.1.3"
}
}
11 changes: 11 additions & 0 deletions __tests__/fixtures/check/integrity-top-level-patterns/yarn.lock
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


foo@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/foo/-/foo-1.0.0.tgz#943e0ec03df00ebeb6273a5b94b916ba54b47581"

left-pad@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/left-pad/-/left-pad-1.1.3.tgz#612f61c033f3a9e08e939f1caebeea41b6f3199a"

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"left-pad": "^1.1.3"
}
}
11 changes: 11 additions & 0 deletions __tests__/fixtures/install/top-level-pattern-check/yarn.lock
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


foo@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/foo/-/foo-1.0.0.tgz#943e0ec03df00ebeb6273a5b94b916ba54b47581"

left-pad@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/left-pad/-/left-pad-1.1.3.tgz#612f61c033f3a9e08e939f1caebeea41b6f3199a"
11 changes: 10 additions & 1 deletion src/cli/commands/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -682,12 +682,21 @@ export class Install {
}

const lockFileHasAllPatterns = patterns.every(p => this.lockfile.getLocked(p));
const lockfilePatternsMatch = Object.keys(this.lockfile.cache || {}).every(p => {
return lockfileBasedOnResolver[p];
});
const resolverPatternsAreSameAsInLockfile = Object.keys(lockfileBasedOnResolver).every(pattern => {
const manifest = this.lockfile.getLocked(pattern);
return manifest && manifest.resolved === lockfileBasedOnResolver[pattern].resolved;
});
// remove command is followed by install with force, lockfile will be rewritten in any case then
if (lockFileHasAllPatterns && resolverPatternsAreSameAsInLockfile && patterns.length && !this.flags.force) {
if (
lockFileHasAllPatterns &&
lockfilePatternsMatch &&
resolverPatternsAreSameAsInLockfile &&
patterns.length &&
!this.flags.force
) {
return;
}

Expand Down
16 changes: 15 additions & 1 deletion src/integrity-checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const integrityErrors = {
LOCKFILE_DONT_MATCH: 'integrityLockfilesDontMatch',
FLAGS_DONT_MATCH: 'integrityFlagsDontMatch',
LINKED_MODULES_DONT_MATCH: 'integrityCheckLinkedModulesDontMatch',
PATTERNS_DONT_MATCH: 'integrityPatternsDontMatch',
};

type IntegrityError = $Keys<typeof integrityErrors>;
Expand Down Expand Up @@ -200,6 +201,7 @@ export default class InstallationIntegrityChecker {
expected: ?IntegrityFile,
checkFiles: boolean,
locationFolder: string,
workspaceLayout: ?WorkspaceLayout,
): Promise<'OK' | IntegrityError> {
if (!expected) {
return 'EXPECTED_IS_NOT_A_JSON';
Expand All @@ -210,6 +212,12 @@ export default class InstallationIntegrityChecker {
if (!compareSortedArrays(actual.flags, expected.flags)) {
return 'FLAGS_DONT_MATCH';
}
const actualPatterns = actual.topLevelPatterns.filter(p => {
return !workspaceLayout || !workspaceLayout.getManifestByPattern(p);
});
if (!compareSortedArrays(actualPatterns, expected.topLevelPatterns || [])) {
return 'PATTERNS_DONT_MATCH';
}
for (const key of Object.keys(actual.lockfileEntries)) {
if (actual.lockfileEntries[key] !== expected.lockfileEntries[key]) {
return 'LOCKFILE_DONT_MATCH';
Expand Down Expand Up @@ -266,7 +274,13 @@ export default class InstallationIntegrityChecker {
await this._getModuleLocation(),
);
const expected = await this._getIntegrityFile(loc.locationPath);
const integrityMatches = await this._compareIntegrityFiles(actual, expected, flags.checkFiles, loc.locationFolder);
const integrityMatches = await this._compareIntegrityFiles(
actual,
expected,
flags.checkFiles,
loc.locationFolder,
workspaceLayout,
);

return {
integrityFileMissing: false,
Expand Down
1 change: 1 addition & 0 deletions src/reporters/lang/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ const messages = {
integrityFlagsDontMatch: "Integrity check: Flags don't match",
integrityLockfilesDontMatch: "Integrity check: Lock files don't match",
integrityFailedFilesMissing: 'Integrity check: Files are missing',
integrityPatternsDontMatch: "Integrity check: Top level patterns don't match",
packageNotInstalled: '$0 not installed',
optionalDepNotInstalled: 'Optional dependency $0 not installed',
packageWrongVersion: '$0 is wrong version: expected $1, got $2',
Expand Down