From a155cab522134534d9079b1d859cb8563848d140 Mon Sep 17 00:00:00 2001 From: Santosh Yadav Date: Mon, 20 May 2019 19:30:49 +0530 Subject: [PATCH 1/2] fix(@schematics/angular): webworker snippet should not generate to module Fixes #14467 --- packages/schematics/angular/web-worker/index.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/schematics/angular/web-worker/index.ts b/packages/schematics/angular/web-worker/index.ts index 717a3741bfe4..e00db6e17b8b 100644 --- a/packages/schematics/angular/web-worker/index.ts +++ b/packages/schematics/angular/web-worker/index.ts @@ -63,8 +63,10 @@ function addSnippet(options: WebWorkerOptions): Rule { } const siblingModules = host.getDir(options.path).subfiles - // Find all files that start with the same name, are ts files, and aren't spec files. - .filter(f => f.startsWith(options.name) && f.endsWith('.ts') && !f.endsWith('spec.ts')) + // Find all files that start with the same name, are ts files, + // and aren't spec or module files. + .filter(f => f.startsWith(options.name) && f.endsWith('.ts') + && !f.endsWith('spec.ts') && !f.endsWith('-.module.ts')) // Sort alphabetically for consistency. .sort(); From 50ceb4d41b625936fbe32ffe3441125ea8ceaec2 Mon Sep 17 00:00:00 2001 From: Alan Date: Tue, 21 May 2019 08:08:27 +0200 Subject: [PATCH 2/2] refactor: update file filtering logic for webworker snippet Insertion --- packages/schematics/angular/web-worker/index.ts | 4 ++-- packages/schematics/angular/web-worker/index_spec.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/schematics/angular/web-worker/index.ts b/packages/schematics/angular/web-worker/index.ts index e00db6e17b8b..012566b1df0a 100644 --- a/packages/schematics/angular/web-worker/index.ts +++ b/packages/schematics/angular/web-worker/index.ts @@ -62,11 +62,11 @@ function addSnippet(options: WebWorkerOptions): Rule { return; } + const fileRegExp = new RegExp(`^${options.name}.*\.ts`); const siblingModules = host.getDir(options.path).subfiles // Find all files that start with the same name, are ts files, // and aren't spec or module files. - .filter(f => f.startsWith(options.name) && f.endsWith('.ts') - && !f.endsWith('spec.ts') && !f.endsWith('-.module.ts')) + .filter(f => fileRegExp.test(f) && !/(module|spec)\.ts$/.test(f)) // Sort alphabetically for consistency. .sort(); diff --git a/packages/schematics/angular/web-worker/index_spec.ts b/packages/schematics/angular/web-worker/index_spec.ts index bc68cba035d5..a8f6520189c1 100644 --- a/packages/schematics/angular/web-worker/index_spec.ts +++ b/packages/schematics/angular/web-worker/index_spec.ts @@ -11,7 +11,7 @@ import { Schema as WorkspaceOptions } from '../workspace/schema'; import { Schema as WebWorkerOptions } from './schema'; -describe('Service Worker Schematic', () => { +describe('Web Worker Schematic', () => { const schematicRunner = new SchematicTestRunner( '@schematics/angular', require.resolve('../collection.json'), @@ -35,7 +35,7 @@ describe('Service Worker Schematic', () => { name: 'bar', inlineStyle: false, inlineTemplate: false, - routing: false, + routing: true, skipTests: false, skipPackageJson: false, };