Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C3] Improve type support in Qwik template #5052

Merged
merged 14 commits into from
Feb 21, 2024
Merged

Conversation

jculvey
Copy link
Contributor

@jculvey jculvey commented Feb 18, 2024

What this PR solves / how to test:

Adds a build-cf-types script to the Qwik template and modifies the entrypoint to contain a definition for the env object composed of all bound resources defined in wrangler.toml.

Also adds a helper function that simplifies handling snippets to be use with codemods. These snippets can now be kept in their own files and benefit from syntax highlighting instead of being embedded as strings in template code.

There's also a new helper script for simplifying the development of codemods in isolation.

Author has addressed the following:

Note for PR author:

We want to celebrate and highlight awesome PR review! If you think this PR received a particularly high-caliber review, please assign it the label highlight pr review so future reviewers can take inspiration and learn from it.

@jculvey jculvey requested review from a team as code owners February 18, 2024 19:23
Copy link

changeset-bot bot commented Feb 18, 2024

🦋 Changeset detected

Latest commit: c761f44

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
create-cloudflare Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

github-actions bot commented Feb 18, 2024

A wrangler prerelease is available for testing. You can install this latest build in your project with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/7990953828/npm-package-wrangler-5052

You can reference the automatically updated head of this PR with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/5052/npm-package-wrangler-5052

Or you can use npx with this latest build directly:

npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/7990953828/npm-package-wrangler-5052 dev path/to/script.js
Additional artifacts:
npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/7990953828/npm-package-create-cloudflare-5052 --no-auto-update
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/7990953828/npm-package-cloudflare-kv-asset-handler-5052
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/7990953828/npm-package-miniflare-5052
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/7990953828/npm-package-cloudflare-pages-shared-5052
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/7990953828/npm-package-cloudflare-vitest-pool-workers-5052

Note that these links will no longer work once the GitHub Actions artifact expires.


wrangler@3.28.4 includes the following runtime dependencies:

Package Constraint Resolved
miniflare workspace:* 3.20240129.3
workerd 1.20240208.0 1.20240208.0
workerd --version 1.20240208.0 2024-02-08

Please ensure constraints are pinned, and miniflare/workerd minor versions match.

Copy link

codecov bot commented Feb 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (fd0fb23) 70.33% compared to head (c761f44) 70.37%.
Report is 11 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #5052      +/-   ##
==========================================
+ Coverage   70.33%   70.37%   +0.04%     
==========================================
  Files         297      298       +1     
  Lines       15458    15512      +54     
  Branches     3966     3983      +17     
==========================================
+ Hits        10872    10917      +45     
- Misses       4586     4595       +9     

see 17 files with indirect coverage changes

Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few nits and unblocking comments.

Comment on lines +92 to +106
return (
files
// don't try loading directories
.filter((fileName) => lstatSync(join(snippetsPath, fileName)).isFile)
// only load js or ts files
.filter((fileName) => [".js", ".ts"].includes(extname(fileName)))
.reduce((acc, snippetPath) => {
const [file, ext] = snippetPath.split(".");
const key = `${file}${ext === "js" ? "Js" : "Ts"}`;
return {
...acc,
[key]: parseFile(join(snippetsPath, snippetPath))?.body,
};
}, {}) as Record<string, recast.types.ASTNode[]>
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT - personally I find use of filters and reduce actually makes the code less readable and in fact less performant due to the recreation of arrays and objects on each iteration.

How about:

	const result: Record<string, Program["body"]|undefined> = {}
	for(const file of files) {
		if (!lstatSync(join(snippetsPath, file)).isFile) {
		  continue;
		}
		const ext = extname(file);
		if (!['.js', '.ts'].includes(ext)) {
			continue;
		}
		const baseName = basename(ext);
		const key = `${baseName}${ext === "js" ? "Js" : "Ts"}`;
		result[key] = parseFile(join(snippetsPath, file))?.body;
	}

	return result;

packages/create-cloudflare/templates/qwik/c3.ts Outdated Show resolved Hide resolved
@@ -93,6 +93,7 @@ const config: TemplateConfig = {
scripts: {
deploy: `${npm} run build && wrangler pages deploy ./dist`,
preview: `${npm} run build && wrangler pages dev ./dist`,
"build-cf-types": `wrangler types`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels a bit incongruous to this PR?

@jculvey jculvey merged commit f68e83e into main Feb 21, 2024
22 checks passed
@jculvey jculvey deleted the c3-qwik-workers-types branch February 21, 2024 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants