From c07e28639bae6017d224a2a586704b738a438284 Mon Sep 17 00:00:00 2001 From: Alan Date: Mon, 17 Jun 2019 12:54:16 +0200 Subject: [PATCH] fix(@schematics/angular): support adding web-worker to pre version 8 applications Fixes #14791 --- packages/schematics/angular/web-worker/index.ts | 15 +++++++++++++-- .../schematics/angular/web-worker/index_spec.ts | 13 +++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/packages/schematics/angular/web-worker/index.ts b/packages/schematics/angular/web-worker/index.ts index 012566b1df0a..2964937bd13f 100644 --- a/packages/schematics/angular/web-worker/index.ts +++ b/packages/schematics/angular/web-worker/index.ts @@ -5,7 +5,15 @@ * 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 { JsonParseMode, join, normalize, parseJsonAst, strings, tags } from '@angular-devkit/core'; +import { + JsonParseMode, + dirname, + join, + normalize, + parseJsonAst, + strings, + tags, +} from '@angular-devkit/core'; import { Rule, SchematicContext, SchematicsException, Tree, apply, applyTemplates, chain, mergeWith, move, noop, url, @@ -23,7 +31,10 @@ function addConfig(options: WebWorkerOptions, root: string, tsConfigPath: string context.logger.debug('updating project configuration.'); // Add worker glob exclusion to tsconfig.app.json. - const workerGlob = 'src/**/*.worker.ts'; + // Projects pre version 8 should to have tsconfig.app.json inside their application + const isInSrc = dirname(normalize(tsConfigPath)).endsWith('src'); + const workerGlob = `${isInSrc ? '' : 'src/'}**/*.worker.ts`; + const buffer = host.read(tsConfigPath); if (buffer) { const tsCfgAst = parseJsonAst(buffer.toString(), JsonParseMode.Loose); diff --git a/packages/schematics/angular/web-worker/index_spec.ts b/packages/schematics/angular/web-worker/index_spec.ts index a8f6520189c1..6843175d005c 100644 --- a/packages/schematics/angular/web-worker/index_spec.ts +++ b/packages/schematics/angular/web-worker/index_spec.ts @@ -114,4 +114,17 @@ describe('Web Worker Schematic', () => { const { compilerOptions } = JSON.parse(tree.readContent(path)); expect(compilerOptions.outDir).toBe('./out-tsc/worker'); }); + + it('supports pre version 8 structure', async () => { + const workspace = JSON.parse(appTree.readContent('/angular.json')); + const tsConfigPath = '/projects/bar/src/tsconfig.app.json'; + workspace.projects.bar.architect.build.options.tsConfig = tsConfigPath; + appTree.overwrite('/angular.json', JSON.stringify(workspace)); + appTree.rename('projects/bar/tsconfig.app.json', tsConfigPath); + + const tree = await schematicRunner.runSchematicAsync('web-worker', defaultOptions, appTree) + .toPromise(); + const { exclude } = JSON.parse(tree.readContent(tsConfigPath)); + expect(exclude).toContain('**/*.worker.ts'); + }); });