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

Function resolveLibFilename

packages/vite/src/node/build.ts:996–1027  ·  view source on GitHub ↗
(
  libOptions: LibraryOptions,
  format: ModuleFormat,
  entryName: string,
  root: string,
  extension?: JsExt,
  packageCache?: PackageCache,
)

Source from the content-addressed store, hash-verified

994}
995
996export function resolveLibFilename(
997 libOptions: LibraryOptions,
998 format: ModuleFormat,
999 entryName: string,
1000 root: string,
1001 extension?: JsExt,
1002 packageCache?: PackageCache,
1003): string {
1004 if (typeof libOptions.fileName === 'function') {
1005 return libOptions.fileName(format, entryName)
1006 }
1007
1008 const packageJson = findNearestMainPackageData(root, packageCache)?.data
1009 const name =
1010 libOptions.fileName ||
1011 (packageJson && typeof libOptions.entry === 'string'
1012 ? getPkgName(packageJson.name)
1013 : entryName)
1014
1015 if (!name)
1016 throw new Error(
1017 'Name in package.json is required if option "build.lib.fileName" is not provided.',
1018 )
1019
1020 extension ??= resolveOutputJsExtension(format, packageJson?.type)
1021
1022 if (format === 'cjs' || format === 'es') {
1023 return `${name}.${extension}`
1024 }
1025
1026 return `${name}.${format}.${extension}`
1027}
1028
1029export function resolveBuildOutputs(
1030 outputs: OutputOptions | OutputOptions[] | undefined,

Callers 2

build.spec.tsFile · 0.90
buildOutputOptionsFunction · 0.85

Calls 3

getPkgNameFunction · 0.90
resolveOutputJsExtensionFunction · 0.85

Tested by

no test coverage detected