-
Notifications
You must be signed in to change notification settings - Fork 785
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
feat: graduate --x-include-runtime
#8166
base: next
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 24d8152 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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/13439225900/npm-package-wrangler-8166 You can reference the automatically updated head of this PR with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/8166/npm-package-wrangler-8166 Or you can use npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13439225900/npm-package-wrangler-8166 dev path/to/script.js Additional artifacts:cloudflare-workers-bindings-extension: wget https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13439225900/npm-package-cloudflare-workers-bindings-extension-8166 -O ./cloudflare-workers-bindings-extension.0.0.0-va382c8b8b.vsix && code --install-extension ./cloudflare-workers-bindings-extension.0.0.0-va382c8b8b.vsix create-cloudflare: npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13439225900/npm-package-create-cloudflare-8166 --no-auto-update @cloudflare/kv-asset-handler: npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13439225900/npm-package-cloudflare-kv-asset-handler-8166 miniflare: npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13439225900/npm-package-miniflare-8166 @cloudflare/pages-shared: npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13439225900/npm-package-cloudflare-pages-shared-8166 @cloudflare/unenv-preset: npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13439225900/npm-package-cloudflare-unenv-preset-8166 @cloudflare/vite-plugin: npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13439225900/npm-package-cloudflare-vite-plugin-8166 @cloudflare/vitest-pool-workers: npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13439225900/npm-package-cloudflare-vitest-pool-workers-8166 @cloudflare/workers-editor-shared: npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13439225900/npm-package-cloudflare-workers-editor-shared-8166 @cloudflare/workers-shared: npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13439225900/npm-package-cloudflare-workers-shared-8166 @cloudflare/workflows-shared: npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13439225900/npm-package-cloudflare-workflows-shared-8166 Note that these links will no longer work once the GitHub Actions artifact expires.
Please ensure constraints are pinned, and |
56b09dc
to
3d88fea
Compare
fixtures/type-generation/tests/type-generation.file-comment.test.ts
Dismissed
Show dismissed
Hide dismissed
3d88fea
to
68d6130
Compare
c86cbf3
to
88426fa
Compare
@@ -0,0 +1,9 @@ | |||
--- | |||
"wrangler": minor |
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.
major? pretty sure there's nothing breaking. inclusion in v4 is mostly for politeness as there's a fair amount of CI usage
a7df791
to
c931fe0
Compare
9a873ab
to
4872cb9
Compare
|
||
`wrangler types` will now produce one file that contains both `Env` types and runtime types based on your compatibility date and flags. This is located at `worker-configuration.d.ts` by default. | ||
|
||
This behaviour was previously gated behind `--experimental-include-runtime`. That flag is no longer necessary and has been removed. It has been replaced by `--include-runtime` and `include-env`, both of which are set to `true` by default. |
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.
This behaviour was previously gated behind `--experimental-include-runtime`. That flag is no longer necessary and has been removed. It has been replaced by `--include-runtime` and `include-env`, both of which are set to `true` by default. | |
This behaviour was previously gated behind `--experimental-include-runtime`. That flag is no longer necessary and has been removed. It has been replaced by `--include-runtime` and `--include-env`, both of which are set to `true` by default. |
@@ -28,7 +28,7 @@ describe("`wrangler types` - file comment", () => { | |||
"packages", | |||
"wrangler" | |||
); | |||
execSync(`npx ${wranglerPath} types ${args}`, { | |||
execSync(`npx ${wranglerPath} types ${args} --include-runtime=false`, { |
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.
Should the describe l8 be updated? or should we not pass --include-runtime=false
?
const file = (await readFile(path.join(helper.tmpPath, "./types.d.ts"))) | ||
.toString() |
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.
Looks like this can be updated at multiple places
const file = (await readFile(path.join(helper.tmpPath, "./types.d.ts"))) | |
.toString() | |
const file = (await readFile(path.join(helper.tmpPath, "./types.d.ts"), "utf8")) |
`"// Generated by Wrangler by running \`wrangler types ./types.d.ts\` (hash: e82ba4d7b995dd9ca6fb0332d81f889b)"` | ||
); | ||
expect(file[1]).match( | ||
/\/\/ Runtime types generated with workerd@1\.\d+\.\d \d\d\d\d-\d\d-\d\d ([a-z_]+,?)*/ |
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.
/\/\/ Runtime types generated with workerd@1\.\d+\.\d \d\d\d\d-\d\d-\d\d ([a-z_]+,?)*/ | |
/\/\/ Runtime types generated with workerd@1\.\d+\.\d \d+-\d+-\d+ ([a-z_]+,?)*/ |
or \d{4}
/ \d{2}
but + is consistent with the first d+
const output = await helper.run( | ||
`wrangler types --x-include-runtime="./types.d.ts"` | ||
); | ||
const file2 = (await readFile(typesPath)).toString(); |
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.
utf8
if (!entry.file.endsWith(".ts")) { | ||
return; | ||
} | ||
let maybeExistingTypesFile: string[]; |
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.
let maybeExistingTypesFile: string[]; | |
let maybeExistingTypesFileLines: string[]; |
import type { Config } from "../config"; | ||
import type { Entry } from "../deployment-bundle/entry"; | ||
|
||
export const checkTypesDiff = async (config: Config, entry: Entry) => { |
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.
Add a comment about what this fn does?
try { | ||
const { envHeader } = await generateEnvTypes( | ||
config, | ||
{ strictVars: previousStrictVars === "false" ? false : true }, |
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.
{ strictVars: previousStrictVars === "false" ? false : true }, | |
{ strictVars: previousStrictVars !== "false" }, |
`Since you have the \`nodejs_compat\` flag, you should install Node.js types by running "npm i --save-dev @types/node${isWorkersTypesInstalled ? '@20.8.3".\nFor more details: https://developers.cloudflare.com/workers/languages/typescript/#known-issues' : '".'}` | ||
) |
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.
Something like the following might improve readibility?
`Since you have the \`nodejs_compat\` flag, you should install Node.js types by running "npm i --save-dev @types/node${isWorkersTypesInstalled ? '@20.8.3".\nFor more details: https://developers.cloudflare.com/workers/languages/typescript/#known-issues' : '".'}` | |
) | |
`Since you have the \`nodejs_compat\` flag, you should install Node.js types by running "npm i --save-dev ${isWorkersTypesInstalled ? "@types/node@20.8.3.\nFor more details: https://developers.cloudflare.com/workers/languages/typescript/#known-issues' : '@types/node.'}` | |
) |
4872cb9
to
2ef9aa4
Compare
|
||
try { | ||
const existingTypes = await readFile(outFile, "utf8"); | ||
if (existingTypes.split("\n")[0] === header) { | ||
const file = (await readFile(outFile, "utf8")).split("\n"); |
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.
const file = (await readFile(outFile, "utf8")).split("\n"); | |
const lines = (await readFile(outFile, "utf8")).split("\n"); |
TODO: rebase on /vnext for inclusion in wrangler v4
Might be best to review commit by commit
This PR will turn on runtime type generation by default for
wrangler types
.The
--experimental-include-runtime
flag will be superseded byinclude-runtime
andinclude-env
, both of which aretrue
by default.Also, the runtime types will be generated in the same file as the env types, at the location specified by path (
worker-configuration.d.ts
by default).Before:

After:
