@savvy-web/rslib-builder 0.1.1 → 0.2.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/index.d.ts CHANGED
@@ -12,7 +12,7 @@
12
12
  * - **Package.json Transformation**: Automatic path updates, PNPM catalog resolution
13
13
  * - **TypeScript Declaration Bundling**: Using tsgo and API Extractor
14
14
  * - **File Array Generation**: Automatic files array creation for package.json
15
- * - **API Model Generation**: Optional api.model.json for documentation tooling
15
+ * - **API Model Generation**: Optional `<packageName>.api.json` for documentation tooling
16
16
  *
17
17
  * @example
18
18
  * Basic usage in rslib.config.ts:
@@ -41,6 +41,7 @@
41
41
 
42
42
  import type { ConfigParams } from '@rslib/core';
43
43
  import type { PackageJson } from 'type-fest';
44
+ import type { PathLike } from 'node:fs';
44
45
  import type { RawCopyPattern } from '@rspack/binding';
45
46
  import type { RsbuildPlugin } from '@rsbuild/core';
46
47
  import type { RslibConfig } from '@rslib/core';
@@ -48,7 +49,7 @@ import type { SourceConfig } from '@rsbuild/core';
48
49
 
49
50
  /**
50
51
  * Options for API model generation.
51
- * When enabled, generates an api.model.json file using API Extractor.
52
+ * When enabled, generates an `<unscopedPackageName>.api.json` file using API Extractor.
52
53
  *
53
54
  * @remarks
54
55
  * API models are only generated for the main "index" entry point (the "." export).
@@ -66,15 +67,9 @@ export declare interface ApiModelOptions {
66
67
  enabled?: boolean;
67
68
  /**
68
69
  * Filename for the generated API model file.
69
- * @defaultValue "api.model.json"
70
+ * @defaultValue `<unscopedPackageName>.api.json` (e.g., `rslib-builder.api.json`)
70
71
  */
71
72
  filename?: string;
72
- /**
73
- * Whether to add a .npmignore file that excludes the API model file.
74
- * This is useful when the API model is for internal tooling only.
75
- * @defaultValue true
76
- */
77
- npmIgnore?: boolean;
78
73
  /**
79
74
  * Local paths to copy the API model and package.json to.
80
75
  * Used for local testing with documentation systems.
@@ -82,7 +77,10 @@ export declare interface ApiModelOptions {
82
77
  * @remarks
83
78
  * Each path must be a directory. The parent directory must exist,
84
79
  * but the final directory will be created if it doesn't exist.
85
- * Both api.model.json and the processed package.json will be copied.
80
+ * Both the API model and the processed package.json will be copied.
81
+ *
82
+ * The API model file is emitted to dist but excluded from npm publish
83
+ * (added as negated pattern `!<filename>` in the `files` array).
86
84
  *
87
85
  * @example
88
86
  * ```typescript
@@ -93,13 +91,38 @@ export declare interface ApiModelOptions {
93
91
  * ```
94
92
  */
95
93
  localPaths?: string[];
94
+ /**
95
+ * TSDoc configuration for custom tag definitions.
96
+ * Passed to API Extractor for documentation processing.
97
+ *
98
+ * @remarks
99
+ * By default, all standard tag groups (core, extended, discretionary) are
100
+ * enabled. Custom tags defined in `tagDefinitions` are automatically
101
+ * supported. Use `supportForTags` only to disable specific tags.
102
+ *
103
+ * @example
104
+ * ```typescript
105
+ * apiModel: {
106
+ * enabled: true,
107
+ * tsdoc: {
108
+ * tagDefinitions: [{ tagName: "@error", syntaxKind: "inline" }]
109
+ * }
110
+ * }
111
+ * ```
112
+ */
113
+ tsdoc?: TsDocOptions;
114
+ /**
115
+ * Options for tsdoc-metadata.json generation.
116
+ * @defaultValue true (enabled when apiModel is enabled)
117
+ */
118
+ tsdocMetadata?: TsDocMetadataOptions | boolean;
96
119
  }
97
120
 
