Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
BioPhoton committed Dec 18, 2024
1 parent 8461eef commit b240bba
Show file tree
Hide file tree
Showing 11 changed files with 2,369 additions and 1,460 deletions.
3 changes: 1 addition & 2 deletions e2e/nx-verdaccio-e2e/fixtures/basic-nx-workspace.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { join } from 'node:path';

export const REPO_NAME = 'nx-ts-repo';
export const REPO_NAME = '__nx-ts-repo__';
export const envRoot = `tmp/environments/${process.env['NX_TASK_TARGET_PROJECT']}`;
export const workspaceRoot = join(envRoot, '__test__', REPO_NAME);
export const projectName = 'pkg';
export const e2eProjectName = 'pkg-e2e';
11 changes: 9 additions & 2 deletions e2e/nx-verdaccio-e2e/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@
"sourceRoot": "projects/nx-verdaccio-e2e/test",
"projectType": "application",
"tags": ["type:e2e", "type:e2e-vi", "npm-env"],
"implicitDependencies": ["nx-verdaccio"],
"implicitDependencies": ["@push-based/nx-verdaccio"],
"targets": {
"lint": {},
"e2e": {
"nxv-env-setup": {
"cache": false,
"options": {
"skipInstall": true,
"postScript": "npx tsx --tsconfig e2e/nx-verdaccio-e2e/tsconfig.spec.json e2e/nx-verdaccio-e2e/setup/exec-global-setup.ts"
}
},
"_e2e": {
"executor": "@nx/vite:test",
"inputs": ["default", "^production"],
"outputs": ["{options.reportsDirectory}"],
Expand Down
85 changes: 65 additions & 20 deletions e2e/nx-verdaccio-e2e/setup/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,24 @@ import {
objectToCliArgs,
updateJson,
} from '@push-based/test-utils';
import { dirname, join } from 'node:path';
import { copyFile, mkdir } from 'node:fs/promises';
import {
logger,
NxJsonConfiguration,
PluginConfiguration,
TargetConfiguration,
} from '@nx/devkit';
import { PackageJson } from 'nx/src/utils/package-json';
import {copyFile, lstat, mkdir, readdir} from 'fs/promises';
import {join} from 'path';
import {dirname, join} from 'node:path';
import {copyFile, mkdir, symlink, readlink} from 'node:fs/promises';
import {logger, NxJsonConfiguration, PluginConfiguration, TargetConfiguration,} from '@nx/devkit';
import {PackageJson} from 'nx/src/utils/package-json';

export async function setup({
envRoot,
projectName,
repoName,
}: {
envRoot,
projectName,
repoName,
}: {
envRoot: string;
repoName: string;
projectName: string;
}) {
await mkdir(envRoot, { recursive: true });
// dedupe packages because symlink copy problems
await mkdir(envRoot, {recursive: true});
// setup nx environment for e2e tests
logger.info(`Created nx workspace under ${envRoot}`);
await executeProcess({
Expand Down Expand Up @@ -100,30 +98,41 @@ export async function setup({
);

logger.info(`Install @push-based/nx-verdaccio`);
await executeProcess({
command: 'npm',
args: objectToCliArgs({
_: ['install', '@push-based/nx-verdaccio'],
save: true,
}),
cwd: envRoot,
verbose: true,
});
await mkdir(
join(
getTestEnvironmentRoot(projectName),
DEFAULT_TEST_FIXTURE_DIST,
repoName
),
{ recursive: true }
{recursive: true}
);
await copyFile(
join(getTestEnvironmentRoot(projectName), '.npmrc'),
join(envRoot, '.npmrc')
);

await executeProcess({
command: 'npm',
args: objectToCliArgs({
_: ['install', '@push-based/nx-verdaccio'],
save: true,
_: ['dedupe']
}),
cwd: envRoot,
verbose: true,
cwd: dirname(envRoot),
});


}

export async function registerNxVerdaccioPlugin(envRoot: string) {
export async function registerNxVerdaccioPlugin(envRoot: string, options?: PluginConfiguration) {
logger.info(`register nx-verdaccio plugin`);
await updateJson<NxJsonConfiguration>(join(envRoot, 'nx.json'), (json) =>
registerPluginInNxJson(json, {
Expand All @@ -133,11 +142,12 @@ export async function registerNxVerdaccioPlugin(envRoot: string) {
targetNames: ['e2e'],
},
},
...options
})
);
}

function registerPluginInNxJson(
export function registerPluginInNxJson(
nxJson: NxJsonConfiguration,
pluginConfig: PluginConfiguration
) {
Expand All @@ -162,3 +172,38 @@ function updatePackageJsonNxTargets(
},
};
}


/**
* This function avoids issues with symlinks and other edge cases.
*
*/
export async function copyDirectory(src: string, dest: string, exclude: string[] = []) {
// Ensure the destination directory exists
await mkdir(dest, {recursive: true});

// Read the contents of the source directory
const entries = await readdir(src, {withFileTypes: true});

for (const entry of entries) {
const srcPath = join(src, entry.name);
const destPath = join(dest, entry.name);

// Skip excluded directories or files
if (exclude.includes(entry.name)) continue;

const stats = await lstat(srcPath);

if (stats.isSymbolicLink()) {
// Handle symbolic links if necessary (copy the link itself or resolve it)
const linkTarget = await readlink(srcPath);
await symlink(linkTarget, destPath);
} else if (stats.isDirectory()) {
// Recursively copy directories
await copyDirectory(srcPath, destPath, exclude);
} else if (stats.isFile()) {
// Copy files
await copyFile(srcPath, destPath);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,83 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`in a fresh Nx workspace > 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,
},
}
`;

exports[`in a fresh Nx workspace > with nx-verdaccio plugin installed > 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,
},
}
`;

exports[`nx-verdaccio plugin create-nodes-v2 > should add package targets to library project 1`] = `
{
"nxv-pkg-install": {
Expand Down
Loading

0 comments on commit b240bba

Please sign in to comment.