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: get commands options and description from new package #477

Merged
5 changes: 5 additions & 0 deletions .changeset/eighty-elephants-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@callstack/repack": minor
---

fix: get commands options and description from new package (support RN>=0.73)
34 changes: 25 additions & 9 deletions packages/repack/commands.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const path = require('path');
const { createRequire } = require('module');

function getReactNativeCliPath() {
function getCommands() {
let cliPath;

try {
Expand All @@ -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 <path>',
Expand Down