Skip to content

Commit 7c8148d

Browse files
chore: migrate to v1 (#146)
1 parent bf38041 commit 7c8148d

File tree

12 files changed

+254
-20
lines changed

12 files changed

+254
-20
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ This plugin supports Nx migrations and provides necessary version and code updat
7575

7676
| qwik-nx version | Nx version |
7777
| ------------------ | ---------- |
78+
| ^1.0.0 | ^16.0.0 |
7879
| ^0.16.0 | ^16.0.0 |
7980
| >= 0.12.0 < 0.16.0 | ^15.8.0 |
8081
| ~0.10.0, ~0.11.0 | ~15.7.2 |
@@ -83,6 +84,8 @@ This plugin supports Nx migrations and provides necessary version and code updat
8384
| ~0.4.0 | ~15.4.0 |
8485
| <=0.4.0 | ^15.0.0 |
8586

87+
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].
88+
8689
## ROADMAP:
8790

8891
- [ ] Complete `add-nx-to-qwik`

packages/qwik-nx/migrations.json

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@
1111
"description": "useClientEffect$ has been changed to useVisisbleTask$",
1212
"cli": "nx",
1313
"implementation": "./src/migrations/update-use-client-effect$-to-use-visisble-task$/update-use-client-effect$-to-use-visisble-task$"
14+
},
15+
"migrate-cloudflare-integration": {
16+
"version": "1.0.0",
17+
"description": "In your entry.cloudflare-pages.ts, export fetch instead of onRequest. This is required in order to use the advanced mode of Cloudflare! it will allow future perf improvements and new features.",
18+
"cli": "nx",
19+
"implementation": "./src/migrations/migrate-cloudflare-integration/migrate-cloudflare-integration"
20+
},
21+
"add-verbose-skip-type-check-option-for-the-build-executor": {
22+
"version": "1.0.0",
23+
"description": "Enabled type checking can be breaking. Adding a verbose option so that it is clear how to disable it",
24+
"cli": "nx",
25+
"implementation": "./src/migrations/add-verbose-skip-type-check-option-for-the-build-executor/add-verbose-skip-type-check-option-for-the-build-executor"
1426
}
1527
},
1628
"packageJsonUpdates": {
@@ -152,6 +164,50 @@
152164
"version": "^0.28.5"
153165
}
154166
}
167+
},
168+
"1.0.0": {
169+
"version": "1.0.0",
170+
"packages": {
171+
"@builder.io/qwik": {
172+
"version": "~1.0.0"
173+
},
174+
"@builder.io/qwik-city": {
175+
"version": "~1.0.0"
176+
},
177+
"@types/eslint": {
178+
"version": "~8.37.0"
179+
},
180+
"@types/node": {
181+
"version": "^18.16.1"
182+
},
183+
"@typescript-eslint/eslint-plugin": {
184+
"version": "^5.59.1"
185+
},
186+
"@typescript-eslint/parser": {
187+
"version": "^5.59.1"
188+
},
189+
"eslint-plugin-qwik": {
190+
"version": "~1.0.0"
191+
},
192+
"typescript": {
193+
"version": "^5.0.4"
194+
},
195+
"undici": {
196+
"version": "^5.22.0"
197+
},
198+
"vite": {
199+
"version": "^4.3.3"
200+
},
201+
"vitest": {
202+
"version": "^0.30.1"
203+
},
204+
"vite-tsconfig-paths": {
205+
"version": "~4.2.0"
206+
},
207+
"storybook-framework-qwik": {
208+
"version": "^0.2.0"
209+
}
210+
}
155211
}
156212
}
157213
}

packages/qwik-nx/src/generators/integrations/cloudflare-pages-integration/files/functions/[[path]].ts.template

Lines changed: 0 additions & 6 deletions
This file was deleted.

packages/qwik-nx/src/generators/integrations/cloudflare-pages-integration/files/src/entry.cloudflare-pages.tsx.template

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,17 @@
77
* - https://qwik.builder.io/integrations/deployments/cloudflare-pages/
88
*
99
*/
10-
import { createQwikCity } from '@builder.io/qwik-city/middleware/cloudflare-pages';
10+
import {
11+
createQwikCity,
12+
type PlatformCloudflarePages,
13+
} from '@builder.io/qwik-city/middleware/cloudflare-pages';
1114
import qwikCityPlan from '@qwik-city-plan';
1215
import render from './entry.ssr';
1316

14-
const onRequest = createQwikCity({ render, qwikCityPlan });
17+
declare global {
18+
interface QwikCityPlatform extends PlatformCloudflarePages {}
19+
}
1520

