@nestjs/cli 9.1.9 → 9.2.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.
@@ -21,7 +21,7 @@ jobs:
21
21
  build:
22
22
  working_directory: ~/nest
23
23
  docker:
24
- - image: cimg/node:19.3
24
+ - image: cimg/node:19.5
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:19.3
46
+ - image: cimg/node:19.5
47
47
  steps:
48
48
  - checkout
49
49
  - *restore-cache
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2017-2022
3
+ Copyright (c) 2017-2023
4
4
  Kamil Mysliwiec <https://kamilmysliwiec.com>
5
5
  Thomas Ricart <thomasr2309@gmail.com>
6
6
 
package/bin/nest.js CHANGED
@@ -1,10 +1,19 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
+ return new (P || (P = Promise))(function (resolve, reject) {
6
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
10
+ });
11
+ };
3
12
  Object.defineProperty(exports, "__esModule", { value: true });
4
13
  const commander = require("commander");
5
14
  const commands_1 = require("../commands");
6
15
  const local_binaries_1 = require("../lib/utils/local-binaries");
7
- const bootstrap = () => {
16
+ const bootstrap = () => __awaiter(void 0, void 0, void 0, function* () {
8
17
  const program = commander;
9
18
  program
10
19
  .version(require('../package.json').version, '-v, --version', 'Output the current version.')
@@ -12,14 +21,14 @@ const bootstrap = () => {
12
21
  .helpOption('-h, --help', 'Output usage information.');
13
22
  if ((0, local_binaries_1.localBinExists)()) {
14
23
  const localCommandLoader = (0, local_binaries_1.loadLocalBinCommandLoader)();
15
- localCommandLoader.load(program);
24
+ yield localCommandLoader.load(program);
16
25
  }
17
26
  else {
18
- commands_1.CommandLoader.load(program);
27
+ yield commands_1.CommandLoader.load(program);
19
28
  }
20
- commander.parse(process.argv);
29
+ commander.parseAsync(process.argv);
21
30
  if (!process.argv.slice(2).length) {
22
31
  program.outputHelp();
23
32
  }
24
- };
33
+ });
25
34
  bootstrap();
@@ -1,5 +1,5 @@
1
1
  import { CommanderStatic } from 'commander';
2
2
  export declare class CommandLoader {
3
- static load(program: CommanderStatic): void;
3
+ static load(program: CommanderStatic): Promise<void>;
4
4
  private static handleInvalidCommand;
5
5
  }
@@ -1,4 +1,13 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.CommandLoader = void 0;
4
13
  const chalk = require("chalk");
@@ -12,13 +21,15 @@ const new_command_1 = require("./new.command");
12
21
  const start_command_1 = require("./start.command");
13
22
  class CommandLoader {
14
23
  static load(program) {
15
- new new_command_1.NewCommand(new actions_1.NewAction()).load(program);
16
- new build_command_1.BuildCommand(new actions_1.BuildAction()).load(program);
17
- new start_command_1.StartCommand(new actions_1.StartAction()).load(program);
18
- new info_command_1.InfoCommand(new actions_1.InfoAction()).load(program);
19
- new add_command_1.AddCommand(new actions_1.AddAction()).load(program);
20
- new generate_command_1.GenerateCommand(new actions_1.GenerateAction()).load(program);
21
- this.handleInvalidCommand(program);
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ new new_command_1.NewCommand(new actions_1.NewAction()).load(program);
26
+ new build_command_1.BuildCommand(new actions_1.BuildAction()).load(program);
27
+ new start_command_1.StartCommand(new actions_1.StartAction()).load(program);
28
+ new info_command_1.InfoCommand(new actions_1.InfoAction()).load(program);
29
+ new add_command_1.AddCommand(new actions_1.AddAction()).load(program);
30
+ yield new generate_command_1.GenerateCommand(new actions_1.GenerateAction()).load(program);
31
+ this.handleInvalidCommand(program);
32
+ });
22
33
  }
