Skip to content

Commit f71b094

Browse files
committed
Merge remote-tracking branch 'origin/main' into fix/rn-polyfills-as-runtime-modules
2 parents ab7a110 + 4023cc7 commit f71b094

8 files changed

Lines changed: 349 additions & 671 deletions

File tree

.changeset/frank-cougars-go.md

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+
Handle previous compiler errors and abort bundling in `RepackOutputPlugin`

CLAUDE.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
44

55
## Development Commands
66

7-
This is a pnpm monorepo using Nx for task orchestration. The root package.json contains the most important commands:
7+
This is a pnpm monorepo using Turborepo for task orchestration. The root package.json contains the most important commands:
88

99
**Build & Development:**
10-
- `pnpm build` - Build all packages using Nx
11-
- `pnpm dev` - Build once then watch for changes across all packages
10+
- `pnpm build` - Run a Turborepo build across workspace packages
11+
- `pnpm dev` - Run Turborepo watch mode for build across workspace packages
1212
- `pnpm lint` - Run Biome linter with auto-fix
1313
- `pnpm lint:ci` - Run Biome linter without auto-fix (CI mode)
1414
- `pnpm typecheck` - Run TypeScript checking across all packages
@@ -70,9 +70,9 @@ Re.Pack provides first-class support for Module Federation for microfrontend arc
7070

7171
## Key Development Notes
7272

73-
- This is a monorepo managed by pnpm workspaces with Nx orchestration
73+
- This is a monorepo managed by pnpm workspaces with Turborepo orchestration
7474
- The project supports both Webpack and Rspack as bundling engines
7575
- Native modules require building iOS and Android code when making changes
7676
- Always run `pnpm lint` and `pnpm typecheck` before committing changes
7777
- Use the tester apps to verify functionality across different React Native configurations
78-
- When working with native code, run `pnpm clang-format` to ensure consistent formatting
78+
- When working with native code, run `pnpm clang-format` to ensure consistent formatting

nx.json

Lines changed: 0 additions & 41 deletions
This file was deleted.

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
},
88
"scripts": {
99
"prepare": "is-in-ci || husky",
10-
"build": "nx run-many -t build",
11-
"dev": "pnpm run build && nx watch --all -- pnpm run build",
10+
"build": "turbo run build",
11+
"dev": "turbo watch build",
1212
"lint": "biome check --write",
1313
"lint:ci": "biome check",
14-
"typecheck": "nx run-many -t typecheck --exclude tests/metro-compat",
15-
"test": "nx run-many -t test",
14+
"typecheck": "turbo run typecheck",
15+
"test": "turbo run test",
1616
"release": "pnpm build && pnpm lint && pnpm test && pnpm changeset publish",
17-
"pods": "nx run-many -t pods",
18-
"pods:update": "nx run-many -t pods:update",
17+
"pods": "turbo run pods",
18+
"pods:update": "turbo run pods:update",
1919
"website:start": "pnpm --filter website run start",
2020
"website:build": "pnpm --filter website run export"
2121
},
@@ -32,7 +32,7 @@
3232
"@changesets/cli": "^2.29.4",
3333
"husky": "^9.1.6",
3434
"is-in-ci": "^1.0.0",
35-
"nx": "22.4.1",
35+
"turbo": "^2.8.10",
3636
"typescript": "catalog:"
3737
}
3838
}

packages/repack/src/plugins/OutputPlugin/OutputPlugin.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,13 @@ export class OutputPlugin {
184184
);
185185

186186
compiler.hooks.done.tapPromise('RepackOutputPlugin', async (stats) => {
187+
if (stats.hasErrors()) {
188+
throw new Error(
189+
'[RepackOutputPlugin] Compilation failed:\n' +
190+
stats.toString('errors-only')
191+
);
192+
}
193+
187194
const compilationStats = stats.toJson({
188195
all: false,
189196
assets: true,

packages/repack/src/plugins/__tests__/OutputPlugin.test.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,69 @@
1+
import fs from 'node:fs/promises';
2+
import os from 'node:os';
3+
import path from 'node:path';
14
import {
25
type EntryNormalized,
36
ModuleFilenameHelpers,
47
type StatsChunk,
8+
rspack,
59
} from '@rspack/core';
10+
import RspackVirtualModulePlugin from 'rspack-plugin-virtual-module';
611
import {
712
OutputPlugin,
813
type OutputPluginConfig,
914
} from '../OutputPlugin/index.js';
1015

16+
async function testCompile(code: string, expectThrow?: string) {
17+
// Create a temporary directory to write files to.
18+
const tempDir = await fs.mkdtemp(
19+
path.join(os.tmpdir(), 'output-plugin-test-')
20+
);
21+
22+
// And then run the compiler with the provided code.
23+
try {
24+
const compiler = rspack({
25+
context: tempDir,
26+
mode: 'production',
27+
devtool: false,
28+
entry: 'index.js',
29+
output: {
30+
filename: 'index.bundle',
31+
path: path.join(tempDir, 'out'),
32+
},
33+
plugins: [
34+
new OutputPlugin({
35+
context: tempDir,
36+
platform: 'ios',
37+
output: {},
38+
}),
39+
new RspackVirtualModulePlugin({
40+
'index.js': code,
41+
}),
42+
],
43+
});
44+
45+
const promise = new Promise<void>((resolve, reject) =>
46+
compiler.run((error, _stats) => {
47+
if (error) {
48+
reject(error);
49+
} else {
50+
resolve();
51+
}
52+
})
53+
);
54+
55+
// Depending on whether we expect an error or not, assert accordingly.
56+
if (expectThrow) {
57+
await expect(promise).rejects.toThrow(expectThrow);
58+
} else {
59+
await expect(promise).resolves.not.toThrow();
60+
}
61+
} finally {
62+
// Delete the temporary directory after the test
63+
await fs.rm(tempDir, { recursive: true, force: true });
64+
}
65+
}
66+
1167
const makeChunk = ({
1268
name,
1369
entry = false,
@@ -204,4 +260,17 @@ describe('OutputPlugin', () => {
204260
});
205261
});
206262
});
263+
264+
describe('apply', () => {
265+
it('should throw an error when compilation has errors', async () => {
266+
await testCompile(
267+
'const x = {{{',
268+
'[RepackOutputPlugin] Compilation failed:'
269+
);
270+
});
271+
272+
it('should complete successfully when compilation succeeds', async () => {
273+
await testCompile('const x = {};');
274+
});
275+
});
207276
});

0 commit comments

Comments
 (0)