-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(@schematics/angular): change
browserslist
file name to `.brows…
…erslistrc` Closes: #15961
- Loading branch information
1 parent
6e33f44
commit b7a612f
Showing
6 changed files
with
96 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 0 additions & 12 deletions
12
packages/schematics/angular/application/files/browserslist.template
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
packages/schematics/angular/migrations/update-10/rename-browserslist-config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
import { Path, join } from '@angular-devkit/core'; | ||
import { DirEntry, Rule } from '@angular-devkit/schematics'; | ||
|
||
function visit(directory: DirEntry): Path[] { | ||
const files: Path[] = []; | ||
|
||
for (const path of directory.subfiles) { | ||
if (path !== 'browserslist') { | ||
continue; | ||
} | ||
|
||
files.push(join(directory.path, path)); | ||
} | ||
|
||
for (const path of directory.subdirs) { | ||
if (path === 'node_modules') { | ||
continue; | ||
} | ||
|
||
files.push(...visit(directory.dir(path))); | ||
} | ||
|
||
return files; | ||
} | ||
|
||
export default function (): Rule { | ||
return tree => { | ||
for (const path of visit(tree.root)) { | ||
tree.rename(path, path.replace(/browserslist$/, '.browserslistrc')); | ||
} | ||
}; | ||
} |
50 changes: 50 additions & 0 deletions
50
packages/schematics/angular/migrations/update-10/rename-browserslist-config_spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
import { EmptyTree } from '@angular-devkit/schematics'; | ||
import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing'; | ||
|
||
describe('Migration to rename Browserslist configurations', () => { | ||
const schematicName = 'rename-browserslist-config'; | ||
|
||
const schematicRunner = new SchematicTestRunner( | ||
'migrations', | ||
require.resolve('../migration-collection.json'), | ||
); | ||
|
||
let tree: UnitTestTree; | ||
beforeEach(() => { | ||
tree = new UnitTestTree(new EmptyTree()); | ||
}); | ||
|
||
it(`should rename file 'browserslist' to 'browserslistrc'`, async () => { | ||
tree.create('/browserslist', 'IE9'); | ||
tree.create('/src/app/home/browserslist', 'IE9'); | ||
|
||
const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise(); | ||
expect(newTree.exists('/.browserslistrc')).toBeTruthy(); | ||
expect(newTree.exists('/browserslist')).toBeFalsy(); | ||
|
||
expect(newTree.exists('/src/app/home/.browserslistrc')).toBeTruthy(); | ||
expect(newTree.exists('/src/app/home/browserslist')).toBeFalsy(); | ||
}); | ||
|
||
it(`should not rename "browserslist" file in 'node_modules'`, async () => { | ||
tree.create('/node_modules/browserslist', 'IE9'); | ||
|
||
const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise(); | ||
expect(newTree.exists('/node_modules/browserslist')).toBeTruthy(); | ||
expect(newTree.exists('/node_modules/.browserslistrc')).toBeFalsy(); | ||
}); | ||
|
||
it(`should not rename a folder which is named 'browserslist'`, async () => { | ||
tree.create('/app/browserslist/file.txt', 'content'); | ||
|
||
const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise(); | ||
expect(newTree.exists('/app/browserslist/file.txt')).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters