feat: scripts-prepend-node-path (#4020)

This commit is contained in:
Zoltan Kochan
2021-11-21 03:53:35 +02:00
committed by GitHub
parent 13663ddb2a
commit 0027785595
20 changed files with 62 additions and 9 deletions

View File

@@ -0,0 +1,7 @@
---
"pnpm": minor
---
New setting added: `scripts-prepend-node-path`. This setting can be `true`, `false`, or `warn-only`.
When `true`, the path to the `node` executable with which pnpm executed is prepended to the `PATH` of the scripts.
When `warn-only`, pnpm will print a warning if the scripts run with a `node` binary that differs from the `node` binary executing the pnpm CLI.

View File

@@ -0,0 +1,5 @@
---
"pnpm": patch
---
The path to the `node` executable that executes pnpm should not be added to the `PATH`, when running scripts.

View File

@@ -0,0 +1,14 @@
---
"@pnpm/build-modules": minor
"@pnpm/config": minor
"@pnpm/core": minor
"@pnpm/headless": minor
"@pnpm/lifecycle": minor
"@pnpm/plugin-commands-installation": minor
"@pnpm/plugin-commands-rebuild": minor
"@pnpm/plugin-commands-script-runners": minor
---
New setting added: `scriptsPrependNodePath`. This setting can be `true`, `false`, or `warn-only`.
When `true`, the path to the `node` executable with which pnpm executed is prepended to the `PATH` of the scripts.
When `warn-only`, pnpm will print a warning if the scripts run with a `node` binary that differs from the `node` binary executing the pnpm CLI.

View File

@@ -25,6 +25,7 @@ export default async (
rawConfig: object
unsafePerm: boolean
userAgent: string
scriptsPrependNodePath?: boolean | 'warn-only'
scriptShell?: string
shellEmulator?: boolean
sideEffectsCacheWrite: boolean
@@ -73,6 +74,7 @@ async function buildDependency (
optional: boolean
rawConfig: object
rootModulesDir: string
scriptsPrependNodePath?: boolean | 'warn-only'
scriptShell?: string
shellEmulator?: boolean
sideEffectsCacheWrite: boolean
@@ -93,6 +95,7 @@ async function buildDependency (
pkgRoot: depNode.dir,
rawConfig: opts.rawConfig,
rootModulesDir: opts.rootModulesDir,
scriptsPrependNodePath: opts.scriptsPrependNodePath,
scriptShell: opts.scriptShell,
shellEmulator: opts.shellEmulator,
unsafePerm: opts.unsafePerm || false,

View File

@@ -45,6 +45,7 @@ export interface Config {
saveExact?: boolean
savePrefix?: string
shellEmulator?: boolean
scriptsPrependNodePath?: boolean | 'warn-only'
force?: boolean
depth?: number
engineStrict?: boolean

View File

@@ -198,6 +198,7 @@ export default async (
registry: npmDefaults.registry,
'save-peer': false,
'save-workspace-protocol': true,
'scripts-prepend-node-path': false,
symlink: true,
'shared-workspace-lockfile': true,
'shared-workspace-shrinkwrap': true,

View File

@@ -28,6 +28,7 @@ export interface StrictInstallOptions {
saveWorkspaceProtocol: boolean
preferWorkspacePackages: boolean
preserveWorkspaceProtocol: boolean
scriptsPrependNodePath: boolean | 'warn-only'
scriptShell?: string
shellEmulator: boolean
storeController: StoreController
@@ -131,6 +132,7 @@ const defaults = async (opts: InstallOptions) => {
rawConfig: {},
registries: DEFAULT_REGISTRIES,
saveWorkspaceProtocol: true,
scriptsPrependNodePath: false,
shamefullyHoist: false,
shellEmulator: false,
sideEffectsCacheRead: false,

View File

@@ -205,6 +205,7 @@ export async function mutateModules (
const scriptsOpts: RunLifecycleHooksConcurrentlyOptions = {
extraBinPaths: opts.extraBinPaths,
rawConfig: opts.rawConfig,
scriptsPrependNodePath: opts.scriptsPrependNodePath,
scriptShell: opts.scriptShell,
shellEmulator: opts.shellEmulator,
stdio: opts.ownLifecycleHooksStdio,
@@ -900,6 +901,7 @@ const _installInContext: InstallFunction = async (projects, ctx, opts) => {
optional: opts.include.optionalDependencies,
rawConfig: opts.rawConfig,
rootModulesDir: ctx.virtualStoreDir,
scriptsPrependNodePath: opts.scriptsPrependNodePath,
scriptShell: opts.scriptShell,
shellEmulator: opts.shellEmulator,
sideEffectsCacheWrite: opts.sideEffectsCacheWrite,

View File

@@ -103,6 +103,7 @@ export interface HeadlessOptions {
lockfileDir: string
modulesDir?: string
virtualStoreDir?: string
scriptsPrependNodePath?: boolean | 'warn-only'
scriptShell?: string
shellEmulator?: boolean
storeController: StoreController
@@ -163,6 +164,7 @@ export default async (opts: HeadlessOptions) => {
optional: false,
extraBinPaths: opts.extraBinPaths,
rawConfig: opts.rawConfig,
scriptsPrependNodePath: opts.scriptsPrependNodePath,
scriptShell: opts.scriptShell,
shellEmulator: opts.shellEmulator,
stdio: opts.ownLifecycleHooksStdio ?? 'inherit',
@@ -347,6 +349,7 @@ export default async (opts: HeadlessOptions) => {
optional: opts.include.optionalDependencies,
rawConfig: opts.rawConfig,
rootModulesDir: virtualStoreDir,
scriptsPrependNodePath: opts.scriptsPrependNodePath,
scriptShell: opts.scriptShell,
shellEmulator: opts.shellEmulator,
sideEffectsCacheWrite: opts.sideEffectsCacheWrite,

View File

@@ -37,7 +37,7 @@
"dependencies": {
"@pnpm/core-loggers": "workspace:6.0.6",
"@pnpm/directory-fetcher": "workspace:1.0.1",
"@pnpm/npm-lifecycle": "^1.0.2",
"@pnpm/npm-lifecycle": "^1.0.3",
"@pnpm/read-package-json": "workspace:5.0.6",
"@pnpm/store-controller-types": "workspace:11.0.7",
"@pnpm/types": "workspace:7.6.0",

View File

@@ -17,6 +17,7 @@ export interface RunLifecycleHookOptions {
rootModulesDir: string
scriptShell?: string
silent?: boolean
scriptsPrependNodePath?: boolean | 'warn-only'
shellEmulator?: boolean
stdio?: string
unsafePerm: boolean
@@ -75,6 +76,7 @@ export default async function runLifecycleHook (
warn: (...msg: string[]) => globalWarn(msg.join(' ')),
},
runConcurrently: true,
scriptsPrependNodePath: opts.scriptsPrependNodePath,
scriptShell: opts.scriptShell,
shellEmulator: opts.shellEmulator,
stdio: opts.stdio ?? 'pipe',

View File

@@ -46,6 +46,7 @@ export function rcOptionsTypes () {
'registry',
'reporter',
'save-workspace-protocol',
'scripts-prepend-node-path',
'shamefully-flatten',
'shamefully-hoist',
'shared-workspace-lockfile',

View File

@@ -58,6 +58,7 @@ export type InstallDepsOptions = Pick<Config,
| 'savePrefix'
| 'saveProd'
| 'saveWorkspaceProtocol'
| 'scriptsPrependNodePath'
| 'scriptShell'
| 'selectedProjectsGraph'
| 'sideEffectsCache'

View File

@@ -56,6 +56,7 @@ export function rcOptionsTypes () {
'save-exact',
'save-prefix',
'save-workspace-protocol',
'scripts-prepend-node-path',
'shamefully-flatten',
'shamefully-hoist',
'shared-workspace-lockfile',

View File

@@ -12,6 +12,7 @@ export interface StrictRebuildOptions {
lockfileDir: string
scriptShell?: string
sideEffectsCacheRead: boolean
scriptsPrependNodePath: boolean | 'warn-only'
shellEmulator: boolean
storeDir: string // TODO: remove this property
storeController: StoreController
@@ -57,6 +58,7 @@ const defaults = async (opts: RebuildOptions) => {
production: true,
rawConfig: {},
registries: DEFAULT_REGISTRIES,
scriptsPrependNodePath: false,
shamefullyHoist: false,
shellEmulator: false,
sideEffectsCacheRead: false,

View File

@@ -155,6 +155,7 @@ export async function rebuild (
const scriptsOpts = {
extraBinPaths: ctx.extraBinPaths,
rawConfig: opts.rawConfig,
scriptsPrependNodePath: opts.scriptsPrependNodePath,
scriptShell: opts.scriptShell,
shellEmulator: opts.shellEmulator,
storeController: store.ctrl,
@@ -280,6 +281,7 @@ async function _rebuild (
pkgRoot,
rawConfig: opts.rawConfig,
rootModulesDir: ctx.rootModulesDir,
scriptsPrependNodePath: opts.scriptsPrependNodePath,
shellEmulator: opts.shellEmulator,
unsafePerm: opts.unsafePerm || false,
})

View File

@@ -19,6 +19,7 @@ export function rcOptionsTypes () {
...pick([
'npm-path',
'reporter',
'scripts-prepend-node-path',
'unsafe-perm',
], allTypes),
}
@@ -76,6 +77,7 @@ export async function handler (
| 'selectedProjectsGraph'
| 'sideEffectsCache'
| 'sideEffectsCacheReadonly'
| 'scriptsPrependNodePath'
| 'shellEmulator'
| 'workspaceDir'
> &

View File

@@ -61,6 +61,7 @@ export function cliOptionsTypes () {
'sort',
'unsafe-perm',
'workspace-concurrency',
'scripts-prepend-node-path',
], allTypes),
...IF_PRESENT_OPTION,
recursive: Boolean,
@@ -113,7 +114,7 @@ For options that may be used with `-r`, see "pnpm help recursive"',
export type RunOpts =
& Omit<RecursiveRunOpts, 'allProjects' | 'selectedProjectsGraph' | 'workspaceDir'>
& { recursive?: boolean }
& Pick<Config, 'dir' | 'engineStrict' | 'extraBinPaths' | 'reporter' | 'scriptShell' | 'shellEmulator' | 'enablePrePostScripts'>
& Pick<Config, 'dir' | 'engineStrict' | 'extraBinPaths' | 'reporter' | 'scriptsPrependNodePath' | 'scriptShell' | 'shellEmulator' | 'enablePrePostScripts'>
& (
& { recursive?: false }
& Partial<Pick<Config, 'allProjects' | 'selectedProjectsGraph' | 'workspaceDir'>>
@@ -174,6 +175,7 @@ so you may run "pnpm -w run ${scriptName}"`,
pkgRoot: dir,
rawConfig: opts.rawConfig,
rootModulesDir: await realpathMissing(path.join(dir, 'node_modules')),
scriptsPrependNodePath: opts.scriptsPrependNodePath,
scriptShell: opts.scriptShell,
silent: opts.reporter === 'silent',
shellEmulator: opts.shellEmulator,

View File

@@ -16,6 +16,7 @@ export type RecursiveRunOpts = Pick<Config,
| 'enablePrePostScripts'
| 'unsafePerm'
| 'rawConfig'
| 'scriptsPrependNodePath'
| 'scriptShell'
| 'shellEmulator'
> & Required<Pick<Config, 'allProjects' | 'selectedProjectsGraph' | 'workspaceDir'>> &
@@ -73,6 +74,7 @@ export default async (
pkgRoot: prefix,
rawConfig: opts.rawConfig,
rootModulesDir: await realpathMissing(path.join(prefix, 'node_modules')),
scriptsPrependNodePath: opts.scriptsPrependNodePath,
scriptShell: opts.scriptShell,
shellEmulator: opts.shellEmulator,
stdio,

14
pnpm-lock.yaml generated
View File

@@ -1166,7 +1166,7 @@ importers:
'@pnpm/directory-fetcher': workspace:1.0.1
'@pnpm/lifecycle': 'link:'
'@pnpm/logger': ^4.0.0
'@pnpm/npm-lifecycle': ^1.0.2
'@pnpm/npm-lifecycle': ^1.0.3
'@pnpm/read-package-json': workspace:5.0.6
'@pnpm/store-controller-types': workspace:11.0.7
'@pnpm/types': workspace:7.6.0
@@ -1178,7 +1178,7 @@ importers:
dependencies:
'@pnpm/core-loggers': link:../core-loggers
'@pnpm/directory-fetcher': link:../directory-fetcher
'@pnpm/npm-lifecycle': 1.0.2
'@pnpm/npm-lifecycle': 1.0.3
'@pnpm/read-package-json': link:../read-package-json
'@pnpm/store-controller-types': link:../store-controller-types
'@pnpm/types': link:../types
@@ -4829,8 +4829,8 @@ packages:
dependencies:
abbrev: 1.1.1
/@pnpm/npm-lifecycle/1.0.2:
resolution: {integrity: sha512-T0w6H7txyusxK4F9Hv2HypGTdyeJseoRQMkK6a47luYevUJg9o/7Q4jVfavOAJhJjVXIuulqolQPzLdTeckhhA==}
/@pnpm/npm-lifecycle/1.0.3:
resolution: {integrity: sha512-DWBCctE1OtT2y652g1+IBn5gO7vf7V5mUKdmR0Prz5DRzlVkhEYpyHbvFUAGiItdH07eOunblc6dQXhhw4InrA==}
engines: {node: '>=12.17'}
dependencies:
'@pnpm/byline': 1.0.0
@@ -5077,8 +5077,8 @@ packages:
'@types/node': 16.11.9
dev: true
/@types/emscripten/1.39.5:
resolution: {integrity: sha512-DIOOg+POSrYl+OlNRHQuIEqCd8DCtynG57H862UCce16nXJX7J8eWxNGgOcf8Eyge8zXeSs27mz1UcFu8L/L7g==}
/@types/emscripten/1.39.6:
resolution: {integrity: sha512-H90aoynNhhkQP6DRweEjJp5vfUVdIj7tdPLsu7pq89vODD/lcugKfZOsfgwpvM6XUewEp2N5dCg1Uf3Qe55Dcg==}
dev: false
/@types/fs-extra/9.0.13:
@@ -5573,7 +5573,7 @@ packages:
resolution: {integrity: sha512-M7ziz16f+tFFnJSCreLtemaGPpjT+NC0E21JQaWXAAlRmFIXz6zl2EZ+tXLxV9yJaplpNDbTgX1j5GPiwg5H5w==}
engines: {node: '>=12 <14 || 14.2 - 14.9 || >14.10.0'}
dependencies:
'@types/emscripten': 1.39.5
'@types/emscripten': 1.39.6
tslib: 1.14.1
dev: false