@leftium/gg 0.0.14 → 0.0.16

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/README.md CHANGED
@@ -22,6 +22,36 @@ npm add @leftium/gg
22
22
 
23
23
  _Coming soon..._
24
24
 
25
+ ## Technical Details
26
+
27
+ ### Bundled Dependencies
28
+
29
+ This library includes a **patched version** of the [`debug`](https://www.npmjs.com/package/debug) package. The patch reformats the output to display time diffs **before** the namespace for better readability:
30
+
31
+ **Standard debug output:**
32
+ ```
33
+ gg:routes/+page.svelte +123ms
34
+ ```
35
+
36
+ **Patched output (this library):**
37
+ ```
38
+ +123ms gg:routes/+page.svelte
39
+ ```
40
+
41
+ The patched `debug` library is bundled directly into the distribution, so consumers automatically get the correct behavior without needing to install or patch `debug` themselves.
42
+
43
+ ### Updating the Bundled debug Library
44
+
45
+ When a new version of `debug` is released:
46
+
47
+ 1. Update debug in devDependencies: `pnpm add -D debug@x.x.x`
48
+ 2. Run the update script: `./scripts/update-debug.sh`
49
+ 3. Verify patches still apply: `git diff src/lib/debug/`
50
+ 4. Test: `pnpm dev && pnpm prepack`
51
+ 5. Commit: `git commit -am "Update bundled debug to x.x.x"`
52
+
53
+ The patch is maintained in `patches/debug@4.4.3.patch` for reference.
54
+
25
55
  ## Inspirations
26
56
 
27
57
  ### debug
@@ -0,0 +1,2 @@
1
+ declare function _exports(val: string | number, options?: Object): string | number;
2
+ export = _exports;
@@ -0,0 +1,162 @@
1
+ /**
2
+ * Helpers.
3
+ */
4
+
5
+ var s = 1000;
6
+ var m = s * 60;
7
+ var h = m * 60;
8
+ var d = h * 24;
9
+ var w = d * 7;
10
+ var y = d * 365.25;
11
+
12
+ /**
13
+ * Parse or format the given `val`.
14
+ *
15
+ * Options:
16
+ *
17
+ * - `long` verbose formatting [false]
18
+ *
19
+ * @param {String|Number} val
20
+ * @param {Object} [options]
21
+ * @throws {Error} throw an error if val is not a non-empty string or a number
22
+ * @return {String|Number}
23
+ * @api public
24
+ */
25
+
26
+ module.exports = function (val, options) {
27
+ options = options || {};
28
+ var type = typeof val;
29
+ if (type === 'string' && val.length > 0) {
30
+ return parse(val);
31
+ } else if (type === 'number' && isFinite(val)) {
32
+ return options.long ? fmtLong(val) : fmtShort(val);
33
+ }
34
+ throw new Error(
35
+ 'val is not a non-empty string or a valid number. val=' +
36
+ JSON.stringify(val)
37
+ );
38
+ };
39
+
40
+ /**
41
+ * Parse the given `str` and return milliseconds.
42
+ *
43
+ * @param {String} str
44
+ * @return {Number}
45
+ * @api private
46
+ */
47
+
48
+ function parse(str) {
49
+ str = String(str);
50
+ if (str.length > 100) {
51
+ return;
52
+ }
53
+ var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
54
+ str
55
+ );
56
+ if (!match) {
57
+ return;
58
+ }
59
+ var n = parseFloat(match[1]);
60
+ var type = (match[2] || 'ms').toLowerCase();
61
+ switch (type) {
62
+ case 'years':
63
+ case 'year':
64
+ case 'yrs':
65
+ case 'yr':
66
+ case 'y':
67
+ return n * y;
68
+ case 'weeks':
69
+ case 'week':
70
+ case 'w':
71
+ return n * w;
72
+ case 'days':
73
+ case 'day':
74
+ case 'd':
75
+ return n * d;
76
+ case 'hours':
77
+ case 'hour':
78
+ case 'hrs':
79
+ case 'hr':
80
+ case 'h':
81
+ return n * h;
82
+ case 'minutes':
83
+ case 'minute':
84
+ case 'mins':
85
+ case 'min':
86
+ case 'm':
87
+ return n * m;
88
+ case 'seconds':
89
+ case 'second':
90
+ case 'secs':
91
+ case 'sec':
92
+ case 's':
93
+ return n * s;
94
+ case 'milliseconds':
95
+ case 'millisecond':
96
+ case 'msecs':
97
+ case 'msec':
98
+ case 'ms':
99
+ return n;
100
+ default:
101
+ return undefined;
102
+ }
103
+ }
104
+
105
+ /**
106
+ * Short format for `ms`.
107
+ *
108
+ * @param {Number} ms
109
+ * @return {String}
110
+ * @api private
111
+ */
112
+
113
+ function fmtShort(ms) {
114
+ var msAbs = Math.abs(ms);
115
+ if (msAbs >= d) {
116
+ return Math.round(ms / d) + 'd';
117
+ }
118
+ if (msAbs >= h) {
119
+ return Math.round(ms / h) + 'h';
120
+ }
121
+ if (msAbs >= m) {
122
+ return Math.round(ms / m) + 'm';
123
+ }
124
+ if (msAbs >= s) {
125
+ return Math.round(ms / s) + 's';
126
+ }
127
+ return ms + 'ms';
128
+ }
129
+
130
+ /**
131
+ * Long format for `ms`.
132
+ *
133
+ * @param {Number} ms
134
+ * @return {String}
135
+ * @api private
136
+ */
137
+
138
+ function fmtLong(ms) {
139
+ var msAbs = Math.abs(ms);
140
+ if (msAbs >= d) {
141
+ return plural(ms, msAbs, d, 'day');
142
+ }
143
+ if (msAbs >= h) {
144
+ return plural(ms, msAbs, h, 'hour');
145
+ }
146
+ if (msAbs >= m) {
147
+ return plural(ms, msAbs, m, 'minute');
148
+ }
149
+ if (msAbs >= s) {
150
+ return plural(ms, msAbs, s, 'second');
151
+ }
152
+ return ms + ' ms';
153
+ }
154
+
155
+ /**
156
+ * Pluralization helper.
157
+ */
158
+
159
+ function plural(ms, msAbs, n, name) {
160
+ var isPlural = msAbs >= n * 1.5;
161
+ return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
162
+ }
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "ms",
3
+ "version": "2.1.3",
4
+ "description": "Tiny millisecond conversion utility",
5
+ "repository": "vercel/ms",
6
+ "main": "./index",
7
+ "files": [
8
+ "index.js"
9
+ ],
10
+ "scripts": {
11
+ "precommit": "lint-staged",
12
+ "lint": "eslint lib/* bin/*",
13
+ "test": "mocha tests.js"
14
+ },
15
+ "eslintConfig": {
16
+ "extends": "eslint:recommended",
17
+ "env": {
18
+ "node": true,
19
+ "es6": true
20
+ }
21
+ },
22
+ "lint-staged": {
23
+ "*.js": [
24
+ "npm run lint",
25
+ "prettier --single-quote --write",
26
+ "git add"
27
+ ]
28
+ },
29
+ "license": "MIT",
30
+ "devDependencies": {
31
+ "eslint": "4.18.2",
32
+ "expect.js": "0.3.1",
33
+ "husky": "0.14.3",
34
+ "lint-staged": "5.0.0",
35
+ "mocha": "4.0.1",
36
+ "prettier": "2.0.5"
37
+ }
38
+ }
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "debug",
3
+ "version": "4.4.3",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "git://github.com/debug-js/debug.git"
7
+ },
8
+ "description": "Lightweight debugging utility for Node.js and the browser",
9
+ "keywords": [
10
+ "debug",
11
+ "log",
12
+ "debugger"
13
+ ],
14
+ "files": [
15
+ "src",
16
+ "LICENSE",
17
+ "README.md"
18
+ ],
19
+ "author": "Josh Junon (https://github.com/qix-)",
20
+ "contributors": [
21
+ "TJ Holowaychuk <tj@vision-media.ca>",
22
+ "Nathan Rajlich <nathan@tootallnate.net> (http://n8.io)",
23
+ "Andrew Rhyne <rhyneandrew@gmail.com>"
24
+ ],
25
+ "license": "MIT",
26
+ "scripts": {
27
+ "lint": "xo",
28
+ "test": "npm run test:node && npm run test:browser && npm run lint",
29
+ "test:node": "mocha test.js test.node.js",
30
+ "test:browser": "karma start --single-run",
31
+ "test:coverage": "cat ./coverage/lcov.info | coveralls"
32
+ },
33
+ "dependencies": {
34
+ "ms": "^2.1.3"
35
+ },
36
+ "devDependencies": {
37
+ "brfs": "^2.0.1",
38
+ "browserify": "^16.2.3",
39
+ "coveralls": "^3.0.2",
40
+ "karma": "^3.1.4",
41
+ "karma-browserify": "^6.0.0",
42
+ "karma-chrome-launcher": "^2.2.0",
43
+ "karma-mocha": "^1.3.0",
44
+ "mocha": "^5.2.0",
45
+ "mocha-lcov-reporter": "^1.2.0",
46
+ "sinon": "^14.0.0",
47
+ "xo": "^0.23.0"
48
+ },
49
+ "peerDependenciesMeta": {
50
+ "supports-color": {
51
+ "optional": true
52
+ }
53
+ },
54
+ "main": "./src/index.js",
55
+ "browser": "./src/browser.js",
56
+ "engines": {
57
+ "node": ">=6.0"
58
+ },
59
+ "xo": {
60
+ "rules": {
61
+ "import/extensions": "off"
62
+ }
63
+ }
64
+ }
@@ -0,0 +1,93 @@
1
+ declare const _exports: {
2
+ (namespace: string): Function;
3
+ debug: {
4
+ (namespace: string): Function;
5
+ debug: /*elided*/ any;
6
+ default: /*elided*/ any;
7
+ coerce: (val: Mixed) => Mixed;
8
+ disable: () => string;
9
+ enable: (namespaces: string) => void;
10
+ enabled: (name: string) => boolean;
11
+ humanize: (val: string | number, options?: Object) => string | number;
12
+ destroy: () => void;
13
+ names: any[];
14
+ skips: any[];
15
+ formatters: {};
16
+ selectColor: (namespace: string) => number | string;
17
+ };
18
+ default: {
19
+ (namespace: string): Function;
20
+ debug: /*elided*/ any;
21
+ default: /*elided*/ any;
22
+ coerce: (val: Mixed) => Mixed;
23
+ disable: () => string;
24
+ enable: (namespaces: string) => void;
25
+ enabled: (name: string) => boolean;
26
+ humanize: (val: string | number, options?: Object) => string | number;
27
+ destroy: () => void;
28
+ names: any[];
29
+ skips: any[];
30
+ formatters: {};
31
+ selectColor: (namespace: string) => number | string;
32
+ };
33
+ coerce: (val: Mixed) => Mixed;
34
+ disable: () => string;
35
+ enable: (namespaces: string) => void;
36
+ enabled: (name: string) => boolean;
37
+ humanize: (val: string | number, options?: Object) => string | number;
38
+ destroy: (() => void) | (() => void);
39
+ names: any[];
40
+ skips: any[];
41
+ formatters: {};
42
+ selectColor: (namespace: string) => number | string;
43
+ formatArgs: typeof formatArgs;
44
+ save: typeof save;
45
+ load: typeof load;
46
+ useColors: typeof useColors;
47
+ storage: LocalStorage;
48
+ /**
49
+ * Colors.
50
+ */
51
+ colors: string[];
52
+ /**
53
+ * Invokes `console.debug()` when available.
54
+ * No-op when `console.debug` is not a "function".
55
+ * If `console.debug` is not available, falls back
56
+ * to `console.log`.
57
+ *
58
+ * @api public
59
+ */
60
+ log: {
61
+ (...data: any[]): void;
62
+ (message?: any, ...optionalParams: any[]): void;
63
+ };
64
+ };
65
+ export = _exports;
66
+ /**
67
+ * Colorize log arguments if enabled.
68
+ *
69
+ * @api public
70
+ */
71
+ declare function formatArgs(args: any): void;
72
+ /**
73
+ * Save `namespaces`.
74
+ *
75
+ * @param {String} namespaces
76
+ * @api private
77
+ */
78
+ declare function save(namespaces: string): void;
79
+ /**
80
+ * Load `namespaces`.
81
+ *
82
+ * @return {String} returns the previously persisted debug modes
83
+ * @api private
84
+ */
85
+ declare function load(): string;
86
+ /**
87
+ * Currently only WebKit-based Web Inspectors, Firefox >= v31,
88
+ * and the Firebug extension (any Firefox version) are known
89
+ * to support "%c" CSS customizations.
90
+ *
91
+ * TODO: add a `localStorage` variable to explicitly enable/disable colors
92
+ */
93
+ declare function useColors(): any;
@@ -0,0 +1 @@
1
+ function useColors(){if("undefined"!=typeof window&&window.process&&("renderer"===window.process.type||window.process.__nwjs))return!0;if("undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let e;return"undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&(e=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(e[1],10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function formatArgs(e){if(e[0]=(this.useColors?"%c":"")+`${("+"+module.exports.humanize(this.diff)).padStart(6)} ${this.namespace}`+(this.useColors?" %c":" ")+e[0]+(this.useColors?"%c ":" "),!this.useColors)return;const o="color: "+this.color;e.splice(1,0,o,"color: inherit");let t=0,C=0;e[0].replace(/%[a-zA-Z%]/g,e=>{"%%"!==e&&(t++,"%c"===e&&(C=t))}),e.splice(C,0,o)}function save(e){try{e?exports.storage.setItem("debug",e):exports.storage.removeItem("debug")}catch(e){}}function load(){let e;try{e=exports.storage.getItem("debug")||exports.storage.getItem("DEBUG")}catch(e){}return!e&&"undefined"!=typeof process&&"env"in process&&(e=process.env.DEBUG),e}function localstorage(){try{return localStorage}catch(e){}}exports.formatArgs=formatArgs,exports.save=save,exports.load=load,exports.useColors=useColors,exports.storage=localstorage(),exports.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),exports.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],exports.log=console.debug||console.log||(()=>{}),module.exports=require("./common")(exports);const{formatters:formatters}=module.exports;formatters.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}};
@@ -0,0 +1,28 @@
1
+ export = setup;
2
+ /**
3
+ * This is the common logic for both the Node.js and web browser
4
+ * implementations of `debug()`.
5
+ */
6
+ declare function setup(env: any): {
7
+ (namespace: string): Function;
8
+ debug: /*elided*/ any;
9
+ default: /*elided*/ any;
10
+ coerce: (val: Mixed) => Mixed;
11
+ disable: () => string;
12
+ enable: (namespaces: string) => void;
13
+ enabled: (name: string) => boolean;
14
+ humanize: (val: string | number, options?: Object) => string | number;
15
+ destroy: () => void;
16
+ /**
17
+ * The currently active debug mode names, and names to skip.
18
+ */
19
+ names: any[];
20
+ skips: any[];
21
+ /**
22
+ * Map of special "%n" handling functions, for the debug "format" argument.
23
+ *
24
+ * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
25
+ */
26
+ formatters: {};
27
+ selectColor: (namespace: string) => number | string;
28
+ };
@@ -0,0 +1 @@
1
+ function setup(e){function n(e){let o,r,s,l=null;function a(...e){if(!a.enabled)return;const t=a,r=Number(new Date),s=r-(o||r);t.diff=s,t.prev=o,t.curr=r,o=r,e[0]=n.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let l=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,(o,r)=>{if("%%"===o)return"%";l++;const s=n.formatters[r];if("function"==typeof s){const n=e[l];o=s.call(t,n),e.splice(l,1),l--}return o}),n.formatArgs.call(t,e);(t.log||n.log).apply(t,e)}return a.namespace=e,a.useColors=n.useColors(),a.color=n.selectColor(e),a.extend=t,a.destroy=n.destroy,Object.defineProperty(a,"enabled",{enumerable:!0,configurable:!1,get:()=>null!==l?l:(r!==n.namespaces&&(r=n.namespaces,s=n.enabled(e)),s),set:e=>{l=e}}),"function"==typeof n.init&&n.init(a),a}function t(e,t){const o=n(this.namespace+(void 0===t?":":t)+e);return o.log=this.log,o}function o(e,n){let t=0,o=0,r=-1,s=0;for(;t<e.length;)if(o<n.length&&(n[o]===e[t]||"*"===n[o]))"*"===n[o]?(r=o,s=t,o++):(t++,o++);else{if(-1===r)return!1;o=r+1,s++,t=s}for(;o<n.length&&"*"===n[o];)o++;return o===n.length}return n.debug=n,n.default=n,n.coerce=function(e){if(e instanceof Error)return e.stack||e.message;return e},n.disable=function(){const e=[...n.names,...n.skips.map(e=>"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){n.save(e),n.namespaces=e,n.names=[],n.skips=[];const t=("string"==typeof e?e:"").trim().replace(/\s+/g,",").split(",").filter(Boolean);for(const e of t)"-"===e[0]?n.skips.push(e.slice(1)):n.names.push(e)},n.enabled=function(e){for(const t of n.skips)if(o(e,t))return!1;for(const t of n.names)if(o(e,t))return!0;return!1},n.humanize=require("../ms"),n.destroy=function(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")},Object.keys(e).forEach(t=>{n[t]=e[t]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(e){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n),t|=0;return n.colors[Math.abs(t)%n.colors.length]},n.enable(n.load()),n}module.exports=setup;
@@ -0,0 +1,104 @@
1
+ declare const _exports: {
2
+ (namespace: string): Function;
3
+ debug: {
4
+ (namespace: string): Function;
5
+ debug: /*elided*/ any;
6
+ default: /*elided*/ any;
7
+ coerce: (val: Mixed) => Mixed;
8
+ disable: () => string;
9
+ enable: (namespaces: string) => void;
10
+ enabled: (name: string) => boolean;
11
+ humanize: (val: string | number, options?: Object) => string | number;
12
+ destroy: () => void;
13
+ names: any[];
14
+ skips: any[];
15
+ formatters: {};
16
+ selectColor: (namespace: string) => number | string;
17
+ };
18
+ default: {
19
+ (namespace: string): Function;
20
+ debug: /*elided*/ any;
21
+ default: /*elided*/ any;
22
+ coerce: (val: Mixed) => Mixed;
23
+ disable: () => string;
24
+ enable: (namespaces: string) => void;
25
+ enabled: (name: string) => boolean;
26
+ humanize: (val: string | number, options?: Object) => string | number;
27
+ destroy: () => void;
28
+ names: any[];
29
+ skips: any[];
30
+ formatters: {};
31
+ selectColor: (namespace: string) => number | string;
32
+ };
33
+ coerce: (val: Mixed) => Mixed;
34
+ disable: () => string;
35
+ enable: (namespaces: string) => void;
36
+ enabled: (name: string) => boolean;
37
+ humanize: (val: string | number, options?: Object) => string | number;
38
+ destroy: (() => void) | (() => void);
39
+ names: any[];
40
+ skips: any[];
41
+ formatters: {};
42
+ selectColor: (namespace: string) => number | string;
43
+ formatArgs: typeof import("./browser.js").formatArgs;
44
+ save: typeof import("./browser.js").save;
45
+ load: typeof import("./browser.js").load;
46
+ useColors: typeof import("./browser.js").useColors;
47
+ storage: LocalStorage;
48
+ colors: string[];
49
+ log: {
50
+ (...data: any[]): void;
51
+ (message?: any, ...optionalParams: any[]): void;
52
+ };
53
+ } | {
54
+ (namespace: string): Function;
55
+ debug: {
56
+ (namespace: string): Function;
57
+ debug: /*elided*/ any;
58
+ default: /*elided*/ any;
59
+ coerce: (val: Mixed) => Mixed;
60
+ disable: () => string;
61
+ enable: (namespaces: string) => void;
62
+ enabled: (name: string) => boolean;
63
+ humanize: (val: string | number, options?: Object) => string | number;
64
+ destroy: () => void;
65
+ names: any[];
66
+ skips: any[];
67
+ formatters: {};
68
+ selectColor: (namespace: string) => number | string;
69
+ };
70
+ default: {
71
+ (namespace: string): Function;
72
+ debug: /*elided*/ any;
73
+ default: /*elided*/ any;
74
+ coerce: (val: Mixed) => Mixed;
75
+ disable: () => string;
76
+ enable: (namespaces: string) => void;
77
+ enabled: (name: string) => boolean;
78
+ humanize: (val: string | number, options?: Object) => string | number;
79
+ destroy: () => void;
80
+ names: any[];
81
+ skips: any[];
82
+ formatters: {};
83
+ selectColor: (namespace: string) => number | string;
84
+ };
85
+ coerce: (val: Mixed) => Mixed;
86
+ disable: () => string;
87
+ enable: (namespaces: string) => void;
88
+ enabled: (name: string) => boolean;
89
+ humanize: (val: string | number, options?: Object) => string | number;
90
+ destroy: (() => void) | (() => void);
91
+ names: any[];
92
+ skips: any[];
93
+ formatters: {};
94
+ selectColor: (namespace: string) => number | string;
95
+ init: typeof import("./node.js").init;
96
+ log: typeof import("./node.js").log;
97
+ formatArgs: typeof import("./node.js").formatArgs;
98
+ save: typeof import("./node.js").save;
99
+ load: typeof import("./node.js").load;
100
+ useColors: typeof import("./node.js").useColors;
101
+ colors: number[];
102
+ inspectOpts: {};
103
+ };
104
+ export = _exports;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Detect Electron renderer / nwjs process, which is node, but we should
3
+ * treat as a browser.
4
+ */
5
+
6
+ if (typeof process === 'undefined' || process.type === 'renderer' || process.browser === true || process.__nwjs) {
7
+ module.exports = require('./browser.js');
8
+ } else {
9
+ module.exports = require('./node.js');
10
+ }
@@ -0,0 +1,95 @@
1
+ declare const _exports: {
2
+ (namespace: string): Function;
3
+ debug: {
4
+ (namespace: string): Function;
5
+ debug: /*elided*/ any;
6
+ default: /*elided*/ any;
7
+ coerce: (val: Mixed) => Mixed;
8
+ disable: () => string;
9
+ enable: (namespaces: string) => void;
10
+ enabled: (name: string) => boolean;
11
+ humanize: (val: string | number, options?: Object) => string | number;
12
+ destroy: () => void;
13
+ names: any[];
14
+ skips: any[];
15
+ formatters: {};
16
+ selectColor: (namespace: string) => number | string;
17
+ };
18
+ default: {
19
+ (namespace: string): Function;
20
+ debug: /*elided*/ any;
21
+ default: /*elided*/ any;
22
+ coerce: (val: Mixed) => Mixed;
23
+ disable: () => string;
24
+ enable: (namespaces: string) => void;
25
+ enabled: (name: string) => boolean;
26
+ humanize: (val: string | number, options?: Object) => string | number;
27
+ destroy: () => void;
28
+ names: any[];
29
+ skips: any[];
30
+ formatters: {};
31
+ selectColor: (namespace: string) => number | string;
32
+ };
33
+ coerce: (val: Mixed) => Mixed;
34
+ disable: () => string;
35
+ enable: (namespaces: string) => void;
36
+ enabled: (name: string) => boolean;
37
+ humanize: (val: string | number, options?: Object) => string | number;
38
+ destroy: (() => void) | (() => void);
39
+ names: any[];
40
+ skips: any[];
41
+ formatters: {};
42
+ selectColor: (namespace: string) => number | string;
43
+ init: typeof init;
44
+ log: typeof log;
45
+ formatArgs: typeof formatArgs;
46
+ save: typeof save;
47
+ load: typeof load;
48
+ useColors: typeof useColors;
49
+ /**
50
+ * Colors.
51
+ */
52
+ colors: number[];
53
+ /**
54
+ * Build up the default `inspectOpts` object from the environment variables.
55
+ *
56
+ * $ DEBUG_COLORS=no DEBUG_DEPTH=10 DEBUG_SHOW_HIDDEN=enabled node script.js
57
+ */
58
+ inspectOpts: {};
59
+ };
60
+ export = _exports;
61
+ /**
62
+ * Init logic for `debug` instances.
63
+ *
64
+ * Create a new `inspectOpts` object in case `useColors` is set
65
+ * differently for a particular `debug` instance.
66
+ */
67
+ declare function init(debug: any): void;
68
+ /**
69
+ * Invokes `util.formatWithOptions()` with the specified arguments and writes to stderr.
70
+ */
71
+ declare function log(...args: any[]): boolean;
72
+ /**
73
+ * Adds ANSI color escape codes if enabled.
74
+ *
75
+ * @api public
76
+ */
77
+ declare function formatArgs(args: any): void;
78
+ /**
79
+ * Save `namespaces`.
80
+ *
81
+ * @param {String} namespaces
82
+ * @api private
83
+ */
84
+ declare function save(namespaces: string): void;
85
+ /**
86
+ * Load `namespaces`.
87
+ *
88
+ * @return {String} returns the previously persisted debug modes
89
+ * @api private
90
+ */
91
+ declare function load(): string;
92
+ /**
93
+ * Is stdout a TTY? Colored output is enabled when `true`.
94
+ */
95
+ declare function useColors(): boolean;
@@ -0,0 +1 @@
1
+ const tty=require("tty"),util=require("util");exports.init=init,exports.log=log,exports.formatArgs=formatArgs,exports.save=save,exports.load=load,exports.useColors=useColors,exports.destroy=util.deprecate(()=>{},"Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."),exports.colors=[6,2,3,4,5,1];try{const t=require("supports-color");t&&(t.stderr||t).level>=2&&(exports.colors=[20,21,26,27,32,33,38,39,40,41,42,43,44,45,56,57,62,63,68,69,74,75,76,77,78,79,80,81,92,93,98,99,112,113,128,129,134,135,148,149,160,161,162,163,164,165,166,167,168,169,170,171,172,173,178,179,184,185,196,197,198,199,200,201,202,203,204,205,206,207,208,209,214,215,220,221])}catch(t){}function useColors(){return"colors"in exports.inspectOpts?Boolean(exports.inspectOpts.colors):tty.isatty(process.stderr.fd)}function formatArgs(t){const{namespace:e,useColors:s}=this;if(s){const s=this.color,o="[3"+(s<8?s:"8;5;"+s),r=`${o};1m${("+"+module.exports.humanize(this.diff)).padStart(6)} ${e} `;t[0]=r+t[0].split("\n").join("\n"+r),t.push(o+"")}else t[0]=getDate()+e+" "+t[0]}function getDate(){return exports.inspectOpts.hideDate?"":(new Date).toISOString()+" "}function log(...t){return process.stderr.write(util.formatWithOptions(exports.inspectOpts,...t)+"\n")}function save(t){t?process.env.DEBUG=t:delete process.env.DEBUG}function load(){return process.env.DEBUG}function init(t){t.inspectOpts={};const e=Object.keys(exports.inspectOpts);for(let s=0;s<e.length;s++)t.inspectOpts[e[s]]=exports.inspectOpts[e[s]]}exports.inspectOpts=Object.keys(process.env).filter(t=>/^debug_/i.test(t)).reduce((t,e)=>{const s=e.substring(6).toLowerCase().replace(/_([a-z])/g,(t,e)=>e.toUpperCase());let o=process.env[e];return o=!!/^(yes|on|true|enabled)$/i.test(o)||!/^(no|off|false|disabled)$/i.test(o)&&("null"===o?null:Number(o)),t[s]=o,t},{}),module.exports=require("./common")(exports);const{formatters:formatters}=module.exports;formatters.o=function(t){return this.inspectOpts.colors=this.useColors,util.inspect(t,this.inspectOpts).split("\n").map(t=>t.trim()).join(" ")},formatters.O=function(t){return this.inspectOpts.colors=this.useColors,util.inspect(t,this.inspectOpts)};
@@ -0,0 +1,2 @@
1
+ export default debugModule;
2
+ import debugModule from './debug/src/index.js';
package/dist/debug.js ADDED
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Re-export patched debug library
3
+ * This file bundles the patched version of debug into the library distribution.
4
+ *
5
+ * The patch moves time diff display before namespace:
6
+ * Standard: gg:file +123ms
7
+ * Patched: +123ms gg:file
8
+ */
9
+
10
+ // The debug/src/index.js handles browser vs node environment detection
11
+ // Import CommonJS module and re-export as ES module default
12
+ import debugModule from './debug/src/index.js';
13
+ export default debugModule;
package/dist/gg.d.ts CHANGED
@@ -7,6 +7,6 @@ export declare function gg(): {
7
7
  };
8
8
  export declare function gg<T>(arg: T, ...args: unknown[]): T;
9
9
  export declare namespace gg {
10
- var disable: () => string;
10
+ var disable: () => void;
11
11
  var enable: (namespaces: string) => void;
12
12
  }
package/dist/gg.js CHANGED
@@ -1,11 +1,36 @@
1
- import * as dotenv from 'dotenv';
2
- import debugFactory from 'debug';
1
+ import debugFactory from './debug.js';
3
2
  import ErrorStackParser from 'error-stack-parser';
4
3
  import { BROWSER } from 'esm-env';
5
- import http from 'http';
4
+ // Helper to detect if we're running in CloudFlare Workers
5
+ const isCloudflareWorker = () => {
6
+ // Check for CloudFlare Workers-specific global
7
+ const globalWithWorkerAPIs = globalThis;
8
+ return (typeof globalThis !== 'undefined' &&
9
+ 'caches' in globalThis &&
10
+ typeof globalWithWorkerAPIs.WebSocketPair !== 'undefined');
11
+ };
12
+ // Check if we're in CloudFlare Workers and warn early
13
+ if (isCloudflareWorker()) {
14
+ console.warn('gg: CloudFlare not supported.');
15
+ }
16
+ // Try to load Node.js modules if not in CloudFlare Workers
17
+ let dotenvModule = null;
18
+ let httpModule = null;
19
+ if (!isCloudflareWorker() && !BROWSER) {
20
+ try {
21
+ dotenvModule = await import('dotenv');
22
+ }
23
+ catch {
24
+ httpModule = await import('http');
25
+ // Failed to import Node.js modules
26
+ console.warn('gg: Node.js modules not available');
27
+ }
28
+ }
6
29
  function findAvailablePort(startingPort) {
30
+ if (!httpModule)
31
+ return Promise.resolve(startingPort);
7
32
  return new Promise((resolve) => {
8
- const server = http.createServer();
33
+ const server = httpModule.createServer();
9
34
  server.listen(startingPort, () => {
10
35
  const actualPort = server?.address()?.port;
11
36
  server.close(() => resolve(actualPort));
@@ -24,9 +49,13 @@ function getServerPort() {
24
49
  // Resolve the promise with the detected port
25
50
  resolve(currentPort);
26
51
  }
52
+ else if (isCloudflareWorker()) {
53
+ // CloudFlare Workers - return default port
54
+ resolve('5173');
55
+ }
27
56
  else {
28
57
  // Node.js environment
29
- const startingPort = Number(process.env.PORT) || 5173; // Default to Vite's default port
58
+ const startingPort = Number(process?.env?.PORT) || 5173; // Default to Vite's default port
30
59
  findAvailablePort(startingPort).then((actualPort) => {
31
60
  resolve(actualPort);
32
61
  });
@@ -36,8 +65,8 @@ function getServerPort() {
36
65
  const timestampRegex = /(\?t=\d+)?$/;
37
66
  const port = await getServerPort();
38
67
  const ggConfig = {
39
- enabled: true,
40
- showHints: true,
68
+ enabled: !isCloudflareWorker(), // Disable in CloudFlare Workers
69
+ showHints: !isCloudflareWorker(), // Don't show hints in CloudFlare Workers
41
70
  editorLink: false,
42
71
  openInEditorUrlTemplate: `http://localhost:${port}/__open-in-editor?file=$FILENAME`,
43
72
  // The srcRoot contains all source files.
@@ -56,43 +85,8 @@ let maxCallpointLength = 0;
56
85
  function openInEditorUrl(fileName) {
57
86
  return ggConfig.openInEditorUrlTemplate.replace('$FILENAME', encodeURIComponent(fileName).replaceAll('%2F', '/'));
58
87
  }
59
- // http://localhost:5173/__open-in-editor?file=src%2Froutes%2F%2Bpage.svelte
60
- // Log some gg info to the JS console/terminal:
61
- if (ggConfig.showHints) {
62
- const ggLogTest = debugFactory('gg:TEST');
63
- let ggMessage = '\n';
64
- // Utilities for forming ggMessage:
65
- const message = (s) => (ggMessage += `${s}\n`);
66
- const checkbox = (test) => (test ? '✅' : '❌');
67
- const makeHint = (test, ifTrue, ifFalse = '') => (test ? ifTrue : ifFalse);
68
- console.log(`Loaded gg module. Checking configuration...`);
69
- if (ggConfig.enabled && ggLogTest.enabled) {
70
- gg('If you can see this logg, gg configured correctly!');
71
- message(`No problems detected:`);
72
- if (BROWSER) {
73
- message(`ℹ️ If gg output still not visible above, enable "Verbose" log level in browser DevTools.`);
74
- }
75
- }
76
- else {
77
- message(`Problems detected; fix all ❌:`);
78
- }
79
- const hint = makeHint(!ggConfig.enabled, ' (Update value in gg.ts file.)');
80
- message(`${checkbox(ggConfig.enabled)} ggConfig.enabled: ${ggConfig.enabled}${hint}`);
81
- if (BROWSER) {
82
- const hint = makeHint(!ggLogTest.enabled, " (Try `localStorage.debug = 'gg:*'`)");
83
- message(`${checkbox(ggLogTest.enabled)} localStorage.debug: ${localStorage?.debug}${hint}`);
84
- const { status } = await fetch('/__open-in-editor?file=+');
85
- message(makeHint(status === 222, `✅ (optional) open-in-editor vite plugin detected! (status code: ${status})`, `⚠️ (optional) open-in-editor vite plugin not detected. (status code: ${status}.) Add plugin in vite.config.ts`));
86
- }
87
- else {
88
- const hint = makeHint(!ggLogTest.enabled, ' (Try `DEBUG=gg:* npm dev`)');
89
- dotenv.config(); // Load the environment variables
90
- message(`${checkbox(ggLogTest.enabled)} DEBUG env variable: ${process?.env?.DEBUG}${hint}`);
91
- }
92
- console.log(ggMessage);
93
- }
94
88
  export function gg(...args) {
95
- if (!ggConfig.enabled) {
89
+ if (!ggConfig.enabled || isCloudflareWorker()) {
96
90
  return args.length ? args[0] : { url: '', stack: [] };
97
91
  }
98
92
  // Ignore first stack frame, which is always the call to gg() itself.
@@ -123,8 +117,50 @@ export function gg(...args) {
123
117
  stack
124
118
  };
125
119
  }
126
- ggLogFunction(...args);
120
+ // Handle the case where args might be empty or have any number of arguments
121
+ if (args.length === 1) {
122
+ ggLogFunction(args[0]);
123
+ }
124
+ else {
125
+ ggLogFunction(args[0], ...args.slice(1));
126
+ }
127
127
  return args[0];
128
128
  }
129
- gg.disable = debugFactory.disable;
130
- gg.enable = debugFactory.enable;
129
+ gg.disable = isCloudflareWorker() ? () => { } : debugFactory.disable;
130
+ gg.enable = isCloudflareWorker() ? () => { } : debugFactory.enable;
131
+ // Log some gg info to the JS console/terminal:
132
+ if (ggConfig.showHints && !isCloudflareWorker()) {
133
+ const ggLogTest = debugFactory('gg:TEST');
134
+ let ggMessage = '\n';
135
+ // Utilities for forming ggMessage:
136
+ const message = (s) => (ggMessage += `${s}\n`);
137
+ const checkbox = (test) => (test ? '✅' : '❌');
138
+ const makeHint = (test, ifTrue, ifFalse = '') => (test ? ifTrue : ifFalse);
139
+ console.log(`Loaded gg module. Checking configuration...`);
140
+ if (ggConfig.enabled && ggLogTest.enabled) {
141
+ gg('If you can see this logg, gg configured correctly!');
142
+ message(`No problems detected:`);
143
+ if (BROWSER) {
144
+ message(`ℹ️ If gg output still not visible above, enable "Verbose" log level in browser DevTools.`);
145
+ }
146
+ }
147
+ else {
148
+ message(`Problems detected; fix all ❌:`);
149
+ }
150
+ const hint = makeHint(!ggConfig.enabled, ' (Update value in gg.ts file.)');
151
+ message(`${checkbox(ggConfig.enabled)} ggConfig.enabled: ${ggConfig.enabled}${hint}`);
152
+ if (BROWSER) {
153
+ const hint = makeHint(!ggLogTest.enabled, " (Try `localStorage.debug = 'gg:*'`)");
154
+ message(`${checkbox(ggLogTest.enabled)} localStorage.debug: ${localStorage?.debug}${hint}`);
155
+ const { status } = await fetch('/__open-in-editor?file=+');
156
+ message(makeHint(status === 222, `✅ (optional) open-in-editor vite plugin detected! (status code: ${status})`, `⚠️ (optional) open-in-editor vite plugin not detected. (status code: ${status}.) Add plugin in vite.config.ts`));
157
+ }
158
+ else {
159
+ const hint = makeHint(!ggLogTest.enabled, ' (Try `DEBUG=gg:* npm dev`)');
160
+ if (dotenvModule) {
161
+ dotenvModule.config(); // Load the environment variables
162
+ }
163
+ message(`${checkbox(ggLogTest.enabled)} DEBUG env variable: ${process?.env?.DEBUG}${hint}`);
164
+ }
165
+ console.log(ggMessage);
166
+ }
package/package.json CHANGED
@@ -1,80 +1,75 @@
1
1
  {
2
- "name": "@leftium/gg",
3
- "version": "0.0.14",
4
- "repository": {
5
- "type": "git",
6
- "url": "git+https://github.com/Leftium/gg.git"
7
- },
8
- "license": "MIT",
9
- "scripts": {
10
- "dev": "vite dev",
11
- "build": "vite build && npm run prepack",
12
- "preview": "vite preview",
13
- "prepare": "svelte-kit sync || echo ''",
14
- "prepack": "svelte-kit sync && svelte-package && publint",
15
- "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
16
- "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
17
- "format": "prettier --write .",
18
- "lint": "prettier --check . && eslint ."
19
- },
20
- "files": [
21
- "dist",
22
- "!dist/**/*.test.*",
23
- "!dist/**/*.spec.*",
24
- "patches/"
25
- ],
26
- "sideEffects": [
27
- "**/*.css"
28
- ],
29
- "types": "./dist/index.d.ts",
30
- "type": "module",
31
- "exports": {
32
- ".": {
33
- "types": "./dist/index.d.ts",
34
- "default": "./dist/index.js"
35
- }
36
- },
37
- "peerDependencies": {
38
- "svelte": "^5.0.0"
39
- },
40
- "devDependencies": {
41
- "@eslint/compat": "^1.3.2",
42
- "@eslint/js": "^9.33.0",
43
- "@picocss/pico": "^2.1.1",
44
- "@sveltejs/adapter-vercel": "^5.8.2",
45
- "@sveltejs/kit": "^2.27.3",
46
- "@sveltejs/package": "^2.4.1",
47
- "@sveltejs/vite-plugin-svelte": "^6.1.1",
48
- "@types/debug": "^4.1.12",
49
- "@types/node": "^24.2.1",
50
- "add": "^2.0.6",
51
- "eslint": "^9.33.0",
52
- "eslint-config-prettier": "^10.1.8",
53
- "eslint-plugin-svelte": "^3.11.0",
54
- "globals": "^16.3.0",
55
- "prettier": "^3.6.2",
56
- "prettier-plugin-svelte": "^3.4.0",
57
- "publint": "^0.3.12",
58
- "svelte": "^5.38.0",
59
- "svelte-check": "^4.3.1",
60
- "typescript": "^5.9.2",
61
- "typescript-eslint": "^8.39.0",
62
- "vite": "^7.1.1",
63
- "vite-plugin-devtools-json": "^0.4.1"
64
- },
65
- "keywords": [
66
- "svelte"
67
- ],
68
- "pnpm": {
69
- "onlyBuiltDependencies": [
70
- "esbuild"
71
- ]
72
- },
73
- "dependencies": {
74
- "debug": "^4.4.1",
75
- "dotenv": "^17.2.1",
76
- "error-stack-parser": "^2.1.4",
77
- "esm-env": "^1.2.2",
78
- "launch-editor": "^2.11.1"
79
- }
80
- }
2
+ "name": "@leftium/gg",
3
+ "version": "0.0.16",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "git+https://github.com/Leftium/gg.git"
7
+ },
8
+ "license": "MIT",
9
+ "files": [
10
+ "dist",
11
+ "!dist/**/*.test.*",
12
+ "!dist/**/*.spec.*",
13
+ "patches/"
14
+ ],
15
+ "sideEffects": [
16
+ "**/*.css"
17
+ ],
18
+ "types": "./dist/index.d.ts",
19
+ "type": "module",
20
+ "exports": {
21
+ ".": {
22
+ "types": "./dist/index.d.ts",
23
+ "default": "./dist/index.js"
24
+ }
25
+ },
26
+ "peerDependencies": {
27
+ "svelte": "^5.0.0"
28
+ },
29
+ "devDependencies": {
30
+ "@eslint/compat": "^1.4.1",
31
+ "@eslint/js": "^9.39.1",
32
+ "@picocss/pico": "^2.1.1",
33
+ "@sveltejs/adapter-vercel": "^6.1.1",
34
+ "@sveltejs/kit": "^2.48.4",
35
+ "@sveltejs/package": "^2.5.4",
36
+ "@sveltejs/vite-plugin-svelte": "^6.2.1",
37
+ "@types/debug": "^4.1.12",
38
+ "@types/node": "^24.10.0",
39
+ "add": "^2.0.6",
40
+ "debug": "^4.4.3",
41
+ "eslint": "^9.39.1",
42
+ "eslint-config-prettier": "^10.1.8",
43
+ "eslint-plugin-svelte": "^3.13.0",
44
+ "globals": "^16.5.0",
45
+ "ms": "^2.1.3",
46
+ "prettier": "^3.6.2",
47
+ "prettier-plugin-svelte": "^3.4.0",
48
+ "publint": "^0.3.15",
49
+ "svelte": "^5.43.3",
50
+ "svelte-check": "^4.3.3",
51
+ "terser": "^5.36.0",
52
+ "typescript": "^5.9.3",
53
+ "typescript-eslint": "^8.46.3",
54
+ "vite": "^7.2.0",
55
+ "vite-plugin-devtools-json": "^1.0.0"
56
+ },
57
+ "keywords": [
58
+ "svelte"
59
+ ],
60
+ "dependencies": {
61
+ "dotenv": "^17.2.3",
62
+ "error-stack-parser": "^2.1.4",
63
+ "esm-env": "^1.2.2",
64
+ "launch-editor": "^2.12.0"
65
+ },
66
+ "scripts": {
67
+ "dev": "vite dev",
68
+ "build": "vite build && npm run prepack",
69
+ "preview": "vite preview",
70
+ "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
71
+ "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
72
+ "format": "prettier --write .",
73
+ "lint": "prettier --check . && eslint ."
74
+ }
75
+ }
@@ -0,0 +1,35 @@
1
+ diff --git a/src/browser.js b/src/browser.js
2
+ index 5993451b82e6b27d981e202b349641816d867ccf..a2eb7c60fb7f5a8b93b2310acb15d6f89c3a1195 100644
3
+ --- a/src/browser.js
4
+ +++ b/src/browser.js
5
+ @@ -148,11 +148,11 @@ function useColors() {
6
+
7
+ function formatArgs(args) {
8
+ args[0] = (this.useColors ? '%c' : '') +
9
+ - this.namespace +
10
+ + `${('+' + module.exports.humanize(this.diff)).padStart(6)} ${this.namespace}` +
11
+ (this.useColors ? ' %c' : ' ') +
12
+ args[0] +
13
+ (this.useColors ? '%c ' : ' ') +
14
+ - '+' + module.exports.humanize(this.diff);
15
+ + '';
16
+
17
+ if (!this.useColors) {
18
+ return;
19
+ diff --git a/src/node.js b/src/node.js
20
+ index 715560a4ca8fb4c8dd6353eafdde6e83af28f05e..3829ba356e038a60408f9f7f0ed742baab527c6b 100644
21
+ --- a/src/node.js
22
+ +++ b/src/node.js
23
+ @@ -170,10 +170,10 @@ function formatArgs(args) {
24
+ if (useColors) {
25
+ const c = this.color;
26
+ const colorCode = '\u001B[3' + (c < 8 ? c : '8;5;' + c);
27
+ - const prefix = ` ${colorCode};1m${name} \u001B[0m`;
28
+ + const prefix = `${colorCode};1m${('+' + module.exports.humanize(this.diff)).padStart(6)} ${name} \u001B[0m`;
29
+
30
+ args[0] = prefix + args[0].split('\n').join('\n' + prefix);
31
+ - args.push(colorCode + 'm+' + module.exports.humanize(this.diff) + '\u001B[0m');
32
+ + args.push(colorCode + '' + '\u001B[0m');
33
+ } else {
34
+ args[0] = getDate() + name + ' ' + args[0];
35
+ }