bimba-cli 0.2.0 → 0.2.2
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/package.json +2 -2
- package/plugin.js +14 -19
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bimba-cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
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,17 +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
|
-
console.log('from cache')
|
|
81
78
|
stats.bundled++;
|
|
82
79
|
stats.cached++;
|
|
80
|
+
//console.log(theme.action("cached: ") + theme.folder(f.dir + '/') + theme.filename(f.base) + " - " + theme.success("ok"));
|
|
83
81
|
return {
|
|
84
82
|
contents: await Bun.file(cached).text(),
|
|
85
83
|
loader: "js",
|
|
@@ -87,11 +85,8 @@ export const imbaPlugin = {
|
|
|
87
85
|
}
|
|
88
86
|
|
|
89
87
|
// clear previous cached version
|
|
90
|
-
const glob = new Glob(
|
|
91
|
-
for await (const file of glob.scan(cache))
|
|
92
|
-
const prev_cached = join(cache, file);
|
|
93
|
-
if (fs.existsSync(prev_cached)) unlink(prev_cached);
|
|
94
|
-
}
|
|
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);
|
|
95
90
|
|
|
96
91
|
// if no cached version read and compile it with the imba compiler
|
|
97
92
|
const file = await Bun.file(path).text();
|
|
@@ -101,19 +96,19 @@ export const imbaPlugin = {
|
|
|
101
96
|
})
|
|
102
97
|
|
|
103
98
|
// print about file complitaion
|
|
104
|
-
|
|
99
|
+
|
|
105
100
|
|
|
106
101
|
// the file has been successfully compiled
|
|
107
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"));
|
|
108
104
|
stats.bundled++;
|
|
109
105
|
stats.compiled++;
|
|
110
106
|
contents = out.js;
|
|
111
107
|
await Bun.write(cached, contents);
|
|
112
|
-
console.write(theme.success("cached" + "\n"));
|
|
113
108
|
}
|
|
114
109
|
// there were errors during compilation
|
|
115
110
|
else {
|
|
116
|
-
console.
|
|
111
|
+
console.log(theme.action("compiling: ") + theme.folder(dir.join(f.dir,'/')) + theme.filename(f.base) + " - " + theme.failure(" fail "));
|
|
117
112
|
stats.failed++;
|
|
118
113
|
for (let i = 0; i < out.errors.length; i++) {
|
|
119
114
|
if(out.errors[i]) printerr(out.errors[i]);
|