@rslib/core 0.13.3 → 0.15.0

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
@@ -18,6 +18,7 @@ const DEFAULT_CONFIG_EXTENSIONS = [
18
18
  '.cts'
19
19
  ];
20
20
  const SWC_HELPERS = '@swc/helpers';
21
+ const SHEBANG_PREFIX = '#!';
21
22
  const SHEBANG_REGEX = /#!.*[\s\n\r]*$/;
22
23
  const REACT_DIRECTIVE_REGEX = /^['"]use (client|server)['"](;?)[\s\n\r]*$/;
23
24
  const DTS_EXTENSIONS = [
@@ -394,7 +395,7 @@ class EntryChunkPlugin {
394
395
  const content = compiler.inputFileSystem.readFileSync(filename, {
395
396
  encoding: 'utf-8'
396
397
  });
397
- if (content.startsWith("#!")) {
398
+ if (content.startsWith(SHEBANG_PREFIX)) {
398
399
  const shebangMatch = matchFirstLine(content, SHEBANG_REGEX);
399
400
  if (shebangMatch) this.shebangEntries[name] = shebangMatch;
400
401
  }
@@ -509,6 +510,7 @@ const isDebug = ()=>{
509
510
  const values = process.env.DEBUG.toLocaleLowerCase().split(',');
510
511
  return [
511
512
  'rslib',
513
+ 'rsbuild',
512
514
  'rs*',
513
515
  'rstack',
514
516
  '*'
@@ -1519,6 +1521,7 @@ function composeMinifyConfig(config) {
1519
1521
  js: true,
1520
1522
  css: false,
1521
1523
  jsOptions: {
1524
+ test: /\.[cm]?jsx?(\?.*)?$/,
1522
1525
  minimizerOptions: {
1523
1526
  mangle: false,
1524
1527
  minify: 'mf' === format,
@@ -1877,6 +1880,34 @@ const fixJsModuleTypePlugin = ()=>({
1877
1880
  });
1878
1881
  }
1879
1882
  });
1883
+ const BundlePlugin = ()=>({
1884
+ name: 'rslib:bundle',
1885
+ setup (api) {
1886
+ api.onBeforeBuild({
1887
+ order: 'post',
1888
+ handler: ({ bundlerConfigs })=>{
1889
+ if (bundlerConfigs) {
1890
+ for (const config of bundlerConfigs)if (config?.module?.parser?.javascript?.jsx === true) {
1891
+ logger.error('Bundle mode does not support preserving JSX syntax. Set "bundle" to "false" or change the JSX runtime to `automatic` or `classic`. Check out ' + picocolors.green('https://rslib.rs/guide/solution/react#jsx-transform') + ' for more details.');
1892
+ process.exit(1);
1893
+ }
1894
+ }
1895
+ }
1896
+ });
1897
+ }
1898
+ });
1899
+ const composeBundleConfig = (bundle)=>{
1900
+ if (bundle) return {
1901
+ rsbuildConfig: {
1902
+ plugins: [
1903
+ BundlePlugin()
1904
+ ]
1905
+ }
1906
+ };
1907
+ return {
1908
+ rsbuildConfig: {}
1909
+ };
1910
+ };
1880
1911
  const composeShimsConfig = (format, shims)=>{
1881
1912
  const resolvedShims = {
1882
1913
  cjs: {
@@ -2342,6 +2373,7 @@ async function composeLibRsbuildConfig(config, multiCompilerIndex, root, sharedP
2342
2373
  const { compilerOptions } = await loadTsconfig(rootPath, config.source?.tsconfigPath);
2343
2374
  const cssModulesAuto = config.output?.cssModules?.auto ?? true;
2344
2375
  const { format = 'esm', shims, bundle = true, banner = {}, footer = {}, autoExtension = true, autoExternal, externalHelpers = false, redirect = {}, umdName } = config;
2376
+ const { rsbuildConfig: bundleConfig } = composeBundleConfig(bundle);
2345
2377
  const { rsbuildConfig: shimsConfig, enabledShims } = composeShimsConfig(format, shims);
2346
2378
  const formatConfig = composeFormatConfig({
2347
2379
  format,
@@ -2375,11 +2407,12 @@ async function composeLibRsbuildConfig(config, multiCompilerIndex, root, sharedP
2375
2407
  const bannerFooterConfig = composeBannerFooterConfig(banner, footer);
2376
2408
  const decoratorsConfig = composeDecoratorsConfig(compilerOptions, config.source?.decorators?.version);
2377
2409
  const printFileSizeConfig = composePrintFileSizeConfig(bundle, target);
2378
- return (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.mergeRsbuildConfig)(formatConfig, shimsConfig, syntaxConfig, externalHelpersConfig, outputFilenameConfig, targetConfig, externalsWarnConfig, userExternalsConfig, autoExternalConfig, targetExternalsConfig, bundlelessExternalConfig, entryConfig, cssConfig, assetConfig, entryChunkConfig, minifyConfig, dtsConfig, bannerFooterConfig, decoratorsConfig, printFileSizeConfig);
2410
+ return (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.mergeRsbuildConfig)(bundleConfig, formatConfig, shimsConfig, syntaxConfig, externalHelpersConfig, outputFilenameConfig, targetConfig, externalsWarnConfig, userExternalsConfig, autoExternalConfig, targetExternalsConfig, bundlelessExternalConfig, entryConfig, cssConfig, assetConfig, entryChunkConfig, minifyConfig, dtsConfig, bannerFooterConfig, decoratorsConfig, printFileSizeConfig);
2379
2411
  }
2380
2412
  async function composeCreateRsbuildConfig(rslibConfig) {
2381
2413
  const constantRsbuildConfig = await createConstantRsbuildConfig();
2382
- const { lib: libConfigsArray, mode: _mode, root, plugins: sharedPlugins, dev: _dev, server: _server, ...sharedRsbuildConfig } = rslibConfig;
2414
+ const { lib: libConfigsArray, mode: _mode, root, plugins: sharedPlugins, dev: _dev, server: _server, logLevel, ...sharedRsbuildConfig } = rslibConfig;
2415
+ if (logLevel && !isDebug()) logger.level = logLevel;
2383
2416
  if (!Array.isArray(libConfigsArray) || 0 === libConfigsArray.length) throw new Error(`Expect "lib" field to be a non-empty array, but got: ${picocolors.cyan(JSON.stringify(libConfigsArray))}.`);
2384
2417
  const libConfigPromises = libConfigsArray.map(async (libConfig, index)=>{
2385
2418
  const userConfig = (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.mergeRsbuildConfig)(sharedRsbuildConfig, libConfig);
@@ -2496,6 +2529,7 @@ async function build(config, options = {}) {
2496
2529
  plugins: config.plugins,
2497
2530
  dev: config.dev,
2498
2531
  server: config.server,
2532
+ logLevel: isDebug() ? 'info' : config.logLevel,
2499
2533
  environments: pruneEnvironments(environments, options.lib)
2500
2534
  }
2501
2535
  });
@@ -3015,6 +3049,7 @@ async function init(options) {
3015
3049
  ...config.source.define
3016
3050
  };
3017
3051
  if (options.root) config.root = root;
3052
+ if (options.logLevel) config.logLevel = options.logLevel;
3018
3053
  return {
3019
3054
  config,
3020
3055
  configFilePath,
@@ -3034,6 +3069,7 @@ async function inspect(config, options = {}) {
3034
3069
  plugins: config.plugins,
3035
3070
  dev: config.dev,
3036
3071
  server: config.server,
3072
+ logLevel: isDebug() ? 'info' : config.logLevel,
3037
3073
  environments: pruneEnvironments(environments, options.lib)
3038
3074
  }
3039
3075
  });
@@ -3041,7 +3077,10 @@ async function inspect(config, options = {}) {
3041
3077
  mode: options.mode,
3042
3078
  verbose: options.verbose,
3043
3079
  outputPath: options.output,
3044
- writeToDisk: true
3080
+ writeToDisk: true,
3081
+ extraConfigs: {
3082
+ rslib: config
3083
+ }
3045
3084
  });
3046
3085
  return rsbuildInstance;
3047
3086
  }
@@ -3066,6 +3105,7 @@ async function initMFRsbuild(config, options = {}) {
3066
3105
  plugins: config.plugins,
3067
3106
  dev: config.dev,
3068
3107
  server: config.server,
3108
+ logLevel: isDebug() ? 'info' : config.logLevel,
3069
3109
  environments: selectedEnvironments
3070
3110
  }
3071
3111
  });
@@ -3074,9 +3114,9 @@ async function initMFRsbuild(config, options = {}) {
3074
3114
  return rsbuildInstance;
3075
3115
  }
3076
3116
  const applyCommonOptions = (cli)=>{
3077
- cli.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('--config-loader <loader>', 'Set the config file loader (jiti | native)', {
3078
- default: 'jiti'
3079
- }).option('--env-dir <dir>', 'specify the directory to load `.env` files').option('--lib <id>', 'specify the library (repeatable, e.g. --lib esm --lib cjs)', {
3117
+ cli.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('--config-loader <loader>', 'Set the config file loader (auto | jiti | native)', {
3118
+ default: 'auto'
3119
+ }).option('--env-dir <dir>', 'specify the directory to load `.env` files').option('--log-level <level>', 'set the log level (info | warn | error | silent)').option('--lib <id>', 'specify the library (repeatable, e.g. --lib esm --lib cjs)', {
3080
3120
  type: [
3081
3121
  String
3082
3122
  ],
@@ -3086,7 +3126,7 @@ const applyCommonOptions = (cli)=>{
3086
3126
  function runCli() {
3087
3127
  const cli = dist('rslib');
3088
3128
  cli.help();
3089
- cli.version("0.13.3");
3129
+ cli.version("0.15.0");
3090
3130
  applyCommonOptions(cli);
3091
3131
  const buildCommand = cli.command('build', 'build the library for production');
3092
3132
  const inspectCommand = cli.command('inspect', 'inspect the Rsbuild / Rspack configs of Rslib projects');
@@ -3153,12 +3193,24 @@ function initNodeEnv() {
3153
3193
  ].includes(command) ? 'production' : 'development';
3154
3194
  }
3155
3195
  }
3196
+ function setupLogLevel() {
3197
+ const logLevelIndex = process.argv.findIndex((item)=>'--log-level' === item || '--logLevel' === item);
3198
+ if (-1 !== logLevelIndex) {
3199
+ const level = process.argv[logLevelIndex + 1];
3200
+ if (level && [
3201
+ 'warn',
3202
+ 'error',
3203
+ 'silent'
3204
+ ].includes(level) && !isDebug()) logger.level = level;
3205
+ }
3206
+ }
3156
3207
  function prepareCli() {
3157
3208
  initNodeEnv();
3209
+ setupLogLevel();
3158
3210
  const { npm_execpath } = process.env;
3159
- if (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) console.log();
3160
- logger.greet(` Rslib v0.13.3\n`);
3211
+ if (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) logger.log();
3212
+ logger.greet(` Rslib v0.15.0\n`);
3161
3213
  }
3162
- const src_version = "0.13.3";
3214
+ const src_version = "0.15.0";
3163
3215
  var __webpack_exports__rspack = __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.rspack;
3164
3216
  export { build, defineConfig, inspect, loadConfig, logger, prepareCli, __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__ as rsbuild, runCli, startMFDevServer, composeCreateRsbuildConfig as unstable_composeCreateRsbuildConfig, src_version as version, __webpack_exports__rspack as rspack };
@@ -1,4 +1,4 @@
1
- import type { RsbuildMode } from '@rsbuild/core';
1
+ import type { LogLevel, RsbuildMode } from '@rsbuild/core';
2
2
  import type { ConfigLoader } from '../config';
3
3
  export type CommonOptions = {
4
4
  root?: string;
@@ -7,6 +7,7 @@ export type CommonOptions = {
7
7
  envMode?: string;
8
8
  lib?: string[];
9
9
  configLoader?: ConfigLoader;
10
+ logLevel?: LogLevel;
10
11
  };
11
12
  export type BuildOptions = CommonOptions & {
12
13
  watch?: boolean;
@@ -8,7 +8,7 @@ export declare function defineConfig(config: RslibConfig): RslibConfig;
8
8
  export declare function defineConfig(config: RslibConfigSyncFn): RslibConfigSyncFn;
9
9
  export declare function defineConfig(config: RslibConfigAsyncFn): RslibConfigAsyncFn;
10
10
  export declare function defineConfig(config: RslibConfigExport): RslibConfigExport;
11
- export type ConfigLoader = 'jiti' | 'native';
11
+ export type ConfigLoader = 'auto' | 'jiti' | 'native';
12
12
  export declare function loadConfig({ cwd, path, envMode, loader, }: {
13
13
  cwd?: string;
14
14
  path?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rslib/core",
3
- "version": "0.13.3",
3
+ "version": "0.15.0",
4
4
  "description": "The Rsbuild-based library development tool.",
5
5
  "homepage": "https://rslib.rs",
6
6
  "bugs": {
@@ -36,8 +36,8 @@
36
36
  "types.d.ts"
37
37
  ],
38
38
  "dependencies": {
39
- "@rsbuild/core": "~1.5.7",
40
- "rsbuild-plugin-dts": "0.13.3"
39
+ "@rsbuild/core": "~1.5.13",
40
+ "rsbuild-plugin-dts": "0.15.0"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@module-federation/rsbuild-plugin": "^0.19.1",
@@ -45,12 +45,12 @@
45
45
  "cac": "^6.7.14",
46
46
  "chokidar": "^4.0.3",
47
47
  "fs-extra": "^11.3.2",
48
- "memfs": "^4.39.0",
48
+ "memfs": "^4.47.0",
49
49
  "path-serializer": "0.5.1",
50
50
  "picocolors": "1.1.1",
51
51
  "prebundle": "1.4.2",
52
52
  "rsbuild-plugin-publint": "^0.3.3",
53
- "rslib": "npm:@rslib/core@0.13.2",
53
+ "rslib": "npm:@rslib/core@0.14.0",
54
54
  "rslog": "^1.2.11",
55
55
  "tinyglobby": "0.2.14",
56
56
  "tsconfck": "3.1.6",