@rslib/core 0.18.5 → 0.19.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.
@@ -1,13 +1,14 @@
1
1
  import type { LogLevel, RsbuildMode } from '@rsbuild/core';
2
- import type { ConfigLoader } from '../config';
3
- import type { Format, Syntax } from '../types/config';
2
+ import type { ConfigLoader } from '../loadConfig';
3
+ import type { Format, Syntax } from '../types';
4
4
  export type CommonOptions = {
5
5
  root?: string;
6
6
  config?: string;
7
+ configLoader?: ConfigLoader;
8
+ env?: boolean;
7
9
  envDir?: string;
8
10
  envMode?: string;
9
11
  lib?: string[];
10
- configLoader?: ConfigLoader;
11
12
  logLevel?: LogLevel;
12
13
  };
13
14
  export type BuildOptions = CommonOptions & {
@@ -32,4 +33,4 @@ export type InspectOptions = CommonOptions & {
32
33
  verbose?: boolean;
33
34
  };
34
35
  export type MfDevOptions = CommonOptions;
35
- export declare function runCli(): void;
36
+ export declare function setupCommands(): void;
@@ -0,0 +1 @@
1
+ export declare function runCLI(): void;
@@ -1,9 +1,5 @@
1
- import type { RslibConfig } from '../types';
1
+ import type { RslibConfig, RslibInstance } from '../types';
2
2
  import type { BuildOptions, CommonOptions } from './commands';
3
3
  export declare const parseEntryOption: (entries?: string[]) => Record<string, string> | undefined;
4
4
  export declare const applyCliOptions: (config: RslibConfig, options: BuildOptions, root: string) => void;
5
- export declare function initConfig(options: CommonOptions): Promise<{
6
- config: RslibConfig;
7
- configFilePath?: string;
8
- watchFiles: string[];
9
- }>;
5
+ export declare function init(options: CommonOptions): Promise<RslibInstance>;
@@ -1,23 +1,5 @@
1
1
  import { type EnvironmentConfig, type RsbuildEntry } from '@rsbuild/core';
2
- import type { AutoExternal, BannerAndFooter, Format, LibConfig, PkgJson, RequireKey, RsbuildConfigEntry, RsbuildConfigOutputTarget, RsbuildConfigWithLibInfo, RslibConfig, RslibConfigAsyncFn, RslibConfigExport, RslibConfigSyncFn } from './types';
3
- /**
4
- * This function helps you to autocomplete configuration types.
5
- * It accepts a Rslib config object, or a function that returns a config.
6
- */
7
- export declare function defineConfig(config: RslibConfig): RslibConfig;
8
- export declare function defineConfig(config: RslibConfigSyncFn): RslibConfigSyncFn;
9
- export declare function defineConfig(config: RslibConfigAsyncFn): RslibConfigAsyncFn;
10
- export declare function defineConfig(config: RslibConfigExport): RslibConfigExport;
11
- export type ConfigLoader = 'auto' | 'jiti' | 'native';
12
- export declare function loadConfig({ cwd, path, envMode, loader, }: {
13
- cwd?: string;
14
- path?: string;
15
- envMode?: string;
16
- loader?: ConfigLoader;
17
- }): Promise<{
18
- content: RslibConfig;
19
- filePath?: string;
20
- }>;
2
+ import type { AutoExternal, BannerAndFooter, Format, LibConfig, PkgJson, RequireKey, RsbuildConfigEntry, RsbuildConfigOutputTarget, RsbuildConfigWithLibInfo, RslibConfig } from './types';
21
3
  export declare const composeAutoExternalConfig: (options: {
22
4
  bundle: boolean;
23
5
  format: Format;
@@ -1,5 +1,3 @@
1
- export declare const DEFAULT_CONFIG_NAME = "rslib.config";
2
- export declare const DEFAULT_CONFIG_EXTENSIONS: readonly [".js", ".ts", ".mjs", ".mts", ".cjs", ".cts"];
3
1
  export declare const SWC_HELPERS = "@swc/helpers";
4
2
  export declare const JS_EXTENSIONS_PATTERN: RegExp;
5
3
  export declare const CSS_EXTENSIONS_PATTERN: RegExp;
@@ -0,0 +1,5 @@
1
+ import type { CreateRslibOptions, RslibInstance } from './types/rslib';
2
+ /**
3
+ * Create an Rslib instance.
4
+ */
5
+ export declare function createRslib(options?: CreateRslibOptions): Promise<RslibInstance>;
@@ -1,12 +1,13 @@
1
- export { build } from './cli/build';
2
- export { runCli } from './cli/commands';
3
- export { inspect } from './cli/inspect';
4
- export { startMFDevServer } from './cli/mf';
5
- export { prepareCli } from './cli/prepare';
6
- export { composeCreateRsbuildConfig as unstable_composeCreateRsbuildConfig, defineConfig, loadConfig, } from './config';
7
- export type * from './types';
8
- export { logger } from './utils/logger';
1
+ /**
2
+ * The methods and types exported from this file are considered as
3
+ * the public API of @rslib/core.
4
+ */
5
+ export { runCLI } from './cli';
6
+ export { createRslib } from './createRslib';
7
+ export { type ConfigParams, defineConfig, type LoadConfigOptions, type LoadConfigResult, type LoadEnvOptions, type LoadEnvResult, loadConfig, loadEnv, } from './loadConfig';
8
+ export { mergeRslibConfig } from './mergeConfig';
9
+ export type { AutoExternal, BannerAndFooter, BuildOptions, BuildResult, CreateRslibOptions, Dts, Format, InspectConfigOptions, InspectConfigResult, LibConfig, LibExperiments, OnAfterCreateRsbuildFn, Redirect, RslibConfig, RslibInstance, Shims, StartMFDevServerOptions, StartServerResult, Syntax, } from './types';
9
10
  export declare const version: string;
10
11
  export type * as Rsbuild from '@rsbuild/core';
11
12
  export * as rsbuild from '@rsbuild/core';
12
- export { type RsbuildPlugin, type Rspack, rspack } from '@rsbuild/core';
13
+ export { type RsbuildPlugin, type Rspack, rspack, } from '@rsbuild/core';
@@ -0,0 +1,34 @@
1
+ import { type LoadConfigOptions as RsbuildLoadConfigOptions } from '@rsbuild/core';
2
+ import type { RslibConfig } from './types';
3
+ export type ConfigParams = {
4
+ env: string;
5
+ command: string;
6
+ envMode?: string;
7
+ meta?: Record<string, unknown>;
8
+ };
9
+ export type RslibConfigSyncFn = (env: ConfigParams) => RslibConfig;
10
+ export type RslibConfigAsyncFn = (env: ConfigParams) => Promise<RslibConfig>;
11
+ export type RslibConfigExport = RslibConfig | RslibConfigSyncFn | RslibConfigAsyncFn;
12
+ export type LoadConfigOptions = Pick<RsbuildLoadConfigOptions, 'cwd' | 'path' | 'envMode' | 'meta' | 'loader'>;
13
+ export type ConfigLoader = RsbuildLoadConfigOptions['loader'];
14
+ export type LoadConfigResult = {
15
+ /**
16
+ * The loaded configuration object.
17
+ */
18
+ content: RslibConfig;
19
+ /**
20
+ * The path to the loaded configuration file.
21
+ * Return `null` if the configuration file is not found.
22
+ */
23
+ filePath: string | null;
24
+ };
25
+ /**
26
+ * This function helps you to autocomplete configuration types.
27
+ * It accepts a Rslib config object, or a function that returns a config.
28
+ */
29
+ export declare function defineConfig(config: RslibConfig): RslibConfig;
30
+ export declare function defineConfig(config: RslibConfigSyncFn): RslibConfigSyncFn;
31
+ export declare function defineConfig(config: RslibConfigAsyncFn): RslibConfigAsyncFn;
32
+ export declare function defineConfig(config: RslibConfigExport): RslibConfigExport;
33
+ export declare function loadConfig({ cwd, path, envMode, meta, loader, }: LoadConfigOptions): Promise<LoadConfigResult>;
34
+ export { type LoadEnvOptions, type LoadEnvResult, loadEnv, } from '@rsbuild/core';
@@ -0,0 +1,15 @@
1
+ import type { RslibConfig } from './types';
2
+ export type RslibConfigWithOptionalLib = Omit<RslibConfig, 'lib'> & {
3
+ lib?: RslibConfig['lib'];
4
+ };
5
+ /**
6
+ * Merge multiple Rslib configurations into a single configuration.
7
+ *
8
+ * For the `lib` array, items are merged based on their `id` field:
9
+ * - Items with the same `id` are deep merged together using `mergeRsbuildConfig`
10
+ * - Items without `id` are appended to the result array
11
+ * - The order of items with `id` is preserved based on their first occurrence
12
+ *
13
+ * Other configuration fields are merged using `mergeRsbuildConfig`.
14
+ */
15
+ export declare function mergeRslibConfig(...originalConfigs: (RslibConfigWithOptionalLib | undefined)[]): RslibConfigWithOptionalLib;
@@ -0,0 +1,9 @@
1
+ import type { RslibInstance } from './types';
2
+ export declare function getWatchFilesForRestart(rslib: RslibInstance): string[] | undefined;
3
+ export declare function watchFilesForRestart(files: string[] | undefined, restart: () => Promise<void>): Promise<void>;
4
+ type Cleaner = () => Promise<unknown> | unknown;
5
+ /**
6
+ * Add a cleaner to handle side effects
7
+ */
8
+ export declare const onBeforeRestart: (cleaner: Cleaner) => void;
9
+ export {};
@@ -196,7 +196,7 @@ export type Redirect = {
196
196
  export type LibExperiments = {
197
197
  /**
198
198
  * Whether to enable Rspack advanced ESM output.
199
- * @defaultValue `false`
199
+ * @defaultValue `true`
200
200
  * @see {@link https://rslib.rs/config/lib/experiments#experimentsadvancedesm}
201
201
  */
202
202
  advancedEsm?: boolean;
@@ -337,13 +337,12 @@ export interface RslibConfig extends RsbuildConfig {
337
337
  * @inheritdoc
338
338
  */
339
339
  output?: RslibOutputConfig;
340
+ /**
341
+ * @private
342
+ */
343
+ _privateMeta?: {
344
+ configFilePath: string;
345
+ envFilePaths?: string[];
346
+ };
340
347
  }
341
- export type ConfigParams = {
342
- env: string;
343
- command: string;
344
- envMode?: string;
345
- };
346
- export type RslibConfigSyncFn = (env: ConfigParams) => RslibConfig;
347
- export type RslibConfigAsyncFn = (env: ConfigParams) => Promise<RslibConfig>;
348
- export type RslibConfigExport = RslibConfig | RslibConfigSyncFn | RslibConfigAsyncFn;
349
348
  export {};
@@ -1,2 +1,3 @@
1
1
  export type * from './config';
2
+ export type * from './rslib';
2
3
  export type * from './utils';
@@ -0,0 +1,102 @@
1
+ import type { BuildResult, LoadEnvOptions, InspectConfigResult as RsbuildInspectConfigResult, RsbuildInstance, RsbuildMode, StartServerResult } from '@rsbuild/core';
2
+ import type { RslibConfig } from './config';
3
+ export type CommonOptions = {
4
+ /**
5
+ * Specify the library id to run the action on.
6
+ */
7
+ lib?: string[];
8
+ };
9
+ export type BuildOptions = CommonOptions & {
10
+ /**
11
+ * Whether to watch for file changes and rebuild.
12
+ * @default false
13
+ */
14
+ watch?: boolean;
15
+ };
16
+ export type InspectConfigOptions = CommonOptions & {
17
+ /**
18
+ * Inspect the config in the specified mode.
19
+ * Available options: 'development' or 'production'.
20
+ * @default 'production'
21
+ */
22
+ mode?: RsbuildMode;
23
+ /**
24
+ * Enables verbose mode to display the complete function
25
+ * content in the configuration.
26
+ * @default false
27
+ */
28
+ verbose?: boolean;
29
+ /**
30
+ * Specify the output path for inspection results.
31
+ * @default 'output.distPath.root'
32
+ */
33
+ outputPath?: string;
34
+ /**
35
+ * Whether to write the inspection results to disk.
36
+ * @default false
37
+ */
38
+ writeToDisk?: boolean;
39
+ };
40
+ export type StartMFDevServerOptions = CommonOptions;
41
+ export type { BuildResult, StartServerResult };
42
+ export type InspectConfigResult = {
43
+ rslibConfig: string;
44
+ } & RsbuildInspectConfigResult;
45
+ export type RslibInstance = {
46
+ /**
47
+ * Get the resolved Rslib configuration.
48
+ */
49
+ getRslibConfig(): Readonly<RslibConfig>;
50
+ /**
51
+ * Register a callback that will be called after creating the internal Rsbuild instance.
52
+ * You can use this to access or call the properties and methods of the Rsbuild instance.
53
+ */
54
+ onAfterCreateRsbuild(callback: OnAfterCreateRsbuildFn): void;
55
+ /**
56
+ * Perform a production mode build. This method will generate the outputs
57
+ * for production and emit them to the output directory.
58
+ */
59
+ build(options?: BuildOptions): Promise<BuildResult>;
60
+ /**
61
+ * Inspect and debug Rslib configurations and the internal Rsbuild and Rspack configurations of the Rslib project. It provides access to:
62
+ * - The resolved Rslib configuration
63
+ * - The resolved Rsbuild configuration
64
+ * - The environment-specific Rsbuild configurations
65
+ * - The generated Rspack configurations
66
+ *
67
+ * The method serializes these configurations to strings and optionally writes
68
+ * them to disk for inspection.
69
+ */
70
+ inspectConfig(options?: InspectConfigOptions): Promise<InspectConfigResult>;
71
+ /**
72
+ * Start the local dev server for the Module Federation format. This method will:
73
+ *
74
+ * 1. Start a development server that serves your mf format module.
75
+ * 2. Watch for file changes and trigger recompilation.
76
+ */
77
+ startMFDevServer(options?: StartMFDevServerOptions): Promise<StartServerResult>;
78
+ };
79
+ export type OnAfterCreateRsbuildFn = (params: {
80
+ /**
81
+ * The Rsbuild instance.
82
+ */
83
+ rsbuild: RsbuildInstance;
84
+ }) => void | Promise<void>;
85
+ export type CreateRslibOptions = {
86
+ /**
87
+ * The root path of current project.
88
+ * @default process.cwd()
89
+ */
90
+ cwd?: string;
91
+ /**
92
+ * Rslib configurations.
93
+ * Passing a function to load the config asynchronously with custom logic.
94
+ */
95
+ config?: RslibConfig | (() => Promise<RslibConfig>);
96
+ /**
97
+ * Whether to call `loadEnv` to load environment variables and define them
98
+ * as global variables via `source.define`.
99
+ * @default false
100
+ */
101
+ loadEnv?: boolean | LoadEnvOptions;
102
+ };
@@ -6,7 +6,7 @@ import type { Format, LibConfig, PkgJson } from '../types';
6
6
  */
7
7
  export declare const nodeBuiltInModules: (string | RegExp)[];
8
8
  export declare function calcLongestCommonPath(absPaths: string[]): Promise<string | null>;
9
- export declare function getAbsolutePath(base: string, filepath: string): string;
9
+ export declare function ensureAbsolutePath(base: string, filepath: string): string;
10
10
  export declare const readPackageJson: (rootPath: string) => undefined | PkgJson;
11
11
  export declare const isObject: (obj: unknown) => obj is Record<string, any>;
12
12
  export declare const isEmptyObject: (obj: object) => boolean;
@@ -22,3 +22,6 @@ 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
24
  export declare function isDirectory(filePath: string): Promise<boolean>;
25
+ export declare const isFunction: (func: unknown) => func is (...args: any[]) => any;
26
+ export declare const getNodeEnv: () => string;
27
+ export declare const setNodeEnv: (env: string) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rslib/core",
3
- "version": "0.18.5",
3
+ "version": "0.19.0",
4
4
  "description": "The Rsbuild-based library development tool.",
5
5
  "homepage": "https://rslib.rs",
6
6
  "bugs": {
@@ -36,21 +36,21 @@
36
36
  "types.d.ts"
37
37
  ],
38
38
  "dependencies": {
39
- "@rsbuild/core": "~1.7.0-beta.0",
40
- "rsbuild-plugin-dts": "0.18.5"
39
+ "@rsbuild/core": "~1.7.0-beta.2",
40
+ "rsbuild-plugin-dts": "0.19.0"
41
41
  },
42
42
  "devDependencies": {
43
- "@module-federation/rsbuild-plugin": "^0.21.6",
43
+ "@module-federation/rsbuild-plugin": "^0.22.0",
44
44
  "@types/fs-extra": "^11.0.4",
45
45
  "cac": "^6.7.14",
46
46
  "chokidar": "^4.0.3",
47
- "fs-extra": "^11.3.2",
47
+ "fs-extra": "^11.3.3",
48
48
  "memfs": "^4.51.1",
49
49
  "path-serializer": "0.5.1",
50
50
  "picocolors": "1.1.1",
51
51
  "prebundle": "1.6.0",
52
52
  "rsbuild-plugin-publint": "^0.3.3",
53
- "rslib": "npm:@rslib/core@0.18.4",
53
+ "rslib": "npm:@rslib/core@0.18.6",
54
54
  "rslog": "^1.3.2",
55
55
  "tinyglobby": "0.2.14",
56
56
  "tsconfck": "3.1.6",
@@ -1,4 +0,0 @@
1
- import { type RsbuildInstance } from '@rsbuild/core';
2
- import type { RslibConfig } from '../types/config';
3
- import type { BuildOptions } from './commands';
4
- export declare function build(config: RslibConfig, options?: Pick<BuildOptions, 'lib' | 'watch' | 'root'>): Promise<RsbuildInstance>;
@@ -1,4 +0,0 @@
1
- import { type RsbuildInstance } from '@rsbuild/core';
2
- import type { RslibConfig } from '../types/config';
3
- import type { InspectOptions } from './commands';
4
- export declare function inspect(config: RslibConfig, options?: Pick<InspectOptions, 'lib' | 'mode' | 'output' | 'verbose'>): Promise<RsbuildInstance>;
@@ -1,4 +0,0 @@
1
- import type { RsbuildInstance } from '@rsbuild/core';
2
- import type { RslibConfig } from '../types';
3
- import type { CommonOptions } from './commands';
4
- export declare function startMFDevServer(config: RslibConfig, options?: Pick<CommonOptions, 'lib'>): Promise<RsbuildInstance | undefined>;
@@ -1 +0,0 @@
1
- export declare function prepareCli(): void;
@@ -1,7 +0,0 @@
1
- export declare function watchFilesForRestart(files: string[], restart: () => Promise<void>): Promise<void>;
2
- type Cleaner = () => Promise<unknown> | unknown;
3
- /**
4
- * Add a cleaner to handle side effects
5
- */
6
- export declare const onBeforeRestart: (cleaner: Cleaner) => void;
7
- export {};