Skip to content

Commit e283ccf

Browse files
ilteoooddannyhw
andauthored
fix(repack): wrap babel-loader fallback value in an array (#1456)
Co-authored-by: Daniel Williams <dannyhyunsoowilliams@gmail.com>
1 parent 56dbfe7 commit e283ccf

3 files changed

Lines changed: 37 additions & 1 deletion

File tree

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+
Fix `BabelPlugin` to set the `babel-loader` entry of `resolveLoader.fallback` as an array containing the resolved path, instead of a plain string. Rspack's resolver and downstream tools that consume the resolved loader config (e.g. `RSDoctor`) expect the value to be an array; a bare string triggered `Given napi value is not an array on NapiResolveOptions.fallback`. This still matches Rspack's `ResolveAlias` (`{ [x: string]: string | false | (string | false)[] }`) and Webpack's resolver loader fallback shape.

‎packages/repack/src/plugins/BabelPlugin.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Compiler as RspackCompiler } from '@rspack/core';
22
import type { Compiler as WebpackCompiler } from 'webpack';
3+
34
/**
45
* Plugin that adds babel-loader fallback to resolveLoader configuration.
56
* This ensures babel-loader can be resolved regardless of the package manager used,
@@ -18,7 +19,7 @@ export class BabelPlugin {
1819
...compiler.options.resolveLoader,
1920
fallback: {
2021
...compiler.options.resolveLoader?.fallback,
21-
'babel-loader': require.resolve('babel-loader'),
22+
'babel-loader': [require.resolve('babel-loader')],
2223
},
2324
};
2425
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import type { Compiler } from '@rspack/core';
2+
import { BabelPlugin } from '../BabelPlugin.js';
3+
4+
const compilerMock: { options: Compiler['options'] } = {
5+
options: {} as Compiler['options'],
6+
};
7+
8+
describe('BabelPlugin', () => {
9+
it('sets resolveLoader.fallback[babel-loader] as an array entry', () => {
10+
const pluginInstance = new BabelPlugin();
11+
pluginInstance.apply(compilerMock as unknown as Compiler);
12+
13+
expect(compilerMock.options.resolveLoader?.fallback).toEqual({
14+
'babel-loader': [expect.any(String)],
15+
});
16+
});
17+
18+
it('preserves existing record fallback entries', () => {
19+
compilerMock.options.resolveLoader = {
20+
fallback: { 'foo-loader': '/path/to/foo-loader' },
21+
};
22+
const pluginInstance = new BabelPlugin();
23+
pluginInstance.apply(compilerMock as unknown as Compiler);
24+
25+
expect(compilerMock.options.resolveLoader.fallback).toEqual({
26+
'foo-loader': '/path/to/foo-loader',
27+
'babel-loader': [expect.any(String)],
28+
});
29+
});
30+
});

0 commit comments

Comments
 (0)