feat(devkit): bump compatibility to Nx 19 - 21.x (#28243)
BREAKING CHANGE <!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> * `@nx/devkit` supports Nx 17 - 20. * Node 18 - 22 is supported * `ExecutorContext.projectGraph`, `ExecutorContext.nxJsonConfiguration`, and `ExecutorContext.projectsConfigurations` is marked as optional because `ExecutorContext` in some versions of Nx did not have them. * `ExecutorContext.workspace` is marked as optional because `ExecutorContext` in some versions of Nx did not have the above properties which contain the same information. * `ProjectGraphNode` is deprecated. * `NxPluginV1.processProjectGraph` was deprecated long ago and there has been a warning since. * `appRootPath` has been deprecated for a long time. * `parseTargetString` had a variant that did not take either the project graph or the executor context. * `readNxJson` has a variant which does not take a tree. This was not clearly deprecated. * There are handlers to require from `@nx/` instead of `@nrwl` * Nx tries to get a root install from `@nrwl/cli` ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> * `@nx/devkit` supports Nx 19 - 21. * Node 20 - 22 is supported * `ExecutorContext.projectGraph`, `ExecutorContext.nxJsonConfiguration`, and `ExecutorContext.projectsConfigurations` is marked as required because `ExecutorContext` in Nx 19+ is guaranteed to have them. * `ExecutorContext.workspace` is removed because the same information is available in the above properties * `ProjectGraphNode` is removed. * `NxPluginV1` is no more. All plugins should be `NxPluginV2`. * `workspaceRoot` is the replacement for `appRootPath`. `appRootPath` is removed. * `parseTargetString` no longer has a variant that did not take either the project graph or the executor context. * `readNxJson` still has a variant which does not take a tree but it's clearly deprecated to be removed in Nx 21. * `@nrwl` packages are no more so we don't have to redirect requires anymore. * `@nrwl/cli` is no more so Nx shouldn't try to get a root install there * ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #
This commit is contained in:
parent
d131b0b677
commit
23bebd91e7
@ -5,12 +5,12 @@
|
||||
A pair of file patterns and [CreateNodesFunction](../../devkit/documents/CreateNodesFunction)
|
||||
|
||||
Nx 19.2+: Both original `CreateNodes` and `CreateNodesV2` are supported. Nx will only invoke `CreateNodesV2` if it is present.
|
||||
Nx 20.X : The `CreateNodesV2` will be the only supported API. This typing will still exist, but be identical to `CreateNodesV2`.
|
||||
Nx 21.X : The `CreateNodesV2` will be the only supported API. This typing will still exist, but be identical to `CreateNodesV2`.
|
||||
Nx **will not** invoke the original `plugin.createNodes` callback. This should give plugin authors a window to transition.
|
||||
Plugin authors should update their plugin's `createNodes` function to align with `CreateNodesV2` / the updated `CreateNodes`.
|
||||
The plugin should contain something like: `export createNodes = createNodesV2;` during this period. This will allow the plugin
|
||||
to maintain compatibility with Nx 19.2 and up.
|
||||
Nx 21.X : The `CreateNodesV2` typing will be removed, as it has replaced `CreateNodes`.
|
||||
Nx 22.X : The `CreateNodesV2` typing will be removed, as it has replaced `CreateNodes`.
|
||||
|
||||
**`Deprecated`**
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
Ƭ **CreateNodesV2**\<`T`\>: readonly [projectFilePattern: string, createNodesFunction: CreateNodesFunctionV2\<T\>]
|
||||
|
||||
A pair of file patterns and [CreateNodesFunctionV2](../../devkit/documents/CreateNodesFunctionV2)
|
||||
In Nx 20 [CreateNodes](../../devkit/documents/CreateNodes) will be replaced with this type. In Nx 21, this type will be removed.
|
||||
In Nx 21 [CreateNodes](../../devkit/documents/CreateNodes) will be replaced with this type. In Nx 22, this type will be removed.
|
||||
|
||||
#### Type parameters
|
||||
|
||||
|
||||
@ -17,7 +17,6 @@ Context that is passed into an executor
|
||||
- [target](../../devkit/documents/ExecutorContext#target): TargetConfiguration<any>
|
||||
- [targetName](../../devkit/documents/ExecutorContext#targetname): string
|
||||
- [taskGraph](../../devkit/documents/ExecutorContext#taskgraph): TaskGraph
|
||||
- [workspace](../../devkit/documents/ExecutorContext#workspace): ProjectsConfigurations & NxJsonConfiguration<string[] | "\*">
|
||||
|
||||
## Properties
|
||||
|
||||
@ -47,23 +46,19 @@ Enable verbose logging
|
||||
|
||||
### nxJsonConfiguration
|
||||
|
||||
• `Optional` **nxJsonConfiguration**: [`NxJsonConfiguration`](../../devkit/documents/NxJsonConfiguration)\<`string`[] \| `"*"`\>
|
||||
• **nxJsonConfiguration**: [`NxJsonConfiguration`](../../devkit/documents/NxJsonConfiguration)\<`string`[] \| `"*"`\>
|
||||
|
||||
The contents of nx.json.
|
||||
|
||||
@todo(vsavkin): mark this as required for v17
|
||||
|
||||
---
|
||||
|
||||
### projectGraph
|
||||
|
||||
• `Optional` **projectGraph**: [`ProjectGraph`](../../devkit/documents/ProjectGraph)
|
||||
• **projectGraph**: [`ProjectGraph`](../../devkit/documents/ProjectGraph)
|
||||
|
||||
A snapshot of the project graph as
|
||||
it existed when the Nx command was kicked off
|
||||
|
||||
@todo(vsavkin) mark this required for v17
|
||||
|
||||
---
|
||||
|
||||
### projectName
|
||||
@ -76,12 +71,10 @@ The name of the project being executed on
|
||||
|
||||
### projectsConfigurations
|
||||
|
||||
• `Optional` **projectsConfigurations**: [`ProjectsConfigurations`](../../devkit/documents/ProjectsConfigurations)
|
||||
• **projectsConfigurations**: [`ProjectsConfigurations`](../../devkit/documents/ProjectsConfigurations)
|
||||
|
||||
Projects config
|
||||
|
||||
@todo(vsavkin): mark this as required for v17
|
||||
|
||||
---
|
||||
|
||||
### root
|
||||
@ -114,13 +107,3 @@ The name of the target being executed
|
||||
|
||||
A snapshot of the task graph as
|
||||
it existed when the Nx command was kicked off
|
||||
|
||||
---
|
||||
|
||||
### workspace
|
||||
|
||||
• `Optional` **workspace**: [`ProjectsConfigurations`](../../devkit/documents/ProjectsConfigurations) & [`NxJsonConfiguration`](../../devkit/documents/NxJsonConfiguration)\<`string`[] \| `"*"`\>
|
||||
|
||||
Deprecated. Use projectsConfigurations or nxJsonConfiguration
|
||||
The full workspace configuration
|
||||
@todo(vsavkin): remove after v17
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
# Type alias: NxPlugin
|
||||
|
||||
Ƭ **NxPlugin**: [`NxPluginV1`](../../devkit/documents/NxPluginV1) \| [`NxPluginV2`](../../devkit/documents/NxPluginV2)
|
||||
Ƭ **NxPlugin**: [`NxPluginV2`](../../devkit/documents/NxPluginV2)
|
||||
|
||||
A plugin for Nx
|
||||
|
||||
@ -1,16 +0,0 @@
|
||||
# Type alias: NxPluginV1
|
||||
|
||||
Ƭ **NxPluginV1**: `Object`
|
||||
|
||||
**`Deprecated`**
|
||||
|
||||
Use [NxPluginV2](../../devkit/documents/NxPluginV2) instead. This will be removed in Nx 20
|
||||
|
||||
#### Type declaration
|
||||
|
||||
| Name | Type | Description |
|
||||
| :------------------------ | :------------------------------------------------------------------------------ | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `name` | `string` | - |
|
||||
| `processProjectGraph?` | `ProjectGraphProcessor` | **`Deprecated`** Use [CreateNodes](../../devkit/documents/CreateNodes) and [CreateDependencies](../../devkit/documents/CreateDependencies) instead. This will be removed in Nx 20 |
|
||||
| `projectFilePatterns?` | `string`[] | A glob pattern to search for non-standard project files. @example: ["*.csproj", "pom.xml"] **`Deprecated`** Use [CreateNodes](../../devkit/documents/CreateNodes) instead. This will be removed in Nx 20 |
|
||||
| `registerProjectTargets?` | [`ProjectTargetConfigurator`](../../devkit/documents/ProjectTargetConfigurator) | **`Deprecated`** Add targets to the projects inside of [CreateNodes](../../devkit/documents/CreateNodes) instead. This will be removed in Nx 20 |
|
||||
@ -16,6 +16,6 @@ A plugin for Nx which creates nodes and dependencies for the [ProjectGraph](../.
|
||||
| :-------------------- | :------------------------------------------------------------------------------ | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `createDependencies?` | [`CreateDependencies`](../../devkit/documents/CreateDependencies)\<`TOptions`\> | Provides a function to analyze files to create dependencies for the [ProjectGraph](../../devkit/documents/ProjectGraph) |
|
||||
| `createMetadata?` | [`CreateMetadata`](../../devkit/documents/CreateMetadata)\<`TOptions`\> | Provides a function to create metadata for the [ProjectGraph](../../devkit/documents/ProjectGraph) |
|
||||
| `createNodes?` | [`CreateNodes`](../../devkit/documents/CreateNodes)\<`TOptions`\> | Provides a file pattern and function that retrieves configuration info from those files. e.g. { '**/\*.csproj': buildProjectsFromCsProjFile } **`Deprecated`\*\* Use createNodesV2 instead. In Nx 20 support for calling createNodes with a single file for the first argument will be removed. |
|
||||
| `createNodesV2?` | [`CreateNodesV2`](../../devkit/documents/CreateNodesV2)\<`TOptions`\> | Provides a file pattern and function that retrieves configuration info from those files. e.g. { '\*_/_.csproj': buildProjectsFromCsProjFiles } In Nx 20 createNodes will be replaced with this property. In Nx 21, this property will be removed. |
|
||||
| `createNodes?` | [`CreateNodes`](../../devkit/documents/CreateNodes)\<`TOptions`\> | Provides a file pattern and function that retrieves configuration info from those files. e.g. { '**/\*.csproj': buildProjectsFromCsProjFile } **`Deprecated`\*\* Use createNodesV2 instead. In Nx 21 support for calling createNodes with a single file for the first argument will be removed. |
|
||||
| `createNodesV2?` | [`CreateNodesV2`](../../devkit/documents/CreateNodesV2)\<`TOptions`\> | Provides a file pattern and function that retrieves configuration info from those files. e.g. { '\*_/_.csproj': buildProjectsFromCsProjFiles } In Nx 21 createNodes will be replaced with this property. In Nx 22, this property will be removed. |
|
||||
| `name` | `string` | - |
|
||||
|
||||
@ -1,288 +0,0 @@
|
||||
# Class: ProjectGraphBuilder
|
||||
|
||||
A class which builds up a project graph
|
||||
|
||||
**`Deprecated`**
|
||||
|
||||
The ProjectGraphProcessor has been deprecated. Use a [CreateNodes](../../devkit/documents/CreateNodes) and/or a [CreateDependencies](../../devkit/documents/CreateDependencies) instead. This will be removed in Nx 20.
|
||||
|
||||
## Table of contents
|
||||
|
||||
### Constructors
|
||||
|
||||
- [constructor](../../devkit/documents/ProjectGraphBuilder#constructor)
|
||||
|
||||
### Properties
|
||||
|
||||
- [graph](../../devkit/documents/ProjectGraphBuilder#graph): ProjectGraph
|
||||
- [removedEdges](../../devkit/documents/ProjectGraphBuilder#removededges): Object
|
||||
|
||||
### Methods
|
||||
|
||||
- [addDependency](../../devkit/documents/ProjectGraphBuilder#adddependency)
|
||||
- [addDynamicDependency](../../devkit/documents/ProjectGraphBuilder#adddynamicdependency)
|
||||
- [addExplicitDependency](../../devkit/documents/ProjectGraphBuilder#addexplicitdependency)
|
||||
- [addExternalNode](../../devkit/documents/ProjectGraphBuilder#addexternalnode)
|
||||
- [addImplicitDependency](../../devkit/documents/ProjectGraphBuilder#addimplicitdependency)
|
||||
- [addNode](../../devkit/documents/ProjectGraphBuilder#addnode)
|
||||
- [addStaticDependency](../../devkit/documents/ProjectGraphBuilder#addstaticdependency)
|
||||
- [getUpdatedProjectGraph](../../devkit/documents/ProjectGraphBuilder#getupdatedprojectgraph)
|
||||
- [mergeProjectGraph](../../devkit/documents/ProjectGraphBuilder#mergeprojectgraph)
|
||||
- [removeDependency](../../devkit/documents/ProjectGraphBuilder#removedependency)
|
||||
- [removeNode](../../devkit/documents/ProjectGraphBuilder#removenode)
|
||||
- [setVersion](../../devkit/documents/ProjectGraphBuilder#setversion)
|
||||
|
||||
## Constructors
|
||||
|
||||
### constructor
|
||||
|
||||
• **new ProjectGraphBuilder**(`graph?`, `projectFileMap?`, `nonProjectFiles?`): [`ProjectGraphBuilder`](../../devkit/documents/ProjectGraphBuilder)
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
| :----------------- | :-------------------------------------------------------- |
|
||||
| `graph?` | [`ProjectGraph`](../../devkit/documents/ProjectGraph) |
|
||||
| `projectFileMap?` | [`ProjectFileMap`](../../devkit/documents/ProjectFileMap) |
|
||||
| `nonProjectFiles?` | [`FileData`](../../devkit/documents/FileData)[] |
|
||||
|
||||
#### Returns
|
||||
|
||||
[`ProjectGraphBuilder`](../../devkit/documents/ProjectGraphBuilder)
|
||||
|
||||
## Properties
|
||||
|
||||
### graph
|
||||
|
||||
• `Readonly` **graph**: [`ProjectGraph`](../../devkit/documents/ProjectGraph)
|
||||
|
||||
---
|
||||
|
||||
### removedEdges
|
||||
|
||||
• `Readonly` **removedEdges**: `Object` = `{}`
|
||||
|
||||
#### Index signature
|
||||
|
||||
▪ [source: `string`]: `Set`\<`string`\>
|
||||
|
||||
## Methods
|
||||
|
||||
### addDependency
|
||||
|
||||
▸ **addDependency**(`source`, `target`, `type`, `sourceFile?`): `void`
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
| :------------ | :-------------------------------------------------------- |
|
||||
| `source` | `string` |
|
||||
| `target` | `string` |
|
||||
| `type` | [`DependencyType`](../../devkit/documents/DependencyType) |
|
||||
| `sourceFile?` | `string` |
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
|
||||
---
|
||||
|
||||
### addDynamicDependency
|
||||
|
||||
▸ **addDynamicDependency**(`sourceProjectName`, `targetProjectName`, `sourceProjectFile`): `void`
|
||||
|
||||
Adds dynamic dependency from source project to target project
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
| :------------------ | :------- |
|
||||
| `sourceProjectName` | `string` |
|
||||
| `targetProjectName` | `string` |
|
||||
| `sourceProjectFile` | `string` |
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
|
||||
---
|
||||
|
||||
### addExplicitDependency
|
||||
|
||||
▸ **addExplicitDependency**(`sourceProjectName`, `sourceProjectFile`, `targetProjectName`): `void`
|
||||
|
||||
Add an explicit dependency from a file in source project to target project
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
| :------------------ | :------- |
|
||||
| `sourceProjectName` | `string` |
|
||||
| `sourceProjectFile` | `string` |
|
||||
| `targetProjectName` | `string` |
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
|
||||
**`Deprecated`**
|
||||
|
||||
this method will be removed in v17. Use [addStaticDependency](../../devkit/documents/ProjectGraphBuilder#addstaticdependency) or [addDynamicDependency](../../devkit/documents/ProjectGraphBuilder#adddynamicdependency) instead
|
||||
|
||||
---
|
||||
|
||||
### addExternalNode
|
||||
|
||||
▸ **addExternalNode**(`node`): `void`
|
||||
|
||||
Adds a external node to the project graph
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
| :----- | :---------------------------------------------------------------------------- |
|
||||
| `node` | [`ProjectGraphExternalNode`](../../devkit/documents/ProjectGraphExternalNode) |
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
|
||||
---
|
||||
|
||||
### addImplicitDependency
|
||||
|
||||
▸ **addImplicitDependency**(`sourceProjectName`, `targetProjectName`): `void`
|
||||
|
||||
Adds implicit dependency from source project to target project
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
| :------------------ | :------- |
|
||||
| `sourceProjectName` | `string` |
|
||||
| `targetProjectName` | `string` |
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
|
||||
---
|
||||
|
||||
### addNode
|
||||
|
||||
▸ **addNode**(`node`): `void`
|
||||
|
||||
Adds a project node to the project graph
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
| :----- | :-------------------------------------------------------------------------- |
|
||||
| `node` | [`ProjectGraphProjectNode`](../../devkit/documents/ProjectGraphProjectNode) |
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
|
||||
---
|
||||
|
||||
### addStaticDependency
|
||||
|
||||
▸ **addStaticDependency**(`sourceProjectName`, `targetProjectName`, `sourceProjectFile?`): `void`
|
||||
|
||||
Adds static dependency from source project to target project
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
| :------------------- | :------- |
|
||||
| `sourceProjectName` | `string` |
|
||||
| `targetProjectName` | `string` |
|
||||
| `sourceProjectFile?` | `string` |
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
|
||||
---
|
||||
|
||||
### getUpdatedProjectGraph
|
||||
|
||||
▸ **getUpdatedProjectGraph**(): [`ProjectGraph`](../../devkit/documents/ProjectGraph)
|
||||
|
||||
#### Returns
|
||||
|
||||
[`ProjectGraph`](../../devkit/documents/ProjectGraph)
|
||||
|
||||
---
|
||||
|
||||
### mergeProjectGraph
|
||||
|
||||
▸ **mergeProjectGraph**(`p`): `void`
|
||||
|
||||
Merges the nodes and dependencies of p into the built project graph.
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
| :--- | :---------------------------------------------------- |
|
||||
| `p` | [`ProjectGraph`](../../devkit/documents/ProjectGraph) |
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
|
||||
---
|
||||
|
||||
### removeDependency
|
||||
|
||||
▸ **removeDependency**(`sourceProjectName`, `targetProjectName`): `void`
|
||||
|
||||
Removes a dependency from source project to target project
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
| :------------------ | :------- |
|
||||
| `sourceProjectName` | `string` |
|
||||
| `targetProjectName` | `string` |
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
|
||||
---
|
||||
|
||||
### removeNode
|
||||
|
||||
▸ **removeNode**(`name`): `void`
|
||||
|
||||
Removes a node and all of its dependency edges from the graph
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
| :----- | :------- |
|
||||
| `name` | `string` |
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
|
||||
---
|
||||
|
||||
### setVersion
|
||||
|
||||
▸ **setVersion**(`version`): `void`
|
||||
|
||||
Set version of the project graph
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
| :-------- | :------- |
|
||||
| `version` | `string` |
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
@ -1,7 +0,0 @@
|
||||
# Type alias: ProjectGraphNode
|
||||
|
||||
Ƭ **ProjectGraphNode**: [`ProjectGraphProjectNode`](../../devkit/documents/ProjectGraphProjectNode) \| [`ProjectGraphExternalNode`](../../devkit/documents/ProjectGraphExternalNode)
|
||||
|
||||
**`Deprecated`**
|
||||
|
||||
this type will be removed in v16. Use [ProjectGraphProjectNode](../../devkit/documents/ProjectGraphProjectNode) or [ProjectGraphExternalNode](../../devkit/documents/ProjectGraphExternalNode) instead
|
||||
@ -1,57 +0,0 @@
|
||||
# Interface: ProjectGraphProcessorContext
|
||||
|
||||
Additional information to be used to process a project graph
|
||||
|
||||
**`Deprecated`**
|
||||
|
||||
The ProjectGraphProcessor is deprecated. This will be removed in Nx 20.
|
||||
|
||||
## Table of contents
|
||||
|
||||
### Properties
|
||||
|
||||
- [fileMap](../../devkit/documents/ProjectGraphProcessorContext#filemap): ProjectFileMap
|
||||
- [filesToProcess](../../devkit/documents/ProjectGraphProcessorContext#filestoprocess): ProjectFileMap
|
||||
- [nxJsonConfiguration](../../devkit/documents/ProjectGraphProcessorContext#nxjsonconfiguration): NxJsonConfiguration<string[] | "\*">
|
||||
- [projectsConfigurations](../../devkit/documents/ProjectGraphProcessorContext#projectsconfigurations): ProjectsConfigurations
|
||||
- [workspace](../../devkit/documents/ProjectGraphProcessorContext#workspace): Workspace
|
||||
|
||||
## Properties
|
||||
|
||||
### fileMap
|
||||
|
||||
• **fileMap**: [`ProjectFileMap`](../../devkit/documents/ProjectFileMap)
|
||||
|
||||
All files in the workspace
|
||||
|
||||
---
|
||||
|
||||
### filesToProcess
|
||||
|
||||
• **filesToProcess**: [`ProjectFileMap`](../../devkit/documents/ProjectFileMap)
|
||||
|
||||
Files changes since last invocation
|
||||
|
||||
---
|
||||
|
||||
### nxJsonConfiguration
|
||||
|
||||
• **nxJsonConfiguration**: [`NxJsonConfiguration`](../../devkit/documents/NxJsonConfiguration)\<`string`[] \| `"*"`\>
|
||||
|
||||
---
|
||||
|
||||
### projectsConfigurations
|
||||
|
||||
• **projectsConfigurations**: [`ProjectsConfigurations`](../../devkit/documents/ProjectsConfigurations)
|
||||
|
||||
---
|
||||
|
||||
### workspace
|
||||
|
||||
• **workspace**: [`Workspace`](../../devkit/documents/Workspace)
|
||||
|
||||
Workspace information such as projects and configuration
|
||||
|
||||
**`Deprecated`**
|
||||
|
||||
use [projectsConfigurations](../../devkit/documents/ProjectGraphProcessorContext#projectsconfigurations) or [nxJsonConfiguration](../../devkit/documents/ProjectGraphProcessorContext#nxjsonconfiguration) instead
|
||||
@ -1,21 +0,0 @@
|
||||
# Type alias: ProjectTargetConfigurator
|
||||
|
||||
Ƭ **ProjectTargetConfigurator**: (`file`: `string`) => `Record`\<`string`, [`TargetConfiguration`](../../devkit/documents/TargetConfiguration)\>
|
||||
|
||||
**`Deprecated`**
|
||||
|
||||
Add targets to the projects in a [CreateNodes](../../devkit/documents/CreateNodes) function instead. This will be removed in Nx 20
|
||||
|
||||
#### Type declaration
|
||||
|
||||
▸ (`file`): `Record`\<`string`, [`TargetConfiguration`](../../devkit/documents/TargetConfiguration)\>
|
||||
|
||||
##### Parameters
|
||||
|
||||
| Name | Type |
|
||||
| :----- | :------- |
|
||||
| `file` | `string` |
|
||||
|
||||
##### Returns
|
||||
|
||||
`Record`\<`string`, [`TargetConfiguration`](../../devkit/documents/TargetConfiguration)\>
|
||||
@ -20,7 +20,6 @@ It only uses language primitives and immutable objects
|
||||
### Classes
|
||||
|
||||
- [AggregateCreateNodesError](../../devkit/documents/AggregateCreateNodesError)
|
||||
- [ProjectGraphBuilder](../../devkit/documents/ProjectGraphBuilder)
|
||||
|
||||
### Interfaces
|
||||
|
||||
@ -49,7 +48,6 @@ It only uses language primitives and immutable objects
|
||||
- [ProjectGraph](../../devkit/documents/ProjectGraph)
|
||||
- [ProjectGraphDependency](../../devkit/documents/ProjectGraphDependency)
|
||||
- [ProjectGraphExternalNode](../../devkit/documents/ProjectGraphExternalNode)
|
||||
- [ProjectGraphProcessorContext](../../devkit/documents/ProjectGraphProcessorContext)
|
||||
- [ProjectGraphProjectNode](../../devkit/documents/ProjectGraphProjectNode)
|
||||
- [ProjectsConfigurations](../../devkit/documents/ProjectsConfigurations)
|
||||
- [RemoteCache](../../devkit/documents/RemoteCache)
|
||||
@ -85,12 +83,9 @@ It only uses language primitives and immutable objects
|
||||
- [ImplicitDependency](../../devkit/documents/ImplicitDependency)
|
||||
- [ImplicitDependencyEntry](../../devkit/documents/ImplicitDependencyEntry)
|
||||
- [NxPlugin](../../devkit/documents/NxPlugin)
|
||||
- [NxPluginV1](../../devkit/documents/NxPluginV1)
|
||||
- [NxPluginV2](../../devkit/documents/NxPluginV2)
|
||||
- [PackageManager](../../devkit/documents/PackageManager)
|
||||
- [PluginConfiguration](../../devkit/documents/PluginConfiguration)
|
||||
- [ProjectGraphNode](../../devkit/documents/ProjectGraphNode)
|
||||
- [ProjectTargetConfigurator](../../devkit/documents/ProjectTargetConfigurator)
|
||||
- [ProjectType](../../devkit/documents/ProjectType)
|
||||
- [ProjectsMetadata](../../devkit/documents/ProjectsMetadata)
|
||||
- [PromiseExecutor](../../devkit/documents/PromiseExecutor)
|
||||
@ -105,7 +100,6 @@ It only uses language primitives and immutable objects
|
||||
### Variables
|
||||
|
||||
- [NX_VERSION](../../devkit/documents/NX_VERSION): string
|
||||
- [appRootPath](../../devkit/documents/appRootPath): string
|
||||
- [cacheDir](../../devkit/documents/cacheDir): string
|
||||
- [logger](../../devkit/documents/logger): Object
|
||||
- [output](../../devkit/documents/output): CLIOutput
|
||||
|
||||
@ -1,9 +0,0 @@
|
||||
# Variable: appRootPath
|
||||
|
||||
• `Const` **appRootPath**: `string` = `workspaceRoot`
|
||||
|
||||
The root of the workspace.
|
||||
|
||||
**`Deprecated`**
|
||||
|
||||
use workspaceRoot instead
|
||||
@ -1,19 +1,5 @@
|
||||
# Function: parseTargetString
|
||||
|
||||
▸ **parseTargetString**(`targetString`): [`Target`](../../devkit/documents/Target)
|
||||
|
||||
@deprecated(v17) A project graph should be passed to parseTargetString for best accuracy.
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
| :------------- | :------- |
|
||||
| `targetString` | `string` |
|
||||
|
||||
#### Returns
|
||||
|
||||
[`Target`](../../devkit/documents/Target)
|
||||
|
||||
▸ **parseTargetString**(`targetString`, `projectGraph`): [`Target`](../../devkit/documents/Target)
|
||||
|
||||
Parses a target string into {project, target, configuration}
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
|
||||
**`Deprecated`**
|
||||
|
||||
You must pass a [Tree](../../devkit/documents/Tree)
|
||||
You must pass a [Tree](../../devkit/documents/Tree). This will be removed in Nx 21.
|
||||
|
||||
▸ **readNxJson**(`tree`): [`NxJsonConfiguration`](../../devkit/documents/NxJsonConfiguration) \| `null`
|
||||
|
||||
|
||||
@ -20,7 +20,6 @@ It only uses language primitives and immutable objects
|
||||
### Classes
|
||||
|
||||
- [AggregateCreateNodesError](../../devkit/documents/AggregateCreateNodesError)
|
||||
- [ProjectGraphBuilder](../../devkit/documents/ProjectGraphBuilder)
|
||||
|
||||
### Interfaces
|
||||
|
||||
@ -49,7 +48,6 @@ It only uses language primitives and immutable objects
|
||||
- [ProjectGraph](../../devkit/documents/ProjectGraph)
|
||||
- [ProjectGraphDependency](../../devkit/documents/ProjectGraphDependency)
|
||||
- [ProjectGraphExternalNode](../../devkit/documents/ProjectGraphExternalNode)
|
||||
- [ProjectGraphProcessorContext](../../devkit/documents/ProjectGraphProcessorContext)
|
||||
- [ProjectGraphProjectNode](../../devkit/documents/ProjectGraphProjectNode)
|
||||
- [ProjectsConfigurations](../../devkit/documents/ProjectsConfigurations)
|
||||
- [RemoteCache](../../devkit/documents/RemoteCache)
|
||||
@ -85,12 +83,9 @@ It only uses language primitives and immutable objects
|
||||
- [ImplicitDependency](../../devkit/documents/ImplicitDependency)
|
||||
- [ImplicitDependencyEntry](../../devkit/documents/ImplicitDependencyEntry)
|
||||
- [NxPlugin](../../devkit/documents/NxPlugin)
|
||||
- [NxPluginV1](../../devkit/documents/NxPluginV1)
|
||||
- [NxPluginV2](../../devkit/documents/NxPluginV2)
|
||||
- [PackageManager](../../devkit/documents/PackageManager)
|
||||
- [PluginConfiguration](../../devkit/documents/PluginConfiguration)
|
||||
- [ProjectGraphNode](../../devkit/documents/ProjectGraphNode)
|
||||
- [ProjectTargetConfigurator](../../devkit/documents/ProjectTargetConfigurator)
|
||||
- [ProjectType](../../devkit/documents/ProjectType)
|
||||
- [ProjectsMetadata](../../devkit/documents/ProjectsMetadata)
|
||||
- [PromiseExecutor](../../devkit/documents/PromiseExecutor)
|
||||
@ -105,7 +100,6 @@ It only uses language primitives and immutable objects
|
||||
### Variables
|
||||
|
||||
- [NX_VERSION](../../devkit/documents/NX_VERSION): string
|
||||
- [appRootPath](../../devkit/documents/appRootPath): string
|
||||
- [cacheDir](../../devkit/documents/cacheDir): string
|
||||
- [logger](../../devkit/documents/logger): Object
|
||||
- [output](../../devkit/documents/output): CLIOutput
|
||||
|
||||
@ -8,8 +8,9 @@ and the version of NodeJS that we tested it against.
|
||||
|
||||
| Nx Version | Node Version | Typescript Version |
|
||||
| --------------- | ---------------- | ------------------ |
|
||||
| 19.x (latest) | 22.x, 20.x, 18.x | ~5.4.2 |
|
||||
| 18.x (previous) | 20.x, 18.x | ~5.4.2 |
|
||||
| 20.x (latest) | 22.x, 20.x | ~5.4.2 |
|
||||
| 19.x (previous) | 22.x, 20.x, 18.x | ~5.4.2 |
|
||||
| 18.x | 20.x, 18.x | ~5.4.2 |
|
||||
| 17.x | 20.x, 18.x | ~5.1.0 |
|
||||
| 16.x | 20.x, 18.x, 16.x | ~5.1.0 |
|
||||
| 15.x | 18.x, 16.x, 14.x | ~5.0.0 |
|
||||
|
||||
@ -8,8 +8,9 @@ and the version of NodeJS that we tested it against.
|
||||
|
||||
| Nx Version | Node Version | Typescript Version |
|
||||
| --------------- | ---------------- | ------------------ |
|
||||
| 19.x (latest) | 22.x, 20.x, 18.x | ~5.4.2 |
|
||||
| 18.x (previous) | 20.x, 18.x | ~5.4.2 |
|
||||
| 20.x (latest) | 22.x, 20.x | ~5.4.2 |
|
||||
| 19.x (previous) | 22.x, 20.x, 18.x | ~5.4.2 |
|
||||
| 18.x | 20.x, 18.x | ~5.4.2 |
|
||||
| 17.x | 20.x, 18.x | ~5.1.0 |
|
||||
| 16.x | 20.x, 18.x, 16.x | ~5.1.0 |
|
||||
| 15.x | 18.x, 16.x, 14.x | ~5.0.0 |
|
||||
|
||||
@ -55,32 +55,43 @@ describe('Extra Nx Misc Tests', () => {
|
||||
const nxJson = readJson('nx.json');
|
||||
nxJson.plugins = ['./tools/plugin'];
|
||||
updateFile('nx.json', JSON.stringify(nxJson));
|
||||
updateFile('test/project.txt', 'plugin-node');
|
||||
updateFile('test2/project.txt', 'plugin-node2');
|
||||
updateFile('test2/dependencies.txt', 'plugin-node');
|
||||
updateFile(
|
||||
'tools/plugin.js',
|
||||
`
|
||||
const { readFileSync } = require('fs');
|
||||
const { dirname } = require('path');
|
||||
module.exports = {
|
||||
processProjectGraph: (graph) => {
|
||||
const Builder = require('@nx/devkit').ProjectGraphBuilder;
|
||||
const builder = new Builder(graph);
|
||||
builder.addNode({
|
||||
name: 'plugin-node',
|
||||
type: 'lib',
|
||||
data: {
|
||||
root: 'test'
|
||||
createNodesV2: ['**/project.txt', (configFiles) => {
|
||||
const results = [];
|
||||
for (const configFile of configFiles) {
|
||||
const name = readFileSync(configFile, 'utf8');
|
||||
results.push([configFile, {
|
||||
projects: {
|
||||
[dirname(configFile)]: {
|
||||
name: name,
|
||||
}
|
||||
}
|
||||
}]);
|
||||
}
|
||||
|
||||
return results;
|
||||
}],
|
||||
createDependencies: () => {
|
||||
return [
|
||||
{
|
||||
|
||||
source: 'plugin-node',
|
||||
/**
|
||||
* The name of a {@link ProjectGraphProjectNode} that the source project depends on
|
||||
*/
|
||||
target: 'plugin-node2',
|
||||
|
||||
type: 'implicit'
|
||||
}
|
||||
});
|
||||
builder.addNode({
|
||||
name: 'plugin-node2',
|
||||
type: 'lib',
|
||||
data: {
|
||||
root: 'test2'
|
||||
}
|
||||
});
|
||||
builder.addImplicitDependency(
|
||||
'plugin-node',
|
||||
'plugin-node2'
|
||||
);
|
||||
return builder.getUpdatedProjectGraph();
|
||||
];
|
||||
}
|
||||
};
|
||||
`
|
||||
|
||||
@ -393,36 +393,6 @@ describe('Nx Running Tests', () => {
|
||||
);
|
||||
}, 10000);
|
||||
|
||||
it('should run targets inferred from plugin-specified project files', () => {
|
||||
// Setup an app to extend
|
||||
const myapp = uniq('app');
|
||||
runCLI(`generate @nx/web:app ${myapp} --directory=apps/${myapp}`);
|
||||
|
||||
// Register an Nx plugin
|
||||
const plugin = `module.exports = {
|
||||
projectFilePatterns: ['inferred-project.nxproject'],
|
||||
registerProjectTargets: () => ({
|
||||
"echo": {
|
||||
"executor": "nx:run-commands",
|
||||
"options": {
|
||||
"command": "echo inferred-target"
|
||||
}
|
||||
}
|
||||
})
|
||||
}`;
|
||||
updateFile('tools/local-plugin/plugin.js', plugin);
|
||||
updateFile('nx.json', (c) => {
|
||||
const nxJson = JSON.parse(c);
|
||||
nxJson.plugins = ['./tools/local-plugin/plugin.js'];
|
||||
return JSON.stringify(nxJson, null, 2);
|
||||
});
|
||||
|
||||
// Create a custom project file for the app
|
||||
updateFile(`apps/${myapp}/inferred-project.nxproject`, 'contents');
|
||||
|
||||
expect(runCLI(`echo ${myapp}`)).toContain('inferred-target');
|
||||
});
|
||||
|
||||
it('should build a specific project with the daemon disabled', () => {
|
||||
const myapp = uniq('app');
|
||||
runCLI(`generate @nx/web:app ${myapp} --directory=apps/${myapp}`);
|
||||
|
||||
@ -271,47 +271,7 @@ describe('Nx Plugin', () => {
|
||||
runCLI(`generate @nx/plugin:plugin ${plugin} --linter=eslint`);
|
||||
});
|
||||
|
||||
it('should be able to infer projects and targets (v1)', async () => {
|
||||
// Setup project inference + target inference
|
||||
updateFile(
|
||||
`${plugin}/src/index.ts`,
|
||||
`import {basename} from 'path'
|
||||
|
||||
export function registerProjectTargets(f) {
|
||||
if (basename(f) === 'my-project-file') {
|
||||
return {
|
||||
build: {
|
||||
executor: "nx:run-commands",
|
||||
options: {
|
||||
command: "echo 'custom registered target'"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const projectFilePatterns = ['my-project-file'];
|
||||
`
|
||||
);
|
||||
|
||||
// Register plugin in nx.json (required for inference)
|
||||
updateFile(`nx.json`, (nxJson) => {
|
||||
const nx = JSON.parse(nxJson);
|
||||
nx.plugins = [`@${workspaceName}/${plugin}`];
|
||||
return JSON.stringify(nx, null, 2);
|
||||
});
|
||||
|
||||
// Create project that should be inferred by Nx
|
||||
const inferredProject = uniq('inferred');
|
||||
createFile(`${inferredProject}/my-project-file`);
|
||||
|
||||
// Attempt to use inferred project w/ Nx
|
||||
expect(runCLI(`build ${inferredProject}`)).toContain(
|
||||
'custom registered target'
|
||||
);
|
||||
});
|
||||
|
||||
it('should be able to infer projects and targets (v2)', async () => {
|
||||
it('should be able to infer projects and targets', async () => {
|
||||
// Setup project inference + target inference
|
||||
updateFile(`${plugin}/src/index.ts`, NX_PLUGIN_V2_CONTENTS);
|
||||
|
||||
|
||||
@ -135,7 +135,7 @@
|
||||
"@types/jest": "29.5.12",
|
||||
"@types/js-yaml": "^4.0.5",
|
||||
"@types/marked": "^2.0.0",
|
||||
"@types/node": "18.19.8",
|
||||
"@types/node": "20.16.10",
|
||||
"@types/npm-package-arg": "6.1.1",
|
||||
"@types/react": "18.3.1",
|
||||
"@types/react-dom": "18.3.0",
|
||||
|
||||
@ -5,6 +5,8 @@ import {
|
||||
normalizePath,
|
||||
parseTargetString,
|
||||
readCachedProjectGraph,
|
||||
readProjectsConfigurationFromProjectGraph,
|
||||
workspaceRoot,
|
||||
} from '@nx/devkit';
|
||||
import { getRootTsConfigPath } from '@nx/js';
|
||||
import type { DependentBuildableProjectNode } from '@nx/js/src/utils/buildable-libs-utils';
|
||||
@ -34,6 +36,7 @@ import type {
|
||||
Schema,
|
||||
SchemaWithBrowserTarget,
|
||||
} from './schema';
|
||||
import { readNxJson } from 'nx/src/config/configuration';
|
||||
|
||||
type BuildTargetOptions = {
|
||||
tsConfig: string;
|
||||
@ -55,11 +58,16 @@ export function executeDevServerBuilder(
|
||||
|
||||
const options = normalizeOptions(rawOptions);
|
||||
|
||||
const projectGraph = readCachedProjectGraph();
|
||||
|
||||
const parsedBuildTarget = parseTargetString(options.buildTarget, {
|
||||
cwd: context.currentDirectory,
|
||||
projectGraph: readCachedProjectGraph(),
|
||||
projectGraph,
|
||||
projectName: context.target.project,
|
||||
projectsConfigurations:
|
||||
readProjectsConfigurationFromProjectGraph(projectGraph),
|
||||
root: context.workspaceRoot,
|
||||
nxJsonConfiguration: readNxJson(workspaceRoot),
|
||||
isVerbose: false,
|
||||
});
|
||||
const browserTargetProjectConfiguration = readCachedProjectConfiguration(
|
||||
|
||||
@ -96,7 +96,7 @@ export async function configurationGeneratorInternal(
|
||||
|
||||
await addFiles(tree, opts, projectGraph, hasPlugin);
|
||||
if (!hasPlugin) {
|
||||
addTarget(tree, opts);
|
||||
addTarget(tree, opts, projectGraph);
|
||||
}
|
||||
|
||||
const linterTask = await addLinterToCyProject(tree, {
|
||||
@ -290,7 +290,11 @@ async function addFiles(
|
||||
}
|
||||
}
|
||||
|
||||
function addTarget(tree: Tree, opts: NormalizedSchema) {
|
||||
function addTarget(
|
||||
tree: Tree,
|
||||
opts: NormalizedSchema,
|
||||
projectGraph: ProjectGraph
|
||||
) {
|
||||
const projectConfig = readProjectConfiguration(tree, opts.project);
|
||||
const cyVersion = installedCypressVersion();
|
||||
projectConfig.targets ??= {};
|
||||
@ -307,7 +311,7 @@ function addTarget(tree: Tree, opts: NormalizedSchema) {
|
||||
},
|
||||
};
|
||||
if (opts.devServerTarget) {
|
||||
const parsedTarget = parseTargetString(opts.devServerTarget);
|
||||
const parsedTarget = parseTargetString(opts.devServerTarget, projectGraph);
|
||||
|
||||
projectConfig.targets.e2e.options = {
|
||||
...projectConfig.targets.e2e.options,
|
||||
|
||||
@ -38,7 +38,7 @@
|
||||
"enquirer": "~2.3.6"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"nx": ">= 17 <= 20"
|
||||
"nx": ">= 19 <= 21"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
|
||||
@ -1,7 +1,11 @@
|
||||
import { parseTargetString, targetToTargetString } from './parse-target-string';
|
||||
|
||||
import * as splitTarget from 'nx/src/utils/split-target';
|
||||
import { ExecutorContext } from 'nx/src/devkit-exports';
|
||||
import {
|
||||
ExecutorContext,
|
||||
ProjectGraph,
|
||||
readProjectsConfigurationFromProjectGraph,
|
||||
} from 'nx/src/devkit-exports';
|
||||
|
||||
const cases = [
|
||||
{ input: 'one:two', expected: { project: 'one', target: 'two' } },
|
||||
@ -16,28 +20,31 @@ const cases = [
|
||||
];
|
||||
|
||||
describe('parseTargetString', () => {
|
||||
const graph: ProjectGraph = {
|
||||
nodes: {
|
||||
'my-project': {
|
||||
type: 'lib',
|
||||
name: 'my-project',
|
||||
data: { root: '/packages/my-project' },
|
||||
},
|
||||
'other-project': {
|
||||
type: 'lib',
|
||||
name: 'other-project',
|
||||
data: { root: '/packages/other-project' },
|
||||
},
|
||||
},
|
||||
dependencies: {},
|
||||
externalNodes: {},
|
||||
version: '',
|
||||
};
|
||||
const mockContext: ExecutorContext = {
|
||||
projectName: 'my-project',
|
||||
cwd: '/virtual',
|
||||
root: '/virtual',
|
||||
isVerbose: false,
|
||||
projectGraph: {
|
||||
nodes: {
|
||||
'my-project': {
|
||||
type: 'lib',
|
||||
name: 'my-project',
|
||||
data: { root: '/packages/my-project' },
|
||||
},
|
||||
'other-project': {
|
||||
type: 'lib',
|
||||
name: 'other-project',
|
||||
data: { root: '/packages/other-project' },
|
||||
},
|
||||
},
|
||||
dependencies: {},
|
||||
externalNodes: {},
|
||||
version: '',
|
||||
},
|
||||
projectGraph: graph,
|
||||
projectsConfigurations: readProjectsConfigurationFromProjectGraph(graph),
|
||||
nxJsonConfiguration: {},
|
||||
};
|
||||
|
||||
it.each(cases)('$input -> $expected', ({ input, expected }) => {
|
||||
|
||||
@ -6,10 +6,6 @@ import {
|
||||
} from 'nx/src/devkit-exports';
|
||||
import { splitByColons, splitTarget } from 'nx/src/devkit-internals';
|
||||
|
||||
/**
|
||||
* @deprecated(v17) A project graph should be passed to parseTargetString for best accuracy.
|
||||
*/
|
||||
export function parseTargetString(targetString: string): Target;
|
||||
/**
|
||||
* Parses a target string into {project, target, configuration}
|
||||
*
|
||||
|
||||
@ -17,9 +17,7 @@ export function readTargetOptions<T = any>(
|
||||
{ project, target, configuration }: Target,
|
||||
context: ExecutorContext
|
||||
): T {
|
||||
const projectConfiguration = (
|
||||
context.workspace || context.projectsConfigurations
|
||||
).projects[project];
|
||||
const projectConfiguration = context.projectsConfigurations.projects[project];
|
||||
|
||||
if (!projectConfiguration) {
|
||||
throw new Error(`Unable to find project ${project}`);
|
||||
@ -36,7 +34,7 @@ export function readTargetOptions<T = any>(
|
||||
nodeModule,
|
||||
executorName,
|
||||
context.root,
|
||||
context.projectsConfigurations?.projects ?? context.workspace.projects
|
||||
context.projectsConfigurations?.projects
|
||||
);
|
||||
|
||||
const defaultProject = calculateDefaultProjectName(
|
||||
|
||||
@ -21,6 +21,7 @@ describe('normalizeOptions', () => {
|
||||
cwd: '/',
|
||||
isVerbose: false,
|
||||
projectName: 'myapp',
|
||||
nxJsonConfiguration: {},
|
||||
projectsConfigurations: {
|
||||
version: 2,
|
||||
projects: {
|
||||
|
||||
@ -95,6 +95,22 @@ describe('Linter Builder', () => {
|
||||
projectName,
|
||||
root: tempFs.tempDir,
|
||||
cwd: tempFs.tempDir,
|
||||
projectGraph: {
|
||||
nodes: {
|
||||
[projectName]: {
|
||||
type: 'app',
|
||||
name: projectName,
|
||||
data: {
|
||||
root: `apps/${projectName}`,
|
||||
sourceRoot: `apps/${projectName}/src`,
|
||||
targets: {},
|
||||
},
|
||||
},
|
||||
},
|
||||
dependencies: {
|
||||
[projectName]: [],
|
||||
},
|
||||
},
|
||||
projectsConfigurations: {
|
||||
version: 2,
|
||||
projects: {
|
||||
|
||||
@ -37,6 +37,25 @@ describe('Jest Executor', () => {
|
||||
mockContext = {
|
||||
root: '/root',
|
||||
projectName: 'proj',
|
||||
projectGraph: {
|
||||
nodes: {
|
||||
proj: {
|
||||
type: 'lib',
|
||||
name: 'proj',
|
||||
data: {
|
||||
root: 'proj',
|
||||
targets: {
|
||||
test: {
|
||||
executor: '@nx/jest:jest',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
dependencies: {
|
||||
proj: [],
|
||||
},
|
||||
},
|
||||
projectsConfigurations: {
|
||||
version: 2,
|
||||
projects: {
|
||||
|
||||
@ -11,6 +11,10 @@ describe('tscExecutor', () => {
|
||||
context = {
|
||||
root: '/root',
|
||||
cwd: '/root',
|
||||
projectGraph: {
|
||||
nodes: {},
|
||||
dependencies: {},
|
||||
},
|
||||
projectsConfigurations: {
|
||||
version: 2,
|
||||
projects: {},
|
||||
|
||||
@ -6,7 +6,12 @@ import {
|
||||
UpdatePackageJsonOption,
|
||||
} from './update-package-json';
|
||||
import { vol } from 'memfs';
|
||||
import { DependencyType, ExecutorContext, ProjectGraph } from '@nx/devkit';
|
||||
import {
|
||||
DependencyType,
|
||||
ExecutorContext,
|
||||
ProjectGraph,
|
||||
readProjectsConfigurationFromProjectGraph,
|
||||
} from '@nx/devkit';
|
||||
import { DependentBuildableProjectNode } from '../buildable-libs-utils';
|
||||
|
||||
jest.mock('nx/src/utils/workspace-root', () => ({
|
||||
@ -471,6 +476,9 @@ describe('updatePackageJson', () => {
|
||||
cwd: '',
|
||||
targetName: 'build',
|
||||
projectGraph,
|
||||
projectsConfigurations:
|
||||
readProjectsConfigurationFromProjectGraph(projectGraph),
|
||||
nxJsonConfiguration: {},
|
||||
};
|
||||
|
||||
it('should generate new package if missing', () => {
|
||||
|
||||
@ -10,6 +10,7 @@ import {
|
||||
ExecutorContext,
|
||||
parseTargetString,
|
||||
readCachedProjectGraph,
|
||||
readProjectsConfigurationFromProjectGraph,
|
||||
readTargetOptions,
|
||||
stripIndents,
|
||||
workspaceRoot,
|
||||
@ -24,6 +25,7 @@ import {
|
||||
import { join } from 'path';
|
||||
import { NextBuildBuilderOptions } from '../src/utils/types';
|
||||
import { CypressExecutorOptions } from '@nx/cypress/src/executors/cypress/cypress.impl';
|
||||
import { readNxJson } from 'nx/src/config/configuration';
|
||||
|
||||
export function nxComponentTestingPreset(
|
||||
pathToConfig: string,
|
||||
@ -71,6 +73,8 @@ export function nxComponentTestingPreset(
|
||||
const parsedBuildTarget = parseTargetString(buildTarget, {
|
||||
cwd: process.cwd(),
|
||||
root: workspaceRoot,
|
||||
projectsConfigurations: readProjectsConfigurationFromProjectGraph(graph),
|
||||
nxJsonConfiguration: readNxJson(workspaceRoot),
|
||||
isVerbose: false,
|
||||
projectName: ctProjectName,
|
||||
projectGraph: graph,
|
||||
|
||||
@ -23,7 +23,8 @@ export default async function* serveExecutor(
|
||||
parseTargetString(options.buildTarget, context),
|
||||
context
|
||||
);
|
||||
const projectRoot = context.workspace.projects[context.projectName].root;
|
||||
const projectRoot =
|
||||
context.projectsConfigurations.projects[context.projectName].root;
|
||||
// This is required for the default custom server to work. See the @nx/next:app generator.
|
||||
const nextDir =
|
||||
!options.dev && resolve(context.root, buildOptions.outputPath);
|
||||
|
||||
@ -4,8 +4,6 @@ import { commandsObject } from '../src/command-line/nx-commands';
|
||||
import { WorkspaceTypeAndRoot } from '../src/utils/find-workspace-root';
|
||||
import { stripIndents } from '../src/utils/strip-indents';
|
||||
|
||||
import * as Mod from 'module';
|
||||
|
||||
/**
|
||||
* Nx is being run inside a workspace.
|
||||
*
|
||||
@ -18,8 +16,6 @@ export function initLocal(workspace: WorkspaceTypeAndRoot) {
|
||||
try {
|
||||
performance.mark('init-local');
|
||||
|
||||
monkeyPatchRequire();
|
||||
|
||||
if (workspace.type !== 'nx' && shouldDelegateToAngularCLI()) {
|
||||
console.warn(
|
||||
stripIndents`Using Nx to run Angular CLI commands is deprecated and will be removed in a future version.
|
||||
@ -162,42 +158,3 @@ To update the cache configuration, you can directly update the relevant options
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(v17): Remove this once the @nrwl/* packages are not
|
||||
function monkeyPatchRequire() {
|
||||
const originalRequire = Mod.prototype.require;
|
||||
|
||||
(Mod.prototype.require as any) = function (...args) {
|
||||
const modulePath = args[0];
|
||||
if (!modulePath.startsWith('@nrwl/')) {
|
||||
return originalRequire.apply(this, args);
|
||||
} else {
|
||||
try {
|
||||
// Try the original require
|
||||
return originalRequire.apply(this, args);
|
||||
} catch (e) {
|
||||
if (e.code !== 'MODULE_NOT_FOUND') {
|
||||
throw e;
|
||||
}
|
||||
|
||||
try {
|
||||
// Retry the require with the @nx package
|
||||
return originalRequire.apply(
|
||||
this,
|
||||
args.map((value, i) => {
|
||||
if (i !== 0) {
|
||||
return value;
|
||||
} else {
|
||||
return value.replace('@nrwl/', '@nx/');
|
||||
}
|
||||
})
|
||||
);
|
||||
} catch {
|
||||
// Throw the original error
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
// do some side-effect of your own
|
||||
};
|
||||
}
|
||||
|
||||
@ -167,18 +167,9 @@ function resolveNx(workspace: WorkspaceTypeAndRoot | null) {
|
||||
} catch {}
|
||||
|
||||
// check for root install
|
||||
try {
|
||||
return require.resolve('nx/bin/nx.js', {
|
||||
paths: [workspace ? workspace.dir : globalsRoot],
|
||||
});
|
||||
} catch {
|
||||
// TODO(v17): Remove this
|
||||
// fallback for old CLI install setup
|
||||
// nx-ignore-next-line
|
||||
return require.resolve('@nrwl/cli/bin/nx.js', {
|
||||
paths: [workspace ? workspace.dir : globalsRoot],
|
||||
});
|
||||
}
|
||||
return require.resolve('nx/bin/nx.js', {
|
||||
paths: [workspace ? workspace.dir : globalsRoot],
|
||||
});
|
||||
}
|
||||
|
||||
function handleMissingLocalInstallation() {
|
||||
|
||||
@ -52,6 +52,11 @@
|
||||
"description": "Set project name in nx.json explicitly",
|
||||
"implementation": "./src/migrations/update-19-2-4/set-project-name",
|
||||
"x-repair-skip": true
|
||||
},
|
||||
"move-use-daemon-process": {
|
||||
"version": "20.0.0-beta.7",
|
||||
"description": "Migration for v20.0.0-beta.7",
|
||||
"implementation": "./src/migrations/update-20-0-0/move-use-daemon-process"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,11 +18,9 @@ import { projectHasTarget } from '../../utils/project-graph-utils';
|
||||
import { filterAffected } from '../../project-graph/affected/affected-project-graph';
|
||||
import { TargetDependencyConfig } from '../../config/workspace-json-project-json';
|
||||
import { readNxJson } from '../../config/configuration';
|
||||
import { workspaceConfigurationCheck } from '../../utils/workspace-configuration-check';
|
||||
import { findMatchingProjects } from '../../utils/find-matching-projects';
|
||||
import { generateGraph } from '../graph/graph';
|
||||
import { allFileData } from '../../utils/all-file-data';
|
||||
import { NX_PREFIX, logger } from '../../utils/logger';
|
||||
|
||||
export async function affected(
|
||||
command: 'graph' | 'print-affected' | 'affected',
|
||||
@ -41,7 +39,6 @@ export async function affected(
|
||||
): Promise<void> {
|
||||
performance.mark('code-loading:end');
|
||||
performance.measure('code-loading', 'init-local', 'code-loading:end');
|
||||
workspaceConfigurationCheck();
|
||||
|
||||
const nxJson = readNxJson();
|
||||
const { nxArgs, overrides } = splitArgsIntoNxArgsAndOverrides(
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
* https://github.com/unjs/changelogen
|
||||
*/
|
||||
import { interpolate } from '../../../tasks-runner/utils';
|
||||
import { workspaceRoot } from '../../../utils/app-root';
|
||||
import { workspaceRoot } from '../../../utils/workspace-root';
|
||||
import { execCommand } from './exec-command';
|
||||
|
||||
export interface GitCommitAuthor {
|
||||
|
||||
@ -2,8 +2,8 @@ import { runCommand } from '../../tasks-runner/run-command';
|
||||
import {
|
||||
NxArgs,
|
||||
readGraphFileFromGraphArg,
|
||||
splitArgsIntoNxArgsAndOverrides,
|
||||
} from '../../utils/command-line-utils';
|
||||
import { splitArgsIntoNxArgsAndOverrides } from '../../utils/command-line-utils';
|
||||
import { projectHasTarget } from '../../utils/project-graph-utils';
|
||||
import { connectToNxCloudIfExplicitlyAsked } from '../connect/connect-to-nx-cloud';
|
||||
import { performance } from 'perf_hooks';
|
||||
@ -16,7 +16,6 @@ import { TargetDependencyConfig } from '../../config/workspace-json-project-json
|
||||
import { readNxJson } from '../../config/configuration';
|
||||
import { output } from '../../utils/output';
|
||||
import { findMatchingProjects } from '../../utils/find-matching-projects';
|
||||
import { workspaceConfigurationCheck } from '../../utils/workspace-configuration-check';
|
||||
import { generateGraph } from '../graph/graph';
|
||||
|
||||
export async function runMany(
|
||||
@ -35,7 +34,6 @@ export async function runMany(
|
||||
) {
|
||||
performance.mark('code-loading:end');
|
||||
performance.measure('code-loading', 'init-local', 'code-loading:end');
|
||||
workspaceConfigurationCheck();
|
||||
const nxJson = readNxJson();
|
||||
const { nxArgs, overrides } = splitArgsIntoNxArgsAndOverrides(
|
||||
args,
|
||||
|
||||
@ -17,7 +17,6 @@ import { output } from '../../utils/output';
|
||||
import { TargetDependencyConfig } from '../../config/workspace-json-project-json';
|
||||
import { readNxJson } from '../../config/configuration';
|
||||
import { calculateDefaultProjectName } from '../../config/calculate-default-project-name';
|
||||
import { workspaceConfigurationCheck } from '../../utils/workspace-configuration-check';
|
||||
import { generateGraph } from '../graph/graph';
|
||||
|
||||
export async function runOne(
|
||||
@ -37,7 +36,6 @@ export async function runOne(
|
||||
): Promise<void> {
|
||||
performance.mark('code-loading:end');
|
||||
performance.measure('code-loading', 'init-local', 'code-loading:end');
|
||||
workspaceConfigurationCheck();
|
||||
|
||||
const nxJson = readNxJson();
|
||||
const projectGraph = await createProjectGraphAsync();
|
||||
|
||||
@ -190,7 +190,6 @@ async function runExecutorInternal<T extends { success: boolean }>(
|
||||
target: targetConfig,
|
||||
projectsConfigurations,
|
||||
nxJsonConfiguration,
|
||||
workspace: { ...projectsConfigurations, ...nxJsonConfiguration },
|
||||
projectName: project,
|
||||
targetName: target,
|
||||
configurationName: configuration,
|
||||
|
||||
@ -209,17 +209,13 @@ export interface ExecutorContext {
|
||||
|
||||
/**
|
||||
* Projects config
|
||||
*
|
||||
* @todo(vsavkin): mark this as required for v17
|
||||
*/
|
||||
projectsConfigurations?: ProjectsConfigurations;
|
||||
projectsConfigurations: ProjectsConfigurations;
|
||||
|
||||
/**
|
||||
* The contents of nx.json.
|
||||
*
|
||||
* @todo(vsavkin): mark this as required for v17
|
||||
*/
|
||||
nxJsonConfiguration?: NxJsonConfiguration;
|
||||
nxJsonConfiguration: NxJsonConfiguration;
|
||||
|
||||
/**
|
||||
* The current working directory
|
||||
@ -234,21 +230,12 @@ export interface ExecutorContext {
|
||||
/**
|
||||
* A snapshot of the project graph as
|
||||
* it existed when the Nx command was kicked off
|
||||
*
|
||||
* @todo(vsavkin) mark this required for v17
|
||||
*/
|
||||
projectGraph?: ProjectGraph;
|
||||
projectGraph: ProjectGraph;
|
||||
|
||||
/**
|
||||
* A snapshot of the task graph as
|
||||
* it existed when the Nx command was kicked off
|
||||
*/
|
||||
taskGraph?: TaskGraph;
|
||||
|
||||
/**
|
||||
* Deprecated. Use projectsConfigurations or nxJsonConfiguration
|
||||
* The full workspace configuration
|
||||
* @todo(vsavkin): remove after v17
|
||||
*/
|
||||
workspace?: ProjectsConfigurations & NxJsonConfiguration;
|
||||
}
|
||||
|
||||
@ -89,11 +89,6 @@ export enum DependencyType {
|
||||
implicit = 'implicit',
|
||||
}
|
||||
|
||||
/** @deprecated this type will be removed in v16. Use {@link ProjectGraphProjectNode} or {@link ProjectGraphExternalNode} instead */
|
||||
export type ProjectGraphNode =
|
||||
| ProjectGraphProjectNode
|
||||
| ProjectGraphExternalNode;
|
||||
|
||||
/**
|
||||
* A node describing a project in a workspace
|
||||
*/
|
||||
|
||||
@ -123,10 +123,7 @@ export class DaemonClient {
|
||||
|
||||
enabled() {
|
||||
if (this._enabled === undefined) {
|
||||
// TODO(v19): Add migration to move it out of existing configs and remove the ?? here.
|
||||
const useDaemonProcessOption =
|
||||
this.nxJson?.useDaemonProcess ??
|
||||
this.nxJson?.tasksRunnerOptions?.['default']?.options?.useDaemonProcess;
|
||||
const useDaemonProcessOption = this.nxJson?.useDaemonProcess;
|
||||
const env = process.env.NX_DAEMON;
|
||||
|
||||
// env takes precedence
|
||||
|
||||
@ -63,11 +63,6 @@ export { AggregateCreateNodesError } from './project-graph/error-types';
|
||||
|
||||
export { createNodesFromFiles } from './project-graph/plugins';
|
||||
|
||||
export type {
|
||||
NxPluginV1,
|
||||
ProjectTargetConfigurator,
|
||||
} from './utils/nx-plugin.deprecated';
|
||||
|
||||
/**
|
||||
* @category Workspace
|
||||
*/
|
||||
@ -153,10 +148,8 @@ export type {
|
||||
FileData,
|
||||
ProjectGraph,
|
||||
ProjectGraphDependency,
|
||||
ProjectGraphNode,
|
||||
ProjectGraphProjectNode,
|
||||
ProjectGraphExternalNode,
|
||||
ProjectGraphProcessorContext,
|
||||
} from './config/project-graph';
|
||||
|
||||
export type { GraphJson } from './command-line/graph/graph';
|
||||
@ -170,7 +163,6 @@ export { DependencyType } from './config/project-graph';
|
||||
* @category Project Graph
|
||||
*/
|
||||
export {
|
||||
ProjectGraphBuilder,
|
||||
RawProjectGraphDependency,
|
||||
DynamicDependency,
|
||||
ImplicitDependency,
|
||||
@ -208,11 +200,10 @@ export { stripIndents } from './utils/strip-indents';
|
||||
*/
|
||||
export { joinPathFragments, normalizePath } from './utils/path';
|
||||
|
||||
// TODO(v16): Change this to export from './utils/workspace-root'
|
||||
/**
|
||||
* @category Utils
|
||||
*/
|
||||
export { workspaceRoot, appRootPath } from './utils/app-root';
|
||||
export { workspaceRoot } from './utils/workspace-root';
|
||||
|
||||
/**
|
||||
* @category Utils
|
||||
|
||||
@ -43,7 +43,6 @@ export function convertNxExecutor(executor: Executor) {
|
||||
targetName: builderContext.target.target,
|
||||
target: builderContext.target.target,
|
||||
configurationName: builderContext.target.configuration,
|
||||
workspace: { ...nxJsonConfiguration, ...projectsConfigurations },
|
||||
projectsConfigurations,
|
||||
nxJsonConfiguration,
|
||||
cwd: process.cwd(),
|
||||
|
||||
@ -7,7 +7,7 @@ import { readJson, updateJson } from './json';
|
||||
import { readNxJson as readNxJsonFromDisk } from '../../config/nx-json';
|
||||
|
||||
/**
|
||||
* @deprecated You must pass a {@link Tree}
|
||||
* @deprecated You must pass a {@link Tree}. This will be removed in Nx 21.
|
||||
*/
|
||||
export function readNxJson(): NxJsonConfiguration | null;
|
||||
export function readNxJson(tree: Tree): NxJsonConfiguration | null;
|
||||
|
||||
@ -0,0 +1,33 @@
|
||||
import { createTreeWithEmptyWorkspace } from '../../generators/testing-utils/create-tree-with-empty-workspace';
|
||||
import { Tree } from '../../generators/tree';
|
||||
|
||||
import update from './move-use-daemon-process';
|
||||
import { readNxJson, updateNxJson } from '../../generators/utils/nx-json';
|
||||
|
||||
describe('move-use-daemon-process migration', () => {
|
||||
let tree: Tree;
|
||||
|
||||
beforeEach(() => {
|
||||
tree = createTreeWithEmptyWorkspace();
|
||||
});
|
||||
|
||||
it('should migrate useDaemonProcess', async () => {
|
||||
updateNxJson(tree, {
|
||||
tasksRunnerOptions: {
|
||||
default: {
|
||||
options: {
|
||||
useDaemonProcess: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await update(tree);
|
||||
|
||||
expect(readNxJson(tree)).toMatchInlineSnapshot(`
|
||||
{
|
||||
"useDaemonProcess": false,
|
||||
}
|
||||
`);
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,37 @@
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
import { Tree } from '../../generators/tree';
|
||||
import { formatChangedFilesWithPrettierIfAvailable } from '../../generators/internal-utils/format-changed-files-with-prettier-if-available';
|
||||
import { readNxJson, updateNxJson } from '../../generators/utils/nx-json';
|
||||
import { NxJsonConfiguration } from '../../config/nx-json';
|
||||
|
||||
export default async function update(tree: Tree) {
|
||||
const nxJson = readNxJson(tree) as NxJsonConfiguration;
|
||||
|
||||
if (
|
||||
nxJson?.tasksRunnerOptions?.['default']?.options?.useDaemonProcess !==
|
||||
undefined
|
||||
) {
|
||||
nxJson.useDaemonProcess =
|
||||
nxJson.tasksRunnerOptions['default'].options.useDaemonProcess;
|
||||
|
||||
delete nxJson.tasksRunnerOptions['default'].options.useDaemonProcess;
|
||||
|
||||
if (
|
||||
Object.keys(nxJson.tasksRunnerOptions['default'].options).length === 0
|
||||
) {
|
||||
delete nxJson.tasksRunnerOptions['default'].options;
|
||||
}
|
||||
|
||||
if (Object.keys(nxJson.tasksRunnerOptions['default']).length === 0) {
|
||||
delete nxJson.tasksRunnerOptions['default'];
|
||||
}
|
||||
|
||||
if (Object.keys(nxJson.tasksRunnerOptions).length === 0) {
|
||||
delete nxJson.tasksRunnerOptions;
|
||||
}
|
||||
|
||||
updateNxJson(tree, nxJson);
|
||||
}
|
||||
|
||||
await formatChangedFilesWithPrettierIfAvailable(tree);
|
||||
}
|
||||
@ -983,9 +983,9 @@ describe('TargetProjectLocator', () => {
|
||||
});
|
||||
|
||||
describe('isBuiltinModuleImport()', () => {
|
||||
const withExclusions = builtinModules.filter(
|
||||
(s) => !['test/mock_loader'].includes(s)
|
||||
);
|
||||
const withExclusions = builtinModules
|
||||
.concat(builtinModules.filter((a) => true).map((s) => 'node:' + s))
|
||||
.concat(['node:test', 'node:sqlite', 'node:test']);
|
||||
|
||||
it.each(withExclusions)(
|
||||
`should return true for %s builtin module`,
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { builtinModules } from 'node:module';
|
||||
import { dirname, join, parse, posix, relative } from 'node:path';
|
||||
import { isBuiltin } from 'node:module';
|
||||
import { dirname, join, posix, relative } from 'node:path';
|
||||
import { clean } from 'semver';
|
||||
import {
|
||||
ProjectGraphExternalNode,
|
||||
@ -31,21 +31,11 @@ type NpmResolutionCache = Map<string, string | null>;
|
||||
*/
|
||||
const defaultNpmResolutionCache: NpmResolutionCache = new Map();
|
||||
|
||||
const builtInModuleSet = new Set<string>([
|
||||
...builtinModules,
|
||||
...builtinModules.map((x) => `node:${x}`),
|
||||
// These are missing in the builtinModules list
|
||||
// See: https://github.com/nodejs/node/issues/42785
|
||||
// TODO(v20): We should be safe to use `isBuiltin` function instead of keep the set here (https://nodejs.org/api/module.html#moduleisbuiltinmodulename)
|
||||
'test',
|
||||
'node:test',
|
||||
'node:sea',
|
||||
'node:sqlite',
|
||||
]);
|
||||
const experimentalNodeModules = new Set(['node:sqlite']);
|
||||
|
||||
export function isBuiltinModuleImport(importExpr: string): boolean {
|
||||
const packageName = getPackageNameFromImportPath(importExpr);
|
||||
return builtInModuleSet.has(packageName);
|
||||
return isBuiltin(packageName) || experimentalNodeModules.has(packageName);
|
||||
}
|
||||
|
||||
export class TargetProjectLocator {
|
||||
|
||||
@ -13,7 +13,6 @@ import {
|
||||
import { applyImplicitDependencies } from './utils/implicit-project-dependencies';
|
||||
import { normalizeProjectNodes } from './utils/normalize-project-nodes';
|
||||
import { LoadedNxPlugin } from './plugins/internal-api';
|
||||
import { isNxPluginV1, isNxPluginV2 } from './plugins/utils';
|
||||
import {
|
||||
CreateDependenciesContext,
|
||||
CreateMetadataContext,
|
||||
@ -32,7 +31,6 @@ import { ProjectConfiguration } from '../config/workspace-json-project-json';
|
||||
import { readNxJson } from '../config/configuration';
|
||||
import { existsSync } from 'fs';
|
||||
import { PackageJson } from '../utils/package-json';
|
||||
import { output } from '../utils/output';
|
||||
import { NxWorkspaceFilesExternals } from '../native';
|
||||
import {
|
||||
AggregateProjectGraphError,
|
||||
@ -40,7 +38,6 @@ import {
|
||||
isAggregateProjectGraphError,
|
||||
isWorkspaceValidityError,
|
||||
ProcessDependenciesError,
|
||||
ProcessProjectGraphError,
|
||||
WorkspaceValidityError,
|
||||
} from './error-types';
|
||||
import {
|
||||
@ -99,10 +96,7 @@ export async function buildProjectGraphUsingProjectFileMap(
|
||||
}
|
||||
|
||||
const errors: Array<
|
||||
| CreateMetadataError
|
||||
| ProcessDependenciesError
|
||||
| ProcessProjectGraphError
|
||||
| WorkspaceValidityError
|
||||
CreateMetadataError | ProcessDependenciesError | WorkspaceValidityError
|
||||
> = [];
|
||||
|
||||
const nxJson = readNxJson();
|
||||
@ -306,52 +300,7 @@ async function updateProjectGraphWithPlugins(
|
||||
sourceMap: ConfigurationSourceMaps
|
||||
) {
|
||||
let graph = initProjectGraph;
|
||||
const errors: Array<
|
||||
ProcessDependenciesError | ProcessProjectGraphError | CreateMetadataError
|
||||
> = [];
|
||||
for (const plugin of plugins) {
|
||||
try {
|
||||
if (
|
||||
isNxPluginV1(plugin) &&
|
||||
plugin.processProjectGraph &&
|
||||
!plugin.createDependencies
|
||||
) {
|
||||
output.warn({
|
||||
title: `${plugin.name} is a v1 plugin.`,
|
||||
bodyLines: [
|
||||
'Nx has recently released a v2 model for project graph plugins. The `processProjectGraph` method is deprecated. Plugins should use some combination of `createNodes` and `createDependencies` instead.',
|
||||
],
|
||||
});
|
||||
performance.mark(`${plugin.name}:processProjectGraph - start`);
|
||||
graph = await plugin.processProjectGraph(graph, {
|
||||
...context,
|
||||
projectsConfigurations: {
|
||||
projects: context.projects,
|
||||
version: 2,
|
||||
},
|
||||
fileMap: context.fileMap.projectFileMap,
|
||||
filesToProcess: context.filesToProcess.projectFileMap,
|
||||
workspace: {
|
||||
version: 2,
|
||||
projects: context.projects,
|
||||
...context.nxJsonConfiguration,
|
||||
},
|
||||
});
|
||||
performance.mark(`${plugin.name}:processProjectGraph - end`);
|
||||
performance.measure(
|
||||
`${plugin.name}:processProjectGraph`,
|
||||
`${plugin.name}:processProjectGraph - start`,
|
||||
`${plugin.name}:processProjectGraph - end`
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
errors.push(
|
||||
new ProcessProjectGraphError(plugin.name, {
|
||||
cause: e,
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
const errors: Array<ProcessDependenciesError | CreateMetadataError> = [];
|
||||
|
||||
const builder = new ProjectGraphBuilder(
|
||||
graph,
|
||||
@ -360,7 +309,7 @@ async function updateProjectGraphWithPlugins(
|
||||
);
|
||||
|
||||
const createDependencyPlugins = plugins.filter(
|
||||
(plugin) => isNxPluginV2(plugin) && plugin.createDependencies
|
||||
(plugin) => plugin.createDependencies
|
||||
);
|
||||
await Promise.all(
|
||||
createDependencyPlugins.map(async (plugin) => {
|
||||
@ -439,10 +388,10 @@ export async function applyProjectMetadata(
|
||||
const errors: CreateMetadataError[] = [];
|
||||
|
||||
const promises = plugins.map(async (plugin) => {
|
||||
if (isNxPluginV2(plugin) && plugin.createMetadata) {
|
||||
if (plugin.createMetadata) {
|
||||
performance.mark(`${plugin.name}:createMetadata - start`);
|
||||
try {
|
||||
const metadata = await plugin.createMetadata(graph, undefined, context);
|
||||
const metadata = await plugin.createMetadata(graph, context);
|
||||
results.push({ metadata, pluginName: plugin.name });
|
||||
} catch (e) {
|
||||
errors.push(new CreateMetadataError(e, plugin.name));
|
||||
|
||||
@ -14,7 +14,6 @@ export class ProjectGraphError extends Error {
|
||||
| ProjectsWithNoNameError
|
||||
| MultipleProjectsWithSameNameError
|
||||
| ProcessDependenciesError
|
||||
| ProcessProjectGraphError
|
||||
| WorkspaceValidityError
|
||||
>;
|
||||
readonly #partialProjectGraph: ProjectGraph;
|
||||
@ -27,7 +26,6 @@ export class ProjectGraphError extends Error {
|
||||
| ProjectsWithNoNameError
|
||||
| MultipleProjectsWithSameNameError
|
||||
| ProcessDependenciesError
|
||||
| ProcessProjectGraphError
|
||||
| CreateMetadataError
|
||||
| WorkspaceValidityError
|
||||
>,
|
||||
@ -312,27 +310,10 @@ export function isWorkspaceValidityError(
|
||||
e?.name === WorkspaceValidityError.name)
|
||||
);
|
||||
}
|
||||
|
||||
export class ProcessProjectGraphError extends Error {
|
||||
constructor(public readonly pluginName: string, { cause }) {
|
||||
super(
|
||||
`The "${pluginName}" plugin threw an error while processing the project graph:`,
|
||||
{
|
||||
cause,
|
||||
}
|
||||
);
|
||||
this.name = this.constructor.name;
|
||||
this.stack = `${this.message}\n${indentString(cause, 2)}`;
|
||||
}
|
||||
}
|
||||
|
||||
export class AggregateProjectGraphError extends Error {
|
||||
constructor(
|
||||
public readonly errors: Array<
|
||||
| CreateMetadataError
|
||||
| ProcessDependenciesError
|
||||
| ProcessProjectGraphError
|
||||
| WorkspaceValidityError
|
||||
CreateMetadataError | ProcessDependenciesError | WorkspaceValidityError
|
||||
>,
|
||||
public readonly partialProjectGraph: ProjectGraph
|
||||
) {
|
||||
|
||||
@ -180,7 +180,7 @@ export function readPackageJson(): any {
|
||||
export { FileData };
|
||||
|
||||
/**
|
||||
* TODO(v20): Remove this function.
|
||||
* TODO(v21): Remove this function.
|
||||
*/
|
||||
function getProjectsSync(
|
||||
root: string,
|
||||
|
||||
@ -313,7 +313,6 @@ describe('nx deps utils', () => {
|
||||
const defaults: FileMapCache = {
|
||||
version: '6.0',
|
||||
nxVersion: nxVersion,
|
||||
deps: {},
|
||||
pathMappings: {
|
||||
mylib: ['libs/mylib/index.ts'],
|
||||
},
|
||||
|
||||
@ -22,7 +22,6 @@ import { nxVersion } from '../utils/versions';
|
||||
export interface FileMapCache {
|
||||
version: string;
|
||||
nxVersion: string;
|
||||
deps: Record<string, string>;
|
||||
pathMappings: Record<string, any>;
|
||||
nxJsonPlugins: PluginData[];
|
||||
pluginsConfig?: any;
|
||||
@ -113,7 +112,6 @@ export function createProjectFileMapCache(
|
||||
const newValue: FileMapCache = {
|
||||
version: '6.0',
|
||||
nxVersion: nxVersion,
|
||||
deps: packageJsonDeps, // TODO(v19): We can remove this in favor of nxVersion
|
||||
// compilerOptions may not exist, especially for package-based repos
|
||||
pathMappings: tsConfig?.compilerOptions?.paths || {},
|
||||
nxJsonPlugins,
|
||||
|
||||
@ -5,7 +5,6 @@ import { join } from 'path';
|
||||
|
||||
import { workspaceRoot } from '../../utils/workspace-root';
|
||||
import { PluginConfiguration } from '../../config/nx-json';
|
||||
import { NxPluginV1 } from '../../utils/nx-plugin.deprecated';
|
||||
import { shouldMergeAngularProjects } from '../../adapter/angular-json';
|
||||
|
||||
import {
|
||||
@ -17,10 +16,7 @@ import {
|
||||
CreateNodesResult,
|
||||
NxPluginV2,
|
||||
} from './public-api';
|
||||
import {
|
||||
ProjectGraph,
|
||||
ProjectGraphProcessor,
|
||||
} from '../../config/project-graph';
|
||||
import { ProjectGraph } from '../../config/project-graph';
|
||||
import { loadNxPluginInIsolation } from './isolation';
|
||||
import { loadNxPlugin, unregisterPluginTSTranspiler } from './loader';
|
||||
import { createNodesFromFiles } from './utils';
|
||||
@ -29,7 +25,7 @@ import {
|
||||
isAggregateCreateNodesError,
|
||||
} from '../error-types';
|
||||
import { IS_WASM } from '../../native';
|
||||
import { platform } from 'os';
|
||||
import { output } from '../../utils/output';
|
||||
|
||||
export class LoadedNxPlugin {
|
||||
readonly name: string;
|
||||
@ -51,13 +47,12 @@ export class LoadedNxPlugin {
|
||||
graph: ProjectGraph,
|
||||
context: CreateMetadataContext
|
||||
) => ReturnType<CreateMetadata>;
|
||||
readonly processProjectGraph?: ProjectGraphProcessor;
|
||||
|
||||
readonly options?: unknown;
|
||||
readonly include?: string[];
|
||||
readonly exclude?: string[];
|
||||
|
||||
constructor(plugin: NormalizedPlugin, pluginDefinition: PluginConfiguration) {
|
||||
constructor(plugin: NxPluginV2, pluginDefinition: PluginConfiguration) {
|
||||
this.name = plugin.name;
|
||||
if (typeof pluginDefinition !== 'string') {
|
||||
this.options = pluginDefinition.options;
|
||||
@ -124,8 +119,6 @@ export class LoadedNxPlugin {
|
||||
this.createMetadata = (graph, context) =>
|
||||
plugin.createMetadata(graph, this.options, context);
|
||||
}
|
||||
|
||||
this.processProjectGraph = plugin.processProjectGraph;
|
||||
}
|
||||
}
|
||||
|
||||
@ -134,9 +127,6 @@ export type CreateNodesResultWithContext = CreateNodesResult & {
|
||||
pluginName: string;
|
||||
};
|
||||
|
||||
export type NormalizedPlugin = NxPluginV2 &
|
||||
Pick<NxPluginV1, 'processProjectGraph'>;
|
||||
|
||||
// Short lived cache (cleared between cmd runs)
|
||||
// holding resolved nx plugin objects.
|
||||
// Allows loaded plugins to not be reloaded when
|
||||
|
||||
@ -1,12 +1,8 @@
|
||||
import {
|
||||
ProjectGraph,
|
||||
ProjectGraphProcessorContext,
|
||||
} from '../../../config/project-graph';
|
||||
import { ProjectGraph } from '../../../config/project-graph';
|
||||
import { PluginConfiguration } from '../../../config/nx-json';
|
||||
import {
|
||||
CreateDependenciesContext,
|
||||
CreateMetadataContext,
|
||||
CreateNodesContext,
|
||||
CreateNodesContextV2,
|
||||
} from '../public-api';
|
||||
import { LoadedNxPlugin } from '../internal-api';
|
||||
@ -111,30 +107,6 @@ export interface PluginCreateMetadataResult {
|
||||
};
|
||||
}
|
||||
|
||||
export interface PluginWorkerProcessProjectGraphMessage {
|
||||
type: 'processProjectGraph';
|
||||
payload: {
|
||||
graph: ProjectGraph;
|
||||
ctx: ProjectGraphProcessorContext;
|
||||
tx: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface PluginWorkerProcessProjectGraphResult {
|
||||
type: 'processProjectGraphResult';
|
||||
payload:
|
||||
| {
|
||||
graph: ProjectGraph;
|
||||
success: true;
|
||||
tx: string;
|
||||
}
|
||||
| {
|
||||
success: false;
|
||||
error: Error;
|
||||
tx: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface PluginWorkerShutdownMessage {
|
||||
type: 'shutdown';
|
||||
payload: {};
|
||||
@ -145,14 +117,12 @@ export type PluginWorkerMessage =
|
||||
| PluginWorkerShutdownMessage
|
||||
| PluginWorkerCreateNodesMessage
|
||||
| PluginCreateDependenciesMessage
|
||||
| PluginWorkerProcessProjectGraphMessage
|
||||
| PluginCreateMetadataMessage;
|
||||
|
||||
export type PluginWorkerResult =
|
||||
| PluginWorkerLoadResult
|
||||
| PluginWorkerCreateNodesResult
|
||||
| PluginCreateDependenciesResult
|
||||
| PluginWorkerProcessProjectGraphResult
|
||||
| PluginCreateMetadataResult;
|
||||
|
||||
export function isPluginWorkerMessage(
|
||||
|
||||
@ -190,26 +190,6 @@ function createWorkerHandler(
|
||||
);
|
||||
}
|
||||
: undefined,
|
||||
processProjectGraph: result.hasProcessProjectGraph
|
||||
? (graph, ctx) => {
|
||||
const tx =
|
||||
pluginName + worker.pid + ':processProjectGraph:' + txId++;
|
||||
return registerPendingPromise(
|
||||
tx,
|
||||
pending,
|
||||
() => {
|
||||
sendMessageOverSocket(socket, {
|
||||
type: 'processProjectGraph',
|
||||
payload: { graph, ctx, tx },
|
||||
});
|
||||
},
|
||||
{
|
||||
operation: 'processProjectGraph',
|
||||
plugin: pluginName,
|
||||
}
|
||||
);
|
||||
}
|
||||
: undefined,
|
||||
createMetadata: result.hasCreateMetadata
|
||||
? (graph, ctx) => {
|
||||
const tx =
|
||||
@ -251,14 +231,6 @@ function createWorkerHandler(
|
||||
rejector(result.error);
|
||||
}
|
||||
},
|
||||
processProjectGraphResult: ({ tx, ...result }) => {
|
||||
const { resolver, rejector } = pending.get(tx);
|
||||
if (result.success) {
|
||||
resolver(result.graph);
|
||||
} else if (result.success === false) {
|
||||
rejector(result.error);
|
||||
}
|
||||
},
|
||||
createMetadataResult: ({ tx, ...result }) => {
|
||||
const { resolver, rejector } = pending.get(tx);
|
||||
if (result.success) {
|
||||
|
||||
@ -108,24 +108,6 @@ const server = createServer((socket) => {
|
||||
};
|
||||
}
|
||||
},
|
||||
processProjectGraph: async ({ graph, ctx, tx }) => {
|
||||
try {
|
||||
const result = await plugin.processProjectGraph(graph, ctx);
|
||||
return {
|
||||
type: 'processProjectGraphResult',
|
||||
payload: { graph: result, success: true, tx },
|
||||
};
|
||||
} catch (e) {
|
||||
return {
|
||||
type: 'processProjectGraphResult',
|
||||
payload: {
|
||||
success: false,
|
||||
error: createSerializableError(e),
|
||||
tx,
|
||||
},
|
||||
};
|
||||
}
|
||||
},
|
||||
createMetadata: async ({ graph, context, tx }) => {
|
||||
try {
|
||||
const result = await plugin.createMetadata(graph, context);
|
||||
|
||||
@ -27,7 +27,6 @@ import { extname } from 'node:path';
|
||||
import { NxPlugin } from './public-api';
|
||||
import { PluginConfiguration } from '../../config/nx-json';
|
||||
import { retrieveProjectConfigurationsWithoutPluginInference } from '../utils/retrieve-workspace-files';
|
||||
import { normalizeNxPlugin } from './utils';
|
||||
import { LoadedNxPlugin } from './internal-api';
|
||||
import { LoadPluginError } from '../error-types';
|
||||
import path = require('node:path/posix');
|
||||
@ -269,13 +268,13 @@ export async function loadNxPluginAsync(
|
||||
}
|
||||
|
||||
performance.mark(`Load Nx Plugin: ${moduleName} - start`);
|
||||
let { pluginPath, name } = await getPluginPathAndName(
|
||||
const { pluginPath, name } = getPluginPathAndName(
|
||||
moduleName,
|
||||
paths,
|
||||
projectsWithoutInference,
|
||||
root
|
||||
);
|
||||
const plugin = normalizeNxPlugin(await importPluginModule(pluginPath));
|
||||
const plugin = await importPluginModule(pluginPath);
|
||||
plugin.name ??= name;
|
||||
performance.mark(`Load Nx Plugin: ${moduleName} - end`);
|
||||
performance.measure(
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
// This file represents the public API for plugins which live in nx.json's plugins array.
|
||||
// For methods to interact with plugins from within Nx, see `./internal-api.ts`.
|
||||
|
||||
import { NxPluginV1 } from '../../utils/nx-plugin.deprecated';
|
||||
import {
|
||||
FileMap,
|
||||
ProjectGraph,
|
||||
@ -66,12 +65,12 @@ export interface CreateNodesResult {
|
||||
* A pair of file patterns and {@link CreateNodesFunction}
|
||||
*
|
||||
* Nx 19.2+: Both original `CreateNodes` and `CreateNodesV2` are supported. Nx will only invoke `CreateNodesV2` if it is present.
|
||||
* Nx 20.X : The `CreateNodesV2` will be the only supported API. This typing will still exist, but be identical to `CreateNodesV2`.
|
||||
* Nx 21.X : The `CreateNodesV2` will be the only supported API. This typing will still exist, but be identical to `CreateNodesV2`.
|
||||
Nx **will not** invoke the original `plugin.createNodes` callback. This should give plugin authors a window to transition.
|
||||
Plugin authors should update their plugin's `createNodes` function to align with `CreateNodesV2` / the updated `CreateNodes`.
|
||||
The plugin should contain something like: `export createNodes = createNodesV2;` during this period. This will allow the plugin
|
||||
to maintain compatibility with Nx 19.2 and up.
|
||||
* Nx 21.X : The `CreateNodesV2` typing will be removed, as it has replaced `CreateNodes`.
|
||||
* Nx 22.X : The `CreateNodesV2` typing will be removed, as it has replaced `CreateNodes`.
|
||||
*
|
||||
* @deprecated Use {@link CreateNodesV2} instead. CreateNodesV2 will replace this API. Read more about the transition above.
|
||||
*/
|
||||
@ -82,7 +81,7 @@ export type CreateNodes<T = unknown> = readonly [
|
||||
|
||||
/**
|
||||
* A pair of file patterns and {@link CreateNodesFunctionV2}
|
||||
* In Nx 20 {@link CreateNodes} will be replaced with this type. In Nx 21, this type will be removed.
|
||||
* In Nx 21 {@link CreateNodes} will be replaced with this type. In Nx 22, this type will be removed.
|
||||
*/
|
||||
export type CreateNodesV2<T = unknown> = readonly [
|
||||
projectFilePattern: string,
|
||||
@ -156,7 +155,7 @@ export type NxPluginV2<TOptions = unknown> = {
|
||||
* Provides a file pattern and function that retrieves configuration info from
|
||||
* those files. e.g. { '**\/*.csproj': buildProjectsFromCsProjFile }
|
||||
*
|
||||
* @deprecated Use {@link createNodesV2} instead. In Nx 20 support for calling createNodes with a single file for the first argument will be removed.
|
||||
* @deprecated Use {@link createNodesV2} instead. In Nx 21 support for calling createNodes with a single file for the first argument will be removed.
|
||||
*/
|
||||
createNodes?: CreateNodes<TOptions>;
|
||||
|
||||
@ -164,7 +163,7 @@ export type NxPluginV2<TOptions = unknown> = {
|
||||
* Provides a file pattern and function that retrieves configuration info from
|
||||
* those files. e.g. { '**\/*.csproj': buildProjectsFromCsProjFiles }
|
||||
*
|
||||
* In Nx 20 {@link createNodes} will be replaced with this property. In Nx 21, this property will be removed.
|
||||
* In Nx 21 {@link createNodes} will be replaced with this property. In Nx 22, this property will be removed.
|
||||
*/
|
||||
createNodesV2?: CreateNodesV2<TOptions>;
|
||||
|
||||
@ -182,4 +181,4 @@ export type NxPluginV2<TOptions = unknown> = {
|
||||
/**
|
||||
* A plugin for Nx
|
||||
*/
|
||||
export type NxPlugin = NxPluginV1 | NxPluginV2;
|
||||
export type NxPlugin = NxPluginV2;
|
||||
|
||||
@ -1,62 +1,9 @@
|
||||
import { dirname } from 'node:path';
|
||||
|
||||
import { toProjectName } from '../../config/to-project-name';
|
||||
import { combineGlobPatterns } from '../../utils/globs';
|
||||
|
||||
import type { NxPluginV1 } from '../../utils/nx-plugin.deprecated';
|
||||
import type { LoadedNxPlugin, NormalizedPlugin } from './internal-api';
|
||||
import {
|
||||
CreateNodesContextV2,
|
||||
CreateNodesFunction,
|
||||
CreateNodesFunctionV2,
|
||||
CreateNodesResult,
|
||||
type NxPlugin,
|
||||
type NxPluginV2,
|
||||
} from './public-api';
|
||||
import { AggregateCreateNodesError } from '../error-types';
|
||||
|
||||
export function isNxPluginV2(plugin: NxPlugin): plugin is NxPluginV2 {
|
||||
return 'createNodes' in plugin || 'createDependencies' in plugin;
|
||||
}
|
||||
|
||||
export function isNxPluginV1(
|
||||
plugin: NxPlugin | LoadedNxPlugin
|
||||
): plugin is NxPluginV1 {
|
||||
return 'processProjectGraph' in plugin || 'projectFilePatterns' in plugin;
|
||||
}
|
||||
|
||||
export function normalizeNxPlugin(plugin: NxPlugin): NormalizedPlugin {
|
||||
if (isNxPluginV2(plugin)) {
|
||||
return plugin;
|
||||
}
|
||||
if (isNxPluginV1(plugin) && plugin.projectFilePatterns) {
|
||||
return {
|
||||
...plugin,
|
||||
createNodes: [
|
||||
`*/**/${combineGlobPatterns(plugin.projectFilePatterns)}`,
|
||||
(configFilePath) => {
|
||||
const root = dirname(configFilePath);
|
||||
return {
|
||||
projects: {
|
||||
[root]: {
|
||||
name: toProjectName(configFilePath),
|
||||
targets: plugin.registerProjectTargets?.(configFilePath),
|
||||
},
|
||||
},
|
||||
};
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
return plugin;
|
||||
}
|
||||
|
||||
export type AsyncFn<T extends Function> = T extends (
|
||||
...args: infer A
|
||||
) => infer R
|
||||
? (...args: A) => Promise<Awaited<R>>
|
||||
: never;
|
||||
|
||||
export async function createNodesFromFiles<T = unknown>(
|
||||
createNodes: CreateNodesFunction<T>,
|
||||
configFiles: readonly string[],
|
||||
|
||||
@ -51,7 +51,6 @@ async function runTasks(
|
||||
cwd: process.cwd(),
|
||||
projectsConfigurations,
|
||||
nxJsonConfiguration,
|
||||
workspace: { ...projectsConfigurations, ...nxJsonConfiguration },
|
||||
isVerbose: false,
|
||||
projectGraph,
|
||||
taskGraph: fullTaskGraph,
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
import { workspaceConfigurationCheck } from '../utils/workspace-configuration-check';
|
||||
import { readNxJson } from '../config/configuration';
|
||||
import { NxArgs } from '../utils/command-line-utils';
|
||||
import { createProjectGraphAsync } from '../project-graph/project-graph';
|
||||
@ -13,7 +12,6 @@ import { TaskResult } from './life-cycle';
|
||||
export async function initTasksRunner(nxArgs: NxArgs) {
|
||||
performance.mark('init-local');
|
||||
loadRootEnvFiles();
|
||||
workspaceConfigurationCheck();
|
||||
const nxJson = readNxJson();
|
||||
if (nxArgs.verbose) {
|
||||
process.env.NX_VERBOSE_LOGGING = 'true';
|
||||
|
||||
@ -1,10 +0,0 @@
|
||||
// TODO(v16): Remove this file
|
||||
import { workspaceRoot } from './workspace-root';
|
||||
|
||||
/**
|
||||
* The root of the workspace.
|
||||
*
|
||||
* @deprecated use workspaceRoot instead
|
||||
*/
|
||||
export const appRootPath = workspaceRoot;
|
||||
export { workspaceRoot };
|
||||
@ -257,43 +257,6 @@ describe('splitArgs', () => {
|
||||
});
|
||||
|
||||
describe('--runner environment handling', () => {
|
||||
it('should set runner based on environment NX_RUNNER, if it is not provided directly on the command', () => {
|
||||
withEnvironment({ NX_RUNNER: 'some-env-runner-name' }, () => {
|
||||
expect(
|
||||
splitArgsIntoNxArgsAndOverrides(
|
||||
{
|
||||
__overrides_unparsed__: ['--notNxArg', 'true', '--override'],
|
||||
$0: '',
|
||||
},
|
||||
'run-one',
|
||||
{} as any,
|
||||
{
|
||||
tasksRunnerOptions: {
|
||||
'some-env-runner-name': { runner: '' },
|
||||
},
|
||||
}
|
||||
).nxArgs.runner
|
||||
).toEqual('some-env-runner-name');
|
||||
|
||||
expect(
|
||||
splitArgsIntoNxArgsAndOverrides(
|
||||
{
|
||||
__overrides_unparsed__: ['--notNxArg', 'true', '--override'],
|
||||
$0: '',
|
||||
runner: 'directlyOnCommand', // higher priority than $NX_RUNNER
|
||||
},
|
||||
'run-one',
|
||||
{} as any,
|
||||
{
|
||||
tasksRunnerOptions: {
|
||||
'some-env-runner-name': { runner: '' },
|
||||
},
|
||||
}
|
||||
).nxArgs.runner
|
||||
).toEqual('directlyOnCommand');
|
||||
});
|
||||
});
|
||||
|
||||
it('should set runner based on environment NX_TASKS_RUNNER, if it is not provided directly on the command', () => {
|
||||
withEnvironment({ NX_TASKS_RUNNER: 'some-env-runner-name' }, () => {
|
||||
expect(
|
||||
|
||||
@ -217,47 +217,37 @@ function normalizeNxArgsRunner(
|
||||
options: { printWarnings: boolean }
|
||||
) {
|
||||
if (!nxArgs.runner) {
|
||||
// TODO: Remove NX_RUNNER environment variable support in Nx v17
|
||||
for (const envKey of ['NX_TASKS_RUNNER', 'NX_RUNNER']) {
|
||||
const runner = process.env[envKey];
|
||||
if (runner) {
|
||||
const runnerExists = nxJson.tasksRunnerOptions?.[runner];
|
||||
if (options.printWarnings) {
|
||||
if (runnerExists) {
|
||||
output.note({
|
||||
title: `No explicit --runner argument provided, but found environment variable ${envKey} so using its value: ${output.bold(
|
||||
`${runner}`
|
||||
)}`,
|
||||
});
|
||||
} else if (
|
||||
nxArgs.verbose ||
|
||||
process.env.NX_VERBOSE_LOGGING === 'true'
|
||||
) {
|
||||
output.warn({
|
||||
title: `Could not find ${output.bold(
|
||||
`${runner}`
|
||||
)} within \`nx.json\` tasksRunnerOptions.`,
|
||||
bodyLines: [
|
||||
`${output.bold(`${runner}`)} was set by ${envKey}`,
|
||||
``,
|
||||
`To suppress this message, either:`,
|
||||
` - provide a valid task runner with --runner`,
|
||||
` - ensure NX_TASKS_RUNNER matches a task runner defined in nx.json`,
|
||||
],
|
||||
});
|
||||
}
|
||||
}
|
||||
const envKey = 'NX_TASKS_RUNNER';
|
||||
const runner = process.env[envKey];
|
||||
if (runner) {
|
||||
const runnerExists = nxJson.tasksRunnerOptions?.[runner];
|
||||
if (options.printWarnings) {
|
||||
if (runnerExists) {
|
||||
// TODO: Remove in v17
|
||||
if (envKey === 'NX_RUNNER' && options.printWarnings) {
|
||||
output.warn({
|
||||
title:
|
||||
'NX_RUNNER is deprecated, please use NX_TASKS_RUNNER instead.',
|
||||
});
|
||||
}
|
||||
nxArgs.runner = runner;
|
||||
output.note({
|
||||
title: `No explicit --runner argument provided, but found environment variable ${envKey} so using its value: ${output.bold(
|
||||
`${runner}`
|
||||
)}`,
|
||||
});
|
||||
} else if (
|
||||
nxArgs.verbose ||
|
||||
process.env.NX_VERBOSE_LOGGING === 'true'
|
||||
) {
|
||||
output.warn({
|
||||
title: `Could not find ${output.bold(
|
||||
`${runner}`
|
||||
)} within \`nx.json\` tasksRunnerOptions.`,
|
||||
bodyLines: [
|
||||
`${output.bold(`${runner}`)} was set by ${envKey}`,
|
||||
``,
|
||||
`To suppress this message, either:`,
|
||||
` - provide a valid task runner with --runner`,
|
||||
` - ensure NX_TASKS_RUNNER matches a task runner defined in nx.json`,
|
||||
],
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (runnerExists) {
|
||||
nxArgs.runner = runner;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,52 +0,0 @@
|
||||
import { shouldMergeAngularProjects } from '../adapter/angular-json';
|
||||
import { ProjectGraphProcessor } from '../config/project-graph';
|
||||
import { TargetConfiguration } from '../config/workspace-json-project-json';
|
||||
import ProjectJsonProjectsPlugin from '../plugins/project-json/build-nodes/project-json';
|
||||
import * as PackageJsonWorkspacesPlugin from '../plugins/package-json';
|
||||
import { NxPluginV2 } from '../project-graph/plugins';
|
||||
|
||||
/**
|
||||
* @deprecated Add targets to the projects in a {@link CreateNodes} function instead. This will be removed in Nx 20
|
||||
*/
|
||||
export type ProjectTargetConfigurator = (
|
||||
file: string
|
||||
) => Record<string, TargetConfiguration>;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link NxPluginV2} instead. This will be removed in Nx 20
|
||||
*/
|
||||
export type NxPluginV1 = {
|
||||
name: string;
|
||||
/**
|
||||
* @deprecated Use {@link CreateNodes} and {@link CreateDependencies} instead. This will be removed in Nx 20
|
||||
*/
|
||||
processProjectGraph?: ProjectGraphProcessor;
|
||||
|
||||
/**
|
||||
* @deprecated Add targets to the projects inside of {@link CreateNodes} instead. This will be removed in Nx 20
|
||||
*/
|
||||
registerProjectTargets?: ProjectTargetConfigurator;
|
||||
|
||||
/**
|
||||
* A glob pattern to search for non-standard project files.
|
||||
* @example: ["*.csproj", "pom.xml"]
|
||||
* @deprecated Use {@link CreateNodes} instead. This will be removed in Nx 20
|
||||
*/
|
||||
projectFilePatterns?: string[];
|
||||
};
|
||||
|
||||
/**
|
||||
* @todo(@agentender) v20: Remove this fn when we remove readWorkspaceConfig
|
||||
*/
|
||||
export function getDefaultPluginsSync(root: string): NxPluginV2[] {
|
||||
const plugins: NxPluginV2[] = [
|
||||
require('../plugins/js'),
|
||||
...(shouldMergeAngularProjects(root, false)
|
||||
? [require('../adapter/angular-json').NxAngularJsonPlugin]
|
||||
: []),
|
||||
PackageJsonWorkspacesPlugin,
|
||||
ProjectJsonProjectsPlugin,
|
||||
];
|
||||
|
||||
return plugins;
|
||||
}
|
||||
@ -6,9 +6,10 @@ import {
|
||||
import { ProjectConfiguration } from '../../config/workspace-json-project-json';
|
||||
import { readJsonFile } from '../fileutils';
|
||||
import { getNxRequirePaths } from '../installation-directory';
|
||||
import { NxPlugin, readPluginPackageJson } from '../../project-graph/plugins';
|
||||
import { readPluginPackageJson } from '../../project-graph/plugins';
|
||||
import { loadNxPlugin } from '../../project-graph/plugins/loader';
|
||||
import { PackageJson } from '../package-json';
|
||||
import { LoadedNxPlugin } from '../../project-graph/plugins/internal-api';
|
||||
|
||||
export interface PluginCapabilities {
|
||||
name: string;
|
||||
@ -42,12 +43,11 @@ export async function getPluginCapabilities(
|
||||
includeRuntimeCapabilities = false
|
||||
): Promise<PluginCapabilities | null> {
|
||||
try {
|
||||
const { json: packageJson, path: packageJsonPath } =
|
||||
await readPluginPackageJson(
|
||||
pluginName,
|
||||
projects,
|
||||
getNxRequirePaths(workspaceRoot)
|
||||
);
|
||||
const { json: packageJson, path: packageJsonPath } = readPluginPackageJson(
|
||||
pluginName,
|
||||
projects,
|
||||
getNxRequirePaths(workspaceRoot)
|
||||
);
|
||||
const pluginModule = includeRuntimeCapabilities
|
||||
? await tryGetModule(packageJson, workspaceRoot)
|
||||
: ({} as Record<string, unknown>);
|
||||
@ -106,7 +106,7 @@ export async function getPluginCapabilities(
|
||||
async function tryGetModule(
|
||||
packageJson: PackageJson,
|
||||
workspaceRoot: string
|
||||
): Promise<NxPlugin | null> {
|
||||
): Promise<LoadedNxPlugin | null> {
|
||||
try {
|
||||
if (
|
||||
packageJson.generators ??
|
||||
@ -116,8 +116,7 @@ async function tryGetModule(
|
||||
packageJson['builders']
|
||||
) {
|
||||
const [pluginPromise] = loadNxPlugin(packageJson.name, workspaceRoot);
|
||||
const plugin = await pluginPromise;
|
||||
return plugin;
|
||||
return await pluginPromise;
|
||||
} else {
|
||||
return {
|
||||
name: packageJson.name,
|
||||
|
||||
@ -1,37 +0,0 @@
|
||||
import { workspaceRoot } from './workspace-root';
|
||||
import { existsSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
import { output } from './output';
|
||||
import { readJsonFile } from '../utils/fileutils';
|
||||
|
||||
//TODO: vsavkin remove after Nx 19
|
||||
export function workspaceConfigurationCheck() {
|
||||
if (existsSync(join(workspaceRoot, 'workspace.json'))) {
|
||||
output.warn({
|
||||
title: 'workspace.json is ignored',
|
||||
bodyLines: [
|
||||
'Nx no longer reads configuration from workspace.json.',
|
||||
'Run "nx g @nx/workspace:fix-configuration" to split workspace.json into individual project.json files.',
|
||||
],
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (existsSync(join(workspaceRoot, 'angular.json'))) {
|
||||
const angularJson = readJsonFile(join(workspaceRoot, 'angular.json'));
|
||||
const v2Props = Object.values(angularJson.projects).find(
|
||||
(p: any) => !!p.targets
|
||||
);
|
||||
if (angularJson.version === 2 || v2Props) {
|
||||
output.error({
|
||||
title: 'angular.json format is incorrect',
|
||||
bodyLines: [
|
||||
'Nx no longer supports the v2 format of angular.json.',
|
||||
'Run "nx g @nx/workspace:fix-configuration" to split angular.json into individual project.json files. (Recommended)',
|
||||
'If you want to preserve angular.json, run "nx g @nx/workspace:fix-configuration --reformat"',
|
||||
],
|
||||
});
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -8,6 +8,15 @@ const context: ExecutorContext = {
|
||||
root: '',
|
||||
cwd: process.cwd(),
|
||||
isVerbose: false,
|
||||
projectGraph: {
|
||||
nodes: {},
|
||||
dependencies: {},
|
||||
},
|
||||
projectsConfigurations: {
|
||||
projects: {},
|
||||
version: 2,
|
||||
},
|
||||
nxJsonConfiguration: {},
|
||||
};
|
||||
|
||||
describe('<%= className %> Executor', () => {
|
||||
|
||||
@ -49,7 +49,8 @@ export default async function* serveExecutor(
|
||||
context: ExecutorContext
|
||||
) {
|
||||
const options = normalizeOptions(schema);
|
||||
const projectRoot = context.workspace.projects[context.projectName].root;
|
||||
const projectRoot =
|
||||
context.projectsConfigurations.projects[context.projectName].root;
|
||||
|
||||
const remixBin = require.resolve('@remix-run/dev/dist/cli');
|
||||
const args = buildRemixDevArgs(options);
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { workspaceRoot } from '@nx/devkit';
|
||||
import { Configuration } from '@rspack/core';
|
||||
import { isNxRspackComposablePlugin } from './config';
|
||||
import { readNxJsonFromDisk } from 'nx/src/devkit-internals';
|
||||
|
||||
/**
|
||||
* Reads the Rspack options from a give Rspack configuration. The configuration can be:
|
||||
@ -25,7 +26,14 @@ export async function readRspackOptions(
|
||||
projectRoot: '',
|
||||
sourceRoot: '',
|
||||
},
|
||||
context: { root: workspaceRoot, cwd: undefined, isVerbose: false },
|
||||
context: {
|
||||
root: workspaceRoot,
|
||||
cwd: undefined,
|
||||
isVerbose: false,
|
||||
nxJsonConfiguration: readNxJsonFromDisk(workspaceRoot),
|
||||
projectGraph: null,
|
||||
projectsConfigurations: null,
|
||||
},
|
||||
}
|
||||
);
|
||||
} else if (typeof rspackConfig === 'function') {
|
||||
|
||||
@ -1,8 +1,14 @@
|
||||
import { type ExecutorContext, readCachedProjectGraph } from '@nx/devkit';
|
||||
import {
|
||||
type ExecutorContext,
|
||||
readCachedProjectGraph,
|
||||
readProjectsConfigurationFromProjectGraph,
|
||||
workspaceRoot,
|
||||
} from '@nx/devkit';
|
||||
import type { NxWebpackExecutionContext } from '../../utils/config';
|
||||
import type { NxAppWebpackPluginOptions } from '../nx-webpack-plugin/nx-app-webpack-plugin-options';
|
||||
import type { Compiler, Configuration } from 'webpack';
|
||||
import { normalizeOptions } from '../nx-webpack-plugin/lib/normalize-options';
|
||||
import { readNxJson } from 'nx/src/config/configuration';
|
||||
|
||||
/**
|
||||
* This function is used to wrap the legacy plugin function to be used with the `composePlugins` function.
|
||||
@ -49,8 +55,11 @@ export async function useLegacyNxPlugin(
|
||||
const context: ExecutorContext = {
|
||||
cwd: process.cwd(),
|
||||
isVerbose: process.env.NX_VERBOSE_LOGGING === 'true',
|
||||
root: project.data.root,
|
||||
projectGraph: readCachedProjectGraph(),
|
||||
root: workspaceRoot,
|
||||
projectGraph,
|
||||
projectsConfigurations:
|
||||
readProjectsConfigurationFromProjectGraph(projectGraph),
|
||||
nxJsonConfiguration: readNxJson(workspaceRoot),
|
||||
target: project.data.targets[targetName],
|
||||
targetName: targetName,
|
||||
projectName: projectName,
|
||||
|
||||
@ -1,11 +1,13 @@
|
||||
import {
|
||||
ExecutorContext,
|
||||
readCachedProjectGraph,
|
||||
readProjectsConfigurationFromProjectGraph,
|
||||
workspaceRoot,
|
||||
} from '@nx/devkit';
|
||||
import { Configuration } from 'webpack';
|
||||
|
||||
import { NormalizedWebpackExecutorOptions } from '../executors/webpack/schema';
|
||||
import { readNxJson } from 'nx/src/config/configuration';
|
||||
|
||||
export const nxWebpackComposablePlugin = 'nxWebpackComposablePlugin';
|
||||
|
||||
@ -102,6 +104,9 @@ function ensureNxWebpackExecutionContext(ctx: NxWebpackExecutionContext): void {
|
||||
projectName,
|
||||
targetName,
|
||||
configurationName,
|
||||
projectsConfigurations:
|
||||
readProjectsConfigurationFromProjectGraph(projectGraph),
|
||||
nxJsonConfiguration: readNxJson(workspaceRoot),
|
||||
cwd: process.cwd(),
|
||||
root: workspaceRoot,
|
||||
isVerbose: process.env['NX_VERBOSE_LOGGING'] === 'true',
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { workspaceRoot } from '@nx/devkit';
|
||||
import { isNxWebpackComposablePlugin } from '../config';
|
||||
import { Configuration } from 'webpack';
|
||||
import { readNxJsonFromDisk } from 'nx/src/devkit-internals';
|
||||
|
||||
/**
|
||||
* Reads the webpack options from a give webpack configuration. The configuration can be:
|
||||
@ -28,7 +29,14 @@ export async function readWebpackOptions(
|
||||
outputPath: undefined,
|
||||
assets: undefined,
|
||||
},
|
||||
context: { root: workspaceRoot, cwd: undefined, isVerbose: false },
|
||||
context: {
|
||||
root: workspaceRoot,
|
||||
cwd: undefined,
|
||||
isVerbose: false,
|
||||
projectsConfigurations: null,
|
||||
projectGraph: null,
|
||||
nxJsonConfiguration: readNxJsonFromDisk(workspaceRoot),
|
||||
},
|
||||
}
|
||||
);
|
||||
} else if (typeof webpackConfig === 'function') {
|
||||
|
||||
509
pnpm-lock.yaml
generated
509
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user