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(CLI): fix getDevNodeOptions #9735

Merged
merged 6 commits into from
Dec 20, 2023
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
4 changes: 2 additions & 2 deletions packages/cli/src/commands/__tests__/dev.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ describe('yarn rw dev', () => {
)

expect(apiCommand.command).toMatchInlineSnapshot(
`"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 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""`
)

expect(generateCommand.command).toEqual('yarn rw-gen-watch')
Expand Down Expand Up @@ -144,7 +144,7 @@ describe('yarn rw dev', () => {
)

expect(apiCommand.command).toMatchInlineSnapshot(
`"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 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""`
)

expect(generateCommand.command).toEqual('yarn rw-gen-watch')
Expand Down
7 changes: 3 additions & 4 deletions packages/cli/src/commands/devHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export const handler = async ({
const jobs = {
api: {
name: 'api',
command: `yarn cross-env NODE_ENV=development ${getDevNodeOptions()} yarn nodemon --quiet --watch "${redwoodConfigPath}" --exec "yarn rw-api-server-watch --port ${apiAvailablePort} ${getApiDebugFlag()} | rw-log-formatter"`,
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"`,
prefixColor: 'cyan',
runWhen: () => fs.existsSync(rwjsPaths.api.src),
},
Expand Down Expand Up @@ -224,18 +224,17 @@ export const handler = async ({
}

/**
* Gets the NODE_OPTIONS environment variable from `process.env`, appending `--enable-source-maps` if it's not already there.
* Gets the value of the `NODE_OPTIONS` env var from `process.env`, appending `--enable-source-maps` if it's not already there.
* See https://nodejs.org/api/cli.html#node_optionsoptions.
*
* @returns {string}
*/
export function getDevNodeOptions() {
const { NODE_OPTIONS } = process.env

const enableSourceMapsOption = '--enable-source-maps'

if (!NODE_OPTIONS) {
return `NODE_OPTIONS=${enableSourceMapsOption}`
return enableSourceMapsOption
}

if (NODE_OPTIONS.includes(enableSourceMapsOption)) {
Expand Down
13 changes: 6 additions & 7 deletions packages/cli/src/lib/__tests__/getDevNodeOptions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,22 @@ describe('getNodeOptions', () => {

it('defaults to enable-source-maps', () => {
const nodeOptions = getDevNodeOptions()
expect(nodeOptions).toEqual(`NODE_OPTIONS=${enableSourceMapsOption}`)
expect(nodeOptions).toEqual(enableSourceMapsOption)
})

it("doesn't specify `--enable-source-maps` twice", () => {
process.env.NODE_OPTIONS = `NODE_OPTIONS=${enableSourceMapsOption}`
process.env.NODE_OPTIONS = enableSourceMapsOption

const nodeOptions = getDevNodeOptions()
expect(nodeOptions).toEqual(`NODE_OPTIONS=${enableSourceMapsOption}`)
expect(nodeOptions).toEqual(enableSourceMapsOption)
})

it('merges existing options with `--enable-source-maps`', () => {
const existingOptions = '--inspect --no-experimental-fetch'
process.env.NODE_OPTIONS = `NODE_OPTIONS=${existingOptions}`
process.env.NODE_OPTIONS = existingOptions

const nodeOptions = getDevNodeOptions()
expect(nodeOptions).toEqual(
`NODE_OPTIONS=${existingOptions} ${enableSourceMapsOption}`
)

expect(nodeOptions).toEqual(`${existingOptions} ${enableSourceMapsOption}`)
})
})
Loading