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(ext/node): add util.parseArgs #21342

Merged
merged 2 commits into from
Nov 29, 2023
Merged

Conversation

kt3k
Copy link
Member

@kt3k kt3k commented Nov 27, 2023

This PR adds parseArgs of node:util.

import { parseArgs } from "node:util";
const args = ['-f', '--bar', 'b'];
const options = {
  foo: {
    type: 'boolean',
    short: 'f',
  },
  bar: {
    type: 'string',
  },
};
const {
  values,
  positionals,
} = parseArgs({ args, options });
console.log(values, positionals);
$ ./target/debug/deno run a.mjs              
[Object: null prototype] { foo: true, bar: "b" } []

closes #20452

ArrayPrototypeSlice,
ArrayPrototypePush,
ArrayPrototypeUnshiftApply,
ObjectPrototypeHasOwnProperty: ObjectHasOwn,
Copy link
Contributor

Choose a reason for hiding this comment

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

This alias is not necessary

Suggested change
ObjectPrototypeHasOwnProperty: ObjectHasOwn,
ObjectHasOwn,

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense. Thanks

const {
ArrayPrototypeFind,
ObjectEntries,
ObjectPrototypeHasOwnProperty: ObjectHasOwn,
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

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

Looks great, I'm unsure about a new flag.

@@ -83,6 +83,7 @@ async function runTest(t: Deno.TestContext, path: string): Promise<void> {
"--quiet",
"--unstable",
//"--unsafely-ignore-certificate-errors",
"--unstable-bare-node-builtins",
Copy link
Member

Choose a reason for hiding this comment

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

Why is this flag required?

Copy link
Member Author

Choose a reason for hiding this comment

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

The added case (test-parse-args.mjs) is the first one in our compat test suite that depends on cli/tests/node_compat/test/common/index.mjs, and that file has bare import of module module

import { createRequire } from 'module';

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

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

LGTM, nice work. Please update compat list in deno-docs repo after landing.

@kt3k kt3k merged commit e332fa4 into denoland:main Nov 29, 2023
14 checks passed
@kt3k kt3k deleted the node-util-parse-args branch November 29, 2023 06:43
@kt3k
Copy link
Member Author

kt3k commented Nov 29, 2023

Please update compat list in deno-docs repo after landing.

I opened denoland/deno-docs#206 and #21378. There seem still 7 APIs missing in node:util.

Danielduel pushed a commit to Danielduel/deno that referenced this pull request Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feature-request] node:util's parseArgs
3 participants