-
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
Put build artifact tracking in integrity file #3224
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,9 +52,9 @@ test.concurrent('properly find and save build artifacts', async () => { | |
await runInstall({}, 'artifacts-finds-and-saves', async (config): Promise<void> => { | ||
const cacheFolder = path.join(config.cacheFolder, 'npm-dummy-0.0.0'); | ||
|
||
expect( | ||
(await fs.readJson(path.join(cacheFolder, constants.METADATA_FILENAME))).artifacts, | ||
).toEqual( | ||
const integrity = await fs.readJson(path.join(config.cwd, 'node_modules', constants.INTEGRITY_FILENAME)); | ||
|
||
expect(integrity.artifacts['[email protected]']).toEqual( | ||
['dummy', path.join('dummy', 'dummy.txt'), 'dummy.txt'], | ||
); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ import * as constants from './constants.js'; | |
import {registryNames} from './registries/index.js'; | ||
import * as fs from './util/fs.js'; | ||
import {sortAlpha, compareSortedArrays} from './util/misc.js'; | ||
|
||
import type {InstallArtifacts} from './package-install-scripts.js'; | ||
|
||
const invariant = require('invariant'); | ||
const path = require('path'); | ||
|
@@ -17,6 +17,7 @@ export type IntegrityCheckResult = { | |
integrityFileMissing: boolean, | ||
integrityMatches?: boolean, | ||
missingPatterns: Array<string>, | ||
artifacts?: ?InstallArtifacts, | ||
}; | ||
|
||
type IntegrityHashLocation = { | ||
|
@@ -33,6 +34,7 @@ type IntegrityFile = { | |
[key: string]: string | ||
}, | ||
files: Array<string>, | ||
artifacts: ?InstallArtifacts, | ||
} | ||
|
||
type IntegrityFlags = { | ||
|
@@ -125,6 +127,7 @@ export default class InstallationIntegrityChecker { | |
patterns: Array<string>, | ||
flags: IntegrityFlags, | ||
modulesFolder: string, | ||
artifacts?: InstallArtifacts, | ||
): Promise<IntegrityFile> { | ||
|
||
const result: IntegrityFile = { | ||
|
@@ -133,6 +136,7 @@ export default class InstallationIntegrityChecker { | |
topLevelPatters: [], | ||
lockfileEntries: {}, | ||
files: [], | ||
artifacts, | ||
}; | ||
|
||
result.topLevelPatters = patterns.sort(sortAlpha); | ||
|
@@ -247,6 +251,7 @@ export default class InstallationIntegrityChecker { | |
integrityFileMissing: false, | ||
integrityMatches, | ||
missingPatterns, | ||
artifacts: expected ? expected.artifacts : null, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Returning artifacts from check seems to break cohesion of the check function. Side note: my fault that check command has side effects (reporter logs), I plan to refactor it. |
||
}; | ||
} | ||
|
||
|
@@ -257,11 +262,12 @@ export default class InstallationIntegrityChecker { | |
patterns: Array<string>, | ||
lockfile: {[key: string]: LockManifest}, | ||
flags: IntegrityFlags, | ||
usedRegistries?: Set<RegistryNames>): Promise<void> { | ||
usedRegistries?: Set<RegistryNames>, | ||
artifacts: InstallArtifacts): Promise<void> { | ||
const loc = await this._getIntegrityHashLocation(usedRegistries); | ||
invariant(loc.locationPath, 'expected integrity hash location'); | ||
await fs.mkdirp(path.dirname(loc.locationPath)); | ||
const integrityFile = await this._generateIntegrityFile(lockfile, patterns, flags, loc.locationFolder); | ||
const integrityFile = await this._generateIntegrityFile(lockfile, patterns, flags, loc.locationFolder, artifacts); | ||
await fs.writeFile(loc.locationPath, JSON.stringify(integrityFile, null, 2)); | ||
} | ||
|
||
|
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.
Is it the right place?
bailout() function is overridden in add.js.
In the next couple of weeks I'd like to do integrity check earlier in install phase.