MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / resolveSpecifiers

Function resolveSpecifiers

scripts/check-ui-package.mjs:95–106  ·  view source on GitHub ↗

* `from './lib/adapter'` -> `from './lib/adapter.js'`, and * `from './lib/trail.svelte'` -> `from './lib/trail.svelte.js'` (the emitted * file for a `.svelte.ts` rune module). * * Driven by the filesystem rather than by the extension alone: `.svelte` is a * real file for a component and a compi

(source, fromFile)

Source from the content-addressed store, hash-verified

93 * looking is right for both.
94 */
95function resolveSpecifiers(source, fromFile) {
96 return source.replace(
97 /(\bfrom\s*|\bimport\s*\(\s*)(['"])(\.[^'"]*)\2/g,
98 (match, head, quote, spec) => {
99 if (RESOLVES.some((ext) => spec.endsWith(ext))) return match;
100 const target = resolve(dirname(fromFile), spec);
101 if (existsSync(target) && statSync(target).isFile()) return match;
102 if (!existsSync(`${target}.js`)) return match;
103 return `${head}${quote}${spec}.js${quote}`;
104 }
105 );
106}
107
108let rewritten = 0;
109for (const path of all) {

Callers 1

Calls 1

resolveFunction · 0.50

Tested by

no test coverage detected