@rslib/core 0.5.3 → 0.5.5

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
@@ -89,7 +89,7 @@ function getAbsolutePath(base, filepath) {
89
89
  const readPackageJson = (rootPath)=>{
90
90
  const pkgJsonPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(rootPath, './package.json');
91
91
  if (!__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].existsSync(pkgJsonPath)) {
92
- __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.warn(`package.json does not exist in the ${rootPath} directory`);
92
+ __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.warn(`The \`package.json\` file does not exist in the ${rootPath} directory`);
93
93
  return;
94
94
  }
95
95
  try {
@@ -147,7 +147,31 @@ const windowsSlashRegex = /\\/g;
147
147
  function normalizeSlash(p) {
148
148
  return p.replace(windowsSlashRegex, '/');
149
149
  }
150
- if (process.env.DEBUG) __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.level = 'verbose';
150
+ const isDebug = ()=>{
151
+ if (!process.env.DEBUG) return false;
152
+ const values = process.env.DEBUG.toLocaleLowerCase().split(',');
153
+ return [
154
+ 'rslib',
155
+ 'rs*',
156
+ 'rstack',
157
+ '*'
158
+ ].some((key)=>values.includes(key));
159
+ };
160
+ if (isDebug()) __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.level = 'verbose';
161
+ function getTime() {
162
+ const now = new Date();
163
+ const hours = String(now.getHours()).padStart(2, '0');
164
+ const minutes = String(now.getMinutes()).padStart(2, '0');
165
+ const seconds = String(now.getSeconds()).padStart(2, '0');
166
+ return `${hours}:${minutes}:${seconds}`;
167
+ }
168
+ __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.override({
169
+ debug: (message, ...args)=>{
170
+ if ('verbose' !== __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.level) return;
171
+ const time = __WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__["default"].gray(`${getTime()}`);
172
+ console.log(` ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__["default"].green('rslib')} ${time} ${message}`, ...args);
173
+ }
174
+ });
151
175
  function initNodeEnv() {
152
176
  if (!process.env.NODE_ENV) {
153
177
  const command = process.argv[2] ?? '';
@@ -160,7 +184,7 @@ function prepareCli() {
160
184
  initNodeEnv();
161
185
  const { npm_execpath } = process.env;
162
186
  if (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) console.log();
163
- __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.greet(` Rslib v0.5.3\n`);
187
+ __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.greet(` Rslib v0.5.5\n`);
164
188
  }
165
189
  const DEFAULT_CONFIG_NAME = 'rslib.config';
166
190
  const DEFAULT_CONFIG_EXTENSIONS = [
@@ -523,18 +547,20 @@ class EntryChunkPlugin {
523
547
  shebangInjectedAssets = new Set();
524
548
  enabledImportMetaUrlShim;
525
549
  contextToWatch = null;
526
- contextWatched = false;
527
550
  constructor({ enabledImportMetaUrlShim = true, contextToWatch }){
528
551
  this.enabledImportMetaUrlShim = enabledImportMetaUrlShim;
529
552
  this.contextToWatch = contextToWatch;
530
553
  }
531
554
  apply(compiler) {
532
- compiler.hooks.afterCompile.tap(EntryChunkPlugin_PLUGIN_NAME, (compilation)=>{
533
- if (this.contextWatched || null === this.contextToWatch) return;
534
- const contextDep = compilation.contextDependencies;
535
- contextDep.add(this.contextToWatch);
536
- this.contextWatched = true;
537
- });
555
+ compiler.hooks.afterCompile.tapPromise(EntryChunkPlugin_PLUGIN_NAME, (compilation)=>new Promise((resolve)=>{
556
+ if (null === this.contextToWatch) {
557
+ resolve();
558
+ return;
559
+ }
560
+ const contextDep = compilation.contextDependencies;
561
+ if (!contextDep.has(this.contextToWatch)) contextDep.add(this.contextToWatch);
562
+ resolve();
563
+ }));
538
564
  compiler.hooks.make.tap(EntryChunkPlugin_PLUGIN_NAME, (compilation)=>{
539
565
  const entries = {};
540
566
  for (const [key, value] of compilation.entries){
@@ -669,7 +695,7 @@ const getDefaultExtension = (options)=>{
669
695
  dtsExtension
670
696
  };
671
697
  if (!pkgJson) {
672
- __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.warn('autoExtension configuration will not be applied due to read package.json failed');
698
+ __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.warn('The `autoExtension` configuration will not be applied due to read package.json failed');
673
699
  return {
674
700
  jsExtension,
675
701
  dtsExtension
@@ -1462,7 +1488,7 @@ const composeExternalsWarnConfig = (format, ...externalsArray)=>{
1462
1488
  };
1463
1489
  if (contextInfo.issuer && 'commonjs' === dependencyType) {
1464
1490
  matchUserExternals(externals, request, _callback);
1465
- if (shouldWarn) __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.warn(composeModuleImportWarn(request));
1491
+ if (shouldWarn) __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.warn(composeModuleImportWarn(request, contextInfo.issuer));
1466
1492
  }
1467
1493
  callback();
1468
1494
  }
@@ -1477,7 +1503,7 @@ const composeAutoExternalConfig = (options)=>{
1477
1503
  const autoExternal = getAutoExternalDefaultValue(format, options.autoExternal);
1478
1504
  if (false === autoExternal) return {};
1479
1505
  if (!pkgJson) {
1480
- __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.warn('autoExternal configuration will not be applied due to read package.json failed');
1506
+ __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.warn('The `autoExternal` configuration will not be applied due to read package.json failed');
1481
1507
  return {};
1482
1508
  }
1483
1509
  const userExternalKeys = userExternals && isObject(userExternals) ? Object.keys(userExternals) : [];
@@ -1852,7 +1878,7 @@ const composeShimsConfig = (format, shims)=>{
1852
1878
  enabledShims
1853
1879
  };
1854
1880
  };
1855
- const composeModuleImportWarn = (request)=>`The externalized commonjs request ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__["default"].green(`"${request}"`)} will use ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__["default"].blue('"module"')} external type in ESM format. If you want to specify other external type, consider setting the request and type with ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__["default"].blue('"output.externals"')}.`;
1881
+ const composeModuleImportWarn = (request, issuer)=>`The externalized commonjs request ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__["default"].green(`"${request}"`)} from ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__["default"].green(issuer)} will use ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__["default"].blue('"module"')} external type in ESM format. If you want to specify other external type, consider setting the request and type with ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__["default"].blue('"output.externals"')}.`;
1856
1882
  const composeExternalsConfig = (format, externals)=>{
1857
1883
  const externalsTypeMap = {
1858
1884
  esm: 'module-import',
@@ -1885,10 +1911,16 @@ const composeAutoExtensionConfig = (config, autoExtension, pkgJson)=>{
1885
1911
  pkgJson,
1886
1912
  autoExtension
1887
1913
  });
1914
+ const filenameHash = config.output?.filenameHash ?? false;
1915
+ const getHash = ()=>{
1916
+ if ('string' == typeof filenameHash) return filenameHash ? `.[${filenameHash}]` : '';
1917
+ return filenameHash ? '.[contenthash:8]' : '';
1918
+ };
1919
+ const hash = getHash();
1888
1920
  const updatedConfig = {
1889
1921
  output: {
1890
1922
  filename: {
1891
- js: `[name]${jsExtension}`,
1923
+ js: `[name]${hash}${jsExtension}`,
1892
1924
  ...config.output?.filename
1893
1925
  }
1894
1926
  }
@@ -2238,7 +2270,7 @@ async function composeLibRsbuildConfig(config, root, sharedPlugins) {
2238
2270
  async function composeCreateRsbuildConfig(rslibConfig) {
2239
2271
  const constantRsbuildConfig = await createConstantRsbuildConfig();
2240
2272
  const { lib: libConfigsArray, mode, root, plugins: sharedPlugins, dev, server, ...sharedRsbuildConfig } = rslibConfig;
2241
- if (!libConfigsArray) throw new Error(`Expect lib field to be an array, but got ${libConfigsArray}.`);
2273
+ if (!Array.isArray(libConfigsArray) || 0 === libConfigsArray.length) throw new Error(`Expect "lib" field to be a non-empty array, but got: ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__["default"].cyan(JSON.stringify(libConfigsArray))}.`);
2242
2274
  const libConfigPromises = libConfigsArray.map(async (libConfig)=>{
2243
2275
  const userConfig = (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.mergeRsbuildConfig)(sharedRsbuildConfig, libConfig);
2244
2276
  const libRsbuildConfig = await composeLibRsbuildConfig(userConfig, root, sharedPlugins);
@@ -2339,8 +2371,8 @@ const beforeRestart = async ({ filePath, clear = true } = {})=>{
2339
2371
  if (clear) clearConsole();
2340
2372
  if (filePath) {
2341
2373
  const filename = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].basename(filePath);
2342
- __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.info(`Restart because ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__["default"].yellow(filename)} is changed.\n`);
2343
- } else __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.info('Restarting...\n');
2374
+ __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.info(`restart because ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__["default"].yellow(filename)} is changed.\n`);
2375
+ } else __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.info('restarting...\n');
2344
2376
  for (const cleaner of cleaners)await cleaner();
2345
2377
  cleaners = [];
2346
2378
  };
@@ -2449,7 +2481,7 @@ const repeatableOption = (value, previous)=>(previous ?? []).concat([
2449
2481
  value
2450
2482
  ]);
2451
2483
  function runCli() {
2452
- __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js_bca3ceaa__.program.name('rslib').usage('<command> [options]').version("0.5.3");
2484
+ __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js_bca3ceaa__.program.name('rslib').usage('<command> [options]').version("0.5.5");
2453
2485
  const buildCommand = __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js_bca3ceaa__.program.command('build');
2454
2486
  const inspectCommand = __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js_bca3ceaa__.program.command('inspect');
2455
2487
  const mfDevCommand = __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js_bca3ceaa__.program.command('mf-dev');
@@ -2510,6 +2542,6 @@ function runCli() {
2510
2542
  });
2511
2543
  __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js_bca3ceaa__.program.parse();
2512
2544
  }
2513
- const src_rslib_entry_version = "0.5.3";
2545
+ const src_rslib_entry_version = "0.5.5";
2514
2546
  var __webpack_exports__logger = __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger;
2515
2547
  export { build, defineConfig, inspect, loadConfig, prepareCli, runCli, startMFDevServer, composeCreateRsbuildConfig as unstable_composeCreateRsbuildConfig, src_rslib_entry_version as version, __webpack_exports__logger as logger };
@@ -27,7 +27,7 @@ export declare function composeMinifyConfig(config: LibConfig): EnvironmentConfi
27
27
  export declare function composeBannerFooterConfig(banner: BannerAndFooter, footer: BannerAndFooter): EnvironmentConfig;
28
28
  export declare function composeDecoratorsConfig(compilerOptions?: Record<string, any>, version?: NonNullable<NonNullable<EnvironmentConfig['source']>['decorators']>['version']): EnvironmentConfig;
29
29
  export declare function createConstantRsbuildConfig(): Promise<EnvironmentConfig>;
30
- export declare const composeModuleImportWarn: (request: string) => string;
30
+ export declare const composeModuleImportWarn: (request: string, issuer: string) => string;
31
31
  export declare const appendEntryQuery: (entries: RsbuildConfigEntry) => RsbuildEntry;
32
32
  export declare const resolveEntryPath: (entries: RsbuildConfigEntry, root: string) => RsbuildEntry;
33
33
  export declare function composeCreateRsbuildConfig(rslibConfig: RslibConfig): Promise<RsbuildConfigWithLibInfo[]>;
@@ -1,4 +1,4 @@
1
- import type { EnvironmentConfig, RsbuildConfig, Rspack } from '@rsbuild/core';
1
+ import type { EnvironmentConfig, OutputConfig, RsbuildConfig, Rspack } from '@rsbuild/core';
2
2
  import type { GetAsyncFunctionFromUnion } from './utils';
3
3
  export type Format = 'esm' | 'cjs' | 'umd' | 'mf';
4
4
  export type FixedEcmaVersions = 'es5' | 'es6' | 'es2015' | 'es2016' | 'es2017' | 'es2018' | 'es2019' | 'es2020' | 'es2021' | 'es2022' | 'es2023';
@@ -16,31 +16,31 @@ export type RsbuildConfigOutputTarget = NonNullable<EnvironmentConfig['output']>
16
16
  export type Syntax = EcmaScriptVersion | string[];
17
17
  export type Dts = {
18
18
  /**
19
- * Whether to bundle the DTS files.
19
+ * Whether to bundle the declaration files.
20
20
  * @defaultValue `false`
21
21
  * @see {@link https://lib.rsbuild.dev/config/lib/dts#dtsbundle}
22
22
  */
23
23
  bundle?: boolean;
24
24
  /**
25
- * The output directory of DTS files.
25
+ * The output directory of declaration files.
26
26
  * @defaultValue {@link https://lib.rsbuild.dev/config/lib/dts#default-value}
27
27
  * @see {@link https://lib.rsbuild.dev/config/lib/dts#dtsdistpath}
28
28
  */
29
29
  distPath?: string;
30
30
  /**
31
- * Whether to generate DTS files with building the project references.
31
+ * Whether to generate declaration files with building the project references.
32
32
  * @defaultValue `false`
33
33
  * @see {@link https://lib.rsbuild.dev/config/lib/dts#dtsbuild}
34
34
  */
35
35
  build?: boolean;
36
36
  /**
37
- * Whether to abort the build process when an error occurs during DTS generation.
37
+ * Whether to abort the build process when an error occurs during declaration files generation.
38
38
  * @defaultValue `true`
39
39
  * @see {@link https://lib.rsbuild.dev/config/lib/dts#dtsabortonerror}
40
40
  */
41
41
  abortOnError?: boolean;
42
42
  /**
43
- * Whether to automatically set the DTS file extension based on the {@link format} option.
43
+ * Whether to automatically set the declaration file extension based on the {@link format} option.
44
44
  * @defaultValue `false`
45
45
  * @see {@link https://lib.rsbuild.dev/config/lib/dts#dtsautoextension}
46
46
  */
@@ -211,13 +211,13 @@ export interface LibConfig extends EnvironmentConfig {
211
211
  */
212
212
  externalHelpers?: boolean;
213
213
  /**
214
- * Inject content into the top of each JavaScript, CSS or DTS file.
214
+ * Inject content into the top of each JavaScript, CSS or declaration file.
215
215
  * @defaultValue `{}`
216
216
  * @see {@link https://lib.rsbuild.dev/config/lib/banner}
217
217
  */
218
218
  banner?: BannerAndFooter;
219
219
  /**
220
- * Inject content into the bottom of each JavaScript, CSS or DTS file.
220
+ * Inject content into the bottom of each JavaScript, CSS or declaration file.
221
221
  * @defaultValue `{}`
222
222
  * @see {@link https://lib.rsbuild.dev/config/lib/footer}
223
223
  */
@@ -259,10 +259,38 @@ export interface LibConfig extends EnvironmentConfig {
259
259
  * @see {@link https://lib.rsbuild.dev/config/lib/out-base}
260
260
  */
261
261
  outBase?: string;
262
+ /**
263
+ * @inheritdoc
264
+ */
265
+ output?: RslibOutputConfig;
262
266
  }
263
267
  export type LibOnlyConfig = Omit<LibConfig, keyof EnvironmentConfig>;
268
+ interface RslibOutputConfig extends OutputConfig {
269
+ /**
270
+ * @override
271
+ * @default 'node'
272
+ */
273
+ target?: OutputConfig['target'];
274
+ /**
275
+ * @override
276
+ * @default false
277
+ */
278
+ filenameHash?: OutputConfig['filenameHash'];
279
+ /**
280
+ * @override
281
+ * When minify is not specified, Rslib will use a sane default for minify options.
282
+ * The default options will only perform dead code elimination and unused code elimination.
283
+ *
284
+ * @see {@link https://lib.rsbuild.dev/config/rsbuild/output#outputminify}
285
+ */
286
+ minify?: OutputConfig['minify'];
287
+ }
264
288
  export interface RslibConfig extends RsbuildConfig {
265
289
  lib: LibConfig[];
290
+ /**
291
+ * @inheritdoc
292
+ */
293
+ output?: RslibOutputConfig;
266
294
  }
267
295
  export type ConfigParams = {
268
296
  env: string;
@@ -272,3 +300,4 @@ export type ConfigParams = {
272
300
  export type RslibConfigSyncFn = (env: ConfigParams) => RslibConfig;
273
301
  export type RslibConfigAsyncFn = (env: ConfigParams) => Promise<RslibConfig>;
274
302
  export type RslibConfigExport = RslibConfig | RslibConfigSyncFn | RslibConfigAsyncFn;
303
+ export {};
@@ -1,5 +1,18 @@
1
+ /**
2
+ * Logging message case convention:
3
+ *
4
+ * Info, ready, success and debug messages:
5
+ * - Start with lowercase
6
+ * - Example: "info build started..."
7
+ *
8
+ * Errors and warnings:
9
+ * - Start with uppercase
10
+ * - Example: "error Failed to build"
11
+ *
12
+ * This convention helps distinguish between normal operations
13
+ * and important alerts that require attention.
14
+ */
1
15
  import { type Logger, logger } from '../../compiled/rslog';
2
16
  export declare const isDebug: () => boolean;
3
- export declare const debug: (message: string | (() => string)) => void;
4
17
  export { logger };
5
18
  export type { Logger };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rslib/core",
3
- "version": "0.5.3",
3
+ "version": "0.5.5",
4
4
  "description": "The Rsbuild-based library development tool.",
5
5
  "homepage": "https://lib.rsbuild.dev",
6
6
  "bugs": {
@@ -36,12 +36,12 @@
36
36
  "types.d.ts"
37
37
  ],
38
38
  "dependencies": {
39
- "@rsbuild/core": "~1.2.13",
39
+ "@rsbuild/core": "~1.2.19",
40
40
  "tinyglobby": "^0.2.12",
41
- "rsbuild-plugin-dts": "0.5.3"
41
+ "rsbuild-plugin-dts": "0.5.5"
42
42
  },
43
43
  "devDependencies": {
44
- "@module-federation/rsbuild-plugin": "^0.9.1",
44
+ "@module-federation/rsbuild-plugin": "^0.11.1",
45
45
  "@types/fs-extra": "^11.0.4",
46
46
  "chokidar": "^4.0.3",
47
47
  "commander": "^13.1.0",
@@ -50,7 +50,7 @@
50
50
  "picocolors": "1.1.1",
51
51
  "prebundle": "1.2.7",
52
52
  "rsbuild-plugin-publint": "^0.3.0",
53
- "rslib": "npm:@rslib/core@0.5.2",
53
+ "rslib": "npm:@rslib/core@0.5.4",
54
54
  "rslog": "^1.2.3",
55
55
  "tsconfck": "3.1.5",
56
56
  "typescript": "^5.8.2",