build 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/env bash
  2. set -exuo pipefail
  3. cd "$(dirname "$0")/.."
  4. node scripts/utils/check-version.cjs
  5. # Build into dist and will publish the package from there,
  6. # so that src/resources/foo.ts becomes <package root>/resources/foo.js
  7. # This way importing from `"@opencode-ai/sdk/resources/foo"` works
  8. # even with `"moduleResolution": "node"`
  9. rm -rf dist; mkdir dist
  10. # Copy src to dist/src and build from dist/src into dist, so that
  11. # the source map for index.js.map will refer to ./src/index.ts etc
  12. cp -rp src README.md dist
  13. for file in LICENSE CHANGELOG.md; do
  14. if [ -e "${file}" ]; then cp "${file}" dist; fi
  15. done
  16. if [ -e "bin/cli" ]; then
  17. mkdir -p dist/bin
  18. cp -p "bin/cli" dist/bin/;
  19. fi
  20. if [ -e "bin/migration-config.json" ]; then
  21. mkdir -p dist/bin
  22. cp -p "bin/migration-config.json" dist/bin/;
  23. fi
  24. # this converts the export map paths for the dist directory
  25. # and does a few other minor things
  26. node scripts/utils/make-dist-package-json.cjs > dist/package.json
  27. # build to .js/.mjs/.d.ts files
  28. ./node_modules/.bin/tsc-multi
  29. # we need to patch index.js so that `new module.exports()` works for cjs backwards
  30. # compat. No way to get that from index.ts because it would cause compile errors
  31. # when building .mjs
  32. node scripts/utils/fix-index-exports.cjs
  33. cp tsconfig.dist-src.json dist/src/tsconfig.json
  34. node scripts/utils/postprocess-files.cjs
  35. # make sure that nothing crashes when we require the output CJS or
  36. # import the output ESM
  37. (cd dist && node -e 'require("@opencode-ai/sdk")')
  38. (cd dist && node -e 'import("@opencode-ai/sdk")' --input-type=module)
  39. if [ -e ./scripts/build-deno ]
  40. then
  41. ./scripts/build-deno
  42. fi