|
| 1 | +"use strict"; |
| 2 | + |
| 3 | +const webpack = require("../../lib/index"); |
| 4 | + |
| 5 | +// Each scope mirrors the directory its file lives in, so a name that stops |
| 6 | +// resolving means `lib/index.js` drifted from the tree. Read through a thunk |
| 7 | +// rather than by indexing, which keeps every access precisely typed. |
| 8 | +const SCOPED = [ |
| 9 | + { name: "asset.AssetModulesPlugin", read: () => webpack.asset.AssetModulesPlugin }, |
| 10 | + { name: "bun.BunTargetPlugin", read: () => webpack.bun.BunTargetPlugin }, |
| 11 | + { name: "cache.Cache", read: () => webpack.cache.Cache }, |
| 12 | + { name: "config.PlatformPlugin", read: () => webpack.config.PlatformPlugin }, |
| 13 | + { name: "config.WebpackOptionsApply", read: () => webpack.config.WebpackOptionsApply }, |
| 14 | + { name: "config.defineConfig", read: () => webpack.config.defineConfig }, |
| 15 | + { name: "config.validateSchema", read: () => webpack.config.validateSchema }, |
| 16 | + { name: "css.CssLoadingRuntimeModule", read: () => webpack.css.CssLoadingRuntimeModule }, |
| 17 | + { name: "deno.DenoTargetPlugin", read: () => webpack.deno.DenoTargetPlugin }, |
| 18 | + { name: "experiments.typescript.TypeScriptPlugin", read: () => webpack.experiments.typescript.TypeScriptPlugin }, |
| 19 | + { name: "json.JsonModulesPlugin", read: () => webpack.json.JsonModulesPlugin }, |
| 20 | + { name: "optimize.ConcatenationScope", read: () => webpack.optimize.ConcatenationScope }, |
| 21 | + { name: "optimize.OptimizationStages", read: () => webpack.optimize.OptimizationStages }, |
| 22 | + { name: "prefetch.AutomaticPrefetchPlugin", read: () => webpack.prefetch.AutomaticPrefetchPlugin }, |
| 23 | + { name: "prefetch.PrefetchPlugin", read: () => webpack.prefetch.PrefetchPlugin }, |
| 24 | + { name: "runtime.RuntimeGlobals", read: () => webpack.runtime.RuntimeGlobals }, |
| 25 | + { name: "runtime.RuntimeModule", read: () => webpack.runtime.RuntimeModule }, |
| 26 | + { name: "util.RequestShortener", read: () => webpack.util.RequestShortener } |
| 27 | +]; |
| 28 | + |
| 29 | +// The old path stays reachable and hands back the very same object. |
| 30 | +const KEPT_ALIASES = [ |
| 31 | + { from: "Cache", to: "cache.Cache", readFrom: () => webpack.Cache, readTo: () => webpack.cache.Cache }, |
| 32 | + { from: "PlatformPlugin", to: "config.PlatformPlugin", readFrom: () => webpack.PlatformPlugin, readTo: () => webpack.config.PlatformPlugin }, |
| 33 | + { from: "WebpackOptionsApply", to: "config.WebpackOptionsApply", readFrom: () => webpack.WebpackOptionsApply, readTo: () => webpack.config.WebpackOptionsApply }, |
| 34 | + { from: "defineConfig", to: "config.defineConfig", readFrom: () => webpack.defineConfig, readTo: () => webpack.config.defineConfig }, |
| 35 | + { from: "validateSchema", to: "config.validateSchema", readFrom: () => webpack.validateSchema, readTo: () => webpack.config.validateSchema }, |
| 36 | + { from: "ConcatenationScope", to: "optimize.ConcatenationScope", readFrom: () => webpack.ConcatenationScope, readTo: () => webpack.optimize.ConcatenationScope }, |
| 37 | + { from: "OptimizationStages", to: "optimize.OptimizationStages", readFrom: () => webpack.OptimizationStages, readTo: () => webpack.optimize.OptimizationStages }, |
| 38 | + { from: "RuntimeGlobals", to: "runtime.RuntimeGlobals", readFrom: () => webpack.RuntimeGlobals, readTo: () => webpack.runtime.RuntimeGlobals }, |
| 39 | + { from: "RuntimeModule", to: "runtime.RuntimeModule", readFrom: () => webpack.RuntimeModule, readTo: () => webpack.runtime.RuntimeModule }, |
| 40 | + { from: "AutomaticPrefetchPlugin", to: "prefetch.AutomaticPrefetchPlugin", readFrom: () => webpack.AutomaticPrefetchPlugin, readTo: () => webpack.prefetch.AutomaticPrefetchPlugin }, |
| 41 | + { from: "PrefetchPlugin", to: "prefetch.PrefetchPlugin", readFrom: () => webpack.PrefetchPlugin, readTo: () => webpack.prefetch.PrefetchPlugin }, |
| 42 | + { from: "web.CssLoadingRuntimeModule", to: "css.CssLoadingRuntimeModule", readFrom: () => webpack.web.CssLoadingRuntimeModule, readTo: () => webpack.css.CssLoadingRuntimeModule } |
| 43 | +]; |
| 44 | + |
| 45 | +describe("scoped exports", () => { |
| 46 | + for (const { name, read } of SCOPED) { |
| 47 | + it(`should expose webpack.${name}`, () => { |
| 48 | + expect(read()).toBeDefined(); |
| 49 | + }); |
| 50 | + } |
| 51 | + |
| 52 | + for (const { from, to, readFrom, readTo } of KEPT_ALIASES) { |
| 53 | + it(`should keep webpack.${from} pointing at webpack.${to}`, () => { |
| 54 | + expect(readFrom()).toBe(readTo()); |
| 55 | + }); |
| 56 | + } |
| 57 | + |
| 58 | + it("should keep the lib root shim pointing at util.RequestShortener", () => { |
| 59 | + expect(require("../../lib/RequestShortener")).toBe( |
| 60 | + webpack.util.RequestShortener |
| 61 | + ); |
| 62 | + }); |
| 63 | +}); |
0 commit comments