diff --git a/nx.json b/nx.json index cbf3b609..f862072d 100644 --- a/nx.json +++ b/nx.json @@ -5,10 +5,7 @@ "libsDir": "projects" }, "namedInputs": { - "default": [ - "{projectRoot}/**/*", - "sharedGlobals" - ], + "default": ["{projectRoot}/**/*", "sharedGlobals"], "production": [ "default", "!{projectRoot}/.eslintrc.json", @@ -22,42 +19,27 @@ "targetDefaults": { "@nx/esbuild:esbuild": { "cache": true, - "dependsOn": [ - "^build" - ], - "inputs": [ - "production", - "^production" - ] + "dependsOn": ["^build"], + "inputs": ["production", "^production"] }, "@nx/vite:test": { "cache": true, - "inputs": [ - "default", - "^production" - ] + "inputs": ["default", "^production"] }, "nx-release-publish": { "dependsOn": [ { - "projects": [ - "self" - ], + "projects": ["self"], "target": "build" }, { - "projects": [ - "dependencies" - ], + "projects": ["dependencies"], "target": "nx-release-publish" } ] }, "build": { - "inputs": [ - "production", - "^production" - ] + "inputs": ["production", "^production"] } }, "plugins": [ diff --git a/tools/bin/npm-env.ts b/tools/bin/setup-npm-env.ts similarity index 89% rename from tools/bin/npm-env.ts rename to tools/bin/setup-npm-env.ts index 1fbd5d6e..3dc6bea7 100644 --- a/tools/bin/npm-env.ts +++ b/tools/bin/setup-npm-env.ts @@ -1,4 +1,4 @@ -import { startNpmEnv, StartVerdaccioAndSetupEnvOptions } from '../utils/env'; +import { setupNpmEnv, StartVerdaccioAndSetupEnvOptions } from '../utils/env'; import yargs, { Options } from 'yargs'; const isVerbose: boolean = process.env.NX_VERBOSE_LOGGING === 'true' ?? false; @@ -29,5 +29,5 @@ const args = yargs(process.argv.slice(2)) .parse() as StartVerdaccioAndSetupEnvOptions; (async () => { - await startNpmEnv(args); + await setupNpmEnv(args); })(); diff --git a/tools/bin/teardown-env.ts b/tools/bin/teardown-npm-env.ts similarity index 65% rename from tools/bin/teardown-env.ts rename to tools/bin/teardown-npm-env.ts index 6f61698f..2096115d 100644 --- a/tools/bin/teardown-env.ts +++ b/tools/bin/teardown-npm-env.ts @@ -1,9 +1,14 @@ -import {logError, logInfo, startNpmEnv, StartVerdaccioAndSetupEnvOptions} from '../utils/env'; -import yargs, {Options} from 'yargs'; -import {join} from "node:path"; -import {readJsonFile} from "@nx/devkit"; -import {VercaddioServerResult} from "../utils/registry"; -import {rm} from "node:fs/promises"; +import { + logError, + logInfo, + setupNpmEnv, + StartVerdaccioAndSetupEnvOptions, +} from '../utils/env'; +import yargs, { Options } from 'yargs'; +import { join } from 'node:path'; +import { readJsonFile } from '@nx/devkit'; +import { VercaddioServerResult } from '../utils/registry'; +import { rm } from 'node:fs/promises'; const isVerbose: boolean = process.env.NX_VERBOSE_LOGGING === 'true' ?? false; @@ -18,16 +23,18 @@ const args = yargs(process.argv.slice(2)) type: 'boolean', description: 'Verbose logging', default: isVerbose, - } + }, } satisfies Partial>) .parse() as StartVerdaccioAndSetupEnvOptions; (async () => { - const {workspaceRoot} = args; + const { workspaceRoot } = args; const registryConfigPath = join(workspaceRoot, 'verdaccio-registry.json'); let registryServerResult: VercaddioServerResult; try { - registryServerResult = await readJsonFile(registryConfigPath); + registryServerResult = await readJsonFile( + registryConfigPath + ); } catch (e) { logError(`No registry config file found at: ${registryConfigPath}`); return; @@ -35,13 +42,13 @@ const args = yargs(process.argv.slice(2)) logInfo('Tearing down environment'); console.table(registryServerResult); - const {pid, storage} = registryServerResult; - await rm(storage, {recursive: true, force: true}) + const { pid, storage } = registryServerResult; + await rm(storage, { recursive: true, force: true }); try { process.kill(Number(pid)); } catch (e) { logError(`Failes kipplng process with id: ${pid}\n${e}`); } finally { - await rm(registryConfigPath) + await rm(registryConfigPath); } })(); diff --git a/tools/plugins/verdaccio-test-env.plugin.ts b/tools/plugins/verdaccio-test-env.plugin.ts index d7d02a17..1a4b0382 100644 --- a/tools/plugins/verdaccio-test-env.plugin.ts +++ b/tools/plugins/verdaccio-test-env.plugin.ts @@ -1,6 +1,10 @@ -import {type CreateNodes, readJsonFile, TargetConfiguration,} from '@nx/devkit'; -import {dirname, join, relative} from 'node:path'; -import type {ProjectConfiguration} from 'nx/src/config/workspace-json-project-json'; +import { + type CreateNodes, + readJsonFile, + TargetConfiguration, +} from '@nx/devkit'; +import { dirname, join, relative } from 'node:path'; +import type { ProjectConfiguration } from 'nx/src/config/workspace-json-project-json'; const tmpNpmEnv = join('tmp', 'npm-env'); @@ -20,11 +24,14 @@ export const createNodes: CreateNodes = [ projects: { [root]: { targets: { - // e2e project + // === e2e project + // start-verdaccio, stop-verdaccio ...(isNpmEnv && verdaccioTargets(projectConfiguration)), + // setup-npm-env, setup-env, setup-deps ...(isNpmEnv && envTargets(projectConfiguration)), - // dependency project - ...(isPublishable && npmTargets({...projectConfiguration, root})), + // === dependency project + // npm-publish, npm-install + ...(isPublishable && npmTargets({ ...projectConfiguration, root })), }, }, }, @@ -32,8 +39,10 @@ export const createNodes: CreateNodes = [ }, ]; -function verdaccioTargets(projectConfiguration: ProjectConfiguration): Record { - const {name: projectName} = projectConfiguration; +function verdaccioTargets( + projectConfiguration: ProjectConfiguration +): Record { + const { name: projectName } = projectConfiguration; return { 'start-verdaccio': { executor: '@nx/js:verdaccio', @@ -44,19 +53,23 @@ function verdaccioTargets(projectConfiguration: ProjectConfiguration): Record { - const {name: projectName} = projectConfiguration; +function envTargets( + projectConfiguration: ProjectConfiguration +): Record { + const { name: projectName } = projectConfiguration; return { 'setup-npm-env': { - command: 'tsx --tsconfig=tools/tsconfig.tools.json tools/bin/npm-env.ts', + command: + 'tsx --tsconfig=tools/tsconfig.tools.json tools/bin/setup-npm-env.ts', options: { projectName, targetName: 'start-verdaccio', @@ -65,17 +78,18 @@ function envTargets(projectConfiguration: ProjectConfiguration): Record function npmTargets( projectConfiguration: ProjectConfiguration ): Record { - const {root, name: projectName, targets} = projectConfiguration; - const {build} = targets; - const {options} = build; - const {outputPath} = options; + const { root, name: projectName, targets } = projectConfiguration; + const { build } = targets; + const { options } = build; + const { outputPath } = options; if (outputPath == null) { throw new Error('outputPath is required'); } - const {name: packageName, version: pkgVersion} = readJsonFile( + const { name: packageName, version: pkgVersion } = readJsonFile( join(root, 'package.json') ); - const userconfig = `${relativeFromPath(outputPath)}/${tmpNpmEnv}/{args.envProjectName}/.npmrc`; - const prefix = `${tmpNpmEnv}/{args.envProjectName}`; + const userconfig = `${relativeFromPath( + outputPath + )}/${tmpNpmEnv}/{args.envProjectName}/.npmrc`; + const prefix = `${tmpNpmEnv}/{args.envProjectName}`; const envProjectName = projectName; return { 'npm-publish': { dependsOn: [ - {projects: 'self', target: 'build', params: 'forward'}, + { projects: 'self', target: 'build', params: 'forward' }, { projects: 'dependencies', target: 'npm-publish', @@ -138,7 +154,7 @@ function npmTargets( }, 'npm-install': { dependsOn: [ - {projects: 'self', target: 'npm-publish', params: 'forward'}, + { projects: 'self', target: 'npm-publish', params: 'forward' }, { projects: 'dependencies', target: 'npm-install', @@ -150,6 +166,6 @@ function npmTargets( pkgVersion, envProjectName, }, - } + }, }; } diff --git a/tools/utils/env.ts b/tools/utils/env.ts index 685f52eb..9f6f5cd2 100644 --- a/tools/utils/env.ts +++ b/tools/utils/env.ts @@ -33,7 +33,7 @@ export type NpmTestEnvResult = VerdaccioEnv & { stop: () => void; }; -export async function startNpmEnv({ +export async function setupNpmEnv({ projectName, verbose = false, targetName = 'start-verdaccio', diff --git a/tools/utils/registry.ts b/tools/utils/registry.ts index 049294d0..e502c2c4 100644 --- a/tools/utils/registry.ts +++ b/tools/utils/registry.ts @@ -9,6 +9,7 @@ export function logInfo(msg: string) { export function logError(msg: string) { error(msg, 'Verdaccio: '); } + export type VerdaccioProcessResult = { protocol: string; port: string | number;