23
34
  static handleInvalidCommand(program) {
24
35
  program.on('command:*', () => {
@@ -1,7 +1,9 @@
1
1
  import { CommanderStatic } from 'commander';
2
2
  import { AbstractCommand } from './abstract.command';
3
3
  export declare class GenerateCommand extends AbstractCommand {
4
- load(program: CommanderStatic): void;
4
+ load(program: CommanderStatic): Promise<void>;
5
5
  private buildDescription;
6
6
  private buildSchematicsListAsTable;
7
+ private getCollection;
8
+ private getSchematics;
7
9
  }
@@ -12,68 +12,74 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.GenerateCommand = void 0;
13
13
  const chalk = require("chalk");
14
14
  const Table = require("cli-table3");
15
- const nest_collection_1 = require("../lib/schematics/nest.collection");
15
+ const schematics_1 = require("../lib/schematics");
16
+ const load_configuration_1 = require("../lib/utils/load-configuration");
16
17
  const abstract_command_1 = require("./abstract.command");
17
18
  class GenerateCommand extends abstract_command_1.AbstractCommand {
18
19
  load(program) {
19
- program
20
- .command('generate <schematic> [name] [path]')
21
- .alias('g')
22
- .description(this.buildDescription())
23
- .option('-d, --dry-run', 'Report actions that would be taken without writing out results.')
24
- .option('-p, --project [project]', 'Project in which to generate files.')
25
- .option('--flat', 'Enforce flat structure of generated element.', () => true)
26
- .option('--no-flat', 'Enforce that directories are generated.', () => false)
27
- .option('--spec', 'Enforce spec files generation.', () => {
28
- return { value: true, passedAsInput: true };
29
- }, true)
30
- .option('--skip-import', 'Skip importing', () => true, false)
31
- .option('--no-spec', 'Disable spec files generation.', () => {
32
- return { value: false, passedAsInput: true };
33
- })
34
- .option('-c, --collection [collectionName]', 'Schematics collection to use.')
35
- .action((schematic, name, path, command) => __awaiter(this, void 0, void 0, function* () {
36
- const options = [];
37
- options.push({ name: 'dry-run', value: !!command.dryRun });
38
- if (command.flat !== undefined) {
39
- options.push({ name: 'flat', value: command.flat });
40
- }
41
- options.push({
42
- name: 'spec',
43
- value: typeof command.spec === 'boolean'
44
- ? command.spec
45
- : command.spec.value,
46
- options: {
47
- passedAsInput: typeof command.spec === 'boolean'
48
- ? false
49
- : command.spec.passedAsInput,
50
- },
51
- });
52
- options.push({
53
- name: 'collection',
54
- value: command.collection,
55
- });
56
- options.push({
57
- name: 'project',
58
- value: command.project,
59
- });
60
- options.push({
61
- name: 'skipImport',
62
- value: command.skipImport,
63
- });
64
- const inputs = [];
65
- inputs.push({ name: 'schematic', value: schematic });
66
- inputs.push({ name: 'name', value: name });
67
- inputs.push({ name: 'path', value: path });
68
- yield this.action.handle(inputs, options);
69
- }));
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ program
22
+ .command('generate <schematic> [name] [path]')
23
+ .alias('g')
24
+ .description(yield this.buildDescription())
25
+ .option('-d, --dry-run', 'Report actions that would be taken without writing out results.')
26
+ .option('-p, --project [project]', 'Project in which to generate files.')
27
+ .option('--flat', 'Enforce flat structure of generated element.', () => true)
28
+ .option('--no-flat', 'Enforce that directories are generated.', () => false)
29
+ .option('--spec', 'Enforce spec files generation.', () => {
30
+ return { value: true, passedAsInput: true };
31
+ }, true)
32
+ .option('--skip-import', 'Skip importing', () => true, false)
33
+ .option('--no-spec', 'Disable spec files generation.', () => {
34
+ return { value: false, passedAsInput: true };
35
+ })
36
+ .option('-c, --collection [collectionName]', 'Schematics collection to use.')
37
+ .action((schematic, name, path, command) => __awaiter(this, void 0, void 0, function* () {
38
+ const options = [];
39
+ options.push({ name: 'dry-run', value: !!command.dryRun });
40
+ if (command.flat !== undefined) {
41
+ options.push({ name: 'flat', value: command.flat });
42
+ }
43
+ options.push({
44
+ name: 'spec',
45
+ value: typeof command.spec === 'boolean'
46
+ ? command.spec
47
+ : command.spec.value,
48
+ options: {
49
+ passedAsInput: typeof command.spec === 'boolean'
50
+ ? false
51
+ : command.spec.passedAsInput,
52
+ },
53
+ });
54
+ options.push({
55
+ name: 'collection',
56
+ value: command.collection,
57
+ });
58
+ options.push({
59
+ name: 'project',
60
+ value: command.project,
61
+ });
62
+ options.push({
63
+ name: 'skipImport',
64
+ value: command.skipImport,
65
+ });
66
+ const inputs = [];
67
+ inputs.push({ name: 'schematic', value: schematic });
68
+ inputs.push({ name: 'name', value: name });
69
+ inputs.push({ name: 'path', value: path });
70
+ yield this.action.handle(inputs, options);
71
+ }));
72
+ });
70
73
  }
71
74
  buildDescription() {
72
- return ('Generate a Nest element.\n' +
73
- ` Schematics available on ${chalk.bold('@nestjs/schematics')} collection:\n` +
74
- this.buildSchematicsListAsTable());
75
+ return __awaiter(this, void 0, void 0, function* () {
76
+ const collection = yield this.getCollection();
77
+ return ('Generate a Nest element.\n' +
78
+ ` Schematics available on ${chalk.bold(collection)} collection:\n` +
79
+ this.buildSchematicsListAsTable(yield this.getSchematics(collection)));
80
+ });
75
81
  }
76
- buildSchematicsListAsTable() {
82
+ buildSchematicsListAsTable(schematics) {
77
83
  const leftMargin = ' ';
78
84
  const tableConfig = {
79
85
  head: ['name', 'alias', 'description'],
@@ -88,7 +94,7 @@ class GenerateCommand extends abstract_command_1.AbstractCommand {
88
94
  },
89
95
  };
90
96
  const table = new Table(tableConfig);
91
- for (const schematic of nest_collection_1.NestCollection.getSchematics()) {
97
+ for (const schematic of schematics) {
92
98
  table.push([
93
99
  chalk.green(schematic.name),
94
100
  chalk.cyan(schematic.alias),
@@ -97,5 +103,17 @@ class GenerateCommand extends abstract_command_1.AbstractCommand {
97
103
  }
98
104
  return table.toString();
99
105
  }
106
+ getCollection() {
107
+ return __awaiter(this, void 0, void 0, function* () {
108
+ const configuration = yield (0, load_configuration_1.loadConfiguration)();
109
+ return configuration.collection;
110
+ });
111
+ }
112
+ getSchematics(collection) {
113
+ return __awaiter(this, void 0, void 0, function* () {
114
+ const abstractCollection = schematics_1.CollectionFactory.create(collection);
115
+ return abstractCollection.getSchematics();
116
+ });
117
+ }
100
118
  }
101
119
  exports.GenerateCommand = GenerateCommand;
@@ -1,6 +1,6 @@
1
1
  import * as ts from 'typescript';
2
- declare type Transformer = ts.TransformerFactory<any> | ts.CustomTransformerFactory;
3
- declare type PluginEntry = string | PluginAndOptions;
2
+ type Transformer = ts.TransformerFactory<any> | ts.CustomTransformerFactory;
3
+ type PluginEntry = string | PluginAndOptions;
4
4
  interface PluginAndOptions {
5
5
  name: 'string';
6
6
  options: Record<string, any>;
@@ -16,11 +16,11 @@ class WatchCompiler {
16
16
  if (!configPath) {
17
17
  throw new Error(errors_1.CLI_ERRORS.MISSING_TYPESCRIPT(configFilename));
18
18
  }
19
- const { projectReferences } = this.tsConfigProvider.getByConfigFilename(configFilename);
19
+ const { options, projectReferences } = this.tsConfigProvider.getByConfigFilename(configFilename);
20
20
  const createProgram = tsBin.createEmitAndSemanticDiagnosticsBuilderProgram;
21
21
  const origDiagnosticReporter = tsBin.createDiagnosticReporter(tsBin.sys, true);
22
22
  const origWatchStatusReporter = tsBin.createWatchStatusReporter(tsBin.sys, true);
23
- const host = tsBin.createWatchCompilerHost(configPath, tsCompilerOptions, tsBin.sys, createProgram, this.createDiagnosticReporter(origDiagnosticReporter), this.createWatchStatusChanged(origWatchStatusReporter, onSuccess));
23
+ const host = tsBin.createWatchCompilerHost(configPath, Object.assign(Object.assign({}, options), tsCompilerOptions), tsBin.sys, createProgram, this.createDiagnosticReporter(origDiagnosticReporter), this.createWatchStatusChanged(origWatchStatusReporter, onSuccess));
24
24
  const pluginsConfig = (0, get_value_or_default_1.getValueOrDefault)(configuration, 'compilerOptions.plugins', appName);
25
25
  const plugins = this.pluginsLoader.load(pluginsConfig);
26
26
  const origCreateProgram = host.createProgram;
@@ -2,8 +2,8 @@ import { Configuration } from '../configuration';
2
2
  import { AssetsManager } from './assets-manager';
3
3
  import { PluginsLoader } from './plugins-loader';
4
4
  import webpack = require('webpack');
5
- declare type WebpackConfigFactory = (config: webpack.Configuration, webpackRef: typeof webpack) => webpack.Configuration;
6
- declare type WebpackConfigFactoryOrConfig = WebpackConfigFactory | webpack.Configuration;
5
+ type WebpackConfigFactory = (config: webpack.Configuration, webpackRef: typeof webpack) => webpack.Configuration;
6
+ type WebpackConfigFactoryOrConfig = WebpackConfigFactory | webpack.Configuration;
7
7
  export declare class WebpackCompiler {
8
8
  private readonly pluginsLoader;
9
9
  constructor(pluginsLoader: PluginsLoader);
@@ -19,7 +19,7 @@ class WorkspaceUtils {
19
19
  if (!isDeleteEnabled) {
20
20
  return;
21
21
  }
22
- yield new Promise((resolve, reject) => rimraf(dirPath, (err) => (err ? reject(err) : resolve())));
22
+ yield rimraf(dirPath);
23
23
  });
24
24
  }
25
25
  }
@@ -1,4 +1,4 @@
1
- export declare type Asset = 'string' | AssetEntry;
1
+ export type Asset = 'string' | AssetEntry;
2
2
  export interface AssetEntry {
3
3
  glob: string;
4
4
  include?: string;
@@ -1,10 +1,12 @@
1
1
  import { AbstractRunner } from '../runners';
2
+ import { Schematic } from './nest.collection';
2
3
  import { SchematicOption } from './schematic.option';
3
- export declare class AbstractCollection {
4
+ export declare abstract class AbstractCollection {
4
5
  protected collection: string;
5
6
  protected runner: AbstractRunner;
6
7
  constructor(collection: string, runner: AbstractRunner);
7
8
  execute(name: string, options: SchematicOption[], extraFlags?: string): Promise<void>;
9
+ abstract getSchematics(): Schematic[];
8
10
  private buildCommandLine;
9
11
  private buildOptions;
10
12
  }
@@ -7,11 +7,12 @@ const custom_collection_1 = require("./custom.collection");
7
7
  const nest_collection_1 = require("./nest.collection");
8
8
  class CollectionFactory {
9
9
  static create(collection) {
10
- switch (collection) {
11
- case collection_1.Collection.NESTJS:
12
- return new nest_collection_1.NestCollection(runners_1.RunnerFactory.create(runners_1.Runner.SCHEMATIC));
13
- default:
14
- return new custom_collection_1.CustomCollection(collection, runners_1.RunnerFactory.create(runners_1.Runner.SCHEMATIC));
10
+ const schematicRunner = runners_1.RunnerFactory.create(runners_1.Runner.SCHEMATIC);
11
+ if (collection === collection_1.Collection.NESTJS) {
12
+ return new nest_collection_1.NestCollection(schematicRunner);
13
+ }
14
+ else {
15
+ return new custom_collection_1.CustomCollection(collection, schematicRunner);
15
16
  }
16
17
  }
17
18
  }
@@ -1,3 +1,10 @@
1
1
  import { AbstractCollection } from './abstract.collection';
2
+ import { Schematic } from './nest.collection';
3
+ export interface CollectionSchematic {
4
+ schema: string;
5
+ description: string;
6
+ aliases: string[];
7
+ }
2
8
  export declare class CustomCollection extends AbstractCollection {
9
+ getSchematics(): Schematic[];
3
10
  }
@@ -1,7 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CustomCollection = void 0;
4
+ const fs_1 = require("fs");
5
+ const path_1 = require("path");
4
6
  const abstract_collection_1 = require("./abstract.collection");
5
7
  class CustomCollection extends abstract_collection_1.AbstractCollection {
8
+ getSchematics() {
9
+ const collectionPackagePath = (0, path_1.dirname)(require.resolve(this.collection));
10
+ const collectionPath = (0, path_1.join)(collectionPackagePath, 'collection.json');
11
+ const collection = JSON.parse((0, fs_1.readFileSync)(collectionPath, 'utf8'));
12
+ const schematics = Object.entries(collection.schematics).map(([name, value]) => {
13
+ var _a;
14
+ const schematic = value;
15
+ const description = schematic.description;
16
+ const alias = ((_a = schematic === null || schematic === void 0 ? void 0 : schematic.aliases) === null || _a === void 0 ? void 0 : _a.length) ? schematic.aliases[0] : '';
17
+ return { name, description, alias };
18
+ });
19
+ return schematics;
20
+ }
6
21
  }
7
22
  exports.CustomCollection = CustomCollection;
@@ -10,6 +10,6 @@ export declare class NestCollection extends AbstractCollection {
10
10
  private static schematics;
11
11
  constructor(runner: AbstractRunner);
12
12
  execute(name: string, options: SchematicOption[]): Promise<void>;
13
- static getSchematics(): Schematic[];
13
+ getSchematics(): Schematic[];
14
14
  private validate;
15
15
  }
@@ -24,7 +24,7 @@ class NestCollection extends abstract_collection_1.AbstractCollection {
24
24
  yield _super.execute.call(this, schematic, options);
25
25
  });
26
26
  }
27
- static getSchematics() {
27
+ getSchematics() {
28
28
  return NestCollection.schematics.filter((item) => item.name !== 'angular-app');
29
29
  }
30
30
  validate(name) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs/cli",
3
- "version": "9.1.9",
3
+ "version": "9.2.0",
4
4
  "description": "Nest - modern, fast, powerful node.js web framework (@cli)",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -38,26 +38,26 @@
38
38
  },
39
39
  "homepage": "https://github.com/nestjs/nest-cli#readme",
40
40
  "dependencies": {
41
- "@angular-devkit/core": "15.0.4",
42
- "@angular-devkit/schematics": "15.0.4",
43
- "@angular-devkit/schematics-cli": "15.0.4",
41
+ "@angular-devkit/core": "15.1.4",
42
+ "@angular-devkit/schematics": "15.1.4",
43
+ "@angular-devkit/schematics-cli": "15.1.4",
44
44
  "@nestjs/schematics": "^9.0.0",
45
45
  "chalk": "3.0.0",
46
46
  "chokidar": "3.5.3",
47
47
  "cli-table3": "0.6.3",
48
48
  "commander": "4.1.1",
49
- "fork-ts-checker-webpack-plugin": "7.2.14",
49
+ "fork-ts-checker-webpack-plugin": "7.3.0",
50
50
  "inquirer": "7.3.3",
51
51
  "node-emoji": "1.11.0",
52
52
  "ora": "5.4.1",
53
53
  "os-name": "4.0.1",
54
- "rimraf": "3.0.2",
54
+ "rimraf": "4.1.2",
55
55
  "shelljs": "0.8.5",
56
56
  "source-map-support": "0.5.21",
57
57
  "tree-kill": "1.2.2",
58
- "tsconfig-paths": "4.1.1",
58
+ "tsconfig-paths": "4.1.2",
59
59
  "tsconfig-paths-webpack-plugin": "4.0.0",
60
- "typescript": "4.9.4",
60
+ "typescript": "4.9.5",
61
61
  "webpack": "5.75.0",
62
62
  "webpack-node-externals": "3.0.0"
63
63
  },
@@ -66,7 +66,7 @@
66
66
  "@commitlint/config-angular": "17.4.2",
67
67
  "@types/copyfiles": "2.4.1",
68
68
  "@types/inquirer": "8.2.5",
69
- "@types/jest": "29.2.6",
69
+ "@types/jest": "29.4.0",
70
70
  "@types/node": "18.11.18",
71
71
  "@types/node-emoji": "1.8.2",
72
72
  "@types/ora": "3.2.0",
@@ -74,16 +74,16 @@
74
74
  "@types/rimraf": "3.0.2",
75
75
  "@types/shelljs": "0.8.11",
76
76
  "@types/webpack-node-externals": "2.5.3",
77
- "@typescript-eslint/eslint-plugin": "5.49.0",
78
- "@typescript-eslint/parser": "5.49.0",
77
+ "@typescript-eslint/eslint-plugin": "5.50.0",
78
+ "@typescript-eslint/parser": "5.50.0",
79
79
  "delete-empty": "3.0.0",
80
- "eslint": "8.32.0",
80
+ "eslint": "8.33.0",
81
81
  "eslint-config-prettier": "8.6.0",
82
82
  "eslint-plugin-import": "2.27.5",
83
83
  "gulp": "4.0.2",
84
84
  "gulp-clean": "0.4.0",
85
85
  "husky": "8.0.3",
86
- "jest": "29.3.1",
86
+ "jest": "29.4.1",
87
87
  "lint-staged": "13.1.0",
88
88
  "prettier": "2.8.3",
89
89
  "release-it": "15.6.0",