Skip to content

Commit

Permalink
fix(workbox-build): make source map filename consistent with injected…
Browse files Browse the repository at this point in the history
… source file
  • Loading branch information
steverep committed May 2, 2024
1 parent f4a49da commit bf6c75a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
5 changes: 4 additions & 1 deletion packages/workbox-build/src/inject-manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ export async function injectManifest(
searchString: options.injectionPoint!,
});

filesToWrite[options.swDest] = source;
filesToWrite[options.swDest] = source.replace(
url!,
encodeURI(upath.basename(destPath)),
);
filesToWrite[destPath] = map;
} else {
// If there's no sourcemap associated with swSrc, a simple string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function translateURLToSourcemapPaths(
const possibleSrcPath = upath.resolve(upath.dirname(swSrc), url);
if (fse.existsSync(possibleSrcPath)) {
srcPath = possibleSrcPath;
destPath = upath.resolve(upath.dirname(swDest), url);
destPath = `${swDest}.map`;
} else {
warning = `${errors['cant-find-sourcemap']} ${possibleSrcPath}`;
}
Expand Down
13 changes: 8 additions & 5 deletions test/workbox-build/node/inject-manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ const upath = require('upath');
const tempy = require('tempy');

const {errors} = require('../../../packages/workbox-build/build/lib/errors');
const {
getSourceMapURL,
} = require('../../../packages/workbox-build/build/lib/get-source-map-url');
const {
injectManifest,
} = require('../../../packages/workbox-build/build/inject-manifest');
Expand Down Expand Up @@ -436,11 +439,8 @@ describe(`[workbox-build] inject-manifest.js (End to End)`, function () {
it(`should update the sourcemap to account for manifest injection`, async function () {
const outputDir = tempy.directory();
const swSrc = upath.join(SW_SRC_DIR, 'basic-with-sourcemap.js.nolint');
const swDest = upath.join(outputDir, 'basic-with-sourcemap.js');
const sourcemapDest = upath.join(
outputDir,
'basic-with-sourcemap.js.map',
);
const swDest = upath.join(outputDir, 'sw.js');
const sourcemapDest = `${swDest}.map`;
const options = Object.assign({}, BASE_OPTIONS, {
swDest,
swSrc,
Expand All @@ -459,6 +459,9 @@ describe(`[workbox-build] inject-manifest.js (End to End)`, function () {
);
expect(actualSourcemap).to.eql(expectedSourcemap);

const actualMapURL = getSourceMapURL(await fse.readFile(swDest, 'utf-8'));
expect(actualMapURL).to.eql(upath.basename(sourcemapDest));

// We can't validate the SW file contents.
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe(`[workbox-build] lib/translate-url-to-sourcemap-paths.ts`, function ()
'../../../../packages/workbox-build/build/lib/translate-url-to-sourcemap-paths';
const URL = 'sw.js.map';
const SWSRC = 'src/sw.js';
const SWDEST = 'dist/sw.js';
const SWDEST = 'dist/service-worker.js';

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

expect(destPath).to.eql('dist/sw.js.map');
expect(destPath).to.eql('dist/service-worker.js.map');
expect(srcPath).to.eq('src/sw.js.map');
expect(warning).to.be.undefined;
});
Expand Down
2 changes: 1 addition & 1 deletion test/workbox-build/static/expected-source-map.js.map

Large diffs are not rendered by default.

0 comments on commit bf6c75a

Please sign in to comment.