@savvy-web/rslib-builder 0.10.0 → 0.12.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/README.md CHANGED
@@ -8,126 +8,47 @@ Build modern ESM Node.js libraries with minimal configuration. Handles
8
8
  TypeScript declarations, package.json transformations, and PNPM workspace
9
9
  resolution automatically.
10
10
 
11
- Building TypeScript packages for npm involves repetitive setup: configuring
12
- bundlers, generating declarations, transforming package.json exports, and
13
- resolving workspace references. rslib-builder handles these tasks so you can
14
- focus on your code.
15
-
16
11
  ## Features
17
12
 
18
- - **Zero Config** - Auto-detects entry points from package.json exports
19
- - **Fast Type Generation** - Uses tsgo (native TypeScript) for 10-100x faster
20
- declaration generation
21
- - **Bundled Declarations** - Rolls up TypeScript types via API Extractor for
22
- cleaner public APIs, with multi-entry support for packages with multiple exports
23
- - **Multi-Target Builds** - Separate dev (source maps) and npm (optimized)
24
- outputs
25
- - **Virtual Entries** - Bundle additional files (like pnpmfile.cjs) with custom
26
- output names, bypassing type generation and package.json exports
27
- - **Flexible Format** - Configure output format (ESM or CJS) at the library level
28
- with per-entry overrides for virtual entries
29
- - **PNPM Integration** - Automatically resolves `catalog:` and `workspace:`
30
- references
31
- - **Package.json Transform** - Converts `.ts` exports to `.js`, generates files
32
- array, removes dev-only fields
33
- - **TSDoc Validation** - Pre-build TSDoc validation with automatic public API discovery
34
- - **API Model Generation** - Optional API model and resolved tsconfig output for
35
- documentation tooling
36
- - **Extensible** - Add custom RSlib/Rsbuild plugins for advanced use cases
37
-
38
- ## Prerequisites
39
-
40
- - Node.js 24.x or later
41
- - pnpm 10.x or later
42
- - TypeScript 5.9.x or later
13
+ - **Zero-Config Entry Detection** - Auto-discovers entry points from package.json
14
+ exports, no manual configuration needed
15
+ - **10-100x Faster Types** - Uses tsgo (native TypeScript compiler) with API
16
+ Extractor for bundled, clean public API declarations
17
+ - **Production-Ready Transforms** - Converts `.ts` exports to `.js`, resolves
18
+ PNPM `catalog:` and `workspace:` references, generates files array
19
+ - **Bundled or Bundleless** - Choose single-file bundles per entry or
20
+ bundleless mode that preserves your source file structure
21
+ - **Multi-Target Builds** - Separate dev (with source maps) and npm (optimized)
22
+ outputs from a single configuration
23
+ - **TSDoc Validation** - Pre-build documentation validation with automatic
24
+ public API discovery
43
25
 
44
26
  ## Installation
45
27
 
46
28
  ```bash
47
- pnpm add -D @savvy-web/rslib-builder
48
- ```
49
-
50
- ### Peer Dependencies
51
-
52
- Install the required peer dependencies:
53
-
54
- ```bash
55
- pnpm add -D @rslib/core @microsoft/api-extractor @typescript/native-preview
29
+ npm install --save-dev @savvy-web/rslib-builder @rslib/core @microsoft/api-extractor @typescript/native-preview
56
30
  ```
57
31
 
58
32
  ## Quick Start
59
33
 
60
- Extend the provided tsconfig for optimal settings:
61
-
62
- ```jsonc
63
- // tsconfig.json
64
- {
65
- "extends": "@savvy-web/rslib-builder/tsconfig/ecma/lib.json"
66
- }
67
- ```
68
-
69
- Create an `rslib.config.ts` in your project root:
70
-
71
34
  ```typescript
35
+ // rslib.config.ts
72
36
  import { NodeLibraryBuilder } from '@savvy-web/rslib-builder';
73
37
 
74
38
  export default NodeLibraryBuilder.create({
75
39
  externals: ['@rslib/core'],
76
- transform({ pkg, target }) {
77
- if (target === 'npm') {
78
- delete pkg.devDependencies;
79
- }
80
- return pkg;
81
- },
82
40
  });
83
41
  ```
