使用 Google Cloud Functions 时如何在 Google Cloud Build 中构建 TypeScript

How to build TypeScript in Google Cloud Build when using Google Cloud Functions

我有在本地构建的 TypeScript 函数,然后提交给 Google Cloud Functions,此时它们通过 Google Cloud Build。我想在一个地方完成我所有的建筑。使用 Google Cloud Functions 时,有什么方法可以在 Google Cloud Build 中编译 TypeScript 吗?

向 Google Cloud Functions 提交代码通过以下 HTTP 调用之一,分别用于创建新函数和修改现有函数:

POST https://cloudfunctions.googleapis.com/v1/{location}/functions
PATCH https://cloudfunctions.googleapis.com/v1/{function.name}

这会使用硬编码 builder 在 Google Cloud Build 中触发构建。假设一个 Yarn 项目,在这个过程的任何部分都没有扩展点。

特别是,构建器运行 NODE_ENV=production yarn install --non-interactive --frozen-lockfile(并且几乎不做其他事情)。指定 NODE_ENV=production 在没有生命周期脚本的情况下运行 yarn install,因此您不能只定义编译 TypeScript 输出的 preparepostinstall 脚本。在将代码提交给 GCF 之前,您需要构建代码