-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Expand file tree
/
Copy pathnode_options.ts
More file actions
50 lines (46 loc) · 1.49 KB
/
node_options.ts
File metadata and controls
50 lines (46 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2018-2026 the Deno authors. MIT license.
import { primordials } from "ext:core/mod.js";
const {
SafeMap,
ArrayPrototypeForEach,
SafeRegExp,
StringPrototypeSlice,
StringPrototypeSplit,
StringPrototypeStartsWith,
} = 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 }],
["--title", { value: "" }],
]);
const nodeOptions = Deno.env.get("NODE_OPTIONS");
const args = nodeOptions
? StringPrototypeSplit(nodeOptions, new SafeRegExp("\\s"))
: [];
ArrayPrototypeForEach(args, (arg) => {
if (StringPrototypeStartsWith(arg, "--title=")) {
options.set("--title", { value: StringPrototypeSlice(arg, 8) });
return;
}
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 };
}