feat: shell emulator

close #2621
PR #2881
This commit is contained in:
Zoltan Kochan
2020-09-23 13:32:48 +03:00
committed by GitHub
parent 846887de32
commit 23cf3c88b1
16 changed files with 301 additions and 179 deletions

View File

@@ -0,0 +1,10 @@
---
"@pnpm/config": minor
"@pnpm/lifecycle": minor
"@pnpm/plugin-commands-installation": minor
"@pnpm/plugin-commands-rebuild": minor
"@pnpm/plugin-commands-script-runners": minor
"supi": minor
---
New option added: `shellEmulator`.

View File

@@ -40,6 +40,7 @@ export interface Config {
fetchRetryMaxtimeout?: number
saveExact?: boolean
savePrefix?: string
shellEmulator?: boolean
force?: boolean
depth?: number
engineStrict?: boolean

View File

@@ -69,6 +69,7 @@ export const types = Object.assign({
'shamefully-hoist': Boolean,
'shared-workspace-lockfile': Boolean,
'shared-workspace-shrinkwrap': Boolean,
'shell-emulator': Boolean,
'shrinkwrap-directory': String,
'shrinkwrap-only': Boolean,
'side-effects-cache': Boolean,
@@ -161,6 +162,7 @@ export default async (
'save-workspace-protocol': true,
'shared-workspace-lockfile': true,
'shared-workspace-shrinkwrap': true,
'shell-emulator': false,
shrinkwrap: npmDefaults.shrinkwrap,
sort: true,
'strict-peer-dependencies': false,

View File

@@ -38,7 +38,7 @@
"@pnpm/core-loggers": "workspace:5.0.0",
"@pnpm/read-package-json": "workspace:3.1.5",
"@pnpm/types": "workspace:6.2.0",
"@zkochan/npm-lifecycle": "4.0.0",
"@zkochan/npm-lifecycle": "4.1.0",
"path-exists": "^4.0.0",
"run-groups": "^3.0.1"
},

View File

@@ -16,6 +16,7 @@ export async function runPostinstallHooks (
prepare?: boolean
rawConfig: object
rootModulesDir: string
shellEmulator?: boolean
unsafePerm: boolean
}
): Promise<boolean> {

View File

@@ -13,6 +13,7 @@ export interface RunLifecycleHookOptions {
rawConfig: object
rootModulesDir: string
silent?: boolean
shellEmulator?: boolean
stdio?: string
unsafePerm: boolean
}
@@ -64,6 +65,7 @@ export default async function runLifecycleHook (
warn: noop,
},
runConcurrently: true,
shellEmulator: opts.shellEmulator,
stdio: opts.stdio ?? 'pipe',
unsafePerm: opts.unsafePerm,
})

View File

@@ -9,6 +9,7 @@ export default async function runLifecycleHooksConcurrently (
opts: {
extraBinPaths?: string[]
rawConfig: object
shellEmulator?: boolean
stdio?: string
unsafePerm: boolean
}
@@ -32,6 +33,7 @@ export default async function runLifecycleHooksConcurrently (
pkgRoot: rootDir,
rawConfig: opts.rawConfig,
rootModulesDir: modulesDir,
shellEmulator: opts.shellEmulator,
stdio: opts.stdio,
unsafePerm: opts.unsafePerm,
}

View File

@@ -59,6 +59,7 @@ export type InstallDepsOptions = Pick<Config,
| 'sideEffectsCacheReadonly'
| 'sort'
| 'sharedWorkspaceLockfile'
| 'shellEmulator'
| 'tag'
| 'optional'
| 'workspaceConcurrency'

View File

@@ -10,6 +10,7 @@ export interface StrictRebuildOptions {
extraBinPaths: string[]
lockfileDir: string
sideEffectsCacheRead: boolean
shellEmulator: boolean
storeDir: string // TODO: remove this property
storeController: StoreController
force: boolean
@@ -55,6 +56,7 @@ const defaults = async (opts: RebuildOptions) => {
rawConfig: {},
registries: DEFAULT_REGISTRIES,
shamefullyHoist: false,
shellEmulator: false,
sideEffectsCacheRead: false,
storeDir: opts.storeDir,
unsafePerm: process.platform === 'win32' ||

View File

@@ -155,6 +155,7 @@ export async function rebuild (
const scriptsOpts = {
extraBinPaths: ctx.extraBinPaths,
rawConfig: opts.rawConfig,
shellEmulator: opts.shellEmulator,
unsafePerm: opts.unsafePerm || false,
}
await runLifecycleHooksConcurrently(
@@ -277,6 +278,7 @@ async function _rebuild (
prepare: pkgSnapshot.prepare,
rawConfig: opts.rawConfig,
rootModulesDir: ctx.rootModulesDir,
shellEmulator: opts.shellEmulator,
unsafePerm: opts.unsafePerm || false,
})
pkgsThatWereRebuilt.add(depPath)

View File

@@ -74,6 +74,7 @@ export async function handler (
| 'selectedProjectsGraph'
| 'sideEffectsCache'
| 'sideEffectsCacheReadonly'
| 'shellEmulator'
| 'workspaceDir'
> &
CreateStoreControllerOptions &

View File

@@ -103,7 +103,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' | 'reporter'>
& Pick<Config, 'dir' | 'engineStrict' | 'reporter' | 'shellEmulator'>
& (
& { recursive?: false }
& Partial<Pick<Config, 'allProjects' | 'selectedProjectsGraph' | 'workspaceDir'>>
@@ -151,6 +151,7 @@ so you may run "pnpm -w ${scriptName}"`,
rawConfig: opts.rawConfig,
rootModulesDir: await realpathMissing(path.join(dir, 'node_modules')),
silent: opts.reporter === 'silent',
shellEmulator: opts.shellEmulator,
stdio: 'inherit',
unsafePerm: true, // when running scripts explicitly, assume that they're trusted.
}

View File

@@ -11,6 +11,7 @@ import realpathMissing = require('realpath-missing')
export type RecursiveRunOpts = Pick<Config,
| 'unsafePerm'
| 'rawConfig'
| 'shellEmulator'
> & Required<Pick<Config, 'allProjects' | 'selectedProjectsGraph' | 'workspaceDir'>> &
Partial<Pick<Config, 'extraBinPaths' | 'bail' | 'sort' | 'workspaceConcurrency'>> &
{
@@ -60,6 +61,7 @@ export default async (
pkgRoot: prefix,
rawConfig: opts.rawConfig,
rootModulesDir: await realpathMissing(path.join(prefix, 'node_modules')),
shellEmulator: opts.shellEmulator,
stdio,
unsafePerm: true, // when running scripts explicitly, assume that they're trusted.
}

View File

@@ -23,6 +23,7 @@ export interface StrictInstallOptions {
preferFrozenLockfile: boolean
saveWorkspaceProtocol: boolean
preserveWorkspaceProtocol: boolean
shellEmulator: boolean
storeController: StoreController
storeDir: string
reporter: ReporterFunction
@@ -117,6 +118,7 @@ const defaults = async (opts: InstallOptions) => {
registries: DEFAULT_REGISTRIES,
saveWorkspaceProtocol: true,
shamefullyHoist: false,
shellEmulator: false,
sideEffectsCacheRead: false,
sideEffectsCacheWrite: false,
storeController: opts.storeController,

View File

@@ -233,6 +233,7 @@ export async function mutateModules (
const scriptsOpts = {
extraBinPaths: opts.extraBinPaths,
rawConfig: opts.rawConfig,
shellEmulator: opts.shellEmulator,
stdio: opts.ownLifecycleHooksStdio,
unsafePerm: opts.unsafePerm || false,
}

446
pnpm-lock.yaml generated
View File

File diff suppressed because it is too large Load Diff