Skip to content

Commit

Permalink
Merge pull request #2580 from modernweb-dev/feat/remove-local-sw
Browse files Browse the repository at this point in the history
feat: remove local sw.js
  • Loading branch information
thepassle authored Dec 11, 2023
2 parents cdbc804 + 3ff231a commit 089dbc9
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 295 deletions.
5 changes: 5 additions & 0 deletions .changeset/sixty-cups-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@web/mocks": minor
---

feat: remove local sw.js, use the service worker as exported by msw instead so the integrity checksums of the SW and browser code are always aligned
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/mocks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"@web/storybook-prebuilt": "^0.1.37",
"@web/storybook-utils": "^1.0.0",
"lit": "^2.7.5 || ^3.0.0",
"msw": "2.0.10"
"msw": "^2.0.11"
},
"devDependencies": {
"@web/dev-server": "^0.4.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/mocks/rollup-plugin.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// @ts-nocheck

import fs from 'node:fs';
import { fileURLToPath } from 'node:url';
import { createRequire } from 'node:module';
import path from 'node:path';

const __dirname = fileURLToPath(new URL('.', import.meta.url));
const require = createRequire(import.meta.url);

export function mockRollupPlugin(
{ interceptor } = {
Expand All @@ -14,7 +14,7 @@ export function mockRollupPlugin(
return {
name: 'rollup-plugin-msw',
writeBundle(opts) {
const serviceWorkerPath = path.resolve(__dirname, './sw.js');
const serviceWorkerPath = require.resolve('msw/mockServiceWorker.js');
const sw = fs.readFileSync(serviceWorkerPath, 'utf8');
const outPath = path.join(opts.dir, '__msw_sw__.js');
fs.writeFileSync(outPath, sw);
Expand Down
285 changes: 0 additions & 285 deletions packages/mocks/sw.js

This file was deleted.

7 changes: 3 additions & 4 deletions packages/mocks/wds-plugin.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { createRequire } from 'node:module';
import { readFileSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import path from 'node:path';

const __dirname = fileURLToPath(new URL('.', import.meta.url));
const require = createRequire(import.meta.url);

export function mockPlugin() {
return {
Expand All @@ -12,7 +11,7 @@ export function mockPlugin() {
*/
serve(context) {
if (context.request.url === '/__msw_sw__.js') {
const serviceWorkerPath = path.resolve(__dirname, './sw.js');
const serviceWorkerPath = require.resolve('msw/mockServiceWorker.js');
return readFileSync(serviceWorkerPath, 'utf8');
}
},
Expand Down

0 comments on commit 089dbc9

Please sign in to comment.