nest-graph-inspector 0.15.0 → 0.16.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 (81) hide show
  1. package/README.md +27 -0
  2. package/dist/adapters/discovery.d.ts +57 -1
  3. package/dist/adapters/discovery.d.ts.map +1 -1
  4. package/dist/adapters/discovery.js +110 -22
  5. package/dist/adapters/discovery.js.map +1 -1
  6. package/dist/cli/bin.d.ts +3 -0
  7. package/dist/cli/bin.d.ts.map +1 -0
  8. package/dist/cli/bin.js +19 -0
  9. package/dist/cli/bin.js.map +1 -0
  10. package/dist/cli/cli-error.d.ts +23 -0
  11. package/dist/cli/cli-error.d.ts.map +1 -0
  12. package/dist/cli/cli-error.js +37 -0
  13. package/dist/cli/cli-error.js.map +1 -0
  14. package/dist/cli/cli.d.ts +20 -0
  15. package/dist/cli/cli.d.ts.map +1 -0
  16. package/dist/cli/cli.js +155 -0
  17. package/dist/cli/cli.js.map +1 -0
  18. package/dist/cli/export-command.d.ts +20 -0
  19. package/dist/cli/export-command.d.ts.map +1 -0
  20. package/dist/cli/export-command.js +254 -0
  21. package/dist/cli/export-command.js.map +1 -0
  22. package/dist/cli/export-graph.d.ts +65 -0
  23. package/dist/cli/export-graph.d.ts.map +1 -0
  24. package/dist/cli/export-graph.js +161 -0
  25. package/dist/cli/export-graph.js.map +1 -0
  26. package/dist/cli/project.d.ts +63 -0
  27. package/dist/cli/project.d.ts.map +1 -0
  28. package/dist/cli/project.js +347 -0
  29. package/dist/cli/project.js.map +1 -0
  30. package/dist/cli/stderr-logger.d.ts +13 -0
  31. package/dist/cli/stderr-logger.d.ts.map +1 -0
  32. package/dist/cli/stderr-logger.js +58 -0
  33. package/dist/cli/stderr-logger.js.map +1 -0
  34. package/dist/graph-output.builder.d.ts +108 -0
  35. package/dist/graph-output.builder.d.ts.map +1 -0
  36. package/dist/graph-output.builder.js +804 -0
  37. package/dist/graph-output.builder.js.map +1 -0
  38. package/dist/index.d.ts +1 -0
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +4 -1
  41. package/dist/index.js.map +1 -1
  42. package/dist/nest-graph-inspector.module.d.ts +13 -1
  43. package/dist/nest-graph-inspector.module.d.ts.map +1 -1
  44. package/dist/nest-graph-inspector.module.js +16 -5
  45. package/dist/nest-graph-inspector.module.js.map +1 -1
  46. package/dist/nest-graph-inspector.setup.d.ts +7 -82
  47. package/dist/nest-graph-inspector.setup.d.ts.map +1 -1
  48. package/dist/nest-graph-inspector.setup.js +7 -778
  49. package/dist/nest-graph-inspector.setup.js.map +1 -1
  50. package/dist/nest-graph-inspector.type.d.ts +9 -5
  51. package/dist/nest-graph-inspector.type.d.ts.map +1 -1
  52. package/package.json +4 -1
  53. package/src/adapters/discovery.spec.ts +297 -19
  54. package/src/adapters/discovery.ts +120 -26
  55. package/src/cli/__fixtures__/accounts.module.ts +58 -0
  56. package/src/cli/__fixtures__/audit.service.ts +24 -0
  57. package/src/cli/__fixtures__/document.service.ts +70 -0
  58. package/src/cli/__fixtures__/documents.module.ts +86 -0
  59. package/src/cli/__fixtures__/fixture-calls.ts +10 -0
  60. package/src/cli/__fixtures__/settings.module.ts +15 -0
  61. package/src/cli/__fixtures__/storage.module.ts +113 -0
  62. package/src/cli/__fixtures__/tsconfig.json +13 -0
  63. package/src/cli/bin.spec.ts +708 -0
  64. package/src/cli/bin.ts +19 -0
  65. package/src/cli/cli-error.ts +36 -0
  66. package/src/cli/cli.spec.ts +161 -0
  67. package/src/cli/cli.ts +142 -0
  68. package/src/cli/export-command.ts +330 -0
  69. package/src/cli/export-graph.spec.ts +586 -0
  70. package/src/cli/export-graph.ts +263 -0
  71. package/src/cli/project.spec.ts +294 -0
  72. package/src/cli/project.ts +474 -0
  73. package/src/cli/stderr-logger.spec.ts +64 -0
  74. package/src/cli/stderr-logger.ts +71 -0
  75. package/src/graph-output.builder.ts +1223 -0
  76. package/src/index.ts +4 -0
  77. package/src/nest-graph-inspector.module.spec.ts +20 -4
  78. package/src/nest-graph-inspector.module.ts +21 -5
  79. package/src/nest-graph-inspector.setup.spec.ts +8 -7
  80. package/src/nest-graph-inspector.setup.ts +23 -1203
  81. package/src/nest-graph-inspector.type.ts +9 -5
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.HELP = void 0;
37
+ exports.processIo = processIo;
38
+ exports.runCli = runCli;
39
+ const node_util_1 = require("node:util");
40
+ const cli_error_1 = require("./cli-error");
41
+ const { version } = require("../../package.json");
42
+ const OPTIONS = {
43
+ entry: { type: "string" },
44
+ module: { type: "string" },
45
+ out: { type: "string", short: "o" },
46
+ project: { type: "string", short: "p" },
47
+ require: { type: "string", short: "r", multiple: true },
48
+ "env-file": { type: "string", multiple: true },
49
+ compact: { type: "boolean" },
50
+ help: { type: "boolean", short: "h" },
51
+ version: { type: "boolean", short: "v" },
52
+ };
53
+ exports.HELP = `Usage: nest-graph-inspector export [options]
54
+
55
+ Writes the dependency graph of a NestJS application without running it. The
56
+ application is booted in Nest's own preview mode, which builds the module
57
+ container but instantiates no provider or controller and calls no lifecycle
58
+ hook. The file is the GraphOutput JSON a running inspector serves at
59
+ /output.json.
60
+
61
+ Options:
62
+ --entry <file> File exporting the root module, compiled JavaScript or —
63
+ with a --require loader — TypeScript. Default: found from
64
+ nest-cli.json and the tsconfig outDir, such as
65
+ dist/app.module.js or dist/src/app.module.js
66
+ --module <name> Export name of the root module class (default: AppModule,
67
+ or the file's only exported module)
68
+ -o, --out <file> Where to write the graph; "-" for stdout
69
+ (default: nest-graph.json)
70
+ -p, --project <dir> Project root; the application is booted from there, as
71
+ it is when started (default: the current directory)
72
+ --env-file <file> Load environment variables from a file before anything
73
+ else, for an application whose main.ts loads them
74
+ before importing AppModule; repeatable. Needs Node.js
75
+ 20.12 or later; --require dotenv/config also works
76
+ -r, --require <id> Module to load first, resolved from the project, such as
77
+ ts-node/register or tsconfig-paths/register; repeatable
78
+ --compact Write the JSON on one line, as /output.json serves it
79
+ -h, --help Show this help
80
+ -v, --version Show the version
81
+
82
+ --entry, --out, --project and --env-file are relative to the current
83
+ directory.
84
+ `;
85
+ /**
86
+ * The process's own output streams, with their `write` captured now — before
87
+ * an application's module files get the chance to replace it — so the graph,
88
+ * the CLI's messages, and the final flush never pass through code the
89
+ * application installed.
90
+ */
91
+ function processIo() {
92
+ return {
93
+ stdout: { write: process.stdout.write.bind(process.stdout) },
94
+ stderr: { write: process.stderr.write.bind(process.stderr) },
95
+ cwd: process.cwd(),
96
+ };
97
+ }
98
+ /**
99
+ * Runs the CLI with `argv` (without `node` and the script) and returns its
100
+ * exit code. `export` diverts `process.stdout` to stderr for the rest of the
101
+ * process, so it belongs in a process of its own, as `bin.ts` runs it.
102
+ */
103
+ async function runCli(argv, io = processIo()) {
104
+ let parsed;
105
+ try {
106
+ parsed = parseCliArgs(argv);
107
+ }
108
+ catch (error) {
109
+ return usageError(io, (0, cli_error_1.describeError)(error));
110
+ }
111
+ const { values, positionals } = parsed;
112
+ if (values.version) {
113
+ io.stdout.write(`${version}\n`);
114
+ return 0;
115
+ }
116
+ if (values.help) {
117
+ io.stdout.write(exports.HELP);
118
+ return 0;
119
+ }
120
+ const [command, ...extra] = positionals;
121
+ if (command === undefined) {
122
+ io.stderr.write(exports.HELP);
123
+ return 2;
124
+ }
125
+ if (command !== "export") {
126
+ return usageError(io, `Unknown command "${command}".`);
127
+ }
128
+ if (extra.length) {
129
+ return usageError(io, `Unexpected argument "${extra[0]}".`);
130
+ }
131
+ try {
132
+ // Loaded on demand, so --help and --version never load TypeScript or Nest.
133
+ const { runExportCommand } = await Promise.resolve().then(() => __importStar(require("./export-command")));
134
+ return await runExportCommand(argv, values, io);
135
+ }
136
+ catch (error) {
137
+ io.stderr.write(error instanceof cli_error_1.CliError
138
+ ? `nest-graph-inspector: ${error.message}\n${error.cause === undefined ? "" : `${(0, cli_error_1.stackOf)(error.cause)}\n`}`
139
+ : `nest-graph-inspector: export failed: ${(0, cli_error_1.stackOf)(error)}\n`);
140
+ return 1;
141
+ }
142
+ }
143
+ function parseCliArgs(argv) {
144
+ return (0, node_util_1.parseArgs)({
145
+ args: [...argv],
146
+ options: OPTIONS,
147
+ allowPositionals: true,
148
+ strict: true,
149
+ });
150
+ }
151
+ function usageError(io, message) {
152
+ io.stderr.write(`nest-graph-inspector: ${message}\nRun "nest-graph-inspector --help" for usage.\n`);
153
+ return 2;
154
+ }
155
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli/cli.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;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AAE,MAAM,EAAE,EAAE,CAAC,CAAC;IAClD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,EAAE,CAAC,MAAM,CAAC,KAAK,CACb,KAAK,YAAY,oBAAQ;YACvB,CAAC,CAAC,yBAAyB,KAAK,CAAC,OAAO,KACpC,KAAK,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,IAAA,mBAAO,EAAC,KAAK,CAAC,KAAK,CAAC,IAC1D,EAAE;YACJ,CAAC,CAAC,wCAAwC,IAAA,mBAAO,EAAC,KAAK,CAAC,IAAI,CAC/D,CAAC;QACF,OAAO,CAAC,CAAC;IACX,CAAC;AACH,CAAC;AAED,SAAS,YAAY,CAAC,IAAuB;IAC3C,OAAO,IAAA,qBAAS,EAAC;QACf,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;QACf,OAAO,EAAE,OAAO;QAChB,gBAAgB,EAAE,IAAI;QACtB,MAAM,EAAE,IAAI;KACb,CAAC,CAAC;AACL,CAAC;AAED,SAAS,UAAU,CAAC,EAAS,EAAE,OAAe;IAC5C,EAAE,CAAC,MAAM,CAAC,KAAK,CACb,yBAAyB,OAAO,kDAAkD,CACnF,CAAC;IACF,OAAO,CAAC,CAAC;AACX,CAAC"}
@@ -0,0 +1,20 @@
1
+ import type { CliIo } from "./cli";
2
+ export declare const DEFAULT_OUT_FILE = "nest-graph.json";
3
+ /** Set on a CLI started by another copy of itself, so it never delegates again. */
4
+ export declare const DELEGATED_ENV = "NEST_GRAPH_INSPECTOR_CLI_DELEGATED";
5
+ export type ExportCommandOptions = {
6
+ entry?: string;
7
+ module?: string;
8
+ out?: string;
9
+ project?: string;
10
+ require?: string[];
11
+ "env-file"?: string[];
12
+ compact?: boolean;
13
+ };
14
+ /**
15
+ * `nest-graph-inspector export`: writes the graph of the project's
16
+ * application, booted in Nest's preview mode, as `GraphOutput` JSON — the
17
+ * document a running inspector serves at `/output.json`.
18
+ */
19
+ export declare function runExportCommand(argv: readonly string[], options: ExportCommandOptions, io: CliIo): Promise<number>;
20
+ //# sourceMappingURL=export-command.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"export-command.d.ts","sourceRoot":"","sources":["../../src/cli/export-command.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAenC,eAAO,MAAM,gBAAgB,oBAAoB,CAAC;AAElD,mFAAmF;AACnF,eAAO,MAAM,aAAa,uCAAuC,CAAC;AAElE,MAAM,MAAM,oBAAoB,GAAG;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF;;;;GAIG;AACH,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,OAAO,EAAE,oBAAoB,EAC7B,EAAE,EAAE,KAAK,GACR,OAAO,CAAC,MAAM,CAAC,CA2HjB"}
@@ -0,0 +1,254 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.DELEGATED_ENV = exports.DEFAULT_OUT_FILE = void 0;
37
+ exports.runExportCommand = runExportCommand;
38
+ const node_child_process_1 = require("node:child_process");
39
+ const node_fs_1 = require("node:fs");
40
+ const node_module_1 = require("node:module");
41
+ const node_path_1 = require("node:path");
42
+ const cli_error_1 = require("./cli-error");
43
+ const project_1 = require("./project");
44
+ const stderr_logger_1 = require("./stderr-logger");
45
+ exports.DEFAULT_OUT_FILE = "nest-graph.json";
46
+ /** Set on a CLI started by another copy of itself, so it never delegates again. */
47
+ exports.DELEGATED_ENV = "NEST_GRAPH_INSPECTOR_CLI_DELEGATED";
48
+ /**
49
+ * `nest-graph-inspector export`: writes the graph of the project's
50
+ * application, booted in Nest's preview mode, as `GraphOutput` JSON — the
51
+ * document a running inspector serves at `/output.json`.
52
+ */
53
+ async function runExportCommand(argv, options, io) {
54
+ const projectDir = (0, node_path_1.resolve)(io.cwd, options.project ?? ".");
55
+ if (!(0, project_1.isDirectory)(projectDir)) {
56
+ throw new cli_error_1.CliError(`Project directory not found: ${projectDir}`);
57
+ }
58
+ const projectRequire = (0, node_module_1.createRequire)((0, node_path_1.join)(projectDir, "package.json"));
59
+ const delegatedExitCode = delegateToProjectPackage(argv, projectRequire, io);
60
+ if (delegatedExitCode !== undefined) {
61
+ return delegatedExitCode;
62
+ }
63
+ loadEnvFiles(options["env-file"] ?? [], io.cwd);
64
+ const entryPath = resolveEntry(options, projectDir, io.cwd);
65
+ const out = options.out ?? exports.DEFAULT_OUT_FILE;
66
+ const outPath = out === "-" ? undefined : (0, node_path_1.resolve)(io.cwd, out);
67
+ // Everything the application reads relative to its working directory —
68
+ // .env files, tsconfig.json for JSDoc — is read from the project, exactly
69
+ // as when it is started from there.
70
+ process.chdir(projectDir);
71
+ divertStdoutToStderr();
72
+ const { result, entryName } = await (async () => {
73
+ for (const request of options.require ?? []) {
74
+ try {
75
+ projectRequire(request);
76
+ }
77
+ catch (error) {
78
+ throw new cli_error_1.CliError(`Cannot load --require ${request} from ${(0, project_1.displayPath)(projectDir, io.cwd)}: ${(0, cli_error_1.describeError)(error)}`, { cause: error });
79
+ }
80
+ }
81
+ // Before the entry, so the application decorates its classes against the
82
+ // same reflect-metadata and @nestjs/core this export boots it with.
83
+ const { nestCore, boot } = (0, project_1.loadNestCore)(projectRequire, projectDir, io.cwd);
84
+ let moduleExports;
85
+ try {
86
+ moduleExports = await (0, project_1.loadModule)(entryPath, projectRequire);
87
+ }
88
+ catch (error) {
89
+ throw new cli_error_1.CliError(`Loading ${(0, project_1.displayPath)(entryPath, io.cwd)} failed: ${(0, cli_error_1.describeError)(error)}`, { cause: error });
90
+ }
91
+ const entry = (0, project_1.selectEntryModule)(moduleExports, options.module, entryPath, io.cwd);
92
+ // Loaded only now, after the project's own reflect-metadata.
93
+ let exportGraphModule;
94
+ try {
95
+ exportGraphModule = await Promise.resolve().then(() => __importStar(require("./export-graph")));
96
+ }
97
+ catch (error) {
98
+ throw new cli_error_1.CliError(`Cannot load nest-graph-inspector's own modules from ${(0, project_1.readOwnPackage)().root}: ${(0, cli_error_1.describeError)(error).split("\n")[0]}. Install nest-graph-inspector in the project and run the export there.`);
99
+ }
100
+ const { exportGraph, PreviewBootstrapError } = exportGraphModule;
101
+ try {
102
+ return {
103
+ entryName: entry.name,
104
+ result: await exportGraph({
105
+ nestCore,
106
+ entryModule: entry.module,
107
+ boot,
108
+ logger: (0, stderr_logger_1.createStderrLogger)((text) => io.stderr.write(text)),
109
+ }),
110
+ };
111
+ }
112
+ catch (error) {
113
+ if (error instanceof PreviewBootstrapError) {
114
+ // Nest has already logged the cause, stack and all.
115
+ throw new cli_error_1.CliError(`${error.message}\n` +
116
+ "Preview mode instantiates nothing, but it still loads your module files and evaluates their decorators: " +
117
+ "an environment variable read at import time, or a forRoot()/register() that throws, fails the export as it would fail your application's start. " +
118
+ "The export also boots with snapshot: true, under which Nest serializes each dynamic module's options with JSON.stringify: " +
119
+ "options holding a circular object or a BigInt fail the export, though your application starts.");
120
+ }
121
+ throw new cli_error_1.CliError(`Building the graph of ${entry.name} failed: ${(0, cli_error_1.describeError)(error)}`, { cause: error });
122
+ }
123
+ })();
124
+ for (const warning of result.warnings) {
125
+ io.stderr.write(`nest-graph-inspector: warning: ${warning}\n`);
126
+ }
127
+ const json = options.compact
128
+ ? JSON.stringify(result.graph)
129
+ : JSON.stringify(result.graph, null, 2);
130
+ if (outPath) {
131
+ try {
132
+ (0, node_fs_1.mkdirSync)((0, node_path_1.dirname)(outPath), { recursive: true });
133
+ (0, node_fs_1.writeFileSync)(outPath, json);
134
+ }
135
+ catch (error) {
136
+ throw new cli_error_1.CliError(`Cannot write ${(0, project_1.displayPath)(outPath, io.cwd)}: ${(0, cli_error_1.describeError)(error)}`);
137
+ }
138
+ }
139
+ else {
140
+ await new Promise((done) => io.stdout.write(json, () => done()));
141
+ }
142
+ io.stderr.write(`nest-graph-inspector: exported ${describeGraph(result.graph, entryName)} to ${outPath ? (0, project_1.displayPath)(outPath, io.cwd) : "stdout"} (booted in Nest preview mode: nothing was instantiated)\n`);
143
+ return 0;
144
+ }
145
+ /**
146
+ * The project's own copy of this package, when it is not this one and ships
147
+ * this CLI, runs the export instead: the application imports
148
+ * `NestGraphInspectorModule` from that copy, and the export tells its module
149
+ * and options apart by class identity, which only that copy's classes match.
150
+ */
151
+ function delegateToProjectPackage(argv, projectRequire, io) {
152
+ // The copy that started this one already chose it.
153
+ if (process.env[exports.DELEGATED_ENV]) {
154
+ return undefined;
155
+ }
156
+ const projectPackage = (0, project_1.findProjectPackage)(projectRequire);
157
+ const ownPackage = (0, project_1.readOwnPackage)();
158
+ if (!projectPackage || projectPackage.root === ownPackage.root) {
159
+ return undefined;
160
+ }
161
+ if (projectPackage.bin && (0, project_1.isFile)(projectPackage.bin)) {
162
+ io.stderr.write(`nest-graph-inspector: using the project's own nest-graph-inspector@${projectPackage.version} (${projectPackage.root})\n`);
163
+ const child = (0, node_child_process_1.spawnSync)(process.execPath, [...process.execArgv, projectPackage.bin, ...argv], {
164
+ cwd: io.cwd,
165
+ stdio: "inherit",
166
+ env: { ...process.env, [exports.DELEGATED_ENV]: "1" },
167
+ });
168
+ if (child.error) {
169
+ throw new cli_error_1.CliError(`Cannot run ${projectPackage.bin}: ${(0, cli_error_1.describeError)(child.error)}`);
170
+ }
171
+ if (child.status === null) {
172
+ throw new cli_error_1.CliError(`The project's nest-graph-inspector was stopped by ${child.signal ?? "a signal"}.`);
173
+ }
174
+ return child.status;
175
+ }
176
+ const cannotRun = projectPackage.bin
177
+ ? `whose export CLI is missing (${projectPackage.bin})`
178
+ : "which does not ship this export CLI";
179
+ io.stderr.write(`nest-graph-inspector: warning: the project installs nest-graph-inspector@${projectPackage.version} (${projectPackage.root}), ${cannotRun}; exporting with nest-graph-inspector@${ownPackage.version} (${ownPackage.root}) instead. Upgrade the project's nest-graph-inspector for a graph built with its own options.\n`);
180
+ return undefined;
181
+ }
182
+ /**
183
+ * Loads `--env-file`s into `process.env` before any of the application's
184
+ * code runs, as a `main.ts` that loads its environment before importing
185
+ * `AppModule` would — and the export never loads `main.ts`. Precedence is
186
+ * `node --env-file`'s: a variable already set in the environment keeps its
187
+ * value, and of two files the later one wins. `process.loadEnvFile()` never
188
+ * overrides a variable, so the files are loaded from the last to the first.
189
+ */
190
+ function loadEnvFiles(paths, cwd) {
191
+ if (!paths.length) {
192
+ return;
193
+ }
194
+ const { loadEnvFile } = process;
195
+ if (typeof loadEnvFile !== "function") {
196
+ throw new cli_error_1.CliError(`--env-file needs Node.js 20.12 or later, which has process.loadEnvFile(); this is Node.js ${process.versions.node}. Use --require dotenv/config instead.`);
197
+ }
198
+ for (const path of [...paths].reverse()) {
199
+ const envFile = (0, node_path_1.resolve)(cwd, path);
200
+ try {
201
+ loadEnvFile(envFile);
202
+ }
203
+ catch (error) {
204
+ throw new cli_error_1.CliError(`Cannot load --env-file ${(0, project_1.displayPath)(envFile, cwd)}: ${(0, cli_error_1.describeError)(error)}`);
205
+ }
206
+ }
207
+ }
208
+ function resolveEntry(options, projectDir, cwd) {
209
+ const entryPath = options.entry
210
+ ? (0, node_path_1.resolve)(cwd, options.entry)
211
+ : (0, project_1.detectEntry)(projectDir, cwd);
212
+ if (!(0, project_1.isFile)(entryPath)) {
213
+ throw new cli_error_1.CliError(`Entry file not found: ${(0, project_1.displayPath)(entryPath, cwd)}. Check the --entry path, and build your project first (nest build) if it points at compiled output.`);
214
+ }
215
+ if ((0, project_1.isTypeScriptFile)(entryPath) && !options.require?.length) {
216
+ throw new cli_error_1.CliError(`${(0, project_1.displayPath)(entryPath, cwd)} is TypeScript, which Node cannot load on its own. ` +
217
+ "Build your project and pass the compiled file, or add a loader that emits decorator metadata: " +
218
+ "--require ts-node/register (and --require tsconfig-paths/register for path aliases).");
219
+ }
220
+ return entryPath;
221
+ }
222
+ /**
223
+ * From here until the process exits, whatever the application writes through
224
+ * `process.stdout` — a `console.log` in a module file, Nest's logger, a timer
225
+ * that fires after the export is done — goes to stderr instead, so standard
226
+ * output carries the graph and nothing else. Never undone: output an
227
+ * application schedules can arrive at any point until the process exits. The
228
+ * graph itself goes through `io.stdout`, which holds the stream's own
229
+ * `write`. A write straight to file descriptor 1 is beyond its reach.
230
+ */
231
+ function divertStdoutToStderr() {
232
+ const stdout = process.stdout;
233
+ stdout.write = process.stderr.write.bind(process.stderr);
234
+ }
235
+ /** `AppModule (7 modules, 15 providers, 4 controllers, 3 cycles)`. */
236
+ function describeGraph(graph, entryName) {
237
+ const modules = Object.values(graph.modules);
238
+ const providers = modules.reduce((total, module) => total + module.providers.length, 0);
239
+ const controllers = modules.reduce((total, module) => total + module.controllers.length, 0);
240
+ const cycles = graph.cycles.modules.length +
241
+ graph.cycles.providers.length +
242
+ graph.cycles.controllers.length;
243
+ const root = graph.root === entryName ? graph.root : `${graph.root} (entry ${entryName})`;
244
+ return `${root} (${[
245
+ plural(modules.length, "module"),
246
+ plural(providers, "provider"),
247
+ plural(controllers, "controller"),
248
+ plural(cycles, "cycle"),
249
+ ].join(", ")})`;
250
+ }
251
+ function plural(count, noun) {
252
+ return `${count} ${noun}${count === 1 ? "" : "s"}`;
253
+ }
254
+ //# sourceMappingURL=export-command.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"export-command.js","sourceRoot":"","sources":["../../src/cli/export-command.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,4CA+HC;AAxKD,2DAA+C;AAC/C,qCAAmD;AACnD,6CAA4C;AAC5C,yCAAmD;AAEnD,2CAAsD;AAEtD,uCAWmB;AACnB,mDAAqD;AAExC,QAAA,gBAAgB,GAAG,iBAAiB,CAAC;AAElD,mFAAmF;AACtE,QAAA,aAAa,GAAG,oCAAoC,CAAC;AAYlE;;;;GAIG;AACI,KAAK,UAAU,gBAAgB,CACpC,IAAuB,EACvB,OAA6B,EAC7B,EAAS;IAET,MAAM,UAAU,GAAG,IAAA,mBAAO,EAAC,EAAE,CAAC,GAAG,EAAE,OAAO,CAAC,OAAO,IAAI,GAAG,CAAC,CAAC;IAC3D,IAAI,CAAC,IAAA,qBAAW,EAAC,UAAU,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,oBAAQ,CAAC,gCAAgC,UAAU,EAAE,CAAC,CAAC;IACnE,CAAC;IAED,MA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,CAAC;AAED,SAAS,MAAM,CAAC,KAAa,EAAE,IAAY;IACzC,OAAO,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;AACrD,CAAC"}
@@ -0,0 +1,65 @@
1
+ import type { LoggerService, Type } from "@nestjs/common";
2
+ import type * as NestCoreExports from "@nestjs/core";
3
+ import type { ModulesContainer } from "@nestjs/core";
4
+ import type { NestGraphInspectorModuleOptions } from "../nest-graph-inspector.type";
5
+ import type { GraphOutput } from "../types/graph-output.type";
6
+ /**
7
+ * What an export needs from `@nestjs/core` — the application's own copy, the
8
+ * one its modules were decorated against. A second copy would build a second,
9
+ * empty container.
10
+ */
11
+ export type NestCore = Pick<typeof NestCoreExports, "NestFactory" | "ModulesContainer">;
12
+ /**
13
+ * How the application is booted. Both build the same container, and so the
14
+ * same graph: `application` is `NestFactory.create()`, which needs
15
+ * `@nestjs/platform-express` — without it Nest exits the process — and
16
+ * `application-context` is `NestFactory.createApplicationContext()`, which
17
+ * needs no HTTP platform.
18
+ */
19
+ export type GraphExportBoot = "application" | "application-context";
20
+ /** Where the options the graph was built with came from. */
21
+ export type GraphExportOptionsSource =
22
+ /** Read from the application's `NestGraphInspectorModule` (plain or `forRoot()`). */
23
+ "application"
24
+ /** `forRootAsync()`: its factory never runs in preview mode, so defaults were used. */
25
+ | "unresolved"
26
+ /** A different copy of this package's module: defaults were used. */
27
+ | "other-copy"
28
+ /** The application does not import the inspector: defaults were used. */
29
+ | "defaults";
30
+ export type GraphExportParams = {
31
+ nestCore: NestCore;
32
+ entryModule: Type<unknown>;
33
+ boot: GraphExportBoot;
34
+ /** Passed to Nest as the application's logger; `false` silences it. */
35
+ logger: LoggerService | false;
36
+ };
37
+ export type GraphExportResult = {
38
+ graph: GraphOutput;
39
+ optionsSource: GraphExportOptionsSource;
40
+ warnings: string[];
41
+ };
42
+ /** Nest could not bootstrap the application in preview mode; `cause` says why. */
43
+ export declare class PreviewBootstrapError extends Error {
44
+ constructor(entryName: string, cause: unknown);
45
+ }
46
+ /**
47
+ * Builds the graph of an application without running it.
48
+ *
49
+ * The application is booted in Nest's own preview mode
50
+ * (https://docs.nestjs.com/devtools/ci-cd-integration): Nest scans every
51
+ * module and resolves every dependency, but calls no constructor, no factory,
52
+ * and no lifecycle hook, except in a module on Nest's
53
+ * `InitializeOnPreviewAllowlist` — in Nest itself, only `InternalCoreModule`.
54
+ * The application is never initialised and never listens. The graph is then
55
+ * built by the same `DiscoveryAdapter` and `GraphOutputBuilder` a running
56
+ * inspector serves `/output.json` from, with the options the application gave
57
+ * the inspector.
58
+ */
59
+ export declare function exportGraph(params: GraphExportParams): Promise<GraphExportResult>;
60
+ /**
61
+ * The graph a running inspector configured with `options` would serve, built
62
+ * over an already-booted container.
63
+ */
64
+ export declare function buildGraphOutput(modulesContainer: ModulesContainer, options: NestGraphInspectorModuleOptions): GraphOutput;
65
+ //# sourceMappingURL=export-graph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"export-graph.d.ts","sourceRoot":"","sources":["../../src/cli/export-graph.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,KAAK,KAAK,eAAe,MAAM,cAAc,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAMrD,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,8BAA8B,CAAC;AAGpF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAG9D;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAAG,IAAI,CACzB,OAAO,eAAe,EACtB,aAAa,GAAG,kBAAkB,CACnC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,eAAe,GAAG,aAAa,GAAG,qBAAqB,CAAC;AAEpE,4DAA4D;AAC5D,MAAM,MAAM,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