Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: run scripts without --unsafe-perm #4369

Merged
merged 3 commits into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/silent-eagles-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@pnpm/lifecycle": major
"pnpm": major
---

Allow to execute a lifecycle script in a directory that doesn't match the package's name. Previously this was only allowed with the `--unsafe-perm` CLI option [#3709](https://github.com/pnpm/pnpm/issues/3709).
18 changes: 0 additions & 18 deletions packages/core/test/install/lifecycleScripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,24 +128,6 @@ test('run install scripts in the current project when its name is different than
expect(output).toStrictEqual(['preinstall', 'install', 'postinstall'])
})

test('do not run install scripts if unsafePerm is false', async () => {
prepareEmpty()
const opts = await testDefaults({ fastUnpack: false, unsafePerm: false })
const manifest = await addDependenciesToPackage({
name: 'different-name',
scripts: {
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',
},
}, ['json-append@1.1.1'], opts)
await install(manifest, opts)

const outputExists = await exists('output.json')

expect(outputExists).toBeFalsy()
})

test('installation fails if lifecycle script fails', async () => {
prepareEmpty()

Expand Down
2 changes: 1 addition & 1 deletion packages/lifecycle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"dependencies": {
"@pnpm/core-loggers": "workspace:6.1.3",
"@pnpm/directory-fetcher": "workspace:1.0.5",
"@pnpm/npm-lifecycle": "^1.0.4",
"@pnpm/npm-lifecycle": "^2.0.0-1",
"@pnpm/read-package-json": "workspace:5.0.10",
"@pnpm/store-controller-types": "workspace:11.0.11",
"@pnpm/types": "workspace:7.9.0",
Expand Down
26 changes: 11 additions & 15 deletions packages/pnpm/test/install/lifecycleScripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,24 +116,20 @@ test('dependency should not be added to package.json and lockfile if it was not
test('node-gyp is in the PATH', async () => {
prepare({
scripts: {
test: 'node-gyp --help',
test: 'echo $PATH && node-gyp --help',
},
})

// `npm test` adds node-gyp to the PATH
// it is removed here to test that pnpm adds it
const initialPath = process.env.PATH

if (typeof initialPath !== 'string') throw new Error('PATH is not defined')

process.env[PATH] = initialPath
.split(path.delimiter)
.filter((p: string) => !p.includes('node-gyp-bin') && !p.includes('npm'))
.join(path.delimiter)

const result = execPnpmSync(['test'])

process.env[PATH] = initialPath
const result = execPnpmSync(['test'], {
env: {
// `npm test` adds node-gyp to the PATH
// it is removed here to test that pnpm adds it
[PATH]: process.env[PATH]!
.split(path.delimiter)
.filter((p: string) => !p.includes('node-gyp-bin'))
.join(path.delimiter),
},
})

expect(result.status).toBe(0)
})
42 changes: 35 additions & 7 deletions pnpm-lock.yaml

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