@ endo/ 回避- 转换
逃避审查的源变化 用户- 辅助应用程序
这个软件包提供了一个功能,可以转换源代码,否则会被SES彻底拒绝. 变相是有意义的保留.
它覆盖类似 HTML 注释和动态的序列 import 内 :
- 评论
- 字符串
- 模板字符串(但没有标记模板字符串)
- 正则表达式文字
并额外覆盖与代码本身内部的 HTML 注释相类似的序列(例如, if (a-->b)) (中文(简体) ).
使用量
选项
两者 evadeCensor 财务报告和审定财务报表 evadeCensorSync 接受源字符串为第一个参数,接受选项对象为第二个参数:
| 选项 | 类型 | 说明 |
|---|---|---|
sourceUrl | string | 源文件的 URL 或文件名 。 用于源地图生成和出错消息. |
sourceMap | string | object | 可选的 现有的源图(作为JSON字符串或对象),要随变换的映射而更新. |
sourceType | 'script' | 'module' | 可选的 指定来源是否为普通JS脚本('script')或ES模块('module') (中文(简体) ). 当提供时,它帮助解析器正确处理代码. |
elideComments | boolean | 可选的 若为 true,在保留新行的同时删除注释内容。 默认为 false。 。 。 . |
onlyComments | boolean | 可选的 若为 true,将变换限制为仅注释内容,使代码不变。 默认为 false。 。 。 . |
示例
参见下文的例子,或参见第二个测试 包/组装-mapper/测试/逃避-转换.test.js 以显示其在车厢内的用途.
// 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));
许可证
阿帕奇 - 2.0