From ccf22d791f2fce6fd42dcfcb86d656daea8b7da3 Mon Sep 17 00:00:00 2001 From: Jakub Romanczyk Date: Thu, 26 Feb 2026 13:23:15 +0100 Subject: [PATCH 1/2] fix: guard entry override in getCliOverrides when --entry-file is omitted When --entry-file is not provided, bundleArgs.entryFile is undefined at runtime. The unconditional call to normalizeEntryFile(undefined) crashes with a TypeError before the validation in bundle() can check whether entry is defined in the user's config. Guard the entry override behind an if-check (matching the existing pattern in getEnvOptions) so that omitting --entry-file lets the user's config-defined entry take effect as documented. Co-Authored-By: Claude Opus 4.6 --- .../config/__tests__/getCliOverrides.test.ts | 119 ++++++++++++++++++ .../commands/common/config/getCliOverrides.ts | 4 +- packages/repack/src/commands/types.ts | 2 +- 3 files changed, 123 insertions(+), 2 deletions(-) create mode 100644 packages/repack/src/commands/common/config/__tests__/getCliOverrides.test.ts diff --git a/packages/repack/src/commands/common/config/__tests__/getCliOverrides.test.ts b/packages/repack/src/commands/common/config/__tests__/getCliOverrides.test.ts new file mode 100644 index 000000000..2bc86efc5 --- /dev/null +++ b/packages/repack/src/commands/common/config/__tests__/getCliOverrides.test.ts @@ -0,0 +1,119 @@ +import { getCliOverrides } from '../getCliOverrides.js'; + +describe('getCliOverrides', () => { + describe('bundle command', () => { + it('should return overrides with entry when entryFile is provided', () => { + expect( + getCliOverrides({ + args: { + platform: 'ios', + dev: false, + minify: true, + entryFile: 'index.js', + }, + command: 'bundle', + }) + ).toEqual({ + mode: 'production', + optimization: { minimize: true }, + entry: './index.js', + }); + }); + + it('should normalize relative entryFile to start with ./', () => { + expect( + getCliOverrides({ + args: { platform: 'ios', dev: true, entryFile: 'src/main.js' }, + command: 'bundle', + }) + ).toEqual({ + mode: 'development', + optimization: { minimize: undefined }, + entry: './src/main.js', + }); + }); + + it('should preserve absolute entryFile as-is', () => { + expect( + getCliOverrides({ + args: { platform: 'ios', dev: false, entryFile: '/app/src/index.js' }, + command: 'bundle', + }) + ).toEqual({ + mode: 'production', + optimization: { minimize: undefined }, + entry: '/app/src/index.js', + }); + }); + + it('should preserve entryFile starting with ./ as-is', () => { + expect( + getCliOverrides({ + args: { platform: 'ios', dev: false, entryFile: './src/index.js' }, + command: 'bundle', + }) + ).toEqual({ + mode: 'production', + optimization: { minimize: undefined }, + entry: './src/index.js', + }); + }); + + it('should not set entry when entryFile is omitted', () => { + const result = getCliOverrides({ + args: { platform: 'ios', dev: false }, + command: 'bundle', + }); + + expect(result).toEqual({ + mode: 'production', + optimization: { minimize: undefined }, + }); + expect(result).not.toHaveProperty('entry'); + }); + }); + + describe('start command', () => { + it('should return devServer overrides', () => { + expect( + getCliOverrides({ + args: { host: 'localhost', port: 8081 }, + command: 'start', + }) + ).toEqual({ + devServer: { + port: 8081, + host: 'localhost', + server: undefined, + }, + }); + }); + + it('should include https server config when https is enabled', () => { + expect( + getCliOverrides({ + args: { + host: 'localhost', + port: 8081, + https: true, + key: '/path/to/key.pem', + cert: '/path/to/cert.pem', + }, + command: 'start', + }) + ).toEqual({ + devServer: { + port: 8081, + host: 'localhost', + server: { + type: 'https', + options: { + key: '/path/to/key.pem', + cert: '/path/to/cert.pem', + }, + }, + }, + }); + }); + }); +}); diff --git a/packages/repack/src/commands/common/config/getCliOverrides.ts b/packages/repack/src/commands/common/config/getCliOverrides.ts index 6b6839ed7..5c4b4cb30 100644 --- a/packages/repack/src/commands/common/config/getCliOverrides.ts +++ b/packages/repack/src/commands/common/config/getCliOverrides.ts @@ -25,7 +25,9 @@ export function getCliOverrides( const bundleArgs = opts.args as BundleArguments; overrides.mode = bundleArgs.dev ? 'development' : 'production'; overrides.optimization = { minimize: bundleArgs.minify }; - overrides.entry = normalizeEntryFile(bundleArgs.entryFile); + if (bundleArgs.entryFile) { + overrides.entry = normalizeEntryFile(bundleArgs.entryFile); + } } else { const startArgs = opts.args as StartArguments; overrides.devServer = { diff --git a/packages/repack/src/commands/types.ts b/packages/repack/src/commands/types.ts index 73c5cd683..2cdc7b18e 100644 --- a/packages/repack/src/commands/types.ts +++ b/packages/repack/src/commands/types.ts @@ -1,7 +1,7 @@ import type { EnvOptions } from '../types.js'; export interface BundleArguments { - entryFile: string; + entryFile?: string; platform: string; dev: boolean; minify?: boolean; From 0720abeb86ea1c03207c12ecbeb603d2d148de52 Mon Sep 17 00:00:00 2001 From: Jakub Romanczyk Date: Thu, 26 Feb 2026 13:24:46 +0100 Subject: [PATCH 2/2] chore: add changeset for entry-file fix Co-Authored-By: Claude Opus 4.6 --- .changeset/fix-entry-file-required.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/fix-entry-file-required.md diff --git a/.changeset/fix-entry-file-required.md b/.changeset/fix-entry-file-required.md new file mode 100644 index 000000000..4a5ca6ce1 --- /dev/null +++ b/.changeset/fix-entry-file-required.md @@ -0,0 +1,5 @@ +--- +"@callstack/repack": patch +--- + +Fix `--entry-file` being required even when `entry` is defined in the bundler config.