98
121
  /**
99
122
  * Plugin to read package.json and configure entry points based on exports.
100
123
  *
101
- * @param options - Plugin configuration options
102
- * @param options.exportsAsIndexes - When true, export paths create index files in nested directories
124
+ * @param options - Plugin configuration options with properties:
125
+ * - `exportsAsIndexes`: When true, export paths create index files in nested directories
103
126
  * @public
104
127
  */
105
128
  export declare const AutoEntryPlugin: (options?: {
@@ -125,7 +148,7 @@ export declare function collectDtsFiles(dir: string, baseDir?: string): Promise<
125
148
  * Plugin to generate TypeScript declaration files using tsgo and emit them through Rslib's asset pipeline.
126
149
  *
127
150
  * @remarks
128
- * This plugin uses tsgo (@typescript/native-preview) for faster declaration file generation
151
+ * This plugin uses tsgo (`\@typescript/native-preview`) for faster declaration file generation
129
152
  * and integrates with Rslib's build system by emitting generated files as compilation assets.
130
153
  *
131
154
  * ## Features
@@ -208,7 +231,7 @@ export declare interface DtsPluginOptions {
208
231
  /**
209
232
  * Packages whose types should be bundled (inlined) into the output .d.ts files.
210
233
  * Only applies when bundle is true.
211
- * Supports glob patterns (e.g., '@commitlint/*', 'type-fest')
234
+ * Supports glob patterns (e.g., '\@commitlint/*', 'type-fest')
212
235
  * @defaultValue []
213
236
  */
214
237
  bundledPackages?: string[];
@@ -229,8 +252,10 @@ export declare interface DtsPluginOptions {
229
252
  buildTarget?: "dev" | "npm";
230
253
  /**
231
254
  * Options for API model generation.
232
- * When enabled, generates an api.model.json file in the dist directory.
255
+ * When enabled, generates an `<unscopedPackageName>.api.json` file in the dist directory.
233
256
  * Only applies when bundle is true.
257
+ *
258
+ * The API model is excluded from npm publish (not added to `files` array).
234
259
  */
235
260
  apiModel?: ApiModelOptions | boolean;
236
261
  }
@@ -251,7 +276,7 @@ export declare function ensureTempDeclarationDir(cwd: string, name: string): Pro
251
276
  * TypeScript source files.
252
277
  *
253
278
  * **Export Path Mapping:**
254
- * - Converts export keys to entry names (e.g., "./utils" -> "utils")
279
+ * - Converts export keys to entry names (e.g., "./utils" becomes "utils")
255
280
  * - Maps the root export "." to "index" entry
256
281
  * - Replaces path separators with hyphens for nested exports (default)
257
282
  * - When `exportsAsIndexes` is true, preserves path structure
@@ -414,6 +439,14 @@ export declare function generateTsgoArgs(options: {
414
439
  */
415
440
  export declare function getTsgoBinPath(): string;
416
441
 
442
+ /**
443
+ * Extracts the unscoped package name from a potentially scoped package name.
444
+ * @param name - The package name (e.g., `@scope/package` or `package`)
445
+ * @returns The unscoped name (e.g., `package`)
446
+ * @internal
447
+ */
448
+ export declare function getUnscopedPackageName(name: string): string;
449
+
417
450
  /**
418
451
  * @public
419
452
  * Node library builder class
@@ -499,7 +532,7 @@ export declare interface NodeLibraryBuilderOptions {
499
532
  * specify which packages (including transitive dependencies) should have their types bundled.
500
533
  * This is particularly useful for ensuring devDependencies are fully inlined without external imports.
501
534
  *
502
- * Supports minimatch patterns (e.g., '@pnpm/**', 'picocolors')
535
+ * Supports minimatch patterns (e.g., '\@pnpm/**', 'picocolors')
503
536
  *
504
537
  * @example
505
538
  * ```typescript
@@ -513,10 +546,10 @@ export declare interface NodeLibraryBuilderOptions {
513
546
  * Optional callback to transform files after they're built but before the files array is finalized.
514
547
  * Useful for copying/renaming files or adding additional files to the build output.
515
548
  *
516
- * @param context - Transform context containing compilation context and files set
517
- * @param context.compilation - Rspack compilation object with assets
518
- * @param context.filesArray - Set of files that will be included in package.json files field
519
- * @param context.target - Current build target (dev/npm/jsr)
549
+ * @param context - Transform context with properties:
550
+ * - `compilation`: Rspack compilation object with assets
551
+ * - `filesArray`: Set of files that will be included in package.json files field
552
+ * - `target`: Current build target (dev/npm/jsr)
520
553
  *
521
554
  * @example
522
555
  * ```typescript
@@ -564,13 +597,13 @@ export declare interface NodeLibraryBuilderOptions {
564
597
  transform?: TransformPackageJsonFn;
565
598
  /**
566
599
  * Options for API model generation.
567
- * When enabled, generates an api.model.json file in the dist directory.
600
+ * When enabled, generates an `<unscopedPackageName>.api.json` file in the dist directory.
568
601
  * Only applies when target is "npm".
569
602
  *
570
603
  * @remarks
571
- * The generated api.model.json file contains the full API documentation
604
+ * The generated API model file contains the full API documentation
572
605
  * in a machine-readable format for use by documentation generators.
573
- * A .npmignore file is also generated to exclude the API model from npm publish.
606
+ * The file is emitted to dist but excluded from npm publish (added as negated pattern in `files` array).
574
607
  *
575
608
  * @example
576
609
  * ```typescript
@@ -596,7 +629,7 @@ export declare interface NodeLibraryBuilderOptions {
596
629
  *
597
630
  * @remarks
598
631
  * This class consolidates all package.json transformation logic including:
599
- * - Path transformations (src/ -> dist/, .ts -> .js)
632
+ * - Path transformations (src/ to dist/, .ts to .js)
600
633
  * - Export conditions generation (types, import, require)
601
634
  * - Bin field transformations
602
635
  * - PNPM catalog and workspace resolution
@@ -673,9 +706,9 @@ export declare class PackageJsonTransformer {
673
706
  * Performs the complete package.json transformation.
674
707
  *
675
708
  * @param packageJson - The source package.json
676
- * @param context - Transform context
677
- * @param context.isProduction - Whether this is a production build
678
- * @param context.customTransform - Optional custom transform function
709
+ * @param context - Transform context with properties:
710
+ * - `isProduction`: Whether this is a production build
711
+ * - `customTransform`: Optional custom transform function
679
712
  * @returns The transformed package.json
680
713
  */
681
714
  transform(packageJson: PackageJson, context?: {
@@ -716,7 +749,7 @@ export declare interface PackageJsonTransformOptions {
716
749
  */
717
750
  processTSExports?: boolean;
718
751
  /**
719
- * Whether to collapse index files (./foo/index.ts -> ./foo.js).
752
+ * Whether to collapse index files (./foo/index.ts becomes ./foo.js).
720
753
  * This is typically true for bundled builds.
721
754
  * @defaultValue false
722
755
  */
@@ -809,7 +842,7 @@ export declare class PnpmCatalog {
809
842
  * @param dir - The directory containing the package (defaults to cwd)
810
843
  * @returns The resolved package.json
811
844
  *
812
- * @throws {Error} When resolution fails for critical dependencies
845
+ * @throws When resolution fails for critical dependencies
813
846
  */
814
847
  resolvePackageJson(packageJson: PackageJson, dir?: string): Promise<PackageJson>;
815
848
  /**
@@ -852,4 +885,203 @@ export declare type TransformPackageJsonFn = (context: {
852
885
  pkg: PackageJson;
853
886
  }) => PackageJson;
854
887
 
888
+ /**
889
+ * Builder for TSDoc configuration files.
890
+ * Handles tag group expansion, config generation, and file persistence.
891
+ * @public
892
+ */
893
+ export declare class TsDocConfigBuilder {
894
+ /** All available TSDoc tag groups. */
895
+ static readonly ALL_GROUPS: TsDocTagGroup[];
896
+ /** Maps group names to TSDoc Standardization enum values. */
897
+ private static readonly GROUP_TO_STANDARDIZATION;
898
+ /**
899
+ * Standard TSDoc tag definitions organized by standardization group.
900
+ * Lazily computed from `\@microsoft/tsdoc` StandardTags.
901
+ */
902
+ static readonly TAG_GROUPS: Record<TsDocTagGroup, TsDocTagDefinition[]>;
903
+ /**
904
+ * Detects if running in a CI environment.
905
+ * @returns true if CI or GITHUB_ACTIONS environment variable is "true"
906
+ */
907
+ static isCI(): boolean;
908
+ /**
909
+ * Gets standard TSDoc tag definitions for a specific group.
910
+ * Uses StandardTags from `\@microsoft/tsdoc` package.
911
+ */
912
+ static getTagsForGroup(group: TsDocTagGroup): TsDocTagDefinition[];
913
+ /**
914
+ * Determines if the TSDoc config should be persisted to disk.
915
+ * @param persistConfig - The persistConfig option value
916
+ * @returns true if the config should be persisted
917
+ */
918
+ static shouldPersist(persistConfig: boolean | PathLike | undefined): boolean;
919
+ /**
920
+ * Gets the output path for the tsdoc.json file.
921
+ * @param persistConfig - The persistConfig option value
922
+ * @param cwd - The current working directory
923
+ * @returns The absolute path where tsdoc.json should be written
924
+ */
925
+ static getConfigPath(persistConfig: boolean | PathLike | undefined, cwd: string): string;
926
+ /**
927
+ * Builds the complete TSDoc configuration from options.
928
+ *
929
+ * @remarks
930
+ * When all groups are enabled (default), returns `useStandardTags: true` to signal
931
+ * that the generated config should use `noStandardTags: false` and let TSDoc
932
+ * automatically load all standard tags. However, `supportForTags` is still populated
933
+ * because API Extractor requires explicit support declarations for each tag.
934
+ *
935
+ * When a subset of groups is specified, returns `useStandardTags: false` to signal
936
+ * that we must explicitly define which tags to include via `noStandardTags: true`.
937
+ */
938
+ static build(options?: TsDocOptions): {
939
+ tagDefinitions: TsDocTagDefinition[];
940
+ supportForTags: Record<string, boolean>;
941
+ useStandardTags: boolean;
942
+ };
943
+ /**
944
+ * Generates a tsdoc.json file from options.
945
+ *
946
+ * @remarks
947
+ * When all groups are enabled (default), generates a minimal config with
948
+ * `noStandardTags: false` so TSDoc automatically loads all standard tags.
949
+ * Only custom tags need to be defined in this case.
950
+ *
951
+ * When a subset of groups is specified, generates a config with
952
+ * `noStandardTags: true` and explicitly defines only the tags from
953
+ * the enabled groups.
954
+ */
955
+ static writeConfigFile(options: TsDocOptions | undefined, outputDir: string): Promise<string>;
956
+ /** Converts TSDocTagSyntaxKind enum to string format. */
957
+ private static syntaxKindToString;
958
+ }
959
+
960
+ /**
961
+ * Options for tsdoc-metadata.json generation.
962
+ * @public
963
+ */
964
+ export declare interface TsDocMetadataOptions {
965
+ /**
966
+ * Whether to generate tsdoc-metadata.json.
967
+ * @defaultValue true (when apiModel is enabled)
968
+ */
969
+ enabled?: boolean;
970
+ /**
971
+ * Custom filename for the TSDoc metadata file.
972
+ * @defaultValue "tsdoc-metadata.json"
973
+ */
974
+ filename?: string;
975
+ }
976
+
977
+ /**
978
+ * TSDoc configuration options for API Extractor.
979
+ * @remarks
980
+ * Provides ergonomic defaults - standard tags are auto-enabled via `groups`,
981
+ * custom tags are auto-supported, and `supportForTags` is only needed to
982
+ * disable specific tags.
983
+ *
984
+ * **Config optimization:** When all groups are enabled (default), the generated
985
+ * `tsdoc.json` uses `noStandardTags: false` to let TSDoc automatically load
986
+ * all standard tags, producing a minimal config file. When a subset of groups
987
+ * is specified, `noStandardTags: true` is used and only the enabled groups'
988
+ * tags are explicitly defined.
989
+ *
990
+ * @public
991
+ */
992
+ export declare interface TsDocOptions {
993
+ /**
994
+ * TSDoc tag groups to enable. Each group includes predefined standard tags
995
+ * from the official `\@microsoft/tsdoc` package.
996
+ * - "core": Essential TSDoc tags (\@param, \@returns, \@remarks, \@deprecated, etc.)
997
+ * - "extended": Additional tags (\@example, \@defaultValue, \@see, \@throws, etc.)
998
+ * - "discretionary": Release stage tags (\@alpha, \@beta, \@public, \@internal)
999
+ *
1000
+ * @remarks
1001
+ * When all groups are enabled (the default), the generated config uses
1002
+ * `noStandardTags: false` and TSDoc loads standard tags automatically.
1003
+ * When a subset is specified, `noStandardTags: true` is used and only
1004
+ * the tags from enabled groups are defined.
1005
+ *
1006
+ * @defaultValue ["core", "extended", "discretionary"]
1007
+ */
1008
+ groups?: TsDocTagGroup[];
1009
+ /**
1010
+ * Custom TSDoc tag definitions beyond the standard groups.
1011
+ * These are automatically added to supportForTags (no need to declare twice).
1012
+ *
1013
+ * @example
1014
+ * ```typescript
1015
+ * tagDefinitions: [
1016
+ * { tagName: "@error", syntaxKind: "inline" },
1017
+ * { tagName: "@category", syntaxKind: "block", allowMultiple: false }
1018
+ * ]
1019
+ * ```
1020
+ */
1021
+ tagDefinitions?: TsDocTagDefinition[];
1022
+ /**
1023
+ * Override support for specific tags. Only needed to DISABLE tags.
1024
+ * Tags from enabled groups and custom tagDefinitions are auto-supported.
1025
+ *
1026
+ * @example
1027
+ * ```typescript
1028
+ * // Disable @beta even though "extended" group is enabled
1029
+ * supportForTags: { "@beta": false }
1030
+ * ```
1031
+ */
1032
+ supportForTags?: Record<string, boolean>;
1033
+ /**
1034
+ * Persist tsdoc.json to disk for tool integration (ESLint, IDEs).
1035
+ * - `true`: Write to project root as "tsdoc.json"
1036
+ * - `PathLike`: Write to specified path
1037
+ * - `false`: Clean up after API Extractor
1038
+ *
1039
+ * @defaultValue `true` when `CI` and `GITHUB_ACTIONS` env vars are not "true",
1040
+ * `false` otherwise (CI environments)
1041
+ */
1042
+ persistConfig?: boolean | PathLike;
1043
+ /**
1044
+ * How to handle TSDoc validation warnings from API Extractor.
1045
+ * - `"log"`: Show warnings in the console but continue the build
1046
+ * - `"fail"`: Show warnings and fail the build if any are found
1047
+ * - `"none"`: Suppress TSDoc warnings entirely
1048
+ *
1049
+ * @remarks
1050
+ * TSDoc warnings include unknown tags, malformed syntax, and other
1051
+ * documentation issues detected by API Extractor during processing.
1052
+ *
1053
+ * @example
1054
+ * ```typescript
1055
+ * // Fail build on any TSDoc issues (CI default)
1056
+ * warnings: "fail"
1057
+ *
1058
+ * // Show warnings but continue build (local default)
1059
+ * warnings: "log"
1060
+ * ```
1061
+ *
1062
+ * @defaultValue `"fail"` in CI environments (`CI` or `GITHUB_ACTIONS` env vars),
1063
+ * `"log"` otherwise
1064
+ */
1065
+ warnings?: "log" | "fail" | "none";
1066
+ }
1067
+
1068
+ /**
1069
+ * TSDoc tag definition for custom documentation tags.
1070
+ * @public
1071
+ */
1072
+ export declare interface TsDocTagDefinition {
1073
+ /** The tag name including the at-sign prefix (e.g., `\@error`, `\@category`) */
1074
+ tagName: string;
1075
+ /** How the tag is parsed: "block" | "inline" | "modifier" */
1076
+ syntaxKind: "block" | "inline" | "modifier";
1077
+ /** Whether the tag can appear multiple times on a declaration */
1078
+ allowMultiple?: boolean;
1079
+ }
1080
+
1081
+ /**
1082
+ * TSDoc standardization groups for predefined tag sets.
1083
+ * @public
1084
+ */
1085
+ export declare type TsDocTagGroup = "core" | "extended" | "discretionary";
1086
+
855
1087
  export { }