Skip to content

Commit 5029a0e

Browse files
fix(qwik-nx): resolve nx versions manually (#223)
1 parent 87dcc5b commit 5029a0e

31 files changed

+706
-553
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ jobs:
1111
runs-on: ${{ matrix.os }}
1212
strategy:
1313
matrix:
14-
node_version: [16]
1514
os: [ubuntu-latest, windows-latest]
1615

1716
steps:
@@ -24,7 +23,7 @@ jobs:
2423
- name: Setup
2524
uses: ./.github/actions/setup
2625
with:
27-
node_version: ${{ matrix.node_version }}
26+
node_version: 18
2827

2928
- name: Test
3029
uses: ./.github/actions/test

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,18 @@ This plugin supports Nx migrations and provides necessary version and code updat
9191

9292
## qwik-nx & Nx Compatibility Chart
9393

94-
| qwik-nx version | Nx version |
95-
| ------------------ | -------------------- |
96-
| ~2.0.0 | ~17.0.0 \|\| ~17.1.0 |
97-
| ^1.1.0 | ^16.8.0 |
98-
| ^1.0.0 | ^16.0.0 |
99-
| ^0.16.0 | ^16.0.0 |
100-
| >= 0.12.0 < 0.16.0 | ^15.8.0 |
101-
| ~0.10.0, ~0.11.0 | ~15.7.2 |
102-
| >= 0.6.0 < 0.10.0 | ~15.6.0 |
103-
| ~0.5.0 | ~15.5.0 |
104-
| ~0.4.0 | ~15.4.0 |
105-
| <=0.4.0 | ^15.0.0 |
94+
| qwik-nx version | Nx version |
95+
| ------------------ | ---------- |
96+
| ^2.0.0 | ^17.0.0 |
97+
| ^1.1.0 | ^16.8.0 |
98+
| ^1.0.0 | ^16.0.0 |
99+
| ^0.16.0 | ^16.0.0 |
100+
| >= 0.12.0 < 0.16.0 | ^15.8.0 |
101+
| ~0.10.0, ~0.11.0 | ~15.7.2 |
102+
| >= 0.6.0 < 0.10.0 | ~15.6.0 |
103+
| ~0.5.0 | ~15.5.0 |
104+
| ~0.4.0 | ~15.4.0 |
105+
| <=0.4.0 | ^15.0.0 |
106106

107107
We will provide support for Nx 15 with critical bug fixes and minor features for a while. If you're using [email protected] or higher, you can stick to [email protected].
108108

e2e/qwik-nx-e2e/tests/application-basic-behavior.suite.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export function testApplicationBasicBehavior(generator: 'app' | 'preset') {
3030
let rootRoutePath: string;
3131
let libComponentName: string;
3232
let libComponentPath: string;
33+
let appComponentSpecFilePath: string;
3334

3435
beforeAll(async () => {
3536
await killPorts(devServerPort, previewServerPort);
@@ -40,6 +41,7 @@ export function testApplicationBasicBehavior(generator: 'app' | 'preset') {
4041
project = uniq('qwik-nx');
4142
libProject = uniq('qwik-nx');
4243
rootRoutePath = `${appPathPrefix}${project}/src/routes/index.tsx`;
44+
appComponentSpecFilePath = `${appPathPrefix}${project}/src/components/my-test-component/my-test-component.spec.tsx`;
4345
libComponentPath = `${libPathPrefix}${libProject}/src/lib/${libProject}.tsx`;
4446
libComponentName = names(libProject).className;
4547

@@ -168,8 +170,24 @@ export function testApplicationBasicBehavior(generator: 'app' | 'preset') {
168170
expect(result.stdout).toContain(
169171
`Successfully ran target test for project ${project}`
170172
);
171-
expect(stripConsoleColors(result.stdout)).toContain(
172-
`Test Files 1 passed`
173+
},
174+
DEFAULT_E2E_TIMEOUT
175+
);
176+
177+
it(
178+
'unit tests should fail (when we want it)',
179+
async () => {
180+
updateFile(appComponentSpecFilePath, (content) => {
181+
return content.replace(
182+
`toContain('MyTestComponent works!')`,
183+
`toContain('Not existing string')`
184+
);
185+
});
186+
const result = await runNxCommandAsync(`test ${project}`, {
187+
silenceError: true,
188+
});
189+
expect(result.stdout).toContain(
190+
`Running target test for project ${project} failed`
173191
);
174192
},
175193
DEFAULT_E2E_TIMEOUT

e2e/qwik-nx-e2e/tests/chore.spec.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ describe('misc checks', () => {
2020
async () => {
2121
const packageJson = readJson('node_modules/qwik-nx/package.json');
2222

23-
expect(packageJson.peerDependencies).toBeUndefined();
24-
expect(packageJson.dependencies).toEqual({
25-
'@nx/devkit': '>=17.0.0 <17.2.0',
26-
'@nx/js': '>=17.0.0 <17.2.0',
27-
'@nx/eslint': '>=17.0.0 <17.2.0',
28-
'@nx/vite': '>=17.0.0 <17.2.0',
23+
expect(packageJson.dependencies).toBeUndefined();
24+
expect(packageJson.devDependencies).toBeUndefined();
25+
expect(packageJson.peerDependencies).toEqual({
26+
'@nx/devkit': '^17.0.0',
27+
'@nx/js': '^17.0.0',
28+
'@nx/eslint': '^17.0.0',
29+
'@nx/vite': '^17.0.0',
2930
});
3031
},
3132
DEFAULT_E2E_TIMEOUT

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"@types/fs-extra": "11.0.1",
4242
"@types/jest": "29.4.0",
4343
"@types/node": "16.11.7",
44+
"@types/semver": "7.5.6",
4445
"@types/tcp-port-used": "1.0.1",
4546
"@types/yargs": "17.0.24",
4647
"@typescript-eslint/eslint-plugin": "5.62.0",
@@ -67,6 +68,7 @@
6768
"nx": "17.0.3",
6869
"prettier": "^2.8.0",
6970
"pretty-quick": "^3.1.3",
71+
"semver": "7.6.0",
7072
"tcp-port-used": "1.0.2",
7173
"tree-kill": "1.2.2",
7274
"ts-jest": "29.1.0",

packages/qwik-nx/migrations.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,26 @@
289289
"version": "~4.4.11"
290290
}
291291
}
292+
},
293+
"2.1.0": {
294+
"version": "2.1.0",
295+
"packages": {
296+
"@builder.io/qwik": {
297+
"version": "~1.4.4"
298+
},
299+
"@builder.io/qwik-city": {
300+
"version": "~1.4.4"
301+
},
302+
"eslint-plugin-qwik": {
303+
"version": "~1.4.4"
304+
},
305+
"vite": {
306+
"version": "~5.0.0"
307+
},
308+
"vitest": {
309+
"version": "^1.0.0"
310+
}
311+
}
292312
}
293313
}
294314
}

packages/qwik-nx/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
},
2222
"generators": "./generators.json",
2323
"executors": "./executors.json",
24-
"dependencies": {
25-
"@nx/devkit": ">=17.0.0 <17.2.0",
26-
"@nx/js": ">=17.0.0 <17.2.0",
27-
"@nx/vite": ">=17.0.0 <17.2.0",
28-
"@nx/eslint": ">=17.0.0 <17.2.0"
24+
"peerDependencies": {
25+
"@nx/devkit": "^17.0.0",
26+
"@nx/js": "^17.0.0",
27+
"@nx/vite": "^17.0.0",
28+
"@nx/eslint": "^17.0.0"
2929
},
3030
"nx-migrations": {
3131
"migrations": "./migrations.json"
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import {
2+
addProjectConfiguration,
3+
formatFiles,
4+
generateFiles,
5+
GeneratorCallback,
6+
joinPathFragments,
7+
names,
8+
TargetConfiguration,
9+
Tree,
10+
runTasksInSerial,
11+
} from '@nx/devkit';
12+
import { Linter } from '@nx/eslint';
13+
import { initGenerator } from '@nx/vite';
14+
import { initGenerator as jsInitGenerator } from '@nx/js';
15+
import { addCommonQwikDependencies } from '../../utils/add-common-qwik-dependencies';
16+
import { addStyledModuleDependencies } from '../../utils/add-styled-dependencies';
17+
import { configureEslint } from '../../utils/configure-eslint';
18+
import setupTailwindGenerator from '../setup-tailwind/setup-tailwind';
19+
import { SetupTailwindOptions } from './../setup-tailwind/schema.d';
20+
import { NormalizedSchema, QwikAppGeneratorSchema } from './schema';
21+
import { getQwikApplicationProjectTargets } from './utils/get-qwik-application-project-params';
22+
import { normalizeOptions } from './utils/normalize-options';
23+
import { addE2eProject } from './utils/add-e2e';
24+
25+
function addFiles(tree: Tree, options: NormalizedSchema) {
26+
const templateOptions = {
27+
...options,
28+
...names(options.name),
29+
template: '',
30+
};
31+
generateFiles(
32+
tree,
33+
joinPathFragments(__dirname, 'files'),
34+
options.projectRoot,
35+
templateOptions
36+
);
37+
}
38+
39+
export async function appGeneratorInternal(
40+
tree: Tree,
41+
options: QwikAppGeneratorSchema
42+
) {
43+
const tasks: GeneratorCallback[] = [];
44+
45+
const normalizedOptions = await normalizeOptions(tree, options);
46+
47+
const targets: Record<string, TargetConfiguration> =
48+
getQwikApplicationProjectTargets(normalizedOptions);
49+
50+
if (!normalizedOptions.setupVitest) {
51+
delete targets['test'];
52+
}
53+
54+
await jsInitGenerator(tree, {
55+
skipFormat: true,
56+
});
57+
58+
addProjectConfiguration(tree, normalizedOptions.projectName, {
59+
root: normalizedOptions.projectRoot,
60+
name: normalizedOptions.projectName,
61+
projectType: 'application',
62+
sourceRoot: `${normalizedOptions.projectRoot}/src`,
63+
targets,
64+
tags: normalizedOptions.parsedTags,
65+
});
66+
67+
addFiles(tree, normalizedOptions);
68+
69+
tasks.push(
70+
await initGenerator(tree, {
71+
includeLib: false,
72+
uiFramework: 'none',
73+
testEnvironment: 'node',
74+
})
75+
);
76+
77+
if (normalizedOptions.linter === Linter.EsLint) {
78+
tasks.push(configureEslint(tree, normalizedOptions.projectName, true));
79+
}
80+
81+
if (normalizedOptions.styleExtension) {
82+
tasks.push(
83+
addStyledModuleDependencies(tree, normalizedOptions.styleExtension)
84+
);
85+
}
86+
87+
tasks.push(addCommonQwikDependencies(tree));
88+
89+
if (
90+
normalizedOptions.e2eTestRunner &&
91+
normalizedOptions.e2eTestRunner !== 'none'
92+
) {
93+
const e2eProjectTask = await addE2eProject(tree, normalizedOptions);
94+
tasks.push(e2eProjectTask);
95+
}
96+
97+
if (!options.skipFormat) {
98+
await formatFiles(tree);
99+
}
100+
101+
if (options.tailwind) {
102+
const twOptions: SetupTailwindOptions = {
103+
project: normalizedOptions.name,
104+
};
105+
tasks.push(await setupTailwindGenerator(tree, twOptions));
106+
}
107+
108+
return runTasksInSerial(...tasks);
109+
}

packages/qwik-nx/src/generators/application/generator.spec.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import { Tree, joinPathFragments, readProjectConfiguration } from '@nx/devkit';
44
import generator from './generator';
55
import { QwikAppGeneratorSchema } from './schema';
66
import { Linter } from '@nx/eslint';
7-
import { getFormattedListChanges } from './../../utils/testing-generators';
8-
9-
// eslint-disable-next-line @typescript-eslint/no-var-requires
10-
const devkit = require('@nx/devkit');
11-
const getInstalledNxVersionModule = require('../../utils/get-installed-nx-version');
7+
import {
8+
getFormattedListChanges,
9+
mockEnsurePackage,
10+
} from './../../utils/testing-generators';
1211

1312
describe('qwik-nx generator', () => {
13+
mockEnsurePackage();
14+
1415
let appTree: Tree;
1516
const defaultOptions: QwikAppGeneratorSchema = {
1617
name: 'myapp',
@@ -22,11 +23,6 @@ describe('qwik-nx generator', () => {
2223
e2eTestRunner: 'none',
2324
};
2425

25-
jest.spyOn(devkit, 'ensurePackage').mockReturnValue(Promise.resolve());
26-
jest
27-
.spyOn(getInstalledNxVersionModule, 'getInstalledNxVersion')
28-
.mockReturnValue('15.6.0');
29-
3026
beforeEach(() => {
3127
appTree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
3228
});

0 commit comments

Comments
 (0)