@nx/node 0.0.0-pr-22179-271588f → 0.0.0-pr-26482-ebe2dba

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.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2017-2023 Narwhal Technologies Inc.
3
+ Copyright (c) 2017-2024 Narwhal Technologies Inc.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/node",
3
- "version": "0.0.0-pr-22179-271588f",
3
+ "version": "0.0.0-pr-26482-ebe2dba",
4
4
  "private": false,
5
5
  "description": "The Node Plugin for Nx contains generators to manage Node applications within an Nx workspace.",
6
6
  "repository": {
@@ -14,9 +14,10 @@
14
14
  "Nest",
15
15
  "Jest",
16
16
  "Cypress",
17
- "CLI"
17
+ "CLI",
18
+ "Backend"
18
19
  ],
19
- "main": "./index.js",
20
+ "main": "./index",
20
21
  "typings": "./index.d.ts",
21
22
  "author": "Victor Savkin",
22
23
  "license": "MIT",
@@ -31,11 +32,11 @@
31
32
  },
32
33
  "dependencies": {
33
34
  "tslib": "^2.3.0",
34
- "@nx/devkit": "0.0.0-pr-22179-271588f",
35
- "@nx/jest": "0.0.0-pr-22179-271588f",
36
- "@nx/js": "0.0.0-pr-22179-271588f",
37
- "@nx/eslint": "0.0.0-pr-22179-271588f",
38
- "@nrwl/node": "0.0.0-pr-22179-271588f"
35
+ "@nx/devkit": "0.0.0-pr-26482-ebe2dba",
36
+ "@nx/jest": "0.0.0-pr-26482-ebe2dba",
37
+ "@nx/js": "0.0.0-pr-26482-ebe2dba",
38
+ "@nx/eslint": "0.0.0-pr-26482-ebe2dba",
39
+ "@nrwl/node": "0.0.0-pr-26482-ebe2dba"
39
40
  },
