-
-
Notifications
You must be signed in to change notification settings - Fork 601
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support
_module
of LoaderContext (#6631)
* Support _module for LoaderContext * Expose request, userRequest, and rawRequest * Remove originSource in CompilerModuleContext * Add testcase * Fix testcase * Fix testcase * Fix Module.rawRequest * Update snapshot * Fix clippy * Add fields for Module * Add comments * Update api.md * Keep module_identifier in loader context * Update api docs
- Loading branch information
Showing
21 changed files
with
271 additions
and
62 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
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
1 change: 1 addition & 0 deletions
1
packages/rspack-test-tools/tests/configCases/loader/context-module/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 = "a"; |
7 changes: 7 additions & 0 deletions
7
packages/rspack-test-tools/tests/configCases/loader/context-module/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,7 @@ | ||
it("should exist request, rawRequest, and userRequest", async () => { | ||
const result = require("./a"); | ||
const { request, userRequest, rawRequest } = result; | ||
expect(request.endsWith("a.js")).toBe(true); | ||
expect(userRequest.endsWith("a.js")).toBe(true); | ||
expect(rawRequest).toBe("./a"); | ||
}); |
12 changes: 12 additions & 0 deletions
12
packages/rspack-test-tools/tests/configCases/loader/context-module/my-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,12 @@ | ||
module.exports = function () { | ||
this._module.buildInfo.LOADER_ACCESS = true; | ||
this._module.buildMeta.LOADER_ACCESS = true; | ||
return ( | ||
"module.exports = " + | ||
JSON.stringify({ | ||
request: this._module.request, | ||
userRequest: this._module.userRequest, | ||
rawRequest: this._module.rawRequest, | ||
}) | ||
); | ||
}; |
43 changes: 43 additions & 0 deletions
43
packages/rspack-test-tools/tests/configCases/loader/context-module/rspack.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,43 @@ | ||
const path = require("path"); | ||
const assert = require("assert"); | ||
|
||
/** | ||
* @type {import('@rspack/core').RspackOptions} | ||
*/ | ||
module.exports = { | ||
context: __dirname, | ||
module: { | ||
rules: [ | ||
{ | ||
test: path.join(__dirname, "a.js"), | ||
use: [ | ||
{ | ||
loader: "./my-loader.js" | ||
} | ||
] | ||
}, | ||
] | ||
}, | ||
plugins: [ | ||
{ | ||
apply(compiler) { | ||
compiler.hooks.thisCompilation.tap("MyPlugin", compilation => { | ||
compilation.hooks.processAssets.tap("MyPlugin", () => { | ||
let hasModule = false; | ||
for (const chunk of compilation.chunks) { | ||
const modules = compilation.chunkGraph.getChunkModules(chunk); | ||
for (const module of modules) { | ||
if (module.identifier().endsWith("a.js")) { | ||
hasModule = true; | ||
assert(module.buildInfo.LOADER_ACCESS === true); | ||
assert(module.buildMeta.LOADER_ACCESS === true); | ||
} | ||
} | ||
} | ||
assert(hasModule); | ||
}) | ||
}) | ||
} | ||
} | ||
] | ||
}; |
2 changes: 1 addition & 1 deletion
2
...test-tools/tests/diagnosticsCases/module-build-failed/asset-module-build-failed/stats.err
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 +1 @@ | ||
ERROR in ./logo.svg× Module build failed:╰─▶ × Error: Failed to loadat Object.<anonymous>.module.exports (<PROJECT_ROOT>/tests/diagnosticsCases/module-build-failed/asset-module-build-failed/my-loader.js:2:8)at LOADER_EXECUTION (<RSPACK_ROOT>/dist/loader-runner/index.js:618:23)at runSyncOrAsync (<RSPACK_ROOT>/dist/loader-runner/index.js:619:11)at <RSPACK_ROOT>/dist/loader-runner/index.js:723:9at handleResult (<RSPACK_ROOT>/dist/loader-runner/loadLoader.js:125:5)at loadLoader (<RSPACK_ROOT>/dist/loader-runner/loadLoader.js:106:16)at iterateNormalLoaders (<RSPACK_ROOT>/dist/loader-runner/index.js:712:5)at <RSPACK_ROOT>/dist/loader-runner/index.js:539:13at new Promise (<anonymous>)at runLoaders (<RSPACK_ROOT>/dist/loader-runner/index.js:514:12)help: File was processed with this loader: '<PROJECT_ROOT>/tests/diagnosticsCases/module-build-failed/asset-module-build-failed/my-loader.js' | ||
ERROR in ./logo.svg× Module build failed:╰─▶ × Error: Failed to loadat Object.<anonymous>.module.exports (<PROJECT_ROOT>/tests/diagnosticsCases/module-build-failed/asset-module-build-failed/my-loader.js:2:8)at LOADER_EXECUTION (<RSPACK_ROOT>/dist/loader-runner/index.js:620:23)at runSyncOrAsync (<RSPACK_ROOT>/dist/loader-runner/index.js:621:11)at <RSPACK_ROOT>/dist/loader-runner/index.js:725:9at handleResult (<RSPACK_ROOT>/dist/loader-runner/loadLoader.js:125:5)at loadLoader (<RSPACK_ROOT>/dist/loader-runner/loadLoader.js:106:16)at iterateNormalLoaders (<RSPACK_ROOT>/dist/loader-runner/index.js:714:5)at <RSPACK_ROOT>/dist/loader-runner/index.js:541:13at new Promise (<anonymous>)at runLoaders (<RSPACK_ROOT>/dist/loader-runner/index.js:516:12)help: File was processed with this loader: '<PROJECT_ROOT>/tests/diagnosticsCases/module-build-failed/asset-module-build-failed/my-loader.js' |
2 changes: 1 addition & 1 deletion
2
...rspack-test-tools/tests/diagnosticsCases/module-build-failed/loader-throw-error/stats.err
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 +1 @@ | ||
ERROR in ./lib.js× Module build failed:╰─▶ × Error: Failed to loadat Object.<anonymous>.module.exports (<PROJECT_ROOT>/tests/diagnosticsCases/module-build-failed/loader-throw-error/my-loader.js:2:9)at LOADER_EXECUTION (<RSPACK_ROOT>/dist/loader-runner/index.js:618:23)at runSyncOrAsync (<RSPACK_ROOT>/dist/loader-runner/index.js:619:11)at <RSPACK_ROOT>/dist/loader-runner/index.js:723:9at handleResult (<RSPACK_ROOT>/dist/loader-runner/loadLoader.js:125:5)at loadLoader (<RSPACK_ROOT>/dist/loader-runner/loadLoader.js:106:16)at iterateNormalLoaders (<RSPACK_ROOT>/dist/loader-runner/index.js:712:5)at <RSPACK_ROOT>/dist/loader-runner/index.js:539:13at new Promise (<anonymous>)at runLoaders (<RSPACK_ROOT>/dist/loader-runner/index.js:514:12)help: File was processed with this loader: '<PROJECT_ROOT>/tests/diagnosticsCases/module-build-failed/loader-throw-error/my-loader.js' | ||
ERROR in ./lib.js× Module build failed:╰─▶ × Error: Failed to loadat Object.<anonymous>.module.exports (<PROJECT_ROOT>/tests/diagnosticsCases/module-build-failed/loader-throw-error/my-loader.js:2:9)at LOADER_EXECUTION (<RSPACK_ROOT>/dist/loader-runner/index.js:620:23)at runSyncOrAsync (<RSPACK_ROOT>/dist/loader-runner/index.js:621:11)at <RSPACK_ROOT>/dist/loader-runner/index.js:725:9at handleResult (<RSPACK_ROOT>/dist/loader-runner/loadLoader.js:125:5)at loadLoader (<RSPACK_ROOT>/dist/loader-runner/loadLoader.js:106:16)at iterateNormalLoaders (<RSPACK_ROOT>/dist/loader-runner/index.js:714:5)at <RSPACK_ROOT>/dist/loader-runner/index.js:541:13at new Promise (<anonymous>)at runLoaders (<RSPACK_ROOT>/dist/loader-runner/index.js:516:12)help: File was processed with this loader: '<PROJECT_ROOT>/tests/diagnosticsCases/module-build-failed/loader-throw-error/my-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
Oops, something went wrong.
8750bf4
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
Threshold exceeded: ["threejs_development-mode_10x + exec","threejs_production-mode_10x + exec"]
8750bf4
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