ioc-manifest 0.3.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/LICENSE +21 -0
- package/README.md +350 -0
- package/bin/ioc.cjs +19 -0
- package/dist/cli/ioc.d.ts +3 -0
- package/dist/cli/ioc.d.ts.map +1 -0
- package/dist/cli/ioc.js +86 -0
- package/dist/cli/ioc.js.map +1 -0
- package/dist/cli/parseIocCli.d.ts +21 -0
- package/dist/cli/parseIocCli.d.ts.map +1 -0
- package/dist/cli/parseIocCli.js +76 -0
- package/dist/cli/parseIocCli.js.map +1 -0
- package/dist/config/iocConfig.d.ts +97 -0
- package/dist/config/iocConfig.d.ts.map +1 -0
- package/dist/config/iocConfig.js +65 -0
- package/dist/config/iocConfig.js.map +1 -0
- package/dist/config/loadIocConfig.d.ts +25 -0
- package/dist/config/loadIocConfig.d.ts.map +1 -0
- package/dist/config/loadIocConfig.js +245 -0
- package/dist/config/loadIocConfig.js.map +1 -0
- package/dist/config/parseDiscoveryScanDirs.d.ts +6 -0
- package/dist/config/parseDiscoveryScanDirs.d.ts.map +1 -0
- package/dist/config/parseDiscoveryScanDirs.js +78 -0
- package/dist/config/parseDiscoveryScanDirs.js.map +1 -0
- package/dist/core/defaultImplementationSelection.d.ts +14 -0
- package/dist/core/defaultImplementationSelection.d.ts.map +1 -0
- package/dist/core/defaultImplementationSelection.js +47 -0
- package/dist/core/defaultImplementationSelection.js.map +1 -0
- package/dist/core/index.d.ts +4 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +3 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/manifest.d.ts +79 -0
- package/dist/core/manifest.d.ts.map +1 -0
- package/dist/core/manifest.js +3 -0
- package/dist/core/manifest.js.map +1 -0
- package/dist/core/resolver.d.ts +18 -0
- package/dist/core/resolver.d.ts.map +1 -0
- package/dist/core/resolver.js +27 -0
- package/dist/core/resolver.js.map +1 -0
- package/dist/generator/contractTypeSourceFile.d.ts +16 -0
- package/dist/generator/contractTypeSourceFile.d.ts.map +1 -0
- package/dist/generator/contractTypeSourceFile.js +236 -0
- package/dist/generator/contractTypeSourceFile.js.map +1 -0
- package/dist/generator/discoverFactories/discoverFactories.d.ts +18 -0
- package/dist/generator/discoverFactories/discoverFactories.d.ts.map +1 -0
- package/dist/generator/discoverFactories/discoverFactories.js +108 -0
- package/dist/generator/discoverFactories/discoverFactories.js.map +1 -0
- package/dist/generator/discoverFactories/discoveryOutcomeTypes.d.ts +47 -0
- package/dist/generator/discoverFactories/discoveryOutcomeTypes.d.ts.map +1 -0
- package/dist/generator/discoverFactories/discoveryOutcomeTypes.js +19 -0
- package/dist/generator/discoverFactories/discoveryOutcomeTypes.js.map +1 -0
- package/dist/generator/discoverFactories/inferFactoryDependencyContracts.d.ts +11 -0
- package/dist/generator/discoverFactories/inferFactoryDependencyContracts.d.ts.map +1 -0
- package/dist/generator/discoverFactories/inferFactoryDependencyContracts.js +118 -0
- package/dist/generator/discoverFactories/inferFactoryDependencyContracts.js.map +1 -0
- package/dist/generator/discoverFactories/scanFactoryFile.d.ts +18 -0
- package/dist/generator/discoverFactories/scanFactoryFile.d.ts.map +1 -0
- package/dist/generator/discoverFactories/scanFactoryFile.js +379 -0
- package/dist/generator/discoverFactories/scanFactoryFile.js.map +1 -0
- package/dist/generator/generateManifest.d.ts +13 -0
- package/dist/generator/generateManifest.d.ts.map +1 -0
- package/dist/generator/generateManifest.js +88 -0
- package/dist/generator/generateManifest.js.map +1 -0
- package/dist/generator/iocProgramContext.d.ts +11 -0
- package/dist/generator/iocProgramContext.d.ts.map +1 -0
- package/dist/generator/iocProgramContext.js +81 -0
- package/dist/generator/iocProgramContext.js.map +1 -0
- package/dist/generator/manifestOptions.d.ts +26 -0
- package/dist/generator/manifestOptions.d.ts.map +1 -0
- package/dist/generator/manifestOptions.js +86 -0
- package/dist/generator/manifestOptions.js.map +1 -0
- package/dist/generator/manifestPaths.d.ts +94 -0
- package/dist/generator/manifestPaths.d.ts.map +1 -0
- package/dist/generator/manifestPaths.js +377 -0
- package/dist/generator/manifestPaths.js.map +1 -0
- package/dist/generator/naming.d.ts +9 -0
- package/dist/generator/naming.d.ts.map +1 -0
- package/dist/generator/naming.js +46 -0
- package/dist/generator/naming.js.map +1 -0
- package/dist/generator/resolveRegistrationPlan.d.ts +66 -0
- package/dist/generator/resolveRegistrationPlan.d.ts.map +1 -0
- package/dist/generator/resolveRegistrationPlan.js +377 -0
- package/dist/generator/resolveRegistrationPlan.js.map +1 -0
- package/dist/generator/types.d.ts +37 -0
- package/dist/generator/types.d.ts.map +1 -0
- package/dist/generator/types.js +2 -0
- package/dist/generator/types.js.map +1 -0
- package/dist/generator/writeManifest.d.ts +19 -0
- package/dist/generator/writeManifest.d.ts.map +1 -0
- package/dist/generator/writeManifest.js +405 -0
- package/dist/generator/writeManifest.js.map +1 -0
- package/dist/groups/baseTypeAssignability.d.ts +48 -0
- package/dist/groups/baseTypeAssignability.d.ts.map +1 -0
- package/dist/groups/baseTypeAssignability.js +145 -0
- package/dist/groups/baseTypeAssignability.js.map +1 -0
- package/dist/groups/resolveGroupPlan.d.ts +85 -0
- package/dist/groups/resolveGroupPlan.d.ts.map +1 -0
- package/dist/groups/resolveGroupPlan.js +215 -0
- package/dist/groups/resolveGroupPlan.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/inspection/formatReports.d.ts +14 -0
- package/dist/inspection/formatReports.d.ts.map +1 -0
- package/dist/inspection/formatReports.js +115 -0
- package/dist/inspection/formatReports.js.map +1 -0
- package/dist/inspection/index.d.ts +8 -0
- package/dist/inspection/index.d.ts.map +1 -0
- package/dist/inspection/index.js +8 -0
- package/dist/inspection/index.js.map +1 -0
- package/dist/inspection/reports.d.ts +40 -0
- package/dist/inspection/reports.d.ts.map +1 -0
- package/dist/inspection/reports.js +95 -0
- package/dist/inspection/reports.js.map +1 -0
- package/dist/inspection/runDiscoveryAnalysis.d.ts +36 -0
- package/dist/inspection/runDiscoveryAnalysis.d.ts.map +1 -0
- package/dist/inspection/runDiscoveryAnalysis.js +48 -0
- package/dist/inspection/runDiscoveryAnalysis.js.map +1 -0
- package/dist/inspection/validateManifest.d.ts +8 -0
- package/dist/inspection/validateManifest.d.ts.map +1 -0
- package/dist/inspection/validateManifest.js +46 -0
- package/dist/inspection/validateManifest.js.map +1 -0
- package/dist/runtime/bootstrap.d.ts +13 -0
- package/dist/runtime/bootstrap.d.ts.map +1 -0
- package/dist/runtime/bootstrap.js +259 -0
- package/dist/runtime/bootstrap.js.map +1 -0
- package/dist/runtime/index.d.ts +4 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +4 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/iocResolutionError.d.ts +54 -0
- package/dist/runtime/iocResolutionError.d.ts.map +1 -0
- package/dist/runtime/iocResolutionError.js +266 -0
- package/dist/runtime/iocResolutionError.js.map +1 -0
- package/dist/runtime/iocResolutionStack.d.ts +21 -0
- package/dist/runtime/iocResolutionStack.d.ts.map +1 -0
- package/dist/runtime/iocResolutionStack.js +17 -0
- package/dist/runtime/iocResolutionStack.js.map +1 -0
- package/dist/runtime/iocRuntimeErrors.d.ts +35 -0
- package/dist/runtime/iocRuntimeErrors.d.ts.map +1 -0
- package/dist/runtime/iocRuntimeErrors.js +27 -0
- package/dist/runtime/iocRuntimeErrors.js.map +1 -0
- package/dist/runtime/registrationKeyIndex.d.ts +12 -0
- package/dist/runtime/registrationKeyIndex.d.ts.map +1 -0
- package/dist/runtime/registrationKeyIndex.js +19 -0
- package/dist/runtime/registrationKeyIndex.js.map +1 -0
- package/package.json +67 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Orchestrates manifest generation: load config, discover factories via TypeScript,
|
|
3
|
+
* build registration + group plans, emit `ioc-manifest.ts` and `ioc-registry.types.ts`, then
|
|
4
|
+
* format with Prettier when available.
|
|
5
|
+
*/
|
|
6
|
+
import { execFileSync } from "node:child_process";
|
|
7
|
+
import fs from "node:fs/promises";
|
|
8
|
+
import { createRequire } from "node:module";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
import { tryLoadIocConfig, resolveIocConfigPath, resolveProjectRootFromIocConfigPath, } from "../config/loadIocConfig.js";
|
|
11
|
+
import { discoverFactories } from "./discoverFactories/discoverFactories.js";
|
|
12
|
+
import { createIocProgramForDiscovery, getDiscoveryTargetFiles, reportDiscoveryProgramDiagnostics, } from "./iocProgramContext.js";
|
|
13
|
+
import { mergeManifestOptionsWithIocConfig, resolveManifestOptions, } from "./manifestOptions.js";
|
|
14
|
+
import { buildRegistrationPlan } from "./resolveRegistrationPlan.js";
|
|
15
|
+
import { writeManifest } from "./writeManifest.js";
|
|
16
|
+
import { buildGroupPlan } from "../groups/resolveGroupPlan.js";
|
|
17
|
+
const require = createRequire(import.meta.url);
|
|
18
|
+
const packageJson = require("../../package.json");
|
|
19
|
+
const packageName = typeof packageJson.name === "string" && packageJson.name.length > 0
|
|
20
|
+
? packageJson.name
|
|
21
|
+
: "ioc-manifest";
|
|
22
|
+
const prettierCliPath = path.join(path.dirname(require.resolve("prettier/package.json")), "bin", "prettier.cjs");
|
|
23
|
+
/**
|
|
24
|
+
* Format via the local `prettier` dependency (not `npx`), so generation works regardless of cwd
|
|
25
|
+
* or npm/npx resolution when using alternate `--config` paths.
|
|
26
|
+
*/
|
|
27
|
+
const formatGeneratedFileWithPrettier = (filePath, projectRoot) => {
|
|
28
|
+
try {
|
|
29
|
+
execFileSync(process.execPath, [prettierCliPath, "--write", filePath], {
|
|
30
|
+
cwd: projectRoot,
|
|
31
|
+
stdio: "inherit",
|
|
32
|
+
env: process.env,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
console.warn(`Failed to format generated files: ${error instanceof Error ? error.message : String(error)}`);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Full generation pipeline for a consuming project. Idempotent writes use atomic rename.
|
|
41
|
+
*
|
|
42
|
+
* @param overrides - Optional paths, glob patterns, factory prefix, or explicit `iocConfigPath`.
|
|
43
|
+
* When `ioc.config.ts` is absent, defaults from {@link resolveManifestOptions} apply.
|
|
44
|
+
*/
|
|
45
|
+
export const generateManifest = async (overrides) => {
|
|
46
|
+
const searchStart = path.resolve(overrides?.paths?.projectRoot ?? process.cwd());
|
|
47
|
+
const configPath = resolveIocConfigPath(searchStart, overrides?.iocConfigPath);
|
|
48
|
+
const config = await tryLoadIocConfig(configPath);
|
|
49
|
+
const resolvedProjectRoot = config
|
|
50
|
+
? resolveProjectRootFromIocConfigPath(configPath)
|
|
51
|
+
: searchStart;
|
|
52
|
+
const base = resolveManifestOptions({
|
|
53
|
+
...overrides,
|
|
54
|
+
paths: {
|
|
55
|
+
...overrides?.paths,
|
|
56
|
+
projectRoot: resolvedProjectRoot,
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
const options = config
|
|
60
|
+
? mergeManifestOptionsWithIocConfig(base, config)
|
|
61
|
+
: base;
|
|
62
|
+
const { paths: { projectRoot, scanDirs, generatedDir, manifestOutPath, workspacePackageImportBases, }, includePatterns, excludePatterns, factoryExportPrefix, } = options;
|
|
63
|
+
await fs.mkdir(generatedDir, { recursive: true });
|
|
64
|
+
const files = await getDiscoveryTargetFiles(scanDirs, includePatterns, excludePatterns, generatedDir);
|
|
65
|
+
const program = createIocProgramForDiscovery(projectRoot, files);
|
|
66
|
+
reportDiscoveryProgramDiagnostics(program, projectRoot, files);
|
|
67
|
+
const { contractMap, acceptedFactories } = discoverFactories(files, program, projectRoot, factoryExportPrefix, { projectRoot, scanDirs, generatedDir, workspacePackageImportBases }, config);
|
|
68
|
+
const plans = buildRegistrationPlan(contractMap, config, {
|
|
69
|
+
projectRoot,
|
|
70
|
+
scanDirs,
|
|
71
|
+
});
|
|
72
|
+
const groupResult = buildGroupPlan(config?.groups, plans, {
|
|
73
|
+
program,
|
|
74
|
+
generatedDir,
|
|
75
|
+
scanDirs,
|
|
76
|
+
});
|
|
77
|
+
await writeManifest(acceptedFactories, plans, groupResult?.manifest, manifestOutPath, packageName, {
|
|
78
|
+
registryTypesBuildContext: {
|
|
79
|
+
program,
|
|
80
|
+
generatedDir,
|
|
81
|
+
scanDirs,
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
formatGeneratedFileWithPrettier(manifestOutPath, projectRoot);
|
|
85
|
+
formatGeneratedFileWithPrettier(path.join(path.dirname(manifestOutPath), "ioc-registry.types.ts"), projectRoot);
|
|
86
|
+
console.log(`Generated ${path.relative(projectRoot, manifestOutPath)} — ${acceptedFactories.length} module factory(ies), ${contractMap.size} contract(s).`);
|
|
87
|
+
};
|
|
88
|
+
//# sourceMappingURL=generateManifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateManifest.js","sourceRoot":"","sources":["../../src/generator/generateManifest.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,mCAAmC,GACpC,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAC7E,OAAO,EACL,4BAA4B,EAC5B,uBAAuB,EACvB,iCAAiC,GAClC,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,iCAAiC,EAEjC,sBAAsB,GACvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,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EAAE;QACvD,WAAW;QACX,QAAQ;KACT,CAAC,CAAC;IACH,MAAM,WAAW,GAAG,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE;QACxD,OAAO;QACP,YAAY;QACZ,QAAQ;KACT,CAAC,CAAC;IAEH,MAAM,aAAa,CACjB,iBAAiB,EACjB,KAAK,EACL,WAAW,EAAE,QAAQ,EACrB,eAAe,EACf,WAAW,EACX;QACE,yBAAyB,EAAE;YACzB,OAAO;YACP,YAAY;YACZ,QAAQ;SACT;KACF,CACF,CAAC;IAEF,+BAA+B,CAAC,eAAe,EAAE,WAAW,CAAC,CAAC;IAE9D,+BAA+B,CAC7B,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,uBAAuB,CAAC,EACjE,WAAW,CACZ,CAAC;IAEF,OAAO,CAAC,GAAG,CACT,aAAa,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,eAAe,CAAC,MAAM,iBAAiB,CAAC,MAAM,yBAAyB,WAAW,CAAC,IAAI,eAAe,CAC/I,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { type ResolvedScanDir } from "./manifestPaths.js";
|
|
3
|
+
/** Absolute paths sorted lexically; globs run per scan root with merged manifest options. */
|
|
4
|
+
export declare const getDiscoveryTargetFiles: (scanDirs: ResolvedScanDir[], includePatterns: string[], excludePatterns: string[], generatedDir: string) => Promise<string[]>;
|
|
5
|
+
/**
|
|
6
|
+
* Loads the workspace `tsconfig.json` and creates a program over `rootNames` only (typically
|
|
7
|
+
* discovery targets). Compiler options (paths, module resolution) match your project build.
|
|
8
|
+
*/
|
|
9
|
+
export declare const createIocProgramForDiscovery: (projectRoot: string, rootNames: string[]) => ts.Program;
|
|
10
|
+
export declare const reportDiscoveryProgramDiagnostics: (program: ts.Program, projectRoot: string, rootNames: readonly string[]) => void;
|
|
11
|
+
//# sourceMappingURL=iocProgramContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iocProgramContext.d.ts","sourceRoot":"","sources":["../../src/generator/iocProgramContext.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,OAAO,EAEL,KAAK,eAAe,EACrB,MAAM,oBAAoB,CAAC;AAI5B,6FAA6F;AAC7F,eAAO,MAAM,uBAAuB,GAClC,UAAU,eAAe,EAAE,EAC3B,iBAAiB,MAAM,EAAE,EACzB,iBAAiB,MAAM,EAAE,EACzB,cAAc,MAAM,KACnB,OAAO,CAAC,MAAM,EAAE,CAgBlB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,4BAA4B,GACvC,aAAa,MAAM,EACnB,WAAW,MAAM,EAAE,KAClB,EAAE,CAAC,OAoCL,CAAC;AAmBF,eAAO,MAAM,iCAAiC,GAC5C,SAAS,EAAE,CAAC,OAAO,EACnB,aAAa,MAAM,EACnB,WAAW,SAAS,MAAM,EAAE,KAC3B,IAgCF,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview TypeScript program bootstrap for discovery: resolve `tsconfig.json`, collect root
|
|
3
|
+
* files via fast-glob from each `scanDirs` entry, and surface compiler diagnostics that affect factory typing.
|
|
4
|
+
*/
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import ts from "typescript";
|
|
7
|
+
import fg from "fast-glob";
|
|
8
|
+
import { generatedExcludePatternForScanRoot, } from "./manifestPaths.js";
|
|
9
|
+
const normalizePath = (p) => path.normalize(p);
|
|
10
|
+
/** Absolute paths sorted lexically; globs run per scan root with merged manifest options. */
|
|
11
|
+
export const getDiscoveryTargetFiles = async (scanDirs, includePatterns, excludePatterns, generatedDir) => {
|
|
12
|
+
const genAbs = path.normalize(generatedDir);
|
|
13
|
+
const hits = await Promise.all(scanDirs.map(({ absPath }) => fg(includePatterns, {
|
|
14
|
+
cwd: absPath,
|
|
15
|
+
absolute: true,
|
|
16
|
+
ignore: [
|
|
17
|
+
...excludePatterns,
|
|
18
|
+
generatedExcludePatternForScanRoot(absPath, genAbs),
|
|
19
|
+
],
|
|
20
|
+
})));
|
|
21
|
+
const unique = [...new Set(hits.flat().map((p) => normalizePath(p)))];
|
|
22
|
+
return unique.sort((a, b) => a.localeCompare(b));
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Loads the workspace `tsconfig.json` and creates a program over `rootNames` only (typically
|
|
26
|
+
* discovery targets). Compiler options (paths, module resolution) match your project build.
|
|
27
|
+
*/
|
|
28
|
+
export const createIocProgramForDiscovery = (projectRoot, rootNames) => {
|
|
29
|
+
const formatHost = {
|
|
30
|
+
getCanonicalFileName: (f) => f,
|
|
31
|
+
getCurrentDirectory: () => projectRoot,
|
|
32
|
+
getNewLine: () => "\n",
|
|
33
|
+
};
|
|
34
|
+
const configPath = ts.findConfigFile(projectRoot, ts.sys.fileExists, "tsconfig.json");
|
|
35
|
+
if (!configPath) {
|
|
36
|
+
throw new Error("[ioc] tsconfig.json not found");
|
|
37
|
+
}
|
|
38
|
+
const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
39
|
+
if (configFile.error) {
|
|
40
|
+
throw new Error(ts.formatDiagnostic(configFile.error, formatHost));
|
|
41
|
+
}
|
|
42
|
+
const parsed = ts.parseJsonConfigFileContent(configFile.config, ts.sys, path.dirname(configPath), undefined, configPath);
|
|
43
|
+
if (parsed.errors.length > 0) {
|
|
44
|
+
const msg = parsed.errors
|
|
45
|
+
.map((d) => ts.formatDiagnostic(d, formatHost))
|
|
46
|
+
.join("\n");
|
|
47
|
+
throw new Error(`[ioc] tsconfig parse errors:\n${msg}`);
|
|
48
|
+
}
|
|
49
|
+
return ts.createProgram({ rootNames, options: parsed.options });
|
|
50
|
+
};
|
|
51
|
+
const formatDiagnostics = (diagnostics, projectRoot) => {
|
|
52
|
+
if (diagnostics.length === 0) {
|
|
53
|
+
return "";
|
|
54
|
+
}
|
|
55
|
+
const formatHost = {
|
|
56
|
+
getCanonicalFileName: (f) => f,
|
|
57
|
+
getCurrentDirectory: () => projectRoot,
|
|
58
|
+
getNewLine: () => "\n",
|
|
59
|
+
};
|
|
60
|
+
return ts.formatDiagnosticsWithColorAndContext(diagnostics, formatHost);
|
|
61
|
+
};
|
|
62
|
+
export const reportDiscoveryProgramDiagnostics = (program, projectRoot, rootNames) => {
|
|
63
|
+
const relevantRootFiles = new Set(rootNames.map((fileName) => normalizePath(fileName)));
|
|
64
|
+
const diagnostics = ts.getPreEmitDiagnostics(program).filter((diagnostic) => {
|
|
65
|
+
if (diagnostic.file === undefined) {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
return relevantRootFiles.has(normalizePath(diagnostic.file.fileName));
|
|
69
|
+
});
|
|
70
|
+
if (diagnostics.length === 0) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const errorDiagnostics = diagnostics.filter((diagnostic) => diagnostic.category === ts.DiagnosticCategory.Error);
|
|
74
|
+
const warningDiagnostics = diagnostics.filter((diagnostic) => diagnostic.category === ts.DiagnosticCategory.Warning);
|
|
75
|
+
console.warn(`[ioc] Continuing despite TypeScript diagnostics: ${errorDiagnostics.length} error(s), ${warningDiagnostics.length} warning(s).`);
|
|
76
|
+
const rendered = formatDiagnostics(diagnostics, projectRoot);
|
|
77
|
+
if (rendered.length > 0) {
|
|
78
|
+
console.warn(rendered);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
//# sourceMappingURL=iocProgramContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iocProgramContext.js","sourceRoot":"","sources":["../../src/generator/iocProgramContext.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,MAAM,WAAW,CAAC;AAC3B,OAAO,EACL,kCAAkC,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AAgB,CAAC,MAAM,cAAc,kBAAkB,CAAC,MAAM,cAAc,CACjI,CAAC;IAEF,MAAM,QAAQ,GAAG,iBAAiB,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;IAC7D,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACzB,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { IocConfig } from "../config/iocConfig.js";
|
|
2
|
+
import { type ManifestRuntimePaths } from "./manifestPaths.js";
|
|
3
|
+
/**
|
|
4
|
+
* Default layout relative to a project root: scan `<root>/src`, emit under `<root>/generated/`
|
|
5
|
+
* (paths always anchored at `projectRoot`).
|
|
6
|
+
*/
|
|
7
|
+
export declare const defaultManifestPathsFromProjectRoot: (projectRoot: string) => ManifestRuntimePaths;
|
|
8
|
+
export type ManifestOptions = {
|
|
9
|
+
paths: ManifestRuntimePaths;
|
|
10
|
+
includePatterns: string[];
|
|
11
|
+
excludePatterns: string[];
|
|
12
|
+
factoryExportPrefix: string;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Snapshot defaults for patterns/prefix; `paths` use the current working directory each time they are read.
|
|
16
|
+
*/
|
|
17
|
+
export declare const DEFAULT_MANIFEST_OPTIONS: ManifestOptions;
|
|
18
|
+
export declare const resolveManifestOptions: (overrides?: Partial<Omit<ManifestOptions, "paths">> & {
|
|
19
|
+
paths?: Partial<ManifestRuntimePaths>;
|
|
20
|
+
}) => ManifestOptions;
|
|
21
|
+
/**
|
|
22
|
+
* Applies `ioc.config` `discovery` overrides. Per-scan-root excludes for the generated directory
|
|
23
|
+
* are applied inside {@link getDiscoveryTargetFiles} (ignore paths are relative to each scan `cwd`).
|
|
24
|
+
*/
|
|
25
|
+
export declare const mergeManifestOptionsWithIocConfig: (base: ManifestOptions, config: IocConfig) => ManifestOptions;
|
|
26
|
+
//# sourceMappingURL=manifestOptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifestOptions.d.ts","sourceRoot":"","sources":["../../src/generator/manifestOptions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAExD,OAAO,EAGL,KAAK,oBAAoB,EAC1B,MAAM,oBAAoB,CAAC;AAE5B;;;GAGG;AACH,eAAO,MAAM,mCAAmC,GAC9C,aAAa,MAAM,KAClB,oBASF,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,EAAE,oBAAoB,CAAC;IAC5B,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,mBAAmB,EAAE,MAAM,CAAC;CAC7B,CAAC;AAcF;;GAEG;AACH,eAAO,MAAM,wBAAwB,EAAE,eAOtC,CAAC;AAEF,eAAO,MAAM,sBAAsB,GACjC,YAAY,OAAO,CAAC,IAAI,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC,GAAG;IACpD,KAAK,CAAC,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAC;CACvC,KACA,eAmBF,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,iCAAiC,GAC5C,MAAM,eAAe,EACrB,QAAQ,SAAS,KAChB,eAgCF,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { parseDiscoveryScanDirs } from "../config/parseDiscoveryScanDirs.js";
|
|
3
|
+
import { resolveScanDirEntries, resolveWorkspacePackageImportBases, } from "./manifestPaths.js";
|
|
4
|
+
/**
|
|
5
|
+
* Default layout relative to a project root: scan `<root>/src`, emit under `<root>/generated/`
|
|
6
|
+
* (paths always anchored at `projectRoot`).
|
|
7
|
+
*/
|
|
8
|
+
export const defaultManifestPathsFromProjectRoot = (projectRoot) => {
|
|
9
|
+
const scanDirs = resolveScanDirEntries(projectRoot, [{ path: "src" }]);
|
|
10
|
+
const generatedDir = path.join(projectRoot, "generated");
|
|
11
|
+
return {
|
|
12
|
+
projectRoot,
|
|
13
|
+
scanDirs,
|
|
14
|
+
generatedDir,
|
|
15
|
+
manifestOutPath: path.join(generatedDir, "ioc-manifest.ts"),
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
const DEFAULT_INCLUDE_PATTERNS = ["examples/**/*.{ts,tsx,js,mjs,cjs}"];
|
|
19
|
+
const DEFAULT_EXCLUDE_PATTERNS = [
|
|
20
|
+
"**/*.d.ts",
|
|
21
|
+
// `*.test.ts` and `*.tests.ts` (and .js / .mjs / .cjs)
|
|
22
|
+
"**/*.{test,tests}.{ts,tsx,js,mjs,cjs}",
|
|
23
|
+
"**/*.{spec,specs}.{ts,tsx,js,mjs,cjs}",
|
|
24
|
+
"generated/**/*",
|
|
25
|
+
"dist/**/*",
|
|
26
|
+
"node_modules/**/*",
|
|
27
|
+
];
|
|
28
|
+
/**
|
|
29
|
+
* Snapshot defaults for patterns/prefix; `paths` use the current working directory each time they are read.
|
|
30
|
+
*/
|
|
31
|
+
export const DEFAULT_MANIFEST_OPTIONS = {
|
|
32
|
+
get paths() {
|
|
33
|
+
return defaultManifestPathsFromProjectRoot(process.cwd());
|
|
34
|
+
},
|
|
35
|
+
includePatterns: DEFAULT_INCLUDE_PATTERNS,
|
|
36
|
+
excludePatterns: DEFAULT_EXCLUDE_PATTERNS,
|
|
37
|
+
factoryExportPrefix: "build",
|
|
38
|
+
};
|
|
39
|
+
export const resolveManifestOptions = (overrides) => {
|
|
40
|
+
const defaults = defaultManifestPathsFromProjectRoot(process.cwd());
|
|
41
|
+
const pathOverrides = overrides?.paths;
|
|
42
|
+
return {
|
|
43
|
+
includePatterns: overrides?.includePatterns ?? DEFAULT_INCLUDE_PATTERNS,
|
|
44
|
+
excludePatterns: overrides?.excludePatterns ?? DEFAULT_EXCLUDE_PATTERNS,
|
|
45
|
+
factoryExportPrefix: overrides?.factoryExportPrefix ?? "build",
|
|
46
|
+
paths: {
|
|
47
|
+
...defaults,
|
|
48
|
+
...pathOverrides,
|
|
49
|
+
projectRoot: pathOverrides?.projectRoot ?? defaults.projectRoot,
|
|
50
|
+
scanDirs: pathOverrides?.scanDirs ?? defaults.scanDirs,
|
|
51
|
+
generatedDir: pathOverrides?.generatedDir ?? defaults.generatedDir,
|
|
52
|
+
manifestOutPath: pathOverrides?.manifestOutPath ?? defaults.manifestOutPath,
|
|
53
|
+
workspacePackageImportBases: pathOverrides?.workspacePackageImportBases ??
|
|
54
|
+
defaults.workspacePackageImportBases,
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Applies `ioc.config` `discovery` overrides. Per-scan-root excludes for the generated directory
|
|
60
|
+
* are applied inside {@link getDiscoveryTargetFiles} (ignore paths are relative to each scan `cwd`).
|
|
61
|
+
*/
|
|
62
|
+
export const mergeManifestOptionsWithIocConfig = (base, config) => {
|
|
63
|
+
const { projectRoot } = base.paths;
|
|
64
|
+
const specs = parseDiscoveryScanDirs(config.discovery.scanDirs, "ioc.config discovery.scanDirs");
|
|
65
|
+
const scanDirs = resolveScanDirEntries(projectRoot, specs);
|
|
66
|
+
const configuredGeneratedDir = config.discovery.generatedDir ?? "generated";
|
|
67
|
+
const generatedDir = path.isAbsolute(configuredGeneratedDir)
|
|
68
|
+
? configuredGeneratedDir
|
|
69
|
+
: path.resolve(projectRoot, configuredGeneratedDir);
|
|
70
|
+
const fromConfig = resolveWorkspacePackageImportBases(projectRoot, config.discovery.workspacePackageImportBases);
|
|
71
|
+
const workspacePackageImportBases = fromConfig ?? base.paths.workspacePackageImportBases;
|
|
72
|
+
return {
|
|
73
|
+
...base,
|
|
74
|
+
paths: {
|
|
75
|
+
projectRoot,
|
|
76
|
+
scanDirs,
|
|
77
|
+
generatedDir,
|
|
78
|
+
manifestOutPath: path.join(generatedDir, "ioc-manifest.ts"),
|
|
79
|
+
workspacePackageImportBases,
|
|
80
|
+
},
|
|
81
|
+
includePatterns: config.discovery.includes ?? base.includePatterns,
|
|
82
|
+
excludePatterns: config.discovery.excludes ?? base.excludePatterns,
|
|
83
|
+
factoryExportPrefix: config.discovery.factoryPrefix ?? base.factoryExportPrefix,
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
//# sourceMappingURL=manifestOptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifestOptions.js","sourceRoot":"","sources":["../../src/generator/manifestOptions.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAC7E,OAAO,EACL,qBAAqB,EACrB,kCAAkC,GAEnC,MAAM,oBAAoB,CAAC;AAE5B;;;GAGG;AACH,MAAM,CAAC,MAAM,mCAAmC,GAAG,CACjD,WAAmB,EACG,EAAE;IACxB,MAAM,QAAQ,GAAG,qBAAqB,CAAC,WAAW,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;IACvE,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;IACzD,OAAO;QACL,WAAW;QACX,QAAQ;QACR,YAAY;QACZ,eAAe,EAAE,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,iBAAiB,CAAC;KAC5D,CAAC;AACJ,CAAC,CAAC;AASF,MAAM,wBAAwB,GAAG,CAAC,mCAAmC,CAAC,CAAC;AAEvE,MAAM,wBAAwB,GAAG;IAC/B,WAAW;IACX,uDAAuD;IACvD,uCAAuC;IACvC,uCAAuC;IACvC,gBAAgB;IAChB,WAAW;IACX,mBAAmB;CACpB,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAoB;IACvD,IAAI,KAAK;QACP,OAAO,mCAAmC,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAC5D,CAAC;IAC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AAW,CAAC;IAC5E,MAAM,YAAY,GAAG,IAAI,CAAC,UAAU,CAAC,sBAAsB,CAAC;QAC1D,CAAC,CAAC,sBAAsB;QACxB,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,sBAAsB,CAAC,CAAC;IAEtD,MAAM,UAAU,GAAG,kCAAkC,CACnD,WAAW,EACX,MAAM,CAAC,SAAS,CAAC,2BAA2B,CAC7C,CAAC;IACF,MAAM,2BAA2B,GAC/B,UAAU,IAAI,IAAI,CAAC,KAAK,CAAC,2BAA2B,CAAC;IAEvD,OAAO;QACL,GAAG,IAAI;QACP,KAAK,EAAE;YACL,WAAW;YACX,QAAQ;YACR,YAAY;YACZ,eAAe,EAAE,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,iBAAiB,CAAC;YAC3D,2BAA2B;SAC5B;QACD,eAAe,EAAE,MAAM,CAAC,SAAS,CAAC,QAAQ,IAAI,IAAI,CAAC,eAAe;QAClE,eAAe,EAAE,MAAM,CAAC,SAAS,CAAC,QAAQ,IAAI,IAAI,CAAC,eAAe;QAClE,mBAAmB,EAAE,MAAM,CAAC,SAAS,CAAC,aAAa,IAAI,IAAI,CAAC,mBAAmB;KAChF,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { IocLifetime, IocScanDirSpec, IocWorkspacePackageImportBase } from "../config/iocConfig.js";
|
|
2
|
+
/**
|
|
3
|
+
* Resolves `root` from {@link IocWorkspacePackageImportBase} to an absolute directory.
|
|
4
|
+
*
|
|
5
|
+
* When `ioc.config.ts` lives in an app package (e.g. `apps/web`), {@link projectRoot} is that
|
|
6
|
+
* package, not the monorepo root. A path like `packages/foo/src` would incorrectly resolve to
|
|
7
|
+
* `apps/web/packages/foo/src`. If that path does not exist, this walks up ancestors of
|
|
8
|
+
* `projectRoot` until `path.join(ancestor, root)` exists — typically the repo root containing
|
|
9
|
+
* `packages/`.
|
|
10
|
+
*/
|
|
11
|
+
export declare const resolveWorkspacePackageRoot: (projectRoot: string, root: string) => string;
|
|
12
|
+
/** After resolving `path` against the package root. Optional `scope` is default registration lifetime for factories under this root. */
|
|
13
|
+
export type ResolvedScanDir = {
|
|
14
|
+
absPath: string;
|
|
15
|
+
importPrefix?: string;
|
|
16
|
+
importMode?: "root" | "subpath";
|
|
17
|
+
scope?: IocLifetime;
|
|
18
|
+
};
|
|
19
|
+
/** Resolved workspace root + import base (absolute root, longest match wins). */
|
|
20
|
+
export type ResolvedWorkspacePackageImportBase = {
|
|
21
|
+
absRoot: string;
|
|
22
|
+
importBase: string;
|
|
23
|
+
};
|
|
24
|
+
/** Resolved filesystem layout for manifest generation and factory discovery. */
|
|
25
|
+
export type ManifestRuntimePaths = {
|
|
26
|
+
projectRoot: string;
|
|
27
|
+
scanDirs: ResolvedScanDir[];
|
|
28
|
+
generatedDir: string;
|
|
29
|
+
/** Primary generated manifest output file. */
|
|
30
|
+
manifestOutPath: string;
|
|
31
|
+
/**
|
|
32
|
+
* Optional workspace package roots with public import bases (from config), sorted by longest
|
|
33
|
+
* `absRoot` first.
|
|
34
|
+
*/
|
|
35
|
+
workspacePackageImportBases?: readonly ResolvedWorkspacePackageImportBase[];
|
|
36
|
+
};
|
|
37
|
+
/** Subset passed into per-file factory discovery (import path + module path math). */
|
|
38
|
+
export type FactoryDiscoveryPaths = Pick<ManifestRuntimePaths, "projectRoot" | "scanDirs" | "generatedDir" | "workspacePackageImportBases">;
|
|
39
|
+
export type ComputeManifestModuleSpecifierOptions = {
|
|
40
|
+
/**
|
|
41
|
+
* When the factory imported the contract type with a bare module specifier (e.g. `knex`,
|
|
42
|
+
* `@koa/router`), preserve that instead of deriving from the resolved declaration file path.
|
|
43
|
+
*/
|
|
44
|
+
preferredModuleSpecifier?: string;
|
|
45
|
+
workspacePackageImportBases?: readonly ResolvedWorkspacePackageImportBase[];
|
|
46
|
+
/**
|
|
47
|
+
* IoC package root (same as manifest `projectRoot`). Used when TypeScript gives a relative
|
|
48
|
+
* `SourceFile.fileName` for the contract declaration so workspace matching still works.
|
|
49
|
+
*/
|
|
50
|
+
projectRoot?: string;
|
|
51
|
+
};
|
|
52
|
+
export declare const resolveScanDirEntries: (projectRoot: string, specs: readonly IocScanDirSpec[]) => ResolvedScanDir[];
|
|
53
|
+
export declare const findResolvedScanDirForFile: (absFile: string, entries: readonly ResolvedScanDir[]) => ResolvedScanDir | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* Default registration lifetime from the most specific `discovery.scanDirs` root containing the
|
|
56
|
+
* factory file. Throws when multiple roots tie for specificity with different paths or conflicting
|
|
57
|
+
* `scope` on duplicate entries.
|
|
58
|
+
*/
|
|
59
|
+
export declare const resolveDiscoveryRootDefaultLifetime: (factoryAbsPath: string, scanDirs: readonly ResolvedScanDir[]) => IocLifetime | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* Stable `modulePath` for manifest indexing: relative to the sole local scan root when there is one;
|
|
62
|
+
* otherwise relative to `projectRoot` (posix) so paths stay unique.
|
|
63
|
+
*/
|
|
64
|
+
export declare const computeDiscoveryModulePath: (absFile: string, projectRoot: string, scanDirs: readonly ResolvedScanDir[]) => string;
|
|
65
|
+
/** Resolves the absolute path of a factory module from its stored `modulePath`. */
|
|
66
|
+
export declare const resolveFactorySourceAbsPath: (modulePath: string, projectRoot: string, scanDirs: readonly ResolvedScanDir[]) => string;
|
|
67
|
+
/**
|
|
68
|
+
* Maps `@types/foo` / `@types/scope__name` to the runtime package name consumers import.
|
|
69
|
+
* See DefinitelyTyped naming: `@types/foo__bar` → `@foo/bar`.
|
|
70
|
+
*/
|
|
71
|
+
export declare const mapTypesPackageToRuntimePackage: (typesPackage: string) => string;
|
|
72
|
+
/**
|
|
73
|
+
* When a resolved declaration file lives under `node_modules`, returns the bare package specifier
|
|
74
|
+
* (never a relative path through `node_modules`). `@types/*` maps to the typed runtime package.
|
|
75
|
+
*/
|
|
76
|
+
export declare const emitBarePackageSpecifierFromNodeModulesPath: (absFile: string) => string | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* Strips declaration-file artifacts and redundant `/index` segments from emitted specifiers.
|
|
79
|
+
* Single-segment package names (e.g. `knex`) drop `.ts`/`.js`; subpaths keep `.js` when present
|
|
80
|
+
* (workspace `importPrefix` + `subpath` mode).
|
|
81
|
+
*/
|
|
82
|
+
export declare const normalizeEmittedModuleSpecifier: (spec: string) => string;
|
|
83
|
+
/**
|
|
84
|
+
* ESM import specifier for a source file as emitted next to `generatedDir` (relative path, package root, or subpath).
|
|
85
|
+
*
|
|
86
|
+
* Resolution order: optional recovered bare import → configured workspace import bases (before
|
|
87
|
+
* `node_modules`, so symlinked workspace packages resolve to `importBase`) → `node_modules`
|
|
88
|
+
* package name → scan dir `importPrefix` / `importMode` → relative path from `generatedDir`.
|
|
89
|
+
*/
|
|
90
|
+
export declare const computeManifestModuleSpecifier: (absFile: string, generatedDir: string, scanDirs: readonly ResolvedScanDir[], options?: ComputeManifestModuleSpecifierOptions) => string;
|
|
91
|
+
export declare const resolveWorkspacePackageImportBases: (projectRoot: string, specs: readonly IocWorkspacePackageImportBase[] | undefined) => readonly ResolvedWorkspacePackageImportBase[] | undefined;
|
|
92
|
+
/** Ignore glob for one scan root so discovery does not pick up generated output (relative to that root's `cwd`). */
|
|
93
|
+
export declare const generatedExcludePatternForScanRoot: (scanAbs: string, generatedAbs: string) => string;
|
|
94
|
+
//# sourceMappingURL=manifestPaths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifestPaths.d.ts","sourceRoot":"","sources":["../../src/generator/manifestPaths.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,WAAW,EACX,cAAc,EACd,6BAA6B,EAC9B,MAAM,wBAAwB,CAAC;AA8BhC;;;;;;;;GAQG;AACH,eAAO,MAAM,2BAA2B,GACtC,aAAa,MAAM,EACnB,MAAM,MAAM,KACX,MAwBF,CAAC;AAEF,wIAAwI;AACxI,MAAM,MAAM,eAAe,GAAG;IAC5B,OAA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