Skip to content

Commit f1c95a4

Browse files
committed
refactor(@angular/cli): support project-root strategy for temporary packages in bun
This change introduces a 'project-root' strategy for acquiring temporary packages, which is now enabled for Bun. Bun has difficulty discovering and using configuration files (like '.npmrc') when executed in an isolated temporary directory. With the 'project-root' strategy, 'bun add' is executed directly in the project's root directory using the '--no-save' flag. This ensures correct configuration inheritance and reliable package resolution. The cleanup for this strategy is currently a no-op to avoid potentially destructive deletions within the project's 'node_modules'.
1 parent eeecf85 commit f1c95a4

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

packages/angular/cli/src/package-managers/package-manager-descriptor.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ export interface PackageManagerDescriptor {
6565
/** The flag to ignore peer dependency warnings/errors. */
6666
readonly ignorePeerDependenciesFlag?: string;
6767

68+
/**
69+
* The strategy to use when acquiring a temporary package.
70+
* - `temporary-directory`: The package is installed in a separate temporary directory. (Default)
71+
* - `project-root`: The package is installed in the project root (e.g. `node_modules`), but not saved to `package.json`.
72+
*/
73+
readonly tempPackageStrategy?: 'temporary-directory' | 'project-root';
74+
75+
/** The flag to install a package without saving it to `package.json`. Used with `project-root` strategy. */
76+
readonly noSaveFlag?: string;
77+
6878
/** A function that returns the arguments and environment variables to use a custom registry. */
6979
readonly getRegistryOptions?: (registry: string) => {
7080
args?: string[];
@@ -141,6 +151,7 @@ export const SUPPORTED_PACKAGE_MANAGERS = {
141151
saveExactFlag: '--save-exact',
142152
saveTildeFlag: '--save-tilde',
143153
saveDevFlag: '--save-dev',
154+
noSaveFlag: '--no-save',
144155
noLockfileFlag: '--no-package-lock',
145156
ignoreScriptsFlag: '--ignore-scripts',
146157
ignorePeerDependenciesFlag: '--force',
@@ -242,6 +253,8 @@ export const SUPPORTED_PACKAGE_MANAGERS = {
242253
saveExactFlag: '--exact',
243254
saveTildeFlag: '', // Bun does not have a flag for tilde, it defaults to caret.
244255
saveDevFlag: '--development',
256+
noSaveFlag: '--no-save',
257+
tempPackageStrategy: 'project-root',
245258
noLockfileFlag: '', // Bun does not have a flag for this.
246259
ignoreScriptsFlag: '--ignore-scripts',
247260
getRegistryOptions: (registry: string) => ({ args: ['--registry', registry] }),

packages/angular/cli/src/package-managers/package-manager.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,18 @@ export class PackageManager {
544544
specifier: string,
545545
options: { registry?: string; ignoreScripts?: boolean } = {},
546546
): Promise<{ workingDirectory: string; cleanup: () => Promise<void> }> {
547+
if (this.descriptor.tempPackageStrategy === 'project-root') {
548+
const flags = [
549+
options.ignoreScripts ? this.descriptor.ignoreScriptsFlag : '',
550+
this.descriptor.noSaveFlag,
551+
].filter((flag): flag is string => !!flag);
552+
const args = [this.descriptor.addCommand, specifier, ...flags];
553+
554+
await this.#run(args, { ...options, cwd: this.cwd });
555+
556+
return { workingDirectory: this.cwd, cleanup: async () => {} };
557+
}
558+
547559
const workingDirectory = await this.host.createTempDirectory(this.options.tempDirectory);
548560
const cleanup = () => this.host.deleteDirectory(workingDirectory);
549561

0 commit comments

Comments
 (0)