-
-
Notifications
You must be signed in to change notification settings - Fork 595
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: passively rebuild modules imported by
importModule
(#8595)
* fix * finish * add test * update tests * ifx
- Loading branch information
Showing
16 changed files
with
234 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
mod cutout; | ||
pub mod cutout; | ||
pub mod repair; | ||
|
||
use rspack_collections::IdentifierSet; | ||
|
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
12 changes: 12 additions & 0 deletions
12
...ages/rspack-test-tools/tests/hotCases/loader/import-module-1/__snapshots__/web/0.snap.txt
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,12 @@ | ||
# Case import-module-1: Step 0 | ||
|
||
## Changed Files | ||
|
||
|
||
## Asset Files | ||
- Bundle: bundle.js | ||
|
||
## Manifest | ||
|
||
|
||
## Update |
56 changes: 56 additions & 0 deletions
56
...ages/rspack-test-tools/tests/hotCases/loader/import-module-1/__snapshots__/web/1.snap.txt
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,56 @@ | ||
# Case import-module-1: Step 1 | ||
|
||
## Changed Files | ||
- a.js | ||
|
||
## Asset Files | ||
- Bundle: bundle.js | ||
- Manifest: main.LAST_HASH.hot-update.json, size: 28 | ||
- Update: main.LAST_HASH.hot-update.js, size: 532 | ||
|
||
## Manifest | ||
|
||
### main.LAST_HASH.hot-update.json | ||
|
||
```json | ||
{"c":["main"],"r":[],"m":[]} | ||
``` | ||
|
||
|
||
## Update | ||
|
||
|
||
### main.LAST_HASH.hot-update.js | ||
|
||
#### Changed Modules | ||
- ./loader.js!./a.js | ||
|
||
#### Changed Runtime Modules | ||
- webpack/runtime/get_full_hash | ||
|
||
#### Changed Content | ||
```js | ||
"use strict"; | ||
self["webpackHotUpdate"]('main', { | ||
"./loader.js!./a.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { | ||
__webpack_require__.r(__webpack_exports__); | ||
__webpack_require__.d(__webpack_exports__, { | ||
"default": function() { return __WEBPACK_DEFAULT_EXPORT__; } | ||
}); | ||
/* ESM default export */ const __WEBPACK_DEFAULT_EXPORT__ = (2); | ||
|
||
|
||
}), | ||
|
||
},function(__webpack_require__) { | ||
// webpack/runtime/get_full_hash | ||
(() => { | ||
__webpack_require__.h = function () { | ||
return "CURRENT_HASH"; | ||
}; | ||
|
||
})(); | ||
|
||
} | ||
); | ||
``` |
3 changes: 3 additions & 0 deletions
3
packages/rspack-test-tools/tests/hotCases/loader/import-module-1/a.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,3 @@ | ||
export default 1; | ||
--- | ||
export default 2; |
13 changes: 13 additions & 0 deletions
13
packages/rspack-test-tools/tests/hotCases/loader/import-module-1/index.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,13 @@ | ||
import a from "./loader.js!./a"; | ||
|
||
it("module and its loader-referencing module should update in right order", (done) => { | ||
expect(a).toBe(1); | ||
NEXT( | ||
require('../../update')(done, true, () => { | ||
expect(a).toBe(2); | ||
done(); | ||
}), | ||
); | ||
}); | ||
|
||
module.hot.accept('./loader.js!./a'); |
6 changes: 6 additions & 0 deletions
6
packages/rspack-test-tools/tests/hotCases/loader/import-module-1/loader.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,6 @@ | ||
module.exports = async function (content) { | ||
if (!content.includes("2")) { | ||
await this.importModule("./loader2.js!./a.js"); | ||
} | ||
return content; | ||
}; |
6 changes: 6 additions & 0 deletions
6
packages/rspack-test-tools/tests/hotCases/loader/import-module-1/loader2.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,6 @@ | ||
module.exports = async function (content) { | ||
if (content.includes("2")) { | ||
throw "should not throw"; | ||
} | ||
return content; | ||
}; |
12 changes: 12 additions & 0 deletions
12
...ages/rspack-test-tools/tests/hotCases/loader/import-module-2/__snapshots__/web/0.snap.txt
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,12 @@ | ||
# Case import-module-2: Step 0 | ||
|
||
## Changed Files | ||
|
||
|
||
## Asset Files | ||
- Bundle: bundle.js | ||
|
||
## Manifest | ||
|
||
|
||
## Update |
50 changes: 50 additions & 0 deletions
50
...ages/rspack-test-tools/tests/hotCases/loader/import-module-2/__snapshots__/web/1.snap.txt
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,50 @@ | ||
# Case import-module-2: Step 1 | ||
|
||
## Changed Files | ||
- import_module_sub.js | ||
|
||
## Asset Files | ||
- Bundle: bundle.js | ||
- Manifest: main.LAST_HASH.hot-update.json, size: 28 | ||
- Update: main.LAST_HASH.hot-update.js, size: 257 | ||
|
||
## Manifest | ||
|
||
### main.LAST_HASH.hot-update.json | ||
|
||
```json | ||
{"c":["main"],"r":[],"m":[]} | ||
``` | ||
|
||
|
||
## Update | ||
|
||
|
||
### main.LAST_HASH.hot-update.js | ||
|
||
#### Changed Modules | ||
- ./loader.js!./a.js | ||
|
||
#### Changed Runtime Modules | ||
- webpack/runtime/get_full_hash | ||
|
||
#### Changed Content | ||
```js | ||
self["webpackHotUpdate"]('main', { | ||
"./loader.js!./a.js": (function (module) { | ||
module.exports = 3; | ||
|
||
}), | ||
|
||
},function(__webpack_require__) { | ||
// webpack/runtime/get_full_hash | ||
(() => { | ||
__webpack_require__.h = function () { | ||
return "CURRENT_HASH"; | ||
}; | ||
|
||
})(); | ||
|
||
} | ||
); | ||
``` |
1 change: 1 addition & 0 deletions
1
packages/rspack-test-tools/tests/hotCases/loader/import-module-2/a.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 @@ | ||
module.exports = 1; |
2 changes: 2 additions & 0 deletions
2
packages/rspack-test-tools/tests/hotCases/loader/import-module-2/import_module_root.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,2 @@ | ||
const loader = require("./import_module_sub.js"); | ||
module.exports = loader; |
3 changes: 3 additions & 0 deletions
3
packages/rspack-test-tools/tests/hotCases/loader/import-module-2/import_module_sub.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,3 @@ | ||
module.exports = 2; | ||
--- | ||
module.exports = 3; |
10 changes: 10 additions & 0 deletions
10
packages/rspack-test-tools/tests/hotCases/loader/import-module-2/index.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,10 @@ | ||
it("module and its loader-referencing module should update in right order", done => { | ||
expect(require("./loader.js!./a")).toBe(2); | ||
NEXT( | ||
require("../../update")(done, true, () => { | ||
expect(require("./loader.js!./a")).toBe(3); | ||
done(); | ||
}) | ||
); | ||
}); | ||
module.hot.accept("./loader.js!./a"); |
4 changes: 4 additions & 0 deletions
4
packages/rspack-test-tools/tests/hotCases/loader/import-module-2/loader.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,4 @@ | ||
module.exports = async function (content) { | ||
let res = await this.importModule("./import_module_root.js"); | ||
return content.replace("1", res); | ||
}; |
8646ecf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 Benchmark detail: Open
8646ecf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 Ran ecosystem CI: Open