From 02e96a6e7f4aa6d2ec4320a2aa14441a77b1c292 Mon Sep 17 00:00:00 2001 From: Adam Foxman Date: Wed, 14 Jul 2021 13:10:53 -0700 Subject: [PATCH 01/16] Move metro configuration and bundling logic into their own packages, making them available to external users. --- packages/cli-bundle-api/package.json | 22 +++++++++++++ .../src}/__mocks__/sign.js | 0 .../filterPlatformAssetScales-test.ts | 0 .../__tests__/getAssetDestPathAndroid-test.ts | 0 .../__tests__/getAssetDestPathIOS-test.ts | 0 .../src}/assetPathUtils.ts | 0 .../src}/buildBundle.ts | 31 ++++++++++++++----- .../src}/filterPlatformAssetScales.ts | 0 .../src}/getAssetDestPathAndroid.ts | 0 .../src}/getAssetDestPathIOS.ts | 0 packages/cli-bundle-api/src/index.ts | 1 + .../src}/saveAssets.ts | 0 packages/cli-bundle-api/tsconfig.json | 11 +++++++ packages/cli/package.json | 2 ++ packages/cli/src/commands/bundle/bundle.ts | 2 +- .../commands/bundle/bundleCommandLineArgs.ts | 21 +------------ packages/cli/src/commands/start/runServer.ts | 2 +- packages/cli/tsconfig.json | 4 ++- packages/metro-config/package.json | 22 +++++++++++++ .../src}/__tests__/loadMetroConfig-test.ts | 1 + packages/metro-config/src/index.ts | 2 ++ .../src}/loadMetroConfig.ts | 2 +- .../src}/metroPlatformResolver.ts | 0 packages/metro-config/tsconfig.json | 11 +++++++ 24 files changed, 103 insertions(+), 31 deletions(-) create mode 100644 packages/cli-bundle-api/package.json rename packages/{cli/src/commands/bundle => cli-bundle-api/src}/__mocks__/sign.js (100%) rename packages/{cli/src/commands/bundle => cli-bundle-api/src}/__tests__/filterPlatformAssetScales-test.ts (100%) rename packages/{cli/src/commands/bundle => cli-bundle-api/src}/__tests__/getAssetDestPathAndroid-test.ts (100%) rename packages/{cli/src/commands/bundle => cli-bundle-api/src}/__tests__/getAssetDestPathIOS-test.ts (100%) rename packages/{cli/src/commands/bundle => cli-bundle-api/src}/assetPathUtils.ts (100%) rename packages/{cli/src/commands/bundle => cli-bundle-api/src}/buildBundle.ts (81%) rename packages/{cli/src/commands/bundle => cli-bundle-api/src}/filterPlatformAssetScales.ts (100%) rename packages/{cli/src/commands/bundle => cli-bundle-api/src}/getAssetDestPathAndroid.ts (100%) rename packages/{cli/src/commands/bundle => cli-bundle-api/src}/getAssetDestPathIOS.ts (100%) create mode 100644 packages/cli-bundle-api/src/index.ts rename packages/{cli/src/commands/bundle => cli-bundle-api/src}/saveAssets.ts (100%) create mode 100644 packages/cli-bundle-api/tsconfig.json create mode 100644 packages/metro-config/package.json rename packages/{cli/src/tools => metro-config/src}/__tests__/loadMetroConfig-test.ts (95%) create mode 100644 packages/metro-config/src/index.ts rename packages/{cli/src/tools => metro-config/src}/loadMetroConfig.ts (99%) rename packages/{cli/src/tools => metro-config/src}/metroPlatformResolver.ts (100%) create mode 100644 packages/metro-config/tsconfig.json diff --git a/packages/cli-bundle-api/package.json b/packages/cli-bundle-api/package.json new file mode 100644 index 000000000..e7fef14db --- /dev/null +++ b/packages/cli-bundle-api/package.json @@ -0,0 +1,22 @@ +{ + "name": "@react-native-community/cli-bundle-api", + "version": "6.0.0-rc.0", + "license": "MIT", + "main": "build/index.js", + "publishConfig": { + "access": "public" + }, + "dependencies": { + "@react-native-community/metro-config": "^6.0.0-rc.0" + }, + "files": [ + "build", + "!*.map" + ], + "homepage": "https://github.com/react-native-community/cli/tree/master/packages/cli-bundle-api", + "repository": { + "type": "git", + "url": "https://github.com/react-native-community/cli.git", + "directory": "packages/cli-bundle-api" + } +} diff --git a/packages/cli/src/commands/bundle/__mocks__/sign.js b/packages/cli-bundle-api/src/__mocks__/sign.js similarity index 100% rename from packages/cli/src/commands/bundle/__mocks__/sign.js rename to packages/cli-bundle-api/src/__mocks__/sign.js diff --git a/packages/cli/src/commands/bundle/__tests__/filterPlatformAssetScales-test.ts b/packages/cli-bundle-api/src/__tests__/filterPlatformAssetScales-test.ts similarity index 100% rename from packages/cli/src/commands/bundle/__tests__/filterPlatformAssetScales-test.ts rename to packages/cli-bundle-api/src/__tests__/filterPlatformAssetScales-test.ts diff --git a/packages/cli/src/commands/bundle/__tests__/getAssetDestPathAndroid-test.ts b/packages/cli-bundle-api/src/__tests__/getAssetDestPathAndroid-test.ts similarity index 100% rename from packages/cli/src/commands/bundle/__tests__/getAssetDestPathAndroid-test.ts rename to packages/cli-bundle-api/src/__tests__/getAssetDestPathAndroid-test.ts diff --git a/packages/cli/src/commands/bundle/__tests__/getAssetDestPathIOS-test.ts b/packages/cli-bundle-api/src/__tests__/getAssetDestPathIOS-test.ts similarity index 100% rename from packages/cli/src/commands/bundle/__tests__/getAssetDestPathIOS-test.ts rename to packages/cli-bundle-api/src/__tests__/getAssetDestPathIOS-test.ts diff --git a/packages/cli/src/commands/bundle/assetPathUtils.ts b/packages/cli-bundle-api/src/assetPathUtils.ts similarity index 100% rename from packages/cli/src/commands/bundle/assetPathUtils.ts rename to packages/cli-bundle-api/src/assetPathUtils.ts diff --git a/packages/cli/src/commands/bundle/buildBundle.ts b/packages/cli-bundle-api/src/buildBundle.ts similarity index 81% rename from packages/cli/src/commands/bundle/buildBundle.ts rename to packages/cli-bundle-api/src/buildBundle.ts index 63a7a440f..defc23939 100644 --- a/packages/cli/src/commands/bundle/buildBundle.ts +++ b/packages/cli-bundle-api/src/buildBundle.ts @@ -9,15 +9,34 @@ // @ts-ignore - no typed definition for the package import Server from 'metro/src/Server'; // @ts-ignore - no typed definition for the package -import outputBundle from 'metro/src/shared/output/bundle'; +const outputBundle = require('metro/src/shared/output/bundle'); import path from 'path'; import chalk from 'chalk'; -import {CommandLineArgs} from './bundleCommandLineArgs'; import {Config} from '@react-native-community/cli-types'; import saveAssets from './saveAssets'; -import loadMetroConfig from '../../tools/loadMetroConfig'; +import {load as loadMetroConfig} from '@react-native-community/metro-config'; import {logger} from '@react-native-community/cli-tools'; +export interface BundleArgs { + assetsDest?: string; + entryFile: string; + resetCache: boolean; + resetGlobalCache: boolean; + transformer?: string; + minify?: boolean; + config?: string; + platform: string; + dev: boolean; + bundleOutput: string; + bundleEncoding?: string; + maxWorkers?: number; + sourcemapOutput?: string; + sourcemapSourcesRoot?: string; + sourcemapUseAbsolutePath: boolean; + verbose: boolean; + unstableTransformProfile?: string; +} + interface RequestOptions { entryFile: string; sourceMapUrl: string | undefined; @@ -40,8 +59,8 @@ export interface AssetData { files: string[]; } -async function buildBundle( - args: CommandLineArgs, +export async function buildBundle( + args: BundleArgs, ctx: Config, output: typeof outputBundle = outputBundle, ) { @@ -106,5 +125,3 @@ async function buildBundle( server.end(); } } - -export default buildBundle; diff --git a/packages/cli/src/commands/bundle/filterPlatformAssetScales.ts b/packages/cli-bundle-api/src/filterPlatformAssetScales.ts similarity index 100% rename from packages/cli/src/commands/bundle/filterPlatformAssetScales.ts rename to packages/cli-bundle-api/src/filterPlatformAssetScales.ts diff --git a/packages/cli/src/commands/bundle/getAssetDestPathAndroid.ts b/packages/cli-bundle-api/src/getAssetDestPathAndroid.ts similarity index 100% rename from packages/cli/src/commands/bundle/getAssetDestPathAndroid.ts rename to packages/cli-bundle-api/src/getAssetDestPathAndroid.ts diff --git a/packages/cli/src/commands/bundle/getAssetDestPathIOS.ts b/packages/cli-bundle-api/src/getAssetDestPathIOS.ts similarity index 100% rename from packages/cli/src/commands/bundle/getAssetDestPathIOS.ts rename to packages/cli-bundle-api/src/getAssetDestPathIOS.ts diff --git a/packages/cli-bundle-api/src/index.ts b/packages/cli-bundle-api/src/index.ts new file mode 100644 index 000000000..6588a1fb6 --- /dev/null +++ b/packages/cli-bundle-api/src/index.ts @@ -0,0 +1 @@ +export * from './buildBundle'; diff --git a/packages/cli/src/commands/bundle/saveAssets.ts b/packages/cli-bundle-api/src/saveAssets.ts similarity index 100% rename from packages/cli/src/commands/bundle/saveAssets.ts rename to packages/cli-bundle-api/src/saveAssets.ts diff --git a/packages/cli-bundle-api/tsconfig.json b/packages/cli-bundle-api/tsconfig.json new file mode 100644 index 000000000..c984967ee --- /dev/null +++ b/packages/cli-bundle-api/tsconfig.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "build" + }, + "references": [ + {"path": "../metro-config"}, + {"path": "../tools"}, + ] +} diff --git a/packages/cli/package.json b/packages/cli/package.json index 5fefbd650..964bcb59c 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -26,9 +26,11 @@ "dependencies": { "@react-native-community/cli-debugger-ui": "^6.0.0-rc.0", "@react-native-community/cli-hermes": "^6.0.0-rc.0", + "@react-native-community/cli-bundle-api": "^6.0.0-rc.0", "@react-native-community/cli-server-api": "^6.0.0-rc.0", "@react-native-community/cli-tools": "^6.0.0-rc.0", "@react-native-community/cli-types": "^6.0.0-rc.0", + "@react-native-community/metro-config": "^6.0.0-rc.0", "appdirsjs": "^1.2.4", "chalk": "^3.0.0", "command-exists": "^1.2.8", diff --git a/packages/cli/src/commands/bundle/bundle.ts b/packages/cli/src/commands/bundle/bundle.ts index 95caa81bc..1f5f8ce8a 100644 --- a/packages/cli/src/commands/bundle/bundle.ts +++ b/packages/cli/src/commands/bundle/bundle.ts @@ -6,7 +6,7 @@ * */ import {Config} from '@react-native-community/cli-types'; -import buildBundle from './buildBundle'; +import {buildBundle} from '@react-native-community/cli-bundle-api'; import bundleCommandLineArgs, {CommandLineArgs} from './bundleCommandLineArgs'; /** diff --git a/packages/cli/src/commands/bundle/bundleCommandLineArgs.ts b/packages/cli/src/commands/bundle/bundleCommandLineArgs.ts index b559d098c..887515a21 100644 --- a/packages/cli/src/commands/bundle/bundleCommandLineArgs.ts +++ b/packages/cli/src/commands/bundle/bundleCommandLineArgs.ts @@ -7,26 +7,7 @@ */ import path from 'path'; - -export interface CommandLineArgs { - assetsDest?: string; - entryFile: string; - resetCache: boolean; - resetGlobalCache: boolean; - transformer?: string; - minify?: boolean; - config?: string; - platform: string; - dev: boolean; - bundleOutput: string; - bundleEncoding?: string; - maxWorkers?: number; - sourcemapOutput?: string; - sourcemapSourcesRoot?: string; - sourcemapUseAbsolutePath: boolean; - verbose: boolean; - unstableTransformProfile?: string; -} +export type {BundleArgs as CommandLineArgs} from '@react-native-community/cli-bundle-api'; export default [ { diff --git a/packages/cli/src/commands/start/runServer.ts b/packages/cli/src/commands/start/runServer.ts index a7acbbae6..2f490fd0c 100644 --- a/packages/cli/src/commands/start/runServer.ts +++ b/packages/cli/src/commands/start/runServer.ts @@ -16,7 +16,7 @@ import { } from '@react-native-community/cli-server-api'; import {Config} from '@react-native-community/cli-types'; -import loadMetroConfig from '../../tools/loadMetroConfig'; +import {load as loadMetroConfig} from '@react-native-community/metro-config'; import releaseChecker from '../../tools/releaseChecker'; import enableWatchMode from './watchMode'; diff --git a/packages/cli/tsconfig.json b/packages/cli/tsconfig.json index f3d42e37b..7fb7e84a7 100644 --- a/packages/cli/tsconfig.json +++ b/packages/cli/tsconfig.json @@ -8,7 +8,9 @@ {"path": "../tools"}, {"path": "../cli-types"}, {"path": "../debugger-ui"}, + {"path": "../cli-bundle-api"}, {"path": "../cli-server-api"}, - {"path": "../cli-hermes"} + {"path": "../cli-hermes"}, + {"path": "../metro-config"}, ] } diff --git a/packages/metro-config/package.json b/packages/metro-config/package.json new file mode 100644 index 000000000..0a27d7743 --- /dev/null +++ b/packages/metro-config/package.json @@ -0,0 +1,22 @@ +{ + "name": "@react-native-community/metro-config", + "version": "6.0.0-rc.0", + "license": "MIT", + "main": "build/index.js", + "publishConfig": { + "access": "public" + }, + "devDependencies": { + "@react-native-community/cli-types": "^6.0.0-rc.0" + }, + "files": [ + "build", + "!*.map" + ], + "homepage": "https://github.com/react-native-community/cli/tree/master/packages/metro-config", + "repository": { + "type": "git", + "url": "https://github.com/react-native-community/cli.git", + "directory": "packages/metro-config" + } +} diff --git a/packages/cli/src/tools/__tests__/loadMetroConfig-test.ts b/packages/metro-config/src/__tests__/loadMetroConfig-test.ts similarity index 95% rename from packages/cli/src/tools/__tests__/loadMetroConfig-test.ts rename to packages/metro-config/src/__tests__/loadMetroConfig-test.ts index 6658f711b..66dd75b0a 100644 --- a/packages/cli/src/tools/__tests__/loadMetroConfig-test.ts +++ b/packages/metro-config/src/__tests__/loadMetroConfig-test.ts @@ -8,6 +8,7 @@ describe('getDefaultConfig', () => { const config = getDefaultConfig({ root: '/', reactNativePath: '', + // @ts-ignore platforms: {}, }); diff --git a/packages/metro-config/src/index.ts b/packages/metro-config/src/index.ts new file mode 100644 index 000000000..8fe9e3ade --- /dev/null +++ b/packages/metro-config/src/index.ts @@ -0,0 +1,2 @@ +export * from './loadMetroConfig'; +export * from './metroPlatformResolver'; diff --git a/packages/cli/src/tools/loadMetroConfig.ts b/packages/metro-config/src/loadMetroConfig.ts similarity index 99% rename from packages/cli/src/tools/loadMetroConfig.ts rename to packages/metro-config/src/loadMetroConfig.ts index 2a67dd072..04adfa013 100644 --- a/packages/cli/src/tools/loadMetroConfig.ts +++ b/packages/metro-config/src/loadMetroConfig.ts @@ -141,7 +141,7 @@ export interface ConfigOptionsT { * * This allows the CLI to always overwrite the file settings. */ -export default function load( +export function load( ctx: ConfigLoadingContext, options?: ConfigOptionsT, ): Promise { diff --git a/packages/cli/src/tools/metroPlatformResolver.ts b/packages/metro-config/src/metroPlatformResolver.ts similarity index 100% rename from packages/cli/src/tools/metroPlatformResolver.ts rename to packages/metro-config/src/metroPlatformResolver.ts diff --git a/packages/metro-config/tsconfig.json b/packages/metro-config/tsconfig.json new file mode 100644 index 000000000..e8205804a --- /dev/null +++ b/packages/metro-config/tsconfig.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "build" + }, + "references": [ + {"path": "../cli-types"}, + {"path": "../tools"}, + ] +} From 76f019f1d406830d10e1e6366d1d3b25bd08a8c9 Mon Sep 17 00:00:00 2001 From: Adam Foxman Date: Thu, 15 Jul 2021 10:13:16 -0700 Subject: [PATCH 02/16] Rename metro-config package to metro --- packages/cli-bundle-api/package.json | 2 +- packages/cli-bundle-api/src/buildBundle.ts | 2 +- packages/cli-bundle-api/tsconfig.json | 2 +- packages/cli/package.json | 2 +- packages/cli/src/commands/start/runServer.ts | 2 +- packages/cli/tsconfig.json | 2 +- packages/{metro-config => metro}/package.json | 6 +++--- .../src/__tests__/loadMetroConfig-test.ts | 0 packages/{metro-config => metro}/src/index.ts | 0 packages/{metro-config => metro}/src/loadMetroConfig.ts | 0 .../{metro-config => metro}/src/metroPlatformResolver.ts | 0 packages/{metro-config => metro}/tsconfig.json | 0 12 files changed, 9 insertions(+), 9 deletions(-) rename packages/{metro-config => metro}/package.json (77%) rename packages/{metro-config => metro}/src/__tests__/loadMetroConfig-test.ts (100%) rename packages/{metro-config => metro}/src/index.ts (100%) rename packages/{metro-config => metro}/src/loadMetroConfig.ts (100%) rename packages/{metro-config => metro}/src/metroPlatformResolver.ts (100%) rename packages/{metro-config => metro}/tsconfig.json (100%) diff --git a/packages/cli-bundle-api/package.json b/packages/cli-bundle-api/package.json index e7fef14db..3a7ab0569 100644 --- a/packages/cli-bundle-api/package.json +++ b/packages/cli-bundle-api/package.json @@ -7,7 +7,7 @@ "access": "public" }, "dependencies": { - "@react-native-community/metro-config": "^6.0.0-rc.0" + "@react-native-community/metro": "^6.0.0-rc.0" }, "files": [ "build", diff --git a/packages/cli-bundle-api/src/buildBundle.ts b/packages/cli-bundle-api/src/buildBundle.ts index defc23939..7f9915ff4 100644 --- a/packages/cli-bundle-api/src/buildBundle.ts +++ b/packages/cli-bundle-api/src/buildBundle.ts @@ -14,7 +14,7 @@ import path from 'path'; import chalk from 'chalk'; import {Config} from '@react-native-community/cli-types'; import saveAssets from './saveAssets'; -import {load as loadMetroConfig} from '@react-native-community/metro-config'; +import {load as loadMetroConfig} from '@react-native-community/metro'; import {logger} from '@react-native-community/cli-tools'; export interface BundleArgs { diff --git a/packages/cli-bundle-api/tsconfig.json b/packages/cli-bundle-api/tsconfig.json index c984967ee..0b09dc299 100644 --- a/packages/cli-bundle-api/tsconfig.json +++ b/packages/cli-bundle-api/tsconfig.json @@ -5,7 +5,7 @@ "outDir": "build" }, "references": [ - {"path": "../metro-config"}, + {"path": "../metro"}, {"path": "../tools"}, ] } diff --git a/packages/cli/package.json b/packages/cli/package.json index 964bcb59c..b1db19d3a 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -30,7 +30,7 @@ "@react-native-community/cli-server-api": "^6.0.0-rc.0", "@react-native-community/cli-tools": "^6.0.0-rc.0", "@react-native-community/cli-types": "^6.0.0-rc.0", - "@react-native-community/metro-config": "^6.0.0-rc.0", + "@react-native-community/metro": "^6.0.0-rc.0", "appdirsjs": "^1.2.4", "chalk": "^3.0.0", "command-exists": "^1.2.8", diff --git a/packages/cli/src/commands/start/runServer.ts b/packages/cli/src/commands/start/runServer.ts index 2f490fd0c..9ba40f994 100644 --- a/packages/cli/src/commands/start/runServer.ts +++ b/packages/cli/src/commands/start/runServer.ts @@ -16,7 +16,7 @@ import { } from '@react-native-community/cli-server-api'; import {Config} from '@react-native-community/cli-types'; -import {load as loadMetroConfig} from '@react-native-community/metro-config'; +import {load as loadMetroConfig} from '@react-native-community/metro'; import releaseChecker from '../../tools/releaseChecker'; import enableWatchMode from './watchMode'; diff --git a/packages/cli/tsconfig.json b/packages/cli/tsconfig.json index 7fb7e84a7..b6baa8571 100644 --- a/packages/cli/tsconfig.json +++ b/packages/cli/tsconfig.json @@ -11,6 +11,6 @@ {"path": "../cli-bundle-api"}, {"path": "../cli-server-api"}, {"path": "../cli-hermes"}, - {"path": "../metro-config"}, + {"path": "../metro"}, ] } diff --git a/packages/metro-config/package.json b/packages/metro/package.json similarity index 77% rename from packages/metro-config/package.json rename to packages/metro/package.json index 0a27d7743..79ea99bff 100644 --- a/packages/metro-config/package.json +++ b/packages/metro/package.json @@ -1,5 +1,5 @@ { - "name": "@react-native-community/metro-config", + "name": "@react-native-community/metro", "version": "6.0.0-rc.0", "license": "MIT", "main": "build/index.js", @@ -13,10 +13,10 @@ "build", "!*.map" ], - "homepage": "https://github.com/react-native-community/cli/tree/master/packages/metro-config", + "homepage": "https://github.com/react-native-community/cli/tree/master/packages/metro", "repository": { "type": "git", "url": "https://github.com/react-native-community/cli.git", - "directory": "packages/metro-config" + "directory": "packages/metro" } } diff --git a/packages/metro-config/src/__tests__/loadMetroConfig-test.ts b/packages/metro/src/__tests__/loadMetroConfig-test.ts similarity index 100% rename from packages/metro-config/src/__tests__/loadMetroConfig-test.ts rename to packages/metro/src/__tests__/loadMetroConfig-test.ts diff --git a/packages/metro-config/src/index.ts b/packages/metro/src/index.ts similarity index 100% rename from packages/metro-config/src/index.ts rename to packages/metro/src/index.ts diff --git a/packages/metro-config/src/loadMetroConfig.ts b/packages/metro/src/loadMetroConfig.ts similarity index 100% rename from packages/metro-config/src/loadMetroConfig.ts rename to packages/metro/src/loadMetroConfig.ts diff --git a/packages/metro-config/src/metroPlatformResolver.ts b/packages/metro/src/metroPlatformResolver.ts similarity index 100% rename from packages/metro-config/src/metroPlatformResolver.ts rename to packages/metro/src/metroPlatformResolver.ts diff --git a/packages/metro-config/tsconfig.json b/packages/metro/tsconfig.json similarity index 100% rename from packages/metro-config/tsconfig.json rename to packages/metro/tsconfig.json From e55648c0d9b7d9e264fca4abf9638d119fafbaff Mon Sep 17 00:00:00 2001 From: Adam Foxman Date: Thu, 15 Jul 2021 23:09:02 -0700 Subject: [PATCH 03/16] Move cli-bundle-api package and bundle command (cli package) into metro. --- packages/cli-bundle-api/package.json | 22 --------------- packages/cli-bundle-api/src/index.ts | 1 - packages/cli-bundle-api/tsconfig.json | 11 -------- packages/cli/package.json | 7 ----- packages/cli/src/commands/index.ts | 3 +-- packages/cli/src/commands/start/runServer.ts | 2 +- packages/cli/tsconfig.json | 1 - packages/metro/package.json | 9 +++++++ .../src/bundle}/__mocks__/sign.js | 0 .../filterPlatformAssetScales-test.ts | 0 .../__tests__/getAssetDestPathAndroid-test.ts | 0 .../__tests__/getAssetDestPathIOS-test.ts | 0 .../src/bundle}/assetPathUtils.ts | 0 .../src => metro/src/bundle}/buildBundle.ts | 27 +++---------------- .../commands => metro/src}/bundle/bundle.ts | 6 ++--- .../src}/bundle/bundleCommandLineArgs.ts | 21 ++++++++++++++- .../src/bundle}/filterPlatformAssetScales.ts | 0 .../src/bundle}/getAssetDestPathAndroid.ts | 0 .../src/bundle}/getAssetDestPathIOS.ts | 0 packages/metro/src/bundle/index.ts | 4 +++ .../src}/bundle/ramBundle.ts | 12 ++++++--- .../src => metro/src/bundle}/saveAssets.ts | 0 .../__tests__/loadMetroConfig-test.ts | 0 packages/metro/src/config/index.ts | 1 + .../metro/src/{ => config}/loadMetroConfig.ts | 8 +++--- .../src/{ => config}/metroPlatformResolver.ts | 0 packages/metro/src/index.ts | 4 +-- 27 files changed, 58 insertions(+), 81 deletions(-) delete mode 100644 packages/cli-bundle-api/package.json delete mode 100644 packages/cli-bundle-api/src/index.ts delete mode 100644 packages/cli-bundle-api/tsconfig.json rename packages/{cli-bundle-api/src => metro/src/bundle}/__mocks__/sign.js (100%) rename packages/{cli-bundle-api/src => metro/src/bundle}/__tests__/filterPlatformAssetScales-test.ts (100%) rename packages/{cli-bundle-api/src => metro/src/bundle}/__tests__/getAssetDestPathAndroid-test.ts (100%) rename packages/{cli-bundle-api/src => metro/src/bundle}/__tests__/getAssetDestPathIOS-test.ts (100%) rename packages/{cli-bundle-api/src => metro/src/bundle}/assetPathUtils.ts (100%) rename packages/{cli-bundle-api/src => metro/src/bundle}/buildBundle.ts (82%) rename packages/{cli/src/commands => metro/src}/bundle/bundle.ts (85%) rename packages/{cli/src/commands => metro/src}/bundle/bundleCommandLineArgs.ts (86%) rename packages/{cli-bundle-api/src => metro/src/bundle}/filterPlatformAssetScales.ts (100%) rename packages/{cli-bundle-api/src => metro/src/bundle}/getAssetDestPathAndroid.ts (100%) rename packages/{cli-bundle-api/src => metro/src/bundle}/getAssetDestPathIOS.ts (100%) create mode 100644 packages/metro/src/bundle/index.ts rename packages/{cli/src/commands => metro/src}/bundle/ramBundle.ts (81%) rename packages/{cli-bundle-api/src => metro/src/bundle}/saveAssets.ts (100%) rename packages/metro/src/{ => config}/__tests__/loadMetroConfig-test.ts (100%) create mode 100644 packages/metro/src/config/index.ts rename packages/metro/src/{ => config}/loadMetroConfig.ts (96%) rename packages/metro/src/{ => config}/metroPlatformResolver.ts (100%) diff --git a/packages/cli-bundle-api/package.json b/packages/cli-bundle-api/package.json deleted file mode 100644 index 3a7ab0569..000000000 --- a/packages/cli-bundle-api/package.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "name": "@react-native-community/cli-bundle-api", - "version": "6.0.0-rc.0", - "license": "MIT", - "main": "build/index.js", - "publishConfig": { - "access": "public" - }, - "dependencies": { - "@react-native-community/metro": "^6.0.0-rc.0" - }, - "files": [ - "build", - "!*.map" - ], - "homepage": "https://github.com/react-native-community/cli/tree/master/packages/cli-bundle-api", - "repository": { - "type": "git", - "url": "https://github.com/react-native-community/cli.git", - "directory": "packages/cli-bundle-api" - } -} diff --git a/packages/cli-bundle-api/src/index.ts b/packages/cli-bundle-api/src/index.ts deleted file mode 100644 index 6588a1fb6..000000000 --- a/packages/cli-bundle-api/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './buildBundle'; diff --git a/packages/cli-bundle-api/tsconfig.json b/packages/cli-bundle-api/tsconfig.json deleted file mode 100644 index 0b09dc299..000000000 --- a/packages/cli-bundle-api/tsconfig.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "extends": "../../tsconfig.json", - "compilerOptions": { - "rootDir": "src", - "outDir": "build" - }, - "references": [ - {"path": "../metro"}, - {"path": "../tools"}, - ] -} diff --git a/packages/cli/package.json b/packages/cli/package.json index b1db19d3a..2ce177dd9 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -26,7 +26,6 @@ "dependencies": { "@react-native-community/cli-debugger-ui": "^6.0.0-rc.0", "@react-native-community/cli-hermes": "^6.0.0-rc.0", - "@react-native-community/cli-bundle-api": "^6.0.0-rc.0", "@react-native-community/cli-server-api": "^6.0.0-rc.0", "@react-native-community/cli-tools": "^6.0.0-rc.0", "@react-native-community/cli-types": "^6.0.0-rc.0", @@ -46,12 +45,6 @@ "joi": "^17.2.1", "leven": "^3.1.0", "lodash": "^4.17.15", - "metro": "^0.66.1", - "metro-config": "^0.66.1", - "metro-core": "^0.66.1", - "metro-react-native-babel-transformer": "^0.66.1", - "metro-resolver": "^0.66.1", - "metro-runtime": "^0.66.1", "minimist": "^1.2.0", "mkdirp": "^0.5.1", "node-stream-zip": "^1.9.1", diff --git a/packages/cli/src/commands/index.ts b/packages/cli/src/commands/index.ts index 9255335de..20befb31c 100644 --- a/packages/cli/src/commands/index.ts +++ b/packages/cli/src/commands/index.ts @@ -1,7 +1,6 @@ import {Command, DetachedCommand} from '@react-native-community/cli-types'; import start from './start/start'; -import bundle from './bundle/bundle'; -import ramBundle from './bundle/ramBundle'; +import {bundle, ramBundle} from '@react-native-community/metro'; import link from './link/link'; import unlink from './link/unlink'; import install from './install/install'; diff --git a/packages/cli/src/commands/start/runServer.ts b/packages/cli/src/commands/start/runServer.ts index 9ba40f994..a161f08d7 100644 --- a/packages/cli/src/commands/start/runServer.ts +++ b/packages/cli/src/commands/start/runServer.ts @@ -16,7 +16,7 @@ import { } from '@react-native-community/cli-server-api'; import {Config} from '@react-native-community/cli-types'; -import {load as loadMetroConfig} from '@react-native-community/metro'; +import {loadMetroConfig} from '@react-native-community/metro'; import releaseChecker from '../../tools/releaseChecker'; import enableWatchMode from './watchMode'; diff --git a/packages/cli/tsconfig.json b/packages/cli/tsconfig.json index b6baa8571..7532e5f7d 100644 --- a/packages/cli/tsconfig.json +++ b/packages/cli/tsconfig.json @@ -8,7 +8,6 @@ {"path": "../tools"}, {"path": "../cli-types"}, {"path": "../debugger-ui"}, - {"path": "../cli-bundle-api"}, {"path": "../cli-server-api"}, {"path": "../cli-hermes"}, {"path": "../metro"}, diff --git a/packages/metro/package.json b/packages/metro/package.json index 79ea99bff..15cfe4ac7 100644 --- a/packages/metro/package.json +++ b/packages/metro/package.json @@ -6,6 +6,15 @@ "publishConfig": { "access": "public" }, + "dependencies": { + "@react-native-community/cli-tools": "^6.0.0-rc.0", + "metro": "^0.66.1", + "metro-config": "^0.66.1", + "metro-core": "^0.66.1", + "metro-react-native-babel-transformer": "^0.66.1", + "metro-resolver": "^0.66.1", + "metro-runtime": "^0.66.1" + }, "devDependencies": { "@react-native-community/cli-types": "^6.0.0-rc.0" }, diff --git a/packages/cli-bundle-api/src/__mocks__/sign.js b/packages/metro/src/bundle/__mocks__/sign.js similarity index 100% rename from packages/cli-bundle-api/src/__mocks__/sign.js rename to packages/metro/src/bundle/__mocks__/sign.js diff --git a/packages/cli-bundle-api/src/__tests__/filterPlatformAssetScales-test.ts b/packages/metro/src/bundle/__tests__/filterPlatformAssetScales-test.ts similarity index 100% rename from packages/cli-bundle-api/src/__tests__/filterPlatformAssetScales-test.ts rename to packages/metro/src/bundle/__tests__/filterPlatformAssetScales-test.ts diff --git a/packages/cli-bundle-api/src/__tests__/getAssetDestPathAndroid-test.ts b/packages/metro/src/bundle/__tests__/getAssetDestPathAndroid-test.ts similarity index 100% rename from packages/cli-bundle-api/src/__tests__/getAssetDestPathAndroid-test.ts rename to packages/metro/src/bundle/__tests__/getAssetDestPathAndroid-test.ts diff --git a/packages/cli-bundle-api/src/__tests__/getAssetDestPathIOS-test.ts b/packages/metro/src/bundle/__tests__/getAssetDestPathIOS-test.ts similarity index 100% rename from packages/cli-bundle-api/src/__tests__/getAssetDestPathIOS-test.ts rename to packages/metro/src/bundle/__tests__/getAssetDestPathIOS-test.ts diff --git a/packages/cli-bundle-api/src/assetPathUtils.ts b/packages/metro/src/bundle/assetPathUtils.ts similarity index 100% rename from packages/cli-bundle-api/src/assetPathUtils.ts rename to packages/metro/src/bundle/assetPathUtils.ts diff --git a/packages/cli-bundle-api/src/buildBundle.ts b/packages/metro/src/bundle/buildBundle.ts similarity index 82% rename from packages/cli-bundle-api/src/buildBundle.ts rename to packages/metro/src/bundle/buildBundle.ts index 7f9915ff4..4418c370f 100644 --- a/packages/cli-bundle-api/src/buildBundle.ts +++ b/packages/metro/src/bundle/buildBundle.ts @@ -12,31 +12,12 @@ import Server from 'metro/src/Server'; const outputBundle = require('metro/src/shared/output/bundle'); import path from 'path'; import chalk from 'chalk'; -import {Config} from '@react-native-community/cli-types'; +import {CommandLineArgs} from './bundleCommandLineArgs'; +import type {Config} from '@react-native-community/cli-types'; import saveAssets from './saveAssets'; -import {load as loadMetroConfig} from '@react-native-community/metro'; +import {loadMetroConfig} from '../config'; import {logger} from '@react-native-community/cli-tools'; -export interface BundleArgs { - assetsDest?: string; - entryFile: string; - resetCache: boolean; - resetGlobalCache: boolean; - transformer?: string; - minify?: boolean; - config?: string; - platform: string; - dev: boolean; - bundleOutput: string; - bundleEncoding?: string; - maxWorkers?: number; - sourcemapOutput?: string; - sourcemapSourcesRoot?: string; - sourcemapUseAbsolutePath: boolean; - verbose: boolean; - unstableTransformProfile?: string; -} - interface RequestOptions { entryFile: string; sourceMapUrl: string | undefined; @@ -60,7 +41,7 @@ export interface AssetData { } export async function buildBundle( - args: BundleArgs, + args: CommandLineArgs, ctx: Config, output: typeof outputBundle = outputBundle, ) { diff --git a/packages/cli/src/commands/bundle/bundle.ts b/packages/metro/src/bundle/bundle.ts similarity index 85% rename from packages/cli/src/commands/bundle/bundle.ts rename to packages/metro/src/bundle/bundle.ts index 1f5f8ce8a..4c68a8dec 100644 --- a/packages/cli/src/commands/bundle/bundle.ts +++ b/packages/metro/src/bundle/bundle.ts @@ -5,8 +5,8 @@ * LICENSE file in the root directory of this source tree. * */ -import {Config} from '@react-native-community/cli-types'; -import {buildBundle} from '@react-native-community/cli-bundle-api'; +import type {Config} from '@react-native-community/cli-types'; +import {buildBundle} from './buildBundle'; import bundleCommandLineArgs, {CommandLineArgs} from './bundleCommandLineArgs'; /** @@ -21,7 +21,7 @@ function bundleWithOutput( return buildBundle(args, config, output); } -export default { +export const bundle = { name: 'bundle', description: 'builds the javascript bundle for offline use', func: bundleWithOutput, diff --git a/packages/cli/src/commands/bundle/bundleCommandLineArgs.ts b/packages/metro/src/bundle/bundleCommandLineArgs.ts similarity index 86% rename from packages/cli/src/commands/bundle/bundleCommandLineArgs.ts rename to packages/metro/src/bundle/bundleCommandLineArgs.ts index 887515a21..b559d098c 100644 --- a/packages/cli/src/commands/bundle/bundleCommandLineArgs.ts +++ b/packages/metro/src/bundle/bundleCommandLineArgs.ts @@ -7,7 +7,26 @@ */ import path from 'path'; -export type {BundleArgs as CommandLineArgs} from '@react-native-community/cli-bundle-api'; + +export interface CommandLineArgs { + assetsDest?: string; + entryFile: string; + resetCache: boolean; + resetGlobalCache: boolean; + transformer?: string; + minify?: boolean; + config?: string; + platform: string; + dev: boolean; + bundleOutput: string; + bundleEncoding?: string; + maxWorkers?: number; + sourcemapOutput?: string; + sourcemapSourcesRoot?: string; + sourcemapUseAbsolutePath: boolean; + verbose: boolean; + unstableTransformProfile?: string; +} export default [ { diff --git a/packages/cli-bundle-api/src/filterPlatformAssetScales.ts b/packages/metro/src/bundle/filterPlatformAssetScales.ts similarity index 100% rename from packages/cli-bundle-api/src/filterPlatformAssetScales.ts rename to packages/metro/src/bundle/filterPlatformAssetScales.ts diff --git a/packages/cli-bundle-api/src/getAssetDestPathAndroid.ts b/packages/metro/src/bundle/getAssetDestPathAndroid.ts similarity index 100% rename from packages/cli-bundle-api/src/getAssetDestPathAndroid.ts rename to packages/metro/src/bundle/getAssetDestPathAndroid.ts diff --git a/packages/cli-bundle-api/src/getAssetDestPathIOS.ts b/packages/metro/src/bundle/getAssetDestPathIOS.ts similarity index 100% rename from packages/cli-bundle-api/src/getAssetDestPathIOS.ts rename to packages/metro/src/bundle/getAssetDestPathIOS.ts diff --git a/packages/metro/src/bundle/index.ts b/packages/metro/src/bundle/index.ts new file mode 100644 index 000000000..c14bb0b42 --- /dev/null +++ b/packages/metro/src/bundle/index.ts @@ -0,0 +1,4 @@ +export {bundle} from './bundle'; +export {ramBundle} from './ramBundle'; +export * from './buildBundle'; +export type {CommandLineArgs} from './bundleCommandLineArgs'; diff --git a/packages/cli/src/commands/bundle/ramBundle.ts b/packages/metro/src/bundle/ramBundle.ts similarity index 81% rename from packages/cli/src/commands/bundle/ramBundle.ts rename to packages/metro/src/bundle/ramBundle.ts index 0f91f24d8..b9d8dfe64 100644 --- a/packages/cli/src/commands/bundle/ramBundle.ts +++ b/packages/metro/src/bundle/ramBundle.ts @@ -9,20 +9,24 @@ import outputUnbundle from 'metro/src/shared/output/RamBundle'; import {withOutput as bundleWithOutput} from './bundle'; import bundleCommandLineArgs, {CommandLineArgs} from './bundleCommandLineArgs'; -import {Config} from '@react-native-community/cli-types'; +import type {Config} from '@react-native-community/cli-types'; /** * Builds the bundle starting to look for dependencies at the given entry path. */ -function ramBundle(argv: Array, config: Config, args: CommandLineArgs) { +function createRamBundle( + argv: Array, + config: Config, + args: CommandLineArgs, +) { return bundleWithOutput(argv, config, args, outputUnbundle); } -export default { +export const ramBundle = { name: 'ram-bundle', description: 'builds javascript as a "Random Access Module" bundle for offline use', - func: ramBundle, + func: createRamBundle, options: bundleCommandLineArgs.concat({ name: '--indexed-ram-bundle', description: diff --git a/packages/cli-bundle-api/src/saveAssets.ts b/packages/metro/src/bundle/saveAssets.ts similarity index 100% rename from packages/cli-bundle-api/src/saveAssets.ts rename to packages/metro/src/bundle/saveAssets.ts diff --git a/packages/metro/src/__tests__/loadMetroConfig-test.ts b/packages/metro/src/config/__tests__/loadMetroConfig-test.ts similarity index 100% rename from packages/metro/src/__tests__/loadMetroConfig-test.ts rename to packages/metro/src/config/__tests__/loadMetroConfig-test.ts diff --git a/packages/metro/src/config/index.ts b/packages/metro/src/config/index.ts new file mode 100644 index 000000000..84ada3284 --- /dev/null +++ b/packages/metro/src/config/index.ts @@ -0,0 +1 @@ +export * from './loadMetroConfig'; diff --git a/packages/metro/src/loadMetroConfig.ts b/packages/metro/src/config/loadMetroConfig.ts similarity index 96% rename from packages/metro/src/loadMetroConfig.ts rename to packages/metro/src/config/loadMetroConfig.ts index 04adfa013..992106f2b 100644 --- a/packages/metro/src/loadMetroConfig.ts +++ b/packages/metro/src/config/loadMetroConfig.ts @@ -4,7 +4,7 @@ import path from 'path'; // @ts-ignore - no typed definition for the package import {loadConfig} from 'metro-config'; -import {Config} from '@react-native-community/cli-types'; +import type {Config} from '@react-native-community/cli-types'; import {reactNativePlatformResolver} from './metroPlatformResolver'; const INTERNAL_CALLSITES_REGEX = new RegExp( @@ -20,7 +20,9 @@ const INTERNAL_CALLSITES_REGEX = new RegExp( ].join('|'), ); -type ConfigLoadingContext = Pick< +export type {Config}; + +export type ConfigLoadingContext = Pick< Config, 'root' | 'reactNativePath' | 'platforms' >; @@ -141,7 +143,7 @@ export interface ConfigOptionsT { * * This allows the CLI to always overwrite the file settings. */ -export function load( +export function loadMetroConfig( ctx: ConfigLoadingContext, options?: ConfigOptionsT, ): Promise { diff --git a/packages/metro/src/metroPlatformResolver.ts b/packages/metro/src/config/metroPlatformResolver.ts similarity index 100% rename from packages/metro/src/metroPlatformResolver.ts rename to packages/metro/src/config/metroPlatformResolver.ts diff --git a/packages/metro/src/index.ts b/packages/metro/src/index.ts index 8fe9e3ade..1f74f5a94 100644 --- a/packages/metro/src/index.ts +++ b/packages/metro/src/index.ts @@ -1,2 +1,2 @@ -export * from './loadMetroConfig'; -export * from './metroPlatformResolver'; +export * from './bundle'; +export * from './config'; From 3fa4c4db0882c968ab9cd5b5785a50e48190374b Mon Sep 17 00:00:00 2001 From: Adam Foxman Date: Thu, 15 Jul 2021 23:34:48 -0700 Subject: [PATCH 04/16] Move resolveNodeModuleDir to cli-tools package --- .../config/__tests__/findDependencies-test.ts | 2 -- .../src/tools/config/resolveNodeModuleDir.ts | 17 ++--------------- packages/tools/src/index.ts | 1 + packages/tools/src/resolveNodeModuleDir.ts | 15 +++++++++++++++ 4 files changed, 18 insertions(+), 17 deletions(-) create mode 100644 packages/tools/src/resolveNodeModuleDir.ts diff --git a/packages/cli/src/tools/config/__tests__/findDependencies-test.ts b/packages/cli/src/tools/config/__tests__/findDependencies-test.ts index 27b10bdb0..084ee49d7 100644 --- a/packages/cli/src/tools/config/__tests__/findDependencies-test.ts +++ b/packages/cli/src/tools/config/__tests__/findDependencies-test.ts @@ -5,8 +5,6 @@ import { getTempDirectory, } from '../../../../../../jest/helpers'; -jest.mock('../resolveNodeModuleDir'); - beforeEach(async () => { await cleanup(DIR); jest.resetModules(); diff --git a/packages/cli/src/tools/config/resolveNodeModuleDir.ts b/packages/cli/src/tools/config/resolveNodeModuleDir.ts index 7a03950cd..68fd4fbfa 100644 --- a/packages/cli/src/tools/config/resolveNodeModuleDir.ts +++ b/packages/cli/src/tools/config/resolveNodeModuleDir.ts @@ -1,15 +1,2 @@ -import path from 'path'; - -/** - * Finds a path inside `node_modules` - */ -export default function resolveNodeModuleDir( - root: string, - packageName: string, -): string { - return path.dirname( - require.resolve(path.join(packageName, 'package.json'), { - paths: [root], - }), - ); -} +import {resolveNodeModuleDir} from '@react-native-community/cli-tools'; +export default resolveNodeModuleDir; diff --git a/packages/tools/src/index.ts b/packages/tools/src/index.ts index 7c5c9dfe6..e3770abd5 100644 --- a/packages/tools/src/index.ts +++ b/packages/tools/src/index.ts @@ -6,5 +6,6 @@ export {fetch, fetchToTemp} from './fetch'; export {default as launchDefaultBrowser} from './launchDefaultBrowser'; export {default as launchDebugger} from './launchDebugger'; export {default as launchEditor} from './launchEditor'; +export {default as resolveNodeModuleDir} from './resolveNodeModuleDir'; export * from './errors'; diff --git a/packages/tools/src/resolveNodeModuleDir.ts b/packages/tools/src/resolveNodeModuleDir.ts new file mode 100644 index 000000000..7a03950cd --- /dev/null +++ b/packages/tools/src/resolveNodeModuleDir.ts @@ -0,0 +1,15 @@ +import path from 'path'; + +/** + * Finds a path inside `node_modules` + */ +export default function resolveNodeModuleDir( + root: string, + packageName: string, +): string { + return path.dirname( + require.resolve(path.join(packageName, 'package.json'), { + paths: [root], + }), + ); +} From 4db4e31e6f35cde676efeed10f66c6f4f2b5781e Mon Sep 17 00:00:00 2001 From: Adam Foxman Date: Thu, 15 Jul 2021 23:48:50 -0700 Subject: [PATCH 05/16] Move releaseChecker into cli-tools --- packages/cli/src/commands/info/info.ts | 3 +-- packages/cli/src/commands/start/runServer.ts | 2 +- packages/tools/package.json | 5 ++++- packages/tools/src/index.ts | 1 + .../tools => tools/src}/releaseChecker/getLatestRelease.ts | 3 ++- .../{cli/src/tools => tools/src}/releaseChecker/index.ts | 4 ++-- .../tools => tools/src}/releaseChecker/printNewRelease.ts | 2 +- .../src}/releaseChecker/releaseCacheManager.ts | 2 +- 8 files changed, 13 insertions(+), 9 deletions(-) rename packages/{cli/src/tools => tools/src}/releaseChecker/getLatestRelease.ts (98%) rename packages/{cli/src/tools => tools/src}/releaseChecker/index.ts (87%) rename packages/{cli/src/tools => tools/src}/releaseChecker/printNewRelease.ts (92%) rename packages/{cli/src/tools => tools/src}/releaseChecker/releaseCacheManager.ts (96%) diff --git a/packages/cli/src/commands/info/info.ts b/packages/cli/src/commands/info/info.ts index fedc47863..b2999fca3 100644 --- a/packages/cli/src/commands/info/info.ts +++ b/packages/cli/src/commands/info/info.ts @@ -7,9 +7,8 @@ // @ts-ignore untyped import getEnvironmentInfo from '../../tools/envinfo'; -import {logger} from '@react-native-community/cli-tools'; +import {logger, releaseChecker} from '@react-native-community/cli-tools'; import {Config} from '@react-native-community/cli-types'; -import releaseChecker from '../../tools/releaseChecker'; const info = async function getInfo(_argv: Array, ctx: Config) { try { diff --git a/packages/cli/src/commands/start/runServer.ts b/packages/cli/src/commands/start/runServer.ts index a161f08d7..fcc95e5ab 100644 --- a/packages/cli/src/commands/start/runServer.ts +++ b/packages/cli/src/commands/start/runServer.ts @@ -17,7 +17,7 @@ import { import {Config} from '@react-native-community/cli-types'; import {loadMetroConfig} from '@react-native-community/metro'; -import releaseChecker from '../../tools/releaseChecker'; +import {releaseChecker} from '@react-native-community/cli-tools'; import enableWatchMode from './watchMode'; export type Args = { diff --git a/packages/tools/package.json b/packages/tools/package.json index b603f21d0..7429f18bc 100644 --- a/packages/tools/package.json +++ b/packages/tools/package.json @@ -7,12 +7,15 @@ "access": "public" }, "dependencies": { + "appdirsjs": "^1.2.4", "chalk": "^3.0.0", "lodash": "^4.17.15", + "mkdirp": "^0.5.1", "mime": "^2.4.1", "node-fetch": "^2.6.0", "open": "^6.2.0", - "shell-quote": "1.6.1" + "shell-quote": "1.6.1", + "semver": "^6.3.0" }, "devDependencies": { "@types/lodash": "^4.14.149", diff --git a/packages/tools/src/index.ts b/packages/tools/src/index.ts index e3770abd5..5c6eb8c50 100644 --- a/packages/tools/src/index.ts +++ b/packages/tools/src/index.ts @@ -6,6 +6,7 @@ export {fetch, fetchToTemp} from './fetch'; export {default as launchDefaultBrowser} from './launchDefaultBrowser'; export {default as launchDebugger} from './launchDebugger'; export {default as launchEditor} from './launchEditor'; +export {default as releaseChecker} from './releaseChecker'; export {default as resolveNodeModuleDir} from './resolveNodeModuleDir'; export * from './errors'; diff --git a/packages/cli/src/tools/releaseChecker/getLatestRelease.ts b/packages/tools/src/releaseChecker/getLatestRelease.ts similarity index 98% rename from packages/cli/src/tools/releaseChecker/getLatestRelease.ts rename to packages/tools/src/releaseChecker/getLatestRelease.ts index 2db89f7a6..b1f27c879 100644 --- a/packages/cli/src/tools/releaseChecker/getLatestRelease.ts +++ b/packages/tools/src/releaseChecker/getLatestRelease.ts @@ -1,6 +1,7 @@ import semver from 'semver'; import cacheManager from './releaseCacheManager'; -import {fetch, logger} from '@react-native-community/cli-tools'; +import {fetch} from '../fetch'; +import logger from '../logger'; export type Release = { version: string; diff --git a/packages/cli/src/tools/releaseChecker/index.ts b/packages/tools/src/releaseChecker/index.ts similarity index 87% rename from packages/cli/src/tools/releaseChecker/index.ts rename to packages/tools/src/releaseChecker/index.ts index 951377830..31ab752d1 100644 --- a/packages/cli/src/tools/releaseChecker/index.ts +++ b/packages/tools/src/releaseChecker/index.ts @@ -1,7 +1,7 @@ import path from 'path'; -import {logger} from '@react-native-community/cli-tools'; +import logger from '../logger'; // @ts-ignore - JS file -import resolveNodeModuleDir from '../config/resolveNodeModuleDir'; +import resolveNodeModuleDir from '../resolveNodeModuleDir'; import getLatestRelease from './getLatestRelease'; import printNewRelease from './printNewRelease'; diff --git a/packages/cli/src/tools/releaseChecker/printNewRelease.ts b/packages/tools/src/releaseChecker/printNewRelease.ts similarity index 92% rename from packages/cli/src/tools/releaseChecker/printNewRelease.ts rename to packages/tools/src/releaseChecker/printNewRelease.ts index 456724f92..56470d88d 100644 --- a/packages/cli/src/tools/releaseChecker/printNewRelease.ts +++ b/packages/tools/src/releaseChecker/printNewRelease.ts @@ -1,5 +1,5 @@ import chalk from 'chalk'; -import {logger} from '@react-native-community/cli-tools'; +import logger from '../logger'; import {Release} from './getLatestRelease'; import cacheManager from './releaseCacheManager'; diff --git a/packages/cli/src/tools/releaseChecker/releaseCacheManager.ts b/packages/tools/src/releaseChecker/releaseCacheManager.ts similarity index 96% rename from packages/cli/src/tools/releaseChecker/releaseCacheManager.ts rename to packages/tools/src/releaseChecker/releaseCacheManager.ts index 9384aff66..5cca60d67 100644 --- a/packages/cli/src/tools/releaseChecker/releaseCacheManager.ts +++ b/packages/tools/src/releaseChecker/releaseCacheManager.ts @@ -3,7 +3,7 @@ import fs from 'fs'; import os from 'os'; import appDirs from 'appdirsjs'; import mkdirp from 'mkdirp'; -import {logger} from '@react-native-community/cli-tools'; +import logger from '../logger'; type ReleaseCacheKey = 'eTag' | 'lastChecked' | 'latestVersion'; type Cache = {[key in ReleaseCacheKey]?: string}; From 1f359effb1a5a3274382111fca8cc4b1102733d9 Mon Sep 17 00:00:00 2001 From: Adam Foxman Date: Thu, 15 Jul 2021 23:54:10 -0700 Subject: [PATCH 06/16] Move hookStdout to cli-tools --- packages/cli/src/commands/start/watchMode.ts | 3 +-- packages/{cli/src/tools => tools/src}/hookStdout.ts | 0 packages/tools/src/index.ts | 1 + 3 files changed, 2 insertions(+), 2 deletions(-) rename packages/{cli/src/tools => tools/src}/hookStdout.ts (100%) diff --git a/packages/cli/src/commands/start/watchMode.ts b/packages/cli/src/commands/start/watchMode.ts index 768028cb2..2920c55fd 100644 --- a/packages/cli/src/commands/start/watchMode.ts +++ b/packages/cli/src/commands/start/watchMode.ts @@ -1,6 +1,5 @@ import readline from 'readline'; -import hookStdout from '../../tools/hookStdout'; -import {logger} from '@react-native-community/cli-tools'; +import {logger, hookStdout} from '@react-native-community/cli-tools'; function printWatchModeInstructions() { logger.log( diff --git a/packages/cli/src/tools/hookStdout.ts b/packages/tools/src/hookStdout.ts similarity index 100% rename from packages/cli/src/tools/hookStdout.ts rename to packages/tools/src/hookStdout.ts diff --git a/packages/tools/src/index.ts b/packages/tools/src/index.ts index 5c6eb8c50..545aab8c6 100644 --- a/packages/tools/src/index.ts +++ b/packages/tools/src/index.ts @@ -8,5 +8,6 @@ export {default as launchDebugger} from './launchDebugger'; export {default as launchEditor} from './launchEditor'; export {default as releaseChecker} from './releaseChecker'; export {default as resolveNodeModuleDir} from './resolveNodeModuleDir'; +export {default as hookStdout} from './hookStdout'; export * from './errors'; From e1da75c3ff1d319e8148f5142cc53d1181bdf442 Mon Sep 17 00:00:00 2001 From: Adam Foxman Date: Fri, 16 Jul 2021 00:04:27 -0700 Subject: [PATCH 07/16] Move start command into metro package --- packages/cli/src/commands/index.ts | 3 +-- packages/metro/package.json | 6 +++++- packages/metro/src/index.ts | 1 + packages/metro/src/start/index.ts | 2 ++ .../{cli/src/commands => metro/src}/start/runServer.ts | 8 +++----- packages/{cli/src/commands => metro/src}/start/start.ts | 4 ++-- .../{cli/src/commands => metro/src}/start/watchMode.ts | 0 packages/metro/tsconfig.json | 1 + yarn.lock | 5 +++++ 9 files changed, 20 insertions(+), 10 deletions(-) create mode 100644 packages/metro/src/start/index.ts rename packages/{cli/src/commands => metro/src}/start/runServer.ts (94%) rename packages/{cli/src/commands => metro/src}/start/start.ts (97%) rename packages/{cli/src/commands => metro/src}/start/watchMode.ts (100%) diff --git a/packages/cli/src/commands/index.ts b/packages/cli/src/commands/index.ts index 20befb31c..659eda552 100644 --- a/packages/cli/src/commands/index.ts +++ b/packages/cli/src/commands/index.ts @@ -1,6 +1,5 @@ import {Command, DetachedCommand} from '@react-native-community/cli-types'; -import start from './start/start'; -import {bundle, ramBundle} from '@react-native-community/metro'; +import {start, bundle, ramBundle} from '@react-native-community/metro'; import link from './link/link'; import unlink from './link/unlink'; import install from './install/install'; diff --git a/packages/metro/package.json b/packages/metro/package.json index 15cfe4ac7..61b0e0e87 100644 --- a/packages/metro/package.json +++ b/packages/metro/package.json @@ -8,12 +8,16 @@ }, "dependencies": { "@react-native-community/cli-tools": "^6.0.0-rc.0", + "@react-native-community/cli-server-api": "^6.0.0-rc.0", + "chalk": "^3.0.0", "metro": "^0.66.1", "metro-config": "^0.66.1", "metro-core": "^0.66.1", "metro-react-native-babel-transformer": "^0.66.1", "metro-resolver": "^0.66.1", - "metro-runtime": "^0.66.1" + "metro-runtime": "^0.66.1", + "mkdirp": "^0.5.1", + "readline": "^1.3.0" }, "devDependencies": { "@react-native-community/cli-types": "^6.0.0-rc.0" diff --git a/packages/metro/src/index.ts b/packages/metro/src/index.ts index 1f74f5a94..92fd329a9 100644 --- a/packages/metro/src/index.ts +++ b/packages/metro/src/index.ts @@ -1,2 +1,3 @@ export * from './bundle'; export * from './config'; +export * from './start'; diff --git a/packages/metro/src/start/index.ts b/packages/metro/src/start/index.ts new file mode 100644 index 000000000..534dd0959 --- /dev/null +++ b/packages/metro/src/start/index.ts @@ -0,0 +1,2 @@ +export * from './start'; +export * from './runServer'; diff --git a/packages/cli/src/commands/start/runServer.ts b/packages/metro/src/start/runServer.ts similarity index 94% rename from packages/cli/src/commands/start/runServer.ts rename to packages/metro/src/start/runServer.ts index fcc95e5ab..72cc357c4 100644 --- a/packages/cli/src/commands/start/runServer.ts +++ b/packages/metro/src/start/runServer.ts @@ -16,7 +16,7 @@ import { } from '@react-native-community/cli-server-api'; import {Config} from '@react-native-community/cli-types'; -import {loadMetroConfig} from '@react-native-community/metro'; +import {loadMetroConfig} from '../config/loadMetroConfig'; import {releaseChecker} from '@react-native-community/cli-tools'; import enableWatchMode from './watchMode'; @@ -39,7 +39,7 @@ export type Args = { interactive: boolean; }; -async function runServer(_argv: Array, ctx: Config, args: Args) { +export async function runServer(_argv: Array, ctx: Config, args: Args) { let reportEvent: ((event: any) => void) | undefined; const terminal = new Terminal(process.stdout); const ReporterImpl = getReporterImpl(args.customLogReporterPath); @@ -119,7 +119,7 @@ async function runServer(_argv: Array, ctx: Config, args: Args) { await releaseChecker(ctx.root); } -function getReporterImpl(customLogReporterPath: string | undefined) { +export function getReporterImpl(customLogReporterPath: string | undefined) { if (customLogReporterPath === undefined) { return require('metro/src/lib/TerminalReporter'); } @@ -136,5 +136,3 @@ function getReporterImpl(customLogReporterPath: string | undefined) { return require(path.resolve(customLogReporterPath)); } } - -export default runServer; diff --git a/packages/cli/src/commands/start/start.ts b/packages/metro/src/start/start.ts similarity index 97% rename from packages/cli/src/commands/start/start.ts rename to packages/metro/src/start/start.ts index accfa96eb..0025245e7 100644 --- a/packages/cli/src/commands/start/start.ts +++ b/packages/metro/src/start/start.ts @@ -7,9 +7,9 @@ */ import path from 'path'; -import runServer from './runServer'; +import {runServer} from './runServer'; -export default { +export const start = { name: 'start', func: runServer, description: 'starts the webserver', diff --git a/packages/cli/src/commands/start/watchMode.ts b/packages/metro/src/start/watchMode.ts similarity index 100% rename from packages/cli/src/commands/start/watchMode.ts rename to packages/metro/src/start/watchMode.ts diff --git a/packages/metro/tsconfig.json b/packages/metro/tsconfig.json index e8205804a..fe00046e2 100644 --- a/packages/metro/tsconfig.json +++ b/packages/metro/tsconfig.json @@ -6,6 +6,7 @@ }, "references": [ {"path": "../cli-types"}, + {"path": "../cli-server-api"}, {"path": "../tools"}, ] } diff --git a/yarn.lock b/yarn.lock index 84fa1bf38..970eefd83 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10181,6 +10181,11 @@ readdirp@~3.3.0: dependencies: picomatch "^2.0.7" +readline@^1.3.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/readline/-/readline-1.3.0.tgz#c580d77ef2cfc8752b132498060dc9793a7ac01c" + integrity sha1-xYDXfvLPyHUrEySYBg3JeTp6wBw= + realpath-native@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/realpath-native/-/realpath-native-2.0.0.tgz#7377ac429b6e1fd599dc38d08ed942d0d7beb866" From 75e00a2a8c2af6a83aa5f3a363c54ebb54d086e7 Mon Sep 17 00:00:00 2001 From: Adam Foxman Date: Tue, 21 Sep 2021 14:08:47 -0700 Subject: [PATCH 08/16] Rename 'metro' package to 'cli-plugin-metro'. --- packages/{metro => cli-plugin-metro}/package.json | 2 +- .../src/bundle/__mocks__/sign.js | 0 .../src/bundle/__tests__/filterPlatformAssetScales-test.ts | 0 .../src/bundle/__tests__/getAssetDestPathAndroid-test.ts | 0 .../src/bundle/__tests__/getAssetDestPathIOS-test.ts | 0 .../src/bundle/assetPathUtils.ts | 0 .../{metro => cli-plugin-metro}/src/bundle/buildBundle.ts | 0 packages/{metro => cli-plugin-metro}/src/bundle/bundle.ts | 0 .../src/bundle/bundleCommandLineArgs.ts | 0 .../src/bundle/filterPlatformAssetScales.ts | 0 .../src/bundle/getAssetDestPathAndroid.ts | 0 .../src/bundle/getAssetDestPathIOS.ts | 0 packages/{metro => cli-plugin-metro}/src/bundle/index.ts | 0 .../{metro => cli-plugin-metro}/src/bundle/ramBundle.ts | 0 .../{metro => cli-plugin-metro}/src/bundle/saveAssets.ts | 0 .../src/config/__tests__/loadMetroConfig-test.ts | 0 packages/{metro => cli-plugin-metro}/src/config/index.ts | 0 .../src/config/loadMetroConfig.ts | 0 .../src/config/metroPlatformResolver.ts | 0 packages/{metro => cli-plugin-metro}/src/index.ts | 0 packages/{metro => cli-plugin-metro}/src/start/index.ts | 0 packages/{metro => cli-plugin-metro}/src/start/runServer.ts | 0 packages/{metro => cli-plugin-metro}/src/start/start.ts | 0 packages/{metro => cli-plugin-metro}/src/start/watchMode.ts | 0 packages/{metro => cli-plugin-metro}/tsconfig.json | 0 packages/cli/src/commands/index.ts | 6 +++++- 26 files changed, 6 insertions(+), 2 deletions(-) rename packages/{metro => cli-plugin-metro}/package.json (94%) rename packages/{metro => cli-plugin-metro}/src/bundle/__mocks__/sign.js (100%) rename packages/{metro => cli-plugin-metro}/src/bundle/__tests__/filterPlatformAssetScales-test.ts (100%) rename packages/{metro => cli-plugin-metro}/src/bundle/__tests__/getAssetDestPathAndroid-test.ts (100%) rename packages/{metro => cli-plugin-metro}/src/bundle/__tests__/getAssetDestPathIOS-test.ts (100%) rename packages/{metro => cli-plugin-metro}/src/bundle/assetPathUtils.ts (100%) rename packages/{metro => cli-plugin-metro}/src/bundle/buildBundle.ts (100%) rename packages/{metro => cli-plugin-metro}/src/bundle/bundle.ts (100%) rename packages/{metro => cli-plugin-metro}/src/bundle/bundleCommandLineArgs.ts (100%) rename packages/{metro => cli-plugin-metro}/src/bundle/filterPlatformAssetScales.ts (100%) rename packages/{metro => cli-plugin-metro}/src/bundle/getAssetDestPathAndroid.ts (100%) rename packages/{metro => cli-plugin-metro}/src/bundle/getAssetDestPathIOS.ts (100%) rename packages/{metro => cli-plugin-metro}/src/bundle/index.ts (100%) rename packages/{metro => cli-plugin-metro}/src/bundle/ramBundle.ts (100%) rename packages/{metro => cli-plugin-metro}/src/bundle/saveAssets.ts (100%) rename packages/{metro => cli-plugin-metro}/src/config/__tests__/loadMetroConfig-test.ts (100%) rename packages/{metro => cli-plugin-metro}/src/config/index.ts (100%) rename packages/{metro => cli-plugin-metro}/src/config/loadMetroConfig.ts (100%) rename packages/{metro => cli-plugin-metro}/src/config/metroPlatformResolver.ts (100%) rename packages/{metro => cli-plugin-metro}/src/index.ts (100%) rename packages/{metro => cli-plugin-metro}/src/start/index.ts (100%) rename packages/{metro => cli-plugin-metro}/src/start/runServer.ts (100%) rename packages/{metro => cli-plugin-metro}/src/start/start.ts (100%) rename packages/{metro => cli-plugin-metro}/src/start/watchMode.ts (100%) rename packages/{metro => cli-plugin-metro}/tsconfig.json (100%) diff --git a/packages/metro/package.json b/packages/cli-plugin-metro/package.json similarity index 94% rename from packages/metro/package.json rename to packages/cli-plugin-metro/package.json index 120a267d3..89e3e78e7 100644 --- a/packages/metro/package.json +++ b/packages/cli-plugin-metro/package.json @@ -1,5 +1,5 @@ { - "name": "@react-native-community/metro", + "name": "@react-native-community/cli-plugin-metro", "version": "6.0.0", "license": "MIT", "main": "build/index.js", diff --git a/packages/metro/src/bundle/__mocks__/sign.js b/packages/cli-plugin-metro/src/bundle/__mocks__/sign.js similarity index 100% rename from packages/metro/src/bundle/__mocks__/sign.js rename to packages/cli-plugin-metro/src/bundle/__mocks__/sign.js diff --git a/packages/metro/src/bundle/__tests__/filterPlatformAssetScales-test.ts b/packages/cli-plugin-metro/src/bundle/__tests__/filterPlatformAssetScales-test.ts similarity index 100% rename from packages/metro/src/bundle/__tests__/filterPlatformAssetScales-test.ts rename to packages/cli-plugin-metro/src/bundle/__tests__/filterPlatformAssetScales-test.ts diff --git a/packages/metro/src/bundle/__tests__/getAssetDestPathAndroid-test.ts b/packages/cli-plugin-metro/src/bundle/__tests__/getAssetDestPathAndroid-test.ts similarity index 100% rename from packages/metro/src/bundle/__tests__/getAssetDestPathAndroid-test.ts rename to packages/cli-plugin-metro/src/bundle/__tests__/getAssetDestPathAndroid-test.ts diff --git a/packages/metro/src/bundle/__tests__/getAssetDestPathIOS-test.ts b/packages/cli-plugin-metro/src/bundle/__tests__/getAssetDestPathIOS-test.ts similarity index 100% rename from packages/metro/src/bundle/__tests__/getAssetDestPathIOS-test.ts rename to packages/cli-plugin-metro/src/bundle/__tests__/getAssetDestPathIOS-test.ts diff --git a/packages/metro/src/bundle/assetPathUtils.ts b/packages/cli-plugin-metro/src/bundle/assetPathUtils.ts similarity index 100% rename from packages/metro/src/bundle/assetPathUtils.ts rename to packages/cli-plugin-metro/src/bundle/assetPathUtils.ts diff --git a/packages/metro/src/bundle/buildBundle.ts b/packages/cli-plugin-metro/src/bundle/buildBundle.ts similarity index 100% rename from packages/metro/src/bundle/buildBundle.ts rename to packages/cli-plugin-metro/src/bundle/buildBundle.ts diff --git a/packages/metro/src/bundle/bundle.ts b/packages/cli-plugin-metro/src/bundle/bundle.ts similarity index 100% rename from packages/metro/src/bundle/bundle.ts rename to packages/cli-plugin-metro/src/bundle/bundle.ts diff --git a/packages/metro/src/bundle/bundleCommandLineArgs.ts b/packages/cli-plugin-metro/src/bundle/bundleCommandLineArgs.ts similarity index 100% rename from packages/metro/src/bundle/bundleCommandLineArgs.ts rename to packages/cli-plugin-metro/src/bundle/bundleCommandLineArgs.ts diff --git a/packages/metro/src/bundle/filterPlatformAssetScales.ts b/packages/cli-plugin-metro/src/bundle/filterPlatformAssetScales.ts similarity index 100% rename from packages/metro/src/bundle/filterPlatformAssetScales.ts rename to packages/cli-plugin-metro/src/bundle/filterPlatformAssetScales.ts diff --git a/packages/metro/src/bundle/getAssetDestPathAndroid.ts b/packages/cli-plugin-metro/src/bundle/getAssetDestPathAndroid.ts similarity index 100% rename from packages/metro/src/bundle/getAssetDestPathAndroid.ts rename to packages/cli-plugin-metro/src/bundle/getAssetDestPathAndroid.ts diff --git a/packages/metro/src/bundle/getAssetDestPathIOS.ts b/packages/cli-plugin-metro/src/bundle/getAssetDestPathIOS.ts similarity index 100% rename from packages/metro/src/bundle/getAssetDestPathIOS.ts rename to packages/cli-plugin-metro/src/bundle/getAssetDestPathIOS.ts diff --git a/packages/metro/src/bundle/index.ts b/packages/cli-plugin-metro/src/bundle/index.ts similarity index 100% rename from packages/metro/src/bundle/index.ts rename to packages/cli-plugin-metro/src/bundle/index.ts diff --git a/packages/metro/src/bundle/ramBundle.ts b/packages/cli-plugin-metro/src/bundle/ramBundle.ts similarity index 100% rename from packages/metro/src/bundle/ramBundle.ts rename to packages/cli-plugin-metro/src/bundle/ramBundle.ts diff --git a/packages/metro/src/bundle/saveAssets.ts b/packages/cli-plugin-metro/src/bundle/saveAssets.ts similarity index 100% rename from packages/metro/src/bundle/saveAssets.ts rename to packages/cli-plugin-metro/src/bundle/saveAssets.ts diff --git a/packages/metro/src/config/__tests__/loadMetroConfig-test.ts b/packages/cli-plugin-metro/src/config/__tests__/loadMetroConfig-test.ts similarity index 100% rename from packages/metro/src/config/__tests__/loadMetroConfig-test.ts rename to packages/cli-plugin-metro/src/config/__tests__/loadMetroConfig-test.ts diff --git a/packages/metro/src/config/index.ts b/packages/cli-plugin-metro/src/config/index.ts similarity index 100% rename from packages/metro/src/config/index.ts rename to packages/cli-plugin-metro/src/config/index.ts diff --git a/packages/metro/src/config/loadMetroConfig.ts b/packages/cli-plugin-metro/src/config/loadMetroConfig.ts similarity index 100% rename from packages/metro/src/config/loadMetroConfig.ts rename to packages/cli-plugin-metro/src/config/loadMetroConfig.ts diff --git a/packages/metro/src/config/metroPlatformResolver.ts b/packages/cli-plugin-metro/src/config/metroPlatformResolver.ts similarity index 100% rename from packages/metro/src/config/metroPlatformResolver.ts rename to packages/cli-plugin-metro/src/config/metroPlatformResolver.ts diff --git a/packages/metro/src/index.ts b/packages/cli-plugin-metro/src/index.ts similarity index 100% rename from packages/metro/src/index.ts rename to packages/cli-plugin-metro/src/index.ts diff --git a/packages/metro/src/start/index.ts b/packages/cli-plugin-metro/src/start/index.ts similarity index 100% rename from packages/metro/src/start/index.ts rename to packages/cli-plugin-metro/src/start/index.ts diff --git a/packages/metro/src/start/runServer.ts b/packages/cli-plugin-metro/src/start/runServer.ts similarity index 100% rename from packages/metro/src/start/runServer.ts rename to packages/cli-plugin-metro/src/start/runServer.ts diff --git a/packages/metro/src/start/start.ts b/packages/cli-plugin-metro/src/start/start.ts similarity index 100% rename from packages/metro/src/start/start.ts rename to packages/cli-plugin-metro/src/start/start.ts diff --git a/packages/metro/src/start/watchMode.ts b/packages/cli-plugin-metro/src/start/watchMode.ts similarity index 100% rename from packages/metro/src/start/watchMode.ts rename to packages/cli-plugin-metro/src/start/watchMode.ts diff --git a/packages/metro/tsconfig.json b/packages/cli-plugin-metro/tsconfig.json similarity index 100% rename from packages/metro/tsconfig.json rename to packages/cli-plugin-metro/tsconfig.json diff --git a/packages/cli/src/commands/index.ts b/packages/cli/src/commands/index.ts index 659eda552..73873843c 100644 --- a/packages/cli/src/commands/index.ts +++ b/packages/cli/src/commands/index.ts @@ -1,5 +1,9 @@ import {Command, DetachedCommand} from '@react-native-community/cli-types'; -import {start, bundle, ramBundle} from '@react-native-community/metro'; +import { + start, + bundle, + ramBundle, +} from '@react-native-community/cli-plugin-metro'; import link from './link/link'; import unlink from './link/unlink'; import install from './install/install'; From 11786fd6136bfded0da60ca4ac6eb75d40b7483e Mon Sep 17 00:00:00 2001 From: Adam Foxman Date: Tue, 21 Sep 2021 14:12:22 -0700 Subject: [PATCH 09/16] Update dependency --- packages/cli/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/package.json b/packages/cli/package.json index 3260405f9..f7a4cca46 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -29,7 +29,7 @@ "@react-native-community/cli-server-api": "^6.0.0-rc.0", "@react-native-community/cli-tools": "^6.0.0-rc.0", "@react-native-community/cli-types": "^6.0.0", - "@react-native-community/metro": "^6.0.0", + "@react-native-community/cli-plugin-metro": "^6.0.0", "appdirsjs": "^1.2.4", "chalk": "^3.0.0", "command-exists": "^1.2.8", From 7fa013376bb50848d8db82192bbacf9463ceecfc Mon Sep 17 00:00:00 2001 From: Adam Foxman Date: Tue, 21 Sep 2021 14:17:16 -0700 Subject: [PATCH 10/16] More renaming --- packages/cli-plugin-metro/package.json | 4 ++-- packages/cli/tsconfig.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/cli-plugin-metro/package.json b/packages/cli-plugin-metro/package.json index 89e3e78e7..28918377c 100644 --- a/packages/cli-plugin-metro/package.json +++ b/packages/cli-plugin-metro/package.json @@ -26,10 +26,10 @@ "build", "!*.map" ], - "homepage": "https://github.com/react-native-community/cli/tree/master/packages/metro", + "homepage": "https://github.com/react-native-community/cli/tree/master/packages/cli-plugin-metro", "repository": { "type": "git", "url": "https://github.com/react-native-community/cli.git", - "directory": "packages/metro" + "directory": "packages/cli-plugin-metro" } } diff --git a/packages/cli/tsconfig.json b/packages/cli/tsconfig.json index 7532e5f7d..2a6002164 100644 --- a/packages/cli/tsconfig.json +++ b/packages/cli/tsconfig.json @@ -10,6 +10,6 @@ {"path": "../debugger-ui"}, {"path": "../cli-server-api"}, {"path": "../cli-hermes"}, - {"path": "../metro"}, + {"path": "../cli-plugin-metro"}, ] } From d6462a3baa7a8c2a016909451403a99e5948173f Mon Sep 17 00:00:00 2001 From: Adam Foxman Date: Tue, 21 Sep 2021 14:30:34 -0700 Subject: [PATCH 11/16] Revert buildBundle to default export --- packages/cli-plugin-metro/src/bundle/buildBundle.ts | 4 +++- packages/cli-plugin-metro/src/bundle/bundle.ts | 2 +- packages/cli-plugin-metro/src/bundle/saveAssets.ts | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/cli-plugin-metro/src/bundle/buildBundle.ts b/packages/cli-plugin-metro/src/bundle/buildBundle.ts index 4418c370f..89b8f7619 100644 --- a/packages/cli-plugin-metro/src/bundle/buildBundle.ts +++ b/packages/cli-plugin-metro/src/bundle/buildBundle.ts @@ -40,7 +40,7 @@ export interface AssetData { files: string[]; } -export async function buildBundle( +async function buildBundle( args: CommandLineArgs, ctx: Config, output: typeof outputBundle = outputBundle, @@ -106,3 +106,5 @@ export async function buildBundle( server.end(); } } + +export default buildBundle; diff --git a/packages/cli-plugin-metro/src/bundle/bundle.ts b/packages/cli-plugin-metro/src/bundle/bundle.ts index 4c68a8dec..35df94466 100644 --- a/packages/cli-plugin-metro/src/bundle/bundle.ts +++ b/packages/cli-plugin-metro/src/bundle/bundle.ts @@ -6,7 +6,7 @@ * */ import type {Config} from '@react-native-community/cli-types'; -import {buildBundle} from './buildBundle'; +import buildBundle from './buildBundle'; import bundleCommandLineArgs, {CommandLineArgs} from './bundleCommandLineArgs'; /** diff --git a/packages/cli-plugin-metro/src/bundle/saveAssets.ts b/packages/cli-plugin-metro/src/bundle/saveAssets.ts index 07cf773d7..356e2311b 100644 --- a/packages/cli-plugin-metro/src/bundle/saveAssets.ts +++ b/packages/cli-plugin-metro/src/bundle/saveAssets.ts @@ -14,7 +14,7 @@ import filterPlatformAssetScales from './filterPlatformAssetScales'; import getAssetDestPathAndroid from './getAssetDestPathAndroid'; import getAssetDestPathIOS from './getAssetDestPathIOS'; import {logger} from '@react-native-community/cli-tools'; -import {AssetData} from './buildBundle'; +import type {AssetData} from './buildBundle'; interface CopiedFiles { [src: string]: string; From 9f88c589aa22b4436e6dfce4f3b55ed1d3582223 Mon Sep 17 00:00:00 2001 From: Adam Foxman Date: Tue, 21 Sep 2021 14:46:34 -0700 Subject: [PATCH 12/16] Make exports explicit --- packages/cli-plugin-metro/src/index.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/cli-plugin-metro/src/index.ts b/packages/cli-plugin-metro/src/index.ts index 92fd329a9..0a0d63949 100644 --- a/packages/cli-plugin-metro/src/index.ts +++ b/packages/cli-plugin-metro/src/index.ts @@ -1,3 +1,10 @@ -export * from './bundle'; +export { + bundle, + ramBundleCommand, + ramBundle, + AssetData, + buildBundle, + CommandLineArgs, +} from './bundle'; export * from './config'; export * from './start'; From c05337967f9e3935385e9944fa492ba46a187bf3 Mon Sep 17 00:00:00 2001 From: Adam Foxman Date: Tue, 21 Sep 2021 15:11:15 -0700 Subject: [PATCH 13/16] Revert exports to default --- packages/cli-plugin-metro/src/bundle/bundle.ts | 2 +- packages/cli-plugin-metro/src/bundle/ramBundle.ts | 12 +++++------- .../cli-plugin-metro/src/config/loadMetroConfig.ts | 2 +- packages/cli-plugin-metro/src/start/runServer.ts | 9 ++++++--- packages/cli-plugin-metro/src/start/start.ts | 4 ++-- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/packages/cli-plugin-metro/src/bundle/bundle.ts b/packages/cli-plugin-metro/src/bundle/bundle.ts index 35df94466..fff01b95b 100644 --- a/packages/cli-plugin-metro/src/bundle/bundle.ts +++ b/packages/cli-plugin-metro/src/bundle/bundle.ts @@ -21,7 +21,7 @@ function bundleWithOutput( return buildBundle(args, config, output); } -export const bundle = { +export default { name: 'bundle', description: 'builds the javascript bundle for offline use', func: bundleWithOutput, diff --git a/packages/cli-plugin-metro/src/bundle/ramBundle.ts b/packages/cli-plugin-metro/src/bundle/ramBundle.ts index b9d8dfe64..6eb8d74ea 100644 --- a/packages/cli-plugin-metro/src/bundle/ramBundle.ts +++ b/packages/cli-plugin-metro/src/bundle/ramBundle.ts @@ -14,19 +14,15 @@ import type {Config} from '@react-native-community/cli-types'; /** * Builds the bundle starting to look for dependencies at the given entry path. */ -function createRamBundle( - argv: Array, - config: Config, - args: CommandLineArgs, -) { +function ramBundle(argv: Array, config: Config, args: CommandLineArgs) { return bundleWithOutput(argv, config, args, outputUnbundle); } -export const ramBundle = { +export default { name: 'ram-bundle', description: 'builds javascript as a "Random Access Module" bundle for offline use', - func: createRamBundle, + func: ramBundle, options: bundleCommandLineArgs.concat({ name: '--indexed-ram-bundle', description: @@ -34,3 +30,5 @@ export const ramBundle = { default: false, }), }; + +export {ramBundle}; diff --git a/packages/cli-plugin-metro/src/config/loadMetroConfig.ts b/packages/cli-plugin-metro/src/config/loadMetroConfig.ts index 992106f2b..42e778e78 100644 --- a/packages/cli-plugin-metro/src/config/loadMetroConfig.ts +++ b/packages/cli-plugin-metro/src/config/loadMetroConfig.ts @@ -143,7 +143,7 @@ export interface ConfigOptionsT { * * This allows the CLI to always overwrite the file settings. */ -export function loadMetroConfig( +export default function loadMetroConfig( ctx: ConfigLoadingContext, options?: ConfigOptionsT, ): Promise { diff --git a/packages/cli-plugin-metro/src/start/runServer.ts b/packages/cli-plugin-metro/src/start/runServer.ts index 72cc357c4..a24a2032d 100644 --- a/packages/cli-plugin-metro/src/start/runServer.ts +++ b/packages/cli-plugin-metro/src/start/runServer.ts @@ -16,7 +16,7 @@ import { } from '@react-native-community/cli-server-api'; import {Config} from '@react-native-community/cli-types'; -import {loadMetroConfig} from '../config/loadMetroConfig'; +import loadMetroConfig from '../config/loadMetroConfig'; import {releaseChecker} from '@react-native-community/cli-tools'; import enableWatchMode from './watchMode'; @@ -39,7 +39,7 @@ export type Args = { interactive: boolean; }; -export async function runServer(_argv: Array, ctx: Config, args: Args) { +async function runServer(_argv: Array, ctx: Config, args: Args) { let reportEvent: ((event: any) => void) | undefined; const terminal = new Terminal(process.stdout); const ReporterImpl = getReporterImpl(args.customLogReporterPath); @@ -119,7 +119,7 @@ export async function runServer(_argv: Array, ctx: Config, args: Args) { await releaseChecker(ctx.root); } -export function getReporterImpl(customLogReporterPath: string | undefined) { +function getReporterImpl(customLogReporterPath: string | undefined) { if (customLogReporterPath === undefined) { return require('metro/src/lib/TerminalReporter'); } @@ -136,3 +136,6 @@ export function getReporterImpl(customLogReporterPath: string | undefined) { return require(path.resolve(customLogReporterPath)); } } + +export default runServer; +export {getReporterImpl}; diff --git a/packages/cli-plugin-metro/src/start/start.ts b/packages/cli-plugin-metro/src/start/start.ts index 0025245e7..accfa96eb 100644 --- a/packages/cli-plugin-metro/src/start/start.ts +++ b/packages/cli-plugin-metro/src/start/start.ts @@ -7,9 +7,9 @@ */ import path from 'path'; -import {runServer} from './runServer'; +import runServer from './runServer'; -export const start = { +export default { name: 'start', func: runServer, description: 'starts the webserver', From 83a290ffb9459e20dbdc67e673b3d23e31412c7e Mon Sep 17 00:00:00 2001 From: Adam Foxman Date: Wed, 22 Sep 2021 11:35:06 -0700 Subject: [PATCH 14/16] PR feedback --- .../__tests__/loadMetroConfig-test.ts | 2 +- .../cli-plugin-metro/src/bundle/buildBundle.ts | 15 ++++++++++++++- packages/cli-plugin-metro/src/bundle/index.ts | 6 +++--- .../src/{config/loadMetroConfig.ts => config.ts} | 0 packages/cli-plugin-metro/src/config/index.ts | 1 - packages/cli-plugin-metro/src/index.ts | 15 +++++++++------ .../src/{config => }/metroPlatformResolver.ts | 0 .../cli-plugin-metro/src/{start => }/runServer.ts | 3 +-- .../cli-plugin-metro/src/{start => }/start.ts | 0 packages/cli-plugin-metro/src/start/index.ts | 2 -- .../cli-plugin-metro/src/{start => }/watchMode.ts | 0 packages/cli/src/commands/index.ts | 6 +++--- 12 files changed, 31 insertions(+), 19 deletions(-) rename packages/cli-plugin-metro/src/{config => }/__tests__/loadMetroConfig-test.ts (88%) rename packages/cli-plugin-metro/src/{config/loadMetroConfig.ts => config.ts} (100%) delete mode 100644 packages/cli-plugin-metro/src/config/index.ts rename packages/cli-plugin-metro/src/{config => }/metroPlatformResolver.ts (100%) rename packages/cli-plugin-metro/src/{start => }/runServer.ts (97%) rename packages/cli-plugin-metro/src/{start => }/start.ts (100%) delete mode 100644 packages/cli-plugin-metro/src/start/index.ts rename packages/cli-plugin-metro/src/{start => }/watchMode.ts (100%) diff --git a/packages/cli-plugin-metro/src/config/__tests__/loadMetroConfig-test.ts b/packages/cli-plugin-metro/src/__tests__/loadMetroConfig-test.ts similarity index 88% rename from packages/cli-plugin-metro/src/config/__tests__/loadMetroConfig-test.ts rename to packages/cli-plugin-metro/src/__tests__/loadMetroConfig-test.ts index 66dd75b0a..6b3101d88 100644 --- a/packages/cli-plugin-metro/src/config/__tests__/loadMetroConfig-test.ts +++ b/packages/cli-plugin-metro/src/__tests__/loadMetroConfig-test.ts @@ -1,4 +1,4 @@ -import {getDefaultConfig} from '../loadMetroConfig'; +import {getDefaultConfig} from '../config'; jest.mock('fs'); jest.mock('path'); diff --git a/packages/cli-plugin-metro/src/bundle/buildBundle.ts b/packages/cli-plugin-metro/src/bundle/buildBundle.ts index 89b8f7619..6f768bce8 100644 --- a/packages/cli-plugin-metro/src/bundle/buildBundle.ts +++ b/packages/cli-plugin-metro/src/bundle/buildBundle.ts @@ -15,7 +15,7 @@ import chalk from 'chalk'; import {CommandLineArgs} from './bundleCommandLineArgs'; import type {Config} from '@react-native-community/cli-types'; import saveAssets from './saveAssets'; -import {loadMetroConfig} from '../config'; +import {default as loadMetroConfig, MetroConfig} from '../config'; import {logger} from '@react-native-community/cli-tools'; interface RequestOptions { @@ -51,6 +51,19 @@ async function buildBundle( config: args.config, }); + return buildBundleWithConfig(args, config, output); +} + +/** + * Create a bundle using a pre-loaded Metro config. The config can be + * re-used for several bundling calls if multiple platforms are being + * bundled. + */ +export async function buildBundleWithConfig( + args: CommandLineArgs, + config: MetroConfig, + output: typeof outputBundle = outputBundle, +) { if (config.resolver.platforms.indexOf(args.platform) === -1) { logger.error( `Invalid platform ${ diff --git a/packages/cli-plugin-metro/src/bundle/index.ts b/packages/cli-plugin-metro/src/bundle/index.ts index c14bb0b42..bd8adf4fb 100644 --- a/packages/cli-plugin-metro/src/bundle/index.ts +++ b/packages/cli-plugin-metro/src/bundle/index.ts @@ -1,4 +1,4 @@ -export {bundle} from './bundle'; -export {ramBundle} from './ramBundle'; -export * from './buildBundle'; +export {default as bundleCommand} from './bundle'; +export {default as ramBundleCommand} from './ramBundle'; +export {buildBundleWithConfig} from './buildBundle'; export type {CommandLineArgs} from './bundleCommandLineArgs'; diff --git a/packages/cli-plugin-metro/src/config/loadMetroConfig.ts b/packages/cli-plugin-metro/src/config.ts similarity index 100% rename from packages/cli-plugin-metro/src/config/loadMetroConfig.ts rename to packages/cli-plugin-metro/src/config.ts diff --git a/packages/cli-plugin-metro/src/config/index.ts b/packages/cli-plugin-metro/src/config/index.ts deleted file mode 100644 index 84ada3284..000000000 --- a/packages/cli-plugin-metro/src/config/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './loadMetroConfig'; diff --git a/packages/cli-plugin-metro/src/index.ts b/packages/cli-plugin-metro/src/index.ts index 0a0d63949..d6a9668bf 100644 --- a/packages/cli-plugin-metro/src/index.ts +++ b/packages/cli-plugin-metro/src/index.ts @@ -1,10 +1,13 @@ export { - bundle, + bundleCommand, ramBundleCommand, - ramBundle, - AssetData, - buildBundle, + buildBundleWithConfig, CommandLineArgs, } from './bundle'; -export * from './config'; -export * from './start'; +export { + Config, + ConfigLoadingContext, + MetroConfig, + getDefaultConfig, +} from './config'; +export {default as startCommand} from './start'; diff --git a/packages/cli-plugin-metro/src/config/metroPlatformResolver.ts b/packages/cli-plugin-metro/src/metroPlatformResolver.ts similarity index 100% rename from packages/cli-plugin-metro/src/config/metroPlatformResolver.ts rename to packages/cli-plugin-metro/src/metroPlatformResolver.ts diff --git a/packages/cli-plugin-metro/src/start/runServer.ts b/packages/cli-plugin-metro/src/runServer.ts similarity index 97% rename from packages/cli-plugin-metro/src/start/runServer.ts rename to packages/cli-plugin-metro/src/runServer.ts index a24a2032d..b07eb253f 100644 --- a/packages/cli-plugin-metro/src/start/runServer.ts +++ b/packages/cli-plugin-metro/src/runServer.ts @@ -16,7 +16,7 @@ import { } from '@react-native-community/cli-server-api'; import {Config} from '@react-native-community/cli-types'; -import loadMetroConfig from '../config/loadMetroConfig'; +import loadMetroConfig from './config'; import {releaseChecker} from '@react-native-community/cli-tools'; import enableWatchMode from './watchMode'; @@ -138,4 +138,3 @@ function getReporterImpl(customLogReporterPath: string | undefined) { } export default runServer; -export {getReporterImpl}; diff --git a/packages/cli-plugin-metro/src/start/start.ts b/packages/cli-plugin-metro/src/start.ts similarity index 100% rename from packages/cli-plugin-metro/src/start/start.ts rename to packages/cli-plugin-metro/src/start.ts diff --git a/packages/cli-plugin-metro/src/start/index.ts b/packages/cli-plugin-metro/src/start/index.ts deleted file mode 100644 index 534dd0959..000000000 --- a/packages/cli-plugin-metro/src/start/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './start'; -export * from './runServer'; diff --git a/packages/cli-plugin-metro/src/start/watchMode.ts b/packages/cli-plugin-metro/src/watchMode.ts similarity index 100% rename from packages/cli-plugin-metro/src/start/watchMode.ts rename to packages/cli-plugin-metro/src/watchMode.ts diff --git a/packages/cli/src/commands/index.ts b/packages/cli/src/commands/index.ts index 73873843c..a2d3fb633 100644 --- a/packages/cli/src/commands/index.ts +++ b/packages/cli/src/commands/index.ts @@ -1,8 +1,8 @@ import {Command, DetachedCommand} from '@react-native-community/cli-types'; import { - start, - bundle, - ramBundle, + startCommand as start, + bundleCommand as bundle, + ramBundleCommand as ramBundle, } from '@react-native-community/cli-plugin-metro'; import link from './link/link'; import unlink from './link/unlink'; From 5ec6ae8f6a492fdfd4b418ba541b6515494ebcfc Mon Sep 17 00:00:00 2001 From: Mike Grabowski Date: Mon, 27 Sep 2021 11:52:21 +0200 Subject: [PATCH 15/16] refactor(structure): moved some files around to reflect the convention a bit better --- packages/cli-plugin-metro/src/bundle/index.ts | 4 ---- .../src/{ => commands}/bundle/__mocks__/sign.js | 0 .../__tests__/filterPlatformAssetScales-test.ts | 0 .../bundle/__tests__/getAssetDestPathAndroid-test.ts | 0 .../bundle/__tests__/getAssetDestPathIOS-test.ts | 0 .../src/{ => commands}/bundle/assetPathUtils.ts | 0 .../src/{ => commands}/bundle/buildBundle.ts | 2 +- .../src/{ => commands}/bundle/bundle.ts | 0 .../{ => commands}/bundle/bundleCommandLineArgs.ts | 0 .../bundle/filterPlatformAssetScales.ts | 0 .../{ => commands}/bundle/getAssetDestPathAndroid.ts | 0 .../src/{ => commands}/bundle/getAssetDestPathIOS.ts | 0 .../cli-plugin-metro/src/commands/bundle/index.ts | 2 ++ .../src/{ => commands}/bundle/ramBundle.ts | 0 .../src/{ => commands}/bundle/saveAssets.ts | 0 packages/cli-plugin-metro/src/commands/index.ts | 4 ++++ .../src/{start.ts => commands/start/index.ts} | 0 .../src/{ => commands/start}/runServer.ts | 4 ++-- .../src/{ => commands/start}/watchMode.ts | 0 packages/cli-plugin-metro/src/index.ts | 11 +++-------- .../src/{ => tools}/__tests__/loadMetroConfig-test.ts | 2 +- .../src/{config.ts => tools/loadMetroConfig.ts} | 0 .../src/{ => tools}/metroPlatformResolver.ts | 0 packages/cli/src/commands/index.ts | 10 ++-------- 24 files changed, 15 insertions(+), 24 deletions(-) delete mode 100644 packages/cli-plugin-metro/src/bundle/index.ts rename packages/cli-plugin-metro/src/{ => commands}/bundle/__mocks__/sign.js (100%) rename packages/cli-plugin-metro/src/{ => commands}/bundle/__tests__/filterPlatformAssetScales-test.ts (100%) rename packages/cli-plugin-metro/src/{ => commands}/bundle/__tests__/getAssetDestPathAndroid-test.ts (100%) rename packages/cli-plugin-metro/src/{ => commands}/bundle/__tests__/getAssetDestPathIOS-test.ts (100%) rename packages/cli-plugin-metro/src/{ => commands}/bundle/assetPathUtils.ts (100%) rename packages/cli-plugin-metro/src/{ => commands}/bundle/buildBundle.ts (97%) rename packages/cli-plugin-metro/src/{ => commands}/bundle/bundle.ts (100%) rename packages/cli-plugin-metro/src/{ => commands}/bundle/bundleCommandLineArgs.ts (100%) rename packages/cli-plugin-metro/src/{ => commands}/bundle/filterPlatformAssetScales.ts (100%) rename packages/cli-plugin-metro/src/{ => commands}/bundle/getAssetDestPathAndroid.ts (100%) rename packages/cli-plugin-metro/src/{ => commands}/bundle/getAssetDestPathIOS.ts (100%) create mode 100644 packages/cli-plugin-metro/src/commands/bundle/index.ts rename packages/cli-plugin-metro/src/{ => commands}/bundle/ramBundle.ts (100%) rename packages/cli-plugin-metro/src/{ => commands}/bundle/saveAssets.ts (100%) create mode 100644 packages/cli-plugin-metro/src/commands/index.ts rename packages/cli-plugin-metro/src/{start.ts => commands/start/index.ts} (100%) rename packages/cli-plugin-metro/src/{ => commands/start}/runServer.ts (98%) rename packages/cli-plugin-metro/src/{ => commands/start}/watchMode.ts (100%) rename packages/cli-plugin-metro/src/{ => tools}/__tests__/loadMetroConfig-test.ts (88%) rename packages/cli-plugin-metro/src/{config.ts => tools/loadMetroConfig.ts} (100%) rename packages/cli-plugin-metro/src/{ => tools}/metroPlatformResolver.ts (100%) diff --git a/packages/cli-plugin-metro/src/bundle/index.ts b/packages/cli-plugin-metro/src/bundle/index.ts deleted file mode 100644 index bd8adf4fb..000000000 --- a/packages/cli-plugin-metro/src/bundle/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export {default as bundleCommand} from './bundle'; -export {default as ramBundleCommand} from './ramBundle'; -export {buildBundleWithConfig} from './buildBundle'; -export type {CommandLineArgs} from './bundleCommandLineArgs'; diff --git a/packages/cli-plugin-metro/src/bundle/__mocks__/sign.js b/packages/cli-plugin-metro/src/commands/bundle/__mocks__/sign.js similarity index 100% rename from packages/cli-plugin-metro/src/bundle/__mocks__/sign.js rename to packages/cli-plugin-metro/src/commands/bundle/__mocks__/sign.js diff --git a/packages/cli-plugin-metro/src/bundle/__tests__/filterPlatformAssetScales-test.ts b/packages/cli-plugin-metro/src/commands/bundle/__tests__/filterPlatformAssetScales-test.ts similarity index 100% rename from packages/cli-plugin-metro/src/bundle/__tests__/filterPlatformAssetScales-test.ts rename to packages/cli-plugin-metro/src/commands/bundle/__tests__/filterPlatformAssetScales-test.ts diff --git a/packages/cli-plugin-metro/src/bundle/__tests__/getAssetDestPathAndroid-test.ts b/packages/cli-plugin-metro/src/commands/bundle/__tests__/getAssetDestPathAndroid-test.ts similarity index 100% rename from packages/cli-plugin-metro/src/bundle/__tests__/getAssetDestPathAndroid-test.ts rename to packages/cli-plugin-metro/src/commands/bundle/__tests__/getAssetDestPathAndroid-test.ts diff --git a/packages/cli-plugin-metro/src/bundle/__tests__/getAssetDestPathIOS-test.ts b/packages/cli-plugin-metro/src/commands/bundle/__tests__/getAssetDestPathIOS-test.ts similarity index 100% rename from packages/cli-plugin-metro/src/bundle/__tests__/getAssetDestPathIOS-test.ts rename to packages/cli-plugin-metro/src/commands/bundle/__tests__/getAssetDestPathIOS-test.ts diff --git a/packages/cli-plugin-metro/src/bundle/assetPathUtils.ts b/packages/cli-plugin-metro/src/commands/bundle/assetPathUtils.ts similarity index 100% rename from packages/cli-plugin-metro/src/bundle/assetPathUtils.ts rename to packages/cli-plugin-metro/src/commands/bundle/assetPathUtils.ts diff --git a/packages/cli-plugin-metro/src/bundle/buildBundle.ts b/packages/cli-plugin-metro/src/commands/bundle/buildBundle.ts similarity index 97% rename from packages/cli-plugin-metro/src/bundle/buildBundle.ts rename to packages/cli-plugin-metro/src/commands/bundle/buildBundle.ts index 6f768bce8..38b95cd93 100644 --- a/packages/cli-plugin-metro/src/bundle/buildBundle.ts +++ b/packages/cli-plugin-metro/src/commands/bundle/buildBundle.ts @@ -15,7 +15,7 @@ import chalk from 'chalk'; import {CommandLineArgs} from './bundleCommandLineArgs'; import type {Config} from '@react-native-community/cli-types'; import saveAssets from './saveAssets'; -import {default as loadMetroConfig, MetroConfig} from '../config'; +import {default as loadMetroConfig, MetroConfig} from '../../tools/loadMetroConfig'; import {logger} from '@react-native-community/cli-tools'; interface RequestOptions { diff --git a/packages/cli-plugin-metro/src/bundle/bundle.ts b/packages/cli-plugin-metro/src/commands/bundle/bundle.ts similarity index 100% rename from packages/cli-plugin-metro/src/bundle/bundle.ts rename to packages/cli-plugin-metro/src/commands/bundle/bundle.ts diff --git a/packages/cli-plugin-metro/src/bundle/bundleCommandLineArgs.ts b/packages/cli-plugin-metro/src/commands/bundle/bundleCommandLineArgs.ts similarity index 100% rename from packages/cli-plugin-metro/src/bundle/bundleCommandLineArgs.ts rename to packages/cli-plugin-metro/src/commands/bundle/bundleCommandLineArgs.ts diff --git a/packages/cli-plugin-metro/src/bundle/filterPlatformAssetScales.ts b/packages/cli-plugin-metro/src/commands/bundle/filterPlatformAssetScales.ts similarity index 100% rename from packages/cli-plugin-metro/src/bundle/filterPlatformAssetScales.ts rename to packages/cli-plugin-metro/src/commands/bundle/filterPlatformAssetScales.ts diff --git a/packages/cli-plugin-metro/src/bundle/getAssetDestPathAndroid.ts b/packages/cli-plugin-metro/src/commands/bundle/getAssetDestPathAndroid.ts similarity index 100% rename from packages/cli-plugin-metro/src/bundle/getAssetDestPathAndroid.ts rename to packages/cli-plugin-metro/src/commands/bundle/getAssetDestPathAndroid.ts diff --git a/packages/cli-plugin-metro/src/bundle/getAssetDestPathIOS.ts b/packages/cli-plugin-metro/src/commands/bundle/getAssetDestPathIOS.ts similarity index 100% rename from packages/cli-plugin-metro/src/bundle/getAssetDestPathIOS.ts rename to packages/cli-plugin-metro/src/commands/bundle/getAssetDestPathIOS.ts diff --git a/packages/cli-plugin-metro/src/commands/bundle/index.ts b/packages/cli-plugin-metro/src/commands/bundle/index.ts new file mode 100644 index 000000000..4a5984cc6 --- /dev/null +++ b/packages/cli-plugin-metro/src/commands/bundle/index.ts @@ -0,0 +1,2 @@ +export {default as bundleCommand} from './bundle'; +export {default as ramBundleCommand} from './ramBundle'; diff --git a/packages/cli-plugin-metro/src/bundle/ramBundle.ts b/packages/cli-plugin-metro/src/commands/bundle/ramBundle.ts similarity index 100% rename from packages/cli-plugin-metro/src/bundle/ramBundle.ts rename to packages/cli-plugin-metro/src/commands/bundle/ramBundle.ts diff --git a/packages/cli-plugin-metro/src/bundle/saveAssets.ts b/packages/cli-plugin-metro/src/commands/bundle/saveAssets.ts similarity index 100% rename from packages/cli-plugin-metro/src/bundle/saveAssets.ts rename to packages/cli-plugin-metro/src/commands/bundle/saveAssets.ts diff --git a/packages/cli-plugin-metro/src/commands/index.ts b/packages/cli-plugin-metro/src/commands/index.ts new file mode 100644 index 000000000..a413ced28 --- /dev/null +++ b/packages/cli-plugin-metro/src/commands/index.ts @@ -0,0 +1,4 @@ +import {bundleCommand, ramBundleCommand} from './bundle'; +import startCommand from './start'; + +export default [bundleCommand, ramBundleCommand, startCommand]; \ No newline at end of file diff --git a/packages/cli-plugin-metro/src/start.ts b/packages/cli-plugin-metro/src/commands/start/index.ts similarity index 100% rename from packages/cli-plugin-metro/src/start.ts rename to packages/cli-plugin-metro/src/commands/start/index.ts diff --git a/packages/cli-plugin-metro/src/runServer.ts b/packages/cli-plugin-metro/src/commands/start/runServer.ts similarity index 98% rename from packages/cli-plugin-metro/src/runServer.ts rename to packages/cli-plugin-metro/src/commands/start/runServer.ts index b07eb253f..eb0970204 100644 --- a/packages/cli-plugin-metro/src/runServer.ts +++ b/packages/cli-plugin-metro/src/commands/start/runServer.ts @@ -16,7 +16,7 @@ import { } from '@react-native-community/cli-server-api'; import {Config} from '@react-native-community/cli-types'; -import loadMetroConfig from './config'; +import loadMetroConfig from '../../tools/loadMetroConfig'; import {releaseChecker} from '@react-native-community/cli-tools'; import enableWatchMode from './watchMode'; @@ -127,7 +127,7 @@ function getReporterImpl(customLogReporterPath: string | undefined) { // First we let require resolve it, so we can require packages in node_modules // as expected. eg: require('my-package/reporter'); return require(customLogReporterPath); - } catch (e) { + } catch (e: any) { if (e.code !== 'MODULE_NOT_FOUND') { throw e; } diff --git a/packages/cli-plugin-metro/src/watchMode.ts b/packages/cli-plugin-metro/src/commands/start/watchMode.ts similarity index 100% rename from packages/cli-plugin-metro/src/watchMode.ts rename to packages/cli-plugin-metro/src/commands/start/watchMode.ts diff --git a/packages/cli-plugin-metro/src/index.ts b/packages/cli-plugin-metro/src/index.ts index d6a9668bf..1c8b1d5d7 100644 --- a/packages/cli-plugin-metro/src/index.ts +++ b/packages/cli-plugin-metro/src/index.ts @@ -1,13 +1,8 @@ -export { - bundleCommand, - ramBundleCommand, - buildBundleWithConfig, - CommandLineArgs, -} from './bundle'; export { Config, ConfigLoadingContext, MetroConfig, getDefaultConfig, -} from './config'; -export {default as startCommand} from './start'; + default as loadMetroConfig, +} from './tools/loadMetroConfig'; +export {default as commands} from './commands'; diff --git a/packages/cli-plugin-metro/src/__tests__/loadMetroConfig-test.ts b/packages/cli-plugin-metro/src/tools/__tests__/loadMetroConfig-test.ts similarity index 88% rename from packages/cli-plugin-metro/src/__tests__/loadMetroConfig-test.ts rename to packages/cli-plugin-metro/src/tools/__tests__/loadMetroConfig-test.ts index 6b3101d88..66dd75b0a 100644 --- a/packages/cli-plugin-metro/src/__tests__/loadMetroConfig-test.ts +++ b/packages/cli-plugin-metro/src/tools/__tests__/loadMetroConfig-test.ts @@ -1,4 +1,4 @@ -import {getDefaultConfig} from '../config'; +import {getDefaultConfig} from '../loadMetroConfig'; jest.mock('fs'); jest.mock('path'); diff --git a/packages/cli-plugin-metro/src/config.ts b/packages/cli-plugin-metro/src/tools/loadMetroConfig.ts similarity index 100% rename from packages/cli-plugin-metro/src/config.ts rename to packages/cli-plugin-metro/src/tools/loadMetroConfig.ts diff --git a/packages/cli-plugin-metro/src/metroPlatformResolver.ts b/packages/cli-plugin-metro/src/tools/metroPlatformResolver.ts similarity index 100% rename from packages/cli-plugin-metro/src/metroPlatformResolver.ts rename to packages/cli-plugin-metro/src/tools/metroPlatformResolver.ts diff --git a/packages/cli/src/commands/index.ts b/packages/cli/src/commands/index.ts index a2d3fb633..e0835bdd4 100644 --- a/packages/cli/src/commands/index.ts +++ b/packages/cli/src/commands/index.ts @@ -1,9 +1,5 @@ import {Command, DetachedCommand} from '@react-native-community/cli-types'; -import { - startCommand as start, - bundleCommand as bundle, - ramBundleCommand as ramBundle, -} from '@react-native-community/cli-plugin-metro'; +import {commands as metroCommands} from '@react-native-community/cli-plugin-metro'; import link from './link/link'; import unlink from './link/unlink'; import install from './install/install'; @@ -16,9 +12,7 @@ import doctor from './doctor'; import profileHermes from '@react-native-community/cli-hermes'; export const projectCommands = [ - start, - bundle, - ramBundle, + ...metroCommands, link, unlink, install, From 27f74ab91b2c8bf351e4747cad3bb4596711ff76 Mon Sep 17 00:00:00 2001 From: Adam Foxman Date: Mon, 27 Sep 2021 16:56:40 -0700 Subject: [PATCH 16/16] Fix type bug, export missing funciton/type. --- .../cli-plugin-metro/src/commands/bundle/buildBundle.ts | 5 ++++- packages/cli-plugin-metro/src/commands/bundle/index.ts | 2 ++ packages/cli-plugin-metro/src/commands/index.ts | 6 ++++-- packages/cli-plugin-metro/src/commands/start/runServer.ts | 4 ++-- packages/cli-plugin-metro/src/index.ts | 6 +++++- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/packages/cli-plugin-metro/src/commands/bundle/buildBundle.ts b/packages/cli-plugin-metro/src/commands/bundle/buildBundle.ts index 38b95cd93..27ccf465a 100644 --- a/packages/cli-plugin-metro/src/commands/bundle/buildBundle.ts +++ b/packages/cli-plugin-metro/src/commands/bundle/buildBundle.ts @@ -15,7 +15,10 @@ import chalk from 'chalk'; import {CommandLineArgs} from './bundleCommandLineArgs'; import type {Config} from '@react-native-community/cli-types'; import saveAssets from './saveAssets'; -import {default as loadMetroConfig, MetroConfig} from '../../tools/loadMetroConfig'; +import { + default as loadMetroConfig, + MetroConfig, +} from '../../tools/loadMetroConfig'; import {logger} from '@react-native-community/cli-tools'; interface RequestOptions { diff --git a/packages/cli-plugin-metro/src/commands/bundle/index.ts b/packages/cli-plugin-metro/src/commands/bundle/index.ts index 4a5984cc6..21b8261bd 100644 --- a/packages/cli-plugin-metro/src/commands/bundle/index.ts +++ b/packages/cli-plugin-metro/src/commands/bundle/index.ts @@ -1,2 +1,4 @@ export {default as bundleCommand} from './bundle'; +export {buildBundleWithConfig} from './buildBundle'; +export type {CommandLineArgs} from './bundleCommandLineArgs'; export {default as ramBundleCommand} from './ramBundle'; diff --git a/packages/cli-plugin-metro/src/commands/index.ts b/packages/cli-plugin-metro/src/commands/index.ts index a413ced28..0b9ffd88f 100644 --- a/packages/cli-plugin-metro/src/commands/index.ts +++ b/packages/cli-plugin-metro/src/commands/index.ts @@ -1,4 +1,6 @@ import {bundleCommand, ramBundleCommand} from './bundle'; import startCommand from './start'; - -export default [bundleCommand, ramBundleCommand, startCommand]; \ No newline at end of file + +export default [bundleCommand, ramBundleCommand, startCommand]; +export {buildBundleWithConfig} from './bundle'; +export type {CommandLineArgs} from './bundle'; diff --git a/packages/cli-plugin-metro/src/commands/start/runServer.ts b/packages/cli-plugin-metro/src/commands/start/runServer.ts index eb0970204..11d554374 100644 --- a/packages/cli-plugin-metro/src/commands/start/runServer.ts +++ b/packages/cli-plugin-metro/src/commands/start/runServer.ts @@ -127,8 +127,8 @@ function getReporterImpl(customLogReporterPath: string | undefined) { // First we let require resolve it, so we can require packages in node_modules // as expected. eg: require('my-package/reporter'); return require(customLogReporterPath); - } catch (e: any) { - if (e.code !== 'MODULE_NOT_FOUND') { + } catch (e) { + if ((e).code !== 'MODULE_NOT_FOUND') { throw e; } // If that doesn't work, then we next try relative to the cwd, eg: diff --git a/packages/cli-plugin-metro/src/index.ts b/packages/cli-plugin-metro/src/index.ts index 1c8b1d5d7..5951018e1 100644 --- a/packages/cli-plugin-metro/src/index.ts +++ b/packages/cli-plugin-metro/src/index.ts @@ -5,4 +5,8 @@ export { getDefaultConfig, default as loadMetroConfig, } from './tools/loadMetroConfig'; -export {default as commands} from './commands'; +export { + default as commands, + buildBundleWithConfig, + CommandLineArgs, +} from './commands';