Skip to content

Commit

Permalink
fix(CLI): merge NODE_OPTIONS in yarn rw dev (redwoodjs#9585)
Browse files Browse the repository at this point in the history
  • Loading branch information
jtoar authored Dec 7, 2023
1 parent ab335d9 commit 3ca1f03
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 22 deletions.
24 changes: 23 additions & 1 deletion 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 NODE_OPTIONS=--enable-source-maps yarn nodemon --quiet --watch "${redwoodConfigPath}" --exec "yarn rw-api-server-watch --port ${apiAvailablePort} ${getApiDebugFlag()} | rw-log-formatter"`,
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"`,
prefixColor: 'cyan',
runWhen: () => fs.existsSync(rwjsPaths.api.src),
},
Expand Down Expand Up @@ -222,3 +222,25 @@ export const handler = async ({
}
})
}

/**
* Gets the NODE_OPTIONS environment variable 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}`
}

if (NODE_OPTIONS.includes(enableSourceMapsOption)) {
return NODE_OPTIONS
}

return `${NODE_OPTIONS} ${enableSourceMapsOption}`
}
27 changes: 27 additions & 0 deletions packages/cli/src/lib/__tests__/getDevNodeOptions.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { getDevNodeOptions } from '../../commands/devHandler'

describe('getNodeOptions', () => {
const enableSourceMapsOption = '--enable-source-maps'

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

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

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

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

const nodeOptions = getDevNodeOptions()
expect(nodeOptions).toEqual(
`NODE_OPTIONS=${existingOptions} ${enableSourceMapsOption}`
)
})
})
40 changes: 19 additions & 21 deletions tasks/release/release.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,28 @@ async function resolveMilestones() {
}

// Depending on if we're releasing a patch or not, there's a few things we need to check.
const {
search: { nodes: prs },
} = await octokit.graphql(`
{
search(
query: "repo:redwoodjs/redwood is:pr is:merged milestone:next-release-patch"
first: 5
type: ISSUE
) {
nodes {
... on PullRequest {
id
}
}
}
}
`)

if (semver === 'patch') {
console.log()
console.log(
`Since we're releasing a ${chalk.magenta(
'patch'
)}, we'll be releasing all the PRs that have the ${chalk.magenta(
`There's ${prs.length} PR(s) that have the ${chalk.magenta(
'next-release-patch'
)} milestone.`
)
Expand All @@ -238,24 +254,6 @@ async function resolveMilestones() {
)
}
} else {
const {
search: { nodes: prs },
} = await octokit.graphql(`
{
search(
query: "repo:redwoodjs/redwood is:pr is:merged milestone:next-release-patch"
first: 5
type: ISSUE
) {
nodes {
... on PullRequest {
id
}
}
}
}
`)

if (prs.length) {
console.log()
console.log(
Expand Down

0 comments on commit 3ca1f03

Please sign in to comment.