From a8175921880271568066f15e8d3204c411967e88 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Fri, 14 May 2021 09:50:03 +0200 Subject: [PATCH] fix(@angular/cli): cannot locate bin for temporary package This fixes an issue where the installation of the temporary Angular CLI failed with `Cannot locate bin for temporary package: @angular/cli.` (cherry picked from commit 6e34d1bf897dcbf76d8edd40a3d70e4d3f190312) --- packages/angular/cli/commands/add-impl.ts | 4 ++-- packages/angular/cli/utilities/install-package.ts | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/angular/cli/commands/add-impl.ts b/packages/angular/cli/commands/add-impl.ts index 7f3300d5d1ca..edb3d4fee0d5 100644 --- a/packages/angular/cli/commands/add-impl.ts +++ b/packages/angular/cli/commands/add-impl.ts @@ -205,13 +205,13 @@ export class AddCommand extends SchematicCommand { if (savePackage === false) { // Temporary packages are located in a different directory // Hence we need to resolve them using the temp path - const { status, tempPath } = await installTempPackage( + const { status, tempNodeModules } = await installTempPackage( packageIdentifier.raw, packageManager, options.registry ? [`--registry="${options.registry}"`] : undefined, ); const resolvedCollectionPath = require.resolve(join(collectionName, 'package.json'), { - paths: [tempPath], + paths: [tempNodeModules], }); if (status !== 0) { diff --git a/packages/angular/cli/utilities/install-package.ts b/packages/angular/cli/utilities/install-package.ts index 5d010c52967a..9b499e9cd62f 100644 --- a/packages/angular/cli/utilities/install-package.ts +++ b/packages/angular/cli/utilities/install-package.ts @@ -78,7 +78,7 @@ export async function installTempPackage( extraArgs?: string[], ): Promise<{ status: 1 | 0; - tempPath: string; + tempNodeModules: string; }> { const tempPath = mkdtempSync(join(realpathSync(tmpdir()), 'angular-cli-packages-')); @@ -121,7 +121,7 @@ export async function installTempPackage( return { status: await installPackage(packageName, packageManager, true, installArgs, tempPath), - tempPath, + tempNodeModules, }; } @@ -130,7 +130,7 @@ export async function runTempPackageBin( packageManager: PackageManager = PackageManager.Npm, args: string[] = [], ): Promise { - const { status: code, tempPath } = await installTempPackage(packageName, packageManager); + const { status: code, tempNodeModules } = await installTempPackage(packageName, packageManager); if (code !== 0) { return code; } @@ -138,7 +138,7 @@ export async function runTempPackageBin( // Remove version/tag etc... from package name // Ex: @angular/cli@latest -> @angular/cli const packageNameNoVersion = packageName.substring(0, packageName.lastIndexOf('@')); - const pkgLocation = join(tempPath, packageNameNoVersion); + const pkgLocation = join(tempNodeModules, packageNameNoVersion); const packageJsonPath = join(pkgLocation, 'package.json'); // Get a binary location for this package