Skip to content

Commit

Permalink
chore(core): rename loaded plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz committed Apr 12, 2024
1 parent b3b1f45 commit 3a3e95c
Show file tree
Hide file tree
Showing 19 changed files with 48 additions and 43 deletions.
1 change: 1 addition & 0 deletions .nx/workflows/agents.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ launch-templates:
GIT_COMMITTER_NAME: Test
SELECTED_PM: 'pnpm'
NPM_CONFIG_PREFIX: '/home/workflows/.npm-global'
NX_VERBOSE_LOGGING: true
init-steps:
- name: Checkout
uses: 'nrwl/nx-cloud-workflows/v3.6/workflow-steps/checkout/main.yaml'
Expand Down
4 changes: 2 additions & 2 deletions packages/devkit/src/utils/add-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const {
} = nx;

// eslint-disable-next-line @typescript-eslint/no-restricted-imports
import { LoadedNxPlugin } from 'nx/src/devkit-internals';
import { RunnableLoadedNxPlugin } from 'nx/src/project-graph/plugins/internal-api';

import type { ConfigurationResult } from 'nx/src/project-graph/utils/project-configuration-utils';

Expand Down Expand Up @@ -57,7 +57,7 @@ export async function addPlugin<PluginOptions>(
global.NX_GRAPH_CREATION = true;
projConfigs = await retrieveProjectConfigurations(
[
new LoadedNxPlugin(
new RunnableLoadedNxPlugin(
{
name: pluginName,
createNodes: createNodesTuple,
Expand Down
4 changes: 2 additions & 2 deletions packages/nx/src/daemon/server/plugins.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { readNxJson } from '../../config/nx-json';
import {
LoadedNxPlugin,
RunnableLoadedNxPlugin,
loadNxPlugins,
} from '../../project-graph/plugins/internal-api';
import { workspaceRoot } from '../../utils/workspace-root';

let loadedPlugins: Promise<LoadedNxPlugin[]>;
let loadedPlugins: Promise<RunnableLoadedNxPlugin[]>;
let cleanup: () => void;

export async function getPlugins() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { serverLogger } from './logger';
import { NxWorkspaceFilesExternals } from '../../native';
import { ConfigurationResult } from '../../project-graph/utils/project-configuration-utils';
import { DaemonProjectGraphError } from '../daemon-project-graph-error';
import { LoadedNxPlugin } from '../../project-graph/plugins/internal-api';
import { RunnableLoadedNxPlugin } from '../../project-graph/plugins/internal-api';
import { getPlugins } from './plugins';
import { ProjectConfigurationsError } from '../../project-graph/error-types';

Expand Down Expand Up @@ -211,7 +211,7 @@ async function processCollectedUpdatedAndDeletedFiles(
}

async function processFilesAndCreateAndSerializeProjectGraph(
plugins: LoadedNxPlugin[]
plugins: RunnableLoadedNxPlugin[]
): Promise<SerializedProjectGraph> {
try {
performance.mark('hash-watched-changes-start');
Expand Down
2 changes: 1 addition & 1 deletion packages/nx/src/devkit-internals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ export {
findProjectForPath,
} from './project-graph/utils/find-project-for-path';
export { retrieveProjectConfigurations } from './project-graph/utils/retrieve-workspace-files';
export { LoadedNxPlugin } from './project-graph/plugins/internal-api';
export { RunnableLoadedNxPlugin } from './project-graph/plugins/internal-api';
export { registerTsProject } from './plugins/js/utils/register';
8 changes: 4 additions & 4 deletions packages/nx/src/project-graph/build-project-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from './nx-deps-cache';
import { applyImplicitDependencies } from './utils/implicit-project-dependencies';
import { normalizeProjectNodes } from './utils/normalize-project-nodes';
import { LoadedNxPlugin } from './plugins/internal-api';
import { RunnableLoadedNxPlugin } from './plugins/internal-api';
import { isNxPluginV1, isNxPluginV2 } from './plugins/utils';
import { CreateDependenciesContext } from './plugins';
import { getRootTsConfigPath } from '../plugins/js/utils/typescript';
Expand Down Expand Up @@ -66,7 +66,7 @@ export async function buildProjectGraphUsingProjectFileMap(
allWorkspaceFiles: FileData[],
rustReferences: NxWorkspaceFilesExternals,
fileMapCache: FileMapCache | null,
plugins: LoadedNxPlugin[]
plugins: RunnableLoadedNxPlugin[]
): Promise<{
projectGraph: ProjectGraph;
projectFileMapCache: FileMapCache;
Expand Down Expand Up @@ -159,7 +159,7 @@ async function buildProjectGraphUsingContext(
ctx: CreateDependenciesContext,
cachedFileData: CachedFileData,
projectGraphVersion: string,
plugins: LoadedNxPlugin[]
plugins: RunnableLoadedNxPlugin[]
) {
performance.mark('build project graph:start');

Expand Down Expand Up @@ -252,7 +252,7 @@ function createContext(
async function updateProjectGraphWithPlugins(
context: CreateDependenciesContext,
initProjectGraph: ProjectGraph,
plugins: LoadedNxPlugin[]
plugins: RunnableLoadedNxPlugin[]
) {
let graph = initProjectGraph;
const errors: Array<ProcessDependenciesError | ProcessProjectGraphError> = [];
Expand Down
3 changes: 2 additions & 1 deletion packages/nx/src/project-graph/file-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { getDefaultPluginsSync } from '../utils/nx-plugin.deprecated';
import { minimatch } from 'minimatch';
import { CreateNodesResult } from '../devkit-exports';
import { PackageJsonProjectsNextToProjectJsonPlugin } from '../plugins/project-json/build-nodes/package-json-next-to-project-json';
import { LoadedNxPlugin } from './plugins/internal-api';
import { RunnableLoadedNxPlugin } from './plugins/internal-api';

export interface Change {
type: string;
Expand Down Expand Up @@ -173,6 +173,7 @@ export function readPackageJson(): any {
return {}; // if package.json doesn't exist
}
}

// Original Exports
export { FileData };
// TODO(17): Remove these exports
Expand Down
8 changes: 4 additions & 4 deletions packages/nx/src/project-graph/plugins/internal-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { runCreateNodesInParallel } from './utils';
import { loadNxPluginInIsolation } from './isolation';
import { loadNxPlugin, unregisterPluginTSTranspiler } from './loader';

export class LoadedNxPlugin {
export class RunnableLoadedNxPlugin {
readonly name: string;
readonly createNodes?: [
filePattern: string,
Expand Down Expand Up @@ -79,14 +79,14 @@ export type NormalizedPlugin = NxPluginV2 &
// referenced multiple times.
export const nxPluginCache: Map<
unknown,
[Promise<LoadedNxPlugin>, () => void]
[Promise<RunnableLoadedNxPlugin>, () => void]
> = new Map();

export async function loadNxPlugins(
plugins: PluginConfiguration[],
root = workspaceRoot
): Promise<[LoadedNxPlugin[], () => void]> {
const result: Promise<LoadedNxPlugin>[] = [];
): Promise<[RunnableLoadedNxPlugin[], () => void]> {
const result: Promise<RunnableLoadedNxPlugin>[] = [];

const loadingMethod =
process.env.NX_ISOLATE_PLUGINS === 'true'
Expand Down
6 changes: 3 additions & 3 deletions packages/nx/src/project-graph/plugins/isolation/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { workspaceRoot } from '../../../utils/workspace-root';
import { PluginConfiguration } from '../../../config/nx-json';
import { LoadedNxPlugin } from '../internal-api';
import { RunnableLoadedNxPlugin } from '../internal-api';
import { loadRemoteNxPlugin } from './plugin-pool';

const remotePluginCache = new Map<
string,
[Promise<LoadedNxPlugin>, () => void]
[Promise<RunnableLoadedNxPlugin>, () => void]
>();

export function loadNxPluginInIsolation(
plugin: PluginConfiguration,
root = workspaceRoot
): [Promise<LoadedNxPlugin>, () => void] {
): [Promise<RunnableLoadedNxPlugin>, () => void] {
const cacheKey = JSON.stringify(plugin);

if (remotePluginCache.has(cacheKey)) {
Expand Down
6 changes: 3 additions & 3 deletions packages/nx/src/project-graph/plugins/isolation/messaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
} from '../../../config/project-graph';
import { PluginConfiguration } from '../../../config/nx-json';
import { CreateDependenciesContext, CreateNodesContext } from '../public-api';
import { LoadedNxPlugin } from '../internal-api';
import { RunnableLoadedNxPlugin } from '../internal-api';

export interface PluginWorkerLoadMessage {
type: 'load';
Expand Down Expand Up @@ -44,7 +44,7 @@ export interface PluginWorkerCreateNodesResult {
payload:
| {
success: true;
result: Awaited<ReturnType<LoadedNxPlugin['createNodes'][1]>>;
result: Awaited<ReturnType<RunnableLoadedNxPlugin['createNodes'][1]>>;
tx: string;
}
| {
Expand All @@ -66,7 +66,7 @@ export interface PluginCreateDependenciesResult {
type: 'createDependenciesResult';
payload:
| {
dependencies: ReturnType<LoadedNxPlugin['createDependencies']>;
dependencies: ReturnType<RunnableLoadedNxPlugin['createDependencies']>;
success: true;
tx: string;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { PluginConfiguration } from '../../../config/nx-json';
// TODO (@AgentEnder): After scoped verbose logging is implemented, re-add verbose logs here.
// import { logger } from '../../utils/logger';

import { LoadedNxPlugin, nxPluginCache } from '../internal-api';
import { RunnableLoadedNxPlugin, nxPluginCache } from '../internal-api';
import { PluginWorkerResult, consumeMessage, createMessage } from './messaging';

const cleanupFunctions = new Set<() => void>();
Expand All @@ -22,7 +22,7 @@ interface PendingPromise {
export function loadRemoteNxPlugin(
plugin: PluginConfiguration,
root: string
): [Promise<LoadedNxPlugin>, () => void] {
): [Promise<RunnableLoadedNxPlugin>, () => void] {
// this should only really be true when running unit tests within
// the Nx repo. We still need to start the worker in this case,
// but its typescript.
Expand Down Expand Up @@ -61,7 +61,7 @@ export function loadRemoteNxPlugin(
cleanupFunctions.add(cleanupFunction);

return [
new Promise<LoadedNxPlugin>((res, rej) => {
new Promise<RunnableLoadedNxPlugin>((res, rej) => {
worker.on(
'message',
createWorkerHandler(worker, pendingPromises, res, rej)
Expand Down Expand Up @@ -104,7 +104,7 @@ async function shutdownPluginWorker(
function createWorkerHandler(
worker: ChildProcess,
pending: Map<string, PendingPromise>,
onload: (plugin: LoadedNxPlugin) => void,
onload: (plugin: RunnableLoadedNxPlugin) => void,
onloadError: (err?: unknown) => void
) {
let pluginName: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { consumeMessage, PluginWorkerMessage } from './messaging';
import { LoadedNxPlugin } from '../internal-api';
import { RunnableLoadedNxPlugin } from '../internal-api';
import { loadNxPlugin } from '../loader';
import { runCreateNodesInParallel } from '../utils';

global.NX_GRAPH_CREATION = true;

let plugin: LoadedNxPlugin;
let plugin: RunnableLoadedNxPlugin;

process.on('message', async (message: string) => {
consumeMessage<PluginWorkerMessage>(message, {
Expand Down
6 changes: 3 additions & 3 deletions packages/nx/src/project-graph/plugins/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
} from '../../config/nx-json';
import { retrieveProjectConfigurationsWithoutPluginInference } from '../utils/retrieve-workspace-files';
import { normalizeNxPlugin } from './utils';
import { LoadedNxPlugin } from './internal-api';
import { RunnableLoadedNxPlugin } from './internal-api';

export function readPluginPackageJson(
pluginName: string,
Expand Down Expand Up @@ -246,7 +246,7 @@ export async function loadNxPluginAsync(
pluginConfiguration: PluginConfiguration,
paths: string[],
root: string
): Promise<LoadedNxPlugin> {
): Promise<RunnableLoadedNxPlugin> {
try {
require.resolve(
typeof pluginConfiguration === 'string'
Expand Down Expand Up @@ -279,7 +279,7 @@ export async function loadNxPluginAsync(
`Load Nx Plugin: ${moduleName} - start`,
`Load Nx Plugin: ${moduleName} - end`
);
return new LoadedNxPlugin(plugin, pluginConfiguration);
return new RunnableLoadedNxPlugin(plugin, pluginConfiguration);
}

async function importPluginModule(pluginPath: string): Promise<NxPlugin> {
Expand Down
4 changes: 2 additions & 2 deletions packages/nx/src/project-graph/plugins/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { combineGlobPatterns } from '../../utils/globs';
import type { NxPluginV1 } from '../../utils/nx-plugin.deprecated';
import type {
CreateNodesResultWithContext,
LoadedNxPlugin,
RunnableLoadedNxPlugin,
NormalizedPlugin,
} from './internal-api';
import type { CreateNodesContext, NxPlugin, NxPluginV2 } from './public-api';
Expand All @@ -17,7 +17,7 @@ export function isNxPluginV2(plugin: NxPlugin): plugin is NxPluginV2 {
}

export function isNxPluginV1(
plugin: NxPlugin | LoadedNxPlugin
plugin: NxPlugin | RunnableLoadedNxPlugin
): plugin is NxPluginV1 {
return 'processProjectGraph' in plugin || 'projectFilePatterns' in plugin;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/nx/src/project-graph/project-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
ProjectConfigurationsError,
} from './error-types';
import { DaemonProjectGraphError } from '../daemon/daemon-project-graph-error';
import { loadNxPlugins, LoadedNxPlugin } from './plugins/internal-api';
import { loadNxPlugins, RunnableLoadedNxPlugin } from './plugins/internal-api';

/**
* Synchronously reads the latest cached copy of the workspace's ProjectGraph.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
readTargetDefaultsForTarget,
} from './project-configuration-utils';
import { NxPluginV2 } from '../plugins';
import { LoadedNxPlugin } from '../plugins/internal-api';
import { RunnableLoadedNxPlugin } from '../plugins/internal-api';

describe('project-configuration-utils', () => {
describe('target merging', () => {
Expand Down Expand Up @@ -1555,7 +1555,11 @@ describe('project-configuration-utils', () => {
undefined,
{},
['libs/a/project.json', 'libs/b/project.json'],
[new LoadedNxPlugin(fakeTagPlugin, { plugin: fakeTagPlugin.name })]
[
new RunnableLoadedNxPlugin(fakeTagPlugin, {
plugin: fakeTagPlugin.name,
}),
]
);

expect(projectConfigurations.projects).toEqual({
Expand All @@ -1578,7 +1582,7 @@ describe('project-configuration-utils', () => {
{},
['libs/a/project.json', 'libs/b/project.json'],
[
new LoadedNxPlugin(fakeTagPlugin, {
new RunnableLoadedNxPlugin(fakeTagPlugin, {
plugin: fakeTagPlugin.name,
include: ['libs/a/**'],
}),
Expand All @@ -1600,7 +1604,7 @@ describe('project-configuration-utils', () => {
{},
['libs/a/project.json', 'libs/b/project.json'],
[
new LoadedNxPlugin(fakeTagPlugin, {
new RunnableLoadedNxPlugin(fakeTagPlugin, {
plugin: fakeTagPlugin.name,
exclude: ['libs/b/**'],
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { join } from 'path';
import { performance } from 'perf_hooks';
import {
CreateNodesResultWithContext,
LoadedNxPlugin,
RunnableLoadedNxPlugin,
} from '../plugins/internal-api';
import {
CreateNodesError,
Expand Down Expand Up @@ -316,7 +316,7 @@ export async function createProjectConfigurations(
root: string = workspaceRoot,
nxJson: NxJsonConfiguration,
projectFiles: string[], // making this parameter allows devkit to pick up newly created projects
plugins: LoadedNxPlugin[]
plugins: RunnableLoadedNxPlugin[]
): Promise<ConfigurationResult> {
performance.mark('build-project-configs:start');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
ConfigurationResult,
createProjectConfigurations,
} from './project-configuration-utils';
import { LoadedNxPlugin, loadNxPlugins } from '../plugins/internal-api';
import { RunnableLoadedNxPlugin, loadNxPlugins } from '../plugins/internal-api';
import {
getNxWorkspaceFilesFromContext,
globWithWorkspaceContext,
Expand Down Expand Up @@ -61,7 +61,7 @@ export async function retrieveWorkspaceFiles(
*/

export function retrieveProjectConfigurations(
plugins: LoadedNxPlugin[],
plugins: RunnableLoadedNxPlugin[],
workspaceRoot: string,
nxJson: NxJsonConfiguration
): Promise<ConfigurationResult> {
Expand Down
1 change: 0 additions & 1 deletion packages/nx/src/utils/nx-plugin.deprecated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import ProjectJsonProjectsPlugin from '../plugins/project-json/build-nodes/proje
import TargetDefaultsPlugin from '../plugins/target-defaults/target-defaults-plugin';
import * as PackageJsonWorkspacesPlugin from '../plugins/package-json-workspaces';
import { NxPluginV2 } from '../project-graph/plugins';
import { LoadedNxPlugin } from '../project-graph/plugins/internal-api';

/**
* @deprecated Add targets to the projects in a {@link CreateNodes} function instead. This will be removed in Nx 19
Expand Down

0 comments on commit 3a3e95c

Please sign in to comment.