@savvy-web/rslib-builder 0.6.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.
Files changed (3) hide show
  1. package/README.md +2 -1
  2. package/index.js +345 -2
  3. package/package.json +21 -1
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 documentation tooling
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.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",
@@ -918,6 +1243,7 @@ function runTsgo(options) {
918
1243
  apiModelFilename,
919
1244
  localTsdocFilename,
920
1245
  hasTsdocMetadata: !!tsdocMetadataPath,
1246
+ hasTsconfig: !!state.parsedConfig && !!state.tsconfigPath,
921
1247
  cwd,
922
1248
  distPath: `dist/${envId}`
923
1249
  });
@@ -939,6 +1265,15 @@ function runTsgo(options) {
939
1265
  if (filesArray) filesArray.add("!tsdoc.json");
940
1266
  core_logger.info(`${picocolors.dim(`[${envId}]`)} Emitted TSDoc config: tsdoc.json (excluded from npm publish)`);
941
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
+ }
942
1277
  for (const [entryName] of bundledFiles){
943
1278
  const bundledFileName = `${entryName}.d.ts`;
944
1279
  const mapFileName = `${bundledFileName}.map`;
@@ -996,7 +1331,7 @@ function runTsgo(options) {
996
1331
  api.onCloseBuild(async ()=>{
997
1332
  const localPathsData = api.useExposed("dts-local-paths-data");
998
1333
  if (!localPathsData) return;
999
- const { localPaths, apiModelFilename, localTsdocFilename, hasTsdocMetadata, cwd, distPath } = localPathsData;
1334
+ const { localPaths, apiModelFilename, localTsdocFilename, hasTsdocMetadata, hasTsconfig, cwd, distPath } = localPathsData;
1000
1335
  const distDir = (0, external_node_path_.join)(cwd, distPath);
1001
1336
  for (const localPath of localPaths){
1002
1337
  const resolvedPath = (0, external_node_path_.join)(cwd, localPath);
@@ -1020,6 +1355,14 @@ function runTsgo(options) {
1020
1355
  name: localTsdocFilename
1021
1356
  });
1022
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
+ }
1023
1366
  const packageJsonSrc = (0, external_node_path_.join)(distDir, "package.json");
1024
1367
  if (existsSync(packageJsonSrc)) filesToCopy.push({
1025
1368
  src: packageJsonSrc,
package/package.json CHANGED
@@ -1,9 +1,28 @@
1
1
  {
2
2
  "name": "@savvy-web/rslib-builder",
3
- "version": "0.6.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",