Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: "pnpm run" supports package.{json5,yaml}
ref #1803
- Loading branch information
Showing
6 changed files
with
68 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import runLifecycleHooks from '@pnpm/lifecycle' | ||
import { readImporterManifestOnly } from '@pnpm/read-importer-manifest' | ||
import { realNodeModulesDir } from '@pnpm/utils' | ||
|
||
export default async function ( | ||
args: string[], | ||
opts: { | ||
prefix: string, | ||
rawNpmConfig: object, | ||
argv: { | ||
cooked: string[], | ||
original: string[], | ||
remain: string[], | ||
}, | ||
}, | ||
command: string, | ||
) { | ||
const manifest = await readImporterManifestOnly(opts.prefix) | ||
const scriptName = args[0] | ||
if (!manifest.scripts || !manifest.scripts[scriptName]) { | ||
const err = new Error(`Missing script: ${scriptName}`) | ||
err['code'] = 'ERR_PNPM_NO_SCRIPT' | ||
throw err | ||
} | ||
const dashDashIndex = opts.argv.cooked.indexOf('--') | ||
const lifecycleOpts = { | ||
args: dashDashIndex === -1 ? [] : opts.argv.cooked.slice(dashDashIndex + 1), | ||
depPath: opts.prefix, | ||
pkgRoot: opts.prefix, | ||
rawNpmConfig: opts.rawNpmConfig, | ||
rootNodeModulesDir: await realNodeModulesDir(opts.prefix), | ||
stdio: 'inherit', | ||
unsafePerm: true, // when running scripts explicitly, assume that they're trusted. | ||
} | ||
if (manifest.scripts[`pre${scriptName}`]) { | ||
await runLifecycleHooks(`pre${scriptName}`, manifest, lifecycleOpts) | ||
} | ||
await runLifecycleHooks(scriptName, manifest, lifecycleOpts) | ||
if (manifest.scripts[`post${scriptName}`]) { | ||
await runLifecycleHooks(`post${scriptName}`, manifest, lifecycleOpts) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters