@leftium/gg 0.0.28 → 0.0.29
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Plugin } from 'vite';
|
|
2
|
-
export interface
|
|
2
|
+
export interface GgCallSitesPluginOptions {
|
|
3
3
|
/**
|
|
4
4
|
* Pattern to strip from file paths to produce short callpoints.
|
|
5
5
|
* Should match up to and including the source root folder.
|
|
@@ -22,10 +22,10 @@ export interface GgTagPluginOptions {
|
|
|
22
22
|
*
|
|
23
23
|
* @example
|
|
24
24
|
* // vite.config.ts
|
|
25
|
-
* import {
|
|
25
|
+
* import { ggCallSitesPlugin } from '@leftium/gg';
|
|
26
26
|
*
|
|
27
27
|
* export default defineConfig({
|
|
28
|
-
* plugins: [
|
|
28
|
+
* plugins: [ggCallSitesPlugin()]
|
|
29
29
|
* });
|
|
30
30
|
*/
|
|
31
|
-
export default function
|
|
31
|
+
export default function ggCallSitesPlugin(options?: GgCallSitesPluginOptions): Plugin;
|
|
@@ -9,17 +9,27 @@
|
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
11
|
* // vite.config.ts
|
|
12
|
-
* import {
|
|
12
|
+
* import { ggCallSitesPlugin } from '@leftium/gg';
|
|
13
13
|
*
|
|
14
14
|
* export default defineConfig({
|
|
15
|
-
* plugins: [
|
|
15
|
+
* plugins: [ggCallSitesPlugin()]
|
|
16
16
|
* });
|
|
17
17
|
*/
|
|
18
|
-
export default function
|
|
18
|
+
export default function ggCallSitesPlugin(options = {}) {
|
|
19
19
|
const srcRootPattern = options.srcRootPattern ?? '.*?(/(?:src|chunks)/)';
|
|
20
20
|
const srcRootRegex = new RegExp(srcRootPattern, 'i');
|
|
21
21
|
return {
|
|
22
|
-
name: 'gg-
|
|
22
|
+
name: 'gg-call-sites',
|
|
23
|
+
config() {
|
|
24
|
+
// Set a compile-time flag so gg() can detect the plugin is installed.
|
|
25
|
+
// Vite replaces all occurrences of __GG_TAG_PLUGIN__ with true at build time,
|
|
26
|
+
// before any code executes — no ordering issues.
|
|
27
|
+
return {
|
|
28
|
+
define: {
|
|
29
|
+
__GG_TAG_PLUGIN__: 'true'
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
},
|
|
23
33
|
transform(code, id) {
|
|
24
34
|
// Only process JS/TS/Svelte files
|
|
25
35
|
if (!/\.(js|ts|svelte|jsx|tsx|mjs|mts)(\?.*)?$/.test(id))
|
package/dist/gg.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import debugFactory from './debug.js';
|
|
2
2
|
import ErrorStackParser from 'error-stack-parser';
|
|
3
3
|
import { BROWSER, DEV } from 'esm-env';
|
|
4
|
+
const _ggCallSitesPlugin = typeof __GG_TAG_PLUGIN__ !== 'undefined' ? __GG_TAG_PLUGIN__ : false;
|
|
4
5
|
/**
|
|
5
6
|
* Creates a debug instance with custom formatArgs to add namespace padding
|
|
6
7
|
* Padding is done at format time, not in the namespace itself, to keep colors stable
|
|
@@ -185,9 +186,12 @@ export function gg(...args) {
|
|
|
185
186
|
let url = '';
|
|
186
187
|
let stack = [];
|
|
187
188
|
let namespace = 'gg:';
|
|
188
|
-
//
|
|
189
|
-
//
|
|
190
|
-
if
|
|
189
|
+
// When ggCallSitesPlugin is installed, all bare gg() calls are rewritten to gg.ns()
|
|
190
|
+
// at build time, so this code path only runs for un-transformed calls.
|
|
191
|
+
// Skip expensive stack parsing if the plugin is handling callpoints.
|
|
192
|
+
// In development without plugin: calculate detailed callpoint information
|
|
193
|
+
// In production without plugin: skip expensive stack parsing and use simple namespace
|
|
194
|
+
if (DEV && !_ggCallSitesPlugin) {
|
|
191
195
|
// Ignore first stack frame, which is always the call to gg() itself.
|
|
192
196
|
stack = ErrorStackParser.parse(new Error()).splice(1);
|
|
193
197
|
// Example: http://localhost:5173/src/routes/+page.svelte
|
|
@@ -258,7 +262,7 @@ export function gg(...args) {
|
|
|
258
262
|
/**
|
|
259
263
|
* gg.ns() - Log with an explicit namespace (callpoint label).
|
|
260
264
|
*
|
|
261
|
-
* In production builds, the
|
|
265
|
+
* In production builds, the ggCallSitesPlugin Vite plugin rewrites bare gg() calls
|
|
262
266
|
* to gg.ns('callpoint', ...) so each call site gets a unique namespace even
|
|
263
267
|
* after minification. Users can also call gg.ns() directly to set a meaningful
|
|
264
268
|
* label that survives across builds.
|
|
@@ -514,10 +518,6 @@ export async function runGgDiagnostics() {
|
|
|
514
518
|
if (BROWSER) {
|
|
515
519
|
const hint = makeHint(!ggLogTest.enabled, " (Try `localStorage.debug = 'gg:*'`)");
|
|
516
520
|
message(`${checkbox(ggLogTest.enabled)} localStorage.debug: ${localStorage?.debug}${hint}`);
|
|
517
|
-
if (DEV) {
|
|
518
|
-
const { status } = await fetch('/__open-in-editor?file=+');
|
|
519
|
-
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`));
|
|
520
|
-
}
|
|
521
521
|
}
|
|
522
522
|
else {
|
|
523
523
|
const hint = makeHint(!ggLogTest.enabled, ' (Try `DEBUG=gg:* npm dev`)');
|
|
@@ -526,6 +526,12 @@ export async function runGgDiagnostics() {
|
|
|
526
526
|
}
|
|
527
527
|
message(`${checkbox(ggLogTest.enabled)} DEBUG env variable: ${process?.env?.DEBUG}${hint}`);
|
|
528
528
|
}
|
|
529
|
+
// Optional plugin diagnostics listed last
|
|
530
|
+
message(makeHint(_ggCallSitesPlugin, `✅ (optional) gg-call-sites vite plugin detected! Call-site namespaces baked in at build time.`, `⚠️ (optional) gg-call-sites vite plugin not detected. Add ggCallSitesPlugin() to vite.config.ts for build-time call-site namespaces (needed for useful namespaces in prod, faster/more reliable in dev)`));
|
|
531
|
+
if (BROWSER && DEV) {
|
|
532
|
+
const { status } = await fetch('/__open-in-editor?file=+');
|
|
533
|
+
message(makeHint(status === 222, `✅ (optional) open-in-editor vite plugin detected! (status code: ${status}) Clickable links open source files in editor.`, `⚠️ (optional) open-in-editor vite plugin not detected. (status code: ${status}) Add openInEditorPlugin() to vite.config.ts for clickable links that open source files in editor`));
|
|
534
|
+
}
|
|
529
535
|
// Use plain console.log for diagnostics - appears in Eruda's Console tab
|
|
530
536
|
console.log(ggMessage);
|
|
531
537
|
// Reset namespace width after configuration check
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { gg, fg, bg } from './gg.js';
|
|
2
2
|
import openInEditorPlugin from './open-in-editor.js';
|
|
3
|
-
import
|
|
4
|
-
export { gg, fg, bg, openInEditorPlugin,
|
|
3
|
+
import ggCallSitesPlugin from './gg-call-sites-plugin.js';
|
|
4
|
+
export { gg, fg, bg, openInEditorPlugin, ggCallSitesPlugin };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Reexport your entry components here
|
|
2
2
|
import { gg, fg, bg } from './gg.js';
|
|
3
3
|
import openInEditorPlugin from './open-in-editor.js';
|
|
4
|
-
import
|
|
5
|
-
export { gg, fg, bg, openInEditorPlugin,
|
|
4
|
+
import ggCallSitesPlugin from './gg-call-sites-plugin.js';
|
|
5
|
+
export { gg, fg, bg, openInEditorPlugin, ggCallSitesPlugin };
|