Skip to content

Commit 089dbc9

Browse files
authored
Merge pull request #2580 from modernweb-dev/feat/remove-local-sw
feat: remove local sw.js
2 parents cdbc804 + 3ff231a commit 089dbc9

File tree

6 files changed

+14
-295
lines changed

6 files changed

+14
-295
lines changed

.changeset/sixty-cups-decide.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@web/mocks": minor
3+
---
4+
5+
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

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/mocks/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"@web/storybook-prebuilt": "^0.1.37",
6767
"@web/storybook-utils": "^1.0.0",
6868
"lit": "^2.7.5 || ^3.0.0",
69-
"msw": "2.0.10"
69+
"msw": "^2.0.11"
7070
},
7171
"devDependencies": {
7272
"@web/dev-server": "^0.4.0",

packages/mocks/rollup-plugin.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// @ts-nocheck
22

33
import fs from 'node:fs';
4-
import { fileURLToPath } from 'node:url';
4+
import { createRequire } from 'node:module';
55
import path from 'node:path';
66

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

99
export function mockRollupPlugin(
1010
{ interceptor } = {
@@ -14,7 +14,7 @@ export function mockRollupPlugin(
1414
return {
1515
name: 'rollup-plugin-msw',
1616
writeBundle(opts) {
17-
const serviceWorkerPath = path.resolve(__dirname, './sw.js');
17+
const serviceWorkerPath = require.resolve('msw/mockServiceWorker.js');
1818
const sw = fs.readFileSync(serviceWorkerPath, 'utf8');
1919
const outPath = path.join(opts.dir, '__msw_sw__.js');
2020
fs.writeFileSync(outPath, sw);

packages/mocks/sw.js

Lines changed: 0 additions & 285 deletions
This file was deleted.

packages/mocks/wds-plugin.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
import { createRequire } from 'node:module';
12
import { readFileSync } from 'node:fs';
2-
import { fileURLToPath } from 'node:url';
3-
import path from 'node:path';
43

5-
const __dirname = fileURLToPath(new URL('.', import.meta.url));
4+
const require = createRequire(import.meta.url);
65

76
export function mockPlugin() {
87
return {
@@ -12,7 +11,7 @@ export function mockPlugin() {
1211
*/
1312
serve(context) {
1413
if (context.request.url === '/__msw_sw__.js') {
15-
const serviceWorkerPath = path.resolve(__dirname, './sw.js');
14+
const serviceWorkerPath = require.resolve('msw/mockServiceWorker.js');
1615
return readFileSync(serviceWorkerPath, 'utf8');
1716
}
1817
},

0 commit comments

Comments
 (0)