diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bf89efe5..8b24cd03 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,6 +24,26 @@ jobs: - name: Audit production dependencies run: npm audit --omit=dev --omit=optional + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version-file: .nvmrc + cache: npm + - name: Set base and head for Nx affected commands + uses: nrwl/nx-set-shas@v4 + - name: Install dependencies + run: npm ci + - name: Lint affected projects + run: npx nx affected -t lint --parallel=3 --verbose + unit-test: strategy: fail-fast: false @@ -70,4 +90,4 @@ jobs: - name: Install dependencies run: npm i - name: E2E test affected projects - run: npx nx affected -t nxv-e2e --exclude="tag:type:example" + run: NX_DAEMON=false; npx nx affected -t nxv-e2e --exclude="tag:type:example" --skipNxCache --verbose diff --git a/examples/e2e/cli-e2e-original/setup/global-setup.ts b/examples/e2e/cli-e2e-original/setup/global-setup.ts index ff352c85..e22e2072 100644 --- a/examples/e2e/cli-e2e-original/setup/global-setup.ts +++ b/examples/e2e/cli-e2e-original/setup/global-setup.ts @@ -30,9 +30,9 @@ export async function setup() { // package publish all projects await executeProcess({ - command: 'nx', + command: 'npx', args: objectToCliArgs({ - _: ['run-many'], + _: ['nx', 'run-many'], targets: 'original-npm-publish', exclude: 'tag:type:testing', skipNxCache: true, @@ -44,9 +44,9 @@ export async function setup() { // package install all projects await executeProcess({ - command: 'nx', + command: 'npx', args: objectToCliArgs({ - _: ['run-many'], + _: ['nx', 'run-many'], targets: 'original-npm-install', exclude: 'tag:type:testing', skipNxCache: true, diff --git a/examples/e2e/cli-e2e-original/tooling/utils/npm.ts b/examples/e2e/cli-e2e-original/tooling/utils/npm.ts index 064b0522..fb5ec867 100644 --- a/examples/e2e/cli-e2e-original/tooling/utils/npm.ts +++ b/examples/e2e/cli-e2e-original/tooling/utils/npm.ts @@ -19,7 +19,10 @@ export async function setupNpmWorkspace(directory: string, verbose?: boolean) { await ensureDirectoryExists(directory); process.chdir(join(cwd, directory)); try { - execFileSync('npm', ['init', '--force']).toString(); + execFileSync('npm', ['init', '--force'], { + shell: true, + windowsHide: true, + }).toString(); } catch (error) { logError(`Error creating NPM workspace: ${(error as Error).message}`); } finally { diff --git a/examples/e2e/cli-e2e-original/tooling/utils/verdaccio-npm-env.ts b/examples/e2e/cli-e2e-original/tooling/utils/verdaccio-npm-env.ts index 6e487c00..a33167a3 100644 --- a/examples/e2e/cli-e2e-original/tooling/utils/verdaccio-npm-env.ts +++ b/examples/e2e/cli-e2e-original/tooling/utils/verdaccio-npm-env.ts @@ -9,7 +9,7 @@ import { rm, writeFile } from 'node:fs/promises'; import { setupNpmWorkspace } from '../utils/npm'; import { error, info } from '../utils/logging'; import { objectToCliArgs } from '@push-based/test-utils'; -import { execSync } from 'node:child_process'; +import { execFileSync } from 'node:child_process'; function logInfo(msg: string) { info(msg, 'Verdaccio Env: '); @@ -95,7 +95,7 @@ export function configureRegistry( if (verbose) { logInfo(`Set registry:\n${setRegistry}`); } - execSync(setRegistry); + execFileSync(setRegistry, { shell: true, windowsHide: true }); /** * Protocol-Agnostic Configuration: The use of // allows NPM to configure authentication for a registry without tying it to a specific protocol (http: or https:). @@ -111,7 +111,10 @@ export function configureRegistry( if (verbose) { logInfo(`Set authToken:\n${setAuthToken}`); } - execSync(setAuthToken); + execFileSync(setAuthToken, { + shell: true, + windowsHide: true, + }); } export function unconfigureRegistry( @@ -125,7 +128,10 @@ export function unconfigureRegistry( if (verbose) { logInfo(`Delete authToken:\n${setAuthToken}`); } - execSync(setAuthToken); + execFileSync(setAuthToken, { + shell: true, + windowsHide: true, + }); const setRegistry = `npm config delete registry ${objectToCliArgs({ userconfig, @@ -133,5 +139,5 @@ export function unconfigureRegistry( if (verbose) { logInfo(`Delete registry:\n${setRegistry}`); } - execSync(setRegistry); + execFileSync(setRegistry, { shell: true, windowsHide: true }); } diff --git a/examples/e2e/cli-e2e-original/tooling/utils/verdaccio-registry.ts b/examples/e2e/cli-e2e-original/tooling/utils/verdaccio-registry.ts index 8832c49e..c14e2409 100644 --- a/examples/e2e/cli-e2e-original/tooling/utils/verdaccio-registry.ts +++ b/examples/e2e/cli-e2e-original/tooling/utils/verdaccio-registry.ts @@ -86,9 +86,9 @@ export async function startVerdaccioServer({ return new Promise((resolve, reject) => { executeProcess({ - command: 'nx', + command: 'npx', args: objectToCliArgs({ - _: [targetName, projectName ?? '', '--'], + _: ['nx', targetName, projectName ?? '', '--'], storage, port, verbose, @@ -96,6 +96,7 @@ export async function startVerdaccioServer({ clear, }), shell: true, + windowsHide: true, observer: { onStdout: (stdout: string, childProcess) => { if (verbose) { diff --git a/examples/projects/core/package.json b/examples/projects/core/package.json index 72822950..3a3bf226 100644 --- a/examples/projects/core/package.json +++ b/examples/projects/core/package.json @@ -3,8 +3,6 @@ "version": "0.0.1", "dependencies": { "@push-based/utils": "*", - "@push-based/models": "*", - "vite": "~5.0.0", - "@nx/vite": "19.8.0" + "@push-based/models": "*" } } diff --git a/package-lock.json b/package-lock.json index df13702f..8fc9a85f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "0.0.0", "license": "MIT", "dependencies": { + "@rollup/rollup-linux-x64-gnu": "*", "memfs": "^4.11.1", "simple-git": "^3.27.0", "tslib": "^2.3.0", @@ -31,7 +32,7 @@ "@nx/workspace": "19.8.0", "@swc-node/register": "~1.9.1", "@swc/cli": "~0.3.12", - "@swc/core": "^1.7.22", + "@swc/core": "^1.7.39", "@swc/helpers": "~0.5.11", "@types/jest": "^29.5.12", "@types/node": "18.16.9", @@ -59,7 +60,8 @@ "optionalDependencies": { "@nx/nx-darwin-arm64": "^19.6.6", "@nx/nx-darwin-x64": "^19.6.6", - "@nx/nx-linux-x64-gnu": "^19.6.6" + "@nx/nx-linux-x64-gnu": "^19.6.6", + "@rollup/rollup-linux-x64-gnu": "^4.24.0" } }, "node_modules/@ampproject/remapping": { @@ -3714,6 +3716,18 @@ "darwin" ] }, + "node_modules/@rollup/rollup-linux-x64-gnu": { + "version": "4.24.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.24.0.tgz", + "integrity": "sha512-ZXFk7M72R0YYFN5q13niV0B7G8/5dcQ9JDp8keJSfr3GoZeXEoMHP/HlvqROA3OMbMdfr19IjCeNAnPUG93b6A==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ] + }, "node_modules/@sinclair/typebox": { "version": "0.27.8", "dev": true, @@ -3843,10 +3857,11 @@ } }, "node_modules/@swc/core": { - "version": "1.7.36", + "version": "1.7.39", + "resolved": "https://registry.npmjs.org/@swc/core/-/core-1.7.39.tgz", + "integrity": "sha512-jns6VFeOT49uoTKLWIEfiQqJAlyqldNAt80kAr8f7a5YjX0zgnG3RBiLMpksx4Ka4SlK4O6TJ/lumIM3Trp82g==", "dev": true, "hasInstallScript": true, - "license": "Apache-2.0", "dependencies": { "@swc/counter": "^0.1.3", "@swc/types": "^0.1.13" @@ -3859,16 +3874,16 @@ "url": "https://opencollective.com/swc" }, "optionalDependencies": { - "@swc/core-darwin-arm64": "1.7.36", - "@swc/core-darwin-x64": "1.7.36", - "@swc/core-linux-arm-gnueabihf": "1.7.36", - "@swc/core-linux-arm64-gnu": "1.7.36", - "@swc/core-linux-arm64-musl": "1.7.36", - "@swc/core-linux-x64-gnu": "1.7.36", - "@swc/core-linux-x64-musl": "1.7.36", - "@swc/core-win32-arm64-msvc": "1.7.36", - "@swc/core-win32-ia32-msvc": "1.7.36", - "@swc/core-win32-x64-msvc": "1.7.36" + "@swc/core-darwin-arm64": "1.7.39", + "@swc/core-darwin-x64": "1.7.39", + "@swc/core-linux-arm-gnueabihf": "1.7.39", + "@swc/core-linux-arm64-gnu": "1.7.39", + "@swc/core-linux-arm64-musl": "1.7.39", + "@swc/core-linux-x64-gnu": "1.7.39", + "@swc/core-linux-x64-musl": "1.7.39", + "@swc/core-win32-arm64-msvc": "1.7.39", + "@swc/core-win32-ia32-msvc": "1.7.39", + "@swc/core-win32-x64-msvc": "1.7.39" }, "peerDependencies": { "@swc/helpers": "*" @@ -3880,12 +3895,13 @@ } }, "node_modules/@swc/core-darwin-arm64": { - "version": "1.7.36", + "version": "1.7.39", + "resolved": "https://registry.npmjs.org/@swc/core-darwin-arm64/-/core-darwin-arm64-1.7.39.tgz", + "integrity": "sha512-o2nbEL6scMBMCTvY9OnbyVXtepLuNbdblV9oNJEFia5v5eGj9WMrnRQiylH3Wp/G2NYkW7V1/ZVW+kfvIeYe9A==", "cpu": [ "arm64" ], "dev": true, - "license": "Apache-2.0 AND MIT", "optional": true, "os": [ "darwin" @@ -3894,6 +3910,150 @@ "node": ">=10" } }, + "node_modules/@swc/core-darwin-x64": { + "version": "1.7.39", + "resolved": "https://registry.npmjs.org/@swc/core-darwin-x64/-/core-darwin-x64-1.7.39.tgz", + "integrity": "sha512-qMlv3XPgtPi/Fe11VhiPDHSLiYYk2dFYl747oGsHZPq+6tIdDQjIhijXPcsUHIXYDyG7lNpODPL8cP/X1sc9MA==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-linux-arm-gnueabihf": { + "version": "1.7.39", + "resolved": "https://registry.npmjs.org/@swc/core-linux-arm-gnueabihf/-/core-linux-arm-gnueabihf-1.7.39.tgz", + "integrity": "sha512-NP+JIkBs1ZKnpa3Lk2W1kBJMwHfNOxCUJXuTa2ckjFsuZ8OUu2gwdeLFkTHbR43dxGwH5UzSmuGocXeMowra/Q==", + "cpu": [ + "arm" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-linux-arm64-gnu": { + "version": "1.7.39", + "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.7.39.tgz", + "integrity": "sha512-cPc+/HehyHyHcvAsk3ML/9wYcpWVIWax3YBaA+ScecJpSE04l/oBHPfdqKUPslqZ+Gcw0OWnIBGJT/fBZW2ayw==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-linux-arm64-musl": { + "version": "1.7.39", + "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.7.39.tgz", + "integrity": "sha512-8RxgBC6ubFem66bk9XJ0vclu3exJ6eD7x7CwDhp5AD/tulZslTYXM7oNPjEtje3xxabXuj/bEUMNvHZhQRFdqA==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-linux-x64-gnu": { + "version": "1.7.39", + "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.7.39.tgz", + "integrity": "sha512-3gtCPEJuXLQEolo9xsXtuPDocmXQx12vewEyFFSMSjOfakuPOBmOQMa0sVL8Wwius8C1eZVeD1fgk0omMqeC+Q==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-linux-x64-musl": { + "version": "1.7.39", + "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.7.39.tgz", + "integrity": "sha512-mg39pW5x/eqqpZDdtjZJxrUvQNSvJF4O8wCl37fbuFUqOtXs4TxsjZ0aolt876HXxxhsQl7rS+N4KioEMSgTZw==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-win32-arm64-msvc": { + "version": "1.7.39", + "resolved": "https://registry.npmjs.org/@swc/core-win32-arm64-msvc/-/core-win32-arm64-msvc-1.7.39.tgz", + "integrity": "sha512-NZwuS0mNJowH3e9bMttr7B1fB8bW5svW/yyySigv9qmV5VcQRNz1kMlCvrCLYRsa93JnARuiaBI6FazSeG8mpA==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-win32-ia32-msvc": { + "version": "1.7.39", + "resolved": "https://registry.npmjs.org/@swc/core-win32-ia32-msvc/-/core-win32-ia32-msvc-1.7.39.tgz", + "integrity": "sha512-qFmvv5UExbJPXhhvCVDBnjK5Duqxr048dlVB6ZCgGzbRxuarOlawCzzLK4N172230pzlAWGLgn9CWl3+N6zfHA==", + "cpu": [ + "ia32" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-win32-x64-msvc": { + "version": "1.7.39", + "resolved": "https://registry.npmjs.org/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.7.39.tgz", + "integrity": "sha512-o+5IMqgOtj9+BEOp16atTfBgCogVak9svhBpwsbcJQp67bQbxGYhAPPDW/hZ2rpSSF7UdzbY9wudoX9G4trcuQ==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=10" + } + }, "node_modules/@swc/counter": { "version": "0.1.3", "dev": true, diff --git a/package.json b/package.json index 9f1103a5..841f05ec 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "@nx/workspace": "19.8.0", "@swc-node/register": "~1.9.1", "@swc/cli": "~0.3.12", - "@swc/core": "^1.7.22", + "@swc/core": "^1.7.39", "@swc/helpers": "~0.5.11", "@types/jest": "^29.5.12", "@types/node": "18.16.9", @@ -55,7 +55,8 @@ "optionalDependencies": { "@nx/nx-darwin-arm64": "^19.6.6", "@nx/nx-darwin-x64": "^19.6.6", - "@nx/nx-linux-x64-gnu": "^19.6.6" + "@nx/nx-linux-x64-gnu": "^19.6.6", + "@rollup/rollup-linux-x64-gnu": "^4.24.0" }, "nx": { "includedScripts": [] diff --git a/projects/nx-verdaccio/.eslintrc.json b/projects/nx-verdaccio/.eslintrc.json index ab72edb1..35abf250 100644 --- a/projects/nx-verdaccio/.eslintrc.json +++ b/projects/nx-verdaccio/.eslintrc.json @@ -40,7 +40,12 @@ "error", { "buildTargets": ["build"], - "ignoredDependencies": ["verdaccio"], + "ignoredDependencies": [ + "verdaccio", + "nx", + "@code-pushup/models", + "@nx/plugin" + ], "checkMissingDependencies": true, "checkObsoleteDependencies": true, "checkVersionMismatches": true, diff --git a/projects/nx-verdaccio/package.json b/projects/nx-verdaccio/package.json index e3b9bc7e..73eff258 100644 --- a/projects/nx-verdaccio/package.json +++ b/projects/nx-verdaccio/package.json @@ -8,9 +8,7 @@ "@nx/devkit": "19.8.0", "ansis": "^3.3.2", "simple-git": "^3.27.0", - "nx": "19.8.0", - "tslib": "^2.3.0", - "verdaccio": "*" + "tslib": "^2.3.0" }, "type": "commonjs", "main": "./src/index.js", diff --git a/projects/nx-verdaccio/src/executors/env-bootstrap/executor.unit-test.ts b/projects/nx-verdaccio/src/executors/env-bootstrap/executor.unit-test.ts index bf25290d..67a03b5b 100644 --- a/projects/nx-verdaccio/src/executors/env-bootstrap/executor.unit-test.ts +++ b/projects/nx-verdaccio/src/executors/env-bootstrap/executor.unit-test.ts @@ -5,7 +5,7 @@ import * as bootstrapExecutorModule from './bootstrap-env'; import { PACKAGE_NAME } from '../../plugin/constants'; import { TARGET_ENVIRONMENT_VERDACCIO_STOP } from '../../plugin/targets/environment.targets'; import { MockAsyncIterableIterator } from '@push-based/test-utils'; -import { ExecutorContext } from '@nx/devkit'; +import { type ExecutorContext } from '@nx/devkit'; describe('runBootstrapExecutor', () => { const e2eProjectName = 'my-lib-e2e'; diff --git a/projects/nx-verdaccio/src/executors/env-bootstrap/npm.ts b/projects/nx-verdaccio/src/executors/env-bootstrap/npm.ts index e60795e2..06725f11 100644 --- a/projects/nx-verdaccio/src/executors/env-bootstrap/npm.ts +++ b/projects/nx-verdaccio/src/executors/env-bootstrap/npm.ts @@ -34,6 +34,8 @@ export async function setupNpmWorkspace( await ensureDirectoryExists(environmentRoot); try { await promisify(execFile)('npm', ['init', '--force'], { + shell: true, + windowsHide: true, cwd: join(cwd, environmentRoot), }); } catch (error) { @@ -79,7 +81,7 @@ export async function configureRegistry( ); } - await promisify(exec)(setRegistry); + await promisify(exec)(setRegistry, { windowsHide: true }); /** * Protocol-Agnostic Configuration: The use of // allows NPM to configure authentication for a registry without tying it to a specific protocol (http: or https:). @@ -97,7 +99,7 @@ export async function configureRegistry( formatInfo(`Set authToken:\n${setAuthToken}`, VERDACCIO_ENV_TOKEN) ); } - await promisify(exec)(setAuthToken); + await promisify(exec)(setAuthToken, { windowsHide: true }); } export type UnconfigureRegistryOptions = Pick< @@ -133,7 +135,7 @@ export async function unconfigureRegistry( formatInfo(`Delete authToken:\n${setAuthToken}`, VERDACCIO_ENV_TOKEN) ); } - await promisify(exec)(setAuthToken); + await promisify(exec)(setAuthToken, { windowsHide: true }); const setRegistry = `npm config delete registry ${objectToCliArgs({ userconfig, @@ -143,5 +145,5 @@ export async function unconfigureRegistry( formatInfo(`Delete registry:\n${setRegistry}`, VERDACCIO_ENV_TOKEN) ); } - await promisify(exec)(setRegistry); + await promisify(exec)(setRegistry, { windowsHide: true }); } diff --git a/projects/nx-verdaccio/src/executors/env-bootstrap/npm.unit-test.ts b/projects/nx-verdaccio/src/executors/env-bootstrap/npm.unit-test.ts index be2459f5..eed5dcd2 100644 --- a/projects/nx-verdaccio/src/executors/env-bootstrap/npm.unit-test.ts +++ b/projects/nx-verdaccio/src/executors/env-bootstrap/npm.unit-test.ts @@ -6,22 +6,19 @@ import { type ConfigureRegistryOptions, setupNpmWorkspace, unconfigureRegistry, - type UnconfigureRegistryOptions, VERDACCIO_ENV_TOKEN, } from './npm'; -import { exec } from 'node:child_process'; import { logger } from '@nx/devkit'; import { formatInfo } from '../../internal/logging'; -vi.mock('child_process', async () => { - const actual = await vi.importActual( - 'child_process' - ); - return { - ...actual, - exec: vi.fn().mockImplementation((cmd, cb) => cb(null, '', '')), - }; -}); +const execMock = vi.fn(); +vi.mock('util', () => ({ + promisify: vi.fn( + () => + (...args) => + execMock(...args) + ), +})); vi.mock('@nx/devkit', async () => { const actual = await vi.importActual('@nx/devkit'); @@ -34,6 +31,9 @@ vi.mock('@nx/devkit', async () => { }); describe('configureRegistry', () => { + beforeEach(() => { + execMock.mockRestore(); + }); it('should set the npm registry and authToken', async () => { const processResult: ConfigureRegistryOptions = { port: 4873, @@ -44,15 +44,15 @@ describe('configureRegistry', () => { await configureRegistry(processResult); - expect(exec).toHaveBeenCalledTimes(2); - expect(exec).toHaveBeenCalledWith( + expect(execMock).toHaveBeenCalledTimes(2); + expect(execMock).toHaveBeenCalledWith( 'npm config set registry="http://localhost:4873" --userconfig="test-config"', - expect.any(Function) + { windowsHide: true } ); - expect(exec).toHaveBeenCalledWith( + expect(execMock).toHaveBeenCalledWith( 'npm config set //localhost:4873/:_authToken "secretVerdaccioToken" --userconfig="test-config"', - expect.any(Function) + { windowsHide: true } ); }); @@ -66,7 +66,7 @@ describe('configureRegistry', () => { await configureRegistry(processResult, true); - expect(exec).toHaveBeenCalledTimes(2); + expect(execMock).toHaveBeenCalledTimes(2); expect(logger.info).toHaveBeenCalledWith( formatInfo( 'Set registry:\nnpm config set registry="http://localhost:4873" --userconfig="test-config"', @@ -83,6 +83,10 @@ describe('configureRegistry', () => { }); describe('unconfigureRegistry', () => { + beforeEach(() => { + execMock.mockRestore(); + }); + it('should delete the npm registry and authToken', async () => { const processResult: UnconfigureRegistryOptions = { userconfig: 'test-config', @@ -92,15 +96,15 @@ describe('unconfigureRegistry', () => { await unconfigureRegistry(processResult); - expect(exec).toHaveBeenCalledTimes(2); - expect(exec).toHaveBeenCalledWith( + expect(execMock).toHaveBeenCalledTimes(2); + expect(execMock).toHaveBeenCalledWith( 'npm config delete registry --userconfig="test-config"', - expect.any(Function) + { windowsHide: true } ); - expect(exec).toHaveBeenCalledWith( + expect(execMock).toHaveBeenCalledWith( 'npm config delete //localhost:4873/:_authToken --userconfig="test-config"', - expect.any(Function) + { windowsHide: true } ); }); @@ -113,7 +117,7 @@ describe('unconfigureRegistry', () => { await unconfigureRegistry(processResult, true); - expect(exec).toHaveBeenCalledTimes(2); + expect(execMock).toHaveBeenCalledTimes(2); expect(logger.info).toHaveBeenCalledWith( formatInfo( 'Delete registry:\nnpm config delete registry --userconfig="test-config"', diff --git a/projects/nx-verdaccio/src/executors/env-bootstrap/schema.ts b/projects/nx-verdaccio/src/executors/env-bootstrap/schema.ts index e5b57a01..f3ec1c41 100644 --- a/projects/nx-verdaccio/src/executors/env-bootstrap/schema.ts +++ b/projects/nx-verdaccio/src/executors/env-bootstrap/schema.ts @@ -1,4 +1,4 @@ -import { Environment } from './npm'; +import { type Environment } from './npm'; export type BootstrapExecutorOptions = Partial< { diff --git a/projects/nx-verdaccio/src/executors/env-bootstrap/verdaccio-registry.ts b/projects/nx-verdaccio/src/executors/env-bootstrap/verdaccio-registry.ts index 61772b1c..eff2e4c4 100644 --- a/projects/nx-verdaccio/src/executors/env-bootstrap/verdaccio-registry.ts +++ b/projects/nx-verdaccio/src/executors/env-bootstrap/verdaccio-registry.ts @@ -98,9 +98,14 @@ export async function startVerdaccioServer({ const isWindows = process.platform === 'win32'; executeProcess({ - command: 'nx', + command: 'npx', args: objectToCliArgs({ - _: [TARGET_ENVIRONMENT_VERDACCIO_START, projectName ?? '', '--'], + _: [ + 'nx', + TARGET_ENVIRONMENT_VERDACCIO_START, + projectName ?? '', + '--', + ], port, ...(verbose !== undefined ? { verbose } : {}), location, @@ -111,6 +116,7 @@ export async function startVerdaccioServer({ detached: !isWindows, //stdio: ['ignore', 'ignore', 'ignore'], // Ignore I/O streams shell: true, + windowsHide: true, observer: { onStdout: (stdout: string, childProcess) => { if (verbose) { diff --git a/projects/nx-verdaccio/src/executors/env-setup/executor.ts b/projects/nx-verdaccio/src/executors/env-setup/executor.ts index 263389ab..9b57f9cf 100644 --- a/projects/nx-verdaccio/src/executors/env-setup/executor.ts +++ b/projects/nx-verdaccio/src/executors/env-setup/executor.ts @@ -15,7 +15,6 @@ import { } from '../../plugin/targets/environment.targets'; import { runSingleExecutor } from '../../internal/run-executor'; import { rm } from 'node:fs/promises'; -import { options } from 'yargs'; import { getEnvironmentRoot } from '../../internal/environment-root'; export type ExecutorOutput = { @@ -59,9 +58,9 @@ export default async function runSetupEnvironmentExecutor( try { await executeProcess({ - command: 'nx', + command: 'npx', args: objectToCliArgs({ - _: [TARGET_ENVIRONMENT_INSTALL, projectName], + _: ['nx', TARGET_ENVIRONMENT_INSTALL, projectName], environmentRoot, ...(verbose ? { verbose } : {}), }), diff --git a/projects/nx-verdaccio/src/executors/env-setup/executor.unit-test.ts b/projects/nx-verdaccio/src/executors/env-setup/executor.unit-test.ts index 943f19b3..924310e8 100644 --- a/projects/nx-verdaccio/src/executors/env-setup/executor.unit-test.ts +++ b/projects/nx-verdaccio/src/executors/env-setup/executor.unit-test.ts @@ -86,12 +86,13 @@ describe('runSetupEnvironmentExecutor', () => { expect(executeProcessSpy).toHaveBeenCalledTimes(1); expect(executeProcessSpy).toHaveBeenCalledWith({ args: [ + 'nx', 'nxv-env-install', projectName, // @TODO check for --environmentRoot too be OS agnostic path expect.stringContaining(projectName), ], - command: 'nx', + command: 'npx', cwd: '/test', }); @@ -212,11 +213,12 @@ describe('runSetupEnvironmentExecutor', () => { expect(executeProcessSpy).toHaveBeenCalledTimes(1); expect(executeProcessSpy).toHaveBeenCalledWith({ args: [ + 'nx', 'nxv-env-install', 'my-lib-e2e', '--environmentRoot="tmp/environments/my-lib-e2e"', ], - command: 'nx', + command: 'npx', cwd: '/test', }); diff --git a/projects/nx-verdaccio/src/executors/env-setup/schema.ts b/projects/nx-verdaccio/src/executors/env-setup/schema.ts index 9688789c..672a8c7a 100644 --- a/projects/nx-verdaccio/src/executors/env-setup/schema.ts +++ b/projects/nx-verdaccio/src/executors/env-setup/schema.ts @@ -1,4 +1,4 @@ -import { Environment } from '../env-bootstrap/npm'; +import { type Environment } from '../env-bootstrap/npm'; export type SetupEnvironmentExecutorOptions = Partial< Environment & { diff --git a/projects/nx-verdaccio/src/executors/env-teardown/teardown-env.ts b/projects/nx-verdaccio/src/executors/env-teardown/teardown-env.ts index 9256b149..2dfe9b0a 100644 --- a/projects/nx-verdaccio/src/executors/env-teardown/teardown-env.ts +++ b/projects/nx-verdaccio/src/executors/env-teardown/teardown-env.ts @@ -14,8 +14,7 @@ export type TeardownEnvironmentOptions = Environment & { verbose?: boolean }; export async function teardownEnvironment( context: ExecutorContext, - options: TeardownEnvironmentOptions, - git: SimpleGit = gitClient + options: TeardownEnvironmentOptions ): Promise { const environmentRoot = getEnvironmentRoot(context, options); // kill verdaccio process if running diff --git a/projects/nx-verdaccio/src/executors/kill-process/executor.unit-test.ts b/projects/nx-verdaccio/src/executors/kill-process/executor.unit-test.ts index 6536fd7c..68f04beb 100644 --- a/projects/nx-verdaccio/src/executors/kill-process/executor.unit-test.ts +++ b/projects/nx-verdaccio/src/executors/kill-process/executor.unit-test.ts @@ -3,8 +3,6 @@ import runKillProcessExecutor from './executor'; import * as killProcessModule from './kill-process'; import { MEMFS_VOLUME } from '@push-based/test-utils'; import { logger } from '@nx/devkit'; -import { PACKAGE_NAME } from '../../plugin/constants'; -import { EXECUTOR_ENVIRONMENT_KILL_PROCESS } from './constant'; vi.mock('@nx/devkit', async () => { const actual = await vi.importActual('@nx/devkit'); diff --git a/projects/nx-verdaccio/src/executors/pkg-install/executor.ts b/projects/nx-verdaccio/src/executors/pkg-install/executor.ts index a680cc49..b7e7176f 100644 --- a/projects/nx-verdaccio/src/executors/pkg-install/executor.ts +++ b/projects/nx-verdaccio/src/executors/pkg-install/executor.ts @@ -32,9 +32,15 @@ export default async function runNpmInstallExecutor( await executeProcess({ command: 'npm', args: objectToCliArgs({ - _: ['install', `${packageNameAndVersion}`], + _: [ + 'install', + `${packageNameAndVersion}`, + '--include=prod', + '--include=dev', + '--include=optional', + '--include=peer', // install all the deps of the package + ], fund: false, // avoid polluted terminal - optional: true, // install optional deps of the package shrinkwrap: false, // avoid package-lock creation or update save: true, // save to package.json dependencies }), diff --git a/projects/nx-verdaccio/src/executors/pkg-install/executor.unit-test.ts b/projects/nx-verdaccio/src/executors/pkg-install/executor.unit-test.ts index 6bd3863e..dbc047b5 100644 --- a/projects/nx-verdaccio/src/executors/pkg-install/executor.unit-test.ts +++ b/projects/nx-verdaccio/src/executors/pkg-install/executor.unit-test.ts @@ -81,6 +81,10 @@ describe('runNpmInstallExecutor', () => { args: [ 'install', 'my-lib@1.0.0', + '--include=prod', + '--include=dev', + '--include=optional', + '--include=peer', '--no-fund', '--no-shrinkwrap', '--save', diff --git a/projects/nx-verdaccio/src/internal/environment-root.ts b/projects/nx-verdaccio/src/internal/environment-root.ts index a779e66e..aedc8622 100644 --- a/projects/nx-verdaccio/src/internal/environment-root.ts +++ b/projects/nx-verdaccio/src/internal/environment-root.ts @@ -1,9 +1,9 @@ import { join } from 'node:path'; -import { ExecutorContext } from '@nx/devkit'; -import { ExpandedPluginConfiguration } from 'nx/src/config/nx-json'; -import { NxVerdaccioCreateNodeOptions } from '../plugin/schema'; +import { type ExecutorContext } from '@nx/devkit'; +import { type ExpandedPluginConfiguration } from 'nx/src/config/nx-json'; +import { type NxVerdaccioCreateNodeOptions } from '../plugin/schema'; import { DEFAULT_ENVIRONMENTS_OUTPUT_DIR } from '../plugin/constants'; -import { Environment } from '../executors/env-bootstrap/npm'; +import { type Environment } from '../executors/env-bootstrap/npm'; export function getEnvironmentDir(context: ExecutorContext) { const plugin = context.nxJsonConfiguration?.plugins?.find((pCfg) => { diff --git a/projects/nx-verdaccio/src/internal/execute-process.ts b/projects/nx-verdaccio/src/internal/execute-process.ts index e358c547..d15de546 100644 --- a/projects/nx-verdaccio/src/internal/execute-process.ts +++ b/projects/nx-verdaccio/src/internal/execute-process.ts @@ -32,7 +32,11 @@ export type ProcessConfig = Omit< SpawnOptionsWithStdioTuple, 'stdio' > & { - stdio?: 'pipe' | 'inherit' | 'ignore' | (StdioPipe | 'pipe' | 'inherit' | 'ignore')[]; + stdio?: + | 'pipe' + | 'inherit' + | 'ignore' + | (StdioPipe | 'pipe' | 'inherit' | 'ignore')[]; command: string; args?: string[]; verbose?: boolean; @@ -76,6 +80,7 @@ export function executeProcess(cfg: ProcessConfig): Promise { // shell:true tells Windows to use shell command for spawning a child process const spawnedProcess = spawn(command, args ?? [], { shell: true, + windowsHide: true, ...options, }) as ChildProcessByStdio; diff --git a/testing/test-nx-utils/src/lib/execute-process.ts b/testing/test-nx-utils/src/lib/execute-process.ts index 02d974a5..9f90164d 100644 --- a/testing/test-nx-utils/src/lib/execute-process.ts +++ b/testing/test-nx-utils/src/lib/execute-process.ts @@ -63,6 +63,8 @@ export function executeProcess(cfg: ProcessConfig): Promise { // shell:true tells Windows to use shell command for spawning a child process const spawnedProcess = spawn(command, args ?? [], { shell: true, + windowsHide: true, + ...options, }) as ChildProcessByStdio; diff --git a/testing/test-utils/src/lib/execute-process.ts b/testing/test-utils/src/lib/execute-process.ts index 02d974a5..9f90164d 100644 --- a/testing/test-utils/src/lib/execute-process.ts +++ b/testing/test-utils/src/lib/execute-process.ts @@ -63,6 +63,8 @@ export function executeProcess(cfg: ProcessConfig): Promise { // shell:true tells Windows to use shell command for spawning a child process const spawnedProcess = spawn(command, args ?? [], { shell: true, + windowsHide: true, + ...options, }) as ChildProcessByStdio; diff --git a/tooling/bin/nx-show-project.ts b/tooling/bin/nx-show-project.ts index edf85066..06683851 100644 --- a/tooling/bin/nx-show-project.ts +++ b/tooling/bin/nx-show-project.ts @@ -1,4 +1,4 @@ -import { execFileSync, execSync } from 'node:child_process'; +import { execFileSync } from 'node:child_process'; import yargs from 'yargs'; import { hideBin } from 'yargs/helpers'; import { objectToCliArgs } from '../../../../packages/utils/src'; @@ -41,9 +41,7 @@ try { // Hide process output via "2>/dev/null". Otherwise, it will print the error message to the terminal. '2>/dev/null', ], - { - shell: true, - } + { shell: true, windowsHide: true } ).toString(); const existingPackage = viewResult diff --git a/tooling/measures/nx-performance/audit/graph-project-time.audit.ts b/tooling/measures/nx-performance/audit/graph-project-time.audit.ts index dd845914..71758856 100644 --- a/tooling/measures/nx-performance/audit/graph-project-time.audit.ts +++ b/tooling/measures/nx-performance/audit/graph-project-time.audit.ts @@ -47,6 +47,7 @@ export async function projectGraphTiming(): Promise<{ duration: number }> { const isWindows = process.platform === 'win32'; await promisify(execFile)('npx', ['nx', 'show', 'projects'], { shell: isWindows, + windowsHide: true, env: { ...process.env, NX_CACHE_PROJECT_GRAPH: 'false', diff --git a/tooling/measures/nx-performance/audit/graph-task-time.audit.ts b/tooling/measures/nx-performance/audit/graph-task-time.audit.ts index d4ba8e68..f260ef93 100644 --- a/tooling/measures/nx-performance/audit/graph-task-time.audit.ts +++ b/tooling/measures/nx-performance/audit/graph-task-time.audit.ts @@ -75,6 +75,7 @@ export async function taskGraphTiming( ], { shell: isWindows, + windowsHide: true, env: { ...process.env, NX_CACHE_PROJECT_GRAPH: 'false',