(projectDir: string)
| 49 | * become unavailable. |
| 50 | */ |
| 51 | export async function resolveYarnScriptForProject(projectDir: string): Promise<YarnCommandInfo> { |
| 52 | let info: YarnCommandInfo | undefined; |
| 53 | |
| 54 | const yarnPathFromConfig = await getYarnPathFromConfigurationIfPresent(projectDir); |
| 55 | if (yarnPathFromConfig !== null) { |
| 56 | const relativePath = path.relative(projectDir, yarnPathFromConfig); |
| 57 | const isLocal = !relativePath.startsWith('..') && !path.isAbsolute(relativePath); |
| 58 | |
| 59 | let isTrusted = true; |
| 60 | if (isLocal) { |
| 61 | if (process.env['NG_DEV_TRUST_YARN_PATH'] === '1') { |
| 62 | isTrusted = true; |
| 63 | } else if (process.stdout.isTTY && process.stdin.isTTY) { |
| 64 | isTrusted = await Prompt.confirm({ |
| 65 | message: |
| 66 | `The project configures a local Yarn path: ${yarnPathFromConfig}.\n` + |
| 67 | `Do you trust this path and want to use it?`, |
| 68 | default: false, |
| 69 | }); |
| 70 | } else { |
| 71 | isTrusted = false; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | if (isTrusted) { |
| 76 | info = {binary: 'node', args: [yarnPathFromConfig]}; |
| 77 | } else { |
| 78 | Log.warn( |
| 79 | `Ignoring local Yarn path: ${yarnPathFromConfig} as it is not trusted.\n` + |
| 80 | `You can trust it by running with NG_DEV_TRUST_YARN_PATH=1 environment variable.`, |
| 81 | ); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | if (!info) { |
| 86 | const yarnPathFromNpmBin = await getYarnPathFromNpmGlobalBinaries(); |
| 87 | if (yarnPathFromNpmBin !== null) { |
| 88 | info = {binary: yarnPathFromNpmBin, args: []}; |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | info ??= {binary: 'yarn', args: []}; |
| 93 | |
| 94 | const yarnVersion = await getYarnVersion(info); |
| 95 | if (yarnVersion && Number(yarnVersion.split('.')[0]) < 2) { |
| 96 | info.args.push('--silent'); |
| 97 | info.legacy = true; |
| 98 | } |
| 99 | |
| 100 | return info; |
| 101 | } |
| 102 | |
| 103 | /** Gets the path to the Yarn binary from the NPM global binary directory. */ |
| 104 | export async function getYarnPathFromNpmGlobalBinaries(): Promise<string | null> { |
no test coverage detected