@ts-ioc-container/bundler 2.0.0 → 3.0.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 (115) hide show
  1. package/AGENTS.md +36 -23
  2. package/README.md +64 -84
  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 +48 -0
  14. package/cjm/exceptions/ExceptionHandler.js +38 -0
  15. package/cjm/features/build/BuildConfig.js +146 -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} +0 -27
  19. package/cjm/features/build/domain/configFiles.js +35 -0
  20. package/cjm/{emit.js → features/build/domain/emit.js} +9 -11
  21. package/cjm/{scan.js → features/build/domain/scan.js} +0 -18
  22. package/cjm/features/build/domain/tokenCollisions.js +29 -0
  23. package/cjm/{tsconfig.js → features/build/domain/tsconfig.js} +17 -11
  24. package/cjm/features/build/services/BundleBuilder.js +93 -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 +83 -26
  30. package/cjm/modules/CommonModule.js +28 -0
  31. package/cjm/schema/ticConfigSchema.js +20 -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 +9 -7
  37. package/tic.schema.json +79 -113
  38. package/tpl/index.cjs +19 -41
  39. package/typings/app.d.ts +23 -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 +33 -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 +159 -0
  61. package/typings/features/build/BuildConfig.d.ts.map +1 -0
  62. package/typings/features/build/BuildController.d.ts +31 -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} +2 -9
  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 +36 -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} +1 -3
  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 +21 -0
  78. package/typings/features/build/domain/tsconfig.d.ts.map +1 -0
  79. package/typings/features/build/services/BundleBuilder.d.ts +65 -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 -9
  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 -106
  103. package/cjm/cli.js +0 -109
  104. package/cjm/config.js +0 -199
  105. package/cjm/errors.js +0 -15
  106. package/cjm/render.js +0 -15
  107. package/typings/build.d.ts +0 -42
  108. package/typings/cli.d.ts +0 -8
  109. package/typings/config.d.ts +0 -162
  110. package/typings/emit.d.ts +0 -23
  111. package/typings/errors.d.ts +0 -13
  112. package/typings/render.d.ts +0 -8
  113. package/typings/tsconfig.d.ts +0 -25
  114. /package/cjm/{glob.js → features/build/domain/glob.js} +0 -0
  115. /package/typings/{glob.d.ts → features/build/domain/glob.d.ts} +0 -0
