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

Function isFilePathESM

packages/vite/src/node/utils.ts:425–442  ·  view source on GitHub ↗
(
  filePath: string,
  packageCache?: PackageCache,
)

Source from the content-addressed store, hash-verified

423}
424
425export function isFilePathESM(
426 filePath: string,
427 packageCache?: PackageCache,
428): boolean {
429 if (/\.m[jt]s$/.test(filePath)) {
430 return true
431 } else if (/\.c[jt]s$/.test(filePath)) {
432 return false
433 } else {
434 // check package.json for type: "module"
435 try {
436 const pkg = findNearestPackageData(path.dirname(filePath), packageCache)
437 return pkg?.data.type === 'module'
438 } catch {
439 return false
440 }
441 }
442}
443
444export const splitRE: RegExp = /\r?\n/g
445

Callers 3

bundleAndLoadConfigFileFunction · 0.90
fetchModuleFunction · 0.90
isNodeModeFunction · 0.90

Calls 1

findNearestPackageDataFunction · 0.90

Tested by

no test coverage detected