Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix asc build #1236

Merged
merged 3 commits into from
Apr 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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