t38-r2-compile-check.mjs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**
  2. * T38 第二轮:改动文件的编译/导入自检(票 38 复验反馈)。
  3. *
  4. * 只做两件事:① 三个 .vue 能被 @vue/compiler-sfc 解析并编译 script+template;
  5. * ② 三个改过的 .js 能被 node 真实 import(导出面完整、无语法错)。
  6. * 不启动 dev server、不控制浏览器(AGENTS.md 的验证纪律)。
  7. */
  8. import { readFileSync } from 'node:fs'
  9. import { parse, compileScript, compileTemplate } from 'vue/compiler-sfc'
  10. const ROOT = new URL('../../../', import.meta.url)
  11. const VUES = ['src/modules/cockpit/components/PanelBlocks.vue', 'src/modules/cockpit/CockpitShell.vue']
  12. let failed = 0
  13. for (const rel of VUES) {
  14. const source = readFileSync(new URL(rel, ROOT), 'utf8')
  15. const { descriptor, errors } = parse(source, { filename: rel })
  16. if (errors.length) {
  17. console.log(`FAIL parse ${rel} — ${errors[0].message}`)
  18. failed += 1
  19. continue
  20. }
  21. try {
  22. compileScript(descriptor, { id: rel })
  23. const tpl = compileTemplate({ source: descriptor.template.content, filename: rel, id: rel })
  24. if (tpl.errors.length) throw new Error(tpl.errors[0])
  25. console.log(`PASS compile ${rel}`)
  26. } catch (error) {
  27. console.log(`FAIL compile ${rel} — ${error.message}`)
  28. failed += 1
  29. }
  30. }
  31. for (const rel of [
  32. 'src/modules/cockpit/domain/mapLocate.js',
  33. 'src/modules/cockpit/domain/overviewPanels.js',
  34. 'src/modules/cockpit/stores/overviewStore.js',
  35. 'src/modules/cockpit/stores/infrastructureStore.js',
  36. ]) {
  37. try {
  38. await import(new URL(rel, ROOT).href)
  39. console.log(`PASS import ${rel}`)
  40. } catch (error) {
  41. console.log(`FAIL import ${rel} — ${error.message}`)
  42. failed += 1
  43. }
  44. }
  45. // 回联入口必须真的被 planLocate 用到(不是导出了没人调)。
  46. const locate = readFileSync(new URL('src/modules/cockpit/domain/mapLocate.js', ROOT), 'utf8')
  47. const planBody = locate.slice(locate.indexOf('export function planLocate'))
  48. if (/findDeviceOwner\(objects, code\)/.test(planBody)) console.log('PASS 回联挂在 planLocate 判定链上')
  49. else {
  50. console.log('FAIL planLocate 没有调用 findDeviceOwner(回联是死导出)')
  51. failed += 1
  52. }
  53. console.log('')
  54. console.log(failed ? `T38 round-2 compile check: ${failed} FAILED` : 'T38 round-2 compile check: all passed')
  55. if (failed) process.exit(1)