Skip to content

Commit bc24e36

Browse files
committed
fix(workbox-build): make source map filename consistent with injected source file
1 parent b001f20 commit bc24e36

File tree

5 files changed

+16
-10
lines changed

5 files changed

+16
-10
lines changed

packages/workbox-build/src/inject-manifest.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,10 @@ export async function injectManifest(
129129
searchString: options.injectionPoint!,
130130
});
131131

132-
filesToWrite[options.swDest] = source;
132+
filesToWrite[options.swDest] = source.replace(
133+
url!,
134+
encodeURI(upath.basename(destPath)),
135+
);
133136
filesToWrite[destPath] = map;
134137
} else {
135138
// If there's no sourcemap associated with swSrc, a simple string

packages/workbox-build/src/lib/translate-url-to-sourcemap-paths.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function translateURLToSourcemapPaths(
2828
const possibleSrcPath = upath.resolve(upath.dirname(swSrc), url);
2929
if (fse.existsSync(possibleSrcPath)) {
3030
srcPath = possibleSrcPath;
31-
destPath = upath.resolve(upath.dirname(swDest), url);
31+
destPath = `${swDest}.map`;
3232
} else {
3333
warning = `${errors['cant-find-sourcemap']} ${possibleSrcPath}`;
3434
}

test/workbox-build/node/inject-manifest.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ const upath = require('upath');
1313
const tempy = require('tempy');
1414

1515
const {errors} = require('../../../packages/workbox-build/build/lib/errors');
16+
const {
17+
getSourceMapURL,
18+
} = require('../../../packages/workbox-build/build/lib/get-source-map-url');
1619
const {
1720
injectManifest,
1821
} = require('../../../packages/workbox-build/build/inject-manifest');
@@ -436,11 +439,8 @@ describe(`[workbox-build] inject-manifest.js (End to End)`, function () {
436439
it(`should update the sourcemap to account for manifest injection`, async function () {
437440
const outputDir = tempy.directory();
438441
const swSrc = upath.join(SW_SRC_DIR, 'basic-with-sourcemap.js.nolint');
439-
const swDest = upath.join(outputDir, 'basic-with-sourcemap.js');
440-
const sourcemapDest = upath.join(
441-
outputDir,
442-
'basic-with-sourcemap.js.map',
443-
);
442+
const swDest = upath.join(outputDir, 'sw.js');
443+
const sourcemapDest = `${swDest}.map`;
444444
const options = Object.assign({}, BASE_OPTIONS, {
445445
swDest,
446446
swSrc,
@@ -459,6 +459,9 @@ describe(`[workbox-build] inject-manifest.js (End to End)`, function () {
459459
);
460460
expect(actualSourcemap).to.eql(expectedSourcemap);
461461

462+
const actualMapURL = getSourceMapURL(await fse.readFile(swDest, 'utf-8'));
463+
expect(actualMapURL).to.eql(upath.basename(sourcemapDest));
464+
462465
// We can't validate the SW file contents.
463466
});
464467

test/workbox-build/node/lib/translate-url-to-sourcemap-paths.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe(`[workbox-build] lib/translate-url-to-sourcemap-paths.ts`, function ()
1616
'../../../../packages/workbox-build/build/lib/translate-url-to-sourcemap-paths';
1717
const URL = 'sw.js.map';
1818
const SWSRC = 'src/sw.js';
19-
const SWDEST = 'dist/sw.js';
19+
const SWDEST = 'dist/service-worker.js';
2020

2121
it(`should return undefined paths when url is undefined`, function () {
2222
const {translateURLToSourcemapPaths} = require(MODULE_PATH);
@@ -80,7 +80,7 @@ describe(`[workbox-build] lib/translate-url-to-sourcemap-paths.ts`, function ()
8080
SWDEST,
8181
);
8282

83-
expect(destPath).to.eql('dist/sw.js.map');
83+
expect(destPath).to.eql('dist/service-worker.js.map');
8484
expect(srcPath).to.eq('src/sw.js.map');
8585
expect(warning).to.be.undefined;
8686
});

test/workbox-build/static/expected-source-map.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)