@savvy-web/rslib-builder 0.3.0 → 0.5.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 +64 -18
- package/index.d.ts +1118 -3
- package/index.js +441 -11
- package/package.json +14 -7
- package/tsconfig/ecma/lib.json +1 -1
package/index.d.ts
CHANGED
|
@@ -40,12 +40,11 @@
|
|
|
40
40
|
*/
|
|
41
41
|
|
|
42
42
|
import type { ConfigParams } from '@rslib/core';
|
|
43
|
-
import type { PackageJson } from 'type-fest';
|
|
44
43
|
import type { PathLike } from 'node:fs';
|
|
45
|
-
import type { RawCopyPattern } from '@rspack/binding';
|
|
46
44
|
import type { RsbuildPlugin } from '@rsbuild/core';
|
|
47
45
|
import type { RslibConfig } from '@rslib/core';
|
|
48
46
|
import type { SourceConfig } from '@rsbuild/core';
|
|
47
|
+
import ts from 'typescript';
|
|
49
48
|
|
|
50
49
|
/**
|
|
51
50
|
* Options for API model generation.
|
|
@@ -227,6 +226,52 @@ export declare interface AutoEntryPluginOptions {
|
|
|
227
226
|
*/
|
|
228
227
|
export declare type BuildTarget = "dev" | "npm";
|
|
229
228
|
|
|
229
|
+
/**
|
|
230
|
+
* Configuration for copying files during the build process.
|
|
231
|
+
*
|
|
232
|
+
* @remarks
|
|
233
|
+
* This interface mirrors rspack's copy pattern configuration and is passed directly
|
|
234
|
+
* to the rspack CopyPlugin. All properties except `from` are optional.
|
|
235
|
+
*
|
|
236
|
+
* @example
|
|
237
|
+
* ```typescript
|
|
238
|
+
* // Copy a directory
|
|
239
|
+
* { from: "./public", to: "./", context: process.cwd() }
|
|
240
|
+
*
|
|
241
|
+
* // Copy specific files
|
|
242
|
+
* { from: "**\/*.json", to: "./config" }
|
|
243
|
+
* ```
|
|
244
|
+
*
|
|
245
|
+
* @public
|
|
246
|
+
*/
|
|
247
|
+
export declare interface CopyPatternConfig {
|
|
248
|
+
/** Source path or glob pattern to copy from */
|
|
249
|
+
from: string;
|
|
250
|
+
/** Destination path (relative to output directory) */
|
|
251
|
+
to?: string;
|
|
252
|
+
/** Base directory for resolving `from` path */
|
|
253
|
+
context?: string;
|
|
254
|
+
/** Type of destination: "dir", "file", or "template" */
|
|
255
|
+
toType?: "dir" | "file" | "template";
|
|
256
|
+
/** If true, does not emit an error if the source is missing */
|
|
257
|
+
noErrorOnMissing?: boolean;
|
|
258
|
+
/** Glob options for pattern matching */
|
|
259
|
+
globOptions?: {
|
|
260
|
+
/** Patterns to ignore */
|
|
261
|
+
ignore?: string[];
|
|
262
|
+
/** Whether to match dotfiles */
|
|
263
|
+
dot?: boolean;
|
|
264
|
+
};
|
|
265
|
+
/** Filter function to include/exclude files */
|
|
266
|
+
filter?: (filepath: string) => boolean | Promise<boolean>;
|
|
267
|
+
/** Transform function to modify file contents */
|
|
268
|
+
transform?: {
|
|
269
|
+
transformer: (input: Buffer, absoluteFilename: string) => string | Buffer | Promise<string> | Promise<Buffer>;
|
|
270
|
+
} | ((input: Buffer, absoluteFilename: string) => string | Buffer | Promise<string> | Promise<Buffer>);
|
|
271
|
+
/** Priority for conflicting files (higher = higher priority) */
|
|
272
|
+
priority?: number;
|
|
273
|
+
}
|
|
274
|
+
|
|
230
275
|
/**
|
|
231
276
|
* Plugin to generate TypeScript declaration files using tsgo and emit them through Rslib's asset pipeline.
|
|
232
277
|
*
|
|
@@ -458,6 +503,439 @@ export declare interface FilesArrayPluginOptions<TTarget extends string = string
|
|
|
458
503
|
target: TTarget;
|
|
459
504
|
}
|
|
460
505
|
|
|
506
|
+
/**
|
|
507
|
+
* Analyzes TypeScript import relationships to discover all files
|
|
508
|
+
* reachable from specified entry points.
|
|
509
|
+
*
|
|
510
|
+
* @remarks
|
|
511
|
+
* This class uses the TypeScript compiler API to trace import statements
|
|
512
|
+
* and discover all files that are part of the public API. It handles:
|
|
513
|
+
*
|
|
514
|
+
* - Static imports: `import { foo } from "./module"`
|
|
515
|
+
* - Dynamic imports: `import("./module")`
|
|
516
|
+
* - Re-exports: `export * from "./module"` and `export { foo } from "./module"`
|
|
517
|
+
* - Circular imports (via visited set tracking)
|
|
518
|
+
*
|
|
519
|
+
* The class automatically filters out:
|
|
520
|
+
* - Files in node_modules
|
|
521
|
+
* - Declaration files (.d.ts)
|
|
522
|
+
* - Test files (*.test.ts, *.spec.ts)
|
|
523
|
+
* - Files in __test__ directories
|
|
524
|
+
*
|
|
525
|
+
* ## Static Methods vs Instance Methods
|
|
526
|
+
*
|
|
527
|
+
* For simple one-off analysis, use the static convenience methods:
|
|
528
|
+
* - {@link ImportGraph.fromEntries} - Trace from explicit entry paths
|
|
529
|
+
* - {@link ImportGraph.fromPackageExports} - Trace from package.json exports
|
|
530
|
+
*
|
|
531
|
+
* For repeated analysis or custom configuration, create an instance
|
|
532
|
+
* and use the instance methods which reuse the TypeScript program.
|
|
533
|
+
*
|
|
534
|
+
* @example
|
|
535
|
+
* Using static methods (recommended for most cases):
|
|
536
|
+
* ```typescript
|
|
537
|
+
* import { ImportGraph } from '@savvy-web/rslib-builder';
|
|
538
|
+
*
|
|
539
|
+
* // Trace from explicit entries
|
|
540
|
+
* const result = ImportGraph.fromEntries(
|
|
541
|
+
* ['./src/index.ts', './src/cli.ts'],
|
|
542
|
+
* { rootDir: process.cwd() }
|
|
543
|
+
* );
|
|
544
|
+
*
|
|
545
|
+
* // Trace from package.json exports
|
|
546
|
+
* const result = ImportGraph.fromPackageExports(
|
|
547
|
+
* './package.json',
|
|
548
|
+
* { rootDir: process.cwd() }
|
|
549
|
+
* );
|
|
550
|
+
* ```
|
|
551
|
+
*
|
|
552
|
+
* @example
|
|
553
|
+
* Using instance methods (for repeated analysis):
|
|
554
|
+
* ```typescript
|
|
555
|
+
* import { ImportGraph } from '@savvy-web/rslib-builder';
|
|
556
|
+
*
|
|
557
|
+
* const graph = new ImportGraph({ rootDir: '/path/to/project' });
|
|
558
|
+
*
|
|
559
|
+
* // Reuses the TypeScript program across multiple calls
|
|
560
|
+
* const libResult = graph.traceFromEntries(['./src/index.ts']);
|
|
561
|
+
* const cliResult = graph.traceFromEntries(['./src/cli.ts']);
|
|
562
|
+
* ```
|
|
563
|
+
*
|
|
564
|
+
* @public
|
|
565
|
+
*/
|
|
566
|
+
export declare class ImportGraph {
|
|
567
|
+
private readonly options;
|
|
568
|
+
private readonly sys;
|
|
569
|
+
private program;
|
|
570
|
+
private compilerOptions;
|
|
571
|
+
private moduleResolutionCache;
|
|
572
|
+
constructor(options: ImportGraphOptions);
|
|
573
|
+
/**
|
|
574
|
+
* Trace all imports from the given entry points.
|
|
575
|
+
*
|
|
576
|
+
* @param entryPaths - Paths to entry files (relative to rootDir or absolute)
|
|
577
|
+
* @returns Deduplicated list of all reachable TypeScript files
|
|
578
|
+
*/
|
|
579
|
+
traceFromEntries(entryPaths: string[]): ImportGraphResult;
|
|
580
|
+
/**
|
|
581
|
+
* Trace imports from package.json exports.
|
|
582
|
+
*
|
|
583
|
+
* @remarks
|
|
584
|
+
* Convenience method that extracts entry points from package.json
|
|
585
|
+
* using EntryExtractor, then traces all imports from those entries.
|
|
586
|
+
*
|
|
587
|
+
* @param packageJsonPath - Path to package.json (relative to rootDir or absolute)
|
|
588
|
+
* @returns Deduplicated list of all reachable TypeScript files
|
|
589
|
+
*/
|
|
590
|
+
traceFromPackageExports(packageJsonPath: string): ImportGraphResult;
|
|
591
|
+
/**
|
|
592
|
+
* Initialize the TypeScript program for module resolution.
|
|
593
|
+
*/
|
|
594
|
+
private initializeProgram;
|
|
595
|
+
/**
|
|
596
|
+
* Find tsconfig.json path.
|
|
597
|
+
*/
|
|
598
|
+
private findTsConfig;
|
|
599
|
+
/**
|
|
600
|
+
* Resolve entry path to absolute path.
|
|
601
|
+
*/
|
|
602
|
+
private resolveEntryPath;
|
|
603
|
+
/**
|
|
604
|
+
* Recursively trace imports from a source file.
|
|
605
|
+
*/
|
|
606
|
+
private traceImports;
|
|
607
|
+
/**
|
|
608
|
+
* Extract all import/export module specifiers from a source file.
|
|
609
|
+
*/
|
|
610
|
+
private extractImports;
|
|
611
|
+
/**
|
|
612
|
+
* Resolve a module specifier to an absolute file path.
|
|
613
|
+
*/
|
|
614
|
+
private resolveImport;
|
|
615
|
+
/**
|
|
616
|
+
* Check if a path is an external module (node_modules).
|
|
617
|
+
*/
|
|
618
|
+
private isExternalModule;
|
|
619
|
+
/**
|
|
620
|
+
* Check if a file should be included in results.
|
|
621
|
+
* Filters out test files and non-TypeScript files.
|
|
622
|
+
*/
|
|
623
|
+
private isSourceFile;
|
|
624
|
+
/**
|
|
625
|
+
* Traces TypeScript imports from entry points.
|
|
626
|
+
*
|
|
627
|
+
* @remarks
|
|
628
|
+
* Static convenience method that creates an ImportGraph instance
|
|
629
|
+
* and traces imports in one call. For repeated analysis where you want
|
|
630
|
+
* to reuse the TypeScript program, create an instance and use
|
|
631
|
+
* {@link ImportGraph.traceFromEntries} instead.
|
|
632
|
+
*
|
|
633
|
+
* @param entryPaths - Paths to entry files (relative to rootDir or absolute)
|
|
634
|
+
* @param options - Import graph configuration options
|
|
635
|
+
* @returns All TypeScript files reachable from the entries
|
|
636
|
+
*
|
|
637
|
+
* @example
|
|
638
|
+
* ```typescript
|
|
639
|
+
* import { ImportGraph } from '@savvy-web/rslib-builder';
|
|
640
|
+
*
|
|
641
|
+
* const result = ImportGraph.fromEntries(
|
|
642
|
+
* ['./src/index.ts', './src/cli.ts'],
|
|
643
|
+
* { rootDir: process.cwd() }
|
|
644
|
+
* );
|
|
645
|
+
* console.log('Found files:', result.files);
|
|
646
|
+
* ```
|
|
647
|
+
*/
|
|
648
|
+
static fromEntries(entryPaths: string[], options: ImportGraphOptions): ImportGraphResult;
|
|
649
|
+
/**
|
|
650
|
+
* Traces TypeScript imports from package.json exports.
|
|
651
|
+
*
|
|
652
|
+
* @remarks
|
|
653
|
+
* Static convenience method that extracts entry points from package.json exports
|
|
654
|
+
* and traces all imports to find public API files. For repeated analysis,
|
|
655
|
+
* create an instance and use {@link ImportGraph.traceFromPackageExports} instead.
|
|
656
|
+
*
|
|
657
|
+
* @param packageJsonPath - Path to package.json (relative to rootDir or absolute)
|
|
658
|
+
* @param options - Import graph configuration options
|
|
659
|
+
* @returns All TypeScript files reachable from the package exports
|
|
660
|
+
*
|
|
661
|
+
* @example
|
|
662
|
+
* ```typescript
|
|
663
|
+
* import { ImportGraph } from '@savvy-web/rslib-builder';
|
|
664
|
+
*
|
|
665
|
+
* const result = ImportGraph.fromPackageExports(
|
|
666
|
+
* './package.json',
|
|
667
|
+
* { rootDir: process.cwd() }
|
|
668
|
+
* );
|
|
669
|
+
* console.log('Public API files:', result.files);
|
|
670
|
+
* ```
|
|
671
|
+
*/
|
|
672
|
+
static fromPackageExports(packageJsonPath: string, options: ImportGraphOptions): ImportGraphResult;
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
/**
|
|
676
|
+
* Structured error from import graph analysis.
|
|
677
|
+
*
|
|
678
|
+
* @remarks
|
|
679
|
+
* Provides detailed error information including the error type for
|
|
680
|
+
* programmatic handling, a human-readable message, and the relevant
|
|
681
|
+
* file path when applicable.
|
|
682
|
+
*
|
|
683
|
+
* @example
|
|
684
|
+
* ```typescript
|
|
685
|
+
* import type { ImportGraphError } from '@savvy-web/rslib-builder';
|
|
686
|
+
*
|
|
687
|
+
* function handleErrors(errors: ImportGraphError[]): void {
|
|
688
|
+
* for (const error of errors) {
|
|
689
|
+
* switch (error.type) {
|
|
690
|
+
* case 'tsconfig_not_found':
|
|
691
|
+
* console.warn('No tsconfig.json found, using defaults');
|
|
692
|
+
* break;
|
|
693
|
+
* case 'entry_not_found':
|
|
694
|
+
* console.error(`Missing entry: ${error.path}`);
|
|
695
|
+
* break;
|
|
696
|
+
* default:
|
|
697
|
+
* console.error(error.message);
|
|
698
|
+
* }
|
|
699
|
+
* }
|
|
700
|
+
* }
|
|
701
|
+
* ```
|
|
702
|
+
*
|
|
703
|
+
* @public
|
|
704
|
+
*/
|
|
705
|
+
export declare interface ImportGraphError {
|
|
706
|
+
/**
|
|
707
|
+
* The type of error that occurred.
|
|
708
|
+
*
|
|
709
|
+
* @remarks
|
|
710
|
+
* Use this field for programmatic error handling to distinguish
|
|
711
|
+
* between different failure modes.
|
|
712
|
+
*/
|
|
713
|
+
type: ImportGraphErrorType;
|
|
714
|
+
/**
|
|
715
|
+
* Human-readable error message.
|
|
716
|
+
*
|
|
717
|
+
* @remarks
|
|
718
|
+
* Suitable for logging or displaying to users.
|
|
719
|
+
*/
|
|
720
|
+
message: string;
|
|
721
|
+
/**
|
|
722
|
+
* The file path related to the error, if applicable.
|
|
723
|
+
*
|
|
724
|
+
* @remarks
|
|
725
|
+
* Present for errors related to specific files like missing entries
|
|
726
|
+
* or file read failures.
|
|
727
|
+
*/
|
|
728
|
+
path?: string;
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
/**
|
|
732
|
+
* Types of errors that can occur during import graph analysis.
|
|
733
|
+
*
|
|
734
|
+
* @remarks
|
|
735
|
+
* These error types allow consumers to handle different failure modes
|
|
736
|
+
* appropriately. For example, a missing tsconfig might be handled differently
|
|
737
|
+
* than a missing entry file.
|
|
738
|
+
*
|
|
739
|
+
* @public
|
|
740
|
+
*/
|
|
741
|
+
export declare type ImportGraphErrorType = "tsconfig_not_found" | "tsconfig_read_error" | "tsconfig_parse_error" | "package_json_not_found" | "package_json_parse_error" | "entry_not_found" | "file_read_error";
|
|
742
|
+
|
|
743
|
+
/**
|
|
744
|
+
* Options for configuring the ImportGraph analyzer.
|
|
745
|
+
*
|
|
746
|
+
* @remarks
|
|
747
|
+
* These options control how the ImportGraph traverses and resolves
|
|
748
|
+
* TypeScript module imports. The `rootDir` is required and serves as
|
|
749
|
+
* the base for resolving relative paths and finding the tsconfig.json.
|
|
750
|
+
*
|
|
751
|
+
* @example
|
|
752
|
+
* ```typescript
|
|
753
|
+
* import type { ImportGraphOptions } from '@savvy-web/rslib-builder';
|
|
754
|
+
*
|
|
755
|
+
* const options: ImportGraphOptions = {
|
|
756
|
+
* rootDir: '/path/to/project',
|
|
757
|
+
* tsconfigPath: './tsconfig.build.json',
|
|
758
|
+
* };
|
|
759
|
+
* ```
|
|
760
|
+
*
|
|
761
|
+
* @public
|
|
762
|
+
*/
|
|
763
|
+
export declare interface ImportGraphOptions {
|
|
764
|
+
/**
|
|
765
|
+
* The project root directory.
|
|
766
|
+
*
|
|
767
|
+
* @remarks
|
|
768
|
+
* All relative paths (entry points, tsconfig path) are resolved from this directory.
|
|
769
|
+
* This should typically be the package root containing your `package.json`.
|
|
770
|
+
*/
|
|
771
|
+
rootDir: string;
|
|
772
|
+
/**
|
|
773
|
+
* Custom path to the TypeScript configuration file.
|
|
774
|
+
*
|
|
775
|
+
* @remarks
|
|
776
|
+
* If not provided, the analyzer searches for `tsconfig.json` starting from `rootDir`
|
|
777
|
+
* and walking up the directory tree. The tsconfig is used for module resolution
|
|
778
|
+
* settings including path aliases and module resolution strategy.
|
|
779
|
+
*
|
|
780
|
+
* @defaultValue Searches for tsconfig.json from rootDir
|
|
781
|
+
*/
|
|
782
|
+
tsconfigPath?: string;
|
|
783
|
+
/**
|
|
784
|
+
* Custom TypeScript system for file operations.
|
|
785
|
+
*
|
|
786
|
+
* @remarks
|
|
787
|
+
* This is primarily used for testing to provide a mock filesystem.
|
|
788
|
+
* In production use, this defaults to `ts.sys` which uses the real filesystem.
|
|
789
|
+
*
|
|
790
|
+
* @defaultValue ts.sys
|
|
791
|
+
* @internal
|
|
792
|
+
*/
|
|
793
|
+
sys?: ts.System;
|
|
794
|
+
/**
|
|
795
|
+
* Additional patterns to exclude from results.
|
|
796
|
+
*
|
|
797
|
+
* @remarks
|
|
798
|
+
* Patterns are matched against file paths using simple string inclusion.
|
|
799
|
+
* Use this to exclude files that don't match the default test file patterns.
|
|
800
|
+
*
|
|
801
|
+
* The default exclusions are always applied:
|
|
802
|
+
* - `.test.` and `.spec.` files
|
|
803
|
+
* - `__test__` and `__tests__` directories
|
|
804
|
+
* - `.d.ts` declaration files
|
|
805
|
+
*
|
|
806
|
+
* @example
|
|
807
|
+
* ```typescript
|
|
808
|
+
* const graph = new ImportGraph({
|
|
809
|
+
* rootDir: process.cwd(),
|
|
810
|
+
* excludePatterns: ['/fixtures/', '/mocks/', '.stories.'],
|
|
811
|
+
* });
|
|
812
|
+
* ```
|
|
813
|
+
*
|
|
814
|
+
* @defaultValue []
|
|
815
|
+
*/
|
|
816
|
+
excludePatterns?: string[];
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
/**
|
|
820
|
+
* Result of import graph analysis.
|
|
821
|
+
*
|
|
822
|
+
* @remarks
|
|
823
|
+
* Contains the complete set of TypeScript source files discovered by tracing
|
|
824
|
+
* imports from entry points. The analysis is non-fatal: errors are collected
|
|
825
|
+
* and tracing continues for other paths even when some imports fail to resolve.
|
|
826
|
+
*
|
|
827
|
+
* @example
|
|
828
|
+
* ```typescript
|
|
829
|
+
* import type { ImportGraphResult } from '@savvy-web/rslib-builder';
|
|
830
|
+
*
|
|
831
|
+
* function processResult(result: ImportGraphResult): void {
|
|
832
|
+
* if (result.errors.length > 0) {
|
|
833
|
+
* console.warn('Some imports could not be resolved:', result.errors);
|
|
834
|
+
* }
|
|
835
|
+
* console.log(`Found ${result.files.length} files from ${result.entries.length} entries`);
|
|
836
|
+
* }
|
|
837
|
+
* ```
|
|
838
|
+
*
|
|
839
|
+
* @public
|
|
840
|
+
*/
|
|
841
|
+
export declare interface ImportGraphResult {
|
|
842
|
+
/**
|
|
843
|
+
* All TypeScript source files reachable from the entry points.
|
|
844
|
+
*
|
|
845
|
+
* @remarks
|
|
846
|
+
* Paths are absolute, normalized, and sorted alphabetically.
|
|
847
|
+
* Test files (`.test.ts`, `.spec.ts`) and test directories (`__test__`, `__tests__`)
|
|
848
|
+
* are automatically filtered out from results.
|
|
849
|
+
*/
|
|
850
|
+
files: string[];
|
|
851
|
+
/**
|
|
852
|
+
* The entry points that were traced.
|
|
853
|
+
*
|
|
854
|
+
* @remarks
|
|
855
|
+
* Paths are absolute and normalized. These are the starting points
|
|
856
|
+
* from which the import graph was traversed.
|
|
857
|
+
*/
|
|
858
|
+
entries: string[];
|
|
859
|
+
/**
|
|
860
|
+
* Errors encountered during import graph analysis.
|
|
861
|
+
*
|
|
862
|
+
* @remarks
|
|
863
|
+
* These errors are non-fatal: tracing continues despite individual failures.
|
|
864
|
+
* Common errors include missing entry files, unresolvable imports,
|
|
865
|
+
* or tsconfig parsing failures.
|
|
866
|
+
*
|
|
867
|
+
* Each error includes a `type` field for programmatic handling and
|
|
868
|
+
* a human-readable `message`. Some errors also include a `path` field
|
|
869
|
+
* indicating the relevant file.
|
|
870
|
+
*/
|
|
871
|
+
errors: ImportGraphError[];
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
/**
|
|
875
|
+
* Matches a JSON array.
|
|
876
|
+
*
|
|
877
|
+
* @public
|
|
878
|
+
*/
|
|
879
|
+
export declare type JsonArray = JsonValue[] | readonly JsonValue[];
|
|
880
|
+
|
|
881
|
+
/**
|
|
882
|
+
* Matches a JSON object.
|
|
883
|
+
*
|
|
884
|
+
* @remarks
|
|
885
|
+
* This type can be useful to enforce some input to be JSON-compatible or as a
|
|
886
|
+
* super-type to be extended from.
|
|
887
|
+
*
|
|
888
|
+
* @public
|
|
889
|
+
*/
|
|
890
|
+
export declare type JsonObject = {
|
|
891
|
+
[Key in string]: JsonValue;
|
|
892
|
+
};
|
|
893
|
+
|
|
894
|
+
/**
|
|
895
|
+
* Package.json type definitions.
|
|
896
|
+
*
|
|
897
|
+
* @remarks
|
|
898
|
+
* This is a local copy of type-fest's PackageJson types with TSDoc fixes.
|
|
899
|
+
* Original source: https://github.com/sindresorhus/type-fest
|
|
900
|
+
*
|
|
901
|
+
* TSDoc fixes applied:
|
|
902
|
+
* - Added deprecation messages to `@deprecated` tags
|
|
903
|
+
* - Fixed code fence formatting in `packageManager` docs
|
|
904
|
+
*
|
|
905
|
+
*/
|
|
906
|
+
/**
|
|
907
|
+
* Matches any valid JSON primitive value.
|
|
908
|
+
*
|
|
909
|
+
* @public
|
|
910
|
+
*/
|
|
911
|
+
export declare type JsonPrimitive = string | number | boolean | null;
|
|
912
|
+
|
|
913
|
+
/**
|
|
914
|
+
* Matches any valid JSON value.
|
|
915
|
+
*
|
|
916
|
+
* @public
|
|
917
|
+
*/
|
|
918
|
+
export declare type JsonValue = JsonPrimitive | JsonObject | JsonArray;
|
|
919
|
+
|
|
920
|
+
/**
|
|
921
|
+
* Allows creating a union type by combining primitive types and literal types
|
|
922
|
+
* without sacrificing auto-completion in IDEs for the literal type part of the union.
|
|
923
|
+
*
|
|
924
|
+
* @remarks
|
|
925
|
+
* Currently, when a union type of a primitive type is combined with literal types,
|
|
926
|
+
* TypeScript loses all information about the combined literals. Thus, when such
|
|
927
|
+
* type is used in an IDE with autocompletion, no suggestions are made for the
|
|
928
|
+
* declared literals.
|
|
929
|
+
*
|
|
930
|
+
* This type is a workaround for Microsoft/TypeScript#29729.
|
|
931
|
+
*
|
|
932
|
+
* @typeParam LiteralType - The literal type(s) to include
|
|
933
|
+
* @typeParam BaseType - The base primitive type
|
|
934
|
+
*
|
|
935
|
+
* @public
|
|
936
|
+
*/
|
|
937
|
+
declare type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
|
|
938
|
+
|
|
461
939
|
/**
|
|
462
940
|
* Builder for Node.js ESM libraries using RSlib.
|
|
463
941
|
*
|
|
@@ -560,7 +1038,7 @@ export declare interface NodeLibraryBuilderOptions {
|
|
|
560
1038
|
* ```
|
|
561
1039
|
*/
|
|
562
1040
|
exportsAsIndexes?: boolean;
|
|
563
|
-
copyPatterns: (string |
|
|
1041
|
+
copyPatterns: (string | CopyPatternConfig)[];
|
|
564
1042
|
/** Additional plugins */
|
|
565
1043
|
plugins: RsbuildPlugin[];
|
|
566
1044
|
define: SourceConfig["define"];
|
|
@@ -696,8 +1174,471 @@ export declare interface NodeLibraryBuilderOptions {
|
|
|
696
1174
|
* ```
|
|
697
1175
|
*/
|
|
698
1176
|
apiModel?: ApiModelOptions | boolean;
|
|
1177
|
+
/**
|
|
1178
|
+
* Options for TSDoc lint validation.
|
|
1179
|
+
* When enabled, validates TSDoc comments before the build starts.
|
|
1180
|
+
*
|
|
1181
|
+
* @remarks
|
|
1182
|
+
* Uses ESLint with `eslint-plugin-tsdoc` to validate TSDoc syntax.
|
|
1183
|
+
* By default, throws errors in CI environments and logs errors locally.
|
|
1184
|
+
* The generated `tsdoc.json` config is persisted locally for IDE integration.
|
|
1185
|
+
*
|
|
1186
|
+
* @example
|
|
1187
|
+
* Enable with defaults (throws in CI, errors locally):
|
|
1188
|
+
* ```typescript
|
|
1189
|
+
* import { NodeLibraryBuilder } from '@savvy-web/rslib-builder';
|
|
1190
|
+
*
|
|
1191
|
+
* export default NodeLibraryBuilder.create({
|
|
1192
|
+
* tsdocLint: true,
|
|
1193
|
+
* });
|
|
1194
|
+
* ```
|
|
1195
|
+
*
|
|
1196
|
+
* @example
|
|
1197
|
+
* Enable with custom configuration:
|
|
1198
|
+
* ```typescript
|
|
1199
|
+
* import { NodeLibraryBuilder } from '@savvy-web/rslib-builder';
|
|
1200
|
+
*
|
|
1201
|
+
* export default NodeLibraryBuilder.create({
|
|
1202
|
+
* tsdocLint: {
|
|
1203
|
+
* tsdoc: {
|
|
1204
|
+
* tagDefinitions: [{ tagName: '@error', syntaxKind: 'block' }],
|
|
1205
|
+
* },
|
|
1206
|
+
* onError: 'throw',
|
|
1207
|
+
* persistConfig: true,
|
|
1208
|
+
* },
|
|
1209
|
+
* });
|
|
1210
|
+
* ```
|
|
1211
|
+
*/
|
|
1212
|
+
tsdocLint?: TsDocLintPluginOptions | boolean;
|
|
699
1213
|
}
|
|
700
1214
|
|
|
1215
|
+
/**
|
|
1216
|
+
* PackageJson namespace containing all sub-types.
|
|
1217
|
+
*
|
|
1218
|
+
* @public
|
|
1219
|
+
*/
|
|
1220
|
+
export declare namespace PackageJson {
|
|
1221
|
+
/**
|
|
1222
|
+
* A person who has been involved in creating or maintaining the package.
|
|
1223
|
+
*/
|
|
1224
|
+
export type Person = string | {
|
|
1225
|
+
name: string;
|
|
1226
|
+
url?: string;
|
|
1227
|
+
email?: string;
|
|
1228
|
+
};
|
|
1229
|
+
/**
|
|
1230
|
+
* Location for reporting bugs.
|
|
1231
|
+
*/
|
|
1232
|
+
export type BugsLocation = string | {
|
|
1233
|
+
/** The URL to the package's issue tracker. */
|
|
1234
|
+
url?: string;
|
|
1235
|
+
/** The email address to which issues should be reported. */
|
|
1236
|
+
email?: string;
|
|
1237
|
+
};
|
|
1238
|
+
/**
|
|
1239
|
+
* Directory locations within the package.
|
|
1240
|
+
*/
|
|
1241
|
+
export interface DirectoryLocations {
|
|
1242
|
+
[directoryType: string]: JsonValue | undefined;
|
|
1243
|
+
/** Location for executable scripts. Sugar to generate entries in the `bin` property by walking the folder. */
|
|
1244
|
+
bin?: string;
|
|
1245
|
+
/** Location for Markdown files. */
|
|
1246
|
+
doc?: string;
|
|
1247
|
+
/** Location for example scripts. */
|
|
1248
|
+
example?: string;
|
|
1249
|
+
/** Location for the bulk of the library. */
|
|
1250
|
+
lib?: string;
|
|
1251
|
+
/** Location for man pages. Sugar to generate a `man` array by walking the folder. */
|
|
1252
|
+
man?: string;
|
|
1253
|
+
/** Location for test files. */
|
|
1254
|
+
test?: string;
|
|
1255
|
+
}
|
|
1256
|
+
/**
|
|
1257
|
+
* Script commands that are run at various times in the lifecycle of the package.
|
|
1258
|
+
*/
|
|
1259
|
+
export type Scripts = {
|
|
1260
|
+
/** Run before the package is published (Also run on local `npm install` without any arguments). */
|
|
1261
|
+
prepublish?: string;
|
|
1262
|
+
/** Run both before the package is packed and published, and on local `npm install` without any arguments. */
|
|
1263
|
+
prepare?: string;
|
|
1264
|
+
/** Run before the package is prepared and packed, only on `npm publish`. */
|
|
1265
|
+
prepublishOnly?: string;
|
|
1266
|
+
/** Run before a tarball is packed (on `npm pack`, `npm publish`, and when installing git dependencies). */
|
|
1267
|
+
prepack?: string;
|
|
1268
|
+
/** Run after the tarball has been generated and moved to its final destination. */
|
|
1269
|
+
postpack?: string;
|
|
1270
|
+
/** Run after the package is published. */
|
|
1271
|
+
publish?: string;
|
|
1272
|
+
/** Run after the package is published. */
|
|
1273
|
+
postpublish?: string;
|
|
1274
|
+
/** Run before the package is installed. */
|
|
1275
|
+
preinstall?: string;
|
|
1276
|
+
/** Run after the package is installed. */
|
|
1277
|
+
install?: string;
|
|
1278
|
+
/** Run after the package is installed and after `install`. */
|
|
1279
|
+
postinstall?: string;
|
|
1280
|
+
/** Run before the package is uninstalled and before `uninstall`. */
|
|
1281
|
+
preuninstall?: string;
|
|
1282
|
+
/** Run before the package is uninstalled. */
|
|
1283
|
+
uninstall?: string;
|
|
1284
|
+
/** Run after the package is uninstalled. */
|
|
1285
|
+
postuninstall?: string;
|
|
1286
|
+
/** Run before bump the package version and before `version`. */
|
|
1287
|
+
preversion?: string;
|
|
1288
|
+
/** Run before bump the package version. */
|
|
1289
|
+
version?: string;
|
|
1290
|
+
/** Run after bump the package version. */
|
|
1291
|
+
postversion?: string;
|
|
1292
|
+
/** Run with the `npm test` command, before `test`. */
|
|
1293
|
+
pretest?: string;
|
|
1294
|
+
/** Run with the `npm test` command. */
|
|
1295
|
+
test?: string;
|
|
1296
|
+
/** Run with the `npm test` command, after `test`. */
|
|
1297
|
+
posttest?: string;
|
|
1298
|
+
/** Run with the `npm stop` command, before `stop`. */
|
|
1299
|
+
prestop?: string;
|
|
1300
|
+
/** Run with the `npm stop` command. */
|
|
1301
|
+
stop?: string;
|
|
1302
|
+
/** Run with the `npm stop` command, after `stop`. */
|
|
1303
|
+
poststop?: string;
|
|
1304
|
+
/** Run with the `npm start` command, before `start`. */
|
|
1305
|
+
prestart?: string;
|
|
1306
|
+
/** Run with the `npm start` command. */
|
|
1307
|
+
start?: string;
|
|
1308
|
+
/** Run with the `npm start` command, after `start`. */
|
|
1309
|
+
poststart?: string;
|
|
1310
|
+
/** Run with the `npm restart` command, before `restart`. */
|
|
1311
|
+
prerestart?: string;
|
|
1312
|
+
/** Run with the `npm restart` command. */
|
|
1313
|
+
restart?: string;
|
|
1314
|
+
/** Run with the `npm restart` command, after `restart`. */
|
|
1315
|
+
postrestart?: string;
|
|
1316
|
+
} & Partial<Record<string, string>>;
|
|
1317
|
+
/**
|
|
1318
|
+
* Dependencies of the package. The version range is a string which has one or
|
|
1319
|
+
* more space-separated descriptors.
|
|
1320
|
+
*/
|
|
1321
|
+
export type Dependency = Partial<Record<string, string>>;
|
|
1322
|
+
/**
|
|
1323
|
+
* Recursive map describing selective dependency version overrides supported by npm.
|
|
1324
|
+
*/
|
|
1325
|
+
export type DependencyOverrides = {
|
|
1326
|
+
[packageName in string]: string | undefined | DependencyOverrides;
|
|
1327
|
+
};
|
|
1328
|
+
/**
|
|
1329
|
+
* Specifies requirements for development environment components.
|
|
1330
|
+
*/
|
|
1331
|
+
export interface DevEngineDependency {
|
|
1332
|
+
name: string;
|
|
1333
|
+
version?: string;
|
|
1334
|
+
onFail?: "ignore" | "warn" | "error" | "download";
|
|
1335
|
+
}
|
|
1336
|
+
/**
|
|
1337
|
+
* A mapping of conditions and the paths to which they resolve.
|
|
1338
|
+
*/
|
|
1339
|
+
export interface ExportConditions {
|
|
1340
|
+
[condition: string]: Exports;
|
|
1341
|
+
}
|
|
1342
|
+
/**
|
|
1343
|
+
* Entry points of a module, optionally with conditions and subpath exports.
|
|
1344
|
+
*/
|
|
1345
|
+
export type Exports = null | string | Array<string | ExportConditions> | ExportConditions;
|
|
1346
|
+
/**
|
|
1347
|
+
* Import map entries of a module, optionally with conditions and subpath imports.
|
|
1348
|
+
*/
|
|
1349
|
+
export interface Imports {
|
|
1350
|
+
[key: `#${string}`]: Exports;
|
|
1351
|
+
}
|
|
1352
|
+
/**
|
|
1353
|
+
* Non-standard entry point fields used by various bundlers.
|
|
1354
|
+
*/
|
|
1355
|
+
export interface NonStandardEntryPoints {
|
|
1356
|
+
/** An ECMAScript module ID that is the primary entry point to the program. */
|
|
1357
|
+
module?: string;
|
|
1358
|
+
/** A module ID with untranspiled code that is the primary entry point to the program. */
|
|
1359
|
+
esnext?: string | {
|
|
1360
|
+
[moduleName: string]: string | undefined;
|
|
1361
|
+
main?: string;
|
|
1362
|
+
browser?: string;
|
|
1363
|
+
};
|
|
1364
|
+
/** A hint to JavaScript bundlers or component tools when packaging modules for client side use. */
|
|
1365
|
+
browser?: string | Partial<Record<string, string | false>>;
|
|
1366
|
+
/**
|
|
1367
|
+
* Denote which files in your project are "pure" and therefore safe for Webpack to prune if unused.
|
|
1368
|
+
*
|
|
1369
|
+
* @see {@link https://webpack.js.org/guides/tree-shaking/ | Webpack Tree Shaking}
|
|
1370
|
+
*/
|
|
1371
|
+
sideEffects?: boolean | string[];
|
|
1372
|
+
}
|
|
1373
|
+
/**
|
|
1374
|
+
* TypeScript-specific configuration fields.
|
|
1375
|
+
*/
|
|
1376
|
+
export interface TypeScriptConfiguration {
|
|
1377
|
+
/** Location of the bundled TypeScript declaration file. */
|
|
1378
|
+
types?: string;
|
|
1379
|
+
/** Version selection map of TypeScript. */
|
|
1380
|
+
typesVersions?: Partial<Record<string, Partial<Record<string, string[]>>>>;
|
|
1381
|
+
/** Location of the bundled TypeScript declaration file. Alias of `types`. */
|
|
1382
|
+
typings?: string;
|
|
1383
|
+
}
|
|
1384
|
+
/**
|
|
1385
|
+
* An alternative configuration for workspaces.
|
|
1386
|
+
*/
|
|
1387
|
+
export interface WorkspaceConfig {
|
|
1388
|
+
/** An array of workspace pattern strings which contain the workspace packages. */
|
|
1389
|
+
packages?: WorkspacePattern[];
|
|
1390
|
+
/**
|
|
1391
|
+
* Designed to solve the problem of packages which break when their `node_modules`
|
|
1392
|
+
* are moved to the root workspace directory - a process known as hoisting.
|
|
1393
|
+
*
|
|
1394
|
+
* @see {@link https://classic.yarnpkg.com/blog/2018/02/15/nohoist/ | Yarn nohoist}
|
|
1395
|
+
*/
|
|
1396
|
+
nohoist?: WorkspacePattern[];
|
|
1397
|
+
}
|
|
1398
|
+
/**
|
|
1399
|
+
* A workspace pattern points to a directory or group of directories which
|
|
1400
|
+
* contain packages that should be included in the workspace installation process.
|
|
1401
|
+
*
|
|
1402
|
+
* @example
|
|
1403
|
+
* `docs` - Include the docs directory and install its dependencies.
|
|
1404
|
+
*
|
|
1405
|
+
* @example
|
|
1406
|
+
* `packages/*` - Include all nested directories within the packages directory.
|
|
1407
|
+
*/
|
|
1408
|
+
export type WorkspacePattern = string;
|
|
1409
|
+
/**
|
|
1410
|
+
* Yarn-specific configuration fields.
|
|
1411
|
+
*/
|
|
1412
|
+
export interface YarnConfiguration {
|
|
1413
|
+
/**
|
|
1414
|
+
* If your package only allows one version of a given dependency, and you'd like
|
|
1415
|
+
* to enforce the same behavior as `yarn install --flat` on the command-line,
|
|
1416
|
+
* set this to `true`.
|
|
1417
|
+
*/
|
|
1418
|
+
flat?: boolean;
|
|
1419
|
+
/** Selective version resolutions. Allows the definition of custom package versions inside dependencies. */
|
|
1420
|
+
resolutions?: Dependency;
|
|
1421
|
+
}
|
|
1422
|
+
/**
|
|
1423
|
+
* JSPM-specific configuration fields.
|
|
1424
|
+
*/
|
|
1425
|
+
export interface JSPMConfiguration {
|
|
1426
|
+
/** JSPM configuration. */
|
|
1427
|
+
jspm?: PackageJson;
|
|
1428
|
+
}
|
|
1429
|
+
/**
|
|
1430
|
+
* Publish configuration options.
|
|
1431
|
+
*/
|
|
1432
|
+
export interface PublishConfig {
|
|
1433
|
+
/** Additional properties from the npm docs on `publishConfig`. */
|
|
1434
|
+
[additionalProperties: string]: JsonValue | undefined;
|
|
1435
|
+
/**
|
|
1436
|
+
* When publishing scoped packages, the access level defaults to restricted.
|
|
1437
|
+
* If you want your scoped package to be publicly viewable set `--access=public`.
|
|
1438
|
+
*/
|
|
1439
|
+
access?: "public" | "restricted";
|
|
1440
|
+
/**
|
|
1441
|
+
* The base URL of the npm registry.
|
|
1442
|
+
*
|
|
1443
|
+
* @defaultValue `'https://registry.npmjs.org/'`
|
|
1444
|
+
*/
|
|
1445
|
+
registry?: string;
|
|
1446
|
+
/**
|
|
1447
|
+
* The tag to publish the package under.
|
|
1448
|
+
*
|
|
1449
|
+
* @defaultValue `'latest'`
|
|
1450
|
+
*/
|
|
1451
|
+
tag?: string;
|
|
1452
|
+
}
|
|
1453
|
+
/**
|
|
1454
|
+
* Type for npm's `package.json` file containing standard npm properties.
|
|
1455
|
+
*
|
|
1456
|
+
* @see {@link https://docs.npmjs.com/creating-a-package-json-file | npm docs}
|
|
1457
|
+
*/
|
|
1458
|
+
export interface PackageJsonStandard {
|
|
1459
|
+
/** The name of the package. */
|
|
1460
|
+
name?: string;
|
|
1461
|
+
/** Package version, parseable by `node-semver`. */
|
|
1462
|
+
version?: string;
|
|
1463
|
+
/** Package description, listed in `npm search`. */
|
|
1464
|
+
description?: string;
|
|
1465
|
+
/** Keywords associated with package, listed in `npm search`. */
|
|
1466
|
+
keywords?: string[];
|
|
1467
|
+
/** The URL to the package's homepage. */
|
|
1468
|
+
homepage?: LiteralUnion<".", string>;
|
|
1469
|
+
/** The URL to the package's issue tracker and/or the email address to which issues should be reported. */
|
|
1470
|
+
bugs?: BugsLocation;
|
|
1471
|
+
/** The license for the package. */
|
|
1472
|
+
license?: string;
|
|
1473
|
+
/** The licenses for the package. */
|
|
1474
|
+
licenses?: Array<{
|
|
1475
|
+
type?: string;
|
|
1476
|
+
url?: string;
|
|
1477
|
+
}>;
|
|
1478
|
+
/** The author of the package. */
|
|
1479
|
+
author?: Person;
|
|
1480
|
+
/** A list of people who contributed to the package. */
|
|
1481
|
+
contributors?: Person[];
|
|
1482
|
+
/** A list of people who maintain the package. */
|
|
1483
|
+
maintainers?: Person[];
|
|
1484
|
+
/** The files included in the package. */
|
|
1485
|
+
files?: string[];
|
|
1486
|
+
/**
|
|
1487
|
+
* Resolution algorithm for importing ".js" files from the package's scope.
|
|
1488
|
+
*
|
|
1489
|
+
* @see {@link https://nodejs.org/api/esm.html#esm_package_json_type_field | Node.js ESM docs}
|
|
1490
|
+
*/
|
|
1491
|
+
type?: "module" | "commonjs";
|
|
1492
|
+
/** The module ID that is the primary entry point to the program. */
|
|
1493
|
+
main?: string;
|
|
1494
|
+
/**
|
|
1495
|
+
* Subpath exports to define entry points of the package.
|
|
1496
|
+
*
|
|
1497
|
+
* @see {@link https://nodejs.org/api/packages.html#subpath-exports | Node.js Subpath exports}
|
|
1498
|
+
*/
|
|
1499
|
+
exports?: Exports;
|
|
1500
|
+
/**
|
|
1501
|
+
* Subpath imports to define internal package import maps.
|
|
1502
|
+
*
|
|
1503
|
+
* @see {@link https://nodejs.org/api/packages.html#subpath-imports | Node.js Subpath imports}
|
|
1504
|
+
*/
|
|
1505
|
+
imports?: Imports;
|
|
1506
|
+
/** The executable files that should be installed into the `PATH`. */
|
|
1507
|
+
bin?: string | Partial<Record<string, string>>;
|
|
1508
|
+
/** Filenames to put in place for the `man` program to find. */
|
|
1509
|
+
man?: string | string[];
|
|
1510
|
+
/** Indicates the structure of the package. */
|
|
1511
|
+
directories?: DirectoryLocations;
|
|
1512
|
+
/** Location for the code repository. */
|
|
1513
|
+
repository?: string | {
|
|
1514
|
+
type: string;
|
|
1515
|
+
url: string;
|
|
1516
|
+
/** Relative path to package.json if it is placed in non-root directory (for monorepos). */
|
|
1517
|
+
directory?: string;
|
|
1518
|
+
};
|
|
1519
|
+
/** Script commands that are run at various times in the lifecycle of the package. */
|
|
1520
|
+
scripts?: Scripts;
|
|
1521
|
+
/** Is used to set configuration parameters used in package scripts that persist across upgrades. */
|
|
1522
|
+
config?: JsonObject;
|
|
1523
|
+
/** The dependencies of the package. */
|
|
1524
|
+
dependencies?: Dependency;
|
|
1525
|
+
/** Additional tooling dependencies that are not required for the package to work. */
|
|
1526
|
+
devDependencies?: Dependency;
|
|
1527
|
+
/** Dependencies that are skipped if they fail to install. */
|
|
1528
|
+
optionalDependencies?: Dependency;
|
|
1529
|
+
/** Dependencies that will usually be required by the package user directly or via another dependency. */
|
|
1530
|
+
peerDependencies?: Dependency;
|
|
1531
|
+
/** Indicate peer dependencies that are optional. */
|
|
1532
|
+
peerDependenciesMeta?: Partial<Record<string, {
|
|
1533
|
+
optional: true;
|
|
1534
|
+
}>>;
|
|
1535
|
+
/** Package names that are bundled when the package is published. */
|
|
1536
|
+
bundledDependencies?: string[];
|
|
1537
|
+
/** Alias of `bundledDependencies`. */
|
|
1538
|
+
bundleDependencies?: string[];
|
|
1539
|
+
/** Overrides is used to support selective version overrides using npm. */
|
|
1540
|
+
overrides?: DependencyOverrides;
|
|
1541
|
+
/** Engines that this package runs on. */
|
|
1542
|
+
engines?: {
|
|
1543
|
+
[EngineName in "npm" | "node" | string]?: string;
|
|
1544
|
+
};
|
|
1545
|
+
/**
|
|
1546
|
+
* Whether to enforce engine requirements strictly.
|
|
1547
|
+
*
|
|
1548
|
+
* @deprecated This field is no longer used by npm. Use the `engine-strict` npm config instead.
|
|
1549
|
+
*/
|
|
1550
|
+
engineStrict?: boolean;
|
|
1551
|
+
/** Operating systems the module runs on. */
|
|
1552
|
+
os?: Array<LiteralUnion<"aix" | "darwin" | "freebsd" | "linux" | "openbsd" | "sunos" | "win32" | "!aix" | "!darwin" | "!freebsd" | "!linux" | "!openbsd" | "!sunos" | "!win32", string>>;
|
|
1553
|
+
/** CPU architectures the module runs on. */
|
|
1554
|
+
cpu?: Array<LiteralUnion<"arm" | "arm64" | "ia32" | "mips" | "mipsel" | "ppc" | "ppc64" | "s390" | "s390x" | "x32" | "x64" | "!arm" | "!arm64" | "!ia32" | "!mips" | "!mipsel" | "!ppc" | "!ppc64" | "!s390" | "!s390x" | "!x32" | "!x64", string>>;
|
|
1555
|
+
/** Define the runtime and package manager for developing the current project. */
|
|
1556
|
+
devEngines?: {
|
|
1557
|
+
os?: DevEngineDependency | DevEngineDependency[];
|
|
1558
|
+
cpu?: DevEngineDependency | DevEngineDependency[];
|
|
1559
|
+
libc?: DevEngineDependency | DevEngineDependency[];
|
|
1560
|
+
runtime?: DevEngineDependency | DevEngineDependency[];
|
|
1561
|
+
packageManager?: DevEngineDependency | DevEngineDependency[];
|
|
1562
|
+
};
|
|
1563
|
+
/**
|
|
1564
|
+
* If set to `true`, a warning will be shown if package is installed locally.
|
|
1565
|
+
*
|
|
1566
|
+
* @deprecated This field is no longer used by npm. Use the `bin` field to create CLI tools instead.
|
|
1567
|
+
*/
|
|
1568
|
+
preferGlobal?: boolean;
|
|
1569
|
+
/** If set to `true`, then npm will refuse to publish it. */
|
|
1570
|
+
private?: boolean;
|
|
1571
|
+
/** A set of config values that will be used at publish-time. */
|
|
1572
|
+
publishConfig?: PublishConfig;
|
|
1573
|
+
/**
|
|
1574
|
+
* Describes and notifies consumers of a package's monetary support information.
|
|
1575
|
+
*
|
|
1576
|
+
* @see {@link https://github.com/npm/rfcs/blob/main/implemented/0017-add-funding-support.md | npm funding RFC}
|
|
1577
|
+
*/
|
|
1578
|
+
funding?: string | {
|
|
1579
|
+
/** The type of funding. */
|
|
1580
|
+
type?: LiteralUnion<"github" | "opencollective" | "patreon" | "individual" | "foundation" | "corporation", string>;
|
|
1581
|
+
/** The URL to the funding page. */
|
|
1582
|
+
url: string;
|
|
1583
|
+
};
|
|
1584
|
+
/**
|
|
1585
|
+
* Used to configure npm workspaces / Yarn workspaces.
|
|
1586
|
+
*
|
|
1587
|
+
* @remarks
|
|
1588
|
+
* Workspaces allow you to manage multiple packages within the same repository
|
|
1589
|
+
* in such a way that you only need to run your install command once in order
|
|
1590
|
+
* to install all of them in a single pass.
|
|
1591
|
+
*
|
|
1592
|
+
* Please note that the top-level `private` property of `package.json` must
|
|
1593
|
+
* be set to `true` in order to use workspaces.
|
|
1594
|
+
*
|
|
1595
|
+
* @see {@link https://docs.npmjs.com/cli/using-npm/workspaces | npm workspaces}
|
|
1596
|
+
* @see {@link https://classic.yarnpkg.com/docs/workspaces/ | Yarn workspaces}
|
|
1597
|
+
*/
|
|
1598
|
+
workspaces?: WorkspacePattern[] | WorkspaceConfig;
|
|
1599
|
+
}
|
|
1600
|
+
/**
|
|
1601
|
+
* Type for `package.json` file used by the Node.js runtime.
|
|
1602
|
+
*
|
|
1603
|
+
* @see {@link https://nodejs.org/api/packages.html#nodejs-packagejson-field-definitions | Node.js docs}
|
|
1604
|
+
*/
|
|
1605
|
+
export interface NodeJsStandard {
|
|
1606
|
+
/**
|
|
1607
|
+
* Defines which package manager is expected to be used when working on the current project.
|
|
1608
|
+
*
|
|
1609
|
+
* @remarks
|
|
1610
|
+
* It can be set to any of the supported package managers, and will ensure that
|
|
1611
|
+
* your teams use the exact same package manager versions without having to
|
|
1612
|
+
* install anything else other than Node.js.
|
|
1613
|
+
*
|
|
1614
|
+
* This field is currently experimental and needs to be opted-in; check the
|
|
1615
|
+
* Corepack page for details about the procedure.
|
|
1616
|
+
*
|
|
1617
|
+
* @example
|
|
1618
|
+
* ```json
|
|
1619
|
+
* {
|
|
1620
|
+
* "packageManager": "pnpm@8.0.0"
|
|
1621
|
+
* }
|
|
1622
|
+
* ```
|
|
1623
|
+
*
|
|
1624
|
+
* @see {@link https://nodejs.org/api/corepack.html | Node.js Corepack docs}
|
|
1625
|
+
*/
|
|
1626
|
+
packageManager?: string;
|
|
1627
|
+
}
|
|
1628
|
+
}
|
|
1629
|
+
|
|
1630
|
+
/**
|
|
1631
|
+
* Type for npm's `package.json` file.
|
|
1632
|
+
*
|
|
1633
|
+
* @remarks
|
|
1634
|
+
* Also includes types for fields used by other popular projects, like TypeScript and Yarn.
|
|
1635
|
+
*
|
|
1636
|
+
* @see {@link https://docs.npmjs.com/creating-a-package-json-file | npm docs}
|
|
1637
|
+
*
|
|
1638
|
+
* @public
|
|
1639
|
+
*/
|
|
1640
|
+
export declare type PackageJson = JsonObject & PackageJson.NodeJsStandard & PackageJson.PackageJsonStandard & PackageJson.NonStandardEntryPoints & PackageJson.TypeScriptConfiguration & PackageJson.YarnConfiguration & PackageJson.JSPMConfiguration;
|
|
1641
|
+
|
|
701
1642
|
/**
|
|
702
1643
|
* Plugin to transform package.json for distribution.
|
|
703
1644
|
*
|
|
@@ -849,6 +1790,15 @@ export declare interface PackageJsonTransformPluginOptions {
|
|
|
849
1790
|
transform?: (pkg: PackageJson) => PackageJson;
|
|
850
1791
|
}
|
|
851
1792
|
|
|
1793
|
+
/**
|
|
1794
|
+
* Matches any primitive value.
|
|
1795
|
+
*
|
|
1796
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Glossary/Primitive | MDN Primitive}
|
|
1797
|
+
*
|
|
1798
|
+
* @public
|
|
1799
|
+
*/
|
|
1800
|
+
declare type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
1801
|
+
|
|
852
1802
|
/**
|
|
853
1803
|
* Async RSLib configuration function type.
|
|
854
1804
|
* @public
|
|
@@ -1001,6 +1951,166 @@ export declare class TsDocConfigBuilder {
|
|
|
1001
1951
|
private static syntaxKindToString;
|
|
1002
1952
|
}
|
|
1003
1953
|
|
|
1954
|
+
/**
|
|
1955
|
+
* Error behavior for TSDoc lint errors.
|
|
1956
|
+
*
|
|
1957
|
+
* @remarks
|
|
1958
|
+
* - `"warn"`: Log warnings but continue the build
|
|
1959
|
+
* - `"error"`: Log errors but continue the build
|
|
1960
|
+
* - `"throw"`: Fail the build with an error
|
|
1961
|
+
*
|
|
1962
|
+
* @public
|
|
1963
|
+
*/
|
|
1964
|
+
export declare type TsDocLintErrorBehavior = "warn" | "error" | "throw";
|
|
1965
|
+
|
|
1966
|
+
/**
|
|
1967
|
+
* Creates a plugin to validate TSDoc comments before build using ESLint with eslint-plugin-tsdoc.
|
|
1968
|
+
*
|
|
1969
|
+
* @remarks
|
|
1970
|
+
* This plugin runs TSDoc validation during the `onBeforeBuild` hook, ensuring that
|
|
1971
|
+
* documentation errors are caught before compilation begins. It generates a virtual
|
|
1972
|
+
* `tsdoc.json` configuration file that can be persisted for IDE and tool integration.
|
|
1973
|
+
*
|
|
1974
|
+
* ## Features
|
|
1975
|
+
*
|
|
1976
|
+
* - Programmatic ESLint execution with `eslint-plugin-tsdoc`
|
|
1977
|
+
* - Configurable error handling (warn, error, throw)
|
|
1978
|
+
* - Automatic CI detection for stricter defaults
|
|
1979
|
+
* - Optional tsdoc.json persistence for tool integration
|
|
1980
|
+
* - Automatic file discovery via import graph analysis
|
|
1981
|
+
* - Customizable file patterns when needed
|
|
1982
|
+
*
|
|
1983
|
+
* ## Error Handling
|
|
1984
|
+
*
|
|
1985
|
+
* | Environment | Default Behavior | On Lint Errors |
|
|
1986
|
+
* |-------------|------------------|----------------|
|
|
1987
|
+
* | Local | `"error"` | Log and continue |
|
|
1988
|
+
* | CI | `"throw"` | Fail the build |
|
|
1989
|
+
*
|
|
1990
|
+
* ## Dependencies
|
|
1991
|
+
*
|
|
1992
|
+
* This plugin uses ESLint programmatically with the following packages:
|
|
1993
|
+
* - `eslint`
|
|
1994
|
+
* - `@typescript-eslint/parser`
|
|
1995
|
+
* - `eslint-plugin-tsdoc`
|
|
1996
|
+
*
|
|
1997
|
+
* @param options - Plugin configuration options
|
|
1998
|
+
* @returns An Rsbuild plugin that validates TSDoc comments before the build
|
|
1999
|
+
*
|
|
2000
|
+
* @example
|
|
2001
|
+
* ```typescript
|
|
2002
|
+
* import { TsDocLintPlugin } from '@savvy-web/rslib-builder';
|
|
2003
|
+
*
|
|
2004
|
+
* export default defineConfig({
|
|
2005
|
+
* plugins: [
|
|
2006
|
+
* TsDocLintPlugin({
|
|
2007
|
+
* onError: 'throw',
|
|
2008
|
+
* persistConfig: true,
|
|
2009
|
+
* }),
|
|
2010
|
+
* ],
|
|
2011
|
+
* });
|
|
2012
|
+
* ```
|
|
2013
|
+
*
|
|
2014
|
+
* @public
|
|
2015
|
+
*/
|
|
2016
|
+
export declare const TsDocLintPlugin: (options?: TsDocLintPluginOptions) => RsbuildPlugin;
|
|
2017
|
+
|
|
2018
|
+
/**
|
|
2019
|
+
* Options for the TSDoc lint plugin.
|
|
2020
|
+
*
|
|
2021
|
+
* @remarks
|
|
2022
|
+
* This plugin validates TSDoc comments in your source files before the build
|
|
2023
|
+
* starts using ESLint with `eslint-plugin-tsdoc`. It helps catch documentation
|
|
2024
|
+
* errors early in the development cycle.
|
|
2025
|
+
*
|
|
2026
|
+
* @example
|
|
2027
|
+
* Enable with defaults (throws in CI, errors locally):
|
|
2028
|
+
* ```typescript
|
|
2029
|
+
* import { TsDocLintPlugin } from '@savvy-web/rslib-builder';
|
|
2030
|
+
*
|
|
2031
|
+
* export default defineConfig({
|
|
2032
|
+
* plugins: [TsDocLintPlugin()],
|
|
2033
|
+
* });
|
|
2034
|
+
* ```
|
|
2035
|
+
*
|
|
2036
|
+
* @example
|
|
2037
|
+
* Custom configuration:
|
|
2038
|
+
* ```typescript
|
|
2039
|
+
* import { TsDocLintPlugin } from '@savvy-web/rslib-builder';
|
|
2040
|
+
*
|
|
2041
|
+
* export default defineConfig({
|
|
2042
|
+
* plugins: [
|
|
2043
|
+
* TsDocLintPlugin({
|
|
2044
|
+
* tsdoc: {
|
|
2045
|
+
* tagDefinitions: [{ tagName: '@error', syntaxKind: 'block' }],
|
|
2046
|
+
* },
|
|
2047
|
+
* onError: 'throw',
|
|
2048
|
+
* persistConfig: true,
|
|
2049
|
+
* }),
|
|
2050
|
+
* ],
|
|
2051
|
+
* });
|
|
2052
|
+
* ```
|
|
2053
|
+
*
|
|
2054
|
+
* @public
|
|
2055
|
+
*/
|
|
2056
|
+
export declare interface TsDocLintPluginOptions {
|
|
2057
|
+
/**
|
|
2058
|
+
* Whether to enable TSDoc linting.
|
|
2059
|
+
* @defaultValue true
|
|
2060
|
+
*/
|
|
2061
|
+
enabled?: boolean;
|
|
2062
|
+
/**
|
|
2063
|
+
* TSDoc configuration for custom tag definitions.
|
|
2064
|
+
* Uses the same options as the DtsPlugin's apiModel.tsdoc option.
|
|
2065
|
+
*
|
|
2066
|
+
* @remarks
|
|
2067
|
+
* By default, all standard tag groups (core, extended, discretionary) are
|
|
2068
|
+
* enabled. Custom tags defined in `tagDefinitions` are automatically
|
|
2069
|
+
* supported.
|
|
2070
|
+
*/
|
|
2071
|
+
tsdoc?: TsDocOptions;
|
|
2072
|
+
/**
|
|
2073
|
+
* Override automatic file discovery with explicit file paths or glob patterns.
|
|
2074
|
+
*
|
|
2075
|
+
* @remarks
|
|
2076
|
+
* By default, TsDocLintPlugin uses import graph analysis to discover files
|
|
2077
|
+
* from your package's exports. This ensures only public API files are linted.
|
|
2078
|
+
*
|
|
2079
|
+
* Use this option only when you need to lint specific files that aren't
|
|
2080
|
+
* part of the export graph, or to override the automatic discovery.
|
|
2081
|
+
*
|
|
2082
|
+
* When specified as glob patterns, test files and `__test__` directories
|
|
2083
|
+
* are still excluded unless explicitly included.
|
|
2084
|
+
*
|
|
2085
|
+
* @example
|
|
2086
|
+
* ```typescript
|
|
2087
|
+
* // Explicit patterns override automatic discovery
|
|
2088
|
+
* TsDocLintPlugin({
|
|
2089
|
+
* include: ["src/**\/*.ts", "!**\/*.test.ts"],
|
|
2090
|
+
* })
|
|
2091
|
+
* ```
|
|
2092
|
+
*/
|
|
2093
|
+
include?: string[];
|
|
2094
|
+
/**
|
|
2095
|
+
* How to handle TSDoc lint errors.
|
|
2096
|
+
* - `"warn"`: Log warnings but continue the build
|
|
2097
|
+
* - `"error"`: Log errors but continue the build
|
|
2098
|
+
* - `"throw"`: Fail the build with an error
|
|
2099
|
+
*
|
|
2100
|
+
* @defaultValue `"throw"` in CI environments, `"error"` locally
|
|
2101
|
+
*/
|
|
2102
|
+
onError?: TsDocLintErrorBehavior;
|
|
2103
|
+
/**
|
|
2104
|
+
* Persist tsdoc.json to disk for tool integration (ESLint, IDEs).
|
|
2105
|
+
* - `true`: Write to project root as "tsdoc.json"
|
|
2106
|
+
* - `PathLike`: Write to specified path
|
|
2107
|
+
* - `false`: Clean up after linting
|
|
2108
|
+
*
|
|
2109
|
+
* @defaultValue `true` when not in CI, `false` in CI environments
|
|
2110
|
+
*/
|
|
2111
|
+
persistConfig?: boolean | PathLike;
|
|
2112
|
+
}
|
|
2113
|
+
|
|
1004
2114
|
/**
|
|
1005
2115
|
* Options for tsdoc-metadata.json generation.
|
|
1006
2116
|
* @public
|
|
@@ -1096,6 +2206,11 @@ export declare interface TsDocOptions {
|
|
|
1096
2206
|
* TSDoc warnings include unknown tags, malformed syntax, and other
|
|
1097
2207
|
* documentation issues detected by API Extractor during processing.
|
|
1098
2208
|
*
|
|
2209
|
+
* **Important:** This setting only applies to first-party warnings (from your
|
|
2210
|
+
* project's source code). Third-party warnings from dependencies in
|
|
2211
|
+
* `node_modules/` are always logged but never fail the build, since they
|
|
2212
|
+
* cannot be fixed by the consuming project.
|
|
2213
|
+
*
|
|
1099
2214
|
* @defaultValue `"fail"` in CI environments (`CI` or `GITHUB_ACTIONS` env vars),
|
|
1100
2215
|
* `"log"` otherwise
|
|
1101
2216
|
*/
|