@rslib/core 0.1.3 → 0.1.4
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/index.js
CHANGED
|
@@ -128,10 +128,13 @@ function isPluginIncluded(pluginName, plugins) {
|
|
|
128
128
|
return false;
|
|
129
129
|
}));
|
|
130
130
|
}
|
|
131
|
-
function checkMFPlugin(config) {
|
|
131
|
+
function checkMFPlugin(config, sharedPlugins) {
|
|
132
132
|
if ('mf' !== config.format) return true;
|
|
133
133
|
// https://github.com/module-federation/core/blob/4e5c4b96ee45899f3ba5904b8927768980d5ad0e/packages/rsbuild-plugin/src/cli/index.ts#L17
|
|
134
|
-
const added = isPluginIncluded('rsbuild:module-federation-enhanced',
|
|
134
|
+
const added = isPluginIncluded('rsbuild:module-federation-enhanced', [
|
|
135
|
+
...sharedPlugins || [],
|
|
136
|
+
...config.plugins || []
|
|
137
|
+
]);
|
|
135
138
|
if (!added) {
|
|
136
139
|
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.warn(`${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js__["default"].green('format: "mf"')} should be used with ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js__["default"].blue('@module-federation/rsbuild-plugin')}", consider installing and adding it to plugins. Check the documentation (https://module-federation.io/guide/basic/rsbuild.html#rslib-module) to get started with "mf" output.`);
|
|
137
140
|
process.exit(1);
|
|
@@ -150,6 +153,7 @@ function debounce(func, wait) {
|
|
|
150
153
|
/**
|
|
151
154
|
* Check if running in a TTY context
|
|
152
155
|
*/ const isTTY = (type = 'stdout')=>('stdin' === type ? process.stdin.isTTY : process.stdout.isTTY) && !process.env.CI;
|
|
156
|
+
const isIntermediateOutputFormat = (format)=>'cjs' === format || 'esm' === format;
|
|
153
157
|
// setup the logger level
|
|
154
158
|
if (process.env.DEBUG) __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.level = 'verbose';
|
|
155
159
|
function initNodeEnv() {
|
|
@@ -166,7 +170,7 @@ function prepareCli() {
|
|
|
166
170
|
// Some package managers automatically output a blank line, some do not.
|
|
167
171
|
const { npm_execpath } = process.env;
|
|
168
172
|
if (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) console.log();
|
|
169
|
-
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.greet(` Rslib v0.1.
|
|
173
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.greet(` Rslib v0.1.4\n`);
|
|
170
174
|
}
|
|
171
175
|
const DEFAULT_CONFIG_NAME = 'rslib.config';
|
|
172
176
|
const DEFAULT_CONFIG_EXTENSIONS = [
|
|
@@ -1519,9 +1523,11 @@ const composeExternalsWarnConfig = (format, ...externalsArray)=>{
|
|
|
1519
1523
|
}
|
|
1520
1524
|
};
|
|
1521
1525
|
};
|
|
1526
|
+
const getAutoExternalDefaultValue = (format, autoExternal)=>autoExternal ?? isIntermediateOutputFormat(format);
|
|
1522
1527
|
const composeAutoExternalConfig = (options)=>{
|
|
1523
|
-
const {
|
|
1524
|
-
|
|
1528
|
+
const { format, pkgJson, userExternals } = options;
|
|
1529
|
+
const autoExternal = getAutoExternalDefaultValue(format, options.autoExternal);
|
|
1530
|
+
if (false === autoExternal) return {};
|
|
1525
1531
|
if (!pkgJson) {
|
|
1526
1532
|
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.warn('autoExternal configuration will not be applied due to read package.json failed');
|
|
1527
1533
|
return {};
|
|
@@ -1582,7 +1588,8 @@ function composeMinifyConfig(config) {
|
|
|
1582
1588
|
toplevel: 'mf' !== format
|
|
1583
1589
|
},
|
|
1584
1590
|
format: {
|
|
1585
|
-
comments: '
|
|
1591
|
+
comments: 'some',
|
|
1592
|
+
preserve_annotations: true
|
|
1586
1593
|
}
|
|
1587
1594
|
}
|
|
1588
1595
|
}
|
|
@@ -2102,7 +2109,7 @@ const composeBundleConfig = (jsExtension, redirect, cssModulesAuto, bundle)=>{
|
|
|
2102
2109
|
};
|
|
2103
2110
|
};
|
|
2104
2111
|
const composeDtsConfig = async (libConfig, dtsExtension)=>{
|
|
2105
|
-
const { autoExternal, banner, footer } = libConfig;
|
|
2112
|
+
const { format, autoExternal, banner, footer } = libConfig;
|
|
2106
2113
|
let { dts } = libConfig;
|
|
2107
2114
|
if (false === dts || void 0 === dts) return {};
|
|
2108
2115
|
// DTS default to bundleless whether js is bundle or not
|
|
@@ -2119,7 +2126,7 @@ const composeDtsConfig = async (libConfig, dtsExtension)=>{
|
|
|
2119
2126
|
build: dts?.build,
|
|
2120
2127
|
abortOnError: dts?.abortOnError,
|
|
2121
2128
|
dtsExtension: dts?.autoExtension ? dtsExtension : '.d.ts',
|
|
2122
|
-
autoExternal,
|
|
2129
|
+
autoExternal: getAutoExternalDefaultValue(format, autoExternal),
|
|
2123
2130
|
banner: banner?.dts,
|
|
2124
2131
|
footer: footer?.dts
|
|
2125
2132
|
})
|
|
@@ -2204,14 +2211,14 @@ const composeExternalHelpersConfig = (externalHelpers, pkgJson)=>{
|
|
|
2204
2211
|
}
|
|
2205
2212
|
return defaultConfig;
|
|
2206
2213
|
};
|
|
2207
|
-
async function composeLibRsbuildConfig(config) {
|
|
2208
|
-
checkMFPlugin(config);
|
|
2214
|
+
async function composeLibRsbuildConfig(config, sharedPlugins) {
|
|
2215
|
+
checkMFPlugin(config, sharedPlugins);
|
|
2209
2216
|
// Get the absolute path of the root directory to align with Rsbuild's default behavior
|
|
2210
2217
|
const rootPath = config.root ? getAbsolutePath(process.cwd(), config.root) : process.cwd();
|
|
2211
2218
|
const pkgJson = readPackageJson(rootPath);
|
|
2212
2219
|
const { compilerOptions } = await loadTsconfig(rootPath, config.source?.tsconfigPath);
|
|
2213
2220
|
const cssModulesAuto = config.output?.cssModules?.auto ?? true;
|
|
2214
|
-
const { format, shims, bundle = true, banner = {}, footer = {}, autoExtension = true, autoExternal
|
|
2221
|
+
const { format, shims, bundle = true, banner = {}, footer = {}, autoExtension = true, autoExternal, externalHelpers = false, redirect = {}, umdName } = config;
|
|
2215
2222
|
const { rsbuildConfig: shimsConfig, enabledShims } = composeShimsConfig(format, shims);
|
|
2216
2223
|
const formatConfig = composeFormatConfig({
|
|
2217
2224
|
format: format,
|
|
@@ -2226,6 +2233,7 @@ async function composeLibRsbuildConfig(config) {
|
|
|
2226
2233
|
const { config: targetConfig, target } = composeTargetConfig(config.output?.target, format);
|
|
2227
2234
|
const syntaxConfig = composeSyntaxConfig(target, config?.syntax);
|
|
2228
2235
|
const autoExternalConfig = composeAutoExternalConfig({
|
|
2236
|
+
format: format,
|
|
2229
2237
|
autoExternal,
|
|
2230
2238
|
pkgJson,
|
|
2231
2239
|
userExternals: config.output?.externals
|
|
@@ -2244,13 +2252,13 @@ async function composeLibRsbuildConfig(config) {
|
|
|
2244
2252
|
}
|
|
2245
2253
|
async function composeCreateRsbuildConfig(rslibConfig) {
|
|
2246
2254
|
const constantRsbuildConfig = await createConstantRsbuildConfig();
|
|
2247
|
-
const { lib: libConfigsArray, ...sharedRsbuildConfig } = rslibConfig;
|
|
2255
|
+
const { lib: libConfigsArray, plugins: sharedPlugins, ...sharedRsbuildConfig } = rslibConfig;
|
|
2248
2256
|
if (!libConfigsArray) throw new Error(`Expect lib field to be an array, but got ${libConfigsArray}.`);
|
|
2249
2257
|
const libConfigPromises = libConfigsArray.map(async (libConfig)=>{
|
|
2250
2258
|
const userConfig = (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.mergeRsbuildConfig)(sharedRsbuildConfig, libConfig);
|
|
2251
2259
|
// Merge the configuration of each environment based on the shared Rsbuild
|
|
2252
2260
|
// configuration and Lib configuration in the settings.
|
|
2253
|
-
const libRsbuildConfig = await composeLibRsbuildConfig(userConfig);
|
|
2261
|
+
const libRsbuildConfig = await composeLibRsbuildConfig(userConfig, sharedPlugins);
|
|
2254
2262
|
// Reset certain fields because they will be completely overridden by the upcoming merge.
|
|
2255
2263
|
// We don't want to retain them in the final configuration.
|
|
2256
2264
|
// The reset process should occur after merging the library configuration.
|
|
@@ -2361,6 +2369,7 @@ async function build(config, options = {}) {
|
|
|
2361
2369
|
const environments = await composeRsbuildEnvironments(config);
|
|
2362
2370
|
const rsbuildInstance = await (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.createRsbuild)({
|
|
2363
2371
|
rsbuildConfig: {
|
|
2372
|
+
plugins: config.plugins,
|
|
2364
2373
|
environments: pruneEnvironments(environments, options.lib)
|
|
2365
2374
|
}
|
|
2366
2375
|
});
|
|
@@ -2407,6 +2416,7 @@ async function inspect(config, options = {}) {
|
|
|
2407
2416
|
const environments = await composeRsbuildEnvironments(config);
|
|
2408
2417
|
const rsbuildInstance = await (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.createRsbuild)({
|
|
2409
2418
|
rsbuildConfig: {
|
|
2419
|
+
plugins: config.plugins,
|
|
2410
2420
|
environments: pruneEnvironments(environments, options.lib)
|
|
2411
2421
|
}
|
|
2412
2422
|
});
|
|
@@ -2429,7 +2439,13 @@ async function initMFRsbuild(rslibConfig) {
|
|
|
2429
2439
|
return;
|
|
2430
2440
|
mfRsbuildConfig.config = changeEnvToDev(mfRsbuildConfig.config);
|
|
2431
2441
|
const rsbuildInstance = await (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.createRsbuild)({
|
|
2432
|
-
rsbuildConfig:
|
|
2442
|
+
rsbuildConfig: {
|
|
2443
|
+
...mfRsbuildConfig.config,
|
|
2444
|
+
plugins: [
|
|
2445
|
+
...rslibConfig.plugins || [],
|
|
2446
|
+
...mfRsbuildConfig.config.plugins || []
|
|
2447
|
+
]
|
|
2448
|
+
}
|
|
2433
2449
|
});
|
|
2434
2450
|
const devServer = await rsbuildInstance.startDevServer();
|
|
2435
2451
|
onBeforeRestart(devServer.server.close);
|
|
@@ -2458,7 +2474,7 @@ const repeatableOption = (value, previous)=>(previous ?? []).concat([
|
|
|
2458
2474
|
value
|
|
2459
2475
|
]);
|
|
2460
2476
|
function runCli() {
|
|
2461
|
-
__WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.name('rslib').usage('<command> [options]').version("0.1.
|
|
2477
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.name('rslib').usage('<command> [options]').version("0.1.4");
|
|
2462
2478
|
const buildCommand = __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.command('build');
|
|
2463
2479
|
const inspectCommand = __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.command('inspect');
|
|
2464
2480
|
const mfDevCommand = __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.command('mf dev');
|
|
@@ -2518,6 +2534,6 @@ function runCli() {
|
|
|
2518
2534
|
});
|
|
2519
2535
|
__WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.parse();
|
|
2520
2536
|
}
|
|
2521
|
-
const src_rslib_entry_version = "0.1.
|
|
2537
|
+
const src_rslib_entry_version = "0.1.4";
|
|
2522
2538
|
var __webpack_exports__logger = __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger;
|
|
2523
2539
|
export { build, defineConfig, inspect, loadConfig, prepareCli, runCli, startMFDevServer, composeCreateRsbuildConfig as unstable_composeCreateRsbuildConfig, src_rslib_entry_version as version, __webpack_exports__logger as logger };
|
package/dist-types/config.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type EnvironmentConfig, type RsbuildConfig } from '@rsbuild/core';
|
|
2
|
-
import type { AutoExternal, BannerAndFooter, LibConfig, PkgJson, RsbuildConfigEntry, RsbuildConfigWithLibInfo, RslibConfig, RslibConfigAsyncFn, RslibConfigExport, RslibConfigSyncFn } from './types';
|
|
2
|
+
import type { AutoExternal, BannerAndFooter, Format, LibConfig, PkgJson, RsbuildConfigEntry, RsbuildConfigWithLibInfo, RslibConfig, RslibConfigAsyncFn, RslibConfigExport, RslibConfigSyncFn } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* This function helps you to autocomplete configuration types.
|
|
5
5
|
* It accepts a Rslib config object, or a function that returns a config.
|
|
@@ -17,7 +17,8 @@ export declare function loadConfig({ cwd, path, envMode, }: {
|
|
|
17
17
|
filePath: string;
|
|
18
18
|
}>;
|
|
19
19
|
export declare const composeAutoExternalConfig: (options: {
|
|
20
|
-
|
|
20
|
+
format: Format;
|
|
21
|
+
autoExternal?: AutoExternal;
|
|
21
22
|
pkgJson?: PkgJson;
|
|
22
23
|
userExternals?: NonNullable<RsbuildConfig["output"]>["externals"];
|
|
23
24
|
}) => RsbuildConfig;
|
|
@@ -67,7 +67,7 @@ export interface LibConfig extends RsbuildConfig {
|
|
|
67
67
|
autoExtension?: boolean;
|
|
68
68
|
/**
|
|
69
69
|
* Whether to automatically externalize dependencies of different dependency types and do not bundle them.
|
|
70
|
-
* @defaultValue `true`
|
|
70
|
+
* @defaultValue `true` when {@link format} is `cjs` or `esm`, `false` when {@link format} is `umd` or `mf`.
|
|
71
71
|
* @see {@link https://lib.rsbuild.dev/config/lib/auto-external}
|
|
72
72
|
*/
|
|
73
73
|
autoExternal?: AutoExternal;
|
|
@@ -90,13 +90,13 @@ export interface LibConfig extends RsbuildConfig {
|
|
|
90
90
|
*/
|
|
91
91
|
externalHelpers?: boolean;
|
|
92
92
|
/**
|
|
93
|
-
* Inject content into the top of each
|
|
93
|
+
* Inject content into the top of each JavaScript, CSS or DTS file.
|
|
94
94
|
* @defaultValue `{}`
|
|
95
95
|
* @see {@link https://lib.rsbuild.dev/config/lib/banner}
|
|
96
96
|
*/
|
|
97
97
|
banner?: BannerAndFooter;
|
|
98
98
|
/**
|
|
99
|
-
* Inject content into the bottom of each
|
|
99
|
+
* Inject content into the bottom of each JavaScript, CSS or DTS file.
|
|
100
100
|
* @defaultValue `{}`
|
|
101
101
|
* @see {@link https://lib.rsbuild.dev/config/lib/footer}
|
|
102
102
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { RsbuildPlugins } from '@rsbuild/core';
|
|
2
2
|
import color from 'picocolors';
|
|
3
|
-
import type { LibConfig, PkgJson } from '../types';
|
|
3
|
+
import type { Format, LibConfig, PkgJson } from '../types';
|
|
4
4
|
/**
|
|
5
5
|
* Node.js built-in modules.
|
|
6
6
|
* Copied from https://github.com/webpack/webpack/blob/dd44b206a9c50f4b4cb4d134e1a0bd0387b159a3/lib/node/NodeTargetPlugin.js#L12-L72
|
|
@@ -14,10 +14,11 @@ export declare const isEmptyObject: (obj: object) => boolean;
|
|
|
14
14
|
export declare function pick<T, U extends keyof T>(obj: T, keys: ReadonlyArray<U>): Pick<T, U>;
|
|
15
15
|
export declare function omit<T extends object, U extends keyof T>(obj: T, keysObj: Record<U, boolean>): Omit<T, keyof U>;
|
|
16
16
|
export declare function isPluginIncluded(pluginName: string, plugins?: RsbuildPlugins): boolean;
|
|
17
|
-
export declare function checkMFPlugin(config: LibConfig): boolean;
|
|
17
|
+
export declare function checkMFPlugin(config: LibConfig, sharedPlugins?: RsbuildPlugins): boolean;
|
|
18
18
|
export declare function debounce<T extends (...args: any[]) => void>(func: T, wait: number): (...args: Parameters<T>) => void;
|
|
19
19
|
/**
|
|
20
20
|
* Check if running in a TTY context
|
|
21
21
|
*/
|
|
22
22
|
export declare const isTTY: (type?: "stdin" | "stdout") => boolean;
|
|
23
|
+
export declare const isIntermediateOutputFormat: (format: Format) => boolean;
|
|
23
24
|
export { color };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rslib/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "The Rsbuild-based library development tool.",
|
|
5
5
|
"homepage": "https://lib.rsbuild.dev",
|
|
6
6
|
"bugs": {
|
|
@@ -32,19 +32,19 @@
|
|
|
32
32
|
"compiled"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@rsbuild/core": "~1.1.
|
|
35
|
+
"@rsbuild/core": "~1.1.10",
|
|
36
36
|
"tinyglobby": "^0.2.10",
|
|
37
|
-
"rsbuild-plugin-dts": "0.1.
|
|
37
|
+
"rsbuild-plugin-dts": "0.1.4"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/fs-extra": "^11.0.4",
|
|
41
41
|
"chokidar": "^4.0.1",
|
|
42
42
|
"commander": "^12.1.0",
|
|
43
43
|
"fs-extra": "^11.2.0",
|
|
44
|
-
"memfs": "^4.
|
|
44
|
+
"memfs": "^4.15.0",
|
|
45
45
|
"picocolors": "1.1.1",
|
|
46
46
|
"prebundle": "1.2.5",
|
|
47
|
-
"rslib": "npm:@rslib/core@0.1.
|
|
47
|
+
"rslib": "npm:@rslib/core@0.1.3",
|
|
48
48
|
"rslog": "^1.2.3",
|
|
49
49
|
"tsconfck": "3.1.4",
|
|
50
50
|
"typescript": "^5.6.3",
|