-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(api): Explicitly generate metadata for
nest build
script (#6329)
- Loading branch information
Showing
5 changed files
with
39 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* This file is responsible for generating Nest.js metadata for the API. | ||
* Metadata generation is required when using SWC with Nest.js due to SWC | ||
* not natively supporting Typescript, which is required to use the `reflect-metadata` | ||
* API and in turn, resolve types for the OpenAPI specification. | ||
* | ||
* @see https://docs.nestjs.com/recipes/swc#monorepo-and-cli-plugins | ||
*/ | ||
import fs from 'node:fs'; | ||
import path from 'node:path'; | ||
import { PluginMetadataGenerator } from '@nestjs/cli/lib/compiler/plugins'; | ||
import { ReadonlyVisitor } from '@nestjs/swagger/dist/plugin'; | ||
|
||
const tsconfigPath = 'tsconfig.build.json'; | ||
const srcPath = path.join(__dirname, '..', 'src'); | ||
const metadataPath = path.join(srcPath, 'metadata.ts'); | ||
|
||
/* | ||
* We create an empty metadata file to ensure that files importing `metadata.ts` | ||
* will compile successfully before the metadata generation occurs. | ||
*/ | ||
const defaultContent = `export default async () => { return {}; };`; | ||
|
||
fs.writeFileSync(metadataPath, defaultContent, 'utf8'); | ||
console.log('metadata.ts file has been generated with default content.'); | ||
|
||
const generator = new PluginMetadataGenerator(); | ||
generator.generate({ | ||
visitors: [new ReadonlyVisitor({ introspectComments: true, pathToSource: srcPath })], | ||
outputDir: srcPath, | ||
tsconfigPath, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.