aliases.js 978 B

123456789101112131415161718192021222324252627282930313233343536
  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 = ['sfc-playground', 'template-explorer', 'dts-test']
  19. for (const dir of dirs) {
  20. const key = `@vue/${dir}`
  21. if (
  22. dir !== 'vue' &&
  23. !nonSrcPackages.includes(dir) &&
  24. !(key in entries) &&
  25. statSync(new URL(`../packages/${dir}`, import.meta.url)).isDirectory()
  26. ) {
  27. entries[key] = resolveEntryForPkg(dir)
  28. }
  29. }
  30. export { entries }