Skip to content

Commit b365b67

Browse files
authored
fix: @react-native/* packages misalignment (#501)
* fix: @react-native/* packages misalignemnt * changeset * rename * add types
1 parent 91b7f4d commit b365b67

File tree

6 files changed

+149
-49
lines changed

6 files changed

+149
-49
lines changed

.changeset/free-coats-obey.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@rnef/plugin-metro': patch
3+
---
4+
5+
fix: @react-native/\* packages misalignemnt

packages/plugin-metro/package.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
},
2020
"dependencies": {
2121
"@react-native-community/cli-server-api": "^19.1.0",
22-
"@react-native/dev-middleware": "^0.80.1",
2322
"@rnef/tools": "^0.8.12",
2423
"metro": "^0.82.2",
2524
"metro-config": "^0.82.2",
@@ -28,12 +27,9 @@
2827
"tslib": "^2.3.0"
2928
},
3029
"devDependencies": {
31-
"@react-native/community-cli-plugin": "0.80.1",
30+
"@react-native/dev-middleware": "^0.80.1",
3231
"@rnef/config": "^0.8.12"
3332
},
34-
"peerDependencies": {
35-
"@react-native/community-cli-plugin": "*"
36-
},
3733
"publishConfig": {
3834
"access": "public"
3935
}

packages/plugin-metro/src/lib/bundle/command.ts

Lines changed: 102 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import fs from 'node:fs';
22
import path from 'node:path';
3-
import {
4-
bundleCommand,
5-
// @ts-expect-error missing typings - TODO drop dependency on community plugin
6-
} from '@react-native/community-cli-plugin';
73
import type { PluginApi } from '@rnef/config';
84
import {
95
colorLink,
@@ -14,6 +10,7 @@ import {
1410
runHermes,
1511
spinner,
1612
} from '@rnef/tools';
13+
import { getReactNativeCommunityCliPlugin } from '../getReactNativeDeps.js';
1714

1815
type BundleCommandArgs = {
1916
assetsDest?: string;
@@ -61,6 +58,9 @@ export function registerBundleCommand(api: PluginApi) {
6158
const bundleOutputDir = path.dirname(args.bundleOutput);
6259
fs.mkdirSync(bundleOutputDir, { recursive: true });
6360

61+
const { bundleCommand } =
62+
await getReactNativeCommunityCliPlugin(reactNativePath);
63+
6464
await bundleCommand.func(
6565
undefined,
6666
{ root, reactNativeVersion, reactNativePath, platforms },
@@ -85,7 +85,104 @@ export function registerBundleCommand(api: PluginApi) {
8585
outro('Success 🎉.');
8686
},
8787
options: [
88-
...bundleCommand.options,
88+
{
89+
name: '--entry-file <path>',
90+
description:
91+
'Path to the root JS file, either absolute or relative to JS root',
92+
},
93+
{
94+
name: '--platform <string>',
95+
description: 'Either "ios" or "android"',
96+
default: 'ios',
97+
},
98+
{
99+
name: '--transformer <string>',
100+
description: 'Specify a custom transformer to be used',
101+
},
102+
{
103+
name: '--dev [boolean]',
104+
description:
105+
'If false, warnings are disabled and the bundle is minified',
106+
parse: (val) => val !== 'false',
107+
default: true,
108+
},
109+
{
110+
name: '--minify [boolean]',
111+
description:
112+
'Allows overriding whether bundle is minified. This defaults to ' +
113+
'false if dev is true, and true if dev is false. Disabling minification ' +
114+
'can be useful for speeding up production builds for testing purposes.',
115+
parse: (val) => val !== 'false',
116+
},
117+
{
118+
name: '--bundle-output <string>',
119+
description:
120+
'File name where to store the resulting bundle, ex. /tmp/groups.bundle',
121+
},
122+
{
123+
name: '--bundle-encoding <string>',
124+
description:
125+
'Encoding the bundle should be written in (https://nodejs.org/api/buffer.html#buffer_buffer).',
126+
default: 'utf8',
127+
},
128+
{
129+
name: '--max-workers <number>',
130+
description:
131+
'Specifies the maximum number of workers the worker-pool ' +
132+
'will spawn for transforming files. This defaults to the number of the ' +
133+
'cores available on your machine.',
134+
},
135+
{
136+
name: '--sourcemap-output <string>',
137+
description:
138+
'File name where to store the sourcemap file for resulting bundle, ex. /tmp/groups.map',
139+
},
140+
{
141+
name: '--sourcemap-sources-root <string>',
142+
description:
143+
"Path to make sourcemap's sources entries relative to, ex. /root/dir",
144+
},
145+
{
146+
name: '--sourcemap-use-absolute-path',
147+
description: 'Report SourceMapURL using its full path',
148+
default: false,
149+
},
150+
{
151+
name: '--assets-dest <string>',
152+
description:
153+
'Directory name where to store assets referenced in the bundle',
154+
},
155+
{
156+
name: '--unstable-transform-profile <string>',
157+
description:
158+
'Experimental, transform JS for a specific JS engine. Currently supported: hermes, hermes-canary, default',
159+
default: 'default',
160+
},
161+
{
162+
name: '--asset-catalog-dest [string]',
163+
description: 'Path where to create an iOS Asset Catalog for images',
164+
},
165+
{
166+
name: '--reset-cache',
167+
description: 'Removes cached files',
168+
default: false,
169+
},
170+
{
171+
name: '--read-global-cache',
172+
description:
173+
'Try to fetch transformed JS code from the global cache, if configured.',
174+
default: false,
175+
},
176+
{
177+
name: '--config <string>',
178+
description: 'Path to the CLI configuration file',
179+
parse: (val) => path.resolve(val),
180+
},
181+
{
182+
name: '--resolver-option <string...>',
183+
description:
184+
'Custom resolver options of the form key=value. URL-encoded. May be specified multiple times.',
185+
},
89186
{
90187
name: '--config-cmd [string]',
91188
description:
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { createRequire } from 'node:module';
2+
import type devMiddleware from '@react-native/dev-middleware';
3+
4+
export async function getDevMiddleware(
5+
reactNativePath: string,
6+
): Promise<typeof devMiddleware> {
7+
const require = createRequire(import.meta.url);
8+
const reactNativeCommunityCliPluginPath = require.resolve(
9+
'@react-native/community-cli-plugin',
10+
{ paths: [reactNativePath] },
11+
);
12+
13+
const devMiddlewarePath = require.resolve('@react-native/dev-middleware', {
14+
paths: [reactNativeCommunityCliPluginPath],
15+
});
16+
17+
return import(devMiddlewarePath);
18+
}
19+
20+
export async function getReactNativeCommunityCliPlugin(
21+
reactNativePath: string,
22+
) {
23+
const require = createRequire(import.meta.url);
24+
const reactNativeCommunityCliPluginPath = require.resolve(
25+
'@react-native/community-cli-plugin',
26+
{ paths: [reactNativePath] },
27+
);
28+
29+
return import(reactNativeCommunityCliPluginPath);
30+
}

packages/plugin-metro/src/lib/start/runServer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
import { createRequire } from 'node:module';
99
import path from 'node:path';
1010
import url from 'node:url';
11-
import { createDevMiddleware } from '@react-native/dev-middleware';
1211
import { createDevServerMiddleware } from '@react-native-community/cli-server-api';
1312
import { color } from '@rnef/tools';
1413
import Metro from 'metro';
1514
import type { Reporter } from 'metro/src/lib/reporting';
1615
import type { TerminalReportableEvent } from 'metro/src/lib/TerminalReporter';
1716
import type { TerminalReporter } from 'metro/src/lib/TerminalReporter';
1817
import { Terminal } from 'metro-core';
18+
import { getDevMiddleware } from '../getReactNativeDeps.js';
1919
import attachKeyHandlers from './attachKeyHandlers.js';
2020
import createDevMiddlewareLogger from './createDevMiddlewareLogger.js';
2121
import loadMetroConfig from './loadMetroConfig.js';
@@ -108,6 +108,9 @@ async function runServer(
108108
port,
109109
watchFolders,
110110
});
111+
const { createDevMiddleware } = await getDevMiddleware(
112+
options.reactNativePath,
113+
);
111114
const { middleware, websocketEndpoints } = createDevMiddleware({
112115
projectRoot,
113116
serverBaseUrl: devServerUrl,

pnpm-lock.yaml

Lines changed: 7 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)