From 9bb95a1b2453c3db0d39c20ffaebf79ca622e033 Mon Sep 17 00:00:00 2001 From: siemhesda <143130929+siemhesda@users.noreply.github.com> Date: Tue, 26 Sep 2023 10:02:06 -0700 Subject: [PATCH 1/8] fix(9arborist)0:; crash on conflict #5151 --- workspaces/arborist/lib/arborist/build-ideal-tree.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/workspaces/arborist/lib/arborist/build-ideal-tree.js b/workspaces/arborist/lib/arborist/build-ideal-tree.js index d04ddf27b6965..a0bdc7d94ad88 100644 --- a/workspaces/arborist/lib/arborist/build-ideal-tree.js +++ b/workspaces/arborist/lib/arborist/build-ideal-tree.js @@ -1299,7 +1299,7 @@ This is a one-time fix-up, please be patient... continue } - const parentEdge = node.parent.edgesOut.get(edge.name) + const parentEdge = node.parent.edgesOut.get(edge.name) || node.parent?.edgeOut?.get(edge.name) const { isProjectRoot, isWorkspace } = node.parent.sourceReference const isMine = isProjectRoot || isWorkspace const conflictOK = this[_force] || !isMine && !this.#strictPeerDeps From fb057db94d5e21578533712a8b0f4ae0887704d5 Mon Sep 17 00:00:00 2001 From: siemhesda <143130929+siemhesda@users.noreply.github.com> Date: Fri, 29 Sep 2023 11:36:50 -0700 Subject: [PATCH 2/8] fix(arborist):; add optional chains to clear bugs --- workspaces/arborist/lib/arborist/build-ideal-tree.js | 4 ++-- workspaces/arborist/lib/place-dep.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/workspaces/arborist/lib/arborist/build-ideal-tree.js b/workspaces/arborist/lib/arborist/build-ideal-tree.js index a0bdc7d94ad88..124a96daf237f 100644 --- a/workspaces/arborist/lib/arborist/build-ideal-tree.js +++ b/workspaces/arborist/lib/arborist/build-ideal-tree.js @@ -1299,8 +1299,8 @@ This is a one-time fix-up, please be patient... continue } - const parentEdge = node.parent.edgesOut.get(edge.name) || node.parent?.edgeOut?.get(edge.name) - const { isProjectRoot, isWorkspace } = node.parent.sourceReference + const parentEdge = node.parent?.edgesOut.get(edge.name) + const { isProjectRoot, isWorkspace } = node.parent?.sourceReference || {} const isMine = isProjectRoot || isWorkspace const conflictOK = this[_force] || !isMine && !this.#strictPeerDeps diff --git a/workspaces/arborist/lib/place-dep.js b/workspaces/arborist/lib/place-dep.js index e757d0c38a6d7..a8ffd04426d4a 100644 --- a/workspaces/arborist/lib/place-dep.js +++ b/workspaces/arborist/lib/place-dep.js @@ -296,7 +296,7 @@ class PlaceDep { continue } - const peer = virtualRoot.children.get(peerEdge.name) + const peer = virtualRoot?.children.get(peerEdge.name) // Note: if the virtualRoot *doesn't* have the peer, then that means // it's an optional peer dep. If it's not being properly met (ie, From 96b07e3dbbd7e933486d8708bc3ccf993dfb7d11 Mon Sep 17 00:00:00 2001 From: siemhesda <143130929+siemhesda@users.noreply.github.com> Date: Fri, 29 Sep 2023 12:19:06 -0700 Subject: [PATCH 3/8] test(arborist): run tests --- .../test/arborist/rebuild.js.test.cjs | 24 +++++++++++++++---- .../tap-snapshots/test/shrinkwrap.js.test.cjs | 24 ------------------- 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/workspaces/arborist/tap-snapshots/test/arborist/rebuild.js.test.cjs b/workspaces/arborist/tap-snapshots/test/arborist/rebuild.js.test.cjs index 8cd2cfd322cc0..404480f248c19 100644 --- a/workspaces/arborist/tap-snapshots/test/arborist/rebuild.js.test.cjs +++ b/workspaces/arborist/tap-snapshots/test/arborist/rebuild.js.test.cjs @@ -26,7 +26,11 @@ Array [ "version": "1.0.0", }, "signal": null, - "stderr": "stderr", + "stderr": String( + Debugger attached. + stderr + Waiting for the debugger to disconnect... + ), "stdout": "npm_package_dev", }, Object { @@ -42,7 +46,11 @@ Array [ "version": "1.0.0", }, "signal": null, - "stderr": "stderr", + "stderr": String( + Debugger attached. + stderr + Waiting for the debugger to disconnect... + ), "stdout": "npm_package_dev_optional", }, Object { @@ -58,7 +66,11 @@ Array [ "version": "1.0.0", }, "signal": null, - "stderr": "stderr", + "stderr": String( + Debugger attached. + stderr + Waiting for the debugger to disconnect... + ), "stdout": String( npm_package_dev npm_package_optional @@ -80,7 +92,11 @@ Array [ "version": "1.0.0", }, "signal": null, - "stderr": "stderr", + "stderr": String( + Debugger attached. + stderr + Waiting for the debugger to disconnect... + ), "stdout": "npm_package_optional", }, ] diff --git a/workspaces/arborist/tap-snapshots/test/shrinkwrap.js.test.cjs b/workspaces/arborist/tap-snapshots/test/shrinkwrap.js.test.cjs index 1b5a393f8846d..a41c41a7b90e6 100644 --- a/workspaces/arborist/tap-snapshots/test/shrinkwrap.js.test.cjs +++ b/workspaces/arborist/tap-snapshots/test/shrinkwrap.js.test.cjs @@ -2652,30 +2652,6 @@ Object { "node_modules/foo/node_modules/glob": Object { "version": "4.0.5", }, - "node_modules/foo/node_modules/glob/node_modules/graceful-fs": Object { - "extraneous": true, - "version": "3.0.2", - }, - "node_modules/foo/node_modules/glob/node_modules/inherits": Object { - "extraneous": true, - "version": "2.0.1", - }, - "node_modules/foo/node_modules/glob/node_modules/minimatch": Object { - "extraneous": true, - "version": "1.0.0", - }, - "node_modules/foo/node_modules/glob/node_modules/minimatch/node_modules/lru-cache": Object { - "extraneous": true, - "version": "2.5.0", - }, - "node_modules/foo/node_modules/glob/node_modules/minimatch/node_modules/sigmund": Object { - "extraneous": true, - "version": "1.0.0", - }, - "node_modules/foo/node_modules/glob/node_modules/once": Object { - "extraneous": true, - "version": "1.3.0", - }, "node_modules/foo/node_modules/selflink": Object { "link": true, "resolved": "", From 6fe272f683ab32585e223c94d2b64e90764423fc Mon Sep 17 00:00:00 2001 From: siemhesda <143130929+siemhesda@users.noreply.github.com> Date: Tue, 3 Oct 2023 11:04:33 -0700 Subject: [PATCH 4/8] fix(arborist): remove trailing space . revert shrinkwrap file --- .../arborist/lib/arborist/build-ideal-tree.js | 2 +- .../tap-snapshots/test/shrinkwrap.js.test.cjs | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/workspaces/arborist/lib/arborist/build-ideal-tree.js b/workspaces/arborist/lib/arborist/build-ideal-tree.js index 124a96daf237f..6f10d85c2f2a9 100644 --- a/workspaces/arborist/lib/arborist/build-ideal-tree.js +++ b/workspaces/arborist/lib/arborist/build-ideal-tree.js @@ -1299,7 +1299,7 @@ This is a one-time fix-up, please be patient... continue } - const parentEdge = node.parent?.edgesOut.get(edge.name) + const parentEdge = node.parent?.edgesOut.get(edge.name) const { isProjectRoot, isWorkspace } = node.parent?.sourceReference || {} const isMine = isProjectRoot || isWorkspace const conflictOK = this[_force] || !isMine && !this.#strictPeerDeps diff --git a/workspaces/arborist/tap-snapshots/test/shrinkwrap.js.test.cjs b/workspaces/arborist/tap-snapshots/test/shrinkwrap.js.test.cjs index a41c41a7b90e6..1b5a393f8846d 100644 --- a/workspaces/arborist/tap-snapshots/test/shrinkwrap.js.test.cjs +++ b/workspaces/arborist/tap-snapshots/test/shrinkwrap.js.test.cjs @@ -2652,6 +2652,30 @@ Object { "node_modules/foo/node_modules/glob": Object { "version": "4.0.5", }, + "node_modules/foo/node_modules/glob/node_modules/graceful-fs": Object { + "extraneous": true, + "version": "3.0.2", + }, + "node_modules/foo/node_modules/glob/node_modules/inherits": Object { + "extraneous": true, + "version": "2.0.1", + }, + "node_modules/foo/node_modules/glob/node_modules/minimatch": Object { + "extraneous": true, + "version": "1.0.0", + }, + "node_modules/foo/node_modules/glob/node_modules/minimatch/node_modules/lru-cache": Object { + "extraneous": true, + "version": "2.5.0", + }, + "node_modules/foo/node_modules/glob/node_modules/minimatch/node_modules/sigmund": Object { + "extraneous": true, + "version": "1.0.0", + }, + "node_modules/foo/node_modules/glob/node_modules/once": Object { + "extraneous": true, + "version": "1.3.0", + }, "node_modules/foo/node_modules/selflink": Object { "link": true, "resolved": "", From 1218334f75262b504195b31764e6dc02bbfe6a03 Mon Sep 17 00:00:00 2001 From: siemhesda <143130929+siemhesda@users.noreply.github.com> Date: Tue, 3 Oct 2023 11:23:12 -0700 Subject: [PATCH 5/8] fix(arborist): revert rebuild.js.test.cjs --- .../test/arborist/rebuild.js.test.cjs | 24 ++++--------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/workspaces/arborist/tap-snapshots/test/arborist/rebuild.js.test.cjs b/workspaces/arborist/tap-snapshots/test/arborist/rebuild.js.test.cjs index 404480f248c19..8cd2cfd322cc0 100644 --- a/workspaces/arborist/tap-snapshots/test/arborist/rebuild.js.test.cjs +++ b/workspaces/arborist/tap-snapshots/test/arborist/rebuild.js.test.cjs @@ -26,11 +26,7 @@ Array [ "version": "1.0.0", }, "signal": null, - "stderr": String( - Debugger attached. - stderr - Waiting for the debugger to disconnect... - ), + "stderr": "stderr", "stdout": "npm_package_dev", }, Object { @@ -46,11 +42,7 @@ Array [ "version": "1.0.0", }, "signal": null, - "stderr": String( - Debugger attached. - stderr - Waiting for the debugger to disconnect... - ), + "stderr": "stderr", "stdout": "npm_package_dev_optional", }, Object { @@ -66,11 +58,7 @@ Array [ "version": "1.0.0", }, "signal": null, - "stderr": String( - Debugger attached. - stderr - Waiting for the debugger to disconnect... - ), + "stderr": "stderr", "stdout": String( npm_package_dev npm_package_optional @@ -92,11 +80,7 @@ Array [ "version": "1.0.0", }, "signal": null, - "stderr": String( - Debugger attached. - stderr - Waiting for the debugger to disconnect... - ), + "stderr": "stderr", "stdout": "npm_package_optional", }, ] From 58aa4cf2892411d4553370c3d2ec626335ac3481 Mon Sep 17 00:00:00 2001 From: siemhesda <143130929+siemhesda@users.noreply.github.com> Date: Tue, 10 Oct 2023 10:52:21 -0700 Subject: [PATCH 6/8] docs(rebuild): change description for the npm-rebuild command --- docs/lib/content/commands/npm-rebuild.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/lib/content/commands/npm-rebuild.md b/docs/lib/content/commands/npm-rebuild.md index da3a088ac7689..d7daa353e0e08 100644 --- a/docs/lib/content/commands/npm-rebuild.md +++ b/docs/lib/content/commands/npm-rebuild.md @@ -10,7 +10,7 @@ description: Rebuild a package ### Description -This command runs the `npm build` command on the matched folders. This is +This command is used to conditionally run the `node gyp` build tool. This is useful when you install a new version of node, and must recompile all your C++ addons with the new binary. It is also useful when installing with `--ignore-scripts` and `--no-bin-links`, to explicitly choose which From 39caef9e3a441aeb80febe009e3c381c8bafd0c6 Mon Sep 17 00:00:00 2001 From: siemhesda <143130929+siemhesda@users.noreply.github.com> Date: Tue, 10 Oct 2023 11:03:19 -0700 Subject: [PATCH 7/8] docs(rebuild): revert 2 files --- workspaces/arborist/lib/arborist/build-ideal-tree.js | 4 ++-- workspaces/arborist/lib/place-dep.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/workspaces/arborist/lib/arborist/build-ideal-tree.js b/workspaces/arborist/lib/arborist/build-ideal-tree.js index 6f10d85c2f2a9..d04ddf27b6965 100644 --- a/workspaces/arborist/lib/arborist/build-ideal-tree.js +++ b/workspaces/arborist/lib/arborist/build-ideal-tree.js @@ -1299,8 +1299,8 @@ This is a one-time fix-up, please be patient... continue } - const parentEdge = node.parent?.edgesOut.get(edge.name) - const { isProjectRoot, isWorkspace } = node.parent?.sourceReference || {} + const parentEdge = node.parent.edgesOut.get(edge.name) + const { isProjectRoot, isWorkspace } = node.parent.sourceReference const isMine = isProjectRoot || isWorkspace const conflictOK = this[_force] || !isMine && !this.#strictPeerDeps diff --git a/workspaces/arborist/lib/place-dep.js b/workspaces/arborist/lib/place-dep.js index a8ffd04426d4a..e757d0c38a6d7 100644 --- a/workspaces/arborist/lib/place-dep.js +++ b/workspaces/arborist/lib/place-dep.js @@ -296,7 +296,7 @@ class PlaceDep { continue } - const peer = virtualRoot?.children.get(peerEdge.name) + const peer = virtualRoot.children.get(peerEdge.name) // Note: if the virtualRoot *doesn't* have the peer, then that means // it's an optional peer dep. If it's not being properly met (ie, From c82f83f4b15ac3515f53ddd6793f3d4c60732a1c Mon Sep 17 00:00:00 2001 From: siemhesda <143130929+siemhesda@users.noreply.github.com> Date: Wed, 18 Oct 2023 10:53:10 -0700 Subject: [PATCH 8/8] docs(rebuild): update command description --- docs/lib/content/commands/npm-rebuild.md | 31 ++++++++++++++++++------ 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/docs/lib/content/commands/npm-rebuild.md b/docs/lib/content/commands/npm-rebuild.md index d7daa353e0e08..aee332e37d8a1 100644 --- a/docs/lib/content/commands/npm-rebuild.md +++ b/docs/lib/content/commands/npm-rebuild.md @@ -10,14 +10,29 @@ description: Rebuild a package ### Description -This command is used to conditionally run the `node gyp` build tool. This is -useful when you install a new version of node, and must recompile all your -C++ addons with the new binary. It is also useful when installing with -`--ignore-scripts` and `--no-bin-links`, to explicitly choose which -packages to build and/or link bins. - -If one or more package specs are provided, then only packages with a -name and version matching one of the specifiers will be rebuilt. +This command does the following: + +1. Execute lifecycle scripts (`preinstall`, `install`, `postinstall`, `prepare`) +2. Links bins depending on whether bin links are enabled + +This command is particularly useful in scenarios including but not limited to: + +1. Installing a new version of **node.js**, where you need to recompile all your C++ add-ons with the updated binary. +2. Installing with `--ignore-scripts` and `--no-bin-links`, to explicitly choose which packages to build and/or link bins. + +If one or more package specs are provided, then only packages with a name and version matching one of the specifiers will be rebuilt. + +Usually, you should not need to run `npm rebuild` as it is already done for you as part of npm install (unless you suppressed these steps with `--ignore-scripts` or `--no-bin-links`). + +If there is a `binding.gyp` file in the root of your package, then npm will use a default install hook: + +``` +"scripts": { + "install": "node-gyp rebuild" +} +``` + +This default behavior is suppressed if the `package.json` has its own `install` or `preinstall` scripts. It is also suppressed if the package specifies `"gypfile": false` ### Configuration