|
| 1 | +diff --git a/dist/index.js b/dist/index.js |
| 2 | +index 6a30f19344431fcbd495c8951695bdd2e5917583..00f310c9123972aa013a924bcc9c8d5b7cb20205 100644 |
| 3 | +--- a/dist/index.js |
| 4 | ++++ b/dist/index.js |
| 5 | +@@ -1646,19 +1646,38 @@ function decodeVirtualModuleId(encoded, _plugin) { |
| 6 | + function isVirtualModuleId(encoded, plugin) { |
| 7 | + return (0, import_path8.dirname)(encoded) === plugin.__virtualModulePrefix; |
| 8 | + } |
| 9 | +-var FakeVirtualModulesPlugin = class { |
| 10 | ++var FakeVirtualModulesPlugin = class FakeVirtualModulesPlugin { |
| 11 | ++ // PATCH (ported from unplugin>=2.x): share the virtual dir per-process and |
| 12 | ++ // reference-count it so parallel compilers in one process (e.g. rslib's js+dts) |
| 13 | ++ // don't delete the dir out from under each other on shutdown. |
| 14 | ++ static counters = /* @__PURE__ */ new Map(); |
| 15 | ++ static initCleanup = false; |
| 16 | ++ name = "FakeVirtualModulesPlugin"; |
| 17 | + constructor(plugin) { |
| 18 | + this.plugin = plugin; |
| 19 | ++ if (!FakeVirtualModulesPlugin.initCleanup) { |
| 20 | ++ FakeVirtualModulesPlugin.initCleanup = true; |
| 21 | ++ process.once("exit", () => { |
| 22 | ++ FakeVirtualModulesPlugin.counters.forEach((_, dir) => { |
| 23 | ++ import_fs3.default.rmSync(dir, { recursive: true, force: true }); |
| 24 | ++ }); |
| 25 | ++ }); |
| 26 | ++ } |
| 27 | + } |
| 28 | +- name = "FakeVirtualModulesPlugin"; |
| 29 | + apply(compiler) { |
| 30 | + const dir = this.plugin.__virtualModulePrefix; |
| 31 | + if (!import_fs3.default.existsSync(dir)) { |
| 32 | + import_fs3.default.mkdirSync(dir, { recursive: true }); |
| 33 | + } |
| 34 | ++ const counter = FakeVirtualModulesPlugin.counters.get(dir) ?? 0; |
| 35 | ++ FakeVirtualModulesPlugin.counters.set(dir, counter + 1); |
| 36 | + compiler.hooks.shutdown.tap(this.name, () => { |
| 37 | +- if (import_fs3.default.existsSync(dir)) { |
| 38 | +- import_fs3.default.rmdirSync(dir, { recursive: true }); |
| 39 | ++ const remaining = (FakeVirtualModulesPlugin.counters.get(dir) ?? 1) - 1; |
| 40 | ++ if (remaining === 0) { |
| 41 | ++ FakeVirtualModulesPlugin.counters.delete(dir); |
| 42 | ++ import_fs3.default.rmSync(dir, { recursive: true, force: true }); |
| 43 | ++ } else { |
| 44 | ++ FakeVirtualModulesPlugin.counters.set(dir, remaining); |
| 45 | + } |
| 46 | + }); |
| 47 | + } |
| 48 | +@@ -1682,7 +1701,7 @@ function getRspackPlugin(factory) { |
| 49 | + return (userOptions) => { |
| 50 | + return { |
| 51 | + apply(compiler) { |
| 52 | +- const VIRTUAL_MODULE_PREFIX = (0, import_path9.resolve)(compiler.options.context ?? process.cwd(), "node_modules/.virtual"); |
| 53 | ++ const VIRTUAL_MODULE_PREFIX = (0, import_path9.resolve)(compiler.options.context ?? process.cwd(), "node_modules/.virtual", compiler.rspack.experiments.VirtualModulesPlugin ? "" : process.pid.toString()); |
| 54 | + const injected = compiler.$unpluginContext || {}; |
| 55 | + compiler.$unpluginContext = injected; |
| 56 | + const meta = { |
| 57 | +@@ -1710,7 +1729,7 @@ function getRspackPlugin(factory) { |
| 58 | + }); |
| 59 | + const externalModules = /* @__PURE__ */ new Set(); |
| 60 | + if (plugin.resolveId) { |
| 61 | +- const vfs = new FakeVirtualModulesPlugin(plugin); |
| 62 | ++ const vfs = compiler.rspack.experiments.VirtualModulesPlugin ? new compiler.rspack.experiments.VirtualModulesPlugin() : new FakeVirtualModulesPlugin(plugin); |
| 63 | + vfs.apply(compiler); |
| 64 | + plugin.__vfsModules = /* @__PURE__ */ new Set(); |
| 65 | + compiler.hooks.compilation.tap(plugin.name, (compilation, { normalModuleFactory }) => { |
| 66 | +@@ -1744,11 +1763,16 @@ function getRspackPlugin(factory) { |
| 67 | + if (isExternal) |
| 68 | + externalModules.add(resolved); |
| 69 | + if (!import_fs4.default.existsSync(resolved)) { |
| 70 | ++ const encodedVirtualPath = encodeVirtualModuleId(resolved, plugin); |
| 71 | + if (!plugin.__vfsModules.has(resolved)) { |
| 72 | + plugin.__vfsModules.add(resolved); |
| 73 | +- await vfs.writeModule(resolved); |
| 74 | ++ if (compiler.rspack.experiments.VirtualModulesPlugin) { |
| 75 | ++ await vfs.writeModule(encodedVirtualPath, ""); |
| 76 | ++ } else { |
| 77 | ++ await vfs.writeModule(resolved); |
| 78 | ++ } |
| 79 | + } |
| 80 | +- resolved = encodeVirtualModuleId(resolved, plugin); |
| 81 | ++ resolved = encodedVirtualPath; |
| 82 | + } |
| 83 | + resolveData.request = resolved; |
| 84 | + }); |
0 commit comments