deno/ext/node/polyfills/internal_binding/node_options.ts
Yoshiya Hinosawa ff8160b594
Some checks are pending
ci / test release linux-aarch64 (push) Blocked by required conditions
ci / test debug macos-aarch64 (push) Blocked by required conditions
ci / test release macos-aarch64 (push) Blocked by required conditions
ci / bench release linux-x86_64 (push) Blocked by required conditions
ci / lint debug linux-x86_64 (push) Blocked by required conditions
ci / lint debug macos-x86_64 (push) Blocked by required conditions
ci / lint debug windows-x86_64 (push) Blocked by required conditions
ci / test debug linux-x86_64 (push) Blocked by required conditions
ci / test release linux-x86_64 (push) Blocked by required conditions
ci / test debug macos-x86_64 (push) Blocked by required conditions
ci / test release macos-x86_64 (push) Blocked by required conditions
ci / test debug windows-x86_64 (push) Blocked by required conditions
ci / test release windows-x86_64 (push) Blocked by required conditions
ci / pre-build (push) Waiting to run
ci / test debug linux-aarch64 (push) Blocked by required conditions
ci / build wasm32 (push) Blocked by required conditions
ci / publish canary (push) Blocked by required conditions
fix(ext/node): support DEP0005 deprecation warning (#29530)
This commit adds support of `DEP0005` warning which is emitted when the user
calls `Buffer` as constructor.
2025-06-04 12:25:32 +09:00

43 lines
1.3 KiB
TypeScript

// Copyright 2018-2025 the Deno authors. MIT license.
import { primordials } from "ext:core/mod.js";
const {
SafeMap,
ArrayPrototypeForEach,
SafeRegExp,
StringPrototypeSplit,
} = primordials;
// This module ports:
// - https://github.com/nodejs/node/blob/master/src/node_options-inl.h
// - https://github.com/nodejs/node/blob/master/src/node_options.cc
// - https://github.com/nodejs/node/blob/master/src/node_options.h
/** Gets the all options for Node.js
* This function is expensive to execute. `getOptionValue` in `internal/options.ts`
* should be used instead to get a specific option. */
export function getOptions() {
const options = new SafeMap([
["--warnings", { value: true }],
["--pending-deprecation", { value: false }],
]);
const nodeOptions = Deno.env.get("NODE_OPTIONS");
const args = nodeOptions
? StringPrototypeSplit(nodeOptions, new SafeRegExp("\\s"))
: [];
ArrayPrototypeForEach(args, (arg) => {
switch (arg) {
case "--no-warnings":
options.set("--warnings", { value: false });
break;
case "--pending-deprecation":
options.set("--pending-deprecation", { value: true });
break;
// TODO(kt3k): Handle other options.
default:
break;
}
});
return { options };
}