bimba-cli 0.2.1 → 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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/plugin.js +14 -18
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bimba-cli",
3
- "version": "0.2.1",
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": "^2.0.0-alpha.234"
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 {resolve, join, dirname, parse} from 'path'
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 = join(process.cwd(),'.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 path_hash = Bun.hash(path)
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(path_hash + '_' + "*.js");
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
- console.write(theme.action("compiling: ") + theme.folder(f.dir + '/') + theme.filename(f.base) + " - ");
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.write(theme.failure(" fail ") + "\n");
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]);