Skip to content

Commit

Permalink
fix(nx-verdaccio): move envRoot into executors
Browse files Browse the repository at this point in the history
  • Loading branch information
BioPhoton committed Oct 18, 2024
1 parent bee6d64 commit 3818fba
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 68 deletions.
6 changes: 6 additions & 0 deletions .verdaccio/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ uplinks:
maxage: 60m

packages:
# allow publishing local packages
'@push-based/*':
access: $all
publish: $all
unpublish: $all

'**':
# give all users (including non-authenticated users) full access
# because it is a local registry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ exports[`nx-verdaccio plugin create-nodes-v2 > should add environment targets to
"nxv-e2e": {
"configurations": {},
"dependsOn": [
"e2e",
{
"params": "forward",
"target": "e2e",
},
],
"executor": "@push-based/nx-verdaccio:env-teardown",
"options": {},
Expand All @@ -26,9 +29,7 @@ exports[`nx-verdaccio plugin create-nodes-v2 > should add environment targets to
"nxv-env-bootstrap": {
"configurations": {},
"executor": "@push-based/nx-verdaccio:env-bootstrap",
"options": {
"environmentRoot": "tmp/environments/lib-a-e2e",
},
"options": {},
"parallelism": true,
},
"nxv-env-install": {
Expand All @@ -40,8 +41,9 @@ exports[`nx-verdaccio plugin create-nodes-v2 > should add environment targets to
"target": "nxv-pkg-install",
},
],
"executor": "nx:noop",
"executor": "nx:run-commands",
"options": {
"command": "echo "dependencies installed for tmp/environments/lib-a-e2e"",
"environmentRoot": "tmp/environments/lib-a-e2e",
},
"parallelism": true,
Expand All @@ -65,9 +67,7 @@ exports[`nx-verdaccio plugin create-nodes-v2 > should add environment targets to
},
"^production",
],
"options": {
"environmentRoot": "tmp/environments/lib-a-e2e",
},
"options": {},
"outputs": [
"{options.environmentRoot}/.npmrc",
"{options.environmentRoot}/package.json",
Expand Down Expand Up @@ -108,42 +108,3 @@ exports[`nx-verdaccio plugin create-nodes-v2 > should add environment targets to
},
}
`;
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,
},
}
`;
24 changes: 14 additions & 10 deletions e2e/nx-verdaccio-e2e/test/plugin-create-nodes.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ describe('nx-verdaccio plugin create-nodes-v2', () => {
const { code, projectJson } = await nxShowProjectJson(cwd, projectAE2e);
expect(code).toBe(0);

expect(projectJson.targets).toStrictEqual(
expect(projectJson.targets).toEqual(
expect.objectContaining({
e2e: expect.objectContaining({
dependsOn: [
Expand All @@ -199,9 +199,6 @@ describe('nx-verdaccio plugin create-nodes-v2', () => {
}),
[TARGET_ENVIRONMENT_BOOTSTRAP]: expect.objectContaining({
executor: '@push-based/nx-verdaccio:env-bootstrap',
options: {
environmentRoot: 'tmp/environments/lib-a-e2e',
},
}),
[TARGET_ENVIRONMENT_INSTALL]: expect.objectContaining({
dependsOn: [
Expand All @@ -211,15 +208,17 @@ describe('nx-verdaccio plugin create-nodes-v2', () => {
target: TARGET_PACKAGE_INSTALL,
},
],
executor: 'nx:noop',
options: { environmentRoot: 'tmp/environments/lib-a-e2e' },
executor: 'nx:run-commands',
options: {
environmentRoot: 'tmp/environments/lib-a-e2e',
command:
'echo "dependencies installed for tmp/environments/lib-a-e2e"',
},
}),
[TARGET_ENVIRONMENT_SETUP]: expect.objectContaining({
cache: true,
executor: '@push-based/nx-verdaccio:env-setup',
options: {
environmentRoot: 'tmp/environments/lib-a-e2e',
},
options: {},
inputs: [
'{projectRoot}/project.json',
{
Expand Down Expand Up @@ -259,7 +258,12 @@ describe('nx-verdaccio plugin create-nodes-v2', () => {
}),
[TARGET_ENVIRONMENT_E2E]: expect.objectContaining({
executor: '@push-based/nx-verdaccio:env-teardown',
dependsOn: ['e2e'],
dependsOn: [
{
params: 'forward',
target: 'e2e',
},
],
}),
[TARGET_ENVIRONMENT_TEARDOWN]: expect.objectContaining({
executor: '@push-based/nx-verdaccio:env-teardown',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
VERDACCIO_REGISTRY_JSON,
} from './constants';
import { runSingleExecutor } from '../../internal/run-executor';
import { getEnvironmentRoot } from '../../internal/environment-root';

const VERDACCIO_TOKEN = 'Verdaccio: ';

Expand Down Expand Up @@ -179,8 +180,8 @@ export function stopVerdaccioServer(options: {
environmentRoot: string;
context: ExecutorContext;
}): Promise<void> {
const { projectName, verbose, context, configuration, environmentRoot } =
options;
const { projectName, verbose, context, configuration } = options;
const environmentRoot = getEnvironmentRoot(context, options);
return runSingleExecutor(
{
project: projectName,
Expand Down
9 changes: 7 additions & 2 deletions projects/nx-verdaccio/src/executors/env-setup/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
} from '../../plugin/targets/environment.targets';
import { runSingleExecutor } from '../../internal/run-executor';
import { rm } from 'node:fs/promises';
import { options } from 'yargs';
import { getEnvironmentRoot } from '../../internal/environment-root';

export type ExecutorOutput = {
success: boolean;
Expand All @@ -27,8 +29,11 @@ export default async function runSetupEnvironmentExecutor(
context: ExecutorContext
) {
const { configurationName: configuration, projectName } = context;
const { verbose, environmentRoot, keepServerRunning } =
terminalAndExecutorOptions;
const { verbose, keepServerRunning } = terminalAndExecutorOptions;
const environmentRoot = getEnvironmentRoot(
context,
terminalAndExecutorOptions
);
try {
await runSingleExecutor(
{
Expand Down
12 changes: 5 additions & 7 deletions projects/nx-verdaccio/src/plugin/targets/environment.targets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ export function verdaccioTargets(
[TARGET_ENVIRONMENT_VERDACCIO_START]: {
// @TODO: consider using the executor function directly to reduce the number of targets
// https://github.com/nrwl/nx/blob/b73f1e0e0002c55fc0bacaa1557140adb9eec8de/packages/js/src/executors/verdaccio/verdaccio.impl.ts#L22
outputs: [
`{options.environmentRoot}/${VERDACCIO_STORAGE_DIR}`,
],
outputs: [`{options.environmentRoot}/${VERDACCIO_STORAGE_DIR}`],
executor: '@nx/js:verdaccio',
options: {
config: '.verdaccio/config.yml',
Expand Down Expand Up @@ -112,7 +110,7 @@ export function getEnvTargets(
const environmentRoot = join(environmentsDir, envProject);
return {
[TARGET_ENVIRONMENT_BOOTSTRAP]: {
executor: `${PACKAGE_NAME}:${EXECUTOR_ENVIRONMENT_BOOTSTRAP}`
executor: `${PACKAGE_NAME}:${EXECUTOR_ENVIRONMENT_BOOTSTRAP}`,
},
// intermediate task just here to execute dependent pkg-install tasks with the correct environmentProject
[TARGET_ENVIRONMENT_INSTALL]: {
Expand All @@ -125,7 +123,7 @@ export function getEnvTargets(
],
options: { environmentRoot },
// This is here to make it appear in the graph in older nx versions (otherwise it is filtered out)
command: `echo "dependencies installed for ${environmentRoot}"`
command: `echo "dependencies installed for ${environmentRoot}"`,
},
// runs env-bootstrap-env, install-env and stop-verdaccio
[TARGET_ENVIRONMENT_SETUP]: {
Expand Down Expand Up @@ -153,15 +151,15 @@ export function getEnvTargets(
'{options.environmentRoot}/node_modules',
],
cache: true,
executor: `${PACKAGE_NAME}:${EXECUTOR_ENVIRONMENT_SETUP}`
executor: `${PACKAGE_NAME}:${EXECUTOR_ENVIRONMENT_SETUP}`,
},
[TARGET_ENVIRONMENT_TEARDOWN]: {
executor: `${PACKAGE_NAME}:${EXECUTOR_ENVIRONMENT_TEARDOWN}`,
},
[TARGET_ENVIRONMENT_E2E]: {
dependsOn: targetNames.map((targetName) => ({
target: targetName,
params: 'forward'
params: 'forward',
})),
executor: `${PACKAGE_NAME}:${EXECUTOR_ENVIRONMENT_TEARDOWN}`,
},
Expand Down

0 comments on commit 3818fba

Please sign in to comment.