Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-entry-file-required.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@callstack/repack": patch
---

Fix `--entry-file` being required even when `entry` is defined in the bundler config.
Original file line number Diff line number Diff line change
@@ -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',
},
},
},
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ export function getCliOverrides<C extends ConfigurationObject>(
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 = {
Expand Down
2 changes: 1 addition & 1 deletion packages/repack/src/commands/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { EnvOptions } from '../types.js';

export interface BundleArguments {
entryFile: string;
entryFile?: string;
platform: string;
dev: boolean;
minify?: boolean;
Expand Down