@nx/workspace 18.1.0-beta.2 → 18.1.0-beta.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/workspace",
3
- "version": "18.1.0-beta.2",
3
+ "version": "18.1.0-beta.4",
4
4
  "private": false,
5
5
  "description": "The Workspace plugin contains executors and generators that are useful for any Nx workspace. It should be present in every Nx workspace and other plugins build on it.",
6
6
  "repository": {
@@ -61,13 +61,13 @@
61
61
  }
62
62
  },
63
63
  "dependencies": {
64
- "@nx/devkit": "18.1.0-beta.2",
64
+ "@nx/devkit": "18.1.0-beta.4",
65
65
  "chalk": "^4.1.0",
66
66
  "enquirer": "~2.3.6",
67
67
  "tslib": "^2.3.0",
68
68
  "yargs-parser": "21.1.1",
69
- "nx": "18.1.0-beta.2",
70
- "@nrwl/workspace": "18.1.0-beta.2"
69
+ "nx": "18.1.0-beta.4",
70
+ "@nrwl/workspace": "18.1.0-beta.4"
71
71
  },
72
72
  "publishConfig": {
73
73
  "access": "public"
@@ -46,16 +46,15 @@ function normalizeOptions(options, tree) {
46
46
  };
47
47
  }
48
48
  function defaultBranchNeedsOriginPrefix(nxJson) {
49
- return !nxJson.affected?.defaultBase?.startsWith('origin/');
49
+ const base = nxJson.defaultBase ?? nxJson.affected?.defaultBase;
50
+ return !base?.startsWith('origin/');
50
51
  }
51
52
  function appendOriginPrefix(nxJson) {
52
- return {
53
- ...nxJson,
54
- affected: {
55
- ...(nxJson.affected ?? {}),
56
- defaultBase: nxJson.affected?.defaultBase
57
- ? `origin/${nxJson.affected.defaultBase}`
58
- : 'origin/main',
59
- },
60
- };
53
+ if (nxJson?.affected?.defaultBase) {
54
+ nxJson.affected.defaultBase = `origin/${nxJson.affected.defaultBase}`;
55
+ }
56
+ if (nxJson.defaultBase || !nxJson.affected) {
57
+ nxJson.defaultBase = `origin/${nxJson.defaultBase ?? (0, default_base_1.deduceDefaultBase)()}`;
58
+ }
59
+ return nxJson;
61
60
  }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.updateJestConfig = void 0;
4
4
  const path = require("path");
