Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(workbox-build): make source map filename consistent with injected source file #3234

Open
wants to merge 1 commit into
base: v7
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.