trickle-observe 0.2.72 → 0.2.73

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.
@@ -1315,31 +1315,24 @@ function transformEsmSource(source, filename, moduleName, backendUrl, debug, tra
1315
1315
  }
1316
1316
  // Build prefix — ALL imports first (ESM requires imports before any statements)
1317
1317
  const needsTracing = varInsertions.length > 0 || destructInsertions.length > 0 || reassignInsertions.length > 0 || forLoopInsertions.length > 0 || catchInsertions.length > 0 || funcParamInsertions.length > 0 || bodyInsertions.length > 0 || hookInsertions.length > 0 || stateInsertions.length > 0 || conciseBodyInsertions.length > 0;
1318
- const importLines = [
1319
- `import { wrapFunction as __trickle_wrapFn, configure as __trickle_configure } from 'trickle-observe';`,
1320
- ];
1321
- if (needsTracing && isSSR) {
1322
- // SSR/Node.js — use file system for writing
1323
- importLines.push(`import { mkdirSync as __trickle_mkdirSync, appendFileSync as __trickle_appendFileSync } from 'node:fs';`, `import { join as __trickle_join } from 'node:path';`);
1318
+ const importLines = [];
1319
+ if (isSSR) {
1320
+ // SSR/Node.js — import trickle-observe for function wrapping + file system for writing
1321
+ importLines.push(`import { wrapFunction as __trickle_wrapFn, configure as __trickle_configure } from 'trickle-observe';`);
1322
+ if (needsTracing) {
1323
+ importLines.push(`import { mkdirSync as __trickle_mkdirSync, appendFileSync as __trickle_appendFileSync } from 'node:fs';`, `import { join as __trickle_join } from 'node:path';`);
1324
+ }
1325
+ }
1326
+ // Browser mode: no imports needed — variable tracers are self-contained,
1327
+ // function wrapping is a no-op, and transport uses import.meta.hot
1328
+ const prefixLines = [...importLines];
1329
+ if (isSSR) {
1330
+ prefixLines.push(`__trickle_configure({ backendUrl: ${JSON.stringify(backendUrl)}, batchIntervalMs: 2000, debug: ${debug}, enabled: true, environment: 'node' });`, `function __trickle_wrap(fn, name, paramNames) {`, ` const opts = {`, ` functionName: name,`, ` module: ${JSON.stringify(moduleName)},`, ` trackArgs: true,`, ` trackReturn: true,`, ` sampleRate: 1,`, ` maxDepth: 5,`, ` environment: 'node',`, ` enabled: true,`, ` };`, ` if (paramNames && paramNames.length) opts.paramNames = paramNames;`, ` return __trickle_wrapFn(fn, opts);`, `}`);
1331
+ }
1332
+ else {
1333
+ // Browser mode: __trickle_wrap is a no-op (function wrapping uses Node.js APIs)
1334
+ prefixLines.push(`function __trickle_wrap(fn) { return fn; }`);
1324
1335
  }
1325
- const prefixLines = [
1326
- ...importLines,
1327
- `__trickle_configure({ backendUrl: ${JSON.stringify(backendUrl)}, batchIntervalMs: 2000, debug: ${debug}, enabled: true, environment: 'node' });`,
1328
- `function __trickle_wrap(fn, name, paramNames) {`,
1329
- ` const opts = {`,
1330
- ` functionName: name,`,
1331
- ` module: ${JSON.stringify(moduleName)},`,
1332
- ` trackArgs: true,`,
1333
- ` trackReturn: true,`,
1334
- ` sampleRate: 1,`,
1335
- ` maxDepth: 5,`,
1336
- ` environment: 'node',`,
1337
- ` enabled: true,`,
1338
- ` };`,
1339
- ` if (paramNames && paramNames.length) opts.paramNames = paramNames;`,
1340
- ` return __trickle_wrapFn(fn, opts);`,
1341
- `}`,
1342
- ];
1343
1336
  // Add unified __trickle_send() transport — browser uses HMR WebSocket, SSR uses fs
1344
1337
  if (needsTracing) {
1345
1338
  if (isSSR) {
@@ -1308,31 +1308,24 @@ export function transformEsmSource(source, filename, moduleName, backendUrl, deb
1308
1308
  }
1309
1309
  // Build prefix — ALL imports first (ESM requires imports before any statements)
1310
1310
  const needsTracing = varInsertions.length > 0 || destructInsertions.length > 0 || reassignInsertions.length > 0 || forLoopInsertions.length > 0 || catchInsertions.length > 0 || funcParamInsertions.length > 0 || bodyInsertions.length > 0 || hookInsertions.length > 0 || stateInsertions.length > 0 || conciseBodyInsertions.length > 0;
1311
- const importLines = [
1312
- `import { wrapFunction as __trickle_wrapFn, configure as __trickle_configure } from 'trickle-observe';`,
1313
- ];
1314
- if (needsTracing && isSSR) {
1315
- // SSR/Node.js — use file system for writing
1316
- importLines.push(`import { mkdirSync as __trickle_mkdirSync, appendFileSync as __trickle_appendFileSync } from 'node:fs';`, `import { join as __trickle_join } from 'node:path';`);
1311
+ const importLines = [];
1312
+ if (isSSR) {
1313
+ // SSR/Node.js — import trickle-observe for function wrapping + file system for writing
1314
+ importLines.push(`import { wrapFunction as __trickle_wrapFn, configure as __trickle_configure } from 'trickle-observe';`);
1315
+ if (needsTracing) {
1316
+ importLines.push(`import { mkdirSync as __trickle_mkdirSync, appendFileSync as __trickle_appendFileSync } from 'node:fs';`, `import { join as __trickle_join } from 'node:path';`);
1317
+ }
1318
+ }
1319
+ // Browser mode: no imports needed — variable tracers are self-contained,
1320
+ // function wrapping is a no-op, and transport uses import.meta.hot
1321
+ const prefixLines = [...importLines];
1322
+ if (isSSR) {
1323
+ prefixLines.push(`__trickle_configure({ backendUrl: ${JSON.stringify(backendUrl)}, batchIntervalMs: 2000, debug: ${debug}, enabled: true, environment: 'node' });`, `function __trickle_wrap(fn, name, paramNames) {`, ` const opts = {`, ` functionName: name,`, ` module: ${JSON.stringify(moduleName)},`, ` trackArgs: true,`, ` trackReturn: true,`, ` sampleRate: 1,`, ` maxDepth: 5,`, ` environment: 'node',`, ` enabled: true,`, ` };`, ` if (paramNames && paramNames.length) opts.paramNames = paramNames;`, ` return __trickle_wrapFn(fn, opts);`, `}`);
1324
+ }
1325
+ else {
1326
+ // Browser mode: __trickle_wrap is a no-op (function wrapping uses Node.js APIs)
1327
+ prefixLines.push(`function __trickle_wrap(fn) { return fn; }`);
1317
1328
  }
1318
- const prefixLines = [
1319
- ...importLines,
1320
- `__trickle_configure({ backendUrl: ${JSON.stringify(backendUrl)}, batchIntervalMs: 2000, debug: ${debug}, enabled: true, environment: 'node' });`,
1321
- `function __trickle_wrap(fn, name, paramNames) {`,
1322
- ` const opts = {`,
1323
- ` functionName: name,`,
1324
- ` module: ${JSON.stringify(moduleName)},`,
1325
- ` trackArgs: true,`,
1326
- ` trackReturn: true,`,
1327
- ` sampleRate: 1,`,
1328
- ` maxDepth: 5,`,
1329
- ` environment: 'node',`,
1330
- ` enabled: true,`,
1331
- ` };`,
1332
- ` if (paramNames && paramNames.length) opts.paramNames = paramNames;`,
1333
- ` return __trickle_wrapFn(fn, opts);`,
1334
- `}`,
1335
- ];
1336
1329
  // Add unified __trickle_send() transport — browser uses HMR WebSocket, SSR uses fs
1337
1330
  if (needsTracing) {
1338
1331
  if (isSSR) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trickle-observe",
3
- "version": "0.2.72",
3
+ "version": "0.2.73",
4
4
  "description": "Runtime type observability for JavaScript applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1309,35 +1309,49 @@ export function transformEsmSource(
1309
1309
 
1310
1310
  // Build prefix — ALL imports first (ESM requires imports before any statements)
1311
1311
  const needsTracing = varInsertions.length > 0 || destructInsertions.length > 0 || reassignInsertions.length > 0 || forLoopInsertions.length > 0 || catchInsertions.length > 0 || funcParamInsertions.length > 0 || bodyInsertions.length > 0 || hookInsertions.length > 0 || stateInsertions.length > 0 || conciseBodyInsertions.length > 0;
1312
- const importLines: string[] = [
1313
- `import { wrapFunction as __trickle_wrapFn, configure as __trickle_configure } from 'trickle-observe';`,
1314
- ];
1315
- if (needsTracing && isSSR) {
1316
- // SSR/Node.js — use file system for writing
1312
+ const importLines: string[] = [];
1313
+
1314
+ if (isSSR) {
1315
+ // SSR/Node.js import trickle-observe for function wrapping + file system for writing
1317
1316
  importLines.push(
1318
- `import { mkdirSync as __trickle_mkdirSync, appendFileSync as __trickle_appendFileSync } from 'node:fs';`,
1319
- `import { join as __trickle_join } from 'node:path';`,
1317
+ `import { wrapFunction as __trickle_wrapFn, configure as __trickle_configure } from 'trickle-observe';`,
1320
1318
  );
1319
+ if (needsTracing) {
1320
+ importLines.push(
1321
+ `import { mkdirSync as __trickle_mkdirSync, appendFileSync as __trickle_appendFileSync } from 'node:fs';`,
1322
+ `import { join as __trickle_join } from 'node:path';`,
1323
+ );
1324
+ }
1321
1325
  }
1326
+ // Browser mode: no imports needed — variable tracers are self-contained,
1327
+ // function wrapping is a no-op, and transport uses import.meta.hot
1322
1328
 
1323
- const prefixLines = [
1324
- ...importLines,
1325
- `__trickle_configure({ backendUrl: ${JSON.stringify(backendUrl)}, batchIntervalMs: 2000, debug: ${debug}, enabled: true, environment: 'node' });`,
1326
- `function __trickle_wrap(fn, name, paramNames) {`,
1327
- ` const opts = {`,
1328
- ` functionName: name,`,
1329
- ` module: ${JSON.stringify(moduleName)},`,
1330
- ` trackArgs: true,`,
1331
- ` trackReturn: true,`,
1332
- ` sampleRate: 1,`,
1333
- ` maxDepth: 5,`,
1334
- ` environment: 'node',`,
1335
- ` enabled: true,`,
1336
- ` };`,
1337
- ` if (paramNames && paramNames.length) opts.paramNames = paramNames;`,
1338
- ` return __trickle_wrapFn(fn, opts);`,
1339
- `}`,
1340
- ];
1329
+ const prefixLines = [...importLines];
1330
+
1331
+ if (isSSR) {
1332
+ prefixLines.push(
1333
+ `__trickle_configure({ backendUrl: ${JSON.stringify(backendUrl)}, batchIntervalMs: 2000, debug: ${debug}, enabled: true, environment: 'node' });`,
1334
+ `function __trickle_wrap(fn, name, paramNames) {`,
1335
+ ` const opts = {`,
1336
+ ` functionName: name,`,
1337
+ ` module: ${JSON.stringify(moduleName)},`,
1338
+ ` trackArgs: true,`,
1339
+ ` trackReturn: true,`,
1340
+ ` sampleRate: 1,`,
1341
+ ` maxDepth: 5,`,
1342
+ ` environment: 'node',`,
1343
+ ` enabled: true,`,
1344
+ ` };`,
1345
+ ` if (paramNames && paramNames.length) opts.paramNames = paramNames;`,
1346
+ ` return __trickle_wrapFn(fn, opts);`,
1347
+ `}`,
1348
+ );
1349
+ } else {
1350
+ // Browser mode: __trickle_wrap is a no-op (function wrapping uses Node.js APIs)
1351
+ prefixLines.push(
1352
+ `function __trickle_wrap(fn) { return fn; }`,
1353
+ );
1354
+ }
1341
1355
 
1342
1356
  // Add unified __trickle_send() transport — browser uses HMR WebSocket, SSR uses fs
1343
1357
  if (needsTracing) {