feat: override frozen-lockfile before lifecycle (#6877)

close #6865
This commit is contained in:
Khải
2023-07-29 22:28:42 +07:00
committed by GitHub
parent 32679f0ad4
commit 692197df3e
5 changed files with 46 additions and 1 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/lifecycle": patch
"pnpm": patch
---
Installation of a git-hosted dependency should not fail if the `pnpm-lock.yaml` file of the installed dependency is not up-to-date [#6865](https://github.com/pnpm/pnpm/issues/6865).

View File

@@ -61,7 +61,10 @@ export async function runLifecycleHook (
? 'silent'
: undefined
await lifecycle(m, stage, opts.pkgRoot, {
config: opts.rawConfig,
config: {
...opts.rawConfig,
'frozen-lockfile': false,
},
dir: opts.rootModulesDir,
extraBinPaths: opts.extraBinPaths ?? [],
extraEnv: {

View File

@@ -0,0 +1,7 @@
{
"name": "inspect-frozen-lockfile",
"version": "1.0.0",
"scripts": {
"postinstall": "rimraf output.json && node postinstall.js | json-append output.json"
}
}

View File

@@ -0,0 +1,13 @@
const value = process.env['npm_config_frozen_lockfile']
switch(value) {
case undefined:
process.stdout.write('unset')
break
case '':
process.stdout.write('empty string')
break
default:
process.stdout.write('string: ' + value)
break
}

View File

@@ -39,6 +39,22 @@ test('runLifecycleHook() escapes the args passed to the script', async () => {
expect((await import(path.join(pkgRoot, 'output.json'))).default).toStrictEqual(['Revert "feature (#1)"'])
})
test('runLifecycleHook() sets frozen-lockfile to false', async () => {
const pkgRoot = f.find('inspect-frozen-lockfile')
const pkg = await import(path.join(pkgRoot, 'package.json'))
await runLifecycleHook('postinstall', pkg, {
depPath: '/inspect-frozen-lockfile/1.0.0',
pkgRoot,
rawConfig: {
'frozen-lockfile': true,
},
rootModulesDir,
unsafePerm: true,
})
expect((await import(path.join(pkgRoot, 'output.json'))).default).toStrictEqual(['empty string'])
})
test('runPostinstallHooks()', async () => {
const pkgRoot = f.find('with-many-scripts')
await rimraf(path.join(pkgRoot, 'output.json'))