@@ -1,162 +0,0 @@
1
- /**
2
- * Which files a bundle reads and parses: the first, cheap stage of selection,
3
- * decided by path alone. The candidates are what the extended tsconfig compiles,
4
- * or the folders in `paths` when given — they override the tsconfig's file set,
5
- * as a child tsconfig's `include` overrides its parent's. A candidate is parsed
6
- * when it matches one of `include` and none of `exclude`. Globs are relative to
7
- * the config file and `/`-separated. With a file naming convention
8
- * (`*.service.ts`), `include` keeps the bundler from reading anything else.
9
- */
10
- export interface FileSelector {
11
- /**
12
- * Folders to scan instead of the tsconfig's file set: relative to the config file,
13
- * or tsconfig `paths` aliases. Required when there is no tsconfig to extend.
14
- */
15
- paths?: (string | PathConfig)[];
16
- /** Globs a file must match one of, e.g. `**\/*.service.ts`. Default: every source file. */
17
- include?: string[];
18
- /** Globs of files never read. Replaces {@link DEFAULT_EXCLUDE} when given. */
19
- exclude?: string[];
20
- }
21
- /** A {@link FileSelector} with its defaults filled in and its globs compiled. */
22
- export interface ResolvedFileSelector {
23
- /** `undefined`: the extended tsconfig's file set. */
24
- paths?: Required<PathConfig>[];
25
- include?: RegExp[];
26
- exclude: RegExp[];
27
- }
28
- /** Which exports of a file count: both kinds, only named exports, or only the default export. */
29
- export type ExportKind = 'any' | 'named' | 'default';
30
- /**
31
- * Which classes of a parsed file are registered: the second stage of selection,
32
- * run on the files {@link FileSelector} let through. A class is selected when
33
- * it is exported, not abstract, and meets every criterion set here; an empty
34
- * rule selects every exported class.
35
- */
36
- export interface ClassSelector {
37
- /** Default `any`. */
38
- export?: ExportKind;
39
- /**
40
- * The class must carry one of these decorators, recognised by name (`register`, or a
41
- * composed one). Default {@link DEFAULT_DECORATORS}; `[]` requires none.
42
- */
43
- decorators?: string[];
44
- /** A glob the class name must match, e.g. `*Service`. An anonymous default export is named after its file. */
45
- name?: string;
46
- /**
47
- * Class names to drop after selection, e.g. one test double sitting next to the
48
- * real registration in the same file.
49
- */
50
- excludeClasses?: string[];
51
- /** A glob the class name must NOT match, e.g. `*Mock`. An anonymous default export is named after its file. */
52
- excludeName?: string;
53
- }
54
- /** A {@link ClassSelector} with its defaults filled in and its globs compiled. */
55
- export interface ResolvedClassSelector {
56
- export: ExportKind;
57
- decorators?: string[];
58
- name?: RegExp;
59
- excludeClasses?: string[];
60
- excludeName?: RegExp;
61
- }
62
- export interface PathConfig {
63
- /** A folder relative to the config file (`./src/services`) or a tsconfig `paths` alias (`@app/services`). */
64
- path: string;
65
- /** Scan sub-folders too. Default `true`. */
66
- recursive?: boolean;
67
- }
68
- /**
69
- * The shape of `*.bundle.json`: one bundle, built on one tsconfig. A project that
70
- * needs several bundles keeps one config file per bundle.
71
- */
72
- export interface BundleConfig {
73
- $schema?: string;
74
- /**
75
- * The generated file, relative to the config file. Default `<root>/<name>.bundle.ts`:
76
- * `<root>` is the tsconfig's `rootDir`, else the common folder of the files it compiles.
77
- * Required when there is no tsconfig to extend.
78
- */
79
- output?: string;
80
- /**
81
- * The bundle's name: letters, digits, `-` and `_`, starting with a letter. Default: the
82
- * config file's stem (`production.bundle.json` -> `production`), else {@link DEFAULT_BUNDLE_NAME}.
83
- * It names the default output (`production.bundle.ts`) and the generated class,
84
- * an `IContainerModule` (`ProductionBundle`, see {@link toClassName}).
85
- */
86
- name?: string;
87
- /** Tags associated with the bundle. */
88
- tags?: string[];
89
- /**
90
- * The tsconfig the bundle builds on, like a tsconfig's own `extends`: the source of
91
- * its file set, `paths` aliases and import extension. Relative to the config file.
92
- * Default `./tsconfig.json`, which may be absent; a tsconfig named here must exist.
93
- */
94
- extends?: string;
95
- /** Extension of generated imports. Inferred from the tsconfig's `moduleResolution` when omitted. */
96
- importExtension?: string;
97
- /** Which files are parsed. Default: what the tsconfig compiles, minus {@link DEFAULT_EXCLUDE}. */
98
- files?: FileSelector;
99
- /** Which classes of a parsed file are registered. Default: every exported class. */
100
- classes?: ClassSelector;
101
- }
102
- /**
103
- * A config file is named `<name>.bundle.json`, `<name>.bundle.yaml` or `<name>.bundle.yml`,
104
- * e.g. `app.bundle.json`, `production.bundle.yaml`. Every format has the same shape.
105
- */
106
- export declare const CONFIG_FILE_SUFFIXES: string[];
107
- export declare const DEFAULT_EXTENDS = "./tsconfig.json";
108
- /** The bundle name when the config file gives none, e.g. building from `tsconfig.json` alone. */
109
- export declare const DEFAULT_BUNDLE_NAME = "base";
110
- /** What `classes.decorators` requires when omitted: the library's own `@register`. */
111
- export declare const DEFAULT_DECORATORS: string[];
112
- export declare const DEFAULT_EXCLUDE: string[];
113
- /** A {@link BundleConfig} whose defaults are filled in and whose paths are absolute. */
114
- export interface ResolvedConfig {
115
- /** The config file itself. */
116
- file: string;
117
- dir: string;
118
- /** `undefined`: derived from the tsconfig at build time (see {@link BundleConfig.output}). */
119
- output?: string;
120
- /** The bundle name: `production` for `production.bundle.json`. */
121
- name: string;
122
- /** The generated class: `ProductionBundle`. */
123
- className: string;
124
- tags: string[];
125
- /** The extended tsconfig; `required` when the config names it, so it must exist. */
126
- tsconfig: {
127
- file: string;
128
- required: boolean;
129
- };
130
- importExtension?: string;
131
- files: ResolvedFileSelector;
132
- classes: ResolvedClassSelector;
133
- /** Non-fatal problems found while resolving, e.g. a `files.exclude` that drops a default test glob. */
134
- warnings: string[];
135
- }
136
- /**
137
- * Validates parsed `*.bundle.json` content and resolves its paths against `file`'s directory.
138
- *
139
- * @throws {TicConfigError} when the content does not match the config shape; the message names the field.
140
- */
141
- export declare function resolveConfig(content: unknown, file: string): ResolvedConfig;
142
- /** The generated class for a bundle name: `production` -> `ProductionBundle`, `my-app_v2` -> `MyAppV2Bundle`. */
143
- export declare function toClassName(name: string): string;
144
- /**
145
- * The root of the package `dir` belongs to: the nearest folder, `dir` or above, with a
146
- * `package.json` — the project root in a single-package project, the package in a
147
- * monorepo. `dir` itself when no folder above has one.
148
- */
149
- export declare function findPackageRoot(dir: string): string;
150
- /**
151
- * The `*.bundle.{json,yaml,yml}` configs in `dir` (not its sub-folders), sorted by name.
152
- *
153
- * @throws {TicConfigError} when one bundle is described in two formats, e.g. `app.bundle.json` and `app.bundle.yaml`.
154
- */
155
- export declare function findConfigFiles(dir: string): string[];
156
- /**
157
- * Reads and validates a `*.bundle.json`, `*.bundle.yaml` or `*.bundle.yml`.
158
- *
159
- * @throws {TicConfigError} when the file is missing, cannot be parsed, or does not match the config shape.
160
- */
161
- export declare function loadConfig(file: string): ResolvedConfig;
162
- //# sourceMappingURL=config.d.ts.map
package/typings/emit.d.ts DELETED
@@ -1,23 +0,0 @@
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
- /**
18
- * Renders the generated bundle — static imports, `registrations`, and the bundle applying them —
19
- * from its protocol, `protocols/Bundle.ts.hbs`. This function only prepares the data: unique local
20
- * names, and one import per file in file order.
21
- */
22
- export declare function emitBundle({ name, configPath, paths, tsconfigPath, classes }: EmitInput): string;
23
- //# sourceMappingURL=emit.d.ts.map
@@ -1,13 +0,0 @@
1
- /** Base class of every error the bundler raises on purpose; the CLI prints its message without a stack. */
2
- export declare class TicError extends Error {
3
- name: string;
4
- }
5
- /** The config file is missing, is not JSON, or does not match the `.bundles.json` shape. */
6
- export declare class TicConfigError extends TicError {
7
- name: string;
8
- }
9
- /** A namespace is neither an existing folder nor a `tsconfig.json` `paths` alias of one. */
10
- export declare class NamespaceNotFoundError extends TicError {
11
- name: string;
12
- }
13
- //# sourceMappingURL=errors.d.ts.map
@@ -1,8 +0,0 @@
1
- import '../tpl/index.cjs';
2
- /**
3
- * Renders a precompiled protocol, looked up by its file basename (`Bundle.ts.hbs`).
4
- *
5
- * @throws {Error} when no protocol is registered under `name`.
6
- */
7
- export declare function renderProtocol(name: string, data: unknown): string;
8
- //# sourceMappingURL=render.d.ts.map
@@ -1,25 +0,0 @@
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
File without changes