Skip to content

Commit

Permalink
feat(misc): add nx syncing mechanism and update the typescript-sync g…
Browse files Browse the repository at this point in the history
…enerator (nrwl#26793)

- Add the `nx sync` command to run sync generators and apply changes to
bring the workspace up to date according to their logic.
- Add the `nx sync:check` command to validate that the workspace is up
to date by running the sync generators without applying the changes. It
can be used on CI as a validation check.
- Update the task runner to run the sync generators (or obtain their
state from the daemon) and prompt the user whether to apply the changes,
if any
- This is only run if the `NX_ENABLE_SYNC_GENERATORS` environment
variable is set to `'true'`
  - Allow the user to configure a default value for the prompt
- Update the `@nx/js:typescript-sync` generator (keep tsconfig project
references in sync with the project graph) with misc fixes

<!-- 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 -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->
<!-- Fixes NXC-787 -->
<!-- Fixes NXC-788 -->
<!-- Fixes NXC-789 -->

Fixes #
  • Loading branch information
leosvelperez authored Aug 12, 2024
1 parent f208acd commit add5a67
Show file tree
Hide file tree
Showing 41 changed files with 2,896 additions and 386 deletions.
9 changes: 9 additions & 0 deletions docs/generated/devkit/NxJsonConfiguration.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Nx.json configuration
- [plugins](../../devkit/documents/NxJsonConfiguration#plugins): PluginConfiguration[]
- [pluginsConfig](../../devkit/documents/NxJsonConfiguration#pluginsconfig): Record<string, Record<string, unknown>>
- [release](../../devkit/documents/NxJsonConfiguration#release): NxReleaseConfiguration
- [sync](../../devkit/documents/NxJsonConfiguration#sync): NxSyncConfiguration
- [targetDefaults](../../devkit/documents/NxJsonConfiguration#targetdefaults): TargetDefaults
- [tasksRunnerOptions](../../devkit/documents/NxJsonConfiguration#tasksrunneroptions): Object
- [useDaemonProcess](../../devkit/documents/NxJsonConfiguration#usedaemonprocess): boolean
Expand Down Expand Up @@ -240,6 +241,14 @@ Configuration for `nx release` (versioning and publishing of applications and li

---

### sync

`Optional` **sync**: `NxSyncConfiguration`

Configuration for the `nx sync` command.

---

### targetDefaults

`Optional` **targetDefaults**: [`TargetDefaults`](../../devkit/documents/TargetDefaults)
Expand Down
10 changes: 10 additions & 0 deletions docs/generated/devkit/TargetConfiguration.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Target's configuration
- [options](../../devkit/documents/TargetConfiguration#options): T
- [outputs](../../devkit/documents/TargetConfiguration#outputs): string[]
- [parallelism](../../devkit/documents/TargetConfiguration#parallelism): boolean
- [syncGenerators](../../devkit/documents/TargetConfiguration#syncgenerators): string[]

## Properties

Expand Down Expand Up @@ -119,3 +120,12 @@ caching engine.

Whether this target can be run in parallel with other tasks
Default is true

---

### syncGenerators

`Optional` **syncGenerators**: `string`[]

List of generators to run before the target to ensure the workspace
is up to date.
13 changes: 13 additions & 0 deletions docs/generated/devkit/Workspace.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use ProjectsConfigurations or NxJsonConfiguration
- [pluginsConfig](../../devkit/documents/Workspace#pluginsconfig): Record<string, Record<string, unknown>>
- [projects](../../devkit/documents/Workspace#projects): Record<string, ProjectConfiguration>
- [release](../../devkit/documents/Workspace#release): NxReleaseConfiguration
- [sync](../../devkit/documents/Workspace#sync): NxSyncConfiguration
- [targetDefaults](../../devkit/documents/Workspace#targetdefaults): TargetDefaults
- [tasksRunnerOptions](../../devkit/documents/Workspace#tasksrunneroptions): Object
- [useDaemonProcess](../../devkit/documents/Workspace#usedaemonprocess): boolean
Expand Down Expand Up @@ -328,6 +329,18 @@ Configuration for `nx release` (versioning and publishing of applications and li

---

### sync

`Optional` **sync**: `NxSyncConfiguration`

Configuration for the `nx sync` command.

#### Inherited from

[NxJsonConfiguration](../../devkit/documents/NxJsonConfiguration).[sync](../../devkit/documents/NxJsonConfiguration#sync)

---

### targetDefaults

`Optional` **targetDefaults**: [`TargetDefaults`](../../devkit/documents/TargetDefaults)
Expand Down
6 changes: 3 additions & 3 deletions docs/generated/manifests/menus.json
Original file line number Diff line number Diff line change
Expand Up @@ -7987,9 +7987,9 @@
"disableCollapsible": false
},
{
"id": "sync",
"path": "/nx-api/js/generators/sync",
"name": "sync",
"id": "typescript-sync",
"path": "/nx-api/js/generators/typescript-sync",
"name": "typescript-sync",
"children": [],
"isExternal": false,
"disableCollapsible": false
Expand Down
10 changes: 5 additions & 5 deletions docs/generated/manifests/nx-api.json
Original file line number Diff line number Diff line change
Expand Up @@ -1283,13 +1283,13 @@
"path": "/nx-api/js/generators/setup-build",
"type": "generator"
},
"/nx-api/js/generators/sync": {
"/nx-api/js/generators/typescript-sync": {
"description": "Synchronize TypeScript project references based on the project graph",
"file": "generated/packages/js/generators/sync.json",
"file": "generated/packages/js/generators/typescript-sync.json",
"hidden": true,
"name": "sync",
"originalFilePath": "/packages/js/src/generators/sync/schema.json",
"path": "/nx-api/js/generators/sync",
"name": "typescript-sync",
"originalFilePath": "/packages/js/src/generators/typescript-sync/schema.json",
"path": "/nx-api/js/generators/typescript-sync",
"type": "generator"
}
},
Expand Down
8 changes: 4 additions & 4 deletions docs/generated/packages-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -1267,11 +1267,11 @@
},
{
"description": "Synchronize TypeScript project references based on the project graph",
"file": "generated/packages/js/generators/sync.json",
"file": "generated/packages/js/generators/typescript-sync.json",
"hidden": true,
"name": "sync",
"originalFilePath": "/packages/js/src/generators/sync/schema.json",
"path": "js/generators/sync",
"name": "typescript-sync",
"originalFilePath": "/packages/js/src/generators/typescript-sync/schema.json",
"path": "js/generators/typescript-sync",
"type": "generator"
}
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sync",
"factory": "./src/generators/sync/sync#syncGenerator",
"name": "typescript-sync",
"factory": "./src/generators/typescript-sync/typescript-sync",
"schema": {
"$schema": "https://json-schema.org/schema",
"$id": "action",
Expand All @@ -11,9 +11,10 @@
"presets": []
},
"description": "Synchronize TypeScript project references based on the project graph",
"alias": ["sync"],
"hidden": true,
"implementation": "/packages/js/src/generators/sync/sync#syncGenerator.ts",
"implementation": "/packages/js/src/generators/typescript-sync/typescript-sync.ts",
"aliases": [],
"path": "/packages/js/src/generators/sync/schema.json",
"path": "/packages/js/src/generators/typescript-sync/schema.json",
"type": "generator"
}
2 changes: 1 addition & 1 deletion docs/shared/reference/sitemap.md
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@
- [release-version](/nx-api/js/generators/release-version)
- [setup-verdaccio](/nx-api/js/generators/setup-verdaccio)
- [setup-build](/nx-api/js/generators/setup-build)
- [sync](/nx-api/js/generators/sync)
- [typescript-sync](/nx-api/js/generators/typescript-sync)
- [nest](/nx-api/nest)
- [documents](/nx-api/nest/documents)
- [Overview](/nx-api/nest/documents/overview)
Expand Down
7 changes: 4 additions & 3 deletions packages/js/generators.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@
"alias": ["build"],
"description": "setup-build generator"
},
"sync": {
"factory": "./src/generators/sync/sync#syncGenerator",
"schema": "./src/generators/sync/schema.json",
"typescript-sync": {
"factory": "./src/generators/typescript-sync/typescript-sync",
"schema": "./src/generators/typescript-sync/schema.json",
"description": "Synchronize TypeScript project references based on the project graph",
"alias": ["sync"],
"hidden": true
}
}
Expand Down
206 changes: 0 additions & 206 deletions packages/js/src/generators/sync/sync.spec.ts

This file was deleted.

Loading

0 comments on commit add5a67

Please sign in to comment.