MCPcopy
hub / github.com/vitejs/vite / resolve

Function resolve

packages/vite/src/node/plugins/css.ts:1553–1587  ·  packages/vite/src/node/plugins/css.ts::resolve
(id, basedir, _importOptions, atRule)

Source from the content-addressed store, hash-verified

1551 postcssPlugins.unshift(
1552 (await importPostcssImport()).default({
1553 async resolve(id, basedir, _importOptions, atRule) {
1554 const publicFile = checkPublicFile(
1555 id,
1556 environment.getTopLevelConfig(),
1557 )
1558 if (publicFile) {
1559 return publicFile
1560 }
1561
1562 const resolved = await atImportResolvers.css(
1563 environment,
1564 id,
1565 class="cm">// The `source` is only absent for an `@import` injected by another plugin
1566 class="cm">// (a node with no source), in which case the resolver falls back to
1567 class="cm">// the project root.
1568 atRule.source?.input.file,
1569 )
1570
1571 if (resolved) {
1572 return path.resolve(resolved)
1573 }
1574
1575 class="cm">// postcss-import falls back to `resolve` dep if this is unresolved,
1576 class="cm">// but we've shimmed to remove the `resolve` dep to cut on bundle size.
1577 class="cm">// warn here to provide a better error message.
1578 if (!path.isAbsolute(id)) {
1579 environment.logger.error(
1580 colors.red(
1581 `Unable to resolve \`@import class="st">"${id}"\` from ${basedir}`,
1582 ),
1583 )
1584 }
1585
1586 return id
1587 },
1588 async load(id) {
1589 const code = await fs.promises.readFile(id, class="st">'utf-8')
1590 const lang = CSS_LANGS_RE.exec(id)?.[1] as CssLang | undefined

Callers 15

transformDynamicImportFunction · 0.70
resolverFunction · 0.70
handlerFunction · 0.70
runFunction · 0.50
runInlinedModuleMethod · 0.50
waitForWatcherFunction · 0.50
resolvePathFunction · 0.50
execAsyncFunction · 0.50
createServerCloseFnFunction · 0.50

Calls 8

checkPublicFileFunction · 0.90
getCssResolversKeysFunction · 0.85
getAtImportResolversFunction · 0.85
resolverFunction · 0.85
getTopLevelConfigMethod · 0.80
addMethod · 0.80
resolveMethod · 0.65
errorMethod · 0.65

Tested by 13

runFunction · 0.40
runInlinedModuleMethod · 0.40
waitForWatcherFunction · 0.40
resolvePathFunction · 0.40
configureServerFunction · 0.40
createSimpleServerFunction · 0.40
[Symbol.asyncDispose]Function · 0.40
fixtureFunction · 0.40
buildProjectFunction · 0.40
handleHotUpdateFunction · 0.40
hotUpdateFunction · 0.40
runFunction · 0.40