From 3faf91c707948da15c22e9e5067b89aa9f818bc6 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 30 Sep 2024 02:11:13 +0200 Subject: [PATCH] feat: modify package json before publishing --- .../src/executors/pkg-publish/pkg-version.ts | 20 +++++++++++++++++++ .../src/plugin/targets/environment.targets.ts | 15 +++++++------- 2 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 projects/nx-verdaccio/src/executors/pkg-publish/pkg-version.ts diff --git a/projects/nx-verdaccio/src/executors/pkg-publish/pkg-version.ts b/projects/nx-verdaccio/src/executors/pkg-publish/pkg-version.ts new file mode 100644 index 00000000..6d1c159c --- /dev/null +++ b/projects/nx-verdaccio/src/executors/pkg-publish/pkg-version.ts @@ -0,0 +1,20 @@ +import { join } from 'node:path'; +import { readFile } from '@nx/plugin/testing'; +import type { PackageJson } from 'nx/src/utils/package-json'; +import { writeFile } from 'node:fs/promises'; + +export async function postfixVersion(dist: string): Promise { + const pkgPath = join(process.cwd(), dist, 'package.json'); + const pkg = JSON.parse(await readFile(pkgPath)) as PackageJson; + return writeFile( + pkgPath, + JSON.stringify( + { + ...pkg, + version: `${pkg.version}-e2e`, + }, + null, + 2 + ) + ); +} diff --git a/projects/nx-verdaccio/src/plugin/targets/environment.targets.ts b/projects/nx-verdaccio/src/plugin/targets/environment.targets.ts index 3b7c8c96..bcb964a5 100644 --- a/projects/nx-verdaccio/src/plugin/targets/environment.targets.ts +++ b/projects/nx-verdaccio/src/plugin/targets/environment.targets.ts @@ -1,7 +1,7 @@ import type { ProjectConfiguration, TargetConfiguration } from '@nx/devkit'; import type { NormalizedCreateNodeOptions } from '../normalize-create-nodes-options'; import { join } from 'node:path'; -import { TARGET_PACKAGE_NPM_INSTALL } from './package.targets'; +import { TARGET_PACKAGE_INSTALL } from './package.targets'; import type { BuildEnvEnvironmentsOptions } from '../schema'; import type { StartVerdaccioOptions } from '../../executors/env-bootstrap/verdaccio-registry'; import { uniquePort } from '../../executors/env-bootstrap/unique-port'; @@ -12,14 +12,13 @@ import { 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 * as constants from 'constants'; import { iterateEntries } from '../../internal/transform'; -export const TARGET_ENVIRONMENT_VERDACCIO_START = 'pb-ve-env-verdaccio-start'; -export const TARGET_ENVIRONMENT_BOOTSTRAP = 'pb-ve-env-bootstrap'; -export const TARGET_ENVIRONMENT_INSTALL = 'pb-ve-env-install'; -export const TARGET_ENVIRONMENT_SETUP = 'pb-ve-env-setup'; -export const TARGET_ENVIRONMENT_VERDACCIO_STOP = 'pb-ve-env-verdaccio-stop'; +export const TARGET_ENVIRONMENT_VERDACCIO_START = 'nxv-env-verdaccio-start'; +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_VERDACCIO_STOP = 'nxv-env-verdaccio-stop'; export function isEnvProject( projectConfig: ProjectConfiguration, @@ -106,7 +105,7 @@ export function getEnvTargets( dependsOn: [ { projects: 'dependencies', - target: TARGET_PACKAGE_NPM_INSTALL, + target: TARGET_PACKAGE_INSTALL, params: 'forward', }, ],