nx 19.4.1 → 19.5.0-beta.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,108 @@
1
+ import {
2
+ instantiateNapiModuleSync as __emnapiInstantiateNapiModuleSync,
3
+ getDefaultContext as __emnapiGetDefaultContext,
4
+ WASI as __WASI,
5
+ createOnMessage as __wasmCreateOnMessageForFsProxy,
6
+ } from '@napi-rs/wasm-runtime'
7
+
8
+ import __wasmUrl from './nx.wasm32-wasi.wasm?url'
9
+
10
+ const __wasi = new __WASI({
11
+ version: 'preview1',
12
+ })
13
+
14
+ const __emnapiContext = __emnapiGetDefaultContext()
15
+
16
+ const __sharedMemory = new WebAssembly.Memory({
17
+ initial: 16384,
18
+ maximum: 32768,
19
+ shared: true,
20
+ })
21
+
22
+ const __wasmFile = await fetch(__wasmUrl).then((res) => res.arrayBuffer())
23
+
24
+ const {
25
+ instance: __napiInstance,
26
+ module: __wasiModule,
27
+ napiModule: __napiModule,
28
+ } = __emnapiInstantiateNapiModuleSync(__wasmFile, {
29
+ context: __emnapiContext,
30
+ asyncWorkPoolSize: 4,
31
+ wasi: __wasi,
32
+ onCreateWorker() {
33
+ const worker = new Worker(new URL('./wasi-worker-browser.mjs', import.meta.url), {
34
+ type: 'module',
35
+ })
36
+
37
+ return worker
38
+ },
39
+ overwriteImports(importObject) {
40
+ importObject.env = {
41
+ ...importObject.env,
42
+ ...importObject.napi,
43
+ ...importObject.emnapi,
44
+ memory: __sharedMemory,
45
+ }
46
+ return importObject
47
+ },
48
+ beforeInit({ instance }) {
49
+ __napi_rs_initialize_modules(instance)
50
+ },
51
+ })
52
+
53
+ function __napi_rs_initialize_modules(__napiInstance) {
54
+ __napiInstance.exports['__napi_register__expand_outputs_0']?.()
55
+ __napiInstance.exports['__napi_register__get_files_for_outputs_1']?.()
56
+ __napiInstance.exports['__napi_register__remove_2']?.()
57
+ __napiInstance.exports['__napi_register__copy_3']?.()
58
+ __napiInstance.exports['__napi_register__hash_array_4']?.()
59
+ __napiInstance.exports['__napi_register__hash_file_5']?.()
60
+ __napiInstance.exports['__napi_register__ImportResult_struct_6']?.()
61
+ __napiInstance.exports['__napi_register__find_imports_7']?.()
62
+ __napiInstance.exports['__napi_register__transfer_project_graph_8']?.()
63
+ __napiInstance.exports['__napi_register__ExternalNode_struct_9']?.()
64
+ __napiInstance.exports['__napi_register__Target_struct_10']?.()
65
+ __napiInstance.exports['__napi_register__Project_struct_11']?.()
66
+ __napiInstance.exports['__napi_register__ProjectGraph_struct_12']?.()
67
+ __napiInstance.exports['__napi_register__HashPlanner_struct_13']?.()
68
+ __napiInstance.exports['__napi_register__HashPlanner_impl_17']?.()
69
+ __napiInstance.exports['__napi_register__HashDetails_struct_18']?.()
70
+ __napiInstance.exports['__napi_register__HasherOptions_struct_19']?.()
71
+ __napiInstance.exports['__napi_register__TaskHasher_struct_20']?.()
72
+ __napiInstance.exports['__napi_register__TaskHasher_impl_23']?.()
73
+ __napiInstance.exports['__napi_register__Task_struct_24']?.()
74
+ __napiInstance.exports['__napi_register__TaskTarget_struct_25']?.()
75
+ __napiInstance.exports['__napi_register__TaskGraph_struct_26']?.()
76
+ __napiInstance.exports['__napi_register__FileData_struct_27']?.()
77
+ __napiInstance.exports['__napi_register__InputsInput_struct_28']?.()
78
+ __napiInstance.exports['__napi_register__FileSetInput_struct_29']?.()
79
+ __napiInstance.exports['__napi_register__RuntimeInput_struct_30']?.()
80
+ __napiInstance.exports['__napi_register__EnvironmentInput_struct_31']?.()
81
+ __napiInstance.exports['__napi_register__ExternalDependenciesInput_struct_32']?.()
82
+ __napiInstance.exports['__napi_register__DepsOutputsInput_struct_33']?.()
83
+ __napiInstance.exports['__napi_register__NxJson_struct_34']?.()
84
+ __napiInstance.exports['__napi_register__WorkspaceContext_struct_35']?.()
85
+ __napiInstance.exports['__napi_register__WorkspaceContext_impl_44']?.()
86
+ __napiInstance.exports['__napi_register__WorkspaceErrors_45']?.()
87
+ __napiInstance.exports['__napi_register__NxWorkspaceFiles_struct_46']?.()
88
+ __napiInstance.exports['__napi_register__NxWorkspaceFilesExternals_struct_47']?.()
89
+ __napiInstance.exports['__napi_register__UpdatedWorkspaceFiles_struct_48']?.()
90
+ __napiInstance.exports['__napi_register__FileMap_struct_49']?.()
91
+ __napiInstance.exports['__napi_register____test_only_transfer_file_map_50']?.()
92
+ __napiInstance.exports['__napi_register__IS_WASM_51']?.()
93
+ }
94
+ export const HashPlanner = __napiModule.exports.HashPlanner
95
+ export const ImportResult = __napiModule.exports.ImportResult
96
+ export const TaskHasher = __napiModule.exports.TaskHasher
97
+ export const WorkspaceContext = __napiModule.exports.WorkspaceContext
98
+ export const copy = __napiModule.exports.copy
99
+ export const expandOutputs = __napiModule.exports.expandOutputs
100
+ export const findImports = __napiModule.exports.findImports
101
+ export const getFilesForOutputs = __napiModule.exports.getFilesForOutputs
102
+ export const hashArray = __napiModule.exports.hashArray
103
+ export const hashFile = __napiModule.exports.hashFile
104
+ export const IS_WASM = __napiModule.exports.IS_WASM
105
+ export const remove = __napiModule.exports.remove
106
+ export const testOnlyTransferFileMap = __napiModule.exports.testOnlyTransferFileMap
107
+ export const transferProjectGraph = __napiModule.exports.transferProjectGraph
108
+ export const WorkspaceErrors = __napiModule.exports.WorkspaceErrors
@@ -0,0 +1,139 @@
1
+ /* eslint-disable */
2
+ /* prettier-ignore */
3
+
4
+ /* auto-generated by NAPI-RS */
5
+
6
+ const __nodeFs = require('node:fs')
7
+ const __nodePath = require('node:path')
8
+ const { WASI: __nodeWASI } = require('node:wasi')
9
+ const { Worker } = require('node:worker_threads')
10
+
11
+ const {
12
+ instantiateNapiModuleSync: __emnapiInstantiateNapiModuleSync,
13
+ getDefaultContext: __emnapiGetDefaultContext,
14
+ createOnMessage: __wasmCreateOnMessageForFsProxy,
15
+ } = require('@napi-rs/wasm-runtime')
16
+
17
+ const __rootDir = __nodePath.parse(process.cwd()).root
18
+
19
+ const __wasi = new __nodeWASI({
20
+ version: 'preview1',
21
+ env: process.env,
22
+ preopens: {
23
+ [__rootDir]: __rootDir,
24
+ }
25
+ })
26
+
27
+ const __emnapiContext = __emnapiGetDefaultContext()
28
+
29
+ const __sharedMemory = new WebAssembly.Memory({
30
+ initial: 16384,
31
+ maximum: 32768,
32
+ shared: true,
33
+ })
34
+
35
+ let __wasmFilePath = __nodePath.join(__dirname, 'nx.wasm32-wasi.wasm')
36
+ const __wasmDebugFilePath = __nodePath.join(__dirname, 'nx.wasm32-wasi.debug.wasm')
37
+
38
+ if (__nodeFs.existsSync(__wasmDebugFilePath)) {
39
+ __wasmFilePath = __wasmDebugFilePath
40
+ } else if (!__nodeFs.existsSync(__wasmFilePath)) {
41
+ try {
42
+ __wasmFilePath = __nodePath.resolve('@nx/nx-wasm32-wasi')
43
+ } catch {
44
+ throw new Error('Cannot find nx.wasm32-wasi.wasm file, and @nx/nx-wasm32-wasi package is not installed.')
45
+ }
46
+ }
47
+
48
+ const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule } = __emnapiInstantiateNapiModuleSync(__nodeFs.readFileSync(__wasmFilePath), {
49
+ context: __emnapiContext,
50
+ asyncWorkPoolSize: (function() {
51
+ const threadsSizeFromEnv = Number(process.env.NAPI_RS_ASYNC_WORK_POOL_SIZE ?? process.env.UV_THREADPOOL_SIZE)
52
+ // NaN > 0 is false
53
+ if (threadsSizeFromEnv > 0) {
54
+ return threadsSizeFromEnv
55
+ } else {
56
+ return 4
57
+ }
58
+ })(),
59
+ wasi: __wasi,
60
+ onCreateWorker() {
61
+ const worker = new Worker(__nodePath.join(__dirname, 'wasi-worker.mjs'), {
62
+ env: process.env,
63
+ execArgv: ['--experimental-wasi-unstable-preview1'],
64
+ })
65
+ worker.onmessage = ({ data }) => {
66
+ __wasmCreateOnMessageForFsProxy(__nodeFs)(data)
67
+ }
68
+ return worker
69
+ },
70
+ overwriteImports(importObject) {
71
+ importObject.env = {
72
+ ...importObject.env,
73
+ ...importObject.napi,
74
+ ...importObject.emnapi,
75
+ memory: __sharedMemory,
76
+ }
77
+ return importObject
78
+ },
79
+ beforeInit({ instance }) {
80
+ __napi_rs_initialize_modules(instance)
81
+ }
82
+ })
83
+
84
+ function __napi_rs_initialize_modules(__napiInstance) {
85
+ __napiInstance.exports['__napi_register__expand_outputs_0']?.()
86
+ __napiInstance.exports['__napi_register__get_files_for_outputs_1']?.()
87
+ __napiInstance.exports['__napi_register__remove_2']?.()
88
+ __napiInstance.exports['__napi_register__copy_3']?.()
89
+ __napiInstance.exports['__napi_register__hash_array_4']?.()
90
+ __napiInstance.exports['__napi_register__hash_file_5']?.()
91
+ __napiInstance.exports['__napi_register__ImportResult_struct_6']?.()
92
+ __napiInstance.exports['__napi_register__find_imports_7']?.()
93
+ __napiInstance.exports['__napi_register__transfer_project_graph_8']?.()
94
+ __napiInstance.exports['__napi_register__ExternalNode_struct_9']?.()
95
+ __napiInstance.exports['__napi_register__Target_struct_10']?.()
96
+ __napiInstance.exports['__napi_register__Project_struct_11']?.()
97
+ __napiInstance.exports['__napi_register__ProjectGraph_struct_12']?.()
98
+ __napiInstance.exports['__napi_register__HashPlanner_struct_13']?.()
99
+ __napiInstance.exports['__napi_register__HashPlanner_impl_17']?.()
100
+ __napiInstance.exports['__napi_register__HashDetails_struct_18']?.()
101
+ __napiInstance.exports['__napi_register__HasherOptions_struct_19']?.()
102
+ __napiInstance.exports['__napi_register__TaskHasher_struct_20']?.()
103
+ __napiInstance.exports['__napi_register__TaskHasher_impl_23']?.()
104
+ __napiInstance.exports['__napi_register__Task_struct_24']?.()
105
+ __napiInstance.exports['__napi_register__TaskTarget_struct_25']?.()
106
+ __napiInstance.exports['__napi_register__TaskGraph_struct_26']?.()
107
+ __napiInstance.exports['__napi_register__FileData_struct_27']?.()
108
+ __napiInstance.exports['__napi_register__InputsInput_struct_28']?.()
109
+ __napiInstance.exports['__napi_register__FileSetInput_struct_29']?.()
110
+ __napiInstance.exports['__napi_register__RuntimeInput_struct_30']?.()
111
+ __napiInstance.exports['__napi_register__EnvironmentInput_struct_31']?.()
112
+ __napiInstance.exports['__napi_register__ExternalDependenciesInput_struct_32']?.()
113
+ __napiInstance.exports['__napi_register__DepsOutputsInput_struct_33']?.()
114
+ __napiInstance.exports['__napi_register__NxJson_struct_34']?.()
115
+ __napiInstance.exports['__napi_register__WorkspaceContext_struct_35']?.()
116
+ __napiInstance.exports['__napi_register__WorkspaceContext_impl_44']?.()
117
+ __napiInstance.exports['__napi_register__WorkspaceErrors_45']?.()
118
+ __napiInstance.exports['__napi_register__NxWorkspaceFiles_struct_46']?.()
119
+ __napiInstance.exports['__napi_register__NxWorkspaceFilesExternals_struct_47']?.()
120
+ __napiInstance.exports['__napi_register__UpdatedWorkspaceFiles_struct_48']?.()
121
+ __napiInstance.exports['__napi_register__FileMap_struct_49']?.()
122
+ __napiInstance.exports['__napi_register____test_only_transfer_file_map_50']?.()
123
+ __napiInstance.exports['__napi_register__IS_WASM_51']?.()
124
+ }
125
+ module.exports.HashPlanner = __napiModule.exports.HashPlanner
126
+ module.exports.ImportResult = __napiModule.exports.ImportResult
127
+ module.exports.TaskHasher = __napiModule.exports.TaskHasher
128
+ module.exports.WorkspaceContext = __napiModule.exports.WorkspaceContext
129
+ module.exports.copy = __napiModule.exports.copy
130
+ module.exports.expandOutputs = __napiModule.exports.expandOutputs
131
+ module.exports.findImports = __napiModule.exports.findImports
132
+ module.exports.getFilesForOutputs = __napiModule.exports.getFilesForOutputs
133
+ module.exports.hashArray = __napiModule.exports.hashArray
134
+ module.exports.hashFile = __napiModule.exports.hashFile
135
+ module.exports.IS_WASM = __napiModule.exports.IS_WASM
136
+ module.exports.remove = __napiModule.exports.remove
137
+ module.exports.testOnlyTransferFileMap = __napiModule.exports.testOnlyTransferFileMap
138
+ module.exports.transferProjectGraph = __napiModule.exports.transferProjectGraph
139
+ module.exports.WorkspaceErrors = __napiModule.exports.WorkspaceErrors
Binary file
@@ -0,0 +1,32 @@
1
+ import { instantiateNapiModuleSync, MessageHandler, WASI } from '@napi-rs/wasm-runtime'
2
+
3
+ const handler = new MessageHandler({
4
+ onLoad({ wasmModule, wasmMemory }) {
5
+ const wasi = new WASI({
6
+ print: function () {
7
+ // eslint-disable-next-line no-console
8
+ console.log.apply(console, arguments)
9
+ },
10
+ printErr: function() {
11
+ // eslint-disable-next-line no-console
12
+ console.error.apply(console, arguments)
13
+ },
14
+ })
15
+ return instantiateNapiModuleSync(wasmModule, {
16
+ childThread: true,
17
+ wasi,
18
+ overwriteImports(importObject) {
19
+ importObject.env = {
20
+ ...importObject.env,
21
+ ...importObject.napi,
22
+ ...importObject.emnapi,
23
+ memory: wasmMemory,
24
+ }
25
+ },
26
+ })
27
+ },
28
+ })
29
+
30
+ globalThis.onmessage = function (e) {
31
+ handler.handle(e)
32
+ }
@@ -0,0 +1,63 @@
1
+ import fs from "node:fs";
2
+ import { createRequire } from "node:module";
3
+ import { parse } from "node:path";
4
+ import { WASI } from "node:wasi";
5
+ import { parentPort, Worker } from "node:worker_threads";
6
+
7
+ const require = createRequire(import.meta.url);
8
+
9
+ const { instantiateNapiModuleSync, MessageHandler, getDefaultContext } = require("@napi-rs/wasm-runtime");
10
+
11
+ if (parentPort) {
12
+ parentPort.on("message", (data) => {
13
+ globalThis.onmessage({ data });
14
+ });
15
+ }
16
+
17
+ Object.assign(globalThis, {
18
+ self: globalThis,
19
+ require,
20
+ Worker,
21
+ importScripts: function (f) {
22
+ ;(0, eval)(fs.readFileSync(f, "utf8") + "//# sourceURL=" + f);
23
+ },
24
+ postMessage: function (msg) {
25
+ if (parentPort) {
26
+ parentPort.postMessage(msg);
27
+ }
28
+ },
29
+ });
30
+
31
+ const emnapiContext = getDefaultContext();
32
+
33
+ const __rootDir = parse(process.cwd()).root;
34
+
35
+ const handler = new MessageHandler({
36
+ onLoad({ wasmModule, wasmMemory }) {
37
+ const wasi = new WASI({
38
+ version: 'preview1',
39
+ env: process.env,
40
+ preopens: {
41
+ [__rootDir]: __rootDir,
42
+ },
43
+ });
44
+
45
+ return instantiateNapiModuleSync(wasmModule, {
46
+ childThread: true,
47
+ wasi,
48
+ context: emnapiContext,
49
+ overwriteImports(importObject) {
50
+ importObject.env = {
51
+ ...importObject.env,
52
+ ...importObject.napi,
53
+ ...importObject.emnapi,
54
+ memory: wasmMemory
55
+ };
56
+ },
57
+ });
58
+ },
59
+ });
60
+
61
+ globalThis.onmessage = function (e) {
62
+ handler.handle(e);
63
+ };
@@ -107,7 +107,6 @@ async function normalizePlugins(plugins, root) {
107
107
  async function getDefaultPlugins(root) {
108
108
  return [
109
109
  (0, path_1.join)(__dirname, '../../plugins/js'),
110
- (0, path_1.join)(__dirname, '../../plugins/target-defaults/target-defaults-plugin'),
111
110
  ...((0, angular_json_1.shouldMergeAngularProjects)(root, false)
112
111
  ? [(0, path_1.join)(__dirname, '../../adapter/angular-json')]
113
112
  : []),
@@ -1,15 +1,10 @@
1
1
  import { NxJsonConfiguration, TargetDefaults } from '../../config/nx-json';
2
2
  import { ProjectGraphExternalNode } from '../../config/project-graph';
3
3
  import { ProjectConfiguration, ProjectMetadata, TargetConfiguration, TargetMetadata } from '../../config/workspace-json-project-json';
4
- import { ONLY_MODIFIES_EXISTING_TARGET } from '../../plugins/target-defaults/symbols';
5
4
  import { LoadedNxPlugin } from '../plugins/internal-api';
6
5
  export type SourceInformation = [file: string | null, plugin: string];
7
6
  export type ConfigurationSourceMaps = Record<string, Record<string, SourceInformation>>;
8
- export declare function mergeProjectConfigurationIntoRootMap(projectRootMap: Record<string, ProjectConfiguration>, project: ProjectConfiguration & {
9
- targets?: Record<string, TargetConfiguration & {
10
- [ONLY_MODIFIES_EXISTING_TARGET]?: boolean;
11
- }>;
12
- }, configurationSourceMaps?: ConfigurationSourceMaps, sourceInformation?: SourceInformation, skipTargetNormalization?: boolean): void;
7
+ export declare function mergeProjectConfigurationIntoRootMap(projectRootMap: Record<string, ProjectConfiguration>, project: ProjectConfiguration, configurationSourceMaps?: ConfigurationSourceMaps, sourceInformation?: SourceInformation, skipTargetNormalization?: boolean): void;
13
8
  export declare function mergeMetadata<T = ProjectMetadata | TargetMetadata>(sourceMap: Record<string, [file: string, plugin: string]>, sourceInformation: [file: string, plugin: string], baseSourceMapPath: string, metadata: T, matchingMetadata?: T): T;
14
9
  export type ConfigurationResult = {
15
10
  /**
@@ -44,6 +39,7 @@ export declare function createProjectConfigurations(root: string, nxJson: NxJson
44
39
  plugins: LoadedNxPlugin[]): Promise<ConfigurationResult>;
45
40
  export declare function readProjectConfigurationsFromRootMap(projectRootMap: Record<string, ProjectConfiguration>): Record<string, ProjectConfiguration>;
46
41
  export declare function validateProject(project: ProjectConfiguration, knownProjects: Record<string, ProjectConfiguration>): void;
42
+ export declare function mergeTargetDefaultWithTargetDefinition(targetName: string, project: ProjectConfiguration, targetDefault: Partial<TargetConfiguration>, sourceMap: Record<string, SourceInformation>): TargetConfiguration;
47
43
  /**
48
44
  * Merges two targets.
49
45
  *
@@ -68,4 +64,10 @@ export declare function mergeTargetConfigurations(target: TargetConfiguration, b
68
64
  export declare function isCompatibleTarget(a: TargetConfiguration, b: TargetConfiguration): boolean;
69
65
  export declare function resolveNxTokensInOptions<T extends Object | Array<unknown>>(object: T, project: ProjectConfiguration, key: string): T;
70
66
  export declare function readTargetDefaultsForTarget(targetName: string, targetDefaults: TargetDefaults, executor?: string): TargetDefaults[string];
67
+ /**
68
+ * Expand's `command` syntactic sugar and replaces tokens in options.
69
+ * @param target The target to normalize
70
+ * @param project The project that the target belongs to
71
+ * @returns The normalized target configuration
72
+ */
71
73
  export declare function normalizeTarget(target: TargetConfiguration, project: ProjectConfiguration): TargetConfiguration<any>;
@@ -1,10 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeTarget = exports.readTargetDefaultsForTarget = exports.resolveNxTokensInOptions = exports.isCompatibleTarget = exports.mergeTargetConfigurations = exports.validateProject = exports.readProjectConfigurationsFromRootMap = exports.createProjectConfigurations = exports.mergeMetadata = exports.mergeProjectConfigurationIntoRootMap = void 0;
3
+ exports.normalizeTarget = exports.readTargetDefaultsForTarget = exports.resolveNxTokensInOptions = exports.isCompatibleTarget = exports.mergeTargetConfigurations = exports.mergeTargetDefaultWithTargetDefinition = exports.validateProject = exports.readProjectConfigurationsFromRootMap = exports.createProjectConfigurations = exports.mergeMetadata = exports.mergeProjectConfigurationIntoRootMap = void 0;
4
4
  const logger_1 = require("../../utils/logger");
5
5
  const fileutils_1 = require("../../utils/fileutils");
6
6
  const workspace_root_1 = require("../../utils/workspace-root");
7
- const symbols_1 = require("../../plugins/target-defaults/symbols");
8
7
  const minimatch_1 = require("minimatch");
9
8
  const path_1 = require("path");
10
9
  const perf_hooks_1 = require("perf_hooks");
@@ -120,22 +119,13 @@ skipTargetNormalization) {
120
119
  // Always set source map info for the target, but don't overwrite info already there
121
120
  // if augmenting an existing target.
122
121
  const target = project.targets?.[targetName];
123
- if (sourceMap && !target?.[symbols_1.ONLY_MODIFIES_EXISTING_TARGET]) {
122
+ if (sourceMap) {
124
123
  sourceMap[`targets.${targetName}`] = sourceInformation;
125
124
  }
126
- // If ONLY_MODIFIES_EXISTING_TARGET is true, and its not on the matching project
127
- // we shouldn't merge its info into the graph
128
- if (target?.[symbols_1.ONLY_MODIFIES_EXISTING_TARGET] &&
129
- !matchingProject.targets?.[targetName]) {
130
- continue;
131
- }
132
125
  const normalizedTarget = skipTargetNormalization
133
126
  ? target
134
127
  : resolveCommandSyntacticSugar(target, project.root);
135
128
  const mergedTarget = mergeTargetConfigurations(normalizedTarget, matchingProject.targets?.[targetName], sourceMap, sourceInformation, `targets.${targetName}`);
136
- // We don't want the symbol to live on past the merge process
137
- if (mergedTarget?.[symbols_1.ONLY_MODIFIES_EXISTING_TARGET])
138
- delete mergedTarget?.[symbols_1.ONLY_MODIFIES_EXISTING_TARGET];
139
129
  updatedProjectConfiguration.targets[targetName] = mergedTarget;
140
130
  }
141
131
  }
@@ -263,7 +253,7 @@ plugins) {
263
253
  results.push(r);
264
254
  }
265
255
  return Promise.all(results).then((results) => {
266
- const { projectRootMap, externalNodes, rootMap, configurationSourceMaps } = mergeCreateNodesResults(results, errors);
256
+ const { projectRootMap, externalNodes, rootMap, configurationSourceMaps } = mergeCreateNodesResults(results, nxJson, errors);
267
257
  perf_hooks_1.performance.mark('build-project-configs:end');
268
258
  perf_hooks_1.performance.measure('build-project-configs', 'build-project-configs:start', 'build-project-configs:end');
269
259
  if (errors.length === 0) {
@@ -287,7 +277,7 @@ plugins) {
287
277
  });
288
278
  }
289
279
  exports.createProjectConfigurations = createProjectConfigurations;
290
- function mergeCreateNodesResults(results, errors) {
280
+ function mergeCreateNodesResults(results, nxJsonConfiguration, errors) {
291
281
  perf_hooks_1.performance.mark('createNodes:merge - start');
292
282
  const projectRootMap = {};
293
283
  const externalNodes = {};
@@ -296,9 +286,6 @@ function mergeCreateNodesResults(results, errors) {
296
286
  const [pluginName, file, nodes] = result;
297
287
  const { projects: projectNodes, externalNodes: pluginExternalNodes } = nodes;
298
288
  const sourceInfo = [file, pluginName];
299
- if (result[symbols_1.OVERRIDE_SOURCE_FILE]) {
300
- sourceInfo[0] = result[symbols_1.OVERRIDE_SOURCE_FILE];
301
- }
302
289
  for (const node in projectNodes) {
303
290
  // Handles `{projects: {'libs/foo': undefined}}`.
304
291
  if (!projectNodes[node]) {
@@ -322,7 +309,7 @@ function mergeCreateNodesResults(results, errors) {
322
309
  Object.assign(externalNodes, pluginExternalNodes);
323
310
  }
324
311
  try {
325
- validateAndNormalizeProjectRootMap(projectRootMap);
312
+ validateAndNormalizeProjectRootMap(projectRootMap, nxJsonConfiguration, configurationSourceMaps);
326
313
  }
327
314
  catch (e) {
328
315
  if ((0, error_types_1.isProjectsWithNoNameError)(e) ||
@@ -401,7 +388,7 @@ function readProjectConfigurationsFromRootMap(projectRootMap) {
401
388
  return projects;
402
389
  }
403
390
  exports.readProjectConfigurationsFromRootMap = readProjectConfigurationsFromRootMap;
404
- function validateAndNormalizeProjectRootMap(projectRootMap) {
391
+ function validateAndNormalizeProjectRootMap(projectRootMap, nxJsonConfiguration, sourceMaps = {}) {
405
392
  // Name -> Project, used to validate that all projects have unique names
406
393
  const projects = {};
407
394
  // If there are projects that have the same name, that is an error.
@@ -434,24 +421,7 @@ function validateAndNormalizeProjectRootMap(projectRootMap) {
434
421
  throw e;
435
422
  }
436
423
  }
437
- for (const targetName in project.targets) {
438
- project.targets[targetName] = normalizeTarget(project.targets[targetName], project);
439
- if (
440
- // If the target has no executor or command, it doesn't do anything
441
- !project.targets[targetName].executor &&
442
- !project.targets[targetName].command) {
443
- // But it may have dependencies that do something
444
- if (project.targets[targetName].dependsOn &&
445
- project.targets[targetName].dependsOn.length > 0) {
446
- project.targets[targetName].executor = 'nx:noop';
447
- }
448
- else {
449
- // If it does nothing, and has no depenencies,
450
- // we can remove it.
451
- delete project.targets[targetName];
452
- }
453
- }
454
- }
424
+ normalizeTargets(project, sourceMaps, nxJsonConfiguration);
455
425
  }
456
426
  if (conflicts.size > 0) {
457
427
  throw new error_types_1.MultipleProjectsWithSameNameError(conflicts, projects);
@@ -461,6 +431,33 @@ function validateAndNormalizeProjectRootMap(projectRootMap) {
461
431
  }
462
432
  return projectRootMap;
463
433
  }
434
+ function normalizeTargets(project, sourceMaps, nxJsonConfiguration) {
435
+ for (const targetName in project.targets) {
436
+ project.targets[targetName] = normalizeTarget(project.targets[targetName], project);
437
+ const projectSourceMaps = sourceMaps[project.root];
438
+ const targetConfig = project.targets[targetName];
439
+ const targetDefaults = readTargetDefaultsForTarget(targetName, nxJsonConfiguration.targetDefaults, targetConfig.executor);
440
+ // We only apply defaults if they exist
441
+ if (targetDefaults && isCompatibleTarget(targetConfig, targetDefaults)) {
442
+ project.targets[targetName] = mergeTargetDefaultWithTargetDefinition(targetName, project, normalizeTarget(targetDefaults, project), projectSourceMaps);
443
+ }
444
+ if (
445
+ // If the target has no executor or command, it doesn't do anything
446
+ !project.targets[targetName].executor &&
447
+ !project.targets[targetName].command) {
448
+ // But it may have dependencies that do something
449
+ if (project.targets[targetName].dependsOn &&
450
+ project.targets[targetName].dependsOn.length > 0) {
451
+ project.targets[targetName].executor = 'nx:noop';
452
+ }
453
+ else {
454
+ // If it does nothing, and has no depenencies,
455
+ // we can remove it.
456
+ delete project.targets[targetName];
457
+ }
458
+ }
459
+ }
460
+ }
464
461
  function validateProject(project,
465
462
  // name -> project
466
463
  knownProjects) {
@@ -482,6 +479,75 @@ knownProjects) {
482
479
  }
483
480
  }
484
481
  exports.validateProject = validateProject;
482
+ function targetDefaultShouldBeApplied(key, sourceMap) {
483
+ const sourceInfo = sourceMap[key];
484
+ if (!sourceInfo) {
485
+ return true;
486
+ }
487
+ // The defined value of the target is from a plugin that
488
+ // isn't part of Nx's core plugins, so target defaults are
489
+ // applied on top of it.
490
+ const [, plugin] = sourceInfo;
491
+ return !plugin?.startsWith('nx/');
492
+ }
493
+ function mergeTargetDefaultWithTargetDefinition(targetName, project, targetDefault, sourceMap) {
494
+ const targetDefinition = project.targets[targetName] ?? {};
495
+ const result = JSON.parse(JSON.stringify(targetDefinition));
496
+ for (const key in targetDefault) {
497
+ switch (key) {
498
+ case 'options': {
499
+ const normalizedDefaults = resolveNxTokensInOptions(targetDefault.options, project, targetName);
500
+ for (const optionKey in normalizedDefaults) {
501
+ const sourceMapKey = `targets.${targetName}.options.${optionKey}`;
502
+ if (targetDefinition.options[optionKey] === undefined ||
503
+ targetDefaultShouldBeApplied(sourceMapKey, sourceMap)) {
504
+ result.options[optionKey] = targetDefault.options[optionKey];
505
+ sourceMap[sourceMapKey] = ['nx.json', 'nx/target-defaults'];
506
+ }
507
+ }
508
+ break;
509
+ }
510
+ case 'configurations': {
511
+ if (!result.configurations) {
512
+ result.configurations = {};
513
+ sourceMap[`targets.${targetName}.configurations`] = [
514
+ 'nx.json',
515
+ 'nx/target-defaults',
516
+ ];
517
+ }
518
+ for (const configuration in targetDefault.configurations) {
519
+ if (!result.configurations[configuration]) {
520
+ result.configurations[configuration] = {};
521
+ sourceMap[`targets.${targetName}.configurations.${configuration}`] =
522
+ ['nx.json', 'nx/target-defaults'];
523
+ }
524
+ const normalizedConfigurationDefaults = resolveNxTokensInOptions(targetDefault.configurations[configuration], project, targetName);
525
+ for (const configurationKey in normalizedConfigurationDefaults) {
526
+ const sourceMapKey = `targets.${targetName}.configurations.${configuration}.${configurationKey}`;
527
+ if (targetDefinition.configurations?.[configuration]?.[configurationKey] === undefined ||
528
+ targetDefaultShouldBeApplied(sourceMapKey, sourceMap)) {
529
+ result.configurations[configuration][configurationKey] =
530
+ targetDefault.configurations[configuration][configurationKey];
531
+ sourceMap[sourceMapKey] = ['nx.json', 'nx/target-defaults'];
532
+ }
533
+ }
534
+ }
535
+ break;
536
+ }
537
+ default: {
538
+ const sourceMapKey = `targets.${targetName}.${key}`;
539
+ if (targetDefinition[key] === undefined ||
540
+ targetDefaultShouldBeApplied(sourceMapKey, sourceMap)) {
541
+ result[key] = targetDefault[key];
542
+ sourceMap[sourceMapKey] = ['nx.json', 'nx/target-defaults'];
543
+ }
544
+ break;
545
+ }
546
+ }
547
+ }
548
+ return result;
549
+ }
550
+ exports.mergeTargetDefaultWithTargetDefinition = mergeTargetDefaultWithTargetDefinition;
485
551
  /**
486
552
  * Merges two targets.
487
553
  *
@@ -500,13 +566,6 @@ function mergeTargetConfigurations(target, baseTarget, projectConfigSourceMap, s
500
566
  // Target is "compatible", e.g. executor is defined only once or is the same
501
567
  // in both places. This means that it is likely safe to merge
502
568
  const isCompatible = isCompatibleTarget(baseTarget ?? {}, target);
503
- // If the targets are not compatible, we would normally overwrite the old target
504
- // with the new one. However, we have a special case for targets that have the
505
- // ONLY_MODIFIES_EXISTING_TARGET symbol set. This prevents the merged target
506
- // equaling info that should have only been used to modify the existing target.
507
- if (!isCompatible && target[symbols_1.ONLY_MODIFIES_EXISTING_TARGET]) {
508
- return baseTarget;
509
- }
510
569
  if (!isCompatible && projectConfigSourceMap) {
511
570
  // if the target is not compatible, we will simply override the options
512
571
  // we have to delete old entries from the source map
@@ -680,6 +739,12 @@ function resolveCommandSyntacticSugar(target, key) {
680
739
  };
681
740
  }
682
741
  }
742
+ /**
743
+ * Expand's `command` syntactic sugar and replaces tokens in options.
744
+ * @param target The target to normalize
745
+ * @param project The project that the target belongs to
746
+ * @returns The normalized target configuration
747
+ */
683
748
  function normalizeTarget(target, project) {
684
749
  target = resolveCommandSyntacticSugar(target, project.root);
685
750
  target.options = resolveNxTokensInOptions(target.options, project, `${project.root}:${target}`);
@@ -9,12 +9,12 @@ import { LoadedNxPlugin } from '../plugins/internal-api';
9
9
  * @param nxJson
10
10
  */
11
11
  export declare function retrieveWorkspaceFiles(workspaceRoot: string, projectRootMap: Record<string, string>): Promise<{
12
- allWorkspaceFiles: import("nx/src/devkit-exports").FileData[];
12
+ allWorkspaceFiles: import("../file-utils").FileData[];
13
13
  fileMap: {
14
14
  projectFileMap: ProjectFiles;
15
- nonProjectFiles: import("nx/src/native").FileData[];
15
+ nonProjectFiles: import("../../native").FileData[];
16
16
  };
17
- rustReferences: import("nx/src/native").NxWorkspaceFilesExternals;
17
+ rustReferences: import("../../native").NxWorkspaceFilesExternals;
18
18
  }>;
19
19
  /**
20
20
  * Walk through the workspace and return `ProjectConfigurations`. Only use this if the projectFileMap is not needed.
@@ -139,6 +139,9 @@ function messageToCode(message) {
139
139
  }
140
140
  }
141
141
  function supportedPtyPlatform() {
142
+ if (native_1.IS_WASM) {
143
+ return false;
144
+ }
142
145
  if (process.platform !== 'win32') {
143
146
  return true;
144
147
  }