Skip to content

Conversation

@thymikee
Copy link
Contributor

@thymikee thymikee commented Nov 22, 2024

Summary

Got Metro to work, so had to get base Re.Pack support 🚀.

On top I've added logic to merge package.json files (and adjusted other plugins to follow), repurposed rewritePackageJson to sortDevDepsInPackageJson and added a helper for making dev deps unique in dist package.json.

create-app output re.pack running
Screenshot 2024-11-21 at 21 10 32 Screenshot 2024-11-21 at 21 04 08

Test plan

Need to add some later

rnef.config.mjs:

import {pluginRepack} from '@callstack/rnef-plugin-repack';
export default {
  plugins: {
    repack: pluginRepack({
      root: __dirname,
      reactNativePath: join(__dirname, './node_modules/react-native'),
      platforms: {android: {}},
    }),
  }
};

@szymonrybczak
Copy link
Collaborator

managed to run it locally 🔥
CleanShot 2024-11-25 at 07 44 41@2x

} else {
fs.copyFileSync(srcFile, distFile);
// merge package.json files
if (nodePath.basename(srcFile) === 'package.json') {
Copy link
Collaborator

Choose a reason for hiding this comment

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

[nit]

  1. would be good to extract to separate function e.g. mergePackageJson.
  2. Should also check for duplicated dep names, if the version is the same, then ok, but in case of mismatch should warn (or try to resolve to common subset?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Check 83e22d3

@@ -0,0 +1,9 @@
{
"name": "rnef-plugin-platform-ios-template",
"scripts": {
Copy link
Collaborator

Choose a reason for hiding this comment

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

💜

@@ -0,0 +1,9 @@
{
"name": "rnef-plugin-platform-ios-template",
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can omit name as it's getting ignored anyway

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nx started to weirdly fail without the name, like it would consider this package.json as a project's one. After trying a few things and removing all the caches, I went with this solution.

}
const dist = JSON.parse(fs.readFileSync(to, 'utf-8'));
dist.scripts = { ...dist.scripts, ...src.scripts };
dist.devDependencies = removeDuplicateDependencies({
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can merge also regular deps & peer deps

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For now we're not doing this so I opted out. Happy to introduce this logic once necessary.

fs.copyFileSync(from, to);
}
const dist = JSON.parse(fs.readFileSync(to, 'utf-8'));
dist.scripts = { ...dist.scripts, ...src.scripts };
Copy link
Collaborator

Choose a reason for hiding this comment

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

[nit] we should check for script overwrite too

{ devDependencies: {} }
);

return {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Warn if there are duplicate deps entries with version mismatch?

(api: PluginApi): PluginOutput => {
api.registerCommand({
name: 'dev',
name: 'start',
Copy link
Collaborator

Choose a reason for hiding this comment

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

so we're back to React Native convention?

start → for starting development server?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't have strong opinions about it. We can change anytime

Copy link
Collaborator

Choose a reason for hiding this comment

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

i guess we wanted to have more web-like experience, but it might create some unpleasant change for rnc cli users, when we proceed it with new convention.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, on the other hand I thought we'd create our own dev server and hook metro/re.pack there and that's apparently not necessary at the moment. happy to revisit that

@thymikee thymikee mentioned this pull request Nov 28, 2024
This was referenced Nov 29, 2024
@thymikee thymikee merged commit 7679c8a into main Dec 2, 2024
1 check passed
@thymikee thymikee deleted the feat/plugin-repack branch December 2, 2024 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants