Skip to content

Commit

Permalink
Fix asc build (#1236)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Apr 21, 2020
1 parent 387c698 commit f2a1916
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 23 deletions.
50 changes: 30 additions & 20 deletions cli/asc.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const mkdirp = require("./util/mkdirp");
const find = require("./util/find");
const EOL = process.platform === "win32" ? "\r\n" : "\n";
const SEP = process.platform === "win32" ? "\\" : "/";
const binaryen = global.Binaryen || (global.Binaryen = require("binaryen"));
const binaryen = global.binaryen || (global.binaryen = require("binaryen"));

// Proxy Binaryen's ready event
Object.defineProperty(exports, "ready", {
Expand All @@ -51,28 +51,38 @@ Object.defineProperty(exports, "ready", {
// useless code fragment on top of an actual error. suppress this:
if (process.removeAllListeners) process.removeAllListeners("uncaughtException");

// Use distribution files if present, otherwise run the sources directly
var assemblyscript, isDev = false;
try { // `asc` on the command line
assemblyscript = require("../dist/assemblyscript.js");
} catch (e) {
try { // `asc` on the command line without dist files
require("ts-node").register({
project: path.join(__dirname, "..", "src", "tsconfig.json"),
skipIgnore: true,
compilerOptions: { target: "ES2016" }
});
require("../src/glue/js");
assemblyscript = require("../src");
isDev = true;
} catch (e_ts) {
try { // `require("dist/asc.js")` in explicit browser tests
assemblyscript = eval("require('./assemblyscript')");
// Use distribution files if present, otherwise run the sources directly.
var assemblyscript;
var isDev = false;
(function loadAssemblyScript() {
try {
assemblyscript = require("assemblyscript");
} catch (e) {
function dynRequire(...args) {
return eval("require")(...args);
}
try { // `asc` on the command line
assemblyscript = dynRequire("../dist/assemblyscript.js");
} catch (e) {
throw Error(e_ts.stack + "\n---\n" + e.stack);
try { // `asc` on the command line without dist files
dynRequire("ts-node").register({
project: path.join(__dirname, "..", "src", "tsconfig.json"),
skipIgnore: true,
compilerOptions: { target: "ES2016" }
});
dynRequire("../src/glue/js");
assemblyscript = dynRequire("../src");
isDev = true;
} catch (e_ts) {
try { // `require("dist/asc.js")` in explicit browser tests
assemblyscript = dynRequire("./assemblyscript");
} catch (e) {
throw Error(e_ts.stack + "\n---\n" + e.stack);
}
}
}
}
}
})();

/** Whether this is a webpack bundle or not. */
exports.isBundle = typeof BUNDLE_VERSION === "string";
Expand Down
2 changes: 1 addition & 1 deletion src/glue/binaryen.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @license Apache-2.0
*/

const binaryen = global.Binaryen || (global.Binaryen = require("binaryen"));
const binaryen = global.binaryen || (global.binaryen = require("binaryen"));

module.exports = binaryen;

Expand Down
2 changes: 1 addition & 1 deletion tests/decompiler.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var binaryen = global.Binaryen = require("../lib/binaryen");
var binaryen = global.binaryen = require("../lib/binaryen");

require("ts-node").register({ project: require("path").join(__dirname, "..", "src", "tsconfig.json") });
require("../src/glue/js");
Expand Down
4 changes: 3 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ const bin = {
context: path.join(__dirname, "cli"),
entry: [ "./asc.js" ],
externals: [
{ "../dist/assemblyscript.js": "assemblyscript" }
"binaryen",
"assemblyscript",
"ts-node"
],
node: {
"buffer": false,
Expand Down

0 comments on commit f2a1916

Please sign in to comment.