From be2af28c921e9bf52ce28141321b4bfe92c6935b Mon Sep 17 00:00:00 2001 From: Ghislain B Date: Tue, 22 Nov 2022 10:37:15 -0500 Subject: [PATCH] fix(run): detect Nx target configuration in package.json files (#416) --- .github/renovate.json5 | 4 --- package.json | 2 +- ...command-with-nx-no-target-defaults.spec.ts | 2 +- .../run/src/__tests__/run-command.spec.ts | 8 ++--- packages/run/src/run-command.ts | 21 ++++++------ pnpm-lock.yaml | 33 ++++++++----------- 6 files changed, 30 insertions(+), 40 deletions(-) diff --git a/.github/renovate.json5 b/.github/renovate.json5 index 57bc116b..07047d3d 100644 --- a/.github/renovate.json5 +++ b/.github/renovate.json5 @@ -24,10 +24,6 @@ packageNames: ['npm'], allowedVersions: '8.0.0', }, - { - packageNames: ['nx'], - allowedVersions: '15.0.8', - }, ], schedule: ['on Thursday'], ignoreDeps: [ diff --git a/package.json b/package.json index a9beb5c7..a0e18985 100644 --- a/package.json +++ b/package.json @@ -85,7 +85,7 @@ "normalize-newline": "^3.0.0", "normalize-path": "^3.0.0", "npmlog": "^7.0.1", - "nx": "15.0.8", + "nx": "15.2.1", "prettier": "^2.7.1", "rimraf": "^3.0.2", "semver": "^7.3.8", diff --git a/packages/run/src/__tests__/run-command-with-nx-no-target-defaults.spec.ts b/packages/run/src/__tests__/run-command-with-nx-no-target-defaults.spec.ts index 08a21cb9..9e440cbd 100644 --- a/packages/run/src/__tests__/run-command-with-nx-no-target-defaults.spec.ts +++ b/packages/run/src/__tests__/run-command-with-nx-no-target-defaults.spec.ts @@ -65,7 +65,7 @@ describe('RunCommand', () => { const logMessages = loggingOutput('verbose'); expect(logMessages).toContain( - 'nx.json was not found or is missing targetDefaults. Task dependencies will not be automatically included.' + 'Nx target configuration was not found. Task dependencies will not be automatically included.' ); }); }); diff --git a/packages/run/src/__tests__/run-command.spec.ts b/packages/run/src/__tests__/run-command.spec.ts index 4d164750..637a0347 100644 --- a/packages/run/src/__tests__/run-command.spec.ts +++ b/packages/run/src/__tests__/run-command.spec.ts @@ -455,7 +455,7 @@ describe('RunCommand', () => { const logMessages = loggingOutput('info'); expect(logMessages).toContain( - 'Using the "ignore" option when nx.json has targetDefaults defined will exclude only tasks that are not determined to be required by Nx.' + 'Using the "ignore" option when Nx targets are configured will exclude only tasks that are not determined to be required by Nx.' ); }); @@ -498,9 +498,7 @@ describe('RunCommand', () => { await lernaRun(testDir)('my-script', '--sort'); const [logMessage] = loggingOutput('warn'); - expect(logMessage).toContain( - '"parallel", "sort", and "no-sort" are ignored when nx.json has targetDefaults defined.' - ); + expect(logMessage).toContain('"parallel", "sort", and "no-sort" are ignored when Nx targets are configured.'); expect(collectedOutput).toContain('package-1'); }); @@ -511,7 +509,7 @@ describe('RunCommand', () => { const logMessages = loggingOutput('info'); expect(logMessages).toContain( - 'Using the "include-dependencies" option when nx.json has targetDefaults defined will include both task dependencies detected by Nx and project dependencies detected by Lerna.' + 'Using the "include-dependencies" option when Nx targets are configured will include both task dependencies detected by Nx and project dependencies detected by Lerna.' ); expect(collectedOutput).toContain('package-1'); }); diff --git a/packages/run/src/run-command.ts b/packages/run/src/run-command.ts index 2c58cbf7..79bdab44 100644 --- a/packages/run/src/run-command.ts +++ b/packages/run/src/run-command.ts @@ -268,7 +268,11 @@ export class RunCommand extends Command { const nxJson = readNxJson(); const targetDependenciesAreDefined = Object.keys(nxJson.targetDependencies || nxJson.targetDefaults || {}).length > 0; - const mimicLernaDefaultBehavior = !(nxJsonExists && targetDependenciesAreDefined); + + const hasProjectSpecificNxConfiguration = this.packagesWithScript.some((p) => !!p.get('nx')); + const hasCustomizedNxConfiguration = + (nxJsonExists && targetDependenciesAreDefined) || hasProjectSpecificNxConfiguration; + const mimicLernaDefaultBehavior = !hasCustomizedNxConfiguration; const targetDependencies = this.toposort && !this.options.parallel && mimicLernaDefaultBehavior @@ -307,36 +311,33 @@ export class RunCommand extends Command { __overrides__: this.args.map((t) => t.toString()), }; - if (!mimicLernaDefaultBehavior) { + if (hasCustomizedNxConfiguration) { this.logger.verbose( this.name, - 'nx.json with targetDefaults was found. Task dependencies will be automatically included.' + 'Nx target configuration was found. Task dependencies will be automatically included.' ); if (this.options.parallel || this.options.sort !== undefined) { - this.logger.warn( - this.name, - `"parallel", "sort", and "no-sort" are ignored when nx.json has targetDefaults defined.` - ); + this.logger.warn(this.name, `"parallel", "sort", and "no-sort" are ignored when Nx targets are configured.`); } if (this.options.includeDependencies) { this.logger.info( this.name, - `Using the "include-dependencies" option when nx.json has targetDefaults defined will include both task dependencies detected by Nx and project dependencies detected by Lerna.` + `Using the "include-dependencies" option when Nx targets are configured will include both task dependencies detected by Nx and project dependencies detected by Lerna.` ); } if (this.options.ignore) { this.logger.info( this.name, - `Using the "ignore" option when nx.json has targetDefaults defined will exclude only tasks that are not determined to be required by Nx.` + `Using the "ignore" option when Nx targets are configured will exclude only tasks that are not determined to be required by Nx.` ); } } else { this.logger.verbose( this.name, - 'nx.json was not found or is missing targetDefaults. Task dependencies will not be automatically included.' + 'Nx target configuration was not found. Task dependencies will not be automatically included.' ); } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 47a50353..06101a68 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -43,7 +43,7 @@ importers: normalize-newline: ^3.0.0 normalize-path: ^3.0.0 npmlog: ^7.0.1 - nx: 15.0.8 + nx: 15.2.1 prettier: ^2.7.1 rimraf: ^3.0.2 semver: ^7.3.8 @@ -93,7 +93,7 @@ importers: normalize-newline: 3.0.0 normalize-path: 3.0.0 npmlog: 7.0.1 - nx: 15.0.8 + nx: 15.2.1 prettier: 2.7.1 rimraf: 3.0.2 semver: 7.3.8 @@ -1430,21 +1430,21 @@ packages: - supports-color dev: false - /@nrwl/cli/15.0.8: - resolution: {integrity: sha512-3dy3VGcStWuZXUK91FNIoxIHO44DSuE3bPVLLPfYoOgn8pYjhykpdp6RZHoDkN2NhRypzM73q2GCrmBMfizRyA==} + /@nrwl/cli/15.2.1: + resolution: {integrity: sha512-ufBJ5o3WCixdp6/TPkpn4rH3QBFJcqCMG1d14A/SvAkEnXu3vWlj3E+4GXf3CK+sGNjjf3ZGoNm7OFV+/Ml4GA==} dependencies: - nx: 15.0.8 + nx: 15.2.1 transitivePeerDependencies: - '@swc-node/register' - '@swc/core' - debug dev: true - /@nrwl/tao/15.0.8: - resolution: {integrity: sha512-Xr1hq3ZCfdKS5XSf8non5eLVdGLEleKdqBhGzdOFssYaPsCDkbavX5mzySzxeLk+DM9rcOFhwwf0x7JCOiq0bQ==} + /@nrwl/tao/15.2.1: + resolution: {integrity: sha512-6ApglWKORasLhtjlJmqo2co/UexSSiD7mWVxT2886oKG2Y/T/5RnPFNhJgGnKJIURCNMxiSKhq7GAA+CE9zRZg==} hasBin: true dependencies: - nx: 15.0.8 + nx: 15.2.1 transitivePeerDependencies: - '@swc-node/register' - '@swc/core' @@ -2716,7 +2716,7 @@ packages: dev: false /concat-map/0.0.1: - resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==} + resolution: {integrity: sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=} /concat-stream/2.0.0: resolution: {integrity: sha512-MWufYdFw53ccGjCA+Ol7XJYpAlW6/prSMzuPOTRnJGcGzuhLn4Scrz7qf6o8bROZ514ltazcIFJZevcfbo0x7A==} @@ -5684,8 +5684,8 @@ packages: gauge: 5.0.0 set-blocking: 2.0.0 - /nx/15.0.8: - resolution: {integrity: sha512-LywcMYwZ3acEoRccUq3WBYbfeX+uGm8dyQjVLFPC1caziYZTpvQCb/BtZgLVXpZKexa2wYDXDkHuhb2pcaYcYw==} + /nx/15.2.1: + resolution: {integrity: sha512-vVeT5D02cDDiSmS3P2Bos/waYQa3m0yl/rouzsKpusVSmzAQGQbKXhxPb4WnNIj8Iz/8KjFeBM/RZO021BtGNg==} hasBin: true requiresBuild: true peerDependencies: @@ -5697,8 +5697,8 @@ packages: '@swc/core': optional: true dependencies: - '@nrwl/cli': 15.0.8 - '@nrwl/tao': 15.0.8 + '@nrwl/cli': 15.2.1 + '@nrwl/tao': 15.2.1 '@parcel/watcher': 2.0.4 '@yarnpkg/lockfile': 1.1.0 '@yarnpkg/parsers': 3.0.0-rc.20 @@ -5731,7 +5731,7 @@ packages: tslib: 2.4.0 v8-compile-cache: 2.3.0 yargs: 17.6.2 - yargs-parser: 21.0.1 + yargs-parser: 21.1.1 transitivePeerDependencies: - debug dev: true @@ -7155,11 +7155,6 @@ packages: engines: {node: '>=10'} dev: false - /yargs-parser/21.0.1: - resolution: {integrity: sha512-9BK1jFpLzJROCI5TzwZL/TU4gqjK5xiHV/RfWLOahrjAko/e4DJkRDZQXfvqAsiZzzYhgAzbgz6lg48jcm4GLg==} - engines: {node: '>=12'} - dev: true - /yargs-parser/21.1.1: resolution: {integrity: sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==} engines: {node: '>=12'}