Skip to content

Commit 9678ce8

Browse files
committed
Also bundle definition files with asc
1 parent 118cf95 commit 9678ce8

File tree

5 files changed

+27
-21
lines changed

5 files changed

+27
-21
lines changed

bin/asc.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ try {
2222

2323
// Common constants
2424

25-
const VERSION = typeof BUNDLE_VERSION === "string" ? BUNDLE_VERSION : require("../package.json").version + (isDev ? "-dev" : "");
26-
const OPTIONS = require("./asc.json");
25+
const isBundle = typeof BUNDLE_VERSION === "string";
26+
const VERSION = exports.version = isBundle ? BUNDLE_VERSION : require("../package.json").version + (isDev ? "-dev" : "");
27+
const OPTIONS = exports.options = require("./asc.json");
2728
const SOURCEMAP_ROOT = "assemblyscript:///";
2829
const LIBRARY_PREFIX = assemblyscript.LIBRARY_PREFIX;
29-
const DEFAULT_OPTIMIZE_LEVEL = 2;
30-
const DEFAULT_SHRINK_LEVEL = 1;
31-
const LIBRARY = typeof BUNDLE_LIBRARY !== "undefined" ? BUNDLE_LIBRARY : {};
32-
33-
exports.VERSION = VERSION;
30+
const DEFAULT_OPTIMIZE_LEVEL = exports.defaultOptimizeLevel = 2;
31+
const DEFAULT_SHRINK_LEVEL = exports.defaultShrinkLevel = 1;
32+
const LIBRARY_FILES = exports.libraryFiles = isBundle ? BUNDLE_LIBRARY : {};
33+
const DEFINITION_FILES = exports.definitionFiles = isBundle ? BUNDLE_DEFINITIONS : {};
3434

3535
function main(argv, options, callback) {
3636
if (typeof options === "function") {
@@ -151,8 +151,8 @@ function main(argv, options, callback) {
151151
// Load library file if explicitly requested
152152
if (sourcePath.startsWith(LIBRARY_PREFIX)) {
153153
for (let i = 0, k = libDirs.length; i < k; ++i) {
154-
if (LIBRARY.hasOwnProperty(sourcePath))
155-
sourceText = LIBRARY[sourcePath];
154+
if (LIBRARY_FILES.hasOwnProperty(sourcePath))
155+
sourceText = LIBRARY_FILES[sourcePath];
156156
else {
157157
sourceText = readFile(path.join(libDirs[i], sourcePath.substring(LIBRARY_PREFIX.length) + ".ts"));
158158
if (sourceText !== null) {
@@ -169,8 +169,8 @@ function main(argv, options, callback) {
169169
sourceText = readFile(path.join(baseDir, sourcePath, "index.ts"));
170170
if (sourceText === null) {
171171
for (let i = 0, k = libDirs.length; i < k; ++i) {
172-
if (LIBRARY.hasOwnProperty(LIBRARY_PREFIX + sourcePath))
173-
sourceText = LIBRARY[LIBRARY_PREFIX + sourcePath];
172+
if (LIBRARY_FILES.hasOwnProperty(LIBRARY_PREFIX + sourcePath))
173+
sourceText = LIBRARY_FILES[LIBRARY_PREFIX + sourcePath];
174174
else {
175175
sourceText = readFile(path.join(libDirs[i], sourcePath + ".ts"));
176176
if (sourceText !== null) {
@@ -196,10 +196,10 @@ function main(argv, options, callback) {
196196
// Include (other) library components
197197
var hasBundledLibrary = false;
198198
if (!args.noLib)
199-
Object.keys(LIBRARY).forEach(libPath => {
199+
Object.keys(LIBRARY_FILES).forEach(libPath => {
200200
if (libPath.lastIndexOf("/") >= LIBRARY_PREFIX.length) return;
201201
stats.parseCount++;
202-
stats.parseTime += measure(() => { parser = assemblyscript.parseFile(LIBRARY[libPath], libPath + ".ts", parser, false); });
202+
stats.parseTime += measure(() => { parser = assemblyscript.parseFile(LIBRARY_FILES[libPath], libPath + ".ts", parser, false); });
203203
hasBundledLibrary = true;
204204
});
205205
for (let i = 0, k = libDirs.length; i < k; ++i) {

dist/asc.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/assemblyscript.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/bundled-asc.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
var asc = require("../dist/asc.js");
22

3+
console.log(Object.keys(asc));
4+
35
var stdout = asc.createMemoryStream();
46
var stderr = asc.createMemoryStream();
57
var stats = asc.createStats();

webpack.config.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ const bin = {
7171
const libDir = path.join(__dirname, "std", "assembly");
7272
const libFiles = require("glob").sync("**/*.ts", { cwd: libDir });
7373
const lib = {};
74-
libFiles.forEach(file => {
75-
// console.log("bundling '(lib)/" + file + "'");
76-
var source = fs.readFileSync(path.join(libDir, file), { encoding: "utf8" });
77-
lib["(lib)/" + file.replace(/\.ts$/, "")] = JSON.stringify(source);
78-
});
74+
libFiles.forEach(file => lib["(lib)/" + file.replace(/\.ts$/, "")] = bundleFile(path.join(libDir, file)));
7975
return lib;
8076
})(),
77+
BUNDLE_DEFINITIONS: {
78+
"assembly": bundleFile(path.join(__dirname, "std", "assembly.d.ts")),
79+
"portable": bundleFile(path.join(__dirname, "std", "portable.d.ts"))
80+
},
8181
__dirname: JSON.stringify(".")
8282
}),
8383
new webpack.IgnorePlugin(/\.\/src|package\.json|^(ts\-node|glob|source\-map\-support)$/),
@@ -91,4 +91,8 @@ const bin = {
9191
]
9292
};
9393

94+
function bundleFile(filename) {
95+
return JSON.stringify(fs.readFileSync(filename, { encoding: "utf8" }).replace(/\r\n/g, "\n"));
96+
}
97+
9498
module.exports = [ lib, bin ];

0 commit comments

Comments
 (0)