-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BREAKING] feat: override start & bundle commands (#537)
* feat: override metro commands by default * feat: update types for commands * test: add basic tests to TesterApp suite * chore: add changeset * chore: adjust changeset
- Loading branch information
Showing
5 changed files
with
191 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
"@callstack/repack": major | ||
--- | ||
|
||
BREAKING CHANGE: | ||
|
||
Re.Pack commands now override the default `start` and `bundle` CLI commands for enhanced functionality and compatibility with `react-native` versions >= 0.74. For earlier versions of `react-native` (< 0.74), the traditional commands `webpack-start` and `webpack-bundle` remain available and recommended. | ||
|
||
This change primarily impacts setups where both Metro and Re.Pack are used simultaneously. | ||
|
||
To maintain your current workflow without adopting these overrides, especially to avoid conflicts in projects using both Metro and Re.Pack, you can opt out by filtering out the new command names and reverting to the legacy `webpack` prefixed commands: | ||
|
||
```js | ||
// react-native.config.js | ||
const commands = require("@callstack/repack/commands"); | ||
|
||
module.exports = { | ||
commands: commands.filter((command) => command.name.startsWith("webpack")), | ||
}; | ||
``` | ||
|
||
Additionally, this update ensures that running `react-native run-ios` or `react-native run-android` will launch the Re.Pack dev server by default instead of the Metro dev server. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,75 +21,85 @@ const REACT_NATIVE_ANDROID_ASSET_PATH = RELATIVE_REACT_NATIVE_PATH.replaceAll( | |
'_' | ||
).replaceAll(/[-.@+]/g, ''); | ||
|
||
beforeAll(async () => { | ||
await fs.promises.rm(TMP_DIR, { | ||
recursive: true, | ||
force: true, | ||
describe('bundle command', () => { | ||
it("should be also available under 'webpack-bundle' alias", () => { | ||
const bundleCommand = commands.find((command) => command.name === 'bundle'); | ||
const webpackBundleCommand = commands.find( | ||
(command) => command.name === 'webpack-bundle' | ||
); | ||
|
||
expect(bundleCommand).toBeDefined(); | ||
expect(webpackBundleCommand).toBeDefined(); | ||
expect(bundleCommand!.func).toEqual(webpackBundleCommand!.func); | ||
}); | ||
}); | ||
|
||
describe.each([ | ||
{ | ||
platform: 'ios', | ||
assets: [ | ||
'index.bundle', | ||
'index.bundle.map', | ||
'miniapp.chunk.bundle', | ||
'miniapp.chunk.bundle.map', | ||
'remote.chunk.bundle', | ||
'remote.chunk.bundle.map', | ||
'src_asyncChunks_Async_local_tsx.chunk.bundle', | ||
'src_asyncChunks_Async_local_tsx.chunk.bundle.map', | ||
'react-native-bundle-output/main.jsbundle', | ||
'react-native-bundle-output/main.jsbundle.map', | ||
'react-native-bundle-output/src_asyncChunks_Async_local_tsx.chunk.bundle', | ||
'react-native-bundle-output/src_asyncChunks_Async_local_tsx.chunk.bundle.map', | ||
'assets/src/miniapp/callstack-dark.png', | ||
`assets/${RELATIVE_REACT_NATIVE_PATH}/Libraries/NewAppScreen/components/logo.png`, | ||
'assets/src/assetsTest/localAssets/webpack.png', | ||
'assets/src/assetsTest/localAssets/[email protected]', | ||
'assets/src/assetsTest/localAssets/[email protected]', | ||
'remote-assets/assets/src/assetsTest/remoteAssets/webpack.png', | ||
'remote-assets/assets/src/assetsTest/remoteAssets/[email protected]', | ||
'remote-assets/assets/src/assetsTest/remoteAssets/[email protected]', | ||
'react-native-bundle-output/assets/src/assetsTest/localAssets/webpack.png', | ||
'react-native-bundle-output/assets/src/assetsTest/localAssets/[email protected]', | ||
'react-native-bundle-output/assets/src/assetsTest/localAssets/[email protected]', | ||
`react-native-bundle-output/assets/${RELATIVE_REACT_NATIVE_PATH}/Libraries/NewAppScreen/components/logo.png`, | ||
], | ||
}, | ||
{ | ||
platform: 'android', | ||
assets: [ | ||
'index.bundle', | ||
'index.bundle.map', | ||
'miniapp.chunk.bundle', | ||
'miniapp.chunk.bundle.map', | ||
'remote.chunk.bundle', | ||
'remote.chunk.bundle.map', | ||
'src_asyncChunks_Async_local_tsx.chunk.bundle', | ||
'src_asyncChunks_Async_local_tsx.chunk.bundle.map', | ||
`drawable-mdpi/${REACT_NATIVE_ANDROID_ASSET_PATH}_libraries_newappscreen_components_logo.png`, | ||
'drawable-mdpi/src_assetstest_localassets_webpack.png', | ||
'drawable-xxhdpi/src_assetstest_localassets_webpack.png', | ||
'drawable-xhdpi/src_assetstest_localassets_webpack.png', | ||
'drawable-mdpi/src_miniapp_callstackdark.png', | ||
'react-native-bundle-output/index.android.bundle', | ||
'react-native-bundle-output/index.android.bundle.map', | ||
'react-native-bundle-output/src_asyncChunks_Async_local_tsx.chunk.bundle', | ||
'react-native-bundle-output/src_asyncChunks_Async_local_tsx.chunk.bundle.map', | ||
`react-native-bundle-output/drawable-mdpi/${REACT_NATIVE_ANDROID_ASSET_PATH}_libraries_newappscreen_components_logo.png`, | ||
'react-native-bundle-output/drawable-mdpi/src_assetstest_localassets_webpack.png', | ||
'react-native-bundle-output/drawable-xxhdpi/src_assetstest_localassets_webpack.png', | ||
'react-native-bundle-output/drawable-xhdpi/src_assetstest_localassets_webpack.png', | ||
'remote-assets/assets/src/assetsTest/remoteAssets/webpack.png', | ||
'remote-assets/assets/src/assetsTest/remoteAssets/[email protected]', | ||
'remote-assets/assets/src/assetsTest/remoteAssets/[email protected]', | ||
], | ||
}, | ||
])( | ||
'bundle command should successfully produce bundle assets', | ||
({ platform, assets }) => { | ||
describe.each([ | ||
{ | ||
platform: 'ios', | ||
assets: [ | ||
'index.bundle', | ||
'index.bundle.map', | ||
'miniapp.chunk.bundle', | ||
'miniapp.chunk.bundle.map', | ||
'remote.chunk.bundle', | ||
'remote.chunk.bundle.map', | ||
'src_asyncChunks_Async_local_tsx.chunk.bundle', | ||
'src_asyncChunks_Async_local_tsx.chunk.bundle.map', | ||
'react-native-bundle-output/main.jsbundle', | ||
'react-native-bundle-output/main.jsbundle.map', | ||
'react-native-bundle-output/src_asyncChunks_Async_local_tsx.chunk.bundle', | ||
'react-native-bundle-output/src_asyncChunks_Async_local_tsx.chunk.bundle.map', | ||
'assets/src/miniapp/callstack-dark.png', | ||
`assets/${RELATIVE_REACT_NATIVE_PATH}/Libraries/NewAppScreen/components/logo.png`, | ||
'assets/src/assetsTest/localAssets/webpack.png', | ||
'assets/src/assetsTest/localAssets/[email protected]', | ||
'assets/src/assetsTest/localAssets/[email protected]', | ||
'remote-assets/assets/src/assetsTest/remoteAssets/webpack.png', | ||
'remote-assets/assets/src/assetsTest/remoteAssets/[email protected]', | ||
'remote-assets/assets/src/assetsTest/remoteAssets/[email protected]', | ||
'react-native-bundle-output/assets/src/assetsTest/localAssets/webpack.png', | ||
'react-native-bundle-output/assets/src/assetsTest/localAssets/[email protected]', | ||
'react-native-bundle-output/assets/src/assetsTest/localAssets/[email protected]', | ||
`react-native-bundle-output/assets/${RELATIVE_REACT_NATIVE_PATH}/Libraries/NewAppScreen/components/logo.png`, | ||
], | ||
}, | ||
{ | ||
platform: 'android', | ||
assets: [ | ||
'index.bundle', | ||
'index.bundle.map', | ||
'miniapp.chunk.bundle', | ||
'miniapp.chunk.bundle.map', | ||
'remote.chunk.bundle', | ||
'remote.chunk.bundle.map', | ||
'src_asyncChunks_Async_local_tsx.chunk.bundle', | ||
'src_asyncChunks_Async_local_tsx.chunk.bundle.map', | ||
`drawable-mdpi/${REACT_NATIVE_ANDROID_ASSET_PATH}_libraries_newappscreen_components_logo.png`, | ||
'drawable-mdpi/src_assetstest_localassets_webpack.png', | ||
'drawable-xxhdpi/src_assetstest_localassets_webpack.png', | ||
'drawable-xhdpi/src_assetstest_localassets_webpack.png', | ||
'drawable-mdpi/src_miniapp_callstackdark.png', | ||
'react-native-bundle-output/index.android.bundle', | ||
'react-native-bundle-output/index.android.bundle.map', | ||
'react-native-bundle-output/src_asyncChunks_Async_local_tsx.chunk.bundle', | ||
'react-native-bundle-output/src_asyncChunks_Async_local_tsx.chunk.bundle.map', | ||
`react-native-bundle-output/drawable-mdpi/${REACT_NATIVE_ANDROID_ASSET_PATH}_libraries_newappscreen_components_logo.png`, | ||
'react-native-bundle-output/drawable-mdpi/src_assetstest_localassets_webpack.png', | ||
'react-native-bundle-output/drawable-xxhdpi/src_assetstest_localassets_webpack.png', | ||
'react-native-bundle-output/drawable-xhdpi/src_assetstest_localassets_webpack.png', | ||
'remote-assets/assets/src/assetsTest/remoteAssets/webpack.png', | ||
'remote-assets/assets/src/assetsTest/remoteAssets/[email protected]', | ||
'remote-assets/assets/src/assetsTest/remoteAssets/[email protected]', | ||
], | ||
}, | ||
])('should successfully produce bundle assets', ({ platform, assets }) => { | ||
beforeAll(async () => { | ||
await fs.promises.rm(TMP_DIR, { | ||
recursive: true, | ||
force: true, | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
delete process.env.TEST_WEBPACK_OUTPUT_PATH; | ||
}); | ||
|
@@ -122,5 +132,5 @@ describe.each([ | |
}, | ||
60 * 1000 | ||
); | ||
} | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters