@nestjs/cli 10.0.1 → 10.0.2

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.
@@ -21,7 +21,7 @@ jobs:
21
21
  build:
22
22
  working_directory: ~/nest
23
23
  docker:
24
- - image: cimg/node:20.3
24
+ - image: cimg/node:20.2
25
25
  steps:
26
26
  - checkout
27
27
  - run:
@@ -43,7 +43,7 @@ jobs:
43
43
  unit_tests:
44
44
  working_directory: ~/nest
45
45
  docker:
46
- - image: cimg/node:20.3
46
+ - image: cimg/node:20.2
47
47
  steps:
48
48
  - checkout
49
49
  - *restore-cache
@@ -4,6 +4,7 @@ export type DeepPluginMeta = ts.ObjectLiteralExpression | {
4
4
  };
5
5
  export interface ReadonlyVisitor {
6
6
  key: string;
7
+ typeImports: Record<string, string>;
7
8
  visit(program: ts.Program, sf: ts.SourceFile): void;
8
9
  collect(): Record<string, Array<[ts.CallExpression, DeepPluginMeta]>>;
9
10
  }
@@ -65,11 +65,16 @@ class PluginMetadataGenerator {
65
65
  visitors.forEach((visitor) => visitor.visit(programRef, sourceFile));
66
66
  }
67
67
  }
68
+ let typeImports = {};
68
69
  const collectedMetadata = {};
69
70
  visitors.forEach((visitor) => {
70
71
  collectedMetadata[visitor.key] = visitor.collect();
72
+ typeImports = {
73
+ ...typeImports,
74
+ ...visitor.typeImports,
75
+ };
71
76
  });
72
- this.pluginMetadataPrinter.print(collectedMetadata, {
77
+ this.pluginMetadataPrinter.print(collectedMetadata, typeImports, {
73
78
  outputDir,
74
79
  filename,
75
80
  });
@@ -4,10 +4,14 @@ export interface PluginMetadataPrintOptions {
4
4
  outputDir: string;
5
5
  filename?: string;
6
6
  }
7
+ type ComposedPluginMeta = Record<string, Record<string, Array<[ts.CallExpression, DeepPluginMeta]>>>;
7
8
  /**
8
9
  * Prints the metadata to a file.
9
10
  */
10
11
  export declare class PluginMetadataPrinter {
11
- print(metadata: Record<string, Record<string, Array<[ts.CallExpression, DeepPluginMeta]>>>, options: PluginMetadataPrintOptions): void;
12
+ print(metadata: ComposedPluginMeta, typeImports: Record<string, string>, options: PluginMetadataPrintOptions): void;
12
13
  private recursivelyCreatePropertyAssignment;
14
+ private createTypeImportVariableStatement;
15
+ private createPropertyAssignment;
13
16
  }
17
+ export {};
@@ -5,13 +5,17 @@ const fs_1 = require("fs");
5
5
  const path_1 = require("path");
6
6
  const ts = require("typescript");
7
7
  const SERIALIZED_METADATA_FILENAME = 'metadata.ts';
8
+ const TYPE_IMPORT_VARIABLE_NAME = 't';
8
9
  /**
9
10
  * Prints the metadata to a file.
10
11
  */
11
12
  class PluginMetadataPrinter {
12
- print(metadata, options) {
13
+ print(metadata, typeImports, options) {
13
14
  const objectLiteralExpr = ts.factory.createObjectLiteralExpression(Object.keys(metadata).map((key) => this.recursivelyCreatePropertyAssignment(key, metadata[key])));
14
- const exportAssignment = ts.factory.createExportAssignment(undefined, undefined, objectLiteralExpr);
15
+ const exportAssignment = ts.factory.createExportAssignment(undefined, undefined, ts.factory.createArrowFunction([ts.factory.createToken(ts.SyntaxKind.AsyncKeyword)], undefined, [], undefined, ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), ts.factory.createBlock([
16
+ this.createTypeImportVariableStatement(typeImports),
17
+ ts.factory.createReturnStatement(objectLiteralExpr),
18
+ ], true)));
15
19
  const printer = ts.createPrinter({
16
20
  newLine: ts.NewLineKind.LineFeed,
17
21
  });
@@ -33,5 +37,16 @@ class PluginMetadataPrinter {
33
37
  ? meta
34
38
  : ts.factory.createObjectLiteralExpression(Object.keys(meta).map((key) => this.recursivelyCreatePropertyAssignment(key, meta[key]))));
35
39
  }
40
+ createTypeImportVariableStatement(typeImports) {
41
+ return ts.factory.createVariableStatement(undefined, ts.factory.createVariableDeclarationList([
42
+ ts.factory.createVariableDeclaration(ts.factory.createIdentifier(TYPE_IMPORT_VARIABLE_NAME), undefined, undefined, ts.factory.createObjectLiteralExpression(Object.keys(typeImports).map((ti) => this.createPropertyAssignment(ti, typeImports[ti])), true)),
43
+ ], ts.NodeFlags.Const |
44
+ ts.NodeFlags.AwaitContext |
45
+ ts.NodeFlags.ContextFlags |
46
+ ts.NodeFlags.TypeExcludesFlags));
47
+ }
48
+ createPropertyAssignment(identifier, target) {
49
+ return ts.factory.createPropertyAssignment(ts.factory.createComputedPropertyName(ts.factory.createStringLiteral(identifier)), ts.factory.createIdentifier(target));
50
+ }
36
51
  }
37
52
  exports.PluginMetadataPrinter = PluginMetadataPrinter;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs/cli",
3
- "version": "10.0.1",
3
+ "version": "10.0.2",
4
4
  "description": "Nest - modern, fast, powerful node.js web framework (@cli)",
5
5
  "publishConfig": {
6
6
  "access": "public"