Skip to content
Open
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
6 changes: 3 additions & 3 deletions plugins/nodejs.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/jetify-com/devbox/main/.schema/devbox-plugin.schema.json",
"version": "0.0.3",
"version": "0.0.4",
"name": "nodejs",
"readme": "Devbox automatically configures Corepack for Nodejs when DEVBOX_COREPACK_ENABLED=1. You can install Yarn or Pnpm by adding them to your `package.json` file using `packageManager`\nCorepack binaries will be installed in your local `.devbox` directory\n\nWhen Corepack is enabled, Devbox also activates the package manager pinned in your `package.json` `packageManager` field automatically. Set DEVBOX_DISABLE_NODEJS_PACKAGE_MANAGER_AUTODETECT=1 to disable this behavior.",
"env": {
Expand All @@ -9,11 +9,11 @@
},
"shell": {
"init_hook": [
"node \"{{ .Virtenv }}/bin/setup-corepack.js\""
"node \"{{ .Virtenv }}/bin/setup-corepack.cjs\""
]
},
"create_files": {
"{{ .Virtenv }}/corepack-bin": "",
"{{ .Virtenv }}/bin/setup-corepack.js": "nodejs/setup-corepack.js"
"{{ .Virtenv }}/bin/setup-corepack.cjs": "nodejs/setup-corepack.cjs"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// Configures Corepack for the Devbox shell. This is the nodejs plugin's
// init_hook, invoked as: node setup-corepack.js
// init_hook, invoked as: node setup-corepack.cjs
//
// The .cjs extension forces CommonJS regardless of the project's package.json,
// which may declare "type": "module" (otherwise the require() calls below fail
// with "require is not defined in ES module scope"). See issue #2856.
//
// It is a no-op unless DEVBOX_COREPACK_ENABLED is set, in which case it:
// 1. Enables Corepack, installing its package-manager shims into the
Expand Down
13 changes: 13 additions & 0 deletions testscripts/plugin/nodejs_corepack_autodetect.test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,21 @@ cp package-no-pkgmgr.json package.json
exec devbox run -- node -e 'console.log("case2-ok")'
stdout 'case2-ok'

# Case 3: package.json declares "type": "module" (issue #2856).
# The setup-corepack script must still load (it uses a .cjs extension so it is
# always treated as CommonJS) and shell init must still succeed.
cp package-esm.json package.json
exec devbox run -- node -e 'console.log("case3-ok")'
stdout 'case3-ok'

-- package-no-pkgmgr.json --
{
"name": "nodejs-corepack-autodetect",
"version": "1.0.0"
}
-- package-esm.json --
{
"name": "nodejs-corepack-autodetect",
"version": "1.0.0",
"type": "module"
}
Loading