Skip to content
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

watch: watch env files in --watch mode #54033

Closed
wants to merge 3 commits into from
Closed

Conversation

HBSPS
Copy link
Contributor

@HBSPS HBSPS commented Jul 25, 2024

observe env files in --watch mode through the watcher's filterFile and forward changes to the childProcess

Fixes: #54001

@nodejs-github-bot nodejs-github-bot added the needs-ci PRs that need a full CI run. label Jul 25, 2024
observe env files in `--watch` mode through the watcher's filterFile and
forward changes to the childProcess

Fixes: nodejs#54001

let kEnv = {};
for (const arg of process.execArgv) {
if (StringPrototypeStartsWith(arg, '--env-file')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use getOptionValue instead of iterating over all of process.execArgv

Copy link
Contributor Author

@HBSPS HBSPS Jul 26, 2024

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 used getOptionValue('--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.

Comment on lines +75 to +76
const envContent = parseEnv(readFileSync(envFile, 'utf8'));
kEnv = { ...kEnv, ...envContent };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const envContent = parseEnv(readFileSync(envFile, 'utf8'));
kEnv = { ...kEnv, ...envContent };

I am pretty sure that watcher.filterFile is enough since the spawned process should handle --env-file by its own
this is also missing error handling (what happens if env file is renamed/deleted)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am pretty sure that watcher.filterFile is enough since the spawned process should handle --env-file by its own

I've tested it many times, but when the child is spwan, it inherits the parent's process.env. If I only use the watcher.filterFile, if the env file is modified, it triggers a restart of the child process, but the information from the modified env doesn't seem to go to the child.

This is why I used parseEnv and readFileSync.

Refs: #54001 (comment)

this is also missing error handling (what happens if env file is renamed/deleted)?

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 ${envFile}: not found like when I first start watch mode?

Copy link
Member

@anonrig anonrig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR needs a test

lib/internal/main/watch_mode.js Show resolved Hide resolved
@HBSPS
Copy link
Contributor Author

HBSPS commented Jul 26, 2024

This PR needs a test

Does this mean I need to write a related test code or does it mean CI workflows in PR?

@anonrig
Copy link
Member

anonrig commented Jul 26, 2024

This PR needs a test

Does this mean I need to write a related test code or does it mean CI workflows in PR?

You need to write a related test code that covers the feature

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

--env-file watch
5 participants