@gjsify/esbuild-plugin-gjsify 0.1.1 → 0.1.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/dist/shims/console-gjs.js +198 -25
- package/esbuild.mjs +7 -2
- package/package.json +5 -5
- package/src/shims/console-gjs.ts +4 -6
|
@@ -1,28 +1,201 @@
|
|
|
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
|
-
|
|
1
|
+
// ../../node/console/src/index.ts
|
|
2
|
+
var _isGJS = typeof print === "function" && typeof printerr === "function";
|
|
3
|
+
function _formatArgs(...args) {
|
|
4
|
+
const fmt = args[0];
|
|
5
|
+
const rest = args.slice(1);
|
|
6
|
+
if (typeof fmt !== "string" || !/%(s|d|i|f|o|O|c)/.test(fmt)) {
|
|
7
|
+
return args.map((a) => typeof a === "string" ? a : JSON.stringify(a)).join(" ");
|
|
8
|
+
}
|
|
9
|
+
let i = 0;
|
|
10
|
+
const result = fmt.replace(/%([sdifOoc])/g, (_match, spec) => {
|
|
11
|
+
if (i >= rest.length) return _match;
|
|
12
|
+
const val = rest[i++];
|
|
13
|
+
switch (spec) {
|
|
14
|
+
case "s":
|
|
15
|
+
return String(val);
|
|
16
|
+
case "d":
|
|
17
|
+
case "i":
|
|
18
|
+
return String(parseInt(String(val), 10));
|
|
19
|
+
case "f":
|
|
20
|
+
return String(parseFloat(String(val)));
|
|
21
|
+
case "o":
|
|
22
|
+
case "O":
|
|
23
|
+
return JSON.stringify(val);
|
|
24
|
+
case "c":
|
|
25
|
+
return "";
|
|
26
|
+
// CSS styles — ignore
|
|
27
|
+
default:
|
|
28
|
+
return _match;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
const remaining = rest.slice(i);
|
|
32
|
+
if (remaining.length === 0) return result;
|
|
33
|
+
return result + " " + remaining.map((a) => typeof a === "string" ? a : JSON.stringify(a)).join(" ");
|
|
34
|
+
}
|
|
35
|
+
var Console = class {
|
|
36
|
+
_stdout;
|
|
37
|
+
_stderr;
|
|
38
|
+
_groupDepth = 0;
|
|
39
|
+
_groupIndentation;
|
|
40
|
+
_timers = /* @__PURE__ */ new Map();
|
|
41
|
+
_counters = /* @__PURE__ */ new Map();
|
|
42
|
+
constructor(stdoutOrOptions, stderr) {
|
|
43
|
+
if (stdoutOrOptions && typeof stdoutOrOptions.write === "function") {
|
|
44
|
+
this._stdout = stdoutOrOptions;
|
|
45
|
+
this._stderr = stderr || this._stdout;
|
|
46
|
+
} else if (stdoutOrOptions && typeof stdoutOrOptions === "object") {
|
|
47
|
+
const opts = stdoutOrOptions;
|
|
48
|
+
this._stdout = opts.stdout;
|
|
49
|
+
this._stderr = opts.stderr || opts.stdout;
|
|
50
|
+
}
|
|
51
|
+
this._groupIndentation = 2;
|
|
52
|
+
}
|
|
53
|
+
_write(stream, ...args) {
|
|
54
|
+
const target = stream === "stderr" ? this._stderr || this._stdout : this._stdout;
|
|
55
|
+
if (target) {
|
|
56
|
+
const indent = " ".repeat(this._groupDepth * this._groupIndentation);
|
|
57
|
+
const message = _formatArgs(...args);
|
|
58
|
+
target.write(indent + message + "\n");
|
|
59
|
+
} else if (_isGJS) {
|
|
60
|
+
const indent = " ".repeat(this._groupDepth * this._groupIndentation);
|
|
61
|
+
const message = indent + _formatArgs(...args);
|
|
62
|
+
if (stream === "stderr") {
|
|
63
|
+
printerr(message);
|
|
64
|
+
} else {
|
|
65
|
+
print(message);
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
const gc = globalThis.console;
|
|
69
|
+
if (stream === "stderr") {
|
|
70
|
+
gc.error(...args);
|
|
71
|
+
} else {
|
|
72
|
+
gc.log(...args);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
log(...args) {
|
|
77
|
+
this._write("stdout", ...args);
|
|
78
|
+
}
|
|
79
|
+
info(...args) {
|
|
80
|
+
this._write("stdout", ...args);
|
|
81
|
+
}
|
|
82
|
+
debug(...args) {
|
|
83
|
+
this._write("stdout", ...args);
|
|
84
|
+
}
|
|
85
|
+
warn(...args) {
|
|
86
|
+
this._write("stderr", ...args);
|
|
87
|
+
}
|
|
88
|
+
error(...args) {
|
|
89
|
+
this._write("stderr", ...args);
|
|
90
|
+
}
|
|
91
|
+
dir(obj, _options) {
|
|
92
|
+
this._write("stdout", obj);
|
|
93
|
+
}
|
|
94
|
+
dirxml(...args) {
|
|
95
|
+
this.log(...args);
|
|
96
|
+
}
|
|
97
|
+
assert(value, ...args) {
|
|
98
|
+
if (!value) {
|
|
99
|
+
this.error("Assertion failed:", ...args);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
clear() {
|
|
103
|
+
if (this._stdout) {
|
|
104
|
+
this._stdout.write("\x1Bc");
|
|
105
|
+
} else if (_isGJS) {
|
|
106
|
+
print("\x1Bc");
|
|
107
|
+
} else {
|
|
108
|
+
globalThis.console.clear();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
count(label = "default") {
|
|
112
|
+
const count2 = (this._counters.get(label) || 0) + 1;
|
|
113
|
+
this._counters.set(label, count2);
|
|
114
|
+
this.log(`${label}: ${count2}`);
|
|
115
|
+
}
|
|
116
|
+
countReset(label = "default") {
|
|
117
|
+
this._counters.delete(label);
|
|
118
|
+
}
|
|
119
|
+
group(...args) {
|
|
120
|
+
if (args.length > 0) this.log(...args);
|
|
121
|
+
this._groupDepth++;
|
|
122
|
+
}
|
|
123
|
+
groupCollapsed(...args) {
|
|
124
|
+
this.group(...args);
|
|
125
|
+
}
|
|
126
|
+
groupEnd() {
|
|
127
|
+
if (this._groupDepth > 0) this._groupDepth--;
|
|
128
|
+
}
|
|
129
|
+
table(tabularData, _properties) {
|
|
130
|
+
if (this._stdout) {
|
|
131
|
+
this._write("stdout", tabularData);
|
|
132
|
+
} else if (_isGJS) {
|
|
133
|
+
print(JSON.stringify(tabularData, null, 2));
|
|
134
|
+
} else {
|
|
135
|
+
globalThis.console.table(tabularData, _properties);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
time(label = "default") {
|
|
139
|
+
this._timers.set(label, Date.now());
|
|
140
|
+
}
|
|
141
|
+
timeEnd(label = "default") {
|
|
142
|
+
const start = this._timers.get(label);
|
|
143
|
+
if (start !== void 0) {
|
|
144
|
+
this.log(`${label}: ${Date.now() - start}ms`);
|
|
145
|
+
this._timers.delete(label);
|
|
146
|
+
} else {
|
|
147
|
+
this.warn(`Warning: No such label '${label}' for console.timeEnd()`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
timeLog(label = "default", ...args) {
|
|
151
|
+
const start = this._timers.get(label);
|
|
152
|
+
if (start !== void 0) {
|
|
153
|
+
this.log(`${label}: ${Date.now() - start}ms`, ...args);
|
|
154
|
+
} else {
|
|
155
|
+
this.warn(`Warning: No such label '${label}' for console.timeLog()`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
trace(...args) {
|
|
159
|
+
const err = new Error();
|
|
160
|
+
const stack = err.stack?.split("\n").slice(1).join("\n") || "";
|
|
161
|
+
this._write("stderr", "Trace:", ...args, "\n" + stack);
|
|
162
|
+
}
|
|
163
|
+
profile(_label) {
|
|
164
|
+
}
|
|
165
|
+
profileEnd(_label) {
|
|
166
|
+
}
|
|
167
|
+
timeStamp(_label) {
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
var _default = new Console();
|
|
171
|
+
var log = (...args) => _default.log(...args);
|
|
172
|
+
var info = (...args) => _default.info(...args);
|
|
173
|
+
var debug = (...args) => _default.debug(...args);
|
|
174
|
+
var warn = (...args) => _default.warn(...args);
|
|
175
|
+
var error = (...args) => _default.error(...args);
|
|
176
|
+
var dir = (obj, options) => _default.dir(obj, options);
|
|
177
|
+
var dirxml = (...args) => _default.dirxml(...args);
|
|
178
|
+
var table = (data, properties) => _default.table(data, properties);
|
|
179
|
+
var clear = () => _default.clear();
|
|
180
|
+
var assert = (value, ...args) => _default.assert(value, ...args);
|
|
181
|
+
var trace = (...args) => _default.trace(...args);
|
|
182
|
+
var time = (label) => _default.time(label);
|
|
183
|
+
var timeEnd = (label) => _default.timeEnd(label);
|
|
184
|
+
var timeLog = (label, ...args) => _default.timeLog(label, ...args);
|
|
185
|
+
var count = (label) => _default.count(label);
|
|
186
|
+
var countReset = (label) => _default.countReset(label);
|
|
187
|
+
var group = (...args) => _default.group(...args);
|
|
188
|
+
var groupCollapsed = (...args) => _default.groupCollapsed(...args);
|
|
189
|
+
var groupEnd = () => _default.groupEnd();
|
|
190
|
+
var profile = (_label) => {
|
|
191
|
+
};
|
|
192
|
+
var profileEnd = (_label) => {
|
|
193
|
+
};
|
|
194
|
+
var timeStamp = (_label) => {
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
// src/shims/console-gjs.ts
|
|
198
|
+
var console = {
|
|
26
199
|
log,
|
|
27
200
|
info,
|
|
28
201
|
debug,
|
package/esbuild.mjs
CHANGED
|
@@ -22,13 +22,18 @@ await build({
|
|
|
22
22
|
},
|
|
23
23
|
});
|
|
24
24
|
|
|
25
|
-
// Build GJS console shim —
|
|
25
|
+
// Build GJS console shim — self-contained file injected into GJS bundles at build time.
|
|
26
|
+
// Bundled with @gjsify/console inlined so the plugin has zero @gjsify/* polyfill deps.
|
|
26
27
|
// Must be ESM with a named export `console` for esbuild's inject feature.
|
|
28
|
+
// Uses alias to resolve from source (console may not be built yet during build:infra).
|
|
27
29
|
await build({
|
|
28
30
|
entryPoints: ['src/shims/console-gjs.ts'],
|
|
29
|
-
bundle:
|
|
31
|
+
bundle: true,
|
|
30
32
|
minify: false,
|
|
31
33
|
platform: 'neutral',
|
|
32
34
|
format: 'esm',
|
|
33
35
|
outfile: 'dist/shims/console-gjs.js',
|
|
36
|
+
alias: {
|
|
37
|
+
'@gjsify/console': '../../node/console/src/index.ts',
|
|
38
|
+
},
|
|
34
39
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/esbuild-plugin-gjsify",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Deepkit type compiler plugin for esbuild",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/esm/index.mjs",
|
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
"esbuild"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@gjsify/esbuild-plugin-alias": "^0.1.
|
|
29
|
-
"@gjsify/esbuild-plugin-deepkit": "^0.1.
|
|
30
|
-
"@gjsify/esbuild-plugin-transform-ext": "^0.1.
|
|
31
|
-
"@gjsify/resolve-npm": "^0.1.
|
|
28
|
+
"@gjsify/esbuild-plugin-alias": "^0.1.2",
|
|
29
|
+
"@gjsify/esbuild-plugin-deepkit": "^0.1.2",
|
|
30
|
+
"@gjsify/esbuild-plugin-transform-ext": "^0.1.2",
|
|
31
|
+
"@gjsify/resolve-npm": "^0.1.2",
|
|
32
32
|
"fast-glob": "^3.3.3"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
package/src/shims/console-gjs.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
// GJS console shim —
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
// esbuild resolves the @gjsify/console import at user-build time and deduplicates
|
|
6
|
-
// it with any explicit `import from 'node:console'` in the same bundle.
|
|
1
|
+
// GJS console shim — bundled and injected into GJS builds via esbuild's `inject` option.
|
|
2
|
+
// Contains the full @gjsify/console implementation inlined (~4KB) so no external
|
|
3
|
+
// @gjsify/* package resolution is needed at user-build time. Uses print()/printerr()
|
|
4
|
+
// on GJS, bypassing GLib.log_structured() — no prefix, ANSI codes work.
|
|
7
5
|
import {
|
|
8
6
|
log, info, debug, warn, error, dir, dirxml, table,
|
|
9
7
|
time, timeEnd, timeLog, trace, assert, clear,
|