Skip to content

Clean up release dependencies #950

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

Merged
merged 1 commit into from
Nov 13, 2019
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
2 changes: 1 addition & 1 deletion bin/asc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if (~tailArgs) {
return;
}

require("source-map-support").install();
try { require("source-map-support").install(); } catch (e) {}

const asc = module.exports = require("../cli/asc.js");
if (/\basc$/.test(process.argv[1])) {
Expand Down
7 changes: 4 additions & 3 deletions cli/asc.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ if (process.browser) process.cwd = function() { return "."; };

const fs = require("fs");
const path = require("path");
const utf8 = require("@protobufjs/utf8");
const utf8 = require("./util/utf8");
const colorsUtil = require("./util/colors");
const optionsUtil = require("./util/options");
const mkdirp = require("./util/mkdirp");
const find = require("./util/find");
const EOL = process.platform === "win32" ? "\r\n" : "\n";
const SEP = process.platform === "win32" ? "\\" : "/";

Expand Down Expand Up @@ -83,9 +84,9 @@ exports.defaultShrinkLevel = 1;
/** Bundled library files. */
exports.libraryFiles = exports.isBundle ? BUNDLE_LIBRARY : (() => { // set up if not a bundle
const libDir = path.join(__dirname, "..", "std", "assembly");
const libFiles = require("glob").sync("**/!(*.d).ts", { cwd: libDir });
const bundled = {};
libFiles.forEach(file => bundled[file.replace(/\.ts$/, "")] = fs.readFileSync(path.join(libDir, file), "utf8" ));
find.files(libDir, find.TS_EXCEPT_DTS)
.forEach(file => bundled[file.replace(/\.ts$/, "")] = fs.readFileSync(path.join(libDir, file), "utf8" ));
return bundled;
})();

Expand Down
3 changes: 3 additions & 0 deletions cli/util/find.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function files(dirname: string, filter?: ((name: string) => bool) | RegExp): string[];
export const TS: RegExp;
export const TS_EXCEPT_DTS: RegExp;
19 changes: 19 additions & 0 deletions cli/util/find.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const fs = require("fs");
const path = require("path");

function findFiles(dirname, filter) {
var out = [];
fs.readdirSync(dirname).forEach(name => {
if (fs.statSync(path.join(dirname, name)).isDirectory()) {
findFiles(path.join(dirname, name), filter).forEach(iname => out.push(name + "/" + iname));
} else if (!filter || typeof filter === "function" ? filter(name) : filter.test(name)) {
out.push(name);
}
});
return out;
}

exports.files = findFiles;

exports.TS = /\.ts$/;
exports.TS_EXCEPT_DTS = /[^\.][^\d]\.ts$/;
24 changes: 24 additions & 0 deletions cli/util/utf8.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Calculates the UTF8 byte length of a string.
* @param {string} string String
* @returns {number} Byte length
*/
export function length(string: string): number;

/**
* Reads UTF8 bytes as a string.
* @param {Uint8Array} buffer Source buffer
* @param {number} start Source start
* @param {number} end Source end
* @returns {string} String read
*/
export function read(buffer: Uint8Array, start: number, end: number): string;

/**
* Writes a string as UTF8 bytes.
* @param {string} string Source string
* @param {Uint8Array} buffer Destination buffer
* @param {number} offset Destination offset
* @returns {number} Bytes written
*/
export function write(string: string, buffer: Uint8Array, offset: number): number;
105 changes: 105 additions & 0 deletions cli/util/utf8.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// @protobufjs/utf8

/**
* A minimal UTF8 implementation for number arrays.
* @memberof util
* @namespace
*/
var utf8 = exports;

/**
* Calculates the UTF8 byte length of a string.
* @param {string} string String
* @returns {number} Byte length
*/
utf8.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;
};

/**
* Reads UTF8 bytes as a string.
* @param {Uint8Array} buffer Source buffer
* @param {number} start Source start
* @param {number} end Source end
* @returns {string} String read
*/
utf8.read = function utf8_read(buffer, start, end) {
var len = end - start;
if (len < 1)
return "";
var parts = null,
chunk = [],
i = 0, // char offset
t; // temporary
while (start < end) {
t = buffer[start++];
if (t < 128)
chunk[i++] = t;
else if (t > 191 && t < 224)
chunk[i++] = (t & 31) << 6 | buffer[start++] & 63;
else if (t > 239 && t < 365) {
t = ((t & 7) << 18 | (buffer[start++] & 63) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63) - 0x10000;
chunk[i++] = 0xD800 + (t >> 10);
chunk[i++] = 0xDC00 + (t & 1023);
} else
chunk[i++] = (t & 15) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63;
if (i > 8191) {
(parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));
i = 0;
}
}
if (parts) {
if (i)
parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));
return parts.join("");
}
return String.fromCharCode.apply(String, chunk.slice(0, i));
};

/**
* Writes a string as UTF8 bytes.
* @param {string} string Source string
* @param {Uint8Array} buffer Destination buffer
* @param {number} offset Destination offset
* @returns {number} Bytes written
*/
utf8.write = function utf8_write(string, buffer, offset) {
var start = offset,
c1, // character 1
c2; // character 2
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;
};
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
try { require("source-map-support").install(); } catch (e) {}
require("ts-node").register({
project: require("path").join(__dirname, "src", "tsconfig.json"),
skipIgnore: true
Expand Down
Loading