From fb5da221a653044cd2638e5453e186d0104483c8 Mon Sep 17 00:00:00 2001 From: Arpit Bhalla <55053424+arpitBhalla@users.noreply.github.com> Date: Mon, 22 Jul 2024 21:16:49 +0530 Subject: [PATCH 1/6] wip --- packages/cli-package-manager/CHANGELOG.md | 4 ++ packages/cli-package-manager/package.json | 29 ++++++++++++ .../src}/__tests__/packageManager-test.ts | 2 +- .../tools => cli-package-manager/src}/bun.ts | 0 .../src}/executeCommand.ts | 0 packages/cli-package-manager/src/index.ts | 6 +++ .../tools => cli-package-manager/src}/npm.ts | 0 .../src}/packageManager.ts | 7 +++ packages/cli-package-manager/src/pnpm.ts | 46 +++++++++++++++++++ .../tools => cli-package-manager/src}/yarn.ts | 0 packages/cli-package-manager/tsconfig.json | 8 ++++ .../commands/init/__tests__/template.test.ts | 2 +- packages/cli/src/commands/init/init.ts | 24 ++++------ packages/cli/src/commands/init/template.ts | 10 ++-- packages/cli/tsconfig.json | 3 +- yarn.lock | 31 ++----------- 16 files changed, 122 insertions(+), 50 deletions(-) create mode 100644 packages/cli-package-manager/CHANGELOG.md create mode 100644 packages/cli-package-manager/package.json rename packages/{cli/src/tools => cli-package-manager/src}/__tests__/packageManager-test.ts (99%) rename packages/{cli/src/tools => cli-package-manager/src}/bun.ts (100%) rename packages/{cli/src/tools => cli-package-manager/src}/executeCommand.ts (100%) create mode 100644 packages/cli-package-manager/src/index.ts rename packages/{cli/src/tools => cli-package-manager/src}/npm.ts (100%) rename packages/{cli/src/tools => cli-package-manager/src}/packageManager.ts (94%) create mode 100644 packages/cli-package-manager/src/pnpm.ts rename packages/{cli/src/tools => cli-package-manager/src}/yarn.ts (100%) create mode 100644 packages/cli-package-manager/tsconfig.json diff --git a/packages/cli-package-manager/CHANGELOG.md b/packages/cli-package-manager/CHANGELOG.md new file mode 100644 index 000000000..e4d87c4d4 --- /dev/null +++ b/packages/cli-package-manager/CHANGELOG.md @@ -0,0 +1,4 @@ +# Change Log + +All notable changes to this project will be documented in this file. +See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. diff --git a/packages/cli-package-manager/package.json b/packages/cli-package-manager/package.json new file mode 100644 index 000000000..868f2eb6a --- /dev/null +++ b/packages/cli-package-manager/package.json @@ -0,0 +1,29 @@ +{ + "name": "@react-native-community/cli-package-manager", + "version": "14.0.0", + "license": "MIT", + "main": "build/index.js", + "publishConfig": { + "access": "public" + }, + "dependencies": { + "@react-native-community/cli-tools": "^14.0.0", + "execa": "^5.0.0", + "find-up": "^5.0.0", + "semver": "^7.5.2" + }, + "devDependencies": { + "@react-native-community/cli-types": "14.0.0" + }, + "files": [ + "build", + "!*.d.ts", + "!*.map" + ], + "homepage": "https://github.com/react-native-community/cli/tree/main/packages/cli-tools", + "repository": { + "type": "git", + "url": "https://github.com/react-native-community/cli.git", + "directory": "packages/cli-package-manager" + } +} diff --git a/packages/cli/src/tools/__tests__/packageManager-test.ts b/packages/cli-package-manager/src/__tests__/packageManager-test.ts similarity index 99% rename from packages/cli/src/tools/__tests__/packageManager-test.ts rename to packages/cli-package-manager/src/__tests__/packageManager-test.ts index 78c31a652..ec76462dc 100644 --- a/packages/cli/src/tools/__tests__/packageManager-test.ts +++ b/packages/cli-package-manager/src/__tests__/packageManager-test.ts @@ -3,7 +3,7 @@ import execa from 'execa'; import * as yarn from '../yarn'; import * as bun from '../bun'; import {logger} from '@react-native-community/cli-tools'; -import * as PackageManager from '../packageManager'; +import * as PackageManager from '..'; const PACKAGES = ['react', 'react-native']; const PROJECT_ROOT = '/some/dir'; diff --git a/packages/cli/src/tools/bun.ts b/packages/cli-package-manager/src/bun.ts similarity index 100% rename from packages/cli/src/tools/bun.ts rename to packages/cli-package-manager/src/bun.ts diff --git a/packages/cli/src/tools/executeCommand.ts b/packages/cli-package-manager/src/executeCommand.ts similarity index 100% rename from packages/cli/src/tools/executeCommand.ts rename to packages/cli-package-manager/src/executeCommand.ts diff --git a/packages/cli-package-manager/src/index.ts b/packages/cli-package-manager/src/index.ts new file mode 100644 index 000000000..9a327f919 --- /dev/null +++ b/packages/cli-package-manager/src/index.ts @@ -0,0 +1,6 @@ +export * from './bun'; +export * from './npm'; +export * from './pnpm'; +export * from './yarn'; +export * from './packageManager'; +export * from './executeCommand'; diff --git a/packages/cli/src/tools/npm.ts b/packages/cli-package-manager/src/npm.ts similarity index 100% rename from packages/cli/src/tools/npm.ts rename to packages/cli-package-manager/src/npm.ts diff --git a/packages/cli/src/tools/packageManager.ts b/packages/cli-package-manager/src/packageManager.ts similarity index 94% rename from packages/cli/src/tools/packageManager.ts rename to packages/cli-package-manager/src/packageManager.ts index 27b56c387..d1f02dab6 100644 --- a/packages/cli/src/tools/packageManager.ts +++ b/packages/cli-package-manager/src/packageManager.ts @@ -33,6 +33,13 @@ const packageManagers = { uninstall: ['remove'], installAll: ['install'], }, + pnpm: { + init: ['init', '-y'], + install: ['install'], + installDev: ['install', '--dev'], + uninstall: ['remove'], + installAll: ['install'], + }, }; function configurePackageManager( diff --git a/packages/cli-package-manager/src/pnpm.ts b/packages/cli-package-manager/src/pnpm.ts new file mode 100644 index 000000000..dce677b3c --- /dev/null +++ b/packages/cli-package-manager/src/pnpm.ts @@ -0,0 +1,46 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + */ + +import {execSync} from 'child_process'; +import findUp from 'find-up'; + +/** + * Use pnpm if available, it's fast and efficient. + * Return the version of pnpm installed on the system, null if pnpm is not available. + */ +export function getPnpmVersionIfAvailable() { + let pnpmVersion; + try { + // execSync returns a Buffer -> convert to string + pnpmVersion = ( + execSync('pnpm --version', { + stdio: [0, 'pipe', 'ignore'], + }).toString() || '' + ).trim(); + } catch (error) { + return null; + } + // Check for a minimum version if needed + // try { + // if (semver.gte(pnpmVersion, '3.0.0')) { + // // Adjust this version as needed + return pnpmVersion; + // } + // return null; + // } catch (error) { + // logger.error(`Cannot parse pnpm version: ${pnpmVersion}`); + // return null; + // } +} + +/** + * Check if project is using pnpm (has `pnpm-lock.yaml` in the tree) + */ +export function isProjectUsingPnpm(cwd: string) { + return findUp.sync('pnpm-lock.yaml', {cwd}); +} diff --git a/packages/cli/src/tools/yarn.ts b/packages/cli-package-manager/src/yarn.ts similarity index 100% rename from packages/cli/src/tools/yarn.ts rename to packages/cli-package-manager/src/yarn.ts diff --git a/packages/cli-package-manager/tsconfig.json b/packages/cli-package-manager/tsconfig.json new file mode 100644 index 000000000..af1413877 --- /dev/null +++ b/packages/cli-package-manager/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "build" + }, + "references": [{"path": "../cli-types"}, {"path": "../cli-tools"}] +} diff --git a/packages/cli/src/commands/init/__tests__/template.test.ts b/packages/cli/src/commands/init/__tests__/template.test.ts index f30e51dc2..2e5deaf8b 100644 --- a/packages/cli/src/commands/init/__tests__/template.test.ts +++ b/packages/cli/src/commands/init/__tests__/template.test.ts @@ -2,7 +2,7 @@ jest.mock('execa', () => jest.fn()); import execa from 'execa'; import path from 'path'; import fs from 'fs'; -import * as PackageManger from '../../../tools/packageManager'; +import * as PackageManger from '@react-native-community/cli-package-manager'; import { installTemplatePackage, getTemplateConfig, diff --git a/packages/cli/src/commands/init/init.ts b/packages/cli/src/commands/init/init.ts index f4da03370..90039d7e5 100644 --- a/packages/cli/src/commands/init/init.ts +++ b/packages/cli/src/commands/init/init.ts @@ -20,15 +20,10 @@ import { executePostInitScript, } from './template'; import {changePlaceholderInTemplate} from './editTemplate'; -import * as PackageManager from '../../tools/packageManager'; +import * as PackageManager from '@react-native-community/cli-package-manager'; import banner from './banner'; import TemplateAndVersionError from './errors/TemplateAndVersionError'; -import {getBunVersionIfAvailable} from '../../tools/bun'; -import { - getNpmVersionIfAvailable, - npmResolveConcreteVersion, -} from '../../tools/npm'; -import {getYarnVersionIfAvailable} from '../../tools/yarn'; +import {} from '@react-native-community/cli-tools'; import {createHash} from 'crypto'; import { createGitRepository, @@ -36,7 +31,6 @@ import { checkIfFolderIsGitRepo, } from './git'; import semver from 'semver'; -import {executeCommand} from '../../tools/executeCommand'; import DirectoryAlreadyExistsError from './errors/DirectoryAlreadyExistsError'; const DEFAULT_VERSION = 'latest'; @@ -89,7 +83,7 @@ const YARN_VERSION = '3.6.4'; const bumpYarnVersion = async (root: string) => { try { - let yarnVersion = semver.parse(getYarnVersionIfAvailable()); + let yarnVersion = semver.parse(PackageManager.getYarnVersionIfAvailable()); if (yarnVersion) { // `yarn set` is unsupported until 1.22, however it's a alias (yarnpkg/yarn/pull/7862) calling `policies set-version`. @@ -97,13 +91,13 @@ const bumpYarnVersion = async (root: string) => { if (yarnVersion.major === 1 && yarnVersion.minor < 22) { setVersionArgs = ['policies', 'set-version', YARN_VERSION]; } - await executeCommand('yarn', setVersionArgs, { + await PackageManager.executeCommand('yarn', setVersionArgs, { root, silent: !logger.isVerbose(), }); // React Native doesn't support PnP, so we need to set nodeLinker to node-modules. Read more here: https://github.com/react-native-community/cli/issues/27#issuecomment-1772626767 - await executeCommand( + await PackageManager.executeCommand( 'yarn', ['config', 'set', 'nodeLinker', 'node-modules'], {root, silent: !logger.isVerbose()}, @@ -387,11 +381,11 @@ function checkPackageManagerAvailability( packageManager: PackageManager.PackageManager, ) { if (packageManager === 'bun') { - return getBunVersionIfAvailable(); + return PackageManager.getBunVersionIfAvailable(); } else if (packageManager === 'npm') { - return getNpmVersionIfAvailable(); + return PackageManager.getNpmVersionIfAvailable(); } else if (packageManager === 'yarn') { - return getYarnVersionIfAvailable(); + return PackageManager.getYarnVersionIfAvailable(); } return false; @@ -532,7 +526,7 @@ export default (async function initialize( let version = options.version ?? DEFAULT_VERSION; try { - const updatedVersion = await npmResolveConcreteVersion( + const updatedVersion = await PackageManager.npmResolveConcreteVersion( options.platformName ?? 'react-native', version, ); diff --git a/packages/cli/src/commands/init/template.ts b/packages/cli/src/commands/init/template.ts index ee2adb537..5c5d06437 100644 --- a/packages/cli/src/commands/init/template.ts +++ b/packages/cli/src/commands/init/template.ts @@ -1,13 +1,12 @@ import execa from 'execa'; import path from 'path'; import {logger, CLIError} from '@react-native-community/cli-tools'; -import * as PackageManager from '../../tools/packageManager'; +import * as PackageManager from '@react-native-community/cli-package-manager'; import copyFiles from '../../tools/copyFiles'; import replacePathSepForRegex from '../../tools/replacePathSepForRegex'; import fs from 'fs'; import chalk from 'chalk'; -import {getYarnVersionIfAvailable} from '../../tools/yarn'; -import {executeCommand} from '../../tools/executeCommand'; +import {executeCommand} from '@react-native-community/cli-package-manager'; export type TemplateConfig = { placeholderName: string; @@ -30,7 +29,10 @@ export async function installTemplatePackage( root, }); - if (packageManager === 'yarn' && getYarnVersionIfAvailable() !== null) { + if ( + packageManager === 'yarn' && + PackageManager.getYarnVersionIfAvailable() !== null + ) { const options = { root, silent: true, diff --git a/packages/cli/tsconfig.json b/packages/cli/tsconfig.json index 0a064f0b7..1731a44be 100644 --- a/packages/cli/tsconfig.json +++ b/packages/cli/tsconfig.json @@ -12,6 +12,7 @@ {"path": "../cli-server-api"}, {"path": "../cli-types"}, {"path": "../cli-debugger-ui"}, - {"path": "../cli-tools"} + {"path": "../cli-tools"}, + {"path": "../cli-package-manager"} ] } diff --git a/yarn.lock b/yarn.lock index 6a6150371..a79129576 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10743,16 +10743,7 @@ string-natural-compare@^3.0.1: resolved "https://registry.yarnpkg.com/string-natural-compare/-/string-natural-compare-3.0.1.tgz#7a42d58474454963759e8e8b7ae63d71c1e7fdf4" integrity sha512-n3sPwynL1nwKi3WJ6AIsClwBMa0zTi54fn2oLU6ndfTSIO05xaznjSf15PcBZU6FNWbmN5Q6cxT4V5hGvB4taw== -"string-width-cjs@npm:string-width@^4.2.0": - version "4.2.3" - resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" - integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== - dependencies: - emoji-regex "^8.0.0" - is-fullwidth-code-point "^3.0.0" - strip-ansi "^6.0.1" - -"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: +"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: version "4.2.3" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -10847,7 +10838,7 @@ string_decoder@~1.1.1: dependencies: safe-buffer "~5.1.0" -"strip-ansi-cjs@npm:strip-ansi@^6.0.1": +"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1: version "6.0.1" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== @@ -10868,13 +10859,6 @@ strip-ansi@^5.0.0, strip-ansi@^5.2.0: dependencies: ansi-regex "^4.1.0" -strip-ansi@^6.0.0, strip-ansi@^6.0.1: - version "6.0.1" - resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" - integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== - dependencies: - ansi-regex "^5.0.1" - strip-ansi@^7.0.1: version "7.0.1" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.0.1.tgz#61740a08ce36b61e50e65653f07060d000975fb2" @@ -11753,7 +11737,7 @@ wordwrap@^1.0.0: resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb" integrity sha1-J1hIEIkUVqQXHI0CJkQa3pDLyus= -"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0": +"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: version "7.0.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== @@ -11771,15 +11755,6 @@ wrap-ansi@^6.0.1, wrap-ansi@^6.2.0: string-width "^4.1.0" strip-ansi "^6.0.0" -wrap-ansi@^7.0.0: - version "7.0.0" - resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" - integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== - dependencies: - ansi-styles "^4.0.0" - string-width "^4.1.0" - strip-ansi "^6.0.0" - wrap-ansi@^8.1.0: version "8.1.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214" From 04e4b7acec4bc55c6e6c786c28b16113f1ad0550 Mon Sep 17 00:00:00 2001 From: Arpit Bhalla <55053424+arpitBhalla@users.noreply.github.com> Date: Thu, 15 Aug 2024 20:04:52 +0530 Subject: [PATCH 2/6] remove pnpm --- packages/cli-package-manager/src/index.ts | 1 - .../cli-package-manager/src/packageManager.ts | 7 --- packages/cli-package-manager/src/pnpm.ts | 46 ------------------- 3 files changed, 54 deletions(-) delete mode 100644 packages/cli-package-manager/src/pnpm.ts diff --git a/packages/cli-package-manager/src/index.ts b/packages/cli-package-manager/src/index.ts index 9a327f919..e11fff9fb 100644 --- a/packages/cli-package-manager/src/index.ts +++ b/packages/cli-package-manager/src/index.ts @@ -1,6 +1,5 @@ export * from './bun'; export * from './npm'; -export * from './pnpm'; export * from './yarn'; export * from './packageManager'; export * from './executeCommand'; diff --git a/packages/cli-package-manager/src/packageManager.ts b/packages/cli-package-manager/src/packageManager.ts index d1f02dab6..27b56c387 100644 --- a/packages/cli-package-manager/src/packageManager.ts +++ b/packages/cli-package-manager/src/packageManager.ts @@ -33,13 +33,6 @@ const packageManagers = { uninstall: ['remove'], installAll: ['install'], }, - pnpm: { - init: ['init', '-y'], - install: ['install'], - installDev: ['install', '--dev'], - uninstall: ['remove'], - installAll: ['install'], - }, }; function configurePackageManager( diff --git a/packages/cli-package-manager/src/pnpm.ts b/packages/cli-package-manager/src/pnpm.ts deleted file mode 100644 index dce677b3c..000000000 --- a/packages/cli-package-manager/src/pnpm.ts +++ /dev/null @@ -1,46 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - */ - -import {execSync} from 'child_process'; -import findUp from 'find-up'; - -/** - * Use pnpm if available, it's fast and efficient. - * Return the version of pnpm installed on the system, null if pnpm is not available. - */ -export function getPnpmVersionIfAvailable() { - let pnpmVersion; - try { - // execSync returns a Buffer -> convert to string - pnpmVersion = ( - execSync('pnpm --version', { - stdio: [0, 'pipe', 'ignore'], - }).toString() || '' - ).trim(); - } catch (error) { - return null; - } - // Check for a minimum version if needed - // try { - // if (semver.gte(pnpmVersion, '3.0.0')) { - // // Adjust this version as needed - return pnpmVersion; - // } - // return null; - // } catch (error) { - // logger.error(`Cannot parse pnpm version: ${pnpmVersion}`); - // return null; - // } -} - -/** - * Check if project is using pnpm (has `pnpm-lock.yaml` in the tree) - */ -export function isProjectUsingPnpm(cwd: string) { - return findUp.sync('pnpm-lock.yaml', {cwd}); -} From d047334b3e07670c28ab46a0ac7ad3b77ef8dd92 Mon Sep 17 00:00:00 2001 From: Arpit Bhalla <55053424+arpitBhalla@users.noreply.github.com> Date: Thu, 15 Aug 2024 20:06:07 +0530 Subject: [PATCH 3/6] wip --- packages/cli/src/commands/init/init.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/cli/src/commands/init/init.ts b/packages/cli/src/commands/init/init.ts index 90039d7e5..24422b1d2 100644 --- a/packages/cli/src/commands/init/init.ts +++ b/packages/cli/src/commands/init/init.ts @@ -23,7 +23,6 @@ import {changePlaceholderInTemplate} from './editTemplate'; import * as PackageManager from '@react-native-community/cli-package-manager'; import banner from './banner'; import TemplateAndVersionError from './errors/TemplateAndVersionError'; -import {} from '@react-native-community/cli-tools'; import {createHash} from 'crypto'; import { createGitRepository, From 44a55c56f3fbace893e067fd26cd1ddfbe4c0f73 Mon Sep 17 00:00:00 2001 From: szymonrybczak Date: Tue, 27 Aug 2024 18:09:36 +0200 Subject: [PATCH 4/6] chore: update version --- packages/cli-package-manager/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli-package-manager/package.json b/packages/cli-package-manager/package.json index 868f2eb6a..a8a746d81 100644 --- a/packages/cli-package-manager/package.json +++ b/packages/cli-package-manager/package.json @@ -1,6 +1,6 @@ { "name": "@react-native-community/cli-package-manager", - "version": "14.0.0", + "version": "14.0.1", "license": "MIT", "main": "build/index.js", "publishConfig": { From cf18e6f7e0ac33f77496ac2279e8db4c39bc5512 Mon Sep 17 00:00:00 2001 From: szymonrybczak Date: Tue, 27 Aug 2024 18:10:04 +0200 Subject: [PATCH 5/6] fix: include `cli-package-manager` inside `packages/cli/package.json` --- packages/cli/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/cli/package.json b/packages/cli/package.json index 24d15f165..4208da52d 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -31,6 +31,7 @@ "@react-native-community/cli-server-api": "14.0.1", "@react-native-community/cli-tools": "14.0.1", "@react-native-community/cli-types": "14.0.1", + "@react-native-community/cli-package-manager": "14.0.1", "chalk": "^4.1.2", "commander": "^9.4.1", "deepmerge": "^4.3.0", From 28fac21fb1830a0415fa7c4545c7f3319daf4e5a Mon Sep 17 00:00:00 2001 From: szymonrybczak Date: Sat, 31 Aug 2024 19:44:55 +0200 Subject: [PATCH 6/6] fix: update test's mocks --- .../cli/src/commands/init/__tests__/template.test.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/commands/init/__tests__/template.test.ts b/packages/cli/src/commands/init/__tests__/template.test.ts index 2e5deaf8b..805c908b5 100644 --- a/packages/cli/src/commands/init/__tests__/template.test.ts +++ b/packages/cli/src/commands/init/__tests__/template.test.ts @@ -19,9 +19,12 @@ afterEach(() => { jest.clearAllMocks(); }); -test('installTemplatePackage', async () => { - jest.spyOn(PackageManger, 'install').mockImplementationOnce(() => null); +jest.mock('@react-native-community/cli-package-manager', () => ({ + init: jest.fn(() => null), + install: jest.fn(() => null), +})); +test('installTemplatePackage', async () => { await installTemplatePackage(TEMPLATE_NAME, TEMPLATE_SOURCE_DIR, 'npm'); expect(PackageManger.install).toHaveBeenCalledWith([TEMPLATE_NAME], { @@ -61,7 +64,9 @@ test('copyTemplate', async () => { const CWD = '.'; jest.spyOn(path, 'resolve').mockImplementationOnce((...e) => e.join('/')); - jest.spyOn(copyFiles, 'default').mockImplementationOnce(() => null); + jest + .spyOn(copyFiles, 'default') + .mockImplementationOnce(() => Promise.resolve([])); jest.spyOn(process, 'cwd').mockImplementationOnce(() => CWD); await copyTemplate(TEMPLATE_NAME, TEMPLATE_DIR, TEMPLATE_SOURCE_DIR);