Skip to content

Commit 8163e79

Browse files
committed
test: ensure that the provide plugin is compatible with custom resolvers
1 parent 704de3d commit 8163e79

File tree

6 files changed

+44
-0
lines changed

6 files changed

+44
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import x from "x";
2+
import y from "y";
3+
4+
it("should work", () => {
5+
expect(x).toBe(42);
6+
expect(y).toBe(24);
7+
})
8+
9+
it("should add provided modules to the share scope - no matter the resolver", async () => {
10+
await __webpack_init_sharing__("default");
11+
expect(Object.keys(__webpack_share_scopes__.default)).toContain("x");
12+
expect(Object.keys(__webpack_share_scopes__.default)).toContain("y");
13+
});

tests/rspack-test/configCases/sharing/provide-shared-with-custom-resolver/node_modules/x/index.js

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

tests/rspack-test/configCases/sharing/provide-shared-with-custom-resolver/node_modules/x/package.json

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

tests/rspack-test/configCases/sharing/provide-shared-with-custom-resolver/node_modules/y/index.js

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

tests/rspack-test/configCases/sharing/provide-shared-with-custom-resolver/node_modules/y/package.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// eslint-disable-next-line node/no-unpublished-require
2+
const { ProvideSharedPlugin } = require("@rspack/core").sharing;
3+
4+
/** @type {import("@rspack/core").Configuration} */
5+
module.exports = {
6+
plugins: [
7+
new ProvideSharedPlugin({
8+
provides: ["x", "y"]
9+
}),
10+
function (compiler) {
11+
compiler.hooks.thisCompilation.tap(
12+
"customResolver",
13+
(compilation, { normalModuleFactory }) => {
14+
normalModuleFactory.hooks.resolve.tap("customResolver", (data) => {
15+
if (data.request === "x") {
16+
data.request = require.resolve(data.request);
17+
}
18+
});
19+
}
20+
)
21+
}
22+
]
23+
};

0 commit comments

Comments
 (0)