@rslib/core 0.5.1 → 0.5.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
@@ -160,7 +160,7 @@ function prepareCli() {
160
160
  initNodeEnv();
161
161
  const { npm_execpath } = process.env;
162
162
  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.1\n`);
163
+ __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.greet(` Rslib v0.5.3\n`);
164
164
  }
165
165
  const DEFAULT_CONFIG_NAME = 'rslib.config';
166
166
  const DEFAULT_CONFIG_EXTENSIONS = [
@@ -315,8 +315,16 @@ const pluginLibAsset = ({ bundle })=>({
315
315
  });
316
316
  config.plugin(LibSvgrPatchPlugin.name).use(LibSvgrPatchPlugin, []);
317
317
  }
318
- if (!bundle) {
319
- if (isUsingSvgr) {
318
+ if (isUsingSvgr) {
319
+ if (bundle) {
320
+ const rule = config.module.rule(CHAIN_ID.RULE.SVG).oneOf(CHAIN_ID.ONE_OF.SVG_URL);
321
+ const originalGeneratorOptions = rule.get('generator');
322
+ const generatorOptions = isUserSetPublicPath ? originalGeneratorOptions : {
323
+ ...originalGeneratorOptions,
324
+ importMode: 'preserve'
325
+ };
326
+ rule.generator(generatorOptions);
327
+ } else {
320
328
  const rule = config.module.rule(CHAIN_ID.RULE.SVG).oneOf(CHAIN_ID.ONE_OF.SVG);
321
329
  rule.issuer([]);
322
330
  }
@@ -369,14 +377,6 @@ class LibCssExtractPlugin {
369
377
  this.options = options ?? {};
370
378
  }
371
379
  apply(compiler) {
372
- compiler.hooks.thisCompilation.tap(LibCssExtractPlugin_pluginName, (compilation)=>{
373
- compilation.hooks.chunkAsset.tap(LibCssExtractPlugin_pluginName, (_chunk, filename)=>{
374
- const asset = compilation.getAsset(filename);
375
- if (!asset) return;
376
- const needRemove = Boolean(asset.name.match(RSLIB_CSS_ENTRY_FLAG));
377
- if (needRemove) compilation.deleteAsset(filename);
378
- });
379
- });
380
380
  compiler.hooks.make.tap(LibCssExtractPlugin_pluginName, (compilation)=>{
381
381
  compilation.hooks.processAssets.tap(LibCssExtractPlugin_pluginName, (assets)=>{
382
382
  const chunkAsset = Object.keys(assets).filter((name)=>/\.css/.test(name));
@@ -454,6 +454,11 @@ const cssConfig_PLUGIN_NAME = 'rsbuild:lib-css';
454
454
  const pluginLibCss = (rootDir, banner, footer)=>({
455
455
  name: cssConfig_PLUGIN_NAME,
456
456
  setup (api) {
457
+ api.processAssets({
458
+ stage: 'additional'
459
+ }, ({ assets, compilation })=>{
460
+ for (const key of Object.keys(assets))if (key.match(RSLIB_CSS_ENTRY_FLAG)) compilation.deleteAsset(key);
461
+ });
457
462
  api.modifyBundlerChain((config, { CHAIN_ID })=>{
458
463
  let isUsingCssExtract = false;
459
464
  for (const ruleId of [
@@ -493,45 +498,16 @@ const composeCssConfig = (rootDir, bundle = true, banner, footer)=>{
493
498
  }
494
499
  };
495
500
  };
496
- const importMetaUrlShim = `const __rslib_import_meta_url__ = /*#__PURE__*/ (function () {
501
+ const EntryChunkPlugin_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module_ab9f2194__.createRequire)(import.meta.url);
502
+ const EntryChunkPlugin_PLUGIN_NAME = 'rsbuild:lib-entry-chunk';
503
+ const EntryChunkPlugin_LOADER_NAME = 'rsbuild:lib-entry-module';
504
+ const IMPORT_META_URL_SHIM = `const __rslib_import_meta_url__ = /*#__PURE__*/ (function () {
497
505
  return typeof document === 'undefined'
498
506
  ? new (require('url'.replace('', '')).URL)('file:' + __filename).href
499
507
  : (document.currentScript && document.currentScript.src) ||
500
508
  new URL('main.js', document.baseURI).href;
501
509
  })();
502
510
  `;
503
- const pluginCjsImportMetaUrlShim = ()=>({
504
- name: 'rsbuild:cjs-import-meta-url-shim',
505
- setup (api) {
506
- api.modifyEnvironmentConfig((config)=>{
507
- config.source.define = {
508
- ...config.source.define,
509
- 'import.meta.url': '__rslib_import_meta_url__'
510
- };
511
- });
512
- }
513
- });
514
- const requireShim = `// Rslib ESM shims
515
- import __rslib_shim_module__ from 'module';
516
- const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(import.meta.url);
517
- `;
518
- const pluginEsmRequireShim = ()=>({
519
- name: 'rsbuild:esm-require-shim',
520
- setup (api) {
521
- api.modifyRspackConfig((config)=>{
522
- config.plugins ??= [];
523
- config.plugins.push(new __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.rspack.BannerPlugin({
524
- banner: requireShim,
525
- stage: __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.rspack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE - 1,
526
- raw: true,
527
- include: /\.(js|cjs)$/
528
- }));
529
- });
530
- }
531
- });
532
- const EntryChunkPlugin_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module_ab9f2194__.createRequire)(import.meta.url);
533
- const EntryChunkPlugin_PLUGIN_NAME = 'rsbuild:lib-entry-chunk';
534
- const EntryChunkPlugin_LOADER_NAME = 'rsbuild:lib-entry-module';
535
511
  const matchFirstLine = (source, regex)=>{
536
512
  const lineBreakPos = source.match(/(\r\n|\n)/);
537
513
  const firstLineContent = source.slice(0, lineBreakPos?.index);
@@ -541,6 +517,7 @@ const matchFirstLine = (source, regex)=>{
541
517
  };
542
518
  class EntryChunkPlugin {
543
519
  reactDirectives = {};
520
+ shimsInjectedAssets = new Set();
544
521
  shebangChmod = 493;
545
522
  shebangEntries = {};
546
523
  shebangInjectedAssets = new Set();
@@ -587,6 +564,7 @@ class EntryChunkPlugin {
587
564
  if (!isJs) return;
588
565
  const name = chunk.name;
589
566
  if (!name) return;
567
+ this.shimsInjectedAssets.add(filename);
590
568
  const shebangEntry = this.shebangEntries[name];
591
569
  if (shebangEntry) this.shebangEntries[filename] = shebangEntry;
592
570
  const reactDirective = this.reactDirectives[name];
@@ -596,12 +574,12 @@ class EntryChunkPlugin {
596
574
  compiler.hooks.make.tap(EntryChunkPlugin_PLUGIN_NAME, (compilation)=>{
597
575
  compilation.hooks.processAssets.tap(EntryChunkPlugin_PLUGIN_NAME, (assets)=>{
598
576
  if (!this.enabledImportMetaUrlShim) return;
599
- const chunkAsset = Object.keys(assets).filter((name)=>JS_EXTENSIONS_PATTERN.test(name));
577
+ const chunkAsset = Object.keys(assets).filter((name)=>JS_EXTENSIONS_PATTERN.test(name) && this.shimsInjectedAssets.has(name));
600
578
  for (const name of chunkAsset)compilation.updateAsset(name, (old)=>{
601
579
  const oldSource = old.source().toString();
602
580
  const replaceSource = new __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.rspack.sources.ReplaceSource(old);
603
- if (oldSource.startsWith('use strict;') || oldSource.startsWith('"use strict";')) replaceSource.replace(0, 11, `"use strict";\n${importMetaUrlShim}`);
604
- else replaceSource.insert(0, importMetaUrlShim);
581
+ if (oldSource.startsWith('use strict;') || oldSource.startsWith('"use strict";')) replaceSource.replace(0, 11, `"use strict";\n${IMPORT_META_URL_SHIM}`);
582
+ else replaceSource.insert(0, IMPORT_META_URL_SHIM);
605
583
  return replaceSource;
606
584
  });
607
585
  });
@@ -653,6 +631,35 @@ const composeEntryChunkConfig = ({ enabledImportMetaUrlShim, contextToWatch = nu
653
631
  }
654
632
  }
655
633
  });
634
+ const pluginCjsImportMetaUrlShim = ()=>({
635
+ name: 'rsbuild:cjs-import-meta-url-shim',
636
+ setup (api) {
637
+ api.modifyEnvironmentConfig((config)=>{
638
+ config.source.define = {
639
+ ...config.source.define,
640
+ 'import.meta.url': '__rslib_import_meta_url__'
641
+ };
642
+ });
643
+ }
644
+ });
645
+ const requireShim = `// Rslib ESM shims
646
+ import __rslib_shim_module__ from 'module';
647
+ const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(import.meta.url);
648
+ `;
649
+ const pluginEsmRequireShim = ()=>({
650
+ name: 'rsbuild:esm-require-shim',
651
+ setup (api) {
652
+ api.modifyRspackConfig((config)=>{
653
+ config.plugins ??= [];
654
+ config.plugins.push(new __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.rspack.BannerPlugin({
655
+ banner: requireShim,
656
+ stage: __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.rspack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE - 1,
657
+ raw: true,
658
+ include: /\.(js|cjs)$/
659
+ }));
660
+ });
661
+ }
662
+ });
656
663
  const getDefaultExtension = (options)=>{
657
664
  const { format, pkgJson, autoExtension } = options;
658
665
  let jsExtension = '.js';
@@ -2442,7 +2449,7 @@ const repeatableOption = (value, previous)=>(previous ?? []).concat([
2442
2449
  value
2443
2450
  ]);
2444
2451
  function runCli() {
2445
- __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js_bca3ceaa__.program.name('rslib').usage('<command> [options]').version("0.5.1");
2452
+ __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js_bca3ceaa__.program.name('rslib').usage('<command> [options]').version("0.5.3");
2446
2453
  const buildCommand = __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js_bca3ceaa__.program.command('build');
2447
2454
  const inspectCommand = __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js_bca3ceaa__.program.command('inspect');
2448
2455
  const mfDevCommand = __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js_bca3ceaa__.program.command('mf-dev');
@@ -2503,6 +2510,6 @@ function runCli() {
2503
2510
  });
2504
2511
  __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js_bca3ceaa__.program.parse();
2505
2512
  }
2506
- const src_rslib_entry_version = "0.5.1";
2513
+ const src_rslib_entry_version = "0.5.3";
2507
2514
  var __webpack_exports__logger = __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger;
2508
2515
  export { build, defineConfig, inspect, loadConfig, prepareCli, runCli, startMFDevServer, composeCreateRsbuildConfig as unstable_composeCreateRsbuildConfig, src_rslib_entry_version as version, __webpack_exports__logger as logger };
@@ -1,4 +1,3 @@
1
1
  import { type RsbuildPlugin } from '@rsbuild/core';
2
- export declare const importMetaUrlShim = "const __rslib_import_meta_url__ = /*#__PURE__*/ (function () {\n return typeof document === 'undefined'\n ? new (require('url'.replace('', '')).URL)('file:' + __filename).href\n : (document.currentScript && document.currentScript.src) ||\n new URL('main.js', document.baseURI).href;\n})();\n";
3
2
  export declare const pluginCjsImportMetaUrlShim: () => RsbuildPlugin;
4
3
  export declare const pluginEsmRequireShim: () => RsbuildPlugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rslib/core",
3
- "version": "0.5.1",
3
+ "version": "0.5.3",
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.10",
39
+ "@rsbuild/core": "~1.2.13",
40
40
  "tinyglobby": "^0.2.12",
41
- "rsbuild-plugin-dts": "0.5.1"
41
+ "rsbuild-plugin-dts": "0.5.3"
42
42
  },
43
43
  "devDependencies": {
44
- "@module-federation/rsbuild-plugin": "^0.8.12",
44
+ "@module-federation/rsbuild-plugin": "^0.9.1",
45
45
  "@types/fs-extra": "^11.0.4",
46
46
  "chokidar": "^4.0.3",
47
47
  "commander": "^13.1.0",
@@ -50,10 +50,10 @@
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.0",
53
+ "rslib": "npm:@rslib/core@0.5.2",
54
54
  "rslog": "^1.2.3",
55
55
  "tsconfck": "3.1.5",
56
- "typescript": "^5.7.3",
56
+ "typescript": "^5.8.2",
57
57
  "@rslib/tsconfig": "0.0.1"
58
58
  },
59
59
  "peerDependencies": {
@@ -69,7 +69,7 @@
69
69
  }
70
70
  },
71
71
  "engines": {
72
- "node": ">=16.0.0"
72
+ "node": ">=16.7.0"
73
73
  },
74
74
  "publishConfig": {
75
75
  "access": "public",