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
37 changes: 28 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,38 @@ 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;
}

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 react-native package');
szymonrybczak marked this conversation as resolved.
Show resolved Hide resolved
}

return cliPath;
return commands;
}

const {
projectCommands: cliCommands,
} = require(`${getReactNativeCliPath()}/commands`);
const cliCommands = getCommands();
szymonrybczak marked this conversation as resolved.
Show resolved Hide resolved

const startCommand = cliCommands.find((command) => command.name === 'start');
const bundleCommand = cliCommands.find((command) => command.name === 'bundle');
const startCommand = Object.values(cliCommands).find(
(command) => command.name === 'start'
);
const bundleCommand = Object.values(cliCommands).find(
(command) => command.name === 'bundle'
);
szymonrybczak marked this conversation as resolved.
Show resolved Hide resolved

const webpackConfigOption = {
name: '--webpackConfig <path>',
Expand Down