Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ jobs:
# flaky targets are retried. The larger machine type comes with 2x more SSD space.
os: [ubuntu-latest-4core]
node: [22]
subset: [yarn, pnpm]
subset: [yarn, pnpm, bun]
shard: [0, 1, 2]
runs-on: ${{ matrix.os }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ jobs:
# flaky targets are retried. The larger machine type comes with 2x more SSD space.
os: [ubuntu-latest-4core]
node: [22]
subset: [yarn, pnpm]
subset: [yarn, pnpm, bun]
shard: [0, 1, 2]
runs-on: ${{ matrix.os }}
steps:
Expand Down
4 changes: 3 additions & 1 deletion packages/angular/cli/src/commands/add/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,9 @@ export default class AddCommandModule
// Only show if installation will actually occur
task.title = 'Installing package';

if (context.savePackage === false) {
if (context.savePackage === false && packageManager.name !== PackageManager.Bun) {
// Bun has a `--no-save` option which we are using to
// install the package and not update the package.json and the lock file.
task.title += ' in temporary location';

// Temporary packages are located in a different directory
Expand Down
8 changes: 5 additions & 3 deletions packages/angular/cli/src/utilities/package-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class PackageManagerUtils {
/** Install a single package. */
async install(
packageName: string,
save: 'dependencies' | 'devDependencies' | true = true,
save: 'dependencies' | 'devDependencies' | boolean = true,
extraArgs: string[] = [],
cwd?: string,
): Promise<boolean> {
Expand All @@ -70,6 +70,8 @@ export class PackageManagerUtils {

if (save === 'devDependencies') {
installArgs.push(packageManagerArgs.saveDev);
} else if (save === false) {
installArgs.push(packageManagerArgs.noLockfile);
}

return this.run([...installArgs, ...extraArgs], { cwd, silent: true });
Expand Down Expand Up @@ -158,11 +160,11 @@ export class PackageManagerUtils {
};
case PackageManager.Bun:
return {
saveDev: '--development',
saveDev: '--dev',
install: 'add',
installAll: 'install',
prefix: '--cwd',
noLockfile: '',
noLockfile: '--no-save',
};
default:
return {
Expand Down
5 changes: 4 additions & 1 deletion tests/legacy-cli/e2e/assets/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ load("//tools:defaults.bzl", "copy_to_bin")

copy_to_bin(
name = "assets",
srcs = glob(["**"]),
srcs = glob(
include = ["**"],
exclude = ["BUILD.bazel"],
),
visibility = ["//visibility:public"],
)
2 changes: 1 addition & 1 deletion tests/legacy-cli/e2e/setup/100-global-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const PACKAGE_MANAGER_VERSION = {
'npm': '10.8.1',
'yarn': '1.22.22',
'pnpm': '10.17.1',
'bun': '1.2.21',
'bun': '1.3.2',
};

export default async function () {
Expand Down
2 changes: 1 addition & 1 deletion tests/legacy-cli/e2e/tests/commands/add/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ng } from '../../../utils/process';
import { expectToFail } from '../../../utils/utils';

export default async function () {
await symlinkFile(assetDir('add-collection'), `./node_modules/add-collection`, 'dir');
await symlinkFile(assetDir('add-collection-dir'), `./node_modules/add-collection`, 'dir');

await ng('add', 'add-collection');
await expectFileToExist('empty-file');
Expand Down
13 changes: 12 additions & 1 deletion tests/legacy-cli/e2e/tests/commands/add/dir.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import { cp } from 'node:fs/promises';
import { resolve } from 'node:path';
import { assetDir } from '../../../utils/assets';
import { expectFileToExist } from '../../../utils/fs';
import { ng } from '../../../utils/process';

export default async function () {
await ng('add', assetDir('add-collection'), '--name=blah', '--skip-confirmation');
const collectionName = 'add-collection-dir';
const dirCollectionPath = resolve(collectionName);

// Copy locally as bun doesn't install the dependency correctly if it has symlinks.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we report this to bun as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I’ll open an issue tomorrow

await cp(assetDir(collectionName), dirCollectionPath, {
recursive: true,
dereference: true,
});

await ng('add', dirCollectionPath, '--name=blah', '--skip-confirmation');
await expectFileToExist('blah');
}
48 changes: 34 additions & 14 deletions tests/legacy-cli/e2e/tests/commands/add/peer.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,44 @@
import assert from 'node:assert/strict';
import { resolve } from 'node:path';
import { cp } from 'node:fs/promises';
import { assetDir } from '../../../utils/assets';
import { ng } from '../../../utils/process';

const warning = 'Adding the package may not succeed.';
export default async function (): Promise<void> {
const warning = /Adding the package may not succeed/;

export default async function () {
const { stdout: bad } = await ng(
'add',
assetDir('add-collection-peer-bad'),
'--skip-confirmation',
const stdout1 = await runNgAdd('add-collection-peer-bad');
assert.match(
stdout1,
warning,
`Peer warning should be shown for add-collection-peer-bad but was not.`,
);
assert.match(bad, new RegExp(warning), 'peer warning not shown on bad package');

const { stdout: base } = await ng('add', assetDir('add-collection'), '--skip-confirmation');
assert.doesNotMatch(base, new RegExp(warning), 'peer warning shown on base package');
const stdout2 = await runNgAdd('add-collection-dir');
assert.doesNotMatch(
stdout2,
warning,
`Peer warning should NOT be shown for add-collection-dir but was.`,
);

const { stdout: good } = await ng(
'add',
assetDir('add-collection-peer-good'),
'--skip-confirmation',
const stdout3 = await runNgAdd('add-collection-peer-good');
assert.doesNotMatch(
stdout3,
warning,
`Peer warning should NOT be shown for add-collection-peer-good but was.`,
);
assert.doesNotMatch(good, new RegExp(warning), 'peer warning shown on good package');
}

async function runNgAdd(collectionName: string): Promise<string> {
const collectionPath = resolve(collectionName);

// Copy locally as bun doesn't install the dependency correctly if it has symlinks.
await cp(assetDir(collectionName), collectionPath, {
recursive: true,
dereference: true,
});

const { stdout } = await ng('add', collectionPath, '--skip-confirmation');

return stdout;
}
59 changes: 33 additions & 26 deletions tests/legacy-cli/e2e/tests/commands/add/secure-registry.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,49 @@
import { expectFileNotToExist, expectFileToExist } from '../../../utils/fs';
import { expectFileNotToExist, expectFileToExist, rimraf } from '../../../utils/fs';
import { getActivePackageManager, installWorkspacePackages } from '../../../utils/packages';
import { git, ng } from '../../../utils/process';
import { createNpmConfigForAuthentication } from '../../../utils/registry';
import { expectToFail } from '../../../utils/utils';

export default async function () {
// The environment variable has priority over the .npmrc
delete process.env['NPM_CONFIG_REGISTRY'];
const isNpm = getActivePackageManager() === 'npm';
const originalNpmConfigRegistry = process.env['NPM_CONFIG_REGISTRY'];
try {
// The environment variable has priority over the .npmrc
delete process.env['NPM_CONFIG_REGISTRY'];
const packageManager = getActivePackageManager();
const supportsUnscopedAuth = packageManager !== 'bun' && packageManager !== 'npm';
const command = ['add', '@angular/pwa', '--skip-confirmation'];

const command = ['add', '@angular/pwa', '--skip-confirmation'];
await expectFileNotToExist('public/manifest.webmanifest');
await expectFileNotToExist('public/manifest.webmanifest');

// Works with unscoped registry authentication details
if (!isNpm) {
// NPM no longer support unscoped.
await createNpmConfigForAuthentication(false);
// Works with unscoped registry authentication details
if (supportsUnscopedAuth) {
// Some package managers such as Bun and NPM do not support unscoped auth.
await createNpmConfigForAuthentication(false);
await ng(...command);
await expectFileToExist('public/manifest.webmanifest');
await git('clean', '-dxf');
}

// Works with scoped registry authentication details
await expectFileNotToExist('public/manifest.webmanifest');

await createNpmConfigForAuthentication(true);
await ng(...command);
await expectFileToExist('public/manifest.webmanifest');
await git('clean', '-dxf');
}
// Works with scoped registry authentication details
await expectFileNotToExist('public/manifest.webmanifest');

await createNpmConfigForAuthentication(true);
await ng(...command);
await expectFileToExist('public/manifest.webmanifest');
// Invalid authentication token
if (!supportsUnscopedAuth) {
// Some package managers such as Bun and NPM do not support unscoped auth.
await createNpmConfigForAuthentication(false, true);
await expectToFail(() => ng(...command));
}

// Invalid authentication token
if (isNpm) {
// NPM no longer support unscoped.
await createNpmConfigForAuthentication(false, true);
await createNpmConfigForAuthentication(true, true);
await expectToFail(() => ng(...command));
} finally {
process.env['NPM_CONFIG_REGISTRY'] = originalNpmConfigRegistry;
await git('clean', '-dxf');
await installWorkspacePackages();
}

await createNpmConfigForAuthentication(true, true);
await expectToFail(() => ng(...command));

await git('clean', '-dxf');
await installWorkspacePackages();
}