5
+ const jest_config_1 = require("../../utils/jest-config");
5
6
  /**
6
7
  * Updates the project name and coverage folder in the jest.config.js if it exists
7
8
  *
@@ -34,13 +35,14 @@ function updateJestConfig(tree, schema, project) {
34
35
  tree.write(jestConfigPath, newContent);
35
36
  }
36
37
  // update root jest.config.ts
37
- const rootJestConfigPath = '/jest.config.ts';
38
- if (!tree.exists(rootJestConfigPath)) {
38
+ const rootJestConfigPath = (0, jest_config_1.findRootJestConfig)(tree);
39
+ if (!rootJestConfigPath || !tree.exists(rootJestConfigPath)) {
39
40
  return;
40
41
  }
41
42
  const findProject = `'<rootDir>/${project.root}'`;
42
43
  const oldRootJestConfigContent = tree.read(rootJestConfigPath, 'utf-8');
43
- const usingJestProjects = oldRootJestConfigContent.includes('getJestProjects()');
44
+ const usingJestProjects = oldRootJestConfigContent.includes('getJestProjects()') ||
45
+ oldRootJestConfigContent.includes('getJestProjectsAsync()');
44
46
  const newRootJestConfigContent = oldRootJestConfigContent.replace(findProject, usingJestProjects ? `` : `'<rootDir>/${schema.relativeToRootDestination}'`);
45
47
  tree.write(rootJestConfigPath, newRootJestConfigContent);
46
48
  }
@@ -2,52 +2,71 @@
2
2
 
3
3
  <a alt="Nx logo" href="https://nx.dev" target="_blank" rel="noreferrer"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-logo.png" width="45"></a>
4
4
 
5
- ✨ **This workspace has been generated by [Nx, Smart Monorepos · Fast CI.](https://nx.dev)** ✨<% if (!!appName) { %>
5
+ ✨ **This workspace has been generated by [Nx, Smart Monorepos · Fast CI.](https://nx.dev)**
6
6
 
7
- <% if (includeServe) { %>
8
- ## Start the app
7
+ ## Integrate with editors
9
8
 
10
- To start the development server run `nx serve <%= appName %>`. Open your browser and navigate to http://localhost:4200/. Happy coding!<% } %>
11
- <% } %>
9
+ Enhance your Nx experience by installing [Nx Console](https://nx.dev/nx-console) for your favorite editor. Nx Console
10
+ provides an interactive UI to view your projects, run tasks, generate code, and more! Available for VSCode, IntelliJ and
11
+ comes with a LSP for Vim users.
12
+ <% if (!!appName) {
13
+ if (isJsStandalone) { %>
14
+ ## Build the library
15
+
16
+ Run `npx nx build` to build the library. The build artifacts are stored in the output directory (i.e. `dist/`), ready to be published.
17
+ <% } else { %>
18
+ ## Start the application
19
+
20
+ Run `npx nx <%= serveCommand %> <%= appName %>` to start the development server. Happy coding!
21
+
22
+ ## Build for production
12
23
 
13
- ## Generate code
24
+ Run `npx nx build <%= appName %>` to build the application. The build artifacts are stored in the output directory (e.g. `dist/` or `build/`), ready to be deployed.
25
+ <% } } else { %>
26
+ ## Nx plugins and code generators
14
27
 
15
- If you happen to use Nx plugins, you can leverage code generators that might come with it.
28
+ Add Nx plugins to leverage their code generators and automated, inferred tasks.
16
29
 
17
- Run `nx list` to get a list of available plugins and whether they have generators. Then run `nx list <plugin-name>` to see what generators are available.
30
+ ```
31
+ # Add plugin
32
+ npx nx add @nx/react
33
+
34
+ # Use code generator
35
+ npx nx generate @nx/react:app demo
18
36
 
19
- Learn more about [Nx generators on the docs](https://nx.dev/features/generate-code).
37
+ # Run development server
38
+ npx nx serve demo
39
+
40
+ # View project details
41
+ npx nx show project demo --web
42
+ ```
20
43
 
44
+ Run `npx nx list` to get a list of available plugins and whether they have generators. Then run `npx nx list <plugin-name>` to see what generators are available.
45
+
46
+ Learn more about [code generators](https://nx.dev/features/generate-code) and [inferred tasks](https://nx.dev/concepts/inferred-tasks) in the docs.
47
+ <% } %>
21
48
  ## Running tasks
22
49
 
23
50
  To execute tasks with Nx use the following syntax:
24
51
 
25
52
  ```
26
- nx <target> <project> <...options>
53
+ npx nx <target> <project> <...options>
27
54
  ```
28
55
 
29
56
  You can also run multiple targets:
30
57
 
31
58
  ```
32
- nx run-many -t <target1> <target2>
59
+ npx nx run-many -t <target1> <target2>
33
60
  ```
34
61
 
35
62
  ..or add `-p` to filter specific projects
36
63
 
37
64
  ```
38
- nx run-many -t <target1> <target2> -p <proj1> <proj2>
65
+ npx nx run-many -t <target1> <target2> -p <proj1> <proj2>
39
66
  ```
40
67
 
41
68
  Targets can be defined in the `package.json` or `projects.json`. Learn more [in the docs](https://nx.dev/features/run-tasks).
42
69
 
43
- ## Want better Editor Integration?
44
-
45
- Have a look at the [Nx Console extensions](https://nx.dev/nx-console). It provides autocomplete support, a UI for exploring and running tasks & generators, and more! Available for VSCode, IntelliJ and comes with a LSP for Vim users.
46
-
47
- ## Ready to deploy?
48
-
49
- Just run `nx build demoapp` to build the application. The build artifacts will be stored in the `dist/` directory, ready to be deployed.
50
-
51
70
  ## Set up CI!
52
71
 
53
72
  Nx comes with local caching already built-in (check your `nx.json`). On CI you might want to go a step further.
@@ -56,8 +75,9 @@ Nx comes with local caching already built-in (check your `nx.json`). On CI you m
56
75
  - [Set up task distribution across multiple machines](https://nx.dev/nx-cloud/features/distribute-task-execution)
57
76
  - [Learn more how to setup CI](https://nx.dev/recipes/ci)
58
77
 
59
- ## Explore the Project Graph
60
- Run `nx graph` to show the graph of the workspace.
78
+ ## Explore the project graph
79
+
80
+ Run `npx nx graph` to show the graph of the workspace.
61
81
  It will show tasks that you can run with Nx.
62
82
 
63
83
  - [Learn more about Exploring the Project Graph](https://nx.dev/core-features/explore-graph)
@@ -67,6 +67,7 @@ function generatePreset(host, opts) {
67
67
  ? `--e2eTestRunner=${opts.e2eTestRunner}`
68
68
  : null,
69
69
  opts.ssr ? `--ssr` : null,
70
+ opts.prefix !== undefined ? `--prefix=${opts.prefix}` : null,
70
71
  ].filter((e) => !!e);
71
72
  }
72
73
  }
@@ -45,9 +45,7 @@ function setPresetProperty(tree, options) {
45
45
  function createNxJson(tree, { directory, defaultBase, preset }) {
46
46
  const nxJson = {
47
47
  $schema: './node_modules/nx/schemas/nx-schema.json',
48
- affected: {
49
- defaultBase,
50
- },
48
+ defaultBase,
51
49
  targetDefaults: process.env.NX_ADD_PLUGINS === 'false'
52
50
  ? {
53
51
  build: {
@@ -61,7 +59,7 @@ function createNxJson(tree, { directory, defaultBase, preset }) {
61
59
  : undefined,
62
60
  };
63
61
  if (defaultBase === 'main') {
64
- delete nxJson.affected;
62
+ delete nxJson.defaultBase;
65
63
  }
66
64
  if (preset !== presets_1.Preset.NPM) {
67
65
  nxJson.namedInputs = {
@@ -71,6 +69,7 @@ function createNxJson(tree, { directory, defaultBase, preset }) {
71
69
  };
72
70
  if (process.env.NX_ADD_PLUGINS === 'false') {
73
71
  nxJson.targetDefaults.build.inputs = ['production', '^production'];
72
+ nxJson.useInferencePlugins = false;
74
73
  }
75
74
  }
76
75
  (0, devkit_1.writeJson)(tree, (0, path_1.join)(directory, 'nx.json'), nxJson);
@@ -103,8 +102,11 @@ function createReadme(tree, { name, appName, directory, preset }) {
103
102
  const formattedNames = (0, devkit_1.names)(name);
104
103
  (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, './files-readme'), directory, {
105
104
  formattedNames,
106
- includeServe: preset !== presets_1.Preset.TsStandalone,
105
+ isJsStandalone: preset === presets_1.Preset.TsStandalone,
107
106
  appName,
107
+ serveCommand: preset === presets_1.Preset.NextJs || preset === presets_1.Preset.NextJsStandalone
108
+ ? 'dev'
109
+ : 'serve',
108
110
  name,
109
111
  });
110
112
  }
@@ -121,8 +123,7 @@ function addNpmScripts(tree, options) {
121
123
  options.preset === presets_1.Preset.ReactStandalone ||
122
124
  options.preset === presets_1.Preset.VueStandalone ||
123
125
  options.preset === presets_1.Preset.NuxtStandalone ||
124
- options.preset === presets_1.Preset.NodeStandalone ||
125
- options.preset === presets_1.Preset.NextJsStandalone) {
126
+ options.preset === presets_1.Preset.NodeStandalone) {
126
127
  (0, devkit_1.updateJson)(tree, (0, path_1.join)(options.directory, 'package.json'), (json) => {
127
128
  Object.assign(json.scripts, {
128
129
  start: 'nx serve',
@@ -132,6 +133,17 @@ function addNpmScripts(tree, options) {
132
133
  return json;
133
134
  });
134
135
  }
136
+ if (options.preset === presets_1.Preset.NextJsStandalone) {
137
+ (0, devkit_1.updateJson)(tree, (0, path_1.join)(options.directory, 'package.json'), (json) => {
138
+ Object.assign(json.scripts, {
139
+ dev: 'nx dev',
140
+ build: 'nx build',
141
+ start: 'nx start',
142
+ test: 'nx test',
143
+ });
144
+ return json;
145
+ });
146
+ }
135
147
  if (options.preset === presets_1.Preset.TsStandalone) {
136
148
  (0, devkit_1.updateJson)(tree, (0, path_1.join)(options.directory, 'package.json'), (json) => {
137
149
  Object.assign(json.scripts, {
@@ -20,6 +20,7 @@ interface Schema {
20
20
  packageManager?: PackageManager;
21
21
  e2eTestRunner?: 'cypress' | 'playwright' | 'detox' | 'jest' | 'none';
22
22
  ssr?: boolean;
23
+ prefix?: string;
23
24
  }
24
25
  export interface NormalizedSchema extends Schema {
25
26
  presetVersion?: string;
@@ -82,6 +82,10 @@
82
82
  "description": "Enable Server-Side Rendering (SSR) and Static Site Generation (SSG/Prerendering) for the Angular application.",
83
83
  "type": "boolean",
84
84
  "default": false
85
+ },
86
+ "prefix": {
87
+ "description": "The prefix to use for Angular component and directive selectors.",
88
+ "type": "string"
85
89
  }
86
90
  },
87
91
  "additionalProperties": true
@@ -16,7 +16,12 @@ async function presetGenerator(tree, options) {
16
16
  exports.presetGenerator = presetGenerator;
17
17
  exports.default = presetGenerator;
18
18
  async function createPreset(tree, options) {
19
- const addPlugin = process.env.NX_ADD_PLUGINS !== 'false';
19
+ console.log('Crate preset');
20
+ const nxJson = (0, devkit_1.readNxJson)(tree);
21
+ const addPlugin = process.env.NX_ADD_PLUGINS !== 'false' &&
22
+ nxJson.useInferencePlugins !== false;
23
+ console.log('Add plugin', addPlugin);
24
+ console.log(options.preset, presets_1.Preset.ReactNative);
20
25
  if (options.preset === presets_1.Preset.Apps) {
21
26
  return;
22
27
  }
@@ -33,6 +38,7 @@ async function createPreset(tree, options) {
33
38
  e2eTestRunner: options.e2eTestRunner ?? 'cypress',
34
39
  bundler: options.bundler,
35
40
  ssr: options.ssr,
41
+ prefix: options.prefix,
36
42
  });
37
43
  }
38
44
  else if (options.preset === presets_1.Preset.AngularStandalone) {
@@ -49,6 +55,7 @@ async function createPreset(tree, options) {
49
55
  e2eTestRunner: options.e2eTestRunner ?? 'cypress',
50
56
  bundler: options.bundler,
51
57
  ssr: options.ssr,
58
+ prefix: options.prefix,
52
59
  });
53
60
  }
54
61
  else if (options.preset === presets_1.Preset.ReactMonorepo) {
@@ -206,8 +213,11 @@ async function createPreset(tree, options) {
206
213
  });
207
214
  }
208
215
  else if (options.preset === presets_1.Preset.ReactNative) {
216
+ console.log('Before require');
209
217
  const { reactNativeApplicationGenerator } = require('@nx' +
210
218
  '/react-native');
219
+ console.log('Hello', reactNativeApplicationGenerator);
220
+ console.log('Active require');
211
221
  return reactNativeApplicationGenerator(tree, {
212
222
  name: options.name,
213
223
  directory: (0, path_1.join)('apps', options.name),
@@ -18,4 +18,5 @@ export interface Schema {
18
18
  e2eTestRunner?: 'cypress' | 'playwright' | 'jest' | 'detox' | 'none';
19
19
  js?: boolean;
20
20
  ssr?: boolean;
21
+ prefix?: string;
21
22
  }
@@ -99,6 +99,10 @@
99
99
  "description": "Enable Server-Side Rendering (SSR) and Static Site Generation (SSG/Prerendering) for the Angular application.",
100
100
  "type": "boolean",
101
101
  "default": false
102
+ },
103
+ "prefix": {
104
+ "description": "The prefix to use for Angular component and directive selectors.",
105
+ "type": "string"
102
106
  }
103
107
  },
104
108
  "required": ["preset", "name"]
@@ -5,9 +5,16 @@ const devkit_1 = require("@nx/devkit");
5
5
  const get_source_nodes_1 = require("../../../utilities/typescript/get-source-nodes");
6
6
  const path_1 = require("path");
7
7
  const typescript_1 = require("../../../utilities/typescript");
8
+ const jest_config_1 = require("../../utils/jest-config");
8
9
  let tsModule;
9
10
  function isUsingUtilityFunction(host) {
10
- return host.read('jest.config.ts').toString().includes('getJestProjects()');
11
+ const rootConfigPath = (0, jest_config_1.findRootJestConfig)(host);
12
+ if (!rootConfigPath) {
13
+ return false;
14
+ }
15
+ const rootConfig = host.read(rootConfigPath, 'utf-8');
16
+ return (rootConfig.includes('getJestProjects()') ||
17
+ rootConfig.includes('getJestProjectsAsync()'));
11
18
  }
12
19
  /**
13
20
  * in a standalone project, the root jest.config.ts is a project config instead
@@ -15,7 +22,11 @@ function isUsingUtilityFunction(host) {
15
22
  * in that case we do not need to edit it to remove it
16
23
  **/
