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. 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;