@architect/plugin-typescript

中文文档
2.1.0发布于 2024/03/27Apache-2.0CommonJS近 30 天下载 1915

TypeScript custom runtime + workflows integration for Architect

原始使用文档
文档目录7 节
  1. @architect/plugin-typescript
  2. Install
  3. Usage
  4. Configuration
  5. tsconfig.json
  6. Project manifest settings
  7. Caveats

Architect Logo

@architect/plugin-typescript

TypeScript support and workflow integration for Architect

GitHub CI status

Install

Into your existing Architect project:

npm i @architect/plugin-typescript --save-dev

Add the following to your Architect project manifest (usually app.arc):

@aws
runtime typescript # sets TS as the the default runtime for your entire project

@plugins
architect/plugin-typescript

Or, if you'd prefer to add a single TS Lambda to start, forego the above runtime typescript setting in your project manifest, and add the following to a single Lambda:

# src/http/get-index/config.arc
@aws
runtime typescript

Usage

Now, simply author and port Lambdas in the src tree with index.ts handlers. For example:

// src/http/get-index/index.ts
import { Context, APIGatewayProxyResult, APIGatewayEvent } from 'aws-lambda'

export const handler = async (event: APIGatewayEvent, context: Context): Promise<APIGatewayProxyResult> => {
  console.log(`Event:`, event)
  console.log(`Context:`, context)
  return { statusCode: 200, body: JSON.stringify({ message: 'Hello world!' }) }
}

The above function will be automatically transpiled by Architect to ./.build/http/get-index.js. (The destination build directory is configurable, see below.)

When working locally, Sandbox automatically detects changes to your TypeScript handlers and re-transpiles them for you.

Configuration

tsconfig.json

By default, Architect TypeScript will pass your tsconfig.json along to the transpiler,esbuild[^1].

If you have a unique tsconfig.json file for a single Lambda (e.g. src/http/get-index/tsconfig.json), that will be given priority over your project-level TSConfig in the root of your project.

Project manifest settings

The following higher-level settings are also available in your Architect project manifest with the @typescript settings pragma:

  • build - customize the build directory; defaults to .build
    • Note: make sure you add this directory to your .gitignore
  • sourcemaps - enable sourcemaps for Architect environments; defaults to testing + staging
    • List of testing, staging, and/or production environment in which to add sourcemaps, or disable all sourcemaps with false
    • We strongly advise you do not add sourcemaps to your production environment as it may have a meaningful impact on end-user performance and coldstart time
  • esbuild-config - add arbitrary esbuild configuration options
    • Value is a relative path to a CJS file that exports an object of esbuild options; these options will be passed to the build
    • Any options that conflict with this plugin's defaults will be ignored
  • base-runtime - set a different base Node.js version; defaults to nodejs20.x

Example:

@typescript
# Build into `./dist`
build dist

# Disable sourcemaps in `staging`, but add them to `production`; you probably shouldn't actually do this though
sourcemaps testing production

# Add esbuild plugins
esbuild-config esbuild-config.js

# Set the Lambda base runtime to Node.js 18
base-runtime nodejs18.x

Caveats

Architect TypeScript, which uses esbuild, bundles to CommonJS to avoid issues surrounding transpiling to ESM with second-order dynamic requires. However, due to ongoing issues surrounding top-level await in esbuild, TypeScript, V8, etc., top-level await is not yet supported.

If you need top-level await, we suggest authoring in plain JavaScript for the time being.

[^1]: Head here for more information about how esbuild makes use of TSConfig

版本与发布记录

@architect/plugin-typescript 共发布 17 个版本,首次发布于 2022/01/19;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.1.0latest2024/03/272 年前
2.0.02024/02/062 年前
1.2.02023/11/282 年前
1.2.0-RC.0RC2023/04/113 年前
1.1.12023/03/303 年前
1.1.02023/02/213 年前

关于 @architect/plugin-typescript 的常见问题

@architect/plugin-typescript 是什么?

TypeScript custom runtime + workflows integration for Architect

如何安装 @architect/plugin-typescript?

在项目目录运行 npm install @architect/plugin-typescript,或使用 pnpm add / yarn add / bun add。

@architect/plugin-typescript 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/architect__plugin-typescript 是否存在。

@architect/plugin-typescript 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@architect/plugin-typescript 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=14。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@architect/plugin-typescript 可以商用吗?

@architect/plugin-typescript 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@architect/plugin-typescript 的下载量有多少?

根据 npm 官方下载统计,@architect/plugin-typescript 在 2026/10/07 – 2026/11/05 这 30 天内被下载 1,915 次,日均约 64 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@architect/plugin-typescript 还在维护吗?

最新版本 2.1.0 发布于 2024/03/27(2 年前);至今共发布 17 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/01/19。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。