Skip to content

Commit a916c1f

Browse files
committed
Fix scope path to end with slash
1 parent d4fa563 commit a916c1f

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

convert/convertManifest.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ export function convertManifest(dataDir: string, verbose: number) {
2525
line = ` "start_url" : "${path}/",`;
2626
}
2727
if (line.includes('scope')) {
28-
const path = process.env.BUILD_BASE_PATH ? process.env.BUILD_BASE_PATH : '/';
28+
const path = process.env.BUILD_BASE_PATH
29+
? process.env.BUILD_BASE_PATH.endsWith('/')
30+
? process.env.BUILD_BASE_PATH
31+
: process.env.BUILD_BASE_PATH + '/'
32+
: '/';
2933
line = ` "scope" : "${path}",`;
3034
}
3135
if (line.includes('"src":') && line.includes('./icons')) {

svelte.config.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ const packageJson = JSON.parse(readFileSync('package.json', 'utf-8'));
77
const templateVersion = packageJson.version;
88
const buildTimestamp = Date.now();
99

10+
// Scope should end with a slash if defined
11+
// BUILD_BASE_PATH should not have a trailing slash, but just make sure
12+
const serviceWorkerScope = process.env.BUILD_BASE_PATH
13+
? process.env.BUILD_BASE_PATH.endsWith('/')
14+
? process.env.BUILD_BASE_PATH
15+
: process.env.BUILD_BASE_PATH + '/'
16+
: '/';
17+
1018
/** @type {import('@sveltejs/kit').Config} */
1119
const config = {
1220
// Consult https://github.com/sveltejs/svelte-preprocess
@@ -34,7 +42,7 @@ const config = {
3442
},
3543
serviceWorker: {
3644
options: {
37-
scope: process.env.BUILD_BASE_PATH
45+
scope: serviceWorkerScope
3846
}
3947
},
4048
version: {

0 commit comments

Comments
 (0)