84
42
 
85
- Add scripts to your `package.json`:
86
-
87
- ```json
88
- {
89
- "scripts": {
90
- "build": "rslib build --env-mode dev",
91
- "build:npm": "rslib build --env-mode npm"
92
- }
93
- }
94
- ```
43
+ Build with `rslib build --env-mode dev` or `rslib build --env-mode npm`.
95
44
 
96
45
  ## Documentation
97
46
 
98
- For detailed documentation, see the [docs/](./docs/) directory:
99
-
100
- - [Getting Started](./docs/guides/getting-started.md) - Installation and setup
101
- - [Configuration](./docs/guides/configuration.md) - All options explained
102
- - [Plugin System](./docs/guides/plugins.md) - Built-in and custom plugins
103
- - [Architecture](./docs/architecture/overview.md) - How it works internally
104
- - [Troubleshooting](./docs/troubleshooting.md) - Common issues and solutions
105
-
106
- ## Example
107
-
108
- This package builds itself using its own `NodeLibraryBuilder`. See
109
- [`rslib.config.ts`](./rslib.config.ts) for a production example.
110
-
111
- ## Support
112
-
113
- This software is provided as-is under the MIT License with no warranty or
114
- support guarantees. While we welcome bug reports and feature requests via
115
- GitHub Issues, we cannot guarantee response times or resolution.
116
-
117
- For security vulnerabilities, please see [SECURITY.md](./SECURITY.md).
118
-
119
- ## Links
120
-
121
- - [RSlib Documentation](https://rslib.dev/)
122
- - [Rsbuild Plugin API](https://rsbuild.dev/plugins/dev/core)
123
- - [API Extractor](https://api-extractor.com/)
124
- - [PNPM Workspace](https://pnpm.io/workspaces)
125
- - [PNPM Catalogs](https://pnpm.io/catalogs)
47
+ For configuration options, API reference, and advanced usage, see [docs](./docs/).
126
48
 
127
49
  ## Contributing
128
50
 
129
- Contributions welcome! See [CONTRIBUTING.md](./CONTRIBUTING.md) for setup
130
- and guidelines.
51
+ See [CONTRIBUTING.md](./CONTRIBUTING.md) for development setup and guidelines.
131
52
 
132
53
  ## License
133
54
 
package/index.d.ts CHANGED
@@ -62,10 +62,9 @@ import ts from 'typescript';
62
62
  * API model generation is enabled by default. To disable, set `apiModel: false`.
63
63
  * Providing an options object implicitly enables API model generation.
64
64
  *
65
- * API models are only generated for the main "index" entry point (the "." export).
66
- * Additional entry points like "./hooks" or "./utils" do not generate separate API models.
67
- * This prevents multiple conflicting API models and ensures a single source of truth
68
- * for package documentation.
65
+ * When a package has multiple entry points, API Extractor runs for each entry and the
66
+ * resulting per-entry models are merged into a single API model with multiple
67
+ * EntryPoint members. Canonical references are scoped per entry point.
69
68
  *
70
69
  * @public
71
70
  */
@@ -222,6 +221,18 @@ export declare interface AutoEntryPluginOptions {
222
221
  * @defaultValue false
223
222
  */
224
223
  exportsAsIndexes?: boolean;
224
+ /**
225
+ * When enabled, uses import graph analysis to discover all reachable files
226
+ * from entry points, and sets RSlib's source.entry to the traced file list
227
+ * instead of named entries.
228
+ *
229
+ * @remarks
230
+ * Named entries are still exposed via the `entrypoints` map for DtsPlugin
231
+ * and PackageJsonTransformPlugin to use.
232
+ *
233
+ * @defaultValue false
234
+ */
235
+ bundleless?: boolean;
225
236
  }
226
237
 
227
238
  /**
@@ -515,24 +526,14 @@ export declare interface ExtractedEntries {
515
526
  * Entry name to TypeScript source path mapping.
516
527
  */
517
528
  entries: Record<string, string>;
529
+ /**
530
+ * Entry name to original export key mapping.
531
+ * Maps entry names back to the original package.json export path
532
+ * (e.g., `"nested-one"` → `"./nested/one"`).
533
+ */
534
+ exportPaths: Record<string, string>;
518
535
  }
519
536
 
520
- /**
521
- * Extracts TypeScript entry points from package.json (functional interface).
522
- *
523
- * @remarks
524
- * This is a convenience function that creates an EntryExtractor instance
525
- * and extracts entries in one call. For repeated use, consider creating
526
- * an EntryExtractor instance directly.
527
- *
528
- * @param packageJson - The package.json object to extract entries from
529
- * @param options - Configuration options for entry extraction
530
- * @returns Object containing the extracted entries
531
- *
532
- * @public
533
- */
534
- export declare function extractEntriesFromPackageJson(packageJson: PackageJson, options?: EntryExtractorOptions): ExtractedEntries;
535
-
536
537
  /**
537
538
  * Plugin to manage the `files` array in package.json for npm publishing.
538
539
  *
@@ -1162,6 +1163,7 @@ export declare class NodeLibraryBuilder {
1162
1163
  targets: ("dev" | "npm")[];
1163
1164
  externals: never[];
1164
1165
  apiModel: true;
1166
+ bundle: true;
1165
1167
  };
1166
1168
  /**
1167
1169
  * Merges user-provided options with default options.
@@ -1206,6 +1208,27 @@ export declare class NodeLibraryBuilder {
1206
1208
  }
1207
1209
 
1208
1210
  /**
1211
+ * Configuration options for the NodeLibraryBuilder.
1212
+ *
1213
+ * @remarks
1214
+ * All options are optional with sensible defaults. The most commonly customized options are:
1215
+ * - `externals`: For dependencies that should remain external
1216
+ * - `dtsBundledPackages`: For inlining type definitions
1217
+ * - `transform`: For custom package.json modifications
1218
+ *
1219
+ * @example
1220
+ * ```typescript
1221
+ * import type { NodeLibraryBuilderOptions } from '@savvy-web/rslib-builder';
1222
+ *
1223
+ * const options: NodeLibraryBuilderOptions = {
1224
+ * externals: ['@rslib/core'],
1225
+ * dtsBundledPackages: ['picocolors'],
1226
+ * apiModel: {
1227
+ * localPaths: ['../docs/packages/my-package'],
1228
+ * },
1229
+ * };
1230
+ * ```
1231
+ *
1209
1232
  * @public
1210
1233
  */
1211
1234
  export declare interface NodeLibraryBuilderOptions {
@@ -1287,11 +1310,46 @@ export declare interface NodeLibraryBuilderOptions {
1287
1310
  * ```
1288
1311
  */
1289
1312
  exportsAsIndexes?: boolean;
1313
+ /**
1314
+ * Patterns for files to copy to the output directory.
1315
+ *
1316
+ * @remarks
1317
+ * Supports both string paths and detailed configuration objects.
1318
+ * A `public/` directory in the project root is automatically added if it exists.
1319
+ *
1320
+ * @defaultValue `[]`
1321
+ */
1290
1322
  copyPatterns: (string | CopyPatternConfig)[];
1291
- /** Additional plugins */
1323
+ /**
1324
+ * Additional Rsbuild plugins to include in the build.
1325
+ *
1326
+ * @remarks
1327
+ * These plugins run after the built-in plugins (AutoEntryPlugin, DtsPlugin, etc.).
1328
+ *
1329
+ * @defaultValue `[]`
1330
+ */
1292
1331
  plugins: RsbuildPlugin[];
1332
+ /**
1333
+ * Compile-time constants for code replacement.
1334
+ *
1335
+ * @remarks
1336
+ * Values are stringified and replaced in the source code during bundling.
1337
+ * The `process.env.__PACKAGE_VERSION__` constant is automatically defined.
1338
+ *
1339
+ * @see {@link https://rsbuild.dev/config/source/define | Rsbuild define documentation}
1340
+ *
1341
+ * @defaultValue `{}`
1342
+ */
1293
1343
  define: SourceConfig["define"];
1294
- /** Path to tsconfig for build (default: ./tsconfig.build.json) */
1344
+ /**
1345
+ * Path to the TypeScript configuration file for the build.
1346
+ *
1347
+ * @remarks
1348
+ * If not specified, the plugin searches for `tsconfig.json` in the project root.
1349
+ * A temporary tsconfig is generated for declaration generation regardless of this setting.
1350
+ *
1351
+ * @defaultValue `undefined` (auto-detected)
1352
+ */
1295
1353
  tsconfigPath: string | undefined;
1296
1354
  /** Build targets to include (default: ["dev", "npm"]) */
1297
1355
  targets?: BuildTarget[];
@@ -1424,6 +1482,19 @@ export declare interface NodeLibraryBuilderOptions {
1424
1482
  * ```
1425
1483
  */
1426
1484
  apiModel?: ApiModelOptions | boolean;
1485
+ /**
1486
+ * Whether to bundle JavaScript output into single files per entry point.
1487
+ *
1488
+ * @remarks
1489
+ * - `true` (default): RSlib bundles JS into single files per entry (current behavior)
1490
+ * - `false`: RSlib runs in bundleless mode, preserving file structure for JS output.
1491
+ * DTS is still bundled per entry via API Extractor (hybrid mode).
1492
+ * When `apiModel` is enabled with multiple entries, per-entry API models are
1493
+ * merged into a single `api.model.json` with multiple EntryPoint members.
1494
+ *
1495
+ * @defaultValue true
1496
+ */
1497
+ bundle?: boolean;
1427
1498
  }
1428
1499
 
1429
1500
  /**
@@ -1872,7 +1943,6 @@ export declare type PackageJson = JsonObject & PackageJson.NodeJsStandard & Pack
1872
1943
  *
1873
1944
  * - Consumes `entrypoints` map from AutoEntryPlugin
1874
1945
  * - Consumes `exportToOutputMap` for exportsAsIndexes mode
1875
- * - Exposes `files-cache` for asset caching
1876
1946
  * - Consumes `use-rollup-types` flag from DtsPlugin
1877
1947
  *
1878
1948
  * @param options - Plugin configuration options
@@ -2846,6 +2916,16 @@ export declare class TsconfigResolver {
2846
2916
  * @defaultValue `true`
2847
2917
  */
2848
2918
  persistConfig?: boolean | PathLike;
2919
+ /**
2920
+ * Whether to run lint per entry point individually with per-entry logging.
2921
+ *
2922
+ * @remarks
2923
+ * When enabled, each entry point is linted separately and results are
2924
+ * logged per entry for better visibility in bundleless mode.
2925
+ *
2926
+ * @defaultValue false
2927
+ */
2928
+ perEntry?: boolean;
2849
2929
  }
2850
2930
 
2851
2931
  /**
@@ -3078,12 +3158,22 @@ export declare class TsconfigResolver {
3078
3158
 
3079
3159
  /**
3080
3160
  * Options for the VirtualEntryPlugin.
3161
+ *
3162
+ * @remarks
3163
+ * Virtual entries are used for special files that need bundling but should not
3164
+ * generate type declarations or appear in package.json exports. Common use cases
3165
+ * include pnpmfile.cjs or other configuration files.
3166
+ *
3081
3167
  * @public
3082
3168
  */
3083
3169
  export declare interface VirtualEntryPluginOptions {
3084
3170
  /**
3085
- * Set of virtual entry names (without extensions).
3086
- * Used by DtsPlugin to skip type generation for these entries.
3171
+ * Set of virtual entry names (without file extensions).
3172
+ *
3173
+ * @remarks
3174
+ * These names are exposed to DtsPlugin to skip type generation.
3175
+ * For example, if `virtualEntryNames` contains `"pnpmfile"`, the
3176
+ * entry `pnpmfile.cjs` will be bundled but no `pnpmfile.d.ts` will be generated.
3087
3177
  */
3088
3178
  virtualEntryNames: Set<string>;
3089
3179
  }