16-
export { onRequest };
21+
const fetch = createQwikCity({ render, qwikCityPlan });
22+
23+
export { fetch };
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
2+
import { Tree, readProjectConfiguration } from '@nx/devkit';
3+
4+
import update from './add-verbose-skip-type-check-option-for-the-build-executor';
5+
import appGenerator from '../../generators/application/generator';
6+
7+
describe('add-verbose-skip-type-check-option-for-the-build-executor migration', () => {
8+
let tree: Tree;
9+
10+
beforeEach(async () => {
11+
tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
12+
await appGenerator(tree, { name: 'myapp' });
13+
});
14+
15+
it('should run successfully', async () => {
16+
await update(tree);
17+
expect(readProjectConfiguration(tree, 'myapp').targets?.['build']).toEqual({
18+
executor: 'qwik-nx:build',
19+
options: {
20+
runSequence: ['myapp:build.client', 'myapp:build.ssr'],
21+
outputPath: 'dist/apps/myapp',
22+
skipTypeCheck: false,
23+
},
24+
configurations: {
25+
preview: {},
26+
},
27+
});
28+
});
29+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Tree, getProjects, updateProjectConfiguration } from '@nx/devkit';
2+
import { isQwikNxProject } from '../../utils/migrations';
3+
4+
export default function update(host: Tree) {
5+
const projects = getProjects(host);
6+
7+
projects.forEach((config, name) => {
8+
if (isQwikNxProject(config)) {
9+
const buildTarget = config.targets?.['build'];
10+
if (buildTarget?.options) {
11+
buildTarget.options = {
12+
...buildTarget.options,
13+
skipTypeCheck: false,
14+
};
15+
updateProjectConfiguration(host, name, config);
16+
}
17+
}
18+
});
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`migrate-cloudflare-integration migration should run successfully: entry.cloudflare-pages.tsx 1`] = `
4+
"import { createQwikCity } from '@builder.io/qwik-city/middleware/cloudflare-pages';
5+
import qwikCityPlan from '@qwik-city-plan';
6+
import render from './entry.ssr';
7+
8+
const fetch = createQwikCity({ render, qwikCityPlan });
9+
10+
export { fetch };"
11+
`;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
2+
import { Tree } from '@nx/devkit';
3+
4+
import update from './migrate-cloudflare-integration';
5+
import { appGenerator } from '../../generators/application/generator';
6+
7+
describe('migrate-cloudflare-integration migration', () => {
8+
let tree: Tree;
9+
10+
beforeEach(async () => {
11+
tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
12+
await appGenerator(tree, { name: 'myapp' });
13+
tree.write('apps/myapp/functions/[[path]].ts', 'export default {}');
14+
tree.write(
15+
'apps/myapp/adapters/cloudflare-pages/vite.config.ts',
16+
'export default {}'
17+
);
18+
tree.write(
19+
'apps/myapp/src/entry.cloudflare-pages.tsx',
20+
`import { createQwikCity } from '@builder.io/qwik-city/middleware/cloudflare-pages';
21+
import qwikCityPlan from '@qwik-city-plan';
22+
import render from './entry.ssr';
23+
24+
const onRequest = createQwikCity({ render, qwikCityPlan });
25+
26+
export { onRequest };`
27+
);
28+
});
29+
30+
it('should run successfully', async () => {
31+
await update(tree);
32+
expect(tree.exists('apps/myapp/functions/[[path]].ts')).toBe(false);
33+
expect(
34+
tree.read('apps/myapp/src/entry.cloudflare-pages.tsx', 'utf-8')
35+
).toMatchSnapshot('entry.cloudflare-pages.tsx');
36+
});
37+
});
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import {
2+
ProjectConfiguration,
3+
ensurePackage,
4+
getProjects,
5+
joinPathFragments,
6+
Tree,
7+
} from '@nx/devkit';
8+
import {
9+
hasCloudflareIntegration,
10+
isQwikNxProject,
11+
} from '../../utils/migrations';
12+
import { tsMorphVersion } from '../../utils/versions';
13+
14+
export default async function update(tree: Tree) {
15+
const projects = getProjects(tree);
16+
17+
for (const [, config] of projects) {
18+
if (isQwikNxProject(config) && hasCloudflareIntegration(tree, config)) {
19+
// functions are no longer needed
20+
tree.delete(joinPathFragments(config.root, 'functions/[[path]].ts'));
21+
await updateCloudflarePagesEntry(tree, config);
22+
}
23+
}
24+
}
25+
26+
async function updateCloudflarePagesEntry(
27+
tree: Tree,
28+
config: ProjectConfiguration
29+
) {
30+
ensurePackage('ts-morph', tsMorphVersion);
31+
const tsMorph = await import('ts-morph');
32+
const filePath = joinPathFragments(
33+
config.root,
34+
'src/entry.cloudflare-pages.tsx'
35+
);
36+
const fileContent = tree.read(filePath)?.toString();
37+
if (!fileContent) {
38+
return;
39+
}
40+
const project = new tsMorph.Project();
41+
const sourceFile = project.createSourceFile('temp.ts', fileContent);
42+
43+
sourceFile.getVariableDeclaration('onRequest')?.rename('fetch');
44+
45+
[...sourceFile.getExportDeclarations()]
46+
.map((e) => e.getNamedExports())
47+
.flat()
48+
.find((n) => n.getName() === 'onRequest')
49+
?.setName('fetch');
50+
51+
tree.write(filePath, sourceFile.getFullText());
52+
}

packages/qwik-nx/src/migrations/update-use-client-effect$-to-use-visisble-task$/update-use-client-effect$-to-use-visisble-task$.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import {
66
} from '@nx/devkit';
77
import { extname } from 'path';
88
import { SyntaxKind } from 'typescript';
9+
import { tsMorphVersion } from '../../utils/versions';
910

1011
export default async function update(tree: Tree) {
11-
ensurePackage('ts-morph', '^17.0.0');
12+
ensurePackage('ts-morph', tsMorphVersion);
1213
const tsMorph = await import('ts-morph');
1314
for (const [, definition] of getProjects(tree)) {
1415
visitNotIgnoredFiles(tree, definition.root, (file) => {

0 commit comments

Comments
 (0)