Skip to content

Commit 516e189

Browse files
committed
fix(@angular/cli): use project-local temporary directory in ng add
The 'ng add' command now attempts to use '.angular/cache' or 'node_modules' as the base for temporary directories when acquiring packages. This ensures that the package manager can inherit project-specific configuration (like '.npmrc' or '.yarnrc') during the installation of temporary packages. The implementation uses a fallback strategy, checking for candidate directories and defaulting to the system's temporary directory if none are found.
1 parent 3fc79b2 commit 516e189

File tree

1 file changed

+12
-0
lines changed
  • packages/angular/cli/src/commands/add

1 file changed

+12
-0
lines changed

packages/angular/cli/src/commands/add/cli.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,22 @@ export default class AddCommandModule
298298
context: AddCommandTaskContext,
299299
task: AddCommandTaskWrapper,
300300
): Promise<void> {
301+
let tempDirectory: string | undefined;
302+
for (const path of ['.angular/cache', 'node_modules']) {
303+
try {
304+
const directory = join(this.context.root, path);
305+
if ((await fs.stat(directory)).isDirectory()) {
306+
tempDirectory = directory;
307+
break;
308+
}
309+
} catch {}
310+
}
311+
301312
context.packageManager = await createPackageManager({
302313
cwd: this.context.root,
303314
logger: this.context.logger,
304315
dryRun: context.dryRun,
316+
tempDirectory,
305317
});
306318
task.output = `Using package manager: ${color.dim(context.packageManager.name)}`;
307319
}

0 commit comments

Comments
 (0)