-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathbabel.config.js
More file actions
60 lines (59 loc) · 2.81 KB
/
Copy pathbabel.config.js
File metadata and controls
60 lines (59 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
module.exports = function (api) {
// Keyed on the environment rather than cached forever, because the config is
// no longer identical across environments — see the jest-only plugin below.
// `api.env()` configures the cache itself, so the `api.cache(true)` that used
// to be on the line above is gone rather than kept alongside it: calling
// `api.cache(true)` FIRST and then `api.env()` throws "Caching has already
// been configured with .never or .forever()". (The reverse order happens to
// be tolerated, but relying on that is a trap not worth setting.)
const isTest = api.env('test');
return {
presets: [
[
'babel-preset-expo',
{
unstable_transformImportMeta: true,
},
],
],
plugins: [
// Makes `await import(...)` reachable under jest, where there is no Metro
// to resolve it. Without this every such call site throws — 93 of them
// across 40 files — and the 41 sitting inside a try/catch swallow it and
// take their error branch while the suite still reports green. Full
// rationale in the plugin file.
//
// Deleting this line is SILENT: measured 2026-08-17, it turns only 4 of
// 1030 tests red and restores the blind spot everywhere else.
// `__tests__/dynamicImportTransform.test.ts` exists to make it loud, and
// asserts both that the transform is here and that it stays out of every
// other environment.
//
// Required as a FUNCTION, not named by path. `dev/harness/babel.harness.js`
// composes this config by calling it directly, and a relative plugin path
// is then resolved against Babel's own internals rather than this file —
// which broke every harness scenario with "Cannot find module". A function
// reference has no such ambiguity. `require` here is relative to this
// file, so it resolves correctly however the config is loaded.
...(isTest ? [require('./jest/babel-plugin-dynamic-import-to-require.js')] : []),
// Reanimated plugin must remain last.
'react-native-reanimated/plugin',
],
// @polkadot/* ships untranspiled ES2022 class syntax that Hermes rejects.
// babel-preset-expo doesn't lower it, so do it here, scoped to the
// @polkadot packages only. (Applying to all of node_modules breaks
// TS-source packages like expo-file-system, whose `declare` fields must
// be transformed by the TypeScript plugin before these class plugins run.)
overrides: [
{
test: /node_modules[\\/]@polkadot[\\/]/,
plugins: [
'@babel/plugin-transform-class-static-block',
'@babel/plugin-transform-class-properties',
'@babel/plugin-transform-private-methods',
'@babel/plugin-transform-private-property-in-object',
],
},
],
};
};