Skip to content

Commit

Permalink
Merge branch 'package-json-conformance-rule' of github.com:nrwl/nx in…
Browse files Browse the repository at this point in the history
…to package-json-conformance-rule
  • Loading branch information
JamesHenry committed Dec 18, 2024
2 parents cc6251a + 7307e30 commit 059d2f8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 23 deletions.
35 changes: 22 additions & 13 deletions docs/shared/recipes/plugins/project-graph-plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ One of the best features of Nx the ability to construct the project graph automa

Project graph plugins are able to add new nodes or dependencies to the project graph. This allows you to extend the project graph with new projects and dependencies. The API is defined by two exported members, which are described below:

- [createNodes](#adding-new-nodes-to-the-project-graph): This tuple allows a plugin to tell Nx information about projects that are identified by a given file.
- [createNodesV2](#adding-new-nodes-to-the-project-graph): This tuple allows a plugin to tell Nx information about projects that are identified by a given file.
- [createDependencies](#adding-new-dependencies-to-the-project-graph): This function allows a plugin to tell Nx about dependencies between projects.

## Adding Plugins to Workspace
Expand Down Expand Up @@ -295,7 +295,7 @@ Breaking down this example, we can see that it follows this flow:

## Accepting Plugin Options

When looking at `createNodes`, and `createDependencies` you may notice a parameter called `options`. This is the first parameter for `createDependencies` or the second parameter for `createDependencies`.
When looking at `createNodesV2`, and `createDependencies` you may notice a parameter called `options`. This is the first parameter for `createDependencies` or the second parameter for `createDependencies`.

By default, its typed as unknown. This is because it belongs to the plugin author. The `CreateNodes`, `CreateDependencies`, and `NxPluginV2` types all accept a generic parameter that allows you to specify the type of the options.

Expand All @@ -319,20 +319,29 @@ As an example, the below `nx.json` file specifies a plugin called `my-plugin` an
`my-plugin` could then consume these options to add a tag to each project it detected:

```typescript
import { createNodesFromFiles } from '@nx/devkit';
import { dirname } from 'path';

type MyPluginOptions = { tagName: string };

export const createNodes: CreateNodes<MyPluginOptions> = [
'**/project.json',
(fileName, opts, ctx) => {
const root = dirname(fileName);
export const createNodesV2: CreateNodesV2<MyPluginOptions> = [
'**/tsconfig.json',
async (configFiles, options, context) => {
return await createNodesFromFiles(
(configFile, options, context) =>
const root = dirname(configFile);

return {
projects: {
[root]: {
tags: opts.tagName ? [opts.tagName] : [],
},
},
};
return {
projects: {
[root]: {
tags: options.tagName ? [options.tagName] : [],
},
},
};
configFiles,
options,
context
);
},
];
```
Expand Down
25 changes: 15 additions & 10 deletions e2e/release/src/circular-dependencies.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
uniq,
updateJson,
} from '@nx/e2e/utils';
import { execSync } from 'node:child_process';
import { resetWorkspaceContext } from 'nx/src/utils/workspace-context';

expect.addSnapshotSerializer({
Expand Down Expand Up @@ -47,6 +48,7 @@ const originalVerboseLoggingValue = process.env.NX_VERBOSE_LOGGING;
describe('nx release circular dependencies', () => {
let pkg1: string;
let pkg2: string;
let e2eRegistryUrl: string;

beforeAll(async () => {
newProject({
Expand Down Expand Up @@ -85,6 +87,9 @@ describe('nx release circular dependencies', () => {
runCLI('reset');
resetWorkspaceContext();
runCLI('reset');

// This is the verdaccio instance that the e2e tests themselves are working from
e2eRegistryUrl = execSync('npm config get registry').toString().trim();
}, 60000);

afterAll(() => {
Expand Down Expand Up @@ -244,7 +249,7 @@ describe('nx release circular dependencies', () => {
integrity: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
total files: 3
Would publish to http://localhost:4873 with tag "latest", but [dry-run] was set
Would publish to ${e2eRegistryUrl} with tag "latest", but [dry-run] was set
> nx run {project-name}:nx-release-publish
Expand All @@ -266,7 +271,7 @@ describe('nx release circular dependencies', () => {
integrity: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
total files: 3
Would publish to http://localhost:4873 with tag "latest", but [dry-run] was set
Would publish to ${e2eRegistryUrl} with tag "latest", but [dry-run] was set
Expand Down Expand Up @@ -429,7 +434,7 @@ describe('nx release circular dependencies', () => {
integrity: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
total files: 3
Would publish to http://localhost:4873 with tag "latest", but [dry-run] was set
Would publish to ${e2eRegistryUrl} with tag "latest", but [dry-run] was set
> nx run {project-name}:nx-release-publish
Expand All @@ -451,7 +456,7 @@ describe('nx release circular dependencies', () => {
integrity: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
total files: 3
Would publish to http://localhost:4873 with tag "latest", but [dry-run] was set
Would publish to ${e2eRegistryUrl} with tag "latest", but [dry-run] was set
Expand Down Expand Up @@ -613,7 +618,7 @@ describe('nx release circular dependencies', () => {
integrity: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
total files: 3
Would publish to http://localhost:4873 with tag "latest", but [dry-run] was set
Would publish to ${e2eRegistryUrl} with tag "latest", but [dry-run] was set
> nx run {project-name}:nx-release-publish
Expand All @@ -635,7 +640,7 @@ describe('nx release circular dependencies', () => {
integrity: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
total files: 3
Would publish to http://localhost:4873 with tag "latest", but [dry-run] was set
Would publish to ${e2eRegistryUrl} with tag "latest", but [dry-run] was set
Expand Down Expand Up @@ -757,7 +762,7 @@ describe('nx release circular dependencies', () => {
integrity: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
total files: 3
Would publish to http://localhost:4873 with tag "latest", but [dry-run] was set
Would publish to ${e2eRegistryUrl} with tag "latest", but [dry-run] was set
Expand Down Expand Up @@ -919,7 +924,7 @@ describe('nx release circular dependencies', () => {
integrity: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
total files: 3
Would publish to http://localhost:4873 with tag "latest", but [dry-run] was set
Would publish to ${e2eRegistryUrl} with tag "latest", but [dry-run] was set
> nx run {project-name}:nx-release-publish
Expand All @@ -941,7 +946,7 @@ describe('nx release circular dependencies', () => {
integrity: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
total files: 3
Would publish to http://localhost:4873 with tag "latest", but [dry-run] was set
Would publish to ${e2eRegistryUrl} with tag "latest", but [dry-run] was set
Expand Down Expand Up @@ -1091,7 +1096,7 @@ describe('nx release circular dependencies', () => {
integrity: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
total files: 3
Would publish to http://localhost:4873 with tag "latest", but [dry-run] was set
Would publish to ${e2eRegistryUrl} with tag "latest", but [dry-run] was set
Expand Down

0 comments on commit 059d2f8

Please sign in to comment.