@ts-ioc-container/bundler 1.5.0 → 2.1.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 (122) hide show
  1. package/AGENTS.md +47 -31
  2. package/README.md +157 -280
  3. package/cjm/app.js +39 -0
  4. package/cjm/bin.js +2 -2
  5. package/cjm/cli/Application.js +58 -0
  6. package/cjm/cli/IErrorHandler.js +5 -0
  7. package/cjm/cli/decorators.js +9 -0
  8. package/cjm/cli/index.js +17 -0
  9. package/cjm/cli/options.js +25 -0
  10. package/cjm/cli/usage.js +19 -0
  11. package/cjm/domain/CliIo.js +7 -0
  12. package/cjm/domain/GlobalConfig.js +7 -0
  13. package/cjm/exceptions/DomainException.js +54 -0
  14. package/cjm/exceptions/ExceptionHandler.js +38 -0
  15. package/cjm/features/build/BuildConfig.js +183 -0
  16. package/cjm/features/build/BuildController.js +91 -0
  17. package/cjm/features/build/BuildModule.js +16 -0
  18. package/cjm/{ImportPaths.js → features/build/domain/ImportPaths.js} +7 -29
  19. package/cjm/features/build/domain/configFiles.js +35 -0
  20. package/cjm/{emit.js → features/build/domain/emit.js} +10 -9
  21. package/cjm/{scan.js → features/build/domain/scan.js} +6 -3
  22. package/cjm/features/build/domain/tokenCollisions.js +29 -0
  23. package/cjm/features/build/domain/tsconfig.js +78 -0
  24. package/cjm/features/build/services/BundleBuilder.js +116 -0
  25. package/cjm/features/build/services/TicConfigService.js +68 -0
  26. package/cjm/features/help/HelpController.js +39 -0
  27. package/cjm/features/help/HelpModule.js +12 -0
  28. package/cjm/features/help/VersionController.js +45 -0
  29. package/cjm/index.js +87 -28
  30. package/cjm/modules/CommonModule.js +28 -0
  31. package/cjm/schema/ticConfigSchema.js +24 -0
  32. package/cjm/services/ConsoleLogger.js +36 -0
  33. package/cjm/services/HandlebarsRenderService.js +33 -0
  34. package/cjm/services/NodeFileSystemService.js +32 -0
  35. package/cjm/services/OutputService.js +33 -0
  36. package/package.json +10 -7
  37. package/tic.schema.json +118 -147
  38. package/tpl/index.cjs +36 -16
  39. package/typings/app.d.ts +24 -0
  40. package/typings/cli/Application.d.ts +16 -0
  41. package/typings/cli/Application.d.ts.map +1 -0
  42. package/typings/cli/IErrorHandler.d.ts +7 -0
  43. package/typings/cli/IErrorHandler.d.ts.map +1 -0
  44. package/typings/cli/decorators.d.ts +10 -0
  45. package/typings/cli/decorators.d.ts.map +1 -0
  46. package/typings/cli/index.d.ts +6 -0
  47. package/typings/cli/index.d.ts.map +1 -0
  48. package/typings/cli/options.d.ts +23 -0
  49. package/typings/cli/options.d.ts.map +1 -0
  50. package/typings/cli/usage.d.ts +2 -0
  51. package/typings/cli/usage.d.ts.map +1 -0
  52. package/typings/domain/CliIo.d.ts +10 -0
  53. package/typings/domain/CliIo.d.ts.map +1 -0
  54. package/typings/domain/GlobalConfig.d.ts +10 -0
  55. package/typings/domain/GlobalConfig.d.ts.map +1 -0
  56. package/typings/exceptions/DomainException.d.ts +37 -0
  57. package/typings/exceptions/DomainException.d.ts.map +1 -0
  58. package/typings/exceptions/ExceptionHandler.d.ts +12 -0
  59. package/typings/exceptions/ExceptionHandler.d.ts.map +1 -0
  60. package/typings/features/build/BuildConfig.d.ts +179 -0
  61. package/typings/features/build/BuildConfig.d.ts.map +1 -0
  62. package/typings/features/build/BuildController.d.ts +32 -0
  63. package/typings/features/build/BuildController.d.ts.map +1 -0
  64. package/typings/features/build/BuildModule.d.ts +5 -0
  65. package/typings/features/build/BuildModule.d.ts.map +1 -0
  66. package/typings/{ImportPaths.d.ts → features/build/domain/ImportPaths.d.ts} +4 -16
  67. package/typings/features/build/domain/ImportPaths.d.ts.map +1 -0
  68. package/typings/features/build/domain/configFiles.d.ts +13 -0
  69. package/typings/features/build/domain/configFiles.d.ts.map +1 -0
  70. package/typings/features/build/domain/emit.d.ts +42 -0
  71. package/typings/features/build/domain/emit.d.ts.map +1 -0
  72. package/typings/features/build/domain/glob.d.ts.map +1 -0
  73. package/typings/{scan.d.ts → features/build/domain/scan.d.ts} +4 -2
  74. package/typings/features/build/domain/scan.d.ts.map +1 -0
  75. package/typings/features/build/domain/tokenCollisions.d.ts +14 -0
  76. package/typings/features/build/domain/tokenCollisions.d.ts.map +1 -0
  77. package/typings/features/build/domain/tsconfig.d.ts +25 -0
  78. package/typings/features/build/domain/tsconfig.d.ts.map +1 -0
  79. package/typings/features/build/services/BundleBuilder.d.ts +68 -0
  80. package/typings/features/build/services/BundleBuilder.d.ts.map +1 -0
  81. package/typings/features/build/services/TicConfigService.d.ts +37 -0
  82. package/typings/features/build/services/TicConfigService.d.ts.map +1 -0
  83. package/typings/features/help/HelpController.d.ts +8 -0
  84. package/typings/features/help/HelpController.d.ts.map +1 -0
  85. package/typings/features/help/HelpModule.d.ts +5 -0
  86. package/typings/features/help/HelpModule.d.ts.map +1 -0
  87. package/typings/features/help/VersionController.d.ts +8 -0
  88. package/typings/features/help/VersionController.d.ts.map +1 -0
  89. package/typings/index.d.ts +25 -11
  90. package/typings/modules/CommonModule.d.ts +9 -0
  91. package/typings/modules/CommonModule.d.ts.map +1 -0
  92. package/typings/schema/ticConfigSchema.d.ts +7 -0
  93. package/typings/schema/ticConfigSchema.d.ts.map +1 -0
  94. package/typings/services/ConsoleLogger.d.ts +20 -0
  95. package/typings/services/ConsoleLogger.d.ts.map +1 -0
  96. package/typings/services/HandlebarsRenderService.d.ts +23 -0
  97. package/typings/services/HandlebarsRenderService.d.ts.map +1 -0
  98. package/typings/services/NodeFileSystemService.d.ts +21 -0
  99. package/typings/services/NodeFileSystemService.d.ts.map +1 -0
  100. package/typings/services/OutputService.d.ts +13 -0
  101. package/typings/services/OutputService.d.ts.map +1 -0
  102. package/cjm/build.js +0 -132
  103. package/cjm/cli.js +0 -84
  104. package/cjm/config.js +0 -162
  105. package/cjm/errors.js +0 -15
  106. package/cjm/exportPredicate.js +0 -13
  107. package/cjm/inclusion.js +0 -24
  108. package/cjm/predicateFile.js +0 -30
  109. package/cjm/render.js +0 -15
  110. package/cjm/utils.js +0 -2
  111. package/typings/build.d.ts +0 -45
  112. package/typings/cli.d.ts +0 -8
  113. package/typings/config.d.ts +0 -123
  114. package/typings/emit.d.ts +0 -18
  115. package/typings/errors.d.ts +0 -13
  116. package/typings/exportPredicate.d.ts +0 -36
  117. package/typings/inclusion.d.ts +0 -42
  118. package/typings/predicateFile.d.ts +0 -16
  119. package/typings/render.d.ts +0 -8
  120. package/typings/utils.d.ts +0 -3
  121. /package/cjm/{glob.js → features/build/domain/glob.js} +0 -0
  122. /package/typings/{glob.d.ts → features/build/domain/glob.d.ts} +0 -0
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The root of the package `dir` belongs to: the nearest folder, `dir` or above, with a
3
+ * `package.json` — the project root in a single-package project, the package in a
4
+ * monorepo. `dir` itself when no folder above has one.
5
+ */
6
+ export declare function findPackageRoot(dir: string): string;
7
+ /**
8
+ * The `*.bundle.{json,yaml,yml}` configs in `dir` (not its sub-folders), sorted by name.
9
+ *
10
+ * @throws {TicConfigError} when one bundle is described in two formats, e.g. `app.bundle.json` and `app.bundle.yaml`.
11
+ */
12
+ export declare function findConfigFiles(dir: string): string[];
13
+ //# sourceMappingURL=configFiles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configFiles.d.ts","sourceRoot":"","sources":["../../../../lib/features/build/domain/configFiles.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAMnD;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAarD"}
@@ -0,0 +1,42 @@
1
+ import type { DiscoveredClass } from './scan.js';
2
+ export interface EmitInput {
3
+ /** Name of the generated class. */
4
+ name: string;
5
+ /** Shown in the header: where the output came from. */
6
+ configPath: string;
7
+ /** The folders scanned; `undefined` when the files came from the extended tsconfig. */
8
+ paths?: string[];
9
+ /** Shown in the header when `paths` is `undefined`: the tsconfig the files came from. */
10
+ tsconfigPath: string;
11
+ classes: (DiscoveredClass & {
12
+ specifier: string;
13
+ })[];
14
+ }
15
+ /** The first line of every generated bundle; marks it as output, never input. */
16
+ export declare const GENERATED_HEADER = "// Generated by `tic build`";
17
+ /** What `protocols/Bundle.ts.hbs` renders. */
18
+ export interface BundleView {
19
+ configPath: string;
20
+ paths?: string[];
21
+ tsconfigPath: string;
22
+ name: string;
23
+ imports: {
24
+ specifier: string;
25
+ defaultName?: string;
26
+ named: string[];
27
+ }[];
28
+ registrations: string[];
29
+ }
30
+ /** The protocol a bundle is rendered from. */
31
+ export declare const BUNDLE_PROTOCOL = "Bundle.ts.hbs";
32
+ /**
33
+ * Prepares the data the bundle protocol renders: unique local names, and one import
34
+ * per file in file order.
35
+ */
36
+ export declare function bundleView({ name, configPath, paths, tsconfigPath, classes }: EmitInput): BundleView;
37
+ /**
38
+ * Renders the generated bundle — static imports, `registrations`, and the bundle applying them —
39
+ * from its protocol, `protocols/Bundle.ts.hbs`.
40
+ */
41
+ export declare function emitBundle(input: EmitInput): string;
42
+ //# sourceMappingURL=emit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emit.d.ts","sourceRoot":"","sources":["../../../../lib/features/build/domain/emit.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAE9C,MAAM,WAAW,SAAS;IACxB,mCAAmC;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,uDAAuD;IACvD,UAAU,EAAE,MAAM,CAAC;IACnB,uFAAuF;IACvF,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,yFAAyF;IACzF,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,CAAC,eAAe,GAAG;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC,EAAE,CAAC;CACtD;AAED,iFAAiF;AACjF,eAAO,MAAM,gBAAgB,gCAAgC,CAAC;AAE9D,8CAA8C;AAC9C,MAAM,WAAW,UAAU;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,EAAE,CAAA;KAAE,EAAE,CAAC;IACxE,aAAa,EAAE,MAAM,EAAE,CAAC;CACzB;AAED,8CAA8C;AAC9C,eAAO,MAAM,eAAe,kBAAkB,CAAC;AAI/C;;;GAGG;AACH,wBAAgB,UAAU,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,EAAE,SAAS,GAAG,UAAU,CAqBpG;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,CAEnD"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"glob.d.ts","sourceRoot":"","sources":["../../../../lib/features/build/domain/glob.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAiBjD;AAED,eAAO,MAAM,OAAO,GAAI,MAAM,MAAM,KAAG,MAAoC,CAAC"}
@@ -1,4 +1,4 @@
1
- import type { ResolvedSelector } from './config.js';
1
+ import type { ResolvedClassSelector } from '../BuildConfig.js';
2
2
  /** An exported class the generated bundle registers. */
