@ts-ioc-container/bundler 8.0.0 → 8.2.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/AGENTS.md +3 -2
- package/README.md +9 -2
- package/cjm/cli/usage.js +1 -1
- package/cjm/features/bundle/BundleController.js +10 -3
- package/cjm/features/bundle/services/BundleService.js +1 -0
- package/package.json +1 -1
- package/typings/features/bundle/BundleController.d.ts +4 -2
- package/typings/features/bundle/BundleController.d.ts.map +1 -1
- package/typings/features/bundle/services/BundleService.d.ts +9 -0
- package/typings/features/bundle/services/BundleService.d.ts.map +1 -1
- package/typings/index.d.ts +1 -1
package/AGENTS.md
CHANGED
|
@@ -14,8 +14,9 @@ it.
|
|
|
14
14
|
prints the bundle to **stdout**; it writes nothing. Saving is the shell's
|
|
15
15
|
job: `tic build app.bundle.json > src/di/app.bundle.ts`,
|
|
16
16
|
`cat dev.bundle.json | tic build > src/di/dev.bundle.ts`; CI checks with
|
|
17
|
-
`tic build app.bundle.json | diff - src/di/app.bundle.ts`.
|
|
18
|
-
|
|
17
|
+
`tic build app.bundle.json | diff - src/di/app.bundle.ts`. Progress (each
|
|
18
|
+
bundled class as ` Name: path`, then a `Bundled …` summary), warnings and
|
|
19
|
+
errors go to stderr. The bundle is `export class AppBundle implements
|
|
19
20
|
IContainerModule`, applied with `container.useModule(new AppBundle())`.
|
|
20
21
|
- Every import in a bundle is written through a tsconfig `paths` alias, so the
|
|
21
22
|
bundle works wherever it is saved; a selected class no alias covers fails the
|
package/README.md
CHANGED
|
@@ -39,8 +39,15 @@ tic build [<config>...]
|
|
|
39
39
|
`tic build` prints the bundle to **stdout** and writes nothing. `<config>` is a
|
|
40
40
|
config file — JSON for `.json`, YAML for `.yaml` / `.yml`. Several are
|
|
41
41
|
[merged](#merging-configs) left to right into one bundle. Without one (or with
|
|
42
|
-
`-`) the config is read from **stdin**.
|
|
43
|
-
they never end up in the bundle
|
|
42
|
+
`-`) the config is read from **stdin**. Progress, warnings and errors go to
|
|
43
|
+
stderr, so they never end up in the bundle:
|
|
44
|
+
|
|
45
|
+
```text
|
|
46
|
+
Bundling AppBundle...
|
|
47
|
+
Clock: src/infra/Clock.ts
|
|
48
|
+
Greeter: src/services/Greeter.ts
|
|
49
|
+
Bundled AppBundle: 2 dependencies from 2 files
|
|
50
|
+
```
|
|
44
51
|
|
|
45
52
|
```bash
|
|
46
53
|
# a config file in, the bundle saved by the shell
|
package/cjm/cli/usage.js
CHANGED
|
@@ -16,7 +16,7 @@ exports.USAGE = [
|
|
|
16
16
|
' -h, --help show this help',
|
|
17
17
|
' -v, --version show the version',
|
|
18
18
|
'',
|
|
19
|
-
'The bundle goes to stdout; the
|
|
19
|
+
'The bundle goes to stdout; progress (the classes in it and a summary) and warnings to stderr.',
|
|
20
20
|
'Saving it is up to you:',
|
|
21
21
|
' tic build app.bundle.json > src/di/app.bundle.ts',
|
|
22
22
|
' tic build common.bundle.yml prod.bundle.yml > src/di/prod.bundle.ts # merged left to right',
|
|
@@ -40,6 +40,7 @@ exports.BUILD_OPTIONS = zod_1.z.object({ positionals: zod_1.z.array(zod_1.z.stri
|
|
|
40
40
|
return { configs: positionals.length > 0 ? positionals : [BuildConfig_1.STDIN] };
|
|
41
41
|
});
|
|
42
42
|
const buildArgs = (0, cli_1.parseOptions)({}, { positionals: true });
|
|
43
|
+
const count = (n, one, many = `${one}s`) => `${n} ${n === 1 ? one : many}`;
|
|
43
44
|
let BundleController = class BundleController {
|
|
44
45
|
io;
|
|
45
46
|
configService;
|
|
@@ -60,12 +61,18 @@ let BundleController = class BundleController {
|
|
|
60
61
|
const config = stdin
|
|
61
62
|
? this.configService.parse(this.stdin(), this.io.cwd)
|
|
62
63
|
: this.configService.load(configs.map((file) => node_path_1.default.resolve(this.io.cwd, file)));
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
this.logger.info(`Bundling ${config.bundleClassName}...`);
|
|
65
|
+
const { bundle, content, classes, files, warnings } = this.bundleService.bundle(config);
|
|
66
|
+
for (const { file, className } of classes) {
|
|
67
|
+
this.logger.info(` ${className}: ${(0, glob_1.toPosix)(node_path_1.default.relative(this.io.cwd, file))}`);
|
|
68
|
+
}
|
|
66
69
|
for (const warning of warnings)
|
|
67
70
|
this.logger.warn(`${label}: ${warning}`);
|
|
68
71
|
this.output.write(content.replace(/\n$/, ''));
|
|
72
|
+
const summary = [count(classes.length, 'dependency', 'dependencies'), `from ${count(files.length, 'file')}`];
|
|
73
|
+
if (warnings.length > 0)
|
|
74
|
+
summary.push(`(${count(warnings.length, 'warning')})`);
|
|
75
|
+
this.logger.info(`Bundled ${bundle}: ${summary.join(' ')}`);
|
|
69
76
|
}
|
|
70
77
|
catch (e) {
|
|
71
78
|
if (e instanceof DomainException_1.TicError && !(e instanceof DomainException_1.UsageError))
|
|
@@ -68,6 +68,7 @@ let BundleService = class BundleService {
|
|
|
68
68
|
bundle: config.bundleClassName,
|
|
69
69
|
registrations: classes.length,
|
|
70
70
|
files: [...new Set(classes.map((cls) => cls.file))],
|
|
71
|
+
classes: classes.map(({ file, className }) => ({ file, className })),
|
|
71
72
|
content,
|
|
72
73
|
warnings: [...config.warnings, ...(0, tokenCollisions_1.tokenCollisions)(classes)],
|
|
73
74
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ts-ioc-container/bundler",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.2.0",
|
|
4
4
|
"description": "Bundles your dependencies into a single container module for ts-ioc-container: the `tic` CLI scans folders (by path or tsconfig alias) and generates one typed bundle that registers every class — `container.useModule(new AppBundle())`.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -29,8 +29,10 @@ export declare class BundleController {
|
|
|
29
29
|
* stdout. Saving it is the shell's job: `tic build app.bundle.json > src/di/app.bundle.ts`,
|
|
30
30
|
* `tic build common.bundle.yml prod.bundle.yml > src/di/prod.bundle.ts`,
|
|
31
31
|
* `cat app.bundle.yml | tic build > out.ts`.
|
|
32
|
-
*
|
|
33
|
-
*
|
|
32
|
+
* Progress goes to stderr, so it never ends up in the bundle: `Bundling AppBundle...`, then
|
|
33
|
+
* each class in it, one per line as its name and its file's path relative to the working
|
|
34
|
+
* directory (` Clock: src/infra/Clock.ts`), the warnings, and a summary
|
|
35
|
+
* (`Bundled AppBundle: 3 dependencies from 2 files (1 warning)`). An error names the configs.
|
|
34
36
|
*
|
|
35
37
|
* @throws {UsageError} when an option is unknown, `-` is given with config files, or the config should come from stdin and nothing is piped in.
|
|
36
38
|
* @throws {TicConfigError} when a config file is missing or unreadable, several are in different folders, the config or its tsconfig is invalid, the bundle has no name, or no tsconfig paths alias covers a selected class's file.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BundleController.d.ts","sourceRoot":"","sources":["../../../lib/features/bundle/BundleController.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,KAAK,KAAK,EAAY,MAAM,oBAAoB,CAAC;AAE1D,OAAO,EAAE,KAAK,OAAO,EAAc,MAAM,8BAA8B,CAAC;AACxE,OAAO,EAAE,KAAK,cAAc,EAAqB,MAAM,8BAA8B,CAAC;AAGtF,OAAO,EAAE,KAAK,cAAc,EAAqB,MAAM,0BAA0B,CAAC;AAClF,OAAO,EAAE,KAAK,iBAAiB,EAAwB,MAAM,6BAA6B,CAAC;AAE3F,eAAO,MAAM,aAAa;;;;;;GAWxB,CAAC;AAEH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,aAAa,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"BundleController.d.ts","sourceRoot":"","sources":["../../../lib/features/bundle/BundleController.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,KAAK,KAAK,EAAY,MAAM,oBAAoB,CAAC;AAE1D,OAAO,EAAE,KAAK,OAAO,EAAc,MAAM,8BAA8B,CAAC;AACxE,OAAO,EAAE,KAAK,cAAc,EAAqB,MAAM,8BAA8B,CAAC;AAGtF,OAAO,EAAE,KAAK,cAAc,EAAqB,MAAM,0BAA0B,CAAC;AAClF,OAAO,EAAE,KAAK,iBAAiB,EAAwB,MAAM,6BAA6B,CAAC;AAE3F,eAAO,MAAM,aAAa;;;;;;GAWxB,CAAC;AAEH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,aAAa,CAAC,CAAC;AAO7D;;;GAGG;AACH,qBACa,gBAAgB;IAEH,OAAO,CAAC,QAAQ,CAAC,EAAE;IACP,OAAO,CAAC,QAAQ,CAAC,aAAa;IACjC,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,MAAM;IAC9B,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAJR,EAAE,EAAE,KAAK,EACG,aAAa,EAAE,iBAAiB,EACnC,aAAa,EAAE,cAAc,EAC7B,MAAM,EAAE,cAAc,EAC7B,MAAM,EAAE,OAAO;IAG1D;;;;;;;;;;;;;;OAcG;IAEH,MAAM,CAAgE,EAAE,OAAO,EAAE,EAAE,eAAe,GAAG,IAAI;IAwBzG;;OAEG;IACH,OAAO,CAAC,KAAK;CAOd"}
|
|
@@ -8,6 +8,8 @@ export interface Bundle {
|
|
|
8
8
|
registrations: number;
|
|
9
9
|
/** Absolute paths of the files the bundle imports from, sorted. */
|
|
10
10
|
files: string[];
|
|
11
|
+
/** The classes the bundle registers, sorted by file and then by declaration order. */
|
|
12
|
+
classes: BundledClass[];
|
|
11
13
|
/** The generated bundle. Nothing is written: saving it is the caller's job (`tic build app.bundle.json > src/di/app.bundle.ts`). */
|
|
12
14
|
content: string;
|
|
13
15
|
/**
|
|
@@ -16,6 +18,13 @@ export interface Bundle {
|
|
|
16
18
|
*/
|
|
17
19
|
warnings: string[];
|
|
18
20
|
}
|
|
21
|
+
/** A class the bundle registers. */
|
|
22
|
+
export interface BundledClass {
|
|
23
|
+
/** Absolute path of the file it is declared in. */
|
|
24
|
+
file: string;
|
|
25
|
+
/** The declared class name; an anonymous default export is named after its file. */
|
|
26
|
+
className: string;
|
|
27
|
+
}
|
|
19
28
|
export interface IBundleService {
|
|
20
29
|
/**
|
|
21
30
|
* Generates the bundle a resolved config describes and returns it; nothing is written.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BundleService.d.ts","sourceRoot":"","sources":["../../../../lib/features/bundle/services/BundleService.ts"],"names":[],"mappings":"AACA,OAAO,EAAwB,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,EAAE,KAAK,kBAAkB,EAAyB,MAAM,yCAAyC,CAAC;AAEzG,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAoB,KAAK,WAAW,EAAkB,MAAM,cAAc,CAAC;AAMlF,MAAM,WAAW,MAAM;IACrB,mCAAmC;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;IACtB,mEAAmE;IACnE,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,oIAAoI;IACpI,OAAO,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B;;;;;OAKG;IACH,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CAAC;CACtC;AAED,eAAO,MAAM,iBAAiB,6BAAoD,CAAC;AAEnF,qBACa,aAAc,YAAW,cAAc;IAEb,OAAO,CAAC,QAAQ,CAAC,EAAE;IAC1B,OAAO,CAAC,QAAQ,CAAC,IAAI;gBADG,EAAE,EAAE,kBAAkB,EAC7B,IAAI,EAAE,WAAW;IAGhE;;;OAGG;IACH,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM;
|
|
1
|
+
{"version":3,"file":"BundleService.d.ts","sourceRoot":"","sources":["../../../../lib/features/bundle/services/BundleService.ts"],"names":[],"mappings":"AACA,OAAO,EAAwB,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,EAAE,KAAK,kBAAkB,EAAyB,MAAM,yCAAyC,CAAC;AAEzG,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAoB,KAAK,WAAW,EAAkB,MAAM,cAAc,CAAC;AAMlF,MAAM,WAAW,MAAM;IACrB,mCAAmC;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;IACtB,mEAAmE;IACnE,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,sFAAsF;IACtF,OAAO,EAAE,YAAY,EAAE,CAAC;IACxB,oIAAoI;IACpI,OAAO,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,oCAAoC;AACpC,MAAM,WAAW,YAAY;IAC3B,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAC;IACb,oFAAoF;IACpF,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,cAAc;IAC7B;;;;;OAKG;IACH,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CAAC;CACtC;AAED,eAAO,MAAM,iBAAiB,6BAAoD,CAAC;AAEnF,qBACa,aAAc,YAAW,cAAc;IAEb,OAAO,CAAC,QAAQ,CAAC,EAAE;IAC1B,OAAO,CAAC,QAAQ,CAAC,IAAI;gBADG,EAAE,EAAE,kBAAkB,EAC7B,IAAI,EAAE,WAAW;IAGhE;;;OAGG;IACH,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM;CA8CrC"}
|
package/typings/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export { type GlobalConfig, GlobalConfigKey, globalConfig } from './domain/Globa
|
|
|
4
4
|
export { Application, action, onDefault, DEFAULT_ACTION, commandArgs, parseOptions, validate, type IErrorHandler, IErrorHandlerKey, USAGE, } from './cli.js';
|
|
5
5
|
export { BuildModule } from './features/bundle/BuildModule.js';
|
|
6
6
|
export { BundleController, BUILD_OPTIONS, type BuildCliOptions } from './features/bundle/BundleController.js';
|
|
7
|
-
export { BundleService, IBundleServiceKey, type IBundleService, type Bundle, } from './features/bundle/services/BundleService.js';
|
|
7
|
+
export { BundleService, IBundleServiceKey, type IBundleService, type Bundle, type BundledClass, } from './features/bundle/services/BundleService.js';
|
|
8
8
|
export { TicConfigService, ITicConfigServiceKey, type ITicConfigService, } from './features/bundle/services/TicConfigService.js';
|
|
9
9
|
export { resolveConfig, BUNDLE_CONFIG_SCHEMA, BUNDLE_CONFIG_FILE_SCHEMA, mergeConfigs, parseConfig, CONFIG_FILE_SUFFIXES, STDIN, configFormat, DEFAULT_TSCONFIG, DEFAULT_EXCLUDE, DEFAULT_DECORATORS, toClassName, type BundleConfigFile, type ClassSelector, type ExportKind, type ResolvedClassSelector, type PathSelector, type ResolvedPathSelector, type BundleConfig, type ConfigFormat, } from './features/bundle/BuildConfig.js';
|
|
10
10
|
export { ticConfigJsonSchema } from './schema/ticConfigSchema.js';
|