@nestjs/schematics 12.0.0-alpha.4 → 12.0.0-alpha.6

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.
Files changed (42) hide show
  1. package/dist/lib/application/files/ts-esm/test/app.e2e-__specFileSuffix__.ts +1 -2
  2. package/dist/lib/application/schema.json +6 -3
  3. package/dist/lib/class/class.factory.js +9 -2
  4. package/dist/lib/class/files/ts/__name__.__specFileSuffix__.ts +1 -1
  5. package/dist/lib/controller/controller.factory.js +1 -0
  6. package/dist/lib/controller/files/ts/__name__.controller.__specFileSuffix__.ts +1 -1
  7. package/dist/lib/filter/files/ts/__name__.filter.__specFileSuffix__.ts +1 -1
  8. package/dist/lib/filter/filter.factory.js +9 -2
  9. package/dist/lib/gateway/files/ts/__name__.gateway.__specFileSuffix__.ts +1 -1
  10. package/dist/lib/gateway/gateway.factory.js +1 -0
  11. package/dist/lib/guard/files/ts/__name__.guard.__specFileSuffix__.ts +1 -1
  12. package/dist/lib/guard/guard.factory.js +9 -2
  13. package/dist/lib/interceptor/files/ts/__name__.interceptor.__specFileSuffix__.ts +1 -1
  14. package/dist/lib/interceptor/interceptor.factory.js +9 -2
  15. package/dist/lib/library/files/ts/src/__name__.module.ts +1 -1
  16. package/dist/lib/library/files/ts/src/__name__.service.__specFileSuffix__.ts +1 -1
  17. package/dist/lib/library/files/ts/src/index.ts +2 -2
  18. package/dist/lib/library/library.factory.js +30 -20
  19. package/dist/lib/middleware/files/ts/__name__.middleware.__specFileSuffix__.ts +1 -1
  20. package/dist/lib/middleware/middleware.factory.js +9 -2
  21. package/dist/lib/pipe/files/ts/__name__.pipe.__specFileSuffix__.ts +1 -1
  22. package/dist/lib/pipe/pipe.factory.js +9 -2
  23. package/dist/lib/provider/files/ts/__name__.__specFileSuffix__.ts +1 -1
  24. package/dist/lib/provider/provider.factory.js +1 -0
  25. package/dist/lib/resolver/files/ts/__name__.resolver.__specFileSuffix__.ts +1 -1
  26. package/dist/lib/resolver/resolver.factory.js +1 -0
  27. package/dist/lib/resource/files/ts/__name__.controller.__specFileSuffix__.ts +2 -2
  28. package/dist/lib/resource/files/ts/__name__.gateway.__specFileSuffix__.ts +2 -2
  29. package/dist/lib/resource/files/ts/__name__.resolver.__specFileSuffix__.ts +2 -2
  30. package/dist/lib/resource/files/ts/__name__.service.__specFileSuffix__.ts +1 -1
  31. package/dist/lib/resource/resource.factory.js +2 -1
  32. package/dist/lib/service/files/ts/__name__.service.__specFileSuffix__.ts +1 -1
  33. package/dist/lib/service/service.factory.js +1 -0
  34. package/dist/lib/sub-app/files/ts/src/__name__.controller.__specFileSuffix__.ts +2 -2
  35. package/dist/lib/sub-app/files/ts/src/__name__.controller.ts +1 -1
  36. package/dist/lib/sub-app/files/ts/src/__name__.module.ts +2 -2
  37. package/dist/lib/sub-app/files/ts/src/main.ts +2 -2
  38. package/dist/lib/sub-app/files/ts/test/app.e2e-__specFileSuffix__.ts +1 -1
  39. package/dist/lib/sub-app/files/ts/tsconfig.app.json +1 -1
  40. package/dist/lib/sub-app/sub-app.factory.js +15 -8
  41. package/dist/lib/sub-app/workspace/ts/tsconfig.app.json +1 -1
  42. package/package.json +1 -1
@@ -1,11 +1,10 @@
1
1
  import { Test, TestingModule } from '@nestjs/testing';
2
2
  import { INestApplication } from '@nestjs/common';
