@bleedingdev/modern-js-builder 3.9.0-ultramodern.8 → 3.9.3-ultramodern.1
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/dist/cjs/index.js +6 -2
- package/dist/cjs/plugins/environmentDefaults.js +9 -8
- package/dist/cjs/plugins/manifest.js +3 -1
- package/dist/cjs/plugins/rscConfig.js +35 -14
- package/dist/cjs/shared/parseCommonConfig.js +44 -22
- package/dist/cjs/shared/pluginOptions.js +122 -0
- package/dist/cjs/shared/tsgo.js +253 -0
- package/dist/esm/index.mjs +1 -0
- package/dist/esm/plugins/environmentDefaults.mjs +9 -8
- package/dist/esm/plugins/manifest.mjs +3 -1
- package/dist/esm/plugins/rscConfig.mjs +35 -14
- package/dist/esm/shared/parseCommonConfig.mjs +45 -23
- package/dist/esm/shared/pluginOptions.mjs +75 -0
- package/dist/esm/shared/tsgo.mjs +198 -0
- package/dist/esm-node/index.mjs +1 -0
- package/dist/esm-node/plugins/environmentDefaults.mjs +9 -8
- package/dist/esm-node/plugins/manifest.mjs +3 -1
- package/dist/esm-node/plugins/rscConfig.mjs +35 -14
- package/dist/esm-node/shared/parseCommonConfig.mjs +45 -23
- package/dist/esm-node/shared/pluginOptions.mjs +76 -0
- package/dist/esm-node/shared/tsgo.mjs +199 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/plugins/rscConfig.d.ts +4 -1
- package/dist/types/shared/pluginOptions.d.ts +32 -0
- package/dist/types/shared/tsgo.d.ts +25 -0
- package/dist/types/types.d.ts +36 -9
- package/package.json +38 -23
package/dist/cjs/index.js
CHANGED
|
@@ -35,10 +35,12 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
35
35
|
createBuilder: ()=>external_createBuilder_js_namespaceObject.createRspackBuilder,
|
|
36
36
|
isHtmlDisabled: ()=>utils_js_namespaceObject.isHtmlDisabled,
|
|
37
37
|
logger: ()=>core_namespaceObject.logger,
|
|
38
|
-
parseRspackConfig: ()=>external_createBuilder_js_namespaceObject.parseConfig
|
|
38
|
+
parseRspackConfig: ()=>external_createBuilder_js_namespaceObject.parseConfig,
|
|
39
|
+
refreshTsgoCheckerConfig: ()=>tsgo_js_namespaceObject.refreshTsgoCheckerConfig
|
|
39
40
|
});
|
|
40
41
|
const external_createBuilder_js_namespaceObject = require("./createBuilder.js");
|
|
41
42
|
const core_namespaceObject = require("@rsbuild/core");
|
|
43
|
+
const tsgo_js_namespaceObject = require("./shared/tsgo.js");
|
|
42
44
|
const utils_js_namespaceObject = require("./shared/utils.js");
|
|
43
45
|
exports.RUNTIME_CHUNK_NAME = __webpack_exports__.RUNTIME_CHUNK_NAME;
|
|
44
46
|
exports.RUNTIME_CHUNK_REGEX = __webpack_exports__.RUNTIME_CHUNK_REGEX;
|
|
@@ -48,6 +50,7 @@ exports.createBuilder = __webpack_exports__.createBuilder;
|
|
|
48
50
|
exports.isHtmlDisabled = __webpack_exports__.isHtmlDisabled;
|
|
49
51
|
exports.logger = __webpack_exports__.logger;
|
|
50
52
|
exports.parseRspackConfig = __webpack_exports__.parseRspackConfig;
|
|
53
|
+
exports.refreshTsgoCheckerConfig = __webpack_exports__.refreshTsgoCheckerConfig;
|
|
51
54
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
52
55
|
"RUNTIME_CHUNK_NAME",
|
|
53
56
|
"RUNTIME_CHUNK_REGEX",
|
|
@@ -56,7 +59,8 @@ for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
|
56
59
|
"createBuilder",
|
|
57
60
|
"isHtmlDisabled",
|
|
58
61
|
"logger",
|
|
59
|
-
"parseRspackConfig"
|
|
62
|
+
"parseRspackConfig",
|
|
63
|
+
"refreshTsgoCheckerConfig"
|
|
60
64
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
61
65
|
Object.defineProperty(exports, '__esModule', {
|
|
62
66
|
value: true
|
|
@@ -88,14 +88,15 @@ const pluginEnvironmentDefaults = (distPath = {})=>({
|
|
|
88
88
|
});
|
|
89
89
|
api.modifyBundlerChain(async (chain, { environment })=>{
|
|
90
90
|
const isServiceWorker = environment.name === utils_js_namespaceObject.SERVICE_WORKER_ENVIRONMENT_NAME;
|
|
91
|
-
if (isServiceWorker
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
91
|
+
if (isServiceWorker) {
|
|
92
|
+
const library = chain.output.get('library');
|
|
93
|
+
chain.output.library({
|
|
94
|
+
...'string' == typeof library || Array.isArray(library) ? {
|
|
95
|
+
name: library
|
|
96
|
+
} : library,
|
|
97
|
+
type: true === chain.output.get('module') ? 'module' : 'commonjs2'
|
|
98
|
+
});
|
|
99
|
+
}
|
|
99
100
|
});
|
|
100
101
|
}
|
|
101
102
|
});
|
|
@@ -40,7 +40,9 @@ const pluginManifest = ()=>({
|
|
|
40
40
|
chain.plugin(CHAIN_ID.PLUGIN.MANIFEST).use(RspackManifestPlugin, [
|
|
41
41
|
{
|
|
42
42
|
fileName: 'web' === target ? 'asset-manifest.json' : `asset-manifest-${target}.json`,
|
|
43
|
-
publicPath
|
|
43
|
+
...'string' == typeof publicPath ? {
|
|
44
|
+
publicPath
|
|
45
|
+
} : {},
|
|
44
46
|
generate: manifest_js_namespaceObject.generateManifest
|
|
45
47
|
}
|
|
46
48
|
]);
|
|
@@ -46,19 +46,26 @@ var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_na
|
|
|
46
46
|
const ASYNC_STORAGE_PATTERN = /universal[/\\]async_storage/;
|
|
47
47
|
const SERVER_LOADER_ENTRY_PATTERN = /[/\\](?:server-loader-combined|route-server-loaders)\.js$/;
|
|
48
48
|
const RENDER_RSC_SOURCE_PATTERN = /render[/\\].*[/\\]server[/\\]rsc/;
|
|
49
|
-
const RENDER_RSC_RSLIB_ENTRY_PATTERN = /render[/\\]dist[/\\]esm[/\\]rsc(
|
|
50
|
-
const RENDER_RSC_RUNTIME = '@modern-js/render/rsc';
|
|
51
|
-
const RENDER_RSC_WORKER_RUNTIME = '@modern-js/render/rsc-worker';
|
|
49
|
+
const RENDER_RSC_RSLIB_ENTRY_PATTERN = /render[/\\]dist[/\\]esm[/\\]rsc(?:\.edge)?\.mjs$/;
|
|
52
50
|
const RSC_COMMON_LAYER = 'rsc-common';
|
|
53
51
|
const ENTRY_NAME_VAR = '__MODERN_JS_ENTRY_NAME';
|
|
54
52
|
const ROUTE_DATA_FILE_PATTERN = /[/\\]routes[/\\](?:.*[/\\])?(?:layout|page|\$)\.(?:loader|data)\.[tj]sx?(?:\?.*)?$/;
|
|
55
53
|
const createVirtualModule = (content)=>`data:text/javascript,${encodeURIComponent(content)}`;
|
|
54
|
+
const resolveRscEnvironments = (environments)=>{
|
|
55
|
+
const resolved = {
|
|
56
|
+
server: environments?.server ?? 'server',
|
|
57
|
+
client: environments?.client ?? 'client'
|
|
58
|
+
};
|
|
59
|
+
for (const [role, name] of Object.entries(resolved))if ('string' != typeof name || !name.trim()) throw new TypeError(`RSC ${role} environment must have a nonempty name`);
|
|
60
|
+
return resolved;
|
|
61
|
+
};
|
|
56
62
|
const isAsyncStorageExclude = (exclude)=>{
|
|
57
63
|
if ('string' == typeof exclude) return ASYNC_STORAGE_PATTERN.test(exclude);
|
|
58
64
|
if (exclude instanceof RegExp) return exclude.test('universal/async_storage') || exclude.test('universal\\async_storage');
|
|
59
65
|
return false;
|
|
60
66
|
};
|
|
61
|
-
function pluginRscConfig() {
|
|
67
|
+
function pluginRscConfig(environments, rscLayerMatchers = []) {
|
|
68
|
+
const serverEnvironment = resolveRscEnvironments(environments).server;
|
|
62
69
|
return {
|
|
63
70
|
name: 'builder:rsc-config',
|
|
64
71
|
setup (api) {
|
|
@@ -71,9 +78,8 @@ function pluginRscConfig() {
|
|
|
71
78
|
return layersCache;
|
|
72
79
|
};
|
|
73
80
|
api.modifyBundlerChain({
|
|
74
|
-
handler: (chain, { isServer })=>{
|
|
75
|
-
if (isServer) {
|
|
76
|
-
chain.resolve.alias.set(`${RENDER_RSC_RUNTIME}$`, RENDER_RSC_WORKER_RUNTIME);
|
|
81
|
+
handler: (chain, { isServer, environment })=>{
|
|
82
|
+
if (isServer || environment.name === serverEnvironment) {
|
|
77
83
|
let emptyModulePath;
|
|
78
84
|
try {
|
|
79
85
|
emptyModulePath = require.resolve('../shared/rsc/rscEmptyModule');
|
|
@@ -96,9 +102,25 @@ function pluginRscConfig() {
|
|
|
96
102
|
order: 'pre'
|
|
97
103
|
});
|
|
98
104
|
api.modifyRspackConfig(async (config, utils)=>{
|
|
99
|
-
const isServer = 'node' === config.target || 'node' === utils.target || utils.environment?.name ===
|
|
105
|
+
const isServer = 'node' === config.target || 'node' === utils.target || utils.environment?.name === serverEnvironment;
|
|
100
106
|
if (!isServer) return;
|
|
101
107
|
const Layers = await getLayers();
|
|
108
|
+
if (utils.environment?.name !== serverEnvironment && rscLayerMatchers.length > 0) {
|
|
109
|
+
config.module ??= {};
|
|
110
|
+
config.module.rules ??= [];
|
|
111
|
+
config.module.rules.push({
|
|
112
|
+
test: rscLayerMatchers,
|
|
113
|
+
layer: Layers.rsc
|
|
114
|
+
}, {
|
|
115
|
+
issuerLayer: Layers.rsc,
|
|
116
|
+
resolve: {
|
|
117
|
+
conditionNames: [
|
|
118
|
+
'react-server',
|
|
119
|
+
'...'
|
|
120
|
+
]
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
102
124
|
if (config.entry) {
|
|
103
125
|
const entries = config.entry;
|
|
104
126
|
const newEntries = {};
|
|
@@ -135,8 +157,8 @@ function pluginRscConfig() {
|
|
|
135
157
|
});
|
|
136
158
|
}
|
|
137
159
|
});
|
|
138
|
-
api.modifyBundlerChain((chain, { isServer, isWebWorker })=>{
|
|
139
|
-
if (!isServer && !isWebWorker) {
|
|
160
|
+
api.modifyBundlerChain((chain, { isServer, isWebWorker, environment })=>{
|
|
161
|
+
if (!isServer && !isWebWorker && environment.name !== serverEnvironment) {
|
|
140
162
|
const entries = chain.entryPoints.entries();
|
|
141
163
|
if (entries && 'object' == typeof entries) for (const entryName of Object.keys(entries)){
|
|
142
164
|
const entryPoint = chain.entry(entryName);
|
|
@@ -150,13 +172,12 @@ function pluginRscConfig() {
|
|
|
150
172
|
}
|
|
151
173
|
async function getRscPlugins(enableRsc, internalDirectory, environments) {
|
|
152
174
|
if (enableRsc) {
|
|
175
|
+
const rscEnvironments = resolveRscEnvironments(environments);
|
|
153
176
|
const rscLayerMatchers = createRscLayerMatchers(internalDirectory);
|
|
154
177
|
const { pluginRSC } = await import("rsbuild-plugin-rsc");
|
|
155
178
|
return [
|
|
156
179
|
pluginRSC({
|
|
157
|
-
|
|
158
|
-
environments
|
|
159
|
-
} : {},
|
|
180
|
+
environments: rscEnvironments,
|
|
160
181
|
layers: {
|
|
161
182
|
ssr: SERVER_LOADER_ENTRY_PATTERN,
|
|
162
183
|
rsc: [
|
|
@@ -167,7 +188,7 @@ async function getRscPlugins(enableRsc, internalDirectory, environments) {
|
|
|
167
188
|
]
|
|
168
189
|
}
|
|
169
190
|
}),
|
|
170
|
-
pluginRscConfig()
|
|
191
|
+
pluginRscConfig(rscEnvironments, rscLayerMatchers)
|
|
171
192
|
];
|
|
172
193
|
}
|
|
173
194
|
return [];
|
|
@@ -34,7 +34,6 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
34
34
|
const core_namespaceObject = require("@rsbuild/core");
|
|
35
35
|
const plugin_css_minimizer_namespaceObject = require("@rsbuild/plugin-css-minimizer");
|
|
36
36
|
const plugin_less_namespaceObject = require("@rsbuild/plugin-less");
|
|
37
|
-
const plugin_react_namespaceObject = require("@rsbuild/plugin-react");
|
|
38
37
|
const plugin_sass_namespaceObject = require("@rsbuild/plugin-sass");
|
|
39
38
|
const devtools_js_namespaceObject = require("../plugins/devtools.js");
|
|
40
39
|
const emitRouteFile_js_namespaceObject = require("../plugins/emitRouteFile.js");
|
|
@@ -43,6 +42,8 @@ const globalVars_js_namespaceObject = require("../plugins/globalVars.js");
|
|
|
43
42
|
const htmlMinify_js_namespaceObject = require("../plugins/htmlMinify.js");
|
|
44
43
|
const runtimeChunk_js_namespaceObject = require("../plugins/runtimeChunk.js");
|
|
45
44
|
const external_devServer_js_namespaceObject = require("./devServer.js");
|
|
45
|
+
const external_pluginOptions_js_namespaceObject = require("./pluginOptions.js");
|
|
46
|
+
const external_tsgo_js_namespaceObject = require("./tsgo.js");
|
|
46
47
|
const external_utils_js_namespaceObject = require("./utils.js");
|
|
47
48
|
const CSS_MODULES_REGEX = /\.modules?\.\w+$/i;
|
|
48
49
|
const GLOBAL_CSS_REGEX = /\.global\.\w+$/;
|
|
@@ -69,7 +70,7 @@ function removeUndefinedKey(obj) {
|
|
|
69
70
|
}
|
|
70
71
|
async function parseCommonConfig(builderConfig, options) {
|
|
71
72
|
const frameworkConfigPath = options?.frameworkConfigPath;
|
|
72
|
-
const { plugins: [...plugins] = [], splitChunks, performance: { ...performanceConfig } = {}, output: { module = false, enableCssModuleTSDeclaration, disableCssModuleExtension, disableTsChecker, disableSvgr, svgDefaultExport, assetsRetry, enableAssetManifest, sourceMap, convertToRem, polyfill, dataUriLimit = 10000, distPath = {}, ...outputConfig } = {}, html: { outputStructure, appIcon, ...htmlConfig } = {}, source: { alias, globalVars, transformImport, reactCompiler, ...sourceConfig } = {}, dev = {}, server = {}, security: { checkSyntax, sri, ...securityConfig } = {}, tools: { devServer, tsChecker, minifyCss, less, sass, htmlPlugin, autoprefixer, ...toolsConfig } = {}, environments = {}, resolve = {} } = builderConfig;
|
|
73
|
+
const { plugins: [...plugins] = [], splitChunks, performance: { ...performanceConfig } = {}, output: { module = false, enableCssModuleTSDeclaration, disableCssModuleExtension, disableTsChecker, disableSvgr, svgDefaultExport, assetsRetry, enableAssetManifest, sourceMap, convertToRem, polyfill, dataUriLimit = 10000, distPath = {}, ...outputConfig } = {}, html: { outputStructure, appIcon, ...htmlConfig } = {}, source: { alias, globalVars, transformImport, reactCompiler, ...sourceConfig } = {}, dev = {}, server = {}, security: { checkSyntax, sri, ...securityConfig } = {}, tools: { devServer, tsChecker, minifyCss, less, sass, svgr, htmlPlugin, autoprefixer, ...toolsConfig } = {}, environments = {}, resolve = {} } = builderConfig;
|
|
73
74
|
let combinedAlias;
|
|
74
75
|
if (alias || resolve.alias) combinedAlias = [].concat(alias ?? []).concat(resolve.alias ?? []);
|
|
75
76
|
const rsbuildConfig = {
|
|
@@ -152,12 +153,8 @@ async function parseCommonConfig(builderConfig, options) {
|
|
|
152
153
|
sourceMap
|
|
153
154
|
}),
|
|
154
155
|
(0, emitRouteFile_js_namespaceObject.pluginEmitRouteFile)(),
|
|
155
|
-
(0, plugin_sass_namespaceObject.pluginSass)(
|
|
156
|
-
|
|
157
|
-
}),
|
|
158
|
-
(0, plugin_less_namespaceObject.pluginLess)({
|
|
159
|
-
lessLoaderOptions: less
|
|
160
|
-
}),
|
|
156
|
+
(0, plugin_sass_namespaceObject.pluginSass)((0, external_pluginOptions_js_namespaceObject.normalizeSassOptions)(sass)),
|
|
157
|
+
(0, plugin_less_namespaceObject.pluginLess)((0, external_pluginOptions_js_namespaceObject.normalizeLessOptions)(less)),
|
|
161
158
|
(0, environmentDefaults_js_namespaceObject.pluginEnvironmentDefaults)(distPath),
|
|
162
159
|
(0, htmlMinify_js_namespaceObject.pluginHtmlMinifierTerser)()
|
|
163
160
|
];
|
|
@@ -168,7 +165,7 @@ async function parseCommonConfig(builderConfig, options) {
|
|
|
168
165
|
if (!disableTsChecker) {
|
|
169
166
|
const { pluginTypeCheck } = await import("@rsbuild/plugin-type-check");
|
|
170
167
|
rsbuildPlugins.push(pluginTypeCheck({
|
|
171
|
-
tsCheckerOptions: tsChecker
|
|
168
|
+
tsCheckerOptions: (0, external_tsgo_js_namespaceObject.withTsgoDefaults)(tsChecker, options?.cwd ?? process.cwd())
|
|
172
169
|
}));
|
|
173
170
|
}
|
|
174
171
|
if (convertToRem) {
|
|
@@ -184,19 +181,44 @@ async function parseCommonConfig(builderConfig, options) {
|
|
|
184
181
|
const { pluginSourceBuild } = await import("@rsbuild/plugin-source-build");
|
|
185
182
|
rsbuildPlugins.push(pluginSourceBuild(true === sourceBuild ? {} : sourceBuild));
|
|
186
183
|
}
|
|
187
|
-
rsbuildPlugins.push(
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
|
|
184
|
+
rsbuildPlugins.push({
|
|
185
|
+
name: 'rsbuild:react',
|
|
186
|
+
async setup (api) {
|
|
187
|
+
const { pluginReact } = await import("@rsbuild/plugin-react");
|
|
188
|
+
return pluginReact().setup(api);
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
if (!options?.disableReactCompiler && void 0 !== reactCompiler) rsbuildPlugins.push({
|
|
192
|
+
name: 'builder:react-compiler',
|
|
193
|
+
setup (api) {
|
|
194
|
+
api.modifyEnvironmentConfig((config, { name, mergeEnvironmentConfig })=>'web' === config.output.target && name !== external_utils_js_namespaceObject.SERVICE_WORKER_ENVIRONMENT_NAME ? mergeEnvironmentConfig({
|
|
195
|
+
tools: {
|
|
196
|
+
swc: {
|
|
197
|
+
jsc: {
|
|
198
|
+
transform: {
|
|
199
|
+
reactCompiler
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}, config) : config);
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
const svgrOptions = (0, external_pluginOptions_js_namespaceObject.resolveSvgrOptions)({
|
|
208
|
+
svgr,
|
|
209
|
+
disableSvgr,
|
|
210
|
+
svgDefaultExport
|
|
211
|
+
});
|
|
212
|
+
if (false !== svgrOptions) rsbuildPlugins.push({
|
|
213
|
+
name: 'rsbuild:svgr',
|
|
214
|
+
pre: [
|
|
215
|
+
'rsbuild:react'
|
|
216
|
+
],
|
|
217
|
+
async setup (api) {
|
|
218
|
+
const { pluginSvgr } = await import("@rsbuild/plugin-svgr");
|
|
219
|
+
await pluginSvgr(svgrOptions).setup(api);
|
|
220
|
+
}
|
|
221
|
+
});
|
|
200
222
|
if (assetsRetry) {
|
|
201
223
|
const { pluginAssetsRetry } = await import("@rsbuild/plugin-assets-retry");
|
|
202
224
|
rsbuildPlugins.push(pluginAssetsRetry(assetsRetry));
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
normalizeLessOptions: ()=>normalizeLessOptions,
|
|
32
|
+
normalizeSassOptions: ()=>normalizeSassOptions,
|
|
33
|
+
resetPluginOptionsWarnings: ()=>resetPluginOptionsWarnings,
|
|
34
|
+
resolveSvgrOptions: ()=>resolveSvgrOptions
|
|
35
|
+
});
|
|
36
|
+
const utils_namespaceObject = require("@modern-js/utils");
|
|
37
|
+
const LESS_PLUGIN_KEYS = [
|
|
38
|
+
'lessLoaderOptions',
|
|
39
|
+
'include',
|
|
40
|
+
'exclude',
|
|
41
|
+
'parallel'
|
|
42
|
+
];
|
|
43
|
+
const SASS_PLUGIN_KEYS = [
|
|
44
|
+
'sassLoaderOptions',
|
|
45
|
+
'include',
|
|
46
|
+
'exclude',
|
|
47
|
+
'rewriteUrls'
|
|
48
|
+
];
|
|
49
|
+
const warned = new Set();
|
|
50
|
+
const resetPluginOptionsWarnings = ()=>{
|
|
51
|
+
warned.clear();
|
|
52
|
+
};
|
|
53
|
+
const warnOnceInDev = (key, message)=>{
|
|
54
|
+
if (!(0, utils_namespaceObject.isDevCommand)() || warned.has(key)) return;
|
|
55
|
+
warned.add(key);
|
|
56
|
+
utils_namespaceObject.logger.warn(message);
|
|
57
|
+
};
|
|
58
|
+
const isPlainObject = (value)=>'object' == typeof value && null !== value && !Array.isArray(value);
|
|
59
|
+
const isPluginLevelOptions = (value, pluginKeys)=>isPlainObject(value) && pluginKeys.some((key)=>key in value);
|
|
60
|
+
const isEmptyObject = (value)=>isPlainObject(value) && 0 === Object.keys(value).length;
|
|
61
|
+
const warnIgnoredKeys = (name, value, pluginKeys, loaderOptionsKey)=>{
|
|
62
|
+
const pluginLevel = Object.keys(value).filter((key)=>pluginKeys.includes(key));
|
|
63
|
+
const ignored = Object.keys(value).filter((key)=>!pluginKeys.includes(key));
|
|
64
|
+
if (0 === ignored.length) return;
|
|
65
|
+
warnOnceInDev(`${name}:mixed`, `\`${name}\` contains plugin-level options (${pluginLevel.join(', ')}) together with other keys (${ignored.join(', ')}). The whole object is passed to the plugin, so the other keys are ignored. Move loader options under \`${loaderOptionsKey}\`.`);
|
|
66
|
+
};
|
|
67
|
+
const normalizeLessOptions = (less)=>{
|
|
68
|
+
if (isPluginLevelOptions(less, LESS_PLUGIN_KEYS)) {
|
|
69
|
+
warnIgnoredKeys('tools.less', less, LESS_PLUGIN_KEYS, 'lessLoaderOptions');
|
|
70
|
+
return less;
|
|
71
|
+
}
|
|
72
|
+
if (void 0 !== less && !isEmptyObject(less)) warnOnceInDev('tools.less', "`tools.less` now accepts the full options of @rsbuild/plugin-less. Passing less-loader options directly is deprecated and will stop working in the next major version. Move them under `lessLoaderOptions`:\n before: tools: { less: { lessOptions: { javascriptEnabled: true } } }\n after: tools: { less: { lessLoaderOptions: { lessOptions: { javascriptEnabled: true } } } }");
|
|
73
|
+
return {
|
|
74
|
+
lessLoaderOptions: less
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
const normalizeSassOptions = (sass)=>{
|
|
78
|
+
if (isPluginLevelOptions(sass, SASS_PLUGIN_KEYS)) {
|
|
79
|
+
warnIgnoredKeys('tools.sass', sass, SASS_PLUGIN_KEYS, 'sassLoaderOptions');
|
|
80
|
+
return sass;
|
|
81
|
+
}
|
|
82
|
+
if (void 0 !== sass && !isEmptyObject(sass)) warnOnceInDev('tools.sass', "`tools.sass` now accepts the full options of @rsbuild/plugin-sass. Passing sass-loader options directly is deprecated and will stop working in the next major version. Move them under `sassLoaderOptions`:\n before: tools: { sass: { sassOptions: { quietDeps: true } } }\n after: tools: { sass: { sassLoaderOptions: { sassOptions: { quietDeps: true } } } }");
|
|
83
|
+
return {
|
|
84
|
+
sassLoaderOptions: sass
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
const mergeSvgrOptions = (target, source)=>{
|
|
88
|
+
const svgrOptions = source.svgrOptions ? {
|
|
89
|
+
...target.svgrOptions,
|
|
90
|
+
...source.svgrOptions
|
|
91
|
+
} : target.svgrOptions;
|
|
92
|
+
return Object.assign(target, source, {
|
|
93
|
+
svgrOptions
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
const resolveSvgrOptions = ({ svgr, disableSvgr, svgDefaultExport })=>{
|
|
97
|
+
if (void 0 !== disableSvgr) warnOnceInDev('output.disableSvgr', disableSvgr ? '`output.disableSvgr` is deprecated and will be removed in the next major version. Use `tools: { svgr: false }` instead.' : '`output.disableSvgr` is deprecated and will be removed in the next major version. SVGR is enabled by default, so `output.disableSvgr: false` can be removed (or use `tools: { svgr: {} }` to keep it explicit).');
|
|
98
|
+
if (void 0 !== svgDefaultExport) warnOnceInDev('output.svgDefaultExport', "`output.svgDefaultExport` is deprecated and will be removed in the next major version. Use `tools.svgr.svgrOptions.exportType` instead:\n before: output: { svgDefaultExport: 'component' }\n after: tools: { svgr: { svgrOptions: { exportType: 'default' } } }\n ('url' maps to exportType: 'named')");
|
|
99
|
+
if (false === svgr) return false;
|
|
100
|
+
if (void 0 === svgr && disableSvgr) return false;
|
|
101
|
+
const defaults = {
|
|
102
|
+
mixedImport: true,
|
|
103
|
+
parallel: true,
|
|
104
|
+
svgrOptions: {
|
|
105
|
+
exportType: 'component' === svgDefaultExport ? 'default' : 'named'
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
return (0, utils_namespaceObject.applyOptionsChain)(defaults, svgr, void 0, mergeSvgrOptions);
|
|
109
|
+
};
|
|
110
|
+
exports.normalizeLessOptions = __webpack_exports__.normalizeLessOptions;
|
|
111
|
+
exports.normalizeSassOptions = __webpack_exports__.normalizeSassOptions;
|
|
112
|
+
exports.resetPluginOptionsWarnings = __webpack_exports__.resetPluginOptionsWarnings;
|
|
113
|
+
exports.resolveSvgrOptions = __webpack_exports__.resolveSvgrOptions;
|
|
114
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
115
|
+
"normalizeLessOptions",
|
|
116
|
+
"normalizeSassOptions",
|
|
117
|
+
"resetPluginOptionsWarnings",
|
|
118
|
+
"resolveSvgrOptions"
|
|
119
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
120
|
+
Object.defineProperty(exports, '__esModule', {
|
|
121
|
+
value: true
|
|
122
|
+
});
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const __rslib_import_meta_url__ = /*#__PURE__*/ function() {
|
|
3
|
+
return "u" < typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
|
|
4
|
+
}();
|
|
5
|
+
var __webpack_require__ = {};
|
|
6
|
+
(()=>{
|
|
7
|
+
__webpack_require__.n = (module)=>{
|
|
8
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
9
|
+
__webpack_require__.d(getter, {
|
|
10
|
+
a: getter
|
|
11
|
+
});
|
|
12
|
+
return getter;
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
17
|
+
var define = (defs, kind)=>{
|
|
18
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
[kind]: defs[key]
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
define(getters, "get");
|
|
24
|
+
define(values, "value");
|
|
25
|
+
};
|
|
26
|
+
})();
|
|
27
|
+
(()=>{
|
|
28
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
29
|
+
})();
|
|
30
|
+
(()=>{
|
|
31
|
+
__webpack_require__.r = (exports1)=>{
|
|
32
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
33
|
+
value: 'Module'
|
|
34
|
+
});
|
|
35
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
36
|
+
value: true
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
})();
|
|
40
|
+
var __webpack_exports__ = {};
|
|
41
|
+
__webpack_require__.r(__webpack_exports__);
|
|
42
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
43
|
+
refreshTsgoCheckerConfig: ()=>refreshTsgoCheckerConfig,
|
|
44
|
+
withTsgoDefaults: ()=>withTsgoDefaults
|
|
45
|
+
});
|
|
46
|
+
const external_node_crypto_namespaceObject = require("node:crypto");
|
|
47
|
+
const external_node_fs_namespaceObject = require("node:fs");
|
|
48
|
+
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
|
|
49
|
+
const external_node_module_namespaceObject = require("node:module");
|
|
50
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
51
|
+
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
52
|
+
const utils_namespaceObject = require("@modern-js/utils");
|
|
53
|
+
const builderRequire = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__);
|
|
54
|
+
const STABLE_TSGO_PACKAGE = "typescript/package.json";
|
|
55
|
+
const TSGO_CHECKER_DIR = external_node_path_default().join('.modern-js', 'tsgo');
|
|
56
|
+
const tryResolve = (request, rootPath)=>{
|
|
57
|
+
try {
|
|
58
|
+
return builderRequire.resolve(request, {
|
|
59
|
+
paths: [
|
|
60
|
+
rootPath
|
|
61
|
+
]
|
|
62
|
+
});
|
|
63
|
+
} catch {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const resolveTsgoPackagePath = (rootPath)=>{
|
|
68
|
+
const packageJsonPath = tryResolve(STABLE_TSGO_PACKAGE, rootPath) ?? builderRequire.resolve(STABLE_TSGO_PACKAGE);
|
|
69
|
+
const packageJson = JSON.parse(external_node_fs_default().readFileSync(packageJsonPath, 'utf8'));
|
|
70
|
+
if ("typescript" !== packageJson.name || '7.0.2' !== packageJson.version) throw new Error(`The native type checker requires typescript@7.0.2; found ${String(packageJson.name)}@${String(packageJson.version)} at ${packageJsonPath}.`);
|
|
71
|
+
return packageJsonPath;
|
|
72
|
+
};
|
|
73
|
+
const toPosixPath = (input)=>input.replaceAll(external_node_path_default().sep, '/');
|
|
74
|
+
const asTsConfigPath = (request)=>{
|
|
75
|
+
if (external_node_path_default().extname(request)) return [
|
|
76
|
+
request
|
|
77
|
+
];
|
|
78
|
+
return [
|
|
79
|
+
request,
|
|
80
|
+
`${request}.json`
|
|
81
|
+
];
|
|
82
|
+
};
|
|
83
|
+
const resolveExtends = (request, configDirectory)=>{
|
|
84
|
+
const configRequire = (0, external_node_module_namespaceObject.createRequire)(external_node_path_default().join(configDirectory, 'tsconfig.json'));
|
|
85
|
+
for (const candidate of asTsConfigPath(request)){
|
|
86
|
+
if (candidate.startsWith('.') || external_node_path_default().isAbsolute(candidate)) {
|
|
87
|
+
const resolved = external_node_path_default().resolve(configDirectory, candidate);
|
|
88
|
+
if (external_node_fs_default().existsSync(resolved)) return resolved;
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
try {
|
|
92
|
+
return configRequire.resolve(candidate);
|
|
93
|
+
} catch {}
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
const PATH_COMPILER_OPTIONS = [
|
|
97
|
+
'rootDir',
|
|
98
|
+
'outDir',
|
|
99
|
+
'declarationDir'
|
|
100
|
+
];
|
|
101
|
+
const absolutiseConfigPaths = (compilerOptions, configDirectory)=>{
|
|
102
|
+
if (!compilerOptions) return {};
|
|
103
|
+
const resolved = {
|
|
104
|
+
...compilerOptions
|
|
105
|
+
};
|
|
106
|
+
for (const option of PATH_COMPILER_OPTIONS){
|
|
107
|
+
const value = resolved[option];
|
|
108
|
+
if ('string' == typeof value && !external_node_path_default().isAbsolute(value)) resolved[option] = external_node_path_default().resolve(configDirectory, value);
|
|
109
|
+
}
|
|
110
|
+
return resolved;
|
|
111
|
+
};
|
|
112
|
+
const readTsConfig = (configFile, visited = new Set())=>{
|
|
113
|
+
if (visited.has(configFile) || !external_node_fs_default().existsSync(configFile)) return {};
|
|
114
|
+
visited.add(configFile);
|
|
115
|
+
const config = utils_namespaceObject.json5.parse(external_node_fs_default().readFileSync(configFile, 'utf8'));
|
|
116
|
+
const configDirectory = external_node_path_default().dirname(configFile);
|
|
117
|
+
const extendsList = Array.isArray(config.extends) ? config.extends : config.extends ? [
|
|
118
|
+
config.extends
|
|
119
|
+
] : [];
|
|
120
|
+
const baseConfig = extendsList.reduce((merged, request)=>{
|
|
121
|
+
const resolved = resolveExtends(request, configDirectory);
|
|
122
|
+
if (!resolved) return merged;
|
|
123
|
+
const parentConfig = readTsConfig(resolved, visited);
|
|
124
|
+
return {
|
|
125
|
+
...merged,
|
|
126
|
+
compilerOptions: {
|
|
127
|
+
...merged.compilerOptions ?? {},
|
|
128
|
+
...parentConfig.compilerOptions ?? {}
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
}, {});
|
|
132
|
+
return {
|
|
133
|
+
...baseConfig,
|
|
134
|
+
compilerOptions: {
|
|
135
|
+
...baseConfig.compilerOptions ?? {},
|
|
136
|
+
...absolutiseConfigPaths(config.compilerOptions, configDirectory)
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
const readProjectReferences = (configFile)=>{
|
|
141
|
+
if (!external_node_fs_default().existsSync(configFile)) return [];
|
|
142
|
+
const config = utils_namespaceObject.json5.parse(external_node_fs_default().readFileSync(configFile, 'utf8'));
|
|
143
|
+
if (!Array.isArray(config.references)) return [];
|
|
144
|
+
const configDirectory = external_node_path_default().dirname(configFile);
|
|
145
|
+
return config.references.filter((reference)=>'string' == typeof reference?.path).map((reference)=>({
|
|
146
|
+
...reference,
|
|
147
|
+
path: toPosixPath(external_node_path_default().resolve(configDirectory, reference.path))
|
|
148
|
+
}));
|
|
149
|
+
};
|
|
150
|
+
const toRelativeConfigPath = (fromDirectory, target)=>{
|
|
151
|
+
const relative = toPosixPath(external_node_path_default().relative(fromDirectory, target));
|
|
152
|
+
if (relative.startsWith('.')) return relative;
|
|
153
|
+
return `./${relative}`;
|
|
154
|
+
};
|
|
155
|
+
const writeFileIfChanged = (file, content)=>{
|
|
156
|
+
if (external_node_fs_default().existsSync(file) && external_node_fs_default().readFileSync(file, 'utf8') === content) return;
|
|
157
|
+
external_node_fs_default().writeFileSync(file, content);
|
|
158
|
+
};
|
|
159
|
+
const defaultTsgoCheckerConfigFile = (configFile)=>{
|
|
160
|
+
const hash = (0, external_node_crypto_namespaceObject.createHash)('sha1').update(configFile).digest('hex').slice(0, 10);
|
|
161
|
+
return external_node_path_default().join(external_node_path_default().dirname(configFile), TSGO_CHECKER_DIR, `tsconfig.${hash}.json`);
|
|
162
|
+
};
|
|
163
|
+
const createTsgoCheckerConfig = (configFile, checkerConfigFile = defaultTsgoCheckerConfigFile(configFile))=>{
|
|
164
|
+
const configDirectory = external_node_path_default().dirname(configFile);
|
|
165
|
+
const checkerConfigDirectory = external_node_path_default().dirname(checkerConfigFile);
|
|
166
|
+
const tsConfig = readTsConfig(configFile);
|
|
167
|
+
const compilerOptions = {
|
|
168
|
+
baseUrl: null
|
|
169
|
+
};
|
|
170
|
+
const declaredRootDir = tsConfig.compilerOptions?.rootDir;
|
|
171
|
+
if ('string' == typeof declaredRootDir) compilerOptions.rootDir = toPosixPath(declaredRootDir);
|
|
172
|
+
else compilerOptions.rootDir = toPosixPath(configDirectory);
|
|
173
|
+
const moduleResolution = String(tsConfig.compilerOptions?.moduleResolution).toLowerCase();
|
|
174
|
+
if ([
|
|
175
|
+
'node',
|
|
176
|
+
'node10'
|
|
177
|
+
].includes(moduleResolution)) compilerOptions.moduleResolution = null;
|
|
178
|
+
const references = readProjectReferences(configFile);
|
|
179
|
+
const checkerConfig = {
|
|
180
|
+
extends: toRelativeConfigPath(checkerConfigDirectory, configFile),
|
|
181
|
+
compilerOptions,
|
|
182
|
+
...references.length > 0 ? {
|
|
183
|
+
references
|
|
184
|
+
} : {}
|
|
185
|
+
};
|
|
186
|
+
external_node_fs_default().mkdirSync(checkerConfigDirectory, {
|
|
187
|
+
recursive: true
|
|
188
|
+
});
|
|
189
|
+
writeFileIfChanged(checkerConfigFile, `${JSON.stringify(checkerConfig, null, 2)}\n`);
|
|
190
|
+
return checkerConfigFile;
|
|
191
|
+
};
|
|
192
|
+
const refreshTsgoCheckerConfig = (checkerConfigFile)=>{
|
|
193
|
+
const checkerConfigDirectory = external_node_path_default().dirname(checkerConfigFile);
|
|
194
|
+
if ('tsgo' !== external_node_path_default().basename(checkerConfigDirectory) || '.modern-js' !== external_node_path_default().basename(external_node_path_default().dirname(checkerConfigDirectory)) || !external_node_fs_default().existsSync(checkerConfigFile)) return;
|
|
195
|
+
let checkerConfig;
|
|
196
|
+
try {
|
|
197
|
+
checkerConfig = utils_namespaceObject.json5.parse(external_node_fs_default().readFileSync(checkerConfigFile, 'utf8'));
|
|
198
|
+
} catch {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
if ('string' != typeof checkerConfig.extends) return;
|
|
202
|
+
const projectConfigFile = external_node_path_default().resolve(checkerConfigDirectory, checkerConfig.extends);
|
|
203
|
+
if (external_node_fs_default().existsSync(projectConfigFile)) try {
|
|
204
|
+
createTsgoCheckerConfig(projectConfigFile, checkerConfigFile);
|
|
205
|
+
} catch {}
|
|
206
|
+
return projectConfigFile;
|
|
207
|
+
};
|
|
208
|
+
const normalizeTsgoConfig = (config, rootPath)=>{
|
|
209
|
+
const { typescript } = config;
|
|
210
|
+
if (typescript?.tsgo === false) return config;
|
|
211
|
+
const compilerOptions = {
|
|
212
|
+
...typescript?.configOverwrite?.compilerOptions ?? {},
|
|
213
|
+
baseUrl: null
|
|
214
|
+
};
|
|
215
|
+
if ([
|
|
216
|
+
'node',
|
|
217
|
+
'node10'
|
|
218
|
+
].includes(String(compilerOptions.moduleResolution).toLowerCase())) compilerOptions.moduleResolution = null;
|
|
219
|
+
config.typescript = {
|
|
220
|
+
...typescript,
|
|
221
|
+
configOverwrite: {
|
|
222
|
+
...typescript?.configOverwrite ?? {},
|
|
223
|
+
compilerOptions
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
if (typescript?.configFile) config.typescript.configFile = createTsgoCheckerConfig(external_node_path_default().resolve(rootPath, typescript.configFile));
|
|
227
|
+
return config;
|
|
228
|
+
};
|
|
229
|
+
const withTsgoDefaults = (userOptions, rootPath)=>{
|
|
230
|
+
const tsgoPath = resolveTsgoPackagePath(rootPath);
|
|
231
|
+
const userChain = userOptions ? Array.isArray(userOptions) ? userOptions : [
|
|
232
|
+
userOptions
|
|
233
|
+
] : [];
|
|
234
|
+
return [
|
|
235
|
+
{
|
|
236
|
+
typescript: {
|
|
237
|
+
tsgo: true,
|
|
238
|
+
typescriptPath: tsgoPath
|
|
239
|
+
}
|
|
240
|
+
},
|
|
241
|
+
...userChain,
|
|
242
|
+
(config)=>normalizeTsgoConfig(config, rootPath)
|
|
243
|
+
];
|
|
244
|
+
};
|
|
245
|
+
exports.refreshTsgoCheckerConfig = __webpack_exports__.refreshTsgoCheckerConfig;
|
|
246
|
+
exports.withTsgoDefaults = __webpack_exports__.withTsgoDefaults;
|
|
247
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
248
|
+
"refreshTsgoCheckerConfig",
|
|
249
|
+
"withTsgoDefaults"
|
|
250
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
251
|
+
Object.defineProperty(exports, '__esModule', {
|
|
252
|
+
value: true
|
|
253
|
+
});
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { createRspackBuilder as createBuilder, parseConfig as parseRspackConfig } from "./createBuilder.mjs";
|
|
2
2
|
export { logger } from "@rsbuild/core";
|
|
3
|
+
export { refreshTsgoCheckerConfig } from "./shared/tsgo.mjs";
|
|
3
4
|
export { RUNTIME_CHUNK_NAME, RUNTIME_CHUNK_REGEX, SERVICE_WORKER_ENVIRONMENT_NAME, castArray, isHtmlDisabled } from "./shared/utils.mjs";
|