Skip to content

Commit

Permalink
fix(@schematics/angular): move and update existing src/browserslist
Browse files Browse the repository at this point in the history
Older projects have their `browserslist` file under the `src` folder.

Fixes #14232
  • Loading branch information
Alan Agius authored and alexeagle committed Apr 23, 2019
1 parent 5f44e64 commit 0a6df3e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Expand Up @@ -110,11 +110,18 @@ function updateBrowserlist(): Rule {
continue;
}

const browserslistPath = join(normalize(project.root), '/browserslist');
const browserslistPath = join(normalize(project.root), 'browserslist');
if (typeof project.sourceRoot === 'string') {
const srcBrowsersList = join(normalize(project.sourceRoot), 'browserslist');
if (tree.exists(srcBrowsersList)) {
tree.rename(srcBrowsersList, browserslistPath);
}
}

const source = tree.read(browserslistPath);
if (!source) {
tree.create(browserslistPath, browserslistContent);
} else {
} else if (!source.toString().toLowerCase().includes('chrome 41')) {
const recorder = tree.beginUpdate(browserslistPath);
recorder.insertRight(source.length, '\nChrome 41 # Googlebot');
tree.commitUpdate(recorder);
Expand Down
Expand Up @@ -92,5 +92,15 @@ describe('Migration to version 8', () => {
expect(tree2.readContent('/browserslist'))
.toContain('Support for Googlebot');
});

it('should move browserslist file if it exists in the sourceRoot', () => {
tree.create('/src/browserslist', 'last 2 Chrome versions');
tree.delete('/browserslist');
const tree2 = schematicRunner.runSchematic('migration-07', {}, tree.branch());
expect(tree2.exists('/browserslist')).toBe(true);
const content = tree2.readContent('/browserslist');
expect(content).toContain('Chrome 41');
expect(content).toContain('last 2 Chrome versions');
});
});
});

0 comments on commit 0a6df3e

Please sign in to comment.