aliases.mjs 988 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // @ts-check
  2. // these aliases are shared between vitest and rollup
  3. import { readdirSync, statSync } from 'node:fs'
  4. import path from 'node:path'
  5. import { fileURLToPath } from 'node:url'
  6. const resolveEntryForPkg = p =>
  7. path.resolve(
  8. fileURLToPath(import.meta.url),
  9. `../../packages/${p}/src/index.ts`
  10. )
  11. const dirs = readdirSync(new URL('../packages', import.meta.url))
  12. const entries = {
  13. vue: resolveEntryForPkg('vue'),
  14. 'vue/compiler-sfc': resolveEntryForPkg('compiler-sfc'),
  15. 'vue/server-renderer': resolveEntryForPkg('server-renderer'),
  16. '@vue/compat': resolveEntryForPkg('vue-compat')
  17. }
  18. const nonSrcPackages = [
  19. 'sfc-playground',
  20. 'size-check',
  21. 'template-explorer'
  22. ]
  23. for (const dir of dirs) {
  24. const key = `@vue/${dir}`
  25. if (
  26. dir !== 'vue' &&
  27. !nonSrcPackages.includes(dir) &&
  28. !(key in entries) &&
  29. statSync(new URL(`../packages/${dir}`, import.meta.url)).isDirectory()
  30. ) {
  31. entries[key] = resolveEntryForPkg(dir)
  32. }
  33. }
  34. export { entries }