From 3ca1f03a5437c41aaea1d0b71711215eb3e5bc91 Mon Sep 17 00:00:00 2001 From: Dominic Saadi Date: Wed, 6 Dec 2023 23:57:03 -0800 Subject: [PATCH] fix(CLI): merge NODE_OPTIONS in `yarn rw dev` (#9585) --- packages/cli/src/commands/devHandler.js | 24 ++++++++++- .../lib/__tests__/getDevNodeOptions.test.js | 27 +++++++++++++ tasks/release/release.mjs | 40 +++++++++---------- 3 files changed, 69 insertions(+), 22 deletions(-) create mode 100644 packages/cli/src/lib/__tests__/getDevNodeOptions.test.js diff --git a/packages/cli/src/commands/devHandler.js b/packages/cli/src/commands/devHandler.js index 964143794423..6ba3e6858659 100644 --- a/packages/cli/src/commands/devHandler.js +++ b/packages/cli/src/commands/devHandler.js @@ -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), }, @@ -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}` +} diff --git a/packages/cli/src/lib/__tests__/getDevNodeOptions.test.js b/packages/cli/src/lib/__tests__/getDevNodeOptions.test.js new file mode 100644 index 000000000000..cc34d471b9d7 --- /dev/null +++ b/packages/cli/src/lib/__tests__/getDevNodeOptions.test.js @@ -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}` + ) + }) +}) diff --git a/tasks/release/release.mjs b/tasks/release/release.mjs index 030565038400..3be51a42d06a 100644 --- a/tasks/release/release.mjs +++ b/tasks/release/release.mjs @@ -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.` ) @@ -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(