@rslib/core 0.1.2 → 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 CHANGED
@@ -166,7 +166,7 @@ function prepareCli() {
166
166
  // Some package managers automatically output a blank line, some do not.
167
167
  const { npm_execpath } = process.env;
168
168
  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.2\n`);
169
+ __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.greet(` Rslib v0.1.3\n`);
170
170
  }
171
171
  const DEFAULT_CONFIG_NAME = 'rslib.config';
172
172
  const DEFAULT_CONFIG_EXTENSIONS = [
@@ -1807,6 +1807,9 @@ const composeFormatConfig = ({ format, bundle = true, umdName, pkgJson })=>{
1807
1807
  } : {
1808
1808
  type: 'umd'
1809
1809
  }
1810
+ },
1811
+ optimization: {
1812
+ nodeEnv: process.env.NODE_ENV
1810
1813
  }
1811
1814
  }
1812
1815
  }
@@ -2368,14 +2371,37 @@ async function build(config, options = {}) {
2368
2371
  else await buildInstance.close();
2369
2372
  return rsbuildInstance;
2370
2373
  }
2371
- async function loadRslibConfig(options) {
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) {
2372
2379
  const cwd = process.cwd();
2373
2380
  const root = options.root ? getAbsolutePath(cwd, options.root) : cwd;
2374
- return loadConfig({
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({
2375
2387
  cwd: root,
2376
2388
  path: options.config,
2377
2389
  envMode: options.envMode
2378
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
+ };
2379
2405
  }
2380
2406
  async function inspect(config, options = {}) {
2381
2407
  const environments = await composeRsbuildEnvironments(config);
@@ -2426,13 +2452,13 @@ function changeEnvToDev(rsbuildConfig) {
2426
2452
  });
2427
2453
  }
2428
2454
  const applyCommonOptions = (command)=>{
2429
- 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');
2430
2456
  };
2431
2457
  const repeatableOption = (value, previous)=>(previous ?? []).concat([
2432
2458
  value
2433
2459
  ]);
2434
2460
  function runCli() {
2435
- __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.name('rslib').usage('<command> [options]').version("0.1.2");
2461
+ __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.name('rslib').usage('<command> [options]').version("0.1.3");
2436
2462
  const buildCommand = __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.command('build');
2437
2463
  const inspectCommand = __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.command('inspect');
2438
2464
  const mfDevCommand = __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.command('mf dev');
@@ -2444,11 +2470,9 @@ function runCli() {
2444
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)=>{
2445
2471
  try {
2446
2472
  const cliBuild = async ()=>{
2447
- const { content: rslibConfig, filePath } = await loadRslibConfig(options);
2448
- await build(rslibConfig, options);
2449
- if (options.watch) watchFilesForRestart([
2450
- filePath
2451
- ], async ()=>{
2473
+ const { config, watchFiles } = await init(options);
2474
+ await build(config, options);
2475
+ if (options.watch) watchFilesForRestart(watchFiles, async ()=>{
2452
2476
  await cliBuild();
2453
2477
  });
2454
2478
  };
@@ -2462,8 +2486,8 @@ function runCli() {
2462
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)=>{
2463
2487
  try {
2464
2488
  // TODO: inspect should output Rslib's config
2465
- const { content: rslibConfig } = await loadRslibConfig(options);
2466
- await inspect(rslibConfig, {
2489
+ const { config } = await init(options);
2490
+ await inspect(config, {
2467
2491
  lib: options.lib,
2468
2492
  mode: options.mode,
2469
2493
  output: options.output,
@@ -2478,12 +2502,10 @@ function runCli() {
2478
2502
  mfDevCommand.description('start Rsbuild dev server of Module Federation format').action(async (options)=>{
2479
2503
  try {
2480
2504
  const cliMfDev = async ()=>{
2481
- const { content: rslibConfig, filePath } = await loadRslibConfig(options);
2505
+ const { config, watchFiles } = await init(options);
2482
2506
  // TODO: support lib option in mf dev server
2483
- await startMFDevServer(rslibConfig);
2484
- watchFilesForRestart([
2485
- filePath
2486
- ], async ()=>{
2507
+ await startMFDevServer(config);
2508
+ watchFilesForRestart(watchFiles, async ()=>{
2487
2509
  await cliMfDev();
2488
2510
  });
2489
2511
  };
@@ -2496,6 +2518,6 @@ function runCli() {
2496
2518
  });
2497
2519
  __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.parse();
2498
2520
  }
2499
- const src_rslib_entry_version = "0.1.2";
2521
+ const src_rslib_entry_version = "0.1.3";
2500
2522
  var __webpack_exports__logger = __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger;
2501
2523
  export { build, defineConfig, inspect, loadConfig, prepareCli, runCli, startMFDevServer, composeCreateRsbuildConfig as unstable_composeCreateRsbuildConfig, src_rslib_entry_version as version, __webpack_exports__logger as logger };
@@ -2,6 +2,7 @@ import type { RsbuildMode } from '@rsbuild/core';
2
2
  export type CommonOptions = {
3
3
  root?: string;
4
4
  config?: string;
5
+ envDir?: string;
5
6
  envMode?: string;
6
7
  lib?: string[];
7
8
  };
@@ -1,6 +1,7 @@
1
1
  import type { RslibConfig } from '../types';
2
2
  import type { CommonOptions } from './commands';
3
- export declare function loadRslibConfig(options: CommonOptions): Promise<{
4
- content: RslibConfig;
5
- filePath: string;
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.2",
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,9 +32,9 @@
32
32
  "compiled"
33
33
  ],
34
34
  "dependencies": {
35
- "@rsbuild/core": "~1.1.7",
35
+ "@rsbuild/core": "~1.1.8",
36
36
  "tinyglobby": "^0.2.10",
37
- "rsbuild-plugin-dts": "0.1.2"
37
+ "rsbuild-plugin-dts": "0.1.3"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/fs-extra": "^11.0.4",
@@ -44,7 +44,7 @@
44
44
  "memfs": "^4.14.1",
45
45
  "picocolors": "1.1.1",
46
46
  "prebundle": "1.2.5",
47
- "rslib": "npm:@rslib/core@0.1.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",