From a2bbac072db14493ae9e1e72b104b47f5cd083f7 Mon Sep 17 00:00:00 2001 From: Jason Jean Date: Tue, 16 Oct 2018 10:55:18 -0400 Subject: [PATCH] fix(@schematics/angular): fix polyfill path resolution --- .../angular/migrations/update-7/polyfill-metadata.ts | 8 ++++---- .../migrations/update-7/polyfill-metadata_spec.ts | 12 ++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/schematics/angular/migrations/update-7/polyfill-metadata.ts b/packages/schematics/angular/migrations/update-7/polyfill-metadata.ts index 328457c8b2ff..895479d461bd 100644 --- a/packages/schematics/angular/migrations/update-7/polyfill-metadata.ts +++ b/packages/schematics/angular/migrations/update-7/polyfill-metadata.ts @@ -52,7 +52,7 @@ function _removeReflectFromPolyfills(tree: Tree, path: string) { * @param targetObject The target information. * @private */ -function _updateProjectTarget(root: string, targetObject: json.JsonObject): Rule { +function _updateProjectTarget(targetObject: json.JsonObject): Rule { // Make sure we're using the correct builder. if (targetObject.builder !== '@angular-devkit/build-angular:browser' || !json.isJsonObject(targetObject.options)) { @@ -63,7 +63,7 @@ function _updateProjectTarget(root: string, targetObject: json.JsonObject): Rule return noop(); } - const polyfillsToUpdate = [`${root}/${options.polyfills}`]; + const polyfillsToUpdate = [options.polyfills]; const configurations = targetObject.configurations; if (json.isJsonObject(configurations)) { for (const configName of Object.keys(configurations)) { @@ -73,7 +73,7 @@ function _updateProjectTarget(root: string, targetObject: json.JsonObject): Rule if (json.isJsonObject(config) && typeof config.polyfills == 'string' && config.aot !== true) { - polyfillsToUpdate.push(`${root}/${config.polyfills}`); + polyfillsToUpdate.push(config.polyfills); } } } @@ -125,7 +125,7 @@ export function polyfillMetadataRule(): Rule { for (const targetName of Object.keys(targets)) { const target = targets[targetName]; if (json.isJsonObject(target)) { - rules.push(_updateProjectTarget(project.root, target)); + rules.push(_updateProjectTarget(target)); } } } diff --git a/packages/schematics/angular/migrations/update-7/polyfill-metadata_spec.ts b/packages/schematics/angular/migrations/update-7/polyfill-metadata_spec.ts index beed4a5dbb58..a696e8ac9bc4 100644 --- a/packages/schematics/angular/migrations/update-7/polyfill-metadata_spec.ts +++ b/packages/schematics/angular/migrations/update-7/polyfill-metadata_spec.ts @@ -86,4 +86,16 @@ describe('polyfillMetadataRule', () => { expect(tree2.readContent(polyfillPath)).not.toMatch(/import .*es7.*reflect.*;/); }); + + it('should work as expected for a project with a root', async () => { + const originalContent = JSON.parse(tree.readContent('angular.json')); + originalContent.projects['migration-test'].root = 'src'; + tree.overwrite('angular.json', JSON.stringify(originalContent)); + const polyfillPath = '/src/polyfills.ts'; + tree.overwrite(polyfillPath, oldPolyfills); + const tree2 = await schematicRunner.runSchematicAsync('migration-03', {}, tree.branch()) + .toPromise(); + + expect(tree2.readContent(polyfillPath)).not.toMatch(/import .*es7.*reflect.*;/); + }); });