17
24
  function isMonorepoConfig(tree) {
18
- return tree.read('jest.config.ts', 'utf-8').includes('projects:');
25
+ const rootConfigPath = (0, jest_config_1.findRootJestConfig)(tree);
26
+ if (!rootConfigPath) {
27
+ return false;
28
+ }
29
+ return tree.read(rootConfigPath, 'utf-8').includes('projects:');
19
30
  }
20
31
  /**
21
32
  * Updates the root jest config projects array and removes the project.
@@ -26,14 +37,15 @@ function updateJestConfig(tree, schema, projectConfig) {
26
37
  }
27
38
  const { createSourceFile, ScriptTarget, isPropertyAssignment, isArrayLiteralExpression, isStringLiteral, } = tsModule;
28
39
  const projectToRemove = schema.projectName;
29
- if (!tree.exists('jest.config.ts') ||
40
+ const rootConfigPath = (0, jest_config_1.findRootJestConfig)(tree);
41
+ if (!tree.exists(rootConfigPath) ||
30
42
  !tree.exists((0, path_1.join)(projectConfig.root, 'jest.config.ts')) ||
31
43
  isUsingUtilityFunction(tree) ||
32
44
  !isMonorepoConfig(tree)) {
33
45
  return;
34
46
  }
35
- const contents = tree.read('jest.config.ts', 'utf-8');
36
- const sourceFile = createSourceFile('jest.config.ts', contents, ScriptTarget.Latest);
47
+ const contents = tree.read(rootConfigPath, 'utf-8');
48
+ const sourceFile = createSourceFile(rootConfigPath, contents, ScriptTarget.Latest);
37
49
  const sourceNodes = (0, get_source_nodes_1.getSourceNodes)(sourceFile);
38
50
  const projectsAssignment = sourceNodes.find((node) => isPropertyAssignment(node) &&
39
51
  node.name.getText(sourceFile) === 'projects' &&
@@ -52,7 +64,7 @@ function updateJestConfig(tree, schema, projectConfig) {
52
64
  const start = previousProject
53
65
  ? previousProject.getEnd()
54
66
  : project.getStart(sourceFile);
55
- tree.write('jest.config.ts', (0, devkit_1.applyChangesToString)(contents, [
67
+ tree.write(rootConfigPath, (0, devkit_1.applyChangesToString)(contents, [
56
68
  {
57
69
  type: devkit_1.ChangeType.Delete,
58
70
  start,
@@ -0,0 +1,2 @@
1
+ import type { Tree } from '@nx/devkit';
2
+ export declare function findRootJestConfig(tree: Tree): string | null;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findRootJestConfig = void 0;
4
+ function findRootJestConfig(tree) {
5
+ if (tree.exists('jest.config.js')) {
6
+ return 'jest.config.js';
7
+ }
8
+ if (tree.exists('jest.config.ts')) {
9
+ return 'jest.config.ts';
10
+ }
11
+ return null;
12
+ }
13
+ exports.findRootJestConfig = findRootJestConfig;