@endo/evasive-transform

中文文档
2.3.1发布于 2026/08/18Apache-2.0TypeScriptES Module近 30 天下载 4.1万

Source transforms to evade SES censorship

原始使用文档
文档目录4 节
  1. Usage
  2. Options
  3. Example
  4. License

@endo/evasive-transform

Source transforms for evading censorship in SES-enabled applications

This package provides a function which transforms source code which would otherwise be rejected outright by SES. The transform is meaning-preserving.

It covers sequences resembling HTML comments and dynamic import inside of:

  • comments
  • strings
  • template strings (but not tagged template strings)
  • regular expression literals

and additionally covers sequences resembling HTML comments inside of code itself (e.g., if (a-->b)).

Usage

Options

Both evadeCensor and evadeCensorSync accept a source string as the first argument and an options object as the second argument:

OptionTypeDescription
sourceUrlstringThe URL or filename of the source file. Used for source map generation and error messages.
sourceMapstring | objectOptional. An existing source map (as JSON string or object) to be updated with the transform's mappings.
sourceType'script' | 'module'Optional. Specifies whether the source is a CommonJS script ('script') or an ES module ('module'). When provided, it helps the parser handle the code correctly.
elideCommentsbooleanOptional. If true, removes comment contents while preserving newlines. Defaults to false.
onlyCommentsbooleanOptional. If true, limits transformation to comment contents only, leaving code unchanged. Defaults to false.

Example

See example below, or see the second test in packages/compartment-mapper/test/evasive-transform.test.js for a demonstration of its usage in compartment-mapper.

// ESM example
import { evadeCensor } from '@endo/evasive-transform';
import fs from 'node:fs/promises';

/**
 * Imagine this file contains a comment like `@property {import('foo').Bar} bar`. SES will refuse to run this code.
 */
const source = await fs.readFile('./dist/index.js', 'utf8');
const sourceMap = await fs.readFile('./dist/index.js.map', 'utf8');
const sourceUrl = 'index.js'; // assuming the source map references index.js
// sourceType can be "script" (CJS) or "module" (ESM)
const sourceType = 'script';

const { code, map } = await evadeCensor(source, {
  sourceMap,
  sourceUrl,
  // always provide a sourceType, if known!
  sourceType,
  elideComments: true,
  onlyComments: true,
});

/**
 * The resulting file will now contain `@property {IMPORT('foo').Bar} bar`, which SES will allow (and TypeScript no longer understands, but that should be fine for the use-case). 
 * 
 * Note that this could be avoided entirely by stripping comments during, say, a bundling phase.
 */
await fs.writeFile('./dist/index.ses.js', code);
await fs.writeFile('./dist/index.ses.js.map', JSON.stringify(map));

License

Apache-2.0

版本与发布记录

@endo/evasive-transform 共发布 24 个版本,首次发布于 2023/10/27;过去 12 个月发布了 4 个版本。

版本发布日期距今
2.3.1latest2026/08/182 个月前
2.3.02026/06/125 个月前
2.2.02026/05/285 个月前
2.1.02026/02/278 个月前
2.0.22025/07/121.3 年前
2.0.12025/06/181.4 年前

关于 @endo/evasive-transform 的常见问题

@endo/evasive-transform 是什么?

Source transforms to evade SES censorship

如何安装 @endo/evasive-transform?

在项目目录运行 npm install @endo/evasive-transform,或使用 pnpm add / yarn add / bun add。

@endo/evasive-transform 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@endo/evasive-transform 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@endo/evasive-transform 可以商用吗?

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

@endo/evasive-transform 的下载量有多少?

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

@endo/evasive-transform 还在维护吗?

最新版本 2.3.1 发布于 2026/08/18(2 个月前);至今共发布 24 个版本,其中过去 12 个月发布了 4 个;首次发布于 2023/10/27。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。