1
0

check-dsh-source.mjs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import * as fs from 'node:fs'
  2. import * as path from 'node:path'
  3. import * as os from 'node:os'
  4. import { fileURLToPath } from 'node:url'
  5. import { createRequire } from 'node:module'
  6. import { execFileSync } from 'node:child_process'
  7. import { loadSourceHost } from './dsh-source.mjs'
  8. const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
  9. const repoRoot = path.resolve(packageRoot, '../..')
  10. const require = createRequire(path.join(repoRoot, 'package.json'))
  11. const sourcePath = process.argv.slice(2).filter(arg => arg !== '--')[0] ?? process.env.WEBNOVEL_DSH_SOURCE
  12. if (sourcePath === undefined) throw new Error('Usage: pnpm test:dsh-source -- <DSH checkout>')
  13. const host = loadSourceHost(sourcePath)
  14. host.entry('@deepseek-ai/dsh-app-boot')
  15. for (const name of ['@deepseek-ai/cordis', '@deepseek-ai/dsh-tools', '@deepseek-ai/dsh-user-questions/types']) {
  16. if (host.typePaths[name] === undefined) throw new Error(`DSH declarations missing: ${name}`)
  17. }
  18. const temp = fs.mkdtempSync(path.join(os.tmpdir(), 'webnovel-dsh-types-'))
  19. const config = path.join(temp, 'tsconfig.json')
  20. try {
  21. for (const name of ['bundle', 'embedding-provider']) {
  22. fs.writeFileSync(config, JSON.stringify({
  23. extends: path.join(repoRoot, 'packages', name, 'tsconfig.json'),
  24. compilerOptions: { paths: host.typePaths },
  25. }, null, 2))
  26. console.log(`[dsh-source] checking ${name} types against ${host.version} (${host.commit})`)
  27. execFileSync(process.execPath, [require.resolve('typescript/bin/tsc'), '-p', config], { cwd: repoRoot, stdio: 'inherit', windowsHide: true })
  28. }
  29. console.log('[dsh-source] running the real Loader against the same built checkout')
  30. const vitest = path.join(path.dirname(require.resolve('vitest/package.json')), 'vitest.mjs')
  31. execFileSync(process.execPath, [vitest, 'run', 'packages/bundle/tests/host-loader.spec.ts'], {
  32. cwd: repoRoot,
  33. env: { ...process.env, WEBNOVEL_DSH_SOURCE: host.root },
  34. stdio: 'inherit',
  35. windowsHide: true,
  36. })
  37. } finally {
  38. fs.unlinkSync(config)
  39. fs.rmdirSync(temp)
  40. }