MCPcopy
hub / github.com/primer/react / resolve

Function resolve

packages/react/src/__tests__/exports.test.ts:523–603  ·  view source on GitHub ↗

* Resolve the given import or export source. If the source is a filepath, it * will attempt to resolve the module relative to the given filepath.

(
  source: string,
  filepath: string,
)

Source from the content-addressed store, hash-verified

521 * will attempt to resolve the module relative to the given filepath.
522 */
523function resolve(
524 source: string,
525 filepath: string,
526): ResolveBareModule | ResolveRelativeModule | ResolveAbsoluteModule | ResolveError {
527 if (source.startsWith('.')) {
528 const directory = path.dirname(filepath)
529 const extension = path.extname(source)
530 if (extension === '' || !extensions.includes(extension)) {
531 const candidate = extensions
532 .flatMap(extension => {
533 return [
534 path.resolve(
535 directory,
536 path.format({
537 name: source,
538 ext: extension,
539 }),
540 ),
541 path.resolve(
542 directory,
543 path.format({
544 dir: source,
545 name: 'index',
546 ext: extension,
547 }),
548 ),
549 ]
550 })
551 .find(candidate => {
552 return existsSync(candidate)
553 })
554 if (candidate) {
555 return {
556 type: 'relative',
557 value: candidate,
558 }
559 }
560
561 return {
562 type: 'error',
563 error: new Error(`Unable to find file: ${source} from: ${filepath}`),
564 }
565 }
566
567 const resolvedPath = path.resolve(directory, source)
568 if (!existsSync(resolvedPath)) {
569 return {
570 type: 'error',
571 error: new Error(`Unable to find file: ${source} from: ${filepath}`),
572 }
573 }
574 return {
575 type: 'relative',
576 value: resolvedPath,
577 }
578 }
579
580 if (source.startsWith('/')) {

Callers 5

rollup.config.jsFile · 0.85
onCloseFunction · 0.85
useLazySuggestionsFunction · 0.85
addSourceFunction · 0.85
handleCallbackFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected