rsbuild-plugin-virtual-module 0.4.0 → 0.4.2

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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  The simplest and most flexible way to build with a compiling magic 🪄
4
4
 
5
- An Rsbuild plugin that allows you to create virtual modules, the pro version of [rspack-plugin-virtual-module](https://github.com/rspack-contrib/rspack-plugin-virtual-module) with loader API.
5
+ An Rsbuild plugin that allows you to create virtual modules, the pro version of [rspack-plugin-virtual-module](https://github.com/rstackjs/rspack-plugin-virtual-module) with loader API.
6
6
 
7
7
  <p>
8
8
  <a href="https://npmjs.com/package/rsbuild-plugin-virtual-module">
package/dist/index.cjs CHANGED
@@ -13,7 +13,7 @@ var __webpack_require__ = {};
13
13
  })();
14
14
  (()=>{
15
15
  __webpack_require__.r = (exports1)=>{
16
- if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
16
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
17
  value: 'Module'
18
18
  });
19
19
  Object.defineProperty(exports1, '__esModule', {
@@ -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){
@@ -59,10 +74,10 @@ const pluginVirtualModule = (pluginOptions = {})=>({
59
74
  });
60
75
  exports.PLUGIN_VIRTUAL_MODULE_NAME = __webpack_exports__.PLUGIN_VIRTUAL_MODULE_NAME;
61
76
  exports.pluginVirtualModule = __webpack_exports__.pluginVirtualModule;
62
- for(var __webpack_i__ in __webpack_exports__)if (-1 === [
77
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
63
78
  "PLUGIN_VIRTUAL_MODULE_NAME",
64
79
  "pluginVirtualModule"
65
- ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
80
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
66
81
  Object.defineProperty(exports, '__esModule', {
67
82
  value: true
68
83
  });
package/dist/index.d.ts CHANGED
@@ -13,5 +13,5 @@ interface PluginVirtualModuleOptions {
13
13
  }
14
14
  declare const PLUGIN_VIRTUAL_MODULE_NAME = "rsbuild:virtual-module";
15
15
  declare const pluginVirtualModule: (pluginOptions?: PluginVirtualModuleOptions) => RsbuildPlugin;
16
- export { PLUGIN_VIRTUAL_MODULE_NAME, pluginVirtualModule };
17
16
  export type { PluginVirtualModuleOptions, VirtualModules };
17
+ export { PLUGIN_VIRTUAL_MODULE_NAME, pluginVirtualModule };
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,9 +1,9 @@
1
1
  {
2
2
  "name": "rsbuild-plugin-virtual-module",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "repository": {
5
5
  "type": "git",
6
- "url": "https://github.com/rspack-contrib/rsbuild-plugin-virtual-module"
6
+ "url": "git+https://github.com/rstackjs/rsbuild-plugin-virtual-module.git"
7
7
  },
8
8
  "license": "MIT",
9
9
  "type": "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,25 +33,25 @@
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",
42
- "rsbuild-plugin-virtual-module": "workspace:*"
36
+ "@biomejs/biome": "^2.4.10",
37
+ "@playwright/test": "^1.59.0",
38
+ "@rsbuild/core": "^2.0.0",
39
+ "@rslib/core": "^0.21.2",
40
+ "@types/node": "^24.12.0",
41
+ "playwright": "^1.59.0",
42
+ "rsbuild-plugin-virtual-module": "workspace:*",
43
+ "simple-git-hooks": "^2.13.1",
44
+ "typescript": "^5.9.3"
43
45
  },
44
46
  "peerDependencies": {
45
- "@rsbuild/core": "1.x"
47
+ "@rsbuild/core": "^1.0.0 || ^2.0.0"
46
48
  },
47
49
  "peerDependenciesMeta": {
48
50
  "@rsbuild/core": {
49
51
  "optional": true
50
52
  }
51
53
  },
52
- "packageManager": "pnpm@10.5.2",
54
+ "packageManager": "pnpm@10.33.0",
53
55
  "publishConfig": {
54
56
  "access": "public",
55
57
  "registry": "https://registry.npmjs.org/"