From 33b1d3b5417c4b71c1199f231f0b46ddfcd94b53 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 13 Oct 2024 02:59:35 +0200 Subject: [PATCH 01/21] feat: add env-teardown executor --- examples/e2e/models-e2e/project.json | 3 ++ .../src/executors/env-teardown/README.md | 53 ++++++++++++++++++ .../src/executors/env-teardown/constants.ts | 1 + .../src/executors/env-teardown/executor.ts | 42 +++++++++++++++ .../src/executors/env-teardown/git.ts | 54 +++++++++++++++++++ .../executors/env-teardown/git.unit-test.ts | 11 ++++ .../src/executors/env-teardown/schema.json | 19 +++++++ .../src/executors/env-teardown/schema.ts | 5 ++ .../executors/env-teardown/teardown-env.ts | 54 +++++++++++++++++++ .../env-teardown/teardown-env.unit-test.ts | 5 ++ .../src/executors/internal/executor-output.ts | 5 ++ .../nx-verdaccio/src/internal/file-system.ts | 11 +++- 12 files changed, 262 insertions(+), 1 deletion(-) create mode 100644 projects/nx-verdaccio/src/executors/env-teardown/README.md create mode 100644 projects/nx-verdaccio/src/executors/env-teardown/constants.ts create mode 100644 projects/nx-verdaccio/src/executors/env-teardown/executor.ts create mode 100644 projects/nx-verdaccio/src/executors/env-teardown/git.ts create mode 100644 projects/nx-verdaccio/src/executors/env-teardown/git.unit-test.ts create mode 100644 projects/nx-verdaccio/src/executors/env-teardown/schema.json create mode 100644 projects/nx-verdaccio/src/executors/env-teardown/schema.ts create mode 100644 projects/nx-verdaccio/src/executors/env-teardown/teardown-env.ts create mode 100644 projects/nx-verdaccio/src/executors/env-teardown/teardown-env.unit-test.ts create mode 100644 projects/nx-verdaccio/src/executors/internal/executor-output.ts diff --git a/examples/e2e/models-e2e/project.json b/examples/e2e/models-e2e/project.json index 276f31c..5522968 100644 --- a/examples/e2e/models-e2e/project.json +++ b/examples/e2e/models-e2e/project.json @@ -7,6 +7,9 @@ "implicitDependencies": ["models"], "targets": { "lint": {}, + "teardown": { + "executor": "@push-based/nx-verdaccio:env-teardown" + }, "e2e": { "executor": "@nx/vite:test", "inputs": ["default", "^production"], diff --git a/projects/nx-verdaccio/src/executors/env-teardown/README.md b/projects/nx-verdaccio/src/executors/env-teardown/README.md new file mode 100644 index 0000000..f8dc5bb --- /dev/null +++ b/projects/nx-verdaccio/src/executors/env-teardown/README.md @@ -0,0 +1,53 @@ +# Teardown Environment Executor + +This executor helps to cleanup a [environment](../../../../../README.md#-environment-folders-to-isolate-files-during-e2e-tests) of a given folder. +If a server is running for the given environment, it will be stopped. +If this folder is checked into github all it's changes will be reverted, if it is not checked into github, the folder will be deleted. + +**Environment folder** + +#### @push-based/nx-verdaccio:env-teardown + +## Usage + +// project.json + +```json +{ + "name": "my-project", + "targets": { + "env-teardown": { + "executor": "@push-based/nx-verdaccio:env-teardown" + } + } +} +``` + +By default, the Nx executor will derive the options from the executor options. + +```jsonc +{ + "name": "my-project", + "targets": { + "env-teardown": { + "executor": "@code-pushup/nx-verdaccio:env-teardown", + "options": { + "envRoot": "/tmp/test-npm-workspace" + "verbose": true, + } + } + } +} +``` + +Show what will be executed without actually executing it: + +`nx run my-project:env-teardown --print-config` + +## Options + +| Name | type | description | +| --------------------- | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------ | +| **envRoot** | `string` (REQUIRED) | The folder in which the package should get published. This folder is the environment folder and contains a configured `.npmrc` file. | +| **verbose** | `boolean` | Show more verbose logs | +| **printConfig** | `boolean` | Print config without executing | diff --git a/projects/nx-verdaccio/src/executors/env-teardown/constants.ts b/projects/nx-verdaccio/src/executors/env-teardown/constants.ts new file mode 100644 index 0000000..91647e3 --- /dev/null +++ b/projects/nx-verdaccio/src/executors/env-teardown/constants.ts @@ -0,0 +1 @@ +export const EXECUTOR_ENVIRONMENT_TEARDOWN = 'env-teardown'; diff --git a/projects/nx-verdaccio/src/executors/env-teardown/executor.ts b/projects/nx-verdaccio/src/executors/env-teardown/executor.ts new file mode 100644 index 0000000..c0ed66f --- /dev/null +++ b/projects/nx-verdaccio/src/executors/env-teardown/executor.ts @@ -0,0 +1,42 @@ +import {type ExecutorContext, logger} from '@nx/devkit'; +import type {TeardownExecutorOptions} from './schema'; +import {teardownEnvironment,} from './teardown-env'; +import {PACKAGE_NAME} from '../../plugin/constants'; +import {EXECUTOR_ENVIRONMENT_TEARDOWN} from "./constants"; +import {ExecutorOutput} from "../internal/executor-output"; + +export async function teardownExecutor( + options: TeardownExecutorOptions, + context: ExecutorContext +): Promise { + const { environmentRoot, verbose } = options; + + if (verbose) { + logger.info( + `Execute ${PACKAGE_NAME}:${EXECUTOR_ENVIRONMENT_TEARDOWN} with options: ${JSON.stringify( + options, + null, + 2 + )}` + ); + } + try { + await teardownEnvironment(context, { + environmentRoot, + verbose, + }); + } catch (error) { + logger.error(error); + return { + success: false, + command: error?.message ?? (error as Error).toString(), + }; + } + + return { + success: true, + command: 'Teared down environment successfully.', + }; +} + +export default teardownExecutor; diff --git a/projects/nx-verdaccio/src/executors/env-teardown/git.ts b/projects/nx-verdaccio/src/executors/env-teardown/git.ts new file mode 100644 index 0000000..07ab2f5 --- /dev/null +++ b/projects/nx-verdaccio/src/executors/env-teardown/git.ts @@ -0,0 +1,54 @@ +import type {SimpleGit} from "simple-git"; +import {simpleGit} from "simple-git"; +import {resolve} from "node:path"; + +export const gitClient: SimpleGit = simpleGit(); + +export async function cleanGitHistoryForFolder( + environmentRoot: string, + options?: { verbose?: boolean }, + git: SimpleGit = gitClient +): Promise { + + await git.show(['--oneline']); + +} + +export async function isFolderInRepo( + folderPath: string +): Promise { + // Initialize simple-git with the folder path + const git = simpleGit(folderPath); + + try { + // Check if the folder is a git repository + const isRepo = (await git.checkIgnore(folderPath)).length === 0 + // console.log(`${folderPath} is ${isRepo ? '' : 'not '} in Git repository.`); + return isRepo; + } catch (error) { + console.log(`${error}`); + return false; + } +} + +export async function isSubfolderInGitRepository(subFolderPath: string, baseFolderPath = process.cwd()) { + // Resolve the full path for the subfolder + const fullSubFolderPath = resolve(baseFolderPath, subFolderPath); + + // Initialize simple-git with the full subfolder path + const git = simpleGit(fullSubFolderPath); + + try { + // Check if the subfolder path is within a Git repository + const isRepo = await git.checkIsRepo(); + if (isRepo) { + console.log(`${fullSubFolderPath} is inside a Git repository.`); + } else { + console.log(`${fullSubFolderPath} is not inside a Git repository.`); + } + return isRepo; + } catch (error) { + console.log(`${fullSubFolderPath} is not inside a Git repository.`); + return false; + } +} diff --git a/projects/nx-verdaccio/src/executors/env-teardown/git.unit-test.ts b/projects/nx-verdaccio/src/executors/env-teardown/git.unit-test.ts new file mode 100644 index 0000000..70ddbcb --- /dev/null +++ b/projects/nx-verdaccio/src/executors/env-teardown/git.unit-test.ts @@ -0,0 +1,11 @@ +import {describe, expect, it, vi} from 'vitest'; +import {cleanGitHistoryForFolder} from './git'; +import {execSync} from 'node:child_process'; + +describe('cleanGitHistoryForFolder', () => { + + it('should clean up given folder', () => { + cleanGitHistoryForFolder('tmp'); + }); + +}); diff --git a/projects/nx-verdaccio/src/executors/env-teardown/schema.json b/projects/nx-verdaccio/src/executors/env-teardown/schema.json new file mode 100644 index 0000000..8ded757 --- /dev/null +++ b/projects/nx-verdaccio/src/executors/env-teardown/schema.json @@ -0,0 +1,19 @@ +{ + "$schema": "http://json-schema.org/schema", + "$id": "TeardownExecutorOptions", + "title": "Environment teardown executor options", + "type": "object", + "properties": { + "environmentRoot": { + "type": "string", + "description": "The root directory of the environment", + "aliases": ["envRoot", "e"] + }, + "verbose": { + "type": "boolean", + "description": "Print additional logs" + } + }, + "additionalProperties": true, + "required": ["environmentRoot"] +} diff --git a/projects/nx-verdaccio/src/executors/env-teardown/schema.ts b/projects/nx-verdaccio/src/executors/env-teardown/schema.ts new file mode 100644 index 0000000..bb46170 --- /dev/null +++ b/projects/nx-verdaccio/src/executors/env-teardown/schema.ts @@ -0,0 +1,5 @@ +import {Environment} from "../env-bootstrap/npm"; + +export type TeardownExecutorOptions = Partial; diff --git a/projects/nx-verdaccio/src/executors/env-teardown/teardown-env.ts b/projects/nx-verdaccio/src/executors/env-teardown/teardown-env.ts new file mode 100644 index 0000000..5667825 --- /dev/null +++ b/projects/nx-verdaccio/src/executors/env-teardown/teardown-env.ts @@ -0,0 +1,54 @@ +import {Environment} from "../env-bootstrap/npm"; +import {simpleGit, type SimpleGit} from "simple-git"; +import {isFolderInRepo} from "./git"; +import {ExecutorContext, logger} from "@nx/devkit"; +import {runSingleExecutor} from "../../internal/run-executor"; +import {join} from "node:path"; +import {VERDACCIO_REGISTRY_JSON} from "../env-bootstrap/constants"; +import {TARGET_ENVIRONMENT_VERDACCIO_STOP} from "@push-based/nx-verdaccio"; +import {fileExists} from "../../internal/file-system"; + +export const gitClient: SimpleGit = simpleGit(process.cwd()); +export type TeardownEnvironmentOptions = Environment & { verbose?: boolean }; + +export async function teardownEnvironment( + context: ExecutorContext, + options: TeardownEnvironmentOptions, + git: SimpleGit = gitClient +): Promise { + const {verbose, environmentRoot} = options; + + // kill verdaccio process if running + const registryJsonExists = await fileExists(join(environmentRoot, VERDACCIO_REGISTRY_JSON)); + if (registryJsonExists) { + await runSingleExecutor( + { + project: context.projectName, + target: TARGET_ENVIRONMENT_VERDACCIO_STOP, + }, + { + ...(verbose ? {verbose} : {}), + filePath: join(environmentRoot, VERDACCIO_REGISTRY_JSON), + }, + context + ); + } else { + logger.info(`No verdaccio-registry.json file found in ${environmentRoot}.`); + } + + // clean environmentRoot + + const environmentRootInRepo = await isFolderInRepo(environmentRoot); + if (environmentRootInRepo) { + await git.checkout([environmentRoot]); + logger.info(`Cleaned git history in ${environmentRoot}.`); + } else { + try { + + } catch (error) { + // throw new Error(`Error cleaning history of folder ${environmentRoot}. ${error.message}`); + } + } + + +} diff --git a/projects/nx-verdaccio/src/executors/env-teardown/teardown-env.unit-test.ts b/projects/nx-verdaccio/src/executors/env-teardown/teardown-env.unit-test.ts new file mode 100644 index 0000000..362ec6b --- /dev/null +++ b/projects/nx-verdaccio/src/executors/env-teardown/teardown-env.unit-test.ts @@ -0,0 +1,5 @@ +import { describe, expect, it, vi } from 'vitest'; +import { teardownEnvironment } from './bootstrap-env'; +import * as verdaccioRegistryModule from './verdaccio-registry'; +import * as npmModule from './npm'; +import * as fs from 'node:fs/promises'; diff --git a/projects/nx-verdaccio/src/executors/internal/executor-output.ts b/projects/nx-verdaccio/src/executors/internal/executor-output.ts new file mode 100644 index 0000000..fd6dca3 --- /dev/null +++ b/projects/nx-verdaccio/src/executors/internal/executor-output.ts @@ -0,0 +1,5 @@ +export type ExecutorOutput = { + success: boolean; + command?: string; + error?: Error; +}; diff --git a/projects/nx-verdaccio/src/internal/file-system.ts b/projects/nx-verdaccio/src/internal/file-system.ts index 63f3175..b6ad6b9 100644 --- a/projects/nx-verdaccio/src/internal/file-system.ts +++ b/projects/nx-verdaccio/src/internal/file-system.ts @@ -1,4 +1,4 @@ -import { mkdir } from 'node:fs/promises'; +import {mkdir, stat} from 'node:fs/promises'; export async function ensureDirectoryExists(baseDir: string) { try { @@ -11,3 +11,12 @@ export async function ensureDirectoryExists(baseDir: string) { } } } + +export async function fileExists(path: string): Promise { + try { + const stats = await stat(path); + return stats.isFile(); + } catch { + return false; + } +} From 4b206b70e554ec90f4a269cc6e6213229f5dbfb1 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 13 Oct 2024 02:59:54 +0200 Subject: [PATCH 02/21] add simple git --- package-lock.json | 198 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 199 insertions(+) diff --git a/package-lock.json b/package-lock.json index 07ce014..f169b5c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "license": "MIT", "dependencies": { "memfs": "^4.11.1", + "simplegit": "^1.0.2", "tslib": "^2.3.0", "yargs": "^17.7.2" }, @@ -7545,6 +7546,14 @@ "node": ">= 0.12.0" } }, + "node_modules/code-point-at": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz", + "integrity": "sha512-RpAVKQA5T63xEj6/giIbUEtZwJ4UFIc3ZtvEkiaUERylqe8xb5IvqcgOurZLahv93CLKfxcw5YI+DZcUBRyLXA==", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/collect-v8-coverage": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/collect-v8-coverage/-/collect-v8-coverage-1.0.2.tgz", @@ -7930,6 +7939,14 @@ } } }, + "node_modules/decamelize": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", + "integrity": "sha512-z2S+W9X73hAUUki+N+9Za2lBlun89zigOyGrsax+KUQ6wKW4ZoWpEYBkGhQjwAjjDCkWxhY0VKEhk8wzY7F5cA==", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/decimal.js": { "version": "10.4.3", "resolved": "https://registry.npmjs.org/decimal.js/-/decimal.js-10.4.3.tgz", @@ -10197,6 +10214,19 @@ "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", "dev": true }, + "node_modules/ini": { + "version": "1.3.8", + "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.8.tgz", + "integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==" + }, + "node_modules/invert-kv": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/invert-kv/-/invert-kv-1.0.0.tgz", + "integrity": "sha512-xgs2NH9AE66ucSq4cNG1nhSFghr5l6tdL15Pk+jl46bmmBapgoaY/AacXyaDznAqmGL99TiLSQgO/XazFSKYeQ==", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/ipaddr.js": { "version": "1.9.1", "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", @@ -11537,6 +11567,17 @@ "node": ">=6" } }, + "node_modules/lcid": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/lcid/-/lcid-1.0.0.tgz", + "integrity": "sha512-YiGkH6EnGrDGqLMITnGjXtGmNtjoXw9SVUzcaos8RBi7Ps0VBylkq+vOcY9QE5poLasPCR849ucFUkl0UzUyOw==", + "dependencies": { + "invert-kv": "^1.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/leven": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/leven/-/leven-3.1.0.tgz", @@ -12254,6 +12295,117 @@ "integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==", "dev": true }, + "node_modules/nconf": { + "version": "0.8.5", + "resolved": "https://registry.npmjs.org/nconf/-/nconf-0.8.5.tgz", + "integrity": "sha512-YXTpOk2LI4QD2vAr4v40+nELcEbUA5BkIoeIz4Orfx9XA0Gxkkf70+KOvIVNDP2YQBz5XWg7l1zgiPvWb0zTPw==", + "dependencies": { + "async": "^1.4.0", + "ini": "^1.3.0", + "secure-keys": "^1.0.0", + "yargs": "^3.19.0" + }, + "engines": { + "node": ">= 0.4.0" + } + }, + "node_modules/nconf/node_modules/ansi-regex": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", + "integrity": "sha512-TIGnTpdo+E3+pCyAluZvtED5p5wCqLdezCyhPZzKPcxvFplEt4i+W7OONCKgeZFT3+y5NZZfOOS/Bdcanm1MYA==", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/nconf/node_modules/async": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/async/-/async-1.5.2.tgz", + "integrity": "sha512-nSVgobk4rv61R9PUSDtYt7mPVB2olxNR5RWJcAsH676/ef11bUZwvu7+RGYrYauVdDPcO519v68wRhXQtxsV9w==" + }, + "node_modules/nconf/node_modules/camelcase": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-2.1.1.tgz", + "integrity": "sha512-DLIsRzJVBQu72meAKPkWQOLcujdXT32hwdfnkI1frSiSRMK1MofjKHf+MEx0SB6fjEFXL8fBDv1dKymBlOp4Qw==", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/nconf/node_modules/cliui": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-3.2.0.tgz", + "integrity": "sha512-0yayqDxWQbqk3ojkYqUKqaAQ6AfNKeKWRNA8kR0WXzAsdHpP4BIaOmMAG87JGuO6qcobyW4GjxHd9PmhEd+T9w==", + "dependencies": { + "string-width": "^1.0.1", + "strip-ansi": "^3.0.1", + "wrap-ansi": "^2.0.0" + } + }, + "node_modules/nconf/node_modules/is-fullwidth-code-point": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", + "integrity": "sha512-1pqUqRjkhPJ9miNq9SwMfdvi6lBJcd6eFxvfaivQhaH3SgisfiuudvFntdKOmxuee/77l+FPjKrQjWvmPjWrRw==", + "dependencies": { + "number-is-nan": "^1.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/nconf/node_modules/string-width": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", + "integrity": "sha512-0XsVpQLnVCXHJfyEs8tC0zpTVIr5PKKsQtkT29IwupnPTjtPmQ3xT/4yCREF9hYkV/3M3kzcUTSAZT6a6h81tw==", + "dependencies": { + "code-point-at": "^1.0.0", + "is-fullwidth-code-point": "^1.0.0", + "strip-ansi": "^3.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/nconf/node_modules/strip-ansi": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", + "integrity": "sha512-VhumSSbBqDTP8p2ZLKj40UjBCV4+v8bUSEpUb4KjRgWk9pbqGF4REFj6KEagidb2f/M6AzC0EmFyDNGaw9OCzg==", + "dependencies": { + "ansi-regex": "^2.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/nconf/node_modules/wrap-ansi": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-2.1.0.tgz", + "integrity": "sha512-vAaEaDM946gbNpH5pLVNR+vX2ht6n0Bt3GXwVB1AuAqZosOvHNF3P7wDnh8KLkSqgUh0uh77le7Owgoz+Z9XBw==", + "dependencies": { + "string-width": "^1.0.1", + "strip-ansi": "^3.0.1" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/nconf/node_modules/y18n": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-3.2.2.tgz", + "integrity": "sha512-uGZHXkHnhF0XeeAPgnKfPv1bgKAYyVvmNL1xlKsPYZPaIHxGti2hHqvOCQv71XMsLxu1QjergkqogUnms5D3YQ==" + }, + "node_modules/nconf/node_modules/yargs": { + "version": "3.32.0", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-3.32.0.tgz", + "integrity": "sha512-ONJZiimStfZzhKamYvR/xvmgW3uEkAUFSP91y2caTEPhzF6uP2JfPiVZcq66b/YR0C3uitxSV7+T1x8p5bkmMg==", + "dependencies": { + "camelcase": "^2.0.1", + "cliui": "^3.0.3", + "decamelize": "^1.1.1", + "os-locale": "^1.4.0", + "string-width": "^1.0.1", + "window-size": "^0.1.4", + "y18n": "^3.2.0" + } + }, "node_modules/ncp": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ncp/-/ncp-2.0.0.tgz", @@ -12386,6 +12538,14 @@ "node": ">=8" } }, + "node_modules/number-is-nan": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", + "integrity": "sha512-4jbtZXNAsfZbAHiiqjLPBiCl16dES1zI4Hpzzxw61Tk+loF+sBDBKx1ICKKKwIqQ7M0mFn1TmkN7euSncWgHiQ==", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/nwsapi": { "version": "2.2.12", "resolved": "https://registry.npmjs.org/nwsapi/-/nwsapi-2.2.12.tgz", @@ -12767,6 +12927,17 @@ "node": ">=4" } }, + "node_modules/os-locale": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/os-locale/-/os-locale-1.4.0.tgz", + "integrity": "sha512-PRT7ZORmwu2MEFt4/fv3Q+mEfN4zetKxufQrkShY2oGvUms9r8otu5HfdyIFHkYXjO7laNsoVGmM2MANfuTA8g==", + "dependencies": { + "lcid": "^1.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/p-cancelable": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-2.1.1.tgz", @@ -13883,6 +14054,11 @@ "integrity": "sha512-AckIIV90rPDcBcglUwXPF3kg0P0qmPsPXAj6BBEENQE1p5yA1xfmDJzfi1Tappj37Pv2mVbKpL3Z1T+Nn7k1Qw==", "dev": true }, + "node_modules/secure-keys": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/secure-keys/-/secure-keys-1.0.0.tgz", + "integrity": "sha512-nZi59hW3Sl5P3+wOO89eHBAAGwmCPd2aE1+dLZV5MO+ItQctIvAqihzaAXIQhvtH4KJPxM080HsnqltR2y8cWg==" + }, "node_modules/semver": { "version": "7.6.3", "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", @@ -14074,6 +14250,17 @@ "url": "https://github.com/steveukx/git-js?sponsor=1" } }, + "node_modules/simplegit": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/simplegit/-/simplegit-1.0.2.tgz", + "integrity": "sha512-jEQKokh61NP+oqj7oFpXtd29zOSO8rR1X1Rs11tNtBLxLhrR976zBnRmzR6zZes7MkqhVUtS1QnyiuBxGDLDrg==", + "dependencies": { + "nconf": "^0.8.4" + }, + "bin": { + "sgit": "index.js" + } + }, "node_modules/sirv": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/sirv/-/sirv-2.0.4.tgz", @@ -16353,6 +16540,17 @@ "node": ">=8" } }, + "node_modules/window-size": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/window-size/-/window-size-0.1.4.tgz", + "integrity": "sha512-2thx4pB0cV3h+Bw7QmMXcEbdmOzv9t0HFplJH/Lz6yu60hXYy5RT8rUu+wlIreVxWsGN20mo+MHeCSfUpQBwPw==", + "bin": { + "window-size": "cli.js" + }, + "engines": { + "node": ">= 0.10.0" + } + }, "node_modules/word-wrap": { "version": "1.2.5", "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz", diff --git a/package.json b/package.json index c329ddd..61677fc 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "private": true, "dependencies": { "memfs": "^4.11.1", + "simplegit": "^1.0.2", "tslib": "^2.3.0", "yargs": "^17.7.2" }, From f25a385835953d72e23661d9c2b5c95a4e4b2016 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 13 Oct 2024 03:01:07 +0200 Subject: [PATCH 03/21] edit executor json --- projects/nx-verdaccio/executors.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/projects/nx-verdaccio/executors.json b/projects/nx-verdaccio/executors.json index e21f0bd..5f45df7 100644 --- a/projects/nx-verdaccio/executors.json +++ b/projects/nx-verdaccio/executors.json @@ -10,6 +10,11 @@ "schema": "./src/executors/env-setup/schema.json", "description": "Generate and install test environments in your workspace. Cached and ready for use." }, + "env-teardown": { + "implementation": "./src/executors/env-teardown/executor", + "schema": "./src/executors/env-teardown/schema.json", + "description": "Teardown test environments in your workspace." + }, "pkg-publish": { "implementation": "./src/executors/pkg-publish/executor", "schema": "./src/executors/pkg-publish/schema.json", From bb3b54d0cf1a8e10b7a233f9d4602601a2afe79f Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 13 Oct 2024 06:24:34 +0200 Subject: [PATCH 04/21] wip --- examples/e2e/models-e2e/project.json | 4 ++ .../executors/env-teardown/teardown-env.ts | 33 +++++----- tooling/bin/nx-show-project.ts | 63 +++++++++++++++++++ tooling/bin/tsconfig.bin.json | 21 +++++++ tooling/bin/tsconfig.json | 18 ++++++ 5 files changed, 120 insertions(+), 19 deletions(-) create mode 100644 tooling/bin/nx-show-project.ts create mode 100644 tooling/bin/tsconfig.bin.json create mode 100644 tooling/bin/tsconfig.json diff --git a/examples/e2e/models-e2e/project.json b/examples/e2e/models-e2e/project.json index 5522968..119eae4 100644 --- a/examples/e2e/models-e2e/project.json +++ b/examples/e2e/models-e2e/project.json @@ -10,6 +10,10 @@ "teardown": { "executor": "@push-based/nx-verdaccio:env-teardown" }, + "nxv-e2e": { + "dependsOn": ["e2e"], + "executor": "@push-based/nx-verdaccio:env-teardown" + }, "e2e": { "executor": "@nx/vite:test", "inputs": ["default", "^production"], 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 5667825..8e0ab2d 100644 --- a/projects/nx-verdaccio/src/executors/env-teardown/teardown-env.ts +++ b/projects/nx-verdaccio/src/executors/env-teardown/teardown-env.ts @@ -2,11 +2,11 @@ import {Environment} from "../env-bootstrap/npm"; import {simpleGit, type SimpleGit} from "simple-git"; import {isFolderInRepo} from "./git"; import {ExecutorContext, logger} from "@nx/devkit"; -import {runSingleExecutor} from "../../internal/run-executor"; import {join} from "node:path"; import {VERDACCIO_REGISTRY_JSON} from "../env-bootstrap/constants"; -import {TARGET_ENVIRONMENT_VERDACCIO_STOP} from "@push-based/nx-verdaccio"; import {fileExists} from "../../internal/file-system"; +import {rm} from "node:fs/promises"; +import runKillProcessExecutor from "../kill-process/executor"; export const gitClient: SimpleGit = simpleGit(process.cwd()); export type TeardownEnvironmentOptions = Environment & { verbose?: boolean }; @@ -16,37 +16,32 @@ export async function teardownEnvironment( options: TeardownEnvironmentOptions, git: SimpleGit = gitClient ): Promise { - const {verbose, environmentRoot} = options; + const { environmentRoot} = options; // kill verdaccio process if running - const registryJsonExists = await fileExists(join(environmentRoot, VERDACCIO_REGISTRY_JSON)); + const registryPath = join(environmentRoot, VERDACCIO_REGISTRY_JSON); + const registryJsonExists = await fileExists(registryPath); if (registryJsonExists) { - await runSingleExecutor( - { - project: context.projectName, - target: TARGET_ENVIRONMENT_VERDACCIO_STOP, - }, - { - ...(verbose ? {verbose} : {}), - filePath: join(environmentRoot, VERDACCIO_REGISTRY_JSON), - }, - context - ); + await runKillProcessExecutor({...options, filePath: registryPath}); } else { logger.info(`No verdaccio-registry.json file found in ${environmentRoot}.`); } // clean environmentRoot - const environmentRootInRepo = await isFolderInRepo(environmentRoot); - if (environmentRootInRepo) { + if (environmentRootInRepo && environmentRootInRepo !== '.') { await git.checkout([environmentRoot]); + await git.clean('f', [environmentRoot]); logger.info(`Cleaned git history in ${environmentRoot}.`); } else { try { - + const registryFiles = [ + join(environmentRoot) + ]; + await rm(environmentRoot, {recursive: true, force: true, retryDelay: 100, maxRetries: 2}); + logger.info(`deleted folder ${environmentRoot}.`); } catch (error) { - // throw new Error(`Error cleaning history of folder ${environmentRoot}. ${error.message}`); + throw new Error(`Error cleaning history of folder ${environmentRoot}. ${error.message}`); } } diff --git a/tooling/bin/nx-show-project.ts b/tooling/bin/nx-show-project.ts new file mode 100644 index 0000000..89c586b --- /dev/null +++ b/tooling/bin/nx-show-project.ts @@ -0,0 +1,63 @@ +import { execFileSync, execSync } from 'node:child_process'; +import yargs from 'yargs'; +import { hideBin } from 'yargs/helpers'; +import { objectToCliArgs } from '../../../../packages/utils/src'; +import type { NpmCheckOptions, NpmCheckResult } from '../types'; + +const argv = yargs(hideBin(process.argv)) + .options({ + pkgRange: { type: 'string', demandOption: true }, + registry: { type: 'string' }, + }) + .coerce('pkgRange', rawVersion => { + if (rawVersion != null && rawVersion !== '') { + return rawVersion; + } else { + return undefined; + } + }) + .coerce('registry', rawRegistry => { + if (rawRegistry != null && rawRegistry !== '') { + return rawRegistry; + } else { + return undefined; + } + }).argv; + +const { pkgRange, registry = 'https://registry.npmjs.org/' } = + argv as NpmCheckOptions; + +try { + const command = 'npm'; + const args = objectToCliArgs({ + _: ['view', pkgRange], + registry, + }); + + const viewResult = execFileSync( + command, + [ + ...args, + // Hide process output via "2>/dev/null". Otherwise, it will print the error message to the terminal. + '2>/dev/null', + ], + { + shell: true, + }, + ).toString(); + + const existingPackage = viewResult + .split('\n') + .filter(Boolean) + .at(0) + ?.split(' ') + .at(0); + console.log(`${existingPackage}#FOUND` satisfies NpmCheckResult); // process output to parse + process.exit(0); +} catch (error) { + // @TODO we use '2>/dev/null' to hide errors from process output, but also can't check error message. Find better solution. + // if (error.message.includes(`npm ERR! 404 '${pkgRange}' is not in this registry`)) { + console.log(`${pkgRange}#NOT_FOUND` satisfies NpmCheckResult); // process output to parse + process.exit(0); + // } +} diff --git a/tooling/bin/tsconfig.bin.json b/tooling/bin/tsconfig.bin.json new file mode 100644 index 0000000..4e4cd0e --- /dev/null +++ b/tooling/bin/tsconfig.bin.json @@ -0,0 +1,21 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../dist/out-tsc", + "declaration": true, + "types": ["node"], + "resolveJsonModule": true + }, + "include": ["src/**/*.ts"], + "exclude": [ + "vite.config.ts", + "src/**/__snapshots__/*.ts", + "src/**/*.test.ts", + "src/**/*.unit-test.ts", + "src/**/*.integration-test.ts", + "src/**/*.spec.ts", + "src/**/*.mock.ts", + "test/**/*.ts", + "mock/**/*.ts" + ] +} diff --git a/tooling/bin/tsconfig.json b/tooling/bin/tsconfig.json new file mode 100644 index 0000000..99bc14d --- /dev/null +++ b/tooling/bin/tsconfig.json @@ -0,0 +1,18 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "module": "CommonJS", + "target": "ES2018", + "verbatimModuleSyntax": false + }, + "files": [], + "include": [], + "references": [ + { + "path": "./tsconfig.lib.json" + }, + { + "path": "./tsconfig.spec.json" + } + ] +} From d6065afcbc6fdd56ce13dd9a64e8d1c1a614839e Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 13 Oct 2024 06:25:31 +0200 Subject: [PATCH 05/21] wip --- projects/nx-verdaccio/src/executors/env-teardown/schema.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/nx-verdaccio/src/executors/env-teardown/schema.json b/projects/nx-verdaccio/src/executors/env-teardown/schema.json index 8ded757..581dd21 100644 --- a/projects/nx-verdaccio/src/executors/env-teardown/schema.json +++ b/projects/nx-verdaccio/src/executors/env-teardown/schema.json @@ -15,5 +15,5 @@ } }, "additionalProperties": true, - "required": ["environmentRoot"] + "required": [] } From e472aca55c2ac3f01963203dd2ba5fa277c1a9af Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 13 Oct 2024 07:15:59 +0200 Subject: [PATCH 06/21] wip --- examples/e2e/models-e2e/project.json | 4 ---- nx.json | 6 ++--- package.json | 6 ++++- .../src/executors/env-setup/executor.ts | 16 ++++++++----- .../executors/env-teardown/teardown-env.ts | 23 ++++++++++++------- .../src/plugin/targets/environment.targets.ts | 8 ++++++- 6 files changed, 40 insertions(+), 23 deletions(-) diff --git a/examples/e2e/models-e2e/project.json b/examples/e2e/models-e2e/project.json index 119eae4..5522968 100644 --- a/examples/e2e/models-e2e/project.json +++ b/examples/e2e/models-e2e/project.json @@ -10,10 +10,6 @@ "teardown": { "executor": "@push-based/nx-verdaccio:env-teardown" }, - "nxv-e2e": { - "dependsOn": ["e2e"], - "executor": "@push-based/nx-verdaccio:env-teardown" - }, "e2e": { "executor": "@nx/vite:test", "inputs": ["default", "^production"], diff --git a/nx.json b/nx.json index 8503016..75f9e01 100644 --- a/nx.json +++ b/nx.json @@ -73,9 +73,6 @@ } }, "plugins": [ - { - "plugin": "./examples/e2e/cli-e2e-original/tooling/original.plugin.ts" - }, { "plugin": "@push-based/nx-verdaccio", "options": { @@ -88,6 +85,9 @@ }, "exclude": ["./examples/e2e/cli-e2e-original"] }, + { + "plugin": "./examples/e2e/cli-e2e-original/tooling/original.plugin.ts" + }, { "plugin": "@nx/eslint/plugin", "options": { diff --git a/package.json b/package.json index 61677fc..0fb0035 100644 --- a/package.json +++ b/package.json @@ -69,5 +69,9 @@ "verdaccio", "performance" ], - "author": "Michael Hladky" + "author": "Michael Hladky", + "directories": { + "doc": "docs", + "example": "examples" + } } diff --git a/projects/nx-verdaccio/src/executors/env-setup/executor.ts b/projects/nx-verdaccio/src/executors/env-setup/executor.ts index 9b2a1aa..1072539 100644 --- a/projects/nx-verdaccio/src/executors/env-setup/executor.ts +++ b/projects/nx-verdaccio/src/executors/env-setup/executor.ts @@ -12,6 +12,7 @@ import { TARGET_ENVIRONMENT_VERDACCIO_STOP, } from '../../plugin/targets/environment.targets'; import { runSingleExecutor } from '../../internal/run-executor'; +import {rm} from "node:fs/promises"; export type ExecutorOutput = { success: boolean; @@ -23,8 +24,8 @@ export default async function runSetupEnvironmentExecutor( terminalAndExecutorOptions: SetupEnvironmentExecutorOptions, context: ExecutorContext ) { - const { configurationName: configuration, projectName } = context; - const { verbose, environmentRoot, keepServerRunning } = + const {configurationName: configuration, projectName} = context; + const {verbose, environmentRoot, keepServerRunning} = terminalAndExecutorOptions; try { await runSingleExecutor( @@ -55,10 +56,10 @@ export default async function runSetupEnvironmentExecutor( args: objectToCliArgs({ _: [TARGET_ENVIRONMENT_INSTALL, projectName], environmentRoot, - ...(verbose ? { verbose } : {}), + ...(verbose ? {verbose} : {}), }), cwd: process.cwd(), - ...(verbose ? { verbose } : {}), + ...(verbose ? {verbose} : {}), }); } catch (error) { logger.error(error.message); @@ -77,13 +78,16 @@ export default async function runSetupEnvironmentExecutor( configuration, }, { - ...(verbose ? { verbose } : {}), + ...(verbose ? {verbose} : {}), filePath: join(environmentRoot, VERDACCIO_REGISTRY_JSON), }, context ); + // delete storage, npmrc + await rm(join(environmentRoot, 'storage'), {recursive: true, force: true, retryDelay: 100, maxRetries: 2}); + await rm(join(environmentRoot, '.npmrc'), {recursive: true, force: true, retryDelay: 100, maxRetries: 2}); } else { - const { url } = readJsonFile( + const {url} = readJsonFile( join(environmentRoot, VERDACCIO_REGISTRY_JSON) ); logger.info(`Verdaccio server kept running under : ${url}`); 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 8e0ab2d..9643369 100644 --- a/projects/nx-verdaccio/src/executors/env-teardown/teardown-env.ts +++ b/projects/nx-verdaccio/src/executors/env-teardown/teardown-env.ts @@ -7,6 +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"; export const gitClient: SimpleGit = simpleGit(process.cwd()); export type TeardownEnvironmentOptions = Environment & { verbose?: boolean }; @@ -16,7 +17,10 @@ export async function teardownEnvironment( options: TeardownEnvironmentOptions, git: SimpleGit = gitClient ): Promise { - const { environmentRoot} = options; + const {environmentRoot: optEnvPath} = options; + const environmentRoot = optEnvPath ?? context.nxJsonConfiguration.plugins.find(pCfg => { + return typeof pCfg === 'object' && pCfg?.plugin === '@push-based/nx-verdaccio'; + }) ?.options.environments.environmentsDir ?? DEFAULT_ENVIRONMENTS_OUTPUT_DIR; // kill verdaccio process if running const registryPath = join(environmentRoot, VERDACCIO_REGISTRY_JSON); @@ -24,15 +28,20 @@ export async function teardownEnvironment( if (registryJsonExists) { await runKillProcessExecutor({...options, filePath: registryPath}); } else { - logger.info(`No verdaccio-registry.json file found in ${environmentRoot}.`); + logger.info(`No verdaccio-registry.json file found in ${environmentRoot}`); + } + + if(environmentRoot === '.') { + logger.info(`Skip teardown environment in root folder`); + return; } // clean environmentRoot const environmentRootInRepo = await isFolderInRepo(environmentRoot); - if (environmentRootInRepo && environmentRootInRepo !== '.') { - await git.checkout([environmentRoot]); - await git.clean('f', [environmentRoot]); - logger.info(`Cleaned git history in ${environmentRoot}.`); + if (environmentRootInRepo) { + // await git.checkout([environmentRoot]); + // await git.clean('f', [environmentRoot]); + logger.info(`Cleaned git history in ${environmentRoot}`); } else { try { const registryFiles = [ @@ -44,6 +53,4 @@ export async function teardownEnvironment( throw new Error(`Error cleaning history of folder ${environmentRoot}. ${error.message}`); } } - - } diff --git a/projects/nx-verdaccio/src/plugin/targets/environment.targets.ts b/projects/nx-verdaccio/src/plugin/targets/environment.targets.ts index 6c6d542..3cdfb78 100644 --- a/projects/nx-verdaccio/src/plugin/targets/environment.targets.ts +++ b/projects/nx-verdaccio/src/plugin/targets/environment.targets.ts @@ -13,10 +13,12 @@ import { PACKAGE_NAME } from '../constants'; import { EXECUTOR_ENVIRONMENT_KILL_PROCESS } from '../../executors/kill-process/constant'; import { EXECUTOR_ENVIRONMENT_SETUP } from '../../executors/env-setup/constants'; import { iterateEntries } from '../../internal/transform'; +import {EXECUTOR_ENVIRONMENT_TEARDOWN} from "../../executors/env-teardown/constants"; export const TARGET_ENVIRONMENT_BOOTSTRAP = 'nxv-env-bootstrap'; export const TARGET_ENVIRONMENT_INSTALL = 'nxv-env-install'; export const TARGET_ENVIRONMENT_SETUP = 'nxv-env-setup'; +export const TARGET_ENVIRONMENT_E2E = 'nxv-e2e'; export const TARGET_ENVIRONMENT_VERDACCIO_START = 'nxv-verdaccio-start'; export const TARGET_ENVIRONMENT_VERDACCIO_STOP = 'nxv-verdaccio-stop'; @@ -93,7 +95,7 @@ export function getEnvTargets( options: NormalizedCreateNodeOptions['environments'] ): Record { const { name: envProject } = projectConfig; - const { environmentsDir } = options; + const { environmentsDir, targetNames } = options; const environmentRoot = join(environmentsDir, envProject); return { [TARGET_ENVIRONMENT_BOOTSTRAP]: { @@ -125,6 +127,10 @@ export function getEnvTargets( environmentRoot, }, }, + [TARGET_ENVIRONMENT_E2E]: { + dependsOn: targetNames, + executor: `${PACKAGE_NAME}:${EXECUTOR_ENVIRONMENT_TEARDOWN}` + }, }; } From 90626821961200b210dab111f666799fbb9b9f96 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 13 Oct 2024 08:52:20 +0200 Subject: [PATCH 07/21] wip --- code-pushup.config.ts | 25 ++++++------- examples/e2e/cli-static-e2e/project.json | 3 +- examples/e2e/models-e2e/project.json | 3 -- project.json | 6 +++ .../src/executors/env-teardown/git.ts | 8 ++-- .../executors/env-teardown/teardown-env.ts | 10 ++--- .../src/plugin/targets/environment.targets.ts | 4 ++ static-environments/user-lists/package.json | 14 ++++++- ...ache-size.audit.ts => task-cache.audit.ts} | 0 .../nx-performance/audit/task-graph.audit.ts | 26 +++++++------ ...oject-task.audit.ts => task-time.audit.ts} | 31 ++++++++++------ tooling/measures/nx-performance/index.ts | 6 +++ .../nx-performance/nx-performance.plugin.ts | 37 ++++++++++--------- 13 files changed, 103 insertions(+), 70 deletions(-) rename tooling/measures/nx-performance/audit/{cache-size.audit.ts => task-cache.audit.ts} (100%) rename tooling/measures/nx-performance/audit/{project-task.audit.ts => task-time.audit.ts} (82%) diff --git a/code-pushup.config.ts b/code-pushup.config.ts index 1038a48..012e26d 100644 --- a/code-pushup.config.ts +++ b/code-pushup.config.ts @@ -1,25 +1,24 @@ -import { CoreConfig } from '@code-pushup/models'; +import {CoreConfig} from '@code-pushup/models'; import nxPerformancePlugin, { nxPerformanceCategoryRefs, type OnlyAudit, } from './tooling/measures/nx-performance/nx-performance.plugin'; +import {TaskTimeAuditOption} from "./tooling/measures/nx-performance"; const onlyAudits: OnlyAudit[] = [ - 'graph-time-project', - 'graph-time-task', - 'cache-size', + // 'graph-time-project', + // 'graph-time-task', + // 'cache-size', 'task-time', ]; const taskGraphTasks = ['cli-e2e:nxv-env-install']; -const taskTimeTasks = [ - 'cli-e2e:e2e', - 'cli-e2e:nxv-env-setup', - 'cli:unit-test', - 'cli:build', - 'core-e2e:e2e', - 'utils-e2e:e2e', - 'models-e2e:e2e', - 'cli-e2e-original:original-e2e', +const taskTimeTasks: TaskTimeAuditOption[] = [ + // {task: 'models-e2e:nxv-env-teardown'}, + {task: 'models-e2e:nxv-env-bootstrap'}, + {task: 'models-e2e:nxv-env-setup'}, + {task: 'models-e2e:e2e'}, + {task: 'models-e2e:nxv-e2e'}, + // 'cli-e2e-original:original-e2e', ]; const cacheSizeTasks = [ 'models-e2e:nxv-env-setup', diff --git a/examples/e2e/cli-static-e2e/project.json b/examples/e2e/cli-static-e2e/project.json index b09f738..bcd2e04 100644 --- a/examples/e2e/cli-static-e2e/project.json +++ b/examples/e2e/cli-static-e2e/project.json @@ -7,12 +7,11 @@ "implicitDependencies": ["cli"], "targets": { "lint": {}, - "e2e-static": { + "e2e": { "executor": "@nx/vite:test", "inputs": ["default", "^production"], "outputs": ["{options.reportsDirectory}"], "options": { - "environmentRoot": "static-environments/user-lists", "reportsDirectory": "../../../coverage/projects/cli-static-e2e" } } diff --git a/examples/e2e/models-e2e/project.json b/examples/e2e/models-e2e/project.json index 5522968..276f31c 100644 --- a/examples/e2e/models-e2e/project.json +++ b/examples/e2e/models-e2e/project.json @@ -7,9 +7,6 @@ "implicitDependencies": ["models"], "targets": { "lint": {}, - "teardown": { - "executor": "@push-based/nx-verdaccio:env-teardown" - }, "e2e": { "executor": "@nx/vite:test", "inputs": ["default", "^production"], diff --git a/project.json b/project.json index 89c3216..9d2d98e 100644 --- a/project.json +++ b/project.json @@ -4,6 +4,12 @@ "includedScripts": [], "// targets": "to see all targets run: nx show project workspace-source --web", "targets": { + "show-project": { + "executor": "nx:run-commands", + "options": { + "command": "tsx --tsconfig=./tooling/bin/tsconfig.bin.json ./tooling/bin/nx-show-project.ts" + } + }, "code-pushup": { "executor": "nx:run-commands", "options": { diff --git a/projects/nx-verdaccio/src/executors/env-teardown/git.ts b/projects/nx-verdaccio/src/executors/env-teardown/git.ts index 07ab2f5..defd6b2 100644 --- a/projects/nx-verdaccio/src/executors/env-teardown/git.ts +++ b/projects/nx-verdaccio/src/executors/env-teardown/git.ts @@ -17,15 +17,17 @@ export async function cleanGitHistoryForFolder( export async function isFolderInRepo( folderPath: string ): Promise { - // Initialize simple-git with the folder path - const git = simpleGit(folderPath); - try { + // Initialize simple-git with the folder path + const git = simpleGit(folderPath); // Check if the folder is a git repository const isRepo = (await git.checkIgnore(folderPath)).length === 0 // console.log(`${folderPath} is ${isRepo ? '' : 'not '} in Git repository.`); return isRepo; } catch (error) { + if((error as Error).message.includes("Cannot use simple-git on a directory that does not exist")) { + return true; + } console.log(`${error}`); return false; } 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 9643369..964d058 100644 --- a/projects/nx-verdaccio/src/executors/env-teardown/teardown-env.ts +++ b/projects/nx-verdaccio/src/executors/env-teardown/teardown-env.ts @@ -17,11 +17,11 @@ export async function teardownEnvironment( options: TeardownEnvironmentOptions, git: SimpleGit = gitClient ): Promise { - const {environmentRoot: optEnvPath} = options; - const environmentRoot = optEnvPath ?? context.nxJsonConfiguration.plugins.find(pCfg => { + const {environmentRoot: optEnvironmentRoot} = options; + const environmentsDir = context.nxJsonConfiguration.plugins.find(pCfg => { return typeof pCfg === 'object' && pCfg?.plugin === '@push-based/nx-verdaccio'; - }) ?.options.environments.environmentsDir ?? DEFAULT_ENVIRONMENTS_OUTPUT_DIR; - + })?.options?.environments?.environmentsDir ?? DEFAULT_ENVIRONMENTS_OUTPUT_DIR; + const environmentRoot = optEnvironmentRoot ?? join(environmentsDir, context.projectName); // kill verdaccio process if running const registryPath = join(environmentRoot, VERDACCIO_REGISTRY_JSON); const registryJsonExists = await fileExists(registryPath); @@ -31,7 +31,7 @@ export async function teardownEnvironment( logger.info(`No verdaccio-registry.json file found in ${environmentRoot}`); } - if(environmentRoot === '.') { + if (environmentRoot === '.') { logger.info(`Skip teardown environment in root folder`); return; } diff --git a/projects/nx-verdaccio/src/plugin/targets/environment.targets.ts b/projects/nx-verdaccio/src/plugin/targets/environment.targets.ts index 3cdfb78..505328f 100644 --- a/projects/nx-verdaccio/src/plugin/targets/environment.targets.ts +++ b/projects/nx-verdaccio/src/plugin/targets/environment.targets.ts @@ -18,6 +18,7 @@ import {EXECUTOR_ENVIRONMENT_TEARDOWN} from "../../executors/env-teardown/consta export const TARGET_ENVIRONMENT_BOOTSTRAP = 'nxv-env-bootstrap'; export const TARGET_ENVIRONMENT_INSTALL = 'nxv-env-install'; export const TARGET_ENVIRONMENT_SETUP = 'nxv-env-setup'; +export const TARGET_ENVIRONMENT_TEARDOWN = 'nxv-env-teardown'; export const TARGET_ENVIRONMENT_E2E = 'nxv-e2e'; export const TARGET_ENVIRONMENT_VERDACCIO_START = 'nxv-verdaccio-start'; export const TARGET_ENVIRONMENT_VERDACCIO_STOP = 'nxv-verdaccio-stop'; @@ -127,6 +128,9 @@ export function getEnvTargets( environmentRoot, }, }, + [TARGET_ENVIRONMENT_TEARDOWN]: { + executor: `${PACKAGE_NAME}:${EXECUTOR_ENVIRONMENT_TEARDOWN}`, + }, [TARGET_ENVIRONMENT_E2E]: { dependsOn: targetNames, executor: `${PACKAGE_NAME}:${EXECUTOR_ENVIRONMENT_TEARDOWN}` diff --git a/static-environments/user-lists/package.json b/static-environments/user-lists/package.json index 38d18e4..52d530d 100644 --- a/static-environments/user-lists/package.json +++ b/static-environments/user-lists/package.json @@ -2,6 +2,16 @@ "name": "user-lists", "private": true, "scripts": {}, - "dependencies": {}, - "devDependencies": {} + "version": "1.0.0", + "main": "index.js", + "keywords": [], + "author": "", + "license": "ISC", + "description": "", + "dependencies": { + "@push-based/cli": "^0.0.1-e2e", + "@push-based/core": "^0.0.1-e2e", + "@push-based/models": "^0.0.1-e2e", + "@push-based/utils": "^0.0.1-e2e" + } } diff --git a/tooling/measures/nx-performance/audit/cache-size.audit.ts b/tooling/measures/nx-performance/audit/task-cache.audit.ts similarity index 100% rename from tooling/measures/nx-performance/audit/cache-size.audit.ts rename to tooling/measures/nx-performance/audit/task-cache.audit.ts diff --git a/tooling/measures/nx-performance/audit/task-graph.audit.ts b/tooling/measures/nx-performance/audit/task-graph.audit.ts index 9242500..1478d07 100644 --- a/tooling/measures/nx-performance/audit/task-graph.audit.ts +++ b/tooling/measures/nx-performance/audit/task-graph.audit.ts @@ -1,6 +1,6 @@ -import { Audit, AuditOutputs } from '@code-pushup/models'; -import { execFile } from 'node:child_process'; -import { slugify } from '@code-pushup/utils'; +import {Audit, AuditOutputs} from '@code-pushup/models'; +import {execFile} from 'node:child_process'; +import {slugify} from '@code-pushup/utils'; export const DEFAULT_MAX_TASK_GRAPH_TIME = 300; export const TASK_GRAPH_TIME_AUDIT_POSTFIX = 'graph-time-task'; @@ -9,12 +9,14 @@ export function getTaskGraphTimeAuditSlug(task: string): string { return `${slugify(task)}-${TASK_GRAPH_TIME_AUDIT_POSTFIX}`; } -export const getTaskGraphTimeAudits = (tasks: string[]): Audit[] => { - return tasks.map((task) => ({ - slug: getTaskGraphTimeAuditSlug(task), // Unique slug for each task - title: '[Graph Time] task graph', - description: 'An audit to check performance of the Nx task graph', - })); +export const getTaskGraphTimeAudits = (tasks: (string)[]): Audit[] => { + return tasks.map((task) => { + return ({ + slug: getTaskGraphTimeAuditSlug(task), // Unique slug for each task + title: '[Graph Time] task graph', + description: 'An audit to check performance of the Nx task graph', + }) + }); }; export type TaskGraphAuditOptions = { @@ -25,11 +27,11 @@ export type TaskGraphAuditOptions = { export async function taskGraphAudits( options?: TaskGraphAuditOptions ): Promise { - const { maxTaskGraphTime = DEFAULT_MAX_TASK_GRAPH_TIME, taskGraphTasks } = - options ?? {}; + const {maxTaskGraphTime = DEFAULT_MAX_TASK_GRAPH_TIME, taskGraphTasks} = + options ?? {}; const results = await taskGraphTiming(taskGraphTasks); - return results.map(({ duration, task }) => ({ + return results.map(({duration, task}) => ({ slug: getTaskGraphTimeAuditSlug(task), score: scoreTaskGraphDuration(duration, maxTaskGraphTime), value: duration, diff --git a/tooling/measures/nx-performance/audit/project-task.audit.ts b/tooling/measures/nx-performance/audit/task-time.audit.ts similarity index 82% rename from tooling/measures/nx-performance/audit/project-task.audit.ts rename to tooling/measures/nx-performance/audit/task-time.audit.ts index 2160bf5..84b07b9 100644 --- a/tooling/measures/nx-performance/audit/project-task.audit.ts +++ b/tooling/measures/nx-performance/audit/task-time.audit.ts @@ -16,27 +16,34 @@ export function getTaskTimeAuditSlug(task: string): string { return `nx-${slugify(task)}-${TASK_TIME_AUDIT_POSTFIX}`; } -export const getTaskTimeAudits = (tasks: string[]): Audit[] => { - return tasks.map((task) => ({ - slug: getTaskTimeAuditSlug(task), // Unique slug for each task - title: `[Task Time] ${task}`, - description: 'An audit to check performance of the Nx task.', - })); +export type TaskTimeAuditOption = { + task: string; + cleanup?: () => void | Promise; +} + +export const getTaskTimeAudits = (tasks: TaskTimeAuditOption[]): Audit[] => { + return tasks.map(({task}) => { + return ({ + slug: getTaskTimeAuditSlug(task), // Unique slug for each task + title: `[Task Time] ${task}`, + description: 'An audit to check performance of the Nx task.', + }) + }); }; -export type ProjectTaskAuditOptions = { - taskTimeTasks: string[]; +export type TaskTimeAuditOptions = { + taskTimeTasks: TaskTimeAuditOption[]; maxTaskTime?: number; }; export async function taskTimeAudits( - options?: ProjectTaskAuditOptions + options?: TaskTimeAuditOptions ): Promise { const { taskTimeTasks = [], maxTaskTime = DEFAULT_MAX_PROJECT_TARGET_TIME } = options ?? {}; // Get the timings for each task - const timings = await projectTaskCacheSizeData(taskTimeTasks); + const timings = await taskTimeData(taskTimeTasks); // Return an array of audits, one per task return timings.map(({ task, taskTime, data, issues }) => ({ @@ -72,12 +79,12 @@ export type TaskTimeResult = { issues?: Issue[]; }; -export async function projectTaskCacheSizeData( +export async function taskTimeData( tasks: T[] ): Promise { const results: TaskTimeResult[] = []; - for (const task of tasks) { + for (const {task} of tasks) { const dist = join(DEFAULT_PLUGIN_OUTPUT, 'task-time'); await executeProcess({ command: `NX_DAEMON=false NX_PROFILE=${dist}/${slugify( diff --git a/tooling/measures/nx-performance/index.ts b/tooling/measures/nx-performance/index.ts index 4f2cbea..ffe8c9a 100644 --- a/tooling/measures/nx-performance/index.ts +++ b/tooling/measures/nx-performance/index.ts @@ -1,3 +1,9 @@ +export { + type TaskTimeAuditOption, +} from './audit/task-time.audit'; +export { + type TaskGraphAuditOptions, +} from './audit/task-graph.audit'; export { type OnlyAudit, nxPerformanceAudits, diff --git a/tooling/measures/nx-performance/nx-performance.plugin.ts b/tooling/measures/nx-performance/nx-performance.plugin.ts index 100ac4f..9bbb6e9 100644 --- a/tooling/measures/nx-performance/nx-performance.plugin.ts +++ b/tooling/measures/nx-performance/nx-performance.plugin.ts @@ -4,7 +4,7 @@ import { CategoryRef, PluginConfig, } from '@code-pushup/models'; -import { PLUGIN_SLUG } from './constant'; +import {PLUGIN_SLUG} from './constant'; import { PROJECT_GRAPH_PERFORMANCE_AUDIT, PROJECT_GRAPH_PERFORMANCE_AUDIT_SLUG, @@ -13,16 +13,16 @@ import { } from './audit/project-graph.audit'; import { getTaskTimeAudits, - ProjectTaskAuditOptions, + TaskTimeAuditOptions, TASK_TIME_AUDIT_POSTFIX, taskTimeAudits, -} from './audit/project-task.audit'; +} from './audit/task-time.audit'; import { CACHE_SIZE_AUDIT_POSTFIX, CacheSizeAuditOptions, cacheSizeAudits, getCacheSizeAudits, -} from './audit/cache-size.audit'; +} from './audit/task-cache.audit'; import { getTaskGraphTimeAudits, TASK_GRAPH_TIME_AUDIT_POSTFIX, @@ -31,10 +31,10 @@ import { } from './audit/task-graph.audit'; export const nxPerformanceAudits = ({ - taskTimeTasks, - cacheSizeTasks, - taskGraphTasks, -}: NxPerfPluginConfig) => [ + taskTimeTasks, + cacheSizeTasks, + taskGraphTasks, + }: NxPerfPluginConfig) => [ PROJECT_GRAPH_PERFORMANCE_AUDIT, ...(taskTimeTasks ? getTaskTimeAudits(taskTimeTasks) : []), ...(cacheSizeTasks ? getCacheSizeAudits(cacheSizeTasks) : []), @@ -48,7 +48,7 @@ export const nxPerformanceCategoryRefs = ( const audits = options?.onlyAudits ? filterOnlyAudits(allAudits, options.onlyAudits) : allAudits; - return audits.map(({ slug }) => ({ + return audits.map(({slug}) => ({ type: 'audit', plugin: PLUGIN_SLUG, slug, @@ -63,10 +63,11 @@ export type OnlyAudit = | typeof TASK_GRAPH_TIME_AUDIT_POSTFIX; export type NxPerfPluginConfig = { onlyAudits?: OnlyAudit[]; -} & ProjectGraphAuditOptions & - ProjectTaskAuditOptions & - CacheSizeAuditOptions & - TaskGraphAuditOptions; +} & + Partial; export function nxPerformancePlugin( options?: NxPerfPluginConfig @@ -93,7 +94,7 @@ export function filterOnlyAudits( onlyAudits: OnlyAudit[] ): Audit[] { const onlyAuditsSet = new Set(onlyAudits); - return audits.filter(({ slug }) => { + return audits.filter(({slug}) => { if ( onlyAuditsSet.has(CACHE_SIZE_AUDIT_POSTFIX) && slug.endsWith(CACHE_SIZE_AUDIT_POSTFIX) @@ -137,16 +138,16 @@ export async function runnerFunction( const onlyAuditsSet = new Set(onlyAudits); return [ ...(onlyAuditsSet.has(PROJECT_GRAPH_PERFORMANCE_AUDIT_SLUG) - ? [await projectGraphAudit({ maxProjectGraphTime })] + ? [await projectGraphAudit({maxProjectGraphTime})] : []), ...(onlyAuditsSet.has(CACHE_SIZE_AUDIT_POSTFIX) - ? await cacheSizeAudits({ maxCacheSize, cacheSizeTasks }) + ? await cacheSizeAudits({maxCacheSize, cacheSizeTasks}) : []), ...(onlyAuditsSet.has(TASK_GRAPH_TIME_AUDIT_POSTFIX) - ? await taskGraphAudits({ maxTaskGraphTime, taskGraphTasks }) + ? await taskGraphAudits({maxTaskGraphTime, taskGraphTasks}) : []), ...(onlyAuditsSet.has(TASK_TIME_AUDIT_POSTFIX) - ? await taskTimeAudits({ maxTaskTime, taskTimeTasks }) + ? await taskTimeAudits({maxTaskTime, taskTimeTasks}) : []), ]; } From 6fe6d6a5418d34645e4ac5b68224683463a99d30 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 13 Oct 2024 09:53:45 +0200 Subject: [PATCH 08/21] wip --- code-pushup.config.ts | 16 ++- e2e/nx-verdaccio-e2e/project.json | 1 + .../plugin-create-nodes.e2e.test.ts.snap | 116 ------------------ .../test/plugin-create-nodes.e2e.test.ts | 35 ++++-- .../executors/env-teardown/teardown-env.ts | 7 +- .../plugin/normalize-create-nodes-options.ts | 4 +- .../src/plugin/nx-verdaccio.plugin.ts | 4 +- projects/nx-verdaccio/src/plugin/schema.ts | 2 +- .../src/plugin/targets/create-targets.ts | 4 +- 9 files changed, 43 insertions(+), 146 deletions(-) delete mode 100644 e2e/nx-verdaccio-e2e/test/__snapshots__/plugin-create-nodes.e2e.test.ts.snap diff --git a/code-pushup.config.ts b/code-pushup.config.ts index 012e26d..d79ff2f 100644 --- a/code-pushup.config.ts +++ b/code-pushup.config.ts @@ -6,26 +6,24 @@ import nxPerformancePlugin, { import {TaskTimeAuditOption} from "./tooling/measures/nx-performance"; const onlyAudits: OnlyAudit[] = [ - // 'graph-time-project', - // 'graph-time-task', - // 'cache-size', + 'graph-time-project', + 'graph-time-task', + 'cache-size', 'task-time', ]; const taskGraphTasks = ['cli-e2e:nxv-env-install']; const taskTimeTasks: TaskTimeAuditOption[] = [ - // {task: 'models-e2e:nxv-env-teardown'}, + {task: 'models-e2e:nxv-env-teardown'}, {task: 'models-e2e:nxv-env-bootstrap'}, {task: 'models-e2e:nxv-env-setup'}, {task: 'models-e2e:e2e'}, {task: 'models-e2e:nxv-e2e'}, - // 'cli-e2e-original:original-e2e', + // {task: 'nx-verdaccio-e2e:nxv-e2e'}, + {task: 'cli-e2e-original:original-e2e'} ]; const cacheSizeTasks = [ 'models-e2e:nxv-env-setup', - 'utils-e2e:nxv-env-setup', - 'core-e2e:nxv-env-setup', - 'cli-e2e:nxv-env-setup', - 'playground-e2e:nxv-env-setup', + 'nx-verdaccio-e2e:nxv-env-setup' ]; export default { plugins: [ diff --git a/e2e/nx-verdaccio-e2e/project.json b/e2e/nx-verdaccio-e2e/project.json index fbcbc68..d3fe428 100644 --- a/e2e/nx-verdaccio-e2e/project.json +++ b/e2e/nx-verdaccio-e2e/project.json @@ -8,6 +8,7 @@ "targets": { "lint": {}, "e2e": { + "dependsOn": ["^build"], "executor": "@nx/vite:test", "inputs": ["default", "^production"], "outputs": ["{options.reportsDirectory}"], 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 deleted file mode 100644 index 8799aa0..0000000 --- a/e2e/nx-verdaccio-e2e/test/__snapshots__/plugin-create-nodes.e2e.test.ts.snap +++ /dev/null @@ -1,116 +0,0 @@ -// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html - -exports[`nx-verdaccio plugin create-nodes-v2 > should add environment targets to project with targetName e2e dynamically 1`] = ` -{ - "e2e": { - "configurations": {}, - "dependsOn": [ - { - "params": "forward", - "target": "nxv-env-setup", - }, - ], - "executor": "nx:noop", - "options": {}, - "parallelism": true, - }, - "nxv-env-bootstrap": { - "configurations": {}, - "executor": "@push-based/nx-verdaccio:env-bootstrap", - "options": { - "environmentRoot": "tmp/environments/lib-a-e2e", - }, - "parallelism": true, - }, - "nxv-env-install": { - "configurations": {}, - "dependsOn": [ - { - "params": "forward", - "projects": "dependencies", - "target": "nxv-pkg-install", - }, - ], - "executor": "nx:noop", - "options": { - "environmentRoot": "tmp/environments/lib-a-e2e", - }, - "parallelism": true, - }, - "nxv-env-setup": { - "cache": false, - "configurations": {}, - "executor": "@push-based/nx-verdaccio:env-setup", - "options": { - "environmentRoot": "tmp/environments/lib-a-e2e", - }, - "outputs": [ - "{options.environmentRoot}/node_modules", - "{options.environmentRoot}/package.json", - "{options.environmentRoot}/.npmrc", - "{options.environmentRoot}/package-lock.json", - ], - "parallelism": true, - }, - "nxv-verdaccio-start": { - "configurations": {}, - "executor": "@nx/js:verdaccio", - "options": { - "clear": true, - "config": ".verdaccio/config.yml", - "environmentDir": "tmp/environments/lib-a-e2e", - "port": Any, - "projectName": "lib-a-e2e", - "storage": "tmp/environments/lib-a-e2e/storage", - }, - "parallelism": true, - }, - "nxv-verdaccio-stop": { - "configurations": {}, - "executor": "@push-based/nx-verdaccio:kill-process", - "options": { - "filePath": "tmp/environments/verdaccio-registry.json", - }, - "parallelism": true, - }, -} -`; - -exports[`nx-verdaccio plugin create-nodes-v2 > should add package targets to library project 1`] = ` -{ - "nxv-pkg-install": { - "configurations": {}, - "dependsOn": [ - { - "params": "forward", - "target": "nxv-pkg-publish", - }, - { - "params": "forward", - "projects": "dependencies", - "target": "nxv-pkg-install", - }, - ], - "executor": "@push-based/nx-verdaccio:pkg-install", - "options": {}, - "parallelism": true, - }, - "nxv-pkg-publish": { - "configurations": {}, - "dependsOn": [ - { - "params": "forward", - "target": "build", - }, - { - "params": "forward", - "projects": "dependencies", - "target": "nxv-pkg-publish", - }, - ], - "executor": "@push-based/nx-verdaccio:pkg-publish", - "options": {}, - "parallelism": true, - }, -} -`; 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 df219ed..7dbb2bc 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 @@ -1,13 +1,13 @@ -import type { Tree } from '@nx/devkit'; -import { join } from 'node:path'; -import { afterEach, expect } from 'vitest'; +import type {Tree} from '@nx/devkit'; +import {join} from 'node:path'; +import {afterEach, expect} from 'vitest'; import { addJsLibToWorkspace, materializeTree, nxShowProjectJson, registerPluginInWorkspace, } from '@push-based/test-nx-utils'; -import { updateProjectConfiguration } from 'nx/src/generators/utils/project-configuration'; +import {updateProjectConfiguration} from 'nx/src/generators/utils/project-configuration'; import { TARGET_ENVIRONMENT_BOOTSTRAP, TARGET_ENVIRONMENT_SETUP, @@ -17,7 +17,11 @@ import { TARGET_ENVIRONMENT_INSTALL, TARGET_ENVIRONMENT_VERDACCIO_STOP, } from '@push-based/nx-verdaccio'; -import { teardownTestFolder } from '@push-based/test-utils'; +import {teardownTestFolder} from '@push-based/test-utils'; +import { + TARGET_ENVIRONMENT_E2E, + TARGET_ENVIRONMENT_TEARDOWN +} from "../../../projects/nx-verdaccio/src/plugin/targets/environment.targets"; describe('nx-verdaccio plugin create-nodes-v2', () => { let tree: Tree; @@ -53,7 +57,7 @@ describe('nx-verdaccio plugin create-nodes-v2', () => { }); await materializeTree(tree, cwd); - const { code, projectJson } = await nxShowProjectJson(cwd, projectA); + const {code, projectJson} = await nxShowProjectJson(cwd, projectA); expect(code).toBe(0); expect(projectJson.targets).toStrictEqual({ @@ -102,7 +106,7 @@ describe('nx-verdaccio plugin create-nodes-v2', () => { }); await materializeTree(tree, cwd); - const { projectJson } = await nxShowProjectJson(cwd, projectAE2e); + const {projectJson} = await nxShowProjectJson(cwd, projectAE2e); expect(projectJson.targets).toStrictEqual( expect.not.objectContaining({ @@ -133,7 +137,7 @@ describe('nx-verdaccio plugin create-nodes-v2', () => { }); await materializeTree(tree, cwd); - const { projectJson: projectJsonB } = await nxShowProjectJson( + const {projectJson: projectJsonB} = await nxShowProjectJson( cwd, projectB ); @@ -146,7 +150,7 @@ describe('nx-verdaccio plugin create-nodes-v2', () => { }) ); - const { projectJson: projectJsonA } = await nxShowProjectJson( + const {projectJson: projectJsonA} = await nxShowProjectJson( cwd, projectA ); @@ -179,7 +183,7 @@ describe('nx-verdaccio plugin create-nodes-v2', () => { }); await materializeTree(tree, cwd); - const { code, projectJson } = await nxShowProjectJson(cwd, projectAE2e); + const {code, projectJson} = await nxShowProjectJson(cwd, projectAE2e); expect(code).toBe(0); expect(projectJson.targets).toStrictEqual( @@ -207,7 +211,7 @@ describe('nx-verdaccio plugin create-nodes-v2', () => { }, ], executor: 'nx:noop', - options: { environmentRoot: 'tmp/environments/lib-a-e2e' }, + options: {environmentRoot: 'tmp/environments/lib-a-e2e'}, }), [TARGET_ENVIRONMENT_SETUP]: expect.objectContaining({ cache: false, @@ -239,6 +243,13 @@ describe('nx-verdaccio plugin create-nodes-v2', () => { filePath: 'tmp/environments/verdaccio-registry.json', }, }), + [TARGET_ENVIRONMENT_E2E]: expect.objectContaining({ + executor: '@push-based/nx-verdaccio:env-teardown', + dependsOn: ["e2e"] + }), + [TARGET_ENVIRONMENT_TEARDOWN]: expect.objectContaining({ + executor: '@push-based/nx-verdaccio:env-teardown' + }), }) ); @@ -266,7 +277,7 @@ describe('nx-verdaccio plugin create-nodes-v2', () => { }); await materializeTree(tree, cwd); - const { projectJson } = await nxShowProjectJson(cwd, projectAE2e); + const {projectJson} = await nxShowProjectJson(cwd, projectAE2e); expect(projectJson.targets).toStrictEqual( expect.not.objectContaining({ 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 964d058..f60857f 100644 --- a/projects/nx-verdaccio/src/executors/env-teardown/teardown-env.ts +++ b/projects/nx-verdaccio/src/executors/env-teardown/teardown-env.ts @@ -8,6 +8,8 @@ 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 {ExpandedPluginConfiguration} from "nx/src/config/nx-json"; +import type {NxVerdaccioCreateNodeOptions} from "../../plugin/schema"; export const gitClient: SimpleGit = simpleGit(process.cwd()); export type TeardownEnvironmentOptions = Environment & { verbose?: boolean }; @@ -18,9 +20,10 @@ export async function teardownEnvironment( git: SimpleGit = gitClient ): Promise { const {environmentRoot: optEnvironmentRoot} = options; - const environmentsDir = context.nxJsonConfiguration.plugins.find(pCfg => { + const plugin = context.nxJsonConfiguration.plugins.find(pCfg => { return typeof pCfg === 'object' && pCfg?.plugin === '@push-based/nx-verdaccio'; - })?.options?.environments?.environmentsDir ?? DEFAULT_ENVIRONMENTS_OUTPUT_DIR; + }) as ExpandedPluginConfiguration; + const environmentsDir = plugin.options.environments?.environmentsDir ?? DEFAULT_ENVIRONMENTS_OUTPUT_DIR; const environmentRoot = optEnvironmentRoot ?? join(environmentsDir, context.projectName); // kill verdaccio process if running const registryPath = join(environmentRoot, VERDACCIO_REGISTRY_JSON); diff --git a/projects/nx-verdaccio/src/plugin/normalize-create-nodes-options.ts b/projects/nx-verdaccio/src/plugin/normalize-create-nodes-options.ts index 9b13cb9..f8d512a 100644 --- a/projects/nx-verdaccio/src/plugin/normalize-create-nodes-options.ts +++ b/projects/nx-verdaccio/src/plugin/normalize-create-nodes-options.ts @@ -1,6 +1,6 @@ import type { NxVerdaccioEnvironmentsOptions, - BuildEnvPluginCreateNodeOptions, + NxVerdaccioCreateNodeOptions, NxVerdaccioPackagesOptions, } from './schema'; import { @@ -20,7 +20,7 @@ export type NormalizedCreateNodeOptions = { }; export function normalizeCreateNodesOptions( - options: BuildEnvPluginCreateNodeOptions + options: NxVerdaccioCreateNodeOptions ): NormalizedCreateNodeOptions { const { environments = {}, packages = {} } = options ?? {}; const { targetNames = [] } = environments; diff --git a/projects/nx-verdaccio/src/plugin/nx-verdaccio.plugin.ts b/projects/nx-verdaccio/src/plugin/nx-verdaccio.plugin.ts index a7c703b..913eda7 100644 --- a/projects/nx-verdaccio/src/plugin/nx-verdaccio.plugin.ts +++ b/projects/nx-verdaccio/src/plugin/nx-verdaccio.plugin.ts @@ -9,7 +9,7 @@ import { type TargetConfiguration, } from '@nx/devkit'; import { dirname, join } from 'node:path'; -import type { BuildEnvPluginCreateNodeOptions } from './schema'; +import type { NxVerdaccioCreateNodeOptions } from './schema'; import { normalizeCreateNodesOptions, type NormalizedCreateNodeOptions, @@ -27,7 +27,7 @@ import { createTargets } from './targets/create-targets'; const PROJECT_JSON_FILE_GLOB = '**/project.json'; -export const createNodesV2: CreateNodesV2 = [ +export const createNodesV2: CreateNodesV2 = [ PROJECT_JSON_FILE_GLOB, async (configFiles, options, context) => { const normalizedOptions = normalizeCreateNodesOptions(options); diff --git a/projects/nx-verdaccio/src/plugin/schema.ts b/projects/nx-verdaccio/src/plugin/schema.ts index 8a3b7a3..86c56ba 100644 --- a/projects/nx-verdaccio/src/plugin/schema.ts +++ b/projects/nx-verdaccio/src/plugin/schema.ts @@ -8,7 +8,7 @@ export type NxVerdaccioPackagesOptions = { targetNames?: string[]; filterByTags?: string[]; }; -export type BuildEnvPluginCreateNodeOptions = { +export type NxVerdaccioCreateNodeOptions = { environments?: NxVerdaccioEnvironmentsOptions; packages?: NxVerdaccioPackagesOptions; }; diff --git a/projects/nx-verdaccio/src/plugin/targets/create-targets.ts b/projects/nx-verdaccio/src/plugin/targets/create-targets.ts index c43590f..9938bab 100644 --- a/projects/nx-verdaccio/src/plugin/targets/create-targets.ts +++ b/projects/nx-verdaccio/src/plugin/targets/create-targets.ts @@ -1,4 +1,4 @@ -import type { BuildEnvPluginCreateNodeOptions } from '../schema'; +import type { NxVerdaccioCreateNodeOptions } from '../schema'; import type { CreateNodesResult, ProjectConfiguration } from '@nx/devkit'; import { logger } from '@nx/devkit'; import { normalizeCreateNodesOptions } from '../normalize-create-nodes-options'; @@ -12,7 +12,7 @@ import { getPkgTargets, isPkgProject } from './package.targets'; export function createTargets( projectConfiguration: ProjectConfiguration, - options: BuildEnvPluginCreateNodeOptions + options: NxVerdaccioCreateNodeOptions ): CreateNodesResult['projects'][string]['targets'] { const { environments, packages } = normalizeCreateNodesOptions(options); From e2f29cfea8c64d214a88f6d9c72d035e0dcf22e9 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 13 Oct 2024 09:57:38 +0200 Subject: [PATCH 09/21] wip --- .../plugin-create-nodes.e2e.test.ts.snap | 131 +++++++++++ package-lock.json | 208 +----------------- package.json | 2 +- 3 files changed, 135 insertions(+), 206 deletions(-) create mode 100644 e2e/nx-verdaccio-e2e/test/__snapshots__/plugin-create-nodes.e2e.test.ts.snap 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 new file mode 100644 index 0000000..bfc9cfb --- /dev/null +++ b/e2e/nx-verdaccio-e2e/test/__snapshots__/plugin-create-nodes.e2e.test.ts.snap @@ -0,0 +1,131 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`nx-verdaccio plugin create-nodes-v2 > should add environment targets to project with targetName e2e dynamically 1`] = ` +{ + "e2e": { + "configurations": {}, + "dependsOn": [ + { + "params": "forward", + "target": "nxv-env-setup", + }, + ], + "executor": "nx:noop", + "options": {}, + "parallelism": true, + }, + "nxv-e2e": { + "configurations": {}, + "dependsOn": [ + "e2e", + ], + "executor": "@push-based/nx-verdaccio:env-teardown", + "options": {}, + "parallelism": true, + }, + "nxv-env-bootstrap": { + "configurations": {}, + "executor": "@push-based/nx-verdaccio:env-bootstrap", + "options": { + "environmentRoot": "tmp/environments/lib-a-e2e", + }, + "parallelism": true, + }, + "nxv-env-install": { + "configurations": {}, + "dependsOn": [ + { + "params": "forward", + "projects": "dependencies", + "target": "nxv-pkg-install", + }, + ], + "executor": "nx:noop", + "options": { + "environmentRoot": "tmp/environments/lib-a-e2e", + }, + "parallelism": true, + }, + "nxv-env-setup": { + "cache": false, + "configurations": {}, + "executor": "@push-based/nx-verdaccio:env-setup", + "options": { + "environmentRoot": "tmp/environments/lib-a-e2e", + }, + "outputs": [ + "{options.environmentRoot}/node_modules", + "{options.environmentRoot}/package.json", + "{options.environmentRoot}/.npmrc", + "{options.environmentRoot}/package-lock.json", + ], + "parallelism": true, + }, + "nxv-env-teardown": { + "configurations": {}, + "executor": "@push-based/nx-verdaccio:env-teardown", + "options": {}, + "parallelism": true, + }, + "nxv-verdaccio-start": { + "configurations": {}, + "executor": "@nx/js:verdaccio", + "options": { + "clear": true, + "config": ".verdaccio/config.yml", + "environmentDir": "tmp/environments/lib-a-e2e", + "port": Any, + "projectName": "lib-a-e2e", + "storage": "tmp/environments/lib-a-e2e/storage", + }, + "parallelism": true, + }, + "nxv-verdaccio-stop": { + "configurations": {}, + "executor": "@push-based/nx-verdaccio:kill-process", + "options": { + "filePath": "tmp/environments/verdaccio-registry.json", + }, + "parallelism": true, + }, +} +`; + +exports[`nx-verdaccio plugin create-nodes-v2 > should add package targets to library project 1`] = ` +{ + "nxv-pkg-install": { + "configurations": {}, + "dependsOn": [ + { + "params": "forward", + "target": "nxv-pkg-publish", + }, + { + "params": "forward", + "projects": "dependencies", + "target": "nxv-pkg-install", + }, + ], + "executor": "@push-based/nx-verdaccio:pkg-install", + "options": {}, + "parallelism": true, + }, + "nxv-pkg-publish": { + "configurations": {}, + "dependsOn": [ + { + "params": "forward", + "target": "build", + }, + { + "params": "forward", + "projects": "dependencies", + "target": "nxv-pkg-publish", + }, + ], + "executor": "@push-based/nx-verdaccio:pkg-publish", + "options": {}, + "parallelism": true, + }, +} +`; diff --git a/package-lock.json b/package-lock.json index f169b5c..250a6e8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "license": "MIT", "dependencies": { "memfs": "^4.11.1", - "simplegit": "^1.0.2", + "simple-git": "^3.27.0", "tslib": "^2.3.0", "yargs": "^17.7.2" }, @@ -3220,7 +3220,6 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/@kwsites/file-exists/-/file-exists-1.1.1.tgz", "integrity": "sha512-m9/5YGR18lIwxSFDwfE3oA7bWuq9kdau6ugN4H2rJeyhFQZcG9AgSHkQtSD15a8WvTgfz9aikZMrKPHvbpqFiw==", - "dev": true, "dependencies": { "debug": "^4.1.1" } @@ -3228,8 +3227,7 @@ "node_modules/@kwsites/promise-deferred": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/@kwsites/promise-deferred/-/promise-deferred-1.1.1.tgz", - "integrity": "sha512-GaHYm+c0O9MjZRu0ongGBRbinu8gVAMd2UZjji6jVmqKtZluZnptXGWhz1E8j8D2HJ3f/yMxKAUC0b+57wncIw==", - "dev": true + "integrity": "sha512-GaHYm+c0O9MjZRu0ongGBRbinu8gVAMd2UZjji6jVmqKtZluZnptXGWhz1E8j8D2HJ3f/yMxKAUC0b+57wncIw==" }, "node_modules/@mole-inc/bin-wrapper": { "version": "8.0.1", @@ -7546,14 +7544,6 @@ "node": ">= 0.12.0" } }, - "node_modules/code-point-at": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz", - "integrity": "sha512-RpAVKQA5T63xEj6/giIbUEtZwJ4UFIc3ZtvEkiaUERylqe8xb5IvqcgOurZLahv93CLKfxcw5YI+DZcUBRyLXA==", - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/collect-v8-coverage": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/collect-v8-coverage/-/collect-v8-coverage-1.0.2.tgz", @@ -7926,7 +7916,6 @@ "version": "4.3.7", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz", "integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==", - "dev": true, "dependencies": { "ms": "^2.1.3" }, @@ -7939,14 +7928,6 @@ } } }, - "node_modules/decamelize": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", - "integrity": "sha512-z2S+W9X73hAUUki+N+9Za2lBlun89zigOyGrsax+KUQ6wKW4ZoWpEYBkGhQjwAjjDCkWxhY0VKEhk8wzY7F5cA==", - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/decimal.js": { "version": "10.4.3", "resolved": "https://registry.npmjs.org/decimal.js/-/decimal.js-10.4.3.tgz", @@ -10214,19 +10195,6 @@ "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", "dev": true }, - "node_modules/ini": { - "version": "1.3.8", - "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.8.tgz", - "integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==" - }, - "node_modules/invert-kv": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/invert-kv/-/invert-kv-1.0.0.tgz", - "integrity": "sha512-xgs2NH9AE66ucSq4cNG1nhSFghr5l6tdL15Pk+jl46bmmBapgoaY/AacXyaDznAqmGL99TiLSQgO/XazFSKYeQ==", - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/ipaddr.js": { "version": "1.9.1", "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", @@ -11567,17 +11535,6 @@ "node": ">=6" } }, - "node_modules/lcid": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/lcid/-/lcid-1.0.0.tgz", - "integrity": "sha512-YiGkH6EnGrDGqLMITnGjXtGmNtjoXw9SVUzcaos8RBi7Ps0VBylkq+vOcY9QE5poLasPCR849ucFUkl0UzUyOw==", - "dependencies": { - "invert-kv": "^1.0.0" - }, - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/leven": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/leven/-/leven-3.1.0.tgz", @@ -12161,8 +12118,7 @@ "node_modules/ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", - "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", - "dev": true + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" }, "node_modules/multi-progress-bars": { "version": "5.0.3", @@ -12295,117 +12251,6 @@ "integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==", "dev": true }, - "node_modules/nconf": { - "version": "0.8.5", - "resolved": "https://registry.npmjs.org/nconf/-/nconf-0.8.5.tgz", - "integrity": "sha512-YXTpOk2LI4QD2vAr4v40+nELcEbUA5BkIoeIz4Orfx9XA0Gxkkf70+KOvIVNDP2YQBz5XWg7l1zgiPvWb0zTPw==", - "dependencies": { - "async": "^1.4.0", - "ini": "^1.3.0", - "secure-keys": "^1.0.0", - "yargs": "^3.19.0" - }, - "engines": { - "node": ">= 0.4.0" - } - }, - "node_modules/nconf/node_modules/ansi-regex": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", - "integrity": "sha512-TIGnTpdo+E3+pCyAluZvtED5p5wCqLdezCyhPZzKPcxvFplEt4i+W7OONCKgeZFT3+y5NZZfOOS/Bdcanm1MYA==", - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/nconf/node_modules/async": { - "version": "1.5.2", - "resolved": "https://registry.npmjs.org/async/-/async-1.5.2.tgz", - "integrity": "sha512-nSVgobk4rv61R9PUSDtYt7mPVB2olxNR5RWJcAsH676/ef11bUZwvu7+RGYrYauVdDPcO519v68wRhXQtxsV9w==" - }, - "node_modules/nconf/node_modules/camelcase": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-2.1.1.tgz", - "integrity": "sha512-DLIsRzJVBQu72meAKPkWQOLcujdXT32hwdfnkI1frSiSRMK1MofjKHf+MEx0SB6fjEFXL8fBDv1dKymBlOp4Qw==", - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/nconf/node_modules/cliui": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/cliui/-/cliui-3.2.0.tgz", - "integrity": "sha512-0yayqDxWQbqk3ojkYqUKqaAQ6AfNKeKWRNA8kR0WXzAsdHpP4BIaOmMAG87JGuO6qcobyW4GjxHd9PmhEd+T9w==", - "dependencies": { - "string-width": "^1.0.1", - "strip-ansi": "^3.0.1", - "wrap-ansi": "^2.0.0" - } - }, - "node_modules/nconf/node_modules/is-fullwidth-code-point": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", - "integrity": "sha512-1pqUqRjkhPJ9miNq9SwMfdvi6lBJcd6eFxvfaivQhaH3SgisfiuudvFntdKOmxuee/77l+FPjKrQjWvmPjWrRw==", - "dependencies": { - "number-is-nan": "^1.0.0" - }, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/nconf/node_modules/string-width": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", - "integrity": "sha512-0XsVpQLnVCXHJfyEs8tC0zpTVIr5PKKsQtkT29IwupnPTjtPmQ3xT/4yCREF9hYkV/3M3kzcUTSAZT6a6h81tw==", - "dependencies": { - "code-point-at": "^1.0.0", - "is-fullwidth-code-point": "^1.0.0", - "strip-ansi": "^3.0.0" - }, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/nconf/node_modules/strip-ansi": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", - "integrity": "sha512-VhumSSbBqDTP8p2ZLKj40UjBCV4+v8bUSEpUb4KjRgWk9pbqGF4REFj6KEagidb2f/M6AzC0EmFyDNGaw9OCzg==", - "dependencies": { - "ansi-regex": "^2.0.0" - }, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/nconf/node_modules/wrap-ansi": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-2.1.0.tgz", - "integrity": "sha512-vAaEaDM946gbNpH5pLVNR+vX2ht6n0Bt3GXwVB1AuAqZosOvHNF3P7wDnh8KLkSqgUh0uh77le7Owgoz+Z9XBw==", - "dependencies": { - "string-width": "^1.0.1", - "strip-ansi": "^3.0.1" - }, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/nconf/node_modules/y18n": { - "version": "3.2.2", - "resolved": "https://registry.npmjs.org/y18n/-/y18n-3.2.2.tgz", - "integrity": "sha512-uGZHXkHnhF0XeeAPgnKfPv1bgKAYyVvmNL1xlKsPYZPaIHxGti2hHqvOCQv71XMsLxu1QjergkqogUnms5D3YQ==" - }, - "node_modules/nconf/node_modules/yargs": { - "version": "3.32.0", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-3.32.0.tgz", - "integrity": "sha512-ONJZiimStfZzhKamYvR/xvmgW3uEkAUFSP91y2caTEPhzF6uP2JfPiVZcq66b/YR0C3uitxSV7+T1x8p5bkmMg==", - "dependencies": { - "camelcase": "^2.0.1", - "cliui": "^3.0.3", - "decamelize": "^1.1.1", - "os-locale": "^1.4.0", - "string-width": "^1.0.1", - "window-size": "^0.1.4", - "y18n": "^3.2.0" - } - }, "node_modules/ncp": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ncp/-/ncp-2.0.0.tgz", @@ -12538,14 +12383,6 @@ "node": ">=8" } }, - "node_modules/number-is-nan": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", - "integrity": "sha512-4jbtZXNAsfZbAHiiqjLPBiCl16dES1zI4Hpzzxw61Tk+loF+sBDBKx1ICKKKwIqQ7M0mFn1TmkN7euSncWgHiQ==", - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/nwsapi": { "version": "2.2.12", "resolved": "https://registry.npmjs.org/nwsapi/-/nwsapi-2.2.12.tgz", @@ -12927,17 +12764,6 @@ "node": ">=4" } }, - "node_modules/os-locale": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/os-locale/-/os-locale-1.4.0.tgz", - "integrity": "sha512-PRT7ZORmwu2MEFt4/fv3Q+mEfN4zetKxufQrkShY2oGvUms9r8otu5HfdyIFHkYXjO7laNsoVGmM2MANfuTA8g==", - "dependencies": { - "lcid": "^1.0.0" - }, - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/p-cancelable": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-2.1.1.tgz", @@ -14054,11 +13880,6 @@ "integrity": "sha512-AckIIV90rPDcBcglUwXPF3kg0P0qmPsPXAj6BBEENQE1p5yA1xfmDJzfi1Tappj37Pv2mVbKpL3Z1T+Nn7k1Qw==", "dev": true }, - "node_modules/secure-keys": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/secure-keys/-/secure-keys-1.0.0.tgz", - "integrity": "sha512-nZi59hW3Sl5P3+wOO89eHBAAGwmCPd2aE1+dLZV5MO+ItQctIvAqihzaAXIQhvtH4KJPxM080HsnqltR2y8cWg==" - }, "node_modules/semver": { "version": "7.6.3", "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", @@ -14239,7 +14060,6 @@ "version": "3.27.0", "resolved": "https://registry.npmjs.org/simple-git/-/simple-git-3.27.0.tgz", "integrity": "sha512-ivHoFS9Yi9GY49ogc6/YAi3Fl9ROnF4VyubNylgCkA+RVqLaKWnDSzXOVzya8csELIaWaYNutsEuAhZrtOjozA==", - "dev": true, "dependencies": { "@kwsites/file-exists": "^1.1.1", "@kwsites/promise-deferred": "^1.1.1", @@ -14250,17 +14070,6 @@ "url": "https://github.com/steveukx/git-js?sponsor=1" } }, - "node_modules/simplegit": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/simplegit/-/simplegit-1.0.2.tgz", - "integrity": "sha512-jEQKokh61NP+oqj7oFpXtd29zOSO8rR1X1Rs11tNtBLxLhrR976zBnRmzR6zZes7MkqhVUtS1QnyiuBxGDLDrg==", - "dependencies": { - "nconf": "^0.8.4" - }, - "bin": { - "sgit": "index.js" - } - }, "node_modules/sirv": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/sirv/-/sirv-2.0.4.tgz", @@ -16540,17 +16349,6 @@ "node": ">=8" } }, - "node_modules/window-size": { - "version": "0.1.4", - "resolved": "https://registry.npmjs.org/window-size/-/window-size-0.1.4.tgz", - "integrity": "sha512-2thx4pB0cV3h+Bw7QmMXcEbdmOzv9t0HFplJH/Lz6yu60hXYy5RT8rUu+wlIreVxWsGN20mo+MHeCSfUpQBwPw==", - "bin": { - "window-size": "cli.js" - }, - "engines": { - "node": ">= 0.10.0" - } - }, "node_modules/word-wrap": { "version": "1.2.5", "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz", diff --git a/package.json b/package.json index 0fb0035..9f1103a 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "private": true, "dependencies": { "memfs": "^4.11.1", - "simplegit": "^1.0.2", + "simple-git": "^3.27.0", "tslib": "^2.3.0", "yargs": "^17.7.2" }, From 663314faafb3dd5a796bb1f58bad5c38e4635cf5 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 13 Oct 2024 10:02:54 +0200 Subject: [PATCH 10/21] wip --- code-pushup.config.ts | 18 +++--- .../test/plugin-create-nodes.e2e.test.ts | 32 +++++------ .../src/executors/env-setup/executor.ts | 28 +++++++--- .../src/executors/env-teardown/README.md | 10 ++-- .../src/executors/env-teardown/executor.ts | 12 ++-- .../src/executors/env-teardown/git.ts | 25 +++++---- .../executors/env-teardown/git.unit-test.ts | 11 ---- .../src/executors/env-teardown/schema.ts | 10 ++-- .../executors/env-teardown/teardown-env.ts | 56 +++++++++++-------- .../env-teardown/teardown-env.unit-test.ts | 5 -- .../nx-verdaccio/src/internal/file-system.ts | 2 +- .../src/plugin/targets/environment.targets.ts | 4 +- tooling/bin/nx-show-project.ts | 6 +- .../nx-performance/audit/task-graph.audit.ts | 18 +++--- .../nx-performance/audit/task-time.audit.ts | 16 ++---- tooling/measures/nx-performance/index.ts | 8 +-- .../nx-performance/nx-performance.plugin.ts | 29 +++++----- 17 files changed, 146 insertions(+), 144 deletions(-) delete mode 100644 projects/nx-verdaccio/src/executors/env-teardown/git.unit-test.ts delete mode 100644 projects/nx-verdaccio/src/executors/env-teardown/teardown-env.unit-test.ts diff --git a/code-pushup.config.ts b/code-pushup.config.ts index d79ff2f..e372d20 100644 --- a/code-pushup.config.ts +++ b/code-pushup.config.ts @@ -1,9 +1,9 @@ -import {CoreConfig} from '@code-pushup/models'; +import { CoreConfig } from '@code-pushup/models'; import nxPerformancePlugin, { nxPerformanceCategoryRefs, type OnlyAudit, } from './tooling/measures/nx-performance/nx-performance.plugin'; -import {TaskTimeAuditOption} from "./tooling/measures/nx-performance"; +import { TaskTimeAuditOption } from './tooling/measures/nx-performance'; const onlyAudits: OnlyAudit[] = [ 'graph-time-project', @@ -13,17 +13,17 @@ const onlyAudits: OnlyAudit[] = [ ]; const taskGraphTasks = ['cli-e2e:nxv-env-install']; const taskTimeTasks: TaskTimeAuditOption[] = [ - {task: 'models-e2e:nxv-env-teardown'}, - {task: 'models-e2e:nxv-env-bootstrap'}, - {task: 'models-e2e:nxv-env-setup'}, - {task: 'models-e2e:e2e'}, - {task: 'models-e2e:nxv-e2e'}, + { task: 'models-e2e:nxv-env-teardown' }, + { task: 'models-e2e:nxv-env-bootstrap' }, + { task: 'models-e2e:nxv-env-setup' }, + { 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' }, ]; const cacheSizeTasks = [ 'models-e2e:nxv-env-setup', - 'nx-verdaccio-e2e:nxv-env-setup' + 'nx-verdaccio-e2e:nxv-env-setup', ]; export default { plugins: [ 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 7dbb2bc..388ec8f 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 @@ -1,13 +1,13 @@ -import type {Tree} from '@nx/devkit'; -import {join} from 'node:path'; -import {afterEach, expect} from 'vitest'; +import type { Tree } from '@nx/devkit'; +import { join } from 'node:path'; +import { afterEach, expect } from 'vitest'; import { addJsLibToWorkspace, materializeTree, nxShowProjectJson, registerPluginInWorkspace, } from '@push-based/test-nx-utils'; -import {updateProjectConfiguration} from 'nx/src/generators/utils/project-configuration'; +import { updateProjectConfiguration } from 'nx/src/generators/utils/project-configuration'; import { TARGET_ENVIRONMENT_BOOTSTRAP, TARGET_ENVIRONMENT_SETUP, @@ -17,11 +17,11 @@ import { TARGET_ENVIRONMENT_INSTALL, TARGET_ENVIRONMENT_VERDACCIO_STOP, } from '@push-based/nx-verdaccio'; -import {teardownTestFolder} from '@push-based/test-utils'; +import { teardownTestFolder } from '@push-based/test-utils'; import { TARGET_ENVIRONMENT_E2E, - TARGET_ENVIRONMENT_TEARDOWN -} from "../../../projects/nx-verdaccio/src/plugin/targets/environment.targets"; + TARGET_ENVIRONMENT_TEARDOWN, +} from '../../../projects/nx-verdaccio/src/plugin/targets/environment.targets'; describe('nx-verdaccio plugin create-nodes-v2', () => { let tree: Tree; @@ -57,7 +57,7 @@ describe('nx-verdaccio plugin create-nodes-v2', () => { }); await materializeTree(tree, cwd); - const {code, projectJson} = await nxShowProjectJson(cwd, projectA); + const { code, projectJson } = await nxShowProjectJson(cwd, projectA); expect(code).toBe(0); expect(projectJson.targets).toStrictEqual({ @@ -106,7 +106,7 @@ describe('nx-verdaccio plugin create-nodes-v2', () => { }); await materializeTree(tree, cwd); - const {projectJson} = await nxShowProjectJson(cwd, projectAE2e); + const { projectJson } = await nxShowProjectJson(cwd, projectAE2e); expect(projectJson.targets).toStrictEqual( expect.not.objectContaining({ @@ -137,7 +137,7 @@ describe('nx-verdaccio plugin create-nodes-v2', () => { }); await materializeTree(tree, cwd); - const {projectJson: projectJsonB} = await nxShowProjectJson( + const { projectJson: projectJsonB } = await nxShowProjectJson( cwd, projectB ); @@ -150,7 +150,7 @@ describe('nx-verdaccio plugin create-nodes-v2', () => { }) ); - const {projectJson: projectJsonA} = await nxShowProjectJson( + const { projectJson: projectJsonA } = await nxShowProjectJson( cwd, projectA ); @@ -183,7 +183,7 @@ describe('nx-verdaccio plugin create-nodes-v2', () => { }); await materializeTree(tree, cwd); - const {code, projectJson} = await nxShowProjectJson(cwd, projectAE2e); + const { code, projectJson } = await nxShowProjectJson(cwd, projectAE2e); expect(code).toBe(0); expect(projectJson.targets).toStrictEqual( @@ -211,7 +211,7 @@ describe('nx-verdaccio plugin create-nodes-v2', () => { }, ], executor: 'nx:noop', - options: {environmentRoot: 'tmp/environments/lib-a-e2e'}, + options: { environmentRoot: 'tmp/environments/lib-a-e2e' }, }), [TARGET_ENVIRONMENT_SETUP]: expect.objectContaining({ cache: false, @@ -245,10 +245,10 @@ describe('nx-verdaccio plugin create-nodes-v2', () => { }), [TARGET_ENVIRONMENT_E2E]: expect.objectContaining({ executor: '@push-based/nx-verdaccio:env-teardown', - dependsOn: ["e2e"] + dependsOn: ['e2e'], }), [TARGET_ENVIRONMENT_TEARDOWN]: expect.objectContaining({ - executor: '@push-based/nx-verdaccio:env-teardown' + executor: '@push-based/nx-verdaccio:env-teardown', }), }) ); @@ -277,7 +277,7 @@ describe('nx-verdaccio plugin create-nodes-v2', () => { }); await materializeTree(tree, cwd); - const {projectJson} = await nxShowProjectJson(cwd, projectAE2e); + const { projectJson } = await nxShowProjectJson(cwd, projectAE2e); expect(projectJson.targets).toStrictEqual( expect.not.objectContaining({ diff --git a/projects/nx-verdaccio/src/executors/env-setup/executor.ts b/projects/nx-verdaccio/src/executors/env-setup/executor.ts index 1072539..509311a 100644 --- a/projects/nx-verdaccio/src/executors/env-setup/executor.ts +++ b/projects/nx-verdaccio/src/executors/env-setup/executor.ts @@ -12,7 +12,7 @@ import { TARGET_ENVIRONMENT_VERDACCIO_STOP, } from '../../plugin/targets/environment.targets'; import { runSingleExecutor } from '../../internal/run-executor'; -import {rm} from "node:fs/promises"; +import { rm } from 'node:fs/promises'; export type ExecutorOutput = { success: boolean; @@ -24,8 +24,8 @@ export default async function runSetupEnvironmentExecutor( terminalAndExecutorOptions: SetupEnvironmentExecutorOptions, context: ExecutorContext ) { - const {configurationName: configuration, projectName} = context; - const {verbose, environmentRoot, keepServerRunning} = + const { configurationName: configuration, projectName } = context; + const { verbose, environmentRoot, keepServerRunning } = terminalAndExecutorOptions; try { await runSingleExecutor( @@ -56,10 +56,10 @@ export default async function runSetupEnvironmentExecutor( args: objectToCliArgs({ _: [TARGET_ENVIRONMENT_INSTALL, projectName], environmentRoot, - ...(verbose ? {verbose} : {}), + ...(verbose ? { verbose } : {}), }), cwd: process.cwd(), - ...(verbose ? {verbose} : {}), + ...(verbose ? { verbose } : {}), }); } catch (error) { logger.error(error.message); @@ -78,16 +78,26 @@ export default async function runSetupEnvironmentExecutor( configuration, }, { - ...(verbose ? {verbose} : {}), + ...(verbose ? { verbose } : {}), filePath: join(environmentRoot, VERDACCIO_REGISTRY_JSON), }, context ); // delete storage, npmrc - await rm(join(environmentRoot, 'storage'), {recursive: true, force: true, retryDelay: 100, maxRetries: 2}); - await rm(join(environmentRoot, '.npmrc'), {recursive: true, force: true, retryDelay: 100, maxRetries: 2}); + await rm(join(environmentRoot, 'storage'), { + recursive: true, + force: true, + retryDelay: 100, + maxRetries: 2, + }); + await rm(join(environmentRoot, '.npmrc'), { + recursive: true, + force: true, + retryDelay: 100, + maxRetries: 2, + }); } else { - const {url} = readJsonFile( + const { url } = readJsonFile( join(environmentRoot, VERDACCIO_REGISTRY_JSON) ); logger.info(`Verdaccio server kept running under : ${url}`); diff --git a/projects/nx-verdaccio/src/executors/env-teardown/README.md b/projects/nx-verdaccio/src/executors/env-teardown/README.md index f8dc5bb..32f7579 100644 --- a/projects/nx-verdaccio/src/executors/env-teardown/README.md +++ b/projects/nx-verdaccio/src/executors/env-teardown/README.md @@ -46,8 +46,8 @@ Show what will be executed without actually executing it: ## Options -| Name | type | description | -| --------------------- | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------ | -| **envRoot** | `string` (REQUIRED) | The folder in which the package should get published. This folder is the environment folder and contains a configured `.npmrc` file. | -| **verbose** | `boolean` | Show more verbose logs | -| **printConfig** | `boolean` | Print config without executing | +| Name | type | description | +| --------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------ | +| **envRoot** | `string` (REQUIRED) | The folder in which the package should get published. This folder is the environment folder and contains a configured `.npmrc` file. | +| **verbose** | `boolean` | Show more verbose logs | +| **printConfig** | `boolean` | Print config without executing | diff --git a/projects/nx-verdaccio/src/executors/env-teardown/executor.ts b/projects/nx-verdaccio/src/executors/env-teardown/executor.ts index c0ed66f..c0ee650 100644 --- a/projects/nx-verdaccio/src/executors/env-teardown/executor.ts +++ b/projects/nx-verdaccio/src/executors/env-teardown/executor.ts @@ -1,9 +1,9 @@ -import {type ExecutorContext, logger} from '@nx/devkit'; -import type {TeardownExecutorOptions} from './schema'; -import {teardownEnvironment,} from './teardown-env'; -import {PACKAGE_NAME} from '../../plugin/constants'; -import {EXECUTOR_ENVIRONMENT_TEARDOWN} from "./constants"; -import {ExecutorOutput} from "../internal/executor-output"; +import { type ExecutorContext, logger } from '@nx/devkit'; +import type { TeardownExecutorOptions } from './schema'; +import { teardownEnvironment } from './teardown-env'; +import { PACKAGE_NAME } from '../../plugin/constants'; +import { EXECUTOR_ENVIRONMENT_TEARDOWN } from './constants'; +import { ExecutorOutput } from '../internal/executor-output'; export async function teardownExecutor( options: TeardownExecutorOptions, diff --git a/projects/nx-verdaccio/src/executors/env-teardown/git.ts b/projects/nx-verdaccio/src/executors/env-teardown/git.ts index defd6b2..694d6e5 100644 --- a/projects/nx-verdaccio/src/executors/env-teardown/git.ts +++ b/projects/nx-verdaccio/src/executors/env-teardown/git.ts @@ -1,6 +1,6 @@ -import type {SimpleGit} from "simple-git"; -import {simpleGit} from "simple-git"; -import {resolve} from "node:path"; +import type { SimpleGit } from 'simple-git'; +import { simpleGit } from 'simple-git'; +import { resolve } from 'node:path'; export const gitClient: SimpleGit = simpleGit(); @@ -9,23 +9,23 @@ export async function cleanGitHistoryForFolder( options?: { verbose?: boolean }, git: SimpleGit = gitClient ): Promise { - await git.show(['--oneline']); - } -export async function isFolderInRepo( - folderPath: string -): Promise { +export async function isFolderInRepo(folderPath: string): Promise { try { // Initialize simple-git with the folder path const git = simpleGit(folderPath); // Check if the folder is a git repository - const isRepo = (await git.checkIgnore(folderPath)).length === 0 + const isRepo = (await git.checkIgnore(folderPath)).length === 0; // console.log(`${folderPath} is ${isRepo ? '' : 'not '} in Git repository.`); return isRepo; } catch (error) { - if((error as Error).message.includes("Cannot use simple-git on a directory that does not exist")) { + if ( + (error as Error).message.includes( + 'Cannot use simple-git on a directory that does not exist' + ) + ) { return true; } console.log(`${error}`); @@ -33,7 +33,10 @@ export async function isFolderInRepo( } } -export async function isSubfolderInGitRepository(subFolderPath: string, baseFolderPath = process.cwd()) { +export async function isSubfolderInGitRepository( + subFolderPath: string, + baseFolderPath = process.cwd() +) { // Resolve the full path for the subfolder const fullSubFolderPath = resolve(baseFolderPath, subFolderPath); diff --git a/projects/nx-verdaccio/src/executors/env-teardown/git.unit-test.ts b/projects/nx-verdaccio/src/executors/env-teardown/git.unit-test.ts deleted file mode 100644 index 70ddbcb..0000000 --- a/projects/nx-verdaccio/src/executors/env-teardown/git.unit-test.ts +++ /dev/null @@ -1,11 +0,0 @@ -import {describe, expect, it, vi} from 'vitest'; -import {cleanGitHistoryForFolder} from './git'; -import {execSync} from 'node:child_process'; - -describe('cleanGitHistoryForFolder', () => { - - it('should clean up given folder', () => { - cleanGitHistoryForFolder('tmp'); - }); - -}); diff --git a/projects/nx-verdaccio/src/executors/env-teardown/schema.ts b/projects/nx-verdaccio/src/executors/env-teardown/schema.ts index bb46170..e918251 100644 --- a/projects/nx-verdaccio/src/executors/env-teardown/schema.ts +++ b/projects/nx-verdaccio/src/executors/env-teardown/schema.ts @@ -1,5 +1,7 @@ -import {Environment} from "../env-bootstrap/npm"; +import { Environment } from '../env-bootstrap/npm'; -export type TeardownExecutorOptions = Partial; +export type TeardownExecutorOptions = Partial< + Environment & { + 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 f60857f..50a4524 100644 --- a/projects/nx-verdaccio/src/executors/env-teardown/teardown-env.ts +++ b/projects/nx-verdaccio/src/executors/env-teardown/teardown-env.ts @@ -1,15 +1,15 @@ -import {Environment} from "../env-bootstrap/npm"; -import {simpleGit, type SimpleGit} from "simple-git"; -import {isFolderInRepo} from "./git"; -import {ExecutorContext, logger} from "@nx/devkit"; -import {join} from "node:path"; -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 {ExpandedPluginConfiguration} from "nx/src/config/nx-json"; -import type {NxVerdaccioCreateNodeOptions} from "../../plugin/schema"; +import { Environment } from '../env-bootstrap/npm'; +import { simpleGit, type SimpleGit } from 'simple-git'; +import { isFolderInRepo } from './git'; +import { ExecutorContext, logger } from '@nx/devkit'; +import { join } from 'node:path'; +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 { ExpandedPluginConfiguration } from 'nx/src/config/nx-json'; +import type { NxVerdaccioCreateNodeOptions } from '../../plugin/schema'; export const gitClient: SimpleGit = simpleGit(process.cwd()); export type TeardownEnvironmentOptions = Environment & { verbose?: boolean }; @@ -19,17 +19,22 @@ 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'; + 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 environmentsDir = + plugin.options.environments?.environmentsDir ?? + DEFAULT_ENVIRONMENTS_OUTPUT_DIR; + const environmentRoot = + optEnvironmentRoot ?? join(environmentsDir, context.projectName); // kill verdaccio process if running const registryPath = join(environmentRoot, VERDACCIO_REGISTRY_JSON); const registryJsonExists = await fileExists(registryPath); if (registryJsonExists) { - await runKillProcessExecutor({...options, filePath: registryPath}); + await runKillProcessExecutor({ ...options, filePath: registryPath }); } else { logger.info(`No verdaccio-registry.json file found in ${environmentRoot}`); } @@ -47,13 +52,18 @@ export async function teardownEnvironment( logger.info(`Cleaned git history in ${environmentRoot}`); } else { try { - const registryFiles = [ - join(environmentRoot) - ]; - await rm(environmentRoot, {recursive: true, force: true, retryDelay: 100, maxRetries: 2}); + const registryFiles = [join(environmentRoot)]; + await rm(environmentRoot, { + recursive: true, + force: true, + retryDelay: 100, + maxRetries: 2, + }); logger.info(`deleted folder ${environmentRoot}.`); } catch (error) { - throw new Error(`Error cleaning history of folder ${environmentRoot}. ${error.message}`); + throw new Error( + `Error cleaning history of folder ${environmentRoot}. ${error.message}` + ); } } } diff --git a/projects/nx-verdaccio/src/executors/env-teardown/teardown-env.unit-test.ts b/projects/nx-verdaccio/src/executors/env-teardown/teardown-env.unit-test.ts deleted file mode 100644 index 362ec6b..0000000 --- a/projects/nx-verdaccio/src/executors/env-teardown/teardown-env.unit-test.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { describe, expect, it, vi } from 'vitest'; -import { teardownEnvironment } from './bootstrap-env'; -import * as verdaccioRegistryModule from './verdaccio-registry'; -import * as npmModule from './npm'; -import * as fs from 'node:fs/promises'; diff --git a/projects/nx-verdaccio/src/internal/file-system.ts b/projects/nx-verdaccio/src/internal/file-system.ts index b6ad6b9..a563321 100644 --- a/projects/nx-verdaccio/src/internal/file-system.ts +++ b/projects/nx-verdaccio/src/internal/file-system.ts @@ -1,4 +1,4 @@ -import {mkdir, stat} from 'node:fs/promises'; +import { mkdir, stat } from 'node:fs/promises'; export async function ensureDirectoryExists(baseDir: string) { try { diff --git a/projects/nx-verdaccio/src/plugin/targets/environment.targets.ts b/projects/nx-verdaccio/src/plugin/targets/environment.targets.ts index 505328f..a8af103 100644 --- a/projects/nx-verdaccio/src/plugin/targets/environment.targets.ts +++ b/projects/nx-verdaccio/src/plugin/targets/environment.targets.ts @@ -13,7 +13,7 @@ import { PACKAGE_NAME } from '../constants'; import { EXECUTOR_ENVIRONMENT_KILL_PROCESS } from '../../executors/kill-process/constant'; import { EXECUTOR_ENVIRONMENT_SETUP } from '../../executors/env-setup/constants'; import { iterateEntries } from '../../internal/transform'; -import {EXECUTOR_ENVIRONMENT_TEARDOWN} from "../../executors/env-teardown/constants"; +import { EXECUTOR_ENVIRONMENT_TEARDOWN } from '../../executors/env-teardown/constants'; export const TARGET_ENVIRONMENT_BOOTSTRAP = 'nxv-env-bootstrap'; export const TARGET_ENVIRONMENT_INSTALL = 'nxv-env-install'; @@ -133,7 +133,7 @@ export function getEnvTargets( }, [TARGET_ENVIRONMENT_E2E]: { dependsOn: targetNames, - executor: `${PACKAGE_NAME}:${EXECUTOR_ENVIRONMENT_TEARDOWN}` + executor: `${PACKAGE_NAME}:${EXECUTOR_ENVIRONMENT_TEARDOWN}`, }, }; } diff --git a/tooling/bin/nx-show-project.ts b/tooling/bin/nx-show-project.ts index 89c586b..edf8506 100644 --- a/tooling/bin/nx-show-project.ts +++ b/tooling/bin/nx-show-project.ts @@ -9,14 +9,14 @@ const argv = yargs(hideBin(process.argv)) pkgRange: { type: 'string', demandOption: true }, registry: { type: 'string' }, }) - .coerce('pkgRange', rawVersion => { + .coerce('pkgRange', (rawVersion) => { if (rawVersion != null && rawVersion !== '') { return rawVersion; } else { return undefined; } }) - .coerce('registry', rawRegistry => { + .coerce('registry', (rawRegistry) => { if (rawRegistry != null && rawRegistry !== '') { return rawRegistry; } else { @@ -43,7 +43,7 @@ try { ], { shell: true, - }, + } ).toString(); const existingPackage = viewResult diff --git a/tooling/measures/nx-performance/audit/task-graph.audit.ts b/tooling/measures/nx-performance/audit/task-graph.audit.ts index 1478d07..7a5ec77 100644 --- a/tooling/measures/nx-performance/audit/task-graph.audit.ts +++ b/tooling/measures/nx-performance/audit/task-graph.audit.ts @@ -1,6 +1,6 @@ -import {Audit, AuditOutputs} from '@code-pushup/models'; -import {execFile} from 'node:child_process'; -import {slugify} from '@code-pushup/utils'; +import { Audit, AuditOutputs } from '@code-pushup/models'; +import { execFile } from 'node:child_process'; +import { slugify } from '@code-pushup/utils'; export const DEFAULT_MAX_TASK_GRAPH_TIME = 300; export const TASK_GRAPH_TIME_AUDIT_POSTFIX = 'graph-time-task'; @@ -9,13 +9,13 @@ export function getTaskGraphTimeAuditSlug(task: string): string { return `${slugify(task)}-${TASK_GRAPH_TIME_AUDIT_POSTFIX}`; } -export const getTaskGraphTimeAudits = (tasks: (string)[]): Audit[] => { +export const getTaskGraphTimeAudits = (tasks: string[]): Audit[] => { return tasks.map((task) => { - return ({ + return { slug: getTaskGraphTimeAuditSlug(task), // Unique slug for each task title: '[Graph Time] task graph', description: 'An audit to check performance of the Nx task graph', - }) + }; }); }; @@ -27,11 +27,11 @@ export type TaskGraphAuditOptions = { export async function taskGraphAudits( options?: TaskGraphAuditOptions ): Promise { - const {maxTaskGraphTime = DEFAULT_MAX_TASK_GRAPH_TIME, taskGraphTasks} = - options ?? {}; + const { maxTaskGraphTime = DEFAULT_MAX_TASK_GRAPH_TIME, taskGraphTasks } = + options ?? {}; const results = await taskGraphTiming(taskGraphTasks); - return results.map(({duration, task}) => ({ + return results.map(({ duration, task }) => ({ slug: getTaskGraphTimeAuditSlug(task), score: scoreTaskGraphDuration(duration, maxTaskGraphTime), value: duration, diff --git a/tooling/measures/nx-performance/audit/task-time.audit.ts b/tooling/measures/nx-performance/audit/task-time.audit.ts index 84b07b9..ad32f1c 100644 --- a/tooling/measures/nx-performance/audit/task-time.audit.ts +++ b/tooling/measures/nx-performance/audit/task-time.audit.ts @@ -1,9 +1,5 @@ import { AuditOutput, Audit, Table, Issue } from '@code-pushup/models'; -import { - executeProcess, - slugify, - formatDuration, -} from '@code-pushup/utils'; +import { executeProcess, slugify, formatDuration } from '@code-pushup/utils'; import { logger, readJsonFile } from '@nx/devkit'; import { DEFAULT_PLUGIN_OUTPUT } from '../constant'; import { join } from 'node:path'; @@ -19,15 +15,15 @@ export function getTaskTimeAuditSlug(task: string): string { export type TaskTimeAuditOption = { task: string; cleanup?: () => void | Promise; -} +}; export const getTaskTimeAudits = (tasks: TaskTimeAuditOption[]): Audit[] => { - return tasks.map(({task}) => { - return ({ + return tasks.map(({ task }) => { + return { slug: getTaskTimeAuditSlug(task), // Unique slug for each task title: `[Task Time] ${task}`, description: 'An audit to check performance of the Nx task.', - }) + }; }); }; @@ -84,7 +80,7 @@ export async function taskTimeData( ): Promise { const results: TaskTimeResult[] = []; - for (const {task} of tasks) { + for (const { task } of tasks) { const dist = join(DEFAULT_PLUGIN_OUTPUT, 'task-time'); await executeProcess({ command: `NX_DAEMON=false NX_PROFILE=${dist}/${slugify( diff --git a/tooling/measures/nx-performance/index.ts b/tooling/measures/nx-performance/index.ts index ffe8c9a..b9eda64 100644 --- a/tooling/measures/nx-performance/index.ts +++ b/tooling/measures/nx-performance/index.ts @@ -1,9 +1,5 @@ -export { - type TaskTimeAuditOption, -} from './audit/task-time.audit'; -export { - type TaskGraphAuditOptions, -} from './audit/task-graph.audit'; +export { type TaskTimeAuditOption } from './audit/task-time.audit'; +export { type TaskGraphAuditOptions } from './audit/task-graph.audit'; export { type OnlyAudit, nxPerformanceAudits, diff --git a/tooling/measures/nx-performance/nx-performance.plugin.ts b/tooling/measures/nx-performance/nx-performance.plugin.ts index 9bbb6e9..6815672 100644 --- a/tooling/measures/nx-performance/nx-performance.plugin.ts +++ b/tooling/measures/nx-performance/nx-performance.plugin.ts @@ -4,7 +4,7 @@ import { CategoryRef, PluginConfig, } from '@code-pushup/models'; -import {PLUGIN_SLUG} from './constant'; +import { PLUGIN_SLUG } from './constant'; import { PROJECT_GRAPH_PERFORMANCE_AUDIT, PROJECT_GRAPH_PERFORMANCE_AUDIT_SLUG, @@ -31,10 +31,10 @@ import { } from './audit/task-graph.audit'; export const nxPerformanceAudits = ({ - taskTimeTasks, - cacheSizeTasks, - taskGraphTasks, - }: NxPerfPluginConfig) => [ + taskTimeTasks, + cacheSizeTasks, + taskGraphTasks, +}: NxPerfPluginConfig) => [ PROJECT_GRAPH_PERFORMANCE_AUDIT, ...(taskTimeTasks ? getTaskTimeAudits(taskTimeTasks) : []), ...(cacheSizeTasks ? getCacheSizeAudits(cacheSizeTasks) : []), @@ -48,7 +48,7 @@ export const nxPerformanceCategoryRefs = ( const audits = options?.onlyAudits ? filterOnlyAudits(allAudits, options.onlyAudits) : allAudits; - return audits.map(({slug}) => ({ + return audits.map(({ slug }) => ({ type: 'audit', plugin: PLUGIN_SLUG, slug, @@ -63,11 +63,12 @@ export type OnlyAudit = | typeof TASK_GRAPH_TIME_AUDIT_POSTFIX; export type NxPerfPluginConfig = { onlyAudits?: OnlyAudit[]; -} & - Partial; + TaskGraphAuditOptions +>; export function nxPerformancePlugin( options?: NxPerfPluginConfig @@ -94,7 +95,7 @@ export function filterOnlyAudits( onlyAudits: OnlyAudit[] ): Audit[] { const onlyAuditsSet = new Set(onlyAudits); - return audits.filter(({slug}) => { + return audits.filter(({ slug }) => { if ( onlyAuditsSet.has(CACHE_SIZE_AUDIT_POSTFIX) && slug.endsWith(CACHE_SIZE_AUDIT_POSTFIX) @@ -138,16 +139,16 @@ export async function runnerFunction( const onlyAuditsSet = new Set(onlyAudits); return [ ...(onlyAuditsSet.has(PROJECT_GRAPH_PERFORMANCE_AUDIT_SLUG) - ? [await projectGraphAudit({maxProjectGraphTime})] + ? [await projectGraphAudit({ maxProjectGraphTime })] : []), ...(onlyAuditsSet.has(CACHE_SIZE_AUDIT_POSTFIX) - ? await cacheSizeAudits({maxCacheSize, cacheSizeTasks}) + ? await cacheSizeAudits({ maxCacheSize, cacheSizeTasks }) : []), ...(onlyAuditsSet.has(TASK_GRAPH_TIME_AUDIT_POSTFIX) - ? await taskGraphAudits({maxTaskGraphTime, taskGraphTasks}) + ? await taskGraphAudits({ maxTaskGraphTime, taskGraphTasks }) : []), ...(onlyAuditsSet.has(TASK_TIME_AUDIT_POSTFIX) - ? await taskTimeAudits({maxTaskTime, taskTimeTasks}) + ? await taskTimeAudits({ maxTaskTime, taskTimeTasks }) : []), ]; } From b6064e6050903248fbe18014975141c23f757e39 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 13 Oct 2024 10:09:44 +0200 Subject: [PATCH 11/21] wip --- e2e/nx-verdaccio-e2e/project.json | 1 - 1 file changed, 1 deletion(-) diff --git a/e2e/nx-verdaccio-e2e/project.json b/e2e/nx-verdaccio-e2e/project.json index d3fe428..fbcbc68 100644 --- a/e2e/nx-verdaccio-e2e/project.json +++ b/e2e/nx-verdaccio-e2e/project.json @@ -8,7 +8,6 @@ "targets": { "lint": {}, "e2e": { - "dependsOn": ["^build"], "executor": "@nx/vite:test", "inputs": ["default", "^production"], "outputs": ["{options.reportsDirectory}"], From beb3bdda1439a663c8b702177a335d1b18190204 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 13 Oct 2024 10:10:27 +0200 Subject: [PATCH 12/21] wip --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dead22e..bf89efe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -70,4 +70,4 @@ jobs: - name: Install dependencies run: npm i - name: E2E test affected projects - run: npx nx affected -t e2e --exclude="tag:type:example" + run: npx nx affected -t nxv-e2e --exclude="tag:type:example" From a2881379467be4ea866d604c59938cb340d0a265 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 13 Oct 2024 10:22:22 +0200 Subject: [PATCH 13/21] wip --- examples/e2e/cli-static-e2e/project.json | 2 +- .../src/executors/env-teardown/git.ts | 26 ------------------- 2 files changed, 1 insertion(+), 27 deletions(-) diff --git a/examples/e2e/cli-static-e2e/project.json b/examples/e2e/cli-static-e2e/project.json index bcd2e04..2ce212a 100644 --- a/examples/e2e/cli-static-e2e/project.json +++ b/examples/e2e/cli-static-e2e/project.json @@ -7,7 +7,7 @@ "implicitDependencies": ["cli"], "targets": { "lint": {}, - "e2e": { + "e2e-static": { "executor": "@nx/vite:test", "inputs": ["default", "^production"], "outputs": ["{options.reportsDirectory}"], diff --git a/projects/nx-verdaccio/src/executors/env-teardown/git.ts b/projects/nx-verdaccio/src/executors/env-teardown/git.ts index 694d6e5..bdd47d4 100644 --- a/projects/nx-verdaccio/src/executors/env-teardown/git.ts +++ b/projects/nx-verdaccio/src/executors/env-teardown/git.ts @@ -1,6 +1,5 @@ import type { SimpleGit } from 'simple-git'; import { simpleGit } from 'simple-git'; -import { resolve } from 'node:path'; export const gitClient: SimpleGit = simpleGit(); @@ -32,28 +31,3 @@ export async function isFolderInRepo(folderPath: string): Promise { return false; } } - -export async function isSubfolderInGitRepository( - subFolderPath: string, - baseFolderPath = process.cwd() -) { - // Resolve the full path for the subfolder - const fullSubFolderPath = resolve(baseFolderPath, subFolderPath); - - // Initialize simple-git with the full subfolder path - const git = simpleGit(fullSubFolderPath); - - try { - // Check if the subfolder path is within a Git repository - const isRepo = await git.checkIsRepo(); - if (isRepo) { - console.log(`${fullSubFolderPath} is inside a Git repository.`); - } else { - console.log(`${fullSubFolderPath} is not inside a Git repository.`); - } - return isRepo; - } catch (error) { - console.log(`${fullSubFolderPath} is not inside a Git repository.`); - return false; - } -} From 20a57e231c7309887f5e10fbd8ce1bef2a513f42 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 13 Oct 2024 10:30:17 +0200 Subject: [PATCH 14/21] wip --- .../src/executors/env-teardown/git.ts | 21 ++---------- .../executors/env-teardown/teardown-env.ts | 32 +++++++++---------- 2 files changed, 18 insertions(+), 35 deletions(-) diff --git a/projects/nx-verdaccio/src/executors/env-teardown/git.ts b/projects/nx-verdaccio/src/executors/env-teardown/git.ts index bdd47d4..bb8e1f7 100644 --- a/projects/nx-verdaccio/src/executors/env-teardown/git.ts +++ b/projects/nx-verdaccio/src/executors/env-teardown/git.ts @@ -1,24 +1,9 @@ -import type { SimpleGit } from 'simple-git'; -import { simpleGit } from 'simple-git'; +import {simpleGit} from 'simple-git'; -export const gitClient: SimpleGit = simpleGit(); - -export async function cleanGitHistoryForFolder( - environmentRoot: string, - options?: { verbose?: boolean }, - git: SimpleGit = gitClient -): Promise { - await git.show(['--oneline']); -} - -export async function isFolderInRepo(folderPath: string): Promise { +export async function isFolderInGit(folderPath: string): Promise { try { - // Initialize simple-git with the folder path const git = simpleGit(folderPath); - // Check if the folder is a git repository - const isRepo = (await git.checkIgnore(folderPath)).length === 0; - // console.log(`${folderPath} is ${isRepo ? '' : 'not '} in Git repository.`); - return isRepo; + return (await git.checkIgnore(folderPath)).length === 0; } catch (error) { if ( (error as Error).message.includes( 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 50a4524..fa4650e 100644 --- a/projects/nx-verdaccio/src/executors/env-teardown/teardown-env.ts +++ b/projects/nx-verdaccio/src/executors/env-teardown/teardown-env.ts @@ -1,15 +1,15 @@ -import { Environment } from '../env-bootstrap/npm'; -import { simpleGit, type SimpleGit } from 'simple-git'; -import { isFolderInRepo } from './git'; -import { ExecutorContext, logger } from '@nx/devkit'; -import { join } from 'node:path'; -import { VERDACCIO_REGISTRY_JSON } from '../env-bootstrap/constants'; -import { fileExists } from '../../internal/file-system'; -import { rm } from 'node:fs/promises'; +import type {Environment} from '../env-bootstrap/npm'; +import {simpleGit, type SimpleGit} from 'simple-git'; +import {isFolderInGit} from './git'; +import type {ExecutorContext, logger} from '@nx/devkit'; +import {join} from 'node:path'; +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 { ExpandedPluginConfiguration } from 'nx/src/config/nx-json'; -import type { NxVerdaccioCreateNodeOptions } from '../../plugin/schema'; +import {DEFAULT_ENVIRONMENTS_OUTPUT_DIR} from '../../plugin/constants'; +import type {ExpandedPluginConfiguration} from 'nx/src/config/nx-json'; +import type {NxVerdaccioCreateNodeOptions} from '../../plugin/schema'; export const gitClient: SimpleGit = simpleGit(process.cwd()); export type TeardownEnvironmentOptions = Environment & { verbose?: boolean }; @@ -44,15 +44,13 @@ export async function teardownEnvironment( return; } - // clean environmentRoot - const environmentRootInRepo = await isFolderInRepo(environmentRoot); - if (environmentRootInRepo) { - // await git.checkout([environmentRoot]); - // await git.clean('f', [environmentRoot]); + const environmentRootInGit = await isFolderInGit(environmentRoot); + if (environmentRootInGit) { + await git.checkout([environmentRoot]); + await git.clean('f', [environmentRoot]); logger.info(`Cleaned git history in ${environmentRoot}`); } else { try { - const registryFiles = [join(environmentRoot)]; await rm(environmentRoot, { recursive: true, force: true, From 6a410c594468437f56baff725d2309df2f26ec2d Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 13 Oct 2024 10:38:26 +0200 Subject: [PATCH 15/21] wip 1 --- .../src/executors/env-teardown/git.ts | 6 +++- .../executors/env-teardown/teardown-env.ts | 30 +++++++++---------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/projects/nx-verdaccio/src/executors/env-teardown/git.ts b/projects/nx-verdaccio/src/executors/env-teardown/git.ts index bb8e1f7..12f1583 100644 --- a/projects/nx-verdaccio/src/executors/env-teardown/git.ts +++ b/projects/nx-verdaccio/src/executors/env-teardown/git.ts @@ -2,8 +2,12 @@ import {simpleGit} from 'simple-git'; export async function isFolderInGit(folderPath: string): Promise { try { + // Initialize simple-git with the folder path const git = simpleGit(folderPath); - return (await git.checkIgnore(folderPath)).length === 0; + // Check if the folder is a git repository + const isRepo = (await git.checkIgnore(folderPath)).length === 0; + // console.log(`${folderPath} is ${isRepo ? '' : 'not '} in Git repository.`); + return isRepo; } catch (error) { if ( (error as Error).message.includes( 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 fa4650e..f35395f 100644 --- a/projects/nx-verdaccio/src/executors/env-teardown/teardown-env.ts +++ b/projects/nx-verdaccio/src/executors/env-teardown/teardown-env.ts @@ -1,15 +1,15 @@ -import type {Environment} from '../env-bootstrap/npm'; -import {simpleGit, type SimpleGit} from 'simple-git'; -import {isFolderInGit} from './git'; -import type {ExecutorContext, logger} from '@nx/devkit'; -import {join} from 'node:path'; -import {VERDACCIO_REGISTRY_JSON} from '../env-bootstrap/constants'; -import {fileExists} from '../../internal/file-system'; -import {rm} from 'node:fs/promises'; +import { Environment } from '../env-bootstrap/npm'; +import { simpleGit, type SimpleGit } from 'simple-git'; +import { isFolderInGit } from './git'; +import { ExecutorContext, logger } from '@nx/devkit'; +import { join } from 'node:path'; +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 { DEFAULT_ENVIRONMENTS_OUTPUT_DIR } from '../../plugin/constants'; +import { ExpandedPluginConfiguration } from 'nx/src/config/nx-json'; +import type { NxVerdaccioCreateNodeOptions } from '../../plugin/schema'; export const gitClient: SimpleGit = simpleGit(process.cwd()); export type TeardownEnvironmentOptions = Environment & { verbose?: boolean }; @@ -44,10 +44,10 @@ export async function teardownEnvironment( return; } - const environmentRootInGit = await isFolderInGit(environmentRoot); - if (environmentRootInGit) { - await git.checkout([environmentRoot]); - await git.clean('f', [environmentRoot]); + const environmentRootInRepo = await isFolderInGit(environmentRoot); + if (environmentRootInRepo) { + // await git.checkout([environmentRoot]); + // await git.clean('f', [environmentRoot]); logger.info(`Cleaned git history in ${environmentRoot}`); } else { try { From 21151ee1486729c8c83049e8014385d3023b4b76 Mon Sep 17 00:00:00 2001 From: Michael Hladky <10064416+BioPhoton@users.noreply.github.com> Date: Sun, 13 Oct 2024 10:44:04 +0200 Subject: [PATCH 16/21] Apply suggestions from code review --- projects/nx-verdaccio/src/executors/env-teardown/git.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/projects/nx-verdaccio/src/executors/env-teardown/git.ts b/projects/nx-verdaccio/src/executors/env-teardown/git.ts index 12f1583..957b723 100644 --- a/projects/nx-verdaccio/src/executors/env-teardown/git.ts +++ b/projects/nx-verdaccio/src/executors/env-teardown/git.ts @@ -2,11 +2,9 @@ import {simpleGit} from 'simple-git'; export async function isFolderInGit(folderPath: string): Promise { try { - // Initialize simple-git with the folder path const git = simpleGit(folderPath); // Check if the folder is a git repository const isRepo = (await git.checkIgnore(folderPath)).length === 0; - // console.log(`${folderPath} is ${isRepo ? '' : 'not '} in Git repository.`); return isRepo; } catch (error) { if ( From ff187b9b19f3b64f6dc5774541a924c21cce3e41 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 13 Oct 2024 10:43:00 +0200 Subject: [PATCH 17/21] wip 2 --- static-environments/user-lists/package.json | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/static-environments/user-lists/package.json b/static-environments/user-lists/package.json index 52d530d..df42d59 100644 --- a/static-environments/user-lists/package.json +++ b/static-environments/user-lists/package.json @@ -7,11 +7,5 @@ "keywords": [], "author": "", "license": "ISC", - "description": "", - "dependencies": { - "@push-based/cli": "^0.0.1-e2e", - "@push-based/core": "^0.0.1-e2e", - "@push-based/models": "^0.0.1-e2e", - "@push-based/utils": "^0.0.1-e2e" - } + "description": "" } From ae04d9486e22bbcfc341504e55047f92bcc8b844 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 13 Oct 2024 10:57:27 +0200 Subject: [PATCH 18/21] wip 3 --- code-pushup.config.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/code-pushup.config.ts b/code-pushup.config.ts index e372d20..4c985c1 100644 --- a/code-pushup.config.ts +++ b/code-pushup.config.ts @@ -1,9 +1,9 @@ -import { CoreConfig } from '@code-pushup/models'; +import {CoreConfig} from '@code-pushup/models'; import nxPerformancePlugin, { nxPerformanceCategoryRefs, type OnlyAudit, } from './tooling/measures/nx-performance/nx-performance.plugin'; -import { TaskTimeAuditOption } from './tooling/measures/nx-performance'; +import {TaskTimeAuditOption} from './tooling/measures/nx-performance'; const onlyAudits: OnlyAudit[] = [ 'graph-time-project', @@ -13,13 +13,13 @@ const onlyAudits: OnlyAudit[] = [ ]; const taskGraphTasks = ['cli-e2e:nxv-env-install']; const taskTimeTasks: TaskTimeAuditOption[] = [ - { task: 'models-e2e:nxv-env-teardown' }, - { task: 'models-e2e:nxv-env-bootstrap' }, - { task: 'models-e2e:nxv-env-setup' }, - { task: 'models-e2e:e2e' }, - { task: 'models-e2e:nxv-e2e' }, - // {task: 'nx-verdaccio-e2e:nxv-e2e'}, - { task: 'cli-e2e-original:original-e2e' }, + {task: 'models-e2e:nxv-env-teardown'}, + {task: 'models-e2e:nxv-env-bootstrap'}, + {task: 'models-e2e:nxv-env-setup'}, + {task: 'models-e2e:e2e'}, + {task: 'models-e2e:nxv-e2e'}, + {task: 'nx-verdaccio-e2e:nxv-e2e'}, + {task: 'cli-e2e-original:original-e2e'}, ]; const cacheSizeTasks = [ 'models-e2e:nxv-env-setup', From b37c39321f5a840d50c8538abeac89a17ca4bbbc Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 13 Oct 2024 11:06:40 +0200 Subject: [PATCH 19/21] wip 3 --- ...project-graph.audit.ts => graph-project-time.audit.ts} | 3 +-- .../{task-graph.audit.ts => graph-task-time.audit.ts} | 0 tooling/measures/nx-performance/nx-performance.plugin.ts | 8 ++++---- 3 files changed, 5 insertions(+), 6 deletions(-) rename tooling/measures/nx-performance/audit/{project-graph.audit.ts => graph-project-time.audit.ts} (97%) rename tooling/measures/nx-performance/audit/{task-graph.audit.ts => graph-task-time.audit.ts} (100%) diff --git a/tooling/measures/nx-performance/audit/project-graph.audit.ts b/tooling/measures/nx-performance/audit/graph-project-time.audit.ts similarity index 97% rename from tooling/measures/nx-performance/audit/project-graph.audit.ts rename to tooling/measures/nx-performance/audit/graph-project-time.audit.ts index d513c8b..dd84591 100644 --- a/tooling/measures/nx-performance/audit/project-graph.audit.ts +++ b/tooling/measures/nx-performance/audit/graph-project-time.audit.ts @@ -3,7 +3,6 @@ import { execFile } from 'node:child_process'; import { promisify } from 'node:util'; export const DEFAULT_MAX_PROJECT_GRAPH_TIME = 300; - export const PROJECT_GRAPH_PERFORMANCE_AUDIT_SLUG = 'graph-time-project'; export const PROJECT_GRAPH_PERFORMANCE_AUDIT = { slug: PROJECT_GRAPH_PERFORMANCE_AUDIT_SLUG, @@ -15,7 +14,7 @@ export type ProjectGraphAuditOptions = { maxProjectGraphTime?: number; }; -export async function projectGraphAudit( +export async function graphProjectTimeAudit( options?: ProjectGraphAuditOptions ): Promise { const { maxProjectGraphTime = DEFAULT_MAX_PROJECT_GRAPH_TIME } = diff --git a/tooling/measures/nx-performance/audit/task-graph.audit.ts b/tooling/measures/nx-performance/audit/graph-task-time.audit.ts similarity index 100% rename from tooling/measures/nx-performance/audit/task-graph.audit.ts rename to tooling/measures/nx-performance/audit/graph-task-time.audit.ts diff --git a/tooling/measures/nx-performance/nx-performance.plugin.ts b/tooling/measures/nx-performance/nx-performance.plugin.ts index 6815672..df5885d 100644 --- a/tooling/measures/nx-performance/nx-performance.plugin.ts +++ b/tooling/measures/nx-performance/nx-performance.plugin.ts @@ -8,9 +8,9 @@ import { PLUGIN_SLUG } from './constant'; import { PROJECT_GRAPH_PERFORMANCE_AUDIT, PROJECT_GRAPH_PERFORMANCE_AUDIT_SLUG, - projectGraphAudit, + graphProjectTimeAudit, ProjectGraphAuditOptions, -} from './audit/project-graph.audit'; +} from './audit/graph-project-time.audit'; import { getTaskTimeAudits, TaskTimeAuditOptions, @@ -28,7 +28,7 @@ import { TASK_GRAPH_TIME_AUDIT_POSTFIX, TaskGraphAuditOptions, taskGraphAudits, -} from './audit/task-graph.audit'; +} from './audit/graph-task-time.audit'; export const nxPerformanceAudits = ({ taskTimeTasks, @@ -139,7 +139,7 @@ export async function runnerFunction( const onlyAuditsSet = new Set(onlyAudits); return [ ...(onlyAuditsSet.has(PROJECT_GRAPH_PERFORMANCE_AUDIT_SLUG) - ? [await projectGraphAudit({ maxProjectGraphTime })] + ? [await graphProjectTimeAudit({ maxProjectGraphTime })] : []), ...(onlyAuditsSet.has(CACHE_SIZE_AUDIT_POSTFIX) ? await cacheSizeAudits({ maxCacheSize, cacheSizeTasks }) From 7e09841bd66021d777d3da4367909f46dead0346 Mon Sep 17 00:00:00 2001 From: Michael Hladky <10064416+BioPhoton@users.noreply.github.com> Date: Sun, 13 Oct 2024 11:13:32 +0200 Subject: [PATCH 20/21] Update static-environments/user-lists/package.json --- static-environments/user-lists/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/static-environments/user-lists/package.json b/static-environments/user-lists/package.json index df42d59..fe5f92f 100644 --- a/static-environments/user-lists/package.json +++ b/static-environments/user-lists/package.json @@ -2,8 +2,8 @@ "name": "user-lists", "private": true, "scripts": {}, - "version": "1.0.0", - "main": "index.js", + "dependencies": {}, + "devDependencies": {} "keywords": [], "author": "", "license": "ISC", From 8106fa16a60f1302fa2b62a90ca4534bbf29ac7e Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 13 Oct 2024 11:15:16 +0200 Subject: [PATCH 21/21] wip 3 --- static-environments/user-lists/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/static-environments/user-lists/package.json b/static-environments/user-lists/package.json index fe5f92f..df42d59 100644 --- a/static-environments/user-lists/package.json +++ b/static-environments/user-lists/package.json @@ -2,8 +2,8 @@ "name": "user-lists", "private": true, "scripts": {}, - "dependencies": {}, - "devDependencies": {} + "version": "1.0.0", + "main": "index.js", "keywords": [], "author": "", "license": "ISC",