Skip to content

Commit

Permalink
fix(@angular/cli): cannot locate bin for temporary package
Browse files Browse the repository at this point in the history
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 6e34d1b)
  • Loading branch information
alan-agius4 committed May 14, 2021
1 parent da020d0 commit a817592
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/angular/cli/commands/add-impl.ts
Expand Up @@ -205,13 +205,13 @@ export class AddCommand extends SchematicCommand<AddCommandSchema> {
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) {
Expand Down
8 changes: 4 additions & 4 deletions packages/angular/cli/utilities/install-package.ts
Expand Up @@ -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-'));

Expand Down Expand Up @@ -121,7 +121,7 @@ export async function installTempPackage(

return {
status: await installPackage(packageName, packageManager, true, installArgs, tempPath),
tempPath,
tempNodeModules,
};
}

Expand All @@ -130,15 +130,15 @@ export async function runTempPackageBin(
packageManager: PackageManager = PackageManager.Npm,
args: string[] = [],
): Promise<number> {
const { status: code, tempPath } = await installTempPackage(packageName, packageManager);
const { status: code, tempNodeModules } = await installTempPackage(packageName, packageManager);
if (code !== 0) {
return code;
}

// 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
Expand Down

0 comments on commit a817592

Please sign in to comment.