Skip to content

Commit 25b8162

Browse files
test: cover the scoped exports and their kept aliases
Every getter this pull request adds is a line only a property read executes, and nothing in configCases reads one, so the patch went in at 0% covered. The test asserts each scope resolves and that each kept flat name is the same object as its scoped path, which is the contract rather than the percentage. Also shortens the changeset: a combined entry may run past 80 characters slightly, and 183 is not slightly.
1 parent f681d15 commit 25b8162

3 files changed

Lines changed: 65 additions & 1 deletion

File tree

‎.changeset/007-export-module-type-and-target-plugins.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"webpack": minor
33
---
44

5-
Export the asset, json, bun, deno and TypeScript plugins and `util.RequestShortener`, move eleven loose exports under the scope their directory implies, and deprecate the old flat names.
5+
Export more plugins under their scope, move eleven loose exports under theirs, deprecate the old.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
});

‎types.d.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32455,6 +32455,7 @@ declare namespace exports {
3245532455
export let global: "__webpack_require__.g";
3245632456
export let harmonyModuleDecorator: "__webpack_require__.hmd";
3245732457
export let hasCssModules: "has css modules";
32458+
export let hasServerRenderedStylesheets: "has server rendered stylesheets";
3245832459
export let hasFetchPriority: "has fetch priority";
3245932460
export let hasChunkPriority: "has chunk priority";
3246032461
export let hasOwnProperty: "__webpack_require__.o";

0 commit comments

Comments
 (0)