Skip to content

Commit

Permalink
fix(semver): 馃悶 use project graph fn from devkit
Browse files Browse the repository at this point in the history
  • Loading branch information
edbzn committed Apr 14, 2022
1 parent 1cce320 commit 729fc7f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
13 changes: 5 additions & 8 deletions packages/semver/src/executors/version/index.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import { createProjectGraphAsync } from '@nrwl/devkit';
import { fileExists } from '@nrwl/nx-plugin/testing';
import { execSync } from 'child_process';
import { existsSync, readFileSync } from 'fs';
import { resolve } from 'path';

import { lastValueFrom } from 'rxjs';
import version from './';
import { createFakeContext, setupTestingWorkspace } from './testing';
import { readPackageJson } from './utils/project';

import type { TestingWorkspace } from './testing';
import type { VersionBuilderSchema } from './schema';
import { createProjectGraphAsync } from '@nrwl/workspace/src/core/project-graph';
import { lastValueFrom } from 'rxjs';
import { createFakeContext, setupTestingWorkspace, type TestingWorkspace } from './testing';
import { getProjectDependencies } from './utils/get-project-dependencies';
import { readPackageJson } from './utils/project';

jest.mock('@nrwl/workspace/src/core/project-graph');
jest.mock('@nrwl/devkit');

describe('@jscutlery/semver:version', () => {
const defaultBuilderOptions: VersionBuilderSchema = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ProjectGraph } from '@nrwl/workspace/src/core/project-graph';

import { type ProjectGraph } from '@nrwl/devkit';
import { getProjectDependencies } from './get-project-dependencies';

const projectGraph: ProjectGraph = {
Expand Down Expand Up @@ -70,9 +69,10 @@ describe('projectDependencies', () => {
});

describe('Nx > 13', () => {
jest.mock('@nrwl/workspace/src/core/project-graph', () => ({
jest.mock('@nrwl/devkit', () => ({
createProjectGraphAsync: mockCreateProjectGraphAsync,
}));
jest.mock('@nrwl/workspace/src/core/project-graph', () => ({}));

beforeEach(() => {
mockCreateProjectGraphAsync.mockRestore();
Expand Down Expand Up @@ -116,6 +116,7 @@ describe('projectDependencies', () => {
});

it('should support Nx < 13 project graph', async () => {
jest.mock('@nrwl/devkit', () => ({}));
jest.mock('@nrwl/workspace/src/core/project-graph', () => ({
createProjectGraph: jest.fn(() => projectGraph),
}));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { ExecutorContext, ProjectGraphDependency } from '@nrwl/devkit';

import type { VersionBuilderSchema } from '../schema';

export interface DependencyRoot {
Expand Down Expand Up @@ -34,14 +33,16 @@ export async function getDependencyRoots({
export async function getProjectDependencies(
projectName: string
): Promise<string[]> {
const module = await import('@nrwl/workspace/src/core/project-graph');
/* @notice: before Nx 13 `createProjectGraphAsync` doesn't exist.
@todo: remove the compatibility support later on. */
const { createProjectGraphAsync } = await import('@nrwl/devkit');
/* @todo: remove the compatibility support later on. */
const dependencyGraph =
typeof module.createProjectGraphAsync === 'function'
? await module.createProjectGraphAsync()
typeof createProjectGraphAsync === 'function'
? await createProjectGraphAsync()
: // eslint-disable-next-line @typescript-eslint/no-explicit-any
(module as any).createProjectGraph();
(
(await import('@nrwl/workspace/src/core/project-graph')) as any
).createProjectGraph();

return getProjectsFromDependencies(dependencyGraph.dependencies[projectName]);
}

Expand Down

0 comments on commit 729fc7f

Please sign in to comment.