Skip to content

Commit cd4260f

Browse files
committed
fix(@angular-devkit/build-angular): correctly generate ServiceWorker config on Windows
Since #20518, the generation of the ServiceWorker configuration has been broken on Windows. The reason is the use of `path.posix.*` methods on non-POSIX paths, resulting in broken paths. I.e. we ended up with something like the following: ```js path.posix.relative('C:\\foo', 'C:\\foo\\bar/baz'); // Expected result: `bar/baz` // Actual result: `../C:\\foo\\bar/baz` ``` This caused the config generator to fail to find any files and thus fail to populate the config with cacheable assets. This commit fixes this by using platform-specific `path.*` methods for path manipulation and manually normalizing the path separators before returning the results. Fixes #20894
1 parent 1ab2ef9 commit cd4260f

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

packages/angular_devkit/build_angular/src/utils/service-worker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class CliFilesystem implements Filesystem {
4646
for await (const entry of await fs.opendir(dir)) {
4747
if (entry.isFile()) {
4848
// Uses posix paths since the service worker expects URLs
49-
items.push('/' + path.posix.relative(this.base, path.posix.join(dir, entry.name)));
49+
items.push('/' + path.relative(this.base, path.join(dir, entry.name)).replace(/\\/g, '/'));
5050
} else if (entry.isDirectory()) {
5151
subdirectories.push(path.join(dir, entry.name));
5252
}

0 commit comments

Comments
 (0)