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

fix(wrangler): enforce single value on non-array arguments #7005

Merged
merged 6 commits into from
Oct 22, 2024

Conversation

edmundhung
Copy link
Member

@edmundhung edmundhung commented Oct 17, 2024

What this PR solves / how to test

Fixes n/a

Author has addressed the following

  • Tests
    • TODO (before merge)
    • Tests included
    • Tests not necessary because:
  • E2E Tests CI Job required? (Use "e2e" label or ask maintainer to run separately)
    • I don't know
    • Required
    • Not required because:
  • Changeset (Changeset guidelines)
    • TODO (before merge)
    • Changeset included
    • Changeset not necessary because:
  • Public documentation
    • TODO (before merge)
    • Cloudflare docs PR(s):
    • Documentation not necessary because: bug fix

Copy link

changeset-bot bot commented Oct 17, 2024

🦋 Changeset detected

Latest commit: 18b523b

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

This PR includes changesets to release 2 packages
Name Type
wrangler Patch
@cloudflare/vitest-pool-workers 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

@edmundhung edmundhung changed the title fix(wrangler): accept duplication arguments only if allowed fix(wrangler): restrict duplicated arguments Oct 17, 2024
Copy link
Contributor

github-actions bot commented Oct 17, 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/11458507774/npm-package-wrangler-7005

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

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

Or you can use npx with this latest build directly:

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

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


wrangler@3.81.0 includes the following runtime dependencies:

Package Constraint Resolved
miniflare workspace:* 3.20241011.0
workerd 1.20241018.1 1.20241018.1
workerd --version 1.20241018.1 2024-10-18

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

@edmundhung edmundhung force-pushed the edmundhung/no-array-on-non-array-args branch from 7864a86 to 4c27cf8 Compare October 18, 2024 11:21
@edmundhung edmundhung changed the title fix(wrangler): restrict duplicated arguments fix(wrangler): enforce single value on non-array arguments Oct 18, 2024
Comment on lines +129 to +138
// Yargs offers an `array: true` option that will always coerces the value to an array
// e.g. `--name foo` becomes `{ name: ["foo"] }` instead of `{ name: "foo" }`
// However, non-array arguments can still receives multiple values
// e.g. `--name foo --name bar` becomes `{ name: ["foo", "bar"] }` regardless of the `array` setting
// @see https://github.com/yargs/yargs/issues/1318
for (const [key, opt] of Object.entries(def.args)) {
if (!opt.array) {
yargs.check(demandSingleValue(key));
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Good stuff! This util is intended for us to be more opinionated than yargs 👏

@edmundhung edmundhung force-pushed the edmundhung/no-array-on-non-array-args branch 2 times, most recently from 4bf4f4b to 9386d88 Compare October 21, 2024 13:49
};
}

export class CommandLineArgsError extends UserError {}
Copy link
Member Author

@edmundhung edmundhung Oct 21, 2024

Choose a reason for hiding this comment

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

I moved it to errors.ts since both demandOneOfOption and demandSingleValue need this error class.

@edmundhung edmundhung added the e2e Run e2e tests on a PR label Oct 21, 2024
@edmundhung edmundhung force-pushed the edmundhung/no-array-on-non-array-args branch from abc064e to c1d4738 Compare October 21, 2024 14:31
@edmundhung edmundhung marked this pull request as ready for review October 21, 2024 14:31
@edmundhung edmundhung requested review from a team as code owners October 21, 2024 14:31
@edmundhung edmundhung force-pushed the edmundhung/no-array-on-non-array-args branch from c1d4738 to 18b523b Compare October 22, 2024 10:42
@edmundhung edmundhung merged commit 6131ef5 into main Oct 22, 2024
19 checks passed
@edmundhung edmundhung deleted the edmundhung/no-array-on-non-array-args branch October 22, 2024 11:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
e2e Run e2e tests on a PR
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants