Skip to content

Commit 8dcc116

Browse files
authored
refactor(commands): unify webpack and Rspack commands (#1424)
1 parent 7a4a36f commit 8dcc116

36 files changed

Lines changed: 664 additions & 622 deletions
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@callstack/repack": patch
3+
---
4+
5+
Reject pending webpack asset requests when compilation fails instead of leaving requests hanging.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@callstack/repack": minor
3+
"@callstack/repack-init": patch
4+
---
5+
6+
Add the unified `@callstack/repack/commands` entry point with automatic bundler detection and a `--bundler` override. Re.Pack Init now uses it, while bundler-specific entry points remain available with deprecation warnings.

‎apps/tester-app/__tests__/bundle.test.ts‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import fs from 'node:fs';
22
import path from 'node:path';
3-
import rspackCommands from '@callstack/repack/commands/rspack';
4-
import webpackCommands from '@callstack/repack/commands/webpack';
3+
import commands from '@callstack/repack/commands';
54
import { globby } from 'globby';
65
import {
76
afterEach,
@@ -17,15 +16,13 @@ describe('bundle command', () => {
1716
describe.each([
1817
{
1918
bundler: 'webpack',
20-
commands: webpackCommands,
2119
configFile: './webpack.config.mjs',
2220
},
2321
{
2422
bundler: 'rspack',
25-
commands: rspackCommands,
2623
configFile: './rspack.config.mjs',
2724
},
28-
])('using $bundler', ({ bundler, commands, configFile }) => {
25+
])('using $bundler', ({ bundler, configFile }) => {
2926
const bundleCommand = commands.find((command) => command.name === 'bundle');
3027
if (!bundleCommand) throw new Error('bundle command not found');
3128

‎apps/tester-app/__tests__/start.test.ts‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import fs from 'node:fs';
22
import path from 'node:path';
3-
import rspackCommands from '@callstack/repack/commands/rspack';
4-
import webpackCommands from '@callstack/repack/commands/webpack';
3+
import commands from '@callstack/repack/commands';
54
import getPort from 'get-port';
65
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
76

@@ -12,15 +11,13 @@ describe('start command', () => {
1211
describe.each([
1312
{
1413
bundler: 'webpack',
15-
commands: webpackCommands,
1614
configFile: './webpack.config.mjs',
1715
},
1816
{
1917
bundler: 'rspack',
20-
commands: rspackCommands,
2118
configFile: './rspack.config.mjs',
2219
},
23-
])('using $bundler', ({ bundler, commands, configFile }) => {
20+
])('using $bundler', ({ bundler, configFile }) => {
2421
const startCommand = commands.find((command) => command.name === 'start');
2522
if (!startCommand) throw new Error('start command not found');
2623

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
const { configureProjects } = require('react-native-test-app');
22

3-
const useWebpack = Boolean(process.env.USE_WEBPACK);
4-
53
module.exports = {
64
project: configureProjects({
75
android: {
@@ -11,7 +9,5 @@ module.exports = {
119
sourceDir: 'ios',
1210
},
1311
}),
14-
commands: useWebpack
15-
? require('@callstack/repack/commands/webpack')
16-
: require('@callstack/repack/commands/rspack'),
12+
commands: require('@callstack/repack/commands'),
1713
};
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
const { configureProjects } = require('react-native-test-app');
22

3-
const useWebpack = Boolean(process.env.USE_WEBPACK);
4-
53
module.exports = {
64
project: configureProjects({
75
android: {
@@ -11,7 +9,5 @@ module.exports = {
119
sourceDir: 'ios',
1210
},
1311
}),
14-
commands: useWebpack
15-
? require('@callstack/repack/commands/webpack')
16-
: require('@callstack/repack/commands/rspack'),
12+
commands: require('@callstack/repack/commands'),
1713
};
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
const { configureProjects } = require('react-native-test-app');
22

3-
const useWebpack = Boolean(process.env.USE_WEBPACK);
4-
53
module.exports = {
64
project: configureProjects({
75
android: {
@@ -11,7 +9,5 @@ module.exports = {
119
sourceDir: 'ios',
1210
},
1311
}),
14-
commands: useWebpack
15-
? require('@callstack/repack/commands/webpack')
16-
: require('@callstack/repack/commands/rspack'),
12+
commands: require('@callstack/repack/commands'),
1713
};

‎packages/init/src/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export default async function run(options: Options) {
6565
options.entry
6666
);
6767

68-
modifyReactNativeConfig(bundler, projectRootDir);
68+
modifyReactNativeConfig(projectRootDir);
6969

7070
modifyIOS(projectRootDir);
7171

‎packages/init/src/tasks/modifyReactNativeConfig.ts‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,23 @@ import path from 'node:path';
33
import dedent from 'dedent';
44
import logger from '../utils/logger.js';
55

6-
const createDefaultConfig = (bundler: 'rspack' | 'webpack') => dedent`
6+
const COMMANDS_REQUIRE = `require('@callstack/repack/commands')`;
7+
8+
const createDefaultConfig = () => dedent`
79
module.exports = {
8-
commands: require('@callstack/repack/commands/${bundler}'),
10+
commands: ${COMMANDS_REQUIRE},
911
};`;
1012

1113
/**
1214
* Checks whether react-native.config.js exists and adds the commands to it
1315
*
1416
* @param cwd current working directory
1517
*/
16-
export default function modifyReactNativeConfig(
17-
bundler: 'rspack' | 'webpack',
18-
cwd: string
19-
): void {
18+
export default function modifyReactNativeConfig(cwd: string): void {
2019
const configPath = path.join(cwd, 'react-native.config.js');
2120

2221
if (!fs.existsSync(configPath)) {
23-
fs.writeFileSync(configPath, createDefaultConfig(bundler));
22+
fs.writeFileSync(configPath, createDefaultConfig());
2423
logger.info('Created react-native.config.js');
2524
return;
2625
}
@@ -31,14 +30,14 @@ export default function modifyReactNativeConfig(
3130
if (!configContent.includes('commands:')) {
3231
updatedConfigContent = configContent.replace(
3332
'module.exports = {',
34-
`module.exports = {\n commands: require('@callstack/repack/commands/${bundler}'),`
33+
`module.exports = {\n commands: ${COMMANDS_REQUIRE},`
3534
);
3635
} else {
3736
const commandsIndex = configContent.indexOf('commands:');
3837
const commandsEndIndex = configContent.indexOf(',', commandsIndex);
3938
const commandsString = configContent.slice(commandsIndex, commandsEndIndex);
4039

41-
const newCommandsString = `commands: require('@callstack/repack/commands/${bundler}')`;
40+
const newCommandsString = `commands: ${COMMANDS_REQUIRE}`;
4241
if (commandsString === newCommandsString) {
4342
logger.info('File react-native.config.js is already up to date');
4443
return;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import commands from '../dist/commands/index.js';
2+
export = commands;

0 commit comments

Comments
 (0)