Skip to content

Commit

Permalink
fix(ext/node): Support returning tokens and option defaults in `node:…
Browse files Browse the repository at this point in the history
…util.parseArgs` (#23192)

Fixes #23179.
Fixes #22454.

Enables passing `{tokens: true}` to `parseArgs` and setting default
values for options.

With this PR, the observable framework works with deno out of the box
(no unstable flags needed).

The existing code was basically copied straight from node, so this PR
mostly just updates that (out of date) vendored code. Also fixes some
issues with error exports (before this PR, in certain error cases we
were attempting to construct error classes that weren't actually in
scope).

The last change (in the second commit) adds a small hack so that we
actually exercise the `test-parse-args.js` node_compat test, previously
it was reported as passing though it should have failed. That test now
passes.

---------

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
  • Loading branch information
2 people authored and satyarohith committed Apr 11, 2024
1 parent f4e4e1b commit 77f2a2c
Show file tree
Hide file tree
Showing 5 changed files with 304 additions and 142 deletions.
8 changes: 8 additions & 0 deletions ext/node/polyfills/internal/errors.ts
Expand Up @@ -17,6 +17,8 @@
* ERR_INVALID_PACKAGE_CONFIG // package.json stuff, probably useless
*/

import { primordials } from "ext:core/mod.js";
const { JSONStringify } = primordials;
import { format, inspect } from "ext:deno_node/internal/util/inspect.mjs";
import { codes } from "ext:deno_node/internal/error_codes.ts";
import {
Expand Down Expand Up @@ -2629,6 +2631,11 @@ codes.ERR_OUT_OF_RANGE = ERR_OUT_OF_RANGE;
codes.ERR_SOCKET_BAD_PORT = ERR_SOCKET_BAD_PORT;
codes.ERR_BUFFER_OUT_OF_BOUNDS = ERR_BUFFER_OUT_OF_BOUNDS;
codes.ERR_UNKNOWN_ENCODING = ERR_UNKNOWN_ENCODING;
codes.ERR_PARSE_ARGS_INVALID_OPTION_VALUE = ERR_PARSE_ARGS_INVALID_OPTION_VALUE;
codes.ERR_PARSE_ARGS_UNEXPECTED_POSITIONAL =
ERR_PARSE_ARGS_UNEXPECTED_POSITIONAL;
codes.ERR_PARSE_ARGS_UNKNOWN_OPTION = ERR_PARSE_ARGS_UNKNOWN_OPTION;

// TODO(kt3k): assign all error classes here.

/**
Expand Down Expand Up @@ -2846,6 +2853,7 @@ export default {
ERR_OUT_OF_RANGE,
ERR_PACKAGE_IMPORT_NOT_DEFINED,
ERR_PACKAGE_PATH_NOT_EXPORTED,
ERR_PARSE_ARGS_INVALID_OPTION_VALUE,
ERR_QUICCLIENTSESSION_FAILED,
ERR_QUICCLIENTSESSION_FAILED_SETSOCKET,
ERR_QUICSESSION_DESTROYED,
Expand Down

0 comments on commit 77f2a2c

Please sign in to comment.