Skip to content

Commit 3ecf29b

Browse files
alan-agius4mgechev
authored andcommitted
fix(@schematics/angular): support adding web-worker to pre version 8 applications
Fixes #14791
1 parent a70932b commit 3ecf29b

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

packages/schematics/angular/web-worker/index.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import { JsonParseMode, join, normalize, parseJsonAst, strings, tags } from '@angular-devkit/core';
8+
import {
9+
JsonParseMode,
10+
dirname,
11+
join,
12+
normalize,
13+
parseJsonAst,
14+
strings,
15+
tags,
16+
} from '@angular-devkit/core';
917
import {
1018
Rule, SchematicContext, SchematicsException, Tree,
1119
apply, applyTemplates, chain, mergeWith, move, noop, url,
@@ -23,7 +31,10 @@ function addConfig(options: WebWorkerOptions, root: string, tsConfigPath: string
2331
context.logger.debug('updating project configuration.');
2432

2533
// Add worker glob exclusion to tsconfig.app.json.
26-
const workerGlob = 'src/**/*.worker.ts';
34+
// Projects pre version 8 should to have tsconfig.app.json inside their application
35+
const isInSrc = dirname(normalize(tsConfigPath)).endsWith('src');
36+
const workerGlob = `${isInSrc ? '' : 'src/'}**/*.worker.ts`;
37+
2738
const buffer = host.read(tsConfigPath);
2839
if (buffer) {
2940
const tsCfgAst = parseJsonAst(buffer.toString(), JsonParseMode.Loose);

packages/schematics/angular/web-worker/index_spec.ts

+13
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,17 @@ describe('Web Worker Schematic', () => {
114114
const { compilerOptions } = JSON.parse(tree.readContent(path));
115115
expect(compilerOptions.outDir).toBe('./out-tsc/worker');
116116
});
117+
118+
it('supports pre version 8 structure', async () => {
119+
const workspace = JSON.parse(appTree.readContent('/angular.json'));
120+
const tsConfigPath = '/projects/bar/src/tsconfig.app.json';
121+
workspace.projects.bar.architect.build.options.tsConfig = tsConfigPath;
122+
appTree.overwrite('/angular.json', JSON.stringify(workspace));
123+
appTree.rename('projects/bar/tsconfig.app.json', tsConfigPath);
124+
125+
const tree = await schematicRunner.runSchematicAsync('web-worker', defaultOptions, appTree)
126+
.toPromise();
127+
const { exclude } = JSON.parse(tree.readContent(tsConfigPath));
128+
expect(exclude).toContain('**/*.worker.ts');
129+
});
117130
});

0 commit comments

Comments
 (0)