Skip to content

Commit 77f8e1e

Browse files
chore(repo): update workspace-plugin to hit installed versions of packages (#35262)
## Current Behavior workspace-plugin:test has violations ## Expected Behavior <img width="650" height="399" alt="image" src="https://github.com/user-attachments/assets/d77c720f-dee9-4e83-8b2f-2823da4990e0" /> --------- Co-authored-by: nx-cloud[bot] <71083854+nx-cloud[bot]@users.noreply.github.com>
1 parent 65a1769 commit 77f8e1e

3 files changed

Lines changed: 20 additions & 40 deletions

File tree

tools/workspace-plugin/jest.config.cts

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,8 @@ module.exports = {
44
preset: '../../jest.preset.js',
55
moduleFileExtensions: ['ts', 'js', 'html'],
66
coverageDirectory: '../../coverage/tools/workspace-plugin',
7-
moduleNameMapper: {
8-
// Override for tools packages - point to packages directory
9-
'^@nx/devkit$': '<rootDir>/../../packages/devkit/index.ts',
10-
'^@nx/devkit/testing$': '<rootDir>/../../packages/devkit/testing.ts',
11-
'^@nx/devkit/internal-testing-utils$':
12-
'<rootDir>/../../packages/devkit/internal-testing-utils.ts',
13-
'^@nx/devkit/src/(.*)$': '<rootDir>/../../packages/devkit/src/$1',
14-
'^nx/src/devkit-exports$':
15-
'<rootDir>/../../packages/nx/src/devkit-exports.ts',
16-
'^nx/src/devkit-internals$':
17-
'<rootDir>/../../packages/nx/src/devkit-internals.ts',
18-
'^nx/src/devkit-testing-exports$':
19-
'<rootDir>/../../packages/nx/src/devkit-testing-exports.ts',
20-
'^@nx/eslint/src/(.*)$': '<rootDir>/../../packages/eslint/src/$1',
21-
'^nx/src/internal-testing-utils/(.*)$':
22-
'<rootDir>/../../packages/nx/src/internal-testing-utils/$1',
23-
'^nx/src/generators/(.*)$': '<rootDir>/../../packages/nx/src/generators/$1',
24-
'^nx/src/plugins/(.*)$': '<rootDir>/../../packages/nx/src/plugins/$1',
25-
'^nx/src/utils/(.*)$': '<rootDir>/../../packages/nx/src/utils/$1',
26-
'^nx/src/config/(.*)$': '<rootDir>/../../packages/nx/src/config/$1',
27-
'^nx/src/command-line/(.*)$':
28-
'<rootDir>/../../packages/nx/src/command-line/$1',
29-
'^nx/src/project-graph/(.*)$':
30-
'<rootDir>/../../packages/nx/src/project-graph/$1',
31-
'^nx/src/daemon/(.*)$': '<rootDir>/../../packages/nx/src/daemon/$1',
32-
'^nx/src/hasher/(.*)$': '<rootDir>/../../packages/nx/src/hasher/$1',
33-
'^nx/src/tasks-runner/(.*)$':
34-
'<rootDir>/../../packages/nx/src/tasks-runner/$1',
35-
'^nx/src/adapter/(.*)$': '<rootDir>/../../packages/nx/src/adapter/$1',
36-
'^nx/package.json$': '<rootDir>/../../packages/nx/package.json',
37-
'^@nx/js/src/(.*)$': '<rootDir>/../../packages/js/src/$1',
38-
'^@nx/plugin$': '<rootDir>/../../packages/plugin/index.ts',
39-
'^@nx/plugin/src/(.*)$': '<rootDir>/../../packages/plugin/src/$1',
40-
},
7+
// Override the workspace-wide resolver that redirects @nx/* imports to
8+
// packages/* source; this project is intended to consume the installed
9+
// versions of its dependencies, not the local monorepo sources.
10+
resolver: undefined,
4111
};

tools/workspace-plugin/src/generators/create-nodes-plugin/generator.spec.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
2-
import { addProjectConfiguration, Tree, writeJson } from '@nx/devkit';
2+
import {
3+
addProjectConfiguration,
4+
Tree,
5+
workspaceRoot,
6+
writeJson,
7+
} from '@nx/devkit';
8+
import { join } from 'node:path';
39

410
import { generatorGenerator } from './generator';
5-
import { setCwd } from '@nx/devkit/internal-testing-utils';
611

712
describe('create-nodes-plugin/generator generator', () => {
813
let tree: Tree;
@@ -19,7 +24,7 @@ describe('create-nodes-plugin/generator generator', () => {
1924

2025
jest.spyOn(process, 'cwd').mockReturnValue('/virtual/packages/eslint');
2126

22-
setCwd('packages/eslint');
27+
process.env.INIT_CWD = join(workspaceRoot, 'packages/eslint');
2328
});
2429

2530
it('should run successfully', async () => {

tools/workspace-plugin/src/generators/remove-migrations/generator.spec.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
2-
import { addProjectConfiguration, Tree, writeJson } from '@nx/devkit';
2+
import {
3+
addProjectConfiguration,
4+
Tree,
5+
workspaceRoot,
6+
writeJson,
7+
} from '@nx/devkit';
8+
import { join } from 'node:path';
39

410
import update from './generator';
5-
import { setCwd } from '@nx/devkit/internal-testing-utils';
611

712
describe('remove-migrations generator', () => {
813
let tree: Tree;
@@ -19,7 +24,7 @@ describe('remove-migrations generator', () => {
1924

2025
jest.spyOn(process, 'cwd').mockReturnValue('/virtual/packages/js');
2126

22-
setCwd('packages/js');
27+
process.env.INIT_CWD = join(workspaceRoot, 'packages/js');
2328
});
2429

2530
it('should remove migrations older than specified version', async () => {

0 commit comments

Comments
 (0)