@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,36 @@
|
|
|
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
|
+
const ALLOWED_SCALES = {
|
|
9
|
+
ios: [1, 2, 3],
|
|
10
|
+
};
|
|
11
|
+
function filterPlatformAssetScales(platform, scales) {
|
|
12
|
+
const whitelist = ALLOWED_SCALES[platform];
|
|
13
|
+
if (!whitelist) {
|
|
14
|
+
return scales;
|
|
15
|
+
}
|
|
16
|
+
const result = scales.filter((scale) => whitelist.indexOf(scale) > -1);
|
|
17
|
+
if (result.length === 0 && scales.length > 0) {
|
|
18
|
+
// No matching scale found, but there are some available. Ideally we don't
|
|
19
|
+
// want to be in this situation and should throw, but for now as a fallback
|
|
20
|
+
// let's just use the closest larger image
|
|
21
|
+
const maxScale = whitelist[whitelist.length - 1];
|
|
22
|
+
for (const scale of scales) {
|
|
23
|
+
if (scale > maxScale) {
|
|
24
|
+
result.push(scale);
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
// There is no larger scales available, use the largest we have
|
|
29
|
+
if (result.length === 0) {
|
|
30
|
+
result.push(scales[scales.length - 1]);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
export default filterPlatformAssetScales;
|
|
36
|
+
//# sourceMappingURL=filterPlatformAssetScales.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filterPlatformAssetScales.js","sourceRoot":"","sources":["../../../../src/lib/bundle/filterPlatformAssetScales.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,cAAc,GAAgC;IAClD,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;CACf,CAAC;AAEF,SAAS,yBAAyB,CAChC,QAAgB,EAChB,MAA6B;IAE7B,MAAM,SAAS,GAAa,cAAc,CAAC,QAAQ,CAAC,CAAC;IACrD,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACvE,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC7C,0EAA0E;QAC1E,2EAA2E;QAC3E,0CAA0C;QAC1C,MAAM,QAAQ,GAAG,SAAS,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QACjD,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,IAAI,KAAK,GAAG,QAAQ,EAAE,CAAC;gBACrB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBACnB,MAAM;YACR,CAAC;QACH,CAAC;QAED,+DAA+D;QAC/D,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACxB,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;QACzC,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,eAAe,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
import type { PackagerAsset } from './assetPathUtils.js';
|
|
9
|
+
declare function getAssetDestPathAndroid(asset: PackagerAsset, scale: number): string;
|
|
10
|
+
export default getAssetDestPathAndroid;
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
import path from 'path';
|
|
9
|
+
import assetPathUtils from './assetPathUtils.js';
|
|
10
|
+
function getAssetDestPathAndroid(asset, scale) {
|
|
11
|
+
const androidFolder = assetPathUtils.getAndroidResourceFolderName(asset, scale);
|
|
12
|
+
const fileName = assetPathUtils.getResourceIdentifier(asset);
|
|
13
|
+
return path.join(androidFolder, `${fileName}.${asset.type}`);
|
|
14
|
+
}
|
|
15
|
+
export default getAssetDestPathAndroid;
|
|
16
|
+
//# sourceMappingURL=getAssetDestPathAndroid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getAssetDestPathAndroid.js","sourceRoot":"","sources":["../../../../src/lib/bundle/getAssetDestPathAndroid.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,cAAc,MAAM,qBAAqB,CAAC;AAEjD,SAAS,uBAAuB,CAAC,KAAoB,EAAE,KAAa;IAClE,MAAM,aAAa,GAAG,cAAc,CAAC,4BAA4B,CAC/D,KAAK,EACL,KAAK,CACN,CAAC;IACF,MAAM,QAAQ,GAAG,cAAc,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAC;IAC7D,OAAO,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,GAAG,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;AAC/D,CAAC;AAED,eAAe,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
import type { PackagerAsset } from './assetPathUtils.js';
|
|
9
|
+
declare function getAssetDestPathIOS(asset: PackagerAsset, scale: number): string;
|
|
10
|
+
export default getAssetDestPathIOS;
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
import path from 'path';
|
|
9
|
+
function getAssetDestPathIOS(asset, scale) {
|
|
10
|
+
const suffix = scale === 1 ? '' : `@${scale}x`;
|
|
11
|
+
const fileName = `${asset.name + suffix}.${asset.type}`;
|
|
12
|
+
return path.join(
|
|
13
|
+
// Assets can have relative paths outside of the project root.
|
|
14
|
+
// Replace `../` with `_` to make sure they don't end up outside of
|
|
15
|
+
// the expected assets directory.
|
|
16
|
+
asset.httpServerLocation.substr(1).replace(/\.\.\//g, '_'), fileName);
|
|
17
|
+
}
|
|
18
|
+
export default getAssetDestPathIOS;
|
|
19
|
+
//# sourceMappingURL=getAssetDestPathIOS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getAssetDestPathIOS.js","sourceRoot":"","sources":["../../../../src/lib/bundle/getAssetDestPathIOS.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,IAAI,MAAM,MAAM,CAAC;AAGxB,SAAS,mBAAmB,CAAC,KAAoB,EAAE,KAAa;IAC9D,MAAM,MAAM,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,GAAG,CAAC;IAC/C,MAAM,QAAQ,GAAG,GAAG,KAAK,CAAC,IAAI,GAAG,MAAM,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;IACxD,OAAO,IAAI,CAAC,IAAI;IACd,8DAA8D;IAC9D,mEAAmE;IACnE,iCAAiC;IACjC,KAAK,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,EAC1D,QAAQ,CACT,CAAC;AACJ,CAAC;AAED,eAAe,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
import type { CommandType } from '@rnef/config';
|
|
9
|
+
export type { BundleCommandArgs } from './buildBundle.js';
|
|
10
|
+
declare const bundleCommand: CommandType;
|
|
11
|
+
export { bundleCommand };
|
|
@@ -0,0 +1,106 @@
|
|
|
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
|
+
import path from 'path';
|
|
9
|
+
import buildBundle from './buildBundle.js';
|
|
10
|
+
const bundleCommand = {
|
|
11
|
+
name: 'bundle',
|
|
12
|
+
description: 'Build the bundle for the provided JavaScript entry file.',
|
|
13
|
+
func: buildBundle,
|
|
14
|
+
options: [
|
|
15
|
+
{
|
|
16
|
+
name: '--entry-file <path>',
|
|
17
|
+
description: 'Path to the root JS file, either absolute or relative to JS root',
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
name: '--platform <string>',
|
|
21
|
+
description: 'Either "ios" or "android"',
|
|
22
|
+
default: 'ios',
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: '--transformer <string>',
|
|
26
|
+
description: 'Specify a custom transformer to be used',
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name: '--dev [boolean]',
|
|
30
|
+
description: 'If false, warnings are disabled and the bundle is minified',
|
|
31
|
+
parse: (val) => val !== 'false',
|
|
32
|
+
default: true,
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: '--minify [boolean]',
|
|
36
|
+
description: 'Allows overriding whether bundle is minified. This defaults to ' +
|
|
37
|
+
'false if dev is true, and true if dev is false. Disabling minification ' +
|
|
38
|
+
'can be useful for speeding up production builds for testing purposes.',
|
|
39
|
+
parse: (val) => val !== 'false',
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: '--bundle-output <string>',
|
|
43
|
+
description: 'File name where to store the resulting bundle, ex. /tmp/groups.bundle',
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: '--bundle-encoding <string>',
|
|
47
|
+
description: 'Encoding the bundle should be written in (https://nodejs.org/api/buffer.html#buffer_buffer).',
|
|
48
|
+
default: 'utf8',
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: '--max-workers <number>',
|
|
52
|
+
description: 'Specifies the maximum number of workers the worker-pool ' +
|
|
53
|
+
'will spawn for transforming files. This defaults to the number of the ' +
|
|
54
|
+
'cores available on your machine.',
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: '--sourcemap-output <string>',
|
|
58
|
+
description: 'File name where to store the sourcemap file for resulting bundle, ex. /tmp/groups.map',
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: '--sourcemap-sources-root <string>',
|
|
62
|
+
description: "Path to make sourcemap's sources entries relative to, ex. /root/dir",
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: '--sourcemap-use-absolute-path',
|
|
66
|
+
description: 'Report SourceMapURL using its full path',
|
|
67
|
+
default: false,
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
name: '--assets-dest <string>',
|
|
71
|
+
description: 'Directory name where to store assets referenced in the bundle',
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
name: '--unstable-transform-profile <string>',
|
|
75
|
+
description: 'Experimental, transform JS for a specific JS engine. Currently supported: hermes, hermes-canary, default',
|
|
76
|
+
default: 'default',
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: '--asset-catalog-dest [string]',
|
|
80
|
+
description: 'Path where to create an iOS Asset Catalog for images',
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
name: '--reset-cache',
|
|
84
|
+
description: 'Removes cached files',
|
|
85
|
+
default: false,
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
name: '--read-global-cache',
|
|
89
|
+
description: 'Try to fetch transformed JS code from the global cache, if configured.',
|
|
90
|
+
default: false,
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
name: '--config <string>',
|
|
94
|
+
description: 'Path to the CLI configuration file',
|
|
95
|
+
parse: (val) => path.resolve(val),
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
name: '--resolver-option <string...>',
|
|
99
|
+
description: 'Custom resolver options of the form key=value. URL-encoded. May be specified multiple times.',
|
|
100
|
+
// @ts-expect-error - TODO: fix this
|
|
101
|
+
parse: (val, previous = []) => previous.concat([val]),
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
};
|
|
105
|
+
export { bundleCommand };
|
|
106
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/bundle/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,WAAW,MAAM,kBAAkB,CAAC;AAI3C,MAAM,aAAa,GAAgB;IACjC,IAAI,EAAE,QAAQ;IACd,WAAW,EAAE,0DAA0D;IACvE,IAAI,EAAE,WAAW;IACjB,OAAO,EAAE;QACP;YACE,IAAI,EAAE,qBAAqB;YAC3B,WAAW,EACT,kEAAkE;SACrE;QACD;YACE,IAAI,EAAE,qBAAqB;YAC3B,WAAW,EAAE,2BAA2B;YACxC,OAAO,EAAE,KAAK;SACf;QACD;YACE,IAAI,EAAE,wBAAwB;YAC9B,WAAW,EAAE,yCAAyC;SACvD;QACD;YACE,IAAI,EAAE,iBAAiB;YACvB,WAAW,EAAE,4DAA4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;SAClD;QACD;YACE,IAAI,EAAE,+BAA+B;YACrC,WAAW,EACT,8FAA8F;YAChG,oCAAoC;YACpC,KAAK,EAAE,CAAC,GAAW,EAAE,WAA0B,EAAE,EAAiB,EAAE,CAClE,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC;SACzB;KACF;CACF,CAAC;AAEF,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
import type { AssetData } from 'metro';
|
|
9
|
+
declare function saveAssets(assets: ReadonlyArray<AssetData>, platform: string, assetsDest?: string, assetCatalogDest?: string): Promise<void>;
|
|
10
|
+
export default saveAssets;
|
|
@@ -0,0 +1,112 @@
|
|
|
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
|
+
import fs from 'fs';
|
|
9
|
+
import path from 'path';
|
|
10
|
+
import { cleanAssetCatalog, getImageSet, isCatalogAsset, writeImageSet, } from './assetCatalogIOS.js';
|
|
11
|
+
import createKeepFileAsync from './createKeepFileAsync.js';
|
|
12
|
+
import filterPlatformAssetScales from './filterPlatformAssetScales.js';
|
|
13
|
+
import getAssetDestPathAndroid from './getAssetDestPathAndroid.js';
|
|
14
|
+
import getAssetDestPathIOS from './getAssetDestPathIOS.js';
|
|
15
|
+
// import { styleText } from 'util'; // Not available in all Node versions
|
|
16
|
+
function styleText(style, text) {
|
|
17
|
+
const styles = {
|
|
18
|
+
red: '\x1b[31m',
|
|
19
|
+
bold: '\x1b[1m',
|
|
20
|
+
reset: '\x1b[0m'
|
|
21
|
+
};
|
|
22
|
+
const colorCode = styles[style] || '';
|
|
23
|
+
return `${colorCode}${text}${styles.reset}`;
|
|
24
|
+
}
|
|
25
|
+
async function saveAssets(assets, platform, assetsDest, assetCatalogDest) {
|
|
26
|
+
if (assetsDest == null) {
|
|
27
|
+
console.warn('Warning: Assets destination folder is not set, skipping...');
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const filesToCopy = {};
|
|
31
|
+
const getAssetDestPath = platform === 'android' ? getAssetDestPathAndroid : getAssetDestPathIOS;
|
|
32
|
+
const addAssetToCopy = (asset) => {
|
|
33
|
+
const validScales = new Set(filterPlatformAssetScales(platform, asset.scales));
|
|
34
|
+
asset.scales.forEach((scale, idx) => {
|
|
35
|
+
if (!validScales.has(scale)) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const src = asset.files[idx];
|
|
39
|
+
const dest = path.join(assetsDest, getAssetDestPath(asset, scale));
|
|
40
|
+
filesToCopy[src] = dest;
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
if (platform === 'ios' && assetCatalogDest != null) {
|
|
44
|
+
// Use iOS Asset Catalog for images. This will allow Apple app thinning to
|
|
45
|
+
// remove unused scales from the optimized bundle.
|
|
46
|
+
const catalogDir = path.join(assetCatalogDest, 'RNAssets.xcassets');
|
|
47
|
+
if (!fs.existsSync(catalogDir)) {
|
|
48
|
+
console.error(`${styleText('red', 'error')}: Could not find asset catalog 'RNAssets.xcassets' in ${assetCatalogDest}. Make sure to create it if it does not exist.`);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
console.info('Adding images to asset catalog', catalogDir);
|
|
52
|
+
cleanAssetCatalog(catalogDir);
|
|
53
|
+
for (const asset of assets) {
|
|
54
|
+
if (isCatalogAsset(asset)) {
|
|
55
|
+
const imageSet = getImageSet(catalogDir, asset, filterPlatformAssetScales(platform, asset.scales));
|
|
56
|
+
writeImageSet(imageSet);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
addAssetToCopy(asset);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
console.info('Done adding images to asset catalog');
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
assets.forEach(addAssetToCopy);
|
|
66
|
+
}
|
|
67
|
+
if (platform === 'android') {
|
|
68
|
+
await createKeepFileAsync(assets, assetsDest);
|
|
69
|
+
}
|
|
70
|
+
return copyAll(filesToCopy);
|
|
71
|
+
}
|
|
72
|
+
function copyAll(filesToCopy) {
|
|
73
|
+
const queue = Object.keys(filesToCopy);
|
|
74
|
+
if (queue.length === 0) {
|
|
75
|
+
return Promise.resolve();
|
|
76
|
+
}
|
|
77
|
+
console.info(`Copying ${queue.length} asset files`);
|
|
78
|
+
return new Promise((resolve, reject) => {
|
|
79
|
+
const copyNext = (error) => {
|
|
80
|
+
if (error) {
|
|
81
|
+
reject(error);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (queue.length === 0) {
|
|
85
|
+
console.info('Done copying assets');
|
|
86
|
+
resolve();
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
// queue.length === 0 is checked in previous branch, so this is string
|
|
90
|
+
const src = queue.shift();
|
|
91
|
+
const dest = filesToCopy[src];
|
|
92
|
+
copy(src, dest, copyNext);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
copyNext();
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
function copy(src, dest, callback) {
|
|
99
|
+
const destDir = path.dirname(dest);
|
|
100
|
+
fs.mkdir(destDir, { recursive: true }, (err) => {
|
|
101
|
+
if (err) {
|
|
102
|
+
callback(err);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
fs.createReadStream(src)
|
|
106
|
+
.pipe(fs.createWriteStream(dest))
|
|
107
|
+
.on('finish', () => callback())
|
|
108
|
+
.on('error', callback);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
export default saveAssets;
|
|
112
|
+
//# sourceMappingURL=saveAssets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"saveAssets.js","sourceRoot":"","sources":["../../../../src/lib/bundle/saveAssets.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EACL,iBAAiB,EACjB,WAAW,EACX,cAAc,EACd,aAAa,GACd,MAAM,sBAAsB,CAAC;AAC9B,OAAO,mBAAmB,MAAM,0BAA0B,CAAC;AAC3D,OAAO,yBAAyB,MAAM,gCAAgC,CAAC;AACvE,OAAO,uBAAuB,MAAM,8BAA8B,CAAC;AACnE,OAAO,mBAAmB,MAAM,0BAA0B,CAAC;AAC3D,0EAA0E;AAC1E,SAAS,SAAS,CAAC,KAAa,EAAE,IAAY;IAC5C,MAAM,MAAM,GAAG;QACb,GAAG,EAAE,UAAU;QACf,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,SAAS;KACjB,CAAC;IACF,MAAM,SAAS,GAAG,MAAM,CAAC,KAA4B,CAAC,IAAI,EAAE,CAAC;IAC7D,OAAO,GAAG,SAAS,GAAG,IAAI,GAAG,MAAM,CAAC,KAAK,EAAE,CAAC;AAC9C,CAAC;AAMD,KAAK,UAAU,UAAU,CACvB,MAAgC,EAChC,QAAgB,EAChB,UAAmB,EACnB,gBAAyB;IAEzB,IAAI,UAAU,IAAI,IAAI,EAAE,CAAC;QACvB,OAAO,CAAC,IAAI,CAAC,4DAA4D,CAAC,CAAC;QAC3E,OAAO;IACT,CAAC;IAED,MAAM,WAAW,GAAgB,EAAE,CAAC;IAEpC,MAAM,gBAAgB,GACpB,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,uBAAuB,CAAC,CAAC,CAAC,mBAAmB,CAAC;IAEzE,MAAM,cAAc,GAAG,CAAC,KAAgB,EAAE,EAAE;QAC1C,MAAM,WAAW,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AQ,CAAC,CAAC;YAC5B,CAAC;QACH,CAAC,CAAC;QACF,QAAQ,EAAE,CAAC;IACb,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,IAAI,CACX,GAAW,EACX,IAAY,EACZ,QAAiC;IAEjC,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,CAAC,GAAG,EAAE,EAAE;QAC7C,IAAI,GAAG,EAAE,CAAC;YACR,QAAQ,CAAC,GAAG,CAAC,CAAC;YACd,OAAO;QACT,CAAC;QACD,EAAE,CAAC,gBAAgB,CAAC,GAAG,CAAC;aACrB,IAAI,CAAC,EAAE,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;aAChC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC;aAC9B,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;AACL,CAAC;AAED,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
export async function getDevMiddleware(reactNativePath) {
|
|
3
|
+
const require = createRequire(import.meta.url);
|
|
4
|
+
const reactNativeCommunityCliPluginPath = require.resolve('@react-native/community-cli-plugin', { paths: [reactNativePath] });
|
|
5
|
+
const devMiddlewarePath = require.resolve('@react-native/dev-middleware', {
|
|
6
|
+
paths: [reactNativeCommunityCliPluginPath],
|
|
7
|
+
});
|
|
8
|
+
return import(devMiddlewarePath);
|
|
9
|
+
}
|
|
10
|
+
export async function getReactNativeCommunityCliPlugin(reactNativePath) {
|
|
11
|
+
const require = createRequire(import.meta.url);
|
|
12
|
+
const reactNativeCommunityCliPluginPath = require.resolve('@react-native/community-cli-plugin', { paths: [reactNativePath] });
|
|
13
|
+
return import(reactNativeCommunityCliPluginPath);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=getDevMiddleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getDevMiddleware.js","sourceRoot":"","sources":["../../../src/lib/getDevMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,eAAuB;IAC5D,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC/C,MAAM,iCAAiC,GAAG,OAAO,CAAC,OAAO,CACvD,oCAAoC,EACpC,EAAE,KAAK,EAAE,CAAC,eAAe,CAAC,EAAE,CAC7B,CAAC;IAEF,MAAM,iBAAiB,GAAG,OAAO,CAAC,OAAO,CAAC,8BAA8B,EAAE;QACxE,KAAK,EAAE,CAAC,iCAAiC,CAAC;KAC3C,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC,iBAAiB,CAAC,CAAC;AACnC,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,gCAAgC,CACpD,eAAuB;IAEvB,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC/C,MAAM,iCAAiC,GAAG,OAAO,CAAC,OAAO,CACvD,oCAAoC,EACpC,EAAE,KAAK,EAAE,CAAC,eAAe,CAAC,EAAE,CAC7B,CAAC;IAEF,OAAO,MAAM,CAAC,iCAAiC,CAAC,CAAC;AACnD,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
export async function getDevMiddleware(reactNativePath) {
|
|
3
|
+
const require = createRequire(import.meta.url);
|
|
4
|
+
const reactNativeCommunityCliPluginPath = require.resolve('@react-native/community-cli-plugin', { paths: [reactNativePath] });
|
|
5
|
+
const devMiddlewarePath = require.resolve('@react-native/dev-middleware', {
|
|
6
|
+
paths: [reactNativeCommunityCliPluginPath],
|
|
7
|
+
});
|
|
8
|
+
return import(devMiddlewarePath);
|
|
9
|
+
}
|
|
10
|
+
export async function getReactNativeCommunityCliPlugin(reactNativePath) {
|
|
11
|
+
const require = createRequire(import.meta.url);
|
|
12
|
+
const reactNativeCommunityCliPluginPath = require.resolve('@react-native/community-cli-plugin', { paths: [reactNativePath] });
|
|
13
|
+
return import(reactNativeCommunityCliPluginPath);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=getReactNativeDeps.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getReactNativeDeps.js","sourceRoot":"","sources":["../../../src/lib/getReactNativeDeps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG5C,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,eAAuB;IAEvB,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC/C,MAAM,iCAAiC,GAAG,OAAO,CAAC,OAAO,CACvD,oCAAoC,EACpC,EAAE,KAAK,EAAE,CAAC,eAAe,CAAC,EAAE,CAC7B,CAAC;IAEF,MAAM,iBAAiB,GAAG,OAAO,CAAC,OAAO,CAAC,8BAA8B,EAAE;QACxE,KAAK,EAAE,CAAC,iCAAiC,CAAC;KAC3C,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC,iBAAiB,CAAC,CAAC;AACnC,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,gCAAgC,CACpD,eAAuB;IAEvB,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC/C,MAAM,iCAAiC,GAAG,OAAO,CAAC,OAAO,CACvD,oCAAoC,EACpC,EAAE,KAAK,EAAE,CAAC,eAAe,CAAC,EAAE,CAC7B,CAAC;IAEF,OAAO,MAAM,CAAC,iCAAiC,CAAC,CAAC;AACnD,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,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, RnefError } from '@rnef/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 RnefError(`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/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,aAAa,CAAC;AAEhD,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,yBAAyB;IACzB,CAAC,QAAQ,EAAE,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,cAAc,CACr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,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 @@
|
|
|
1
|
+
{"version":3,"file":"pluginMetro.d.ts","sourceRoot":"","sources":["../../../src/lib/pluginMetro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAI5D,eAAO,MAAM,WAAW,cAEhB,SAAS,KAAG,YAQjB,CAAC;AAEJ,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { registerBundleCommand } from './bundle/command.js';
|
|
2
|
+
import { registerStartCommand } from './start/command.js';
|
|
3
|
+
export const pluginMetro = () => (api) => {
|
|
4
|
+
registerStartCommand(api);
|
|
5
|
+
registerBundleCommand(api);
|
|
6
|
+
return {
|
|
7
|
+
name: '@rock-js/plugin-metro',
|
|
8
|
+
description: 'Rock plugin for Metro bundler.',
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export default pluginMetro;
|
|
12
|
+
//# sourceMappingURL=pluginMetro.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pluginMetro.js","sourceRoot":"","sources":["../../../src/lib/pluginMetro.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAE1D,MAAM,CAAC,MAAM,WAAW,GACtB,GAAG,EAAE,CACL,CAAC,GAAc,EAAgB,EAAE;IAC/B,oBAAoB,CAAC,GAAG,CAAC,CAAC;IAC1B,qBAAqB,CAAC,GAAG,CAAC,CAAC;IAE3B,OAAO;QACL,IAAI,EAAE,uBAAuB;QAC7B,WAAW,EAAE,gCAAgC;KAC9C,CAAC;AACJ,CAAC,CAAC;AAEJ,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
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 class OpenDebuggerKeyboardHandler {
|
|
9
|
+
#private;
|
|
10
|
+
constructor({ devServerUrl, reporter, }: {
|
|
11
|
+
devServerUrl: string;
|
|
12
|
+
reporter: TerminalReporter;
|
|
13
|
+
});
|
|
14
|
+
/**
|
|
15
|
+
* Used in response to 'j' to debug - fetch the available debug targets and:
|
|
16
|
+
* - If no targets, warn
|
|
17
|
+
* - If one target, open it
|
|
18
|
+
* - If more, show a list. The keyboard listener should run subsequent key
|
|
19
|
+
* presses through maybeHandleTargetSelection, which will launch the
|
|
20
|
+
* debugger if a match is made.
|
|
21
|
+
*/
|
|
22
|
+
handleOpenDebugger(): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Handle key presses that correspond to a valid selection from a visible
|
|
25
|
+
* selection list.
|
|
26
|
+
*
|
|
27
|
+
* @return true if we've handled the key as a target selection, false if the
|
|
28
|
+
* caller should handle the key.
|
|
29
|
+
*/
|
|
30
|
+
maybeHandleTargetSelection(keyName: string): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Dismiss any target selection UI, if shown.
|
|
33
|
+
*/
|
|
34
|
+
dismiss(): void;
|
|
35
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OpenDebuggerKeyboardHandler.d.ts","sourceRoot":"","sources":["../../../../src/lib/start/OpenDebuggerKeyboardHandler.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAQvE,MAAM,CAAC,OAAO,OAAO,2BAA2B;;gBAKlC,EACV,YAAY,EACZ,QAAQ,GACT,EAAE;QACD,YAAY,EAAE,MAAM,CAAC;QACrB,QAAQ,EAAE,gBAAgB,CAAC;KAC5B;IAkCD;;;;;;;OAOG;IACG,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC;IAmDzC;;;;;;OAMG;IACH,0BAA0B,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAgBpD;;OAEG;IACH,OAAO;CA6BR"}
|