-
Notifications
You must be signed in to change notification settings - Fork 759
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
generate types for the next experimental template #7756
base: main
Are you sure you want to change the base?
Conversation
|
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/12765538678/npm-package-wrangler-7756 You can reference the automatically updated head of this PR with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/7756/npm-package-wrangler-7756 Or you can use npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12765538678/npm-package-wrangler-7756 dev path/to/script.js Additional artifacts:cloudflare-workers-bindings-extension: wget https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12765538678/npm-package-cloudflare-workers-bindings-extension-7756 -O ./cloudflare-workers-bindings-extension.0.0.0-v08528926a.vsix && code --install-extension ./cloudflare-workers-bindings-extension.0.0.0-v08528926a.vsix create-cloudflare: npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12765538678/npm-package-create-cloudflare-7756 --no-auto-update @cloudflare/kv-asset-handler: npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12765538678/npm-package-cloudflare-kv-asset-handler-7756 miniflare: npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12765538678/npm-package-miniflare-7756 @cloudflare/pages-shared: npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12765538678/npm-package-cloudflare-pages-shared-7756 @cloudflare/unenv-preset: npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12765538678/npm-package-cloudflare-unenv-preset-7756 @cloudflare/vitest-pool-workers: npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12765538678/npm-package-cloudflare-vitest-pool-workers-7756 @cloudflare/workers-editor-shared: npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12765538678/npm-package-cloudflare-workers-editor-shared-7756 @cloudflare/workers-shared: npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12765538678/npm-package-cloudflare-workers-shared-7756 @cloudflare/workflows-shared: npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12765538678/npm-package-cloudflare-workflows-shared-7756 Note that these links will no longer work once the GitHub Actions artifact expires.
Please ensure constraints are pinned, and |
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.
Can we do this more simply?
@@ -27,6 +32,14 @@ const configure = async () => { | |||
startText: "Adding the Cloudflare adapter", | |||
doneText: `${brandColor(`installed`)} ${dim(packages.join(", "))}`, | |||
}); | |||
|
|||
const { npm } = detectPackageManager(); | |||
await runCommand([npm, "run", NPM_TYPE_GEN_SCRIPT], { |
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.
I feel like a simpler change that doesn't require changes to how C3 hooks are run, is just to put the command that generates the types into a variable. Then run it here and use it to update the package.json below.
E.g.
await runCommand([npm, "run", NPM_TYPE_GEN_SCRIPT], { | |
const GENERATE_TYPES = ["wrangler", "types", "--env-interface", "CloudflareEnv", "cloudflare-env.d.ts"]; | |
await runCommand([npx, ...GENERATE_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.
That would work too but I prefer using the actual script.
Do you think that calling updatePackageScripts()
before configure
might ever cause issues?
(One of the reason is that we have hacks for yarn that does not support npx)
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.
I don't see the benefit in making this change to how C3 hooks run when a simple change to the c3.ts file would suffice. The update to the package.json is simply to make user facing scripts ready to go, not to support internal scripts.
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.
- What I mentionned
workers-sdk/packages/create-cloudflare/src/frameworks/index.ts
Lines 31 to 35 in df0e5be
// yarn cannot `yarn create@some-version` and doesn't have an npx equivalent | |
// So to retain the ability to lock versions we run it with `npx` and spoof | |
// the user agent so scaffolding tools treat the invocation like yarn | |
const cmd = [...(npm === "yarn" ? ["npx"] : dlx), cli, ...args]; | |
const env = npm === "yarn" ? { npm_config_user_agent: "yarn" } : {}; |
The update to the package.json is simply to make user facing scripts ready to go, not to support internal scripts.
the .d.ts
is supposed to be generated/updated by running the "user facing script", that is what this PR implements.
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.
That comment is not relevant here, I believe. We are not running the CLI generator script in this command, which has to be run outside of a node package.
Here we are just running wrangler types
command inside the package, which works fine with yarn.
@@ -49,7 +62,7 @@ export default { | |||
scripts: { | |||
deploy: `opennextjs-cloudflare && wrangler deploy`, | |||
preview: `opennextjs-cloudflare && wrangler dev`, | |||
"cf-typegen": `wrangler types --env-interface CloudflareEnv cloudflare-env.d.ts`, | |||
[NPM_TYPE_GEN_SCRIPT]: `wrangler types --env-interface CloudflareEnv cloudflare-env.d.ts`, |
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.
[NPM_TYPE_GEN_SCRIPT]: `wrangler types --env-interface CloudflareEnv cloudflare-env.d.ts`, | |
"cf-typegen: GENERATE_TYPES.join(" "), |
Ironically the tests for "// Generated by wrangler" was passing for files not generated by wrangler
Instead of copying an empty
cloudflare-env.d.ts
, the file is generated when the template is configured.Then it contains the existing bindgins:
Notes:
transformPackageJson
beforeconfigure
so that the latest can execute the added scriptsusesTypescript(...)
for template supporting JS).