Skip to content

Commit 90b3aab

Browse files
committed
fix(core): nx v15 prefers output paths that start with {workspaceRoot}
1 parent 8ff832a commit 90b3aab

File tree

15 files changed

+363
-243
lines changed

15 files changed

+363
-243
lines changed

demo/apps/web-frontend/jest.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ export default {
88
},
99
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
1010
coverageDirectory: '../../coverage//demo/apps/web-frontend',
11+
testEnvironment: 'jsdom',
1112
};

e2e/core-e2e/tests/nx-dotnet.spec.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -376,35 +376,24 @@ describe('nx-dotnet e2e', () => {
376376
});
377377
});
378378

379-
it('should work with workspace.json + project.json', () => {
380-
const relativeProjectPath = joinPathFragments('apps', api);
379+
it('should work with project.json', () => {
381380
writeFileSync(
382381
join(projectFolder, 'project.json'),
383382
JSON.stringify({
384-
root: relativeProjectPath,
383+
targets: {},
385384
}),
386385
);
387-
updateFile('workspace.json', (c) => {
388-
const json = JSON.parse(c);
389-
json.projects[api] = relativeProjectPath;
390-
return JSON.stringify(json, null, 2);
391-
});
392386
expect(() => runNxCommand(`build ${api}`)).not.toThrow();
393387
});
394388

395-
it('should work without workspace.json or project.json', () => {
396-
const workspaceJsonContents = readFile('workspace.json');
397-
unlinkSync(join(e2eDir, 'workspace.json'));
398-
389+
it('should work without project.json', () => {
399390
const projectJsonContents = readFile(
400391
joinPathFragments('apps', api, 'project.json'),
401392
);
402393
unlinkSync(join(projectFolder, 'project.json'));
403394

404395
expect(() => runNxCommand(`build ${api}`)).not.toThrow();
405396

406-
writeFileSync(join(e2eDir, 'workspace.json'), workspaceJsonContents);
407-
408397
writeFileSync(join(projectFolder, 'project.json'), projectJsonContents);
409398
});
410399
});

e2e/utils/index.ts

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
import * as path from 'path';
1616
import { dirSync } from 'tmp';
1717

18-
import isCI = require('is-ci');
18+
import * as isCI from 'is-ci';
1919
import { workspaceConfigName } from 'nx/src/config/workspaces';
2020
import { detectPackageManager } from '@nrwl/devkit';
2121
interface RunCmdOpts {
@@ -143,11 +143,6 @@ export function runCLI(
143143
console.log(r);
144144
}
145145

146-
const needsMaxWorkers = /g.*(express|nest|node|web|react):app.*/;
147-
if (command && needsMaxWorkers.test(command)) {
148-
setMaxWorkers();
149-
}
150-
151146
return r;
152147
} catch (e: any) {
153148
if (opts.silenceError) {
@@ -181,39 +176,6 @@ export function runCommand(command: string): string {
181176
}
182177
}
183178

184-
/**
185-
* Sets maxWorkers in CI on all projects that require it
186-
* so that it doesn't try to run it with 34 workers
187-
*
188-
* maxWorkers required for: node, web, jest
189-
*/
190-
function setMaxWorkers() {
191-
if (isCI) {
192-
const workspaceFile = workspaceConfigName(tmpProjPath());
193-
const workspace = readJson(workspaceFile);
194-
195-
Object.keys(workspace.projects).forEach((appName) => {
196-
const project = workspace.projects[appName];
197-
const { build } = project.targets ?? project.architect;
198-
199-
if (!build) {
200-
return;
201-
}
202-
203-
const executor = build.builder ?? build.executor;
204-
if (
205-
executor.startsWith('@nrwl/node') ||
206-
executor.startsWith('@nrwl/web') ||
207-
executor.startsWith('@nrwl/jest')
208-
) {
209-
build.options.maxWorkers = 4;
210-
}
211-
});
212-
213-
updateFile(workspaceFile, JSON.stringify(workspace));
214-
}
215-
}
216-
217179
export function createFile(f: string, content: string = ''): void {
218180
const path = tmpProjPath(f);
219181
createFileSync(path);

jest.config.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
1+
import { getJestProjects } from '@nrwl/jest';
2+
13
export default {
2-
projects: [
3-
'<rootDir>/e2e/core-e2e',
4-
'<rootDir>/e2e/nx-ghpages-e2e',
5-
'<rootDir>/e2e/nxdoc-e2e',
6-
'<rootDir>/packages/core',
7-
'<rootDir>/packages/dotnet',
8-
'<rootDir>/packages/nx-ghpages',
9-
'<rootDir>/packages/nxdoc',
10-
'<rootDir>/packages/utils',
11-
'<rootDir>/smoke/core',
12-
'<rootDir>/demo/libs/generated/webapi-types',
13-
'<rootDir>/demo/apps/web-frontend',
14-
'<rootDir>/demo/apps/web-frontend',
15-
],
4+
projects: getJestProjects(),
165
};

jest.preset.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
const nxPreset = require('@nrwl/jest/preset').default;
22

3-
module.exports = { ...nxPreset };
3+
module.exports = { ...nxPreset, testEnvironment: 'node' };

package.json

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,18 @@
4444
"@commitlint/cli": "^16.2.1",
4545
"@commitlint/config-conventional": "^17.1.0",
4646
"@commitlint/types": "^16.2.1",
47-
"@nrwl/cypress": "15.0.0-rc1",
48-
"@nrwl/devkit": "15.0.0-rc1",
49-
"@nrwl/eslint-plugin-nx": "15.0.0-rc1",
50-
"@nrwl/jest": "15.0.0-rc1",
51-
"@nrwl/js": "15.0.0-rc1",
52-
"@nrwl/linter": "15.0.0-rc1",
53-
"@nrwl/node": "15.0.0-rc1",
54-
"@nrwl/nx-cloud": "14.7.0",
55-
"@nrwl/nx-plugin": "15.0.0-rc1",
56-
"@nrwl/react": "15.0.0-rc1",
57-
"@nrwl/web": "15.0.0-rc1",
58-
"@nrwl/workspace": "15.0.0-rc1",
47+
"@nrwl/cypress": "15.0.1",
48+
"@nrwl/devkit": "15.0.1",
49+
"@nrwl/eslint-plugin-nx": "15.0.1",
50+
"@nrwl/jest": "15.0.1",
51+
"@nrwl/js": "15.0.1",
52+
"@nrwl/linter": "15.0.1",
53+
"@nrwl/node": "15.0.1",
54+
"@nrwl/nx-cloud": "15.0.0",
55+
"@nrwl/nx-plugin": "15.0.1",
56+
"@nrwl/react": "15.0.1",
57+
"@nrwl/web": "15.0.1",
58+
"@nrwl/workspace": "15.0.1",
5959
"@nx-plus/docusaurus": "14.0.0",
6060
"@semantic-release/changelog": "^6.0.1",
6161
"@semantic-release/commit-analyzer": "^9.0.2",
@@ -93,11 +93,12 @@
9393
"fs-extra": "^10.1.0",
9494
"husky": "^8.0.1",
9595
"jest": "28.1.3",
96+
"jest-environment-jsdom": "28.1.3",
9697
"jsonc-eslint-parser": "^2.1.0",
9798
"kill-port": "^1.6.1",
9899
"lint-staged": "^13.0.3",
99100
"node-fetch": "2.6.6",
100-
"nx": "15.0.0-rc1",
101+
"nx": "15.0.1",
101102
"openapi-types": "^11.0.1",
102103
"prettier": "2.7.1",
103104
"react-test-renderer": "18.2.0",

packages/core/src/generators/swagger-typescript/generator.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ describe('swagger-typescript generator', () => {
121121
let tree: Tree;
122122

123123
beforeEach(() => {
124-
tree = createTreeWithEmptyWorkspace(2);
124+
tree = createTreeWithEmptyWorkspace();
125125
libraryGenerator(tree, { name: 'generated-ts' });
126126
tree.write('swagger.json', MOCK_SWAGGER_JSON);
127127
});

packages/core/src/generators/utils/generate-project.spec.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { readProjectConfiguration, Tree, writeJson } from '@nrwl/devkit';
22
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
33

4-
import { resolve } from 'path';
5-
64
import { DotNetClient, mockDotnetFactory } from '@nx-dotnet/dotnet';
75

86
import { NxDotnetProjectGeneratorSchema } from '../../models';
@@ -25,7 +23,7 @@ describe('nx-dotnet project generator', () => {
2523
let options: NxDotnetProjectGeneratorSchema;
2624

2725
beforeEach(() => {
28-
appTree = createTreeWithEmptyWorkspace(2);
26+
appTree = createTreeWithEmptyWorkspace();
2927
dotnetClient = new DotNetClient(mockDotnetFactory());
3028

3129
const packageJson = { scripts: {}, devDependencies: {} };
@@ -86,10 +84,7 @@ describe('nx-dotnet project generator', () => {
8684
const outputPath = config.targets?.build.outputs || [];
8785
expect(outputPath.length).toBe(1);
8886

89-
const absoluteDistPath = resolve(appTree.root, outputPath[0]);
90-
const expectedDistPath = resolve(appTree.root, './dist/apps/test');
91-
92-
expect(absoluteDistPath).toEqual(expectedDistPath);
87+
expect(outputPath[0]).toEqual('{workspaceRoot}/dist/apps/test');
9388
});
9489

9590
it('should include serve target for applications', async () => {

packages/core/src/generators/utils/generate-test-project.spec.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
88

99
import * as fs from 'fs';
10-
import { resolve } from 'path';
1110

1211
import { DotNetClient, mockDotnetFactory } from '@nx-dotnet/dotnet';
1312
import * as utils from '@nx-dotnet/utils';
@@ -100,15 +99,9 @@ describe('nx-dotnet test project generator', () => {
10099
const config = readProjectConfiguration(appTree, testProjectName);
101100
console.log(config.targets?.build.options);
102101
const outputPath = config.targets?.build.outputs?.[0];
103-
expect(outputPath).toBeTruthy();
104-
105-
const absoluteDistPath = resolve(appTree.root, outputPath || '');
106-
const expectedDistPath = resolve(
107-
appTree.root,
108-
'./dist/apps/domain/existing-app-test',
102+
expect(outputPath).toEqual(
103+
'{workspaceRoot}/dist/apps/domain/existing-app-test',
109104
);
110-
111-
expect(absoluteDistPath).toEqual(expectedDistPath);
112105
});
113106

114107
it('should include lint target', async () => {

packages/core/src/generators/utils/get-path-to-startup-assembly.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,49 @@ import {
33
joinPathFragments,
44
ProjectConfiguration,
55
TargetConfiguration,
6+
workspaceRoot,
67
} from '@nrwl/devkit';
78

89
import { execSync } from 'child_process';
910
import { sync } from 'fast-glob';
1011
import { existsSync } from 'fs';
11-
import { basename } from 'path';
12+
import { basename, relative, resolve } from 'path';
1213

1314
export function buildStartupAssemblyPath(
1415
projectName: string,
1516
project: ProjectConfiguration,
1617
csProjFilePath: string,
1718
) {
1819
const [target, configuration] = findBuildTarget(project);
19-
const outputDirectory = configuration?.outputs?.[0];
20+
let outputDirectory = configuration?.outputs?.[0];
2021
if (!outputDirectory) {
2122
throw new Error(`Specify the output directory for ${project.root}
2223
2324
To generate swagger with Nx, the outputs must be captured. This is also necessary for Nx's caching mechanism.
2425
Simply update the outputs array in project.json with the location of your build artifacts.
2526
`);
2627
}
28+
outputDirectory = resolve(
29+
outputDirectory
30+
.replace('{workspaceRoot}', workspaceRoot)
31+
.replace('{projectRoot}', project.root),
32+
);
2733
if (!existsSync(outputDirectory)) {
2834
execSync(`${getPackageManagerCommand().exec} nx ${target} ${projectName}`);
2935
}
30-
console.log('before dll name');
3136
const dllName = basename(csProjFilePath).replace(
3237
/(?:\.csproj|\.vbproj|\.fsproj)$/,
3338
'.dll',
3439
);
35-
console.log('dll name', dllName, outputDirectory);
40+
const foundDll = sync(`**/${dllName}`, { cwd: outputDirectory })[0];
41+
if (!foundDll) {
42+
throw new Error(
43+
`[nx-dotnet] Unable to locate ${dllName} in ${relative(
44+
workspaceRoot,
45+
outputDirectory,
46+
)}`,
47+
);
48+
}
3649
return joinPathFragments(
3750
outputDirectory,
3851
sync(`**/${dllName}`, { cwd: outputDirectory })[0],

0 commit comments

Comments
 (0)