Skip to content

Commit 0993f62

Browse files
afoxmangrabbou
andauthored
feat: move all metro logic and commands into a dedicated package (#1447)
* Move metro configuration and bundling logic into their own packages, making them available to external users. * Rename metro-config package to metro * Move cli-bundle-api package and bundle command (cli package) into metro. * Move resolveNodeModuleDir to cli-tools package * Move releaseChecker into cli-tools * Move hookStdout to cli-tools * Move start command into metro package * Rename 'metro' package to 'cli-plugin-metro'. * Update dependency * More renaming * Revert buildBundle to default export * Make exports explicit * Revert exports to default * PR feedback * refactor(structure): moved some files around to reflect the convention a bit better * Fix type bug, export missing funciton/type. Co-authored-by: Mike Grabowski <grabbou@gmail.com>
1 parent 0239244 commit 0993f62

39 files changed

+143
-51
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "@react-native-community/cli-plugin-metro",
3+
"version": "6.0.0",
4+
"license": "MIT",
5+
"main": "build/index.js",
6+
"publishConfig": {
7+
"access": "public"
8+
},
9+
"dependencies": {
10+
"@react-native-community/cli-tools": "^6.0.0-rc.0",
11+
"@react-native-community/cli-server-api": "^6.0.0-rc.0",
12+
"chalk": "^3.0.0",
13+
"metro": "^0.66.1",
14+
"metro-config": "^0.66.1",
15+
"metro-core": "^0.66.1",
16+
"metro-react-native-babel-transformer": "^0.66.1",
17+
"metro-resolver": "^0.66.1",
18+
"metro-runtime": "^0.66.1",
19+
"mkdirp": "^0.5.1",
20+
"readline": "^1.3.0"
21+
},
22+
"devDependencies": {
23+
"@react-native-community/cli-types": "^6.0.0"
24+
},
25+
"files": [
26+
"build",
27+
"!*.map"
28+
],
29+
"homepage": "https://github.com/react-native-community/cli/tree/master/packages/cli-plugin-metro",
30+
"repository": {
31+
"type": "git",
32+
"url": "https://github.com/react-native-community/cli.git",
33+
"directory": "packages/cli-plugin-metro"
34+
}
35+
}

packages/cli/src/commands/bundle/__mocks__/sign.js renamed to packages/cli-plugin-metro/src/commands/bundle/__mocks__/sign.js

File renamed without changes.

packages/cli/src/commands/bundle/__tests__/filterPlatformAssetScales-test.ts renamed to packages/cli-plugin-metro/src/commands/bundle/__tests__/filterPlatformAssetScales-test.ts

File renamed without changes.

packages/cli/src/commands/bundle/__tests__/getAssetDestPathAndroid-test.ts renamed to packages/cli-plugin-metro/src/commands/bundle/__tests__/getAssetDestPathAndroid-test.ts

File renamed without changes.

packages/cli/src/commands/bundle/__tests__/getAssetDestPathIOS-test.ts renamed to packages/cli-plugin-metro/src/commands/bundle/__tests__/getAssetDestPathIOS-test.ts

File renamed without changes.

packages/cli/src/commands/bundle/assetPathUtils.ts renamed to packages/cli-plugin-metro/src/commands/bundle/assetPathUtils.ts

File renamed without changes.

packages/cli/src/commands/bundle/buildBundle.ts renamed to packages/cli-plugin-metro/src/commands/bundle/buildBundle.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@
99
// @ts-ignore - no typed definition for the package
1010
import Server from 'metro/src/Server';
1111
// @ts-ignore - no typed definition for the package
12-
import outputBundle from 'metro/src/shared/output/bundle';
12+
const outputBundle = require('metro/src/shared/output/bundle');
1313
import path from 'path';
1414
import chalk from 'chalk';
1515
import {CommandLineArgs} from './bundleCommandLineArgs';
16-
import {Config} from '@react-native-community/cli-types';
16+
import type {Config} from '@react-native-community/cli-types';
1717
import saveAssets from './saveAssets';
18-
import loadMetroConfig from '../../tools/loadMetroConfig';
18+
import {
19+
default as loadMetroConfig,
20+
MetroConfig,
21+
} from '../../tools/loadMetroConfig';
1922
import {logger} from '@react-native-community/cli-tools';
2023

2124
interface RequestOptions {
@@ -51,6 +54,19 @@ async function buildBundle(
5154
config: args.config,
5255
});
5356

57+
return buildBundleWithConfig(args, config, output);
58+
}
59+
60+
/**
61+
* Create a bundle using a pre-loaded Metro config. The config can be
62+
* re-used for several bundling calls if multiple platforms are being
63+
* bundled.
64+
*/
65+
export async function buildBundleWithConfig(
66+
args: CommandLineArgs,
67+
config: MetroConfig,
68+
output: typeof outputBundle = outputBundle,
69+
) {
5470
if (config.resolver.platforms.indexOf(args.platform) === -1) {
5571
logger.error(
5672
`Invalid platform ${

packages/cli/src/commands/bundle/bundle.ts renamed to packages/cli-plugin-metro/src/commands/bundle/bundle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* LICENSE file in the root directory of this source tree.
66
*
77
*/
8-
import {Config} from '@react-native-community/cli-types';
8+
import type {Config} from '@react-native-community/cli-types';
99
import buildBundle from './buildBundle';
1010
import bundleCommandLineArgs, {CommandLineArgs} from './bundleCommandLineArgs';
1111

packages/cli/src/commands/bundle/bundleCommandLineArgs.ts renamed to packages/cli-plugin-metro/src/commands/bundle/bundleCommandLineArgs.ts

File renamed without changes.

packages/cli/src/commands/bundle/filterPlatformAssetScales.ts renamed to packages/cli-plugin-metro/src/commands/bundle/filterPlatformAssetScales.ts

File renamed without changes.

0 commit comments

Comments
 (0)