diff --git a/.verdaccio/config.yml b/.verdaccio/config.yml index 2e9f83b1..bc61ec2b 100644 --- a/.verdaccio/config.yml +++ b/.verdaccio/config.yml @@ -9,6 +9,12 @@ uplinks: maxage: 60m packages: + # allow publishing local packages + '@push-based/*': + access: $all + publish: $all + unpublish: $all + '**': # give all users (including non-authenticated users) full access # because it is a local registry diff --git a/code-pushup.config.ts b/code-pushup.config.ts index 4c985c11..99f40a44 100644 --- a/code-pushup.config.ts +++ b/code-pushup.config.ts @@ -19,7 +19,7 @@ const taskTimeTasks: TaskTimeAuditOption[] = [ {task: 'models-e2e:e2e'}, {task: 'models-e2e:nxv-e2e'}, {task: 'nx-verdaccio-e2e:nxv-e2e'}, - {task: 'cli-e2e-original:original-e2e'}, + {task: 'cli-e2e-original:original-e2e', options: { exclude: ["nx-verdaccio"]}}, ]; const cacheSizeTasks = [ 'models-e2e:nxv-env-setup', diff --git a/e2e/nx-verdaccio-e2e/test/__snapshots__/plugin-create-nodes.e2e.test.ts.snap b/e2e/nx-verdaccio-e2e/test/__snapshots__/plugin-create-nodes.e2e.test.ts.snap index f2dbc096..57aa2a41 100644 --- a/e2e/nx-verdaccio-e2e/test/__snapshots__/plugin-create-nodes.e2e.test.ts.snap +++ b/e2e/nx-verdaccio-e2e/test/__snapshots__/plugin-create-nodes.e2e.test.ts.snap @@ -17,7 +17,10 @@ exports[`nx-verdaccio plugin create-nodes-v2 > should add environment targets to "nxv-e2e": { "configurations": {}, "dependsOn": [ - "e2e", + { + "params": "forward", + "target": "e2e", + }, ], "executor": "@push-based/nx-verdaccio:env-teardown", "options": {}, @@ -26,9 +29,7 @@ exports[`nx-verdaccio plugin create-nodes-v2 > should add environment targets to "nxv-env-bootstrap": { "configurations": {}, "executor": "@push-based/nx-verdaccio:env-bootstrap", - "options": { - "environmentRoot": "tmp/environments/lib-a-e2e", - }, + "options": {}, "parallelism": true, }, "nxv-env-install": { @@ -40,8 +41,9 @@ exports[`nx-verdaccio plugin create-nodes-v2 > should add environment targets to "target": "nxv-pkg-install", }, ], - "executor": "nx:noop", + "executor": "nx:run-commands", "options": { + "command": "echo "dependencies installed for tmp/environments/lib-a-e2e"", "environmentRoot": "tmp/environments/lib-a-e2e", }, "parallelism": true, @@ -65,9 +67,7 @@ exports[`nx-verdaccio plugin create-nodes-v2 > should add environment targets to }, "^production", ], - "options": { - "environmentRoot": "tmp/environments/lib-a-e2e", - }, + "options": {}, "outputs": [ "{options.environmentRoot}/.npmrc", "{options.environmentRoot}/package.json", diff --git a/e2e/nx-verdaccio-e2e/test/plugin-create-nodes.e2e.test.ts b/e2e/nx-verdaccio-e2e/test/plugin-create-nodes.e2e.test.ts index ff321877..a15eeca9 100644 --- a/e2e/nx-verdaccio-e2e/test/plugin-create-nodes.e2e.test.ts +++ b/e2e/nx-verdaccio-e2e/test/plugin-create-nodes.e2e.test.ts @@ -187,7 +187,7 @@ describe('nx-verdaccio plugin create-nodes-v2', () => { const { code, projectJson } = await nxShowProjectJson(cwd, projectAE2e); expect(code).toBe(0); - expect(projectJson.targets).toStrictEqual( + expect(projectJson.targets).toEqual( expect.objectContaining({ e2e: expect.objectContaining({ dependsOn: [ @@ -199,9 +199,6 @@ describe('nx-verdaccio plugin create-nodes-v2', () => { }), [TARGET_ENVIRONMENT_BOOTSTRAP]: expect.objectContaining({ executor: '@push-based/nx-verdaccio:env-bootstrap', - options: { - environmentRoot: 'tmp/environments/lib-a-e2e', - }, }), [TARGET_ENVIRONMENT_INSTALL]: expect.objectContaining({ dependsOn: [ @@ -211,15 +208,17 @@ describe('nx-verdaccio plugin create-nodes-v2', () => { target: TARGET_PACKAGE_INSTALL, }, ], - executor: 'nx:noop', - options: { environmentRoot: 'tmp/environments/lib-a-e2e' }, + executor: 'nx:run-commands', + options: { + environmentRoot: 'tmp/environments/lib-a-e2e', + command: + 'echo "dependencies installed for tmp/environments/lib-a-e2e"', + }, }), [TARGET_ENVIRONMENT_SETUP]: expect.objectContaining({ cache: true, executor: '@push-based/nx-verdaccio:env-setup', - options: { - environmentRoot: 'tmp/environments/lib-a-e2e', - }, + options: {}, inputs: [ '{projectRoot}/project.json', { @@ -259,7 +258,12 @@ describe('nx-verdaccio plugin create-nodes-v2', () => { }), [TARGET_ENVIRONMENT_E2E]: expect.objectContaining({ executor: '@push-based/nx-verdaccio:env-teardown', - dependsOn: ['e2e'], + dependsOn: [ + { + params: 'forward', + target: 'e2e', + }, + ], }), [TARGET_ENVIRONMENT_TEARDOWN]: expect.objectContaining({ executor: '@push-based/nx-verdaccio:env-teardown', diff --git a/examples/e2e/cli-e2e-original/tooling/original.plugin.ts b/examples/e2e/cli-e2e-original/tooling/original.plugin.ts index 57ba1518..f79125e4 100644 --- a/examples/e2e/cli-e2e-original/tooling/original.plugin.ts +++ b/examples/e2e/cli-e2e-original/tooling/original.plugin.ts @@ -54,12 +54,16 @@ function verdaccioTargets(): Record { function npmTargets( projectConfiguration: ProjectConfiguration & { name: string } ): Record { - const { root } = projectConfiguration; + const { root, name, tags } = projectConfiguration; const outputPath = getBuildOutputPathFromBuildTarget(projectConfiguration); const { name: packageName, version: pkgVersion } = readJsonFile( join(root, 'package.json') ); + // + if(!tags.some(i => i === 'type:example')) { + return {}; + } return { 'original-npm-publish': { command: 'npm publish', diff --git a/projects/nx-verdaccio/src/executors/env-bootstrap/executor.ts b/projects/nx-verdaccio/src/executors/env-bootstrap/executor.ts index 8213f072..890ea36c 100644 --- a/projects/nx-verdaccio/src/executors/env-bootstrap/executor.ts +++ b/projects/nx-verdaccio/src/executors/env-bootstrap/executor.ts @@ -14,6 +14,7 @@ import { } from '../../plugin/targets/environment.targets'; import { runSingleExecutor } from '../../internal/run-executor'; import { PACKAGE_NAME } from '../../plugin/constants'; +import { getEnvironmentRoot } from '../../internal/environment-root'; export type BootstrapExecutorOutput = { success: boolean; @@ -26,7 +27,8 @@ export async function bootstrapExecutor( context: ExecutorContext ): Promise { const { configurationName, projectName } = context; - const { keepServerRunning, environmentRoot, verbose } = options; + const { keepServerRunning, verbose } = options; + const environmentRoot = getEnvironmentRoot(context, options); if (verbose) { logger.info( 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 df79f9c2..bf25290d 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,13 +5,14 @@ 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'; describe('runBootstrapExecutor', () => { const e2eProjectName = 'my-lib-e2e'; const e2eProjectsConfiguration = { root: `e2e/${e2eProjectName}`, }; - const context = { + const context: ExecutorContext = { cwd: 'test', isVerbose: false, root: 'tmp/environments/test', @@ -22,6 +23,9 @@ describe('runBootstrapExecutor', () => { [e2eProjectName]: e2eProjectsConfiguration, }, }, + nxJsonConfiguration: { + plugins: [], + }, }; const stopVerdaccioTask = { project: e2eProjectName, diff --git a/projects/nx-verdaccio/src/executors/env-bootstrap/schema.json b/projects/nx-verdaccio/src/executors/env-bootstrap/schema.json index 7f58d5f6..7bb21d47 100644 --- a/projects/nx-verdaccio/src/executors/env-bootstrap/schema.json +++ b/projects/nx-verdaccio/src/executors/env-bootstrap/schema.json @@ -25,5 +25,5 @@ } }, "additionalProperties": true, - "required": ["environmentRoot"] + "required": [] } diff --git a/projects/nx-verdaccio/src/executors/env-bootstrap/schema.ts b/projects/nx-verdaccio/src/executors/env-bootstrap/schema.ts index 550c5fa6..e5b57a01 100644 --- a/projects/nx-verdaccio/src/executors/env-bootstrap/schema.ts +++ b/projects/nx-verdaccio/src/executors/env-bootstrap/schema.ts @@ -1,6 +1,9 @@ -export type BootstrapExecutorOptions = Partial<{ - keepServerRunning: boolean; - environmentRoot: string; - printConfig: boolean; - verbose: boolean; -}>; +import { Environment } from './npm'; + +export type BootstrapExecutorOptions = Partial< + { + keepServerRunning: boolean; + printConfig: boolean; + verbose: boolean; + } & Environment +>; 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 98d0728a..4fb722e7 100644 --- a/projects/nx-verdaccio/src/executors/env-bootstrap/verdaccio-registry.ts +++ b/projects/nx-verdaccio/src/executors/env-bootstrap/verdaccio-registry.ts @@ -14,6 +14,7 @@ import { VERDACCIO_REGISTRY_JSON, } from './constants'; import { runSingleExecutor } from '../../internal/run-executor'; +import { getEnvironmentRoot } from '../../internal/environment-root'; const VERDACCIO_TOKEN = 'Verdaccio: '; @@ -179,8 +180,8 @@ export function stopVerdaccioServer(options: { environmentRoot: string; context: ExecutorContext; }): Promise { - const { projectName, verbose, context, configuration, environmentRoot } = - options; + const { projectName, verbose, context, configuration } = options; + const environmentRoot = getEnvironmentRoot(context, options); return runSingleExecutor( { project: projectName, diff --git a/projects/nx-verdaccio/src/executors/env-setup/executor.ts b/projects/nx-verdaccio/src/executors/env-setup/executor.ts index fb0dbd20..263389ab 100644 --- a/projects/nx-verdaccio/src/executors/env-setup/executor.ts +++ b/projects/nx-verdaccio/src/executors/env-setup/executor.ts @@ -15,6 +15,8 @@ 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 = { success: boolean; @@ -27,8 +29,11 @@ export default async function runSetupEnvironmentExecutor( context: ExecutorContext ) { const { configurationName: configuration, projectName } = context; - const { verbose, environmentRoot, keepServerRunning } = - terminalAndExecutorOptions; + const { verbose, keepServerRunning } = terminalAndExecutorOptions; + const environmentRoot = getEnvironmentRoot( + context, + terminalAndExecutorOptions + ); try { await runSingleExecutor( { 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 5a58fa77..943f19b3 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 @@ -77,12 +77,7 @@ describe('runSetupEnvironmentExecutor', () => { }; await expect( - runSetupEnvironmentExecutor( - { - environmentRoot: 'tmp/environments/my-lib-e2e', - }, - context - ) + runSetupEnvironmentExecutor({}, context) ).resolves.toStrictEqual({ success: true, command: 'Environment env-setup complete.', @@ -108,7 +103,6 @@ describe('runSetupEnvironmentExecutor', () => { target: TARGET_ENVIRONMENT_BOOTSTRAP, }, { - environmentRoot: 'tmp/environments/my-lib-e2e', keepServerRunning: true, }, context diff --git a/projects/nx-verdaccio/src/executors/env-setup/schema.json b/projects/nx-verdaccio/src/executors/env-setup/schema.json index 06c4e07f..7c56ad90 100644 --- a/projects/nx-verdaccio/src/executors/env-setup/schema.json +++ b/projects/nx-verdaccio/src/executors/env-setup/schema.json @@ -29,5 +29,5 @@ } }, "additionalProperties": true, - "required": ["environmentRoot"] + "required": [] } diff --git a/projects/nx-verdaccio/src/executors/env-setup/schema.ts b/projects/nx-verdaccio/src/executors/env-setup/schema.ts index 3f14617e..9688789c 100644 --- a/projects/nx-verdaccio/src/executors/env-setup/schema.ts +++ b/projects/nx-verdaccio/src/executors/env-setup/schema.ts @@ -1,6 +1,9 @@ -export type SetupEnvironmentExecutorOptions = Partial<{ - environmentRoot: string; - keepServerRunning: boolean; - progress: boolean; - verbose: boolean; -}>; +import { Environment } from '../env-bootstrap/npm'; + +export type SetupEnvironmentExecutorOptions = Partial< + Environment & { + keepServerRunning: boolean; + progress: boolean; + verbose: boolean; + } +>; 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 13e2ad98..9256b149 100644 --- a/projects/nx-verdaccio/src/executors/env-teardown/teardown-env.ts +++ b/projects/nx-verdaccio/src/executors/env-teardown/teardown-env.ts @@ -7,9 +7,7 @@ import { VERDACCIO_REGISTRY_JSON } from '../env-bootstrap/constants'; import { fileExists } from '../../internal/file-system'; import { rm } from 'node:fs/promises'; import runKillProcessExecutor from '../kill-process/executor'; -import { DEFAULT_ENVIRONMENTS_OUTPUT_DIR } from '../../plugin/constants'; -import { type ExpandedPluginConfiguration } from 'nx/src/config/nx-json'; -import type { NxVerdaccioCreateNodeOptions } from '../../plugin/schema'; +import { getEnvironmentRoot } from '../../internal/environment-root'; export const gitClient: SimpleGit = simpleGit(process.cwd()); export type TeardownEnvironmentOptions = Environment & { verbose?: boolean }; @@ -19,17 +17,7 @@ export async function teardownEnvironment( options: TeardownEnvironmentOptions, git: SimpleGit = gitClient ): Promise { - const { environmentRoot: optEnvironmentRoot } = options; - const plugin = context.nxJsonConfiguration.plugins.find((pCfg) => { - return ( - typeof pCfg === 'object' && pCfg?.plugin === '@push-based/nx-verdaccio' - ); - }) as ExpandedPluginConfiguration; - const environmentsDir = - plugin.options.environments?.environmentsDir ?? - DEFAULT_ENVIRONMENTS_OUTPUT_DIR; - const environmentRoot = - optEnvironmentRoot ?? join(environmentsDir, context.projectName); + const environmentRoot = getEnvironmentRoot(context, options); // kill verdaccio process if running const registryPath = join(environmentRoot, VERDACCIO_REGISTRY_JSON); const registryJsonExists = await fileExists(registryPath); diff --git a/projects/nx-verdaccio/src/internal/environment-root.ts b/projects/nx-verdaccio/src/internal/environment-root.ts new file mode 100644 index 00000000..a779e66e --- /dev/null +++ b/projects/nx-verdaccio/src/internal/environment-root.ts @@ -0,0 +1,27 @@ +import { join } from 'node:path'; +import { ExecutorContext } from '@nx/devkit'; +import { ExpandedPluginConfiguration } from 'nx/src/config/nx-json'; +import { NxVerdaccioCreateNodeOptions } from '../plugin/schema'; +import { DEFAULT_ENVIRONMENTS_OUTPUT_DIR } from '../plugin/constants'; +import { Environment } from '../executors/env-bootstrap/npm'; + +export function getEnvironmentDir(context: ExecutorContext) { + const plugin = context.nxJsonConfiguration?.plugins?.find((pCfg) => { + return ( + typeof pCfg === 'object' && pCfg?.plugin === '@push-based/nx-verdaccio' + ); + }) as ExpandedPluginConfiguration; + return ( + plugin?.options?.environments?.environmentsDir ?? + DEFAULT_ENVIRONMENTS_OUTPUT_DIR + ); +} + +export function getEnvironmentRoot( + context: ExecutorContext, + options: Partial +) { + const { environmentRoot: optEnvironmentRoot } = options; + const environmentsDir = getEnvironmentDir(context); + return optEnvironmentRoot ?? join(environmentsDir, context.projectName); +} diff --git a/projects/nx-verdaccio/src/plugin/targets/environment.targets.ts b/projects/nx-verdaccio/src/plugin/targets/environment.targets.ts index bde97d73..c656e57b 100644 --- a/projects/nx-verdaccio/src/plugin/targets/environment.targets.ts +++ b/projects/nx-verdaccio/src/plugin/targets/environment.targets.ts @@ -71,9 +71,7 @@ export function verdaccioTargets( [TARGET_ENVIRONMENT_VERDACCIO_START]: { // @TODO: consider using the executor function directly to reduce the number of targets // https://github.com/nrwl/nx/blob/b73f1e0e0002c55fc0bacaa1557140adb9eec8de/packages/js/src/executors/verdaccio/verdaccio.impl.ts#L22 - outputs: [ - `{options.environmentRoot}/${VERDACCIO_STORAGE_DIR}`, - ], + outputs: [`{options.environmentRoot}/${VERDACCIO_STORAGE_DIR}`], executor: '@nx/js:verdaccio', options: { config: '.verdaccio/config.yml', @@ -113,7 +111,6 @@ export function getEnvTargets( return { [TARGET_ENVIRONMENT_BOOTSTRAP]: { executor: `${PACKAGE_NAME}:${EXECUTOR_ENVIRONMENT_BOOTSTRAP}`, - options: { environmentRoot }, }, // intermediate task just here to execute dependent pkg-install tasks with the correct environmentProject [TARGET_ENVIRONMENT_INSTALL]: { @@ -126,7 +123,7 @@ export function getEnvTargets( ], options: { environmentRoot }, // This is here to make it appear in the graph in older nx versions (otherwise it is filtered out) - command: `echo "dependencies installed for ${environmentRoot}"` + command: `echo "dependencies installed for ${environmentRoot}"`, }, // runs env-bootstrap-env, install-env and stop-verdaccio [TARGET_ENVIRONMENT_SETUP]: { @@ -155,9 +152,6 @@ export function getEnvTargets( ], cache: true, executor: `${PACKAGE_NAME}:${EXECUTOR_ENVIRONMENT_SETUP}`, - options: { - environmentRoot, - }, }, [TARGET_ENVIRONMENT_TEARDOWN]: { executor: `${PACKAGE_NAME}:${EXECUTOR_ENVIRONMENT_TEARDOWN}`, @@ -165,7 +159,7 @@ export function getEnvTargets( [TARGET_ENVIRONMENT_E2E]: { dependsOn: targetNames.map((targetName) => ({ target: targetName, - params: 'forward' + params: 'forward', })), executor: `${PACKAGE_NAME}:${EXECUTOR_ENVIRONMENT_TEARDOWN}`, }, diff --git a/tooling/measures/nx-performance/audit/task-time.audit.ts b/tooling/measures/nx-performance/audit/task-time.audit.ts index 7cd2e684..e252f395 100644 --- a/tooling/measures/nx-performance/audit/task-time.audit.ts +++ b/tooling/measures/nx-performance/audit/task-time.audit.ts @@ -1,5 +1,5 @@ import { AuditOutput, Audit, Table, Issue } from '@code-pushup/models'; -import { executeProcess, slugify, formatDuration } from '@code-pushup/utils'; +import {executeProcess, slugify, formatDuration, objectToCliArgs} from '@code-pushup/utils'; import { logger, readJsonFile } from '@nx/devkit'; import { DEFAULT_PLUGIN_OUTPUT } from '../constant'; import { join } from 'node:path'; @@ -14,6 +14,7 @@ export function getTaskTimeAuditSlug(task: string): string { export type TaskTimeAuditOption = { task: string; + options?: Record; cleanup?: () => void | Promise; }; @@ -80,13 +81,13 @@ export async function taskTimeData( ): Promise { const results: TaskTimeResult[] = []; - for (const { task } of tasks) { + for (const { task, options = {} } of tasks) { const dist = join(DEFAULT_PLUGIN_OUTPUT, 'task-time'); await executeProcess({ command: `NX_DAEMON=false NX_PROFILE=${dist}/${slugify( task )}-profile.json npx`, - args: ['nx', 'run', task, '--parallel=1', '--skipNxCache'], + args: ['nx', 'run', task, '--parallel=1', '--skipNxCache', ...objectToCliArgs(options)], observer: { onStdout: (stdout) => logger.info(stdout), onStderr: (stderr) => logger.error(stderr),