@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
package/AGENTS.md CHANGED
@@ -7,40 +7,56 @@ nothing here runs inside the container, and the core package is not changed by
7
7
  it.
8
8
 
9
9
  - The CLI is `ts-ioc-container`, with `tic` as a shortcut (both `bin` entries,
10
- same program). `tic build` reads `tic.config.json` (schema: `tic.schema.json`) and writes one
11
- bundle per `bundles[]` entry — a generated class, `export class AppBundle implements IContainerModule`, applied with `container.useModule(new AppBundle())`. `--check` writes nothing and exits 1
12
- when an output is stale — run it in CI.
13
- - A namespace is a folder: relative to the config file, or a tsconfig `paths`
14
- alias. Generated imports use the most specific alias, else a relative path.
15
- - Default selection is every exported, non-abstract class. A module's
16
- `select: { export, decorators, nameGlob, excludeClasses, excludeNameGlob, excludeAliases }`
17
- narrows it; positive criteria must all hold and then `excludeClasses` (exact
18
- names), `excludeNameGlob` (glob) and `excludeAliases` (tsconfig `paths` aliases
19
- the file resolves through, e.g. `services` for `@services/*`) drop classes.
10
+ same program). One config file describes one bundle: `<name>.bundle.json`, or the same in
11
+ YAML as `<name>.bundle.yaml` / `.yml` (an empty YAML file = all defaults)
12
+ (schema: `tic.schema.json`), flat — `output`, `name`, `tags`, `extends`,
13
+ `importExtension`, `files`, `classes`, all optional. `tic build` works on
14
+ the package it is invoked in (nearest `package.json` up from the working
15
+ directory; never a workspace root): it builds every `*.bundle.{json,yaml,yml}` there
16
+ (or the ones named with repeatable `-c`), else — zero config — one bundle
17
+ from that package's `tsconfig.json` with every default. Each writes one class — `export class AppBundle implements IContainerModule`,
18
+ applied with `container.useModule(new AppBundle())`. Several bundles (e.g.
19
+ `production.bundle.json`, `development.bundle.json`) mean several configs.
20
+ `--check` writes nothing and exits 1 when an output is stale — run it in CI.
21
+ - A config `extends` a tsconfig (default `./tsconfig.json`, may be absent; one
22
+ named explicitly must exist), like a child tsconfig: what it compiles is the
23
+ bundle's file set, and its `paths` aliases and module resolution shape the
24
+ generated imports (most specific alias, else a relative path). `output`
25
+ defaults to `<root>/<name>.bundle.ts`: root = tsconfig `rootDir`, else the
26
+ common folder of its files. `name` defaults to the config's stem
27
+ (`production.bundle.json` → `production`), else `base`; the class is
28
+ `toClassName(name)` — `ProductionBundle`, `BaseBundle`.
29
+ - Selection has two stages. `files: { paths, include, exclude }` decides by path
30
+ which files are read and parsed at all. `paths` override the tsconfig's file
31
+ set with folders (relative to the config, or tsconfig aliases); required when
32
+ there is no tsconfig. A candidate must match one of `include` (default: all)
33
+ and none of `exclude` (default: test files, `__tests__/`, `node_modules/`; a
34
+ non-empty list replaces it, and the build warns if it drops a default). Globs
35
+ are relative to the config. With file naming conventions, `include` is the
36
+ speed lever — nothing else is read. Files `tic build` generated are never input.
37
+ - `classes: { export, decorators, name, excludeClasses, excludeName }`
38
+ then picks classes of the parsed files; default is every exported,
39
+ non-abstract class decorated with `@register` (`decorators` defaults to
40
+ `["register"]`; `[]` requires none); positive criteria must all hold and then `excludeClasses` (exact
41
+ names) and `excludeName` (glob) drop classes.
20
42
  Decorators match by name, so composed ones must be listed. The build warns when
21
43
  two selected classes pass the same plain-identifier first decorator argument (a
22
44
  same-token heuristic), unless a decorator they share has differing arguments
23
45
  (scope-gated, e.g. `@perPage('a')` vs `@perPage('b')`).
24
46
  - Never edit a `*.bundle.ts` by hand — change the classes or the config and
25
47
  rerun `tic build`.
26
- - Files take part when they match no `exclude` glob **and** an
27
- `InclusionPredicate` (`({ filename }) => boolean`, filename relative to the
28
- config) returns true. The predicate comes from `build({ include })`, else the
29
- bundle's `include` file, else a conventional `tic.include.*` next to the
30
- config. Predicate files are `require`d once per process — read env vars
31
- inside the predicate. README "Recipe: generate per environment" shows the
32
- per-environment setup.
33
- - Right after parsing, an `ExportPredicate` (`FilterPredicate<ExportContext>`:
34
- filename, exportName, className, isDefault, decorators, tags) filters class by
35
- class, after `select`; found via `build({ filterExports })`, a bundle's
36
- `filterExports` file, or `tic.exports.*` next to the config.
37
- - Prefer `byTags((tags, context) => ...)` (a `TagInclusionPredicate`) over parsing
38
- file names: tags are the dot-parts between base name and extension
39
- (`Report.production.eu.ts` → `['production', 'eu']`). Usage examples:
40
- `__tests__/examples/inclusion-predicates.spec.ts`.
41
- - For a lean production build, the production entry must import only the
42
- production bundle (README "One bundle per environment"); statically importing
43
- both bundles ships both.
44
- - Programmatic API: `build({ config, cwd, check })`, `run(argv, io)`,
45
- `loadConfig(file)`; errors are `TicConfigError` / `NamespaceNotFoundError`
46
- (both `TicError`).
48
+ - Unknown config fields are errors, at every level.
49
+ - Programmatic API: `build({ config, cwd, check })` (one config, one output),
50
+ `findConfigFiles(dir)`, `run(argv, io)`, `loadConfig(file)`; every error the
51
+ bundler raises on purpose is a `TicError` with a stable `code`
52
+ (`TicConfigError` = `INVALID_CONFIG`, `NamespaceNotFoundError`, `UsageError`,
53
+ `StaleBundlesError`, …).
54
+ - Internals follow `release-monorepo-semantically` (ADR 0023): `createContainer(io)`
55
+ in `lib/app.ts` is the composition root; `Application` resolves the controller
56
+ registered under the command name (`@register('build')`) and runs its
57
+ `@onDefault(invoke)` action, which parses its own options with
58
+ `@inject(pipe(commandArgs, parseOptions(spec), validate(SCHEMA)))`. Work lives in
59
+ services behind tokens (`IBundleBuilderKey`, `ITicConfigServiceKey`, …); pure
60
+ logic in `lib/features/build/domain/`. A new command is a controller plus a module.
61
+ - The config schema is `BUNDLE_CONFIG_SCHEMA` (zod); `tic.schema.json` is generated
62
+ from it with `pnpm run generate:schema` — never edit it by hand.