-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.ts
78 lines (76 loc) · 2.13 KB
/
test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// import { build } from "arenaless-bundler";
import { build } from "./index";
import * as fs from "fs";
async function test() {
let files_text: Record<string, string> = {
"hello/index.ts": `import {hello} from "./hi";
import hellots from "@/hello/hi.ts?text";
import hellob64 from "./hi.ts?base64";
import {Text} from "dao3-areact/component";
hello();
console.log(hellots);
console.log(hellob64);
import JSON5 from "json5";
console.log(JSON5.parse("{a:1}"))
import foo from "foo";
console.log(foo)`,
"hello/hi.ts": `export function hello():void{
console.log("hello");
}`,
"foo.json": `{"bar":12345}`,
"importMap.arenaless.jsonc":`{"imports":{"dao3-areact":"npm:dao3-areact"}}`
}
// let imagebuf=fs.readFileSync("./image.png");
// to uint array
// let image=new Uint8Array(imagebuf);
let files: Record<string, Uint8Array> = {
//"image.png": image,
};
for (let key in files_text) {
files[key] = new TextEncoder().encode(files_text[key]);
}
let res = await build(files, "hello/index.ts", `{
"compilerOptions": {
"target": "ESNext",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"baseUrl": "./",
"rootDir": "./",
"outDir": "dist", // do not change this
"lib": [],
"paths": {
"foo": [
"./foo.json"
],"@/*":[
"./*"
]
},
},
"include": [
"./**/*.ts",
"./**/*.d.ts",
"./types"
],
"exclude": [
"node_modules",
"dist"
]
}`, console, "cjs", `{
"imports":{"json5":"npm:json5"}
}`, false);
// console.log(res)
return res;
};
(async () => {
for (let i = 1; i < 10 + 1; i++) {
let start = Date.now();
let res = await test();
fs.writeFileSync("./test_output.js", res, { encoding: "utf-8" });
console.log(`${i}. ${Date.now() - start}ms`);
}
})();