Skip to content

Commit 68d986a

Browse files
committed
fixup! fix(@schematics/angular): avoid adding web worker snippet to server configuration files
1 parent 89c86cc commit 68d986a

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ function addSnippet(options: WebWorkerOptions): Rule {
4141
const siblingModules = host
4242
.getDir(options.path)
4343
.subfiles // Find all files that start with the same name, are ts files,
44-
// and aren't spec, module, or configuration files (including their server variants).
45-
.filter((f) => fileRegExp.test(f) && !/\.(module|spec|config|routes|server)\.ts$/.test(f))
44+
// and aren't spec, module, declaration, or configuration files (including their server variants).
45+
.filter((f) => fileRegExp.test(f) && !/\.(module|spec|config|routes|server|d)\.ts$/.test(f))
4646
// Sort alphabetically for consistency.
4747
.sort();
4848

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ describe('Web Worker Schematic', () => {
9696
});
9797

9898
it('should add snippet to the component file and not a server configuration file', async () => {
99-
appTree = await schematicRunner.runSchematic('server', { project: 'bar' }, appTree);
100-
const tree = await schematicRunner.runSchematic('web-worker', defaultOptions, appTree);
99+
const serverAppTree = await schematicRunner.runSchematic('server', { project: 'bar' }, appTree);
100+
const tree = await schematicRunner.runSchematic('web-worker', defaultOptions, serverAppTree);
101101

102102
const appComponent = tree.readContent('/projects/bar/src/app/app.ts');
103103
expect(appComponent).toContain(`new Worker(new URL('./${defaultOptions.name}.worker`);
@@ -115,6 +115,16 @@ describe('Web Worker Schematic', () => {
115115
expect(content).toContain(`new Worker(new URL('./observer.worker`);
116116
});
117117

118+
it('should not add snippet to a declaration file', async () => {
119+
appTree.create('/projects/bar/src/app/app.d.ts', 'declare const foo: string;\n');
120+
const tree = await schematicRunner.runSchematic('web-worker', defaultOptions, appTree);
121+
122+
expect(tree.readContent('/projects/bar/src/app/app.d.ts')).not.toContain('new Worker');
123+
expect(tree.readContent('/projects/bar/src/app/app.ts')).toContain(
124+
`new Worker(new URL('./${defaultOptions.name}.worker`,
125+
);
126+
});
127+
118128
it(`should add 'tsconfig.worker.json' outside of 'src' directory in root app`, async () => {
119129
const rootAppOptions = { ...appOptions, projectRoot: '', name: 'foo' };
120130
const workerOptions = { ...defaultOptions, project: 'foo' };

0 commit comments

Comments
 (0)