From 6b5a840179cca0eeb6741b13b44173db03e336ee Mon Sep 17 00:00:00 2001
From: Hiroshi Ogawa
Date: Tue, 6 Aug 2024 09:07:38 +0900
Subject: [PATCH 1/6] fix(worker): fix `injectScripts` injection
---
packages/vite/src/node/plugins/worker.ts | 2 +-
playground/worker/classic-worker.js | 2 ++
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/packages/vite/src/node/plugins/worker.ts b/packages/vite/src/node/plugins/worker.ts
index dcaed0473e13b1..2e614ec7e0fa85 100644
--- a/packages/vite/src/node/plugins/worker.ts
+++ b/packages/vite/src/node/plugins/worker.ts
@@ -265,7 +265,7 @@ export function webWorkerPlugin(config: ResolvedConfig): Plugin {
}
if (injectEnv) {
const s = new MagicString(raw)
- s.prepend(injectEnv)
+ s.prepend(injectEnv + ';\n')
return {
code: s.toString(),
map: s.generateMap({ hires: 'boundary' }),
diff --git a/playground/worker/classic-worker.js b/playground/worker/classic-worker.js
index be6fa357e70ec4..d68c61c14fd78f 100644
--- a/playground/worker/classic-worker.js
+++ b/playground/worker/classic-worker.js
@@ -1,3 +1,5 @@
+(() => {})() // this is to test `importScripts` injection doesn't break the code
+
let base = `/${self.location.pathname.split('/')[1]}`
if (base.endsWith('.js') || base === `/worker-entries`) base = '' // for dev
From 10fb68df064220ab72e2edffe21a99f689319405 Mon Sep 17 00:00:00 2001
From: Hiroshi Ogawa
Date: Tue, 6 Aug 2024 09:12:53 +0900
Subject: [PATCH 2/6] chore: prettier-ignore
---
playground/worker/classic-worker.js | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/playground/worker/classic-worker.js b/playground/worker/classic-worker.js
index d68c61c14fd78f..73de876270d54e 100644
--- a/playground/worker/classic-worker.js
+++ b/playground/worker/classic-worker.js
@@ -1,4 +1,5 @@
-(() => {})() // this is to test `importScripts` injection doesn't break the code
+// prettier-ignore
+;(() => {})() // this is to test `importScripts` injection doesn't break the code
let base = `/${self.location.pathname.split('/')[1]}`
if (base.endsWith('.js') || base === `/worker-entries`) base = '' // for dev
From a2e648bed9ac96eccf858bf7c612a60b3829dbbe Mon Sep 17 00:00:00 2001
From: Hiroshi Ogawa
Date: Tue, 6 Aug 2024 09:17:15 +0900
Subject: [PATCH 3/6] Revert "chore: prettier-ignore"
This reverts commit 10fb68df064220ab72e2edffe21a99f689319405.
---
playground/worker/classic-worker.js | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/playground/worker/classic-worker.js b/playground/worker/classic-worker.js
index 73de876270d54e..d68c61c14fd78f 100644
--- a/playground/worker/classic-worker.js
+++ b/playground/worker/classic-worker.js
@@ -1,5 +1,4 @@
-// prettier-ignore
-;(() => {})() // this is to test `importScripts` injection doesn't break the code
+(() => {})() // this is to test `importScripts` injection doesn't break the code
let base = `/${self.location.pathname.split('/')[1]}`
if (base.endsWith('.js') || base === `/worker-entries`) base = '' // for dev
From f3163265e8abe79bc5ecfd098ad3558462ebe3dc Mon Sep 17 00:00:00 2001
From: Hiroshi Ogawa
Date: Tue, 6 Aug 2024 09:31:57 +0900
Subject: [PATCH 4/6] chore: prettierignore
---
.prettierignore | 1 +
1 file changed, 1 insertion(+)
diff --git a/.prettierignore b/.prettierignore
index 0fc71ddd114101..95541be4525222 100644
--- a/.prettierignore
+++ b/.prettierignore
@@ -11,3 +11,4 @@ playground/html/invalid.html
playground/html/valid.html
playground/external/public/slash@3.0.0.js
playground/ssr-html/public/slash@3.0.0.js
+playground/worker/classic-worker.js
From 70c746c1be3b7d7903596e577c1fb6b370dd9b69 Mon Sep 17 00:00:00 2001
From: Hiroshi Ogawa
Date: Tue, 6 Aug 2024 09:36:31 +0900
Subject: [PATCH 5/6] test: add new worker
---
.prettierignore | 2 +-
playground/worker/__tests__/es/worker-es.spec.ts | 5 +++++
playground/worker/classic-iife.js | 5 +++++
playground/worker/classic-worker.js | 2 --
playground/worker/index.html | 1 +
playground/worker/worker/main-classic.js | 6 ++++++
6 files changed, 18 insertions(+), 3 deletions(-)
create mode 100644 playground/worker/classic-iife.js
diff --git a/.prettierignore b/.prettierignore
index 95541be4525222..2edad99b984dee 100644
--- a/.prettierignore
+++ b/.prettierignore
@@ -11,4 +11,4 @@ playground/html/invalid.html
playground/html/valid.html
playground/external/public/slash@3.0.0.js
playground/ssr-html/public/slash@3.0.0.js
-playground/worker/classic-worker.js
+playground/worker/classic-iife.js
diff --git a/playground/worker/__tests__/es/worker-es.spec.ts b/playground/worker/__tests__/es/worker-es.spec.ts
index 080ab455950a4c..56f60b61190d96 100644
--- a/playground/worker/__tests__/es/worker-es.spec.ts
+++ b/playground/worker/__tests__/es/worker-es.spec.ts
@@ -190,6 +190,11 @@ test('classic worker', async () => {
'A classic',
true,
)
+ await untilUpdated(
+ () => page.textContent('.classic-iife'),
+ 'classic-iife',
+ true,
+ )
})
test('emit chunk', async () => {
diff --git a/playground/worker/classic-iife.js b/playground/worker/classic-iife.js
new file mode 100644
index 00000000000000..c62e9696a8f4b1
--- /dev/null
+++ b/playground/worker/classic-iife.js
@@ -0,0 +1,5 @@
+(() => {
+ self.addEventListener('message', () => {
+ self.postMessage('classic-iife');
+ })
+})()
diff --git a/playground/worker/classic-worker.js b/playground/worker/classic-worker.js
index d68c61c14fd78f..be6fa357e70ec4 100644
--- a/playground/worker/classic-worker.js
+++ b/playground/worker/classic-worker.js
@@ -1,5 +1,3 @@
-(() => {})() // this is to test `importScripts` injection doesn't break the code
-
let base = `/${self.location.pathname.split('/')[1]}`
if (base.endsWith('.js') || base === `/worker-entries`) base = '' // for dev
diff --git a/playground/worker/index.html b/playground/worker/index.html
index c1944046af6998..99b4069b0de355 100644
--- a/playground/worker/index.html
+++ b/playground/worker/index.html
@@ -132,6 +132,7 @@
+
new SharedWorker(new URL('./classic-shared-worker.js', import.meta.url), {
diff --git a/playground/worker/worker/main-classic.js b/playground/worker/worker/main-classic.js
index 315d8aed8b885a..0601031d316d9d 100644
--- a/playground/worker/worker/main-classic.js
+++ b/playground/worker/worker/main-classic.js
@@ -38,3 +38,9 @@ classicSharedWorker.port.addEventListener('message', (ev) => {
text('.classic-shared-worker', JSON.stringify(ev.data))
})
classicSharedWorker.port.start()
+
+const classicIife = new Worker(new URL('../classic-iife.js', import.meta.url))
+classicIife.addEventListener('message', (e) => {
+ text('.classic-iife', e.data)
+})
+classicIife.postMessage('ping')
From 4e96e1243c8a4e076aff5d67edbaca8459fe5b1f Mon Sep 17 00:00:00 2001
From: Hiroshi Ogawa
Date: Tue, 6 Aug 2024 09:52:16 +0900
Subject: [PATCH 6/6] Revert "test: add new worker"
This reverts commit 70c746c1be3b7d7903596e577c1fb6b370dd9b69.
---
.prettierignore | 2 +-
playground/worker/__tests__/es/worker-es.spec.ts | 5 -----
playground/worker/classic-iife.js | 5 -----
playground/worker/classic-worker.js | 2 ++
playground/worker/index.html | 1 -
playground/worker/worker/main-classic.js | 6 ------
6 files changed, 3 insertions(+), 18 deletions(-)
delete mode 100644 playground/worker/classic-iife.js
diff --git a/.prettierignore b/.prettierignore
index 2edad99b984dee..95541be4525222 100644
--- a/.prettierignore
+++ b/.prettierignore
@@ -11,4 +11,4 @@ playground/html/invalid.html
playground/html/valid.html
playground/external/public/slash@3.0.0.js
playground/ssr-html/public/slash@3.0.0.js
-playground/worker/classic-iife.js
+playground/worker/classic-worker.js
diff --git a/playground/worker/__tests__/es/worker-es.spec.ts b/playground/worker/__tests__/es/worker-es.spec.ts
index 56f60b61190d96..080ab455950a4c 100644
--- a/playground/worker/__tests__/es/worker-es.spec.ts
+++ b/playground/worker/__tests__/es/worker-es.spec.ts
@@ -190,11 +190,6 @@ test('classic worker', async () => {
'A classic',
true,
)
- await untilUpdated(
- () => page.textContent('.classic-iife'),
- 'classic-iife',
- true,
- )
})
test('emit chunk', async () => {
diff --git a/playground/worker/classic-iife.js b/playground/worker/classic-iife.js
deleted file mode 100644
index c62e9696a8f4b1..00000000000000
--- a/playground/worker/classic-iife.js
+++ /dev/null
@@ -1,5 +0,0 @@
-(() => {
- self.addEventListener('message', () => {
- self.postMessage('classic-iife');
- })
-})()
diff --git a/playground/worker/classic-worker.js b/playground/worker/classic-worker.js
index be6fa357e70ec4..d68c61c14fd78f 100644
--- a/playground/worker/classic-worker.js
+++ b/playground/worker/classic-worker.js
@@ -1,3 +1,5 @@
+(() => {})() // this is to test `importScripts` injection doesn't break the code
+
let base = `/${self.location.pathname.split('/')[1]}`
if (base.endsWith('.js') || base === `/worker-entries`) base = '' // for dev
diff --git a/playground/worker/index.html b/playground/worker/index.html
index 99b4069b0de355..c1944046af6998 100644
--- a/playground/worker/index.html
+++ b/playground/worker/index.html
@@ -132,7 +132,6 @@
-
new SharedWorker(new URL('./classic-shared-worker.js', import.meta.url), {
diff --git a/playground/worker/worker/main-classic.js b/playground/worker/worker/main-classic.js
index 0601031d316d9d..315d8aed8b885a 100644
--- a/playground/worker/worker/main-classic.js
+++ b/playground/worker/worker/main-classic.js
@@ -38,9 +38,3 @@ classicSharedWorker.port.addEventListener('message', (ev) => {
text('.classic-shared-worker', JSON.stringify(ev.data))
})
classicSharedWorker.port.start()
-
-const classicIife = new Worker(new URL('../classic-iife.js', import.meta.url))
-classicIife.addEventListener('message', (e) => {
- text('.classic-iife', e.data)
-})
-classicIife.postMessage('ping')