Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move bootstrap out of setup target #54

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ jobs:
- name: Install dependencies
run: npm i
- name: E2E test affected projects
run: npx nx affected -t nxv-e2e --exclude="tag:type:example"
run: npx nx affected -t nxv-e2e --exclude="tag:type:example" --verbose
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,13 @@ exports[`nx-verdaccio plugin create-nodes-v2 > should add environment targets to
"parallelism": true,
},
"nxv-env-setup": {
"cache": true,
"configurations": {},
"dependsOn": [
{
"params": "forward",
"target": "nxv-env-bootstrap",
},
],
"executor": "@push-based/nx-verdaccio:env-setup",
"inputs": [
"{projectRoot}/project.json",
Expand Down Expand Up @@ -93,9 +98,6 @@ exports[`nx-verdaccio plugin create-nodes-v2 > should add environment targets to
"projectName": "lib-a-e2e",
"storage": "tmp/environments/lib-a-e2e/storage",
},
"outputs": [
"{options.environmentRoot}/storage",
],
"parallelism": true,
},
"nxv-verdaccio-stop": {
Expand Down
8 changes: 6 additions & 2 deletions e2e/nx-verdaccio-e2e/test/plugin-create-nodes.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,17 @@ describe('nx-verdaccio plugin create-nodes-v2', () => {
],
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,
dependsOn: [
{
params: 'forward',
target: TARGET_ENVIRONMENT_BOOTSTRAP,
},
],
executor: '@push-based/nx-verdaccio:env-setup',
options: {},
inputs: [
Expand Down
25 changes: 0 additions & 25 deletions projects/nx-verdaccio/src/executors/env-setup/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@ import {
import type { SetupEnvironmentExecutorOptions } from './schema';
import { VERDACCIO_REGISTRY_JSON } from '../env-bootstrap/constants';
import {
TARGET_ENVIRONMENT_BOOTSTRAP,
TARGET_ENVIRONMENT_INSTALL,
} 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 = {
Expand All @@ -34,28 +31,6 @@ export default async function runSetupEnvironmentExecutor(
context,
terminalAndExecutorOptions
);
try {
await runSingleExecutor(
{
project: projectName,
target: TARGET_ENVIRONMENT_BOOTSTRAP,
configuration,
},
{
...terminalAndExecutorOptions,
// we always want to keep the server running as in the next step we install packages
// the `keepServerRunning` passed in `options` is only used to stop the server after the installation (or keep it running for debug reasons)
keepServerRunning: true,
},
context
);
} catch (error) {
logger.error(error.message);
return {
success: false,
command: `Failed executing target ${TARGET_ENVIRONMENT_BOOTSTRAP}\n ${error.message}`,
};
}

try {
await executeProcess({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('runSetupEnvironmentExecutor', () => {
.mockResolvedValueOnce(
new MockAsyncIterableIterator<{ success: boolean; command: string }>({
success: true,
command: 'Bootstraped environemnt successfully.',
command: 'Bootstrapped environment successfully.',
})
)
.mockResolvedValueOnce(
Expand Down Expand Up @@ -95,18 +95,7 @@ describe('runSetupEnvironmentExecutor', () => {
cwd: '/test',
});

expect(runExecutorSpy).toHaveBeenCalledTimes(2);
expect(runExecutorSpy).toHaveBeenCalledWith(
{
configuration: undefined,
project: projectName,
target: TARGET_ENVIRONMENT_BOOTSTRAP,
},
{
keepServerRunning: true,
},
context
);
expect(runExecutorSpy).toHaveBeenCalledTimes(1);
expect(runExecutorSpy).toHaveBeenCalledWith(
{
configuration: undefined,
Expand All @@ -121,36 +110,6 @@ describe('runSetupEnvironmentExecutor', () => {
);
});

it('should catch error cause by runBootstrapEnvironment', async () => {
runExecutorSpy.mockRejectedValueOnce(
new Error('Error in runBootstrapEnvironment')
);

await expect(
runSetupEnvironmentExecutor(
{},
{
cwd: 'test',
isVerbose: false,
root: 'tmp/environments/test',
projectName: 'my-lib-e2e',
projectsConfigurations: {
version: 2,
projects: {
'my-lib': {
root: 'e2e/my-lib-e2e',
},
},
},
}
)
).resolves.toStrictEqual({
success: false,
command:
'Failed executing target nxv-env-bootstrap\n Error in runBootstrapEnvironment',
});
});

it('should keep server running if keepServerRunning is passed', async () => {
runExecutorSpy
.mockResolvedValueOnce(
Expand Down Expand Up @@ -220,19 +179,7 @@ describe('runSetupEnvironmentExecutor', () => {
cwd: '/test',
});

expect(runExecutorSpy).toHaveBeenCalledTimes(1);
expect(runExecutorSpy).toHaveBeenCalledWith(
{
configuration: undefined,
project: 'my-lib-e2e',
target: TARGET_ENVIRONMENT_BOOTSTRAP,
},
expect.objectContaining({
environmentRoot: 'tmp/environments/my-lib-e2e',
keepServerRunning: true,
}),
context
);
expect(runExecutorSpy).toHaveBeenCalledTimes(0);

expect(devkit.logger.info).toHaveBeenCalledTimes(1);
expect(devkit.logger.info).toHaveBeenCalledWith(
Expand Down
3 changes: 3 additions & 0 deletions projects/nx-verdaccio/src/plugin/nx-verdaccio.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ export const createNodesV2: CreateNodesV2<NxVerdaccioCreateNodeOptions> = [
},
];

/**
* @deprecated Use `createNodesV2` form instead.
*/
export const createNodes: CreateNodes = [
PROJECT_JSON_FILE_GLOB,
(
Expand Down
11 changes: 8 additions & 3 deletions projects/nx-verdaccio/src/plugin/targets/environment.targets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export function getEnvTargets(
[TARGET_ENVIRONMENT_BOOTSTRAP]: {
executor: `${PACKAGE_NAME}:${EXECUTOR_ENVIRONMENT_BOOTSTRAP}`,
},
// intermediate task just here to execute dependent pkg-install tasks with the correct environmentProject
// intermediate task called in enc-setup to execute dependent pkg-install tasks with the correct environmentProject
[TARGET_ENVIRONMENT_INSTALL]: {
dependsOn: [
{
Expand All @@ -121,12 +121,17 @@ export function getEnvTargets(
params: 'forward',
},
],
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}"`,
},
// runs env-bootstrap-env, install-env and stop-verdaccio
// runs install-env and stop-verdaccio
[TARGET_ENVIRONMENT_SETUP]: {
dependsOn: [
{
target: TARGET_ENVIRONMENT_BOOTSTRAP,
params: 'forward',
},
],
// list of inputs that all subsequent tasks depend on
inputs: [
'{projectRoot}/project.json',
Expand Down
Loading