nestjs-docfy 0.5.0 → 0.6.1

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.
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.registerWebpackPlugin = registerWebpackPlugin;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const detect_project_1 = require("./detect-project");
10
+ /**
11
+ * Adds "nestjs-docfy" to compilerOptions.plugins in the target project's
12
+ * nest-cli.json. Opt-in only (--register-plugin) — some users deliberately
13
+ * prefer patch-spec over a compiler plugin, so this must never run silently.
14
+ *
15
+ * Returns null when nest-cli.json is missing or not valid JSON (nothing we
16
+ * can safely edit). Rewrites the file with 2-space indentation; comments or
17
+ * unusual formatting in the original file are not preserved.
18
+ */
19
+ function registerWebpackPlugin(root, dryRun) {
20
+ const nestCliPath = path_1.default.join(root, 'nest-cli.json');
21
+ let raw;
22
+ try {
23
+ raw = fs_1.default.readFileSync(nestCliPath, 'utf8');
24
+ }
25
+ catch {
26
+ return null;
27
+ }
28
+ let json;
29
+ try {
30
+ json = JSON.parse(raw);
31
+ }
32
+ catch {
33
+ return null;
34
+ }
35
+ const compilerOptions = json.compilerOptions ?? {};
36
+ const plugins = Array.isArray(compilerOptions.plugins) ? compilerOptions.plugins : [];
37
+ if ((0, detect_project_1.pluginListHasDocfy)(plugins)) {
38
+ return { path: nestCliPath, changed: false };
39
+ }
40
+ if (!dryRun) {
41
+ json.compilerOptions = { ...compilerOptions, plugins: [...plugins, 'nestjs-docfy'] };
42
+ fs_1.default.writeFileSync(nestCliPath, `${JSON.stringify(json, null, 2)}\n`, 'utf8');
43
+ }
44
+ return { path: nestCliPath, changed: true };
45
+ }
46
+ //# sourceMappingURL=register-webpack-plugin.js.map
@@ -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AE,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC9E,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAC9C,CAAC"}
@@ -43,6 +43,19 @@ export interface DocfyUiSetupOptions {
43
43
  * `{ raw: false }`) when using `staticSpecPath` on a Fastify app.
44
44
  */
45
45
  staticSpecPath?: string;
46
+ /**
47
+ * List of OpenAPI specs to offer in docfy-ui's spec switcher — useful when
48
+ * one docfy-ui instance should let users browse multiple services without
49
+ * leaving the UI. Each `url` is fetched client-side exactly like the
50
+ * default `/api-json` spec is, so it can point at another same-origin
51
+ * route or a different origin (subject to that origin's CORS policy).
52
+ * When omitted (the default), docfy-ui behaves exactly as before —
53
+ * a single spec, no switcher rendered.
54
+ */
55
+ specs?: {
56
+ name: string;
57
+ url: string;
58
+ }[];
46
59
  }
