@rsbuild/core 0.3.11 → 0.4.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/cli/commands.js +2 -2
- package/dist/cli/config.d.ts +1 -6
- package/dist/cli/config.js +20 -34
- package/dist/cli/prepare.js +1 -1
- package/dist/constants.d.ts +0 -1
- package/dist/constants.js +0 -3
- package/dist/createRsbuild.js +6 -4
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -3
- package/dist/pluginManager.d.ts +7 -0
- package/dist/pluginManager.js +176 -0
- package/dist/plugins/index.js +2 -1
- package/dist/plugins/moduleFederation.d.ts +2 -0
- package/dist/plugins/moduleFederation.js +123 -0
- package/dist/provider/config.d.ts +1 -1
- package/dist/provider/config.js +107 -8
- package/dist/provider/{core/createCompiler.d.ts → createCompiler.d.ts} +1 -1
- package/dist/provider/{core/createCompiler.js → createCompiler.js} +1 -1
- package/dist/provider/{core/createContext.d.ts → createContext.d.ts} +1 -1
- package/dist/provider/{core/createContext.js → createContext.js} +2 -2
- package/dist/provider/index.d.ts +6 -6
- package/dist/provider/index.js +11 -9
- package/dist/provider/initConfigs.d.ts +11 -0
- package/dist/provider/{core/initConfigs.js → initConfigs.js} +8 -7
- package/dist/provider/{core/initHooks.d.ts → initHooks.d.ts} +2 -1
- package/dist/provider/{core/initHooks.js → initHooks.js} +1 -0
- package/dist/provider/initPlugins.d.ts +7 -0
- package/dist/provider/{core/initPlugins.js → initPlugins.js} +3 -2
- package/dist/provider/{core/inspectConfig.d.ts → inspectConfig.d.ts} +1 -1
- package/dist/provider/{core/inspectConfig.js → inspectConfig.js} +3 -3
- package/dist/provider/plugins/css.js +0 -1
- package/dist/provider/plugins/less.js +2 -1
- package/dist/provider/plugins/swc.js +1 -1
- package/dist/provider/provider.js +20 -20
- package/dist/provider/{core/rspackConfig.d.ts → rspackConfig.d.ts} +1 -1
- package/dist/provider/{core/rspackConfig.js → rspackConfig.js} +2 -2
- package/dist/provider/shared.d.ts +1 -1
- package/dist/provider/shared.js +79 -14
- package/dist/server/devServer.js +1 -0
- package/dist/server/helper.d.ts +14 -0
- package/dist/server/helper.js +64 -1
- package/dist/server/proxy.js +1 -1
- package/dist/types.d.ts +1 -1
- package/package.json +3 -3
- package/dist/provider/core/initConfigs.d.ts +0 -11
- package/dist/provider/core/initPlugins.d.ts +0 -7
- /package/dist/provider/{core/build.d.ts → build.d.ts} +0 -0
- /package/dist/provider/{core/build.js → build.js} +0 -0
- /package/dist/provider/{core/devMiddleware.d.ts → devMiddleware.d.ts} +0 -0
- /package/dist/provider/{core/devMiddleware.js → devMiddleware.js} +0 -0
package/dist/provider/shared.js
CHANGED
|
@@ -74,6 +74,7 @@ const applyDefaultPlugins = (plugins) => (0, import_shared3.awaitableGetter)([
|
|
|
74
74
|
plugins.preloadOrPrefetch(),
|
|
75
75
|
plugins.performance(),
|
|
76
76
|
plugins.server(),
|
|
77
|
+
plugins.moduleFederation(),
|
|
77
78
|
Promise.resolve().then(() => __toESM(require("./plugins/rspackProfile"))).then((m) => m.pluginRspackProfile())
|
|
78
79
|
]);
|
|
79
80
|
const rspackMinVersion = "0.5.0";
|
|
@@ -111,29 +112,93 @@ const getCompiledPath = (packageName) => {
|
|
|
111
112
|
return (0, import_shared.getSharedPkgCompiledPath)(packageName);
|
|
112
113
|
};
|
|
113
114
|
const BUILTIN_LOADER = "builtin:";
|
|
114
|
-
|
|
115
|
+
const addNodePolyfillTip = (message) => {
|
|
116
|
+
if (!message.includes(`Can't resolve`)) {
|
|
117
|
+
return message;
|
|
118
|
+
}
|
|
119
|
+
const matchArray = message.match(/Can't resolve '(\w+)'/);
|
|
120
|
+
if (!matchArray) {
|
|
121
|
+
return message;
|
|
122
|
+
}
|
|
123
|
+
const moduleName = matchArray[1];
|
|
124
|
+
const nodeModules = [
|
|
125
|
+
"assert",
|
|
126
|
+
"buffer",
|
|
127
|
+
"child_process",
|
|
128
|
+
"cluster",
|
|
129
|
+
"console",
|
|
130
|
+
"constants",
|
|
131
|
+
"crypto",
|
|
132
|
+
"dgram",
|
|
133
|
+
"dns",
|
|
134
|
+
"domain",
|
|
135
|
+
"events",
|
|
136
|
+
"fs",
|
|
137
|
+
"http",
|
|
138
|
+
"https",
|
|
139
|
+
"module",
|
|
140
|
+
"net",
|
|
141
|
+
"os",
|
|
142
|
+
"path",
|
|
143
|
+
"punycode",
|
|
144
|
+
"process",
|
|
145
|
+
"querystring",
|
|
146
|
+
"readline",
|
|
147
|
+
"repl",
|
|
148
|
+
"stream",
|
|
149
|
+
"_stream_duplex",
|
|
150
|
+
"_stream_passthrough",
|
|
151
|
+
"_stream_readable",
|
|
152
|
+
"_stream_transform",
|
|
153
|
+
"_stream_writable",
|
|
154
|
+
"string_decoder",
|
|
155
|
+
"sys",
|
|
156
|
+
"timers",
|
|
157
|
+
"tls",
|
|
158
|
+
"tty",
|
|
159
|
+
"url",
|
|
160
|
+
"util",
|
|
161
|
+
"vm",
|
|
162
|
+
"zlib"
|
|
163
|
+
];
|
|
164
|
+
if (moduleName && nodeModules.includes(moduleName)) {
|
|
165
|
+
const tips = [
|
|
166
|
+
`Tip: "${moduleName}" is a built-in Node.js module and cannot be imported in client-side code.`,
|
|
167
|
+
`Check if you need to import Node.js module. If needed, you can use "@rsbuild/plugin-node-polyfill".`
|
|
168
|
+
];
|
|
169
|
+
return `${message}
|
|
170
|
+
|
|
171
|
+
${import_shared.color.yellow(tips.join("\n"))}`;
|
|
172
|
+
}
|
|
173
|
+
return message;
|
|
174
|
+
};
|
|
175
|
+
function formatErrorMessage(errors) {
|
|
176
|
+
const messages = errors.map((error) => addNodePolyfillTip(error));
|
|
177
|
+
const text = `${messages.join("\n\n")}
|
|
178
|
+
`;
|
|
179
|
+
const isTerserError = text.includes("from Terser");
|
|
180
|
+
const title = import_shared.color.bold(
|
|
181
|
+
import_shared.color.red(isTerserError ? "Minify error: " : "Compile error: ")
|
|
182
|
+
);
|
|
183
|
+
const tip = import_shared.color.yellow(
|
|
184
|
+
isTerserError ? "Failed to minify with terser, check for syntax errors." : "Failed to compile, check the errors for troubleshooting."
|
|
185
|
+
);
|
|
186
|
+
return `${title}
|
|
187
|
+
${tip}
|
|
188
|
+
${text}`;
|
|
189
|
+
}
|
|
190
|
+
function formatStats(stats) {
|
|
115
191
|
const statsData = stats.toJson({
|
|
116
192
|
preset: "errors-warnings"
|
|
117
193
|
});
|
|
118
194
|
const { errors, warnings } = (0, import_formatStats.formatStatsMessages)(statsData);
|
|
119
195
|
if (errors.length) {
|
|
120
|
-
const errorMsgs = `${errors.join("\n\n")}
|
|
121
|
-
`;
|
|
122
|
-
const isTerserError = errorMsgs.includes("from Terser");
|
|
123
|
-
const title = import_shared.color.bold(
|
|
124
|
-
import_shared.color.red(isTerserError ? "Minify error: " : "Compile error: ")
|
|
125
|
-
);
|
|
126
|
-
const tip = import_shared.color.yellow(
|
|
127
|
-
isTerserError ? "Failed to minify with terser, check for syntax errors." : "Failed to compile, check the errors for troubleshooting."
|
|
128
|
-
);
|
|
129
196
|
return {
|
|
130
|
-
message:
|
|
131
|
-
${tip}
|
|
132
|
-
${errorMsgs}`,
|
|
197
|
+
message: formatErrorMessage(errors),
|
|
133
198
|
level: "error"
|
|
134
199
|
};
|
|
135
200
|
}
|
|
136
|
-
if (warnings.length
|
|
201
|
+
if (warnings.length) {
|
|
137
202
|
const title = import_shared.color.bold(import_shared.color.yellow("Compile Warning: \n"));
|
|
138
203
|
return {
|
|
139
204
|
message: `${title}${`${warnings.join("\n\n")}
|
package/dist/server/devServer.js
CHANGED
|
@@ -167,6 +167,7 @@ async function startDevServer(options, createDevMiddleware, {
|
|
|
167
167
|
(0, import_shared.debug)("listen dev server done");
|
|
168
168
|
await serverAPIs.afterStart();
|
|
169
169
|
const closeServer = async () => {
|
|
170
|
+
await options.context.hooks.onCloseDevServer.call();
|
|
170
171
|
await devMiddlewares.close();
|
|
171
172
|
httpServer.close();
|
|
172
173
|
};
|
package/dist/server/helper.d.ts
CHANGED
|
@@ -19,6 +19,20 @@ export declare const mergeDevOptions: ({ rsbuildConfig, port, }: {
|
|
|
19
19
|
rsbuildConfig: RsbuildConfig;
|
|
20
20
|
port: number;
|
|
21
21
|
}) => DevConfig;
|
|
22
|
+
/**
|
|
23
|
+
* Get available free port.
|
|
24
|
+
* @param port - Current port want to use.
|
|
25
|
+
* @param tryLimits - Maximum number of retries.
|
|
26
|
+
* @param strictPort - Whether to throw an error when the port is occupied.
|
|
27
|
+
* @returns Available port number.
|
|
28
|
+
*/
|
|
29
|
+
export declare const getPort: ({ host, port, strictPort, tryLimits, silent, }: {
|
|
30
|
+
host: string;
|
|
31
|
+
port: string | number;
|
|
32
|
+
strictPort: boolean;
|
|
33
|
+
tryLimits?: number | undefined;
|
|
34
|
+
silent?: boolean | undefined;
|
|
35
|
+
}) => Promise<number>;
|
|
22
36
|
export declare const getServerOptions: ({ rsbuildConfig, getPortSilently, }: {
|
|
23
37
|
rsbuildConfig: RsbuildConfig;
|
|
24
38
|
getPortSilently?: boolean | undefined;
|
package/dist/server/helper.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,17 +17,27 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
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
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
var helper_exports = {};
|
|
20
30
|
__export(helper_exports, {
|
|
21
31
|
HMR_SOCK_PATH: () => HMR_SOCK_PATH,
|
|
22
32
|
formatRoutes: () => formatRoutes,
|
|
23
33
|
getDevOptions: () => getDevOptions,
|
|
34
|
+
getPort: () => getPort,
|
|
24
35
|
getServerOptions: () => getServerOptions,
|
|
25
36
|
mergeDevOptions: () => mergeDevOptions,
|
|
26
37
|
printServerURLs: () => printServerURLs
|
|
27
38
|
});
|
|
28
39
|
module.exports = __toCommonJS(helper_exports);
|
|
40
|
+
var import_node_net = __toESM(require("node:net"));
|
|
29
41
|
var import_shared = require("@rsbuild/shared");
|
|
30
42
|
const formatPrefix = (prefix) => {
|
|
31
43
|
if (!prefix) {
|
|
@@ -129,12 +141,62 @@ const mergeDevOptions = ({
|
|
|
129
141
|
const devConfig = rsbuildConfig.dev ? (0, import_shared.deepmerge)(defaultDevConfig, rsbuildConfig.dev) : defaultDevConfig;
|
|
130
142
|
return devConfig;
|
|
131
143
|
};
|
|
144
|
+
const getPort = async ({
|
|
145
|
+
host,
|
|
146
|
+
port,
|
|
147
|
+
strictPort,
|
|
148
|
+
tryLimits = 20,
|
|
149
|
+
silent = false
|
|
150
|
+
}) => {
|
|
151
|
+
if (typeof port === "string") {
|
|
152
|
+
port = parseInt(port, 10);
|
|
153
|
+
}
|
|
154
|
+
if (strictPort) {
|
|
155
|
+
tryLimits = 1;
|
|
156
|
+
}
|
|
157
|
+
const original = port;
|
|
158
|
+
let found = false;
|
|
159
|
+
let attempts = 0;
|
|
160
|
+
while (!found && attempts <= tryLimits) {
|
|
161
|
+
try {
|
|
162
|
+
await new Promise((resolve, reject) => {
|
|
163
|
+
const server = import_node_net.default.createServer();
|
|
164
|
+
server.unref();
|
|
165
|
+
server.on("error", reject);
|
|
166
|
+
server.listen({ port, host }, () => {
|
|
167
|
+
found = true;
|
|
168
|
+
server.close(resolve);
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
} catch (e) {
|
|
172
|
+
if (e.code !== "EADDRINUSE") {
|
|
173
|
+
throw e;
|
|
174
|
+
}
|
|
175
|
+
port++;
|
|
176
|
+
attempts++;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (port !== original) {
|
|
180
|
+
if (strictPort) {
|
|
181
|
+
throw new Error(
|
|
182
|
+
`Port "${original}" is occupied, please choose another one.`
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
if (!silent) {
|
|
186
|
+
import_shared.logger.info(
|
|
187
|
+
`Port ${original} is in use, ${import_shared.color.yellow(`using port ${port}.`)}
|
|
188
|
+
`
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return port;
|
|
193
|
+
};
|
|
132
194
|
const getServerOptions = async ({
|
|
133
195
|
rsbuildConfig,
|
|
134
196
|
getPortSilently
|
|
135
197
|
}) => {
|
|
136
198
|
const host = rsbuildConfig.server?.host || import_shared.DEFAULT_DEV_HOST;
|
|
137
|
-
const port = await
|
|
199
|
+
const port = await getPort({
|
|
138
200
|
host,
|
|
139
201
|
port: rsbuildConfig.server?.port || import_shared.DEFAULT_PORT,
|
|
140
202
|
strictPort: rsbuildConfig.server?.strictPort || false,
|
|
@@ -167,6 +229,7 @@ const getDevOptions = async ({
|
|
|
167
229
|
HMR_SOCK_PATH,
|
|
168
230
|
formatRoutes,
|
|
169
231
|
getDevOptions,
|
|
232
|
+
getPort,
|
|
170
233
|
getServerOptions,
|
|
171
234
|
mergeDevOptions,
|
|
172
235
|
printServerURLs
|
package/dist/server/proxy.js
CHANGED
|
@@ -70,7 +70,7 @@ const createProxyMiddleware = (proxyOptions) => {
|
|
|
70
70
|
}
|
|
71
71
|
};
|
|
72
72
|
middlewares.push(middleware);
|
|
73
|
-
proxyMiddlewares.push(proxyMiddleware);
|
|
73
|
+
opts.ws && proxyMiddlewares.push(proxyMiddleware);
|
|
74
74
|
}
|
|
75
75
|
const handleUpgrade = (req, socket, head) => {
|
|
76
76
|
for (const middleware of proxyMiddlewares) {
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { RsbuildConfig, RsbuildPlugin, RsbuildPlugins, RsbuildContext, NormalizedConfig, RsbuildPluginAPI } from '@rsbuild/shared';
|
|
2
|
-
import type { Hooks } from './provider/
|
|
2
|
+
import type { Hooks } from './provider/initHooks';
|
|
3
3
|
export type { RsbuildPlugin, RsbuildPlugins, RsbuildPluginAPI };
|
|
4
4
|
/** The inner context. */
|
|
5
5
|
export type InternalContext = RsbuildContext & {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "The Rspack-based build tool.",
|
|
5
5
|
"homepage": "https://rsbuild.dev",
|
|
6
6
|
"bugs": {
|
|
@@ -52,12 +52,12 @@
|
|
|
52
52
|
"types.d.ts"
|
|
53
53
|
],
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@rspack/core": "0.5.
|
|
55
|
+
"@rspack/core": "0.5.4",
|
|
56
56
|
"@swc/helpers": "0.5.3",
|
|
57
57
|
"core-js": "~3.32.2",
|
|
58
58
|
"html-webpack-plugin": "npm:html-rspack-plugin@5.5.7",
|
|
59
59
|
"postcss": "^8.4.33",
|
|
60
|
-
"@rsbuild/shared": "0.
|
|
60
|
+
"@rsbuild/shared": "0.4.1"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@types/node": "16.x",
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { type PluginStore, type RspackConfig, type CreateRsbuildOptions } from '@rsbuild/shared';
|
|
2
|
-
import type { InternalContext, NormalizedConfig } from '../../types';
|
|
3
|
-
export type InitConfigsOptions = {
|
|
4
|
-
context: InternalContext;
|
|
5
|
-
pluginStore: PluginStore;
|
|
6
|
-
rsbuildOptions: Required<CreateRsbuildOptions>;
|
|
7
|
-
};
|
|
8
|
-
export declare function initRsbuildConfig({ context, pluginStore, }: Pick<InitConfigsOptions, 'context' | 'pluginStore'>): Promise<NormalizedConfig>;
|
|
9
|
-
export declare function initConfigs({ context, pluginStore, rsbuildOptions, }: InitConfigsOptions): Promise<{
|
|
10
|
-
rspackConfigs: RspackConfig[];
|
|
11
|
-
}>;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { type PluginStore, type RsbuildPluginAPI } from '@rsbuild/shared';
|
|
2
|
-
import type { InternalContext, NormalizedConfig } from '../../types';
|
|
3
|
-
export declare function getHTMLPathByEntry(entryName: string, config: NormalizedConfig): string;
|
|
4
|
-
export declare function getPluginAPI({ context, pluginStore, }: {
|
|
5
|
-
context: InternalContext;
|
|
6
|
-
pluginStore: PluginStore;
|
|
7
|
-
}): RsbuildPluginAPI;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|