toilscript 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/NOTICE +94 -0
- package/README.md +114 -0
- package/bin/asc.js +35 -0
- package/bin/asinit.js +468 -0
- package/dist/asc.d.ts +4 -0
- package/dist/toilscript.d.ts +4 -0
- package/dist/transform.cjs +1 -0
- package/dist/transform.d.ts +1 -0
- package/dist/transform.js +1 -0
- package/lib/binaryen.d.ts +2 -0
- package/lib/binaryen.js +2 -0
- package/package.json +114 -0
- package/std/README.md +6 -0
- package/std/assembly/array.ts +550 -0
- package/std/assembly/arraybuffer.ts +77 -0
- package/std/assembly/atomics.ts +127 -0
- package/std/assembly/bindings/asyncify.ts +16 -0
- package/std/assembly/bindings/dom.ts +291 -0
- package/std/assembly/bindings/node.ts +6 -0
- package/std/assembly/bitflags.ts +53 -0
- package/std/assembly/builtins.ts +2650 -0
- package/std/assembly/byteslice.ts +177 -0
- package/std/assembly/compat.ts +2 -0
- package/std/assembly/console.ts +42 -0
- package/std/assembly/crypto.ts +9 -0
- package/std/assembly/dataview.ts +181 -0
- package/std/assembly/date.ts +375 -0
- package/std/assembly/diagnostics.ts +11 -0
- package/std/assembly/encoding.ts +151 -0
- package/std/assembly/endian.ts +45 -0
- package/std/assembly/error.ts +44 -0
- package/std/assembly/fixedarray.ts +173 -0
- package/std/assembly/fixedmap.ts +326 -0
- package/std/assembly/fixedset.ts +275 -0
- package/std/assembly/function.ts +42 -0
- package/std/assembly/index.d.ts +2891 -0
- package/std/assembly/iterator.ts +35 -0
- package/std/assembly/map.ts +269 -0
- package/std/assembly/math.ts +3289 -0
- package/std/assembly/memory.ts +123 -0
- package/std/assembly/number.ts +388 -0
- package/std/assembly/object.ts +36 -0
- package/std/assembly/performance.ts +9 -0
- package/std/assembly/pointer.ts +80 -0
- package/std/assembly/polyfills.ts +27 -0
- package/std/assembly/process.ts +50 -0
- package/std/assembly/reference.ts +48 -0
- package/std/assembly/regexp.ts +12 -0
- package/std/assembly/rt/README.md +83 -0
- package/std/assembly/rt/common.ts +81 -0
- package/std/assembly/rt/index-incremental.ts +2 -0
- package/std/assembly/rt/index-memory.ts +1 -0
- package/std/assembly/rt/index-minimal.ts +2 -0
- package/std/assembly/rt/index-stub.ts +1 -0
- package/std/assembly/rt/index.d.ts +37 -0
- package/std/assembly/rt/itcms.ts +419 -0
- package/std/assembly/rt/memory-runtime.ts +94 -0
- package/std/assembly/rt/rtrace.ts +15 -0
- package/std/assembly/rt/stub.ts +133 -0
- package/std/assembly/rt/tcms.ts +254 -0
- package/std/assembly/rt/tlsf.ts +592 -0
- package/std/assembly/rt.ts +90 -0
- package/std/assembly/set.ts +225 -0
- package/std/assembly/shared/feature.ts +68 -0
- package/std/assembly/shared/runtime.ts +13 -0
- package/std/assembly/shared/target.ts +11 -0
- package/std/assembly/shared/tsconfig.json +11 -0
- package/std/assembly/shared/typeinfo.ts +72 -0
- package/std/assembly/staticarray.ts +423 -0
- package/std/assembly/string.ts +850 -0
- package/std/assembly/symbol.ts +114 -0
- package/std/assembly/table.ts +16 -0
- package/std/assembly/tsconfig.json +6 -0
- package/std/assembly/typedarray.ts +1954 -0
- package/std/assembly/uri.ts +17 -0
- package/std/assembly/util/bytes.ts +107 -0
- package/std/assembly/util/casemap.ts +497 -0
- package/std/assembly/util/error.ts +58 -0
- package/std/assembly/util/hash.ts +117 -0
- package/std/assembly/util/math.ts +1922 -0
- package/std/assembly/util/memory.ts +290 -0
- package/std/assembly/util/number.ts +873 -0
- package/std/assembly/util/sort.ts +313 -0
- package/std/assembly/util/string.ts +1202 -0
- package/std/assembly/util/uri.ts +275 -0
- package/std/assembly/vector.ts +4 -0
- package/std/assembly.json +16 -0
- package/std/portable/index.d.ts +461 -0
- package/std/portable/index.js +416 -0
- package/std/portable.json +11 -0
- package/std/types/assembly/index.d.ts +1 -0
- package/std/types/assembly/package.json +3 -0
- package/std/types/portable/index.d.ts +1 -0
- package/std/types/portable/package.json +3 -0
- package/tsconfig-base.json +13 -0
- package/util/README.md +23 -0
- package/util/browser/fs.js +1 -0
- package/util/browser/module.js +5 -0
- package/util/browser/path.js +520 -0
- package/util/browser/process.js +59 -0
- package/util/browser/url.js +23 -0
- package/util/cpu.d.ts +9 -0
- package/util/cpu.js +42 -0
- package/util/find.d.ts +6 -0
- package/util/find.js +20 -0
- package/util/node.d.ts +21 -0
- package/util/node.js +34 -0
- package/util/options.d.ts +70 -0
- package/util/options.js +262 -0
- package/util/terminal.d.ts +52 -0
- package/util/terminal.js +35 -0
- package/util/text.d.ts +26 -0
- package/util/text.js +114 -0
- package/util/tsconfig.json +9 -0
- package/util/web.d.ts +11 -0
- package/util/web.js +33 -0
package/bin/asinit.js
ADDED
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import { createRequire } from "module";
|
|
6
|
+
import { fileURLToPath } from "url";
|
|
7
|
+
import { stdoutColors } from "../util/terminal.js";
|
|
8
|
+
import * as optionsUtil from "../util/options.js";
|
|
9
|
+
|
|
10
|
+
const dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
11
|
+
const require = createRequire(import.meta.url);
|
|
12
|
+
const version = require("../package.json").version; // TODO
|
|
13
|
+
|
|
14
|
+
const npmDefaultTest = "echo \"Error: no test specified\" && exit 1";
|
|
15
|
+
|
|
16
|
+
const commands = {
|
|
17
|
+
"npm": {
|
|
18
|
+
install: "npm install",
|
|
19
|
+
run: "npm run",
|
|
20
|
+
test: "npm test"
|
|
21
|
+
},
|
|
22
|
+
"yarn": {
|
|
23
|
+
install: "yarn install",
|
|
24
|
+
run: "yarn",
|
|
25
|
+
test: "yarn test"
|
|
26
|
+
},
|
|
27
|
+
"pnpm": {
|
|
28
|
+
install: "pnpm install",
|
|
29
|
+
run: "pnpm run",
|
|
30
|
+
test: "pnpm test"
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
let pm = "npm";
|
|
35
|
+
if (typeof process.env.npm_config_user_agent === "string") {
|
|
36
|
+
if (/\byarn\//.test(process.env.npm_config_user_agent)) {
|
|
37
|
+
pm = "yarn";
|
|
38
|
+
} else if (/\bpnpm\//.test(process.env.npm_config_user_agent)) {
|
|
39
|
+
pm = "pnpm";
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const asinitOptions = {
|
|
44
|
+
"help": {
|
|
45
|
+
"category": "General",
|
|
46
|
+
"description": "Prints this help message.",
|
|
47
|
+
"type": "b",
|
|
48
|
+
"alias": "h"
|
|
49
|
+
},
|
|
50
|
+
"yes": {
|
|
51
|
+
"category": "General",
|
|
52
|
+
"description": [
|
|
53
|
+
"Answers all questions with their default option",
|
|
54
|
+
"for non-interactive usage."
|
|
55
|
+
],
|
|
56
|
+
"type": "b",
|
|
57
|
+
"alias": "y"
|
|
58
|
+
},
|
|
59
|
+
"noColors": {
|
|
60
|
+
"description": "Disables terminal colors.",
|
|
61
|
+
"type": "b",
|
|
62
|
+
"default": false
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const cliOptions = optionsUtil.parse(process.argv.slice(2), asinitOptions);
|
|
67
|
+
|
|
68
|
+
if (cliOptions.options.noColors) {
|
|
69
|
+
stdoutColors.enabled = false;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (cliOptions.options.help || cliOptions.arguments.length === 0) printHelp();
|
|
73
|
+
|
|
74
|
+
function printHelp() {
|
|
75
|
+
console.log([
|
|
76
|
+
"Sets up a new ToilScript project or updates an existing one.",
|
|
77
|
+
"",
|
|
78
|
+
stdoutColors.white("SYNTAX"),
|
|
79
|
+
" " + stdoutColors.cyan("asinit") + " directory [options]",
|
|
80
|
+
"",
|
|
81
|
+
stdoutColors.white("EXAMPLES"),
|
|
82
|
+
" " + stdoutColors.cyan("asinit") + " .",
|
|
83
|
+
" " + stdoutColors.cyan("asinit") + " ./newProject -y",
|
|
84
|
+
"",
|
|
85
|
+
stdoutColors.white("OPTIONS"),
|
|
86
|
+
optionsUtil.help(asinitOptions, { noCategories: true })
|
|
87
|
+
].join("\n"));
|
|
88
|
+
process.exit(0);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const compilerDir = path.join(dirname, "..");
|
|
92
|
+
const projectDir = path.resolve(cliOptions.arguments[0]);
|
|
93
|
+
const assemblyDir = path.join(projectDir, "assembly");
|
|
94
|
+
const tsconfigFile = path.join(assemblyDir, "tsconfig.json");
|
|
95
|
+
const toilconfigFile = path.join(projectDir, "toilconfig.json");
|
|
96
|
+
let tsconfigBase = path.relative(assemblyDir, path.join(compilerDir, "std", "assembly.json"));
|
|
97
|
+
if (/^(\.\.[/\\])*node_modules[/\\]toilscript[/\\]/.test(tsconfigBase)) {
|
|
98
|
+
// Use node resolution if the compiler is a normal dependency
|
|
99
|
+
tsconfigBase = "toilscript/std/assembly.json";
|
|
100
|
+
}
|
|
101
|
+
const entryFile = path.join(assemblyDir, "index.ts");
|
|
102
|
+
const buildDir = path.join(projectDir, "build");
|
|
103
|
+
const testsDir = path.join(projectDir, "test");
|
|
104
|
+
const gitignoreFile = path.join(buildDir, ".gitignore");
|
|
105
|
+
const packageFile = path.join(projectDir, "package.json");
|
|
106
|
+
|
|
107
|
+
const indexHtmlFile = path.join(projectDir, "index.html");
|
|
108
|
+
const testsIndexFile = path.join(testsDir, "index.js");
|
|
109
|
+
|
|
110
|
+
const paths = [
|
|
111
|
+
[assemblyDir, "Directory holding the ToilScript sources being compiled to WebAssembly."],
|
|
112
|
+
[tsconfigFile, "TypeScript configuration inheriting recommended ToilScript settings."],
|
|
113
|
+
[entryFile, "Example entry file being compiled to WebAssembly to get you started."],
|
|
114
|
+
[buildDir, "Build artifact directory where compiled WebAssembly files are stored."],
|
|
115
|
+
[gitignoreFile, "Git configuration that excludes compiled binaries from source control."],
|
|
116
|
+
[toilconfigFile, "Configuration file defining both a 'debug' and a 'release' target."],
|
|
117
|
+
[packageFile, "Package info containing the necessary commands to compile to WebAssembly."],
|
|
118
|
+
[testsIndexFile, "Starter test to check that the module is functioning."],
|
|
119
|
+
[indexHtmlFile, "Starter HTML file that loads the module in a browser."]
|
|
120
|
+
];
|
|
121
|
+
|
|
122
|
+
const formatPath = filePath => "./" + path.relative(projectDir, filePath).replace(/\\/g, "/");
|
|
123
|
+
|
|
124
|
+
if (fs.existsSync(packageFile)) {
|
|
125
|
+
const pkg = JSON.parse(fs.readFileSync(packageFile));
|
|
126
|
+
if ("type" in pkg && pkg["type"] !== "module") {
|
|
127
|
+
console.error(stdoutColors.red([
|
|
128
|
+
`Error: The "type" field in ${formatPath(packageFile)} is set to "${pkg["type"]}".`,
|
|
129
|
+
` asinit requires the "type" field to be set to "module" (ES modules).`
|
|
130
|
+
].join("\n")));
|
|
131
|
+
process.exit(1);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
console.log([
|
|
136
|
+
"Version: " + version,
|
|
137
|
+
"",
|
|
138
|
+
stdoutColors.white([
|
|
139
|
+
"This command will make sure that the following files exist in the project",
|
|
140
|
+
"directory '" + projectDir + "':"
|
|
141
|
+
].join("\n")),
|
|
142
|
+
...paths.map(([filePath, description]) => "\n " + stdoutColors.cyan(formatPath(filePath)) + "\n " + description),
|
|
143
|
+
"",
|
|
144
|
+
"The command will try to update existing files to match the correct settings",
|
|
145
|
+
"for this instance of the compiler in '" + compilerDir + "'.",
|
|
146
|
+
""
|
|
147
|
+
].join("\n"));
|
|
148
|
+
|
|
149
|
+
function createProject(answer) {
|
|
150
|
+
if (!/^y?$/i.test(answer)) {
|
|
151
|
+
process.exit(1);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
console.log();
|
|
155
|
+
ensureProjectDirectory();
|
|
156
|
+
ensureAssemblyDirectory();
|
|
157
|
+
ensureTsconfigJson();
|
|
158
|
+
ensureEntryFile();
|
|
159
|
+
ensureBuildDirectory();
|
|
160
|
+
ensureGitignore();
|
|
161
|
+
ensurePackageJson();
|
|
162
|
+
ensureAsconfigJson();
|
|
163
|
+
ensureTestsDirectory();
|
|
164
|
+
ensureTestsIndexJs();
|
|
165
|
+
ensureIndexHtml();
|
|
166
|
+
|
|
167
|
+
console.log([
|
|
168
|
+
stdoutColors.green("Done!"),
|
|
169
|
+
"",
|
|
170
|
+
"Don't forget to install dependencies before you start:",
|
|
171
|
+
"",
|
|
172
|
+
stdoutColors.white(" " + commands[pm].install),
|
|
173
|
+
"",
|
|
174
|
+
"To edit the entry file, open '" + stdoutColors.cyan("assembly/index.ts") + "' in your editor of choice.",
|
|
175
|
+
"Create as many additional files as necessary and use them as imports.",
|
|
176
|
+
"",
|
|
177
|
+
"To build the entry file to WebAssembly when you are ready, run:",
|
|
178
|
+
"",
|
|
179
|
+
stdoutColors.white(" " + commands[pm].run + " asbuild"),
|
|
180
|
+
"",
|
|
181
|
+
"Running the command above creates the following binaries incl. their respective",
|
|
182
|
+
"text format representations and source maps:",
|
|
183
|
+
"",
|
|
184
|
+
stdoutColors.cyan(" ./build/debug.wasm"),
|
|
185
|
+
stdoutColors.cyan(" ./build/debug.wasm.map"),
|
|
186
|
+
stdoutColors.cyan(" ./build/debug.wat"),
|
|
187
|
+
"",
|
|
188
|
+
" ^ The debuggable WebAssembly module as generated by the compiler.",
|
|
189
|
+
" This one matches your sources exactly, without any optimizations.",
|
|
190
|
+
"",
|
|
191
|
+
stdoutColors.cyan(" ./build/release.wasm"),
|
|
192
|
+
stdoutColors.cyan(" ./build/release.wasm.map"),
|
|
193
|
+
stdoutColors.cyan(" ./build/release.wat"),
|
|
194
|
+
"",
|
|
195
|
+
" ^ The optimized WebAssembly module using default optimization settings.",
|
|
196
|
+
" You can change the optimization settings in '" + stdoutColors.cyan("package.json")+ "'.",
|
|
197
|
+
"",
|
|
198
|
+
"To run the tests, do:",
|
|
199
|
+
"",
|
|
200
|
+
stdoutColors.white(" " + commands[pm].test),
|
|
201
|
+
"",
|
|
202
|
+
"The ToilScript documentation covers all the details:",
|
|
203
|
+
"",
|
|
204
|
+
" https://www.assemblyscript.org",
|
|
205
|
+
"",
|
|
206
|
+
"Have a nice day!"
|
|
207
|
+
].join("\n"));
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (cliOptions.options.yes) {
|
|
211
|
+
createProject("y");
|
|
212
|
+
} else {
|
|
213
|
+
const rl = require("readline").createInterface({
|
|
214
|
+
input: process.stdin,
|
|
215
|
+
output: process.stdout
|
|
216
|
+
});
|
|
217
|
+
rl.question(stdoutColors.white("Do you want to proceed?") + " [Y/n] ", result => {
|
|
218
|
+
rl.close();
|
|
219
|
+
createProject(result);
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function ensureProjectDirectory() {
|
|
224
|
+
console.log("- Making sure that the project directory exists...");
|
|
225
|
+
if (!fs.existsSync(projectDir)) {
|
|
226
|
+
fs.mkdirSync(projectDir);
|
|
227
|
+
console.log(stdoutColors.green(" Created: ") + projectDir);
|
|
228
|
+
} else {
|
|
229
|
+
console.log(stdoutColors.yellow(" Exists: ") + projectDir);
|
|
230
|
+
}
|
|
231
|
+
console.log();
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function ensureAssemblyDirectory() {
|
|
235
|
+
console.log("- Making sure that the 'assembly' directory exists...");
|
|
236
|
+
if (!fs.existsSync(assemblyDir)) {
|
|
237
|
+
fs.mkdirSync(assemblyDir);
|
|
238
|
+
console.log(stdoutColors.green(" Created: ") + assemblyDir);
|
|
239
|
+
} else {
|
|
240
|
+
console.log(stdoutColors.yellow(" Exists: ") + assemblyDir);
|
|
241
|
+
}
|
|
242
|
+
console.log();
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function ensureTsconfigJson() {
|
|
246
|
+
console.log("- Making sure that 'assembly/tsconfig.json' is set up...");
|
|
247
|
+
const base = tsconfigBase.replace(/\\/g, "/");
|
|
248
|
+
if (!fs.existsSync(tsconfigFile)) {
|
|
249
|
+
fs.writeFileSync(tsconfigFile, JSON.stringify({
|
|
250
|
+
"extends": base,
|
|
251
|
+
"include": [
|
|
252
|
+
"./**/*.ts"
|
|
253
|
+
]
|
|
254
|
+
}, null, 2));
|
|
255
|
+
console.log(stdoutColors.green(" Created: ") + tsconfigFile);
|
|
256
|
+
|
|
257
|
+
} else {
|
|
258
|
+
let tsconfig = JSON.parse(fs.readFileSync(tsconfigFile, "utf8"));
|
|
259
|
+
tsconfig["extends"] = base;
|
|
260
|
+
fs.writeFileSync(tsconfigFile, JSON.stringify(tsconfig, null, 2));
|
|
261
|
+
console.log(stdoutColors.green(" Updated: ") + tsconfigFile);
|
|
262
|
+
}
|
|
263
|
+
console.log();
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function ensureAsconfigJson() {
|
|
267
|
+
console.log("- Making sure that 'toilconfig.json' is set up...");
|
|
268
|
+
if (!fs.existsSync(toilconfigFile)) {
|
|
269
|
+
fs.writeFileSync(toilconfigFile, JSON.stringify({
|
|
270
|
+
targets: {
|
|
271
|
+
debug: {
|
|
272
|
+
// -o build/debug.wasm -t build/debug.wat --sourceMap --debug
|
|
273
|
+
outFile: "build/debug.wasm",
|
|
274
|
+
textFile: "build/debug.wat",
|
|
275
|
+
sourceMap: true,
|
|
276
|
+
debug: true
|
|
277
|
+
},
|
|
278
|
+
release: {
|
|
279
|
+
// -o build/release.wasm -t build/release.wat --sourceMap --optimize
|
|
280
|
+
outFile: "build/release.wasm",
|
|
281
|
+
textFile: "build/release.wat",
|
|
282
|
+
sourceMap: true,
|
|
283
|
+
optimizeLevel: 3,
|
|
284
|
+
shrinkLevel: 0,
|
|
285
|
+
converge: false,
|
|
286
|
+
noAssert: false
|
|
287
|
+
}
|
|
288
|
+
},
|
|
289
|
+
options: {
|
|
290
|
+
bindings: "esm"
|
|
291
|
+
}
|
|
292
|
+
}, null, 2));
|
|
293
|
+
console.log(stdoutColors.green(" Created: ") + toilconfigFile);
|
|
294
|
+
} else {
|
|
295
|
+
console.log(stdoutColors.yellow(" Exists: ") + toilconfigFile);
|
|
296
|
+
}
|
|
297
|
+
console.log();
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function ensureEntryFile() {
|
|
301
|
+
console.log("- Making sure that 'assembly/index.ts' exists...");
|
|
302
|
+
if (!fs.existsSync(entryFile)) {
|
|
303
|
+
fs.writeFileSync(entryFile, [
|
|
304
|
+
"// The entry file of your WebAssembly module.",
|
|
305
|
+
"",
|
|
306
|
+
"export function add(a: i32, b: i32): i32 {",
|
|
307
|
+
" return a + b;",
|
|
308
|
+
"}"
|
|
309
|
+
].join("\n") + "\n");
|
|
310
|
+
console.log(stdoutColors.green(" Created: ") + entryFile);
|
|
311
|
+
} else {
|
|
312
|
+
console.log(stdoutColors.yellow(" Exists: ") + entryFile);
|
|
313
|
+
}
|
|
314
|
+
console.log();
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function ensureBuildDirectory() {
|
|
318
|
+
console.log("- Making sure that the 'build' directory exists...");
|
|
319
|
+
if (!fs.existsSync(buildDir)) {
|
|
320
|
+
fs.mkdirSync(buildDir);
|
|
321
|
+
console.log(stdoutColors.green(" Created: ") + buildDir);
|
|
322
|
+
} else {
|
|
323
|
+
console.log(stdoutColors.yellow(" Exists: ") + buildDir);
|
|
324
|
+
}
|
|
325
|
+
console.log();
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function ensureGitignore() {
|
|
329
|
+
console.log("- Making sure that 'build/.gitignore' is set up...");
|
|
330
|
+
if (!fs.existsSync(gitignoreFile)) {
|
|
331
|
+
fs.writeFileSync(gitignoreFile, [
|
|
332
|
+
"*",
|
|
333
|
+
"!.gitignore"
|
|
334
|
+
].join("\n") + "\n");
|
|
335
|
+
console.log(stdoutColors.green(" Created: ") + gitignoreFile);
|
|
336
|
+
} else {
|
|
337
|
+
console.log(stdoutColors.yellow(" Exists: ") + gitignoreFile);
|
|
338
|
+
}
|
|
339
|
+
console.log();
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
function ensurePackageJson() {
|
|
343
|
+
console.log("- Making sure that 'package.json' contains the build commands...");
|
|
344
|
+
const entryPath = path.relative(projectDir, entryFile).replace(/\\/g, "/");
|
|
345
|
+
const buildDebug = "asc " + entryPath + " --target debug";
|
|
346
|
+
const buildRelease = "asc " + entryPath + " --target release";
|
|
347
|
+
const buildAll = commands[pm].run + " asbuild:debug && " + commands[pm].run + " asbuild:release";
|
|
348
|
+
if (!fs.existsSync(packageFile)) {
|
|
349
|
+
fs.writeFileSync(packageFile, JSON.stringify({
|
|
350
|
+
"type": "module",
|
|
351
|
+
"exports": {
|
|
352
|
+
".": {
|
|
353
|
+
"import": "./build/release.js",
|
|
354
|
+
"types": "./build/release.d.ts"
|
|
355
|
+
}
|
|
356
|
+
},
|
|
357
|
+
"scripts": {
|
|
358
|
+
"asbuild:debug": buildDebug,
|
|
359
|
+
"asbuild:release": buildRelease,
|
|
360
|
+
"asbuild": buildAll,
|
|
361
|
+
"test": "node --test",
|
|
362
|
+
"start": "npx serve ."
|
|
363
|
+
},
|
|
364
|
+
"devDependencies": {
|
|
365
|
+
"toilscript": "^" + version
|
|
366
|
+
}
|
|
367
|
+
}, null, 2));
|
|
368
|
+
console.log(stdoutColors.green(" Created: ") + packageFile);
|
|
369
|
+
} else {
|
|
370
|
+
let pkg = JSON.parse(fs.readFileSync(packageFile));
|
|
371
|
+
let scripts = pkg.scripts || {};
|
|
372
|
+
let updated = false;
|
|
373
|
+
if (!pkg["type"]) {
|
|
374
|
+
pkg["type"] = "module";
|
|
375
|
+
updated = true;
|
|
376
|
+
}
|
|
377
|
+
if (!pkg["exports"]) {
|
|
378
|
+
pkg["exports"] = {
|
|
379
|
+
".": {
|
|
380
|
+
"import": "./build/release.js",
|
|
381
|
+
"types": "./build/release.d.ts"
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
if (!scripts["asbuild"]) {
|
|
386
|
+
scripts["asbuild:debug"] = buildDebug;
|
|
387
|
+
scripts["asbuild:release"] = buildRelease;
|
|
388
|
+
scripts["asbuild"] = buildAll;
|
|
389
|
+
pkg["scripts"] = scripts;
|
|
390
|
+
updated = true;
|
|
391
|
+
}
|
|
392
|
+
if (!scripts["test"] || scripts["test"] == npmDefaultTest) {
|
|
393
|
+
scripts["test"] = "node --test";
|
|
394
|
+
pkg["scripts"] = scripts;
|
|
395
|
+
updated = true;
|
|
396
|
+
}
|
|
397
|
+
if (!scripts["start"]) {
|
|
398
|
+
scripts["start"] = "npx serve .";
|
|
399
|
+
pkg["scripts"] = scripts;
|
|
400
|
+
updated = true;
|
|
401
|
+
}
|
|
402
|
+
let devDependencies = pkg["devDependencies"] || {};
|
|
403
|
+
if (!devDependencies["toilscript"]) {
|
|
404
|
+
devDependencies["toilscript"] = "^" + version;
|
|
405
|
+
pkg["devDependencies"] = devDependencies;
|
|
406
|
+
updated = true;
|
|
407
|
+
}
|
|
408
|
+
if (updated) {
|
|
409
|
+
fs.writeFileSync(packageFile, JSON.stringify(pkg, null, 2));
|
|
410
|
+
console.log(stdoutColors.green(" Updated: ") + packageFile);
|
|
411
|
+
} else {
|
|
412
|
+
console.log(stdoutColors.yellow(" Exists: ") + packageFile);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
console.log();
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
function ensureTestsDirectory() {
|
|
419
|
+
console.log("- Making sure that the 'test' directory exists...");
|
|
420
|
+
if (!fs.existsSync(testsDir)) {
|
|
421
|
+
fs.mkdirSync(testsDir);
|
|
422
|
+
console.log(stdoutColors.green(" Created: ") + testsDir);
|
|
423
|
+
} else {
|
|
424
|
+
console.log(stdoutColors.yellow(" Exists: ") + testsDir);
|
|
425
|
+
}
|
|
426
|
+
console.log();
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
function ensureTestsIndexJs() {
|
|
430
|
+
console.log("- Making sure that 'test/index.js' exists...");
|
|
431
|
+
if (!fs.existsSync(testsIndexFile)) {
|
|
432
|
+
fs.writeFileSync(testsIndexFile, [
|
|
433
|
+
"import assert from \"node:assert/strict\";",
|
|
434
|
+
"import { it } from \"node:test\";",
|
|
435
|
+
"import { add } from \"../build/debug.js\";",
|
|
436
|
+
"",
|
|
437
|
+
"it(\"add\", () => {",
|
|
438
|
+
" assert.equal(add(1, 2), 3);",
|
|
439
|
+
"});"
|
|
440
|
+
].join("\n") + "\n");
|
|
441
|
+
console.log(stdoutColors.green(" Created: ") + testsIndexFile);
|
|
442
|
+
} else {
|
|
443
|
+
console.log(stdoutColors.yellow(" Exists: ") + testsIndexFile);
|
|
444
|
+
}
|
|
445
|
+
console.log();
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
function ensureIndexHtml() {
|
|
449
|
+
console.log("- Making sure that 'index.html' exists...");
|
|
450
|
+
if (!fs.existsSync(indexHtmlFile)) {
|
|
451
|
+
fs.writeFileSync(indexHtmlFile, [
|
|
452
|
+
"<!DOCTYPE html>",
|
|
453
|
+
"<html lang=\"en\">",
|
|
454
|
+
"<head>",
|
|
455
|
+
"<script type=\"module\">",
|
|
456
|
+
"import { add } from \"./build/release.js\";",
|
|
457
|
+
"document.body.innerText = add(1, 2);",
|
|
458
|
+
"</script>",
|
|
459
|
+
"</head>",
|
|
460
|
+
"<body></body>",
|
|
461
|
+
"</html>",
|
|
462
|
+
].join("\n") + "\n");
|
|
463
|
+
console.log(stdoutColors.green(" Created: ") + indexHtmlFile);
|
|
464
|
+
} else {
|
|
465
|
+
console.log(stdoutColors.yellow(" Exists: ") + indexHtmlFile);
|
|
466
|
+
}
|
|
467
|
+
console.log();
|
|
468
|
+
}
|
package/dist/asc.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = class Transform { /* stub */ };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Transform } from "./asc";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export class Transform { /* stub */ };
|
package/lib/binaryen.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "toilscript",
|
|
3
|
+
"description": "A TypeScript-like language for WebAssembly.",
|
|
4
|
+
"keywords": [
|
|
5
|
+
"typescript",
|
|
6
|
+
"webassembly",
|
|
7
|
+
"compiler",
|
|
8
|
+
"toilscript",
|
|
9
|
+
"wasm"
|
|
10
|
+
],
|
|
11
|
+
"version": "0.0.1",
|
|
12
|
+
"author": "Daniel Wirtz <dcode+assemblyscript@dcode.io>",
|
|
13
|
+
"license": "Apache-2.0",
|
|
14
|
+
"homepage": "https://github.com/dacely-cloud/toilscript",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/dacely-cloud/toilscript.git"
|
|
18
|
+
},
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/dacely-cloud/toilscript/issues"
|
|
21
|
+
},
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=20",
|
|
24
|
+
"npm": ">=10"
|
|
25
|
+
},
|
|
26
|
+
"engineStrict": true,
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"binaryen": "129.0.0-nightly.20260428",
|
|
29
|
+
"long": "^5.2.4"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@eslint/js": "^10.0.1",
|
|
33
|
+
"@types/node": "^25.6.0",
|
|
34
|
+
"as-float": "^1.0.1",
|
|
35
|
+
"diff": "^9.0.0",
|
|
36
|
+
"esbuild": "^0.28.0",
|
|
37
|
+
"eslint": "^10.2.1",
|
|
38
|
+
"glob": "^13.0.6",
|
|
39
|
+
"globals": "^17.5.0",
|
|
40
|
+
"typescript": "^6.0.3",
|
|
41
|
+
"typescript-eslint": "^8.59.0"
|
|
42
|
+
},
|
|
43
|
+
"type": "module",
|
|
44
|
+
"exports": {
|
|
45
|
+
".": {
|
|
46
|
+
"import": "./dist/toilscript.js",
|
|
47
|
+
"types": "./dist/toilscript.d.ts"
|
|
48
|
+
},
|
|
49
|
+
"./asc": {
|
|
50
|
+
"import": "./dist/asc.js",
|
|
51
|
+
"types": "./dist/asc.d.ts"
|
|
52
|
+
},
|
|
53
|
+
"./transform": {
|
|
54
|
+
"import": "./dist/transform.js",
|
|
55
|
+
"types": "./dist/transform.d.ts",
|
|
56
|
+
"require": "./dist/transform.cjs"
|
|
57
|
+
},
|
|
58
|
+
"./binaryen": {
|
|
59
|
+
"import": "./lib/binaryen.js",
|
|
60
|
+
"types": "./lib/binaryen.d.ts"
|
|
61
|
+
},
|
|
62
|
+
"./*": "./*"
|
|
63
|
+
},
|
|
64
|
+
"imports": {
|
|
65
|
+
"#rtrace": {
|
|
66
|
+
"import": "./lib/rtrace/index.js",
|
|
67
|
+
"types": "./lib/rtrace/index.d.ts"
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"bin": {
|
|
71
|
+
"asc": "./bin/asc.js",
|
|
72
|
+
"asinit": "./bin/asinit.js"
|
|
73
|
+
},
|
|
74
|
+
"scripts": {
|
|
75
|
+
"check": "npm run check:config && npm run check:import && npm run lint",
|
|
76
|
+
"check:config": "tsc --noEmit -p src --diagnostics --listFiles",
|
|
77
|
+
"check:import": "tsc --noEmit --skipLibCheck --target ESNEXT --module nodenext --moduleResolution nodenext --experimentalDecorators tests/import/index",
|
|
78
|
+
"lint": "eslint --max-warnings 0 --ext js . && eslint --max-warnings 0 --ext ts .",
|
|
79
|
+
"build": "node scripts/build",
|
|
80
|
+
"watch": "node scripts/build --watch",
|
|
81
|
+
"coverage": "npx c8 -- npm test",
|
|
82
|
+
"test": "npm run test:parser && npm run test:compiler -- --parallel && npm run test:browser && npm run test:asconfig && npm run test:transform && npm run test:cli",
|
|
83
|
+
"test:parser": "node --enable-source-maps tests/parser",
|
|
84
|
+
"test:compiler": "node --enable-source-maps --no-warnings tests/compiler",
|
|
85
|
+
"test:browser": "node --enable-source-maps tests/browser",
|
|
86
|
+
"test:asconfig": "cd tests/asconfig && npm run test",
|
|
87
|
+
"test:transform": "npm run test:transform:esm && npm run test:transform:cjs",
|
|
88
|
+
"test:transform:esm": "node bin/asc tests/compiler/empty --transform ./tests/transform/index.js --noEmit && node bin/asc tests/compiler/empty --transform ./tests/transform/simple.js --noEmit",
|
|
89
|
+
"test:transform:cjs": "node bin/asc tests/compiler/empty --transform ./tests/transform/cjs/index.js --noEmit && node bin/asc tests/compiler/empty --transform ./tests/transform/cjs/simple.js --noEmit",
|
|
90
|
+
"test:cli": "node tests/cli/options.js",
|
|
91
|
+
"asbuild": "npm run asbuild:debug && npm run asbuild:release",
|
|
92
|
+
"asbuild:debug": "node bin/asc --config src/toilconfig.json --target debug",
|
|
93
|
+
"asbuild:release": "node bin/asc --config src/toilconfig.json --target release",
|
|
94
|
+
"asbuild:rtraced": "node bin/asc --config src/toilconfig.json --target rtraced",
|
|
95
|
+
"bootstrap": "npm run bootstrap:debug && npm run bootstrap:release",
|
|
96
|
+
"bootstrap:debug": "node bin/asc --config src/toilconfig.json --target debug && node bin/asc --config src/toilconfig.json --target debug-bootstrap --wasm ./build/toilscript.debug.js && node bin/asc --config src/toilconfig.json --target debug-bootstrap --wasm ./build/toilscript.debug-bootstrap.js && git --no-pager diff --no-index build/toilscript.debug.wast build/toilscript.debug-bootstrap.wast",
|
|
97
|
+
"bootstrap:release": "node bin/asc --config src/toilconfig.json --target release && node bin/asc --config src/toilconfig.json --target release-bootstrap --wasm ./build/toilscript.release.js && node bin/asc --config src/toilconfig.json --target release-bootstrap --wasm ./build/toilscript.release-bootstrap.js && git --no-pager diff --no-index build/toilscript.release.wast build/toilscript.release-bootstrap.wast",
|
|
98
|
+
"bootstrap:rtraced": "node bin/asc --config src/toilconfig.json --target rtraced && node bin/asc --config src/toilconfig.json --target rtraced --wasm ./build/toilscript.rtraced.js"
|
|
99
|
+
},
|
|
100
|
+
"files": [
|
|
101
|
+
"bin/",
|
|
102
|
+
"dist/",
|
|
103
|
+
"std/",
|
|
104
|
+
"util/",
|
|
105
|
+
"lib/binaryen.js",
|
|
106
|
+
"lib/binaryen.d.ts",
|
|
107
|
+
"tsconfig-base.json",
|
|
108
|
+
"NOTICE"
|
|
109
|
+
],
|
|
110
|
+
"funding": {
|
|
111
|
+
"type": "opencollective",
|
|
112
|
+
"url": "https://opencollective.com/assemblyscript"
|
|
113
|
+
}
|
|
114
|
+
}
|