Fix missing dependency in asc, see #157; Downgrade ts-node to v6

This commit is contained in:
dcodeIO
2018-07-04 21:47:58 +02:00
parent 5ca5df3dc7
commit c4ebc8c291
19 changed files with 79 additions and 91 deletions

View File

@ -24,17 +24,25 @@ const EOL = process.platform === "win32" ? "\r\n" : "\n";
// Use distribution files if present, otherwise run the sources directly
var assemblyscript, isDev = false;
(() => {
try {
try { // `asc` on the command line
assemblyscript = require("../dist/assemblyscript.js");
} catch (e) {
try {
try { // `asc` on the command line without dist files
require("ts-node").register({ project: path.join(__dirname, "..", "src", "tsconfig.json") });
require("../src/glue/js");
assemblyscript = require("../src");
isDev = true;
} catch (e) {
// last resort: same directory CommonJS
assemblyscript = eval("require('./assemblyscript')");
} catch (e_ts) {
try { // `require("dist/asc.js")` in explicit browser tests
assemblyscript = eval("require('./assemblyscript')");
} catch (e) {
// combine both errors that lead us here
e.stack = e_ts.stack + "\n---\n" + e.stack;
// Emscripten adds an `uncaughtException` listener to Binaryen that results in an additional
// useless code fragment on top of the actual error. suppress this:
if (process.removeAllListeners) process.removeAllListeners("uncaughtException");
throw e;
}
}
}
})();
@ -408,9 +416,8 @@ exports.main = function main(argv, options, callback) {
assemblyscript.setGlobalAlias(compilerOptions, "abort", "~lib/env/abort"); // to disable: --use abort=
// Add or override aliases if specified
var aliases = args.use;
if (aliases != null) {
if (typeof aliases === "string") aliases = aliases.split(",");
if (args.use) {
let aliases = args.use;
for (let i = 0, k = aliases.length; i < k; ++i) {
let part = aliases[i];
let p = part.indexOf("=");
@ -709,7 +716,7 @@ exports.main = function main(argv, options, callback) {
var files;
try {
stats.readTime += measure(() => {
files = require("glob").sync("!(*.d).ts", { cwd: dirname });
files = fs.readdirSync(dirname).filter(file => /^(?!.*\.d\.ts$).*\.ts$/.test(file));
});
return files;
} catch (e) {

View File

@ -133,7 +133,7 @@
"Aliases a global object under another name, e.g., to switch",
"the default 'Math' implementation used: --use Math=JSMath"
],
"type": "s",
"type": "S",
"alias": "u"
},
"trapMode": {

View File

@ -30,13 +30,15 @@ function parse(argv, config) {
for (var i = 0, k = (argv = argv.slice()).length; i < k; ++i) {
let arg = argv[i];
if (arg == "--") { ++i; break; }
let match = /^(?:(\-\w)|(\-\-\w{2,})(?:=(.*))?)$/.exec(arg), option, key;
let match = /^(?:(\-\w)(?:=(.*))?|(\-\-\w{2,})(?:=(.*))?)$/.exec(arg), option, key;
if (match) {
if (config[arg]) option = config[key = arg]; // exact
else if (match[1] != null) option = config[key = aliases[match[1].substring(1)]]; // alias
else if (match[2] != null) {
option = config[key = match[2].substring(2)]; // full
if (option && match[3] != null) argv[i--] = match[3];
else if (match[1] != null) { // alias
option = config[key = aliases[match[1].substring(1)]];
if (option && match[2] != null) argv[i--] = match[2];
} else if (match[3] != null) { // full
option = config[key = match[3].substring(2)];
if (option && match[4] != null) argv[i--] = match[4];
}
} else {
if (arg.charCodeAt(0) == 45) option = config[key = arg]; // exact