{"version":3,"file":"index.js","names":[],"sources":["esm/babel-preset/index.js"],"sourcesContent":["import path from \"node:path\";\nimport { createRequire } from \"node:module\";\nimport mm from \"micromatch\";\nimport tsconfigPaths from \"tsconfig-paths\";\nimport { pickOnePublicEnv } from \"../native/env\";\nimport {\n  API_ROUTE_GLOB_PATTERN,\n  ROUTE_NATIVE_EXCLUSION_GLOB_PATTERNS\n} from \"../router/glob-patterns\";\nfunction toPosixRelativePath(relativePath) {\n  return path.sep === \"\\\\\" ? relativePath.replace(/\\\\/g, \"/\") : relativePath;\n}\nfunction oneBabelPreset(api, options = {}) {\n  const hasViteInjectedOnePlugins = typeof api?.caller === \"function\" ? api.caller((caller) => !!caller?.oneViteMetroBabelConfig) : false;\n  const isVxrnCompiler = typeof api?.caller === \"function\" ? api.caller((caller) => caller?.name === \"vxrn\") : false;\n  if (isVxrnCompiler) {\n    return { presets: [], plugins: [] };\n  }\n  if (!api?.caller && typeof api?.cache === \"function\") {\n    api.cache(true);\n  }\n  const projectRoot = path.resolve(\n    options.projectRoot ?? (typeof api?.cwd === \"function\" ? api.cwd() : process.cwd())\n  );\n  const require2 = createRequire(projectRoot + \"/\");\n  let reactNativePresetPath;\n  try {\n    reactNativePresetPath = require2.resolve(\"@react-native/babel-preset\");\n  } catch {\n    throw new Error(\n      `[one/babel-preset] Could not resolve '@react-native/babel-preset' from ${projectRoot}. Install it as a project dependency (it ships with every React Native app template).`\n    );\n  }\n  return {\n    // presets run right to left: strip TypeScript exports before expanding\n    // runtime namespace exports, then let the RN module transform consume them.\n    presets: [\n      {\n        plugins: [\n          createRequire(require2.resolve(\"one/package.json\")).resolve(\n            \"@babel/plugin-transform-export-namespace-from\"\n          )\n        ]\n      },\n      require2(reactNativePresetPath)\n    ],\n    plugins: hasViteInjectedOnePlugins ? [] : buildOneBabelPlugins({\n      projectRoot,\n      relativeRouterRoot: options.routerRoot ?? \"app\",\n      ignoredRouteFiles: options.ignoredRouteFiles,\n      linking: options.linking,\n      setupFile: options.setupFile,\n      includeImportMetaEnv: options.includeImportMetaEnv\n    })\n  };\n}\nfunction buildOneBabelPlugins({\n  projectRoot,\n  relativeRouterRoot,\n  ignoredRouteFiles,\n  linking,\n  setupFile,\n  includeImportMetaEnv = true\n}) {\n  const tsconfig = tsconfigPaths.loadConfig(projectRoot);\n  if (tsconfig.resultType === \"failed\") {\n    throw new Error(\"[one/babel-preset] tsconfig.json paths could not be loaded\");\n  }\n  const require2 = createRequire(projectRoot + \"/\");\n  const metroEntryPath = require2.resolve(\"one/metro-entry\", {\n    paths: [projectRoot]\n  });\n  const setupFileRelativeToMetroEntry = (() => {\n    if (!setupFile) return void 0;\n    const file = typeof setupFile === \"string\" ? setupFile : setupFile.native || setupFile.ios || setupFile.android;\n    if (!file) return void 0;\n    return toPosixRelativePath(\n      path.relative(path.dirname(metroEntryPath), path.join(projectRoot, file))\n    );\n  })();\n  return [\n    // standalone Metro CLI needs `import.meta.env.*` /\n    // `process.env.*` baked in. The Vite path passes `false` here and injects\n    // its own version with the user's `define` env via the server hook.\n    ...includeImportMetaEnv ? [\n      [\n        \"@vxrn/vite-plugin-metro/babel-plugins/import-meta-env-plugin\",\n        { env: buildStandaloneImportMetaEnv() }\n      ]\n    ] : [],\n    \"one/babel-plugin-environment-guard\",\n    [\"one/babel-plugin-remove-server-code\", { routerRoot: relativeRouterRoot }],\n    [\n      \"babel-plugin-module-resolver\",\n      // \"vite-tsconfig-paths\" for Metro\n      {\n        alias: Object.fromEntries(\n          Object.entries(tsconfig.paths).map(([k, v]) => {\n            const key = k.endsWith(\"/*\") ? k.replace(/\\/\\*$/, \"\") : `${k}$`;\n            let value = v[0].replace(/\\/\\*$/, \"\");\n            if (!value.startsWith(\"./\")) value = `./${value}`;\n            return [key, value];\n          })\n        )\n      }\n    ],\n    [\n      \"one/babel-plugin-one-router-metro\",\n      {\n        // posix-only, becomes the first arg of `require.context()` in `one-router-metro`;\n        // backslashes on Windows drift the babel-emitted AST per platform.\n        ONE_ROUTER_APP_ROOT_RELATIVE_TO_ENTRY: toPosixRelativePath(\n          path.relative(\n            path.dirname(metroEntryPath),\n            path.join(projectRoot, relativeRouterRoot)\n          )\n        ),\n        ONE_ROUTER_ROOT_FOLDER_NAME: relativeRouterRoot,\n        ONE_ROUTER_REQUIRE_CONTEXT_REGEX_STRING: buildRouterRequireContextRegexString(ignoredRouteFiles),\n        ONE_ROUTER_LINKING_CONFIG: linking,\n        ONE_SETUP_FILE_NATIVE: setupFileRelativeToMetroEntry\n      }\n    ],\n    \"one/babel-plugin-inline-one-server-url\"\n  ];\n}\nfunction buildStandaloneImportMetaEnv() {\n  const isProduction = process.env.NODE_ENV !== \"development\";\n  const expoPlatform = process.env.ONE_PLATFORM === \"ios\" || process.env.ONE_PLATFORM === \"android\" ? process.env.ONE_PLATFORM : process.env.EXPO_OS === \"ios\" || process.env.EXPO_OS === \"android\" ? process.env.EXPO_OS : void 0;\n  const env = {\n    ...pickOnePublicEnv(process.env),\n    MODE: isProduction ? \"production\" : \"development\",\n    BASE_URL: \"/\",\n    PROD: isProduction,\n    DEV: !isProduction,\n    SSR: false,\n    ONE_PLATFORM: process.env.ONE_PLATFORM ?? \"web\",\n    ...expoPlatform ? { EXPO_OS: expoPlatform } : {}\n  };\n  for (const [key, value] of Object.entries(process.env)) {\n    if (key.startsWith(\"ONE_\") || key.startsWith(\"VITE_\")) {\n      env[key] = value;\n    }\n  }\n  return env;\n}\nfunction normalizeReSource(source) {\n  return source.replace(/\\[\\\\\\\\\\/\\]/g, \"\\\\/\").replace(/\\[\\^\\\\\\\\\\/\\]/g, \"[^/]\");\n}\nfunction buildRouterRequireContextRegexString(ignoredRouteFiles) {\n  const excludeRes = [\n    ...(ignoredRouteFiles || []).map((pattern) => mm.makeRe(pattern)),\n    ...ROUTE_NATIVE_EXCLUSION_GLOB_PATTERNS.map((pattern) => mm.makeRe(pattern)),\n    mm.makeRe(API_ROUTE_GLOB_PATTERN)\n  ];\n  const mustStartWith = String.raw`^(?:(?:^|\\/|(?:(?:(?!(?:^|\\/)\\.).)*?)\\/)(?!\\.)(?=.)[^/]*?`;\n  const mustEndWith = String.raw`)$`;\n  const negatives = excludeRes.map((re, i) => {\n    const reSource = normalizeReSource(re.source);\n    if (!(reSource.startsWith(mustStartWith) && reSource.endsWith(mustEndWith))) {\n      const pattern = ignoredRouteFiles?.[i];\n      throw new Error(\n        pattern ? `[one/metro] ignoredRouteFile pattern \"${pattern}\" is not supported. We cannot process the corresponding regex \"${reSource}\" for now.` : `Unsupported regex \"${reSource}\" in \"ignoredRouteFiles\".`\n      );\n    }\n    const inner = reSource.slice(\n      mustStartWith.length,\n      reSource.length - mustEndWith.length\n    );\n    return String.raw`(?:.*${inner})`;\n  });\n  return String.raw`^(?:\\.\\/)(?!${negatives.join(\"|\")}$).*\\.tsx?$`;\n}\nexport {\n  buildOneBabelPlugins,\n  buildRouterRequireContextRegexString,\n  oneBabelPreset as default\n};\n//# sourceMappingURL=index.js.map\n"],"mappings":";;;;;;;;AASA,SAAS,oBAAoB,cAAc;CACzC,OAAO,KAAK,QAAQ,OAAO,aAAa,QAAQ,OAAO,GAAG,IAAI;AAChE;AACA,SAAS,eAAe,KAAK,UAAU,CAAC,GAAG;CACzC,MAAM,4BAA4B,OAAO,KAAK,WAAW,aAAa,IAAI,QAAQ,WAAW,CAAC,CAAC,QAAQ,uBAAuB,IAAI;CAClI,MAAM,iBAAiB,OAAO,KAAK,WAAW,aAAa,IAAI,QAAQ,WAAW,QAAQ,SAAS,MAAM,IAAI;CAC7G,IAAI,gBAAgB;EAClB,OAAO;GAAE,SAAS,CAAC;GAAG,SAAS,CAAC;EAAE;CACpC;CACA,IAAI,CAAC,KAAK,UAAU,OAAO,KAAK,UAAU,YAAY;EACpD,IAAI,MAAM,IAAI;CAChB;CACA,MAAM,cAAc,KAAK,QACvB,QAAQ,gBAAgB,OAAO,KAAK,QAAQ,aAAa,IAAI,IAAI,IAAI,QAAQ,IAAI,EACnF;CACA,MAAM,WAAW,cAAc,cAAc,GAAG;C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