-
Notifications
You must be signed in to change notification settings - Fork 3.7k
fix: refactor node.ideallyInert to node.inert #8602
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 | ||||
---|---|---|---|---|---|---|
|
@@ -7,7 +7,6 @@ const pacote = require('pacote') | |||||
const promiseAllRejectLate = require('promise-all-reject-late') | ||||||
const runScript = require('@npmcli/run-script') | ||||||
const { callLimit: promiseCallLimit } = require('promise-call-limit') | ||||||
const { checkEngine, checkPlatform } = require('npm-install-checks') | ||||||
const { depth: dfwalk } = require('treeverse') | ||||||
const { dirname, resolve, relative, join } = require('node:path') | ||||||
const { log, time } = require('proc-log') | ||||||
|
@@ -74,7 +73,6 @@ module.exports = cls => class Reifier extends cls { | |||||
#dryRun | ||||||
#nmValidated = new Set() | ||||||
#omit | ||||||
#omitted | ||||||
#retiredPaths = {} | ||||||
#retiredUnchanged = {} | ||||||
#savePrefix | ||||||
|
@@ -99,7 +97,6 @@ module.exports = cls => class Reifier extends cls { | |||||
} | ||||||
|
||||||
this.#omit = new Set(options.omit) | ||||||
this.#omitted = new Set() | ||||||
|
||||||
// start tracker block | ||||||
this.addTracker('reify') | ||||||
|
@@ -132,15 +129,17 @@ module.exports = cls => class Reifier extends cls { | |||||
this.idealTree = oldTree | ||||||
} | ||||||
await this[_saveIdealTree](options) | ||||||
// clean omitted | ||||||
for (const node of this.#omitted) { | ||||||
node.parent = null | ||||||
// clean inert | ||||||
for (const node of this.idealTree.inventory.values()) { | ||||||
if (node.inert) { | ||||||
node.parent = null | ||||||
} | ||||||
} | ||||||
// clean up any trash that is still in the tree | ||||||
for (const path of this[_trashList]) { | ||||||
const loc = relpath(this.idealTree.realpath, path) | ||||||
const node = this.idealTree.inventory.get(loc) | ||||||
if (node && node.root === this.idealTree && !node.ideallyInert) { | ||||||
if (node && node.root === this.idealTree) { | ||||||
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.
Suggested change
|
||||||
node.parent = null | ||||||
} | ||||||
} | ||||||
|
@@ -228,18 +227,6 @@ module.exports = cls => class Reifier extends cls { | |||||
this.idealTree.meta.hiddenLockfile = true | ||||||
this.idealTree.meta.lockfileVersion = defaultLockfileVersion | ||||||
|
||||||
// Preserve inertness for failed stuff. | ||||||
if (this.actualTree) { | ||||||
for (const [loc, actual] of this.actualTree.inventory.entries()) { | ||||||
if (actual.ideallyInert) { | ||||||
const ideal = this.idealTree.inventory.get(loc) | ||||||
if (ideal) { | ||||||
ideal.ideallyInert = true | ||||||
} | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
this.actualTree = this.idealTree | ||||||
this.idealTree = null | ||||||
|
||||||
|
@@ -465,7 +452,6 @@ module.exports = cls => class Reifier extends cls { | |||||
// and ideal trees. | ||||||
this.diff = Diff.calculate({ | ||||||
omit: this.#omit, | ||||||
omitted: this.#omitted, | ||||||
shrinkwrapInflated: this.#shrinkwrapInflated, | ||||||
filterNodes, | ||||||
actual: this.actualTree, | ||||||
|
@@ -566,9 +552,6 @@ module.exports = cls => class Reifier extends cls { | |||||
// retire the same path at the same time. | ||||||
const dirsChecked = new Set() | ||||||
return promiseAllRejectLate(leaves.map(async node => { | ||||||
if (node.ideallyInert) { | ||||||
return | ||||||
} | ||||||
for (const d of walkUp(node.path)) { | ||||||
if (d === node.top.path) { | ||||||
break | ||||||
|
@@ -662,18 +645,7 @@ module.exports = cls => class Reifier extends cls { | |||||
const timeEnd = time.start(`reifyNode:${node.location}`) | ||||||
this.addTracker('reify', node.name, node.location) | ||||||
|
||||||
const { npmVersion, nodeVersion, cpu, os, libc } = this.options | ||||||
const p = Promise.resolve().then(async () => { | ||||||
// when we reify an optional node, check the engine and platform | ||||||
// first. be sure to ignore the --force and --engine-strict flags, | ||||||
// since we always want to skip any optional packages we can't install. | ||||||
// these checks throwing will result in a rollback and removal | ||||||
// of the mismatches | ||||||
// eslint-disable-next-line promise/always-return | ||||||
if (node.optional) { | ||||||
checkEngine(node.package, npmVersion, nodeVersion, false) | ||||||
checkPlatform(node.package, false, { cpu, os, libc }) | ||||||
} | ||||||
await this[_checkBins](node) | ||||||
await this.#extractOrLink(node) | ||||||
const { _id, deprecated } = node.package | ||||||
|
@@ -707,10 +679,6 @@ module.exports = cls => class Reifier extends cls { | |||||
} | ||||||
|
||||||
async #extractOrLink (node) { | ||||||
if (node.ideallyInert) { | ||||||
return | ||||||
} | ||||||
|
||||||
const nm = resolve(node.parent.path, 'node_modules') | ||||||
await this.#validateNodeModules(nm) | ||||||
|
||||||
|
@@ -791,9 +759,9 @@ module.exports = cls => class Reifier extends cls { | |||||
[_handleOptionalFailure] (node, p) { | ||||||
return (node.optional ? p.catch(() => { | ||||||
const set = optionalSet(node) | ||||||
for (node of set) { | ||||||
for (const node of set) { | ||||||
log.verbose('reify', 'failed optional dependency', node.path) | ||||||
node.ideallyInert = true | ||||||
node.inert = true | ||||||
this[_addNodeToTrashList](node) | ||||||
} | ||||||
}) : p).then(() => node) | ||||||
|
@@ -1165,9 +1133,6 @@ module.exports = cls => class Reifier extends cls { | |||||
|
||||||
this.#retiredUnchanged[retireFolder] = [] | ||||||
return promiseAllRejectLate(diff.unchanged.map(node => { | ||||||
if (node.ideallyInert) { | ||||||
return | ||||||
} | ||||||
// no need to roll back links, since we'll just delete them anyway | ||||||
if (node.isLink) { | ||||||
return mkdir(dirname(node.path), { recursive: true, force: true }) | ||||||
|
@@ -1247,7 +1212,7 @@ module.exports = cls => class Reifier extends cls { | |||||
// skip links that only live within node_modules as they are most | ||||||
// likely managed by packages we installed, we only want to rebuild | ||||||
// unchanged links we directly manage | ||||||
const linkedFromRoot = (node.parent === tree && !node.ideallyInert) || node.target.fsTop === tree | ||||||
const linkedFromRoot = (node.parent === tree && !node.inert) || node.target.fsTop === tree | ||||||
if (node.isLink && linkedFromRoot) { | ||||||
nodes.push(node) | ||||||
} | ||||||
|
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
We normally do not allow changes to the
package-lock.json
file. It makes sense that this change is here now given that this is an optional dep ofchokidar
.In order that we don't complicate things I removed the
package-lock.json
from my local copy of this branch and rannpm run resetdeps
to verify that what's in here now is valid. The package lock was identical, so we're good to allow it in this PR as changed.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 only updated this after CI failed complaining about mismatched package lock. This is the result of fixing missing optional deps here: https://github.com/npm/cli/pull/8602/files#diff-02626074e1a4a170693607e4a3a69dfc08ee52067734717833b22cf162923e07R354