@savvy-web/rslib-builder 0.5.0 → 0.7.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 +2 -1
- package/index.d.ts +15 -3
- package/index.js +370 -9
- package/package.json +21 -1
- package/tsdoc-metadata.json +11 -11
package/README.md
CHANGED
|
@@ -27,7 +27,8 @@ focus on your code.
|
|
|
27
27
|
- **Package.json Transform** - Converts `.ts` exports to `.js`, generates files
|
|
28
28
|
array, removes dev-only fields
|
|
29
29
|
- **TSDoc Validation** - Pre-build TSDoc validation with automatic public API discovery
|
|
30
|
-
- **API Model Generation** - Optional API model output for
|
|
30
|
+
- **API Model Generation** - Optional API model and resolved tsconfig output for
|
|
31
|
+
documentation tooling
|
|
31
32
|
- **Extensible** - Add custom RSlib/Rsbuild plugins for advanced use cases
|
|
32
33
|
|
|
33
34
|
## Prerequisites
|
package/index.d.ts
CHANGED
|
@@ -119,6 +119,18 @@ export declare interface ApiModelOptions {
|
|
|
119
119
|
* @defaultValue true (enabled when apiModel is enabled)
|
|
120
120
|
*/
|
|
121
121
|
tsdocMetadata?: TsDocMetadataOptions | boolean;
|
|
122
|
+
/**
|
|
123
|
+
* Controls handling of API Extractor's "forgotten export" messages.
|
|
124
|
+
* A forgotten export occurs when a public API references a declaration
|
|
125
|
+
* that isn't exported from the entry point.
|
|
126
|
+
*
|
|
127
|
+
* - `"include"` (default): Log a warning, include in the API model
|
|
128
|
+
* - `"error"`: Fail the build with details about the forgotten exports
|
|
129
|
+
* - `"ignore"`: Turn off detection — suppress all messages
|
|
130
|
+
*
|
|
131
|
+
* @defaultValue "include"
|
|
132
|
+
*/
|
|
133
|
+
forgottenExports?: "include" | "error" | "ignore";
|
|
122
134
|
}
|
|
123
135
|
|
|
124
136
|
/**
|
|
@@ -934,7 +946,7 @@ export declare type JsonValue = JsonPrimitive | JsonObject | JsonArray;
|
|
|
934
946
|
*
|
|
935
947
|
* @public
|
|
936
948
|
*/
|
|
937
|
-
declare type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
|
|
949
|
+
export declare type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
|
|
938
950
|
|
|
939
951
|
/**
|
|
940
952
|
* Builder for Node.js ESM libraries using RSlib.
|
|
@@ -1797,13 +1809,13 @@ export declare interface PackageJsonTransformPluginOptions {
|
|
|
1797
1809
|
*
|
|
1798
1810
|
* @public
|
|
1799
1811
|
*/
|
|
1800
|
-
declare type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
1812
|
+
export declare type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
1801
1813
|
|
|
1802
1814
|
/**
|
|
1803
1815
|
* Async RSLib configuration function type.
|
|
1804
1816
|
* @public
|
|
1805
1817
|
*/
|
|
1806
|
-
declare type RslibConfigAsyncFn = (env: ConfigParams) => Promise<RslibConfig>;
|
|
1818
|
+
export declare type RslibConfigAsyncFn = (env: ConfigParams) => Promise<RslibConfig>;
|
|
1807
1819
|
|
|
1808
1820
|
/**
|
|
1809
1821
|
* Function to transform package.json during the build process.
|
package/index.js
CHANGED
|
@@ -10,7 +10,7 @@ import { getWorkspaceRoot } from "workspace-tools";
|
|
|
10
10
|
import { spawn } from "node:child_process";
|
|
11
11
|
import { StandardTags, Standardization, TSDocTagSyntaxKind } from "@microsoft/tsdoc";
|
|
12
12
|
import deep_equal from "deep-equal";
|
|
13
|
-
import typescript, { createCompilerHost, findConfigFile, formatDiagnostic, parseJsonConfigFileContent, readConfigFile, sys } from "typescript";
|
|
13
|
+
import typescript, { ImportsNotUsedAsValues, JsxEmit, ModuleDetectionKind, ModuleKind, ModuleResolutionKind, NewLineKind, ScriptTarget, createCompilerHost, findConfigFile, formatDiagnostic, parseJsonConfigFileContent, readConfigFile, sys } from "typescript";
|
|
14
14
|
import { createRequire } from "node:module";
|
|
15
15
|
import { inspect } from "node:util";
|
|
16
16
|
import sort_package_json from "sort-package-json";
|
|
@@ -369,6 +369,331 @@ const TSConfigs = {
|
|
|
369
369
|
}
|
|
370
370
|
}
|
|
371
371
|
};
|
|
372
|
+
const TSCONFIG_SCHEMA_URL = "https://json.schemastore.org/tsconfig";
|
|
373
|
+
const PRESERVED_BOOLEAN_OPTIONS = [
|
|
374
|
+
"strict",
|
|
375
|
+
"strictNullChecks",
|
|
376
|
+
"strictFunctionTypes",
|
|
377
|
+
"strictBindCallApply",
|
|
378
|
+
"strictPropertyInitialization",
|
|
379
|
+
"noImplicitAny",
|
|
380
|
+
"noImplicitThis",
|
|
381
|
+
"alwaysStrict",
|
|
382
|
+
"noUnusedLocals",
|
|
383
|
+
"noUnusedParameters",
|
|
384
|
+
"exactOptionalPropertyTypes",
|
|
385
|
+
"noImplicitReturns",
|
|
386
|
+
"noFallthroughCasesInSwitch",
|
|
387
|
+
"noUncheckedIndexedAccess",
|
|
388
|
+
"noImplicitOverride",
|
|
389
|
+
"noPropertyAccessFromIndexSignature",
|
|
390
|
+
"allowUnusedLabels",
|
|
391
|
+
"allowUnreachableCode",
|
|
392
|
+
"esModuleInterop",
|
|
393
|
+
"allowSyntheticDefaultImports",
|
|
394
|
+
"forceConsistentCasingInFileNames",
|
|
395
|
+
"resolveJsonModule",
|
|
396
|
+
"isolatedModules",
|
|
397
|
+
"verbatimModuleSyntax",
|
|
398
|
+
"skipLibCheck",
|
|
399
|
+
"skipDefaultLibCheck",
|
|
400
|
+
"downlevelIteration",
|
|
401
|
+
"importHelpers",
|
|
402
|
+
"preserveConstEnums",
|
|
403
|
+
"isolatedDeclarations",
|
|
404
|
+
"allowImportingTsExtensions",
|
|
405
|
+
"rewriteRelativeImportExtensions",
|
|
406
|
+
"allowArbitraryExtensions",
|
|
407
|
+
"useDefineForClassFields",
|
|
408
|
+
"noLib",
|
|
409
|
+
"preserveSymlinks"
|
|
410
|
+
];
|
|
411
|
+
const PRESERVED_STRING_OPTIONS = [
|
|
412
|
+
"jsxFactory",
|
|
413
|
+
"jsxFragmentFactory",
|
|
414
|
+
"jsxImportSource",
|
|
415
|
+
"reactNamespace",
|
|
416
|
+
"declarationMapBuildInfo"
|
|
417
|
+
];
|
|
418
|
+
class TsconfigResolver {
|
|
419
|
+
static SCRIPT_TARGET_MAP = new Map([
|
|
420
|
+
[
|
|
421
|
+
ScriptTarget.ES3,
|
|
422
|
+
"es3"
|
|
423
|
+
],
|
|
424
|
+
[
|
|
425
|
+
ScriptTarget.ES5,
|
|
426
|
+
"es5"
|
|
427
|
+
],
|
|
428
|
+
[
|
|
429
|
+
ScriptTarget.ES2015,
|
|
430
|
+
"es2015"
|
|
431
|
+
],
|
|
432
|
+
[
|
|
433
|
+
ScriptTarget.ES2016,
|
|
434
|
+
"es2016"
|
|
435
|
+
],
|
|
436
|
+
[
|
|
437
|
+
ScriptTarget.ES2017,
|
|
438
|
+
"es2017"
|
|
439
|
+
],
|
|
440
|
+
[
|
|
441
|
+
ScriptTarget.ES2018,
|
|
442
|
+
"es2018"
|
|
443
|
+
],
|
|
444
|
+
[
|
|
445
|
+
ScriptTarget.ES2019,
|
|
446
|
+
"es2019"
|
|
447
|
+
],
|
|
448
|
+
[
|
|
449
|
+
ScriptTarget.ES2020,
|
|
450
|
+
"es2020"
|
|
451
|
+
],
|
|
452
|
+
[
|
|
453
|
+
ScriptTarget.ES2021,
|
|
454
|
+
"es2021"
|
|
455
|
+
],
|
|
456
|
+
[
|
|
457
|
+
ScriptTarget.ES2022,
|
|
458
|
+
"es2022"
|
|
459
|
+
],
|
|
460
|
+
[
|
|
461
|
+
ScriptTarget.ES2023,
|
|
462
|
+
"es2023"
|
|
463
|
+
],
|
|
464
|
+
[
|
|
465
|
+
ScriptTarget.ES2024,
|
|
466
|
+
"es2024"
|
|
467
|
+
],
|
|
468
|
+
[
|
|
469
|
+
ScriptTarget.ESNext,
|
|
470
|
+
"esnext"
|
|
471
|
+
],
|
|
472
|
+
[
|
|
473
|
+
ScriptTarget.JSON,
|
|
474
|
+
"json"
|
|
475
|
+
]
|
|
476
|
+
]);
|
|
477
|
+
static MODULE_KIND_MAP = new Map([
|
|
478
|
+
[
|
|
479
|
+
ModuleKind.None,
|
|
480
|
+
"none"
|
|
481
|
+
],
|
|
482
|
+
[
|
|
483
|
+
ModuleKind.CommonJS,
|
|
484
|
+
"commonjs"
|
|
485
|
+
],
|
|
486
|
+
[
|
|
487
|
+
ModuleKind.AMD,
|
|
488
|
+
"amd"
|
|
489
|
+
],
|
|
490
|
+
[
|
|
491
|
+
ModuleKind.UMD,
|
|
492
|
+
"umd"
|
|
493
|
+
],
|
|
494
|
+
[
|
|
495
|
+
ModuleKind.System,
|
|
496
|
+
"system"
|
|
497
|
+
],
|
|
498
|
+
[
|
|
499
|
+
ModuleKind.ES2015,
|
|
500
|
+
"es2015"
|
|
501
|
+
],
|
|
502
|
+
[
|
|
503
|
+
ModuleKind.ES2020,
|
|
504
|
+
"es2020"
|
|
505
|
+
],
|
|
506
|
+
[
|
|
507
|
+
ModuleKind.ES2022,
|
|
508
|
+
"es2022"
|
|
509
|
+
],
|
|
510
|
+
[
|
|
511
|
+
ModuleKind.ESNext,
|
|
512
|
+
"esnext"
|
|
513
|
+
],
|
|
514
|
+
[
|
|
515
|
+
ModuleKind.Node16,
|
|
516
|
+
"node16"
|
|
517
|
+
],
|
|
518
|
+
[
|
|
519
|
+
101,
|
|
520
|
+
"node18"
|
|
521
|
+
],
|
|
522
|
+
[
|
|
523
|
+
102,
|
|
524
|
+
"node20"
|
|
525
|
+
],
|
|
526
|
+
[
|
|
527
|
+
ModuleKind.NodeNext,
|
|
528
|
+
"nodenext"
|
|
529
|
+
],
|
|
530
|
+
[
|
|
531
|
+
ModuleKind.Preserve,
|
|
532
|
+
"preserve"
|
|
533
|
+
]
|
|
534
|
+
]);
|
|
535
|
+
static MODULE_RESOLUTION_MAP = new Map([
|
|
536
|
+
[
|
|
537
|
+
ModuleResolutionKind.Classic,
|
|
538
|
+
"classic"
|
|
539
|
+
],
|
|
540
|
+
[
|
|
541
|
+
ModuleResolutionKind.Node10,
|
|
542
|
+
"node10"
|
|
543
|
+
],
|
|
544
|
+
[
|
|
545
|
+
ModuleResolutionKind.Node16,
|
|
546
|
+
"node16"
|
|
547
|
+
],
|
|
548
|
+
[
|
|
549
|
+
ModuleResolutionKind.NodeNext,
|
|
550
|
+
"nodenext"
|
|
551
|
+
],
|
|
552
|
+
[
|
|
553
|
+
ModuleResolutionKind.Bundler,
|
|
554
|
+
"bundler"
|
|
555
|
+
]
|
|
556
|
+
]);
|
|
557
|
+
static JSX_EMIT_MAP = new Map([
|
|
558
|
+
[
|
|
559
|
+
JsxEmit.None,
|
|
560
|
+
"none"
|
|
561
|
+
],
|
|
562
|
+
[
|
|
563
|
+
JsxEmit.Preserve,
|
|
564
|
+
"preserve"
|
|
565
|
+
],
|
|
566
|
+
[
|
|
567
|
+
JsxEmit.React,
|
|
568
|
+
"react"
|
|
569
|
+
],
|
|
570
|
+
[
|
|
571
|
+
JsxEmit.ReactNative,
|
|
572
|
+
"react-native"
|
|
573
|
+
],
|
|
574
|
+
[
|
|
575
|
+
JsxEmit.ReactJSX,
|
|
576
|
+
"react-jsx"
|
|
577
|
+
],
|
|
578
|
+
[
|
|
579
|
+
JsxEmit.ReactJSXDev,
|
|
580
|
+
"react-jsxdev"
|
|
581
|
+
]
|
|
582
|
+
]);
|
|
583
|
+
static MODULE_DETECTION_MAP = new Map([
|
|
584
|
+
[
|
|
585
|
+
ModuleDetectionKind.Legacy,
|
|
586
|
+
"legacy"
|
|
587
|
+
],
|
|
588
|
+
[
|
|
589
|
+
ModuleDetectionKind.Auto,
|
|
590
|
+
"auto"
|
|
591
|
+
],
|
|
592
|
+
[
|
|
593
|
+
ModuleDetectionKind.Force,
|
|
594
|
+
"force"
|
|
595
|
+
]
|
|
596
|
+
]);
|
|
597
|
+
static NEW_LINE_MAP = new Map([
|
|
598
|
+
[
|
|
599
|
+
NewLineKind.CarriageReturnLineFeed,
|
|
600
|
+
"crlf"
|
|
601
|
+
],
|
|
602
|
+
[
|
|
603
|
+
NewLineKind.LineFeed,
|
|
604
|
+
"lf"
|
|
605
|
+
]
|
|
606
|
+
]);
|
|
607
|
+
static IMPORTS_NOT_USED_MAP = new Map([
|
|
608
|
+
[
|
|
609
|
+
ImportsNotUsedAsValues.Remove,
|
|
610
|
+
"remove"
|
|
611
|
+
],
|
|
612
|
+
[
|
|
613
|
+
ImportsNotUsedAsValues.Preserve,
|
|
614
|
+
"preserve"
|
|
615
|
+
],
|
|
616
|
+
[
|
|
617
|
+
ImportsNotUsedAsValues.Error,
|
|
618
|
+
"error"
|
|
619
|
+
]
|
|
620
|
+
]);
|
|
621
|
+
static convertScriptTarget(target) {
|
|
622
|
+
if (void 0 === target) return;
|
|
623
|
+
const mapped = TsconfigResolver.SCRIPT_TARGET_MAP.get(target);
|
|
624
|
+
if (void 0 !== mapped) return mapped;
|
|
625
|
+
return `es${target}`;
|
|
626
|
+
}
|
|
627
|
+
static convertModuleKind(module) {
|
|
628
|
+
if (void 0 === module) return;
|
|
629
|
+
const mapped = TsconfigResolver.MODULE_KIND_MAP.get(module);
|
|
630
|
+
if (void 0 !== mapped) return mapped;
|
|
631
|
+
return String(module);
|
|
632
|
+
}
|
|
633
|
+
static convertModuleResolution(resolution) {
|
|
634
|
+
if (void 0 === resolution) return;
|
|
635
|
+
const mapped = TsconfigResolver.MODULE_RESOLUTION_MAP.get(resolution);
|
|
636
|
+
if (void 0 !== mapped) return mapped;
|
|
637
|
+
return String(resolution);
|
|
638
|
+
}
|
|
639
|
+
static convertJsxEmit(jsx) {
|
|
640
|
+
if (void 0 === jsx) return;
|
|
641
|
+
const mapped = TsconfigResolver.JSX_EMIT_MAP.get(jsx);
|
|
642
|
+
if (void 0 !== mapped) return mapped;
|
|
643
|
+
return String(jsx);
|
|
644
|
+
}
|
|
645
|
+
static convertModuleDetection(detection) {
|
|
646
|
+
if (void 0 === detection) return;
|
|
647
|
+
const mapped = TsconfigResolver.MODULE_DETECTION_MAP.get(detection);
|
|
648
|
+
if (void 0 !== mapped) return mapped;
|
|
649
|
+
return String(detection);
|
|
650
|
+
}
|
|
651
|
+
static convertNewLine(newLine) {
|
|
652
|
+
if (void 0 === newLine) return;
|
|
653
|
+
const mapped = TsconfigResolver.NEW_LINE_MAP.get(newLine);
|
|
654
|
+
if (void 0 !== mapped) return mapped;
|
|
655
|
+
return String(newLine);
|
|
656
|
+
}
|
|
657
|
+
static convertImportsNotUsedAsValues(importsNotUsedAsValues) {
|
|
658
|
+
if (void 0 === importsNotUsedAsValues) return;
|
|
659
|
+
const mapped = TsconfigResolver.IMPORTS_NOT_USED_MAP.get(importsNotUsedAsValues);
|
|
660
|
+
if (void 0 !== mapped) return mapped;
|
|
661
|
+
return String(importsNotUsedAsValues);
|
|
662
|
+
}
|
|
663
|
+
static convertLibReference(lib) {
|
|
664
|
+
const filename = lib.includes("/") || lib.includes("\\") ? lib.split(/[\\/]/).pop() ?? lib : lib;
|
|
665
|
+
return filename.replace(/^lib\./, "").replace(/\.d\.ts$/, "");
|
|
666
|
+
}
|
|
667
|
+
resolve(parsed, rootDir) {
|
|
668
|
+
const opts = parsed.options;
|
|
669
|
+
const compilerOptions = {};
|
|
670
|
+
this.addEnumOptions(compilerOptions, opts);
|
|
671
|
+
if (opts.lib && opts.lib.length > 0) compilerOptions.lib = opts.lib.map(TsconfigResolver.convertLibReference);
|
|
672
|
+
compilerOptions.composite = false;
|
|
673
|
+
compilerOptions.noEmit = true;
|
|
674
|
+
this.addPreservedBooleanOptions(compilerOptions, opts);
|
|
675
|
+
this.addPreservedStringOptions(compilerOptions, opts);
|
|
676
|
+
return {
|
|
677
|
+
$schema: TSCONFIG_SCHEMA_URL,
|
|
678
|
+
compilerOptions
|
|
679
|
+
};
|
|
680
|
+
}
|
|
681
|
+
addEnumOptions(compilerOptions, opts) {
|
|
682
|
+
if (void 0 !== opts.target) compilerOptions.target = TsconfigResolver.convertScriptTarget(opts.target);
|
|
683
|
+
if (void 0 !== opts.module) compilerOptions.module = TsconfigResolver.convertModuleKind(opts.module);
|
|
684
|
+
if (void 0 !== opts.moduleResolution) compilerOptions.moduleResolution = TsconfigResolver.convertModuleResolution(opts.moduleResolution);
|
|
685
|
+
if (void 0 !== opts.moduleDetection) compilerOptions.moduleDetection = TsconfigResolver.convertModuleDetection(opts.moduleDetection);
|
|
686
|
+
if (void 0 !== opts.jsx) compilerOptions.jsx = TsconfigResolver.convertJsxEmit(opts.jsx);
|
|
687
|
+
if (void 0 !== opts.newLine) compilerOptions.newLine = TsconfigResolver.convertNewLine(opts.newLine);
|
|
688
|
+
if (void 0 !== opts.importsNotUsedAsValues) compilerOptions.importsNotUsedAsValues = TsconfigResolver.convertImportsNotUsedAsValues(opts.importsNotUsedAsValues);
|
|
689
|
+
}
|
|
690
|
+
addPreservedBooleanOptions(compilerOptions, opts) {
|
|
691
|
+
for (const opt of PRESERVED_BOOLEAN_OPTIONS)if (void 0 !== opts[opt]) compilerOptions[opt] = opts[opt];
|
|
692
|
+
}
|
|
693
|
+
addPreservedStringOptions(compilerOptions, opts) {
|
|
694
|
+
for (const opt of PRESERVED_STRING_OPTIONS)if (void 0 !== opts[opt]) compilerOptions[opt] = opts[opt];
|
|
695
|
+
}
|
|
696
|
+
}
|
|
372
697
|
class TsDocConfigBuilder {
|
|
373
698
|
static ALL_GROUPS = [
|
|
374
699
|
"core",
|
|
@@ -528,6 +853,7 @@ async function bundleDtsFiles(options) {
|
|
|
528
853
|
const tsdocOptions = "object" == typeof apiModel ? apiModel.tsdoc : void 0;
|
|
529
854
|
const tsdocMetadataOption = "object" == typeof apiModel ? apiModel.tsdocMetadata : void 0;
|
|
530
855
|
const tsdocWarnings = tsdocOptions?.warnings ?? (TsDocConfigBuilder.isCI() ? "fail" : "log");
|
|
856
|
+
const forgottenExports = ("object" == typeof apiModel ? apiModel.forgottenExports : void 0) ?? "include";
|
|
531
857
|
const tsdocMetadataEnabled = apiModelEnabled && (void 0 === tsdocMetadataOption || true === tsdocMetadataOption || "object" == typeof tsdocMetadataOption && false !== tsdocMetadataOption.enabled);
|
|
532
858
|
const tsdocMetadataFilename = "object" == typeof tsdocMetadataOption && tsdocMetadataOption.filename ? tsdocMetadataOption.filename : "tsdoc-metadata.json";
|
|
533
859
|
getApiExtractorPath();
|
|
@@ -568,6 +894,7 @@ async function bundleDtsFiles(options) {
|
|
|
568
894
|
configObject: {
|
|
569
895
|
projectFolder: cwd,
|
|
570
896
|
mainEntryPointFilePath: tempDtsPath,
|
|
897
|
+
enumMemberOrder: "preserve",
|
|
571
898
|
compiler: {
|
|
572
899
|
tsconfigFilePath: tsconfigPath
|
|
573
900
|
},
|
|
@@ -590,6 +917,7 @@ async function bundleDtsFiles(options) {
|
|
|
590
917
|
tsdocConfigFile: tsdocConfigFile
|
|
591
918
|
});
|
|
592
919
|
const collectedTsdocWarnings = [];
|
|
920
|
+
const collectedForgottenExports = [];
|
|
593
921
|
const extractorResult = Extractor.invoke(extractorConfig, {
|
|
594
922
|
localBuild: true,
|
|
595
923
|
showVerboseMessages: false,
|
|
@@ -613,17 +941,27 @@ async function bundleDtsFiles(options) {
|
|
|
613
941
|
});
|
|
614
942
|
message.logLevel = "none";
|
|
615
943
|
}
|
|
944
|
+
if ("ae-forgotten-export" === message.messageId && message.text) if ("ignore" === forgottenExports) message.logLevel = "none";
|
|
945
|
+
else {
|
|
946
|
+
collectedForgottenExports.push({
|
|
947
|
+
text: message.text,
|
|
948
|
+
sourceFilePath: message.sourceFilePath,
|
|
949
|
+
sourceFileLine: message.sourceFileLine,
|
|
950
|
+
sourceFileColumn: message.sourceFileColumn
|
|
951
|
+
});
|
|
952
|
+
message.logLevel = "none";
|
|
953
|
+
}
|
|
616
954
|
}
|
|
617
955
|
});
|
|
618
956
|
if (!extractorResult.succeeded) throw new Error(`API Extractor failed for entry "${entryName}"`);
|
|
957
|
+
const formatWarning = (warning)=>{
|
|
958
|
+
const location = warning.sourceFilePath ? `${picocolors.cyan((0, external_node_path_.relative)(cwd, warning.sourceFilePath))}${warning.sourceFileLine ? `:${warning.sourceFileLine}` : ""}${warning.sourceFileColumn ? `:${warning.sourceFileColumn}` : ""}` : null;
|
|
959
|
+
return location ? `${location}: ${picocolors.yellow(warning.text)}` : picocolors.yellow(warning.text);
|
|
960
|
+
};
|
|
619
961
|
if (collectedTsdocWarnings.length > 0) {
|
|
620
962
|
const isThirdParty = (warning)=>warning.sourceFilePath?.includes("node_modules/") ?? false;
|
|
621
963
|
const firstPartyWarnings = collectedTsdocWarnings.filter((w)=>!isThirdParty(w));
|
|
622
964
|
const thirdPartyWarnings = collectedTsdocWarnings.filter(isThirdParty);
|
|
623
|
-
const formatWarning = (warning)=>{
|
|
624
|
-
const location = warning.sourceFilePath ? `${picocolors.cyan((0, external_node_path_.relative)(cwd, warning.sourceFilePath))}${warning.sourceFileLine ? `:${warning.sourceFileLine}` : ""}${warning.sourceFileColumn ? `:${warning.sourceFileColumn}` : ""}` : null;
|
|
625
|
-
return location ? `${location}: ${picocolors.yellow(warning.text)}` : picocolors.yellow(warning.text);
|
|
626
|
-
};
|
|
627
965
|
if (thirdPartyWarnings.length > 0) {
|
|
628
966
|
const thirdPartyMessages = thirdPartyWarnings.map(formatWarning).join("\n ");
|
|
629
967
|
core_logger.warn(`TSDoc warnings from dependencies for entry "${entryName}" (cannot be fixed, bundled types may have documentation issues):\n ${thirdPartyMessages}`);
|
|
@@ -634,6 +972,11 @@ async function bundleDtsFiles(options) {
|
|
|
634
972
|
if ("log" === tsdocWarnings) core_logger.warn(`TSDoc warnings for entry "${entryName}":\n ${firstPartyMessages}`);
|
|
635
973
|
}
|
|
636
974
|
}
|
|
975
|
+
if (collectedForgottenExports.length > 0) {
|
|
976
|
+
const forgottenMessages = collectedForgottenExports.map(formatWarning).join("\n ");
|
|
977
|
+
if ("error" === forgottenExports) throw new Error(`Forgotten exports detected for entry "${entryName}":\n ${forgottenMessages}`);
|
|
978
|
+
if ("include" === forgottenExports) core_logger.warn(`Forgotten exports for entry "${entryName}":\n ${forgottenMessages}`);
|
|
979
|
+
}
|
|
637
980
|
if (generateApiModel && tempApiModelPath) apiModelPath = tempApiModelPath;
|
|
638
981
|
if (generateTsdocMetadata && tempTsdocMetadataPath) tsdocMetadataPath = tempTsdocMetadataPath;
|
|
639
982
|
if (banner || footer) {
|
|
@@ -885,7 +1228,7 @@ function runTsgo(options) {
|
|
|
885
1228
|
if (apiModelPath) {
|
|
886
1229
|
const defaultApiModelFilename = packageJson.name ? `${getUnscopedPackageName(packageJson.name)}.api.json` : "api.json";
|
|
887
1230
|
const apiModelFilename = "object" == typeof options.apiModel && options.apiModel.filename ? options.apiModel.filename : defaultApiModelFilename;
|
|
888
|
-
const apiModelContent = await readFile(apiModelPath, "utf-8");
|
|
1231
|
+
const apiModelContent = (await readFile(apiModelPath, "utf-8")).replaceAll("\r\n", "\n");
|
|
889
1232
|
const apiModelSource = new context.sources.OriginalSource(apiModelContent, apiModelFilename);
|
|
890
1233
|
context.compilation.emitAsset(apiModelFilename, apiModelSource);
|
|
891
1234
|
if (filesArray) filesArray.add(`!${apiModelFilename}`);
|
|
@@ -900,6 +1243,7 @@ function runTsgo(options) {
|
|
|
900
1243
|
apiModelFilename,
|
|
901
1244
|
localTsdocFilename,
|
|
902
1245
|
hasTsdocMetadata: !!tsdocMetadataPath,
|
|
1246
|
+
hasTsconfig: !!state.parsedConfig && !!state.tsconfigPath,
|
|
903
1247
|
cwd,
|
|
904
1248
|
distPath: `dist/${envId}`
|
|
905
1249
|
});
|
|
@@ -908,19 +1252,28 @@ function runTsgo(options) {
|
|
|
908
1252
|
if (tsdocMetadataPath) {
|
|
909
1253
|
const tsdocMetadataOption = "object" == typeof options.apiModel ? options.apiModel.tsdocMetadata : void 0;
|
|
910
1254
|
const tsdocMetadataFilename = "object" == typeof tsdocMetadataOption && tsdocMetadataOption.filename ? tsdocMetadataOption.filename : "tsdoc-metadata.json";
|
|
911
|
-
const tsdocMetadataContent = await readFile(tsdocMetadataPath, "utf-8");
|
|
1255
|
+
const tsdocMetadataContent = (await readFile(tsdocMetadataPath, "utf-8")).replaceAll("\r\n", "\n");
|
|
912
1256
|
const tsdocMetadataSource = new context.sources.OriginalSource(tsdocMetadataContent, tsdocMetadataFilename);
|
|
913
1257
|
context.compilation.emitAsset(tsdocMetadataFilename, tsdocMetadataSource);
|
|
914
1258
|
if (filesArray) filesArray.add(tsdocMetadataFilename);
|
|
915
1259
|
core_logger.info(`${picocolors.dim(`[${envId}]`)} Emitted TSDoc metadata: ${tsdocMetadataFilename}`);
|
|
916
1260
|
}
|
|
917
1261
|
if (tsdocConfigPath) {
|
|
918
|
-
const tsdocConfigContent = await readFile(tsdocConfigPath, "utf-8");
|
|
1262
|
+
const tsdocConfigContent = (await readFile(tsdocConfigPath, "utf-8")).replaceAll("\r\n", "\n");
|
|
919
1263
|
const tsdocConfigSource = new context.sources.OriginalSource(tsdocConfigContent, "tsdoc.json");
|
|
920
1264
|
context.compilation.emitAsset("tsdoc.json", tsdocConfigSource);
|
|
921
1265
|
if (filesArray) filesArray.add("!tsdoc.json");
|
|
922
1266
|
core_logger.info(`${picocolors.dim(`[${envId}]`)} Emitted TSDoc config: tsdoc.json (excluded from npm publish)`);
|
|
923
1267
|
}
|
|
1268
|
+
if (apiModelPath && state.parsedConfig && state.tsconfigPath) {
|
|
1269
|
+
const resolver = new TsconfigResolver();
|
|
1270
|
+
const resolvedTsconfig = resolver.resolve(state.parsedConfig, cwd);
|
|
1271
|
+
const tsconfigContent = `${JSON.stringify(resolvedTsconfig, null, "\t")}\n`;
|
|
1272
|
+
const tsconfigSource = new context.sources.OriginalSource(tsconfigContent, "tsconfig.json");
|
|
1273
|
+
context.compilation.emitAsset("tsconfig.json", tsconfigSource);
|
|
1274
|
+
if (filesArray) filesArray.add("!tsconfig.json");
|
|
1275
|
+
core_logger.info(`${picocolors.dim(`[${envId}]`)} Emitted resolved tsconfig: tsconfig.json (excluded from npm publish)`);
|
|
1276
|
+
}
|
|
924
1277
|
for (const [entryName] of bundledFiles){
|
|
925
1278
|
const bundledFileName = `${entryName}.d.ts`;
|
|
926
1279
|
const mapFileName = `${bundledFileName}.map`;
|
|
@@ -978,7 +1331,7 @@ function runTsgo(options) {
|
|
|
978
1331
|
api.onCloseBuild(async ()=>{
|
|
979
1332
|
const localPathsData = api.useExposed("dts-local-paths-data");
|
|
980
1333
|
if (!localPathsData) return;
|
|
981
|
-
const { localPaths, apiModelFilename, localTsdocFilename, hasTsdocMetadata, cwd, distPath } = localPathsData;
|
|
1334
|
+
const { localPaths, apiModelFilename, localTsdocFilename, hasTsdocMetadata, hasTsconfig, cwd, distPath } = localPathsData;
|
|
982
1335
|
const distDir = (0, external_node_path_.join)(cwd, distPath);
|
|
983
1336
|
for (const localPath of localPaths){
|
|
984
1337
|
const resolvedPath = (0, external_node_path_.join)(cwd, localPath);
|
|
@@ -1002,6 +1355,14 @@ function runTsgo(options) {
|
|
|
1002
1355
|
name: localTsdocFilename
|
|
1003
1356
|
});
|
|
1004
1357
|
}
|
|
1358
|
+
if (hasTsconfig) {
|
|
1359
|
+
const tsconfigSrc = (0, external_node_path_.join)(distDir, "tsconfig.json");
|
|
1360
|
+
if (existsSync(tsconfigSrc)) filesToCopy.push({
|
|
1361
|
+
src: tsconfigSrc,
|
|
1362
|
+
dest: (0, external_node_path_.join)(resolvedPath, "tsconfig.json"),
|
|
1363
|
+
name: "tsconfig.json"
|
|
1364
|
+
});
|
|
1365
|
+
}
|
|
1005
1366
|
const packageJsonSrc = (0, external_node_path_.join)(distDir, "package.json");
|
|
1006
1367
|
if (existsSync(packageJsonSrc)) filesToCopy.push({
|
|
1007
1368
|
src: packageJsonSrc,
|
package/package.json
CHANGED
|
@@ -1,9 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@savvy-web/rslib-builder",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "RSlib-based build system for Node.js libraries with automatic package.json transformation, TypeScript declaration bundling, and multi-target support",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"rslib",
|
|
8
|
+
"rsbuild",
|
|
9
|
+
"typescript",
|
|
10
|
+
"declarations",
|
|
11
|
+
"dts",
|
|
12
|
+
"bundler",
|
|
13
|
+
"build",
|
|
14
|
+
"esm",
|
|
15
|
+
"node",
|
|
16
|
+
"library",
|
|
17
|
+
"api-extractor",
|
|
18
|
+
"tsgo",
|
|
19
|
+
"tsdoc",
|
|
20
|
+
"monorepo"
|
|
21
|
+
],
|
|
6
22
|
"homepage": "https://github.com/savvy-web/rslib-builder",
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/savvy-web/rslib-builder/issues"
|
|
25
|
+
},
|
|
7
26
|
"repository": {
|
|
8
27
|
"type": "git",
|
|
9
28
|
"url": "https://github.com/savvy-web/rslib-builder.git"
|
|
@@ -64,6 +83,7 @@
|
|
|
64
83
|
},
|
|
65
84
|
"files": [
|
|
66
85
|
"!rslib-builder.api.json",
|
|
86
|
+
"!tsconfig.json",
|
|
67
87
|
"LICENSE",
|
|
68
88
|
"README.md",
|
|
69
89
|
"index.d.ts",
|
package/tsdoc-metadata.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
// This file is read by tools that parse documentation comments conforming to the TSDoc standard.
|
|
2
|
-
// It should be published with your NPM package. It should not be tracked by Git.
|
|
3
|
-
{
|
|
4
|
-
"tsdocVersion": "0.12",
|
|
5
|
-
"toolPackages": [
|
|
6
|
-
{
|
|
7
|
-
"packageName": "@microsoft/api-extractor",
|
|
8
|
-
"packageVersion": "7.55.2"
|
|
9
|
-
}
|
|
10
|
-
]
|
|
11
|
-
}
|
|
1
|
+
// This file is read by tools that parse documentation comments conforming to the TSDoc standard.
|
|
2
|
+
// It should be published with your NPM package. It should not be tracked by Git.
|
|
3
|
+
{
|
|
4
|
+
"tsdocVersion": "0.12",
|
|
5
|
+
"toolPackages": [
|
|
6
|
+
{
|
|
7
|
+
"packageName": "@microsoft/api-extractor",
|
|
8
|
+
"packageVersion": "7.55.2"
|
|
9
|
+
}
|
|
10
|
+
]
|
|
11
|
+
}
|