Skip to content

Commit 070c2e0

Browse files
committed
refactor(@schematics/angular): use new .browserslistrc file in ng generate config
Note that the generated file does include `bl2bl` branding: ``` # This file was created by bl2bl2. # Learn more at https://github.com/web-platform-dx/bl2bl ``` I opted to leave that in as it is technically accurate, though might be a bit confusing to users in this context.
1 parent 8fd7982 commit 070c2e0

File tree

5 files changed

+17
-9
lines changed

5 files changed

+17
-9
lines changed

packages/angular/build/BUILD.bazel

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ bl2bl_bin.bl2bl(
4545
srcs = ["src/browserslist/package.json"],
4646
outs = ["src/browserslist/.browserslistrc"],
4747
chdir = "%s/src/browserslist" % package_name(),
48+
visibility = ["//packages/schematics/angular:__pkg__"],
4849
)
4950

5051
RUNTIME_ASSETS = glob(

packages/schematics/angular/BUILD.bazel

+9
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,20 @@ copy_to_bin(
4242
srcs = glob(["**/schema.json"]),
4343
)
4444

45+
# Copy the generated browserslist file into this package.
46+
genrule(
47+
name = "angular_browserslist",
48+
srcs = ["//packages/angular/build:angular_browserslist"],
49+
outs = [".browserslistrc"],
50+
cmd = "cp $< $@",
51+
)
52+
4553
RUNTIME_ASSETS = [
4654
"collection.json",
4755
"migrations/migration-collection.json",
4856
"package.json",
4957
"utility/latest-versions/package.json",
58+
":angular_browserslist",
5059
] + glob(
5160
include = [
5261
"*/schema.json",

packages/schematics/angular/config/files/.browserslistrc.template

+1-7
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,4 @@
88
# You can see what browsers were selected by your queries by running:
99
# npx browserslist
1010

11-
last 2 Chrome versions
12-
last 1 Firefox version
13-
last 2 Edge major versions
14-
last 2 Safari major versions
15-
last 2 iOS major versions
16-
last 2 Android major versions
17-
Firefox ESR
11+
<%= config %>

packages/schematics/angular/config/index.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
strings,
1818
url,
1919
} from '@angular-devkit/schematics';
20+
import { promises as fs } from 'node:fs';
2021
import { posix as path } from 'node:path';
2122
import { relativePathToWorkspaceRoot } from '../utility/paths';
2223
import { getWorkspace as readWorkspace, updateWorkspace } from '../utility/workspace';
@@ -42,10 +43,13 @@ function addBrowserslistConfig(options: ConfigOptions): Rule {
4243
throw new SchematicsException(`Project name "${options.project}" doesn't not exist.`);
4344
}
4445

46+
// Read Angular's default vendored `.browserslistrc` file.
47+
const config = await fs.readFile(require.resolve('../.browserslistrc'), 'utf8');
48+
4549
return mergeWith(
4650
apply(url('./files'), [
4751
filter((p) => p.endsWith('.browserslistrc.template')),
48-
applyTemplates({}),
52+
applyTemplates({ config }),
4953
move(project.root),
5054
]),
5155
);

packages/schematics/angular/config/index_spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ describe('Config Schematic', () => {
9494
describe(`when 'type' is 'browserslist'`, () => {
9595
it('should create a .browserslistrc file', async () => {
9696
const tree = await runConfigSchematic(ConfigType.Browserslist);
97-
expect(tree.exists('projects/foo/.browserslistrc')).toBeTrue();
97+
expect(tree.readContent('projects/foo/.browserslistrc')).toContain('Chrome >=');
9898
});
9999
});
100100
});

0 commit comments

Comments
 (0)