Conversation
|
In the previous PR #6724 I have suggested to declare the config (useNodeVersion) in the |
|
Having this new setting be in per-project |
|
Maybe we should add warnings as well for the use of root-only keys in local workspace package in another PR? |
| // TODO: fix the related implementation then remove `.skip` | ||
| test.skip('recursive run when some packages define node version, config does not define use-node-version', async () => { | ||
| preparePackages([ | ||
| { | ||
| name: 'node-version-undefined', | ||
| scripts: { | ||
| 'assert-node-version': `node -e "assert.equal(process.version, '${process.version}')"`, | ||
| }, | ||
| }, | ||
| { | ||
| name: 'node-version-18', | ||
| scripts: { | ||
| 'assert-node-version': 'node -e "assert.equal(process.version, \'v18.0.0\')"', | ||
| }, | ||
| pnpm: { | ||
| useNodeVersion: '18.0.0', | ||
| }, | ||
| }, | ||
| { | ||
| name: 'node-version-20', | ||
| scripts: { | ||
| 'assert-node-version': 'node -e "assert.equal(process.version, \'v20.0.0\')"', | ||
| }, | ||
| pnpm: { | ||
| useNodeVersion: '20.0.0', | ||
| }, | ||
| }, | ||
| ]) | ||
| await run.handler({ | ||
| ...DEFAULT_OPTS, | ||
| ...await filterPackagesFromDir(process.cwd(), [{ namePattern: '*' }]), | ||
| dir: process.cwd(), | ||
| recursive: true, | ||
| workspaceDir: process.cwd(), | ||
| workspaceConcurrency: 3, // if this step fails, change this value to 1 to see error message. | ||
| }, ['assert-node-version']) | ||
| }) |
There was a problem hiding this comment.
This test doesn't work when placed here but it work when moved to /pnpm/test. Not sure why.
|
I am wondering about the location of this setting. We might want to move it to a subfield. Like |
I have implemented this suggestion in c96153e. You may revert the change if you don't like it. Aesthetically speaking, it makes certain part of the code more long-winded, but could it be fixed by reusing Regarding the "future", I wonder how would they live alongside {
"pnpm": {
"executionEnv": {
"nodeVersion": "20.0.0",
"env": {
"USERNAME": "username",
"TOKEN": "d94f9468de245385b5204d1554e248db"
}
}
}
}Or should this be a bit flatter (with intermediate |
I think it would be inside Although, I am not sure it would make sense at all. Usually variables are either system specific or they contain secrets. Also, I am not sure you'd want to set the variables for all the scripts. Usually they are only needed for one specific command. |
| if (pkg.package.manifest.pnpm?.executionEnv?.nodeVersion) { | ||
| lifecycleOpts.extraBinPaths = (await node.prepareExecutionEnv(opts, { executionEnv: pkg.package.manifest.pnpm.executionEnv })).extraBinPaths | ||
| } |
There was a problem hiding this comment.
| if (pkg.package.manifest.pnpm?.executionEnv?.nodeVersion) { | |
| lifecycleOpts.extraBinPaths = (await node.prepareExecutionEnv(opts, { executionEnv: pkg.package.manifest.pnpm.executionEnv })).extraBinPaths | |
| } | |
| const { executionEnv } = pkg.package.manifest.pnpm ?? {} | |
| if (executionEnv) { | |
| lifecycleOpts.extraBinPaths = (await node.prepareExecutionEnv(opts, { executionEnv })).extraBinPaths | |
| } |
| if (manifest.pnpm?.executionEnv?.nodeVersion) { | ||
| lifecycleOpts.extraBinPaths = (await node.prepareExecutionEnv(opts, { executionEnv: manifest.pnpm.executionEnv })).extraBinPaths | ||
| } |
There was a problem hiding this comment.
| if (manifest.pnpm?.executionEnv?.nodeVersion) { | |
| lifecycleOpts.extraBinPaths = (await node.prepareExecutionEnv(opts, { executionEnv: manifest.pnpm.executionEnv })).extraBinPaths | |
| } | |
| const { executionEnv } = manifest.pnpm ?? {} | |
| if (manifest.pnpm?.executionEnv?.nodeVersion) { | |
| lifecycleOpts.extraBinPaths = (await node.prepareExecutionEnv(opts, { executionEnv })).extraBinPaths | |
| } |
| } else { | ||
| return [...binPaths.slice(0, index), nodePath, ...binPaths.slice(index + 1)] | ||
| } | ||
| } |
There was a problem hiding this comment.
I am not sure why this complex function is needed at all. The node location should be just appended to the array. Replacing is not good because we need the specified node path to have the highest priority. What if the replaced directory didn't have the highest priority? Also, even if it will be duplicated, I don't think it is an issue.
| } | ||
|
|
||
| return { | ||
| extraBinPaths: [await nodePathPromise, ...extraBinPaths ?? []], |
There was a problem hiding this comment.
it should be added to the end
It would allow extraBinPaths to override node. Do you still want this?
There was a problem hiding this comment.
isn't that the whole point? To override node with the version specified in the setting.
There was a problem hiding this comment.
It would allow the tail of extraBinPaths to override the node provided by the nodePathPromise. The tail of extraBinPaths may or may not include node from use-node-version of .npmrc. It would defeat the whole point.
There was a problem hiding this comment.
Yes, you are correct. The directories at the beginning have bigger priority. It is correct as it is now.
There was a problem hiding this comment.
I have added a test that would fail should extraBinPaths was handled incorrectly (leading to use-node-version overrides executionEnv): 2721d44
You may revert if you find it unnecessary.
| "@pnpm/plugin-commands-installation": major | ||
| "@pnpm/plugin-commands-publishing": major | ||
| "@pnpm/plugin-commands-script-runners": major | ||
| "@pnpm/plugin-commands-env": minor |
|
OMG! amazing! Thank you @KSXGitHub @zkochan ❤️ PS: Does that also execute the |
|
No, this is somewhat more complex as the dependency may be used by several different projects in the workspace, which all use different node.js versions. So, which node.js version should be used to build the dependency? We can add a field for the dependency itself to tell which node.js version it requires for being build. See related RFC: pnpm/rfcs#7 |
Fixes #6720
TODO:
pnpm runpnpm install,pnpm add,pnpm updatepnpm publish