( destPath: string, scriptNames: string | Iterable<string>, spawnOpts?: SpawnOptions, projectCreatedAt?: number )
| 1563 | } |
| 1564 | |
| 1565 | export async function runPackageJsonScript( |
| 1566 | destPath: string, |
| 1567 | scriptNames: string | Iterable<string>, |
| 1568 | spawnOpts?: SpawnOptions, |
| 1569 | projectCreatedAt?: number |
| 1570 | ) { |
| 1571 | assert(path.isAbsolute(destPath)); |
| 1572 | |
| 1573 | const { |
| 1574 | packageJson, |
| 1575 | cliType, |
| 1576 | lockfileVersion, |
| 1577 | packageJsonPackageManager, |
| 1578 | turboSupportsCorepackHome, |
| 1579 | } = await scanParentDirs(destPath, true); |
| 1580 | const scriptName = getScriptName( |
| 1581 | packageJson, |
| 1582 | typeof scriptNames === 'string' ? [scriptNames] : scriptNames |
| 1583 | ); |
| 1584 | if (!scriptName) return false; |
| 1585 | |
| 1586 | debug('Running user script...'); |
| 1587 | const runScriptTime = Date.now(); |
| 1588 | |
| 1589 | const opts: SpawnOptionsExtended = { |
| 1590 | cwd: destPath, |
| 1591 | ...spawnOpts, |
| 1592 | env: getEnvForPackageManager({ |
| 1593 | cliType, |
| 1594 | lockfileVersion, |
| 1595 | packageJsonPackageManager, |
| 1596 | env: cloneEnv(process.env, spawnOpts?.env), |
| 1597 | packageJsonEngines: packageJson?.engines, |
| 1598 | turboSupportsCorepackHome, |
| 1599 | projectCreatedAt, |
| 1600 | }), |
| 1601 | }; |
| 1602 | |
| 1603 | if (cliType === 'npm') { |
| 1604 | opts.prettyCommand = `npm run ${scriptName}`; |
| 1605 | } else if (cliType === 'pnpm') { |
| 1606 | opts.prettyCommand = `pnpm run ${scriptName}`; |
| 1607 | } else if (cliType === 'bun') { |
| 1608 | opts.prettyCommand = `bun run ${scriptName}`; |
| 1609 | } else if (cliType === 'vlt') { |
| 1610 | opts.prettyCommand = `vlt run ${scriptName}`; |
| 1611 | } else { |
| 1612 | opts.prettyCommand = `yarn run ${scriptName}`; |
| 1613 | } |
| 1614 | |
| 1615 | console.log(`Running "${opts.prettyCommand}"`); |
| 1616 | await spawnAsync(cliType, ['run', scriptName], opts); |
| 1617 | |
| 1618 | debug(`Script complete [${Date.now() - runScriptTime}ms]`); |
| 1619 | return true; |
| 1620 | } |
| 1621 | |
| 1622 | export async function runBundleInstall( |
no test coverage detected