aliases.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  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 = (/** @type {string} */ 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. /** @type {Record<string, string>} */
  13. const entries = {
  14. vue: resolveEntryForPkg('vue'),
  15. 'vue/compiler-sfc': resolveEntryForPkg('compiler-sfc'),
  16. 'vue/server-renderer': resolveEntryForPkg('server-renderer'),
  17. '@vue/compat': resolveEntryForPkg('vue-compat'),
  18. }
  19. const nonSrcPackages = ['sfc-playground', 'template-explorer', 'dts-test']
  20. for (const dir of dirs) {
  21. const key = `@vue/${dir}`
  22. if (
  23. dir !== 'vue' &&
  24. !nonSrcPackages.includes(dir) &&
  25. !(key in entries) &&
  26. statSync(new URL(`../packages/${dir}`, import.meta.url)).isDirectory()
  27. ) {
  28. entries[key] = resolveEntryForPkg(dir)
  29. }
  30. }
  31. export { entries }