nestjs-docfy 0.4.0 → 0.6.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 +177 -84
- package/dist/apply-docfy-metadata.d.ts +37 -0
- package/dist/apply-docfy-metadata.js +55 -0
- package/dist/apply-docfy-metadata.js.map +1 -0
- package/dist/cli/build-openapi-patch.d.ts +16 -12
- package/dist/cli/build-openapi-patch.js +98 -15
- package/dist/cli/build-openapi-patch.js.map +1 -1
- package/dist/cli/check.js.map +1 -1
- package/dist/cli/coverage.js +1 -3
- package/dist/cli/coverage.js.map +1 -1
- package/dist/cli/detect-project.d.ts +8 -0
- package/dist/cli/detect-project.js +28 -5
- package/dist/cli/detect-project.js.map +1 -1
- package/dist/cli/errors.js.map +1 -1
- package/dist/cli/eval-decorator-args.d.ts +5 -3
- package/dist/cli/eval-decorator-args.js +64 -11
- package/dist/cli/eval-decorator-args.js.map +1 -1
- package/dist/cli/extract-docs-config.d.ts +21 -1
- package/dist/cli/extract-docs-config.js +18 -6
- package/dist/cli/extract-docs-config.js.map +1 -1
- package/dist/cli/extract-methods.d.ts +11 -0
- package/dist/cli/extract-methods.js +113 -29
- package/dist/cli/extract-methods.js.map +1 -1
- package/dist/cli/generate-client.d.ts +15 -0
- package/dist/cli/generate-client.js +62 -0
- package/dist/cli/generate-client.js.map +1 -0
- package/dist/cli/generate-file.js +24 -24
- package/dist/cli/generate-file.js.map +1 -1
- package/dist/cli/index.js +140 -53
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/lint.js +1 -3
- package/dist/cli/lint.js.map +1 -1
- package/dist/cli/logger.js +12 -6
- package/dist/cli/logger.js.map +1 -1
- package/dist/cli/merge-docs.js.map +1 -1
- package/dist/cli/merge-spec-patch.d.ts +15 -8
- package/dist/cli/merge-spec-patch.js +20 -4
- package/dist/cli/merge-spec-patch.js.map +1 -1
- package/dist/cli/parse-args.d.ts +2 -0
- package/dist/cli/parse-args.js +3 -6
- package/dist/cli/parse-args.js.map +1 -1
- package/dist/cli/patch-spec.d.ts +32 -8
- package/dist/cli/patch-spec.js +37 -15
- package/dist/cli/patch-spec.js.map +1 -1
- package/dist/cli/read-spec-source.d.ts +7 -0
- package/dist/cli/read-spec-source.js +74 -0
- package/dist/cli/read-spec-source.js.map +1 -0
- package/dist/cli/register-webpack-plugin.d.ts +16 -0
- package/dist/cli/register-webpack-plugin.js +46 -0
- package/dist/cli/register-webpack-plugin.js.map +1 -0
- package/dist/cli/resolve-tsconfig.js +1 -5
- package/dist/cli/resolve-tsconfig.js.map +1 -1
- package/dist/cli/scan-controllers.d.ts +11 -0
- package/dist/cli/scan-controllers.js +10 -3
- package/dist/cli/scan-controllers.js.map +1 -1
- package/dist/cli/watch.js +3 -1
- package/dist/cli/watch.js.map +1 -1
- package/dist/cli/writer.js.map +1 -1
- package/dist/docfy-ui.module.d.ts +13 -0
- package/dist/docfy-ui.module.js +6 -3
- package/dist/docfy-ui.module.js.map +1 -1
- package/dist/docfy.module.js +1 -1
- package/dist/docfy.module.js.map +1 -1
- package/dist/docs.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/plugin/generate-metadata.d.ts +35 -0
- package/dist/plugin/generate-metadata.js +46 -0
- package/dist/plugin/generate-metadata.js.map +1 -0
- package/dist/plugin/index.d.ts +30 -0
- package/dist/plugin/index.js +62 -0
- package/dist/plugin/index.js.map +1 -0
- package/dist/registry.d.ts +3 -3
- package/dist/registry.js.map +1 -1
- package/dist/resolve-docs-path.d.ts +1 -1
- package/dist/resolve-docs-path.js.map +1 -1
- package/dist/resolve-source-from-stack.js.map +1 -1
- package/dist/with-docs.decorator.js.map +1 -1
- package/package.json +25 -4
- package/dist/require-ts.d.ts +0 -32
- package/dist/require-ts.js +0 -122
- package/dist/require-ts.js.map +0 -1
|
@@ -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`,
|
package/dist/docfy-ui.module.js
CHANGED
|
@@ -39,11 +39,11 @@ const path = __importStar(require("path"));
|
|
|
39
39
|
const express = __importStar(require("express"));
|
|
40
40
|
function loadFastifyStatic() {
|
|
41
41
|
try {
|
|
42
|
-
// eslint-disable-next-line @typescript-eslint/no-
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
43
43
|
return require('@fastify/static');
|
|
44
44
|
}
|
|
45
45
|
catch {
|
|
46
|
-
throw new Error(
|
|
46
|
+
throw new Error('DocfyUiModule.setup(): serving docfy-ui on a Fastify-based Nest app requires ' +
|
|
47
47
|
"the optional peer dependency '@fastify/static'. Install it with `npm install @fastify/static`.");
|
|
48
48
|
}
|
|
49
49
|
}
|
|
@@ -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-ui.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AACzB,2CAA6B;AAC7B,iDAAmC;
|
|
1
|
+
{"version":3,"file":"docfy-ui.module.js","sourceRoot":"","sources":["../src/docfy-ui.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AACzB,2CAA6B;AAC7B,iDAAmC;AAkEnC,SAAS,iBAAiB;IACxB,IAAI,CAAC;QACH,iEAAiE;QACjE,OAAO,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACpC,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,KAAK,CACb,+EAA+E;YAC7E,gGAAgG,CACnG,CAAC;IACJ,CAAC;AACH,CAAC;AAkBD;;;;;;;;;;;;;GAaG;AACH,MAAa,aAAa;IACxB,MAAM,CAAC,KAAK,CAAC,SAAiB,EAAE,GAAuB,EAAE,UAA+B,EAAE;QACxF,MAAM,WAAW,GAAG,GAAG,CAAC,cAAc,EAAE,CAAC;QACzC,MAAM,SAAS,GAAG,WAAW,CAAC,OAAO,EAAE,KAAK,SAAS,CAAC;QAEtD,I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E;oBAC7B,IAAI,EAAE,KAAK;oBACX,gEAAgE;oBAChE,+DAA+D;oBAC/D,QAAQ,EAAE,KAAK;oBACf,gEAAgE;oBAChE,oDAAoD;oBACpD,6DAA6D;oBAC7D,YAAY;oBACZ,KAAK,EAAE,KAAK;oBACZ,aAAa,EAAE,KAAK;iBACrB,CAAC,CAAC;gBACH,MAAM,CAAC,kBAAkB,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;oBACxC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;gBAC1C,CAAC,CAAC,CAAC;gBACH,IAAI,EAAE,CAAC;YACT,CAAC,EACD,EAAE,MAAM,EAAE,SAAS,EAAE,CACtB,CAAC;YACF,OAAO;QACT,CAAC;QAED,wEAAwE;QACxE,+DAA+D;QAC/D,2CAA2C;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/dist/docfy.module.js
CHANGED
|
@@ -52,7 +52,7 @@ let DocfyModule = DocfyModule_1 = class DocfyModule {
|
|
|
52
52
|
// The docs file simply doesn't exist — allowed unless strict mode
|
|
53
53
|
const message = `No docs file found for ${controllerClass.name}. Expected: ${docsPath}`;
|
|
54
54
|
if (strict)
|
|
55
|
-
throw new Error(`[nestjs-docfy] ${message}
|
|
55
|
+
throw new Error(`[nestjs-docfy] ${message}`, { cause: err });
|
|
56
56
|
DocfyModule_1.logger.warn(message);
|
|
57
57
|
}
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AC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAChD,OAAO,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AACtC,CAAC"}
|
package/dist/docs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"docs.js","sourceRoot":"","sources":["../src/docs.ts"],"names":[],"mappings":";;AAwCA,
|
|
1
|
+
{"version":3,"file":"docs.js","sourceRoot":"","sources":["../src/docs.ts"],"names":[],"mappings":";;AAwCA,oBA4BC;AApED,6DAAwD;AAwBxD;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,IAAI,CAAI,eAA+B,EAAE,MAAqB;IAC5E,IAAI,MAAM,CAAC,eAAe,EAAE,CAAC;QAC3B,KAAK,MAAM,SAAS,IAAI,MAAM,CAAC,eAAe,EAAE,CAAC;YAC/C,SAAS,CAAC,eAAe,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;IAED,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;QACjB,qCAAgB,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;IAC7D,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,OAAO;QAAE,OAAO;IAE5B,KAAK,MAAM,CAAC,UAAU,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAkC,EAAE,CAAC;QACvG,MAAM,UAAU,GAAG,MAAM,CAAC,wBAAwB,CAAC,eAAe,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;QAE1F,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,OAAO,CAAC,IAAI,CACV,0BAA0B,UAAU,kBAAkB,eAAe,CAAC,IAAI,IAAI;gBAC5E,uCAAuC,CAC1C,CAAC;YACF,SAAS;QACX,CAAC;QAED,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACnC,SAAS,CAAC,eAAe,CAAC,SAAS,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;QAC/D,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,4 +3,5 @@ export { docs, DocsConfig } from './docs';
|
|
|
3
3
|
export { DocfyModule, DocfyModuleOptions } from './docfy.module';
|
|
4
4
|
export { attachTagGroups } from './attach-tag-groups';
|
|
5
5
|
export { TagGroup } from './tag-group-registry';
|
|
6
|
-
export { DocfyUiModule, DocfyUiSetupTarget, DocfyUiSetupOptions, DocfyUiHttpAdapter
|
|
6
|
+
export { DocfyUiModule, DocfyUiSetupTarget, DocfyUiSetupOptions, DocfyUiHttpAdapter } from './docfy-ui.module';
|
|
7
|
+
export { applyDocfyMetadata, ApplyDocfyMetadataOptions } from './apply-docfy-metadata';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DocfyUiModule = exports.attachTagGroups = exports.DocfyModule = exports.docs = exports.DOCFY_MARKER = exports.WithDocs = void 0;
|
|
3
|
+
exports.applyDocfyMetadata = exports.DocfyUiModule = exports.attachTagGroups = exports.DocfyModule = exports.docs = exports.DOCFY_MARKER = exports.WithDocs = void 0;
|
|
4
4
|
var with_docs_decorator_1 = require("./with-docs.decorator");
|
|
5
5
|
Object.defineProperty(exports, "WithDocs", { enumerable: true, get: function () { return with_docs_decorator_1.WithDocs; } });
|
|
6
6
|
Object.defineProperty(exports, "DOCFY_MARKER", { enumerable: true, get: function () { return with_docs_decorator_1.DOCFY_MARKER; } });
|
|
@@ -12,4 +12,6 @@ var attach_tag_groups_1 = require("./attach-tag-groups");
|
|
|
12
12
|
Object.defineProperty(exports, "attachTagGroups", { enumerable: true, get: function () { return attach_tag_groups_1.attachTagGroups; } });
|
|
13
13
|
var docfy_ui_module_1 = require("./docfy-ui.module");
|
|
14
14
|
Object.defineProperty(exports, "DocfyUiModule", { enumerable: true, get: function () { return docfy_ui_module_1.DocfyUiModule; } });
|
|
15
|
+
var apply_docfy_metadata_1 = require("./apply-docfy-metadata");
|
|
16
|
+
Object.defineProperty(exports, "applyDocfyMetadata", { enumerable: true, get: function () { return apply_docfy_metadata_1.applyDocfyMetadata; } });
|
|
15
17
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,6DAA+D;AAAtD,+GAAA,QAAQ,OAAA;AAAE,mHAAA,YAAY,OAAA;AAC/B,+BAA0C;AAAjC,4FAAA,IAAI,OAAA;AACb,+CAAiE;AAAxD,2GAAA,WAAW,OAAA;AACpB,yDAAsD;AAA7C,oHAAA,eAAe,OAAA;AAExB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,6DAA+D;AAAtD,+GAAA,QAAQ,OAAA;AAAE,mHAAA,YAAY,OAAA;AAC/B,+BAA0C;AAAjC,4FAAA,IAAI,OAAA;AACb,+CAAiE;AAAxD,2GAAA,WAAW,OAAA;AACpB,yDAAsD;AAA7C,oHAAA,eAAe,OAAA;AAExB,qDAA+G;AAAtG,gHAAA,aAAa,OAAA;AACtB,+DAAuF;AAA9E,0HAAA,kBAAkB,OAAA"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** Filename the CLI plugin writes into the build output dir, and `applyDocfyMetadata()` reads by default. */
|
|
2
|
+
export declare const DOCFY_METADATA_FILENAME = "docfy-metadata.json";
|
|
3
|
+
export interface GenerateMetadataOptions {
|
|
4
|
+
/** Absolute path to the project's tsconfig — the same one the build is using. */
|
|
5
|
+
tsConfigFilePath: string;
|
|
6
|
+
/** Absolute path to the project root, used for the same symlink/path-traversal safety check `scanApp` always applies. */
|
|
7
|
+
projectRoot: string;
|
|
8
|
+
/** Absolute path to the directory the metadata file should be written into (typically the build's outDir). */
|
|
9
|
+
outDir: string;
|
|
10
|
+
/** Controller glob override — same convention as the CLI's `--pattern` flag. Defaults to `**\/*.controller.ts`. */
|
|
11
|
+
controllerGlob?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface GenerateMetadataResult {
|
|
14
|
+
/** Absolute path the metadata file was written to. */
|
|
15
|
+
outFile: string;
|
|
16
|
+
/** How many "METHOD /path" operations the generated patch touches. */
|
|
17
|
+
patchedOperationCount: number;
|
|
18
|
+
controllersWithoutDocs: string[];
|
|
19
|
+
unparseableDocsFiles: string[];
|
|
20
|
+
scanErrors: {
|
|
21
|
+
file: string;
|
|
22
|
+
message: string;
|
|
23
|
+
}[];
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Scans every controller in the project via static analysis (ts-morph — the
|
|
27
|
+
* same engine `generate`/`check`/`patch-spec` already use) and writes the
|
|
28
|
+
* resulting SpecPatch to a JSON file in the build output directory.
|
|
29
|
+
*
|
|
30
|
+
* This is the piece the CLI plugin (`src/plugin/index.ts`) calls once per
|
|
31
|
+
* compilation. Unlike the `patch-spec` CLI command, it needs no base OpenAPI
|
|
32
|
+
* document — `applyDocfyMetadata()` reads the written file at runtime and
|
|
33
|
+
* merges it into whatever `SwaggerModule.createDocument()` produces then.
|
|
34
|
+
*/
|
|
35
|
+
export declare function generateDocfyMetadata(options: GenerateMetadataOptions): GenerateMetadataResult;
|
|
@@ -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.DOCFY_METADATA_FILENAME = void 0;
|
|
7
|
+
exports.generateDocfyMetadata = generateDocfyMetadata;
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const scan_controllers_1 = require("../cli/scan-controllers");
|
|
11
|
+
const patch_spec_1 = require("../cli/patch-spec");
|
|
12
|
+
/** Filename the CLI plugin writes into the build output dir, and `applyDocfyMetadata()` reads by default. */
|
|
13
|
+
exports.DOCFY_METADATA_FILENAME = 'docfy-metadata.json';
|
|
14
|
+
/**
|
|
15
|
+
* Scans every controller in the project via static analysis (ts-morph — the
|
|
16
|
+
* same engine `generate`/`check`/`patch-spec` already use) and writes the
|
|
17
|
+
* resulting SpecPatch to a JSON file in the build output directory.
|
|
18
|
+
*
|
|
19
|
+
* This is the piece the CLI plugin (`src/plugin/index.ts`) calls once per
|
|
20
|
+
* compilation. Unlike the `patch-spec` CLI command, it needs no base OpenAPI
|
|
21
|
+
* document — `applyDocfyMetadata()` reads the written file at runtime and
|
|
22
|
+
* merges it into whatever `SwaggerModule.createDocument()` produces then.
|
|
23
|
+
*/
|
|
24
|
+
function generateDocfyMetadata(options) {
|
|
25
|
+
const app = {
|
|
26
|
+
name: 'app',
|
|
27
|
+
root: options.projectRoot,
|
|
28
|
+
tsconfig: options.tsConfigFilePath,
|
|
29
|
+
controllerGlob: options.controllerGlob ?? '**/*.controller.ts',
|
|
30
|
+
};
|
|
31
|
+
const { controllers, errors: scanErrors, projectsByControllerPath, } = (0, scan_controllers_1.scanApp)(app, options.projectRoot, options.controllerGlob, 'ts');
|
|
32
|
+
const { patch, controllersWithoutDocs, unparseableDocsFiles } = (0, patch_spec_1.computeSpecPatch)(controllers, 'ts', (absolutePath) => {
|
|
33
|
+
try {
|
|
34
|
+
return fs_1.default.readFileSync(absolutePath, 'utf8');
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}, projectsByControllerPath);
|
|
40
|
+
fs_1.default.mkdirSync(options.outDir, { recursive: true });
|
|
41
|
+
const outFile = path_1.default.join(options.outDir, exports.DOCFY_METADATA_FILENAME);
|
|
42
|
+
fs_1.default.writeFileSync(outFile, JSON.stringify(patch, null, 2), 'utf8');
|
|
43
|
+
const patchedOperationCount = Object.values(patch).reduce((count, methods) => count + Object.keys(methods).length, 0);
|
|
44
|
+
return { outFile, patchedOperationCount, controllersWithoutDocs, unparseableDocsFiles, scanErrors };
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=generate-metadata.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-metadata.js","sourceRoot":"","sources":["../../src/plugin/generate-metadata.ts"],"names":[],"mappings":";;;;;;AAwCA,sDAiCC;AAzED,4CAAoB;AACpB,gDAAwB;AACxB,8DAAkD;AAClD,kDAAqD;AAGrD,6GAA6G;AAChG,QAAA,uBAAuB,GAAG,qBAAqB,CAAC;AAuB7D;;;;;;;;;GASG;AACH,SAAgB,qBAAqB,CAAC,OAAgC;IACpE,MAAM,GAAG,GAAe;QACtB,IAAI,EAAE,KAAK;QACX,IAAI,EAAE,OAAO,CAAC,WAAW;QACzB,QAAQ,EAAE,OAAO,CAAC,gBAAgB;QAClC,cAAc,EAAE,OAAO,CAAC,cAAc,IAAI,oBAAoB;KAC/D,CAAC;IAEF,MAAM,EACJ,WAAW,EACX,MAAM,EAAE,UAAU,EAClB,wBAAwB,GACzB,GAAG,IAAA,0BAAO,EAAC,GAAG,EAAE,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;IACpE,MAAM,EAAE,KAAK,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,GAAG,IAAA,6BAAgB,EAC9E,WAAW,EACX,IAAI,EACJ,CAAC,YAAY,EAAE,EAAE;QACf,IAAI,CAAC;YACH,OAAO,YAAE,CAAC,YAAY,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;QAC/C,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC,EACD,wBAAwB,CACzB,CAAC;IAEF,YAAE,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAClD,MAAM,OAAO,GAAG,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,+BAAuB,CAAC,CAAC;IACnE,YAAE,CAAC,aAAa,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IAElE,MAAM,qBAAqB,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IAEtH,OAAO,EAAE,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,UAAU,EAAE,CAAC;AACtG,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type * as ts from 'typescript';
|
|
2
|
+
export { DOCFY_METADATA_FILENAME } from './generate-metadata';
|
|
3
|
+
export interface DocfyPluginOptions {
|
|
4
|
+
/** Root directory to scan for controllers. Defaults to the directory containing the resolved tsconfig. */
|
|
5
|
+
projectRoot?: string;
|
|
6
|
+
/** Controller glob override — same convention as the CLI's `--pattern` flag. */
|
|
7
|
+
controllerGlob?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* NestJS CLI "compiler plugin" entry point — register it in `nest-cli.json`:
|
|
11
|
+
* `"compilerOptions": { "plugins": ["nestjs-docfy"] }`. The Nest CLI's plugin
|
|
12
|
+
* loader calls exactly this `before(options, program)` shape for both the
|
|
13
|
+
* `tsc` and the `webpack` builder (see `@nestjs/cli`'s `PluginsLoader` and
|
|
14
|
+
* `ts-loader`'s `getCustomTransformers` wiring) — the same mechanism
|
|
15
|
+
* `@nestjs/swagger/plugin` already relies on to work under `webpack: true`,
|
|
16
|
+
* which is the one thing `DocfyModule`'s `require.cache`-based discovery
|
|
17
|
+
* structurally cannot do (see the README's "Not supported: webpack: true"
|
|
18
|
+
* section).
|
|
19
|
+
*
|
|
20
|
+
* Unlike `@nestjs/swagger/plugin`, this does not rewrite any AST node — it
|
|
21
|
+
* returns an identity transformer. Its only job is a build-time side
|
|
22
|
+
* effect: run the exact same static analysis `generate`/`check`/`patch-spec`
|
|
23
|
+
* already do, once per compilation, and write the resulting patch to a JSON
|
|
24
|
+
* file next to the compiled output. `applyDocfyMetadata()` (exported from
|
|
25
|
+
* the package root) reads that file at runtime and merges it into the
|
|
26
|
+
* document right after `SwaggerModule.createDocument()` — the same merge
|
|
27
|
+
* `patch-spec` does, just automatic on every build instead of a separate
|
|
28
|
+
* manual CLI invocation.
|
|
29
|
+
*/
|
|
30
|
+
export declare function before(options?: DocfyPluginOptions, program?: ts.Program): ts.TransformerFactory<ts.SourceFile>;
|
|
@@ -0,0 +1,62 @@
|
|
|
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.DOCFY_METADATA_FILENAME = void 0;
|
|
7
|
+
exports.before = before;
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const generate_metadata_1 = require("./generate-metadata");
|
|
10
|
+
var generate_metadata_2 = require("./generate-metadata");
|
|
11
|
+
Object.defineProperty(exports, "DOCFY_METADATA_FILENAME", { enumerable: true, get: function () { return generate_metadata_2.DOCFY_METADATA_FILENAME; } });
|
|
12
|
+
/**
|
|
13
|
+
* NestJS CLI "compiler plugin" entry point — register it in `nest-cli.json`:
|
|
14
|
+
* `"compilerOptions": { "plugins": ["nestjs-docfy"] }`. The Nest CLI's plugin
|
|
15
|
+
* loader calls exactly this `before(options, program)` shape for both the
|
|
16
|
+
* `tsc` and the `webpack` builder (see `@nestjs/cli`'s `PluginsLoader` and
|
|
17
|
+
* `ts-loader`'s `getCustomTransformers` wiring) — the same mechanism
|
|
18
|
+
* `@nestjs/swagger/plugin` already relies on to work under `webpack: true`,
|
|
19
|
+
* which is the one thing `DocfyModule`'s `require.cache`-based discovery
|
|
20
|
+
* structurally cannot do (see the README's "Not supported: webpack: true"
|
|
21
|
+
* section).
|
|
22
|
+
*
|
|
23
|
+
* Unlike `@nestjs/swagger/plugin`, this does not rewrite any AST node — it
|
|
24
|
+
* returns an identity transformer. Its only job is a build-time side
|
|
25
|
+
* effect: run the exact same static analysis `generate`/`check`/`patch-spec`
|
|
26
|
+
* already do, once per compilation, and write the resulting patch to a JSON
|
|
27
|
+
* file next to the compiled output. `applyDocfyMetadata()` (exported from
|
|
28
|
+
* the package root) reads that file at runtime and merges it into the
|
|
29
|
+
* document right after `SwaggerModule.createDocument()` — the same merge
|
|
30
|
+
* `patch-spec` does, just automatic on every build instead of a separate
|
|
31
|
+
* manual CLI invocation.
|
|
32
|
+
*/
|
|
33
|
+
function before(options = {}, program) {
|
|
34
|
+
if (!program) {
|
|
35
|
+
throw new Error('nestjs-docfy plugin: the "program" reference must be provided when using the CLI plugin. ' +
|
|
36
|
+
'This is usually caused by "isolatedModules" being set to true in your tsconfig.');
|
|
37
|
+
}
|
|
38
|
+
const compilerOptions = program.getCompilerOptions();
|
|
39
|
+
const configFilePath = compilerOptions.configFilePath;
|
|
40
|
+
if (!configFilePath) {
|
|
41
|
+
throw new Error('nestjs-docfy plugin: could not determine the tsconfig path from the TypeScript program. ' +
|
|
42
|
+
'This plugin must be registered via nest-cli.json\'s "compilerOptions.plugins".');
|
|
43
|
+
}
|
|
44
|
+
const projectRoot = options.projectRoot ?? path_1.default.dirname(configFilePath);
|
|
45
|
+
const outDir = compilerOptions.outDir ?? path_1.default.join(projectRoot, 'dist');
|
|
46
|
+
try {
|
|
47
|
+
(0, generate_metadata_1.generateDocfyMetadata)({
|
|
48
|
+
tsConfigFilePath: configFilePath,
|
|
49
|
+
projectRoot,
|
|
50
|
+
outDir,
|
|
51
|
+
controllerGlob: options.controllerGlob,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
// A build-time analysis failure shouldn't be silently swallowed, but it
|
|
56
|
+
// also shouldn't fail the app's entire build — same "loud warning, not a
|
|
57
|
+
// crash" philosophy DocfyModule already follows for a missing docs file.
|
|
58
|
+
console.warn(`[nestjs-docfy] Failed to generate build-time metadata: ${err instanceof Error ? err.message : String(err)}`);
|
|
59
|
+
}
|
|
60
|
+
return () => (sourceFile) => sourceFile;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/plugin/index.ts"],"names":[],"mappings":";;;;;;AAkCA,wBAqCC;AAtED,gDAAwB;AACxB,2DAA4D;AAE5D,yDAA8D;AAArD,4HAAA,uBAAuB,OAAA;AAShC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAgB,MAAM,CAAC,UAA8B,EAAE,EAAE,OAAoB;IAC3E,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,2FAA2F;YACzF,iFAAiF,CACpF,CAAC;IACJ,CAAC;IAED,MAAM,eAAe,GAAG,OAAO,CAAC,kBAAkB,EAAsD,CAAC;IACzG,MAAM,cAAc,GAAG,eAAe,CAAC,cAAc,CAAC;IACtD,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CACb,0FAA0F;YACxF,gFAAgF,CACnF,CAAC;IACJ,CAAC;IAED,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,cAAI,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;IACxE,MAAM,MAAM,GAAG,eAAe,CAAC,MAAM,IAAI,cAAI,CAAC,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IAExE,IAAI,CAAC;QACH,IAAA,yCAAqB,EAAC;YACpB,gBAAgB,EAAE,cAAc;YAChC,WAAW;YACX,MAAM;YACN,cAAc,EAAE,OAAO,CAAC,cAAc;SACvC,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,wEAAwE;QACxE,yEAAyE;QACzE,yEAAyE;QACzE,OAAO,CAAC,IAAI,CACV,0DAA0D,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAC7G,CAAC;IACJ,CAAC;IAED,OAAO,GAAG,EAAE,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC;AAC1C,CAAC"}
|
package/dist/registry.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const DocfyRegistry: {
|
|
2
|
-
add(target:
|
|
3
|
-
getAll(): ReadonlySet<
|
|
4
|
-
getCallSite(target:
|
|
2
|
+
add(target: NewableFunction, callSiteStack?: string): void;
|
|
3
|
+
getAll(): ReadonlySet<NewableFunction>;
|
|
4
|
+
getCallSite(target: NewableFunction): string | undefined;
|
|
5
5
|
_reset(): void;
|
|
6
6
|
};
|
package/dist/registry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":";;;AAAA,yDAAyD;AACzD,yEAAyE;AACzE,MAAM,QAAQ,GAAG,IAAI,GAAG,
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":";;;AAAA,yDAAyD;AACzD,yEAAyE;AACzE,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAmB,CAAC;AAE5C,4EAA4E;AAC5E,4EAA4E;AAC5E,wEAAwE;AACxE,2EAA2E;AAC3E,MAAM,SAAS,GAAG,IAAI,OAAO,EAA2B,CAAC;AAE5C,QAAA,aAAa,GAAG;IAC3B,GAAG,CAAC,MAAuB,EAAE,aAAsB;QACjD,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACrB,IAAI,aAAa;YAAE,SAAS,CAAC,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAC1D,CAAC;IAED,MAAM;QACJ,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,WAAW,CAAC,MAAuB;QACjC,OAAO,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC/B,CAAC;IAED,4DAA4D;IAC5D,MAAM;QACJ,QAAQ,CAAC,KAAK,EAAE,CAAC;IACnB,CAAC;CACF,CAAC"}
|
|
@@ -23,5 +23,5 @@ type CacheSnapshot = Record<string, {
|
|
|
23
23
|
* the bundle position from the stack trace back to the original file via
|
|
24
24
|
* that bundle's source map (emitted by default by the webpack build).
|
|
25
25
|
*/
|
|
26
|
-
export declare function resolveDocsPath(controllerClass:
|
|
26
|
+
export declare function resolveDocsPath(controllerClass: NewableFunction, readCache?: () => CacheSnapshot, callSiteStack?: string): string | null;
|
|
27
27
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-docs-path.js","sourceRoot":"","sources":["../src/resolve-docs-path.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,
|
|
1
|
+
{"version":3,"file":"resolve-docs-path.js","sourceRoot":"","sources":["../src/resolve-docs-path.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,0CAeC;AA1CD,2CAA6B;AAC7B,2EAAiF;AAIjF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,SAAgB,eAAe,CAC7B,eAAgC,EAChC,YAAiC,GAAG,EAAE,CAAC,OAAO,CAAC,KAAiC,EAChF,aAAsB;IAEtB,MAAM,cAAc,GAAG,eAAe,CAAC,eAAe,EAAE,SAAS,EAAE,CAAC,IAAI,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;gBACrB,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBAC1B,MAAM;YACR,CAAC;QACH,CAAC;IACH,CAAC;IAED,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACzC,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC;IAElD,4DAA4D;IAC5D,kEAAkE;IAClE,qEAAqE;IACrE,MAAM,UAAU,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;QACvC,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/C,OAAO,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;IACvE,CAAC,CAAC,CAAC;IAEH,OAAO,UAAU,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;AACrC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-source-from-stack.js","sourceRoot":"","sources":["../src/resolve-source-from-stack.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,sCAaC;
|
|
1
|
+
{"version":3,"file":"resolve-source-from-stack.js","sourceRoot":"","sources":["../src/resolve-source-from-stack.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,sCAaC;AAoCD,kDAmCC;AAlHD,uCAAyB;AACzB,2CAA6B;AAC7B,2CAA6D;AAQ7D,MAAM,cAAc,GAAG,kCAAkC,CAAC;AAE1D;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAgB,aAAa,CAAC,KAAyB;IACrD,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAC;IACxB,MAAM,KAAK,GAAG,KAAK,CAAC,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C;QAED,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACtC,MAAM,UAAU,GAAG,GAAG,CAAC,UAAU,IAAI,EAAE,CAAC;QACxC,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC3D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,GAAG,CAAC,IAAI,CAAC;IAClB,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,SAAS,oBAAoB,CAAC,MAAc;IAC1C,MAAM,KAAK,GAAG,2BAA2B,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACvD,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACjC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-docs.decorator.js","sourceRoot":"","sources":["../src/with-docs.decorator.ts"],"names":[],"mappings":";;;AAuBA,4BAYC;AAnCD,2CAA6C;AAC7C,yCAA2C;AAE3C;;;;;;;;GAQG;AACU,QAAA,YAAY,GAAG,iBAAiB,CAAC;AAE9C;;;;;;;;GAQG;AACH,SAAgB,QAAQ;IACtB,yEAAyE;IACzE,0EAA0E;IAC1E,0EAA0E;IAC1E,uEAAuE;IACvE,0EAA0E;IAC1E,MAAM,aAAa,GAAG,IAAI,KAAK,EAAE,CAAC,KAAK,CAAC;IAExC,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"with-docs.decorator.js","sourceRoot":"","sources":["../src/with-docs.decorator.ts"],"names":[],"mappings":";;;AAuBA,4BAYC;AAnCD,2CAA6C;AAC7C,yCAA2C;AAE3C;;;;;;;;GAQG;AACU,QAAA,YAAY,GAAG,iBAAiB,CAAC;AAE9C;;;;;;;;GAQG;AACH,SAAgB,QAAQ;IACtB,yEAAyE;IACzE,0EAA0E;IAC1E,0EAA0E;IAC1E,uEAAuE;IACvE,0EAA0E;IAC1E,MAAM,aAAa,GAAG,IAAI,KAAK,EAAE,CAAC,KAAK,CAAC;IAExC,OAAO,CAAC,MAAuB,EAAE,EAAE;QACjC,IAAA,oBAAW,EAAC,oBAAY,EAAE,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC;QACxC,wBAAa,CAAC,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAC3C,CAAC,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nestjs-docfy",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
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",
|
|
@@ -14,6 +14,11 @@
|
|
|
14
14
|
"types": "./dist/testing.d.ts",
|
|
15
15
|
"require": "./dist/testing.js",
|
|
16
16
|
"default": "./dist/testing.js"
|
|
17
|
+
},
|
|
18
|
+
"./plugin": {
|
|
19
|
+
"types": "./dist/plugin/index.d.ts",
|
|
20
|
+
"require": "./dist/plugin/index.js",
|
|
21
|
+
"default": "./dist/plugin/index.js"
|
|
17
22
|
}
|
|
18
23
|
},
|
|
19
24
|
"bin": {
|
|
@@ -32,7 +37,12 @@
|
|
|
32
37
|
"test": "jest",
|
|
33
38
|
"test:watch": "jest --watch",
|
|
34
39
|
"test:cov": "jest --coverage",
|
|
35
|
-
"
|
|
40
|
+
"lint": "eslint .",
|
|
41
|
+
"lint:fix": "eslint . --fix",
|
|
42
|
+
"format": "prettier --write .",
|
|
43
|
+
"format:check": "prettier --check .",
|
|
44
|
+
"prepublishOnly": "npm run build",
|
|
45
|
+
"release": "semantic-release"
|
|
36
46
|
},
|
|
37
47
|
"keywords": [
|
|
38
48
|
"nestjs",
|
|
@@ -79,25 +89,36 @@
|
|
|
79
89
|
}
|
|
80
90
|
},
|
|
81
91
|
"devDependencies": {
|
|
92
|
+
"@eslint/js": "^10.0.1",
|
|
82
93
|
"@fastify/static": "^9.3.0",
|
|
83
94
|
"@nestjs/common": "^11.0.0",
|
|
84
95
|
"@nestjs/core": "^11.0.0",
|
|
85
96
|
"@nestjs/platform-fastify": "^11.1.28",
|
|
86
97
|
"@nestjs/swagger": "^11.0.0",
|
|
98
|
+
"@semantic-release/changelog": "^7.0.0",
|
|
99
|
+
"@semantic-release/git": "^11.0.1",
|
|
87
100
|
"@types/express": "^5.0.0",
|
|
88
101
|
"@types/jest": "^29.5.14",
|
|
89
102
|
"@types/node": "^22.0.0",
|
|
103
|
+
"eslint": "^10.8.0",
|
|
104
|
+
"eslint-config-prettier": "^10.1.8",
|
|
105
|
+
"eslint-plugin-prettier": "^5.5.6",
|
|
90
106
|
"fastify": "^5.10.0",
|
|
107
|
+
"globals": "^17.7.0",
|
|
91
108
|
"jest": "^29.7.0",
|
|
109
|
+
"prettier": "^3.9.6",
|
|
92
110
|
"reflect-metadata": "^0.2.2",
|
|
111
|
+
"semantic-release": "^25.0.8",
|
|
93
112
|
"ts-jest": "^29.2.5",
|
|
94
113
|
"ts-node": "^10.9.2",
|
|
95
|
-
"typescript": "^5.7.3"
|
|
114
|
+
"typescript": "^5.7.3",
|
|
115
|
+
"typescript-eslint": "^8.65.0"
|
|
96
116
|
},
|
|
97
117
|
"dependencies": {
|
|
98
118
|
"commander": "^15.0.0",
|
|
99
|
-
"docfy-ui": "^0.0
|
|
119
|
+
"docfy-ui": "^0.1.0",
|
|
100
120
|
"express": "^5.0.0",
|
|
121
|
+
"openapi-typescript": "^7.13.0",
|
|
101
122
|
"picocolors": "^1.1.1",
|
|
102
123
|
"source-map": "^0.6.1",
|
|
103
124
|
"ts-morph": "^28.0.0"
|
package/dist/require-ts.d.ts
DELETED
|
@@ -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;
|
package/dist/require-ts.js
DELETED
|
@@ -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
|
package/dist/require-ts.js.map
DELETED
|
@@ -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,CAAC,KAAK,CAAC,+BAA+B,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,SAAS,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC;IAC3G,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5B,uEAAuE;QACvE,uEAAuE;QACvE,sEAAsE;QACtE,6CAA6C;QAC7C,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,uBAAuB,OAAO,GAAG,CAAC,EAAE;YAChE,IAAI,EAAE,kBAAkB;SACzB,CAAC,CAAC;IACL,CAAC;IAED,mBAAmB,EAAE,CAAC;IACtB,iEAAiE;IACjE,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC;AAC1B,CAAC;AAED,IAAI,UAAU,GAAG,KAAK,CAAC;AAEvB,SAAS,mBAAmB;IAC1B,IAAI,UAAU,IAAI,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC;QAAE,OAAO;IACpD,MAAM,OAAO,GAAG,WAAW,EAAE,CAAC;IAC9B,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,iFAAiF;YAC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