rsbuild-plugin-virtual-module 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -43,10 +43,25 @@ const pluginVirtualModule = (pluginOptions = {})=>({
43
43
  ];
44
44
  });
45
45
  api.modifyBundlerChain((chain, { rspack })=>{
46
- chain.plugin('RSBUILD_VIRTUAL_MODULE_PLUGIN').use(new rspack.experiments.VirtualModulesPlugin(Object.fromEntries(virtualFileAbsolutePaths.map((i)=>[
46
+ const pluginId = 'RSBUILD_VIRTUAL_MODULE_PLUGIN';
47
+ const virtualModules = Object.fromEntries(virtualFileAbsolutePaths.map((i)=>[
47
48
  i[1],
48
49
  ''
49
- ]))));
50
+ ]));
51
+ if (chain.plugins.has(pluginId)) chain.plugin(pluginId).tap((options)=>{
52
+ const existingPaths = new Set(Object.keys(options[0] ?? {}));
53
+ const conflictPath = virtualFileAbsolutePaths.find(([, path])=>existingPaths.has(path));
54
+ if (conflictPath) throw new Error(`Virtual module name conflicted: ${conflictPath[0]}`);
55
+ return [
56
+ {
57
+ ...options[0],
58
+ ...virtualModules
59
+ }
60
+ ];
61
+ });
62
+ else chain.plugin(pluginId).use(rspack.experiments.VirtualModulesPlugin, [
63
+ virtualModules
64
+ ]);
50
65
  chain.resolve.alias.merge(Object.fromEntries(virtualFileAbsolutePaths));
51
66
  });
52
67
  for (const [moduleName, absolutePath] of virtualFileAbsolutePaths){
package/dist/index.js CHANGED
@@ -1,23 +1,38 @@
1
- import * as __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__ from "node:path";
1
+ import { extname, join } from "node:path";
2
2
  const PLUGIN_VIRTUAL_MODULE_NAME = 'rsbuild:virtual-module';
3
3
  const pluginVirtualModule = (pluginOptions = {})=>({
4
4
  name: PLUGIN_VIRTUAL_MODULE_NAME,
5
5
  async setup (api) {
6
6
  const { virtualModules = {}, tempDir: virtualFolderName = '.rsbuild-virtual-module' } = pluginOptions;
7
- const TEMP_DIR = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(api.context.rootPath, virtualFolderName);
7
+ const TEMP_DIR = join(api.context.rootPath, virtualFolderName);
8
8
  const virtualFileAbsolutePaths = Object.keys(virtualModules).map((i)=>{
9
- let absolutePath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(TEMP_DIR, i);
10
- if (!(0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.extname)(absolutePath)) absolutePath = `${absolutePath}.js`;
9
+ let absolutePath = join(TEMP_DIR, i);
10
+ if (!extname(absolutePath)) absolutePath = `${absolutePath}.js`;
11
11
  return [
12
12
  i,
13
13
  absolutePath
14
14
  ];
15
15
  });
16
16
  api.modifyBundlerChain((chain, { rspack })=>{
17
- chain.plugin('RSBUILD_VIRTUAL_MODULE_PLUGIN').use(new rspack.experiments.VirtualModulesPlugin(Object.fromEntries(virtualFileAbsolutePaths.map((i)=>[
17
+ const pluginId = 'RSBUILD_VIRTUAL_MODULE_PLUGIN';
18
+ const virtualModules = Object.fromEntries(virtualFileAbsolutePaths.map((i)=>[
18
19
  i[1],
19
20
  ''
20
- ]))));
21
+ ]));
22
+ if (chain.plugins.has(pluginId)) chain.plugin(pluginId).tap((options)=>{
23
+ const existingPaths = new Set(Object.keys(options[0] ?? {}));
24
+ const conflictPath = virtualFileAbsolutePaths.find(([, path])=>existingPaths.has(path));
25
+ if (conflictPath) throw new Error(`Virtual module name conflicted: ${conflictPath[0]}`);
26
+ return [
27
+ {
28
+ ...options[0],
29
+ ...virtualModules
30
+ }
31
+ ];
32
+ });
33
+ else chain.plugin(pluginId).use(rspack.experiments.VirtualModulesPlugin, [
34
+ virtualModules
35
+ ]);
21
36
  chain.resolve.alias.merge(Object.fromEntries(virtualFileAbsolutePaths));
22
37
  });
23
38
  for (const [moduleName, absolutePath] of virtualFileAbsolutePaths){
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rsbuild-plugin-virtual-module",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/rspack-contrib/rsbuild-plugin-virtual-module"
@@ -17,7 +17,9 @@
17
17
  "main": "./dist/index.js",
18
18
  "module": "./dist/index.mjs",
19
19
  "types": "./dist/index.d.ts",
20
- "files": ["dist"],
20
+ "files": [
21
+ "dist"
22
+ ],
21
23
  "scripts": {
22
24
  "build": "rslib build",
23
25
  "dev": "rslib build --watch",
@@ -31,14 +33,14 @@
31
33
  "pre-commit": "npm run lint:write"
32
34
  },
33
35
  "devDependencies": {
34
- "@biomejs/biome": "^1.9.4",
35
- "@playwright/test": "^1.51.1",
36
- "@rsbuild/core": "^1.5.3",
37
- "@rslib/core": "^0.6.1",
38
- "@types/node": "^22.13.16",
39
- "playwright": "^1.51.1",
40
- "simple-git-hooks": "^2.12.1",
41
- "typescript": "^5.8.2",
36
+ "@biomejs/biome": "^2.2.4",
37
+ "@playwright/test": "^1.55.0",
38
+ "@rsbuild/core": "^1.5.7",
39
+ "@rslib/core": "^0.13.3",
40
+ "@types/node": "^24.5.1",
41
+ "playwright": "^1.55.0",
42
+ "simple-git-hooks": "^2.13.1",
43
+ "typescript": "^5.9.2",
42
44
  "rsbuild-plugin-virtual-module": "workspace:*"
43
45
  },
44
46
  "peerDependencies": {
@@ -49,7 +51,7 @@
49
51
  "optional": true
50
52
  }
51
53
  },
52
- "packageManager": "pnpm@10.5.2",
54
+ "packageManager": "pnpm@10.16.1",
53
55
  "publishConfig": {
54
56
  "access": "public",
55
57
  "registry": "https://registry.npmjs.org/"