-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
watch: watch env files in --watch mode
#54033
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -6,6 +6,7 @@ const { | |||||
| ArrayPrototypePush, | ||||||
| ArrayPrototypePushApply, | ||||||
| ArrayPrototypeSlice, | ||||||
| StringPrototypeSplit, | ||||||
| StringPrototypeStartsWith, | ||||||
| } = primordials; | ||||||
|
|
||||||
|
|
@@ -22,10 +23,11 @@ const { FilesWatcher } = require('internal/watch_mode/files_watcher'); | |||||
| const { green, blue, red, white, clear } = require('internal/util/colors'); | ||||||
|
|
||||||
| const { spawn } = require('child_process'); | ||||||
| const { inspect } = require('util'); | ||||||
| const { inspect, parseEnv } = require('util'); | ||||||
| const { setTimeout, clearTimeout } = require('timers'); | ||||||
| const { resolve } = require('path'); | ||||||
| const { once } = require('events'); | ||||||
| const { readFileSync } = require('fs'); | ||||||
|
|
||||||
| prepareMainThreadExecution(false, false); | ||||||
| markBootstrapComplete(); | ||||||
|
|
@@ -64,11 +66,23 @@ let exited; | |||||
|
|
||||||
| function start() { | ||||||
| exited = false; | ||||||
|
|
||||||
| let kEnv = {}; | ||||||
| for (const arg of process.execArgv) { | ||||||
| if (StringPrototypeStartsWith(arg, '--env-file')) { | ||||||
| const envFile = resolve(StringPrototypeSplit(arg, '=')[1]); | ||||||
| watcher.filterFile(envFile, null); | ||||||
| const envContent = parseEnv(readFileSync(envFile, 'utf8')); | ||||||
| kEnv = { ...kEnv, ...envContent }; | ||||||
|
Comment on lines
+75
to
+76
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I am pretty sure that
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I've tested it many times, but when the child is spwan, it inherits the parent's This is why I used Refs: #54001 (comment)
Oh, this is my mistake. If I can't find the --env-file I set when I started watch mode (because it's renamed or deleted), is it a good way to print
anonrig marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| } | ||||||
| } | ||||||
|
|
||||||
| const stdio = kShouldFilterModules ? ['inherit', 'inherit', 'inherit', 'ipc'] : 'inherit'; | ||||||
| child = spawn(process.execPath, argsWithoutWatchOptions, { | ||||||
| stdio, | ||||||
| env: { | ||||||
| ...process.env, | ||||||
| ...kEnv, | ||||||
| WATCH_REPORT_DEPENDENCIES: '1', | ||||||
| }, | ||||||
| }); | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use
getOptionValueinstead of iterating over all ofprocess.execArgvUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact, I've already applied
getOptionValue, but when I usedgetOptionValue('--env-file')with multiple --env-file options set, I had a problem that I could only get the last --env-file information. Not an array of --env-file information.