MCPcopy
hub / github.com/TanStack/router / handler

Function handler

packages/start-plugin-core/src/start-compiler-plugin/plugin.ts:249–316  ·  view source on GitHub ↗
(code, id)

Source from the content-addressed store, hash-verified

247 },
248 },
249 async handler(code, id) {
250 let compiler = compilers[this.environment.name]
251 if (!compiler) {
252 // Default to 'dev' mode for unknown environments (conservative: no caching)
253 const mode = this.environment.mode === 'build' ? 'build' : 'dev'
254 compiler = new StartCompiler({
255 env: environment.type,
256 envName: environment.name,
257 root,
258 lookupKinds: LookupKindsPerEnv[environment.type],
259 lookupConfigurations: getLookupConfigurationsForEnv(
260 environment.type,
261 opts.framework,
262 ),
263 mode,
264 framework: opts.framework,
265 providerEnvName: opts.providerEnvName,
266 generateFunctionId: opts.generateFunctionId,
267 onServerFnsById,
268 getKnownServerFns: () => serverFnsById,
269 loadModule: async (id: string) => {
270 if (this.environment.mode === 'build') {
271 const loaded = await this.load({ id })
272 // Handle modules with no runtime code (e.g., type-only exports).
273 // After TypeScript compilation, these become empty modules.
274 // Create an empty module info instead of throwing.
275 const code = loaded.code ?? ''
276 compiler!.ingestModule({ code, id })
277 } else if (this.environment.mode === 'dev') {
278 /**
279 * in dev, vite does not return code from `ctx.load()`
280 * so instead, we need to take a different approach
281 * we must force vite to load the module and run it through the vite plugin pipeline
282 * we can do this by using the `fetchModule` method
283 * the `captureServerFnModuleLookupPlugin` captures the module code via its transform hook and invokes analyzeModuleAST
284 */
285 await this.environment.fetchModule(
286 id + '?' + SERVER_FN_LOOKUP,
287 )
288 } else {
289 throw new Error(
290 `could not load module ${id}: unknown environment mode ${this.environment.mode}`,
291 )
292 }
293 },
294 resolveId: async (source: string, importer?: string) => {
295 const r = await this.resolve(source, importer)
296 if (r) {
297 if (!r.external) {
298 return cleanId(r.id)
299 }
300 }
301 return null
302 },
303 })
304 compilers[this.environment.name] = compiler
305 }
306

Callers 1

compileMethod · 0.70

Calls 13

cleanIdFunction · 0.90
detectKindsInCodeFunction · 0.90
parseIdQueryFunction · 0.85
resolvePathFunction · 0.85
generateManifestModuleFunction · 0.85
ingestModuleMethod · 0.80
resolveMethod · 0.80
compileMethod · 0.80
startsWithMethod · 0.80
toStringMethod · 0.65
errorMethod · 0.65

Tested by

no test coverage detected