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 { join , normalize } from '@angular-devkit/core' ;
89import {
910 Rule ,
1011 SchematicContext ,
@@ -23,6 +24,7 @@ import { addSymbolToNgModuleMetadata, insertImport, isImported } from '../utilit
2324import { InsertChange } from '../utility/change' ;
2425import { addPackageJsonDependency , getPackageJsonDependency } from '../utility/dependencies' ;
2526import { getAppModulePath } from '../utility/ng-ast-utils' ;
27+ import { relativePathToWorkspaceRoot } from '../utility/paths' ;
2628import { targetBuildNotFoundError } from '../utility/project-targets' ;
2729import { getWorkspace , updateWorkspace } from '../utility/workspace' ;
2830import { BrowserBuilderOptions } from '../utility/workspace-models' ;
@@ -136,18 +138,19 @@ export default function (options: ServiceWorkerOptions): Rule {
136138 const root = project . root ;
137139
138140 config . serviceWorker = true ;
139- config . ngswConfigPath = `${ root && ! root . endsWith ( '/' ) ? root + '/' : root } ngsw-config.json` ;
140-
141- const relativePathToWorkspaceRoot = project . root ?
142- project . root . split ( '/' ) . filter ( x => x !== '' ) . map ( x => '..' ) . join ( '/' ) : '.' ;
141+ config . ngswConfigPath = join ( normalize ( root ) , 'ngsw-config.json' ) ;
143142
144143 let { resourcesOutputPath = '' } = config ;
145144 if ( resourcesOutputPath ) {
146- resourcesOutputPath = '/' + resourcesOutputPath . split ( '/' ) . filter ( x => ! ! x ) . join ( '/' ) ;
145+ resourcesOutputPath = normalize ( `/ ${ resourcesOutputPath } ` ) ;
147146 }
148147
149148 const templateSource = apply ( url ( './files' ) , [
150- applyTemplates ( { ...options , resourcesOutputPath, relativePathToWorkspaceRoot } ) ,
149+ applyTemplates ( {
150+ ...options ,
151+ resourcesOutputPath,
152+ relativePathToWorkspaceRoot : relativePathToWorkspaceRoot ( project . root ) ,
153+ } ) ,
151154 move ( project . root ) ,
152155 ] ) ;
153156
0 commit comments