@glasstrace/sdk 1.1.1 → 1.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.
Files changed (46) hide show
  1. package/README.md +78 -1
  2. package/dist/{chunk-DIM4JRXM.js → chunk-2M57EO6U.js} +2 -2
  3. package/dist/{chunk-P22UQ2OJ.js → chunk-3LILTM3T.js} +1 -1
  4. package/dist/chunk-3LILTM3T.js.map +1 -0
  5. package/dist/{chunk-MXDZHFJQ.js → chunk-C567H5EQ.js} +2 -2
  6. package/dist/{chunk-7SZQN6IU.js → chunk-NB7GJE4S.js} +2 -2
  7. package/dist/chunk-NB7GJE4S.js.map +1 -0
  8. package/dist/{chunk-ZRDQ6ZKI.js → chunk-UJ2JC7PZ.js} +92 -473
  9. package/dist/chunk-UJ2JC7PZ.js.map +1 -0
  10. package/dist/{chunk-Y26HJUPD.js → chunk-Z35HKVSO.js} +135 -8
  11. package/dist/chunk-Z35HKVSO.js.map +1 -0
  12. package/dist/cli/init.cjs +463 -440
  13. package/dist/cli/init.cjs.map +1 -1
  14. package/dist/cli/init.js +434 -63
  15. package/dist/cli/init.js.map +1 -1
  16. package/dist/cli/mcp-add.cjs +14 -2
  17. package/dist/cli/mcp-add.cjs.map +1 -1
  18. package/dist/cli/mcp-add.js +17 -5
  19. package/dist/cli/mcp-add.js.map +1 -1
  20. package/dist/cli/status.cjs.map +1 -1
  21. package/dist/cli/status.js +1 -3
  22. package/dist/cli/status.js.map +1 -1
  23. package/dist/cli/uninit.cjs +3 -3
  24. package/dist/cli/uninit.cjs.map +1 -1
  25. package/dist/cli/uninit.js +3 -3
  26. package/dist/cli/validate.cjs +14162 -2
  27. package/dist/cli/validate.cjs.map +1 -1
  28. package/dist/cli/validate.d.cts +7 -3
  29. package/dist/cli/validate.d.ts +7 -3
  30. package/dist/cli/validate.js +25 -2
  31. package/dist/cli/validate.js.map +1 -1
  32. package/dist/index.cjs +134 -5
  33. package/dist/index.cjs.map +1 -1
  34. package/dist/index.js +3 -3
  35. package/dist/{monorepo-GSL6JD3G.js → monorepo-PFVNPQ6X.js} +3 -5
  36. package/dist/node-entry.cjs +134 -5
  37. package/dist/node-entry.cjs.map +1 -1
  38. package/dist/node-entry.js +3 -3
  39. package/package.json +1 -1
  40. package/dist/chunk-7SZQN6IU.js.map +0 -1
  41. package/dist/chunk-P22UQ2OJ.js.map +0 -1
  42. package/dist/chunk-Y26HJUPD.js.map +0 -1
  43. package/dist/chunk-ZRDQ6ZKI.js.map +0 -1
  44. /package/dist/{chunk-DIM4JRXM.js.map → chunk-2M57EO6U.js.map} +0 -0
  45. /package/dist/{chunk-MXDZHFJQ.js.map → chunk-C567H5EQ.js.map} +0 -0
  46. /package/dist/{monorepo-GSL6JD3G.js.map → monorepo-PFVNPQ6X.js.map} +0 -0
@@ -1,426 +1,51 @@
1
- import {
2
- NEXT_CONFIG_NAMES
3
- } from "./chunk-7SZQN6IU.js";
4
1
  import {
5
2
  isDevApiKey,
6
3
  readEnvLocalApiKey
7
- } from "./chunk-P22UQ2OJ.js";
4
+ } from "./chunk-3LILTM3T.js";
8
5
  import {
9
6
  AnonApiKeySchema
10
7
  } from "./chunk-X5MAXP5T.js";
8
+ import {
9
+ NEXT_CONFIG_NAMES
10
+ } from "./chunk-NB7GJE4S.js";
11
11
 
12
12
  // src/cli/uninit.ts
13
- import * as fs3 from "node:fs";
13
+ import * as fs2 from "node:fs";
14
14
  import * as os from "node:os";
15
- import * as path3 from "node:path";
15
+ import * as path2 from "node:path";
16
16
 
17
- // src/cli/scaffolder.ts
17
+ // src/cli/discovery-file.ts
18
18
  import * as fs from "node:fs";
19
19
  import * as path from "node:path";
