@rslib/core 0.0.7 → 0.0.9

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.9\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);
@@ -1383,27 +1403,36 @@ async function createConstantRsbuildConfig() {
1383
1403
  });
1384
1404
  }
1385
1405
  const composeFormatConfig = (format)=>{
1406
+ const jsParserOptions = {
1407
+ importMeta: false,
1408
+ requireResolve: false,
1409
+ requireDynamic: false,
1410
+ requireAsExpression: false,
1411
+ importDynamic: false
1412
+ };
1386
1413
  switch(format){
1387
1414
  case 'esm':
1388
1415
  return {
1389
1416
  tools: {
1390
1417
  rspack: {
1391
- output: {
1392
- module: true,
1393
- chunkFormat: 'module',
1394
- library: {
1395
- type: 'modern-module'
1396
- }
1397
- },
1398
1418
  module: {
1399
1419
  parser: {
1400
- javascript: {
1401
- importMeta: false
1402
- }
1420
+ javascript: jsParserOptions
1403
1421
  }
1404
1422
  },
1405
1423
  optimization: {
1406
- concatenateModules: true
1424
+ concatenateModules: true,
1425
+ sideEffects: 'flag'
1426
+ },
1427
+ output: {
1428
+ module: true,
1429
+ chunkFormat: 'module',
1430
+ library: {
1431
+ type: 'modern-module'
1432
+ },
1433
+ chunkLoading: 'import',
1434
+ workerChunkLoading: 'import',
1435
+ wasmLoading: 'fetch'
1407
1436
  },
1408
1437
  experiments: {
1409
1438
  outputModule: true
@@ -1420,9 +1449,7 @@ const composeFormatConfig = (format)=>{
1420
1449
  rspack: {
1421
1450
  module: {
1422
1451
  parser: {
1423
- javascript: {
1424
- importMeta: false
1425
- }
1452
+ javascript: jsParserOptions
1426
1453
  }
1427
1454
  },
1428
1455
  output: {
@@ -1430,7 +1457,10 @@ const composeFormatConfig = (format)=>{
1430
1457
  chunkFormat: 'commonjs',
1431
1458
  library: {
1432
1459
  type: 'commonjs'
1433
- }
1460
+ },
1461
+ chunkLoading: 'require',
1462
+ workerChunkLoading: 'async-node',
1463
+ wasmLoading: 'async-node'
1434
1464
  }
1435
1465
  }
1436
1466
  }
@@ -1507,19 +1537,16 @@ const composeAutoExtensionConfig = (config, autoExtension, pkgJson)=>{
1507
1537
  };
1508
1538
  const composeSyntaxConfig = (syntax, target)=>{
1509
1539
  // 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
1540
+ if (syntax) return {
1541
+ tools: {
1542
+ rspack: (config)=>{
1543
+ config.target = transformSyntaxToRspackTarget(syntax);
1520
1544
  }
1521
- };
1522
- }
1545
+ },
1546
+ output: {
1547
+ overrideBrowserslist: transformSyntaxToBrowserslist(syntax, target)
1548
+ }
1549
+ };
1523
1550
  return {
1524
1551
  tools: {
1525
1552
  rspack: (config)=>{
@@ -1635,12 +1662,7 @@ const composeTargetConfig = (target = 'web')=>{
1635
1662
  rspack: {
1636
1663
  target: [
1637
1664
  'web'
1638
- ],
1639
- output: {
1640
- chunkLoading: 'import',
1641
- workerChunkLoading: 'import',
1642
- wasmLoading: 'fetch'
1643
- }
1665
+ ]
1644
1666
  }
1645
1667
  }
1646
1668
  };
@@ -1650,15 +1672,7 @@ const composeTargetConfig = (target = 'web')=>{
1650
1672
  rspack: {
1651
1673
  target: [
1652
1674
  'node'
1653
- ],
1654
- // "__dirname" and "__filename" shims will automatically be enabled when `output.module` is `true`,
1655
- // and leave them as-is in the rest of the cases.
1656
- // { node: { __dirname: ..., __filename: ... } }
1657
- output: {
1658
- chunkLoading: 'require',
1659
- workerChunkLoading: 'async-node',
1660
- wasmLoading: 'async-node'
1661
- }
1675
+ ]
1662
1676
  }
1663
1677
  },
1664
1678
  output: {
@@ -1813,7 +1827,7 @@ const applyCommonOptions = (command)=>{
1813
1827
  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
1828
  };
1815
1829
  function runCli() {
1816
- __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.name('rslib').usage('<command> [options]').version("0.0.7");
1830
+ __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.name('rslib').usage('<command> [options]').version("0.0.9");
1817
1831
  const buildCommand = __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.command('build');
1818
1832
  const inspectCommand = __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.command('inspect');
1819
1833
  [
@@ -1855,6 +1869,6 @@ function runCli() {
1855
1869
  });
1856
1870
  __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.parse();
1857
1871
  }
1858
- const src_version = "0.0.7";
1872
+ const src_version = "0.0.9";
1859
1873
  var __webpack_exports__logger = __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger;
1860
1874
  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.9",
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.5",
36
- "rsbuild-plugin-dts": "0.0.7"
35
+ "@rsbuild/core": "1.0.10",
36
+ "rsbuild-plugin-dts": "0.0.9"
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.12.0",
43
+ "memfs": "^4.13.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.8",
47
47
  "rslog": "^1.2.3",
48
48
  "tsconfck": "3.1.3",
49
49
  "typescript": "^5.6.2",