@rslib/core 0.1.1 → 0.1.3
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 +57 -27
- package/dist-types/cli/commands.d.ts +1 -0
- package/dist-types/cli/init.d.ts +4 -3
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -8,7 +8,6 @@ import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core__ from "@rsbuild/core";
|
|
|
8
8
|
import * as __WEBPACK_EXTERNAL_MODULE_tinyglobby__ from "tinyglobby";
|
|
9
9
|
import * as __WEBPACK_EXTERNAL_MODULE_node_module__ from "node:module";
|
|
10
10
|
import * as __WEBPACK_EXTERNAL_MODULE_module__ from "module";
|
|
11
|
-
import * as __WEBPACK_EXTERNAL_MODULE__compiled_chokidar_index_js__ from "../compiled/chokidar/index.js";
|
|
12
11
|
/**
|
|
13
12
|
* Node.js built-in modules.
|
|
14
13
|
* Copied from https://github.com/webpack/webpack/blob/dd44b206a9c50f4b4cb4d134e1a0bd0387b159a3/lib/node/NodeTargetPlugin.js#L12-L72
|
|
@@ -167,7 +166,7 @@ function prepareCli() {
|
|
|
167
166
|
// Some package managers automatically output a blank line, some do not.
|
|
168
167
|
const { npm_execpath } = process.env;
|
|
169
168
|
if (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) console.log();
|
|
170
|
-
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.greet(` Rslib v0.1.
|
|
169
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.greet(` Rslib v0.1.3\n`);
|
|
171
170
|
}
|
|
172
171
|
const DEFAULT_CONFIG_NAME = 'rslib.config';
|
|
173
172
|
const DEFAULT_CONFIG_EXTENSIONS = [
|
|
@@ -1808,6 +1807,9 @@ const composeFormatConfig = ({ format, bundle = true, umdName, pkgJson })=>{
|
|
|
1808
1807
|
} : {
|
|
1809
1808
|
type: 'umd'
|
|
1810
1809
|
}
|
|
1810
|
+
},
|
|
1811
|
+
optimization: {
|
|
1812
|
+
nodeEnv: process.env.NODE_ENV
|
|
1811
1813
|
}
|
|
1812
1814
|
}
|
|
1813
1815
|
}
|
|
@@ -1837,6 +1839,18 @@ const composeFormatConfig = ({ format, bundle = true, umdName, pkgJson })=>{
|
|
|
1837
1839
|
throw new Error(`Unsupported format: ${format}`);
|
|
1838
1840
|
}
|
|
1839
1841
|
};
|
|
1842
|
+
const formatRsbuildPlugin = ()=>({
|
|
1843
|
+
name: 'rsbuild:format',
|
|
1844
|
+
setup (api) {
|
|
1845
|
+
api.modifyBundlerChain((config, { CHAIN_ID })=>{
|
|
1846
|
+
// Fix for https://github.com/web-infra-dev/rslib/issues/499.
|
|
1847
|
+
// Prevent parsing and try bundling `new URL()` in ESM format.
|
|
1848
|
+
config.module.rule(CHAIN_ID.RULE.JS).parser({
|
|
1849
|
+
url: false
|
|
1850
|
+
});
|
|
1851
|
+
});
|
|
1852
|
+
}
|
|
1853
|
+
});
|
|
1840
1854
|
const composeShimsConfig = (format, shims)=>{
|
|
1841
1855
|
const resolvedShims = {
|
|
1842
1856
|
cjs: {
|
|
@@ -1872,7 +1886,8 @@ const composeShimsConfig = (format, shims)=>{
|
|
|
1872
1886
|
}
|
|
1873
1887
|
},
|
|
1874
1888
|
plugins: [
|
|
1875
|
-
resolvedShims.esm.require && pluginEsmRequireShim()
|
|
1889
|
+
resolvedShims.esm.require && pluginEsmRequireShim(),
|
|
1890
|
+
formatRsbuildPlugin()
|
|
1876
1891
|
].filter(Boolean)
|
|
1877
1892
|
};
|
|
1878
1893
|
break;
|
|
@@ -2307,15 +2322,11 @@ const pruneEnvironments = (environments, libs)=>{
|
|
|
2307
2322
|
};
|
|
2308
2323
|
async function watchFilesForRestart(files, restart) {
|
|
2309
2324
|
if (!files.length) return;
|
|
2310
|
-
const
|
|
2325
|
+
const chokidar = await import("../compiled/chokidar/index.js");
|
|
2326
|
+
const watcher = chokidar.watch(files, {
|
|
2311
2327
|
ignoreInitial: true,
|
|
2312
2328
|
// If watching fails due to read permissions, the errors will be suppressed silently.
|
|
2313
|
-
ignorePermissionErrors: true
|
|
2314
|
-
ignored: [
|
|
2315
|
-
'**/node_modules/**',
|
|
2316
|
-
'**/.git/**',
|
|
2317
|
-
'**/.DS_Store/**'
|
|
2318
|
-
]
|
|
2329
|
+
ignorePermissionErrors: true
|
|
2319
2330
|
});
|
|
2320
2331
|
const callback = debounce(async (filePath)=>{
|
|
2321
2332
|
watcher.close();
|
|
@@ -2360,14 +2371,37 @@ async function build(config, options = {}) {
|
|
|
2360
2371
|
else await buildInstance.close();
|
|
2361
2372
|
return rsbuildInstance;
|
|
2362
2373
|
}
|
|
2363
|
-
|
|
2374
|
+
const getEnvDir = (cwd, envDir)=>{
|
|
2375
|
+
if (envDir) return __WEBPACK_EXTERNAL_MODULE_node_path__["default"].isAbsolute(envDir) ? envDir : __WEBPACK_EXTERNAL_MODULE_node_path__["default"].resolve(cwd, envDir);
|
|
2376
|
+
return cwd;
|
|
2377
|
+
};
|
|
2378
|
+
async function init(options) {
|
|
2364
2379
|
const cwd = process.cwd();
|
|
2365
2380
|
const root = options.root ? getAbsolutePath(cwd, options.root) : cwd;
|
|
2366
|
-
|
|
2381
|
+
const envs = (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.loadEnv)({
|
|
2382
|
+
cwd: getEnvDir(root, options.envDir),
|
|
2383
|
+
mode: options.envMode
|
|
2384
|
+
});
|
|
2385
|
+
onBeforeRestart(envs.cleanup);
|
|
2386
|
+
const { content: config, filePath: configFilePath } = await loadConfig({
|
|
2367
2387
|
cwd: root,
|
|
2368
2388
|
path: options.config,
|
|
2369
2389
|
envMode: options.envMode
|
|
2370
2390
|
});
|
|
2391
|
+
config.source ||= {};
|
|
2392
|
+
config.source.define = {
|
|
2393
|
+
...envs.publicVars,
|
|
2394
|
+
...config.source.define
|
|
2395
|
+
};
|
|
2396
|
+
if (options.root) config.root = root;
|
|
2397
|
+
return {
|
|
2398
|
+
config,
|
|
2399
|
+
configFilePath,
|
|
2400
|
+
watchFiles: [
|
|
2401
|
+
configFilePath,
|
|
2402
|
+
...envs.filePaths
|
|
2403
|
+
]
|
|
2404
|
+
};
|
|
2371
2405
|
}
|
|
2372
2406
|
async function inspect(config, options = {}) {
|
|
2373
2407
|
const environments = await composeRsbuildEnvironments(config);
|
|
@@ -2418,13 +2452,13 @@ function changeEnvToDev(rsbuildConfig) {
|
|
|
2418
2452
|
});
|
|
2419
2453
|
}
|
|
2420
2454
|
const applyCommonOptions = (command)=>{
|
|
2421
|
-
command.option('-c --config <config>', 'specify the configuration file, can be a relative or absolute path').option('-r --root <root>', 'specify the project root directory, can be an absolute path or a path relative to cwd').option('--env-mode <mode>', 'specify the env mode to load the `.env.[mode]` file');
|
|
2455
|
+
command.option('-c --config <config>', 'specify the configuration file, can be a relative or absolute path').option('-r --root <root>', 'specify the project root directory, can be an absolute path or a path relative to cwd').option('--env-mode <mode>', 'specify the env mode to load the `.env.[mode]` file').option('--env-dir <dir>', 'specify the directory to load `.env` files');
|
|
2422
2456
|
};
|
|
2423
2457
|
const repeatableOption = (value, previous)=>(previous ?? []).concat([
|
|
2424
2458
|
value
|
|
2425
2459
|
]);
|
|
2426
2460
|
function runCli() {
|
|
2427
|
-
__WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.name('rslib').usage('<command> [options]').version("0.1.
|
|
2461
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.name('rslib').usage('<command> [options]').version("0.1.3");
|
|
2428
2462
|
const buildCommand = __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.command('build');
|
|
2429
2463
|
const inspectCommand = __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.command('inspect');
|
|
2430
2464
|
const mfDevCommand = __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.command('mf dev');
|
|
@@ -2436,11 +2470,9 @@ function runCli() {
|
|
|
2436
2470
|
buildCommand.option('--lib <id>', 'build the specified library (may be repeated)', repeatableOption).option('-w --watch', 'turn on watch mode, watch for changes and rebuild').description('build the library for production').action(async (options)=>{
|
|
2437
2471
|
try {
|
|
2438
2472
|
const cliBuild = async ()=>{
|
|
2439
|
-
const {
|
|
2440
|
-
await build(
|
|
2441
|
-
if (options.watch) watchFilesForRestart(
|
|
2442
|
-
filePath
|
|
2443
|
-
], async ()=>{
|
|
2473
|
+
const { config, watchFiles } = await init(options);
|
|
2474
|
+
await build(config, options);
|
|
2475
|
+
if (options.watch) watchFilesForRestart(watchFiles, async ()=>{
|
|
2444
2476
|
await cliBuild();
|
|
2445
2477
|
});
|
|
2446
2478
|
};
|
|
@@ -2454,8 +2486,8 @@ function runCli() {
|
|
|
2454
2486
|
inspectCommand.description('inspect the Rsbuild / Rspack configs of Rslib projects').option('--lib <id>', 'inspect the specified library (may be repeated)', repeatableOption).option('--output <output>', 'specify inspect content output path', '.rsbuild').option('--verbose', 'show full function definitions in output').action(async (options)=>{
|
|
2455
2487
|
try {
|
|
2456
2488
|
// TODO: inspect should output Rslib's config
|
|
2457
|
-
const {
|
|
2458
|
-
await inspect(
|
|
2489
|
+
const { config } = await init(options);
|
|
2490
|
+
await inspect(config, {
|
|
2459
2491
|
lib: options.lib,
|
|
2460
2492
|
mode: options.mode,
|
|
2461
2493
|
output: options.output,
|
|
@@ -2470,12 +2502,10 @@ function runCli() {
|
|
|
2470
2502
|
mfDevCommand.description('start Rsbuild dev server of Module Federation format').action(async (options)=>{
|
|
2471
2503
|
try {
|
|
2472
2504
|
const cliMfDev = async ()=>{
|
|
2473
|
-
const {
|
|
2505
|
+
const { config, watchFiles } = await init(options);
|
|
2474
2506
|
// TODO: support lib option in mf dev server
|
|
2475
|
-
await startMFDevServer(
|
|
2476
|
-
watchFilesForRestart(
|
|
2477
|
-
filePath
|
|
2478
|
-
], async ()=>{
|
|
2507
|
+
await startMFDevServer(config);
|
|
2508
|
+
watchFilesForRestart(watchFiles, async ()=>{
|
|
2479
2509
|
await cliMfDev();
|
|
2480
2510
|
});
|
|
2481
2511
|
};
|
|
@@ -2488,6 +2518,6 @@ function runCli() {
|
|
|
2488
2518
|
});
|
|
2489
2519
|
__WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.parse();
|
|
2490
2520
|
}
|
|
2491
|
-
const src_rslib_entry_version = "0.1.
|
|
2521
|
+
const src_rslib_entry_version = "0.1.3";
|
|
2492
2522
|
var __webpack_exports__logger = __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger;
|
|
2493
2523
|
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/cli/init.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { RslibConfig } from '../types';
|
|
2
2
|
import type { CommonOptions } from './commands';
|
|
3
|
-
export declare function
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
export declare function init(options: CommonOptions): Promise<{
|
|
4
|
+
config: RslibConfig;
|
|
5
|
+
configFilePath: string;
|
|
6
|
+
watchFiles: string[];
|
|
6
7
|
}>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rslib/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
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.8",
|
|
36
36
|
"tinyglobby": "^0.2.10",
|
|
37
|
-
"rsbuild-plugin-dts": "0.1.
|
|
37
|
+
"rsbuild-plugin-dts": "0.1.3"
|
|
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.14.
|
|
44
|
+
"memfs": "^4.14.1",
|
|
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.2",
|
|
48
48
|
"rslog": "^1.2.3",
|
|
49
49
|
"tsconfck": "3.1.4",
|
|
50
50
|
"typescript": "^5.6.3",
|