extension 3.2.0-next.3 → 3.2.0-next.6

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.
@@ -12,6 +12,7 @@ export declare class Telemetry {
12
12
  private disabled;
13
13
  private apiKey?;
14
14
  private host?;
15
+ private storage;
15
16
  private buffer;
16
17
  private timer;
17
18
  constructor(init: TelemetryInit);
package/dist/cli.js CHANGED
@@ -361,30 +361,76 @@ function configDir() {
361
361
  if ('win32' === process.platform && process.env.APPDATA) return external_node_path_default().join(process.env.APPDATA, 'extensionjs');
362
362
  return external_node_path_default().join(external_node_os_default().homedir(), '.config', 'extensionjs');
363
363
  }
364
+ function telemetry_cacheDir() {
365
+ const xdg = process.env.XDG_CACHE_HOME;
366
+ if (xdg) return external_node_path_default().join(xdg, 'extensionjs');
367
+ if ('win32' === process.platform) {
368
+ const base = process.env.LOCALAPPDATA || process.env.APPDATA;
369
+ if (base) return external_node_path_default().join(base, 'extensionjs', 'Cache');
370
+ }
371
+ if ('darwin' === process.platform) return external_node_path_default().join(external_node_os_default().homedir(), 'Library', 'Caches', 'extensionjs');
372
+ return null;
373
+ }
364
374
  function ensureDir(p) {
365
- if (external_node_fs_default().existsSync(p)) return;
366
- external_node_fs_default().mkdirSync(p, {
367
- recursive: true
368
- });
375
+ try {
376
+ if (external_node_fs_default().existsSync(p)) return true;
377
+ external_node_fs_default().mkdirSync(p, {
378
+ recursive: true
379
+ });
380
+ return true;
381
+ } catch {
382
+ return false;
383
+ }
384
+ }
385
+ function ensureWritableDir(p) {
386
+ if (!ensureDir(p)) return false;
387
+ try {
388
+ external_node_fs_default().accessSync(p, external_node_fs_default().constants.W_OK);
389
+ const probe = external_node_path_default().join(p, `.write-test-${process.pid}-${Date.now()}`);
390
+ external_node_fs_default().writeFileSync(probe, 'ok', 'utf8');
391
+ external_node_fs_default().unlinkSync(probe);
392
+ return true;
393
+ } catch {
394
+ return false;
395
+ }
369
396
  }
370
397
  function loadOrCreateId(file) {
371
- if (external_node_fs_default().existsSync(file)) return external_node_fs_default().readFileSync(file, 'utf8').trim();
398
+ try {
399
+ if (external_node_fs_default().existsSync(file)) return external_node_fs_default().readFileSync(file, 'utf8').trim();
400
+ } catch {}
372
401
  const id = external_node_crypto_default().randomUUID();
373
- ensureDir(external_node_path_default().dirname(file));
374
- external_node_fs_default().writeFileSync(file, id, 'utf8');
402
+ if (ensureDir(external_node_path_default().dirname(file))) try {
403
+ external_node_fs_default().writeFileSync(file, id, 'utf8');
404
+ } catch {}
375
405
  return id;
376
406
  }
377
- function auditFilePath() {
378
- const dir = external_node_path_default().join(configDir(), 'telemetry');
379
- ensureDir(dir);
380
- return external_node_path_default().join(dir, 'events.jsonl');
407
+ function telemetryCandidates() {
408
+ const candidates = [
409
+ configDir(),
410
+ telemetry_cacheDir(),
411
+ external_node_path_default().join(external_node_os_default().tmpdir(), 'extensionjs'),
412
+ external_node_path_default().join(process.cwd(), '.cache', 'extensionjs')
413
+ ].filter(Boolean);
414
+ return Array.from(new Set(candidates));
415
+ }
416
+ function resolveTelemetryStorage() {
417
+ for (const base of telemetryCandidates()){
418
+ const telemetryDir = external_node_path_default().join(base, 'telemetry');
419
+ if (ensureWritableDir(telemetryDir)) return {
420
+ telemetryDir,
421
+ auditFile: external_node_path_default().join(telemetryDir, 'events.jsonl'),
422
+ idFile: external_node_path_default().join(telemetryDir, 'anonymous-id'),
423
+ consentFile: external_node_path_default().join(telemetryDir, 'consent')
424
+ };
425
+ }
426
+ return null;
381
427
  }
382
428
  const DEFAULT_FLUSH_AT = Number(process.env.EXTENSION_TELEMETRY_FLUSH_AT || 10);
383
429
  const DEFAULT_FLUSH_INTERVAL = Number(process.env.EXTENSION_TELEMETRY_FLUSH_INTERVAL || 2000);
384
430
  const DEFAULT_TIMEOUT_MS = Number(process.env.EXTENSION_TELEMETRY_TIMEOUT_MS || 200);
385
431
  class Telemetry {
386
432
  track(event, props = {}) {
387
- if (this.disabled) return;
433
+ if (this.disabled || !this.storage) return;
388
434
  const payload = {
389
435
  event,
390
436
  properties: {
@@ -394,7 +440,12 @@ class Telemetry {
394
440
  },
395
441
  distinct_id: this.anonId
396
442
  };
397
- external_node_fs_default().appendFileSync(auditFilePath(), JSON.stringify(payload) + '\n');
443
+ try {
444
+ external_node_fs_default().appendFileSync(this.storage.auditFile, JSON.stringify(payload) + '\n');
445
+ } catch {
446
+ this.disabled = true;
447
+ return;
448
+ }
398
449
  if (this.debug) console.error('[telemetry]', JSON.stringify(payload));
399
450
  if (!this.apiKey || !this.host) return;
400
451
  this.buffer.push(payload);
@@ -439,14 +490,16 @@ class Telemetry {
439
490
  _define_property(this, "disabled", void 0);
440
491
  _define_property(this, "apiKey", void 0);
441
492
  _define_property(this, "host", void 0);
493
+ _define_property(this, "storage", null);
442
494
  _define_property(this, "buffer", []);
443
495
  _define_property(this, "timer", null);
444
496
  this.debug = '1' === process.env.EXTENSION_TELEMETRY_DEBUG;
445
497
  this.disabled = Boolean(init.disabled);
446
498
  this.anonId = 'disabled';
447
499
  if (!this.disabled) {
448
- const idFile = external_node_path_default().join(configDir(), 'telemetry', 'anonymous-id');
449
- this.anonId = loadOrCreateId(idFile);
500
+ this.storage = resolveTelemetryStorage();
501
+ if (this.storage) this.anonId = loadOrCreateId(this.storage.idFile);
502
+ else this.disabled = true;
450
503
  }
451
504
  this.common = {
452
505
  app: init.app,
@@ -459,15 +512,17 @@ class Telemetry {
459
512
  };
460
513
  this.apiKey = init.apiKey || process.env.EXTENSION_PUBLIC_POSTHOG_KEY;
461
514
  this.host = init.host || process.env.EXTENSION_PUBLIC_POSTHOG_HOST;
462
- if (!this.disabled) {
463
- const consentPath = external_node_path_default().join(configDir(), 'telemetry', 'consent');
464
- if (!external_node_fs_default().existsSync(consentPath)) {
465
- external_node_fs_default().writeFileSync(consentPath, 'ok', 'utf8');
466
- this.track('cli_telemetry_consent', {
467
- value: 'implicit_opt_in'
468
- });
469
- console.log(`${external_pintor_default().gray('►►►')} Telemetry is enabled for Extension.js. To opt out, run with --no-telemetry. Learn more in TELEMETRY.md.`);
470
- }
515
+ if (!this.disabled && this.storage) {
516
+ const consentPath = this.storage.consentFile;
517
+ try {
518
+ if (!external_node_fs_default().existsSync(consentPath)) {
519
+ external_node_fs_default().writeFileSync(consentPath, 'ok', 'utf8');
520
+ this.track('cli_telemetry_consent', {
521
+ value: 'implicit_opt_in'
522
+ });
523
+ console.log(`${external_pintor_default().gray('►►►')} Telemetry is enabled for Extension.js. To opt out, run with --no-telemetry. Learn more in TELEMETRY.md.`);
524
+ }
525
+ } catch {}
471
526
  }
472
527
  }
473
528
  }
package/package.json CHANGED
@@ -35,7 +35,7 @@
35
35
  "extension": "./dist/cli.js"
36
36
  },
37
37
  "name": "extension",
38
- "version": "3.2.0-next.3",
38
+ "version": "3.2.0-next.6",
39
39
  "description": "Create cross-browser extensions with no build configuration.",
40
40
  "homepage": "https://extension.js.org/",
41
41
  "bugs": {
@@ -51,6 +51,7 @@
51
51
  "registry": "https://registry.npmjs.org"
52
52
  },
53
53
  "scripts": {
54
+ "pretest": "pnpm run compile",
54
55
  "prepublishOnly": "pnpm run compile",
55
56
  "compile": "rslib build",
56
57
  "watch": "rslib build --watch",
@@ -88,8 +89,8 @@
88
89
  "cli"
89
90
  ],
90
91
  "dependencies": {
91
- "extension-create": "^3.2.0-next.3",
92
- "extension-develop": "^3.2.0-next.3",
92
+ "extension-create": "^3.2.0-next.6",
93
+ "extension-develop": "^3.2.0-next.6",
93
94
  "commander": "^14.0.2",
94
95
  "pintor": "0.3.0",
95
96
  "semver": "^7.7.3",