From 452125a6a6d57c11b959d9eab5e8e995583541fe Mon Sep 17 00:00:00 2001 From: Jakub Romanczyk Date: Wed, 12 Mar 2025 18:39:09 +0100 Subject: [PATCH 1/5] chore: remove RNC CLI peer deps --- packages/repack/package.json | 6 ------ packages/repack/src/commands/rspack/bundle.ts | 5 ++--- packages/repack/src/commands/rspack/start.ts | 5 ++--- packages/repack/src/commands/types.ts | 17 ++++++++--------- packages/repack/src/commands/webpack/bundle.ts | 5 ++--- packages/repack/src/commands/webpack/start.ts | 5 ++--- pnpm-lock.yaml | 9 --------- 7 files changed, 16 insertions(+), 36 deletions(-) diff --git a/packages/repack/package.json b/packages/repack/package.json index fd8bb650e..4913da3df 100644 --- a/packages/repack/package.json +++ b/packages/repack/package.json @@ -59,9 +59,6 @@ }, "peerDependencies": { "@module-federation/enhanced": ">=0.6.10", - "@react-native-community/cli": "*", - "@react-native-community/cli-tools": "*", - "@react-native-community/cli-types": "*", "@rspack/core": ">=1", "react-native": ">=0.74", "webpack": ">=5.90" @@ -107,9 +104,6 @@ "@babel/plugin-transform-modules-commonjs": "^7.23.2", "@module-federation/enhanced": "0.8.9", "@module-federation/sdk": "0.6.10", - "@react-native-community/cli": "15.0.1", - "@react-native-community/cli-tools": "15.0.1", - "@react-native-community/cli-types": "15.0.1", "@rspack/core": "catalog:", "@swc/helpers": "catalog:", "@types/dedent": "^0.7.0", diff --git a/packages/repack/src/commands/rspack/bundle.ts b/packages/repack/src/commands/rspack/bundle.ts index 796b25307..604a7d0df 100644 --- a/packages/repack/src/commands/rspack/bundle.ts +++ b/packages/repack/src/commands/rspack/bundle.ts @@ -1,11 +1,10 @@ -import type { Config } from '@react-native-community/cli-types'; import { type Configuration, rspack } from '@rspack/core'; import type { Stats } from '@rspack/core'; import { makeCompilerConfig } from '../common/config/makeCompilerConfig.js'; import { CLIError } from '../common/error.js'; import { normalizeStatsOptions, writeStats } from '../common/index.js'; import { setupEnvironment } from '../common/setupEnvironment.js'; -import type { BundleArguments } from '../types.js'; +import type { BundleArguments, CliConfig } from '../types.js'; /** * Bundle command for React Native Community CLI. @@ -21,7 +20,7 @@ import type { BundleArguments } from '../types.js'; */ export async function bundle( _: string[], - cliConfig: Config, + cliConfig: CliConfig, args: BundleArguments ) { const [config] = await makeCompilerConfig({ diff --git a/packages/repack/src/commands/rspack/start.ts b/packages/repack/src/commands/rspack/start.ts index ec6d1ddf8..772fcdcf0 100644 --- a/packages/repack/src/commands/rspack/start.ts +++ b/packages/repack/src/commands/rspack/start.ts @@ -1,4 +1,3 @@ -import type { Config } from '@react-native-community/cli-types'; import type { Configuration } from '@rspack/core'; import packageJson from '../../../package.json'; import { @@ -18,7 +17,7 @@ import { import { runAdbReverse } from '../common/index.js'; import logo from '../common/logo.js'; import { setupEnvironment } from '../common/setupEnvironment.js'; -import type { StartArguments } from '../types.js'; +import type { CliConfig, StartArguments } from '../types.js'; import { Compiler } from './Compiler.js'; /** @@ -35,7 +34,7 @@ import { Compiler } from './Compiler.js'; */ export async function start( _: string[], - cliConfig: Config, + cliConfig: CliConfig, args: StartArguments ) { const detectedPlatforms = Object.keys(cliConfig.platforms); diff --git a/packages/repack/src/commands/types.ts b/packages/repack/src/commands/types.ts index b862e92ea..c1eafc250 100644 --- a/packages/repack/src/commands/types.ts +++ b/packages/repack/src/commands/types.ts @@ -33,22 +33,21 @@ export interface StartArguments { webpackConfig?: string; } -interface CommonCliOptions { - config: { - root: string; - platforms: string[]; - bundlerConfigPath: string; - reactNativePath: string; - }; +export interface CliConfig { + root: string; + platforms: string[]; + reactNativePath: string; } -export interface StartCliOptions extends CommonCliOptions { +export interface StartCliOptions { command: 'start'; + config: CliConfig; arguments: { start: StartArguments }; } -export interface BundleCliOptions extends CommonCliOptions { +export interface BundleCliOptions { command: 'bundle'; + config: CliConfig; arguments: { bundle: BundleArguments }; } diff --git a/packages/repack/src/commands/webpack/bundle.ts b/packages/repack/src/commands/webpack/bundle.ts index 201d1b6ad..3b9dd3ab5 100644 --- a/packages/repack/src/commands/webpack/bundle.ts +++ b/packages/repack/src/commands/webpack/bundle.ts @@ -1,10 +1,9 @@ -import type { Config } from '@react-native-community/cli-types'; import webpack, { type Configuration } from 'webpack'; import { makeCompilerConfig } from '../common/config/makeCompilerConfig.js'; import { CLIError } from '../common/error.js'; import { normalizeStatsOptions, writeStats } from '../common/index.js'; import { setupEnvironment } from '../common/setupEnvironment.js'; -import type { BundleArguments } from '../types.js'; +import type { BundleArguments, CliConfig } from '../types.js'; /** * Bundle command for React Native Community CLI. * It runs Webpack, builds bundle and saves it alongside any other assets and Source Map @@ -19,7 +18,7 @@ import type { BundleArguments } from '../types.js'; */ export async function bundle( _: string[], - cliConfig: Config, + cliConfig: CliConfig, args: BundleArguments ) { const [config] = await makeCompilerConfig({ diff --git a/packages/repack/src/commands/webpack/start.ts b/packages/repack/src/commands/webpack/start.ts index 7303c9afe..bc6018648 100644 --- a/packages/repack/src/commands/webpack/start.ts +++ b/packages/repack/src/commands/webpack/start.ts @@ -1,6 +1,5 @@ // @ts-expect-error type-only import import type { Server } from '@callstack/repack-dev-server'; -import type { Config } from '@react-native-community/cli-types'; import type { Configuration, StatsCompilation } from 'webpack'; import packageJson from '../../../package.json'; import { @@ -21,7 +20,7 @@ import { } from '../common/index.js'; import logo from '../common/logo.js'; import { setupEnvironment } from '../common/setupEnvironment.js'; -import type { StartArguments } from '../types.js'; +import type { CliConfig, StartArguments } from '../types.js'; import { Compiler } from './Compiler.js'; /** @@ -38,7 +37,7 @@ import { Compiler } from './Compiler.js'; */ export async function start( _: string[], - cliConfig: Config, + cliConfig: CliConfig, args: StartArguments ) { const detectedPlatforms = Object.keys(cliConfig.platforms); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ea0676f61..693fd779d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -592,15 +592,6 @@ importers: '@module-federation/sdk': specifier: 0.6.10 version: 0.6.10 - '@react-native-community/cli': - specifier: 15.0.1 - version: 15.0.1(typescript@5.7.2) - '@react-native-community/cli-tools': - specifier: 15.0.1 - version: 15.0.1 - '@react-native-community/cli-types': - specifier: 15.0.1 - version: 15.0.1 '@rspack/core': specifier: 'catalog:' version: 1.2.7(@swc/helpers@0.5.15) From 4f144c6bd2fada95d38e54e9eb4ed7a20d02757c Mon Sep 17 00:00:00 2001 From: Jakub Romanczyk Date: Wed, 12 Mar 2025 18:46:41 +0100 Subject: [PATCH 2/5] refactor: cli error --- packages/repack/src/commands/common/cliError.ts | 13 +++++++++++++ .../src/commands/common/config/getConfigFilePath.ts | 2 +- packages/repack/src/commands/common/error.ts | 11 ----------- packages/repack/src/commands/rspack/Compiler.ts | 2 +- packages/repack/src/commands/rspack/bundle.ts | 2 +- packages/repack/src/commands/rspack/start.ts | 2 +- packages/repack/src/commands/webpack/Compiler.ts | 2 +- packages/repack/src/commands/webpack/bundle.ts | 2 +- packages/repack/src/commands/webpack/start.ts | 2 +- 9 files changed, 20 insertions(+), 18 deletions(-) create mode 100644 packages/repack/src/commands/common/cliError.ts delete mode 100644 packages/repack/src/commands/common/error.ts diff --git a/packages/repack/src/commands/common/cliError.ts b/packages/repack/src/commands/common/cliError.ts new file mode 100644 index 000000000..92dfb71c1 --- /dev/null +++ b/packages/repack/src/commands/common/cliError.ts @@ -0,0 +1,13 @@ +import { VERBOSE_ENV_KEY } from '../../env.js'; + +export class CLIError extends Error { + constructor(message: string) { + super(message); + this.name = 'CLIError'; + + // hide stack trace in non-verbose mode + if (!process.env[VERBOSE_ENV_KEY]) { + this.stack = undefined; + } + } +} diff --git a/packages/repack/src/commands/common/config/getConfigFilePath.ts b/packages/repack/src/commands/common/config/getConfigFilePath.ts index 4c3d553f1..a5109c00e 100644 --- a/packages/repack/src/commands/common/config/getConfigFilePath.ts +++ b/packages/repack/src/commands/common/config/getConfigFilePath.ts @@ -6,7 +6,7 @@ import { DEFAULT_RSPACK_CONFIG_LOCATIONS, DEFAULT_WEBPACK_CONFIG_LOCATIONS, } from '../../consts.js'; -import { CLIError } from '../error.js'; +import { CLIError } from '../cliError.js'; function discoverConfigFilePath(root: string, candidates: string[]) { for (const candidate of candidates) { diff --git a/packages/repack/src/commands/common/error.ts b/packages/repack/src/commands/common/error.ts deleted file mode 100644 index 8ccd8451b..000000000 --- a/packages/repack/src/commands/common/error.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { logger } from '@react-native-community/cli-tools'; - -export class CLIError extends Error { - constructor(message: string) { - super(message); - this.name = `${message}`; - logger.debug(this.stack ?? ''); - // Setting stack to undefined to avoid stack trace - this.stack = undefined; - } -} diff --git a/packages/repack/src/commands/rspack/Compiler.ts b/packages/repack/src/commands/rspack/Compiler.ts index 0c4734f84..e215a4504 100644 --- a/packages/repack/src/commands/rspack/Compiler.ts +++ b/packages/repack/src/commands/rspack/Compiler.ts @@ -11,7 +11,7 @@ import type { import memfs from 'memfs'; import type { Reporter } from '../../logging/types.js'; import type { HMRMessage } from '../../types.js'; -import { CLIError } from '../common/error.js'; +import { CLIError } from '../common/cliError.js'; import { adaptFilenameToPlatform, runAdbReverse } from '../common/index.js'; import { DEV_SERVER_ASSET_TYPES } from '../consts.js'; import type { CompilerAsset } from './types.js'; diff --git a/packages/repack/src/commands/rspack/bundle.ts b/packages/repack/src/commands/rspack/bundle.ts index 604a7d0df..d81d5afdc 100644 --- a/packages/repack/src/commands/rspack/bundle.ts +++ b/packages/repack/src/commands/rspack/bundle.ts @@ -1,7 +1,7 @@ import { type Configuration, rspack } from '@rspack/core'; import type { Stats } from '@rspack/core'; +import { CLIError } from '../common/cliError.js'; import { makeCompilerConfig } from '../common/config/makeCompilerConfig.js'; -import { CLIError } from '../common/error.js'; import { normalizeStatsOptions, writeStats } from '../common/index.js'; import { setupEnvironment } from '../common/setupEnvironment.js'; import type { BundleArguments, CliConfig } from '../types.js'; diff --git a/packages/repack/src/commands/rspack/start.ts b/packages/repack/src/commands/rspack/start.ts index 772fcdcf0..7a44da17c 100644 --- a/packages/repack/src/commands/rspack/start.ts +++ b/packages/repack/src/commands/rspack/start.ts @@ -7,8 +7,8 @@ import { composeReporters, makeLogEntryFromFastifyLog, } from '../../logging/index.js'; +import { CLIError } from '../common/cliError.js'; import { makeCompilerConfig } from '../common/config/makeCompilerConfig.js'; -import { CLIError } from '../common/error.js'; import { getMimeType, parseFileUrl, diff --git a/packages/repack/src/commands/webpack/Compiler.ts b/packages/repack/src/commands/webpack/Compiler.ts index 9a0c1904f..724e24831 100644 --- a/packages/repack/src/commands/webpack/Compiler.ts +++ b/packages/repack/src/commands/webpack/Compiler.ts @@ -7,7 +7,7 @@ import type { SendProgress } from '@callstack/repack-dev-server'; import type webpack from 'webpack'; import { WORKER_ENV_KEY } from '../../env.js'; import type { LogType, Reporter } from '../../logging/types.js'; -import { CLIError } from '../common/error.js'; +import { CLIError } from '../common/cliError.js'; import { DEV_SERVER_ASSET_TYPES } from '../consts.js'; import type { StartArguments } from '../types.js'; import type { diff --git a/packages/repack/src/commands/webpack/bundle.ts b/packages/repack/src/commands/webpack/bundle.ts index 3b9dd3ab5..ee5a3dbf3 100644 --- a/packages/repack/src/commands/webpack/bundle.ts +++ b/packages/repack/src/commands/webpack/bundle.ts @@ -1,6 +1,6 @@ import webpack, { type Configuration } from 'webpack'; +import { CLIError } from '../common/cliError.js'; import { makeCompilerConfig } from '../common/config/makeCompilerConfig.js'; -import { CLIError } from '../common/error.js'; import { normalizeStatsOptions, writeStats } from '../common/index.js'; import { setupEnvironment } from '../common/setupEnvironment.js'; import type { BundleArguments, CliConfig } from '../types.js'; diff --git a/packages/repack/src/commands/webpack/start.ts b/packages/repack/src/commands/webpack/start.ts index bc6018648..3d129ff43 100644 --- a/packages/repack/src/commands/webpack/start.ts +++ b/packages/repack/src/commands/webpack/start.ts @@ -10,8 +10,8 @@ import { makeLogEntryFromFastifyLog, } from '../../logging/index.js'; import type { HMRMessage } from '../../types.js'; +import { CLIError } from '../common/cliError.js'; import { makeCompilerConfig } from '../common/config/makeCompilerConfig.js'; -import { CLIError } from '../common/error.js'; import { getMimeType, parseFileUrl, From 69f32eb119ef294d0c4a71dd6113a2bfc73872dd Mon Sep 17 00:00:00 2001 From: Jakub Romanczyk Date: Wed, 12 Mar 2025 18:50:53 +0100 Subject: [PATCH 3/5] chore: changeset --- .changeset/shy-impalas-join.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/shy-impalas-join.md diff --git a/.changeset/shy-impalas-join.md b/.changeset/shy-impalas-join.md new file mode 100644 index 000000000..90ab87568 --- /dev/null +++ b/.changeset/shy-impalas-join.md @@ -0,0 +1,5 @@ +--- +"@callstack/repack": minor +--- + +Drop having `@react-native-community/cli` as peer dependency From 2c9001d72e67abbab3676ef12c9cb092e61a64a3 Mon Sep 17 00:00:00 2001 From: Jakub Romanczyk Date: Wed, 12 Mar 2025 19:02:24 +0100 Subject: [PATCH 4/5] chore: cleanup jsdocs --- packages/repack/src/commands/rspack/bundle.ts | 10 +++------- packages/repack/src/commands/rspack/start.ts | 9 +++------ packages/repack/src/commands/webpack/bundle.ts | 10 +++------- packages/repack/src/commands/webpack/start.ts | 9 +++------ 4 files changed, 12 insertions(+), 26 deletions(-) diff --git a/packages/repack/src/commands/rspack/bundle.ts b/packages/repack/src/commands/rspack/bundle.ts index d81d5afdc..8a7a7b614 100644 --- a/packages/repack/src/commands/rspack/bundle.ts +++ b/packages/repack/src/commands/rspack/bundle.ts @@ -7,16 +7,12 @@ import { setupEnvironment } from '../common/setupEnvironment.js'; import type { BundleArguments, CliConfig } from '../types.js'; /** - * Bundle command for React Native Community CLI. - * It runs Rspack, builds bundle and saves it alongside any other assets and Source Map - * to filesystem. + * Bundle command that builds and saves the bundle + * alongside any other assets to filesystem using Webpack. * * @param _ Original, non-parsed arguments that were provided when running this command. - * @param config React Native Community CLI configuration object. + * @param cliConfig Configuration object containing platform and project settings. * @param args Parsed command line arguments. - * - * @internal - * @category CLI command */ export async function bundle( _: string[], diff --git a/packages/repack/src/commands/rspack/start.ts b/packages/repack/src/commands/rspack/start.ts index 7a44da17c..eb5e84b70 100644 --- a/packages/repack/src/commands/rspack/start.ts +++ b/packages/repack/src/commands/rspack/start.ts @@ -21,16 +21,13 @@ import type { CliConfig, StartArguments } from '../types.js'; import { Compiler } from './Compiler.js'; /** - * Start command for React Native Community CLI. - * It runs `@callstack/repack-dev-server` to provide Development Server functionality to React Native apps + * Start command that runs a development server. + * It runs `@callstack/repack-dev-server` to provide Development Server functionality * in development mode. * * @param _ Original, non-parsed arguments that were provided when running this command. - * @param config React Native Community CLI configuration object. + * @param cliConfig Configuration object containing platform and project settings. * @param args Parsed command line arguments. - * - * @internal - * @category CLI command */ export async function start( _: string[], diff --git a/packages/repack/src/commands/webpack/bundle.ts b/packages/repack/src/commands/webpack/bundle.ts index ee5a3dbf3..ad1a9d9fc 100644 --- a/packages/repack/src/commands/webpack/bundle.ts +++ b/packages/repack/src/commands/webpack/bundle.ts @@ -5,16 +5,12 @@ import { normalizeStatsOptions, writeStats } from '../common/index.js'; import { setupEnvironment } from '../common/setupEnvironment.js'; import type { BundleArguments, CliConfig } from '../types.js'; /** - * Bundle command for React Native Community CLI. - * It runs Webpack, builds bundle and saves it alongside any other assets and Source Map - * to filesystem. + * Bundle command that builds and saves the bundle + * alongside any other assets to filesystem using Webpack. * * @param _ Original, non-parsed arguments that were provided when running this command. - * @param config React Native Community CLI configuration object. + * @param cliConfig Configuration object containing platform and project settings. * @param args Parsed command line arguments. - * - * @internal - * @category CLI command */ export async function bundle( _: string[], diff --git a/packages/repack/src/commands/webpack/start.ts b/packages/repack/src/commands/webpack/start.ts index 3d129ff43..614cda423 100644 --- a/packages/repack/src/commands/webpack/start.ts +++ b/packages/repack/src/commands/webpack/start.ts @@ -24,16 +24,13 @@ import type { CliConfig, StartArguments } from '../types.js'; import { Compiler } from './Compiler.js'; /** - * Start command for React Native Community CLI. - * It runs `@callstack/repack-dev-server` to provide Development Server functionality to React Native apps + * Start command that runs a development server. + * It runs `@callstack/repack-dev-server` to provide Development Server functionality * in development mode. * * @param _ Original, non-parsed arguments that were provided when running this command. - * @param config React Native Community CLI configuration object. + * @param cliConfig Configuration object containing platform and project settings. * @param args Parsed command line arguments. - * - * @internal - * @category CLI command */ export async function start( _: string[], From 09d477e40408bd7fc12259d8d5a8c982a4cdcb5a Mon Sep 17 00:00:00 2001 From: Jakub Romanczyk Date: Wed, 12 Mar 2025 19:17:45 +0100 Subject: [PATCH 5/5] chore: update changeset --- .changeset/shy-impalas-join.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/shy-impalas-join.md b/.changeset/shy-impalas-join.md index 90ab87568..4c8d8902c 100644 --- a/.changeset/shy-impalas-join.md +++ b/.changeset/shy-impalas-join.md @@ -1,5 +1,5 @@ --- -"@callstack/repack": minor +"@callstack/repack": patch --- Drop having `@react-native-community/cli` as peer dependency