Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PluginMetadataGenerator runs type checking #3275

Open
2 of 4 tasks
its-dibo opened this issue Jan 27, 2025 · 1 comment
Open
2 of 4 tasks

PluginMetadataGenerator runs type checking #3275

its-dibo opened this issue Jan 27, 2025 · 1 comment

Comments

@its-dibo
Copy link

its-dibo commented Jan 27, 2025

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

for some reason the generated file contains const t = {}; which makes PluginMetadataGenerator fails

src/generate-metadata.ts
import { PluginMetadataGenerator } from '@nestjs/cli/lib/compiler/plugins/plugin-metadata-generator';
import { ReadonlyVisitor } from '@nestjs/swagger/dist/plugin';

const generator = new PluginMetadataGenerator();

generator.generate({
  visitors: [
    new ReadonlyVisitor({
      introspectComments: true,
      classValidatorShim: true,
      pathToSource: import.meta.dirname,
    }),
  ],
  outputDir: import.meta.dirname,
  filename: 'nest-swagger-metadata.ts',
  watch: false,
  tsconfigPath: './tsconfig.json',
  printDiagnostics: false,
});

run the generator

node -r tsconfig-paths/register -r dotenv/config --loader ts-node/esm --experimental-specifier-resolution=node --experimental-import-meta-resolve --no-warnings src/generate-metadata.ts

the generated metadata file:

nest-swagger-metadata.ts
/* eslint-disable */
export default async () => {
  const t = {};
  return {
    '@nestjs/swagger': {
      models: [],
      controllers: [
        [
          import('./app.controller'),
          { AppController: { getHello: { type: String } } },
        ],
        [
          import('./api/osrm/osrm.controller'),
          {
            OsrmController: {
              getShortestTrip: {
                summary:
                  'Calculates the shortest trip route between multiple points.\nThis endpoint solves the Traveling Salesman Problem (TSP) to find an optimal route.',
                description:
                  'This method optimizes the route order to minimize total travel time/distance. It performs the following:\n1. Takes a set of points that need to be visited\n2. Determines the optimal order to visit these points\n3. Returns a route that visits all points in the optimized order\n\nThe route may or may not return to the starting point, based on the `roundtrip` option.',
                type: Object,
              },
              getFastestRoute: {
                summary:
                  'Calculates the fastest route between points in the exact order provided.\nUnlike getShortestTrip, this method preserves the input point order.',
                description:
                  'This method finds the fastest route that visits all points in the specified order:\n1. Takes an ordered array of waypoints\n2. Calculates the fastest route visiting these points in sequence\n3. Returns detailed route information including turn-by-turn directions',
                type: Object,
              },
              getNearestPoint: {
                summary:
                  'Finds the nearest road segment to a given coordinate.\nUseful for snapping a point to the road network.',
                description:
                  'This method helps align GPS coordinates with the actual road network:\n1. Takes a coordinate point\n2. Finds the nearest point on the road network\n3. Returns the snapped location and additional road segment information',
                type: Object,
              },
              snap: {
                summary:
                  'Snap a list of coordinates to the nearest points on the street network.',
                type: Object,
              },
              getTable: {
                summary:
                  'Computes the duration and/or distance of the fastest route between all pairs of supplied coordinates.\nThis endpoint returns a matrix of durations or distances or both between the coordinate pairs.',
                description:
                  'This method calculates the fastest route durations and distances between all pairs of points:\n1. Takes an array of points\n2. Computes the duration and/or distance between each pair of points\n3. Returns a matrix of results',
                type: Object,
              },
              getVectorTiles: {
                summary:
                  'Retrieves vector tiles based on the provided options.',
                type: Object,
              },
            },
          },
        ],
      ],
    },
  };
};

Output error
> [email protected] _node /workspaces/mashrouk/apps/maps
> node -r tsconfig-paths/register -r dotenv/config --loader ts-node/esm --experimental-specifier-resolution=node --experimental-import-meta-resolve --no-warnings "src/generate-metadata.ts"

⠋  TSC  Initializing type checker...
src/nest-swagger-metadata.ts:3:9 - error TS6133: 't' is declared but its value is never read.

3   const t = {};
          ~

 ELIFECYCLE  Command failed with exit code 1.
 ELIFECYCLE  Command failed with exit code 1.

 *  The terminal process "/bin/bash '-c', 'pnpm run prebuild'" terminated with exit code: 1. 
 *  Terminal will be reused by tasks, press any key to close it. 

I think the issue is caused by this line
https://github.com/nestjs/nest-cli/blob/e1f487ec02a80367d89b9f97b4b3feb6302241c5/lib/compiler/plugins/plugin-metadata-generator.ts#L118

Minimum reproduction code

.

Steps to reproduce

No response

Expected behavior

the metadata file is generated without errors, or the type checking is disabled for the auto generated files

Package version

11.0.3

NestJS version

11.0.5

Node.js version

v22.12.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

@kamilmysliwiec
Copy link
Member

Please provide a minimum reproduction repository (Git repository/StackBlitz/CodeSandbox project).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants