yeg
2026-09-09 b226aa0db7fbecb8fff92476537adc0ca3e16a4f
1
2
3
4
5
6
7
8
9
10
11
12
const fs = require('node:fs');
const path = require('node:path');
const ts = require('typescript');
// 无服务的公共绘图函数测试;加载器只负责转译本地 TypeScript 模块。
module.exports = function load(file) {
  if (file instanceof URL) file = require('node:url').fileURLToPath(file);
  const source = fs.readFileSync(file, 'utf8');
  const script = ts.transpileModule(source, { compilerOptions: { target: ts.ScriptTarget.ES2022, module: ts.ModuleKind.CommonJS } }).outputText;
  const exports = {};
  new Function('exports', 'require', script)(exports, id => id.startsWith('.') ? load(path.resolve(path.dirname(file), id.endsWith('.ts') ? id : id + '.ts')) : require(id));
  return exports;
};