20
- function hasRegisterGlasstraceCall(content) {
21
- return content.split("\n").some((line) => {
22
- const uncommented = line.replace(/\/\/.*$/, "");
23
- return /\bregisterGlasstrace\s*\(/.test(uncommented);
24
- });
25
- }
26
- function injectRegisterGlasstrace(content) {
27
- if (hasRegisterGlasstraceCall(content)) {
28
- return { injected: false, content };
29
- }
30
- const registerFnRegex = /export\s+(?:async\s+)?function\s+register\s*\([^)]*\)\s*\{/;
31
- const match = registerFnRegex.exec(content);
32
- if (!match) {
33
- return { injected: false, content };
34
- }
35
- const afterBrace = content.slice(match.index + match[0].length);
36
- const indentMatch = /\n([ \t]+)/.exec(afterBrace);
37
- const indent = indentMatch ? indentMatch[1] : " ";
38
- const importLine = 'import { registerGlasstrace } from "@glasstrace/sdk";\n';
39
- const hasGlasstraceImport = content.includes("@glasstrace/sdk");
40
- const insertPoint = match.index + match[0].length;
41
- const callInjection = `
42
- ${indent}// Glasstrace must be registered before other instrumentation
43
- ${indent}registerGlasstrace();
44
- `;
45
- let modified;
46
- if (hasGlasstraceImport) {
47
- const importRegex = /import\s*\{([^}]+)\}\s*from\s*["']@glasstrace\/sdk["']/;
48
- const importMatch = importRegex.exec(content);
49
- if (importMatch) {
50
- const specifiers = importMatch[1];
51
- const alreadyImported = specifiers.split(",").some((s) => s.trim() === "registerGlasstrace");
52
- if (alreadyImported) {
53
- modified = content.slice(0, insertPoint) + callInjection + content.slice(insertPoint);
54
- } else {
55
- const existingImports = specifiers.trimEnd();
56
- const separator = existingImports.endsWith(",") ? " " : ", ";
57
- const updatedImport = `import { ${existingImports.trim()}${separator}registerGlasstrace } from "@glasstrace/sdk"`;
58
- modified = content.replace(importMatch[0], updatedImport);
59
- const newMatch = registerFnRegex.exec(modified);
60
- if (newMatch) {
61
- const newInsertPoint = newMatch.index + newMatch[0].length;
62
- modified = modified.slice(0, newInsertPoint) + callInjection + modified.slice(newInsertPoint);
63
- }
64
- }
65
- } else {
66
- modified = importLine + content;
67
- const newMatch = registerFnRegex.exec(modified);
68
- if (newMatch) {
69
- const newInsertPoint = newMatch.index + newMatch[0].length;
70
- modified = modified.slice(0, newInsertPoint) + callInjection + modified.slice(newInsertPoint);
71
- }
72
- }
73
- } else {
74
- modified = importLine + content.slice(0, insertPoint) + callInjection + content.slice(insertPoint);
75
- }
76
- return { injected: true, content: modified };
77
- }
78
- var INSTRUMENTATION_FILENAMES = [
79
- "instrumentation.ts",
80
- "instrumentation.js",
81
- "instrumentation.mjs"
82
- ];
83
- function resolveInstrumentationTarget(projectRoot) {
84
- const rootExisting = [];
85
- const srcExisting = [];
86
- for (const name of INSTRUMENTATION_FILENAMES) {
87
- const rootPath = path.join(projectRoot, name);
88
- if (isRegularFile(rootPath)) {
89
- rootExisting.push(rootPath);
90
- }
91
- const srcPath = path.join(projectRoot, "src", name);
92
- if (isRegularFile(srcPath)) {
93
- srcExisting.push(srcPath);
94
- }
95
- }
96
- const existing = [...rootExisting, ...srcExisting];
97
- if (rootExisting.length > 0 && srcExisting.length > 0) {
98
- return {
99
- target: null,
100
- layout: null,
101
- existing,
102
- rootExisting,
103
- srcExisting,
104
- conflict: true
105
- };
106
- }
107
- if (srcExisting.length > 0) {
108
- return {
109
- target: srcExisting[0],
110
- layout: "src",
111
- existing,
112
- rootExisting,
113
- srcExisting,
114
- conflict: false
115
- };
116
- }
117
- if (rootExisting.length > 0) {
118
- return {
119
- target: rootExisting[0],
120
- layout: "root",
121
- existing,
122
- rootExisting,
123
- srcExisting,
124
- conflict: false
125
- };
126
- }
127
- const srcDir = path.join(projectRoot, "src");
128
- const layout = isDirectory(srcDir) ? "src" : "root";
129
- const target = layout === "src" ? path.join(projectRoot, "src", "instrumentation.ts") : path.join(projectRoot, "instrumentation.ts");
130
- return {
131
- target,
132
- layout,
133
- existing,
134
- rootExisting,
135
- srcExisting,
136
- conflict: false
137
- };
138
- }
139
- function isDirectory(p) {
140
- try {
141
- return fs.statSync(p).isDirectory();
142
- } catch {
143
- return false;
144
- }
145
- }
146
- function isRegularFile(p) {
147
- try {
148
- const stat = fs.lstatSync(p);
149
- if (stat.isSymbolicLink()) {
150
- return fs.statSync(p).isFile();
151
- }
152
- return stat.isFile();
153
- } catch {
154
- return false;
155
- }
156
- }
157
- function appendRegisterFunction(content) {
158
- const importLine = 'import { registerGlasstrace } from "@glasstrace/sdk";\n';
159
- const functionBlock = "\nexport async function register() {\n // Glasstrace must be registered before Prisma instrumentation\n // to ensure all ORM spans are captured correctly.\n // If you use @prisma/instrumentation, import it after this call.\n registerGlasstrace();\n}\n";
160
- let withImport = content;
161
- const hasGlasstraceImport = content.includes("@glasstrace/sdk");
162
- if (!hasGlasstraceImport) {
163
- withImport = importLine + content;
164
- } else {
165
- const importRegex = /import\s*\{([^}]+)\}\s*from\s*["']@glasstrace\/sdk["']/;
166
- const importMatch = importRegex.exec(content);
167
- if (importMatch) {
168
- const specifiers = importMatch[1];
169
- const alreadyImported = specifiers.split(",").some((s) => s.trim() === "registerGlasstrace");
170
- if (!alreadyImported) {
171
- const existingImports = specifiers.trimEnd();
172
- const separator = existingImports.endsWith(",") ? " " : ", ";
173
- const updatedImport = `import { ${existingImports.trim()}${separator}registerGlasstrace } from "@glasstrace/sdk"`;
174
- withImport = content.replace(importMatch[0], updatedImport);
175
- }
176
- } else {
177
- withImport = importLine + content;
178
- }
179
- }
180
- const trailingNewline = withImport.endsWith("\n") ? "" : "\n";
181
- return withImport + trailingNewline + functionBlock;
182
- }
183
- async function defaultInstrumentationPrompt(question, defaultValue) {
184
- if (!process.stdin.isTTY) return defaultValue;
185
- const readline = await import("node:readline");
186
- const rl = readline.createInterface({
187
- input: process.stdin,
188
- output: process.stdout
189
- });
190
- return new Promise((resolve) => {
191
- const suffix = defaultValue ? " [Y/n] " : " [y/N] ";
192
- rl.question(question + suffix, (answer) => {
193
- rl.close();
194
- const trimmed = answer.trim().toLowerCase();
195
- if (trimmed === "") {
196
- resolve(defaultValue);
197
- return;
198
- }
199
- resolve(trimmed === "y" || trimmed === "yes");
200
- });
201
- });
202
- }
203
- async function scaffoldInstrumentation(projectRoot, options = {}) {
204
- const target = resolveInstrumentationTarget(projectRoot);
205
- if (target.conflict) {
206
- return {
207
- action: "conflict",
208
- // Point the user at the `src/` variant — modern Next.js apps with a
209
- // `src/` directory load from there, so that's the merge target. The
210
- // competing path is reported separately for the error message.
211
- filePath: target.srcExisting[0],
212
- conflictingPath: target.rootExisting[0]
213
- };
214
- }
215
- const filePath = target.target;
216
- const layout = target.layout;
217
- if (filePath === null || layout === null) {
218
- return { action: "unrecognized" };
219
- }
220
- const force = options.force === true;
221
- const prompt = options.prompt ?? defaultInstrumentationPrompt;
222
- if (!fs.existsSync(filePath)) {
223
- const content = `import { registerGlasstrace } from "@glasstrace/sdk";
224
-
225
- export async function register() {
226
- // Glasstrace must be registered before Prisma instrumentation
227
- // to ensure all ORM spans are captured correctly.
228
- // If you use @prisma/instrumentation, import it after this call.
229
- registerGlasstrace();
230
- }
231
- `;
232
- fs.mkdirSync(path.dirname(filePath), { recursive: true });
233
- fs.writeFileSync(filePath, content, "utf-8");
234
- return { action: "created", filePath, layout };
235
- }
236
- const existing = fs.readFileSync(filePath, "utf-8");
237
- if (hasRegisterGlasstraceCall(existing)) {
238
- return { action: "already-registered", filePath, layout };
239
- }
240
- if (!force) {
241
- const approved = await prompt(
242
- `Merge registerGlasstrace() into ${path.relative(projectRoot, filePath)}?`,
243
- false
244
- );
245
- if (!approved) {
246
- return { action: "skipped", filePath, layout };
247
- }
248
- }
249
- const injectResult = injectRegisterGlasstrace(existing);
250
- if (injectResult.injected) {
251
- fs.writeFileSync(filePath, injectResult.content, "utf-8");
252
- return { action: "injected", filePath, layout };
253
- }
254
- const appended = appendRegisterFunction(existing);
255
- fs.writeFileSync(filePath, appended, "utf-8");
256
- return { action: "appended", filePath, layout };
257
- }
258
- async function scaffoldNextConfig(projectRoot) {
259
- let configPath;
260
- let configName;
261
- for (const name of NEXT_CONFIG_NAMES) {
262
- const candidate = path.join(projectRoot, name);
263
- if (fs.existsSync(candidate)) {
264
- configPath = candidate;
265
- configName = name;
266
- break;
267
- }
268
- }
269
- if (configPath === void 0 || configName === void 0) {
270
- return null;
271
- }
272
- const existing = fs.readFileSync(configPath, "utf-8");
273
- if (existing.trim().length === 0) {
274
- return { modified: false, reason: "empty-file" };
275
- }
276
- if (existing.includes("withGlasstraceConfig")) {
277
- return { modified: false, reason: "already-wrapped" };
278
- }
279
- const isESM = configName.endsWith(".ts") || configName.endsWith(".mjs");
280
- if (isESM) {
281
- const importLine = 'import { withGlasstraceConfig } from "@glasstrace/sdk";\n';
282
- const wrapResult2 = wrapExport(existing);
283
- if (!wrapResult2.wrapped) {
284
- return { modified: false, reason: "no-export" };
285
- }
286
- const modified2 = importLine + "\n" + wrapResult2.content;
287
- fs.writeFileSync(configPath, modified2, "utf-8");
288
- return { modified: true };
289
- }
290
- const requireLine = 'const { withGlasstraceConfig } = require("@glasstrace/sdk");\n';
291
- const wrapResult = wrapCJSExport(existing);
292
- if (!wrapResult.wrapped) {
293
- return { modified: false, reason: "no-export" };
294
- }
295
- const modified = requireLine + "\n" + wrapResult.content;
296
- fs.writeFileSync(configPath, modified, "utf-8");
297
- return { modified: true };
298
- }
299
- function wrapExport(content) {
300
- const marker = "export default";
301
- const idx = content.lastIndexOf(marker);
302
- if (idx === -1) {
303
- return { content, wrapped: false };
304
- }
305
- const preamble = content.slice(0, idx);
306
- const exprRaw = content.slice(idx + marker.length);
307
- const expr = exprRaw.trim().replace(/;?\s*$/, "");
308
- if (expr.length === 0) {
309
- return { content, wrapped: false };
310
- }
311
- return {
312
- content: preamble + `export default withGlasstraceConfig(${expr});
313
- `,
314
- wrapped: true
315
- };
316
- }
317
- function wrapCJSExport(content) {
318
- const cjsMarker = "module.exports";
319
- const cjsIdx = content.lastIndexOf(cjsMarker);
320
- if (cjsIdx === -1) {
321
- return { content, wrapped: false };
322
- }
323
- const preamble = content.slice(0, cjsIdx);
324
- const afterMarker = content.slice(cjsIdx + cjsMarker.length);
325
- const eqMatch = /^\s*=\s*/.exec(afterMarker);
326
- if (!eqMatch) {
327
- return { content, wrapped: false };
328
- }
329
- const exprRaw = afterMarker.slice(eqMatch[0].length);
330
- const expr = exprRaw.trim().replace(/;?\s*$/, "");
331
- if (expr.length === 0) {
332
- return { content, wrapped: false };
333
- }
334
- return {
335
- content: preamble + `module.exports = withGlasstraceConfig(${expr});
336
- `,
337
- wrapped: true
338
- };
339
- }
340
- async function scaffoldEnvLocal(projectRoot) {
341
- const filePath = path.join(projectRoot, ".env.local");
342
- if (fs.existsSync(filePath)) {
343
- const existing = fs.readFileSync(filePath, "utf-8");
344
- if (/^\s*#?\s*GLASSTRACE_API_KEY\s*=/m.test(existing)) {
345
- return false;
346
- }
347
- const separator = existing.endsWith("\n") ? "" : "\n";
348
- fs.writeFileSync(filePath, existing + separator + "# GLASSTRACE_API_KEY=your_key_here\n", "utf-8");
349
- return true;
350
- }
351
- fs.writeFileSync(filePath, "# GLASSTRACE_API_KEY=your_key_here\n", "utf-8");
352
- return true;
353
- }
354
- async function addCoverageMapEnv(projectRoot) {
355
- const filePath = path.join(projectRoot, ".env.local");
356
- if (!fs.existsSync(filePath)) {
357
- fs.writeFileSync(filePath, "GLASSTRACE_COVERAGE_MAP=true\n", "utf-8");
358
- return true;
359
- }
360
- const existing = fs.readFileSync(filePath, "utf-8");
361
- const keyRegex = /^(\s*GLASSTRACE_COVERAGE_MAP\s*=\s*)(.*)$/m;
362
- const keyMatch = keyRegex.exec(existing);
363
- if (keyMatch) {
364
- const currentValue = keyMatch[2].trim();
365
- if (currentValue === "true") {
366
- return false;
367
- }
368
- const updated = existing.replace(keyRegex, `${keyMatch[1]}true`);
369
- fs.writeFileSync(filePath, updated, "utf-8");
370
- return true;
371
- }
372
- const separator = existing.endsWith("\n") ? "" : "\n";
373
- fs.writeFileSync(filePath, existing + separator + "GLASSTRACE_COVERAGE_MAP=true\n", "utf-8");
374
- return true;
375
- }
376
- async function scaffoldGitignore(projectRoot) {
377
- const filePath = path.join(projectRoot, ".gitignore");
378
- if (fs.existsSync(filePath)) {
379
- const existing = fs.readFileSync(filePath, "utf-8");
380
- const lines = existing.split("\n").map((l) => l.trim());
381
- if (lines.includes(".glasstrace/")) {
382
- return false;
383
- }
384
- const separator = existing.endsWith("\n") ? "" : "\n";
385
- fs.writeFileSync(filePath, existing + separator + ".glasstrace/\n", "utf-8");
386
- return true;
387
- }
388
- fs.writeFileSync(filePath, ".glasstrace/\n", "utf-8");
389
- return true;
390
- }
391
-
392
- // src/cli/discovery-file.ts
393
- import * as fs2 from "node:fs";
394
- import * as path2 from "node:path";
395
20
  var WELL_KNOWN_GLASSTRACE_PATH = ".well-known/glasstrace.json";
396
21
  var DISCOVERY_FILE_VERSION = 1;
397
22
  function resolveStaticRoot(projectRoot) {
398
23
  if (isSvelteKitProject(projectRoot)) {
399
24
  return {
400
- absolutePath: path2.join(projectRoot, "static"),
25
+ absolutePath: path.join(projectRoot, "static"),
401
26
  layout: "static"
402
27
  };
403
28
  }
404
29
  return {
405
- absolutePath: path2.join(projectRoot, "public"),
30
+ absolutePath: path.join(projectRoot, "public"),
406
31
  layout: "public"
407
32
  };
408
33
  }
409
34
  function isSvelteKitProject(projectRoot) {
410
- const pkgPath = path2.join(projectRoot, "package.json");
35
+ const pkgPath = path.join(projectRoot, "package.json");
411
36
  let isEsm = false;
412
37
  try {
413
- const pkgContent = fs2.readFileSync(pkgPath, "utf-8");
38
+ const pkgContent = fs.readFileSync(pkgPath, "utf-8");
414
39
  const parsed = JSON.parse(pkgContent);
415
40
  isEsm = parsed.type === "module";
416
41
  } catch {
417
42
  return false;
418
43
  }
419
44
  if (!isEsm) return false;
420
- const svelteConfigJs = path2.join(projectRoot, "svelte.config.js");
421
- const svelteConfigTs = path2.join(projectRoot, "svelte.config.ts");
422
- const appHtml = path2.join(projectRoot, "src", "app.html");
423
- return fs2.existsSync(svelteConfigJs) || fs2.existsSync(svelteConfigTs) || fs2.existsSync(appHtml);
45
+ const svelteConfigJs = path.join(projectRoot, "svelte.config.js");
46
+ const svelteConfigTs = path.join(projectRoot, "svelte.config.ts");
47
+ const appHtml = path.join(projectRoot, "src", "app.html");
48
+ return fs.existsSync(svelteConfigJs) || fs.existsSync(svelteConfigTs) || fs.existsSync(appHtml);
424
49
  }
425
50
  function relativeDiscoveryPath(layout) {
426
51
  const rootDir = layout === "static" ? "static" : "public";
@@ -429,7 +54,7 @@ function relativeDiscoveryPath(layout) {
429
54
  function readExistingDiscoveryFile(filePath) {
430
55
  let raw;
431
56
  try {
432
- raw = fs2.readFileSync(filePath, "utf-8");
57
+ raw = fs.readFileSync(filePath, "utf-8");
433
58
  } catch {
434
59
  return null;
435
60
  }
@@ -468,11 +93,11 @@ function serializeDiscoveryPayload(key, extras) {
468
93
  }
469
94
  function writeDiscoveryFile(projectRoot, anonKey) {
470
95
  const { absolutePath: staticRoot, layout } = resolveStaticRoot(projectRoot);
471
- const wellKnownDir = path2.join(staticRoot, ".well-known");
472
- const filePath = path2.join(wellKnownDir, "glasstrace.json");
96
+ const wellKnownDir = path.join(staticRoot, ".well-known");
97
+ const filePath = path.join(wellKnownDir, "glasstrace.json");
473
98
  let existingAction;
474
99
  let extras = {};
475
- if (fs2.existsSync(filePath)) {
100
+ if (fs.existsSync(filePath)) {
476
101
  const existing = readExistingDiscoveryFile(filePath);
477
102
  if (existing === null) {
478
103
  existingAction = "skipped-foreign";
@@ -490,35 +115,35 @@ function writeDiscoveryFile(projectRoot, anonKey) {
490
115
  existingAction = "created";
491
116
  }
492
117
  const tmpPath = `${filePath}.tmp-${process.pid}`;
493
- const needsWindowsReplace = process.platform === "win32" && fs2.existsSync(filePath);
118
+ const needsWindowsReplace = process.platform === "win32" && fs.existsSync(filePath);
494
119
  const backupPath = needsWindowsReplace ? `${filePath}.bak-${process.pid}` : null;
495
120
  try {
496
- fs2.mkdirSync(wellKnownDir, { recursive: true });
121
+ fs.mkdirSync(wellKnownDir, { recursive: true });
497
122
  const payload = serializeDiscoveryPayload(anonKey, extras);
498
- fs2.writeFileSync(tmpPath, payload, { encoding: "utf-8" });
123
+ fs.writeFileSync(tmpPath, payload, { encoding: "utf-8" });
499
124
  if (backupPath !== null) {
500
- fs2.renameSync(filePath, backupPath);
125
+ fs.renameSync(filePath, backupPath);
501
126
  try {
502
- fs2.renameSync(tmpPath, filePath);
127
+ fs.renameSync(tmpPath, filePath);
503
128
  } catch (renameErr) {
504
129
  try {
505
- fs2.renameSync(backupPath, filePath);
130
+ fs.renameSync(backupPath, filePath);
506
131
  } catch {
507
132
  }
508
133
  throw renameErr;
509
134
  }
510
135
  try {
511
- fs2.unlinkSync(backupPath);
136
+ fs.unlinkSync(backupPath);
512
137
  } catch {
513
138
  }
514
139
  } else {
515
- fs2.renameSync(tmpPath, filePath);
140
+ fs.renameSync(tmpPath, filePath);
516
141
  }
517
142
  return { action: existingAction, filePath, layout };
518
143
  } catch (err) {
519
144
  try {
520
- if (fs2.existsSync(tmpPath)) {
521
- fs2.unlinkSync(tmpPath);
145
+ if (fs.existsSync(tmpPath)) {
146
+ fs.unlinkSync(tmpPath);
522
147
  }
523
148
  } catch {
524
149
  }
@@ -535,13 +160,13 @@ function removeDiscoveryFile(projectRoot) {
535
160
  const layouts = ["public", "static"];
536
161
  const outcomes = [];
537
162
  for (const layout of layouts) {
538
- const staticRoot = path2.join(projectRoot, layout);
539
- const wellKnownDir = path2.join(staticRoot, ".well-known");
540
- const filePath = path2.join(wellKnownDir, "glasstrace.json");
163
+ const staticRoot = path.join(projectRoot, layout);
164
+ const wellKnownDir = path.join(staticRoot, ".well-known");
165
+ const filePath = path.join(wellKnownDir, "glasstrace.json");
541
166
  let removed = false;
542
167
  try {
543
- if (fs2.existsSync(filePath)) {
544
- fs2.unlinkSync(filePath);
168
+ if (fs.existsSync(filePath)) {
169
+ fs.unlinkSync(filePath);
545
170
  removed = true;
546
171
  }
547
172
  } catch (err) {
@@ -556,10 +181,10 @@ function removeDiscoveryFile(projectRoot) {
556
181
  let directoryRemoved = false;
557
182
  if (removed) {
558
183
  try {
559
- if (fs2.existsSync(wellKnownDir)) {
560
- const entries = fs2.readdirSync(wellKnownDir);
184
+ if (fs.existsSync(wellKnownDir)) {
185
+ const entries = fs.readdirSync(wellKnownDir);
561
186
  if (entries.length === 0) {
562
- fs2.rmdirSync(wellKnownDir);
187
+ fs.rmdirSync(wellKnownDir);
563
188
  directoryRemoved = true;
564
189
  }
565
190
  }
@@ -892,24 +517,24 @@ function processTomlMcpConfig(content) {
892
517
  return { action: "removed-section", content: result + "\n" };
893
518
  }
894
519
  function writeShutdownMarker(projectRoot) {
895
- const dirPath = path3.join(projectRoot, ".glasstrace");
896
- if (!fs3.existsSync(dirPath)) {
520
+ const dirPath = path2.join(projectRoot, ".glasstrace");
521
+ if (!fs2.existsSync(dirPath)) {
897
522
  return false;
898
523
  }
899
- const markerPath = path3.join(dirPath, "shutdown-requested");
524
+ const markerPath = path2.join(dirPath, "shutdown-requested");
900
525
  const tmpPath = `${markerPath}.tmp`;
901
526
  const body = JSON.stringify({ requestedAt: (/* @__PURE__ */ new Date()).toISOString() });
902
527
  try {
903
- fs3.writeFileSync(tmpPath, body, { encoding: "utf-8", mode: 384 });
528
+ fs2.writeFileSync(tmpPath, body, { encoding: "utf-8", mode: 384 });
904
529
  try {
905
- fs3.chmodSync(tmpPath, 384);
530
+ fs2.chmodSync(tmpPath, 384);
906
531
  } catch {
907
532
  }
908
- fs3.renameSync(tmpPath, markerPath);
533
+ fs2.renameSync(tmpPath, markerPath);
909
534
  return true;
910
535
  } catch {
911
536
  try {
912
- fs3.unlinkSync(tmpPath);
537
+ fs2.unlinkSync(tmpPath);
913
538
  } catch {
914
539
  }
915
540
  return false;
@@ -950,8 +575,8 @@ async function runUninit(options) {
950
575
  summary.push("Wrote .glasstrace/shutdown-requested marker");
951
576
  }
952
577
  } else {
953
- const dirPath = path3.join(projectRoot, ".glasstrace");
954
- if (fs3.existsSync(dirPath)) {
578
+ const dirPath = path2.join(projectRoot, ".glasstrace");
579
+ if (fs2.existsSync(dirPath)) {
955
580
  summary.push(`${prefix}Would write .glasstrace/shutdown-requested marker`);
956
581
  }
957
582
  }
@@ -963,11 +588,11 @@ async function runUninit(options) {
963
588
  try {
964
589
  let configHandled = false;
965
590
  for (const name of NEXT_CONFIG_NAMES) {
966
- const configPath = path3.join(projectRoot, name);
967
- if (!fs3.existsSync(configPath)) {
591
+ const configPath = path2.join(projectRoot, name);
592
+ if (!fs2.existsSync(configPath)) {
968
593
  continue;
969
594
  }
970
- const content = fs3.readFileSync(configPath, "utf-8");
595
+ const content = fs2.readFileSync(configPath, "utf-8");
971
596
  if (!content.includes("withGlasstraceConfig")) {
972
597
  continue;
973
598
  }
@@ -977,7 +602,7 @@ async function runUninit(options) {
977
602
  const cleaned = removeGlasstraceConfigImport(unwrapResult.content);
978
603
  const final = cleanLeadingBlankLines(cleaned);
979
604
  if (!dryRun) {
980
- fs3.writeFileSync(configPath, final, "utf-8");
605
+ fs2.writeFileSync(configPath, final, "utf-8");
981
606
  }
982
607
  summary.push(`${prefix}Unwrapped withGlasstraceConfig from ${name}`);
983
608
  configHandled = true;
@@ -998,20 +623,20 @@ async function runUninit(options) {
998
623
  );
999
624
  }
1000
625
  try {
1001
- const instrPath = path3.join(projectRoot, "instrumentation.ts");
1002
- if (fs3.existsSync(instrPath)) {
1003
- const content = fs3.readFileSync(instrPath, "utf-8");
626
+ const instrPath = path2.join(projectRoot, "instrumentation.ts");
627
+ if (fs2.existsSync(instrPath)) {
628
+ const content = fs2.readFileSync(instrPath, "utf-8");
1004
629
  if (content.includes("registerGlasstrace") || content.includes("@glasstrace/sdk")) {
1005
630
  if (isInitCreatedInstrumentation(content)) {
1006
631
  if (!dryRun) {
1007
- fs3.unlinkSync(instrPath);
632
+ fs2.unlinkSync(instrPath);
1008
633
  }
1009
634
  summary.push(`${prefix}Deleted instrumentation.ts (init-created)`);
1010
635
  } else {
1011
636
  const cleaned = removeRegisterGlasstrace(content);
1012
637
  if (cleaned !== content) {
1013
638
  if (!dryRun) {
1014
- fs3.writeFileSync(instrPath, cleaned, "utf-8");
639
+ fs2.writeFileSync(instrPath, cleaned, "utf-8");
1015
640
  }
1016
641
  summary.push(
1017
642
  `${prefix}Removed registerGlasstrace() from instrumentation.ts`
@@ -1026,10 +651,10 @@ async function runUninit(options) {
1026
651
  );
1027
652
  }
1028
653
  try {
1029
- const glasstraceDir = path3.join(projectRoot, ".glasstrace");
1030
- if (fs3.existsSync(glasstraceDir)) {
654
+ const glasstraceDir = path2.join(projectRoot, ".glasstrace");
655
+ if (fs2.existsSync(glasstraceDir)) {
1031
656
  if (!dryRun) {
1032
- fs3.rmSync(glasstraceDir, { recursive: true, force: true });
657
+ fs2.rmSync(glasstraceDir, { recursive: true, force: true });
1033
658
  }
1034
659
  summary.push(`${prefix}Removed .glasstrace/ directory`);
1035
660
  }
@@ -1042,8 +667,8 @@ async function runUninit(options) {
1042
667
  if (dryRun) {
1043
668
  for (const previewLayout of ["public", "static"]) {
1044
669
  const relPath = relativeDiscoveryPath(previewLayout);
1045
- const absPath = path3.join(projectRoot, relPath);
1046
- if (fs3.existsSync(absPath)) {
670
+ const absPath = path2.join(projectRoot, relPath);
671
+ if (fs2.existsSync(absPath)) {
1047
672
  summary.push(`${prefix}Would remove ${relPath}`);
1048
673
  }
1049
674
  }
@@ -1068,9 +693,9 @@ async function runUninit(options) {
1068
693
  );
1069
694
  }
1070
695
  try {
1071
- const envPath = path3.join(projectRoot, ".env.local");
1072
- if (fs3.existsSync(envPath)) {
1073
- const content = fs3.readFileSync(envPath, "utf-8");
696
+ const envPath = path2.join(projectRoot, ".env.local");
697
+ if (fs2.existsSync(envPath)) {
698
+ const content = fs2.readFileSync(envPath, "utf-8");
1074
699
  const existingKey = readEnvLocalApiKey(content);
1075
700
  const hasDevKey = isDevApiKey(existingKey);
1076
701
  let proceed = true;
@@ -1103,12 +728,12 @@ async function runUninit(options) {
1103
728
  const result = filtered.join("\n");
1104
729
  if (result.trim().length === 0) {
1105
730
  if (!dryRun) {
1106
- fs3.unlinkSync(envPath);
731
+ fs2.unlinkSync(envPath);
1107
732
  }
1108
733
  summary.push(`${prefix}Deleted .env.local (no remaining entries)`);
1109
734
  } else {
1110
735
  if (!dryRun) {
1111
- fs3.writeFileSync(envPath, result, "utf-8");
736
+ fs2.writeFileSync(envPath, result, "utf-8");
1112
737
  }
1113
738
  let devKeyAnnotation = "";
1114
739
  if (devKeyPath === "interactive-confirmed") {
@@ -1131,9 +756,9 @@ async function runUninit(options) {
1131
756
  );
1132
757
  }
1133
758
  try {
1134
- const gitignorePath = path3.join(projectRoot, ".gitignore");
1135
- if (fs3.existsSync(gitignorePath)) {
1136
- const content = fs3.readFileSync(gitignorePath, "utf-8");
759
+ const gitignorePath = path2.join(projectRoot, ".gitignore");
760
+ if (fs2.existsSync(gitignorePath)) {
761
+ const content = fs2.readFileSync(gitignorePath, "utf-8");
1137
762
  const lines = content.split("\n");
1138
763
  const mcpGitignoreEntries = /* @__PURE__ */ new Set([
1139
764
  ".glasstrace/",
@@ -1149,12 +774,12 @@ async function runUninit(options) {
1149
774
  const result = filtered.join("\n");
1150
775
  if (result.trim().length === 0) {
1151
776
  if (!dryRun) {
1152
- fs3.unlinkSync(gitignorePath);
777
+ fs2.unlinkSync(gitignorePath);
1153
778
  }
1154
779
  summary.push(`${prefix}Deleted .gitignore (no remaining entries)`);
1155
780
  } else {
1156
781
  if (!dryRun) {
1157
- fs3.writeFileSync(gitignorePath, result, "utf-8");
782
+ fs2.writeFileSync(gitignorePath, result, "utf-8");
1158
783
  }
1159
784
  summary.push(`${prefix}Removed Glasstrace entries from .gitignore`);
1160
785
  }
@@ -1167,63 +792,63 @@ async function runUninit(options) {
1167
792
  }
1168
793
  try {
1169
794
  for (const configFile of MCP_CONFIG_FILES) {
1170
- const configPath = path3.join(projectRoot, configFile);
1171
- if (!fs3.existsSync(configPath)) {
795
+ const configPath = path2.join(projectRoot, configFile);
796
+ if (!fs2.existsSync(configPath)) {
1172
797
  continue;
1173
798
  }
1174
- const content = fs3.readFileSync(configPath, "utf-8");
799
+ const content = fs2.readFileSync(configPath, "utf-8");
1175
800
  const result = processJsonMcpConfig(content);
1176
801
  if (result.action === "deleted") {
1177
802
  if (!dryRun) {
1178
- fs3.unlinkSync(configPath);
803
+ fs2.unlinkSync(configPath);
1179
804
  }
1180
805
  summary.push(`${prefix}Deleted ${configFile}`);
1181
806
  } else if (result.action === "removed-key" && result.content !== void 0) {
1182
807
  if (!dryRun) {
1183
- fs3.writeFileSync(configPath, result.content, "utf-8");
808
+ fs2.writeFileSync(configPath, result.content, "utf-8");
1184
809
  }
1185
810
  summary.push(`${prefix}Removed glasstrace from ${configFile}`);
1186
811
  }
1187
812
  }
1188
- const codexConfigPath = path3.join(projectRoot, ".codex", "config.toml");
1189
- if (fs3.existsSync(codexConfigPath)) {
1190
- const content = fs3.readFileSync(codexConfigPath, "utf-8");
813
+ const codexConfigPath = path2.join(projectRoot, ".codex", "config.toml");
814
+ if (fs2.existsSync(codexConfigPath)) {
815
+ const content = fs2.readFileSync(codexConfigPath, "utf-8");
1191
816
  const tomlResult = processTomlMcpConfig(content);
1192
817
  if (tomlResult.action === "deleted") {
1193
818
  if (!dryRun) {
1194
- fs3.unlinkSync(codexConfigPath);
819
+ fs2.unlinkSync(codexConfigPath);
1195
820
  }
1196
821
  summary.push(`${prefix}Deleted .codex/config.toml`);
1197
822
  } else if (tomlResult.action === "removed-section" && tomlResult.content !== void 0) {
1198
823
  if (!dryRun) {
1199
- fs3.writeFileSync(codexConfigPath, tomlResult.content, "utf-8");
824
+ fs2.writeFileSync(codexConfigPath, tomlResult.content, "utf-8");
1200
825
  }
1201
826
  summary.push(`${prefix}Removed glasstrace from .codex/config.toml`);
1202
827
  }
1203
828
  }
1204
- const hasWindsurfMarkers = fs3.existsSync(path3.join(projectRoot, ".windsurfrules")) || fs3.existsSync(path3.join(projectRoot, ".windsurf"));
829
+ const hasWindsurfMarkers = fs2.existsSync(path2.join(projectRoot, ".windsurfrules")) || fs2.existsSync(path2.join(projectRoot, ".windsurf"));
1205
830
  if (hasWindsurfMarkers) {
1206
- const windsurfConfigPath = path3.join(
831
+ const windsurfConfigPath = path2.join(
1207
832
  os.homedir(),
1208
833
  ".codeium",
1209
834
  "windsurf",
1210
835
  "mcp_config.json"
1211
836
  );
1212
- if (fs3.existsSync(windsurfConfigPath)) {
1213
- const content = fs3.readFileSync(windsurfConfigPath, "utf-8");
837
+ if (fs2.existsSync(windsurfConfigPath)) {
838
+ const content = fs2.readFileSync(windsurfConfigPath, "utf-8");
1214
839
  const windsurfResult = processJsonMcpConfig(content);
1215
840
  const home = os.homedir();
1216
841
  const displayPath = windsurfConfigPath.startsWith(home) ? "~" + windsurfConfigPath.slice(home.length) : windsurfConfigPath;
1217
842
  if (windsurfResult.action === "deleted") {
1218
843
  if (!dryRun) {
1219
- fs3.unlinkSync(windsurfConfigPath);
844
+ fs2.unlinkSync(windsurfConfigPath);
1220
845
  }
1221
846
  summary.push(
1222
847
  `${prefix}Deleted global Windsurf config (${displayPath})`
1223
848
  );
1224
849
  } else if (windsurfResult.action === "removed-key" && windsurfResult.content !== void 0) {
1225
850
  if (!dryRun) {
1226
- fs3.writeFileSync(windsurfConfigPath, windsurfResult.content, "utf-8");
851
+ fs2.writeFileSync(windsurfConfigPath, windsurfResult.content, "utf-8");
1227
852
  }
1228
853
  summary.push(
1229
854
  `${prefix}Removed glasstrace from global Windsurf config (${displayPath})`
@@ -1238,21 +863,21 @@ async function runUninit(options) {
1238
863
  }
1239
864
  try {
1240
865
  for (const infoFile of AGENT_INFO_FILES) {
1241
- const filePath = path3.join(projectRoot, infoFile);
1242
- if (!fs3.existsSync(filePath)) {
866
+ const filePath = path2.join(projectRoot, infoFile);
867
+ if (!fs2.existsSync(filePath)) {
1243
868
  continue;
1244
869
  }
1245
- const content = fs3.readFileSync(filePath, "utf-8");
870
+ const content = fs2.readFileSync(filePath, "utf-8");
1246
871
  const result = removeMarkerSection(content);
1247
872
  if (result.removed) {
1248
873
  if (result.content.trim().length === 0) {
1249
874
  if (!dryRun) {
1250
- fs3.unlinkSync(filePath);
875
+ fs2.unlinkSync(filePath);
1251
876
  }
1252
877
  summary.push(`${prefix}Deleted ${infoFile} (only contained Glasstrace section)`);
1253
878
  } else {
1254
879
  if (!dryRun) {
1255
- fs3.writeFileSync(filePath, result.content, "utf-8");
880
+ fs2.writeFileSync(filePath, result.content, "utf-8");
1256
881
  }
1257
882
  summary.push(`${prefix}Removed Glasstrace section from ${infoFile}`);
1258
883
  }
@@ -1270,12 +895,6 @@ async function runUninit(options) {
1270
895
  }
1271
896
 
1272
897
  export {
1273
- resolveInstrumentationTarget,
1274
- scaffoldInstrumentation,
1275
- scaffoldNextConfig,
1276
- scaffoldEnvLocal,
1277
- addCoverageMapEnv,
1278
- scaffoldGitignore,
1279
898
  resolveStaticRoot,
1280
899
  relativeDiscoveryPath,
1281
900
  writeDiscoveryFile,
@@ -1294,4 +913,4 @@ export {
1294
913
  writeShutdownMarker,
1295
914
  runUninit
1296
915
  };
1297
- //# sourceMappingURL=chunk-ZRDQ6ZKI.js.map
916
+ //# sourceMappingURL=chunk-UJ2JC7PZ.js.map