diff --git a/.changeset/eighty-elephants-report.md b/.changeset/eighty-elephants-report.md new file mode 100644 index 000000000..180635cda --- /dev/null +++ b/.changeset/eighty-elephants-report.md @@ -0,0 +1,5 @@ +--- +"@callstack/repack": minor +--- + +fix: get commands options and description from new package (support RN>=0.73) diff --git a/packages/repack/commands.js b/packages/repack/commands.js index 2ebdebf3a..3574818a5 100644 --- a/packages/repack/commands.js +++ b/packages/repack/commands.js @@ -1,7 +1,7 @@ const path = require('path'); const { createRequire } = require('module'); -function getReactNativeCliPath() { +function getCommands() { let cliPath; try { @@ -25,19 +25,35 @@ function getReactNativeCliPath() { // NOOP } - if (!cliPath) { - throw new Error('Cannot resolve @react-native-community/cli package'); + const { projectCommands } = require(`${cliPath}/commands`); + const commandNames = Object.values(projectCommands).map(({ name }) => name); + + if (commandNames.includes('bundle') && commandNames.includes('start')) { + return projectCommands; + } + + // RN >= 0.73 + let commands; + + try { + commands = require(require.resolve( + 'react-native/react-native.config.js' + )).commands; + } catch (e) { + // NOOP + } + + if (!commands) { + throw new Error('Cannot resolve path to react-native package'); } - return cliPath; + return commands; } -const { - projectCommands: cliCommands, -} = require(`${getReactNativeCliPath()}/commands`); +const cliCommands = Object.values(getCommands()); -const startCommand = cliCommands.find((command) => command.name === 'start'); -const bundleCommand = cliCommands.find((command) => command.name === 'bundle'); +const startCommand = cliCommands.find(({ name }) => name === 'start'); +const bundleCommand = cliCommands.find(({ name }) => name === 'bundle'); const webpackConfigOption = { name: '--webpackConfig ',