@rslib/core 0.0.6 → 0.0.8

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
@@ -7,11 +7,6 @@ import * as __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__ from "../co
7
7
  import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core__ from "@rsbuild/core";
8
8
  import * as __WEBPACK_EXTERNAL_MODULE__compiled_fast_glob_index_js__ from "../compiled/fast-glob/index.js";
9
9
  import * as __WEBPACK_EXTERNAL_MODULE_module__ from "module";
10
- var index_js_namespaceObject = __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__;
11
- var external_node_fs_namespaceObject = __WEBPACK_EXTERNAL_MODULE_node_fs__;
12
- var promises_namespaceObject = __WEBPACK_EXTERNAL_MODULE_node_fs_promises__;
13
- var external_node_path_namespaceObject = __WEBPACK_EXTERNAL_MODULE_node_path__;
14
- var picocolors_index_js_namespaceObject = __WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js__;
15
10
  /**
16
11
  * Node.js built-in modules.
17
12
  * Copied from https://github.com/webpack/webpack/blob/dd44b206a9c50f4b4cb4d134e1a0bd0387b159a3/lib/node/NodeTargetPlugin.js#L12-L72
@@ -80,7 +75,7 @@ async function calcLongestCommonPath(absPaths) {
80
75
  // we support two cases
81
76
  // 1. /packages-a/src/index.ts
82
77
  // 2. D:/packages-a/src/index.ts
83
- const sep = external_node_path_namespaceObject["default"].posix.sep;
78
+ const sep = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].posix.sep;
84
79
  const splitPaths = absPaths.map((p)=>p.split(sep));
85
80
  let lcaFragments = splitPaths[0];
86
81
  for(let i = 1; i < splitPaths.length; i++){
@@ -91,20 +86,20 @@ async function calcLongestCommonPath(absPaths) {
91
86
  lcaFragments = lcaFragments.slice(0, j);
92
87
  }
93
88
  let lca = lcaFragments.length > 0 ? lcaFragments.join(sep) : sep;
94
- const stats = await promises_namespaceObject["default"].stat(lca);
95
- if (stats?.isFile()) lca = external_node_path_namespaceObject["default"].dirname(lca);
89
+ const stats = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises__["default"].stat(lca);
90
+ if (stats?.isFile()) lca = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname(lca);
96
91
  return lca;
97
92
  }
98
93
  const readPackageJson = (rootPath)=>{
99
- const pkgJsonPath = external_node_path_namespaceObject["default"].join(rootPath, './package.json');
100
- if (!external_node_fs_namespaceObject["default"].existsSync(pkgJsonPath)) {
101
- index_js_namespaceObject.logger.warn(`package.json does not exist in the ${rootPath} directory`);
94
+ const pkgJsonPath = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(rootPath, './package.json');
95
+ if (!__WEBPACK_EXTERNAL_MODULE_node_fs__["default"].existsSync(pkgJsonPath)) {
96
+ __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.warn(`package.json does not exist in the ${rootPath} directory`);
102
97
  return;
103
98
  }
104
99
  try {
105
- return JSON.parse(external_node_fs_namespaceObject["default"].readFileSync(pkgJsonPath, 'utf8'));
100
+ return JSON.parse(__WEBPACK_EXTERNAL_MODULE_node_fs__["default"].readFileSync(pkgJsonPath, 'utf8'));
106
101
  } catch (err) {
107
- index_js_namespaceObject.logger.warn(`Failed to parse ${pkgJsonPath}, it might not be valid JSON`);
102
+ __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.warn(`Failed to parse ${pkgJsonPath}, it might not be valid JSON`);
108
103
  return;
109
104
  }
110
105
  };
@@ -123,7 +118,7 @@ function omit(obj, keys) {
123
118
  }, {});
124
119
  }
125
120
  // setup the logger level
126
- if (process.env.DEBUG) index_js_namespaceObject.logger.level = 'verbose';
121
+ if (process.env.DEBUG) __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.level = 'verbose';
127
122
  function initNodeEnv() {
128
123
  if (!process.env.NODE_ENV) {
129
124
  const command = process.argv[2] ?? '';
@@ -138,13 +133,10 @@ function prepareCli() {
138
133
  // Some package managers automatically output a blank line, some do not.
139
134
  const { npm_execpath } = process.env;
140
135
  if (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) console.log();
141
- index_js_namespaceObject.logger.greet(` Rslib v0.0.6\n`);
136
+ __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.greet(` Rslib v0.0.8\n`);
142
137
  }
143
- var commander_index_js_namespaceObject = __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__;
144
- var core_namespaceObject = __WEBPACK_EXTERNAL_MODULE__rsbuild_core__;
145
- var fast_glob_index_js_namespaceObject = __WEBPACK_EXTERNAL_MODULE__compiled_fast_glob_index_js__;
146
138
  const DEFAULT_CONFIG_NAME = 'rslib.config';
147
- const DEFAULT_EXTENSIONS = [
139
+ const DEFAULT_CONFIG_EXTENSIONS = [
148
140
  '.js',
149
141
  '.ts',
150
142
  '.mjs',
@@ -153,6 +145,65 @@ const DEFAULT_EXTENSIONS = [
153
145
  '.cts'
154
146
  ];
155
147
  const SWC_HELPERS = '@swc/helpers';
148
+ const JS_EXTENSIONS = [
149
+ 'js',
150
+ 'mjs',
151
+ 'jsx',
152
+ 'ts',
153
+ 'mts',
154
+ 'tsx',
155
+ 'cjs',
156
+ 'cjsx',
157
+ 'mjsx',
158
+ 'mtsx',
159
+ 'cts',
160
+ 'ctsx'
161
+ ];
162
+ const CSS_EXTENSIONS = [
163
+ 'css',
164
+ 'sass',
165
+ 'scss',
166
+ 'less'
167
+ ];
168
+ const ENTRY_EXTENSIONS = [
169
+ ...JS_EXTENSIONS,
170
+ ...CSS_EXTENSIONS
171
+ ];
172
+ const JS_EXTENSIONS_PATTERN = new RegExp(`\\.(${JS_EXTENSIONS.join('|')})$`);
173
+ const ENTRY_EXTENSIONS_PATTERN = new RegExp(`\\.(${ENTRY_EXTENSIONS.join('|')})$`);
174
+ const importMetaUrlShim = `var __rslib_import_meta_url__ = /*#__PURE__*/ (function () {
175
+ return typeof document === 'undefined'
176
+ ? new (require('url'.replace('', '')).URL)('file:' + __filename).href
177
+ : (document.currentScript && document.currentScript.src) ||
178
+ new URL('main.js', document.baseURI).href;
179
+ })();
180
+ `;
181
+ // This Rsbuild plugin will shim `import.meta.url` for CommonJS modules.
182
+ // - Replace `import.meta.url` with `importMetaUrl`.
183
+ // - Inject `importMetaUrl` to the end of the module (can't inject at the beginning because of `"use strict";`).
184
+ // This is a short-term solution, and we hope to provide built-in polyfills like `node.__filename` on Rspack side.
185
+ const pluginCjsShim = ()=>({
186
+ name: 'rsbuild-plugin-cjs-shim',
187
+ setup (api) {
188
+ api.modifyEnvironmentConfig((config)=>{
189
+ config.source.define = {
190
+ ...config.source.define,
191
+ 'import.meta.url': '__rslib_import_meta_url__'
192
+ };
193
+ });
194
+ api.modifyRspackConfig((config)=>{
195
+ config.plugins ??= [];
196
+ config.plugins.push(new __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.rspack.BannerPlugin({
197
+ banner: importMetaUrlShim,
198
+ // Just before minify stage, to perform tree shaking.
199
+ stage: __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.rspack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE - 1,
200
+ raw: true,
201
+ footer: true,
202
+ include: /\.(js|cjs)$/
203
+ }));
204
+ });
205
+ }
206
+ });
156
207
  const getDefaultExtension = (options)=>{
157
208
  const { format, pkgJson, autoExtension } = options;
158
209
  let jsExtension = '.js';
@@ -162,7 +213,7 @@ const getDefaultExtension = (options)=>{
162
213
  dtsExtension
163
214
  };
164
215
  if (!pkgJson) {
165
- index_js_namespaceObject.logger.warn('autoExtension configuration will not be applied due to read package.json failed');
216
+ __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.warn('autoExtension configuration will not be applied due to read package.json failed');
166
217
  return {
167
218
  jsExtension,
168
219
  dtsExtension
@@ -207,6 +258,11 @@ const calcEsnextBrowserslistByTarget = (target)=>{
207
258
  if ('node' === target) return LATEST_TARGET_VERSIONS.node;
208
259
  return LATEST_TARGET_VERSIONS.web;
209
260
  };
261
+ const RSPACK_TARGET_UNLISTED_MODERN_ECMA_VERSIONS = [
262
+ 'es2023',
263
+ 'es2024',
264
+ 'esnext'
265
+ ];
210
266
  /**
211
267
  * The esX to browserslist mapping is transformed from esbuild:
212
268
  * https://github.com/evanw/esbuild/blob/main/internal/compat/js_table.go
@@ -324,6 +380,25 @@ const calcEsnextBrowserslistByTarget = (target)=>{
324
380
  Safari: '3.1.0'
325
381
  }
326
382
  };
383
+ function transformSyntaxToRspackTarget(syntax) {
384
+ const handleSyntaxItem = (syntaxItem)=>{
385
+ const normalizedSyntaxItem = syntaxItem.toLowerCase();
386
+ if (normalizedSyntaxItem.startsWith('es')) {
387
+ if (normalizedSyntaxItem in ESX_TO_BROWSERSLIST) {
388
+ // The latest EcmaScript version supported by Rspack's `target` is es2022.
389
+ // Higher versions are treated as es2022.
390
+ if (RSPACK_TARGET_UNLISTED_MODERN_ECMA_VERSIONS.includes(normalizedSyntaxItem)) return 'es2022';
391
+ return normalizedSyntaxItem;
392
+ }
393
+ throw new Error(`Unsupported ES version: ${syntaxItem}`);
394
+ }
395
+ return `browserslist:${syntaxItem}`;
396
+ };
397
+ if (Array.isArray(syntax)) return syntax.map(handleSyntaxItem);
398
+ return [
399
+ handleSyntaxItem(syntax)
400
+ ];
401
+ }
327
402
  function transformSyntaxToBrowserslist(syntax, target) {
328
403
  const handleSyntaxItem = (syntaxItem)=>{
329
404
  const normalizedSyntaxItem = syntaxItem.toLowerCase();
@@ -345,8 +420,8 @@ function transformSyntaxToBrowserslist(syntax, target) {
345
420
  if (Array.isArray(syntax)) return syntax.flatMap(handleSyntaxItem);
346
421
  return handleSyntaxItem(syntax);
347
422
  }
348
- const POSIX_SEP_RE = new RegExp('\\' + external_node_path_namespaceObject["default"].posix.sep, 'g');
349
- const NATIVE_SEP_RE = new RegExp('\\' + external_node_path_namespaceObject["default"].sep, 'g');
423
+ const POSIX_SEP_RE = new RegExp('\\' + __WEBPACK_EXTERNAL_MODULE_node_path__["default"].posix.sep, 'g');
424
+ const NATIVE_SEP_RE = new RegExp('\\' + __WEBPACK_EXTERNAL_MODULE_node_path__["default"].sep, 'g');
350
425
  /** @type {Map<string,RegExp>}*/ const PATTERN_REGEX_CACHE = new Map();
351
426
  const GLOB_ALL_PATTERN = "**/*";
352
427
  const TS_EXTENSIONS = [
@@ -355,16 +430,16 @@ const TS_EXTENSIONS = [
355
430
  '.mts',
356
431
  '.cts'
357
432
  ];
358
- const JS_EXTENSIONS = [
433
+ const util_JS_EXTENSIONS = [
359
434
  '.js',
360
435
  '.jsx',
361
436
  '.mjs',
362
437
  '.cjs'
363
438
  ];
364
- const TSJS_EXTENSIONS = TS_EXTENSIONS.concat(JS_EXTENSIONS);
439
+ const TSJS_EXTENSIONS = TS_EXTENSIONS.concat(util_JS_EXTENSIONS);
365
440
  const TS_EXTENSIONS_RE_GROUP = `\\.(?:${TS_EXTENSIONS.map((ext)=>ext.substring(1)).join('|')})`;
366
441
  const TSJS_EXTENSIONS_RE_GROUP = `\\.(?:${TSJS_EXTENSIONS.map((ext)=>ext.substring(1)).join('|')})`;
367
- const IS_POSIX = external_node_path_namespaceObject["default"].posix.sep === external_node_path_namespaceObject["default"].sep;
442
+ const IS_POSIX = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].posix.sep === __WEBPACK_EXTERNAL_MODULE_node_path__["default"].sep;
368
443
  /**
369
444
  * @template T
370
445
  * @returns {{resolve:(result:T)=>void, reject:(error:any)=>void, promise: Promise<T>}}
@@ -385,10 +460,10 @@ const IS_POSIX = external_node_path_namespaceObject["default"].posix.sep === ext
385
460
  * @param {import('./cache.js').TSConfckCache} [cache]
386
461
  * @returns {Promise<string|void>}
387
462
  */ async function util_resolveTSConfigJson(filename, cache) {
388
- if ('.json' !== external_node_path_namespaceObject["default"].extname(filename)) return; // ignore files that are not json
389
- const tsconfig = external_node_path_namespaceObject["default"].resolve(filename);
463
+ if ('.json' !== __WEBPACK_EXTERNAL_MODULE_node_path__["default"].extname(filename)) return; // ignore files that are not json
464
+ const tsconfig = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].resolve(filename);
390
465
  if (cache && (cache.hasParseResult(tsconfig) || cache.hasParseResult(filename))) return tsconfig;
391
- return external_node_fs_namespaceObject.promises.stat(tsconfig).then((stat)=>{
466
+ return __WEBPACK_EXTERNAL_MODULE_node_fs__.promises.stat(tsconfig).then((stat)=>{
392
467
  if (stat.isFile() || stat.isFIFO()) return tsconfig;
393
468
  throw new Error(`${filename} exists but is not a regular file.`);
394
469
  });
@@ -407,7 +482,7 @@ const IS_POSIX = external_node_path_namespaceObject["default"].posix.sep === ext
407
482
  *
408
483
  * @param {string} filename with posix separators
409
484
  * @returns {string} filename with native separators
410
- */ const posix2native = IS_POSIX ? (filename)=>filename : (filename)=>filename.replace(POSIX_SEP_RE, external_node_path_namespaceObject["default"].sep);
485
+ */ const posix2native = IS_POSIX ? (filename)=>filename : (filename)=>filename.replace(POSIX_SEP_RE, __WEBPACK_EXTERNAL_MODULE_node_path__["default"].sep);
411
486
  /**
412
487
  * convert native separator to posix separator
413
488
  *
@@ -417,7 +492,7 @@ const IS_POSIX = external_node_path_namespaceObject["default"].posix.sep === ext
417
492
  *
418
493
  * @param {string} filename - filename with native separators
419
494
  * @returns {string} filename with posix separators
420
- */ const util_native2posix = IS_POSIX ? (filename)=>filename : (filename)=>filename.replace(NATIVE_SEP_RE, external_node_path_namespaceObject["default"].posix.sep);
495
+ */ const util_native2posix = IS_POSIX ? (filename)=>filename : (filename)=>filename.replace(NATIVE_SEP_RE, __WEBPACK_EXTERNAL_MODULE_node_path__["default"].posix.sep);
421
496
  /**
422
497
  * converts params to native separator, resolves path and converts native back to posix
423
498
  *
@@ -426,16 +501,16 @@ const IS_POSIX = external_node_path_namespaceObject["default"].posix.sep === ext
426
501
  * @param dir {string|null} directory to resolve from
427
502
  * @param filename {string} filename or pattern to resolve
428
503
  * @returns string
429
- */ const resolve2posix = IS_POSIX ? (dir, filename)=>dir ? external_node_path_namespaceObject["default"].resolve(dir, filename) : external_node_path_namespaceObject["default"].resolve(filename) : (dir, filename)=>util_native2posix(dir ? external_node_path_namespaceObject["default"].resolve(posix2native(dir), posix2native(filename)) : external_node_path_namespaceObject["default"].resolve(posix2native(filename)));
504
+ */ const resolve2posix = IS_POSIX ? (dir, filename)=>dir ? __WEBPACK_EXTERNAL_MODULE_node_path__["default"].resolve(dir, filename) : __WEBPACK_EXTERNAL_MODULE_node_path__["default"].resolve(filename) : (dir, filename)=>util_native2posix(dir ? __WEBPACK_EXTERNAL_MODULE_node_path__["default"].resolve(posix2native(dir), posix2native(filename)) : __WEBPACK_EXTERNAL_MODULE_node_path__["default"].resolve(posix2native(filename)));
430
505
  /**
431
506
  *
432
507
  * @param {import('./public.d.ts').TSConfckParseResult} result
433
508
  * @param {import('./public.d.ts').TSConfckParseOptions} [options]
434
509
  * @returns {string[]}
435
510
  */ function util_resolveReferencedTSConfigFiles(result, options) {
436
- const dir = external_node_path_namespaceObject["default"].dirname(result.tsconfigFile);
511
+ const dir = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname(result.tsconfigFile);
437
512
  return result.tsconfig.references.map((ref)=>{
438
- const refPath = ref.path.endsWith('.json') ? ref.path : external_node_path_namespaceObject["default"].join(ref.path, options?.configName ?? 'tsconfig.json');
513
+ const refPath = ref.path.endsWith('.json') ? ref.path : __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(ref.path, options?.configName ?? 'tsconfig.json');
439
514
  return resolve2posix(dir, refPath);
440
515
  });
441
516
  }
@@ -458,7 +533,7 @@ const IS_POSIX = external_node_path_namespaceObject["default"].posix.sep === ext
458
533
  * @param {import('./public.d.ts').TSConfckParseResult} result
459
534
  * @returns {boolean}
460
535
  */ function util_isIncluded(filename, result) {
461
- const dir = util_native2posix(external_node_path_namespaceObject["default"].dirname(result.tsconfigFile));
536
+ const dir = util_native2posix(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname(result.tsconfigFile));
462
537
  const files = (result.tsconfig.files || []).map((file)=>resolve2posix(dir, file));
463
538
  const absoluteFilename = resolve2posix(null, filename);
464
539
  if (files.includes(filename)) return true;
@@ -560,13 +635,13 @@ const IS_POSIX = external_node_path_namespaceObject["default"].posix.sep === ext
560
635
  * @param {import('./public.d.ts').TSConfckFindOptions} [options] - options
561
636
  * @returns {Promise<string|null>} absolute path to closest tsconfig.json or null if not found
562
637
  */ async function find(filename, options) {
563
- let dir = external_node_path_namespaceObject["default"].dirname(external_node_path_namespaceObject["default"].resolve(filename));
638
+ let dir = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].resolve(filename));
564
639
  if (options?.ignoreNodeModules && util_isInNodeModules(dir)) return null;
565
640
  const cache = options?.cache;
566
641
  const configName = options?.configName ?? 'tsconfig.json';
567
642
  if (cache?.hasConfigPath(dir, configName)) return cache.getConfigPath(dir, configName);
568
643
  const { promise, resolve, reject } = util_makePromise();
569
- if (options?.root && !external_node_path_namespaceObject["default"].isAbsolute(options.root)) options.root = external_node_path_namespaceObject["default"].resolve(options.root);
644
+ if (options?.root && !__WEBPACK_EXTERNAL_MODULE_node_path__["default"].isAbsolute(options.root)) options.root = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].resolve(options.root);
570
645
  findUp(dir, {
571
646
  promise,
572
647
  resolve,
@@ -594,13 +669,13 @@ const IS_POSIX = external_node_path_namespaceObject["default"].posix.sep === ext
594
669
  else resolve(cached);
595
670
  } else cache.setConfigPath(dir, promise, configName);
596
671
  }
597
- const tsconfig = external_node_path_namespaceObject["default"].join(dir, options?.configName ?? 'tsconfig.json');
598
- external_node_fs_namespaceObject["default"].stat(tsconfig, (err, stats)=>{
672
+ const tsconfig = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(dir, options?.configName ?? 'tsconfig.json');
673
+ __WEBPACK_EXTERNAL_MODULE_node_fs__["default"].stat(tsconfig, (err, stats)=>{
599
674
  if (stats && (stats.isFile() || stats.isFIFO())) resolve(tsconfig);
600
675
  else if (err?.code !== 'ENOENT') reject(err);
601
676
  else {
602
677
  let parent;
603
- if (root === dir || (parent = external_node_path_namespaceObject["default"].dirname(dir)) === dir) resolve(null);
678
+ if (root === dir || (parent = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname(dir)) === dir) resolve(null);
604
679
  else findUp(parent, {
605
680
  promise,
606
681
  resolve,
@@ -617,7 +692,7 @@ const IS_POSIX = external_node_path_namespaceObject["default"].posix.sep === ext
617
692
  * @property {(dir: string)=>boolean} skip - function to skip dirs
618
693
  * @property {boolean} err - error flag
619
694
  * @property {string[]} configNames - config file names
620
- */ external_node_path_namespaceObject["default"].sep;
695
+ */ __WEBPACK_EXTERNAL_MODULE_node_path__["default"].sep;
621
696
  /*
622
697
  this file contains code from strip-bom and strip-json-comments by Sindre Sorhus
623
698
  https://github.com/sindresorhus/strip-json-comments/blob/v4.0.0/index.js
@@ -752,7 +827,6 @@ const multiComment = Symbol('multiComment');
752
827
  if (0xfeff === string.charCodeAt(0)) return string.slice(1);
753
828
  return string;
754
829
  }
755
- var external_module_namespaceObject = __WEBPACK_EXTERNAL_MODULE_module__;
756
830
  const not_found_result = {
757
831
  tsconfigFile: null,
758
832
  tsconfig: {}
@@ -784,7 +858,7 @@ const not_found_result = {
784
858
  parseReferences(result, options)
785
859
  ]);
786
860
  }
787
- result.tsconfig = util_replaceTokens(result.tsconfig, external_node_path_namespaceObject["default"].dirname(tsconfigFile));
861
+ result.tsconfig = util_replaceTokens(result.tsconfig, __WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname(tsconfigFile));
788
862
  resolve(util_resolveSolutionTSConfig(filename, result));
789
863
  } catch (e) {
790
864
  reject(e);
@@ -817,12 +891,12 @@ const not_found_result = {
817
891
  * @returns {Promise<import('./public.d.ts').TSConfckParseResult>}
818
892
  */ async function parseFile(tsconfigFile, cache, skipCache) {
819
893
  if (!skipCache && cache?.hasParseResult(tsconfigFile) && !cache.getParseResult(tsconfigFile)._isRootFile_) return cache.getParseResult(tsconfigFile);
820
- const promise = external_node_fs_namespaceObject.promises.readFile(tsconfigFile, 'utf-8').then(toJson).then((json)=>{
894
+ const promise = __WEBPACK_EXTERNAL_MODULE_node_fs__.promises.readFile(tsconfigFile, 'utf-8').then(toJson).then((json)=>{
821
895
  const parsed = JSON.parse(json);
822
896
  applyDefaults(parsed, tsconfigFile);
823
897
  return {
824
898
  tsconfigFile,
825
- tsconfig: normalizeTSConfig(parsed, external_node_path_namespaceObject["default"].dirname(tsconfigFile))
899
+ tsconfig: normalizeTSConfig(parsed, __WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname(tsconfigFile))
826
900
  };
827
901
  }).catch((e)=>{
828
902
  throw new TSConfckParseError(`parsing ${tsconfigFile} failed: ${e}`, 'PARSE_FILE', tsconfigFile, e);
@@ -838,7 +912,7 @@ const not_found_result = {
838
912
  */ function normalizeTSConfig(tsconfig, dir) {
839
913
  // set baseUrl to absolute path
840
914
  const baseUrl = tsconfig.compilerOptions?.baseUrl;
841
- if (baseUrl && !baseUrl.startsWith('${') && !external_node_path_namespaceObject["default"].isAbsolute(baseUrl)) tsconfig.compilerOptions.baseUrl = resolve2posix(dir, baseUrl);
915
+ if (baseUrl && !baseUrl.startsWith('${') && !__WEBPACK_EXTERNAL_MODULE_node_path__["default"].isAbsolute(baseUrl)) tsconfig.compilerOptions.baseUrl = resolve2posix(dir, baseUrl);
842
916
  return tsconfig;
843
917
  }
844
918
  /**
@@ -913,14 +987,14 @@ const not_found_result = {
913
987
  */ function resolveExtends(extended, from) {
914
988
  if ('..' === extended) // see #149
915
989
  extended = '../tsconfig.json';
916
- const req = (0, external_module_namespaceObject.createRequire)(from);
990
+ const req = (0, __WEBPACK_EXTERNAL_MODULE_module__.createRequire)(from);
917
991
  let error;
918
992
  try {
919
993
  return req.resolve(extended);
920
994
  } catch (e) {
921
995
  error = e;
922
996
  }
923
- if ('.' !== extended[0] && !external_node_path_namespaceObject["default"].isAbsolute(extended)) try {
997
+ if ('.' !== extended[0] && !__WEBPACK_EXTERNAL_MODULE_node_path__["default"].isAbsolute(extended)) try {
924
998
  return req.resolve(`${extended}/tsconfig.json`);
925
999
  } catch (e) {
926
1000
  error = e;
@@ -946,7 +1020,7 @@ const EXTENDABLE_KEYS = [
946
1020
  */ function extendTSConfig(extending, extended) {
947
1021
  const extendingConfig = extending.tsconfig;
948
1022
  const extendedConfig = extended.tsconfig;
949
- const relativePath = util_native2posix(external_node_path_namespaceObject["default"].relative(external_node_path_namespaceObject["default"].dirname(extending.tsconfigFile), external_node_path_namespaceObject["default"].dirname(extended.tsconfigFile)));
1023
+ const relativePath = util_native2posix(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].relative(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname(extending.tsconfigFile), __WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname(extended.tsconfigFile)));
950
1024
  for (const key of Object.keys(extendedConfig).filter((key)=>EXTENDABLE_KEYS.includes(key)))if ('compilerOptions' === key) {
951
1025
  if (!extendingConfig.compilerOptions) extendingConfig.compilerOptions = {};
952
1026
  for (const option of Object.keys(extendedConfig.compilerOptions)){
@@ -993,9 +1067,9 @@ const REBASE_KEYS = [
993
1067
  * @param {string} prependPath
994
1068
  * @returns {string}
995
1069
  */ function rebasePath(value, prependPath) {
996
- if (external_node_path_namespaceObject["default"].isAbsolute(value) || value.startsWith('${configDir}')) return value;
1070
+ if (__WEBPACK_EXTERNAL_MODULE_node_path__["default"].isAbsolute(value) || value.startsWith('${configDir}')) return value;
997
1071
  // relative paths use posix syntax in tsconfig
998
- return external_node_path_namespaceObject["default"].posix.normalize(external_node_path_namespaceObject["default"].posix.join(prependPath, value));
1072
+ return __WEBPACK_EXTERNAL_MODULE_node_path__["default"].posix.normalize(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].posix.join(prependPath, value));
999
1073
  }
1000
1074
  class TSConfckParseError extends Error {
1001
1075
  /**
@@ -1046,12 +1120,12 @@ const DEFAULT_JSCONFIG_COMPILER_OPTIONS = {
1046
1120
  /**
1047
1121
  * @param {string} configFileName
1048
1122
  */ function isJSConfig(configFileName) {
1049
- return 'jsconfig.json' === external_node_path_namespaceObject["default"].basename(configFileName);
1123
+ return 'jsconfig.json' === __WEBPACK_EXTERNAL_MODULE_node_path__["default"].basename(configFileName);
1050
1124
  }
1051
1125
  async function loadTsconfig(root, tsconfigPath = 'tsconfig.json') {
1052
- const tsconfigFileName = await find((0, external_node_path_namespaceObject.join)(root, tsconfigPath), {
1126
+ const tsconfigFileName = await find((0, __WEBPACK_EXTERNAL_MODULE_node_path__.join)(root, tsconfigPath), {
1053
1127
  root,
1054
- configName: (0, external_node_path_namespaceObject.basename)(tsconfigPath)
1128
+ configName: (0, __WEBPACK_EXTERNAL_MODULE_node_path__.basename)(tsconfigPath)
1055
1129
  });
1056
1130
  if (tsconfigFileName) {
1057
1131
  const { tsconfig } = await parse(tsconfigFileName);
@@ -1059,27 +1133,24 @@ async function loadTsconfig(root, tsconfigPath = 'tsconfig.json') {
1059
1133
  }
1060
1134
  return {};
1061
1135
  }
1062
- /**
1063
- * This function helps you to autocomplete configuration types.
1064
- * It accepts a Rslib config object, or a function that returns a config.
1065
- */ function defineConfig(config) {
1136
+ function defineConfig(config) {
1066
1137
  return config;
1067
1138
  }
1068
- const findConfig = (basePath)=>DEFAULT_EXTENSIONS.map((ext)=>basePath + ext).find(external_node_fs_namespaceObject["default"].existsSync);
1139
+ const findConfig = (basePath)=>DEFAULT_CONFIG_EXTENSIONS.map((ext)=>basePath + ext).find(__WEBPACK_EXTERNAL_MODULE_node_fs__["default"].existsSync);
1069
1140
  const resolveConfigPath = (root, customConfig)=>{
1070
1141
  if (customConfig) {
1071
- const customConfigPath = (0, external_node_path_namespaceObject.isAbsolute)(customConfig) ? customConfig : (0, external_node_path_namespaceObject.join)(root, customConfig);
1072
- if (external_node_fs_namespaceObject["default"].existsSync(customConfigPath)) return customConfigPath;
1073
- index_js_namespaceObject.logger.warn(`Cannot find config file: ${picocolors_index_js_namespaceObject["default"].dim(customConfigPath)}\n`);
1142
+ const customConfigPath = (0, __WEBPACK_EXTERNAL_MODULE_node_path__.isAbsolute)(customConfig) ? customConfig : (0, __WEBPACK_EXTERNAL_MODULE_node_path__.join)(root, customConfig);
1143
+ if (__WEBPACK_EXTERNAL_MODULE_node_fs__["default"].existsSync(customConfigPath)) return customConfigPath;
1144
+ __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.warn(`Cannot find config file: ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js__["default"].dim(customConfigPath)}\n`);
1074
1145
  }
1075
- const configFilePath = findConfig((0, external_node_path_namespaceObject.join)(root, DEFAULT_CONFIG_NAME));
1146
+ const configFilePath = findConfig((0, __WEBPACK_EXTERNAL_MODULE_node_path__.join)(root, DEFAULT_CONFIG_NAME));
1076
1147
  if (configFilePath) return configFilePath;
1077
1148
  throw new Error(`${DEFAULT_CONFIG_NAME} not found in ${root}`);
1078
1149
  };
1079
1150
  async function loadConfig({ cwd = process.cwd(), path, envMode }) {
1080
1151
  const configFilePath = resolveConfigPath(cwd, path);
1081
- const { content } = await (0, core_namespaceObject.loadConfig)({
1082
- cwd: (0, external_node_path_namespaceObject.dirname)(configFilePath),
1152
+ const { content } = await (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.loadConfig)({
1153
+ cwd: (0, __WEBPACK_EXTERNAL_MODULE_node_path__.dirname)(configFilePath),
1083
1154
  path: configFilePath,
1084
1155
  envMode
1085
1156
  });
@@ -1145,7 +1216,7 @@ const composeExternalsWarnConfig = (format, ...externalsArray)=>{
1145
1216
  };
1146
1217
  if (contextInfo.issuer && 'commonjs' === dependencyType) {
1147
1218
  matchUserExternals(externals, request, _callback);
1148
- if (externalized) index_js_namespaceObject.logger.warn(composeModuleImportWarn(request));
1219
+ if (externalized) __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.warn(composeModuleImportWarn(request));
1149
1220
  }
1150
1221
  callback();
1151
1222
  }
@@ -1157,7 +1228,7 @@ const composeAutoExternalConfig = (options)=>{
1157
1228
  const { autoExternal, pkgJson, userExternals } = options;
1158
1229
  if (!autoExternal) return {};
1159
1230
  if (!pkgJson) {
1160
- index_js_namespaceObject.logger.warn('autoExternal configuration will not be applied due to read package.json failed');
1231
+ __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.warn('autoExternal configuration will not be applied due to read package.json failed');
1161
1232
  return {};
1162
1233
  }
1163
1234
  const externalOptions = {
@@ -1230,30 +1301,30 @@ function composeBannerFooterConfig(banner, footer) {
1230
1301
  if (isEmptyObject(bannerConfig) && isEmptyObject(footerConfig)) return {};
1231
1302
  const plugins = [];
1232
1303
  if (!isEmptyObject(bannerConfig)) {
1233
- if (bannerConfig.js) plugins.push(new core_namespaceObject.rspack.BannerPlugin({
1304
+ if (bannerConfig.js) plugins.push(new __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.rspack.BannerPlugin({
1234
1305
  banner: bannerConfig.js,
1235
- stage: core_namespaceObject.rspack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE + 1,
1306
+ stage: __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.rspack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE + 1,
1236
1307
  raw: true,
1237
1308
  include: /\.(js|mjs|cjs)$/
1238
1309
  }));
1239
- if (bannerConfig.css) plugins.push(new core_namespaceObject.rspack.BannerPlugin({
1310
+ if (bannerConfig.css) plugins.push(new __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.rspack.BannerPlugin({
1240
1311
  banner: bannerConfig.css,
1241
- stage: core_namespaceObject.rspack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE + 1,
1312
+ stage: __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.rspack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE + 1,
1242
1313
  raw: true,
1243
1314
  include: /\.(css)$/
1244
1315
  }));
1245
1316
  }
1246
1317
  if (!isEmptyObject(footerConfig)) {
1247
- if (footerConfig.js) plugins.push(new core_namespaceObject.rspack.BannerPlugin({
1318
+ if (footerConfig.js) plugins.push(new __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.rspack.BannerPlugin({
1248
1319
  banner: footerConfig.js,
1249
- stage: core_namespaceObject.rspack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE + 1,
1320
+ stage: __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.rspack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE + 1,
1250
1321
  raw: true,
1251
1322
  footer: true,
1252
1323
  include: /\.(js|mjs|cjs)$/
1253
1324
  }));
1254
- if (footerConfig.css) plugins.push(new core_namespaceObject.rspack.BannerPlugin({
1325
+ if (footerConfig.css) plugins.push(new __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.rspack.BannerPlugin({
1255
1326
  banner: footerConfig.css,
1256
- stage: core_namespaceObject.rspack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE + 1,
1327
+ stage: __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.rspack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE + 1,
1257
1328
  raw: true,
1258
1329
  footer: true,
1259
1330
  include: /\.(css)$/
@@ -1278,7 +1349,7 @@ function composeDecoratorsConfig(compilerOptions, version) {
1278
1349
  };
1279
1350
  }
1280
1351
  async function createConstantRsbuildConfig() {
1281
- return (0, core_namespaceObject.defineConfig)({
1352
+ return (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.defineConfig)({
1282
1353
  mode: 'production',
1283
1354
  dev: {
1284
1355
  progressBar: false
@@ -1362,8 +1433,18 @@ const composeFormatConfig = (format)=>{
1362
1433
  };
1363
1434
  case 'cjs':
1364
1435
  return {
1436
+ plugins: [
1437
+ pluginCjsShim()
1438
+ ],
1365
1439
  tools: {
1366
1440
  rspack: {
1441
+ module: {
1442
+ parser: {
1443
+ javascript: {
1444
+ importMeta: false
1445
+ }
1446
+ }
1447
+ },
1367
1448
  output: {
1368
1449
  iife: false,
1369
1450
  chunkFormat: 'commonjs',
@@ -1378,6 +1459,13 @@ const composeFormatConfig = (format)=>{
1378
1459
  return {
1379
1460
  tools: {
1380
1461
  rspack: {
1462
+ module: {
1463
+ parser: {
1464
+ javascript: {
1465
+ importMeta: false
1466
+ }
1467
+ }
1468
+ },
1381
1469
  output: {
1382
1470
  library: {
1383
1471
  type: 'umd'
@@ -1390,7 +1478,7 @@ const composeFormatConfig = (format)=>{
1390
1478
  throw new Error(`Unsupported format: ${format}`);
1391
1479
  }
1392
1480
  };
1393
- const composeModuleImportWarn = (request)=>`The externalized commonjs request ${picocolors_index_js_namespaceObject["default"].green(`"${request}"`)} will use ${picocolors_index_js_namespaceObject["default"].blue('"module"')} external type in ESM format. If you want to specify other external type, considering set the request and type with ${picocolors_index_js_namespaceObject["default"].blue('"output.externals"')}.`;
1481
+ const composeModuleImportWarn = (request)=>`The externalized commonjs request ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js__["default"].green(`"${request}"`)} will use ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js__["default"].blue('"module"')} external type in ESM format. If you want to specify other external type, considering set the request and type with ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js__["default"].blue('"output.externals"')}.`;
1394
1482
  const composeExternalsConfig = (format, externals)=>{
1395
1483
  // TODO: Define the internal externals config in Rsbuild's externals instead
1396
1484
  // Rspack's externals as they will not be merged from different fields. All externals
@@ -1442,13 +1530,7 @@ const composeSyntaxConfig = (syntax, target)=>{
1442
1530
  if (syntax) return {
1443
1531
  tools: {
1444
1532
  rspack: (config)=>{
1445
- // TODO: Rspack should could resolve `browserslist:{query}` like webpack.
1446
- // https://webpack.js.org/configuration/target/#browserslist
1447
- // Using 'es5' as a temporary solution for compatibility.
1448
- config.target = [
1449
- 'es5'
1450
- ];
1451
- return config;
1533
+ config.target = transformSyntaxToRspackTarget(syntax);
1452
1534
  }
1453
1535
  },
1454
1536
  output: {
@@ -1490,18 +1572,20 @@ const composeEntryConfig = async (entries, bundle, root)=>{
1490
1572
  ] : null;
1491
1573
  if (!entryFiles) throw new Error('Entry can only be a string or an array of strings for now');
1492
1574
  // Turn entries in array into each separate entry.
1493
- const resolvedEntryFiles = await (0, fast_glob_index_js_namespaceObject["default"])(entryFiles, {
1575
+ const globEntryFiles = await (0, __WEBPACK_EXTERNAL_MODULE__compiled_fast_glob_index_js__["default"])(entryFiles, {
1494
1576
  cwd: root
1495
1577
  });
1578
+ // Filter the glob resolved entry files based on the allowed extensions
1579
+ const resolvedEntryFiles = globEntryFiles.filter((file)=>ENTRY_EXTENSIONS_PATTERN.test(file));
1496
1580
  if (0 === resolvedEntryFiles.length) throw new Error(`Cannot find ${resolvedEntryFiles}`);
1497
1581
  // Similar to `rootDir` in tsconfig and `outbase` in esbuild.
1498
1582
  const lcp = await calcLongestCommonPath(resolvedEntryFiles);
1499
1583
  // Using the longest common path of all non-declaration input files by default.
1500
1584
  const outBase = null === lcp ? root : lcp;
1501
1585
  for (const file of resolvedEntryFiles){
1502
- const { dir, name } = external_node_path_namespaceObject["default"].parse(external_node_path_namespaceObject["default"].relative(outBase, file));
1586
+ const { dir, name } = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].parse(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].relative(outBase, file));
1503
1587
  // Entry filename contains nested path to preserve source directory structure.
1504
- const entryFileName = external_node_path_namespaceObject["default"].join(dir, name);
1588
+ const entryFileName = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(dir, name);
1505
1589
  resolvedEntries[entryFileName] = file;
1506
1590
  }
1507
1591
  }
@@ -1527,7 +1611,13 @@ const composeBundleConfig = (jsExtension, bundle = true)=>{
1527
1611
  // This may result in a change in semantics,
1528
1612
  // user should use copy to keep origin file or use another separate entry to deal this
1529
1613
  let request = data.request;
1530
- if ('.' === request[0]) request = (0, external_node_path_namespaceObject.extname)(request) ? request.replace(/\.[^.]+$/, jsExtension) : `${request}${jsExtension}`;
1614
+ if ('.' === request[0]) {
1615
+ if ((0, __WEBPACK_EXTERNAL_MODULE_node_path__.extname)(request)) {
1616
+ if (!JS_EXTENSIONS_PATTERN.test(request)) // If it does not match jsExtensionsPattern, we should do nothing, eg: ./foo.png
1617
+ return callback();
1618
+ request = request.replace(/\.[^.]+$/, jsExtension);
1619
+ } else request = `${request}${jsExtension}`;
1620
+ }
1531
1621
  return callback(null, request);
1532
1622
  }
1533
1623
  callback();
@@ -1562,7 +1652,12 @@ const composeTargetConfig = (target = 'web')=>{
1562
1652
  rspack: {
1563
1653
  target: [
1564
1654
  'web'
1565
- ]
1655
+ ],
1656
+ output: {
1657
+ chunkLoading: 'import',
1658
+ workerChunkLoading: 'import',
1659
+ wasmLoading: 'fetch'
1660
+ }
1566
1661
  }
1567
1662
  }
1568
1663
  };
@@ -1572,12 +1667,17 @@ const composeTargetConfig = (target = 'web')=>{
1572
1667
  rspack: {
1573
1668
  target: [
1574
1669
  'node'
1575
- ]
1670
+ ],
1671
+ // "__dirname" and "__filename" shims will automatically be enabled when `output.module` is `true`,
1672
+ // and leave them as-is in the rest of the cases.
1673
+ // { node: { __dirname: ..., __filename: ... } }
1674
+ output: {
1675
+ chunkLoading: 'require',
1676
+ workerChunkLoading: 'async-node',
1677
+ wasmLoading: 'async-node'
1678
+ }
1576
1679
  }
1577
1680
  },
1578
- // "__dirname" and "__filename" shims will automatically be enabled when `output.module` is `true`,
1579
- // and leave them as-is in the rest of the cases.
1580
- // { node: { __dirname: ..., __filename: ... } }
1581
1681
  output: {
1582
1682
  // When output.target is 'node', Node.js's built-in will be treated as externals of type `node-commonjs`.
1583
1683
  // Simply override the built-in modules to make them external.
@@ -1615,7 +1715,7 @@ const composeExternalHelpersConfig = (externalHelpers, pkgJson)=>{
1615
1715
  ...Object.keys(pkgJson?.devDependencies ?? [])
1616
1716
  ];
1617
1717
  if (!deps.includes(SWC_HELPERS)) {
1618
- index_js_namespaceObject.logger.error(`${picocolors_index_js_namespaceObject["default"].green('externalHelpers')} is enabled, but the ${picocolors_index_js_namespaceObject["default"].blue(SWC_HELPERS)} dependency declaration was not found in package.json.`);
1718
+ __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.error(`${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js__["default"].green('externalHelpers')} is enabled, but the ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js__["default"].blue(SWC_HELPERS)} dependency declaration was not found in package.json.`);
1619
1719
  process.exit(1);
1620
1720
  }
1621
1721
  defaultConfig = Object.assign(defaultConfig, {
@@ -1628,7 +1728,7 @@ const composeExternalHelpersConfig = (externalHelpers, pkgJson)=>{
1628
1728
  return defaultConfig;
1629
1729
  };
1630
1730
  async function composeLibRsbuildConfig(config, configPath) {
1631
- const rootPath = (0, external_node_path_namespaceObject.dirname)(configPath);
1731
+ const rootPath = (0, __WEBPACK_EXTERNAL_MODULE_node_path__.dirname)(configPath);
1632
1732
  const pkgJson = readPackageJson(rootPath);
1633
1733
  const { compilerOptions } = await loadTsconfig(rootPath, config.source?.tsconfigPath);
1634
1734
  const { format, banner = {}, footer = {}, autoExtension = true, autoExternal = true, externalHelpers = false } = config;
@@ -1644,13 +1744,13 @@ async function composeLibRsbuildConfig(config, configPath) {
1644
1744
  pkgJson,
1645
1745
  userExternals: config.output?.externals
1646
1746
  });
1647
- const entryConfig = await composeEntryConfig(config.source?.entry, config.bundle, (0, external_node_path_namespaceObject.dirname)(configPath));
1747
+ const entryConfig = await composeEntryConfig(config.source?.entry, config.bundle, (0, __WEBPACK_EXTERNAL_MODULE_node_path__.dirname)(configPath));
1648
1748
  const dtsConfig = await composeDtsConfig(config, dtsExtension);
1649
1749
  const externalsWarnConfig = composeExternalsWarnConfig(format, autoExternalConfig?.output?.externals, externalsConfig?.output?.externals);
1650
1750
  const minifyConfig = composeMinifyConfig(config.output?.minify);
1651
1751
  const bannerFooterConfig = composeBannerFooterConfig(banner, footer);
1652
1752
  const decoratorsConfig = composeDecoratorsConfig(compilerOptions, config.source?.decorators?.version);
1653
- return (0, core_namespaceObject.mergeRsbuildConfig)(formatConfig, externalHelpersConfig, externalsWarnConfig, externalsConfig, autoExternalConfig, autoExtensionConfig, syntaxConfig, bundleConfig, targetConfig, entryConfig, minifyConfig, dtsConfig, bannerFooterConfig, decoratorsConfig);
1753
+ return (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.mergeRsbuildConfig)(formatConfig, externalHelpersConfig, externalsWarnConfig, externalsConfig, autoExternalConfig, autoExtensionConfig, syntaxConfig, bundleConfig, targetConfig, entryConfig, minifyConfig, dtsConfig, bannerFooterConfig, decoratorsConfig);
1654
1754
  }
1655
1755
  async function composeCreateRsbuildConfig(rslibConfig, path) {
1656
1756
  const constantRsbuildConfig = await createConstantRsbuildConfig();
@@ -1658,7 +1758,7 @@ async function composeCreateRsbuildConfig(rslibConfig, path) {
1658
1758
  const { lib: libConfigsArray, ...sharedRsbuildConfig } = rslibConfig;
1659
1759
  if (!libConfigsArray) throw new Error(`Expect lib field to be an array, but got ${libConfigsArray}.`);
1660
1760
  const libConfigPromises = libConfigsArray.map(async (libConfig)=>{
1661
- const userConfig = (0, core_namespaceObject.mergeRsbuildConfig)(sharedRsbuildConfig, libConfig);
1761
+ const userConfig = (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.mergeRsbuildConfig)(sharedRsbuildConfig, libConfig);
1662
1762
  // Merge the configuration of each environment based on the shared Rsbuild
1663
1763
  // configuration and Lib configuration in the settings.
1664
1764
  const libRsbuildConfig = await composeLibRsbuildConfig(userConfig, configPath);
@@ -1680,7 +1780,7 @@ async function composeCreateRsbuildConfig(rslibConfig, path) {
1680
1780
  // We should state in the document that the built-in configuration should not be changed optionally
1681
1781
  // In compose process of 2, we may read some config from 1, and reassemble the related config,
1682
1782
  // so before final mergeRsbuildConfig, we reset some specified fields
1683
- config: (0, core_namespaceObject.mergeRsbuildConfig)(constantRsbuildConfig, libRsbuildConfig, omit(userConfig, [
1783
+ config: (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.mergeRsbuildConfig)(constantRsbuildConfig, libRsbuildConfig, omit(userConfig, [
1684
1784
  'bundle',
1685
1785
  'format',
1686
1786
  'autoExtension',
@@ -1713,7 +1813,7 @@ async function initRsbuild(rslibConfig) {
1713
1813
  const currentFormatIndex = formatIndex[format]++;
1714
1814
  environments[1 === currentFormatCount ? format : `${format}${currentFormatIndex}`] = config;
1715
1815
  }
1716
- return (0, core_namespaceObject.createRsbuild)({
1816
+ return (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.createRsbuild)({
1717
1817
  rsbuildConfig: {
1718
1818
  environments
1719
1819
  }
@@ -1730,9 +1830,9 @@ const applyCommonOptions = (command)=>{
1730
1830
  command.option('-c --config <config>', 'specify the configuration file, can be a relative or absolute path').option('--env-mode <mode>', 'specify the env mode to load the `.env.[mode]` file');
1731
1831
  };
1732
1832
  function runCli() {
1733
- commander_index_js_namespaceObject.program.name('rslib').usage('<command> [options]').version("0.0.6");
1734
- const buildCommand = commander_index_js_namespaceObject.program.command('build');
1735
- const inspectCommand = commander_index_js_namespaceObject.program.command('inspect');
1833
+ __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.name('rslib').usage('<command> [options]').version("0.0.8");
1834
+ const buildCommand = __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.command('build');
1835
+ const inspectCommand = __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.command('inspect');
1736
1836
  [
1737
1837
  buildCommand,
1738
1838
  inspectCommand
@@ -1745,8 +1845,8 @@ function runCli() {
1745
1845
  });
1746
1846
  await build(rslibConfig, options);
1747
1847
  } catch (err) {
1748
- index_js_namespaceObject.logger.error('Failed to build.');
1749
- index_js_namespaceObject.logger.error(err);
1848
+ __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.error('Failed to build.');
1849
+ __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.error(err);
1750
1850
  process.exit(1);
1751
1851
  }
1752
1852
  });
@@ -1765,13 +1865,13 @@ function runCli() {
1765
1865
  writeToDisk: true
1766
1866
  });
1767
1867
  } catch (err) {
1768
- index_js_namespaceObject.logger.error('Failed to inspect config.');
1769
- index_js_namespaceObject.logger.error(err);
1868
+ __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.error('Failed to inspect config.');
1869
+ __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.error(err);
1770
1870
  process.exit(1);
1771
1871
  }
1772
1872
  });
1773
- commander_index_js_namespaceObject.program.parse();
1873
+ __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.parse();
1774
1874
  }
1775
- const src_version = "0.0.6";
1776
- var __webpack_exports__logger = index_js_namespaceObject.logger;
1875
+ const src_version = "0.0.8";
1876
+ var __webpack_exports__logger = __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger;
1777
1877
  export { build, defineConfig, loadConfig, prepareCli, runCli, src_version as version, __webpack_exports__logger as logger };
@@ -1,3 +1,8 @@
1
1
  export declare const DEFAULT_CONFIG_NAME = "rslib.config";
2
- export declare const DEFAULT_EXTENSIONS: readonly [".js", ".ts", ".mjs", ".mts", ".cjs", ".cts"];
2
+ export declare const DEFAULT_CONFIG_EXTENSIONS: readonly [".js", ".ts", ".mjs", ".mts", ".cjs", ".cts"];
3
3
  export declare const SWC_HELPERS = "@swc/helpers";
4
+ export declare const JS_EXTENSIONS: string[];
5
+ export declare const CSS_EXTENSIONS: string[];
6
+ export declare const ENTRY_EXTENSIONS: string[];
7
+ export declare const JS_EXTENSIONS_PATTERN: RegExp;
8
+ export declare const ENTRY_EXTENSIONS_PATTERN: RegExp;
@@ -0,0 +1,2 @@
1
+ import { type RsbuildPlugin } from '@rsbuild/core';
2
+ export declare const pluginCjsShim: () => RsbuildPlugin;
@@ -1,4 +1,4 @@
1
- import type { RsbuildConfig } from '@rsbuild/core';
1
+ import type { RsbuildConfig, Rspack } from '@rsbuild/core';
2
2
  import type { FixedEcmaVersions, LatestEcmaVersions, RsbuildConfigOutputTarget, Syntax } from '../types/config';
3
3
  export declare const LATEST_TARGET_VERSIONS: Record<NonNullable<RsbuildConfigOutputTarget>, string[]>;
4
4
  /**
@@ -9,4 +9,5 @@ export declare const LATEST_TARGET_VERSIONS: Record<NonNullable<RsbuildConfigOut
9
9
  * TODO: align with Rsbuild, we may should align with SWC
10
10
  */
11
11
  export declare const ESX_TO_BROWSERSLIST: Record<FixedEcmaVersions, Record<string, string | string[]>> & Record<LatestEcmaVersions, (target: RsbuildConfigOutputTarget) => string[]>;
12
+ export declare function transformSyntaxToRspackTarget(syntax: Syntax): Rspack.Configuration['target'];
12
13
  export declare function transformSyntaxToBrowserslist(syntax: Syntax, target?: NonNullable<RsbuildConfig['output']>['target']): NonNullable<NonNullable<RsbuildConfig['output']>['overrideBrowserslist']>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rslib/core",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "The Rspack-based library build tool.",
5
5
  "homepage": "https://lib.rsbuild.dev",
6
6
  "bugs": {
@@ -32,18 +32,18 @@
32
32
  "compiled"
33
33
  ],
34
34
  "dependencies": {
35
- "@rsbuild/core": "1.0.3",
36
- "rsbuild-plugin-dts": "0.0.6"
35
+ "@rsbuild/core": "1.0.7",
36
+ "rsbuild-plugin-dts": "0.0.8"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/fs-extra": "^11.0.4",
40
40
  "commander": "^12.1.0",
41
41
  "fast-glob": "^3.3.2",
42
42
  "fs-extra": "^11.2.0",
43
- "memfs": "^4.11.1",
43
+ "memfs": "^4.12.0",
44
44
  "picocolors": "1.1.0",
45
45
  "prebundle": "1.2.2",
46
- "rslib": "npm:@rslib/core@0.0.5",
46
+ "rslib": "npm:@rslib/core@0.0.7",
47
47
  "rslog": "^1.2.3",
48
48
  "tsconfck": "3.1.3",
49
49
  "typescript": "^5.6.2",