@leftium/gg 0.0.19 → 0.0.20

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/dist/gg.js +27 -34
  2. package/package.json +1 -1
package/dist/gg.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import debugFactory from './debug.js';
2
2
  import ErrorStackParser from 'error-stack-parser';
3
- import { BROWSER } from 'esm-env';
3
+ import { BROWSER, DEV } from 'esm-env';
4
4
  // Helper to detect if we're running in CloudFlare Workers
5
5
  const isCloudflareWorker = () => {
6
6
  // Check for CloudFlare Workers-specific global
@@ -96,45 +96,38 @@ export function gg(...args) {
96
96
  if (!ggConfig.enabled || isCloudflareWorker()) {
97
97
  return args.length ? args[0] : { url: '', stack: [] };
98
98
  }
99
- // Ignore first stack frame, which is always the call to gg() itself.
100
- const stack = ErrorStackParser.parse(new Error()).splice(1);
101
- // Example: http://localhost:5173/src/routes/+page.svelte
102
- const filename = stack[0].fileName?.replace(timestampRegex, '') || '';
103
- // Example: src/routes/+page.svelte
104
- const filenameToOpen = filename.replace(srcRootRegex, '$<folderName>/');
105
- const url = openInEditorUrl(filenameToOpen);
106
- // Example: routes/+page.svelte
107
- let filenameToDisplay = filename.replace(srcRootRegex, '');
108
- // In production builds, simplify the built file paths for better readability
109
- // e.g., "_app/immutable/nodes/0.CY8nc6EF.js" -> "nodes/0"
110
- // e.g., ".svelte-kit/output/server/entries/pages/_layout.svelte.js" -> "pages/_layout"
111
- if (filenameToDisplay.includes('_app/immutable/')) {
112
- // Client-side production build
113
- filenameToDisplay = filenameToDisplay
114
- .replace(/.*\/_app\/immutable\//, '') // Remove path prefix
115
- .replace(/\.[a-zA-Z0-9]+\.js$/, ''); // Remove hash and .js
116
- }
117
- else if (filenameToDisplay.includes('.svelte-kit/output/')) {
118
- // Server-side production build
119
- filenameToDisplay = filenameToDisplay
120
- .replace(/.*\.svelte-kit\/output\/server\/entries\//, '') // Remove path prefix
121
- .replace(/\.svelte\.js$/, '') // Remove .svelte.js
122
- .replace(/\.js$/, ''); // Remove .js
123
- }
124
- const { functionName } = stack[0];
125
- //console.log({ filename, fileNameToOpen: filenameToOpen, fileNameToDisplay: filenameToDisplay });
126
- // A callpoint is uniquely identified by the filename plus function name
127
- const callpoint = `${filenameToDisplay}${functionName ? `@${functionName}` : ''}`;
128
- if (callpoint.length < 80 && callpoint.length > maxCallpointLength) {
129
- maxCallpointLength = callpoint.length;
99
+ // Initialize return values
100
+ let fileName = '';
101
+ let functionName = '';
102
+ let url = '';
103
+ let stack = [];
104
+ let namespace = 'gg:';
105
+ // In development: calculate detailed callpoint information
106
+ // In production: skip expensive stack parsing and use simple namespace
107
+ if (DEV) {
108
+ // Ignore first stack frame, which is always the call to gg() itself.
109
+ stack = ErrorStackParser.parse(new Error()).splice(1);
110
+ // Example: http://localhost:5173/src/routes/+page.svelte
111
+ const filename = stack[0].fileName?.replace(timestampRegex, '') || '';
112
+ // Example: src/routes/+page.svelte
113
+ const filenameToOpen = filename.replace(srcRootRegex, '$<folderName>/');
114
+ url = openInEditorUrl(filenameToOpen);
115
+ // Example: routes/+page.svelte
116
+ fileName = filename.replace(srcRootRegex, '');
117
+ functionName = stack[0].functionName || '';
118
+ // A callpoint is uniquely identified by the filename plus function name
119
+ const callpoint = `${fileName}${functionName ? `@${functionName}` : ''}`;
120
+ if (callpoint.length < 80 && callpoint.length > maxCallpointLength) {
121
+ maxCallpointLength = callpoint.length;
122
+ }
123
+ namespace = `gg:${callpoint.padEnd(maxCallpointLength, ' ')}${ggConfig.editorLink ? url : ''}`;
130
124
  }
131
- const namespace = `gg:${callpoint.padEnd(maxCallpointLength, ' ')}${ggConfig.editorLink ? url : ''}`;
132
125
  const ggLogFunction = namespaceToLogFunction.get(namespace) ||
133
126
  namespaceToLogFunction.set(namespace, debugFactory(namespace)).get(namespace);
134
127
  if (!args.length) {
135
128
  ggLogFunction(` 📝📝 ${url} 👀👀`);
136
129
  return {
137
- fileName: filenameToDisplay,
130
+ fileName,
138
131
  functionName,
139
132
  url,
140
133
  stack
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leftium/gg",
3
- "version": "0.0.19",
3
+ "version": "0.0.20",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/Leftium/gg.git"