@rslib/core 0.13.2 → 0.14.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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Madeline Gurriarán
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ {"name":"tinyglobby","author":"Superchupu","version":"0.2.14","funding":{"url":"https://github.com/sponsors/SuperchupuDev"},"license":"MIT","types":"index.d.ts","type":"commonjs"}
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import node_fs, { chmodSync, promises } from "node:fs";
2
2
  import node_path, { basename, dirname, extname, isAbsolute, join } from "node:path";
3
- import { glob } from "tinyglobby";
3
+ import { glob } from "../compiled/tinyglobby/index.js";
4
4
  import { createRequire } from "node:module";
5
5
  import picocolors from "../compiled/picocolors/index.js";
6
6
  import { logger } from "../compiled/rslog/index.js";
@@ -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
  '*'
@@ -1387,12 +1389,13 @@ const resolveConfigPath = (root, customConfig)=>{
1387
1389
  if (configFilePath) return configFilePath;
1388
1390
  throw new Error(`${DEFAULT_CONFIG_NAME} not found in ${root}`);
1389
1391
  };
1390
- async function loadConfig({ cwd = process.cwd(), path, envMode }) {
1392
+ async function loadConfig({ cwd = process.cwd(), path, envMode, loader }) {
1391
1393
  const configFilePath = resolveConfigPath(cwd, path);
1392
1394
  const { content } = await (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.loadConfig)({
1393
1395
  cwd: dirname(configFilePath),
1394
1396
  path: configFilePath,
1395
- envMode
1397
+ envMode,
1398
+ loader
1396
1399
  });
1397
1400
  return {
1398
1401
  content: content,
@@ -1984,7 +1987,7 @@ const composeExternalsConfig = (format, externals)=>{
1984
1987
  }
1985
1988
  };
1986
1989
  };
1987
- const composeAutoExtensionConfig = (config, format, autoExtension, pkgJson)=>{
1990
+ const composeOutputFilenameConfig = (config, format, autoExtension, multiCompilerIndex, pkgJson)=>{
1988
1991
  const { jsExtension, dtsExtension } = getDefaultExtension({
1989
1992
  format,
1990
1993
  pkgJson,
@@ -1995,17 +1998,38 @@ const composeAutoExtensionConfig = (config, format, autoExtension, pkgJson)=>{
1995
1998
  if ('string' == typeof filenameHash) return filenameHash ? `.[${filenameHash}]` : '';
1996
1999
  return filenameHash ? '.[contenthash:8]' : '';
1997
2000
  };
2001
+ const inferChunkFilename = (filename)=>{
2002
+ if ('function' != typeof filename) {
2003
+ const hasName = filename.includes('[name]');
2004
+ const hasId = filename.includes('[id]');
2005
+ const hasChunkHash = filename.includes('[chunkhash]');
2006
+ const hasContentHash = filename.includes('[contenthash]');
2007
+ const multiCompilerPrefix = 'number' == typeof multiCompilerIndex ? `${multiCompilerIndex}~` : '';
2008
+ if (hasChunkHash || hasContentHash || hasName || hasId) return filename.replace(/(^|\/)([^/]*(?:\?|$))/, `$1${multiCompilerPrefix}$2`);
2009
+ return filename.replace(/(^|\/)([^/]*(?:\?|$))/, `$1${multiCompilerIndex}[id].$2`);
2010
+ }
2011
+ };
1998
2012
  const hash = getHash();
1999
2013
  const defaultJsFilename = `[name]${hash}${jsExtension}`;
2000
2014
  const userJsFilename = config.output?.filename?.js;
2015
+ const defaultJsChunkFilename = inferChunkFilename(userJsFilename ?? defaultJsFilename);
2001
2016
  const finalJsExtension = 'string' == typeof userJsFilename && userJsFilename ? extname(userJsFilename) : jsExtension;
2002
- const finalConfig = userJsFilename ? {} : {
2017
+ const chunkFilename = {
2018
+ tools: {
2019
+ rspack: {
2020
+ output: {
2021
+ chunkFilename: defaultJsChunkFilename
2022
+ }
2023
+ }
2024
+ }
2025
+ };
2026
+ const finalConfig = userJsFilename ? chunkFilename : (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.mergeRsbuildConfig)(chunkFilename, {
2003
2027
  output: {
2004
2028
  filename: {
2005
2029
  js: defaultJsFilename
2006
2030
  }
2007
2031
  }
2008
- };
2032
+ });
2009
2033
  return {
2010
2034
  config: finalConfig,
2011
2035
  jsExtension: finalJsExtension,
@@ -2313,7 +2337,7 @@ const composeExternalHelpersConfig = (externalHelpers, pkgJson)=>{
2313
2337
  }
2314
2338
  return defaultConfig;
2315
2339
  };
2316
- async function composeLibRsbuildConfig(config, root, sharedPlugins) {
2340
+ async function composeLibRsbuildConfig(config, multiCompilerIndex, root, sharedPlugins) {
2317
2341
  checkMFPlugin(config, sharedPlugins);
2318
2342
  const rootPath = root ? getAbsolutePath(process.cwd(), root) : process.cwd();
2319
2343
  const pkgJson = readPackageJson(rootPath);
@@ -2329,7 +2353,7 @@ async function composeLibRsbuildConfig(config, root, sharedPlugins) {
2329
2353
  });
2330
2354
  const externalHelpersConfig = composeExternalHelpersConfig(externalHelpers, pkgJson);
2331
2355
  const userExternalsConfig = composeExternalsConfig(format, config.output?.externals);
2332
- const { config: autoExtensionConfig, jsExtension, dtsExtension } = composeAutoExtensionConfig(config, format, autoExtension, pkgJson);
2356
+ const { config: outputFilenameConfig, jsExtension, dtsExtension } = composeOutputFilenameConfig(config, format, autoExtension, multiCompilerIndex, pkgJson);
2333
2357
  const { entryConfig, outBase } = await composeEntryConfig(config.source?.entry, config.bundle, rootPath, cssModulesAuto, config.outBase);
2334
2358
  const { config: bundlelessExternalConfig } = composeBundlelessExternalConfig(jsExtension, redirect, cssModulesAuto, bundle, outBase);
2335
2359
  const { config: targetConfig, externalsConfig: targetExternalsConfig, target } = composeTargetConfig(config.output?.target, format);
@@ -2353,15 +2377,16 @@ async function composeLibRsbuildConfig(config, root, sharedPlugins) {
2353
2377
  const bannerFooterConfig = composeBannerFooterConfig(banner, footer);
2354
2378
  const decoratorsConfig = composeDecoratorsConfig(compilerOptions, config.source?.decorators?.version);
2355
2379
  const printFileSizeConfig = composePrintFileSizeConfig(bundle, target);
2356
- return (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.mergeRsbuildConfig)(formatConfig, shimsConfig, syntaxConfig, externalHelpersConfig, autoExtensionConfig, targetConfig, externalsWarnConfig, userExternalsConfig, autoExternalConfig, targetExternalsConfig, bundlelessExternalConfig, entryConfig, cssConfig, assetConfig, entryChunkConfig, minifyConfig, dtsConfig, bannerFooterConfig, decoratorsConfig, printFileSizeConfig);
2380
+ 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);
2357
2381
  }
2358
2382
  async function composeCreateRsbuildConfig(rslibConfig) {
2359
2383
  const constantRsbuildConfig = await createConstantRsbuildConfig();
2360
- const { lib: libConfigsArray, mode: _mode, root, plugins: sharedPlugins, dev: _dev, server: _server, ...sharedRsbuildConfig } = rslibConfig;
2384
+ const { lib: libConfigsArray, mode: _mode, root, plugins: sharedPlugins, dev: _dev, server: _server, logLevel, ...sharedRsbuildConfig } = rslibConfig;
2385
+ if (logLevel && !isDebug()) logger.level = logLevel;
2361
2386
  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))}.`);
2362
- const libConfigPromises = libConfigsArray.map(async (libConfig)=>{
2387
+ const libConfigPromises = libConfigsArray.map(async (libConfig, index)=>{
2363
2388
  const userConfig = (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.mergeRsbuildConfig)(sharedRsbuildConfig, libConfig);
2364
- const libRsbuildConfig = await composeLibRsbuildConfig(userConfig, root, sharedPlugins);
2389
+ const libRsbuildConfig = await composeLibRsbuildConfig(userConfig, libConfigsArray.length > 1 ? index : null, root, sharedPlugins);
2365
2390
  userConfig.source ??= {};
2366
2391
  userConfig.source.entry = {};
2367
2392
  userConfig.output ??= {};
@@ -2474,6 +2499,7 @@ async function build(config, options = {}) {
2474
2499
  plugins: config.plugins,
2475
2500
  dev: config.dev,
2476
2501
  server: config.server,
2502
+ logLevel: isDebug() ? 'info' : config.logLevel,
2477
2503
  environments: pruneEnvironments(environments, options.lib)
2478
2504
  }
2479
2505
  });
@@ -2984,7 +3010,8 @@ async function init(options) {
2984
3010
  const { content: config, filePath: configFilePath } = await loadConfig({
2985
3011
  cwd: root,
2986
3012
  path: options.config,
2987
- envMode: options.envMode
3013
+ envMode: options.envMode,
3014
+ loader: options.configLoader
2988
3015
  });
2989
3016
  config.source ||= {};
2990
3017
  config.source.define = {
@@ -2992,6 +3019,7 @@ async function init(options) {
2992
3019
  ...config.source.define
2993
3020
  };
2994
3021
  if (options.root) config.root = root;
3022
+ if (options.logLevel) config.logLevel = options.logLevel;
2995
3023
  return {
2996
3024
  config,
2997
3025
  configFilePath,
@@ -3011,6 +3039,7 @@ async function inspect(config, options = {}) {
3011
3039
  plugins: config.plugins,
3012
3040
  dev: config.dev,
3013
3041
  server: config.server,
3042
+ logLevel: isDebug() ? 'info' : config.logLevel,
3014
3043
  environments: pruneEnvironments(environments, options.lib)
3015
3044
  }
3016
3045
  });
@@ -3043,6 +3072,7 @@ async function initMFRsbuild(config, options = {}) {
3043
3072
  plugins: config.plugins,
3044
3073
  dev: config.dev,
3045
3074
  server: config.server,
3075
+ logLevel: isDebug() ? 'info' : config.logLevel,
3046
3076
  environments: selectedEnvironments
3047
3077
  }
3048
3078
  });
@@ -3051,7 +3081,9 @@ async function initMFRsbuild(config, options = {}) {
3051
3081
  return rsbuildInstance;
3052
3082
  }
3053
3083
  const applyCommonOptions = (cli)=>{
3054
- 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('--env-dir <dir>', 'specify the directory to load `.env` files').option('--lib <id>', 'specify the library (repeatable, e.g. --lib esm --lib cjs)', {
3084
+ 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)', {
3085
+ default: 'auto'
3086
+ }).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)', {
3055
3087
  type: [
3056
3088
  String
3057
3089
  ],
@@ -3061,7 +3093,7 @@ const applyCommonOptions = (cli)=>{
3061
3093
  function runCli() {
3062
3094
  const cli = dist('rslib');
3063
3095
  cli.help();
3064
- cli.version("0.13.2");
3096
+ cli.version("0.14.0");
3065
3097
  applyCommonOptions(cli);
3066
3098
  const buildCommand = cli.command('build', 'build the library for production');
3067
3099
  const inspectCommand = cli.command('inspect', 'inspect the Rsbuild / Rspack configs of Rslib projects');
@@ -3128,12 +3160,24 @@ function initNodeEnv() {
3128
3160
  ].includes(command) ? 'production' : 'development';
3129
3161
  }
3130
3162
  }
3163
+ function setupLogLevel() {
3164
+ const logLevelIndex = process.argv.findIndex((item)=>'--log-level' === item || '--logLevel' === item);
3165
+ if (-1 !== logLevelIndex) {
3166
+ const level = process.argv[logLevelIndex + 1];
3167
+ if (level && [
3168
+ 'warn',
3169
+ 'error',
3170
+ 'silent'
3171
+ ].includes(level) && !isDebug()) logger.level = level;
3172
+ }
3173
+ }
3131
3174
  function prepareCli() {
3132
3175
  initNodeEnv();
3176
+ setupLogLevel();
3133
3177
  const { npm_execpath } = process.env;
3134
- if (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) console.log();
3135
- logger.greet(` Rslib v0.13.2\n`);
3178
+ if (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) logger.log();
3179
+ logger.greet(` Rslib v0.14.0\n`);
3136
3180
  }
3137
- const src_version = "0.13.2";
3181
+ const src_version = "0.14.0";
3138
3182
  var __webpack_exports__rspack = __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.rspack;
3139
3183
  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,10 +1,13 @@
1
- import type { RsbuildMode } from '@rsbuild/core';
1
+ import type { LogLevel, RsbuildMode } from '@rsbuild/core';
2
+ import type { ConfigLoader } from '../config';
2
3
  export type CommonOptions = {
3
4
  root?: string;
4
5
  config?: string;
5
6
  envDir?: string;
6
7
  envMode?: string;
7
8
  lib?: string[];
9
+ configLoader?: ConfigLoader;
10
+ logLevel?: LogLevel;
8
11
  };
9
12
  export type BuildOptions = CommonOptions & {
10
13
  watch?: boolean;
@@ -8,10 +8,12 @@ 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 declare function loadConfig({ cwd, path, envMode, }: {
11
+ export type ConfigLoader = 'auto' | 'jiti' | 'native';
12
+ export declare function loadConfig({ cwd, path, envMode, loader, }: {
12
13
  cwd?: string;
13
14
  path?: string;
14
15
  envMode?: string;
16
+ loader?: ConfigLoader;
15
17
  }): Promise<{
16
18
  content: RslibConfig;
17
19
  filePath: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rslib/core",
3
- "version": "0.13.2",
3
+ "version": "0.14.0",
4
4
  "description": "The Rsbuild-based library development tool.",
5
5
  "homepage": "https://rslib.rs",
6
6
  "bugs": {
@@ -36,23 +36,23 @@
36
36
  "types.d.ts"
37
37
  ],
38
38
  "dependencies": {
39
- "@rsbuild/core": "1.5.4",
40
- "tinyglobby": "^0.2.15",
41
- "rsbuild-plugin-dts": "0.13.2"
39
+ "@rsbuild/core": "~1.5.11",
40
+ "rsbuild-plugin-dts": "0.14.0"
42
41
  },
43
42
  "devDependencies": {
44
- "@module-federation/rsbuild-plugin": "^0.18.4",
43
+ "@module-federation/rsbuild-plugin": "^0.19.1",
45
44
  "@types/fs-extra": "^11.0.4",
46
45
  "cac": "^6.7.14",
47
46
  "chokidar": "^4.0.3",
48
- "fs-extra": "^11.3.1",
49
- "memfs": "^4.38.3",
47
+ "fs-extra": "^11.3.2",
48
+ "memfs": "^4.43.0",
50
49
  "path-serializer": "0.5.1",
51
50
  "picocolors": "1.1.1",
52
51
  "prebundle": "1.4.2",
53
52
  "rsbuild-plugin-publint": "^0.3.3",
54
- "rslib": "npm:@rslib/core@0.13.0",
53
+ "rslib": "npm:@rslib/core@0.13.3",
55
54
  "rslog": "^1.2.11",
55
+ "tinyglobby": "0.2.14",
56
56
  "tsconfck": "3.1.6",
57
57
  "typescript": "^5.9.2",
58
58
  "@rslib/tsconfig": "0.0.1"