Skip to content

Commit

Permalink
remove unused code, fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
BioPhoton committed Sep 9, 2024
1 parent 23eae7f commit c3872c7
Show file tree
Hide file tree
Showing 25 changed files with 346 additions and 324 deletions.
14 changes: 4 additions & 10 deletions e2e-examples/cli-e2e-env/setup/global-setup.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { executeProcess, objectToCliArgs } from '@org/test-utils';
import { NpmTestEnvResult, VerdaccioExecuterOptions } from '@org/tools-utils';
import { NpmTestEnvResult } from '@org/tools-utils';
import { join } from 'node:path';
import { rm } from 'node:fs/promises';
import { readJsonFile } from '@nx/devkit';
Expand All @@ -21,13 +21,7 @@ export async function setup() {
// start registry
await executeProcess({
command: 'nx',
args: objectToCliArgs<
Partial<
VerdaccioExecuterOptions & {
_: string[];
}
>
>({
args: objectToCliArgs({
_: ['env-setup-npm-env', projectName ?? ''],
verbose: isVerbose,
clear: true,
Expand All @@ -37,12 +31,12 @@ export async function setup() {
shell: true,
});

const workspaceRoot = join('tmp', 'npm-env', projectName);
const workspaceRoot = join('tmp', 'environments', projectName);
activeRegistry = await readJsonFile(
join(workspaceRoot, 'verdaccio-registry.json')
);
const { registry } = activeRegistry;
stopRegistry = () => process.kill(Number(registry.pid));
stopRegistry = () => process.kill(Number(registry?.pid));

// package publish all projects
await executeProcess({
Expand Down
47 changes: 47 additions & 0 deletions e2e-examples/cli-e2e-env/tooling/bin/setup-npm-env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import yargs, { Options } from 'yargs';
import {
setupNpmEnv,
StartVerdaccioAndSetupEnvOptions,
} from '@org/tools-utils';

const isVerbose: boolean =
process.env['NX_VERBOSE_LOGGING'] === 'true' ?? false;

const args = yargs(process.argv.slice(2))
.version(false)
.options({
projectName: {
type: 'string',
description: 'Project name',
demandOption: true,
},
workspaceRoot: {
type: 'string',
description: 'Location of test environment',
},
verbose: {
type: 'boolean',
description: 'Verbose logging',
default: isVerbose,
},
targetName: {
type: 'string',
description: 'Verbose logging',
default: isVerbose,
},
port: {
type: 'number',
},
} satisfies Partial<Record<keyof StartVerdaccioAndSetupEnvOptions, Options>>)
.parse() as StartVerdaccioAndSetupEnvOptions;

(async () => {
const workspaceRoot = args.workspaceRoot;
if (workspaceRoot == null) {
throw new Error('Workspace root required.');
}
await setupNpmEnv({
...args,
workspaceRoot,
});
})();
21 changes: 6 additions & 15 deletions e2e-examples/cli-e2e-env/tooling/env.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { dirname, join, relative } from 'node:path';
import type { ProjectConfiguration } from 'nx/src/config/workspace-json-project-json';
import { getBuildOutputPathFromBuildTarget } from '@org/tools-utils';

const tmpNpmEnv = join('tmp', 'npm-env');
const tmpEnv = join('tmp', 'environments');

export const createNodes: CreateNodes = [
'**/project.json',
Expand All @@ -22,15 +22,6 @@ export const createNodes: CreateNodes = [
throw new Error('Project name required');
}

// only execute for the -env example projects e.g. `cli-e2e-env`, `e2e-models-env`
if (!projectName.endsWith('-env')) {
return {
projects: {
[root]: {},
},
};
}

const tags = projectConfiguration?.tags ?? [];
const isPublishable = tags.some((target) => target === 'publishable');
const isNpmEnv = tags.some((target) => target === 'npm-env');
Expand Down Expand Up @@ -67,11 +58,11 @@ function verdaccioTargets(
},
'env-setup-npm-env': {
command:
'tsx --tsconfig=tools/tsconfig.tools.json tools/tools-utils/src/bin/setup-npm-env.ts',
'tsx --tsconfig=e2e-examples/cli-e2e-env/tsconfig.tools.json e2e-examples/cli-e2e-env/tooling/bin/setup-npm-env.ts',
options: {
projectName,
targetName: 'env-start-verdaccio',
workspaceRoot: join(tmpNpmEnv, projectName),
workspaceRoot: join(tmpEnv, projectName),
location: 'none',
},
},
Expand All @@ -95,16 +86,16 @@ function npmTargets(
'env-npm-publish': {
command: `npm publish --userconfig=${relativeFromPath(
outputPath
)}/${tmpNpmEnv}/{args.envProjectName}/.npmrc`,
)}/${tmpEnv}/{args.envProjectName}/.npmrc`,
options: {
cwd: outputPath,
envProjectName: `${projectName}-npm-env`,
},
},
'env-npm-install': {
command: `npm install --no-fund --no-shrinkwrap --save ${packageName}@{args.pkgVersion} --prefix=${tmpNpmEnv}/{args.envProjectName} --userconfig=${relativeFromPath(
command: `npm install --no-fund --no-shrinkwrap --save ${packageName}@{args.pkgVersion} --prefix=${tmpEnv}/{args.envProjectName} --userconfig=${relativeFromPath(
outputPath
)}/${tmpNpmEnv}/{args.envProjectName}/.npmrc`,
)}/${tmpEnv}/{args.envProjectName}/.npmrc`,
options: {
pkgVersion,
envProjectName: `${projectName}-npm-env`,
Expand Down
10 changes: 1 addition & 9 deletions e2e-examples/cli-e2e-graph/tooling/graph.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,6 @@ export const createNodes: CreateNodes = [
throw new Error('Project name required');
}

// only execute for the -graph example projects e.g. `cli-e2e-graph`, `e2e-models-graph`
if (!projectName.endsWith('-graph')) {
return {
projects: {
[root]: {},
},
};
}

const tags = projectConfiguration?.tags ?? [];
const isPublishable = tags.some((target) => target === 'publishable');
const isNpmEnv = tags.some((target) => target === 'npm-env');
Expand Down Expand Up @@ -87,6 +78,7 @@ function verdaccioTargets(
},
],
command: 'echo Dependencies installed!',
options: {},
},
};
}
Expand Down
39 changes: 18 additions & 21 deletions e2e-examples/cli-e2e-original/setup/global-setup.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
import { rm } from 'node:fs/promises';
import { executeProcess, objectToCliArgs } from '@org/test-utils';
import {
configureRegistry,
RegistryResult,
startVerdaccioServer,
unconfigureRegistry,
VercaddioServerResult,
} from '@org/tools-utils';
import { rm } from 'node:fs/promises';

const isVerbose = true; // process.env.NX_VERBOSE_LOGGING === 'true' ?? false;

let activeRegistry: VercaddioServerResult;
let stopRegistry: () => void;
const projectName = process.env['NX_TASK_TARGET_PROJECT'];

export async function setup() {
// start Verdaccio server and setup local registry storage
const { stop, registry } = await startVerdaccioServer({
if (projectName == null) {
throw new Error('Project name required.');
}

const registryResult = await startVerdaccioServer({
targetName: 'original-local-registry',
verbose: isVerbose,
clear: true,
});
activeRegistry = registry;
stopRegistry = stop;

// configure env with verdaccio registry as default
// exec commands:
// - `npm config set registry "${url}"`
// - `npm config set //${host}:${port}/:_authToken "secretVerdaccioToken"`
configureRegistry(registry, isVerbose);
configureRegistry(registryResult.registry, isVerbose);

// package publish all projects
await executeProcess({
Expand All @@ -52,9 +47,13 @@ export async function setup() {
}),
verbose: isVerbose,
});

// @TODO figure out why named exports don't work https://vitest.dev/config/#globalsetup
return () => teardownSetup(registryResult);
}

export async function teardown() {
export async function teardownSetup({ registry, stop }: RegistryResult) {
console.info(`Teardown ${projectName}`);
// uninstall all projects
await executeProcess({
command: 'nx',
Expand All @@ -64,11 +63,9 @@ export async function teardown() {
}),
verbose: isVerbose,
});
stopRegistry();
// exec commands:
// - `npm config delete //${host}:${port}/:_authToken`
// - `npm config delete registry`
unconfigureRegistry(activeRegistry, isVerbose);
await rm(activeRegistry.storage, { recursive: true, force: true });

stop();
unconfigureRegistry(registry, isVerbose);
await rm(registry.storage, { recursive: true, force: true });
await rm('local-registry', { recursive: true, force: true });
}
8 changes: 4 additions & 4 deletions e2e-examples/cli-e2e-original/tooling/original.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ export const createNodes: CreateNodes = [
(tag) => tag === 'publishable'
);


return {
projects: {
[root]: {
targets: {
...(isRoot && verdaccioTargets()),
...(isPublishable && npmTargets({ ...projectConfiguration, root, name: projectName })),
...(isPublishable &&
npmTargets({ ...projectConfiguration, root, name: projectName })),
},
},
},
Expand All @@ -45,7 +45,7 @@ function verdaccioTargets(): Record<string, TargetConfiguration> {
options: {
config: '.verdaccio/config.yml',
storage: `tmp/local-registry/storage`,
port: 4200
port: 4200,
},
},
};
Expand All @@ -68,7 +68,7 @@ function npmTargets(
},
},
'original-npm-install': {
command: `npm install -D ${packageName}@{args.pkgVersion}`,
command: `npm install -D --no-fund --no-package-lock ${packageName}@{args.pkgVersion}`,
options: {
pkgVersion,
},
Expand Down
5 changes: 3 additions & 2 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@
}
},
"plugins": [
"./tooling/build-env/src/plugin/verdaccio-env.plugin.ts",
"./e2e-examples/cli-e2e-original/tooling/original.plugin.ts"
"./e2e-examples/cli-e2e-original/tooling/original.plugin.ts",
"./e2e-examples/cli-e2e-env/tooling/env.plugin.ts",
"./tooling/build-env/src/plugin/verdaccio-env.plugin.ts"
],
"release": {
"version": {
Expand Down
Loading

0 comments on commit c3872c7

Please sign in to comment.