bimba-cli 0.2.4 → 0.2.6
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/index.js +26 -18
- package/package.json +6 -3
- package/plugin.js +8 -54
package/index.js
CHANGED
|
@@ -101,26 +101,34 @@ async function bundle() {
|
|
|
101
101
|
|
|
102
102
|
console.log("──────────────────────────────────────────────────────────────────────");
|
|
103
103
|
console.log(theme.start(`Start building the Imba entrypoint: ${theme.filedir(entrypoint)}`));
|
|
104
|
-
|
|
105
|
-
const result = await Bun.build({
|
|
106
|
-
entrypoints: [entrypoint],
|
|
107
|
-
outdir: flags.outdir,
|
|
108
|
-
target: flags.target || 'browser',
|
|
109
|
-
sourcemap: flags.sourcemap || 'none',
|
|
110
|
-
minify: flags.minify || true,
|
|
111
|
-
plugins: [imbaPlugin]
|
|
112
|
-
});
|
|
113
104
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
105
|
+
let result = undefined
|
|
106
|
+
try {
|
|
107
|
+
result = await Bun.build({
|
|
108
|
+
entrypoints: [entrypoint],
|
|
109
|
+
outdir: flags.outdir,
|
|
110
|
+
target: flags.target || 'browser',
|
|
111
|
+
sourcemap: flags.sourcemap || 'none',
|
|
112
|
+
minify: flags.minify || true,
|
|
113
|
+
plugins: [imbaPlugin]
|
|
114
|
+
});
|
|
118
115
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
116
|
+
if(stats.failed)
|
|
117
|
+
console.log(theme.start(theme.failure("Failure.") +` Imba compiler failed to proceed ${theme.count(stats.failed)} file${stats.failed > 1 ? 's' : ''}`));
|
|
118
|
+
else
|
|
119
|
+
console.log(theme.start(theme.success("Success.") +` It took ${theme.time(Date.now() - start)} ms to bundle ${theme.count(stats.bundled)} file${stats.bundled > 1 ? 's' : ''} to the folder: ${theme.filedir(flags.outdir)}`));
|
|
120
|
+
|
|
121
|
+
if(!result.success && !stats.errors){
|
|
122
|
+
for (const log of result.logs) {
|
|
123
|
+
console.log(log);
|
|
124
|
+
}
|
|
122
125
|
}
|
|
123
126
|
}
|
|
124
|
-
|
|
125
|
-
|
|
127
|
+
catch(error) {
|
|
128
|
+
console.log('')
|
|
129
|
+
console.log(error)
|
|
130
|
+
}
|
|
131
|
+
finally {
|
|
132
|
+
bundling = false;
|
|
133
|
+
};
|
|
126
134
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bimba-cli",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"repository":
|
|
3
|
+
"version": "0.2.6",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/HeapVoid/bimba.git"
|
|
7
|
+
},
|
|
5
8
|
"module": "index.js",
|
|
6
9
|
"bin": {
|
|
7
|
-
"bimba": "
|
|
10
|
+
"bimba": "index.js"
|
|
8
11
|
},
|
|
9
12
|
"scripts": {
|
|
10
13
|
"upload": "npm publish"
|
package/plugin.js
CHANGED
|
@@ -15,69 +15,26 @@ export let stats = {
|
|
|
15
15
|
compiled: 0,
|
|
16
16
|
cached: 0,
|
|
17
17
|
bundled: 0,
|
|
18
|
-
errors: 0
|
|
18
|
+
errors: 0,
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
export const imbaPlugin = {
|
|
22
22
|
name: "imba",
|
|
23
23
|
async setup(build) {
|
|
24
24
|
|
|
25
|
-
// // when there is import without file extension
|
|
26
|
-
// build.onResolve({filter: /^.*[^.]{5}$/ }, ({ path, importer }) => {
|
|
27
|
-
|
|
28
|
-
// let filename = path;
|
|
29
|
-
// // resolve relative path
|
|
30
|
-
// if (path.startsWith('.')) { filename = dir.resolve(dir.dirname(importer), filename) };
|
|
31
|
-
|
|
32
|
-
// // assume that the file is .js
|
|
33
|
-
// try { return {path: Bun.resolveSync(filename + '.js', '.')}}
|
|
34
|
-
// catch (error) {
|
|
35
|
-
// // assume that the file is .mjs
|
|
36
|
-
// try { return {path: Bun.resolveSync(filename + '.mjs', '.')}}
|
|
37
|
-
// catch (error) {
|
|
38
|
-
// // assume that the file is .cs
|
|
39
|
-
// try { return {path: Bun.resolveSync(filename + '.cjs', '.')}}
|
|
40
|
-
// catch (error) {
|
|
41
|
-
// // assume that the file is .imba
|
|
42
|
-
// try { return {path: Bun.resolveSync(filename + '.imba', '.')}}
|
|
43
|
-
// catch (error) {
|
|
44
|
-
// // if direct resolution failed
|
|
45
|
-
// filename += '.imba';
|
|
46
|
-
|
|
47
|
-
// // assume that the relative path should be resolved relative to importer
|
|
48
|
-
// let fn = dir.resolve(dir.dirname(importer), filename);
|
|
49
|
-
// if (fs.existsSync(fn)) return {path: fn};
|
|
50
|
-
// // assume that the relative path should be resolved relative to node_modules
|
|
51
|
-
// fn = dir.resolve('./node_modules', filename);
|
|
52
|
-
// if (fs.existsSync(fn)) return {path: fn};
|
|
53
|
-
// // assume that the relative path should be resolved relative to project root
|
|
54
|
-
// fn = dir.resolve(process.cwd(), filename);
|
|
55
|
-
// if (fs.existsSync(fn)) return {path: fn};
|
|
56
|
-
|
|
57
|
-
// // if the path still is unresolved throw error and leave the further resolution on Bun's resolver
|
|
58
|
-
// if (error instanceof Error) {
|
|
59
|
-
// throw new Error(error.message);
|
|
60
|
-
// }
|
|
61
|
-
// else
|
|
62
|
-
// throw new Error('Could not resolve file: ' + path);
|
|
63
|
-
// }
|
|
64
|
-
// }
|
|
65
|
-
// }
|
|
66
|
-
// }
|
|
67
|
-
// })
|
|
68
|
-
|
|
69
25
|
// when an .imba file is imported...
|
|
70
26
|
build.onLoad({ filter: /\.imba$/ }, async ({ path }) => {
|
|
71
|
-
|
|
27
|
+
|
|
72
28
|
const f = dir.parse(path)
|
|
73
29
|
let contents = '';
|
|
74
|
-
|
|
75
|
-
// return the cached version if
|
|
30
|
+
|
|
31
|
+
// return the cached version if exists
|
|
76
32
|
const cached = cache + Bun.hash(path) + '_' + fs.statSync(path).mtimeMs + '.js';
|
|
77
33
|
if (fs.existsSync(cached)) {
|
|
78
34
|
stats.bundled++;
|
|
79
35
|
stats.cached++;
|
|
80
36
|
//console.log(theme.action("cached: ") + theme.folder(f.dir + '/') + theme.filename(f.base) + " - " + theme.success("ok"));
|
|
37
|
+
//console.log(theme.action("compiling: ") + theme.folder(dir.join(f.dir,'/')) + theme.filename(f.base) + " - " + theme.success("from cache"));
|
|
81
38
|
return {
|
|
82
39
|
contents: await Bun.file(cached).text(),
|
|
83
40
|
loader: "js",
|
|
@@ -91,15 +48,12 @@ export const imbaPlugin = {
|
|
|
91
48
|
// if no cached version read and compile it with the imba compiler
|
|
92
49
|
const file = await Bun.file(path).text();
|
|
93
50
|
const out = compiler.compile(file, {
|
|
94
|
-
|
|
95
|
-
|
|
51
|
+
sourcePath: path,
|
|
52
|
+
platform: 'browser'
|
|
96
53
|
})
|
|
97
54
|
|
|
98
|
-
// print about file complitaion
|
|
99
|
-
|
|
100
|
-
|
|
101
55
|
// the file has been successfully compiled
|
|
102
|
-
if (!out.errors
|
|
56
|
+
if (!out.errors?.length) {
|
|
103
57
|
console.log(theme.action("compiling: ") + theme.folder(dir.join(f.dir,'/')) + theme.filename(f.base) + " - " + theme.success("cached"));
|
|
104
58
|
stats.bundled++;
|
|
105
59
|
stats.compiled++;
|