(
ctx: Rollup.PluginContext,
id: string,
importerId: string | undefined,
resolveOpts?: Parameters<Extract<Plugin['resolveId'], Function>>[2]
)
| 437 | * `load()` phase ensure it is built first. |
| 438 | */ |
| 439 | const resolveId = async ( |
| 440 | ctx: Rollup.PluginContext, |
| 441 | id: string, |
| 442 | importerId: string | undefined, |
| 443 | resolveOpts?: Parameters<Extract<Plugin['resolveId'], Function>>[2] |
| 444 | ) => { |
| 445 | if (id.startsWith('\0')) { |
| 446 | return; |
| 447 | } |
| 448 | |
| 449 | // Intercept requests to open in editor |
| 450 | const editMatch = devServer && /^(.*)\?editor(:(\d+)(:\d+)?)?$/.exec(id); |
| 451 | if (editMatch) { |
| 452 | // Throttle so we don't open multiple times on re-resolve |
| 453 | if (!doNotEdit) { |
| 454 | doNotEdit = true; |
| 455 | setTimeout(() => (doNotEdit = false), 500); |
| 456 | |
| 457 | const [, origId, location] = editMatch; |
| 458 | // Find the actual file on disk by asking vite to resolve it |
| 459 | const resolved = await ctx.resolve(origId, importerId); |
| 460 | if (resolved) { |
| 461 | const file = devServer!.moduleGraph.getModuleById(resolved.id)?.file; |
| 462 | if (file) { |
| 463 | const path = `${file}${location}`; |
| 464 | try { |
| 465 | console.warn(`Opening in editor: ${path}`); |
| 466 | const launchEditor = (await import('launch-editor')).default; |
| 467 | launchEditor(path); |
| 468 | } catch (e: any) { |
| 469 | console.error(`Failed to open editor: ${e.message}`); |
| 470 | } |
| 471 | } |
| 472 | } |
| 473 | } |
| 474 | return { id: `\0editor` }; |
| 475 | } |
| 476 | |
| 477 | const count = resolveIdCount++; |
| 478 | const isServer = getIsServer(resolveOpts); |
| 479 | debug(`resolveId(${count})`, `begin ${id} | ${isServer ? 'server' : 'client'} | ${importerId}`); |
| 480 | |
| 481 | const parsedImporterId = importerId && parseId(importerId); |
| 482 | importerId = parsedImporterId && normalizePath(parsedImporterId.pathId); |
| 483 | |
| 484 | // Relative paths must be resolved vs the importer |
| 485 | if (id.startsWith('.') && parsedImporterId) { |
| 486 | const path = getPath(); |
| 487 | const importerDir = path.dirname(parsedImporterId.pathId); |
| 488 | if (importerDir) { |
| 489 | id = path.resolve(importerDir, id); |
| 490 | } |
| 491 | } |
| 492 | |
| 493 | // Split query, remove windows path encoding etc |
| 494 | const parsedId = parseId(id); |
| 495 | const pathId = normalizePath(parsedId.pathId); |
| 496 |
nothing calls this directly
no test coverage detected
searching dependent graphs…