40
41
  "publishConfig": {
41
42
  "access": "public"
@@ -3,6 +3,7 @@ import { Schema } from './schema';
3
3
  export interface NormalizedSchema extends Schema {
4
4
  appProjectRoot: string;
5
5
  parsedTags: string[];
6
+ outputPath: string;
6
7
  }
7
8
  export declare function addLintingToApplication(tree: Tree, options: NormalizedSchema): Promise<GeneratorCallback>;
8
9
  export declare function applicationGenerator(tree: Tree, schema: Schema): Promise<GeneratorCallback>;
@@ -23,7 +23,7 @@ function getWebpackBuildConfig(project, options) {
23
23
  options: {
24
24
  target: 'node',
25
25
  compiler: 'tsc',
26
- outputPath: (0, devkit_1.joinPathFragments)('dist', options.rootProject ? options.name : options.appProjectRoot),
26
+ outputPath: options.outputPath,
27
27
  main: (0, devkit_1.joinPathFragments)(project.sourceRoot, 'main' + (options.js ? '.js' : '.ts')),
28
28
  tsConfig: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
29
29
  assets: [(0, devkit_1.joinPathFragments)(project.sourceRoot, 'assets')],
@@ -44,7 +44,7 @@ function getEsBuildConfig(project, options) {
44
44
  defaultConfiguration: 'production',
45
45
  options: {
46
46
  platform: 'node',
47
- outputPath: (0, devkit_1.joinPathFragments)('dist', options.rootProject ? options.name : options.appProjectRoot),
47
+ outputPath: options.outputPath,
48
48
  // Use CJS for Node apps for widest compatibility.
49
49
  format: ['cjs'],
50
50
  bundle: false,
@@ -120,7 +120,7 @@ function addAppFiles(tree, options) {
120
120
  rootTsConfigPath: (0, js_1.getRelativePathToRootTsConfig)(tree, options.appProjectRoot),
121
121
  webpackPluginOptions: (0, has_webpack_plugin_1.hasWebpackPlugin)(tree)
122
122
  ? {
123
- outputPath: (0, devkit_1.joinPathFragments)('dist', options.rootProject ? options.name : options.appProjectRoot),
123
+ outputPath: options.outputPath,
124
124
  main: './src/main' + (options.js ? '.js' : '.ts'),
125
125
  tsConfig: './tsconfig.app.json',
126
126
  assets: ['./src/assets'],
@@ -407,6 +407,7 @@ async function normalizeOptions(host, options) {
407
407
  unitTestRunner: options.unitTestRunner ?? 'jest',
408
408
  rootProject: options.rootProject ?? false,
409
409
  port: options.port ?? 3000,
410
+ outputPath: (0, devkit_1.joinPathFragments)('dist', options.rootProject ? options.name : appProjectRoot),
410
411
  };
411
412
  }
412
413
  exports.default = applicationGenerator;
@@ -1,5 +1,5 @@
1
1
  <% if (webpackPluginOptions) { %>
2
- const { NxWebpackPlugin } = require('@nx/webpack');
2
+ const { NxAppWebpackPlugin } = require('@nx/webpack/app-plugin');
3
3
  const { join } = require('path');
4
4
 
5
5
  module.exports = {
@@ -7,7 +7,7 @@ module.exports = {
7
7
  path: join(__dirname, '<%= offset %><%= webpackPluginOptions.outputPath %>'),
8
8
  },
9
9
  plugins: [
10
- new NxWebpackPlugin({
10
+ new NxAppWebpackPlugin({
11
11
  target: 'node',
12
12
  compiler: 'tsc',
13
13
  main: '<%= webpackPluginOptions.main %>',
@@ -9,6 +9,7 @@ const path = require("path");
9
9
  const versions_1 = require("../../utils/versions");
10
10
  const eslint_file_1 = require("@nx/eslint/src/generators/utils/eslint-file");
11
11
  const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
12
+ const config_file_1 = require("@nx/jest/src/utils/config/config-file");
12
13
  async function e2eProjectGenerator(host, options) {
13
14
  return await e2eProjectGeneratorInternal(host, {
14
15
  addPlugin: false,
@@ -34,14 +35,42 @@ async function e2eProjectGeneratorInternal(host, _options) {
34
35
  jestConfig: `${options.e2eProjectRoot}/jest.config.ts`,
35
36
  passWithNoTests: true,
36
37
  },
38
+ dependsOn: [`${options.project}:build`],
37
39
  },
38
40
  },
39
41
  });
42
+ // TODO(@nicholas): Find a better way to get build target
43
+ // We remove the 'test' target from the e2e project because it is not needed
44
+ // The 'e2e' target is the one that should run the tests for the e2e project
45
+ const nxJson = (0, devkit_1.readNxJson)(host);
46
+ const hasPlugin = nxJson.plugins?.some((p) => {
47
+ if (typeof p !== 'string' && p.plugin === '@nx/jest/plugin') {
48
+ return true;
49
+ }
50
+ });
51
+ if (hasPlugin) {
52
+ (0, devkit_1.updateJson)(host, 'nx.json', (json) => {
53
+ return {
54
+ ...json,
55
+ plugins: json.plugins?.map((p) => {
56
+ if (typeof p !== 'string' && p.plugin === '@nx/jest/plugin') {
57
+ return {
58
+ ...p,
59
+ exclude: [...(p.exclude || []), `${options.e2eProjectRoot}/**/*`],
60
+ };
61
+ }
62
+ return p;
63
+ }),
64
+ };
65
+ });
66
+ }
67
+ const jestPreset = (0, config_file_1.findRootJestPreset)(host) ?? 'jest.preset.js';
40
68
  if (options.projectType === 'server') {
41
69
  (0, devkit_1.generateFiles)(host, path.join(__dirname, 'files/server/common'), options.e2eProjectRoot, {
42
70
  ...options,
43
71
  ...(0, devkit_1.names)(options.rootProject ? 'server' : options.project),
44
72
  offsetFromRoot: (0, devkit_1.offsetFromRoot)(options.e2eProjectRoot),
73
+ jestPreset,
45
74
  tmpl: '',
46
75
  });
47
76
  if (options.isNest) {
@@ -60,6 +89,7 @@ async function e2eProjectGeneratorInternal(host, _options) {
60
89
  ...(0, devkit_1.names)(options.rootProject ? 'cli' : options.project),
61
90
  mainFile,
62
91
  offsetFromRoot: (0, devkit_1.offsetFromRoot)(options.e2eProjectRoot),
92
+ jestPreset,
63
93
  tmpl: '',
64
94
  });
65
95
  }
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable */
2
2
  export default {
3
3
  displayName: '<%= e2eProjectName %>',
4
- preset: '<%= offsetFromRoot %>/jest.preset.js',
4
+ preset: '<%= offsetFromRoot %><%= jestPreset %>',
5
5
  setupFiles: ['<rootDir>/src/test-setup.ts'],
6
6
  testEnvironment: 'node',
7
7
  transform: {
@@ -10,5 +10,5 @@ export default {
10
10
  }],
11
11
  },
12
12
  moduleFileExtensions: ['ts', 'js', 'html'],
13
- coverageDirectory: '<%= offsetFromRoot %>/coverage/<%= e2eProjectName %>',
13
+ coverageDirectory: '<%= offsetFromRoot %>coverage/<%= e2eProjectName %>',
14
14
  };
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable */
2
2
  export default {
3
3
  displayName: '<%= e2eProjectName %>',
4
- preset: '<%= offsetFromRoot %>jest.preset.js',
4
+ preset: '<%= offsetFromRoot %><%= jestPreset %>',
5
5
  globalSetup: '<rootDir>/src/support/global-setup.ts',
6
6
  globalTeardown: '<rootDir>/src/support/global-teardown.ts',
7
7
  setupFiles: ['<rootDir>/src/support/test-setup.ts'],
@@ -14,7 +14,7 @@ WORKDIR /app
14
14
  RUN addgroup --system <%= project %> && \
15
15
  adduser --system -G <%= project %> <%= project %>
16
16
 
17
- COPY <%= buildLocation %> <%= project %>
17
+ COPY <%= buildLocation %> <%= project %>/
18
18
  RUN chown -R <%= project %>:<%= project %> .
19
19
 
20
20
  # You can remove this install step if you build with `--bundle` option.
@@ -3,4 +3,5 @@ export interface SetUpDockerOptions {
3
3
  targetName?: string;
4
4
  buildTarget?: string;
5
5
  skipFormat?: boolean;
6
+ outputPath: string;
6
7
  }
@@ -24,6 +24,10 @@
24
24
  "description": "The name of the build target",
25
25
  "type": "string",
26
26
  "default": "build"
27
+ },
28
+ "outputPath": {
29
+ "description": "The output path for the node application",
30
+ "type": "string"
27
31
  }
28
32
  }
29
33
  }
@@ -12,22 +12,15 @@ function normalizeOptions(tree, setupOptions) {
12
12
  };
13
13
  }
14
14
  function addDocker(tree, options) {
15
- const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
16
- if (!project || !options.targetName) {
17
- return;
18
- }
19
- if (tree.exists((0, devkit_1.joinPathFragments)(project.root, 'DockerFile'))) {
20
- devkit_1.logger.info(`Skipping setup since a Dockerfile already exists inside ${project.root}`);
21
- }
22
- else {
23
- const outputPath = project.targets[`${options.buildTarget}`]?.options.outputPath;
24
- (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, './files'), project.root, {
25
- tmpl: '',
26
- app: project.sourceRoot,
27
- buildLocation: outputPath,
28
- project: options.project,
29
- });
15
+ const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
16
+ if (!projectConfig) {
17
+ throw new Error(`Cannot find project configuration for ${options.project}`);
30
18
  }
19
+ (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, './files'), projectConfig.root, {
20
+ tmpl: '',
21
+ buildLocation: options.outputPath,
22
+ project: options.project,
23
+ });
31
24
  }
32
25
  function updateProjectConfig(tree, options) {
33
26
  let projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);