From 5f77d65554609dac52f91c6e128c28f98d7891d7 Mon Sep 17 00:00:00 2001 From: James Henry Date: Wed, 18 Dec 2024 16:28:39 +0400 Subject: [PATCH 1/2] chore(release): fix e2e (#29399) --- e2e/release/src/circular-dependencies.test.ts | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/e2e/release/src/circular-dependencies.test.ts b/e2e/release/src/circular-dependencies.test.ts index f6b091334b186..93bfa346e9b02 100644 --- a/e2e/release/src/circular-dependencies.test.ts +++ b/e2e/release/src/circular-dependencies.test.ts @@ -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({ @@ -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({ @@ -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(() => { @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 From 6051e6e208ddbe97cafa7f0c9ba5ab8888e7d13e Mon Sep 17 00:00:00 2001 From: Isaac Mann Date: Wed, 18 Dec 2024 08:15:04 -0500 Subject: [PATCH 2/2] docs(core): fix references to createNodes v1 (#29400) --- .../recipes/plugins/project-graph-plugins.md | 35 ++++++++++++------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/docs/shared/recipes/plugins/project-graph-plugins.md b/docs/shared/recipes/plugins/project-graph-plugins.md index fd9adcb8b1956..a0dfceaeefd16 100644 --- a/docs/shared/recipes/plugins/project-graph-plugins.md +++ b/docs/shared/recipes/plugins/project-graph-plugins.md @@ -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 @@ -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. @@ -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 = [ - '**/project.json', - (fileName, opts, ctx) => { - const root = dirname(fileName); +export const createNodesV2: CreateNodesV2 = [ + '**/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 + ); }, ]; ```