Skip to content

Commit 30fa495

Browse files
authored
feat: use RNC CLI explicitly when bundling the project (#869)
* fix: add --config-cmd to bundle options * feat: replace whole shellScript instead of modifying it * feat: remove modification of old Android configs for RN < 0.71 * feat: modify cliPath when modyfing android * feat: add autolinking conditionionaly, better messages * fix: properly escape shell script for iOS * fix: remove extra dquote from modifyAndroid cliFile * chore: add changeset * refactor: expand RNC CLI * fix: drop replacing bundleCommand on iOS * chore: drop modyfing Android altogether * chore: update changeset
1 parent 93f2c74 commit 30fa495

File tree

6 files changed

+45
-141
lines changed

6 files changed

+45
-141
lines changed

.changeset/curvy-cars-pretend.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@callstack/repack": patch
3+
---
4+
5+
Add `--config-cmd` to options for bundle command for compatibility with RN >= 0.76

.changeset/rare-planes-lie.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@callstack/repack": minor
3+
"@callstack/repack-init": minor
4+
---
5+
6+
Use `@react-native-community/cli` explictly iOS project settings (through `CLI_PATH`).
7+
8+
Drop (unofficial) support for modyfing Android config for RN versions < 0.71.

packages/init/src/index.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import checkReactNative from './tasks/checkReactNative.js';
44
import createBundlerConfig from './tasks/createBundlerConfig.js';
55
import ensureProjectExists from './tasks/ensureProjectExists.js';
66
import handleReactNativeConfig from './tasks/handleReactNativeConfig.js';
7-
import modifyAndroid from './tasks/modifyAndroid.js';
87
import modifyIOS from './tasks/modifyIOS.js';
98

109
import logger, { enableVerboseLogging } from './utils/logger.js';
@@ -31,16 +30,15 @@ export default async function run({
3130
try {
3231
const { cwd, rootDir } = await ensureProjectExists();
3332
const packageManager = await checkPackageManager(rootDir);
34-
const reactNativeVersion = checkReactNative(cwd);
33+
34+
checkReactNative(cwd);
3535

3636
await addDependencies(bundler, cwd, packageManager, repackVersion);
3737

3838
await createBundlerConfig(bundler, cwd, templateType, entry);
3939

4040
handleReactNativeConfig(bundler, cwd);
4141

42-
modifyAndroid(cwd, reactNativeVersion);
43-
4442
modifyIOS(cwd);
4543

4644
logger.done('Setup complete. Thanks for using Re.Pack!');

packages/init/src/tasks/modifyAndroid.ts

-121
This file was deleted.

packages/init/src/tasks/modifyIOS.ts

+24-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import fs from 'node:fs';
22
import path from 'node:path';
3+
import dedent from 'dedent';
34
import xcode from 'xcode';
45

56
import logger from '../utils/logger.js';
@@ -41,24 +42,29 @@ function getBundleReactNativePhase(
4142
return bundleReactNative;
4243
}
4344

44-
function modifyBundleReactNativeShellScript(
45+
function replaceBundleReactNativeShellScript(
4546
phase: ShellScriptBuildPhase
4647
): ShellScriptBuildPhase {
47-
const shellScriptContent = phase.shellScript;
48-
const shellScriptContentLines = shellScriptContent.split('\\n');
48+
const script = dedent`
49+
set -e
4950
50-
const bundleCommand = 'export BUNDLE_COMMAND=webpack-bundle';
51+
if [[ -f "$PODS_ROOT/../.xcode.env" ]]; then
52+
source "$PODS_ROOT/../.xcode.env"
53+
fi
54+
if [[ -f "$PODS_ROOT/../.xcode.env.local" ]]; then
55+
source "$PODS_ROOT/../.xcode.env.local"
56+
fi
5157
52-
if (shellScriptContentLines.includes(bundleCommand)) {
53-
logger.info(
54-
`${phase.name} phase in project.pbxproj already contains ${bundleCommand}`
55-
);
56-
return phase;
57-
}
58+
export CLI_PATH="$("$NODE_BINARY" --print "require('path').dirname(require.resolve('@react-native-community/cli/package.json')) + '/build/bin.js'")"
59+
60+
WITH_ENVIRONMENT="$REACT_NATIVE_PATH/scripts/xcode/with-environment.sh"
61+
REACT_NATIVE_XCODE="$REACT_NATIVE_PATH/scripts/react-native-xcode.sh"
5862
59-
shellScriptContentLines.splice(1, 0, '', bundleCommand);
63+
/bin/sh -c "$WITH_ENVIRONMENT $REACT_NATIVE_XCODE"
64+
`;
65+
66+
phase.shellScript = `"${script.replace(/"/g, '\\"').split('\n').join('\\n')}\\n"`;
6067

61-
phase.shellScript = shellScriptContentLines.join('\\n');
6268
return phase;
6369
}
6470

@@ -67,7 +73,7 @@ function modifyPbxprojConfig(pbxprojPath: string) {
6773
project.parseSync();
6874

6975
const bundleReactNativePhase = getBundleReactNativePhase(project);
70-
modifyBundleReactNativeShellScript(bundleReactNativePhase);
76+
replaceBundleReactNativeShellScript(bundleReactNativePhase);
7177

7278
return project.writeSync();
7379
}
@@ -93,7 +99,10 @@ export default function modifyIOS(cwd: string) {
9399
const updatedConfig = modifyPbxprojConfig(projectPbxProjPath);
94100

95101
fs.writeFileSync(projectPbxProjPath, updatedConfig);
96-
logger.success(
97-
`Added "webpack-bundle" as BUNDLE_COMMAND to build phase shellScript in ${relativeProjectPbxProjPath}`
102+
103+
logger.info(
104+
`Added "@react-native-community/cli" as CLI_PATH to build phase shellScript in ${relativeProjectPbxProjPath}`
98105
);
106+
107+
logger.success('Successfully modified iOS project files');
99108
}

packages/repack/src/commands/options.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,16 @@ export const bundleCommandOptions = [
113113
description:
114114
'Directory name where to store assets referenced in the bundle',
115115
},
116-
// noop, but kept for compatibility
116+
// noop, needed for compatibility
117117
{
118118
name: '--reset-cache',
119119
description: '(unsupported) Resets the transformation cache',
120120
},
121+
// noop, needed for compatibility
122+
{
123+
name: '--config-cmd',
124+
description: '(unsupported) Command to generate a JSON project config',
125+
},
121126
// options specific to Re.Pack
122127
{
123128
name: '--json <statsFile>',

0 commit comments

Comments
 (0)