diff --git a/src/cmd/run.ts b/src/cmd/run.ts index bfb248d983..fce1f5de3f 100644 --- a/src/cmd/run.ts +++ b/src/cmd/run.ts @@ -2,7 +2,7 @@ import {PnpmOptions} from '../types' import {sync as runScriptSync} from '../runScript' export default function (input: string[], opts: PnpmOptions) { - runScriptSync('npm', ['run'].concat(input), { + return runScriptSync('npm', ['run'].concat(input), { cwd: process.cwd(), stdio: 'inherit', }) diff --git a/test/index.ts b/test/index.ts index 1f2de28308..7e27447869 100644 --- a/test/index.ts +++ b/test/index.ts @@ -5,3 +5,4 @@ import './uninstall' import './link' import './prune' import './cache' +import './run' diff --git a/test/packages/publish-all.sh b/test/packages/publish-all.sh index fde2783a63..4b76890bdf 100644 --- a/test/packages/publish-all.sh +++ b/test/packages/publish-all.sh @@ -74,3 +74,7 @@ cd ..; cd sh-hello-world; npm publish; cd ..; + +cd symlinks-preserved; +npm publish; +cd ..; diff --git a/test/packages/symlinks-preserved/index.js b/test/packages/symlinks-preserved/index.js new file mode 100644 index 0000000000..1713f603ab --- /dev/null +++ b/test/packages/symlinks-preserved/index.js @@ -0,0 +1,4 @@ +'use strict' +const fs = require('fs') + +module.exports = fs.realpathSync(__filename) !== __filename diff --git a/test/packages/symlinks-preserved/package.json b/test/packages/symlinks-preserved/package.json new file mode 100644 index 0000000000..fbd75f5ec2 --- /dev/null +++ b/test/packages/symlinks-preserved/package.json @@ -0,0 +1,4 @@ +{ + "name": "symlinks-preserved", + "version": "1.0.0" +} \ No newline at end of file diff --git a/test/run.ts b/test/run.ts new file mode 100644 index 0000000000..f7ac8d85b6 --- /dev/null +++ b/test/run.ts @@ -0,0 +1,35 @@ +import tape = require('tape') +import promisifyTape from 'tape-promise' +const test = promisifyTape(tape) +import semver = require('semver') +import fs = require('mz/fs') +import prepare from './support/prepare' +import testDefaults from './support/testDefaults' +import {installPkgs} from '../lib' +import runCmd from '../lib/cmd/run' + +const preserveSymlinksEnvVariable = semver.satisfies(process.version, '>=7.1.0') + +test('run node in scripts with preserve symlinks mode', async function (t) { + if (!preserveSymlinksEnvVariable) { + t.skip('this test is only for Node.js >= 7.1.0') + return + } + + prepare({ + scripts: { + test: 'node index' + } + }) + + await fs.writeFile('index.js', ` + const fs = require('fs') + const symlinksPreserved = require('symlinks-preserved') + fs.writeFileSync('test-result', symlinksPreserved, 'utf8') + `, 'utf8') + + await installPkgs(['symlinks-preserved'], testDefaults()) + const result = runCmd(['test'], {}) + t.equal(result.status, 0, 'executable exited with success') + t.equal(await fs.readFile('test-result', 'utf8'), 'true', 'symlinks are preserved') +})