3
3
  export interface DiscoveredClass {
4
4
  file: string;
@@ -27,11 +27,13 @@ export interface DiscoveredClass {
27
27
  args: string[];
28
28
  }[];
29
29
  }
30
+ /** A TypeScript source file the bundler may parse: not a declaration file. */
31
+ export declare const isSourceFile: (file: string) => boolean;
30
32
  /** Source files of `dir`, sorted by path so the generated output is stable across machines. */
31
33
  export declare function listSourceFiles(dir: string, recursive: boolean, isExcluded: (file: string) => boolean): string[];
32
34
  /**
33
35
  * The exported, non-abstract classes of one file that `selector` selects, in
34
36
  * declaration order. Syntax only: decorators are recognised by name, not by type.
35
37
  */
36
- export declare function findClasses(file: string, selector: ResolvedSelector, text?: string): DiscoveredClass[];
38
+ export declare function findClasses(file: string, selector: ResolvedClassSelector, text?: string): DiscoveredClass[];
37
39
  //# sourceMappingURL=scan.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scan.d.ts","sourceRoot":"","sources":["../../../../lib/features/build/domain/scan.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAE5D,wDAAwD;AACxD,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,qEAAqE;IACrE,UAAU,EAAE,MAAM,CAAC;IACnB,yEAAyE;IACzE,SAAS,EAAE,MAAM,CAAC;IAClB,oFAAoF;IACpF,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;IACnB,iEAAiE;IACjE,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB;;;;OAIG;IACH,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB;;;;OAIG;IACH,cAAc,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE,EAAE,CAAC;CACpD;AAKD,8EAA8E;AAC9E,eAAO,MAAM,YAAY,GAAI,MAAM,MAAM,KAAG,OAAiE,CAAC;AAE9G,+FAA+F;AAC/F,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,GAAG,MAAM,EAAE,CAchH;AA2BD;;;GAGG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,qBAAqB,EAC/B,IAAI,SAA6B,GAChC,eAAe,EAAE,CAmFnB"}
