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

fix NODE_OPTIONS env forwarding #11587

Merged
merged 4 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .changesets/11587.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
- fix `NODE_OPTIONS` env forwarding (#11587) by @cometkim

This change updates how we pass through any `NODE_OPTIONS` when you run the API side development server with `yarn rw dev`. Previously there may have been issues like unescaped spaces in paths which would have produced errors like:

```
api | node:events:497
api | throw er; // Unhandled 'error' event
api | ^
api |
api | Error: spawn space.js --enable-source-maps ENOENT
api | at ChildProcess._handle.onexit (node:internal/child_process:286:19)
api | at onErrorNT (node:internal/child_process:484:16)
api | at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
api | Emitted 'error' event on ChildProcess instance at:
api | at ChildProcess._handle.onexit (node:internal/child_process:292:12)
api | at onErrorNT (node:internal/child_process:484:16)
api | at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
api | errno: -2,
api | code: 'ENOENT',
api | syscall: 'spawn space.js --enable-source-maps',
api | path: 'space.js --enable-source-maps',
api | spawnargs: [
api | 'yarn',
api | 'nodemon',
api | '--quiet',
api | '--watch',
api | '/Users/jgmw/Development/redwood/rw-test/node_options_fix/redwood.toml',
api | '--exec',
api | 'yarn rw-api-server-watch --port 8911 --debug-port 18911 | rw-log-formatter'
api | ]
api | }
api |
api | Node.js v20.17.0
```

Now these sort of error should no longer occur.
8 changes: 6 additions & 2 deletions packages/cli/src/commands/__tests__/dev.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,10 @@ describe('yarn rw dev', () => {
// test environments (vite sets this in their vite-ecosystem-ci tests)
.replace(/--max-old-space-size=\d+\s/, ''),
).toEqual(
'yarn cross-env NODE_ENV=development NODE_OPTIONS="--enable-source-maps" yarn nodemon --quiet --watch "/mocked/project/redwood.toml" --exec "yarn rw-api-server-watch --port 8911 --debug-port 18911 | rw-log-formatter"',
'yarn nodemon --quiet --watch "/mocked/project/redwood.toml" --exec "yarn rw-api-server-watch --port 8911 --debug-port 18911 | rw-log-formatter"',
)
expect(apiCommand.env.NODE_ENV).toEqual('development')
expect(apiCommand.env.NODE_OPTIONS).toContain('--enable-source-maps')

expect(generateCommand.command).toEqual('yarn rw-gen-watch')
})
Expand Down Expand Up @@ -166,8 +168,10 @@ describe('yarn rw dev', () => {
// test environments (vite sets this in their vite-ecosystem-ci tests)
.replace(/--max-old-space-size=\d+\s/, ''),
).toEqual(
'yarn cross-env NODE_ENV=development NODE_OPTIONS="--enable-source-maps" yarn nodemon --quiet --watch "/mocked/project/redwood.toml" --exec "yarn rw-api-server-watch --port 8911 --debug-port 18911 | rw-log-formatter"',
'yarn nodemon --quiet --watch "/mocked/project/redwood.toml" --exec "yarn rw-api-server-watch --port 8911 --debug-port 18911 | rw-log-formatter"',
)
expect(apiCommand.env.NODE_ENV).toEqual('development')
expect(apiCommand.env.NODE_OPTIONS).toContain('--enable-source-maps')

expect(generateCommand.command).toEqual('yarn rw-gen-watch')
})
Expand Down
19 changes: 11 additions & 8 deletions packages/cli/src/commands/devHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,18 @@ export const handler = async ({
api: {
name: 'api',
command: [
`yarn cross-env NODE_ENV=development NODE_OPTIONS="${getDevNodeOptions()}"`,
' yarn nodemon',
' --quiet',
` --watch "${redwoodConfigPath}"`,
' --exec "yarn rw-api-server-watch',
` --port ${apiAvailablePort}`,
` ${getApiDebugFlag()}`,
' | rw-log-formatter"',
'yarn nodemon',
' --quiet',
` --watch "${redwoodConfigPath}"`,
' --exec "yarn rw-api-server-watch',
` --port ${apiAvailablePort}`,
` ${getApiDebugFlag()}`,
' | rw-log-formatter"',
].join(' '),
env: {
NODE_ENV: 'development',
NODE_OPTIONS: getDevNodeOptions(),
},
prefixColor: 'cyan',
runWhen: () => fs.existsSync(rwjsPaths.api.src),
},
Expand Down
Loading