mirror of
https://github.com/selfxyz/self.git
synced 2026-04-27 03:01:15 -04:00
tsup wraps require() as __require() in ESM builds for externalized modules. Metro's dependency collector only recognizes standard require() calls, so __require() calls for .lottie assets are invisible during bundling, causing "Unknown named module" errors at runtime. This Babel plugin converts __require(stringLiteral) back to require(stringLiteral) before Metro's dependency collection pass, allowing the custom resolver to properly locate and bundle .lottie assets from the SDK dist. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
57 lines
1.5 KiB
JavaScript
57 lines
1.5 KiB
JavaScript
// SPDX-FileCopyrightText: 2025-2026 Social Connect Labs, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
// NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE.
|
|
|
|
// tsup wraps require() as __require() in ESM builds for externalized modules.
|
|
// Metro's dependency collector only recognizes standard require() calls, so __require()
|
|
// calls are invisible to bundling. This plugin converts them back to require() so Metro
|
|
// can resolve and include the assets (e.g. .lottie files from the SDK dist).
|
|
function rewriteDunderRequire() {
|
|
return {
|
|
visitor: {
|
|
CallExpression(path) {
|
|
if (
|
|
path.node.callee.type === 'Identifier' &&
|
|
path.node.callee.name === '__require' &&
|
|
path.node.arguments.length === 1 &&
|
|
path.node.arguments[0].type === 'StringLiteral'
|
|
) {
|
|
path.node.callee.name = 'require';
|
|
}
|
|
},
|
|
},
|
|
};
|
|
}
|
|
|
|
module.exports = {
|
|
presets: ['module:@react-native/babel-preset'],
|
|
plugins: [
|
|
rewriteDunderRequire,
|
|
[
|
|
'module-resolver',
|
|
{
|
|
root: ['./src'],
|
|
alias: { '@': './src' },
|
|
},
|
|
],
|
|
['@babel/plugin-transform-private-methods', { loose: true }],
|
|
'@babel/plugin-transform-export-namespace-from',
|
|
[
|
|
'module:react-native-dotenv',
|
|
{
|
|
moduleName: '@env',
|
|
path: '.env',
|
|
blacklist: null,
|
|
whitelist: null,
|
|
safe: false,
|
|
allowUndefined: true,
|
|
},
|
|
],
|
|
],
|
|
env: {
|
|
production: {
|
|
plugins: ['transform-remove-console'],
|
|
},
|
|
},
|
|
};
|