{"version":3,"file":"virtualEntryPlugin.js","names":[],"sources":["esm/vite/plugins/virtualEntryPlugin.js"],"sourcesContent":["import { resolve } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport { configuration } from \"@vxrn/compiler\";\nimport micromatch from \"micromatch\";\nimport { isNativeEnvironment } from \"vxrn\";\nimport {\n  API_ROUTE_GLOB_PATTERN,\n  ROUTE_GLOB_PATTERN,\n  ROUTE_NATIVE_EXCLUSION_GLOB_PATTERNS,\n  ROUTE_WEB_EXCLUSION_GLOB_PATTERNS\n} from \"../../router/glob-patterns\";\nimport { matchDirectoryRenderMode, matchFileRenderMode } from \"../../router/matchers\";\nimport {\n  resolvedVirtualEntryId,\n  resolvedVirtualEntryIdNative,\n  virtualEntryId,\n  virtualEntryIdNative\n} from \"./virtualEntryConstants\";\nconst escapeRe = (s) => s.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\nconst VIRTUAL_ENTRY_SOURCE_RE = new RegExp(\n  `^(?:${escapeRe(virtualEntryId)}|${escapeRe(virtualEntryIdNative)})$`\n);\nconst VIRTUAL_ENTRY_RESOLVED_RE = new RegExp(\n  `^(?:${escapeRe(resolvedVirtualEntryId)}|${escapeRe(resolvedVirtualEntryIdNative)})$`\n);\nfunction normalizeSetupFile(setupFile) {\n  if (!setupFile) return {};\n  if (typeof setupFile === \"string\") {\n    return {\n      client: setupFile,\n      server: setupFile,\n      ios: setupFile,\n      android: setupFile\n    };\n  }\n  if (\"native\" in setupFile) {\n    return {\n      client: setupFile.client,\n      server: setupFile.server,\n      ios: setupFile.native,\n      android: setupFile.native\n    };\n  }\n  const sf = setupFile;\n  return {\n    client: sf.client,\n    server: sf.server,\n    ios: sf.ios,\n    android: sf.android\n  };\n}\nfunction getSetupFileImport(environmentName, setupFiles, useStaticImport, root) {\n  const envMap = {\n    client: \"client\",\n    ssr: \"server\",\n    worker: \"server\",\n    ios: \"ios\",\n    android: \"android\"\n  };\n  const key = envMap[environmentName];\n  if (!key) return { importStatement: \"\", promiseDeclaration: \"\", promiseVarName: \"\" };\n  const setupFile = setupFiles[key];\n  if (!setupFile)\n    return { importStatement: \"\", promiseDeclaration: \"\", promiseVarName: \"\" };\n  const resolvedSetupFile = root ? pathToFileURL(resolve(root, setupFile)).href : setupFile;\n  if (useStaticImport) {\n    return {\n      importStatement: `import ${JSON.stringify(resolvedSetupFile)}`,\n      promiseDeclaration: \"\",\n      promiseVarName: \"\"\n    };\n  }\n  return {\n    importStatement: \"\",\n    promiseDeclaration: `const __oneGetSetupPromise = () => import(${JSON.stringify(resolvedSetupFile)})`,\n    promiseVarName: \"__oneGetSetupPromise\"\n  };\n}\nfunction createVirtualEntry(options) {\n  const routeGlobs = [\n    `/${options.root}/${ROUTE_GLOB_PATTERN}`,\n    ...options.router?.ignoredRouteFiles?.map(\n      (pattern) => `!/${options.root}/${pattern}`\n    ) || []\n  ];\n  const apiRouteGlobs = `/${options.root}/${API_ROUTE_GLOB_PATTERN}`;\n  const setupFiles = normalizeSetupFile(options.setupFile);\n  let viteRoot = \"\";\n  let isDevMode = false;\n  return {\n    name: \"one-virtual-entry\",\n    enforce: \"pre\",\n    configResolved(config) {\n      viteRoot = config.root;\n      isDevMode = config.command === \"serve\";\n    },\n    // only the two virtual entry ids reach js; every other import in the graph\n    // is rejected rust-side\n    resolveId: {\n      filter: { id: VIRTUAL_ENTRY_SOURCE_RE },\n      handler(id) {\n        if (id === virtualEntryId) {\n          return resolvedVirtualEntryId;\n        }\n        if (id === virtualEntryIdNative) {\n          return resolvedVirtualEntryIdNative;\n        }\n      }\n    },\n    load: {\n      filter: { id: VIRTUAL_ENTRY_RESOLVED_RE },\n      handler(id) {\n        if (id === resolvedVirtualEntryId) {\n          const isNative = isNativeEnvironment(this.environment);\n          const isSSR = this.environment.name === \"ssr\" || this.environment.name === \"worker\";\n          const serverSpaRouteFiles = isSSR ? options.routeIndex.getPaths().map((file) => file.replace(/^\\.\\//, \"\")).filter((file) => /\\.tsx?$/.test(file)).filter(\n            (file) => !micromatch.isMatch(file, ROUTE_WEB_EXCLUSION_GLOB_PATTERNS)\n          ).filter((file) => {\n            const parts = file.split(\"/\");\n            const filename = parts.at(-1) || \"\";\n            if (filename.startsWith(\"_layout\") || filename.startsWith(\"_middleware\")) {\n              return false;\n            }\n            const fileMode = matchFileRenderMode(filename);\n            if (fileMode) return fileMode === \"spa\";\n            let parentMode;\n            for (const directory of parts.slice(0, -1)) {\n              parentMode = matchDirectoryRenderMode(directory)?.renderMode ?? parentMode;\n            }\n            return parentMode === \"spa\";\n          }) : [];\n          const serverSpaRouteStubs = serverSpaRouteFiles.map(\n            (file) => `${JSON.stringify(`/${options.root}/${file}`)}: () => Promise.resolve({})`\n          ).join(\",\\n    \");\n          const serverSpaBuildGlobs = serverSpaRouteFiles.map(\n            (file) => `/${options.root}/${file}`\n          );\n          const serverSpaExportGlob = (name) => `  ${name}: import.meta.glob(${JSON.stringify(serverSpaBuildGlobs)}, { exhaustive: true, import: '${name}', query: '?one-spa-build' })`;\n          const serverSpaBuildRoutes = serverSpaBuildGlobs.length ? `{\n${[\"loader\", \"loaderCache\", \"generateStaticParams\", \"sitemap\"].map(serverSpaExportGlob).join(\",\\n\")}\n}` : \"{}\";\n          const webRouteGlobs = [\n            ...routeGlobs,\n            ...ROUTE_WEB_EXCLUSION_GLOB_PATTERNS.map((pattern) => `!${pattern}`),\n            ...serverSpaRouteFiles.map((file) => `!/${options.root}/${file}`)\n          ];\n          const useStaticImport = isNative || isSSR && isDevMode;\n          const setupResult = getSetupFileImport(\n            this.environment.name,\n            setupFiles,\n            useStaticImport,\n            viteRoot\n          );\n          const nativewindImport = configuration.enableNativewind ? `import 'react-native-css-interop/dist/runtime/components'` : \"\";\n          const setupPromiseArg = setupResult.promiseVarName ? `getSetupPromise: ${setupResult.promiseVarName},` : \"\";\n          const linkingArg = options.router?.linking ? `linking: ${JSON.stringify(options.router.linking)},` : \"\";\n          const isDevClient = this.environment.mode === \"dev\" && this.environment.name === \"client\";\n          const refreshPreambleImport = isDevClient ? `import { injectIntoGlobalHook as __oneInjectRefresh } from '/@react-refresh'` : \"\";\n          const refreshPreambleSetup = isDevClient ? `if (typeof window !== 'undefined' && !window.$RefreshReg$) {\n  __oneInjectRefresh(window)\n  window.$RefreshReg$ = () => {}\n  window.$RefreshSig$ = () => (type) => type\n}` : \"\";\n          return `\n${setupResult.promiseDeclaration}\n${nativewindImport}\n${refreshPreambleImport}\n\nimport { createApp, registerPreloadedRoute as _registerPreloadedRoute } from 'one'\n${setupResult.importStatement}\n${refreshPreambleSetup}\n\n// Export registerPreloadedRoute so preload files can import it from this bundle\n// Named export that wraps the original function\nexport function registerPreloadedRoute(key, module) {\n  return _registerPreloadedRoute(key, module)\n}\n\n// Also expose on window for debugging and to prevent tree-shaking\nif (typeof window !== 'undefined') {\n  window.__oneRegisterPreloadedRoute = registerPreloadedRoute\n}\n\n// a route that declares spa by filename or parent directory is stubbed out of\n// the route map below so the server never holds its page component. its\n// server-side exports come from here instead, one glob per export so the page\n// never comes with them.\nexport const oneServerSpaRouteExports = ${serverSpaBuildRoutes}\n\n// globbing ${JSON.stringify(webRouteGlobs)}\nexport default createApp({\n  ${setupPromiseArg}\n  routes: {\n    ...import.meta.glob(${JSON.stringify(webRouteGlobs)}, { exhaustive: true }),\n    ${serverSpaRouteStubs}\n  },\n  routerRoot: ${JSON.stringify(options.root)},\n  flags: ${JSON.stringify(options.flags)},\n  ${linkingArg}\n})\n        `;\n        }\n        if (id === resolvedVirtualEntryIdNative) {\n          const isNative = isNativeEnvironment(this.environment);\n          const setupResult = getSetupFileImport(\n            this.environment.name,\n            setupFiles,\n            isNative,\n            viteRoot\n          );\n          const linkingArg = options.router?.linking ? `linking: ${JSON.stringify(options.router.linking)},` : \"\";\n          return `\nimport { createApp } from 'one'\n${setupResult.importStatement}\n\n// globbing ${JSON.stringify(routeGlobs)}\nexport default createApp({\n  routes: import.meta.glob(${JSON.stringify([...routeGlobs, ...ROUTE_NATIVE_EXCLUSION_GLOB_PATTERNS.map((p) => `!${p}`), `!${apiRouteGlobs}`])}, { exhaustive: true }),\n  routerRoot: ${JSON.stringify(options.root)},\n  flags: ${JSON.stringify(options.flags)},\n  ${linkingArg}\n})\n        `;\n        }\n      }\n    }\n  };\n}\nexport {\n  createVirtualEntry\n};\n//# sourceMappingURL=virtualEntryPlugin.js.map\n"],"mappings":";;;;;;;;;;AAkBA,MAAM,YAAY,MAAM,EAAE,QAAQ,uBAAuB,MAAM;AAC/D,MAAM,0BAA0B,IAAI,OAClC,OAAO,SAAS,cAAc,EAAE,GAAG,SAAS,oBAAoB,EAAE,GACpE;AACA,MAAM,4BAA4B,IAAI,OACpC,OAAO,SAAS,sBAAsB,EAAE,GAAG,SAAS,4BAA4B,EAAE,GACpF;AACA,SAAS,mBAAmB,WAAW;CACrC,IAAI,CAAC,WAAW,OAAO,CAAC;CACxB,IAAI,OAAO,cAAc,UAAU;EACjC,OAAO;GACL,QAAQ;GACR,QAAQ;GACR,KAAK;GACL,SAAS;EACX;CACF;CACA,IAAI,YAAY,WAAW;EACzB,OAAO;GACL,QAAQ,UAAU;GAClB,QAAQ,UAAU;GAClB,KAAK,UAAU;GACf,SAAS,UAAU;EACrB;CACF;CACA,MAAM,KAAK;CACX,OAAO;EACL,QAAQ,GAAG;EACX,QAAQ,GAAG;EACX,KAAK,GAAG;EACR,SAAS,GAAG;CACd;AACF;AACA,SAAS,mBAAmB,iBAAiB,YAAY,iBAAiB,MAAM;CAC9E,MAAM,SAAS;EACb,QAAQ;EACR,KAAK;EACL,QAAQ;EACR,KAAK;EACL,SAAS;CACX;CACA,MAAM,MAAM,OAAO;CACnB,IAAI,CAAC,KAAK,OAAO;EAAE,iBAAiB;EAAI,oBAAoB;EAAI,gBAAgB;CAAG;CACnF,MAAM,YAAY,WAAW;CAC7B,IAAI,CAAC,WACH,OAAO;EAAE,iBAAiB;EAAI,oBAAoB;EAAI,gBAAgB;CAAG;CAC3E,MAAM,oBAAoB,OAAO,cAAc,QAAQ,MAAM,SA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