feat: ignore-dep-scripts (#5142)

This commit is contained in:
Zoltan Kochan
2022-08-02 11:40:31 +03:00
committed by GitHub
parent 39c0401277
commit 43cd6aaca3
7 changed files with 53 additions and 2 deletions

View File

@@ -0,0 +1,8 @@
---
"@pnpm/config": minor
"@pnpm/core": minor
"@pnpm/headless": minor
"pnpm": minor
---
When `ignore-dep-scripts` is `true`, ignore scripts of dependencies but run the scripts of the project.

View File

@@ -27,6 +27,7 @@ export interface Config {
global?: boolean
dir: string
bin: string
ignoreDepScripts?: boolean
ignoreScripts?: boolean
ignoreCompatibilityDb?: boolean
includeWorkspaceRoot?: boolean

View File

@@ -61,6 +61,7 @@ export const types = Object.assign({
hoist: Boolean,
'hoist-pattern': Array,
'ignore-compatibility-db': Boolean,
'ignore-dep-scripts': Boolean,
'ignore-pnpmfile': Boolean,
'ignore-workspace': Boolean,
'ignore-workspace-root-check': Boolean,

View File

@@ -33,6 +33,7 @@ export interface StrictInstallOptions {
lockfileOnly: boolean
fixLockfile: boolean
ignoreCompatibilityDb: boolean
ignoreDepScripts: boolean
ignorePackageManifest: boolean
preferFrozenLockfile: boolean
saveWorkspaceProtocol: boolean | 'rolling'
@@ -131,6 +132,7 @@ const defaults = async (opts: InstallOptions) => {
publicHoistPattern: undefined,
hooks: {},
ignoreCurrentPrefs: false,
ignoreDepScripts: false,
ignoreScripts: false,
include: {
dependencies: true,

View File

@@ -947,7 +947,7 @@ const _installInContext: InstallFunction = async (projects, ctx, opts) => {
extraBinPaths: ctx.extraBinPaths,
extraNodePaths: ctx.extraNodePaths,
extraEnv,
ignoreScripts: opts.ignoreScripts,
ignoreScripts: opts.ignoreScripts || opts.ignoreDepScripts,
lockfileDir: ctx.lockfileDir,
optional: opts.include.optionalDependencies,
preferSymlinkedExecutables: opts.preferSymlinkedExecutables,

View File

@@ -618,3 +618,41 @@ test('lifecycle scripts run after linking root dependencies', async () => {
// if there was no exception, the test passed
})
test('ignore-dep-scripts', async () => {
prepareEmpty()
const manifest = {
scripts: {
'pnpm:devPreinstall': 'node -e "require(\'fs\').writeFileSync(\'test.txt\', \'\', \'utf-8\')"',
install: 'node -e "process.stdout.write(\'install\')" | json-append output.json',
postinstall: 'node -e "process.stdout.write(\'postinstall\')" | json-append output.json',
preinstall: 'node -e "process.stdout.write(\'preinstall\')" | json-append output.json',
},
dependencies: {
'json-append': '1.1.1',
'pre-and-postinstall-scripts-example': '1.0.0',
},
}
await install(manifest, await testDefaults({ fastUnpack: false, ignoreDepScripts: true }))
{
const output = await loadJsonFile<string[]>('output.json')
expect(output).toStrictEqual(['preinstall', 'install', 'postinstall'])
expect(await exists('test.txt')).toBeTruthy()
expect(await exists('node_modules/pre-and-postinstall-scripts-example/generated-by-preinstall.js')).toBeFalsy()
}
await rimraf('node_modules')
await rimraf('output.json')
await install(manifest, await testDefaults({ fastUnpack: false, ignoreDepScripts: true }))
{
const output = await loadJsonFile<string[]>('output.json')
expect(output).toStrictEqual(['preinstall', 'install', 'postinstall'])
expect(await exists('test.txt')).toBeTruthy()
expect(await exists('node_modules/pre-and-postinstall-scripts-example/generated-by-preinstall.js')).toBeFalsy()
}
})

View File

@@ -103,6 +103,7 @@ export interface HeadlessOptions {
extraNodePaths?: string[]
preferSymlinkedExecutables?: boolean
hoistingLimits?: HoistingLimits
ignoreDepScripts: boolean
ignoreScripts: boolean
ignorePackageManifest?: boolean
include: IncludedDependencies
@@ -435,7 +436,7 @@ export default async (opts: HeadlessOptions) => {
extraBinPaths,
extraEnv,
depsStateCache,
ignoreScripts: opts.ignoreScripts,
ignoreScripts: opts.ignoreScripts || opts.ignoreDepScripts,
lockfileDir,
optional: opts.include.optionalDependencies,
preferSymlinkedExecutables: opts.preferSymlinkedExecutables,