@nx/devkit 17.1.0-beta.0 → 17.1.0-beta.3

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,8 +1,8 @@
1
1
  {
2
2
  "name": "@nx/devkit",
3
- "version": "17.1.0-beta.0",
3
+ "version": "17.1.0-beta.3",
4
4
  "private": false,
5
- "description": "The Nx Devkit is used to customize Nx for different technologies and use cases. It contains many utility functions for reading and writing files, updating configuration, working with Abstract Syntax Trees(ASTs), and more.",
5
+ "description": "The Nx Devkit is used to customize Nx for different technologies and use cases. It contains many utility functions for reading and writing files, updating configuration, working with Abstract Syntax Trees(ASTs), and more. Learn more about [extending Nx by leveraging the Nx Devkit](https://nx.dev/extending-nx/intro/getting-started) on our docs.",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/nrwl/nx.git",
@@ -34,7 +34,7 @@
34
34
  "tmp": "~0.2.1",
35
35
  "tslib": "^2.3.0",
36
36
  "semver": "7.5.3",
37
- "@nrwl/devkit": "17.1.0-beta.0"
37
+ "@nrwl/devkit": "17.1.0-beta.3"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "nx": ">= 16 <= 18"
@@ -42,7 +42,7 @@ function validateName(name, projectNameAndRootFormat) {
42
42
  }
43
43
  }
44
44
  function getExample(callingGenerator, formats) {
45
- return `Example: nx g ${callingGenerator} ${formats['as-provided'].projectName} --directory ${formats['as-provided'].projectRoot}`;
45
+ return `Example: nx g ${callingGenerator} ${formats['derived'].projectName} --directory ${formats['derived'].projectRoot}`;
46
46
  }
