Skip to content

Commit db45881

Browse files
dgp1130alan-agius4
authored andcommitted
refactor(@schematics/angular): generate Baseline date in ng generate config browserslist
This changes `ng generate config browserslist` to no longer generate a list of browsers used by Angular, but instead generate a dependency on `browserslist-config-baseline` and configures the date to match Angular. This used to generate a `.browserslistrc` file, however since the config is a single line and `browserslist-config-baseline` requires a separate config in the `package.json`, it feels a little more ergonomic to put both in the `package.json` file instead.
1 parent e809630 commit db45881

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

packages/schematics/angular/BUILD.bazel

+9
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
# found in the LICENSE file at https://angular.dev/license
55

66
load("@npm2//:defs.bzl", "npm_link_all_packages")
7+
load("//:constants.bzl", "BASELINE_DATE")
78
load("//tools:defaults.bzl", "copy_to_bin", "jasmine_test", "npm_package", "ts_project")
89
load("//tools:ts_json_schema.bzl", "ts_json_schema")
10+
load("//tools/baseline_browserslist:baseline_browserslist.bzl", "baseline_browserslist")
911

1012
licenses(["notice"])
1113

@@ -42,11 +44,18 @@ copy_to_bin(
4244
srcs = glob(["**/schema.json"]),
4345
)
4446

47+
baseline_browserslist(
48+
name = "angular_browserslist",
49+
out = "config/.browserslistrc",
50+
baseline = BASELINE_DATE,
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

+2-8
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,10 @@
22
# For additional information regarding the format and rule options, please see:
33
# https://github.com/browserslist/browserslist#queries
44

5-
# For the full list of supported browsers by the Angular framework, please see:
5+
# For Angular's browser support policy, please see:
66
# https://angular.dev/reference/versions#browser-support
77

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 { readFile } from 'node:fs/promises';
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 readFile(path.join(__dirname, '.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)