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

chore: defineCommand refactor for wrangler types and tail #7220

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

emily-shen
Copy link
Contributor

@emily-shen emily-shen commented Nov 11, 2024

moving another couple of commands to defineCommand
related #6655


  • Tests
    • TODO (before merge)
    • Tests included
    • Tests not necessary because: no behaviour change, just needs to pass existing
  • E2E Tests CI Job required? (Use "e2e" label or ask maintainer to run separately)
    • I don't know
    • Required
    • Not required because: no behaviour change, just needs to pass existing
  • Public documentation
    • TODO (before merge)
    • Cloudflare docs PR(s):
    • Documentation not necessary because: internal refactor

@emily-shen emily-shen requested a review from a team as a code owner November 11, 2024 13:16
Copy link

changeset-bot bot commented Nov 11, 2024

⚠️ No Changeset found

Latest commit: 1338784

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

Copy link
Contributor

github-actions bot commented Nov 11, 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/11854761777/npm-package-wrangler-7220

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

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

Or you can use npx with this latest build directly:

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

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


[email protected] includes the following runtime dependencies:

Package Constraint Resolved
miniflare workspace:* 3.20241106.0
workerd 1.20241106.1 1.20241106.1
workerd --version 1.20241106.1 2024-11-06

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

packages/wrangler/src/tail/index.ts Show resolved Hide resolved
Comment on lines +49 to +61
const validInterfaceRegex = /^[a-zA-Z][a-zA-Z0-9_]*$/;

if (!validInterfaceRegex.test(envInterface)) {
throw new CommandLineArgsError(
`The provided env-interface value ("${envInterface}") does not satisfy the validation regex: ${validInterfaceRegex}`
);
}
if (!validInterfaceRegex.test(envInterface)) {
throw new CommandLineArgsError(
`The provided env-interface value ("${envInterface}") does not satisfy the validation regex: ${validInterfaceRegex}`
);
}

if (!outputPath.endsWith(".d.ts")) {
throw new CommandLineArgsError(
`The provided path value ("${outputPath}") does not point to a declaration file (please use the 'd.ts' extension)`
);
}
if (!outputPath.endsWith(".d.ts")) {
throw new CommandLineArgsError(
`The provided path value ("${outputPath}") does not point to a declaration file (please use the 'd.ts' extension)`
);
}
Copy link
Member

Choose a reason for hiding this comment

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

The difference you see on the tests seems to be caused by us calling readConfig before the handler. Move these logic to validateArgs might fix it

Copy link
Contributor Author

@emily-shen emily-shen Nov 13, 2024

Choose a reason for hiding this comment

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

ugh it isn't failing locally, that's super weird - but good point
edit: nope, the tests are failing for tail and this is for types (sorry again for having the two in one PR 😅 ...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh sorry do you mean the tests I modify? Yeah those have changed because readConfig is running first. Don't think moving these into validateArgs would fix it, but arguably makes sense to do anyway 👍

Could have moved the config file check into validateArgs, but I thought it would be better to have readConfig handle the case where the specified config file doesn't exist since that's a general error (hence getting a ParseError now), and the type gen handler to handle the case where there is no config file at all, since that's a wrangler types specific error.

await expect(
runWrangler("types -c hello.toml")
).rejects.toThrowErrorMatchingInlineSnapshot(
`[ParseError: Could not read file: hello.toml]`
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like a slightly worse error message—is there any way we can improve it?

Copy link
Contributor Author

@emily-shen emily-shen Nov 14, 2024

Choose a reason for hiding this comment

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

think its okay as it does also output ENOENT: no such file or directory... but that didn't show up in the snapshot for some reason 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Untriaged
Development

Successfully merging this pull request may close these issues.

3 participants