Skip to content

Commit

Permalink
fix: fix test imports
Browse files Browse the repository at this point in the history
  • Loading branch information
BioPhoton committed Sep 24, 2024
1 parent bf430f3 commit b6d651a
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 32 deletions.
2 changes: 1 addition & 1 deletion nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
{
"plugin": "./projects/build-env/src/plugin/build-env.plugin.ts",
"options": {
"publishable": {
"packages": {
"filterByTags": ["publishable"]
},
"environments": {
Expand Down
30 changes: 19 additions & 11 deletions projects/build-env/src/plugin/build-env.plugin.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import {type CreateNodes, type ProjectConfiguration, readJsonFile,} from '@nx/devkit';
import {dirname, join} from 'node:path';
import {getEnvTargets, isEnvProject, updateEnvTargetNames, verdaccioTargets} from "./targets/environment.targets";
import {getPkgTargets, isPkgProject} from "./targets/package.targets";
import {BuildEnvPluginCreateNodeOptions} from "./schema";
import {normalizeCreateNodesOptions} from "./normalize-create-nodes-options";
import {
type CreateNodes,
type ProjectConfiguration,
readJsonFile,
} from '@nx/devkit';
import { dirname, join } from 'node:path';
import {
getEnvTargets,
isEnvProject,
updateEnvTargetNames,
verdaccioTargets,
} from './targets/environment.targets';
import { getPkgTargets, isPkgProject } from './targets/package.targets';
import type { BuildEnvPluginCreateNodeOptions } from './schema';
import { normalizeCreateNodesOptions } from './normalize-create-nodes-options';

export const createNodes: CreateNodes = [
'**/project.json',
(projectConfigurationFile: string, opt: BuildEnvPluginCreateNodeOptions) => {
const {environments, publishable} = normalizeCreateNodesOptions(opt);
const { environments, packages } = normalizeCreateNodesOptions(opt);

const projectConfiguration: ProjectConfiguration = readJsonFile(
join(process.cwd(), projectConfigurationFile)
Expand All @@ -24,7 +33,7 @@ export const createNodes: CreateNodes = [

if (
!isEnvProject(projectConfiguration, environments) &&
!isPkgProject(projectConfiguration, publishable)
!isPkgProject(projectConfiguration, packages)
) {
return {};
}
Expand All @@ -42,16 +51,15 @@ export const createNodes: CreateNodes = [
// bootstrap-env, setup-env, install-env (intermediate target to run dependency targets)
...getEnvTargets(projectConfiguration, environments),
// adjust targets to run setup-env
...updateEnvTargetNames(projectConfiguration, environments)
...updateEnvTargetNames(projectConfiguration, environments),
}),
// === package targets ===
// npm-publish, npm-install
...(isPkgProject(projectConfiguration, publishable) &&
...(isPkgProject(projectConfiguration, packages) &&
getPkgTargets()),
},
},
},
};
},
];

17 changes: 10 additions & 7 deletions projects/build-env/src/plugin/normalize-create-nodes-options.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import {
import type {
BuildEnvEnvironmentsOptions,
BuildEnvPluginCreateNodeOptions,
BuildEnvPublishingOptions
} from "./schema";
import {DEFAULT_ENVIRONMENTS_OUTPUT_DIR, DEFAULT_OPTION_ENVIRONMENT_TARGET_NAMES} from "./constants";
BuildEnvPackagesOptions,
} from './schema';
import {
DEFAULT_ENVIRONMENTS_OUTPUT_DIR,
DEFAULT_OPTION_ENVIRONMENT_TARGET_NAMES,
} from './constants';

export type NormalizedCreateNodeOptions = {
environments: Omit<
Expand All @@ -13,15 +16,15 @@ export type NormalizedCreateNodeOptions = {
Required<
Pick<BuildEnvEnvironmentsOptions, 'targetNames' | 'environmentsDir'>
>;
publishable: BuildEnvPublishingOptions;
packages: BuildEnvPackagesOptions;
};

export function normalizeCreateNodesOptions(
options: BuildEnvPluginCreateNodeOptions
): NormalizedCreateNodeOptions {
const {
environments: givenEnvironments = {},
publishable: givenPublishable = {},
packages: givenPublishable = {},
} = options ?? {};

if (
Expand All @@ -39,7 +42,7 @@ export function normalizeCreateNodesOptions(
targetNames: [DEFAULT_OPTION_ENVIRONMENT_TARGET_NAMES],
...givenEnvironments,
},
publishable: {
packages: {
...givenPublishable,
},
};
Expand Down
4 changes: 2 additions & 2 deletions projects/build-env/src/plugin/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ export type BuildEnvEnvironmentsOptions = {
targetNames?: string[];
filterByTags?: string[];
};
export type BuildEnvPublishingOptions = {
export type BuildEnvPackagesOptions = {
environmentsDir?: string;
targetNames?: string[];
filterByTags?: string[];
};
export type BuildEnvPluginCreateNodeOptions = {
environments?: BuildEnvEnvironmentsOptions;
publishable?: BuildEnvPublishingOptions;
packages?: BuildEnvPackagesOptions;
};
16 changes: 8 additions & 8 deletions projects/build-env/src/plugin/targets/environment.targets.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type {ProjectConfiguration, TargetConfiguration} from "@nx/devkit";
import {NormalizedCreateNodeOptions} from "../normalize-create-nodes-options";
import {join} from "node:path";
import {DEFAULT_NPM_INSTALL_TARGET} from "./package.targets";
import {BuildEnvEnvironmentsOptions} from "../schema";
import type {StartVerdaccioOptions} from "../../executors/bootstrap/verdaccio-registry";
import {uniquePort} from "../../executors/bootstrap/unique-port";
import {VERDACCIO_REGISTRY_JSON} from "../../executors/bootstrap/constants";
import type { ProjectConfiguration, TargetConfiguration } from '@nx/devkit';
import type { NormalizedCreateNodeOptions } from '../normalize-create-nodes-options';
import { join } from 'node:path';
import { DEFAULT_NPM_INSTALL_TARGET } from './package.targets';
import type { BuildEnvEnvironmentsOptions } from '../schema';
import type { StartVerdaccioOptions } from '../../executors/bootstrap/verdaccio-registry';
import { uniquePort } from '../../executors/bootstrap/unique-port';
import { VERDACCIO_REGISTRY_JSON } from '../../executors/bootstrap/constants';

export const DEFAULT_START_VERDACCIO_TARGET = 'build-env-verdaccio-start';
export const DEFAULT_BOOTSTRAP_TARGET = 'build-env-env-bootstrap';
Expand Down
6 changes: 3 additions & 3 deletions projects/build-env/src/plugin/targets/package.targets.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type {ProjectConfiguration, TargetConfiguration} from "@nx/devkit";
import {NormalizedCreateNodeOptions} from "../normalize-create-nodes-options";
import type { ProjectConfiguration, TargetConfiguration } from '@nx/devkit';
import type { NormalizedCreateNodeOptions } from '../normalize-create-nodes-options';

export const DEFAULT_NPM_INSTALL_TARGET = 'build-env-release-install';
export const DEFAULT_NPM_PUBLISH_TARGET = 'build-env-release-publish';

export function isPkgProject(
projectConfig: ProjectConfiguration,
options: NormalizedCreateNodeOptions['publishable']
options: NormalizedCreateNodeOptions['packages']
): boolean {
const { projectType, tags: existingTags = [] } = projectConfig;
const { filterByTags: publishableTagFilters } = options;
Expand Down

0 comments on commit b6d651a

Please sign in to comment.