Skip to content

Commit 6e7f4d9

Browse files
FrozenPandazalexeagle
authored andcommitted
fix(@schematics/angular): fix polyfill path resolution
1 parent d0bea7a commit 6e7f4d9

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

packages/schematics/angular/migrations/update-7/polyfill-metadata.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function _removeReflectFromPolyfills(tree: Tree, path: string) {
5252
* @param targetObject The target information.
5353
* @private
5454
*/
55-
function _updateProjectTarget(root: string, targetObject: json.JsonObject): Rule {
55+
function _updateProjectTarget(targetObject: json.JsonObject): Rule {
5656
// Make sure we're using the correct builder.
5757
if (targetObject.builder !== '@angular-devkit/build-angular:browser'
5858
|| !json.isJsonObject(targetObject.options)) {
@@ -63,7 +63,7 @@ function _updateProjectTarget(root: string, targetObject: json.JsonObject): Rule
6363
return noop();
6464
}
6565

66-
const polyfillsToUpdate = [`${root}/${options.polyfills}`];
66+
const polyfillsToUpdate = [options.polyfills];
6767
const configurations = targetObject.configurations;
6868
if (json.isJsonObject(configurations)) {
6969
for (const configName of Object.keys(configurations)) {
@@ -73,7 +73,7 @@ function _updateProjectTarget(root: string, targetObject: json.JsonObject): Rule
7373
if (json.isJsonObject(config)
7474
&& typeof config.polyfills == 'string'
7575
&& config.aot !== true) {
76-
polyfillsToUpdate.push(`${root}/${config.polyfills}`);
76+
polyfillsToUpdate.push(config.polyfills);
7777
}
7878
}
7979
}
@@ -125,7 +125,7 @@ export function polyfillMetadataRule(): Rule {
125125
for (const targetName of Object.keys(targets)) {
126126
const target = targets[targetName];
127127
if (json.isJsonObject(target)) {
128-
rules.push(_updateProjectTarget(project.root, target));
128+
rules.push(_updateProjectTarget(target));
129129
}
130130
}
131131
}

packages/schematics/angular/migrations/update-7/polyfill-metadata_spec.ts

+12
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,16 @@ describe('polyfillMetadataRule', () => {
8686

8787
expect(tree2.readContent(polyfillPath)).not.toMatch(/import .*es7.*reflect.*;/);
8888
});
89+
90+
it('should work as expected for a project with a root', async () => {
91+
const originalContent = JSON.parse(tree.readContent('angular.json'));
92+
originalContent.projects['migration-test'].root = 'src';
93+
tree.overwrite('angular.json', JSON.stringify(originalContent));
94+
const polyfillPath = '/src/polyfills.ts';
95+
tree.overwrite(polyfillPath, oldPolyfills);
96+
const tree2 = await schematicRunner.runSchematicAsync('migration-03', {}, tree.branch())
97+
.toPromise();
98+
99+
expect(tree2.readContent(polyfillPath)).not.toMatch(/import .*es7.*reflect.*;/);
100+
});
89101
});

0 commit comments

Comments
 (0)