MCPcopy Create free account
hub / github.com/TanStack/query / ensureImportFileExtension

Function ensureImportFileExtension

packages/angular-query/vite.config.ts:7–32  ·  view source on GitHub ↗
({
  content,
  extension,
}: {
  content: string
  extension: string
})

Source from the content-addressed store, hash-verified

5import packageJson from './package.json' with { type: 'json' }
6
7function ensureImportFileExtension({
8 content,
9 extension,
10}: {
11 content: string
12 extension: string
13}) {
14 // replace e.g. `import { foo } from './foo'` with `import { foo } from './foo.js'`
15 content = content.replace(
16 /(im|ex)port\s[\w{}/*\s,]+from\s['"](?:\.\.?\/)+?[^'"]+(?=['"];?)/gm,
17 (specifier) =>
18 /\.(?:[cm]?js|json)$/.test(specifier)
19 ? specifier
20 : `${specifier}.${extension}`,
21 )
22
23 // replace e.g. `import('./foo')` with `import('./foo.js')`
24 content = content.replace(
25 /import\(['"](?:\.\.?\/)+?[^'"]+(?=['"];?)/gm,
26 (specifier) =>
27 /\.(?:[cm]?js|json)$/.test(specifier)
28 ? specifier
29 : `${specifier}.${extension}`,
30 )
31 return content
32}
33
34const externalDependencies = Object.keys({
35 ...packageJson.dependencies,

Callers 1

vite.config.tsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected