@rsbuild/webpack 0.0.0-next-20231103091827
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/LICENSE +21 -0
- package/README.md +19 -0
- package/compiled/ansi-escapes/index.d.ts +248 -0
- package/compiled/ansi-escapes/index.js +1 -0
- package/compiled/ansi-escapes/license +9 -0
- package/compiled/ansi-escapes/package.json +1 -0
- package/compiled/ansi-escapes/type-fest/index.d.ts +2 -0
- package/compiled/babel-plugin-lodash/index.d.ts +1 -0
- package/compiled/babel-plugin-lodash/index.js +1 -0
- package/compiled/babel-plugin-lodash/license +44 -0
- package/compiled/babel-plugin-lodash/package.json +1 -0
- package/compiled/babel-plugin-transform-react-remove-prop-types/index.d.ts +1 -0
- package/compiled/babel-plugin-transform-react-remove-prop-types/index.js +1 -0
- package/compiled/babel-plugin-transform-react-remove-prop-types/license +22 -0
- package/compiled/babel-plugin-transform-react-remove-prop-types/package.json +1 -0
- package/compiled/cli-truncate/index.d.ts +96 -0
- package/compiled/cli-truncate/index.js +1 -0
- package/compiled/cli-truncate/license +9 -0
- package/compiled/cli-truncate/package.json +1 -0
- package/compiled/copy-webpack-plugin/index.d.ts +1 -0
- package/compiled/copy-webpack-plugin/index.js +22 -0
- package/compiled/copy-webpack-plugin/license +20 -0
- package/compiled/copy-webpack-plugin/package.json +1 -0
- package/compiled/patch-console/build/index.d.ts +4 -0
- package/compiled/patch-console/index.js +1 -0
- package/compiled/patch-console/package.json +1 -0
- package/compiled/schema-utils3/index.d.ts +1 -0
- package/compiled/schema-utils3/index.js +3 -0
- package/compiled/schema-utils3/license +20 -0
- package/compiled/schema-utils3/package.json +1 -0
- package/compiled/tapable/index.js +1 -0
- package/compiled/tapable/license +21 -0
- package/compiled/tapable/package.json +1 -0
- package/compiled/tapable/tapable.d.ts +116 -0
- package/compiled/webpack-manifest-plugin/index.js +1 -0
- package/compiled/webpack-manifest-plugin/license +21 -0
- package/compiled/webpack-manifest-plugin/package.json +1 -0
- package/compiled/webpack-manifest-plugin/types/helpers.d.ts +23 -0
- package/compiled/webpack-manifest-plugin/types/hooks.d.ts +24 -0
- package/compiled/webpack-manifest-plugin/types/index.d.ts +30 -0
- package/compiled/webpack-sources/index.d.ts +1 -0
- package/compiled/webpack-sources/index.js +1 -0
- package/compiled/webpack-sources/license +21 -0
- package/compiled/webpack-sources/package.json +1 -0
- package/dist/config/defaults.d.ts +3 -0
- package/dist/config/defaults.js +52 -0
- package/dist/config/normalize.d.ts +7 -0
- package/dist/config/normalize.js +33 -0
- package/dist/core/build.d.ts +20 -0
- package/dist/core/build.js +80 -0
- package/dist/core/createCompiler.d.ts +8 -0
- package/dist/core/createCompiler.js +68 -0
- package/dist/core/createContext.d.ts +13 -0
- package/dist/core/createContext.js +56 -0
- package/dist/core/devMiddleware.d.ts +5 -0
- package/dist/core/devMiddleware.js +73 -0
- package/dist/core/initConfigs.d.ts +14 -0
- package/dist/core/initConfigs.js +76 -0
- package/dist/core/initHooks.d.ts +19 -0
- package/dist/core/initHooks.js +44 -0
- package/dist/core/initPlugins.d.ts +9 -0
- package/dist/core/initPlugins.js +83 -0
- package/dist/core/inspectConfig.d.ts +20 -0
- package/dist/core/inspectConfig.js +81 -0
- package/dist/core/startDevServer.d.ts +5 -0
- package/dist/core/startDevServer.js +75 -0
- package/dist/core/webpackConfig.d.ts +9 -0
- package/dist/core/webpackConfig.js +164 -0
- package/dist/exports/webpack.d.ts +2 -0
- package/dist/exports/webpack.js +35 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +34 -0
- package/dist/plugins/babel.d.ts +3 -0
- package/dist/plugins/babel.js +171 -0
- package/dist/plugins/basic.d.ts +5 -0
- package/dist/plugins/basic.js +60 -0
- package/dist/plugins/copy.d.ts +2 -0
- package/dist/plugins/copy.js +69 -0
- package/dist/plugins/css.d.ts +23 -0
- package/dist/plugins/css.js +123 -0
- package/dist/plugins/fallback.d.ts +2 -0
- package/dist/plugins/fallback.js +51 -0
- package/dist/plugins/hmr.d.ts +2 -0
- package/dist/plugins/hmr.js +41 -0
- package/dist/plugins/lazyCompilation.d.ts +2 -0
- package/dist/plugins/lazyCompilation.js +43 -0
- package/dist/plugins/less.d.ts +6 -0
- package/dist/plugins/less.js +65 -0
- package/dist/plugins/manifest.d.ts +2 -0
- package/dist/plugins/manifest.js +58 -0
- package/dist/plugins/minimize.d.ts +2 -0
- package/dist/plugins/minimize.js +64 -0
- package/dist/plugins/moduleScopes.d.ts +5 -0
- package/dist/plugins/moduleScopes.js +85 -0
- package/dist/plugins/output.d.ts +2 -0
- package/dist/plugins/output.js +66 -0
- package/dist/plugins/progress.d.ts +2 -0
- package/dist/plugins/progress.js +57 -0
- package/dist/plugins/react.d.ts +2 -0
- package/dist/plugins/react.js +96 -0
- package/dist/plugins/resolve.d.ts +2 -0
- package/dist/plugins/resolve.js +88 -0
- package/dist/plugins/sass.d.ts +2 -0
- package/dist/plugins/sass.js +76 -0
- package/dist/plugins/sri.d.ts +2 -0
- package/dist/plugins/sri.js +43 -0
- package/dist/plugins/tsLoader.d.ts +2 -0
- package/dist/plugins/tsLoader.js +103 -0
- package/dist/provider.d.ts +9 -0
- package/dist/provider.js +104 -0
- package/dist/shared/fs.d.ts +1 -0
- package/dist/shared/fs.js +38 -0
- package/dist/shared/index.d.ts +1 -0
- package/dist/shared/index.js +22 -0
- package/dist/shared/plugin.d.ts +5 -0
- package/dist/shared/plugin.js +111 -0
- package/dist/types/config/index.d.ts +30 -0
- package/dist/types/config/index.js +26 -0
- package/dist/types/config/security.d.ts +9 -0
- package/dist/types/config/security.js +16 -0
- package/dist/types/config/source.d.ts +26 -0
- package/dist/types/config/source.js +16 -0
- package/dist/types/config/tools.d.ts +52 -0
- package/dist/types/config/tools.js +16 -0
- package/dist/types/context.d.ts +17 -0
- package/dist/types/context.js +16 -0
- package/dist/types/hooks.d.ts +24 -0
- package/dist/types/hooks.js +16 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.js +30 -0
- package/dist/types/plugin.d.ts +10 -0
- package/dist/types/plugin.js +16 -0
- package/dist/types/thirdParty/css.d.ts +7 -0
- package/dist/types/thirdParty/css.js +16 -0
- package/dist/types/thirdParty/index.d.ts +9 -0
- package/dist/types/thirdParty/index.js +16 -0
- package/dist/webpackPlugins/ModuleScopePlugin.d.ts +16 -0
- package/dist/webpackPlugins/ModuleScopePlugin.js +111 -0
- package/dist/webpackPlugins/ProgressPlugin/ProgressPlugin.d.ts +13 -0
- package/dist/webpackPlugins/ProgressPlugin/ProgressPlugin.js +102 -0
- package/dist/webpackPlugins/ProgressPlugin/helpers/bar.d.ts +5 -0
- package/dist/webpackPlugins/ProgressPlugin/helpers/bar.js +143 -0
- package/dist/webpackPlugins/ProgressPlugin/helpers/bus.d.ts +17 -0
- package/dist/webpackPlugins/ProgressPlugin/helpers/bus.js +105 -0
- package/dist/webpackPlugins/ProgressPlugin/helpers/index.d.ts +4 -0
- package/dist/webpackPlugins/ProgressPlugin/helpers/index.js +28 -0
- package/dist/webpackPlugins/ProgressPlugin/helpers/log.d.ts +8 -0
- package/dist/webpackPlugins/ProgressPlugin/helpers/log.js +62 -0
- package/dist/webpackPlugins/ProgressPlugin/helpers/nonTty.d.ts +15 -0
- package/dist/webpackPlugins/ProgressPlugin/helpers/nonTty.js +56 -0
- package/dist/webpackPlugins/ProgressPlugin/helpers/percentage.d.ts +7 -0
- package/dist/webpackPlugins/ProgressPlugin/helpers/percentage.js +52 -0
- package/dist/webpackPlugins/ProgressPlugin/helpers/type.d.ts +25 -0
- package/dist/webpackPlugins/ProgressPlugin/helpers/type.js +16 -0
- package/dist/webpackPlugins/ProgressPlugin/helpers/utils.d.ts +1 -0
- package/dist/webpackPlugins/ProgressPlugin/helpers/utils.js +30 -0
- package/package.json +88 -0
- package/static/ModuleFilenameHelpers.js +2 -0
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { RsbuildPlugin } from '../types';
|
|
2
|
+
import { Plugins } from '@rsbuild/shared';
|
|
3
|
+
export declare const applyMinimalPlugins: (plugins: Plugins) => import("@rsbuild/shared").AwaitableGetter<RsbuildPlugin>;
|
|
4
|
+
export declare const applyBasicPlugins: (plugins: Plugins) => import("@rsbuild/shared").AwaitableGetter<RsbuildPlugin>;
|
|
5
|
+
export declare const applyDefaultPlugins: (plugins: Plugins) => import("@rsbuild/shared").AwaitableGetter<RsbuildPlugin>;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var plugin_exports = {};
|
|
30
|
+
__export(plugin_exports, {
|
|
31
|
+
applyBasicPlugins: () => applyBasicPlugins,
|
|
32
|
+
applyDefaultPlugins: () => applyDefaultPlugins,
|
|
33
|
+
applyMinimalPlugins: () => applyMinimalPlugins
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(plugin_exports);
|
|
36
|
+
var import_shared = require("@rsbuild/shared");
|
|
37
|
+
const applyMinimalPlugins = (plugins) => {
|
|
38
|
+
var _a, _b, _c;
|
|
39
|
+
return (0, import_shared.awaitableGetter)([
|
|
40
|
+
Promise.resolve().then(() => __toESM(require("../plugins/basic"))).then((m) => m.pluginBasic()),
|
|
41
|
+
(_a = plugins.entry) == null ? void 0 : _a.call(plugins),
|
|
42
|
+
(_b = plugins.cache) == null ? void 0 : _b.call(plugins),
|
|
43
|
+
(_c = plugins.target) == null ? void 0 : _c.call(plugins),
|
|
44
|
+
Promise.resolve().then(() => __toESM(require("../plugins/output"))).then((m) => m.pluginOutput()),
|
|
45
|
+
plugins.devtool(),
|
|
46
|
+
Promise.resolve().then(() => __toESM(require("../plugins/resolve"))).then((m) => m.pluginResolve())
|
|
47
|
+
]);
|
|
48
|
+
};
|
|
49
|
+
const applyBasicPlugins = (plugins) => (0, import_shared.awaitableGetter)([
|
|
50
|
+
...applyMinimalPlugins(plugins).promises,
|
|
51
|
+
Promise.resolve().then(() => __toESM(require("../plugins/copy"))).then((m) => m.pluginCopy()),
|
|
52
|
+
plugins.html(),
|
|
53
|
+
plugins.image(),
|
|
54
|
+
plugins.define(),
|
|
55
|
+
Promise.resolve().then(() => __toESM(require("../plugins/tsLoader"))).then((m) => m.pluginTsLoader()),
|
|
56
|
+
Promise.resolve().then(() => __toESM(require("../plugins/babel"))).then((m) => m.pluginBabel()),
|
|
57
|
+
Promise.resolve().then(() => __toESM(require("../plugins/css"))).then((m) => m.pluginCss()),
|
|
58
|
+
Promise.resolve().then(() => __toESM(require("../plugins/sass"))).then((m) => m.pluginSass()),
|
|
59
|
+
Promise.resolve().then(() => __toESM(require("../plugins/less"))).then((m) => m.pluginLess())
|
|
60
|
+
]);
|
|
61
|
+
const applyDefaultPlugins = (plugins) => {
|
|
62
|
+
var _a, _b, _c;
|
|
63
|
+
return (0, import_shared.awaitableGetter)([
|
|
64
|
+
...applyMinimalPlugins(plugins).promises,
|
|
65
|
+
(_a = plugins.fileSize) == null ? void 0 : _a.call(plugins),
|
|
66
|
+
(_b = plugins.cleanOutput) == null ? void 0 : _b.call(plugins),
|
|
67
|
+
Promise.resolve().then(() => __toESM(require("../plugins/hmr"))).then((m) => m.pluginHMR()),
|
|
68
|
+
plugins.svg(),
|
|
69
|
+
Promise.resolve().then(() => __toESM(require("../plugins/copy"))).then((m) => m.pluginCopy()),
|
|
70
|
+
Promise.resolve().then(() => __toESM(require("../plugins/react"))).then((m) => m.pluginReactWebpack()),
|
|
71
|
+
plugins.font(),
|
|
72
|
+
plugins.image(),
|
|
73
|
+
plugins.media(),
|
|
74
|
+
plugins.html(),
|
|
75
|
+
plugins.wasm(),
|
|
76
|
+
plugins.moment(),
|
|
77
|
+
plugins.nodeAddons(),
|
|
78
|
+
plugins.define(),
|
|
79
|
+
Promise.resolve().then(() => __toESM(require("../plugins/progress"))).then((m) => m.pluginProgress()),
|
|
80
|
+
Promise.resolve().then(() => __toESM(require("../plugins/minimize"))).then((m) => m.pluginMinimize()),
|
|
81
|
+
Promise.resolve().then(() => __toESM(require("../plugins/manifest"))).then((m) => m.pluginManifest()),
|
|
82
|
+
Promise.resolve().then(() => __toESM(require("../plugins/moduleScopes"))).then((m) => m.pluginModuleScopes()),
|
|
83
|
+
Promise.resolve().then(() => __toESM(require("../plugins/tsLoader"))).then((m) => m.pluginTsLoader()),
|
|
84
|
+
Promise.resolve().then(() => __toESM(require("../plugins/babel"))).then((m) => m.pluginBabel()),
|
|
85
|
+
Promise.resolve().then(() => __toESM(require("../plugins/css"))).then((m) => m.pluginCss()),
|
|
86
|
+
Promise.resolve().then(() => __toESM(require("../plugins/sass"))).then((m) => m.pluginSass()),
|
|
87
|
+
Promise.resolve().then(() => __toESM(require("../plugins/less"))).then((m) => m.pluginLess()),
|
|
88
|
+
plugins.rem(),
|
|
89
|
+
plugins.bundleAnalyzer(),
|
|
90
|
+
plugins.toml(),
|
|
91
|
+
plugins.yaml(),
|
|
92
|
+
plugins.splitChunks(),
|
|
93
|
+
Promise.resolve().then(() => __toESM(require("../plugins/sri"))).then((m) => m.pluginSRI()),
|
|
94
|
+
(_c = plugins.startUrl) == null ? void 0 : _c.call(plugins),
|
|
95
|
+
plugins.inlineChunk(),
|
|
96
|
+
plugins.assetsRetry(),
|
|
97
|
+
plugins.externals(),
|
|
98
|
+
plugins.performance(),
|
|
99
|
+
Promise.resolve().then(() => __toESM(require("../plugins/lazyCompilation"))).then((m) => m.pluginLazyCompilation()),
|
|
100
|
+
plugins.networkPerformance(),
|
|
101
|
+
plugins.preloadOrPrefetch(),
|
|
102
|
+
Promise.resolve().then(() => __toESM(require("../plugins/fallback"))).then((m) => m.pluginFallback())
|
|
103
|
+
// fallback should be the last plugin
|
|
104
|
+
]);
|
|
105
|
+
};
|
|
106
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
107
|
+
0 && (module.exports = {
|
|
108
|
+
applyBasicPlugins,
|
|
109
|
+
applyDefaultPlugins,
|
|
110
|
+
applyMinimalPlugins
|
|
111
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { DeepReadonly } from '@rsbuild/shared';
|
|
2
|
+
import type { NormalizedSecurityConfig, SecurityConfig } from './security';
|
|
3
|
+
import type { NormalizedSourceConfig, SourceConfig } from './source';
|
|
4
|
+
import type { NormalizedToolsConfig, ToolsConfig } from './tools';
|
|
5
|
+
import type { DevConfig, HtmlConfig, OutputConfig, ExperimentsConfig, PerformanceConfig, NormalizedDevConfig, NormalizedHtmlConfig, NormalizedOutputConfig, NormalizedExperimentsConfig, NormalizedPerformanceConfig } from '@rsbuild/shared';
|
|
6
|
+
export type { DevConfig, HtmlConfig, OutputConfig, ExperimentsConfig, PerformanceConfig, NormalizedDevConfig, NormalizedHtmlConfig, NormalizedOutputConfig, NormalizedExperimentsConfig, NormalizedPerformanceConfig };
|
|
7
|
+
export * from './security';
|
|
8
|
+
export * from './source';
|
|
9
|
+
export * from './tools';
|
|
10
|
+
/** The Rsbuild config when using Webpack as the bundler */
|
|
11
|
+
export interface RsbuildConfig {
|
|
12
|
+
dev?: DevConfig;
|
|
13
|
+
html?: HtmlConfig;
|
|
14
|
+
tools?: ToolsConfig;
|
|
15
|
+
source?: SourceConfig;
|
|
16
|
+
output?: OutputConfig;
|
|
17
|
+
security?: SecurityConfig;
|
|
18
|
+
performance?: PerformanceConfig;
|
|
19
|
+
experiments?: ExperimentsConfig;
|
|
20
|
+
}
|
|
21
|
+
export type NormalizedConfig = DeepReadonly<{
|
|
22
|
+
dev: NormalizedDevConfig;
|
|
23
|
+
html: NormalizedHtmlConfig;
|
|
24
|
+
tools: NormalizedToolsConfig;
|
|
25
|
+
source: NormalizedSourceConfig;
|
|
26
|
+
output: NormalizedOutputConfig;
|
|
27
|
+
security: NormalizedSecurityConfig;
|
|
28
|
+
performance: NormalizedPerformanceConfig;
|
|
29
|
+
experiments: NormalizedExperimentsConfig;
|
|
30
|
+
}>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var config_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(config_exports);
|
|
18
|
+
__reExport(config_exports, require("./security"), module.exports);
|
|
19
|
+
__reExport(config_exports, require("./source"), module.exports);
|
|
20
|
+
__reExport(config_exports, require("./tools"), module.exports);
|
|
21
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
22
|
+
0 && (module.exports = {
|
|
23
|
+
...require("./security"),
|
|
24
|
+
...require("./source"),
|
|
25
|
+
...require("./tools")
|
|
26
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { SriOptions, SecurityConfig as BaseSecurityConfig, NormalizedSecurityConfig as BaseNormalizedSecurityConfig } from '@rsbuild/shared';
|
|
2
|
+
export type SecurityConfig = BaseSecurityConfig & {
|
|
3
|
+
/**
|
|
4
|
+
* Adding an integrity attribute (`integrity`) to sub-resources introduced by HTML allows the browser to
|
|
5
|
+
* verify the integrity of the introduced resource, thus preventing tampering with the downloaded resource.
|
|
6
|
+
*/
|
|
7
|
+
sri?: SriOptions | boolean;
|
|
8
|
+
};
|
|
9
|
+
export type NormalizedSecurityConfig = BaseNormalizedSecurityConfig & Required<Pick<SecurityConfig, 'sri'>>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var security_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(security_exports);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ChainedConfig, SourceConfig as BaseSourceConfig, NormalizedSourceConfig as BaseNormalizedSourceConfig } from '@rsbuild/shared';
|
|
2
|
+
export type ModuleScopes = Array<string | RegExp>;
|
|
3
|
+
export type TransformImport = {
|
|
4
|
+
libraryName: string;
|
|
5
|
+
libraryDirectory?: string;
|
|
6
|
+
style?: string | boolean;
|
|
7
|
+
styleLibraryDirectory?: string;
|
|
8
|
+
camelToDashComponentName?: boolean;
|
|
9
|
+
transformToDefaultImport?: boolean;
|
|
10
|
+
customName?: ((member: string) => string | undefined) | string;
|
|
11
|
+
customStyleName?: ((member: string) => string | undefined) | string;
|
|
12
|
+
};
|
|
13
|
+
export interface SourceConfig extends BaseSourceConfig {
|
|
14
|
+
/**
|
|
15
|
+
* Restrict importing paths. After configuring this option, all source files can only import code from
|
|
16
|
+
* the specific paths, and import code from other paths is not allowed.
|
|
17
|
+
*/
|
|
18
|
+
moduleScopes?: ChainedConfig<ModuleScopes>;
|
|
19
|
+
}
|
|
20
|
+
export interface NormalizedSourceConfig extends BaseNormalizedSourceConfig {
|
|
21
|
+
/**
|
|
22
|
+
* Restrict importing paths. After configuring this option, all source files can only import code from
|
|
23
|
+
* the specific paths, and import code from other paths is not allowed.
|
|
24
|
+
*/
|
|
25
|
+
moduleScopes?: ChainedConfig<ModuleScopes>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var source_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(source_exports);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { ArrayOrNot, ChainedConfig, FileFilterUtil, TerserPluginOptions, ToolsConfig as BaseToolsConfig } from '@rsbuild/shared';
|
|
2
|
+
import type { BabelTransformOptions, BabelConfigUtils } from '@rsbuild/plugin-babel';
|
|
3
|
+
import type { PluginCssMinimizerOptions } from '@rsbuild/plugin-css-minimizer';
|
|
4
|
+
import type { ModifyWebpackChainUtils, ModifyWebpackConfigUtils } from '../hooks';
|
|
5
|
+
import type { WebpackChain, WebpackConfig, TSLoaderOptions, CSSExtractOptions } from '../thirdParty';
|
|
6
|
+
import type { NormalizedCSSExtractOptions } from '../thirdParty/css';
|
|
7
|
+
export type ToolsTerserConfig = ChainedConfig<TerserPluginOptions>;
|
|
8
|
+
export type ToolsTSLoaderConfig = ChainedConfig<TSLoaderOptions, {
|
|
9
|
+
addIncludes: FileFilterUtil;
|
|
10
|
+
addExcludes: FileFilterUtil;
|
|
11
|
+
}>;
|
|
12
|
+
export type ToolsCssExtractConfig = CSSExtractOptions | ((options: CSSExtractOptions) => CSSExtractOptions | void);
|
|
13
|
+
export type ToolsWebpackConfig = ChainedConfig<WebpackConfig, ModifyWebpackConfigUtils>;
|
|
14
|
+
export type ToolsWebpackChainConfig = ArrayOrNot<(chain: WebpackChain, utils: ModifyWebpackChainUtils) => void>;
|
|
15
|
+
export type ToolsBabelConfig = ChainedConfig<BabelTransformOptions, BabelConfigUtils>;
|
|
16
|
+
export interface ToolsConfig extends BaseToolsConfig {
|
|
17
|
+
/**
|
|
18
|
+
* Modify the options of [babel-loader](https://github.com/babel/babel-loader)
|
|
19
|
+
* When `tools.babel`'s type is Function,the default babel config will be passed in as the first parameter, the config object can be modified directly, or a value can be returned as the final result.
|
|
20
|
+
* When `tools.babel`'s type is `Object`, the config will be shallow merged with default config by `Object.assign`.
|
|
21
|
+
* Note that `Object.assign` is a shallow copy and will completely overwrite the built-in `presets` or `plugins` array, please use it with caution.
|
|
22
|
+
*/
|
|
23
|
+
babel?: ToolsBabelConfig;
|
|
24
|
+
/**
|
|
25
|
+
* Modify the options of [terser-webpack-plugin](https://github.com/webpack-contrib/terser-webpack-plugin).
|
|
26
|
+
*/
|
|
27
|
+
terser?: ToolsTerserConfig;
|
|
28
|
+
/**
|
|
29
|
+
* Modify the options of [ts-loader](https://github.com/TypeStrong/ts-loader).
|
|
30
|
+
* When `tools.tsLoader` is not undefined, Rsbuild will use ts-loader instead of babel-loader to compile TypeScript code.
|
|
31
|
+
*/
|
|
32
|
+
tsLoader?: ToolsTSLoaderConfig;
|
|
33
|
+
/**
|
|
34
|
+
* Modify the options of [mini-css-extract-plugin](https://github.com/webpack-contrib/mini-css-extract-plugin).
|
|
35
|
+
*/
|
|
36
|
+
cssExtract?: CSSExtractOptions;
|
|
37
|
+
/**
|
|
38
|
+
* Configure [webpack](https://webpack.js.org/).
|
|
39
|
+
*/
|
|
40
|
+
webpack?: ToolsWebpackConfig;
|
|
41
|
+
/**
|
|
42
|
+
* Configure webpack by [webpack-chain](https://github.com/neutrinojs/webpack-chain).
|
|
43
|
+
*/
|
|
44
|
+
webpackChain?: ToolsWebpackChainConfig;
|
|
45
|
+
/**
|
|
46
|
+
* Modify the options of [css-minimizer-webpack-plugin](https://github.com/webpack-contrib/css-minimizer-webpack-plugin).
|
|
47
|
+
*/
|
|
48
|
+
minifyCss?: PluginCssMinimizerOptions['pluginOptions'];
|
|
49
|
+
}
|
|
50
|
+
export interface NormalizedToolsConfig extends ToolsConfig {
|
|
51
|
+
cssExtract: NormalizedCSSExtractOptions;
|
|
52
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var tools_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(tools_exports);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Context as BaseContext } from '@rsbuild/shared';
|
|
2
|
+
import type { Hooks } from '../core/initHooks';
|
|
3
|
+
import type { RsbuildConfig, NormalizedConfig } from './config';
|
|
4
|
+
import type { RsbuildPluginAPI } from './plugin';
|
|
5
|
+
/** The inner context. */
|
|
6
|
+
export type Context = BaseContext & {
|
|
7
|
+
/** All hooks. */
|
|
8
|
+
hooks: Readonly<Hooks>;
|
|
9
|
+
/** Current Rsbuild config. */
|
|
10
|
+
config: Readonly<RsbuildConfig>;
|
|
11
|
+
/** The original Rsbuild config passed from the createRsbuild method. */
|
|
12
|
+
originalConfig: Readonly<RsbuildConfig>;
|
|
13
|
+
/** The normalized Rsbuild config. */
|
|
14
|
+
normalizedConfig?: NormalizedConfig;
|
|
15
|
+
/** The plugin API. */
|
|
16
|
+
pluginAPI?: RsbuildPluginAPI;
|
|
17
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var context_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(context_exports);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ChainIdentifier, ModifyChainUtils } from '@rsbuild/shared';
|
|
2
|
+
import type { WebpackChain, WebpackConfig } from './thirdParty';
|
|
3
|
+
import type { RuleSetRule, WebpackPluginInstance } from 'webpack';
|
|
4
|
+
export type ModifyWebpackChainUtils = ModifyChainUtils & {
|
|
5
|
+
webpack: typeof import('webpack');
|
|
6
|
+
CHAIN_ID: ChainIdentifier;
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated Use target instead.
|
|
9
|
+
* */
|
|
10
|
+
name: string;
|
|
11
|
+
/**
|
|
12
|
+
* @deprecated Use HtmlPlugin instead.
|
|
13
|
+
*/
|
|
14
|
+
HtmlWebpackPlugin: typeof import('html-webpack-plugin');
|
|
15
|
+
};
|
|
16
|
+
export type ModifyWebpackConfigUtils = ModifyWebpackChainUtils & {
|
|
17
|
+
addRules: (rules: RuleSetRule | RuleSetRule[]) => void;
|
|
18
|
+
prependPlugins: (plugins: WebpackPluginInstance | WebpackPluginInstance[]) => void;
|
|
19
|
+
appendPlugins: (plugins: WebpackPluginInstance | WebpackPluginInstance[]) => void;
|
|
20
|
+
removePlugin: (pluginName: string) => void;
|
|
21
|
+
mergeConfig: typeof import('@rsbuild/shared/webpack-merge').merge;
|
|
22
|
+
};
|
|
23
|
+
export type ModifyWebpackChainFn = (chain: WebpackChain, utils: ModifyWebpackChainUtils) => Promise<void> | void;
|
|
24
|
+
export type ModifyWebpackConfigFn = (config: WebpackConfig, utils: ModifyWebpackConfigUtils) => Promise<WebpackConfig | void> | WebpackConfig | void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var hooks_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(hooks_exports);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var types_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(types_exports);
|
|
18
|
+
__reExport(types_exports, require("./hooks"), module.exports);
|
|
19
|
+
__reExport(types_exports, require("./config"), module.exports);
|
|
20
|
+
__reExport(types_exports, require("./plugin"), module.exports);
|
|
21
|
+
__reExport(types_exports, require("./context"), module.exports);
|
|
22
|
+
__reExport(types_exports, require("./thirdParty"), module.exports);
|
|
23
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
24
|
+
0 && (module.exports = {
|
|
25
|
+
...require("./hooks"),
|
|
26
|
+
...require("./config"),
|
|
27
|
+
...require("./plugin"),
|
|
28
|
+
...require("./context"),
|
|
29
|
+
...require("./thirdParty")
|
|
30
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { DefaultRsbuildPluginAPI, RsbuildPlugin as BaseRsbuildPlugin } from '@rsbuild/shared';
|
|
2
|
+
import type { Compiler, MultiCompiler } from 'webpack';
|
|
3
|
+
import type { RsbuildConfig, NormalizedConfig } from './config';
|
|
4
|
+
import type { WebpackConfig } from './thirdParty';
|
|
5
|
+
import type { ModifyWebpackChainFn, ModifyWebpackConfigFn } from './hooks';
|
|
6
|
+
export interface RsbuildPluginAPI extends DefaultRsbuildPluginAPI<RsbuildConfig, NormalizedConfig, WebpackConfig, Compiler | MultiCompiler> {
|
|
7
|
+
modifyWebpackChain: (fn: ModifyWebpackChainFn) => void;
|
|
8
|
+
modifyWebpackConfig: (fn: ModifyWebpackConfigFn) => void;
|
|
9
|
+
}
|
|
10
|
+
export type RsbuildPlugin = BaseRsbuildPlugin<RsbuildPluginAPI>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var plugin_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(plugin_exports);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { PluginOptions as MiniCSSExtractPluginOptions, LoaderOptions as MiniCSSExtractLoaderOptions } from 'mini-css-extract-plugin';
|
|
2
|
+
export { MiniCSSExtractPluginOptions, MiniCSSExtractLoaderOptions };
|
|
3
|
+
export interface CSSExtractOptions {
|
|
4
|
+
pluginOptions?: MiniCSSExtractPluginOptions;
|
|
5
|
+
loaderOptions?: MiniCSSExtractLoaderOptions;
|
|
6
|
+
}
|
|
7
|
+
export type NormalizedCSSExtractOptions = Required<CSSExtractOptions>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var css_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(css_exports);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { WebpackChain } from '@rsbuild/shared';
|
|
2
|
+
import type webpack from 'webpack';
|
|
3
|
+
import type { Configuration as WebpackConfig } from 'webpack';
|
|
4
|
+
import type { Options as RawTSLoaderOptions } from 'ts-loader';
|
|
5
|
+
export type { Options as HTMLPluginOptions } from 'html-webpack-plugin';
|
|
6
|
+
export type { SubresourceIntegrityPluginOptions as SubresourceIntegrityOptions } from 'webpack-subresource-integrity';
|
|
7
|
+
export type TSLoaderOptions = Partial<RawTSLoaderOptions>;
|
|
8
|
+
export type { webpack, WebpackChain, WebpackConfig };
|
|
9
|
+
export type { CSSExtractOptions, MiniCSSExtractPluginOptions, MiniCSSExtractLoaderOptions } from './css';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var thirdParty_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(thirdParty_exports);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare class ModuleScopePlugin {
|
|
2
|
+
scopes: Array<string | RegExp>;
|
|
3
|
+
allowedFiles: Set<string>;
|
|
4
|
+
allowedDirs: string[];
|
|
5
|
+
allowedPatterns: RegExp[];
|
|
6
|
+
relativeAllowedDirs: string[];
|
|
7
|
+
cache: Map<string, boolean>;
|
|
8
|
+
constructor({
|
|
9
|
+
scopes,
|
|
10
|
+
allowedFiles
|
|
11
|
+
}: {
|
|
12
|
+
scopes: Array<string | RegExp>;
|
|
13
|
+
allowedFiles?: string[];
|
|
14
|
+
});
|
|
15
|
+
apply(resolver: any): void;
|
|
16
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var ModuleScopePlugin_exports = {};
|
|
20
|
+
__export(ModuleScopePlugin_exports, {
|
|
21
|
+
ModuleScopePlugin: () => ModuleScopePlugin
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(ModuleScopePlugin_exports);
|
|
24
|
+
var import_path = require("path");
|
|
25
|
+
var import_chalk = require("@rsbuild/shared/chalk");
|
|
26
|
+
var import_shared = require("@rsbuild/shared");
|
|
27
|
+
class ModuleScopePlugin {
|
|
28
|
+
constructor({
|
|
29
|
+
scopes,
|
|
30
|
+
allowedFiles = []
|
|
31
|
+
}) {
|
|
32
|
+
this.scopes = scopes;
|
|
33
|
+
this.allowedFiles = new Set(allowedFiles);
|
|
34
|
+
this.allowedDirs = scopes.filter(import_shared.isString);
|
|
35
|
+
this.allowedPatterns = scopes.filter(import_shared.isRegExp);
|
|
36
|
+
this.relativeAllowedDirs = this.allowedDirs.map(
|
|
37
|
+
(allowedDir) => `${(0, import_path.relative)((0, import_path.dirname)(allowedDir), allowedDir)}/`
|
|
38
|
+
);
|
|
39
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
40
|
+
}
|
|
41
|
+
apply(resolver) {
|
|
42
|
+
const { allowedFiles, allowedDirs, allowedPatterns, relativeAllowedDirs } = this;
|
|
43
|
+
resolver.hooks.file.tapAsync(
|
|
44
|
+
"ModuleScopePlugin",
|
|
45
|
+
(request, contextResolver, callback) => {
|
|
46
|
+
const { issuer } = request.context;
|
|
47
|
+
if (!issuer || this.cache.get(issuer)) {
|
|
48
|
+
return callback();
|
|
49
|
+
}
|
|
50
|
+
this.cache.set(issuer, true);
|
|
51
|
+
if (
|
|
52
|
+
// If this resolves to a node_module, we don't care what happens next
|
|
53
|
+
request.descriptionFileRoot.indexOf("/node_modules/") !== -1 || request.descriptionFileRoot.indexOf("\\node_modules\\") !== -1 || !request.__innerRequest_request
|
|
54
|
+
) {
|
|
55
|
+
return callback();
|
|
56
|
+
}
|
|
57
|
+
if (allowedDirs.every((allowedDir) => {
|
|
58
|
+
const result = (0, import_path.relative)(allowedDir, issuer);
|
|
59
|
+
return result.startsWith("../") || result.startsWith("..\\");
|
|
60
|
+
})) {
|
|
61
|
+
return callback();
|
|
62
|
+
}
|
|
63
|
+
const requestFullPath = (0, import_path.resolve)(
|
|
64
|
+
(0, import_path.dirname)(issuer),
|
|
65
|
+
request.__innerRequest_request
|
|
66
|
+
);
|
|
67
|
+
if (allowedPatterns.some(
|
|
68
|
+
(allowedPattern) => allowedPattern.test(requestFullPath)
|
|
69
|
+
)) {
|
|
70
|
+
return callback();
|
|
71
|
+
}
|
|
72
|
+
if (allowedFiles.has(requestFullPath)) {
|
|
73
|
+
return callback();
|
|
74
|
+
}
|
|
75
|
+
if (allowedDirs.every((allowedDir) => {
|
|
76
|
+
const requestRelative = (0, import_path.relative)(allowedDir, requestFullPath);
|
|
77
|
+
return requestRelative.startsWith("../") || requestRelative.startsWith("..\\");
|
|
78
|
+
})) {
|
|
79
|
+
let message = `You attempted to import ${import_chalk.chalk.bold(
|
|
80
|
+
request.__innerRequest_request
|
|
81
|
+
)} which is not allowed. `;
|
|
82
|
+
if (allowedDirs.length) {
|
|
83
|
+
message += `Allowed dirs: ${import_chalk.chalk.bold(
|
|
84
|
+
relativeAllowedDirs.join(",")
|
|
85
|
+
)}. `;
|
|
86
|
+
}
|
|
87
|
+
if (allowedPatterns.length) {
|
|
88
|
+
message += `Allowed patterns: ${import_chalk.chalk.bold(
|
|
89
|
+
allowedPatterns.map((p) => p.toString()).join(",")
|
|
90
|
+
)}. `;
|
|
91
|
+
}
|
|
92
|
+
message += `Please check the source.moduleScopes configuration.`;
|
|
93
|
+
const scopeError = new Error(message);
|
|
94
|
+
Object.defineProperty(scopeError, "ModuleScopePlugin", {
|
|
95
|
+
value: true,
|
|
96
|
+
writable: false,
|
|
97
|
+
enumerable: false
|
|
98
|
+
});
|
|
99
|
+
this.cache.set(issuer, false);
|
|
100
|
+
return callback(scopeError, request);
|
|
101
|
+
} else {
|
|
102
|
+
return callback();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
109
|
+
0 && (module.exports = {
|
|
110
|
+
ModuleScopePlugin
|
|
111
|
+
});
|