47
47
  async function determineFormat(tree, formats, callingGenerator) {
48
48
  if (!formats.derived) {
@@ -0,0 +1,8 @@
1
+ import type { CreateNodesContext } from 'nx/src/devkit-exports';
2
+ import type { InputDefinition } from 'nx/src/config/workspace-json-project-json';
3
+ /**
4
+ * Get the named inputs available for a directory
5
+ */
6
+ export declare function getNamedInputs(directory: string, context: CreateNodesContext): {
7
+ [inputName: string]: (string | InputDefinition)[];
8
+ };
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getNamedInputs = void 0;
4
+ const path_1 = require("path");
5
+ const fs_1 = require("fs");
6
+ const nx_1 = require("../../nx");
7
+ const { readJsonFile } = (0, nx_1.requireNx)();
8
+ /**
9
+ * Get the named inputs available for a directory
10
+ */
11
+ function getNamedInputs(directory, context) {
12
+ const projectJsonPath = (0, path_1.join)(directory, 'project.json');
13
+ const projectJson = (0, fs_1.existsSync)(projectJsonPath)
14
+ ? readJsonFile(projectJsonPath)
15
+ : null;
16
+ const packageJsonPath = (0, path_1.join)(directory, 'package.json');
17
+ const packageJson = (0, fs_1.existsSync)(packageJsonPath)
18
+ ? readJsonFile(packageJsonPath)
19
+ : null;
20
+ return {
21
+ ...context.nxJsonConfiguration.namedInputs,
22
+ ...packageJson?.nx?.namedInputs,
23
+ ...projectJson?.namedInputs,
24
+ };
25
+ }
26
+ exports.getNamedInputs = getNamedInputs;
@@ -0,0 +1,3 @@
1
+ import type { Tree } from 'nx/src/generators/tree';
2
+ import type { CreateNodes } from 'nx/src/utils/nx-plugin';
3
+ export declare function replaceProjectConfigurationsWithPlugin<T = unknown>(tree: Tree, rootMappings: Map<string, string>, pluginPath: string, createNodes: CreateNodes<T>, pluginOptions: T): void;
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.replaceProjectConfigurationsWithPlugin = void 0;
4
+ const nx_1 = require("../../nx");
5
+ const { readNxJson, updateNxJson, glob, hashObject, findProjectForPath, readProjectConfiguration, updateProjectConfiguration, } = (0, nx_1.requireNx)();
6
+ function replaceProjectConfigurationsWithPlugin(tree, rootMappings, pluginPath, createNodes, pluginOptions) {
7
+ const nxJson = readNxJson(tree);
8
+ const hasPlugin = nxJson.plugins?.some((p) => typeof p === 'string' ? p === pluginPath : p.plugin === pluginPath);
9
+ if (hasPlugin) {
10
+ return;
11
+ }
12
+ nxJson.plugins ??= [];
13
+ nxJson.plugins.push({
14
+ plugin: pluginPath,
15
+ options: pluginOptions,
16
+ });
17
+ updateNxJson(tree, nxJson);
18
+ const [pluginGlob, createNodesFunction] = createNodes;
19
+ const configFiles = glob(tree, [pluginGlob]);
20
+ for (const configFile of configFiles) {
21
+ try {
22
+ const projectName = findProjectForPath(configFile, rootMappings);
23
+ const projectConfig = readProjectConfiguration(tree, projectName);
24
+ const nodes = createNodesFunction(configFile, pluginOptions, {
25
+ workspaceRoot: tree.root,
26
+ nxJsonConfiguration: readNxJson(tree),
27
+ });
28
+ const node = nodes.projects[Object.keys(nodes.projects)[0]];
29
+ for (const [targetName, targetConfig] of Object.entries(node.targets)) {
30
+ const targetFromProjectConfig = projectConfig.targets[targetName];
31
+ if (targetFromProjectConfig.executor !== targetConfig.executor) {
32
+ continue;
33
+ }
34
+ const targetFromCreateNodes = node.targets[targetName];
35
+ removeConfigurationDefinedByPlugin(targetName, targetFromProjectConfig, targetFromCreateNodes, projectConfig);
36
+ }
37
+ updateProjectConfiguration(tree, projectName, projectConfig);
38
+ }
39
+ catch (e) {
40
+ console.error(e);
41
+ }
42
+ }
43
+ }
44
+ exports.replaceProjectConfigurationsWithPlugin = replaceProjectConfigurationsWithPlugin;
45
+ function removeConfigurationDefinedByPlugin(targetName, targetFromProjectConfig, targetFromCreateNodes, projectConfig) {
46
+ // Executor
47
+ delete targetFromProjectConfig.executor;
48
+ // Default Configuration
49
+ if (targetFromProjectConfig.defaultConfiguration ===
50
+ targetFromCreateNodes.defaultConfiguration) {
51
+ delete targetFromProjectConfig.defaultConfiguration;
52
+ }
53
+ // Cache
54
+ if (targetFromProjectConfig.cache === targetFromCreateNodes.cache) {
55
+ delete targetFromProjectConfig.cache;
56
+ }
57
+ // Depends On
58
+ if (targetFromProjectConfig.dependsOn &&
59
+ shouldRemoveArrayProperty(targetFromProjectConfig.dependsOn, targetFromCreateNodes.dependsOn)) {
60
+ delete targetFromProjectConfig.dependsOn;
61
+ }
62
+ // Outputs
63
+ if (targetFromProjectConfig.outputs &&
64
+ shouldRemoveArrayProperty(targetFromProjectConfig.outputs, targetFromCreateNodes.outputs)) {
65
+ delete targetFromProjectConfig.outputs;
66
+ }
67
+ // Inputs
68
+ if (targetFromProjectConfig.inputs &&
69
+ shouldRemoveArrayProperty(targetFromProjectConfig.inputs, targetFromCreateNodes.inputs)) {
70
+ delete targetFromProjectConfig.inputs;
71
+ }
72
+ // Options
73
+ for (const [optionName, optionValue] of Object.entries(targetFromProjectConfig.options ?? {})) {
74
+ if (targetFromCreateNodes.options[optionName] === optionValue) {
75
+ delete targetFromProjectConfig.options[optionName];
76
+ }
77
+ }
78
+ if (Object.keys(targetFromProjectConfig.options).length === 0) {
79
+ delete targetFromProjectConfig.options;
80
+ }
81
+ // Configurations
82
+ for (const [configName, configOptions] of Object.entries(targetFromProjectConfig.configurations ?? {})) {
83
+ for (const [optionName, optionValue] of Object.entries(configOptions)) {
84
+ if (targetFromCreateNodes.configurations?.[configName]?.[optionName] ===
85
+ optionValue) {
86
+ delete targetFromProjectConfig.configurations[configName][optionName];
87
+ }
88
+ }
89
+ if (Object.keys(configOptions).length === 0) {
90
+ delete targetFromProjectConfig.configurations[configName];
91
+ }
92
+ }
93
+ if (Object.keys(targetFromProjectConfig.configurations ?? {}).length === 0) {
94
+ delete targetFromProjectConfig.configurations;
95
+ }
96
+ if (Object.keys(targetFromProjectConfig).length === 0) {
97
+ delete projectConfig.targets[targetName];
98
+ }
99
+ }
100
+ function shouldRemoveArrayProperty(arrayValuesFromProjectConfiguration, arrayValuesFromCreateNodes) {
101
+ const setOfArrayValuesFromProjectConfiguration = new Set(arrayValuesFromProjectConfiguration);
102
+ loopThroughArrayValuesFromCreateNodes: for (const arrayValueFromCreateNodes of arrayValuesFromCreateNodes) {
103
+ if (typeof arrayValueFromCreateNodes === 'string') {
104
+ if (!setOfArrayValuesFromProjectConfiguration.has(arrayValueFromCreateNodes)) {
105
+ // If the inputs from the project configuration is missing an input from createNodes it was removed
106
+ return false;
107
+ }
108
+ else {
109
+ setOfArrayValuesFromProjectConfiguration.delete(arrayValueFromCreateNodes);
110
+ }
111
+ }
112
+ else {
113
+ for (const arrayValue of setOfArrayValuesFromProjectConfiguration.values()) {
114
+ if (typeof arrayValue !== 'string' &&
115
+ hashObject(arrayValue) === hashObject(arrayValueFromCreateNodes)) {
116
+ setOfArrayValuesFromProjectConfiguration.delete(arrayValue);
117
+ // Continue the outer loop, breaking out of this loop
118
+ continue loopThroughArrayValuesFromCreateNodes;
119
+ }
120
+ }
121
+ // If an input was not matched, that means the input was removed
122
+ return false;
123
+ }
124
+ }
125
+ // If there are still inputs in the project configuration, they have added additional inputs
126
+ return setOfArrayValuesFromProjectConfiguration.size === 0;
127
+ }
@@ -1 +1 @@
1
- export declare const typescriptVersion = "~5.1.3";
1
+ export declare const typescriptVersion = "~5.2.2";
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.typescriptVersion = void 0;
4
- exports.typescriptVersion = '~5.1.3';
4
+ exports.typescriptVersion = '~5.2.2';