Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions packages/schematics/angular/web-worker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand Down
13 changes: 13 additions & 0 deletions packages/schematics/angular/web-worker/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});