@@ -12,7 +12,6 @@ import * as crypto from 'crypto';
12
12
import { createReadStream , promises as fs , constants as fsConstants } from 'fs' ;
13
13
import * as path from 'path' ;
14
14
import { pipeline } from 'stream' ;
15
- import { pathToFileURL } from 'url' ;
16
15
import { loadEsmModule } from './load-esm' ;
17
16
18
17
class CliFilesystem implements Filesystem {
@@ -63,34 +62,17 @@ class CliFilesystem implements Filesystem {
63
62
}
64
63
65
64
export async function augmentAppWithServiceWorker (
66
- projectRoot : Path ,
67
65
appRoot : Path ,
68
66
outputPath : Path ,
69
67
baseHref : string ,
70
68
ngswConfigPath ?: string ,
71
69
) : Promise < void > {
72
70
const distPath = getSystemPath ( normalize ( outputPath ) ) ;
73
- const systemProjectRoot = getSystemPath ( projectRoot ) ;
74
-
75
- // Find the service worker package
76
- const workerPath = require . resolve ( '@angular/service-worker/ngsw-worker.js' , {
77
- paths : [ systemProjectRoot ] ,
78
- } ) ;
79
- // Absolute paths on Windows must be `file://` URLs when using ESM. Otherwise,
80
- // `c:` would be interpreted as a protocol instead of a drive letter.
81
- const swConfigPath = pathToFileURL (
82
- require . resolve ( '@angular/service-worker/config' , {
83
- paths : [ systemProjectRoot ] ,
84
- } ) ,
85
- ) ;
86
71
87
72
// Determine the configuration file path
88
- let configPath ;
89
- if ( ngswConfigPath ) {
90
- configPath = getSystemPath ( normalize ( ngswConfigPath ) ) ;
91
- } else {
92
- configPath = path . join ( getSystemPath ( appRoot ) , 'ngsw-config.json' ) ;
93
- }
73
+ const configPath = ngswConfigPath
74
+ ? getSystemPath ( normalize ( ngswConfigPath ) )
75
+ : path . join ( getSystemPath ( appRoot ) , 'ngsw-config.json' ) ;
94
76
95
77
// Read the configuration file
96
78
let config : Config | undefined ;
@@ -113,7 +95,9 @@ export async function augmentAppWithServiceWorker(
113
95
// Once TypeScript provides support for keeping the dynamic import this workaround can be
114
96
// changed to a direct dynamic import.
115
97
const GeneratorConstructor = (
116
- await loadEsmModule < typeof import ( '@angular/service-worker/config' ) > ( swConfigPath )
98
+ await loadEsmModule < typeof import ( '@angular/service-worker/config' ) > (
99
+ '@angular/service-worker/config' ,
100
+ )
117
101
) . Generator ;
118
102
119
103
// Generate the manifest
@@ -124,6 +108,9 @@ export async function augmentAppWithServiceWorker(
124
108
const manifest = JSON . stringify ( output , null , 2 ) ;
125
109
await fs . writeFile ( path . join ( distPath , 'ngsw.json' ) , manifest ) ;
126
110
111
+ // Find the service worker package
112
+ const workerPath = require . resolve ( '@angular/service-worker/ngsw-worker.js' ) ;
113
+
127
114
// Write the worker code
128
115
await fs . copyFile (
129
116
workerPath ,
0 commit comments