Remove unnecessary dependencies in asc bundle; Update dependencies

This commit is contained in:
dcodeIO 2018-03-31 00:03:02 +02:00
parent 60f75c931b
commit 2e5077da2d
8 changed files with 303 additions and 311 deletions

View File

@ -13,7 +13,8 @@
const fs = require("fs");
const path = require("path");
const os = require("os");
const utf8 = require("./util/utf8");
const EOL = process.platform === "win32" ? "\r\n" : "\n";
// Use distribution files if present, otherwise run the sources directly
var assemblyscript, isDev;
@ -152,7 +153,7 @@ exports.main = function main(argv, options, callback) {
if (!callback) callback = function defaultCallback(err) {
var code = 0;
if (err) {
stderr.write(err.stack + os.EOL);
stderr.write(err.stack + EOL);
code = 1;
}
return code;
@ -160,7 +161,7 @@ exports.main = function main(argv, options, callback) {
// Just print the version if requested
if (args.version) {
stdout.write("Version " + exports.version + (isDev ? "-dev" : "") + os.EOL);
stdout.write("Version " + exports.version + (isDev ? "-dev" : "") + EOL);
return callback(null);
}
// Print the help message if requested or no source files are provided
@ -181,7 +182,7 @@ exports.main = function main(argv, options, callback) {
for (let i = 0; i < indent; ++i) {
line = " " + line;
}
return os.EOL + line;
return EOL + line;
}).join(""));
} else {
opts.push(text + option.desc);
@ -197,7 +198,7 @@ exports.main = function main(argv, options, callback) {
" asc hello1.ts hello2.ts -b -O > hello.wasm",
"",
"Options:"
].concat(opts).join(os.EOL) + os.EOL);
].concat(opts).join(EOL) + EOL);
return callback(null);
}
@ -566,7 +567,7 @@ exports.main = function main(argv, options, callback) {
path.basename(sourceMapURL)
), JSON.stringify(sourceMap));
} else {
stderr.write("Skipped source map (stdout already occupied)" + os.EOL);
stderr.write("Skipped source map (stdout already occupied)" + EOL);
}
}
}
@ -741,7 +742,7 @@ function checkDiagnostics(emitter, stderr) {
while ((diagnostic = assemblyscript.nextDiagnostic(emitter)) != null) {
stderr.write(
assemblyscript.formatDiagnostic(diagnostic, stderr.isTTY, true) +
os.EOL + os.EOL
EOL + EOL
);
if (assemblyscript.isError(diagnostic)) hasErrors = true;
}
@ -803,24 +804,36 @@ function printStats(stats, output) {
"Emit : " + format(stats.emitTime, stats.emitCount),
"Validate : " + format(stats.validateTime, stats.validateCount),
"Optimize : " + format(stats.optimizeTime, stats.optimizeCount)
].join(os.EOL) + os.EOL);
].join(EOL) + EOL);
}
exports.printStats = printStats;
var Buf = typeof global !== "undefined" && global.Buffer || Uint8Array;
/** Creates a memory stream that can be used in place of stdout/stderr. */
function createMemoryStream(fn) {
var stream = [];
stream.write = function(chunk) {
if (typeof chunk === "string") {
this.push(Buffer.from(chunk, "utf8"));
} else {
this.push(chunk);
let buffer = new Buf(utf8.length(chunk));
utf8.write(chunk, buffer, 0);
chunk = buffer;
}
this.push(chunk);
if (fn) fn(chunk);
};
stream.toBuffer = function() {
return Buffer.concat(this);
var offset = 0, i = 0, k = this.length;
while (i < k) offset += this[i++].length;
var buffer = new Buf(offset);
offset = i = 0;
while (i < k) {
buffer.set(this[i], offset);
offset += this[i].length;
++i;
}
return buffer;
};
stream.toString = function() {
return this.toBuffer().toString("utf8");

46
bin/util/utf8.js Normal file
View File

@ -0,0 +1,46 @@
// see: https://github.com/dcodeIO/protobuf.js/tree/master/lib/utf8
exports.length = function utf8_length(string) {
var len = 0,
c = 0;
for (var i = 0; i < string.length; ++i) {
c = string.charCodeAt(i);
if (c < 128) {
len += 1;
} else if (c < 2048) {
len += 2;
} else if ((c & 0xFC00) === 0xD800 && (string.charCodeAt(i + 1) & 0xFC00) === 0xDC00) {
++i;
len += 4;
} else {
len += 3;
}
}
return len;
};
exports.write = function utf8_write(string, buffer, offset) {
var start = offset,
c1, c2;
for (var i = 0; i < string.length; ++i) {
c1 = string.charCodeAt(i);
if (c1 < 128) {
buffer[offset++] = c1;
} else if (c1 < 2048) {
buffer[offset++] = c1 >> 6 | 192;
buffer[offset++] = c1 & 63 | 128;
} else if ((c1 & 0xFC00) === 0xD800 && ((c2 = string.charCodeAt(i + 1)) & 0xFC00) === 0xDC00) {
c1 = 0x10000 + ((c1 & 0x03FF) << 10) + (c2 & 0x03FF);
++i;
buffer[offset++] = c1 >> 18 | 240;
buffer[offset++] = c1 >> 12 & 63 | 128;
buffer[offset++] = c1 >> 6 & 63 | 128;
buffer[offset++] = c1 & 63 | 128;
} else {
buffer[offset++] = c1 >> 12 | 224;
buffer[offset++] = c1 >> 6 & 63 | 128;
buffer[offset++] = c1 & 63 | 128;
}
}
return offset - start;
};

2
dist/asc.js vendored

File diff suppressed because one or more lines are too long

2
dist/asc.js.map vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

505
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -11,25 +11,25 @@
"url": "https://github.com/AssemblyScript/assemblyscript/issues"
},
"dependencies": {
"binaryen": "44.0.0-nightly.20180309",
"binaryen": "45.0.0-nightly.20180330",
"glob": "^7.1.2",
"long": "^4.0.0",
"minimist": "^1.2.0",
"ts-node": "^5.0.1"
},
"devDependencies": {
"@types/node": "^9.4.7",
"@types/node": "^9.6.1",
"browser-process-hrtime": "^0.1.2",
"chalk": "^2.3.2",
"diff": "^3.5.0",
"source-map-support": "^0.5.3",
"ts-loader": "^4.0.1",
"source-map-support": "^0.5.4",
"ts-loader": "^4.1.0",
"tslint": "^5.9.1",
"typedoc": "^0.11.1",
"typedoc-plugin-external-module-name": "^1.1.1",
"typescript": "^2.7.2",
"webpack": "^4.1.1",
"webpack-cli": "^2.0.11"
"typescript": "^2.8.1",
"webpack": "^4.4.1",
"webpack-cli": "^2.0.13"
},
"main": "index.js",
"types": "index.d.ts",
@ -40,7 +40,7 @@
"node": ">=8"
},
"scripts": {
"build": "webpack --mode production",
"build": "webpack --mode production --display-modules",
"clean": "node scripts/clean",
"lint": "npm run lint:compiler && npm run lint:library",
"lint:compiler": "tslint -c tslint.json --project src --formatters-dir lib/lint/formatters --format as",

View File

@ -39,10 +39,12 @@ const bin = {
"../dist/assemblyscript.js": "assemblyscript"
}],
node: {
"buffer": false,
"fs": "empty",
"global": true,
"os": false,
"process": "mock",
"crypto": "empty"
"crypto": false
},
output: {
filename: "asc.js",