typescript: Register ts-node to run TS modules in frontend tests.

This commit is contained in:
Thomas Ip
2019-02-10 22:22:15 +08:00
committed by Tim Abbott
parent 676eafae7e
commit a290333325
2 changed files with 21 additions and 4 deletions

View File

@@ -1,3 +1,13 @@
require('ts-node').register({
project: 'static/ts/tsconfig.json',
compilerOptions: {
typeRoots: ["node_modules/@types", "../../static/ts/js_typings"],
// We don't have webpack to handle es6 modules here so directly
// transpile to CommonJS format.
module: "commonjs",
},
});
var path = require('path');
var fs = require('fs');

View File

@@ -20,12 +20,19 @@ exports.patch_builtin = function (name, val) {
};
exports.zrequire = function (name, fn) {
var path;
if (fn === undefined) {
fn = 'js/' + name;
try {
path = require.resolve('js/' + name);
} catch (_e /* MODULE_NOT_FOUND */) {
path = require.resolve('ts/' + name);
}
} else {
path = require.resolve(fn);
}
delete require.cache[require.resolve(fn)];
var obj = require(fn);
requires.push(fn);
delete require.cache[path];
var obj = require(path);
requires.push(path);
set_global(name, obj);
return obj;
};