@rslib/core 0.0.7 → 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
@@ -133,7 +133,7 @@ function prepareCli() {
133
133
  // Some package managers automatically output a blank line, some do not.
134
134
  const { npm_execpath } = process.env;
135
135
  if (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) console.log();
136
- __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.greet(` Rslib v0.0.7\n`);
136
+ __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.greet(` Rslib v0.0.8\n`);
137
137
  }
138
138
  const DEFAULT_CONFIG_NAME = 'rslib.config';
139
139
  const DEFAULT_CONFIG_EXTENSIONS = [
@@ -185,8 +185,7 @@ const importMetaUrlShim = `var __rslib_import_meta_url__ = /*#__PURE__*/ (functi
185
185
  const pluginCjsShim = ()=>({
186
186
  name: 'rsbuild-plugin-cjs-shim',
187
187
  setup (api) {
188
- api.modifyRsbuildConfig((config)=>{
189
- config.source ||= {};
188
+ api.modifyEnvironmentConfig((config)=>{
190
189
  config.source.define = {
191
190
  ...config.source.define,
192
191
  'import.meta.url': '__rslib_import_meta_url__'
@@ -259,6 +258,11 @@ const calcEsnextBrowserslistByTarget = (target)=>{
259
258
  if ('node' === target) return LATEST_TARGET_VERSIONS.node;
260
259
  return LATEST_TARGET_VERSIONS.web;
261
260
  };
261
+ const RSPACK_TARGET_UNLISTED_MODERN_ECMA_VERSIONS = [
262
+ 'es2023',
263
+ 'es2024',
264
+ 'esnext'
265
+ ];
262
266
  /**
263
267
  * The esX to browserslist mapping is transformed from esbuild:
264
268
  * https://github.com/evanw/esbuild/blob/main/internal/compat/js_table.go
@@ -376,6 +380,25 @@ const calcEsnextBrowserslistByTarget = (target)=>{
376
380
  Safari: '3.1.0'
377
381
  }
378
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
+ }
379
402
  function transformSyntaxToBrowserslist(syntax, target) {
380
403
  const handleSyntaxItem = (syntaxItem)=>{
381
404
  const normalizedSyntaxItem = syntaxItem.toLowerCase();
@@ -1110,10 +1133,7 @@ async function loadTsconfig(root, tsconfigPath = 'tsconfig.json') {
1110
1133
  }
1111
1134
  return {};
1112
1135
  }
1113
- /**
1114
- * This function helps you to autocomplete configuration types.
1115
- * It accepts a Rslib config object, or a function that returns a config.
1116
- */ function defineConfig(config) {
1136
+ function defineConfig(config) {
1117
1137
  return config;
1118
1138
  }
1119
1139
  const findConfig = (basePath)=>DEFAULT_CONFIG_EXTENSIONS.map((ext)=>basePath + ext).find(__WEBPACK_EXTERNAL_MODULE_node_fs__["default"].existsSync);
@@ -1507,19 +1527,16 @@ const composeAutoExtensionConfig = (config, autoExtension, pkgJson)=>{
1507
1527
  };
1508
1528
  const composeSyntaxConfig = (syntax, target)=>{
1509
1529
  // Defaults to ESNext, Rslib will assume all of the latest JavaScript and CSS features are supported.
1510
- if (syntax) {
1511
- const resolvedBrowserslist = transformSyntaxToBrowserslist(syntax, target);
1512
- return {
1513
- tools: {
1514
- rspack: (config)=>{
1515
- config.target = resolvedBrowserslist.map((item)=>`browserslist:${item}`);
1516
- }
1517
- },
1518
- output: {
1519
- overrideBrowserslist: resolvedBrowserslist
1530
+ if (syntax) return {
1531
+ tools: {
1532
+ rspack: (config)=>{
1533
+ config.target = transformSyntaxToRspackTarget(syntax);
1520
1534
  }
1521
- };
1522
- }
1535
+ },
1536
+ output: {
1537
+ overrideBrowserslist: transformSyntaxToBrowserslist(syntax, target)
1538
+ }
1539
+ };
1523
1540
  return {
1524
1541
  tools: {
1525
1542
  rspack: (config)=>{
@@ -1813,7 +1830,7 @@ const applyCommonOptions = (command)=>{
1813
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');
1814
1831
  };
1815
1832
  function runCli() {
1816
- __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.name('rslib').usage('<command> [options]').version("0.0.7");
1833
+ __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.name('rslib').usage('<command> [options]').version("0.0.8");
1817
1834
  const buildCommand = __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.command('build');
1818
1835
  const inspectCommand = __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.command('inspect');
1819
1836
  [
@@ -1855,6 +1872,6 @@ function runCli() {
1855
1872
  });
1856
1873
  __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.parse();
1857
1874
  }
1858
- const src_version = "0.0.7";
1875
+ const src_version = "0.0.8";
1859
1876
  var __webpack_exports__logger = __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger;
1860
1877
  export { build, defineConfig, loadConfig, prepareCli, runCli, src_version as version, __webpack_exports__logger as logger };
@@ -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.7",
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,8 +32,8 @@
32
32
  "compiled"
33
33
  ],
34
34
  "dependencies": {
35
- "@rsbuild/core": "1.0.5",
36
- "rsbuild-plugin-dts": "0.0.7"
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",
@@ -43,7 +43,7 @@
43
43
  "memfs": "^4.12.0",
44
44
  "picocolors": "1.1.0",
45
45
  "prebundle": "1.2.2",
46
- "rslib": "npm:@rslib/core@0.0.6",
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",