mirror of
https://github.com/pnpm/pnpm.git
synced 2026-03-28 20:11:48 -04:00
@@ -130,7 +130,14 @@ async function installInContext (installType: string, packagesToInstall: Depende
|
||||
}
|
||||
await linkBins(path.join(ctx.root, 'node_modules'))
|
||||
if (!opts.ignoreScripts && ctx.pkg) {
|
||||
await mainPostInstall(ctx.pkg && ctx.pkg.scripts || {}, ctx.root, opts.production)
|
||||
const scripts = ctx.pkg && ctx.pkg.scripts || {}
|
||||
|
||||
if (scripts['postinstall']) {
|
||||
npmRun('postinstall', ctx.root)
|
||||
}
|
||||
if (installType === 'general' && scripts['prepublish']) {
|
||||
npmRun('prepublish', ctx.root)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,11 +193,6 @@ function adaptConfig (opts: StrictPnpmOptions) {
|
||||
}
|
||||
}
|
||||
|
||||
function mainPostInstall (scripts: Object, pkgRoot: string, isProductionInstall: boolean) {
|
||||
if (scripts['postinstall']) npmRun('postinstall', pkgRoot)
|
||||
if (!isProductionInstall && scripts['prepublish']) npmRun('prepublish', pkgRoot)
|
||||
}
|
||||
|
||||
function npmRun (scriptName: string, pkgRoot: string) {
|
||||
const result = runScriptSync('npm', ['run', scriptName], {
|
||||
cwd: pkgRoot,
|
||||
|
||||
@@ -508,7 +508,7 @@ test('postinstall is executed after installation', t => {
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('prepublish is executed after installation', t => {
|
||||
test('prepublish is not executed after installation with arguments', t => {
|
||||
prepare({
|
||||
scripts: {
|
||||
prepublish: 'echo "Hello world!"'
|
||||
@@ -517,6 +517,21 @@ test('prepublish is executed after installation', t => {
|
||||
|
||||
const result = spawnSync('ts-node', [pnpmBin, 'install', 'is-negative'])
|
||||
|
||||
t.equal(result.status, 0, 'installation was successfull')
|
||||
t.ok(result.stdout.toString().indexOf('Hello world!') === -1, 'prepublish script was not executed')
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('prepublish is executed after argumentless installation', t => {
|
||||
prepare({
|
||||
scripts: {
|
||||
prepublish: 'echo "Hello world!"'
|
||||
}
|
||||
})
|
||||
|
||||
const result = spawnSync('ts-node', [pnpmBin, 'install'])
|
||||
|
||||
t.equal(result.status, 0, 'installation was successfull')
|
||||
t.ok(result.stdout.toString().indexOf('Hello world!') !== -1, 'prepublish script was executed')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user