47
60
  /**
48
61
  * Serves the published `docfy-ui` package's static build at `mountPath`,
@@ -75,9 +75,12 @@ class DocfyUiModule {
75
75
  const indexHtmlPath = require.resolve('docfy-ui/dist/index.html');
76
76
  const uiDir = path.dirname(indexHtmlPath);
77
77
  const basePath = mountPath === '/' ? '/' : `${mountPath.replace(/\/+$/, '')}/`;
78
+ const specsScript = options.specs
79
+ ? `\n <script>window.__DOCFY_SPECS__ = ${JSON.stringify(options.specs)};</script>`
80
+ : '';
78
81
  const indexHtml = fs
79
82
  .readFileSync(indexHtmlPath, 'utf8')
80
- .replace('<head>', `<head>\n <base href="${basePath}" />\n <script>window.__DOCFY_BASE_PATH__ = ${JSON.stringify(basePath)};</script>`);
83
+ .replace('<head>', `<head>\n <base href="${basePath}" />\n <script>window.__DOCFY_BASE_PATH__ = ${JSON.stringify(basePath)};</script>${specsScript}`);
81
84
  if (isFastify) {
82
85
  const fastifyStatic = loadFastifyStatic();
83
86
  const instance = httpAdapter.getInstance();
@@ -1 +1 @@
1
- {"version":3,"file":"docfy-ui.module.js","sourceRoot":"","sources":["../src/docfy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A2C;QAC3C,GAAG,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;QAC5D,GAAG,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,IAAqB,EAAE,GAAqB,EAAE,EAAE;YAClE,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YACtB,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACtB,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AA9DD,sCA8DC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nestjs-docfy",
3
- "version": "0.5.0",
3
+ "version": "0.6.1",
4
4
  "description": "Keep your NestJS controllers clean — Swagger docs live in a separate companion file by naming convention",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -116,8 +116,9 @@
116
116
  },
117
117
  "dependencies": {
118
118
  "commander": "^15.0.0",
119
- "docfy-ui": "^0.0.5",
119
+ "docfy-ui": "^0.1.0",
120
120
  "express": "^5.0.0",
121
+ "openapi-typescript": "^7.13.0",
121
122
  "picocolors": "^1.1.1",
122
123
  "source-map": "^0.6.1",
123
124
  "ts-morph": "^28.0.0"
@@ -1,32 +0,0 @@
1
- /**
2
- * Loads a .ts companion docs file at runtime without relying on a
3
- * pre-registered TypeScript loader (ts-node, tsx, etc.).
4
- *
5
- * Why this is needed: docs files are intentionally never imported by
6
- * application code (that's the whole point of the *.controller.docs.ts
7
- * convention — they attach metadata from outside the controller). Under
8
- * NestJS CLI's `webpack: true` build mode, that means they're never part
9
- * of the bundle's reachable module graph, so they never get compiled to
10
- * .js even when the rest of the app is — there's nothing for a plain
11
- * `require()` to load. resolveDocsPath can correctly locate the original
12
- * .ts file (see resolve-source-from-stack.ts), but loading it still needs
13
- * this.
14
- *
15
- * Registers `require.extensions['.ts']` — exactly the mechanism ts-node's
16
- * own `register()` uses — rather than manually constructing a `Module`
17
- * instance and calling `_compile()` directly. That distinction matters for
18
- * correctness, not just style: Node's module *resolution* (not just
19
- * compilation) only tries an extension if it's a registered key of
20
- * `require.extensions`. A docs file importing a sibling relative path
21
- * (`import { UsersController } from './users.controller'`) needs Node to
22
- * try `./users.controller.ts` while resolving — manually compiling just
23
- * the entry file doesn't make Node try `.ts` for anything *it* requires
24
- * in turn, so any relative import inside the docs file would still throw
25
- * "Cannot find module" one level down.
26
- *
27
- * Transpiles with esbuild — type-stripping only, since docs files call
28
- * decorator factories as plain functions (`docs(Controller, { classDecorators:
29
- * [ApiTags('x')] })`) rather than using TypeScript decorator syntax
30
- * themselves, so no decorator-metadata emulation is needed.
31
- */
32
- export declare function requireTypeScriptFile(absPath: string): unknown;
@@ -1,122 +0,0 @@
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.requireTypeScriptFile = requireTypeScriptFile;
37
- const fs = __importStar(require("fs"));
38
- /**
39
- * Loads a .ts companion docs file at runtime without relying on a
40
- * pre-registered TypeScript loader (ts-node, tsx, etc.).
41
- *
42
- * Why this is needed: docs files are intentionally never imported by
43
- * application code (that's the whole point of the *.controller.docs.ts
44
- * convention — they attach metadata from outside the controller). Under
45
- * NestJS CLI's `webpack: true` build mode, that means they're never part
46
- * of the bundle's reachable module graph, so they never get compiled to
47
- * .js even when the rest of the app is — there's nothing for a plain
48
- * `require()` to load. resolveDocsPath can correctly locate the original
49
- * .ts file (see resolve-source-from-stack.ts), but loading it still needs
50
- * this.
51
- *
52
- * Registers `require.extensions['.ts']` — exactly the mechanism ts-node's
53
- * own `register()` uses — rather than manually constructing a `Module`
54
- * instance and calling `_compile()` directly. That distinction matters for
55
- * correctness, not just style: Node's module *resolution* (not just
56
- * compilation) only tries an extension if it's a registered key of
57
- * `require.extensions`. A docs file importing a sibling relative path
58
- * (`import { UsersController } from './users.controller'`) needs Node to
59
- * try `./users.controller.ts` while resolving — manually compiling just
60
- * the entry file doesn't make Node try `.ts` for anything *it* requires
61
- * in turn, so any relative import inside the docs file would still throw
62
- * "Cannot find module" one level down.
63
- *
64
- * Transpiles with esbuild — type-stripping only, since docs files call
65
- * decorator factories as plain functions (`docs(Controller, { classDecorators:
66
- * [ApiTags('x')] })`) rather than using TypeScript decorator syntax
67
- * themselves, so no decorator-metadata emulation is needed.
68
- */
69
- function requireTypeScriptFile(absPath) {
70
- console.error('[DEBUG requireTypeScriptFile]', JSON.stringify(absPath), 'exists=', fs.existsSync(absPath));
71
- if (!fs.existsSync(absPath)) {
72
- // Matches the shape of Node's own require() MODULE_NOT_FOUND error, so
73
- // callers that distinguish "file doesn't exist" from "file threw while
74
- // loading" (DocfyModule's isMissingDocsFile) work the same regardless
75
- // of which loader actually handled the path.
76
- throw Object.assign(new Error(`Cannot find module '${absPath}'`), {
77
- code: 'MODULE_NOT_FOUND',
78
- });
79
- }
80
- registerTsExtension();
81
- // eslint-disable-next-line @typescript-eslint/no-require-imports
82
- return require(absPath);
83
- }
84
- let registered = false;
85
- function registerTsExtension() {
86
- if (registered || require.extensions['.ts'])
87
- return;
88
- const esbuild = loadEsbuild();
89
- if (!esbuild) {
90
- throw new Error(`[nestjs-docfy] Cannot load a .ts docs file: no TypeScript loader is registered ` +
91
- `(e.g. ts-node) and the "esbuild" dependency isn't available. Install esbuild ` +
92
- `(it's a direct dependency of nestjs-docfy and should already be present — ` +
93
- `check your install), or disable webpack bundling ("webpack": false in ` +
94
- `nest-cli.json) so docs files get compiled to .js like everything else.`);
95
- }
96
- require.extensions['.ts'] = (mod, filename) => {
97
- const source = fs.readFileSync(filename, 'utf8');
98
- const { code } = esbuild.transformSync(source, {
99
- loader: 'ts',
100
- format: 'cjs',
101
- target: 'es2019',
102
- sourcefile: filename,
103
- // A docs file's own relative imports can pull in real application
104
- // source (e.g. the controller it documents), which legitimately uses
105
- // NestJS's decorator syntax — without this, esbuild rejects parameter
106
- // decorators like `@Body()` outright.
107
- tsconfigRaw: { compilerOptions: { experimentalDecorators: true, emitDecoratorMetadata: true } },
108
- });
109
- mod._compile(code, filename);
110
- };
111
- registered = true;
112
- }
113
- function loadEsbuild() {
114
- try {
115
- // eslint-disable-next-line @typescript-eslint/no-require-imports
116
- return require('esbuild');
117
- }
118
- catch {
119
- return null;
120
- }
121
- }
122
- //# sourceMappingURL=require-ts.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"require-ts.js","sourceRoot":"","sources":["../src/require-ts.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,sDAeC;AAtDD,uCAAyB;AAQzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,SAAgB,qBAAqB,CAAC,OAAe;IACnD,OAAO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