@rslib/core 0.12.3 → 0.13.0

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
@@ -18,7 +18,6 @@ const DEFAULT_CONFIG_EXTENSIONS = [
18
18
  '.cts'
19
19
  ];
20
20
  const SWC_HELPERS = '@swc/helpers';
21
- const SHEBANG_PREFIX = '#!';
22
21
  const SHEBANG_REGEX = /#!.*[\s\n\r]*$/;
23
22
  const REACT_DIRECTIVE_REGEX = /^['"]use (client|server)['"](;?)[\s\n\r]*$/;
24
23
  const DTS_EXTENSIONS = [
@@ -395,7 +394,7 @@ class EntryChunkPlugin {
395
394
  const content = compiler.inputFileSystem.readFileSync(filename, {
396
395
  encoding: 'utf-8'
397
396
  });
398
- if (content.startsWith(SHEBANG_PREFIX)) {
397
+ if (content.startsWith("#!")) {
399
398
  const shebangMatch = matchFirstLine(content, SHEBANG_REGEX);
400
399
  if (shebangMatch) this.shebangEntries[name] = shebangMatch;
401
400
  }
@@ -696,6 +695,14 @@ const windowsSlashRegex = /\\/g;
696
695
  function normalizeSlash(p) {
697
696
  return p.replace(windowsSlashRegex, '/');
698
697
  }
698
+ async function isDirectory(filePath) {
699
+ try {
700
+ const stat = await node_fs_promises.stat(filePath);
701
+ return stat.isDirectory();
702
+ } catch {
703
+ return false;
704
+ }
705
+ }
699
706
  const LATEST_TARGET_VERSIONS = {
700
707
  node: [
701
708
  'last 1 node versions'
@@ -1775,7 +1782,10 @@ const composeFormatConfig = ({ format, bundle = true, umdName, pkgJson })=>{
1775
1782
  }
1776
1783
  },
1777
1784
  optimization: {
1778
- nodeEnv: process.env.NODE_ENV
1785
+ nodeEnv: process.env.NODE_ENV,
1786
+ splitChunks: {
1787
+ chunks: 'async'
1788
+ }
1779
1789
  },
1780
1790
  plugins
1781
1791
  }
@@ -1858,6 +1868,14 @@ const disableUrlParseRsbuildPlugin = ()=>({
1858
1868
  });
1859
1869
  }
1860
1870
  });
1871
+ const fixJsModuleTypePlugin = ()=>({
1872
+ name: 'rsbuild:fix-js-module-type',
1873
+ setup (api) {
1874
+ api.modifyBundlerChain((config, { CHAIN_ID })=>{
1875
+ config.module.rule(CHAIN_ID.RULE.JS).delete('type');
1876
+ });
1877
+ }
1878
+ });
1861
1879
  const composeShimsConfig = (format, shims)=>{
1862
1880
  const resolvedShims = {
1863
1881
  cjs: {
@@ -1893,7 +1911,8 @@ const composeShimsConfig = (format, shims)=>{
1893
1911
  },
1894
1912
  plugins: [
1895
1913
  resolvedShims.esm.require && pluginEsmRequireShim(),
1896
- disableUrlParseRsbuildPlugin()
1914
+ disableUrlParseRsbuildPlugin(),
1915
+ fixJsModuleTypePlugin()
1897
1916
  ].filter(Boolean)
1898
1917
  };
1899
1918
  break;
@@ -1901,13 +1920,19 @@ const composeShimsConfig = (format, shims)=>{
1901
1920
  rsbuildConfig = {
1902
1921
  plugins: [
1903
1922
  resolvedShims.cjs['import.meta.url'] && pluginCjsImportMetaUrlShim(),
1904
- disableUrlParseRsbuildPlugin()
1923
+ disableUrlParseRsbuildPlugin(),
1924
+ fixJsModuleTypePlugin()
1905
1925
  ].filter(Boolean)
1906
1926
  };
1907
1927
  break;
1908
1928
  case 'umd':
1909
1929
  case 'iife':
1910
1930
  case 'mf':
1931
+ rsbuildConfig = {
1932
+ plugins: [
1933
+ fixJsModuleTypePlugin()
1934
+ ]
1935
+ };
1911
1936
  break;
1912
1937
  default:
1913
1938
  throw new Error(`Unsupported format: ${format}`);
@@ -2075,7 +2100,8 @@ const composeEntryConfig = async (rawEntry, bundle, root, cssModulesAuto, userOu
2075
2100
  if (!entryFiles) throw new Error('Entry can only be a string or an array of strings for now');
2076
2101
  const globEntryFiles = await glob(entryFiles, {
2077
2102
  cwd: root,
2078
- absolute: true
2103
+ absolute: true,
2104
+ dot: true
2079
2105
  });
2080
2106
  const resolvedEntryFiles = globEntryFiles.filter((i)=>!DTS_EXTENSIONS_PATTERN.test(i));
2081
2107
  if (0 === resolvedEntryFiles.length) throw new Error(`Cannot find ${resolvedEntryFiles}`);
@@ -2152,7 +2178,7 @@ const composeBundlelessExternalConfig = (jsExtension, redirect, cssModulesAuto,
2152
2178
  const isSubpath = normalizeSlash(resolvedRequest).startsWith(`${normalizeSlash(outBase)}/`);
2153
2179
  if (isSubpath) {
2154
2180
  resolvedRequest = normalizeSlash(node_path.relative(node_path.dirname(issuer), resolvedRequest));
2155
- if ('.' !== resolvedRequest[0]) resolvedRequest = `./${resolvedRequest}`;
2181
+ if (!resolvedRequest.startsWith('./') && !resolvedRequest.startsWith('../')) resolvedRequest = `./${resolvedRequest}`;
2156
2182
  return resolvedRequest;
2157
2183
  }
2158
2184
  return;
@@ -2176,7 +2202,10 @@ const composeBundlelessExternalConfig = (jsExtension, redirect, cssModulesAuto,
2176
2202
  resolvedRequest = assetRedirectPath ? redirectedPath : request;
2177
2203
  if (assetRedirectExtension) resolvedRequest = resolvedRequest.replace(/\.[^.]+$/, jsExtension);
2178
2204
  }
2179
- else if (jsRedirectExtension) resolvedRequest = `${resolvedRequest}${jsExtension}`;
2205
+ else if (jsRedirectExtension) {
2206
+ if (!jsRedirectPath && await isDirectory(join(dirname(issuer), resolvedRequest))) resolvedRequest = `${resolvedRequest.replace(/\/+$/, '')}/index`;
2207
+ resolvedRequest = `${resolvedRequest}${jsExtension}`;
2208
+ }
2180
2209
  }
2181
2210
  callback(void 0, resolvedRequest);
2182
2211
  return;
@@ -2208,7 +2237,8 @@ const composeDtsConfig = async (libConfig, format, dtsExtension)=>{
2208
2237
  alias: dts?.alias,
2209
2238
  banner: banner?.dts,
2210
2239
  footer: footer?.dts,
2211
- redirect: redirect?.dts
2240
+ redirect: redirect?.dts,
2241
+ tsgo: dts?.tsgo
2212
2242
  })
2213
2243
  ]
2214
2244
  };
@@ -3031,7 +3061,7 @@ const applyCommonOptions = (cli)=>{
3031
3061
  function runCli() {
3032
3062
  const cli = dist('rslib');
3033
3063
  cli.help();
3034
- cli.version("0.12.3");
3064
+ cli.version("0.13.0");
3035
3065
  applyCommonOptions(cli);
3036
3066
  const buildCommand = cli.command('build', 'build the library for production');
3037
3067
  const inspectCommand = cli.command('inspect', 'inspect the Rsbuild / Rspack configs of Rslib projects');
@@ -3102,8 +3132,8 @@ function prepareCli() {
3102
3132
  initNodeEnv();
3103
3133
  const { npm_execpath } = process.env;
3104
3134
  if (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) console.log();
3105
- logger.greet(` Rslib v0.12.3\n`);
3135
+ logger.greet(` Rslib v0.13.0\n`);
3106
3136
  }
3107
- const src_version = "0.12.3";
3137
+ const src_version = "0.13.0";
3108
3138
  var __webpack_exports__rspack = __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.rspack;
3109
3139
  export { build, defineConfig, inspect, loadConfig, logger, prepareCli, __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__ as rsbuild, runCli, startMFDevServer, composeCreateRsbuildConfig as unstable_composeCreateRsbuildConfig, src_version as version, __webpack_exports__rspack as rspack };
@@ -58,6 +58,13 @@ export type Dts = {
58
58
  * @see {@link https://rslib.rs/config/lib/dts#dtsalias}
59
59
  */
60
60
  alias?: Record<string, string>;
61
+ /**
62
+ * Whether to generate declaration files with `tsgo`.
63
+ * @experimental
64
+ * @defaultValue `false`
65
+ * @see {@link https://rslib.rs/config/lib/dts#dtstsgo}
66
+ */
67
+ tsgo?: boolean;
61
68
  } | boolean;
62
69
  export type AutoExternal = boolean | {
63
70
  /**
@@ -21,3 +21,4 @@ export declare function debounce<T extends (...args: any[]) => void>(func: T, wa
21
21
  export declare const isTTY: (type?: "stdin" | "stdout") => boolean;
22
22
  export declare const isIntermediateOutputFormat: (format: Format) => boolean;
23
23
  export declare function normalizeSlash(p: string): string;
24
+ export declare function isDirectory(filePath: string): Promise<boolean>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rslib/core",
3
- "version": "0.12.3",
3
+ "version": "0.13.0",
4
4
  "description": "The Rsbuild-based library development tool.",
5
5
  "homepage": "https://rslib.rs",
6
6
  "bugs": {
@@ -36,21 +36,22 @@
36
36
  "types.d.ts"
37
37
  ],
38
38
  "dependencies": {
39
- "@rsbuild/core": "~1.5.0",
40
- "tinyglobby": "^0.2.14",
41
- "rsbuild-plugin-dts": "0.12.3"
39
+ "@rsbuild/core": "~1.5.4",
40
+ "tinyglobby": "^0.2.15",
41
+ "rsbuild-plugin-dts": "0.13.0"
42
42
  },
43
43
  "devDependencies": {
44
- "@module-federation/rsbuild-plugin": "^0.18.3",
44
+ "@module-federation/rsbuild-plugin": "^0.18.4",
45
45
  "@types/fs-extra": "^11.0.4",
46
46
  "cac": "^6.7.14",
47
47
  "chokidar": "^4.0.3",
48
48
  "fs-extra": "^11.3.1",
49
- "memfs": "^4.38.1",
49
+ "memfs": "^4.38.2",
50
+ "path-serializer": "0.5.1",
50
51
  "picocolors": "1.1.1",
51
- "prebundle": "1.4.1",
52
+ "prebundle": "1.4.2",
52
53
  "rsbuild-plugin-publint": "^0.3.3",
53
- "rslib": "npm:@rslib/core@0.12.2",
54
+ "rslib": "npm:@rslib/core@0.12.4",
54
55
  "rslog": "^1.2.11",
55
56
  "tsconfck": "3.1.6",
56
57
  "typescript": "^5.9.2",