@rslib/core 0.13.2 → 0.13.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.
@@ -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";
@@ -1387,12 +1387,13 @@ const resolveConfigPath = (root, customConfig)=>{
1387
1387
  if (configFilePath) return configFilePath;
1388
1388
  throw new Error(`${DEFAULT_CONFIG_NAME} not found in ${root}`);
1389
1389
  };
1390
- async function loadConfig({ cwd = process.cwd(), path, envMode }) {
1390
+ async function loadConfig({ cwd = process.cwd(), path, envMode, loader }) {
1391
1391
  const configFilePath = resolveConfigPath(cwd, path);
1392
1392
  const { content } = await (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.loadConfig)({
1393
1393
  cwd: dirname(configFilePath),
1394
1394
  path: configFilePath,
1395
- envMode
1395
+ envMode,
1396
+ loader
1396
1397
  });
1397
1398
  return {
1398
1399
  content: content,
@@ -1984,7 +1985,7 @@ const composeExternalsConfig = (format, externals)=>{
1984
1985
  }
1985
1986
  };
1986
1987
  };
1987
- const composeAutoExtensionConfig = (config, format, autoExtension, pkgJson)=>{
1988
+ const composeOutputFilenameConfig = (config, format, autoExtension, multiCompilerIndex, pkgJson)=>{
1988
1989
  const { jsExtension, dtsExtension } = getDefaultExtension({
1989
1990
  format,
1990
1991
  pkgJson,
@@ -1995,17 +1996,38 @@ const composeAutoExtensionConfig = (config, format, autoExtension, pkgJson)=>{
1995
1996
  if ('string' == typeof filenameHash) return filenameHash ? `.[${filenameHash}]` : '';
1996
1997
  return filenameHash ? '.[contenthash:8]' : '';
1997
1998
  };
1999
+ const inferChunkFilename = (filename)=>{
2000
+ if ('function' != typeof filename) {
2001
+ const hasName = filename.includes('[name]');
2002
+ const hasId = filename.includes('[id]');
2003
+ const hasChunkHash = filename.includes('[chunkhash]');
2004
+ const hasContentHash = filename.includes('[contenthash]');
2005
+ const multiCompilerPrefix = 'number' == typeof multiCompilerIndex ? `${multiCompilerIndex}~` : '';
2006
+ if (hasChunkHash || hasContentHash || hasName || hasId) return filename.replace(/(^|\/)([^/]*(?:\?|$))/, `$1${multiCompilerPrefix}$2`);
2007
+ return filename.replace(/(^|\/)([^/]*(?:\?|$))/, `$1${multiCompilerIndex}[id].$2`);
2008
+ }
2009
+ };
1998
2010
  const hash = getHash();
1999
2011
  const defaultJsFilename = `[name]${hash}${jsExtension}`;
2000
2012
  const userJsFilename = config.output?.filename?.js;
2013
+ const defaultJsChunkFilename = inferChunkFilename(userJsFilename ?? defaultJsFilename);
2001
2014
  const finalJsExtension = 'string' == typeof userJsFilename && userJsFilename ? extname(userJsFilename) : jsExtension;
2002
- const finalConfig = userJsFilename ? {} : {
2015
+ const chunkFilename = {
2016
+ tools: {
2017
+ rspack: {
2018
+ output: {
2019
+ chunkFilename: defaultJsChunkFilename
2020
+ }
2021
+ }
2022
+ }
2023
+ };
2024
+ const finalConfig = userJsFilename ? chunkFilename : (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.mergeRsbuildConfig)(chunkFilename, {
2003
2025
  output: {
2004
2026
  filename: {
2005
2027
  js: defaultJsFilename
2006
2028
  }
2007
2029
  }
2008
- };
2030
+ });
2009
2031
  return {
2010
2032
  config: finalConfig,
2011
2033
  jsExtension: finalJsExtension,
@@ -2313,7 +2335,7 @@ const composeExternalHelpersConfig = (externalHelpers, pkgJson)=>{
2313
2335
  }
2314
2336
  return defaultConfig;
2315
2337
  };
2316
- async function composeLibRsbuildConfig(config, root, sharedPlugins) {
2338
+ async function composeLibRsbuildConfig(config, multiCompilerIndex, root, sharedPlugins) {
2317
2339
  checkMFPlugin(config, sharedPlugins);
2318
2340
  const rootPath = root ? getAbsolutePath(process.cwd(), root) : process.cwd();
2319
2341
  const pkgJson = readPackageJson(rootPath);
@@ -2329,7 +2351,7 @@ async function composeLibRsbuildConfig(config, root, sharedPlugins) {
2329
2351
  });
2330
2352
  const externalHelpersConfig = composeExternalHelpersConfig(externalHelpers, pkgJson);
2331
2353
  const userExternalsConfig = composeExternalsConfig(format, config.output?.externals);
2332
- const { config: autoExtensionConfig, jsExtension, dtsExtension } = composeAutoExtensionConfig(config, format, autoExtension, pkgJson);
2354
+ const { config: outputFilenameConfig, jsExtension, dtsExtension } = composeOutputFilenameConfig(config, format, autoExtension, multiCompilerIndex, pkgJson);
2333
2355
  const { entryConfig, outBase } = await composeEntryConfig(config.source?.entry, config.bundle, rootPath, cssModulesAuto, config.outBase);
2334
2356
  const { config: bundlelessExternalConfig } = composeBundlelessExternalConfig(jsExtension, redirect, cssModulesAuto, bundle, outBase);
2335
2357
  const { config: targetConfig, externalsConfig: targetExternalsConfig, target } = composeTargetConfig(config.output?.target, format);
@@ -2353,15 +2375,15 @@ async function composeLibRsbuildConfig(config, root, sharedPlugins) {
2353
2375
  const bannerFooterConfig = composeBannerFooterConfig(banner, footer);
2354
2376
  const decoratorsConfig = composeDecoratorsConfig(compilerOptions, config.source?.decorators?.version);
2355
2377
  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);
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);
2357
2379
  }
2358
2380
  async function composeCreateRsbuildConfig(rslibConfig) {
2359
2381
  const constantRsbuildConfig = await createConstantRsbuildConfig();
2360
2382
  const { lib: libConfigsArray, mode: _mode, root, plugins: sharedPlugins, dev: _dev, server: _server, ...sharedRsbuildConfig } = rslibConfig;
2361
2383
  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)=>{
2384
+ const libConfigPromises = libConfigsArray.map(async (libConfig, index)=>{
2363
2385
  const userConfig = (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.mergeRsbuildConfig)(sharedRsbuildConfig, libConfig);
2364
- const libRsbuildConfig = await composeLibRsbuildConfig(userConfig, root, sharedPlugins);
2386
+ const libRsbuildConfig = await composeLibRsbuildConfig(userConfig, libConfigsArray.length > 1 ? index : null, root, sharedPlugins);
2365
2387
  userConfig.source ??= {};
2366
2388
  userConfig.source.entry = {};
2367
2389
  userConfig.output ??= {};
@@ -2984,7 +3006,8 @@ async function init(options) {
2984
3006
  const { content: config, filePath: configFilePath } = await loadConfig({
2985
3007
  cwd: root,
2986
3008
  path: options.config,
2987
- envMode: options.envMode
3009
+ envMode: options.envMode,
3010
+ loader: options.configLoader
2988
3011
  });
2989
3012
  config.source ||= {};
2990
3013
  config.source.define = {
@@ -3051,7 +3074,9 @@ async function initMFRsbuild(config, options = {}) {
3051
3074
  return rsbuildInstance;
3052
3075
  }
3053
3076
  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)', {
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)', {
3055
3080
  type: [
3056
3081
  String
3057
3082
  ],
@@ -3061,7 +3086,7 @@ const applyCommonOptions = (cli)=>{
3061
3086
  function runCli() {
3062
3087
  const cli = dist('rslib');
3063
3088
  cli.help();
3064
- cli.version("0.13.2");
3089
+ cli.version("0.13.3");
3065
3090
  applyCommonOptions(cli);
3066
3091
  const buildCommand = cli.command('build', 'build the library for production');
3067
3092
  const inspectCommand = cli.command('inspect', 'inspect the Rsbuild / Rspack configs of Rslib projects');
@@ -3132,8 +3157,8 @@ function prepareCli() {
3132
3157
  initNodeEnv();
3133
3158
  const { npm_execpath } = process.env;
3134
3159
  if (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) console.log();
3135
- logger.greet(` Rslib v0.13.2\n`);
3160
+ logger.greet(` Rslib v0.13.3\n`);
3136
3161
  }
3137
- const src_version = "0.13.2";
3162
+ const src_version = "0.13.3";
3138
3163
  var __webpack_exports__rspack = __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.rspack;
3139
3164
  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,12 @@
1
1
  import type { 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;
8
10
  };
9
11
  export type BuildOptions = CommonOptions & {
10
12
  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 = '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.13.3",
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.7",
40
+ "rsbuild-plugin-dts": "0.13.3"
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.39.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.2",
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"