Skip to content

Commit

Permalink
feat: script-shell
Browse files Browse the repository at this point in the history
close #2942
PR #2943
  • Loading branch information
zkochan committed Oct 20, 2020
1 parent 68aedc3 commit 50b360e
Show file tree
Hide file tree
Showing 17 changed files with 74 additions and 6 deletions.
12 changes: 12 additions & 0 deletions .changeset/large-avocados-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"@pnpm/build-modules": minor
"@pnpm/config": minor
"@pnpm/headless": minor
"@pnpm/lifecycle": minor
"@pnpm/plugin-commands-installation": minor
"@pnpm/plugin-commands-rebuild": minor
"@pnpm/plugin-commands-script-runners": minor
"supi": patch
---

A new option added for specifying the shell to use, when running scripts: scriptShell.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@commitlint/config-conventional": "^11.0.0",
"@commitlint/prompt-cli": "^11.0.0",
"@pnpm/eslint-config": "workspace:*",
"@pnpm/registry-mock": "^2.1.0",
"@pnpm/registry-mock": "^2.2.0",
"@pnpm/tsconfig": "workspace:*",
"@types/jest": "^26.0.14",
"@types/node": "^12.12.68",
Expand Down
6 changes: 6 additions & 0 deletions packages/build-modules/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export default async (
rawConfig: object
unsafePerm: boolean
userAgent: string
scriptShell?: string
shellEmulator?: boolean
sideEffectsCacheWrite: boolean
storeController: StoreController
rootModulesDir: string
Expand Down Expand Up @@ -69,6 +71,8 @@ async function buildDependency (
optional: boolean
rawConfig: object
rootModulesDir: string
scriptShell?: string
shellEmulator?: boolean
sideEffectsCacheWrite: boolean
storeController: StoreController
unsafePerm: boolean
Expand All @@ -88,6 +92,8 @@ async function buildDependency (
prepare: depNode.prepare,
rawConfig: opts.rawConfig,
rootModulesDir: opts.rootModulesDir,
scriptShell: opts.scriptShell,
shellEmulator: opts.shellEmulator,
unsafePerm: opts.unsafePerm || false,
})
if (hasSideEffects && opts.sideEffectsCacheWrite) {
Expand Down
1 change: 1 addition & 0 deletions packages/config/src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface Config {
saveOptional?: boolean
savePeer?: boolean
saveWorkspaceProtocol?: boolean
scriptShell?: string
stream?: boolean
production?: boolean
fetchRetries?: number
Expand Down
1 change: 1 addition & 0 deletions packages/config/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export const types = Object.assign({
reporter: String,
'save-peer': Boolean,
'save-workspace-protocol': Boolean,
'script-shell': String,
'shamefully-flatten': Boolean,
'shamefully-hoist': Boolean,
'shared-workspace-lockfile': Boolean,
Expand Down
6 changes: 6 additions & 0 deletions packages/headless/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ export interface HeadlessOptions {
lockfileDir: string
modulesDir?: string
virtualStoreDir?: string
scriptShell?: string
shellEmulator?: boolean
storeController: StoreController
sideEffectsCacheRead: boolean
sideEffectsCacheWrite: boolean
Expand Down Expand Up @@ -147,6 +149,8 @@ export default async (opts: HeadlessOptions) => {
const scriptsOpts = {
optional: false,
rawConfig: opts.rawConfig,
scriptShell: opts.scriptShell,
shellEmulator: opts.shellEmulator,
stdio: opts.ownLifecycleHooksStdio ?? 'inherit',
unsafePerm: opts.unsafePerm || false,
}
Expand Down Expand Up @@ -341,6 +345,8 @@ export default async (opts: HeadlessOptions) => {
optional: opts.include.optionalDependencies,
rawConfig: opts.rawConfig,
rootModulesDir: virtualStoreDir,
scriptShell: opts.scriptShell,
shellEmulator: opts.shellEmulator,
sideEffectsCacheWrite: opts.sideEffectsCacheWrite,
storeController: opts.storeController,
unsafePerm: opts.unsafePerm,
Expand Down
2 changes: 2 additions & 0 deletions packages/lifecycle/src/runLifecycleHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface RunLifecycleHookOptions {
pkgRoot: string
rawConfig: object
rootModulesDir: string
scriptShell?: string
silent?: boolean
shellEmulator?: boolean
stdio?: string
Expand Down Expand Up @@ -71,6 +72,7 @@ export default async function runLifecycleHook (
warn: noop,
},
runConcurrently: true,
scriptShell: opts.scriptShell,
shellEmulator: opts.shellEmulator,
stdio: opts.stdio ?? 'pipe',
unsafePerm: opts.unsafePerm,
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-commands-installation/src/installDeps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export type InstallDepsOptions = Pick<Config,
| 'savePrefix'
| 'saveProd'
| 'saveWorkspaceProtocol'
| 'scriptShell'
| 'selectedProjectsGraph'
| 'sideEffectsCache'
| 'sideEffectsCacheReadonly'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface StrictRebuildOptions {
childConcurrency: number
extraBinPaths: string[]
lockfileDir: string
scriptShell?: string
sideEffectsCacheRead: boolean
shellEmulator: boolean
storeDir: string // TODO: remove this property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export async function rebuild (
const scriptsOpts = {
extraBinPaths: ctx.extraBinPaths,
rawConfig: opts.rawConfig,
scriptShell: opts.scriptShell,
shellEmulator: opts.shellEmulator,
unsafePerm: opts.unsafePerm || false,
}
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-commands-rebuild/src/rebuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export async function handler (
| 'engineStrict'
| 'rawLocalConfig'
| 'registries'
| 'scriptShell'
| 'selectedProjectsGraph'
| 'sideEffectsCache'
| 'sideEffectsCacheReadonly'
Expand Down
3 changes: 2 additions & 1 deletion packages/plugin-commands-script-runners/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,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' | 'shellEmulator'>
& Pick<Config, 'dir' | 'engineStrict' | 'reporter' | 'scriptShell' | 'shellEmulator'>
& (
& { recursive?: false }
& Partial<Pick<Config, 'allProjects' | 'selectedProjectsGraph' | 'workspaceDir'>>
Expand Down Expand Up @@ -154,6 +154,7 @@ so you may run "pnpm -w ${scriptName}"`,
pkgRoot: dir,
rawConfig: opts.rawConfig,
rootModulesDir: await realpathMissing(path.join(dir, 'node_modules')),
scriptShell: opts.scriptShell,
silent: opts.reporter === 'silent',
shellEmulator: opts.shellEmulator,
stdio: 'inherit',
Expand Down
2 changes: 2 additions & 0 deletions packages/plugin-commands-script-runners/src/runRecursive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import realpathMissing = require('realpath-missing')
export type RecursiveRunOpts = Pick<Config,
| 'unsafePerm'
| 'rawConfig'
| 'scriptShell'
| 'shellEmulator'
> & Required<Pick<Config, 'allProjects' | 'selectedProjectsGraph' | 'workspaceDir'>> &
Partial<Pick<Config, 'extraBinPaths' | 'bail' | 'sort' | 'workspaceConcurrency'>> &
Expand Down Expand Up @@ -67,6 +68,7 @@ export default async (
pkgRoot: prefix,
rawConfig: opts.rawConfig,
rootModulesDir: await realpathMissing(path.join(prefix, 'node_modules')),
scriptShell: opts.scriptShell,
shellEmulator: opts.shellEmulator,
stdio,
unsafePerm: true, // when running scripts explicitly, assume that they're trusted.
Expand Down
29 changes: 29 additions & 0 deletions packages/plugin-commands-script-runners/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
test as testCommand,
} from '@pnpm/plugin-commands-script-runners'
import prepare, { preparePackages } from '@pnpm/prepare'
import { REGISTRY_MOCK_PORT } from '@pnpm/registry-mock'
import './exec'
import './runCompletion'
import './runRecursive'
Expand Down Expand Up @@ -390,3 +391,31 @@ test('scripts work with PnP', async (t) => {
t.deepEqual(scriptsRan, ['foo'])
t.end()
})

test('pnpm run with custom shell', async (t) => {
prepare(t, {
scripts: {
build: 'foo bar',
},
dependencies: {
'shell-mock': '0.0.0',
},
})

await execa(pnpmBin, [
'install',
`--registry=http://localhost:${REGISTRY_MOCK_PORT}`,
'--store-dir',
path.resolve(DEFAULT_OPTS.storeDir),
])

await run.handler({
dir: process.cwd(),
extraBinPaths: [],
rawConfig: {},
scriptShell: path.resolve('node_modules/.bin/shell-mock'),
}, ['build'])

t.deepEqual(await import(path.resolve('shell-input.json')), ['-c', 'foo bar'])
t.end()
})
1 change: 1 addition & 0 deletions packages/supi/src/install/extendInstallOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface StrictInstallOptions {
preferFrozenLockfile: boolean
saveWorkspaceProtocol: boolean
preserveWorkspaceProtocol: boolean
scriptShell?: string
shellEmulator: boolean
storeController: StoreController
storeDir: string
Expand Down
3 changes: 3 additions & 0 deletions packages/supi/src/install/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ export async function mutateModules (
const scriptsOpts: RunLifecycleHooksConcurrentlyOptions = {
extraBinPaths: opts.extraBinPaths,
rawConfig: opts.rawConfig,
scriptShell: opts.scriptShell,
shellEmulator: opts.shellEmulator,
stdio: opts.ownLifecycleHooksStdio,
unsafePerm: opts.unsafePerm || false,
Expand Down Expand Up @@ -753,6 +754,8 @@ async function installInContext (
optional: opts.include.optionalDependencies,
rawConfig: opts.rawConfig,
rootModulesDir: ctx.virtualStoreDir,
scriptShell: opts.scriptShell,
shellEmulator: opts.shellEmulator,
sideEffectsCacheWrite: opts.sideEffectsCacheWrite,
storeController: opts.storeController,
unsafePerm: opts.unsafePerm,
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 50b360e

Please sign in to comment.