bimba-cli 0.2.1 → 0.2.3
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 +7 -1
- package/package.json +2 -2
- package/plugin.js +14 -18
package/index.js
CHANGED
|
@@ -64,6 +64,7 @@ if(!entrypoint || !flags.outdir) {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
// build
|
|
67
|
+
let bundling = false;
|
|
67
68
|
bundle();
|
|
68
69
|
watch(bundle);
|
|
69
70
|
|
|
@@ -83,6 +84,9 @@ function watch(callback) {
|
|
|
83
84
|
}
|
|
84
85
|
|
|
85
86
|
async function bundle() {
|
|
87
|
+
if (bundling) return;
|
|
88
|
+
bundling = true;
|
|
89
|
+
|
|
86
90
|
if (!fs.existsSync(entrypoint)) {
|
|
87
91
|
console.log(theme.failure('Error.') + ` The specified entrypoint does not exist: ${theme.filedir(entrypoint)}`);
|
|
88
92
|
process.exit(0);
|
|
@@ -106,7 +110,7 @@ async function bundle() {
|
|
|
106
110
|
minify: flags.minify || true,
|
|
107
111
|
plugins: [imbaPlugin]
|
|
108
112
|
});
|
|
109
|
-
|
|
113
|
+
|
|
110
114
|
if(stats.failed)
|
|
111
115
|
console.log(theme.start(theme.failure("Failure.") +` Imba compiler failed to proceed ${theme.count(stats.failed)} file${stats.failed > 1 ? 's' : ''}`));
|
|
112
116
|
else
|
|
@@ -117,4 +121,6 @@ async function bundle() {
|
|
|
117
121
|
console.log(log);
|
|
118
122
|
}
|
|
119
123
|
}
|
|
124
|
+
|
|
125
|
+
bundling = false;
|
|
120
126
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bimba-cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"repository": "github:HeapVoid/bimba",
|
|
5
5
|
"module": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -11,6 +11,6 @@
|
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"type": "module",
|
|
13
13
|
"devDependencies": {
|
|
14
|
-
"imba": "
|
|
14
|
+
"imba": "latest"
|
|
15
15
|
}
|
|
16
16
|
}
|
package/plugin.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { plugin } from "bun";
|
|
2
2
|
import {theme} from './utils.js';
|
|
3
3
|
import * as compiler from 'imba/compiler'
|
|
4
|
-
import
|
|
4
|
+
import dir from 'path'
|
|
5
5
|
import fs from 'fs'
|
|
6
6
|
import { Glob } from "bun";
|
|
7
7
|
import { unlink } from "node:fs/promises";
|
|
8
8
|
|
|
9
|
-
export const cache =
|
|
9
|
+
export const cache = process.cwd() + '/.cache/';
|
|
10
10
|
if (!fs.existsSync(cache)){ fs.mkdirSync(cache);}
|
|
11
11
|
|
|
12
12
|
// this should be reset from outside to get results of entrypoint building
|
|
@@ -27,7 +27,7 @@ export const imbaPlugin = {
|
|
|
27
27
|
|
|
28
28
|
let filename = path;
|
|
29
29
|
// resolve relative path
|
|
30
|
-
if (path.startsWith('.')) { filename = resolve(dirname(importer), filename) };
|
|
30
|
+
if (path.startsWith('.')) { filename = dir.resolve(dir.dirname(importer), filename) };
|
|
31
31
|
|
|
32
32
|
// assume that the file is .js
|
|
33
33
|
try { return {path: Bun.resolveSync(filename + '.js', '.')}}
|
|
@@ -45,13 +45,13 @@ export const imbaPlugin = {
|
|
|
45
45
|
filename += '.imba';
|
|
46
46
|
|
|
47
47
|
// assume that the relative path should be resolved relative to importer
|
|
48
|
-
let fn = resolve(dirname(importer), filename);
|
|
48
|
+
let fn = dir.resolve(dir.dirname(importer), filename);
|
|
49
49
|
if (fs.existsSync(fn)) return {path: fn};
|
|
50
50
|
// assume that the relative path should be resolved relative to node_modules
|
|
51
|
-
fn = resolve('./node_modules', filename);
|
|
51
|
+
fn = dir.resolve('./node_modules', filename);
|
|
52
52
|
if (fs.existsSync(fn)) return {path: fn};
|
|
53
53
|
// assume that the relative path should be resolved relative to project root
|
|
54
|
-
fn = resolve(process.cwd(), filename);
|
|
54
|
+
fn = dir.resolve(process.cwd(), filename);
|
|
55
55
|
if (fs.existsSync(fn)) return {path: fn};
|
|
56
56
|
|
|
57
57
|
// if the path still is unresolved throw error and leave the further resolution on Bun's resolver
|
|
@@ -69,16 +69,15 @@ export const imbaPlugin = {
|
|
|
69
69
|
// when an .imba file is imported...
|
|
70
70
|
build.onLoad({ filter: /\.imba$/ }, async ({ path }) => {
|
|
71
71
|
|
|
72
|
-
const f = parse(path)
|
|
72
|
+
const f = dir.parse(path)
|
|
73
73
|
let contents = '';
|
|
74
74
|
|
|
75
75
|
// return the cached version if it exists
|
|
76
|
-
const
|
|
77
|
-
const time_hash = Bun.hash(fs.statSync(path).mtimeMs)
|
|
78
|
-
const cached = join(cache, path_hash + '_' + time_hash + '.js');
|
|
76
|
+
const cached = cache + Bun.hash(path) + '_' + fs.statSync(path).mtimeMs + '.js';
|
|
79
77
|
if (fs.existsSync(cached)) {
|
|
80
78
|
stats.bundled++;
|
|
81
79
|
stats.cached++;
|
|
80
|
+
//console.log(theme.action("cached: ") + theme.folder(f.dir + '/') + theme.filename(f.base) + " - " + theme.success("ok"));
|
|
82
81
|
return {
|
|
83
82
|
contents: await Bun.file(cached).text(),
|
|
84
83
|
loader: "js",
|
|
@@ -86,11 +85,8 @@ export const imbaPlugin = {
|
|
|
86
85
|
}
|
|
87
86
|
|
|
88
87
|
// clear previous cached version
|
|
89
|
-
const glob = new Glob(
|
|
90
|
-
for await (const file of glob.scan(cache))
|
|
91
|
-
const prev_cached = join(cache, file);
|
|
92
|
-
if (fs.existsSync(prev_cached)) unlink(prev_cached);
|
|
93
|
-
}
|
|
88
|
+
const glob = new Glob(Bun.hash(path) + '_' + "*.js");
|
|
89
|
+
for await (const file of glob.scan(cache)) if (fs.existsSync(cache + file)) unlink(cache + file);
|
|
94
90
|
|
|
95
91
|
// if no cached version read and compile it with the imba compiler
|
|
96
92
|
const file = await Bun.file(path).text();
|
|
@@ -100,19 +96,19 @@ export const imbaPlugin = {
|
|
|
100
96
|
})
|
|
101
97
|
|
|
102
98
|
// print about file complitaion
|
|
103
|
-
|
|
99
|
+
|
|
104
100
|
|
|
105
101
|
// the file has been successfully compiled
|
|
106
102
|
if (!out.errors || !out.errors.length) {
|
|
103
|
+
console.log(theme.action("compiling: ") + theme.folder(dir.join(f.dir,'/')) + theme.filename(f.base) + " - " + theme.success("cached"));
|
|
107
104
|
stats.bundled++;
|
|
108
105
|
stats.compiled++;
|
|
109
106
|
contents = out.js;
|
|
110
107
|
await Bun.write(cached, contents);
|
|
111
|
-
console.write(theme.success("cached" + "\n"));
|
|
112
108
|
}
|
|
113
109
|
// there were errors during compilation
|
|
114
110
|
else {
|
|
115
|
-
console.
|
|
111
|
+
console.log(theme.action("compiling: ") + theme.folder(dir.join(f.dir,'/')) + theme.filename(f.base) + " - " + theme.failure(" fail "));
|
|
116
112
|
stats.failed++;
|
|
117
113
|
for (let i = 0; i < out.errors.length; i++) {
|
|
118
114
|
if(out.errors[i]) printerr(out.errors[i]);
|