Skip to content

Commit b7a612f

Browse files
alan-agius4mgechev
authored andcommittedApr 6, 2020
feat(@schematics/angular): change browserslist file name to .browserslistrc
Closes: #15961
1 parent 6e33f44 commit b7a612f

File tree

6 files changed

+96
-18
lines changed

6 files changed

+96
-18
lines changed
 

‎packages/angular_devkit/build_angular/test/browser/scripts-array_spec_large.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ describe('Browser Builder scripts array', () => {
9595
host.appendToFile('src/main.ts', '\nimport \'./input-script.js\';');
9696

9797
// Enable differential loading
98-
host.appendToFile('browserslist', '\nIE 10');
98+
host.appendToFile('.browserslistrc', '\nIE 10');
9999

100100
// Remove styles so we don't have to account for them in the index.html order check.
101101
const { files } = await browserBuild(architect, host, target, {

‎packages/schematics/angular/application/files/browserslist.template

-12
This file was deleted.

‎packages/schematics/angular/migrations/migration-collection.json

+5
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@
5959
"version": "10.0.0-beta.0",
6060
"factory": "./update-10/update-tslint",
6161
"description": "Update tslint to version 6."
62+
},
63+
"rename-browserslist-config": {
64+
"version": "10.0.0-beta.0",
65+
"factory": "./update-10/rename-browserslist-config",
66+
"description": "Renaming Browserslist configurations to '.browserslistrc'."
6267
}
6368
}
6469
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
import { Path, join } from '@angular-devkit/core';
9+
import { DirEntry, Rule } from '@angular-devkit/schematics';
10+
11+
function visit(directory: DirEntry): Path[] {
12+
const files: Path[] = [];
13+
14+
for (const path of directory.subfiles) {
15+
if (path !== 'browserslist') {
16+
continue;
17+
}
18+
19+
files.push(join(directory.path, path));
20+
}
21+
22+
for (const path of directory.subdirs) {
23+
if (path === 'node_modules') {
24+
continue;
25+
}
26+
27+
files.push(...visit(directory.dir(path)));
28+
}
29+
30+
return files;
31+
}
32+
33+
export default function (): Rule {
34+
return tree => {
35+
for (const path of visit(tree.root)) {
36+
tree.rename(path, path.replace(/browserslist$/, '.browserslistrc'));
37+
}
38+
};
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
import { EmptyTree } from '@angular-devkit/schematics';
9+
import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing';
10+
11+
describe('Migration to rename Browserslist configurations', () => {
12+
const schematicName = 'rename-browserslist-config';
13+
14+
const schematicRunner = new SchematicTestRunner(
15+
'migrations',
16+
require.resolve('../migration-collection.json'),
17+
);
18+
19+
let tree: UnitTestTree;
20+
beforeEach(() => {
21+
tree = new UnitTestTree(new EmptyTree());
22+
});
23+
24+
it(`should rename file 'browserslist' to 'browserslistrc'`, async () => {
25+
tree.create('/browserslist', 'IE9');
26+
tree.create('/src/app/home/browserslist', 'IE9');
27+
28+
const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise();
29+
expect(newTree.exists('/.browserslistrc')).toBeTruthy();
30+
expect(newTree.exists('/browserslist')).toBeFalsy();
31+
32+
expect(newTree.exists('/src/app/home/.browserslistrc')).toBeTruthy();
33+
expect(newTree.exists('/src/app/home/browserslist')).toBeFalsy();
34+
});
35+
36+
it(`should not rename "browserslist" file in 'node_modules'`, async () => {
37+
tree.create('/node_modules/browserslist', 'IE9');
38+
39+
const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise();
40+
expect(newTree.exists('/node_modules/browserslist')).toBeTruthy();
41+
expect(newTree.exists('/node_modules/.browserslistrc')).toBeFalsy();
42+
});
43+
44+
it(`should not rename a folder which is named 'browserslist'`, async () => {
45+
tree.create('/app/browserslist/file.txt', 'content');
46+
47+
const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise();
48+
expect(newTree.exists('/app/browserslist/file.txt')).toBeTruthy();
49+
});
50+
});

‎packages/schematics/angular/migrations/update-8/differential-loading_spec.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,12 @@ describe('Migration to version 8', () => {
105105
});
106106

107107
it(`should create browserslist file if it doesn't exist`, async () => {
108-
tree.delete('/browserslist');
109108
const tree2 = await schematicRunner.runSchematicAsync('migration-07', {}, tree.branch()).toPromise();
110109
expect(tree2.exists('/browserslist')).toBe(true);
111110
});
112111

113112
it('should move browserslist file if it exists in the sourceRoot', async () => {
114113
tree.create('/src/browserslist', 'last 2 Chrome versions');
115-
tree.delete('/browserslist');
116114
const tree2 = await schematicRunner.runSchematicAsync('migration-07', {}, tree.branch()).toPromise();
117115
expect(tree2.exists('/browserslist')).toBe(true);
118116
});
@@ -191,7 +189,6 @@ describe('Migration to version 8', () => {
191189
});
192190

193191
it(`should not update projects which browser builder is not 'build-angular:browser'`, async () => {
194-
tree.delete('/browserslist');
195192
const config = JSON.parse(tree.readContent('angular.json'));
196193
config.projects['migration-test'].architect.build.builder = '@dummy/builders:browser';
197194

@@ -201,8 +198,7 @@ describe('Migration to version 8', () => {
201198
});
202199

203200
it(`should move 'browserslist' to root when 'sourceRoot' is not defined`, async () => {
204-
tree.rename('/browserslist', '/src/browserslist');
205-
expect(tree.exists('/src/browserslist')).toBe(true);
201+
tree.create('/src/browserslist', 'content');
206202

207203
const config = JSON.parse(tree.readContent('angular.json'));
208204
config.projects['migration-test'].sourceRoot = undefined;

0 commit comments

Comments
 (0)
Please sign in to comment.