-
Notifications
You must be signed in to change notification settings - Fork 747
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
Conversation
🦋 Changeset detectedLatest commit: c761f44 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
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 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.
Please ensure constraints are pinned, and |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ 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 |
There was a problem hiding this 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.
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[]> | ||
); |
There was a problem hiding this comment.
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;
@@ -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`, |
There was a problem hiding this comment.
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?
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 theenv
object composed of all bound resources defined inwrangler.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.