Skip to content

Commit fc83b5a

Browse files
feat(qwik-nx): add "root" prop migration
1 parent d110eec commit fc83b5a

File tree

4 files changed

+112
-5
lines changed

4 files changed

+112
-5
lines changed

packages/qwik-nx/migrations.json

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
{
2-
"generators": {},
2+
"generators": {
3+
"add-root-property-to-vite-config": {
4+
"version": "3.0.0",
5+
"description": "Migration for v3.0.0",
6+
"implementation": "./src/migrations/add-root-property-to-vite-config"
7+
}
8+
},
39
"packageJsonUpdates": {
410
"3.0.0": {
5-
"version": "2.3.0",
11+
"version": "3.0.0",
612
"packages": {
713
"@builder.io/qwik": {
8-
"version": "~1.10.0"
14+
"version": "~1.12.0"
915
},
1016
"@builder.io/qwik-city": {
11-
"version": "~1.10.0"
17+
"version": "~1.12.0"
1218
},
1319
"eslint-plugin-qwik": {
14-
"version": "~1.10.0"
20+
"version": "~1.12.0"
1521
},
1622
"vite": {
1723
"version": "~5.3.5"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`add-root-property-to-vite-config migration should add/update the "root" property 1`] = `
4+
"import { qwikVite } from \\"@builder.io/qwik/optimizer\\";
5+
import { defineConfig } from \\"vite\\";
6+
import tsconfigPaths from \\"vite-tsconfig-paths\\";
7+
import { qwikNxVite } from \\"qwik-nx/plugins\\";
8+
export default defineConfig({
9+
root: apps / myapp,
10+
plugins: [
11+
qwikNxVite(),
12+
qwikVite({
13+
client: {
14+
outDir: \\"../../dist/apps/myapp/client\\",
15+
},
16+
ssr: {
17+
outDir: \\"../../dist/apps/myapp/server\\",
18+
},
19+
}),
20+
tsconfigPaths({ root: \\"../../\\" }),
21+
]
22+
});
23+
"
24+
`;
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
2+
import { Tree } from '@nx/devkit';
3+
4+
import appGenerator from '../generators/application/generator';
5+
import update from './add-root-property-to-vite-config';
6+
7+
describe('add-root-property-to-vite-config migration', () => {
8+
let tree: Tree;
9+
10+
beforeEach(async () => {
11+
tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
12+
await appGenerator(tree, { directory: 'apps/myapp' });
13+
});
14+
15+
it('should add/update the "root" property', async () => {
16+
const viteConfigPath = `apps/myapp/vite.config.ts`;
17+
// just to ensure the file at that paths exists before updating it
18+
expect(tree.exists(viteConfigPath)).toBeTruthy();
19+
20+
tree.write(viteConfigPath, getViteConfigSample());
21+
update(tree);
22+
expect(tree.read(viteConfigPath, 'utf-8')).toMatchSnapshot();
23+
});
24+
});
25+
26+
const getViteConfigSample = (
27+
includeRootProp = false
28+
) => `import { qwikVite } from '@builder.io/qwik/optimizer';
29+
import { defineConfig } from 'vite';
30+
import tsconfigPaths from 'vite-tsconfig-paths';
31+
import { qwikNxVite } from 'qwik-nx/plugins';
32+
33+
export default defineConfig({
34+
${includeRootProp ? '\nroot: "apps/myapp"' : ''}
35+
plugins: [
36+
qwikNxVite(),
37+
qwikVite({
38+
client: {
39+
outDir: '../../dist/apps/myapp/client',
40+
},
41+
ssr: {
42+
outDir: '../../dist/apps/myapp/server',
43+
},
44+
}),
45+
tsconfigPaths({ root: '../../' }),
46+
],
47+
});
48+
`;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/* eslint-disable @typescript-eslint/no-unused-vars */
2+
import { getProjects, Tree } from '@nx/devkit';
3+
import { isQwikNxProject } from '../utils/migrations';
4+
import { normalizeViteConfigFilePathWithTree } from '@nx/vite';
5+
import { updateViteConfig } from '../utils/update-vite-config';
6+
7+
export default function update(host: Tree) {
8+
const projects = getProjects(host);
9+
10+
projects.forEach((config, name) => {
11+
if (isQwikNxProject(config)) {
12+
const viteConfigPath = normalizeViteConfigFilePathWithTree(
13+
host,
14+
config.root
15+
);
16+
if (!viteConfigPath) {
17+
return;
18+
}
19+
const viteConfig = host.read(viteConfigPath)!.toString();
20+
21+
const updated = updateViteConfig(viteConfig, {
22+
viteConfig: {
23+
root: config.root,
24+
},
25+
});
26+
host.write(viteConfigPath, updated);
27+
}
28+
});
29+
}

0 commit comments

Comments
 (0)