3
3
  import request from 'supertest';
4
- import { App } from 'supertest/types';
5
4
  import { AppModule } from './../src/app.module.js';
6
5
 
7
6
  describe('AppController (e2e)', () => {
8
- let app: INestApplication<App>;
7
+ let app: INestApplication;
9
8
 
10
9
  beforeEach(async () => {
11
10
  const moduleFixture: TestingModule = await Test.createTestingModule({
@@ -41,13 +41,16 @@
41
41
  "type": "string",
42
42
  "description": "Nest application module type (CJS or ESM).",
43
43
  "enum": ["cjs", "esm"],
44
- "default": "cjs",
44
+ "default": "esm",
45
45
  "x-prompt": {
46
46
  "message": "Which module system would you like to use?",
47
47
  "type": "list",
48
48
  "items": [
49
- { "value": "cjs", "label": "CJS (CommonJS)" },
50
- { "value": "esm", "label": "ESM (ES Modules)" }
49
+ {
50
+ "value": "esm",
51
+ "label": "ESM (ES Modules) [ with vitest ]"
52
+ },
53
+ { "value": "cjs", "label": "CJS (CommonJS) [ with jest ]" }
51
54
  ]
52
55
  }
53
56
  },
@@ -2,11 +2,18 @@ import { join, strings } from '@angular-devkit/core';
2
2
  import { apply, chain, filter, mergeWith, move, noop, SchematicsException, template, url, } from '@angular-devkit/schematics';
3
3
  import { normalizeToKebabOrSnakeCase } from '../../utils/formatting.js';
4
4
  import { NameParser } from '../../utils/name.parser.js';
5
- import { mergeSourceRoot } from '../../utils/source-root.helpers.js';
5
+ import { isEsmProject, mergeSourceRoot, } from '../../utils/source-root.helpers.js';
6
6
  import { DEFAULT_LANGUAGE } from '../defaults.js';
7
7
  export function main(options) {
8
8
  options = transform(options);
9
- return chain([mergeSourceRoot(options), mergeWith(generate(options))]);
9
+ return chain([
10
+ mergeSourceRoot(options),
11
+ (tree) => {
12
+ options.isEsm = isEsmProject(tree);
13
+ return tree;
14
+ },
15
+ mergeWith(generate(options)),
16
+ ]);
10
17
  }
11
18
  function transform(options) {
12
19
  const target = Object.assign({}, options);
@@ -1,4 +1,4 @@
1
- import { <%= classify(className) %> } from './<%= name %>';
1
+ import { <%= classify(className) %> } from './<%= name %><%= isEsm ? '.js' : '' %>';
2
2
 
3
3
  describe('<%= classify(className) %>', () => {
4
4
  it('should be defined', () => {
@@ -11,6 +11,7 @@ const ELEMENT_TYPE = 'controller';
11
11
  export function main(options) {
12
12
  options = transform(options);
13
13
  return (tree, context) => {
14
+ options.isEsm = isEsmProject(tree);
14
15
  return branchAndMerge(chain([
15
16
  mergeSourceRoot(options),
16
17
  mergeWith(generate(options)),
@@ -1,5 +1,5 @@
1
1
  import { Test, TestingModule } from '@nestjs/testing';
2
- import { <%= classify(name) %>Controller } from './<%= name %>.controller';
2
+ import { <%= classify(name) %>Controller } from './<%= name %>.controller<%= isEsm ? '.js' : '' %>';
3
3
 
4
4
  describe('<%= classify(name) %>Controller', () => {
5
5
  let controller: <%= classify(name) %>Controller;
@@ -1,4 +1,4 @@
1
- import { <%= classify(name) %>Filter } from './<%= name %>.filter';
1
+ import { <%= classify(name) %>Filter } from './<%= name %>.filter<%= isEsm ? '.js' : '' %>';
2
2
 
3
3
  describe('<%= classify(name) %>Filter', () => {
4
4
  it('should be defined', () => {
@@ -2,10 +2,17 @@ import { join, strings } from '@angular-devkit/core';
2
2
  import { apply, chain, filter, mergeWith, move, noop, SchematicsException, template, url, } from '@angular-devkit/schematics';
3
3
  import { normalizeToKebabOrSnakeCase } from '../../utils/formatting.js';
4
4
  import { NameParser } from '../../utils/name.parser.js';
5
- import { mergeSourceRoot } from '../../utils/source-root.helpers.js';
5
+ import { isEsmProject, mergeSourceRoot, } from '../../utils/source-root.helpers.js';
6
6
  export function main(options) {
7
7
  options = transform(options);
8
- return chain([mergeSourceRoot(options), mergeWith(generate(options))]);
8
+ return chain([
9
+ mergeSourceRoot(options),
10
+ (tree) => {
11
+ options.isEsm = isEsmProject(tree);
12
+ return tree;
13
+ },
14
+ mergeWith(generate(options)),
15
+ ]);
9
16
  }
10
17
  function transform(options) {
11
18
  const target = Object.assign({}, options);
@@ -1,5 +1,5 @@
1
1
  import { Test, TestingModule } from '@nestjs/testing';
2
- import { <%= classify(name) %>Gateway } from './<%= name %>.gateway';
2
+ import { <%= classify(name) %>Gateway } from './<%= name %>.gateway<%= isEsm ? '.js' : '' %>';
3
3
 
4
4
  describe('<%= classify(name) %>Gateway', () => {
5
5
  let gateway: <%= classify(name) %>Gateway;
@@ -8,6 +8,7 @@ import { isEsmProject, mergeSourceRoot, } from '../../utils/source-root.helpers.
8
8
  export function main(options) {
9
9
  options = transform(options);
10
10
  return (tree, context) => {
11
+ options.isEsm = isEsmProject(tree);
11
12
  return branchAndMerge(chain([
12
13
  mergeSourceRoot(options),
13
14
  addDeclarationToModule(options),
@@ -1,4 +1,4 @@
1
- import { <%= classify(name) %>Guard } from './<%= name %>.guard';
1
+ import { <%= classify(name) %>Guard } from './<%= name %>.guard<%= isEsm ? '.js' : '' %>';
2
2
 
3
3
  describe('<%= classify(name) %>Guard', () => {
4
4
  it('should be defined', () => {
@@ -2,10 +2,17 @@ import { join, strings } from '@angular-devkit/core';
2
2
  import { apply, chain, filter, mergeWith, move, noop, SchematicsException, template, url, } from '@angular-devkit/schematics';
3
3
  import { normalizeToKebabOrSnakeCase } from '../../utils/formatting.js';
4
4
  import { NameParser } from '../../utils/name.parser.js';
5
- import { mergeSourceRoot } from '../../utils/source-root.helpers.js';
5
+ import { isEsmProject, mergeSourceRoot, } from '../../utils/source-root.helpers.js';
6
6
  export function main(options) {
7
7
  options = transform(options);
8
- return chain([mergeSourceRoot(options), mergeWith(generate(options))]);
8
+ return chain([
9
+ mergeSourceRoot(options),
10
+ (tree) => {
11
+ options.isEsm = isEsmProject(tree);
12
+ return tree;
13
+ },
14
+ mergeWith(generate(options)),
15
+ ]);
9
16
  }
10
17
  function transform(options) {
11
18
  const target = Object.assign({}, options);
@@ -1,4 +1,4 @@
1
- import { <%= classify(name) %>Interceptor } from './<%= name %>.interceptor';
1
+ import { <%= classify(name) %>Interceptor } from './<%= name %>.interceptor<%= isEsm ? '.js' : '' %>';
2
2
 
3
3
  describe('<%= classify(name) %>Interceptor', () => {
4
4
  it('should be defined', () => {
@@ -2,10 +2,17 @@ import { join, strings } from '@angular-devkit/core';
2
2
  import { apply, chain, filter, mergeWith, move, noop, SchematicsException, template, url, } from '@angular-devkit/schematics';
3
3
  import { normalizeToKebabOrSnakeCase } from '../../utils/formatting.js';
4
4
  import { NameParser } from '../../utils/name.parser.js';
5
- import { mergeSourceRoot } from '../../utils/source-root.helpers.js';
5
+ import { isEsmProject, mergeSourceRoot, } from '../../utils/source-root.helpers.js';
6
6
  export function main(options) {
7
7
  options = transform(options);
8
- return chain([mergeSourceRoot(options), mergeWith(generate(options))]);
8
+ return chain([
9
+ mergeSourceRoot(options),
10
+ (tree) => {
11
+ options.isEsm = isEsmProject(tree);
12
+ return tree;
13
+ },
14
+ mergeWith(generate(options)),
15
+ ]);
9
16
  }
10
17
  function transform(options) {
11
18
  const target = Object.assign({}, options);
@@ -1,5 +1,5 @@
1
1
  import { Module } from '@nestjs/common';
2
- import { <%= classify(name) %>Service } from './<%= name %>.service';
2
+ import { <%= classify(name) %>Service } from './<%= name %>.service<%= isEsm ? '.js' : '' %>';
3
3
 
4
4
  @Module({
5
5
  providers: [<%= classify(name) %>Service],
@@ -1,5 +1,5 @@
1
1
  import { Test, TestingModule } from '@nestjs/testing';
2
- import { <%= classify(name) %>Service } from './<%= name %>.service';
2
+ import { <%= classify(name) %>Service } from './<%= name %>.service<%= isEsm ? '.js' : '' %>';
3
3
 
4
4
  describe('<%= classify(name) %>Service', () => {
5
5
  let service: <%= classify(name) %>Service;
@@ -1,2 +1,2 @@
1
- export * from './<%= name %>.module';
2
- export * from './<%= name %>.service';
1
+ export * from './<%= name %>.module<%= isEsm ? '.js' : '' %>';
2
+ export * from './<%= name %>.service<%= isEsm ? '.js' : '' %>';
@@ -4,6 +4,7 @@ import { parse } from 'jsonc-parser';
4
4
  import { createModuleNameMapper, inPlaceSortByKeys, normalizeToKebabOrSnakeCase, } from '../../utils/index.js';
5
5
  import { DEFAULT_LANGUAGE, DEFAULT_LIB_PATH, DEFAULT_PATH_NAME, PROJECT_TYPE, } from '../defaults.js';
6
6
  import { FileSystemReader } from '../readers/index.js';
7
+ import { isEsmProject } from '../../utils/source-root.helpers.js';
7
8
  export function main(options) {
8
9
  options = transform(options);
9
10
  return chain([
@@ -11,6 +12,10 @@ export function main(options) {
11
12
  updatePackageJson(options),
12
13
  updateJestEndToEnd(options),
13
14
  updateTsConfig(options.name, options.prefix, options.path),
15
+ (tree) => {
16
+ options.isEsm = isEsmProject(tree);
17
+ return tree;
18
+ },
14
19
  branchAndMerge(mergeWith(generate(options))),
15
20
  ]);
16
21
  }
@@ -134,30 +139,33 @@ function updateJsonFile(host, path, callback) {
134
139
  }
135
140
  return host;
136
141
  }
137
- function updateTsConfig(packageName, _packagePrefix, root) {
142
+ function updateTsConfig(packageName, packagePrefix, root) {
138
143
  return (host) => {
139
144
  if (!host.exists('tsconfig.json')) {
140
145
  return host;
141
146
  }
142
- const refPath = `./${join(root, packageName, 'tsconfig.lib.json')}`;
147
+ const distRoot = join(root, packageName, 'src');
148
+ const packageKey = packagePrefix
149
+ ? packagePrefix + '/' + packageName
150
+ : packageName;
143
151
  return updateJsonFile(host, 'tsconfig.json', (tsconfig) => {
144
152
  if (!tsconfig.compilerOptions) {
145
153
  tsconfig.compilerOptions = {};
146
154
  }
147
155
  delete tsconfig.compilerOptions.baseUrl;
148
- delete tsconfig.compilerOptions.paths;
149
- if (!tsconfig.files) {
150
- tsconfig.files = [];
156
+ if (!tsconfig.compilerOptions.paths) {
157
+ tsconfig.compilerOptions.paths = {};
151
158
  }
152
- delete tsconfig.include;
153
- delete tsconfig.exclude;
154
- if (!tsconfig.references) {
155
- tsconfig.references = [];
159
+ if (!tsconfig.compilerOptions.paths[packageKey]) {
160
+ tsconfig.compilerOptions.paths[packageKey] = [];
156
161
  }
157
- const hasRef = tsconfig.references.some((ref) => ref.path === refPath);
158
- if (!hasRef) {
159
- tsconfig.references.push({ path: refPath });
162
+ tsconfig.compilerOptions.paths[packageKey].push('./' + distRoot);
163
+ const deepPackagePath = packageKey + '/*';
164
+ if (!tsconfig.compilerOptions.paths[deepPackagePath]) {
165
+ tsconfig.compilerOptions.paths[deepPackagePath] = [];
160
166
  }
167
+ tsconfig.compilerOptions.paths[deepPackagePath].push('./' + distRoot + '/*');
168
+ inPlaceSortByKeys(tsconfig.compilerOptions.paths);
161
169
  });
162
170
  };
163
171
  }
@@ -198,12 +206,14 @@ function addLibraryToCliOptions(projectRoot, projectName) {
198
206
  };
199
207
  }
200
208
  function generate(options) {
201
- const path = join(options.path, options.name);
202
- return apply(url(join('./files', options.language)), [
203
- template({
204
- ...strings,
205
- ...options,
206
- }),
207
- move(path),
208
- ]);
209
+ return (context) => {
210
+ const path = join(options.path, options.name);
211
+ return apply(url(join('./files', options.language)), [
212
+ template({
213
+ ...strings,
214
+ ...options,
215
+ }),
216
+ move(path),
217
+ ])(context);
218
+ };
209
219
  }
@@ -1,4 +1,4 @@
1
- import { <%= classify(name) %>Middleware } from './<%= name %>.middleware';
1
+ import { <%= classify(name) %>Middleware } from './<%= name %>.middleware<%= isEsm ? '.js' : '' %>';
2
2
 
3
3
  describe('<%= classify(name) %>Middleware', () => {
4
4
  it('should be defined', () => {
@@ -2,10 +2,17 @@ import { join, strings } from '@angular-devkit/core';
2
2
  import { apply, chain, filter, mergeWith, move, noop, SchematicsException, template, url, } from '@angular-devkit/schematics';
3
3
  import { normalizeToKebabOrSnakeCase } from '../../utils/formatting.js';
4
4
  import { NameParser } from '../../utils/name.parser.js';
5
- import { mergeSourceRoot } from '../../utils/source-root.helpers.js';
5
+ import { isEsmProject, mergeSourceRoot, } from '../../utils/source-root.helpers.js';
6
6
  export function main(options) {
7
7
  options = transform(options);
8
- return chain([mergeSourceRoot(options), mergeWith(generate(options))]);
8
+ return chain([
9
+ mergeSourceRoot(options),
10
+ (tree) => {
11
+ options.isEsm = isEsmProject(tree);
12
+ return tree;
13
+ },
14
+ mergeWith(generate(options)),
15
+ ]);
9
16
  }
10
17
  function transform(options) {
11
18
  const target = Object.assign({}, options);
@@ -1,4 +1,4 @@
1
- import { <%= classify(name) %>Pipe } from './<%= name %>.pipe';
1
+ import { <%= classify(name) %>Pipe } from './<%= name %>.pipe<%= isEsm ? '.js' : '' %>';
2
2
 
3
3
  describe('<%= classify(name) %>Pipe', () => {
4
4
  it('should be defined', () => {
@@ -2,10 +2,17 @@ import { join, strings } from '@angular-devkit/core';
2
2
  import { apply, chain, filter, mergeWith, move, noop, SchematicsException, template, url, } from '@angular-devkit/schematics';
3
3
  import { normalizeToKebabOrSnakeCase } from '../../utils/formatting.js';
4
4
  import { NameParser } from '../../utils/name.parser.js';
5
- import { mergeSourceRoot } from '../../utils/source-root.helpers.js';
5
+ import { isEsmProject, mergeSourceRoot, } from '../../utils/source-root.helpers.js';
6
6
  export function main(options) {
7
7
  options = transform(options);
8
- return chain([mergeSourceRoot(options), mergeWith(generate(options))]);
8
+ return chain([
9
+ mergeSourceRoot(options),
10
+ (tree) => {
11
+ options.isEsm = isEsmProject(tree);
12
+ return tree;
13
+ },
14
+ mergeWith(generate(options)),
15
+ ]);
9
16
  }
10
17
  function transform(options) {
11
18
  const target = Object.assign({}, options);
@@ -1,5 +1,5 @@
1
1
  import { Test, TestingModule } from '@nestjs/testing';
2
- import { <%= classify(className) %> } from './<%= name %>';
2
+ import { <%= classify(className) %> } from './<%= name %><%= isEsm ? '.js' : '' %>';
3
3
 
4
4
  describe('<%= classify(className) %>', () => {
5
5
  let provider: <%= classify(className) %>;
@@ -8,6 +8,7 @@ import { isEsmProject, mergeSourceRoot, } from '../../utils/source-root.helpers.
8
8
  export function main(options) {
9
9
  options = transform(options);
10
10
  return (tree, context) => {
11
+ options.isEsm = isEsmProject(tree);
11
12
  return branchAndMerge(chain([
12
13
  mergeSourceRoot(options),
13
14
  addDeclarationToModule(options),
@@ -1,5 +1,5 @@
1
1
  import { Test, TestingModule } from '@nestjs/testing';
2
- import { <%= classify(name) %>Resolver } from './<%= name %>.resolver';
2
+ import { <%= classify(name) %>Resolver } from './<%= name %>.resolver<%= isEsm ? '.js' : '' %>';
3
3
 
4
4
  describe('<%= classify(name) %>Resolver', () => {
5
5
  let resolver: <%= classify(name) %>Resolver;
@@ -8,6 +8,7 @@ import { isEsmProject, mergeSourceRoot, } from '../../utils/source-root.helpers.
8
8
  export function main(options) {
9
9
  options = transform(options);
10
10
  return (tree, context) => {
11
+ options.isEsm = isEsmProject(tree);
11
12
  return branchAndMerge(chain([
12
13
  mergeSourceRoot(options),
13
14
  addDeclarationToModule(options),
@@ -1,6 +1,6 @@
1
1
  import { Test, TestingModule } from '@nestjs/testing';
2
- import { <%= classify(name) %>Controller } from './<%= name %>.controller';
3
- import { <%= classify(name) %>Service } from './<%= name %>.service';
2
+ import { <%= classify(name) %>Controller } from './<%= name %>.controller<%= isEsm ? '.js' : '' %>';
3
+ import { <%= classify(name) %>Service } from './<%= name %>.service<%= isEsm ? '.js' : '' %>';
4
4
 
5
5
  describe('<%= classify(name) %>Controller', () => {
6
6
  let controller: <%= classify(name) %>Controller;
@@ -1,6 +1,6 @@
1
1
  import { Test, TestingModule } from '@nestjs/testing';
2
- import { <%= classify(name) %>Gateway } from './<%= name %>.gateway';
3
- import { <%= classify(name) %>Service } from './<%= name %>.service';
2
+ import { <%= classify(name) %>Gateway } from './<%= name %>.gateway<%= isEsm ? '.js' : '' %>';
3
+ import { <%= classify(name) %>Service } from './<%= name %>.service<%= isEsm ? '.js' : '' %>';
4
4
 
5
5
  describe('<%= classify(name) %>Gateway', () => {
6
6
  let gateway: <%= classify(name) %>Gateway;
@@ -1,6 +1,6 @@
1
1
  import { Test, TestingModule } from '@nestjs/testing';
2
- import { <%= classify(name) %>Resolver } from './<%= name %>.resolver';
3
- import { <%= classify(name) %>Service } from './<%= name %>.service';
2
+ import { <%= classify(name) %>Resolver } from './<%= name %>.resolver<%= isEsm ? '.js' : '' %>';
3
+ import { <%= classify(name) %>Service } from './<%= name %>.service<%= isEsm ? '.js' : '' %>';
4
4
 
5
5
  describe('<%= classify(name) %>Resolver', () => {
6
6
  let resolver: <%= classify(name) %>Resolver;
@@ -1,5 +1,5 @@
1
1
  import { Test, TestingModule } from '@nestjs/testing';
2
- import { <%= classify(name) %>Service } from './<%= name %>.service';
2
+ import { <%= classify(name) %>Service } from './<%= name %>.service<%= isEsm ? '.js' : '' %>';
3
3
 
4
4
  describe('<%= classify(name) %>Service', () => {
5
5
  let service: <%= classify(name) %>Service;
@@ -1,7 +1,7 @@
1
1
  import { join, strings } from '@angular-devkit/core';
2
2
  import { classify } from '@angular-devkit/core/src/utils/strings';
3
3
  import { apply, branchAndMerge, chain, filter, mergeWith, move, noop, SchematicsException, template, url, } from '@angular-devkit/schematics';
4
- import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
4
+ import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks/index.js';
5
5
  import * as pluralize from 'pluralize';
6
6
  import { ModuleDeclarator, ModuleFinder, } from '../../index.js';
7
7
  import { addPackageJsonDependency, getPackageJsonDependency, NodeDependencyType, } from '../../utils/dependencies.utils.js';
@@ -11,6 +11,7 @@ import { isEsmProject, mergeSourceRoot, } from '../../utils/source-root.helpers.
11
11
  export function main(options) {
12
12
  options = transform(options);
13
13
  return (tree, context) => {
14
+ options.isEsm = isEsmProject(tree);
14
15
  return branchAndMerge(chain([
15
16
  addMappedTypesDependencyIfApplies(options),
16
17
  mergeSourceRoot(options),
@@ -1,5 +1,5 @@
1
1
  import { Test, TestingModule } from '@nestjs/testing';
2
- import { <%= classify(name) %>Service } from './<%= name %>.service';
2
+ import { <%= classify(name) %>Service } from './<%= name %>.service<%= isEsm ? '.js' : '' %>';
3
3
 
4
4
  describe('<%= classify(name) %>Service', () => {
5
5
  let service: <%= classify(name) %>Service;
@@ -11,6 +11,7 @@ function isNullOrUndefined(value) {
11
11
  export function main(options) {
12
12
  options = transform(options);
13
13
  return (tree, context) => {
14
+ options.isEsm = isEsmProject(tree);
14
15
  return branchAndMerge(chain([
15
16
  mergeSourceRoot(options),
16
17
  addDeclarationToModule(options),
@@ -1,6 +1,6 @@
1
1
  import { Test, TestingModule } from '@nestjs/testing';
2
- import { <%= classify(name) %>Controller } from './<%= name %>.controller';
3
- import { <%= classify(name) %>Service } from './<%= name %>.service';
2
+ import { <%= classify(name) %>Controller } from './<%= name %>.controller<%= isEsm ? '.js' : '' %>';
3
+ import { <%= classify(name) %>Service } from './<%= name %>.service<%= isEsm ? '.js' : '' %>';
4
4
 
5
5
  describe('<%= classify(name) %>Controller', () => {
6
6
  let <%= camelize(name) %>Controller: <%= classify(name) %>Controller;
@@ -1,5 +1,5 @@
1
1
  import { Controller, Get } from '@nestjs/common';
2
- import { <%= classify(name) %>Service } from './<%= name %>.service';
2
+ import { <%= classify(name) %>Service } from './<%= name %>.service<%= isEsm ? '.js' : '' %>';
3
3
 
4
4
  @Controller()
5
5
  export class <%= classify(name) %>Controller {
@@ -1,6 +1,6 @@
1
1
  import { Module } from '@nestjs/common';
2
- import { <%= classify(name) %>Controller } from './<%= name %>.controller';
3
- import { <%= classify(name) %>Service } from './<%= name %>.service';
2
+ import { <%= classify(name) %>Controller } from './<%= name %>.controller<%= isEsm ? '.js' : '' %>';
3
+ import { <%= classify(name) %>Service } from './<%= name %>.service<%= isEsm ? '.js' : '' %>';
4
4
 
5
5
  @Module({
6
6
  imports: [],
@@ -1,8 +1,8 @@
1
1
  import { NestFactory } from '@nestjs/core';
2
- import { <%= classify(name) %>Module } from './<%= name %>.module';
2
+ import { <%= classify(name) %>Module } from './<%= name %>.module<%= isEsm ? '.js' : '' %>';
3
3
 
4
4
  async function bootstrap() {
5
5
  const app = await NestFactory.create(<%= classify(name) %>Module);
6
6
  await app.listen(process.env.port ?? 3000);
7
7
  }
8
- bootstrap();
8
+ <%= isEsm ? 'await ' : '' %>bootstrap();
@@ -1,7 +1,7 @@
1
1
  import { Test, TestingModule } from '@nestjs/testing';
2
2
  import { INestApplication } from '@nestjs/common';
3
3
  import * as request from 'supertest';
4
- import { <%= classify(name)%>Module } from './../src/<%= name %>.module';
4
+ import { <%= classify(name)%>Module } from './../src/<%= name %>.module<%= isEsm ? '.js' : '' %>';
5
5
 
6
6
  describe('<%= classify(name)%>Controller (e2e)', () => {
7
7
  let app: INestApplication;
@@ -2,7 +2,7 @@
2
2
  "extends": "../../tsconfig.json",
3
3
  "compilerOptions": {
4
4
  "composite": true,
5
- "declaration": false,
5
+ "declaration": true,
6
6
  "outDir": "../../dist/apps/<%= name %>"
7
7
  },
8
8
  "include": ["src/**/*"],
@@ -4,6 +4,7 @@ import { existsSync, readFileSync } from 'fs';
4
4
  import { parse, stringify } from 'comment-json';
5
5
  import { inPlaceSortByKeys, normalizeToKebabOrSnakeCase, } from '../../utils/index.js';
6
6
  import { DEFAULT_APPS_PATH, DEFAULT_APP_NAME, DEFAULT_DIR_ENTRY_APP, DEFAULT_LANGUAGE, DEFAULT_LIB_PATH, DEFAULT_PATH_NAME, PROJECT_TYPE, TEST_ENV, } from '../defaults.js';
7
+ import { isEsmProject } from '../../utils/source-root.helpers.js';
7
8
  export function main(options) {
8
9
  const appName = getAppNameFromPackageJson();
9
10
  options = transform(options);
@@ -18,6 +19,10 @@ export function main(options) {
18
19
  ])(tree, context),
19
20
  addAppsToCliOptions(options.path, options.name, appName),
20
21
  addTsConfigReference(options.path, options.name),
22
+ (tree) => {
23
+ options.isEsm = isEsmProject(tree);
24
+ return tree;
25
+ },
21
26
  branchAndMerge(mergeWith(generate(options))),
22
27
  ]);
23
28
  }
@@ -285,12 +290,14 @@ function generateWorkspace(options, appName) {
285
290
  ]);
286
291
  }
287
292
  function generate(options) {
288
- const path = join(options.path, options.name);
289
- return apply(url(join('./files', options.language)), [
290
- template({
291
- ...strings,
292
- ...options,
293
- }),
294
- move(path),
295
- ]);
293
+ return (context) => {
294
+ const path = join(options.path, options.name);
295
+ return apply(url(join('./files', options.language)), [
296
+ template({
297
+ ...strings,
298
+ ...options,
299
+ }),
300
+ move(path),
301
+ ])(context);
302
+ };
296
303
  }
@@ -2,7 +2,7 @@
2
2
  "extends": "../../tsconfig.json",
3
3
  "compilerOptions": {
4
4
  "composite": true,
5
- "declaration": false,
5
+ "declaration": true,
6
6
  "outDir": "../../dist/apps/<%= name %>"
7
7
  },
8
8
  "include": ["src/**/*"],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs/schematics",
3
- "version": "12.0.0-alpha.4",
3
+ "version": "12.0.0-alpha.6",
4
4
  "description": "Nest - modern, fast, powerful node.js web framework (@schematics)",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",