build-tests.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/env node
  2. const { execSync } = require("child_process")
  3. const esbuild = require("esbuild")
  4. const watch = process.argv.includes("--watch")
  5. /**
  6. * @type {import('esbuild').Plugin}
  7. */
  8. const esbuildProblemMatcherPlugin = {
  9. name: "esbuild-problem-matcher",
  10. setup(build) {
  11. build.onStart(() => {
  12. console.log("[watch] build started")
  13. })
  14. build.onEnd((result) => {
  15. result.errors.forEach(({ text, location }) => {
  16. console.error(`✘ [ERROR] ${text}`)
  17. console.error(` ${location.file}:${location.line}:${location.column}:`)
  18. })
  19. console.log("[watch] build finished")
  20. })
  21. },
  22. }
  23. const srcConfig = {
  24. bundle: true,
  25. minify: false,
  26. sourcemap: true,
  27. sourcesContent: true,
  28. logLevel: "silent",
  29. entryPoints: ["src/packages/**/*.ts"],
  30. outdir: "out/packages",
  31. format: "cjs",
  32. platform: "node",
  33. define: {
  34. "process.env.IS_TEST": "true",
  35. },
  36. external: ["vscode"],
  37. plugins: [esbuildProblemMatcherPlugin],
  38. }
  39. async function main() {
  40. const srcCtx = await esbuild.context(srcConfig)
  41. if (watch) {
  42. await srcCtx.watch()
  43. } else {
  44. await srcCtx.rebuild()
  45. await srcCtx.dispose()
  46. }
  47. }
  48. execSync("tsc -p ./tsconfig.test.json --outDir out", { encoding: "utf-8" })
  49. main().catch((e) => {
  50. console.error(e)
  51. process.exit(1)
  52. })