-
Notifications
You must be signed in to change notification settings - Fork 485
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: runtime condition of hot accept dependency
- Loading branch information
1 parent
9401101
commit 625e982
Showing
18 changed files
with
279 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
packages/rspack/tests/hotCases/worker/issue-5597/changed-file.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// TODO: remove this file after cache. | ||
const path = require('path'); | ||
|
||
module.exports = [ | ||
path.resolve(__dirname, './moduleA.js'), | ||
path.resolve(__dirname, './moduleAs.js'), | ||
path.resolve(__dirname, './moduleB.js'), | ||
path.resolve(__dirname, './moduleBs.js'), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default "chunk"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default "chunkS"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const update = () => | ||
new Promise((resolve, reject) => { | ||
NEXT(err => { | ||
if (err) reject(err); | ||
else resolve(); | ||
}); | ||
}); | ||
|
||
const expectMessage = (w, msg) => | ||
new Promise((resolve, reject) => { | ||
w.onmessage = ({ data }) => { | ||
if (data === msg) resolve(); | ||
else reject(new Error(data)); | ||
}; | ||
}); | ||
|
||
const next = w => { | ||
const p = expectMessage(w, "next"); | ||
w.postMessage("next"); | ||
return p; | ||
}; | ||
|
||
it("should support hot module replacement in WebWorkers", async () => { | ||
const a = new Worker(new URL("workerA.js", import.meta.url)); | ||
const b = new Worker(new URL("workerB.js", import.meta.url)); | ||
for (let i = 0; i < 7; i++) { | ||
await update(); | ||
await next(a); | ||
await next(b); | ||
} | ||
await a.terminate(); | ||
await b.terminate(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default "module"; |
15 changes: 15 additions & 0 deletions
15
packages/rspack/tests/hotCases/worker/issue-5597/moduleA.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export default 0; | ||
--- | ||
export default 1; | ||
--- | ||
export default 2; | ||
--- | ||
export default 3; | ||
--- | ||
export default 4; | ||
--- | ||
export default 5; | ||
--- | ||
export default 6; | ||
--- | ||
export default 7; |
15 changes: 15 additions & 0 deletions
15
packages/rspack/tests/hotCases/worker/issue-5597/moduleAs.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export default 0; | ||
--- | ||
export default 1; | ||
--- | ||
export default 2; | ||
--- | ||
export default 3; | ||
--- | ||
export default 4; | ||
--- | ||
export default 5; | ||
--- | ||
export default 6; | ||
--- | ||
export default 7; |
15 changes: 15 additions & 0 deletions
15
packages/rspack/tests/hotCases/worker/issue-5597/moduleB.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export default 0; | ||
--- | ||
export default 1; | ||
--- | ||
export default 2; | ||
--- | ||
export default 3; | ||
--- | ||
export default 4; | ||
--- | ||
export default 5; | ||
--- | ||
export default 6; | ||
--- | ||
export default 7; |
15 changes: 15 additions & 0 deletions
15
packages/rspack/tests/hotCases/worker/issue-5597/moduleBs.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export default 0; | ||
--- | ||
export default 1; | ||
--- | ||
export default 2; | ||
--- | ||
export default 3; | ||
--- | ||
export default 4; | ||
--- | ||
export default 5; | ||
--- | ||
export default 6; | ||
--- | ||
export default 7; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default "moduleS"; |
5 changes: 5 additions & 0 deletions
5
packages/rspack/tests/hotCases/worker/issue-5597/webpack.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
output: { | ||
filename: '[name].[fullhash].js' | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
packages/rspack/tests/hotCases/worker/issue-5597/worker.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
export default fn => { | ||
self.onmessage = async ({ data: msg }) => { | ||
try { | ||
switch (msg) { | ||
case "next": | ||
if (!(await import.meta.webpackHot.check(true))) | ||
throw new Error("No update found"); | ||
await fn(); | ||
self.postMessage("next"); | ||
break; | ||
default: | ||
throw new Error("Unexpected message"); | ||
} | ||
} catch (e) { | ||
self.postMessage("error: " + e.stack); | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import worker from "./worker"; | ||
import "./moduleA"; | ||
worker(() => import(/* webpackChunkName: "shared" */ "./moduleAs")); | ||
import.meta.webpackHot.accept("./moduleA"); | ||
import.meta.webpackHot.accept("./moduleAs"); |
Oops, something went wrong.