diff --git a/packages/cli-plugin-metro/package.json b/packages/cli-plugin-metro/package.json new file mode 100644 index 000000000..28918377c --- /dev/null +++ b/packages/cli-plugin-metro/package.json @@ -0,0 +1,35 @@ +{ + "name": "@react-native-community/cli-plugin-metro", + "version": "6.0.0", + "license": "MIT", + "main": "build/index.js", + "publishConfig": { + "access": "public" + }, + "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", + "mkdirp": "^0.5.1", + "readline": "^1.3.0" + }, + "devDependencies": { + "@react-native-community/cli-types": "^6.0.0" + }, + "files": [ + "build", + "!*.map" + ], + "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/cli-plugin-metro" + } +} diff --git a/packages/cli/src/commands/bundle/__mocks__/sign.js b/packages/cli-plugin-metro/src/commands/bundle/__mocks__/sign.js similarity index 100% rename from packages/cli/src/commands/bundle/__mocks__/sign.js rename to packages/cli-plugin-metro/src/commands/bundle/__mocks__/sign.js diff --git a/packages/cli/src/commands/bundle/__tests__/filterPlatformAssetScales-test.ts b/packages/cli-plugin-metro/src/commands/bundle/__tests__/filterPlatformAssetScales-test.ts similarity index 100% rename from packages/cli/src/commands/bundle/__tests__/filterPlatformAssetScales-test.ts rename to packages/cli-plugin-metro/src/commands/bundle/__tests__/filterPlatformAssetScales-test.ts diff --git a/packages/cli/src/commands/bundle/__tests__/getAssetDestPathAndroid-test.ts b/packages/cli-plugin-metro/src/commands/bundle/__tests__/getAssetDestPathAndroid-test.ts similarity index 100% rename from packages/cli/src/commands/bundle/__tests__/getAssetDestPathAndroid-test.ts rename to packages/cli-plugin-metro/src/commands/bundle/__tests__/getAssetDestPathAndroid-test.ts diff --git a/packages/cli/src/commands/bundle/__tests__/getAssetDestPathIOS-test.ts b/packages/cli-plugin-metro/src/commands/bundle/__tests__/getAssetDestPathIOS-test.ts similarity index 100% rename from packages/cli/src/commands/bundle/__tests__/getAssetDestPathIOS-test.ts rename to packages/cli-plugin-metro/src/commands/bundle/__tests__/getAssetDestPathIOS-test.ts diff --git a/packages/cli/src/commands/bundle/assetPathUtils.ts b/packages/cli-plugin-metro/src/commands/bundle/assetPathUtils.ts similarity index 100% rename from packages/cli/src/commands/bundle/assetPathUtils.ts rename to packages/cli-plugin-metro/src/commands/bundle/assetPathUtils.ts diff --git a/packages/cli/src/commands/bundle/buildBundle.ts b/packages/cli-plugin-metro/src/commands/bundle/buildBundle.ts similarity index 83% rename from packages/cli/src/commands/bundle/buildBundle.ts rename to packages/cli-plugin-metro/src/commands/bundle/buildBundle.ts index 63a7a440f..27ccf465a 100644 --- a/packages/cli/src/commands/bundle/buildBundle.ts +++ b/packages/cli-plugin-metro/src/commands/bundle/buildBundle.ts @@ -9,13 +9,16 @@ // @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 type {Config} from '@react-native-community/cli-types'; import saveAssets from './saveAssets'; -import loadMetroConfig from '../../tools/loadMetroConfig'; +import { + default as loadMetroConfig, + MetroConfig, +} from '../../tools/loadMetroConfig'; import {logger} from '@react-native-community/cli-tools'; interface RequestOptions { @@ -51,6 +54,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/src/commands/bundle/bundle.ts b/packages/cli-plugin-metro/src/commands/bundle/bundle.ts similarity index 93% rename from packages/cli/src/commands/bundle/bundle.ts rename to packages/cli-plugin-metro/src/commands/bundle/bundle.ts index 95caa81bc..fff01b95b 100644 --- a/packages/cli/src/commands/bundle/bundle.ts +++ b/packages/cli-plugin-metro/src/commands/bundle/bundle.ts @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * */ -import {Config} from '@react-native-community/cli-types'; +import type {Config} from '@react-native-community/cli-types'; import buildBundle from './buildBundle'; import bundleCommandLineArgs, {CommandLineArgs} from './bundleCommandLineArgs'; diff --git a/packages/cli/src/commands/bundle/bundleCommandLineArgs.ts b/packages/cli-plugin-metro/src/commands/bundle/bundleCommandLineArgs.ts similarity index 100% rename from packages/cli/src/commands/bundle/bundleCommandLineArgs.ts rename to packages/cli-plugin-metro/src/commands/bundle/bundleCommandLineArgs.ts diff --git a/packages/cli/src/commands/bundle/filterPlatformAssetScales.ts b/packages/cli-plugin-metro/src/commands/bundle/filterPlatformAssetScales.ts similarity index 100% rename from packages/cli/src/commands/bundle/filterPlatformAssetScales.ts rename to packages/cli-plugin-metro/src/commands/bundle/filterPlatformAssetScales.ts diff --git a/packages/cli/src/commands/bundle/getAssetDestPathAndroid.ts b/packages/cli-plugin-metro/src/commands/bundle/getAssetDestPathAndroid.ts similarity index 100% rename from packages/cli/src/commands/bundle/getAssetDestPathAndroid.ts rename to packages/cli-plugin-metro/src/commands/bundle/getAssetDestPathAndroid.ts diff --git a/packages/cli/src/commands/bundle/getAssetDestPathIOS.ts b/packages/cli-plugin-metro/src/commands/bundle/getAssetDestPathIOS.ts similarity index 100% rename from packages/cli/src/commands/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..21b8261bd --- /dev/null +++ b/packages/cli-plugin-metro/src/commands/bundle/index.ts @@ -0,0 +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/src/commands/bundle/ramBundle.ts b/packages/cli-plugin-metro/src/commands/bundle/ramBundle.ts similarity index 92% rename from packages/cli/src/commands/bundle/ramBundle.ts rename to packages/cli-plugin-metro/src/commands/bundle/ramBundle.ts index 0f91f24d8..6eb8d74ea 100644 --- a/packages/cli/src/commands/bundle/ramBundle.ts +++ b/packages/cli-plugin-metro/src/commands/bundle/ramBundle.ts @@ -9,7 +9,7 @@ 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. @@ -30,3 +30,5 @@ export default { default: false, }), }; + +export {ramBundle}; diff --git a/packages/cli/src/commands/bundle/saveAssets.ts b/packages/cli-plugin-metro/src/commands/bundle/saveAssets.ts similarity index 98% rename from packages/cli/src/commands/bundle/saveAssets.ts rename to packages/cli-plugin-metro/src/commands/bundle/saveAssets.ts index 07cf773d7..356e2311b 100644 --- a/packages/cli/src/commands/bundle/saveAssets.ts +++ b/packages/cli-plugin-metro/src/commands/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; 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..0b9ffd88f --- /dev/null +++ b/packages/cli-plugin-metro/src/commands/index.ts @@ -0,0 +1,6 @@ +import {bundleCommand, ramBundleCommand} from './bundle'; +import startCommand from './start'; + +export default [bundleCommand, ramBundleCommand, startCommand]; +export {buildBundleWithConfig} from './bundle'; +export type {CommandLineArgs} from './bundle'; diff --git a/packages/cli/src/commands/start/start.ts b/packages/cli-plugin-metro/src/commands/start/index.ts similarity index 100% rename from packages/cli/src/commands/start/start.ts rename to packages/cli-plugin-metro/src/commands/start/index.ts diff --git a/packages/cli/src/commands/start/runServer.ts b/packages/cli-plugin-metro/src/commands/start/runServer.ts similarity index 97% rename from packages/cli/src/commands/start/runServer.ts rename to packages/cli-plugin-metro/src/commands/start/runServer.ts index a7acbbae6..11d554374 100644 --- a/packages/cli/src/commands/start/runServer.ts +++ b/packages/cli-plugin-metro/src/commands/start/runServer.ts @@ -17,7 +17,7 @@ import { import {Config} from '@react-native-community/cli-types'; import loadMetroConfig from '../../tools/loadMetroConfig'; -import releaseChecker from '../../tools/releaseChecker'; +import {releaseChecker} from '@react-native-community/cli-tools'; import enableWatchMode from './watchMode'; export type Args = { @@ -128,7 +128,7 @@ function getReporterImpl(customLogReporterPath: string | undefined) { // as expected. eg: require('my-package/reporter'); return require(customLogReporterPath); } catch (e) { - if (e.code !== 'MODULE_NOT_FOUND') { + 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/src/commands/start/watchMode.ts b/packages/cli-plugin-metro/src/commands/start/watchMode.ts similarity index 93% rename from packages/cli/src/commands/start/watchMode.ts rename to packages/cli-plugin-metro/src/commands/start/watchMode.ts index e7bd24efc..5b6fd7520 100644 --- a/packages/cli/src/commands/start/watchMode.ts +++ b/packages/cli-plugin-metro/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-plugin-metro/src/index.ts b/packages/cli-plugin-metro/src/index.ts new file mode 100644 index 000000000..5951018e1 --- /dev/null +++ b/packages/cli-plugin-metro/src/index.ts @@ -0,0 +1,12 @@ +export { + Config, + ConfigLoadingContext, + MetroConfig, + getDefaultConfig, + default as loadMetroConfig, +} from './tools/loadMetroConfig'; +export { + default as commands, + buildBundleWithConfig, + CommandLineArgs, +} from './commands'; diff --git a/packages/cli/src/tools/__tests__/loadMetroConfig-test.ts b/packages/cli-plugin-metro/src/tools/__tests__/loadMetroConfig-test.ts similarity index 95% rename from packages/cli/src/tools/__tests__/loadMetroConfig-test.ts rename to packages/cli-plugin-metro/src/tools/__tests__/loadMetroConfig-test.ts index 6658f711b..66dd75b0a 100644 --- a/packages/cli/src/tools/__tests__/loadMetroConfig-test.ts +++ b/packages/cli-plugin-metro/src/tools/__tests__/loadMetroConfig-test.ts @@ -8,6 +8,7 @@ describe('getDefaultConfig', () => { const config = getDefaultConfig({ root: '/', reactNativePath: '', + // @ts-ignore platforms: {}, }); diff --git a/packages/cli/src/tools/loadMetroConfig.ts b/packages/cli-plugin-metro/src/tools/loadMetroConfig.ts similarity index 96% rename from packages/cli/src/tools/loadMetroConfig.ts rename to packages/cli-plugin-metro/src/tools/loadMetroConfig.ts index 2a67dd072..42e778e78 100644 --- a/packages/cli/src/tools/loadMetroConfig.ts +++ b/packages/cli-plugin-metro/src/tools/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 default function load( +export default function loadMetroConfig( ctx: ConfigLoadingContext, options?: ConfigOptionsT, ): Promise { diff --git a/packages/cli/src/tools/metroPlatformResolver.ts b/packages/cli-plugin-metro/src/tools/metroPlatformResolver.ts similarity index 100% rename from packages/cli/src/tools/metroPlatformResolver.ts rename to packages/cli-plugin-metro/src/tools/metroPlatformResolver.ts diff --git a/packages/cli-plugin-metro/tsconfig.json b/packages/cli-plugin-metro/tsconfig.json new file mode 100644 index 000000000..fe00046e2 --- /dev/null +++ b/packages/cli-plugin-metro/tsconfig.json @@ -0,0 +1,12 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "build" + }, + "references": [ + {"path": "../cli-types"}, + {"path": "../cli-server-api"}, + {"path": "../tools"}, + ] +} diff --git a/packages/cli/package.json b/packages/cli/package.json index 4bd4555f9..78fca4101 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -29,6 +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/cli-plugin-metro": "^6.0.0", "appdirsjs": "^1.2.4", "chalk": "^3.0.0", "command-exists": "^1.2.8", @@ -44,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..e0835bdd4 100644 --- a/packages/cli/src/commands/index.ts +++ b/packages/cli/src/commands/index.ts @@ -1,7 +1,5 @@ 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 {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'; @@ -14,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, 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/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/cli/tsconfig.json b/packages/cli/tsconfig.json index f3d42e37b..2a6002164 100644 --- a/packages/cli/tsconfig.json +++ b/packages/cli/tsconfig.json @@ -9,6 +9,7 @@ {"path": "../cli-types"}, {"path": "../debugger-ui"}, {"path": "../cli-server-api"}, - {"path": "../cli-hermes"} + {"path": "../cli-hermes"}, + {"path": "../cli-plugin-metro"}, ] } 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/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 7c5c9dfe6..545aab8c6 100644 --- a/packages/tools/src/index.ts +++ b/packages/tools/src/index.ts @@ -6,5 +6,8 @@ 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 {default as hookStdout} from './hookStdout'; 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}; 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], + }), + ); +} diff --git a/yarn.lock b/yarn.lock index 020e74cc1..a8bfae5fd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10167,6 +10167,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"