Skip to content

Commit

Permalink
fix: get commands options and description from new package (#477)
Browse files Browse the repository at this point in the history
* fix: get commands options and description from new package

* chore: add changset

* fix: keep backward compatability

* Update packages/repack/commands.js

Co-authored-by: Jakub Romańczyk <[email protected]>

* Update packages/repack/commands.js

Co-authored-by: Jakub Romańczyk <[email protected]>

* Update packages/repack/commands.js

Co-authored-by: Jakub Romańczyk <[email protected]>

* fix: linter

* chore(repack): document the changes

* chore: update changeset

---------

Co-authored-by: Jakub Romańczyk <[email protected]>
Co-authored-by: Jakub Romańczyk <[email protected]>
  • Loading branch information
3 people authored Dec 18, 2023
1 parent cc997a2 commit e1476e6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
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

0 comments on commit e1476e6

Please sign in to comment.