@rock-js/plugin-metro 0.8.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +2 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/lib/bundle/__tests__/filterPlatformAssetScales-test.d.ts +8 -0
- package/dist/src/lib/bundle/__tests__/filterPlatformAssetScales-test.js +29 -0
- package/dist/src/lib/bundle/__tests__/filterPlatformAssetScales-test.js.map +1 -0
- package/dist/src/lib/bundle/assetCatalogIOS.d.ts +21 -0
- package/dist/src/lib/bundle/assetCatalogIOS.js +54 -0
- package/dist/src/lib/bundle/assetCatalogIOS.js.map +1 -0
- package/dist/src/lib/bundle/assetPathUtils.d.ts +28 -0
- package/dist/src/lib/bundle/assetPathUtils.js +72 -0
- package/dist/src/lib/bundle/assetPathUtils.js.map +1 -0
- package/dist/src/lib/bundle/buildBundle.d.ts +57 -0
- package/dist/src/lib/bundle/buildBundle.js +99 -0
- package/dist/src/lib/bundle/buildBundle.js.map +1 -0
- package/dist/src/lib/bundle/command.d.ts +2 -0
- package/dist/src/lib/bundle/command.d.ts.map +1 -0
- package/dist/src/lib/bundle/command.js +135 -0
- package/dist/src/lib/bundle/command.js.map +1 -0
- package/dist/src/lib/bundle/createKeepFileAsync.d.ts +10 -0
- package/dist/src/lib/bundle/createKeepFileAsync.js +28 -0
- package/dist/src/lib/bundle/createKeepFileAsync.js.map +1 -0
- package/dist/src/lib/bundle/filterPlatformAssetScales.d.ts +9 -0
- package/dist/src/lib/bundle/filterPlatformAssetScales.js +36 -0
- package/dist/src/lib/bundle/filterPlatformAssetScales.js.map +1 -0
- package/dist/src/lib/bundle/getAssetDestPathAndroid.d.ts +10 -0
- package/dist/src/lib/bundle/getAssetDestPathAndroid.js +16 -0
- package/dist/src/lib/bundle/getAssetDestPathAndroid.js.map +1 -0
- package/dist/src/lib/bundle/getAssetDestPathIOS.d.ts +10 -0
- package/dist/src/lib/bundle/getAssetDestPathIOS.js +19 -0
- package/dist/src/lib/bundle/getAssetDestPathIOS.js.map +1 -0
- package/dist/src/lib/bundle/index.d.ts +11 -0
- package/dist/src/lib/bundle/index.js +106 -0
- package/dist/src/lib/bundle/index.js.map +1 -0
- package/dist/src/lib/bundle/saveAssets.d.ts +10 -0
- package/dist/src/lib/bundle/saveAssets.js +112 -0
- package/dist/src/lib/bundle/saveAssets.js.map +1 -0
- package/dist/src/lib/getDevMiddleware.d.ts +2 -0
- package/dist/src/lib/getDevMiddleware.js +15 -0
- package/dist/src/lib/getDevMiddleware.js.map +1 -0
- package/dist/src/lib/getReactNativeDeps.d.ts +3 -0
- package/dist/src/lib/getReactNativeDeps.js +15 -0
- package/dist/src/lib/getReactNativeDeps.js.map +1 -0
- package/dist/src/lib/loadMetroConfig.d.ts +24 -0
- package/dist/src/lib/loadMetroConfig.js +76 -0
- package/dist/src/lib/loadMetroConfig.js.map +1 -0
- package/dist/src/lib/pluginMetro.d.ts +3 -0
- package/dist/src/lib/pluginMetro.d.ts.map +1 -0
- package/dist/src/lib/pluginMetro.js +12 -0
- package/dist/src/lib/pluginMetro.js.map +1 -0
- package/dist/src/lib/start/OpenDebuggerKeyboardHandler.d.ts +35 -0
- package/dist/src/lib/start/OpenDebuggerKeyboardHandler.d.ts.map +1 -0
- package/dist/src/lib/start/OpenDebuggerKeyboardHandler.js +128 -0
- package/dist/src/lib/start/OpenDebuggerKeyboardHandler.js.map +1 -0
- package/dist/src/lib/start/attachKeyHandlers.d.ts +14 -0
- package/dist/src/lib/start/attachKeyHandlers.d.ts.map +1 -0
- package/dist/src/lib/start/attachKeyHandlers.js +107 -0
- package/dist/src/lib/start/attachKeyHandlers.js.map +1 -0
- package/dist/src/lib/start/command.d.ts +8 -0
- package/dist/src/lib/start/command.d.ts.map +1 -0
- package/dist/src/lib/start/command.js +110 -0
- package/dist/src/lib/start/command.js.map +1 -0
- package/dist/src/lib/start/createDevMiddlewareLogger.d.ts +18 -0
- package/dist/src/lib/start/createDevMiddlewareLogger.d.ts.map +1 -0
- package/dist/src/lib/start/createDevMiddlewareLogger.js +27 -0
- package/dist/src/lib/start/createDevMiddlewareLogger.js.map +1 -0
- package/dist/src/lib/start/loadMetroConfig.d.ts +24 -0
- package/dist/src/lib/start/loadMetroConfig.d.ts.map +1 -0
- package/dist/src/lib/start/loadMetroConfig.js +76 -0
- package/dist/src/lib/start/loadMetroConfig.js.map +1 -0
- package/dist/src/lib/start/metroPlatformResolver.d.ts +24 -0
- package/dist/src/lib/start/metroPlatformResolver.d.ts.map +1 -0
- package/dist/src/lib/start/metroPlatformResolver.js +38 -0
- package/dist/src/lib/start/metroPlatformResolver.js.map +1 -0
- package/dist/src/lib/start/runServer.d.ts +32 -0
- package/dist/src/lib/start/runServer.d.ts.map +1 -0
- package/dist/src/lib/start/runServer.js +133 -0
- package/dist/src/lib/start/runServer.js.map +1 -0
- package/dist/src/utils/loadMetroConfig.d.ts +24 -0
- package/dist/src/utils/loadMetroConfig.js +76 -0
- package/dist/src/utils/loadMetroConfig.js.map +1 -0
- package/dist/src/utils/metroPlatformResolver.d.ts +24 -0
- package/dist/src/utils/metroPlatformResolver.js +38 -0
- package/dist/src/utils/metroPlatformResolver.js.map +1 -0
- package/dist/src/utils/parseKeyValueParamArray.d.ts +8 -0
- package/dist/src/utils/parseKeyValueParamArray.js +21 -0
- package/dist/src/utils/parseKeyValueParamArray.js.map +1 -0
- package/package.json +41 -0
- package/template/metro.config.js +11 -0
- package/template/package.json +7 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import { color } from '@rock-js/tools';
|
|
8
|
+
export default class OpenDebuggerKeyboardHandler {
|
|
9
|
+
#devServerUrl;
|
|
10
|
+
#reporter;
|
|
11
|
+
#targetsShownForSelection = null;
|
|
12
|
+
constructor({ devServerUrl, reporter, }) {
|
|
13
|
+
this.#devServerUrl = devServerUrl;
|
|
14
|
+
this.#reporter = reporter;
|
|
15
|
+
}
|
|
16
|
+
async #tryOpenDebuggerForTarget(target) {
|
|
17
|
+
this.#targetsShownForSelection = null;
|
|
18
|
+
this.#clearTerminalMenu();
|
|
19
|
+
try {
|
|
20
|
+
await fetch(new URL('/open-debugger?target=' + encodeURIComponent(target.id), this.#devServerUrl).href, { method: 'POST' });
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
this.#log('error', 'Failed to open debugger for %s (%s): %s', target.title, target.description, 'Network error');
|
|
24
|
+
// @ts-expect-error - TBD
|
|
25
|
+
if (e.cause != null) {
|
|
26
|
+
// @ts-expect-error - it's not null
|
|
27
|
+
this.#log('error', 'Cause: %s', e.cause);
|
|
28
|
+
}
|
|
29
|
+
this.#clearTerminalMenu();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Used in response to 'j' to debug - fetch the available debug targets and:
|
|
34
|
+
* - If no targets, warn
|
|
35
|
+
* - If one target, open it
|
|
36
|
+
* - If more, show a list. The keyboard listener should run subsequent key
|
|
37
|
+
* presses through maybeHandleTargetSelection, which will launch the
|
|
38
|
+
* debugger if a match is made.
|
|
39
|
+
*/
|
|
40
|
+
async handleOpenDebugger() {
|
|
41
|
+
this.#setTerminalMenu('Fetching available debugging targets...');
|
|
42
|
+
this.#targetsShownForSelection = null;
|
|
43
|
+
try {
|
|
44
|
+
const res = await fetch(this.#devServerUrl + '/json/list', {
|
|
45
|
+
method: 'POST',
|
|
46
|
+
});
|
|
47
|
+
if (res.status !== 200) {
|
|
48
|
+
throw new Error(`Unexpected status code: ${res.status}`);
|
|
49
|
+
}
|
|
50
|
+
const targets = (await res.json());
|
|
51
|
+
if (!Array.isArray(targets)) {
|
|
52
|
+
throw new Error('Expected array.');
|
|
53
|
+
}
|
|
54
|
+
if (targets.length === 0) {
|
|
55
|
+
this.#log('warn', 'No connected targets');
|
|
56
|
+
this.#clearTerminalMenu();
|
|
57
|
+
}
|
|
58
|
+
else if (targets.length === 1) {
|
|
59
|
+
const target = targets[0];
|
|
60
|
+
void this.#tryOpenDebuggerForTarget(target);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
this.#targetsShownForSelection = targets;
|
|
64
|
+
if (targets.length > 9) {
|
|
65
|
+
this.#log('warn', '10 or more debug targets available, showing the first 9.');
|
|
66
|
+
}
|
|
67
|
+
this.#setTerminalMenu(`Multiple debug targets available, please select:\n ${targets
|
|
68
|
+
.slice(0, 9)
|
|
69
|
+
.map(({ title }, i) => `${color.inverse(` ${i + 1} `)} - "${title}"`)
|
|
70
|
+
.join('\n ')}`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
// @ts-expect-error - error is not typed
|
|
75
|
+
this.#log('error', `Failed to fetch debug targets: ${e.message}`);
|
|
76
|
+
this.#clearTerminalMenu();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Handle key presses that correspond to a valid selection from a visible
|
|
81
|
+
* selection list.
|
|
82
|
+
*
|
|
83
|
+
* @return true if we've handled the key as a target selection, false if the
|
|
84
|
+
* caller should handle the key.
|
|
85
|
+
*/
|
|
86
|
+
maybeHandleTargetSelection(keyName) {
|
|
87
|
+
if (keyName >= '1' && keyName <= '9') {
|
|
88
|
+
const targetIndex = Number(keyName) - 1;
|
|
89
|
+
if (this.#targetsShownForSelection != null &&
|
|
90
|
+
targetIndex < this.#targetsShownForSelection.length) {
|
|
91
|
+
const target = this.#targetsShownForSelection[targetIndex];
|
|
92
|
+
void this.#tryOpenDebuggerForTarget(target);
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Dismiss any target selection UI, if shown.
|
|
100
|
+
*/
|
|
101
|
+
dismiss() {
|
|
102
|
+
this.#clearTerminalMenu();
|
|
103
|
+
this.#targetsShownForSelection = null;
|
|
104
|
+
}
|
|
105
|
+
#log(level, ...data) {
|
|
106
|
+
this.#reporter.update({
|
|
107
|
+
// @ts-expect-error - metro types are not updated
|
|
108
|
+
type: 'unstable_server_log',
|
|
109
|
+
// @ts-expect-error - metro types are not updated
|
|
110
|
+
level,
|
|
111
|
+
data,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
#setTerminalMenu(message) {
|
|
115
|
+
this.#reporter.update({
|
|
116
|
+
// @ts-expect-error - metro types are not updated
|
|
117
|
+
type: 'unstable_server_menu_updated',
|
|
118
|
+
message,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
#clearTerminalMenu() {
|
|
122
|
+
this.#reporter.update({
|
|
123
|
+
// @ts-expect-error - metro types are not updated
|
|
124
|
+
type: 'unstable_server_menu_cleared',
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=OpenDebuggerKeyboardHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OpenDebuggerKeyboardHandler.js","sourceRoot":"","sources":["../../../../src/lib/start/OpenDebuggerKeyboardHandler.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AASvC,MAAM,CAAC,OAAO,OAAO,2BAA2B;IAC9C,aAAa,CAAS;IACtB,SAAS,CAAmB;IAC5B,yBAAyB,GAA0C,IAAI,CAAC;IAExE,YAAY,EACV,YAAY,EACZ,QAAQ,GAIT;QACC,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;QAClC,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,yBAAyB,CAAC,MAAuB;QACr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,EAAE,CAAC;YACrC,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YACxC,IACE,IAAI,CAAC,yBAAyB,IAAI,IAAI;gBACtC,WAAW,GAAG,IAAI,CAAC,yBAAyB,CAAC,MAAM,EACnD,CAAC;gBACD,MAAM,MAAM,GAAG,IAAI,CAAC,yBAAyB,CAAC,WAAW,CAAC,CAAC;gBAE3D,KAAK,IAAI,CAAC,yBAAyB,CAAC,MAAM,CAAC,CAAC;gBAC5C,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;OAEG;IACH,OAAO;QACL,IAAI,CAAC,kBAAkB,EAAE,CAAC;QAC1B,IAAI,CAAC,yBAAyB,GAAG,IAAI,CAAC;IACxC,CAAC;IAED,IAAI,CAAC,KAAgC,EAAE,GAAG,IAAoB;QAC5D,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;YACpB,iDAAiD;YACjD,IAAI,EAAE,qBAAqB;YAC3B,iDAAiD;YACjD,KAAK;YACL,IAAI;SACL,CAAC,CAAC;IACL,CAAC;IAED,gBAAgB,CAAC,OAAe;QAC9B,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;YACpB,iDAAiD;YACjD,IAAI,EAAE,8BAA8B;YACpC,OAAO;SACR,CAAC,CAAC;IACL,CAAC;IAED,kBAAkB;QAChB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;YACpB,iDAAiD;YACjD,IAAI,EAAE,8BAA8B;SACrC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { TerminalReporter } from 'metro/src/lib/TerminalReporter';
|
|
8
|
+
export default function attachKeyHandlers({ devServerUrl, messageSocket, reporter, }: {
|
|
9
|
+
devServerUrl: string;
|
|
10
|
+
messageSocket: {
|
|
11
|
+
broadcast: (type: string, params?: Record<string, unknown> | null) => void;
|
|
12
|
+
};
|
|
13
|
+
reporter: TerminalReporter;
|
|
14
|
+
}): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attachKeyHandlers.d.ts","sourceRoot":"","sources":["../../../../src/lib/start/attachKeyHandlers.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AA0BvE,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,EACxC,YAAY,EACZ,aAAa,EACb,QAAQ,GACT,EAAE;IACD,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE;QACb,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,KAAK,IAAI,CAAC;KAC5E,CAAC;IACF,QAAQ,EAAE,gBAAgB,CAAC;CAC5B,QAmFA"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import readline from 'node:readline';
|
|
8
|
+
import { ReadStream } from 'node:tty';
|
|
9
|
+
import { color, RockError } from '@rock-js/tools';
|
|
10
|
+
import OpenDebuggerKeyboardHandler from './OpenDebuggerKeyboardHandler.js';
|
|
11
|
+
const CTRL_C = '\u0003';
|
|
12
|
+
const CTRL_D = '\u0004';
|
|
13
|
+
const RELOAD_TIMEOUT = 500;
|
|
14
|
+
const throttle = (callback, timeout) => {
|
|
15
|
+
let previousCallTimestamp = 0;
|
|
16
|
+
return () => {
|
|
17
|
+
const currentCallTimestamp = new Date().getTime();
|
|
18
|
+
if (currentCallTimestamp - previousCallTimestamp > timeout) {
|
|
19
|
+
previousCallTimestamp = currentCallTimestamp;
|
|
20
|
+
callback();
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
export default function attachKeyHandlers({ devServerUrl, messageSocket, reporter, }) {
|
|
25
|
+
if (process.stdin.isTTY !== true) {
|
|
26
|
+
reporter.update({
|
|
27
|
+
// @ts-expect-error - metro types are not updated
|
|
28
|
+
type: 'unstable_server_log',
|
|
29
|
+
level: 'info',
|
|
30
|
+
// @ts-expect-error - metro types are not updated
|
|
31
|
+
data: 'Interactive mode is not supported in this environment',
|
|
32
|
+
});
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
readline.emitKeypressEvents(process.stdin);
|
|
36
|
+
setRawMode(true);
|
|
37
|
+
const reload = throttle(() => {
|
|
38
|
+
reporter.update({
|
|
39
|
+
// @ts-expect-error - metro types are not updated
|
|
40
|
+
type: 'unstable_server_log',
|
|
41
|
+
level: 'info',
|
|
42
|
+
// @ts-expect-error - metro types are not updated
|
|
43
|
+
data: 'Reloading connected app(s)...',
|
|
44
|
+
});
|
|
45
|
+
messageSocket.broadcast('reload', null);
|
|
46
|
+
}, RELOAD_TIMEOUT);
|
|
47
|
+
const openDebuggerKeyboardHandler = new OpenDebuggerKeyboardHandler({
|
|
48
|
+
reporter,
|
|
49
|
+
devServerUrl,
|
|
50
|
+
});
|
|
51
|
+
process.stdin.on('keypress', (str, key) => {
|
|
52
|
+
if (openDebuggerKeyboardHandler.maybeHandleTargetSelection(key.name)) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
switch (key.sequence) {
|
|
56
|
+
case 'r':
|
|
57
|
+
reload();
|
|
58
|
+
break;
|
|
59
|
+
case 'd':
|
|
60
|
+
reporter.update({
|
|
61
|
+
// @ts-expect-error - metro types are not updated
|
|
62
|
+
type: 'unstable_server_log',
|
|
63
|
+
level: 'info',
|
|
64
|
+
// @ts-expect-error - metro types are not updated
|
|
65
|
+
data: 'Opening Dev Menu...',
|
|
66
|
+
});
|
|
67
|
+
messageSocket.broadcast('devMenu', null);
|
|
68
|
+
break;
|
|
69
|
+
case 'j':
|
|
70
|
+
void openDebuggerKeyboardHandler.handleOpenDebugger();
|
|
71
|
+
break;
|
|
72
|
+
case CTRL_C:
|
|
73
|
+
case CTRL_D:
|
|
74
|
+
openDebuggerKeyboardHandler.dismiss();
|
|
75
|
+
reporter.update({
|
|
76
|
+
// @ts-expect-error - metro types are not updated
|
|
77
|
+
type: 'unstable_server_log',
|
|
78
|
+
level: 'info',
|
|
79
|
+
// @ts-expect-error - metro types are not updated
|
|
80
|
+
data: 'Stopping server',
|
|
81
|
+
});
|
|
82
|
+
setRawMode(false);
|
|
83
|
+
process.stdin.pause();
|
|
84
|
+
process.emit('SIGINT');
|
|
85
|
+
process.exit();
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
reporter.update({
|
|
89
|
+
// @ts-expect-error - metro types are not updated
|
|
90
|
+
type: 'unstable_server_log',
|
|
91
|
+
level: 'info',
|
|
92
|
+
// @ts-expect-error - metro types are not updated
|
|
93
|
+
data: `Key commands available:
|
|
94
|
+
|
|
95
|
+
${color.bold(color.inverse(' r '))} - reload app(s)
|
|
96
|
+
${color.bold(color.inverse(' d '))} - open Dev Menu
|
|
97
|
+
${color.bold(color.inverse(' j '))} - open DevTools
|
|
98
|
+
`,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
function setRawMode(enable) {
|
|
102
|
+
if (!(process.stdin instanceof ReadStream)) {
|
|
103
|
+
throw new RockError('process.stdin must be a readable stream to modify raw mode');
|
|
104
|
+
}
|
|
105
|
+
process.stdin.setRawMode(enable);
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=attachKeyHandlers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attachKeyHand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AClB,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;gBACtB,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBACvB,OAAO,CAAC,IAAI,EAAE,CAAC;QACnB,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,MAAM,CAAC;QACd,iDAAiD;QACjD,IAAI,EAAE,qBAAqB;QAC3B,KAAK,EAAE,MAAM;QACb,iDAAiD;QACjD,IAAI,EAAE;;IAEN,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAChC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAChC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;CACnC;KACE,CAAC,CAAC;AACL,CAAC;AAED,SAAS,UAAU,CAAC,MAAe;IACjC,IAAI,CAAC,CAAC,OAAO,CAAC,KAAK,YAAY,UAAU,CAAC,EAAE,CAAC;QAC3C,MAAM,IAAI,SAAS,CACjB,4DAA4D,CAC7D,CAAC;IACJ,CAAC;IACD,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { PluginApi } from '@rock-js/config';
|
|
8
|
+
export declare const registerStartCommand: (api: PluginApi) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../../../src/lib/start/command.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAK9C,eAAO,MAAM,oBAAoB,QAAS,SAAS,SAkHlD,CAAC"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import { findDevServerPort, intro } from '@rock-js/tools';
|
|
9
|
+
import runServer from './runServer.js';
|
|
10
|
+
export const registerStartCommand = (api) => {
|
|
11
|
+
api.registerCommand({
|
|
12
|
+
name: 'start',
|
|
13
|
+
action: async (args) => {
|
|
14
|
+
intro('Starting Metro dev server');
|
|
15
|
+
const root = api.getProjectRoot();
|
|
16
|
+
const { port, startDevServer } = await findDevServerPort(args.port ? Number(args.port) : 8081, root);
|
|
17
|
+
if (!startDevServer) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const reactNativeVersion = api.getReactNativeVersion();
|
|
21
|
+
const reactNativePath = api.getReactNativePath();
|
|
22
|
+
const platforms = api.getPlatforms();
|
|
23
|
+
return runServer({
|
|
24
|
+
root,
|
|
25
|
+
reactNativeVersion,
|
|
26
|
+
reactNativePath,
|
|
27
|
+
platforms,
|
|
28
|
+
}, { ...args, port });
|
|
29
|
+
},
|
|
30
|
+
description: 'Start the Metro development server.',
|
|
31
|
+
options: [
|
|
32
|
+
{
|
|
33
|
+
name: '--port <number>',
|
|
34
|
+
description: 'Port to run the server on',
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: '--host <string>',
|
|
38
|
+
description: 'Host to run the server on',
|
|
39
|
+
default: '',
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: '--project-root, --projectRoot <path>',
|
|
43
|
+
description: 'Path to a custom project root',
|
|
44
|
+
parse: (val) => path.resolve(val),
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: '--watch-folders, --watchFolders <list>',
|
|
48
|
+
description: 'Specify any additional folders to be added to the watch list',
|
|
49
|
+
parse: (val) => val.split(',').map((folder) => path.resolve(folder)),
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
name: '--asset-plugins, --assetPlugins <list>',
|
|
53
|
+
description: 'Specify any additional asset plugins to be used by the packager by full filepath',
|
|
54
|
+
parse: (val) => val.split(','),
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: '--source-exts, --sourceExts <list>',
|
|
58
|
+
description: 'Specify any additional source extensions to be used by the packager',
|
|
59
|
+
parse: (val) => val.split(','),
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
name: '--max-workers <number>',
|
|
63
|
+
description: 'Specifies the maximum number of workers the worker-pool ' +
|
|
64
|
+
'will spawn for transforming files. This defaults to the number of the ' +
|
|
65
|
+
'cores available on your machine.',
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
name: '--transformer <string>',
|
|
69
|
+
description: 'Specify a custom transformer to be used',
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
name: '--reset-cache, --resetCache',
|
|
73
|
+
description: 'Removes cached files',
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
name: '--custom-log-reporter-path, --customLogReporterPath <string>',
|
|
77
|
+
description: 'Path to a JavaScript file that exports a log reporter as a replacement for TerminalReporter',
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
name: '--https',
|
|
81
|
+
description: 'Enables https connections to the server',
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
name: '--key <path>',
|
|
85
|
+
description: 'Path to custom SSL key',
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
name: '--cert <path>',
|
|
89
|
+
description: 'Path to custom SSL cert',
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
name: '--config <string>',
|
|
93
|
+
description: 'Path to the CLI configuration file',
|
|
94
|
+
parse: (val) => path.resolve(val),
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: '--no-interactive',
|
|
98
|
+
description: 'Disables interactive mode',
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
name: '--client-logs',
|
|
102
|
+
description: '[Deprecated] Enable plain text JavaScript log streaming for all ' +
|
|
103
|
+
'connected apps. This feature is deprecated and will be removed in ' +
|
|
104
|
+
'future.',
|
|
105
|
+
default: false,
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
//# sourceMappingURL=command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.js","sourceRoot":"","sources":["../../../../src/lib/start/command.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,iBAAiB,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAE1D,OAAO,SAAS,MAAM,gBAAgB,CAAC;AAEvC,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,GAAc,EAAE,EAAE;IACrD,GAAG,CAAC,eAAe,CAAC;QAClB,IAAI,EAAE,OAAO;QACb,MAAM,EAAE,KAAK,EAAE,IAAsB,EAAE,EAAE;YACvC,KAAK,CAAC,2BAA2B,CAAC,CAAC;YACnC,MAAM,IAAI,GAAG,GAAG,CAAC,cAAc,EAAE,CAAC;YAClC,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,GAAG,MAAM,iBAAiB,CACtD,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,EACpC,IAAI,CACL,CAAC;YAEF,IAAI,CAAC,cAAc,EAAE,CAAC;gBACpB,OAAO;YACT,CAAC;YAED,MAAM,kBAAkB,GAAG,GAAG,CAAC,qBAAqB,EAAE,CAAC;YACvD,MAAM,eAAe,GAAG,GAAG,CAAC,kBAAkB,EAAE,CAAC;YACjD,MAAM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AE,yCAAyC;aACvD;YACD;gBACE,IAAI,EAAE,6BAA6B;gBACnC,WAAW,EAAE,sBAAsB;aACpC;YACD;gBACE,IAAI,EAAE,8DAA8D;gBACpE,WAAW,EACT,6FAA6F;aAChG;YACD;gBACE,IAAI,EAAE,SAAS;gBACf,WAAW,EAAE,yCAAyC;aACvD;YACD;gBACE,IAAI,EAAE,cAAc;gBACpB,WAAW,EAAE,wBAAwB;aACtC;YACD;gBACE,IAAI,EAAE,eAAe;gBACrB,WAAW,EAAE,yBAAyB;aACvC;YACD;gBACE,IAAI,EAAE,mBAAmB;gBACzB,WAAW,EAAE,oCAAoC;gBACjD,KAAK,EAAE,CAAC,GAAW,EAAU,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC;aAClD;YACD;gBACE,IAAI,EAAE,kBAAkB;gBACxB,WAAW,EAAE,2BAA2B;aACzC;YACD;gBACE,IAAI,EAAE,eAAe;gBACrB,WAAW,EACT,kEAAkE;oBAClE,oEAAoE;oBACpE,SAAS;gBACX,OAAO,EAAE,KAAK;aACf;SACF;KACF,CAAC,CAAC;AACL,CAAC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { TerminalReporter } from 'metro/src/lib/TerminalReporter';
|
|
8
|
+
type LoggerFn = (...message: ReadonlyArray<string>) => void;
|
|
9
|
+
/**
|
|
10
|
+
* Create a dev-middleware logger object that will emit logs via Metro's
|
|
11
|
+
* terminal reporter.
|
|
12
|
+
*/
|
|
13
|
+
export default function createDevMiddlewareLogger(reporter: TerminalReporter): Readonly<{
|
|
14
|
+
info: LoggerFn;
|
|
15
|
+
error: LoggerFn;
|
|
16
|
+
warn: LoggerFn;
|
|
17
|
+
}>;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createDevMiddlewareLogger.d.ts","sourceRoot":"","sources":["../../../../src/lib/start/createDevMiddlewareLogger.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAEvE,KAAK,QAAQ,GAAG,CAAC,GAAG,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC;AAE5D;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,yBAAyB,CAC/C,QAAQ,EAAE,gBAAgB,GACzB,QAAQ,CAAC;IACV,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,QAAQ,CAAC;IAChB,IAAI,EAAE,QAAQ,CAAC;CAChB,CAAC,CAMD"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Create a dev-middleware logger object that will emit logs via Metro's
|
|
9
|
+
* terminal reporter.
|
|
10
|
+
*/
|
|
11
|
+
export default function createDevMiddlewareLogger(reporter) {
|
|
12
|
+
return {
|
|
13
|
+
info: makeLogger(reporter, 'info'),
|
|
14
|
+
warn: makeLogger(reporter, 'warn'),
|
|
15
|
+
error: makeLogger(reporter, 'error'),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function makeLogger(reporter, level) {
|
|
19
|
+
return (...data) => reporter.update({
|
|
20
|
+
// @ts-expect-error - metro types are not updated
|
|
21
|
+
type: 'unstable_server_log',
|
|
22
|
+
// @ts-expect-error - metro types are not updated
|
|
23
|
+
level,
|
|
24
|
+
data,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=createDevMiddlewareLogger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createDevMiddlewareLogger.js","sourceRoot":"","sources":["../../../../src/lib/start/createDevMiddlewareLogger.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,yBAAyB,CAC/C,QAA0B;IAM1B,OAAO;QACL,IAAI,EAAE,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC;QAClC,IAAI,EAAE,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC;QAClC,KAAK,EAAE,UAAU,CAAC,QAAQ,EAAE,OAAO,CAAC;KACrC,CAAC;AACJ,CAAC;AAED,SAAS,UAAU,CACjB,QAA0B,EAC1B,KAAgC;IAEhC,OAAO,CAAC,GAAG,IAAoB,EAAE,EAAE,CACjC,QAAQ,CAAC,MAAM,CAAC;QACd,iDAAiD;QACjD,IAAI,EAAE,qBAAqB;QAC3B,iDAAiD;QACjD,KAAK;QACL,IAAI;KACL,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { ConfigT, YargArguments } from 'metro-config';
|
|
8
|
+
export type ConfigLoadingContext = Readonly<{
|
|
9
|
+
root: string;
|
|
10
|
+
reactNativePath: string;
|
|
11
|
+
platforms: Record<string, object>;
|
|
12
|
+
}>;
|
|
13
|
+
/**
|
|
14
|
+
* Load Metro config.
|
|
15
|
+
*
|
|
16
|
+
* Allows the CLI to override select values in `metro.config.js` based on
|
|
17
|
+
* dynamic user options in `ctx`.
|
|
18
|
+
*/
|
|
19
|
+
export default function loadMetroConfig(ctx: {
|
|
20
|
+
platforms: Record<string, object>;
|
|
21
|
+
reactNativeVersion: string;
|
|
22
|
+
reactNativePath: string;
|
|
23
|
+
root: string;
|
|
24
|
+
}, options?: YargArguments): Promise<ConfigT>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loadMetroConfig.d.ts","sourceRoot":"","sources":["../../../../src/lib/start/loadMetroConfig.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAE,OAAO,EAAgB,aAAa,EAAE,MAAM,cAAc,CAAC;AAIzE,MAAM,MAAM,oBAAoB,GAAG,QAAQ,CAAC;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnC,CAAC,CAAC;AAuDH;;;;;GAKG;AACH,wBAA8B,eAAe,CAC3C,GAAG,EAAE;IACH,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,kBAAkB,EAAE,MAAM,CAAC;IAC3B,eAAe,EAAE,MAAM,CAAC;IACxB,IAAI,EAAE,MAAM,CAAC;CACd,EACD,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,OAAO,CAAC,CA8BlB"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import { createRequire } from 'node:module';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { logger, RockError } from '@rock-js/tools';
|
|
10
|
+
import { loadConfig, mergeConfig, resolveConfig } from 'metro-config';
|
|
11
|
+
import { reactNativePlatformResolver } from './metroPlatformResolver.js';
|
|
12
|
+
/**
|
|
13
|
+
* Get the config options to override based on RN CLI inputs.
|
|
14
|
+
*/
|
|
15
|
+
function getOverrideConfig(ctx, config) {
|
|
16
|
+
const outOfTreePlatforms = Object.keys(ctx.platforms).filter(
|
|
17
|
+
// @ts-expect-error - TBD
|
|
18
|
+
(platform) => ctx.platforms[platform].npmPackageName);
|
|
19
|
+
const resolver = {
|
|
20
|
+
platforms: [...Object.keys(ctx.platforms), 'native'],
|
|
21
|
+
};
|
|
22
|
+
if (outOfTreePlatforms.length) {
|
|
23
|
+
// @ts-expect-error - TBD
|
|
24
|
+
resolver.resolveRequest = reactNativePlatformResolver(outOfTreePlatforms.reduce((result, platform) => {
|
|
25
|
+
// @ts-expect-error - TBD
|
|
26
|
+
result[platform] = ctx.platforms[platform].npmPackageName;
|
|
27
|
+
return result;
|
|
28
|
+
}, {}), config.resolver?.resolveRequest);
|
|
29
|
+
}
|
|
30
|
+
const require = createRequire(import.meta.url);
|
|
31
|
+
return {
|
|
32
|
+
resolver,
|
|
33
|
+
serializer: {
|
|
34
|
+
// We can include multiple copies of InitializeCore here because metro will
|
|
35
|
+
// only add ones that are already part of the bundle
|
|
36
|
+
getModulesRunBeforeMainModule: () => [
|
|
37
|
+
require.resolve(path.join(ctx.reactNativePath, 'Libraries/Core/InitializeCore'), { paths: [ctx.root] }),
|
|
38
|
+
...outOfTreePlatforms.map((platform) => require.resolve(
|
|
39
|
+
// @ts-expect-error - TBD
|
|
40
|
+
`${ctx.platforms[platform].npmPackageName}/Libraries/Core/InitializeCore`, { paths: [ctx.root] })),
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Load Metro config.
|
|
47
|
+
*
|
|
48
|
+
* Allows the CLI to override select values in `metro.config.js` based on
|
|
49
|
+
* dynamic user options in `ctx`.
|
|
50
|
+
*/
|
|
51
|
+
export default async function loadMetroConfig(ctx, options = {}) {
|
|
52
|
+
const cwd = ctx.root;
|
|
53
|
+
const projectConfig = await resolveConfig(options.config, cwd);
|
|
54
|
+
if (projectConfig.isEmpty) {
|
|
55
|
+
throw new RockError(`No Metro config found in ${cwd}`);
|
|
56
|
+
}
|
|
57
|
+
logger.debug(`Reading Metro config from ${projectConfig.filepath}`);
|
|
58
|
+
// @ts-expect-error - we're fine with this
|
|
59
|
+
if (!global.__REACT_NATIVE_METRO_CONFIG_LOADED) {
|
|
60
|
+
const warning = `
|
|
61
|
+
=================================================================================================
|
|
62
|
+
From React Native 0.73, your project's Metro config should extend '@react-native/metro-config'
|
|
63
|
+
or it will fail to build. Please copy the template at:
|
|
64
|
+
https://github.com/react-native-community/template/blob/main/template/metro.config.js
|
|
65
|
+
This warning will be removed in future (https://github.com/facebook/metro/issues/1018).
|
|
66
|
+
=================================================================================================
|
|
67
|
+
`;
|
|
68
|
+
for (const line of warning.trim().split('\n')) {
|
|
69
|
+
console.warn(line);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const config = await loadConfig({ cwd, ...options });
|
|
73
|
+
const overrideConfig = getOverrideConfig(ctx, config);
|
|
74
|
+
return mergeConfig(config, overrideConfig);
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=loadMetroConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loadMetroConfig.js","sourceRoot":"","sources":["../../../../src/lib/start/loadMetroConfig.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEnD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAC;AAQzE;;GAEG;AACH,SAAS,iBAAiB,CACxB,GAAyB,EACzB,MAAe;IAEf,MAAM,kBAAkB,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,MAAM;IAC1D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F;KACF,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,eAAe,CAC3C,GAKC,EACD,UAAyB,EAAE;IAE3B,MAAM,GAAG,GAAG,GAAG,CAAC,IAAI,CAAC;IACrB,MAAM,aAAa,GAAG,MAAM,aAAa,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAE/D,IAAI,aAAa,CAAC,OAAO,EAAE,CAAC;QAC1B,MAAM,IAAI,SAAS,CAAC,4BAA4B,GAAG,EAAE,CAAC,CAAC;IACzD,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,6BAA6B,aAAa,CAAC,QAAQ,EAAE,CAAC,CAAC;IAEpE,0CAA0C;IAC1C,IAAI,CAAC,MAAM,CAAC,kCAAkC,EAAE,CAAC;QAC/C,MAAM,OAAO,GAAG;;;;;;;KAOf,CAAC;QAEF,KAAK,MAAM,IAAI,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;YAC9C,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACrB,CAAC;IACH,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IACrD,MAAM,cAAc,GAAG,iBAAiB,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAEtD,OAAO,WAAW,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { CustomResolver } from 'metro-resolver';
|
|
8
|
+
/**
|
|
9
|
+
* This is an implementation of a metro resolveRequest option which will remap react-native imports
|
|
10
|
+
* to different npm packages based on the platform requested. This allows a single metro instance/config
|
|
11
|
+
* to produce bundles for multiple out of tree platforms at a time.
|
|
12
|
+
*
|
|
13
|
+
* @param platformImplementations
|
|
14
|
+
* A map of platform to npm package that implements that platform
|
|
15
|
+
*
|
|
16
|
+
* Ex:
|
|
17
|
+
* {
|
|
18
|
+
* windows: 'react-native-windows'
|
|
19
|
+
* macos: 'react-native-macos'
|
|
20
|
+
* }
|
|
21
|
+
*/
|
|
22
|
+
export declare function reactNativePlatformResolver(platformImplementations: {
|
|
23
|
+
[platform: string]: string;
|
|
24
|
+
}, customResolver: CustomResolver | null | undefined): CustomResolver;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metroPlatformResolver.d.ts","sourceRoot":"","sources":["../../../../src/lib/start/metroPlatformResolver.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,gBAAgB,CAAC;AAEnD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,2BAA2B,CACzC,uBAAuB,EAAE;IACvB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;CAC5B,EACD,cAAc,EAAE,cAAc,GAAG,IAAI,GAAG,SAAS,GAChD,cAAc,CAiBhB"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* This is an implementation of a metro resolveRequest option which will remap react-native imports
|
|
9
|
+
* to different npm packages based on the platform requested. This allows a single metro instance/config
|
|
10
|
+
* to produce bundles for multiple out of tree platforms at a time.
|
|
11
|
+
*
|
|
12
|
+
* @param platformImplementations
|
|
13
|
+
* A map of platform to npm package that implements that platform
|
|
14
|
+
*
|
|
15
|
+
* Ex:
|
|
16
|
+
* {
|
|
17
|
+
* windows: 'react-native-windows'
|
|
18
|
+
* macos: 'react-native-macos'
|
|
19
|
+
* }
|
|
20
|
+
*/
|
|
21
|
+
export function reactNativePlatformResolver(platformImplementations, customResolver) {
|
|
22
|
+
return (context, moduleName, platform) => {
|
|
23
|
+
let modifiedModuleName = moduleName;
|
|
24
|
+
if (platform != null && platformImplementations[platform]) {
|
|
25
|
+
if (moduleName === 'react-native') {
|
|
26
|
+
modifiedModuleName = platformImplementations[platform];
|
|
27
|
+
}
|
|
28
|
+
else if (moduleName.startsWith('react-native/')) {
|
|
29
|
+
modifiedModuleName = `${platformImplementations[platform]}/${modifiedModuleName.slice('react-native/'.length)}`;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (customResolver) {
|
|
33
|
+
return customResolver(context, modifiedModuleName, platform);
|
|
34
|
+
}
|
|
35
|
+
return context.resolveRequest(context, modifiedModuleName, platform);
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=metroPlatformResolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metroPlatformResolver.js","sourceRoot":"","sources":["../../../../src/lib/start/metroPlatformResolver.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,2BAA2B,CACzC,uBAEC,EACD,cAAiD;IAEjD,OAAO,CAAC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,EAAE;QACvC,IAAI,kBAAkB,GAAG,UAAU,CAAC;QACpC,IAAI,QAAQ,IAAI,IAAI,IAAI,uBAAuB,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC1D,IAAI,UAAU,KAAK,cAAc,EAAE,CAAC;gBAClC,kBAAkB,GAAG,uBAAuB,CAAC,QAAQ,CAAC,CAAC;YACzD,CAAC;iBAAM,IAAI,UAAU,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE,CAAC;gBAClD,kBAAkB,GAAG,GACnB,uBAAuB,CAAC,QAAQ,CAClC,IAAI,kBAAkB,CAAC,KAAK,CAAC,eAAe,CAAC,MAAM,CAAC,EAAE,CAAC;YACzD,CAAC;QACH,CAAC;QACD,IAAI,cAAc,EAAE,CAAC;YACnB,OAAO,cAAc,CAAC,OAAO,EAAE,kBAAkB,EAAE,QAAQ,CAAC,CAAC;QAC/D,CAAC;QACD,OAAO,OAAO,CAAC,cAAc,CAAC,OAAO,EAAE,kBAAkB,EAAE,QAAQ,CAAC,CAAC;IACvE,CAAC,CAAC;AACJ,CAAC"}
|