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
32 changes: 11 additions & 21 deletions packages/repack/commands.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,33 @@
const path = require('path');
const { createRequire } = require('module');

function getReactNativeCliPath() {
let cliPath;

try {
cliPath = path.dirname(require.resolve('@react-native-community/cli'));
} catch {
// NOOP
}

try {
cliPath = path.dirname(
require.resolve('react-native/node_modules/@react-native-community/cli')
require.resolve('@react-native/community-cli-plugin')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will break Re.Pack working with 0.71 or 0.72, isn't it? Couldn't we look for "bin" entry in react-native package, which points to the cli?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately we can't go with the easy path, because right now start and bundle command are added in react-native.config.js so they won't exist under /commands dir.

);
} catch {
// NOOP
}

try {
const rnRequire = createRequire(require.resolve('react-native'));
cliPath = path.dirname(rnRequire.resolve('@react-native-community/cli'));
} catch {
// NOOP
}

if (!cliPath) {
throw new Error('Cannot resolve @react-native-community/cli package');
throw new Error(
'Cannot resolve @react-native/community-cli-plugin package'
);
}

return cliPath;
}

const {
projectCommands: cliCommands,
} = require(`${getReactNativeCliPath()}/commands`);
const cliCommands = require(getReactNativeCliPath());

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
Loading