@@ -0,0 +1,14 @@
1
+ import type { DiscoveredClass } from './scan.js';
2
+ /**
3
+ * A heuristic for "two selected classes bind the same token": when the decorator's
4
+ * first argument is a plain identifier, equal identifiers are almost always the same
5
+ * token, and registration is last-wins, so one silently replaces the other. Purely
6
+ * syntactic — aliased imports and computed keys are not resolved.
7
+ *
8
+ * Scope-gated classes (`@perPage('stations')`, `@perPage('sessions')`) share the
9
+ * token but are not last-wins: the classes are distinguished by a decorator they
10
+ * share called with different arguments, so each scope registers its own. Those
11
+ * groups are not warned about.
12
+ */
13
+ export declare function tokenCollisions(classes: DiscoveredClass[]): string[];
14
+ //# sourceMappingURL=tokenCollisions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tokenCollisions.d.ts","sourceRoot":"","sources":["../../../../lib/features/build/domain/tokenCollisions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAE9C;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,eAAe,EAAE,GAAG,MAAM,EAAE,CAmBpE"}
@@ -0,0 +1,25 @@
1
+ import { ImportPaths } from './ImportPaths.js';
2
+ /** What a bundle takes from the tsconfig it extends. */
3
+ export interface ExtendedTsconfig {
4
+ importPaths: ImportPaths;
5
+ /** Absolute paths of the files the tsconfig compiles; `undefined` when there is no tsconfig. */
6
+ fileNames?: string[];
7
+ /**
8
+ * Where the sources live, as tsc sees it: `rootDir`, else the longest common folder of
9
+ * the non-declaration files it compiles, else the tsconfig's folder. `undefined` when
10
+ * there is no tsconfig.
11
+ */
12
+ rootDir?: string;
13
+ }
14
+ /**
15
+ * Reads the tsconfig a bundle extends, following its own `extends`: its `paths` aliases,
16
+ * import extension and file set (`files` / `include` / `exclude`). An absent tsconfig that
17
+ * was not named explicitly yields no aliases and no file set.
18
+ *
19
+ * @throws {TicConfigError} when a required tsconfig is missing or cannot be parsed.
20
+ */
21
+ export declare function loadTsconfig(tsconfig: {
22
+ file: string;
23
+ required: boolean;
24
+ }, importExtension?: string): ExtendedTsconfig;
25
+ //# sourceMappingURL=tsconfig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tsconfig.d.ts","sourceRoot":"","sources":["../../../../lib/features/build/domain/tsconfig.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAM5C,wDAAwD;AACxD,MAAM,WAAW,gBAAgB;IAC/B,WAAW,EAAE,WAAW,CAAC;IACzB,gGAAgG;IAChG,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAeD;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,QAAQ,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,EAC7C,eAAe,CAAC,EAAE,MAAM,GACvB,gBAAgB,CAkBlB"}
@@ -0,0 +1,68 @@
1
+ import { SingleToken } from 'ts-ioc-container';
2
+ import { type IRenderService } from '../../../services/HandlebarsRenderService.js';
3
+ import { type IFileSystemService } from '../../../services/NodeFileSystemService.js';
4
+ import { type ITicConfigService } from './TicConfigService.js';
5
+ /** What one build does. Paths resolve against the run's working directory. */
6
+ export interface BuildRequest {
7
+ /**
8
+ * Path of the `*.bundle.json` to build, relative to the working directory. Omitted: build
9
+ * from the `tsconfig.json` of the package the working directory is in (see `findPackageRoot`),
10
+ * every setting at its default.
11
+ */
12
+ config?: string;
13
+ /** Compare instead of writing: outputs that would change are reported `stale`. */
14
+ check?: boolean;
15
+ }
16
+ export interface BuildOptions extends BuildRequest {
17
+ /** Default `process.cwd()`. */
18
+ cwd?: string;
19
+ }
20
+ /** `written` / `unchanged` after a build; `stale` / `unchanged` after a check. */
21
+ export type OutputStatus = 'written' | 'unchanged' | 'stale';
22
+ export interface OutputResult {
23
+ /** Absolute path of the generated file. */
24
+ file: string;
25
+ /** Name of the generated class. */
26
+ bundle: string;
27
+ status: OutputStatus;
28
+ registrations: number;
29
+ content: string;
30
+ }
31
+ export interface BuildResult {
32
+ /** Absolute path of the config that was built. */
33
+ config: string;
34
+ output: OutputResult;
35
+ /**
36
+ * Non-fatal problems found while building, e.g. a `files.exclude` that drops a default
37
+ * test glob or two selected classes passing the same decorator token.
38
+ */
39
+ warnings: string[];
40
+ }
41
+ export interface IBundleBuilder {
42
+ /**
43
+ * Generates the bundle a config describes. Nothing is written unless generation succeeds.
44
+ *
45
+ * @throws {TicConfigError} when the config or its tsconfig is missing or invalid, or the config has neither `files.paths` nor a tsconfig.
46
+ * @throws {NamespaceNotFoundError} when a path is neither a folder nor a tsconfig paths alias of one.
47
+ */
48
+ build(request?: BuildRequest): BuildResult;
49
+ }
50
+ export declare const IBundleBuilderKey: SingleToken<IBundleBuilder>;
51
+ export declare class BundleBuilder implements IBundleBuilder {
52
+ private readonly cwd;
53
+ private readonly configs;
54
+ private readonly fs;
55
+ private readonly renderer;
56
+ constructor(cwd: string, configs: ITicConfigService, fs: IFileSystemService, renderer: IRenderService);
57
+ /**
58
+ * @throws {TicConfigError} when the config or its tsconfig is missing or invalid, or the config has neither `files.paths` nor a tsconfig.
59
+ * @throws {NamespaceNotFoundError} when a path is neither a folder nor a tsconfig paths alias of one.
60
+ */
61
+ build({ config, check }?: BuildRequest): BuildResult;
62
+ /**
63
+ * @throws {TicConfigError} when the tsconfig is invalid, or the config names no `files.paths` and there is no tsconfig to take files from.
64
+ * @throws {NamespaceNotFoundError} when a path is neither a folder nor a tsconfig paths alias of one.
65
+ */
66
+ private generate;
67
+ }
68
+ //# sourceMappingURL=BundleBuilder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BundleBuilder.d.ts","sourceRoot":"","sources":["../../../../lib/features/build/services/BundleBuilder.ts"],"names":[],"mappings":"AACA,OAAO,EAAwB,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAGrE,OAAO,EAAE,KAAK,cAAc,EAAqB,MAAM,2CAA2C,CAAC;AACnG,OAAO,EAAE,KAAK,kBAAkB,EAAyB,MAAM,yCAAyC,CAAC;AAQzG,OAAO,EAAE,KAAK,iBAAiB,EAAuC,MAAM,oBAAoB,CAAC;AAEjG,8EAA8E;AAC9E,MAAM,WAAW,YAAY;IAC3B;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kFAAkF;IAClF,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,YAAa,SAAQ,YAAY;IAChD,+BAA+B;IAC/B,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,kFAAkF;AAClF,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,WAAW,GAAG,OAAO,CAAC;AAE7D,MAAM,WAAW,YAAY;IAC3B,2CAA2C;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,mCAAmC;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,YAAY,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,WAAW;IAC1B,kDAAkD;IAClD,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,YAAY,CAAC;IACrB;;;OAGG;IACH,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B;;;;;OAKG;IACH,KAAK,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,WAAW,CAAC;CAC5C;AAED,eAAO,MAAM,iBAAiB,6BAAoD,CAAC;AAEnF,qBACa,aAAc,YAAW,cAAc;IAEnB,OAAO,CAAC,QAAQ,CAAC,GAAG;IACf,OAAO,CAAC,QAAQ,CAAC,OAAO;IACvB,OAAO,CAAC,QAAQ,CAAC,EAAE;IACvB,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAHV,GAAG,EAAE,MAAM,EACN,OAAO,EAAE,iBAAiB,EACzB,EAAE,EAAE,kBAAkB,EAC1B,QAAQ,EAAE,cAAc;IAG1E;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,EAAE,KAAa,EAAE,GAAE,YAAiB,GAAG,WAAW;IAiBhE;;;OAGG;IACH,OAAO,CAAC,QAAQ;CAkDjB"}
@@ -0,0 +1,37 @@
1
+ import { SingleToken } from 'ts-ioc-container';
2
+ import { type IFileSystemService } from '../../../services/NodeFileSystemService.js';
3
+ import { type ResolvedConfig } from '../BuildConfig.js';
4
+ /** The tsconfig a build without a config file extends. */
5
+ export declare const TSCONFIG_FILE = "tsconfig.json";
6
+ export interface ITicConfigService {
7
+ /**
8
+ * Reads and validates a `*.bundle.json`, `*.bundle.yaml` or `*.bundle.yml`.
9
+ *
10
+ * @throws {TicConfigError} when the file is missing, cannot be parsed, or does not match the config shape.
11
+ */
12
+ load(file: string): ResolvedConfig;
13
+ /**
14
+ * The configs to build, as absolute paths: the ones named (relative to the working
15
+ * directory), else every `*.bundle.{json,yaml,yml}` at the root of the package the working
16
+ * directory is in, else `[undefined]` — one build from that package's `tsconfig.json`
17
+ * with default settings. Never looks past the package into a workspace root.
18
+ *
19
+ * @throws {TicConfigError} when none is named and the package has neither a config nor a `tsconfig.json`, or one bundle is described in two formats.
20
+ */
21
+ discover(named: string[]): (string | undefined)[];
22
+ }
23
+ export declare const ITicConfigServiceKey: SingleToken<ITicConfigService>;
24
+ export declare class TicConfigService implements ITicConfigService {
25
+ private readonly cwd;
26
+ private readonly fs;
27
+ constructor(cwd: string, fs: IFileSystemService);
28
+ /**
29
+ * @throws {TicConfigError} when the file is missing, cannot be parsed, or does not match the config shape.
30
+ */
31
+ load(file: string): ResolvedConfig;
32
+ /**
33
+ * @throws {TicConfigError} when none is named and the package has neither a config nor a `tsconfig.json`, or one bundle is described in two formats.
34
+ */
35
+ discover(named: string[]): (string | undefined)[];
36
+ }
37
+ //# sourceMappingURL=TicConfigService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TicConfigService.d.ts","sourceRoot":"","sources":["../../../../lib/features/build/services/TicConfigService.ts"],"names":[],"mappings":"AACA,OAAO,EAAwB,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAIrE,OAAO,EAAE,KAAK,kBAAkB,EAAyB,MAAM,yCAAyC,CAAC;AACzG,OAAO,EAAE,KAAK,cAAc,EAAiB,MAAM,gBAAgB,CAAC;AAGpE,0DAA0D;AAC1D,eAAO,MAAM,aAAa,kBAAkB,CAAC;AAE7C,MAAM,WAAW,iBAAiB;IAChC;;;;OAIG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,CAAC;IAEnC;;;;;;;OAOG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE,CAAC;CACnD;AAED,eAAO,MAAM,oBAAoB,gCAA0D,CAAC;AAE5F,qBACa,gBAAiB,YAAW,iBAAiB;IAEzB,OAAO,CAAC,QAAQ,CAAC,GAAG;IACd,OAAO,CAAC,QAAQ,CAAC,EAAE;gBADR,GAAG,EAAE,MAAM,EACL,EAAE,EAAE,kBAAkB;IAG5E;;OAEG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc;IAKlC;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE;CAQlD"}
@@ -0,0 +1,8 @@
1
+ import { type IOutputService } from '../../services/OutputService.js';
2
+ /** `tic help`, also `tic --help` / `tic -h`. */
3
+ export declare class HelpController {
4
+ private readonly output;
5
+ constructor(output: IOutputService);
6
+ printUsage(): void;
7
+ }
8
+ //# sourceMappingURL=HelpController.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HelpController.d.ts","sourceRoot":"","sources":["../../../lib/features/help/HelpController.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,cAAc,EAAqB,MAAM,8BAA8B,CAAC;AAEtF,gDAAgD;AAChD,qBACa,cAAc;IACkB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,cAAc;IAGlF,UAAU,IAAI,IAAI;CAGnB"}
@@ -0,0 +1,5 @@
1
+ import { type IContainer, type IContainerModule } from 'ts-ioc-container';
2
+ export declare class HelpModule implements IContainerModule {
3
+ applyTo(container: IContainer): void;
4
+ }
5
+ //# sourceMappingURL=HelpModule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HelpModule.d.ts","sourceRoot":"","sources":["../../../lib/features/help/HelpModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,gBAAgB,EAAqB,MAAM,kBAAkB,CAAC;AAI7F,qBAAa,UAAW,YAAW,gBAAgB;IACjD,OAAO,CAAC,SAAS,EAAE,UAAU,GAAG,IAAI;CAGrC"}
@@ -0,0 +1,8 @@
1
+ import { type IOutputService } from '../../services/OutputService.js';
2
+ /** `tic version`, also `tic --version` / `tic -v`. */
3
+ export declare class VersionController {
4
+ private readonly output;
5
+ constructor(output: IOutputService);
6
+ printVersion(): void;
7
+ }
8
+ //# sourceMappingURL=VersionController.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VersionController.d.ts","sourceRoot":"","sources":["../../../lib/features/help/VersionController.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,cAAc,EAAqB,MAAM,8BAA8B,CAAC;AAItF,sDAAsD;AACtD,qBACa,iBAAiB;IACe,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,cAAc;IAGlF,YAAY,IAAI,IAAI;CAGrB"}
@@ -1,12 +1,26 @@
1
- export { build, type BuildOptions, type BuildResult, type OutputResult, type OutputStatus } from './build.js';
2
- export { run, type CliIo } from './cli.js';
3
- export { loadConfig, resolveConfig, DEFAULT_CONFIG_FILE, DEFAULT_EXCLUDE, DEFAULT_BUNDLE_NAME, type TicConfig, type BundleConfig, type NamespaceConfig, type ClassSelector, type ExportKind, type ResolvedSelector, type ResolvedConfig, type ResolvedBundle, } from './config.js';
4
- export { ImportPaths } from './ImportPaths.js';
5
- export { type FilterPredicate } from './utils.js';
6
- export { type ExportPredicate, type ExportContext, EXPORTS_CONVENTION, findConventionalExportPredicate, loadExportPredicate, } from './exportPredicate.js';
7
- export { type InclusionPredicate, type InclusionContext, type TagInclusionPredicate, byTags, fileTags, INCLUSION_CONVENTION, findConventionalPredicate, loadInclusionPredicate, } from './inclusion.js';
8
- export { findClasses, listSourceFiles, type DiscoveredClass } from './scan.js';
9
- export { emitBundle, type EmitInput } from './emit.js';
10
- export { globToRegExp } from './glob.js';
11
- export { TicError, TicConfigError, NamespaceNotFoundError } from './errors.js';
1
+ export { build, run, loadConfig, createContainer } from './app.js';
2
+ export { type CliIo, CliIoKey } from './domain/CliIo.js';
3
+ export { type GlobalConfig, GlobalConfigKey, globalConfig } from './domain/GlobalConfig.js';
4
+ export { Application, action, onDefault, DEFAULT_ACTION, commandArgs, parseOptions, validate, type IErrorHandler, IErrorHandlerKey, USAGE, } from './cli.js';
5
+ export { BuildModule } from './features/build/BuildModule.js';
6
+ export { BuildController, BUILD_OPTIONS, type BuildCliOptions } from './features/build/BuildController.js';
7
+ export { BundleBuilder, IBundleBuilderKey, type IBundleBuilder, type BuildRequest, type BuildOptions, type BuildResult, type OutputResult, type OutputStatus, } from './features/build/services/BundleBuilder.js';
8
+ export { TicConfigService, ITicConfigServiceKey, TSCONFIG_FILE, type ITicConfigService, } from './features/build/services/TicConfigService.js';
9
+ export { resolveConfig, BUNDLE_CONFIG_SCHEMA, CONFIG_FILE_SUFFIXES, DEFAULT_EXTENDS, DEFAULT_EXCLUDE, DEFAULT_BUNDLE_NAME, DEFAULT_DECORATORS, toClassName, type BundleConfig, type PathConfig, type ClassSelector, type ExportKind, type ResolvedClassSelector, type FileSelector, type ResolvedFileSelector, type ResolvedConfig, } from './features/build/BuildConfig.js';
10
+ export { findConfigFiles, findPackageRoot } from './features/build/domain/configFiles.js';
11
+ export { ticConfigJsonSchema } from './schema/ticConfigSchema.js';
12
+ export { ImportPaths } from './features/build/domain/ImportPaths.js';
13
+ export { loadTsconfig, type ExtendedTsconfig } from './features/build/domain/tsconfig.js';
14
+ export { findClasses, isSourceFile, listSourceFiles, type DiscoveredClass } from './features/build/domain/scan.js';
15
+ export { emitBundle, bundleView, BUNDLE_PROTOCOL, GENERATED_HEADER, type EmitInput, type BundleView, } from './features/build/domain/emit.js';
16
+ export { tokenCollisions } from './features/build/domain/tokenCollisions.js';
17
+ export { globToRegExp } from './features/build/domain/glob.js';
18
+ export { HelpModule } from './features/help/HelpModule.js';
19
+ export { CommonModule } from './modules/CommonModule.js';
20
+ export { type IOutputService, IOutputServiceKey, StdOutputService } from './services/OutputService.js';
21
+ export { type ILogger, ILoggerKey, ConsoleLogger } from './services/ConsoleLogger.js';
22
+ export { type IFileSystemService, IFileSystemServiceKey, NodeFileSystemService, } from './services/NodeFileSystemService.js';
23
+ export { type IRenderService, IRenderServiceKey, HandlebarsRenderService, renderProtocol, } from './services/HandlebarsRenderService.js';
24
+ export { TicError, TicConfigError, NamespaceNotFoundError, MissingCommandError, UnknownCommandError, UnknownActionError, UsageError, StaleBundlesError, } from './exceptions/DomainException.js';
25
+ export { ExceptionHandler } from './exceptions/ExceptionHandler.js';
12
26
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,9 @@
1
+ import { type IContainer, type IContainerModule } from 'ts-ioc-container';
2
+ import { type CliIo } from '../domain/CliIo.js';
3
+ /** Services every feature shares: the run's context, its output streams, and error reporting. */
4
+ export declare class CommonModule implements IContainerModule {
5
+ private readonly io;
6
+ constructor(io: CliIo);
7
+ applyTo(container: IContainer): void;
8
+ }
9
+ //# sourceMappingURL=CommonModule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CommonModule.d.ts","sourceRoot":"","sources":["../../lib/modules/CommonModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,gBAAgB,EAAqB,MAAM,kBAAkB,CAAC;AAC7F,OAAO,EAAE,KAAK,KAAK,EAAY,MAAM,iBAAiB,CAAC;AAQvD,iGAAiG;AACjG,qBAAa,YAAa,YAAW,gBAAgB;IACvC,OAAO,CAAC,QAAQ,CAAC,EAAE;gBAAF,EAAE,EAAE,KAAK;IAEtC,OAAO,CAAC,SAAS,EAAE,UAAU,GAAG,IAAI;CAUrC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The JSON Schema published as `tic.schema.json`, generated from the zod schema
3
+ * `tic build` validates with. `pnpm run generate:schema` writes it; a test fails
4
+ * when the committed file is stale.
5
+ */
6
+ export declare function ticConfigJsonSchema(): Record<string, unknown>;
7
+ //# sourceMappingURL=ticConfigSchema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ticConfigSchema.d.ts","sourceRoot":"","sources":["../../lib/schema/ticConfigSchema.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAoB7D"}
@@ -0,0 +1,20 @@
1
+ import { SingleToken } from 'ts-ioc-container';
2
+ import { type CliIo } from '../domain/CliIo.js';
3
+ /**
4
+ * Diagnostics, kept off stdout so a command's output stays machine-readable.
5
+ * Every line is prefixed with `tic:`.
6
+ */
7
+ export interface ILogger {
8
+ /** A non-fatal problem: `tic: warning: <message>`. */
9
+ warn(message: string): void;
10
+ /** A fatal problem: `tic: <message>`. */
11
+ error(message: string): void;
12
+ }
13
+ export declare const ILoggerKey: SingleToken<ILogger>;
14
+ export declare class ConsoleLogger implements ILogger {
15
+ private readonly io;
16
+ constructor(io: CliIo);
17
+ warn(message: string): void;
18
+ error(message: string): void;
19
+ }
20
+ //# sourceMappingURL=ConsoleLogger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConsoleLogger.d.ts","sourceRoot":"","sources":["../../lib/services/ConsoleLogger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,EAAE,KAAK,KAAK,EAAY,MAAM,iBAAiB,CAAC;AAEvD;;;GAGG;AACH,MAAM,WAAW,OAAO;IACtB,sDAAsD;IACtD,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,yCAAyC;IACzC,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B;AAED,eAAO,MAAM,UAAU,sBAAsC,CAAC;AAE9D,qBACa,aAAc,YAAW,OAAO;IACT,OAAO,CAAC,QAAQ,CAAC,EAAE;gBAAF,EAAE,EAAE,KAAK;IAE5D,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAI3B,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;CAG7B"}
@@ -0,0 +1,23 @@
1
+ import '../../tpl/index.cjs';
2
+ import { SingleToken } from 'ts-ioc-container';
3
+ /**
4
+ * Renders a precompiled protocol, looked up by its file basename (`Bundle.ts.hbs`).
5
+ *
6
+ * @throws {Error} when no protocol is registered under `name`.
7
+ */
8
+ export declare function renderProtocol(name: string, data: unknown): string;
9
+ /** Turns prepared data into a generated file through its protocol. */
10
+ export interface IRenderService {
11
+ /**
12
+ * @throws {Error} when no protocol is registered under `protocol`.
13
+ */
14
+ render(protocol: string, data: unknown): string;
15
+ }
16
+ export declare const IRenderServiceKey: SingleToken<IRenderService>;
17
+ export declare class HandlebarsRenderService implements IRenderService {
18
+ /**
19
+ * @throws {Error} when no protocol is registered under `protocol`.
20
+ */
21
+ render(protocol: string, data: unknown): string;
22
+ }
23
+ //# sourceMappingURL=HandlebarsRenderService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HandlebarsRenderService.d.ts","sourceRoot":"","sources":["../../lib/services/HandlebarsRenderService.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAE7B,OAAO,EAAY,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAQzD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,MAAM,CAIlE;AAED,sEAAsE;AACtE,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,MAAM,CAAC;CACjD;AAED,eAAO,MAAM,iBAAiB,6BAAoD,CAAC;AAEnF,qBACa,uBAAwB,YAAW,cAAc;IAC5D;;OAEG;IACH,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,MAAM;CAGhD"}
@@ -0,0 +1,21 @@
1
+ import { SingleToken } from 'ts-ioc-container';
2
+ /** The files a build reads and writes. Paths are absolute. */
3
+ export interface IFileSystemService {
4
+ fileExists(file: string): boolean;
5
+ /**
6
+ * @throws {Error} when the file cannot be read, e.g. it does not exist (`ENOENT`).
7
+ */
8
+ readFile(file: string): string;
9
+ /** Creates missing parent folders. */
10
+ writeFile(file: string, content: string): void;
11
+ }
12
+ export declare const IFileSystemServiceKey: SingleToken<IFileSystemService>;
13
+ export declare class NodeFileSystemService implements IFileSystemService {
14
+ fileExists(file: string): boolean;
15
+ /**
16
+ * @throws {Error} when the file cannot be read, e.g. it does not exist (`ENOENT`).
17
+ */
18
+ readFile(file: string): string;
19
+ writeFile(file: string, content: string): void;
20
+ }
21
+ //# sourceMappingURL=NodeFileSystemService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NodeFileSystemService.d.ts","sourceRoot":"","sources":["../../lib/services/NodeFileSystemService.ts"],"names":[],"mappings":"AAEA,OAAO,EAAY,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEzD,8DAA8D;AAC9D,MAAM,WAAW,kBAAkB;IACjC,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAClC;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B,sCAAsC;IACtC,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CAChD;AAED,eAAO,MAAM,qBAAqB,iCAA4D,CAAC;AAE/F,qBACa,qBAAsB,YAAW,kBAAkB;IAC9D,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAIjC;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAI9B,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;CAI/C"}
@@ -0,0 +1,13 @@
1
+ import { SingleToken } from 'ts-ioc-container';
2
+ import { type CliIo } from '../domain/CliIo.js';
3
+ /** A command's result, one line at a time: what a caller of `tic` reads from stdout. */
4
+ export interface IOutputService {
5
+ write(line: string): void;
6
+ }
7
+ export declare const IOutputServiceKey: SingleToken<IOutputService>;
8
+ export declare class StdOutputService implements IOutputService {
9
+ private readonly io;
10
+ constructor(io: CliIo);
11
+ write(line: string): void;
12
+ }
13
+ //# sourceMappingURL=OutputService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OutputService.d.ts","sourceRoot":"","sources":["../../lib/services/OutputService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,EAAE,KAAK,KAAK,EAAY,MAAM,iBAAiB,CAAC;AAEvD,wFAAwF;AACxF,MAAM,WAAW,cAAc;IAC7B,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAED,eAAO,MAAM,iBAAiB,6BAAoD,CAAC;AAEnF,qBACa,gBAAiB,YAAW,cAAc;IACnB,OAAO,CAAC,QAAQ,CAAC,EAAE;gBAAF,EAAE,EAAE,KAAK;IAE5D,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;CAG1B"}
package/cjm/build.js DELETED
@@ -1,132 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.build = build;
7
- const node_fs_1 = require("node:fs");
8
- const node_path_1 = __importDefault(require("node:path"));
9
- const config_1 = require("./config");
10
- const emit_1 = require("./emit");
11
- const glob_1 = require("./glob");
12
- const ImportPaths_1 = require("./ImportPaths");
13
- const exportPredicate_1 = require("./exportPredicate");
14
- const inclusion_1 = require("./inclusion");
15
- const scan_1 = require("./scan");
16
- function build({ config = config_1.DEFAULT_CONFIG_FILE, cwd = process.cwd(), check = false, include, filterExports, } = {}) {
17
- const resolved = (0, config_1.loadConfig)(node_path_1.default.resolve(cwd, config));
18
- const paths = ImportPaths_1.ImportPaths.load(resolved.tsconfig, resolved.importExtension);
19
- const includeFor = predicateResolver({
20
- override: include,
21
- conventional: (0, inclusion_1.findConventionalPredicate)(resolved.dir),
22
- fileOf: (bundle) => bundle.include,
23
- load: inclusion_1.loadInclusionPredicate,
24
- });
25
- const filterExportsFor = predicateResolver({
26
- override: filterExports,
27
- conventional: (0, exportPredicate_1.findConventionalExportPredicate)(resolved.dir),
28
- fileOf: (bundle) => bundle.filterExports,
29
- load: exportPredicate_1.loadExportPredicate,
30
- });
31
- const generated = resolved.bundles.map((bundle, i) => generate(resolved, bundle, `bundles[${i}]`, paths, {
32
- include: includeFor(bundle),
33
- filterExports: filterExportsFor(bundle),
34
- }));
35
- const outputs = generated.map(({ bundle, content, registrations }) => {
36
- const current = (0, node_fs_1.existsSync)(bundle.output) ? (0, node_fs_1.readFileSync)(bundle.output, 'utf8') : undefined;
37
- const status = current === content ? 'unchanged' : check ? 'stale' : 'written';
38
- if (status === 'written') {
39
- (0, node_fs_1.mkdirSync)(node_path_1.default.dirname(bundle.output), { recursive: true });
40
- (0, node_fs_1.writeFileSync)(bundle.output, content);
41
- }
42
- return { file: bundle.output, bundle: bundle.name, status, registrations, content };
43
- });
44
- return {
45
- config: resolved.file,
46
- outputs,
47
- warnings: [...resolved.warnings, ...generated.flatMap((g) => g.warnings)],
48
- };
49
- }
50
- function predicateResolver({ override, conventional, fileOf, load, }) {
51
- const loaded = new Map();
52
- return (bundle) => {
53
- if (override)
54
- return override;
55
- const file = fileOf(bundle) ?? conventional;
56
- if (file === undefined)
57
- return undefined;
58
- if (!loaded.has(file))
59
- loaded.set(file, load(file));
60
- return loaded.get(file);
61
- };
62
- }
63
- function generate(config, bundle, field, paths, { include, filterExports }) {
64
- const relative = (file) => (0, glob_1.toPosix)(node_path_1.default.relative(config.dir, file));
65
- const outputs = new Set(config.bundles.map((m) => m.output));
66
- const excludes = bundle.exclude.map(glob_1.globToRegExp);
67
- const isExcluded = (file) => {
68
- if (outputs.has(file))
69
- return true;
70
- const filename = relative(file);
71
- return excludes.some((glob) => glob.test(filename)) || (include !== undefined && !include({ filename }));
72
- };
73
- const files = new Set();
74
- for (const namespace of bundle.namespaces) {
75
- const dir = paths.resolveNamespace(namespace.path, config.dir);
76
- for (const file of (0, scan_1.listSourceFiles)(dir, namespace.recursive, isExcluded))
77
- files.add(file);
78
- }
79
- const excludedAliases = new Set((bundle.select.excludeAliases ?? []).map(ImportPaths_1.normalizeAliasName));
80
- const isAliasExcluded = (file) => {
81
- if (excludedAliases.size === 0)
82
- return false;
83
- const alias = paths.aliasName(file);
84
- return alias !== undefined && excludedAliases.has(alias);
85
- };
86
- const classes = [...files]
87
- .sort((a, b) => (a < b ? -1 : a > b ? 1 : 0))
88
- .flatMap((file) => (0, scan_1.findClasses)(file, bundle.select))
89
- .filter((cls) => {
90
- if (isAliasExcluded(cls.file))
91
- return false;
92
- if (!filterExports)
93
- return true;
94
- const filename = relative(cls.file);
95
- const { exportName, className, isDefault, decorators } = cls;
96
- return filterExports({ filename, exportName, className, isDefault, decorators, tags: (0, inclusion_1.fileTags)(filename) });
97
- })
98
- .map((cls) => ({ ...cls, specifier: paths.specifier(bundle.output, cls.file) }));
99
- const content = (0, emit_1.emitBundle)({
100
- name: bundle.name,
101
- configPath: (0, glob_1.toPosix)(node_path_1.default.relative(node_path_1.default.dirname(bundle.output), config.file)),
102
- namespaces: bundle.namespaces.map((ns) => ns.path),
103
- classes,
104
- });
105
- return { bundle, content, registrations: classes.length, warnings: tokenCollisions(classes, field) };
106
- }
107
- function tokenCollisions(classes, field) {
108
- const owners = new Map();
109
- for (const cls of classes) {
110
- for (const token of cls.tokens) {
111
- const group = owners.get(token) ?? [];
112
- if (!group.some((owner) => owner.className === cls.className))
113
- group.push(cls);
114
- owners.set(token, group);
115
- }
116
- }
117
- return [...owners]
118
- .filter(([, group]) => group.length > 1 && !scopeDisjoint(group))
119
- .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
120
- .map(([token, group]) => {
121
- const names = group.map((cls) => cls.className);
122
- return (`${field}: decorator token "${token}" is passed by ${names.join(', ')}; ` +
123
- `registration is last-wins, exclude one with select.excludeClasses`);
124
- });
125
- }
126
- function scopeDisjoint(group) {
127
- const [first, ...rest] = group;
128
- return first.decoratorCalls.some(({ name, args }) => rest.every((cls) => {
129
- const same = cls.decoratorCalls.find((call) => call.name === name);
130
- return same !== undefined && same.args.join('\u0000') !== args.join('\u0000');
131
- }));
132
- }