Open Ethan-Arrowood opened 3 months ago
Note that ParseNodeOptionsEnvVar only splits the argument string into a vector of strings by whitespaces. It's not a full parser (i.e. doesn't validate and assign values).
That is okay. I think providing even the consistent whitespace/quote parsing is important. The core of the issue we ran into in Next.js was because we didn't understand the parsing rules for process.env.NODE_OPTIONS
.
I'd have to go and look at the code again, but there was something else that was validating the parsed options. That could be valuable to export as well.
What is the problem this feature will solve?
Node.js has an internal parser for correctly parsing and validating the
process.env.NODE_OPTIONS
variable. I'd like to expose this parser to user land as something likeutil.parseNodeOptions
.What is the feature you are proposing to solve the problem?
The exact parser code is here: https://github.com/nodejs/node/blob/c29d53c5cfc63c5a876084e788d70c9e87bed880/src/node_options.cc#L1401
The solution should create a new C++ function that accesses the
NODE_OPTIONS
environment variable from theEnvironment
so that we do not incur an unnecessary serialization cost passing theNODE_OPTIONS
from JS.Calling the function should return the list of strings.
The function should throw any error it encounters during the parsing process.
I will contribute this feature myself soon π
What alternatives have you considered?
We required this functionality for a recent bug in Next.js. I was able to solve that issue by manually converting the C++ parser to JS and using that.
The PR introducing the fix: https://github.com/vercel/next.js/pull/65046
The JS parser implementation itself: https://github.com/vercel/next.js/blob/270a9db0567808db5d53e7a18c7be0a4710796e8/packages/next/src/server/lib/utils.ts#L59-L113