Something went wrong. Try again.
Mirror — see github.com/blacksky-algorithms/blacksky.community
Something went wrong. Try again.
blacksky.community babel.config.js
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132/** * React Compiler tags generated nodes with loc = Symbol(GeneratedSource), * which breaks the structuredClone Metro performs on the AST when * EXPO_UNSTABLE_TREE_SHAKING is enabled. Strip them after all other * transforms have run. * * @returns {import('@babel/core').PluginObj} */const stripSymbolLocs = () => ({ post(file) { file.path.traverse({ enter(path) { if (typeof path.node.loc === 'symbol') { path.node.loc = undefined } }, }) if (typeof file.ast.program.loc === 'symbol') { file.ast.program.loc = undefined } },})
/** * Inline Sentry's debug flags before Metro tree shaking. Replacing only the * global is insufficient because Metro cannot propagate DEBUG_BUILD's value * across module boundaries to remove the guarded logging code. * * @param {{types: typeof import('@babel/types')}} api * @returns {import('@babel/core').PluginObj} */const stripSentryDebug = ({types}) => ({ visitor: { ImportDeclaration(path, state) { if ( !/[/\\]node_modules[/\\]@sentry[/\\]/.test(state.filename ?? '') || !/^(?:\.\.?\/)+debug-build(?:\.js)?$/.test(path.node.source.value) ) { return }
for (const specifier of path.get('specifiers')) { if ( !specifier.isImportSpecifier() || !types.isIdentifier(specifier.node.imported, {name: 'DEBUG_BUILD'}) ) { continue } const binding = path.scope.getBinding(specifier.node.local.name) for (const reference of binding?.referencePaths ?? []) { // Preserve re-exports; only replace expressions using this binding. if (!reference.parentPath.isExportSpecifier()) { reference.replaceWith(types.booleanLiteral(false)) } } } }, ReferencedIdentifier(path) { if ( path.node.name === '__SENTRY_DEBUG__' && !path.scope.hasBinding('__SENTRY_DEBUG__') ) { path.replaceWith(types.booleanLiteral(false)) } }, },})
/** * @param {import("@babel/core").ConfigAPI} api * @returns {import("@babel/core").InputOptions} */module.exports = function (api) { const workletsPluginOptions = { /* * Bundle mode writes each worklet to a file as it transforms. Jest * transforms in parallel workers, so a worker can load a file another is * still writing. */ bundleMode: !api.env('test'), strictGlobal: true, // optional, but recommended }
return { presets: [ [ 'babel-preset-expo', { lazyImports: true, native: { // Disable ESM -> CJS compilation because Metro takes care of it. // However, we need it in Jest tests since those run without Metro. disableImportExportTransform: !api.env('test'), }, }, ], ], plugins: [ ['@lingui/babel-plugin-lingui-macro', {stripMessageField: false}], ['babel-plugin-react-compiler', {target: '19'}], [ 'module-resolver', { alias: { // This needs to be mirrored in tsconfig.json '#': './src', crypto: './src/platform/crypto.ts', }, }, ],
// cannot use `env` field because it will put them after // the `react-native-worklets/plugin` plugin ...(api.env('test') ? [ '@babel/plugin-transform-class-static-block', // Compile `import()` to require so jest (which runs without // `--experimental-vm-modules`) can execute lazily-loaded modules // like `@ipld/dag-cbor` via its moduleNameMapper. '@babel/plugin-transform-dynamic-import', ] : []), ...(api.env('production') ? ['transform-remove-console', stripSentryDebug] : []),
stripSymbolLocs, ['react-native-worklets/plugin', workletsPluginOptions], // NOTE: this plugin MUST be last ], }}