extension 3.1.1 → 3.2.0-next.11

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.
package/dist/cli.js CHANGED
@@ -1,6 +1,20 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
- var __webpack_require__ = {};
3
+ var __webpack_modules__ = {
4
+ "extension-develop/package.json" (module) {
5
+ module.exports = require("extension-develop/package.json");
6
+ }
7
+ };
8
+ var __webpack_module_cache__ = {};
9
+ function __webpack_require__(moduleId) {
10
+ var cachedModule = __webpack_module_cache__[moduleId];
11
+ if (void 0 !== cachedModule) return cachedModule.exports;
12
+ var module = __webpack_module_cache__[moduleId] = {
13
+ exports: {}
14
+ };
15
+ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
16
+ return module.exports;
17
+ }
4
18
  (()=>{
5
19
  __webpack_require__.n = (module)=>{
6
20
  var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
@@ -22,66 +36,72 @@ var __webpack_require__ = {};
22
36
  __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
23
37
  })();
24
38
  var __webpack_exports__ = {};
25
- const external_commander_namespaceObject = require("commander");
26
- const external_update_check_namespaceObject = require("update-check");
27
- var external_update_check_default = /*#__PURE__*/ __webpack_require__.n(external_update_check_namespaceObject);
28
- const external_pintor_namespaceObject = require("pintor");
29
- var external_pintor_default = /*#__PURE__*/ __webpack_require__.n(external_pintor_namespaceObject);
30
- function getLoggingPrefix(type) {
31
- const isAuthor = 'true' === process.env.EXTENSION_AUTHOR_MODE;
32
- if (isAuthor) {
33
- const base = 'error' === type ? 'ERROR Author says' : '►►► Author says';
34
- return external_pintor_default().brightMagenta(base);
35
- }
36
- if ('error' === type) return external_pintor_default().red('ERROR');
37
- if ('warn' === type) return external_pintor_default().brightYellow('►►►');
38
- if ('info' === type) return external_pintor_default().gray('►►►');
39
- return external_pintor_default().green('►►►');
40
- }
41
- const code = (text)=>external_pintor_default().blue(text);
42
- const arg = (text)=>external_pintor_default().gray(text);
43
- const fmt = {
44
- heading: (title)=>external_pintor_default().underline(external_pintor_default().blue(title)),
45
- label: (k)=>external_pintor_default().gray(k.toUpperCase()),
46
- val: (v)=>external_pintor_default().underline(v),
47
- code: (v)=>external_pintor_default().blue(v),
48
- bullet: (s)=>`- ${s}`,
49
- block (title, rows) {
50
- const head = fmt.heading(title);
51
- const body = rows.map(([k, v])=>`${fmt.label(k)} ${v}`).join('\n');
52
- return `${head}\n${body}`;
53
- },
54
- truncate (input, max = 800) {
55
- const s = (()=>{
56
- try {
57
- return 'string' == typeof input ? input : JSON.stringify(input);
58
- } catch {
59
- return String(input);
60
- }
61
- })();
62
- return s.length > max ? s.slice(0, max) + '…' : s;
39
+ (()=>{
40
+ const external_commander_namespaceObject = require("commander");
41
+ const external_update_check_namespaceObject = require("update-check");
42
+ var external_update_check_default = /*#__PURE__*/ __webpack_require__.n(external_update_check_namespaceObject);
43
+ const external_pintor_namespaceObject = require("pintor");
44
+ var external_pintor_default = /*#__PURE__*/ __webpack_require__.n(external_pintor_namespaceObject);
45
+ function getLoggingPrefix(type) {
46
+ const isAuthor = 'true' === process.env.EXTENSION_AUTHOR_MODE;
47
+ if (isAuthor) {
48
+ const base = 'error' === type ? 'ERROR Author says' : '►►► Author says';
49
+ return external_pintor_default().brightMagenta(base);
50
+ }
51
+ if ('error' === type) return external_pintor_default().red('ERROR');
52
+ if ('warn' === type) return external_pintor_default().brightYellow('►►►');
53
+ if ('info' === type) return external_pintor_default().gray('►►►');
54
+ return external_pintor_default().green('►►►');
63
55
  }
64
- };
65
- const commandDescriptions = {
66
- create: 'Creates a new extension from a template (React, TypeScript, Vue, Svelte, etc.)',
67
- dev: 'Starts the development server with hot reloading',
68
- start: 'Builds and starts the extension in production mode',
69
- preview: 'Previews the extension in production mode without building',
70
- build: 'Builds the extension for packaging/distribution',
71
- cleanup: 'Cleans up orphaned instances and frees unused ports'
72
- };
73
- function unhandledError(err) {
74
- const message = err instanceof Error ? err.stack || err.message : 'string' == typeof err ? err : fmt.truncate(err);
75
- return `${getLoggingPrefix('error')} ${external_pintor_default().red(String(message || 'Unknown error'))}`;
76
- }
77
- function updateFailed(err) {
78
- return `${getLoggingPrefix('error')} Failed to check for updates.\n${external_pintor_default().red(String(err?.message || err))}`;
79
- }
80
- function checkUpdates(packageJson, update) {
81
- return `${getLoggingPrefix('info')} 🧩 ${external_pintor_default().blue('Extension.js')} update available.\n\nYou are currently using version ${external_pintor_default().red(String(packageJson.version))}. Latest stable is ${external_pintor_default().green(String(update.latest))}.\nUpdate to the latest stable to get fixes and new features.`;
82
- }
83
- function programUserHelp() {
84
- return `\n${getLoggingPrefix('info')} ${external_pintor_default().underline('Help center for the Extension.js program')}
56
+ const code = (text)=>external_pintor_default().blue(text);
57
+ const arg = (text)=>external_pintor_default().gray(text);
58
+ const fmt = {
59
+ heading: (title)=>external_pintor_default().underline(external_pintor_default().blue(title)),
60
+ label: (k)=>external_pintor_default().gray(k.toUpperCase()),
61
+ val: (v)=>external_pintor_default().underline(v),
62
+ code: (v)=>external_pintor_default().blue(v),
63
+ bullet: (s)=>`- ${s}`,
64
+ block (title, rows) {
65
+ const head = fmt.heading(title);
66
+ const body = rows.map(([k, v])=>`${fmt.label(k)} ${v}`).join('\n');
67
+ return `${head}\n${body}`;
68
+ },
69
+ truncate (input, max = 800) {
70
+ const s = (()=>{
71
+ try {
72
+ return 'string' == typeof input ? input : JSON.stringify(input);
73
+ } catch {
74
+ return String(input);
75
+ }
76
+ })();
77
+ return s.length > max ? s.slice(0, max) + '…' : s;
78
+ }
79
+ };
80
+ const commandDescriptions = {
81
+ create: 'Creates a new extension from a template (React, TypeScript, Vue, Svelte, etc.)',
82
+ dev: 'Starts the development server with hot reloading',
83
+ start: 'Builds and starts the extension in production mode',
84
+ preview: 'Previews the extension in production mode without building',
85
+ build: 'Builds the extension for packaging/distribution',
86
+ cleanup: 'Cleans up orphaned instances and frees unused ports'
87
+ };
88
+ function unhandledError(err) {
89
+ const message = err instanceof Error ? err.stack || err.message : 'string' == typeof err ? err : fmt.truncate(err);
90
+ return `${getLoggingPrefix('error')} ${external_pintor_default().red(String(message || 'Unknown error'))}`;
91
+ }
92
+ function updateFailed(err) {
93
+ return `${getLoggingPrefix('error')} Failed to check for updates.\n${external_pintor_default().red(String(err?.message || err))}`;
94
+ }
95
+ function checkUpdates(packageJson, update) {
96
+ const suffix = external_pintor_default().gray(`(version ${String(update.latest)} is available!)`);
97
+ const message = `${getLoggingPrefix('info')} 🧩 ${external_pintor_default().blue('Extension.js')} update available.\n\nYou are currently using version ${external_pintor_default().red(String(packageJson.version))}. Latest stable is ${external_pintor_default().green(String(update.latest))}.\nUpdate to the latest stable to get fixes and new features.`;
98
+ return {
99
+ suffix,
100
+ message
101
+ };
102
+ }
103
+ function programUserHelp() {
104
+ return `\n${getLoggingPrefix('info')} ${external_pintor_default().underline('Help center for the Extension.js program')}
85
105
 
86
106
  Usage: extension [command] [options]
87
107
 
@@ -159,12 +179,12 @@ AI Assistants
159
179
 
160
180
  Report issues
161
181
  - ${external_pintor_default().underline('https://github.com/cezaraugusto/extension/issues/new')}`;
162
- }
163
- function unsupportedBrowserFlag(value, supported) {
164
- return `${getLoggingPrefix('error')} Unsupported --browser value: ${value}. Supported: ${supported.join(', ')}.`;
165
- }
166
- function programAIHelp() {
167
- return `\n${getLoggingPrefix('info')} ${external_pintor_default().gray('Development tips for extension developers and AI assistants')}
182
+ }
183
+ function unsupportedBrowserFlag(value, supported) {
184
+ return `${getLoggingPrefix('error')} Unsupported --browser value: ${value}. Supported: ${supported.join(', ')}.`;
185
+ }
186
+ function programAIHelp() {
187
+ return `\n${getLoggingPrefix('info')} ${external_pintor_default().gray('Development tips for extension developers and AI assistants')}
168
188
 
169
189
  Browser-Specific Configuration
170
190
  - Use browser prefixes in manifest.json for browser-specific fields:
@@ -297,639 +317,703 @@ Cross-Browser Compatibility
297
317
  - Use ${code('--polyfill')} flag to enable webextension-polyfill
298
318
  - Automatically handles browser API differences
299
319
  - Supports Chrome, Edge, Firefox with single codebase`;
300
- }
301
- const external_semver_namespaceObject = require("semver");
302
- const external_node_fs_namespaceObject = require("node:fs");
303
- var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
304
- const external_node_path_namespaceObject = require("node:path");
305
- var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
306
- let cachedPackageJson = null;
307
- function getCliPackageJson() {
308
- if (cachedPackageJson) return cachedPackageJson;
309
- const candidates = [
310
- external_node_path_default().resolve(__dirname, 'package.json'),
311
- external_node_path_default().resolve(__dirname, '..', 'package.json')
312
- ];
313
- for (const candidate of candidates)if (external_node_fs_default().existsSync(candidate)) {
314
- const content = external_node_fs_default().readFileSync(candidate, 'utf8');
315
- const parsed = JSON.parse(content);
316
- cachedPackageJson = parsed;
317
- return parsed;
318
- }
319
- throw new Error('Extension.js CLI package.json not found.');
320
- }
321
- function isStableVersion(version) {
322
- const v = external_semver_namespaceObject.parse(version);
323
- return Boolean(v && 0 === v.prerelease.length);
324
- }
325
- async function check_updates_checkUpdates() {
326
- const packageJson = getCliPackageJson();
327
- let update = null;
328
- try {
329
- update = await external_update_check_default()(packageJson);
330
- } catch (err) {
331
- if ('true' === process.env.EXTENSION_AUTHOR_MODE) console.error(updateFailed(err));
332
- }
333
- if (update && isStableVersion(update.latest)) return checkUpdates(packageJson, update);
334
- return null;
335
- }
336
- const external_fs_namespaceObject = require("fs");
337
- var external_fs_default = /*#__PURE__*/ __webpack_require__.n(external_fs_namespaceObject);
338
- const external_path_namespaceObject = require("path");
339
- var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
340
- const external_node_os_namespaceObject = require("node:os");
341
- var external_node_os_default = /*#__PURE__*/ __webpack_require__.n(external_node_os_namespaceObject);
342
- const external_node_crypto_namespaceObject = require("node:crypto");
343
- var external_node_crypto_default = /*#__PURE__*/ __webpack_require__.n(external_node_crypto_namespaceObject);
344
- function _define_property(obj, key, value) {
345
- if (key in obj) Object.defineProperty(obj, key, {
346
- value: value,
347
- enumerable: true,
348
- configurable: true,
349
- writable: true
350
- });
351
- else obj[key] = value;
352
- return obj;
353
- }
354
- function isCI() {
355
- const v = process.env;
356
- return Boolean(v.CI || v.GITHUB_ACTIONS || v.GITLAB_CI || v.BUILDKITE || v.CIRCLECI || v.TRAVIS);
357
- }
358
- function configDir() {
359
- const xdg = process.env.XDG_CONFIG_HOME;
360
- if (xdg) return external_node_path_default().join(xdg, 'extensionjs');
361
- if ('win32' === process.platform && process.env.APPDATA) return external_node_path_default().join(process.env.APPDATA, 'extensionjs');
362
- return external_node_path_default().join(external_node_os_default().homedir(), '.config', 'extensionjs');
363
- }
364
- function ensureDir(p) {
365
- if (external_node_fs_default().existsSync(p)) return;
366
- external_node_fs_default().mkdirSync(p, {
367
- recursive: true
368
- });
369
- }
370
- function loadOrCreateId(file) {
371
- if (external_node_fs_default().existsSync(file)) return external_node_fs_default().readFileSync(file, 'utf8').trim();
372
- const id = external_node_crypto_default().randomUUID();
373
- ensureDir(external_node_path_default().dirname(file));
374
- external_node_fs_default().writeFileSync(file, id, 'utf8');
375
- return id;
376
- }
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');
381
- }
382
- const DEFAULT_FLUSH_AT = Number(process.env.EXTENSION_TELEMETRY_FLUSH_AT || 10);
383
- const DEFAULT_FLUSH_INTERVAL = Number(process.env.EXTENSION_TELEMETRY_FLUSH_INTERVAL || 2000);
384
- const DEFAULT_TIMEOUT_MS = Number(process.env.EXTENSION_TELEMETRY_TIMEOUT_MS || 200);
385
- class Telemetry {
386
- track(event, props = {}) {
387
- if (this.disabled) return;
388
- const payload = {
389
- event,
390
- properties: {
391
- ...this.common,
392
- ...props,
393
- $ip: null
394
- },
395
- distinct_id: this.anonId
396
- };
397
- external_node_fs_default().appendFileSync(auditFilePath(), JSON.stringify(payload) + '\n');
398
- if (this.debug) console.error('[telemetry]', JSON.stringify(payload));
399
- if (!this.apiKey || !this.host) return;
400
- this.buffer.push(payload);
401
- if (this.buffer.length >= DEFAULT_FLUSH_AT) return void this.flush();
402
- if (!this.timer) this.timer = setTimeout(()=>{
403
- this.timer = null;
404
- this.flush();
405
- }, DEFAULT_FLUSH_INTERVAL);
406
- }
407
- async flush() {
408
- if (this.disabled || !this.apiKey || !this.host) return;
409
- if (0 === this.buffer.length) return;
410
- const batch = this.buffer.splice(0, this.buffer.length);
411
- try {
412
- const ac = new AbortController();
413
- const t = setTimeout(()=>ac.abort(), DEFAULT_TIMEOUT_MS);
414
- const url = new URL('/capture/', this.host);
415
- await fetch(url.toString(), {
416
- method: 'POST',
417
- headers: {
418
- 'content-type': 'application/json'
419
- },
420
- body: JSON.stringify({
421
- api_key: this.apiKey,
422
- batch: batch.map((e)=>({
423
- event: e.event,
424
- properties: e.properties,
425
- distinct_id: e.distinct_id
426
- }))
427
- }),
428
- signal: ac.signal,
429
- keepalive: true
430
- }).catch(()=>{});
431
- clearTimeout(t);
432
- } catch {}
433
320
  }
434
- shutdown() {}
435
- constructor(init){
436
- _define_property(this, "anonId", void 0);
437
- _define_property(this, "common", void 0);
438
- _define_property(this, "debug", void 0);
439
- _define_property(this, "disabled", void 0);
440
- _define_property(this, "apiKey", void 0);
441
- _define_property(this, "host", void 0);
442
- _define_property(this, "buffer", []);
443
- _define_property(this, "timer", null);
444
- this.debug = '1' === process.env.EXTENSION_TELEMETRY_DEBUG;
445
- this.disabled = Boolean(init.disabled);
446
- this.anonId = 'disabled';
447
- if (!this.disabled) {
448
- const idFile = external_node_path_default().join(configDir(), 'telemetry', 'anonymous-id');
449
- this.anonId = loadOrCreateId(idFile);
321
+ const external_semver_namespaceObject = require("semver");
322
+ const external_node_fs_namespaceObject = require("node:fs");
323
+ var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
324
+ const external_node_path_namespaceObject = require("node:path");
325
+ var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
326
+ let cachedPackageJson = null;
327
+ function getCliPackageJson() {
328
+ if (cachedPackageJson) return cachedPackageJson;
329
+ const candidates = [
330
+ external_node_path_default().resolve(__dirname, 'package.json'),
331
+ external_node_path_default().resolve(__dirname, '..', 'package.json')
332
+ ];
333
+ for (const candidate of candidates)if (external_node_fs_default().existsSync(candidate)) {
334
+ const content = external_node_fs_default().readFileSync(candidate, 'utf8');
335
+ const parsed = JSON.parse(content);
336
+ cachedPackageJson = parsed;
337
+ return parsed;
450
338
  }
451
- this.common = {
452
- app: init.app,
453
- version: init.version,
454
- os: process.platform,
455
- arch: process.arch,
456
- node: process.versions.node,
457
- is_ci: isCI(),
458
- schema_version: 1
459
- };
460
- this.apiKey = init.apiKey || process.env.EXTENSION_PUBLIC_POSTHOG_KEY;
461
- 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
- }
339
+ throw new Error('Extension.js CLI package.json not found.');
340
+ }
341
+ function isStableVersion(version) {
342
+ const v = external_semver_namespaceObject.parse(version);
343
+ return Boolean(v && 0 === v.prerelease.length);
344
+ }
345
+ async function check_updates_checkUpdates() {
346
+ const packageJson = getCliPackageJson();
347
+ let update = null;
348
+ try {
349
+ update = await external_update_check_default()(packageJson);
350
+ } catch (err) {
351
+ if ('true' === process.env.EXTENSION_AUTHOR_MODE) console.error(updateFailed(err));
352
+ }
353
+ if (update && isStableVersion(update.latest)) {
354
+ if (isStableVersion(packageJson.version)) return checkUpdates(packageJson, update);
471
355
  }
356
+ return null;
472
357
  }
473
- }
474
- function summarizeManifest(manifest) {
475
- const mv = manifest?.manifest_version === 2 ? 2 : 3;
476
- const permissions = Array.isArray(manifest?.permissions) ? manifest.permissions : [];
477
- const optionalPermissions = Array.isArray(manifest?.optional_permissions) ? manifest.optional_permissions : [];
478
- const hostPermissions = Array.isArray(manifest?.host_permissions) ? manifest.host_permissions : [];
479
- const usesAllUrls = [
480
- ...permissions,
481
- ...hostPermissions
482
- ].includes('<all_urls>');
483
- const usesDeclarativeNetRequest = permissions.includes('declarativeNetRequest') || permissions.includes('declarativeNetRequestWithHostAccess');
484
- const background = manifest?.background;
485
- let backgroundType = 'none';
486
- if (3 === mv && background?.service_worker) backgroundType = 'service_worker';
487
- else if (2 === mv && (Array.isArray(background?.scripts) && background.scripts.length > 0 || background?.page)) backgroundType = 'event_page';
488
- const contentScriptsCount = Array.isArray(manifest?.content_scripts) ? manifest.content_scripts.length : 0;
489
- const hasDevtoolsPage = Boolean(manifest?.devtools_page);
490
- const hasActionPopup = Boolean(manifest?.action?.default_popup);
491
- return {
492
- mv,
493
- permissions_count: permissions.length,
494
- optional_permissions_count: optionalPermissions.length,
495
- host_permissions_count: hostPermissions.length,
496
- uses_all_urls: usesAllUrls,
497
- uses_declarative_net_request: usesDeclarativeNetRequest,
498
- background_type: backgroundType,
499
- content_scripts_count: contentScriptsCount,
500
- has_devtools_page: hasDevtoolsPage,
501
- has_action_popup: hasActionPopup
502
- };
503
- }
504
- function isTelemetryDisabledFromArgs(argv) {
505
- return argv.includes('--no-telemetry');
506
- }
507
- const telemetryDisabled = isTelemetryDisabledFromArgs(process.argv);
508
- function findManifestJson(projectRoot) {
509
- const stack = [
510
- projectRoot
511
- ];
512
- while(stack.length > 0){
513
- const dir = stack.pop();
514
- if (!dir) continue;
515
- let entries;
358
+ const external_fs_namespaceObject = require("fs");
359
+ var external_fs_default = /*#__PURE__*/ __webpack_require__.n(external_fs_namespaceObject);
360
+ const external_path_namespaceObject = require("path");
361
+ var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
362
+ const external_node_os_namespaceObject = require("node:os");
363
+ var external_node_os_default = /*#__PURE__*/ __webpack_require__.n(external_node_os_namespaceObject);
364
+ const external_node_crypto_namespaceObject = require("node:crypto");
365
+ var external_node_crypto_default = /*#__PURE__*/ __webpack_require__.n(external_node_crypto_namespaceObject);
366
+ function _define_property(obj, key, value) {
367
+ if (key in obj) Object.defineProperty(obj, key, {
368
+ value: value,
369
+ enumerable: true,
370
+ configurable: true,
371
+ writable: true
372
+ });
373
+ else obj[key] = value;
374
+ return obj;
375
+ }
376
+ function isCI() {
377
+ const v = process.env;
378
+ return Boolean(v.CI || v.GITHUB_ACTIONS || v.GITLAB_CI || v.BUILDKITE || v.CIRCLECI || v.TRAVIS);
379
+ }
380
+ function configDir() {
381
+ const xdg = process.env.XDG_CONFIG_HOME;
382
+ if (xdg) return external_node_path_default().join(xdg, 'extensionjs');
383
+ if ('win32' === process.platform && process.env.APPDATA) return external_node_path_default().join(process.env.APPDATA, 'extensionjs');
384
+ return external_node_path_default().join(external_node_os_default().homedir(), '.config', 'extensionjs');
385
+ }
386
+ function telemetry_cacheDir() {
387
+ const xdg = process.env.XDG_CACHE_HOME;
388
+ if (xdg) return external_node_path_default().join(xdg, 'extensionjs');
389
+ if ('win32' === process.platform) {
390
+ const base = process.env.LOCALAPPDATA || process.env.APPDATA;
391
+ if (base) return external_node_path_default().join(base, 'extensionjs', 'Cache');
392
+ }
393
+ if ('darwin' === process.platform) return external_node_path_default().join(external_node_os_default().homedir(), 'Library', 'Caches', 'extensionjs');
394
+ return null;
395
+ }
396
+ function ensureDir(p) {
516
397
  try {
517
- entries = external_fs_default().readdirSync(dir, {
518
- withFileTypes: true
398
+ if (external_node_fs_default().existsSync(p)) return true;
399
+ external_node_fs_default().mkdirSync(p, {
400
+ recursive: true
519
401
  });
402
+ return true;
520
403
  } catch {
521
- continue;
404
+ return false;
522
405
  }
523
- for (const entry of entries){
524
- if (entry.isFile() && 'manifest.json' === entry.name) return external_path_default().join(dir, entry.name);
525
- if (entry.isDirectory() && !entry.name.startsWith('.') && 'node_modules' !== entry.name && 'dist' !== entry.name) stack.push(external_path_default().join(dir, entry.name));
406
+ }
407
+ function ensureWritableDir(p) {
408
+ if (!ensureDir(p)) return false;
409
+ try {
410
+ external_node_fs_default().accessSync(p, external_node_fs_default().constants.W_OK);
411
+ const probe = external_node_path_default().join(p, `.write-test-${process.pid}-${Date.now()}`);
412
+ external_node_fs_default().writeFileSync(probe, 'ok', 'utf8');
413
+ external_node_fs_default().unlinkSync(probe);
414
+ return true;
415
+ } catch {
416
+ return false;
526
417
  }
527
418
  }
528
- return null;
529
- }
530
- const telemetry_cli_telemetry = new Telemetry({
531
- app: 'extension',
532
- version: getCliPackageJson().version,
533
- disabled: telemetryDisabled
534
- });
535
- if (!telemetryDisabled) {
536
- const startedAt = Date.now();
537
- const known = new Set([
538
- 'create',
539
- 'dev',
540
- 'start',
541
- 'preview',
542
- 'build',
543
- 'cleanup'
544
- ]);
545
- const invoked = process.argv.slice(2).find((a)=>known.has(a)) || 'unknown';
546
- telemetry_cli_telemetry.track('cli_boot', {
547
- command_guess: invoked
548
- });
549
- const manifestPath = findManifestJson(process.cwd());
550
- if (manifestPath) {
551
- const raw = external_fs_default().readFileSync(manifestPath, 'utf8');
552
- const json = JSON.parse(raw);
553
- const summary = summarizeManifest(json);
554
- telemetry_cli_telemetry.track('manifest_summary', summary);
555
- }
556
- process.on('beforeExit', async function() {
557
- telemetry_cli_telemetry.track('cli_shutdown', {
558
- command_guess: invoked,
559
- duration_ms: Date.now() - startedAt,
560
- exit_code: process.exitCode ?? 0
561
- });
562
- await telemetry_cli_telemetry.flush();
563
- });
564
- process.on('uncaughtException', function(err) {
565
- telemetry_cli_telemetry.track('cli_error', {
566
- command_guess: invoked,
567
- error_name: String(err?.name || 'Error').slice(0, 64)
568
- });
569
- });
570
- process.on('unhandledRejection', function(reason) {
571
- telemetry_cli_telemetry.track('cli_error', {
572
- command_guess: invoked,
573
- error_name: String(reason?.name || 'PromiseRejection').slice(0, 64)
574
- });
575
- });
576
- }
577
- require("node:url");
578
- function parseOptionalBoolean(value) {
579
- if (void 0 === value) return true;
580
- const normalized = String(value).trim().toLowerCase();
581
- return ![
582
- 'false',
583
- '0',
584
- 'no',
585
- 'off'
586
- ].includes(normalized);
587
- }
588
- const vendors = (browser)=>{
589
- const value = browser ?? 'chromium';
590
- return 'all' === value ? [
591
- 'chrome',
592
- 'edge',
593
- 'firefox'
594
- ] : String(value).split(',');
595
- };
596
- function validateVendorsOrExit(vendorsList, onInvalid) {
597
- const supported = [
598
- 'chrome',
599
- 'edge',
600
- 'firefox',
601
- 'chromium',
602
- 'chromium-based',
603
- 'gecko-based',
604
- 'firefox-based'
605
- ];
606
- for (const v of vendorsList)if (!supported.includes(v)) {
607
- onInvalid(v, supported);
608
- process.exit(1);
419
+ function loadOrCreateId(file) {
420
+ try {
421
+ if (external_node_fs_default().existsSync(file)) return external_node_fs_default().readFileSync(file, 'utf8').trim();
422
+ } catch {}
423
+ const id = external_node_crypto_default().randomUUID();
424
+ if (ensureDir(external_node_path_default().dirname(file))) try {
425
+ external_node_fs_default().writeFileSync(file, id, 'utf8');
426
+ } catch {}
427
+ return id;
609
428
  }
610
- }
611
- function registerCreateCommand(program, telemetry) {
612
- program.command('create').arguments('<project-name|project-path>').usage('create <project-name|project-path> [options]').description(commandDescriptions.create).option('-t, --template <template-name>', 'specify a template for the created project').option('--install [boolean]', 'whether or not to install the dependencies after creating the project (enabled by default)', parseOptionalBoolean, true).action(async function(pathOrRemoteUrl, { template, install }) {
429
+ function telemetryCandidates() {
430
+ const candidates = [
431
+ configDir(),
432
+ telemetry_cacheDir(),
433
+ external_node_path_default().join(external_node_os_default().tmpdir(), 'extensionjs'),
434
+ external_node_path_default().join(process.cwd(), '.cache', 'extensionjs')
435
+ ].filter(Boolean);
436
+ return Array.from(new Set(candidates));
437
+ }
438
+ function resolveTelemetryStorage() {
439
+ for (const base of telemetryCandidates()){
440
+ const telemetryDir = external_node_path_default().join(base, 'telemetry');
441
+ if (ensureWritableDir(telemetryDir)) return {
442
+ telemetryDir,
443
+ auditFile: external_node_path_default().join(telemetryDir, 'events.jsonl'),
444
+ idFile: external_node_path_default().join(telemetryDir, 'anonymous-id'),
445
+ consentFile: external_node_path_default().join(telemetryDir, 'consent')
446
+ };
447
+ }
448
+ return null;
449
+ }
450
+ const DEFAULT_FLUSH_AT = Number(process.env.EXTENSION_TELEMETRY_FLUSH_AT || 10);
451
+ const DEFAULT_FLUSH_INTERVAL = Number(process.env.EXTENSION_TELEMETRY_FLUSH_INTERVAL || 2000);
452
+ const DEFAULT_TIMEOUT_MS = Number(process.env.EXTENSION_TELEMETRY_TIMEOUT_MS || 200);
453
+ class Telemetry {
454
+ track(event, props = {}) {
455
+ if (this.disabled || !this.storage) return;
456
+ const payload = {
457
+ event,
458
+ properties: {
459
+ ...this.common,
460
+ ...props,
461
+ $ip: null
462
+ },
463
+ distinct_id: this.anonId
464
+ };
465
+ try {
466
+ external_node_fs_default().appendFileSync(this.storage.auditFile, JSON.stringify(payload) + '\n');
467
+ } catch {
468
+ this.disabled = true;
469
+ return;
470
+ }
471
+ if (this.debug) console.error('[telemetry]', JSON.stringify(payload));
472
+ if (!this.apiKey || !this.host) return;
473
+ this.buffer.push(payload);
474
+ if (this.buffer.length >= DEFAULT_FLUSH_AT) return void this.flush();
475
+ if (!this.timer) this.timer = setTimeout(()=>{
476
+ this.timer = null;
477
+ this.flush();
478
+ }, DEFAULT_FLUSH_INTERVAL);
479
+ }
480
+ async flush() {
481
+ if (this.disabled || !this.apiKey || !this.host) return;
482
+ if (0 === this.buffer.length) return;
483
+ const batch = this.buffer.splice(0, this.buffer.length);
484
+ try {
485
+ const ac = new AbortController();
486
+ const t = setTimeout(()=>ac.abort(), DEFAULT_TIMEOUT_MS);
487
+ const url = new URL('/capture/', this.host);
488
+ await fetch(url.toString(), {
489
+ method: 'POST',
490
+ headers: {
491
+ 'content-type': 'application/json'
492
+ },
493
+ body: JSON.stringify({
494
+ api_key: this.apiKey,
495
+ batch: batch.map((e)=>({
496
+ event: e.event,
497
+ properties: e.properties,
498
+ distinct_id: e.distinct_id
499
+ }))
500
+ }),
501
+ signal: ac.signal,
502
+ keepalive: true
503
+ }).catch(()=>{});
504
+ clearTimeout(t);
505
+ } catch {}
506
+ }
507
+ shutdown() {}
508
+ constructor(init){
509
+ _define_property(this, "anonId", void 0);
510
+ _define_property(this, "common", void 0);
511
+ _define_property(this, "debug", void 0);
512
+ _define_property(this, "disabled", void 0);
513
+ _define_property(this, "apiKey", void 0);
514
+ _define_property(this, "host", void 0);
515
+ _define_property(this, "storage", null);
516
+ _define_property(this, "buffer", []);
517
+ _define_property(this, "timer", null);
518
+ this.debug = '1' === process.env.EXTENSION_TELEMETRY_DEBUG;
519
+ this.disabled = Boolean(init.disabled);
520
+ this.anonId = 'disabled';
521
+ if (!this.disabled) {
522
+ this.storage = resolveTelemetryStorage();
523
+ if (this.storage) this.anonId = loadOrCreateId(this.storage.idFile);
524
+ else this.disabled = true;
525
+ }
526
+ this.common = {
527
+ app: init.app,
528
+ version: init.version,
529
+ os: process.platform,
530
+ arch: process.arch,
531
+ node: process.versions.node,
532
+ is_ci: isCI(),
533
+ schema_version: 1
534
+ };
535
+ this.apiKey = init.apiKey || process.env.EXTENSION_PUBLIC_POSTHOG_KEY;
536
+ this.host = init.host || process.env.EXTENSION_PUBLIC_POSTHOG_HOST;
537
+ if (!this.disabled && this.storage) {
538
+ const consentPath = this.storage.consentFile;
539
+ try {
540
+ if (!external_node_fs_default().existsSync(consentPath)) {
541
+ external_node_fs_default().writeFileSync(consentPath, 'ok', 'utf8');
542
+ this.track('cli_telemetry_consent', {
543
+ value: 'implicit_opt_in'
544
+ });
545
+ console.log(`${external_pintor_default().gray('►►►')} Telemetry is enabled for Extension.js. To opt out, run with --no-telemetry. Learn more in TELEMETRY.md.`);
546
+ }
547
+ } catch {}
548
+ }
549
+ }
550
+ }
551
+ function summarizeManifest(manifest) {
552
+ const mv = manifest?.manifest_version === 2 ? 2 : 3;
553
+ const permissions = Array.isArray(manifest?.permissions) ? manifest.permissions : [];
554
+ const optionalPermissions = Array.isArray(manifest?.optional_permissions) ? manifest.optional_permissions : [];
555
+ const hostPermissions = Array.isArray(manifest?.host_permissions) ? manifest.host_permissions : [];
556
+ const usesAllUrls = [
557
+ ...permissions,
558
+ ...hostPermissions
559
+ ].includes('<all_urls>');
560
+ const usesDeclarativeNetRequest = permissions.includes('declarativeNetRequest') || permissions.includes('declarativeNetRequestWithHostAccess');
561
+ const background = manifest?.background;
562
+ let backgroundType = 'none';
563
+ if (3 === mv && background?.service_worker) backgroundType = 'service_worker';
564
+ else if (2 === mv && (Array.isArray(background?.scripts) && background.scripts.length > 0 || background?.page)) backgroundType = 'event_page';
565
+ const contentScriptsCount = Array.isArray(manifest?.content_scripts) ? manifest.content_scripts.length : 0;
566
+ const hasDevtoolsPage = Boolean(manifest?.devtools_page);
567
+ const hasActionPopup = Boolean(manifest?.action?.default_popup);
568
+ return {
569
+ mv,
570
+ permissions_count: permissions.length,
571
+ optional_permissions_count: optionalPermissions.length,
572
+ host_permissions_count: hostPermissions.length,
573
+ uses_all_urls: usesAllUrls,
574
+ uses_declarative_net_request: usesDeclarativeNetRequest,
575
+ background_type: backgroundType,
576
+ content_scripts_count: contentScriptsCount,
577
+ has_devtools_page: hasDevtoolsPage,
578
+ has_action_popup: hasActionPopup
579
+ };
580
+ }
581
+ function isTelemetryDisabledFromArgs(argv) {
582
+ return argv.includes('--no-telemetry');
583
+ }
584
+ const telemetryDisabled = isTelemetryDisabledFromArgs(process.argv);
585
+ function findManifestJson(projectRoot) {
586
+ const stack = [
587
+ projectRoot
588
+ ];
589
+ while(stack.length > 0){
590
+ const dir = stack.pop();
591
+ if (!dir) continue;
592
+ let entries;
593
+ try {
594
+ entries = external_fs_default().readdirSync(dir, {
595
+ withFileTypes: true
596
+ });
597
+ } catch {
598
+ continue;
599
+ }
600
+ for (const entry of entries){
601
+ if (entry.isFile() && 'manifest.json' === entry.name) return external_path_default().join(dir, entry.name);
602
+ if (entry.isDirectory() && !entry.name.startsWith('.') && 'node_modules' !== entry.name && 'dist' !== entry.name) stack.push(external_path_default().join(dir, entry.name));
603
+ }
604
+ }
605
+ return null;
606
+ }
607
+ const telemetry_cli_telemetry = new Telemetry({
608
+ app: 'extension',
609
+ version: getCliPackageJson().version,
610
+ disabled: telemetryDisabled
611
+ });
612
+ if (!telemetryDisabled) {
613
613
  const startedAt = Date.now();
614
- telemetry.track('cli_command_start', {
615
- command: 'create',
616
- template: template || 'default',
617
- install: Boolean(install)
614
+ const known = new Set([
615
+ 'create',
616
+ 'dev',
617
+ 'start',
618
+ 'preview',
619
+ 'build',
620
+ 'cleanup'
621
+ ]);
622
+ const invoked = process.argv.slice(2).find((a)=>known.has(a)) || 'unknown';
623
+ telemetry_cli_telemetry.track('cli_boot', {
624
+ command_guess: invoked
618
625
  });
619
- try {
620
- const { extensionCreate } = await import("extension-create");
621
- const { ensureDependencies } = await import("extension-develop");
622
- const projectPath = external_path_namespaceObject.isAbsolute(pathOrRemoteUrl) ? pathOrRemoteUrl : external_path_namespaceObject.join(process.cwd(), pathOrRemoteUrl);
623
- await extensionCreate(pathOrRemoteUrl, {
624
- template,
625
- install,
626
- cliVersion: getCliPackageJson().version
627
- });
628
- if (install) await ensureDependencies(projectPath, {
629
- skipProjectInstall: true,
630
- showRunAgainMessage: false
631
- });
632
- telemetry.track('cli_command_finish', {
633
- command: 'create',
626
+ const manifestPath = findManifestJson(process.cwd());
627
+ if (manifestPath) {
628
+ const raw = external_fs_default().readFileSync(manifestPath, 'utf8');
629
+ const json = JSON.parse(raw);
630
+ const summary = summarizeManifest(json);
631
+ telemetry_cli_telemetry.track('manifest_summary', summary);
632
+ }
633
+ process.on('beforeExit', async function() {
634
+ telemetry_cli_telemetry.track('cli_shutdown', {
635
+ command_guess: invoked,
634
636
  duration_ms: Date.now() - startedAt,
635
- success: true,
636
- exit_code: 0
637
+ exit_code: process.exitCode ?? 0
637
638
  });
638
- } catch (err) {
639
- telemetry.track('cli_command_finish', {
640
- command: 'create',
641
- duration_ms: Date.now() - startedAt,
642
- success: false,
643
- exit_code: 1
639
+ await telemetry_cli_telemetry.flush();
640
+ });
641
+ process.on('uncaughtException', function(err) {
642
+ telemetry_cli_telemetry.track('cli_error', {
643
+ command_guess: invoked,
644
+ error_name: String(err?.name || 'Error').slice(0, 64)
644
645
  });
645
- throw err;
646
- }
647
- });
648
- }
649
- function normalizeSourceOption(source, startingUrl) {
650
- if (!source) return;
651
- const hasExplicitSourceString = 'string' == typeof source && 'true' !== String(source).trim().toLowerCase();
652
- const hasStartingUrl = 'string' == typeof startingUrl && String(startingUrl).trim().length > 0;
653
- if (!hasExplicitSourceString) return hasStartingUrl ? String(startingUrl) : 'https://example.com';
654
- return String(source);
655
- }
656
- function parseLogContexts(raw) {
657
- if (!raw || 0 === String(raw).trim().length) return;
658
- if ('all' === String(raw).trim().toLowerCase()) return;
659
- const allowed = [
660
- 'background',
661
- 'content',
662
- 'page',
663
- 'sidebar',
664
- 'popup',
665
- 'options',
666
- 'devtools'
667
- ];
668
- const values = String(raw).split(',').map((s)=>s.trim()).filter((s)=>s.length > 0).filter((c)=>allowed.includes(c));
669
- return values.length > 0 ? values : void 0;
670
- }
671
- function registerDevCommand(program, telemetry) {
672
- program.command('dev').arguments('[project-path|remote-url]').usage('dev [project-path|remote-url] [options]').description(commandDescriptions.dev).option('--profile <path-to-file | boolean>', 'what path to use for the browser profile. A boolean value of false sets the profile to the default user profile. Defaults to a fresh profile').option('--browser <chrome | chromium | edge | firefox | chromium-based | gecko-based | firefox-based>', 'specify a browser/engine to run. Defaults to `chromium`').option('--chromium-binary <path-to-binary>', 'specify a path to the Chromium binary. This option overrides the --browser setting. Defaults to the system default').option('--gecko-binary, --firefox-binary <path-to-binary>', 'specify a path to the Gecko binary. This option overrides the --browser setting. Defaults to the system default').option('--polyfill [boolean]', 'whether or not to apply the cross-browser polyfill. Defaults to `false`').option('--no-open', 'do not open the browser automatically (default: open)').option('--starting-url <url>', 'specify the starting URL for the browser. Defaults to `undefined`').option('--port <port>', 'specify the port to use for the development server. Defaults to `8080`').option('--log-context <list>', '[experimental] comma-separated contexts to include (background,content,page,sidebar,popup,options,devtools). Use `all` to include all contexts (default)').option('--logs <off|error|warn|info|debug|trace|all>', '[experimental] minimum centralized logger level to display in terminal (default: off)').option('--log-format <pretty|json>', '[experimental] output format for logger events. Defaults to `pretty`').option('--no-log-timestamps', 'disable ISO timestamps in pretty output').option('--no-log-color', 'disable color in pretty output').option('--log-url <pattern>', '[experimental] only show logs where event.url matches this substring or regex (/re/i)').option('--log-tab <id>', 'only show logs for a specific tabId (number)').option('--source [url]', "[experimental] opens the provided URL in Chrome and prints the full, live HTML of the page after content scripts are injected").option('--author, --author-mode', '[internal] enable maintainer diagnostics (does not affect user runtime logs)').action(async function(pathOrRemoteUrl, { browser = 'chromium', ...devOptions }) {
673
- if (devOptions.author || devOptions['authorMode']) {
674
- process.env.EXTENSION_AUTHOR_MODE = 'true';
675
- if (!process.env.EXTENSION_VERBOSE) process.env.EXTENSION_VERBOSE = '1';
676
- }
677
- const cmdStart = Date.now();
678
- telemetry.track('cli_command_start', {
679
- command: 'dev',
680
- vendors: vendors(browser),
681
- polyfill_used: devOptions.polyfill?.toString() !== 'false',
682
- log_level: devOptions.logLevel || 'off',
683
- log_format: devOptions.logFormat || 'pretty',
684
- custom_binary_used: Boolean(devOptions.chromiumBinary || devOptions.geckoBinary)
685
646
  });
686
- const list = vendors(browser);
687
- validateVendorsOrExit(list, (invalid, supported)=>{
688
- console.error(unsupportedBrowserFlag(invalid, supported));
647
+ process.on('unhandledRejection', function(reason) {
648
+ telemetry_cli_telemetry.track('cli_error', {
649
+ command_guess: invoked,
650
+ error_name: String(reason?.name || 'PromiseRejection').slice(0, 64)
651
+ });
689
652
  });
690
- const normalizedSource = normalizeSourceOption(devOptions.source, devOptions.startingUrl);
691
- if (normalizedSource) {
692
- devOptions.source = normalizedSource;
693
- devOptions.watchSource = true;
653
+ }
654
+ require("node:url");
655
+ function parseOptionalBoolean(value) {
656
+ if (void 0 === value) return true;
657
+ const normalized = String(value).trim().toLowerCase();
658
+ return ![
659
+ 'false',
660
+ '0',
661
+ 'no',
662
+ 'off'
663
+ ].includes(normalized);
664
+ }
665
+ const vendors = (browser)=>{
666
+ const value = browser ?? 'chromium';
667
+ return 'all' === value ? [
668
+ 'chrome',
669
+ 'edge',
670
+ 'firefox'
671
+ ] : String(value).split(',');
672
+ };
673
+ function validateVendorsOrExit(vendorsList, onInvalid) {
674
+ const supported = [
675
+ 'chrome',
676
+ 'edge',
677
+ 'firefox',
678
+ 'chromium',
679
+ 'chromium-based',
680
+ 'gecko-based',
681
+ 'firefox-based'
682
+ ];
683
+ for (const v of vendorsList)if (!supported.includes(v)) {
684
+ onInvalid(v, supported);
685
+ process.exit(1);
694
686
  }
695
- const { extensionDev } = await import("extension-develop");
696
- for (const vendor of list){
697
- const vendorStart = Date.now();
698
- telemetry.track('cli_vendor_start', {
687
+ }
688
+ function registerCreateCommand(program, telemetry) {
689
+ program.command('create').arguments('<project-name|project-path>').usage('create <project-name|project-path> [options]').description(commandDescriptions.create).option('-t, --template <template-name>', 'specify a template for the created project').option('--install [boolean]', 'whether or not to install the dependencies after creating the project (enabled by default)', parseOptionalBoolean, true).action(async function(pathOrRemoteUrl, { template, install }) {
690
+ const startedAt = Date.now();
691
+ telemetry.track('cli_command_start', {
692
+ command: 'create',
693
+ template: template || 'default',
694
+ install: Boolean(install)
695
+ });
696
+ try {
697
+ const { extensionCreate } = await import("extension-create");
698
+ external_path_namespaceObject.isAbsolute(pathOrRemoteUrl) || external_path_namespaceObject.join(process.cwd(), pathOrRemoteUrl);
699
+ await extensionCreate(pathOrRemoteUrl, {
700
+ template,
701
+ install,
702
+ cliVersion: getCliPackageJson().version
703
+ });
704
+ telemetry.track('cli_command_finish', {
705
+ command: 'create',
706
+ duration_ms: Date.now() - startedAt,
707
+ success: true,
708
+ exit_code: 0
709
+ });
710
+ } catch (err) {
711
+ telemetry.track('cli_command_finish', {
712
+ command: 'create',
713
+ duration_ms: Date.now() - startedAt,
714
+ success: false,
715
+ exit_code: 1
716
+ });
717
+ throw err;
718
+ }
719
+ });
720
+ }
721
+ function normalizeSourceOption(source, startingUrl) {
722
+ if (!source) return;
723
+ const hasExplicitSourceString = 'string' == typeof source && 'true' !== String(source).trim().toLowerCase();
724
+ const hasStartingUrl = 'string' == typeof startingUrl && String(startingUrl).trim().length > 0;
725
+ if (!hasExplicitSourceString) return hasStartingUrl ? String(startingUrl) : 'https://example.com';
726
+ return String(source);
727
+ }
728
+ function parseLogContexts(raw) {
729
+ if (!raw || 0 === String(raw).trim().length) return;
730
+ if ('all' === String(raw).trim().toLowerCase()) return;
731
+ const allowed = [
732
+ 'background',
733
+ 'content',
734
+ 'page',
735
+ 'sidebar',
736
+ 'popup',
737
+ 'options',
738
+ 'devtools'
739
+ ];
740
+ const values = String(raw).split(',').map((s)=>s.trim()).filter((s)=>s.length > 0).filter((c)=>allowed.includes(c));
741
+ return values.length > 0 ? values : void 0;
742
+ }
743
+ function registerDevCommand(program, telemetry) {
744
+ program.command('dev').arguments('[project-path|remote-url]').usage('dev [project-path|remote-url] [options]').description(commandDescriptions.dev).option('--profile <path-to-file | boolean>', 'what path to use for the browser profile. A boolean value of false sets the profile to the default user profile. Defaults to a fresh profile').option('--browser <chrome | chromium | edge | firefox | chromium-based | gecko-based | firefox-based>', 'specify a browser/engine to run. Defaults to `chromium`').option('--chromium-binary <path-to-binary>', 'specify a path to the Chromium binary. This option overrides the --browser setting. Defaults to the system default').option('--gecko-binary, --firefox-binary <path-to-binary>', 'specify a path to the Gecko binary. This option overrides the --browser setting. Defaults to the system default').option('--polyfill [boolean]', 'whether or not to apply the cross-browser polyfill. Defaults to `false`').option('--no-open', 'do not open the browser automatically (default: open)').option('--starting-url <url>', 'specify the starting URL for the browser. Defaults to `undefined`').option('--port <port>', 'specify the port to use for the development server. Defaults to `8080`').option('--log-context <list>', '[experimental] comma-separated contexts to include (background,content,page,sidebar,popup,options,devtools). Use `all` to include all contexts (default)').option('--logs <off|error|warn|info|debug|trace|all>', '[experimental] minimum centralized logger level to display in terminal (default: off)').option('--log-format <pretty|json>', '[experimental] output format for logger events. Defaults to `pretty`').option('--no-log-timestamps', 'disable ISO timestamps in pretty output').option('--no-log-color', 'disable color in pretty output').option('--log-url <pattern>', '[experimental] only show logs where event.url matches this substring or regex (/re/i)').option('--log-tab <id>', 'only show logs for a specific tabId (number)').option('--source [url]', "[experimental] opens the provided URL in Chrome and prints the full, live HTML of the page after content scripts are injected").option('--install [boolean]', '[internal] install project dependencies when missing', parseOptionalBoolean).option('--author, --author-mode', '[internal] enable maintainer diagnostics (does not affect user runtime logs)').action(async function(pathOrRemoteUrl, { browser = 'chromium', ...devOptions }) {
745
+ if (devOptions.author || devOptions['authorMode']) {
746
+ process.env.EXTENSION_AUTHOR_MODE = 'true';
747
+ if (!process.env.EXTENSION_VERBOSE) process.env.EXTENSION_VERBOSE = '1';
748
+ }
749
+ const cmdStart = Date.now();
750
+ telemetry.track('cli_command_start', {
699
751
  command: 'dev',
700
- vendor
752
+ vendors: vendors(browser),
753
+ polyfill_used: devOptions.polyfill?.toString() !== 'false',
754
+ log_level: devOptions.logLevel || 'off',
755
+ log_format: devOptions.logFormat || 'pretty',
756
+ custom_binary_used: Boolean(devOptions.chromiumBinary || devOptions.geckoBinary)
701
757
  });
702
- const logsOption = devOptions.logs;
703
- const logContextOption = devOptions.logContext;
704
- const devArgs = {
705
- ...devOptions,
706
- profile: devOptions.profile,
707
- browser: vendor,
708
- chromiumBinary: devOptions.chromiumBinary,
709
- geckoBinary: devOptions.geckoBinary,
710
- polyfill: devOptions.polyfill?.toString() !== 'false',
711
- open: devOptions.open,
712
- startingUrl: devOptions.startingUrl,
713
- source: devOptions.source,
714
- watchSource: devOptions.watchSource,
715
- logLevel: logsOption || devOptions.logLevel || 'off',
716
- logContexts: parseLogContexts(logContextOption),
717
- logFormat: devOptions.logFormat || 'pretty',
718
- logTimestamps: false !== devOptions.logTimestamps,
719
- logColor: false !== devOptions.logColor,
720
- logUrl: devOptions.logUrl,
721
- logTab: devOptions.logTab
722
- };
723
- await extensionDev(pathOrRemoteUrl, devArgs);
724
- telemetry.track('cli_vendor_finish', {
758
+ const list = vendors(browser);
759
+ validateVendorsOrExit(list, (invalid, supported)=>{
760
+ console.error(unsupportedBrowserFlag(invalid, supported));
761
+ });
762
+ const normalizedSource = normalizeSourceOption(devOptions.source, devOptions.startingUrl);
763
+ if (normalizedSource) {
764
+ devOptions.source = normalizedSource;
765
+ devOptions.watchSource = true;
766
+ }
767
+ const { extensionDev } = await import("extension-develop");
768
+ for (const vendor of list){
769
+ const vendorStart = Date.now();
770
+ telemetry.track('cli_vendor_start', {
771
+ command: 'dev',
772
+ vendor
773
+ });
774
+ const logsOption = devOptions.logs;
775
+ const logContextOption = devOptions.logContext;
776
+ const devArgs = {
777
+ ...devOptions,
778
+ profile: devOptions.profile,
779
+ browser: vendor,
780
+ chromiumBinary: devOptions.chromiumBinary,
781
+ geckoBinary: devOptions.geckoBinary,
782
+ polyfill: devOptions.polyfill?.toString() !== 'false',
783
+ open: devOptions.open,
784
+ startingUrl: devOptions.startingUrl,
785
+ source: devOptions.source,
786
+ watchSource: devOptions.watchSource,
787
+ install: devOptions.install,
788
+ logLevel: logsOption || devOptions.logLevel || 'off',
789
+ logContexts: parseLogContexts(logContextOption),
790
+ logFormat: devOptions.logFormat || 'pretty',
791
+ logTimestamps: false !== devOptions.logTimestamps,
792
+ logColor: false !== devOptions.logColor,
793
+ logUrl: devOptions.logUrl,
794
+ logTab: devOptions.logTab
795
+ };
796
+ await extensionDev(pathOrRemoteUrl, devArgs);
797
+ telemetry.track('cli_vendor_finish', {
798
+ command: 'dev',
799
+ vendor,
800
+ duration_ms: Date.now() - vendorStart
801
+ });
802
+ }
803
+ telemetry.track('cli_command_finish', {
725
804
  command: 'dev',
726
- vendor,
727
- duration_ms: Date.now() - vendorStart
805
+ duration_ms: Date.now() - cmdStart,
806
+ success: 0 === process.exitCode || null == process.exitCode,
807
+ exit_code: process.exitCode ?? 0
728
808
  });
729
- }
730
- telemetry.track('cli_command_finish', {
731
- command: 'dev',
732
- duration_ms: Date.now() - cmdStart,
733
- success: 0 === process.exitCode || null == process.exitCode,
734
- exit_code: process.exitCode ?? 0
735
809
  });
736
- });
737
- }
738
- function registerStartCommand(program, telemetry) {
739
- program.command('start').arguments('[project-path|remote-url]').usage('start [project-path|remote-url] [options]').description(commandDescriptions.start).option('--profile <path-to-file | boolean>', 'what path to use for the browser profile. A boolean value of false sets the profile to the default user profile. Defaults to a fresh profile').option('--browser <chrome | chromium | edge | firefox | chromium-based | gecko-based | firefox-based>', 'specify a browser/engine to run. Defaults to `chromium`').option('--polyfill [boolean]', 'whether or not to apply the cross-browser polyfill. Defaults to `true`').option('--chromium-binary <path-to-binary>', 'specify a path to the Chromium binary. This option overrides the --browser setting. Defaults to the system default').option('--gecko-binary, --firefox-binary <path-to-binary>', 'specify a path to the Gecko binary. This option overrides the --browser setting. Defaults to the system default').option('--starting-url <url>', 'specify the starting URL for the browser. Defaults to `undefined`').option('--port <port>', 'specify the port to use for the development server. Defaults to `8080`').option('--log-context <list>', '[experimental] comma-separated contexts to include (background,content,page,sidebar,popup,options,devtools). Use `all` to include all contexts (default)').option('--logs <off|error|warn|info|debug|trace|all>', '[experimental] minimum centralized logger level to display in terminal (default: off)').option('--log-format <pretty|json>', '[experimental] output format for logger events. Defaults to `pretty`').option('--no-log-timestamps', 'disable ISO timestamps in pretty output').option('--no-log-color', 'disable color in pretty output').option('--log-url <pattern>', '[experimental] only show logs where event.url matches this substring or regex (/re/i)').option('--log-tab <id>', 'only show logs for a specific tabId (number)').option('--source [url]', "[experimental] opens the provided URL in Chrome and prints the full, live HTML of the page after content scripts are injected").option('--author, --author-mode', '[internal] enable maintainer diagnostics (does not affect user runtime logs)').action(async function(pathOrRemoteUrl, { browser = 'chromium', ...startOptions }) {
740
- if (startOptions.author || startOptions.authorMode) {
741
- process.env.EXTENSION_AUTHOR_MODE = 'true';
742
- if (!process.env.EXTENSION_VERBOSE) process.env.EXTENSION_VERBOSE = '1';
743
- }
744
- const cmdStart = Date.now();
745
- telemetry.track('cli_command_start', {
746
- command: 'start',
747
- vendors: vendors(browser),
748
- polyfill_used: startOptions.polyfill?.toString() !== 'false'
749
- });
750
- const list = vendors(browser);
751
- validateVendorsOrExit(list, (invalid, supported)=>{
752
- console.error(unsupportedBrowserFlag(invalid, supported));
753
- });
754
- const { extensionStart } = await import("extension-develop");
755
- for (const vendor of list){
756
- const vendorStart = Date.now();
757
- telemetry.track('cli_vendor_start', {
810
+ }
811
+ function registerStartCommand(program, telemetry) {
812
+ program.command('start').arguments('[project-path|remote-url]').usage('start [project-path|remote-url] [options]').description(commandDescriptions.start).option('--profile <path-to-file | boolean>', 'what path to use for the browser profile. A boolean value of false sets the profile to the default user profile. Defaults to a fresh profile').option('--browser <chrome | chromium | edge | firefox | chromium-based | gecko-based | firefox-based>', 'specify a browser/engine to run. Defaults to `chromium`').option('--polyfill [boolean]', 'whether or not to apply the cross-browser polyfill. Defaults to `true`').option('--chromium-binary <path-to-binary>', 'specify a path to the Chromium binary. This option overrides the --browser setting. Defaults to the system default').option('--gecko-binary, --firefox-binary <path-to-binary>', 'specify a path to the Gecko binary. This option overrides the --browser setting. Defaults to the system default').option('--starting-url <url>', 'specify the starting URL for the browser. Defaults to `undefined`').option('--port <port>', 'specify the port to use for the development server. Defaults to `8080`').option('--log-context <list>', '[experimental] comma-separated contexts to include (background,content,page,sidebar,popup,options,devtools). Use `all` to include all contexts (default)').option('--logs <off|error|warn|info|debug|trace|all>', '[experimental] minimum centralized logger level to display in terminal (default: off)').option('--log-format <pretty|json>', '[experimental] output format for logger events. Defaults to `pretty`').option('--no-log-timestamps', 'disable ISO timestamps in pretty output').option('--no-log-color', 'disable color in pretty output').option('--log-url <pattern>', '[experimental] only show logs where event.url matches this substring or regex (/re/i)').option('--log-tab <id>', 'only show logs for a specific tabId (number)').option('--source [url]', "[experimental] opens the provided URL in Chrome and prints the full, live HTML of the page after content scripts are injected").option('--install [boolean]', '[experimental] install project dependencies when missing', parseOptionalBoolean).option('--author, --author-mode', '[experimental] enable maintainer diagnostics (does not affect user runtime logs)').action(async function(pathOrRemoteUrl, { browser = 'chromium', ...startOptions }) {
813
+ if (startOptions.author || startOptions.authorMode) {
814
+ process.env.EXTENSION_AUTHOR_MODE = 'true';
815
+ if (!process.env.EXTENSION_VERBOSE) process.env.EXTENSION_VERBOSE = '1';
816
+ }
817
+ const cmdStart = Date.now();
818
+ telemetry.track('cli_command_start', {
758
819
  command: 'start',
759
- vendor
820
+ vendors: vendors(browser),
821
+ polyfill_used: startOptions.polyfill?.toString() !== 'false'
760
822
  });
761
- const logsOption = startOptions.logs;
762
- const logContextOption = startOptions.logContext;
763
- const logContexts = parseLogContexts(logContextOption);
764
- await extensionStart(pathOrRemoteUrl, {
765
- mode: 'production',
766
- profile: startOptions.profile,
767
- browser: vendor,
768
- chromiumBinary: startOptions.chromiumBinary,
769
- geckoBinary: startOptions.geckoBinary,
770
- startingUrl: startOptions.startingUrl,
771
- port: startOptions.port,
772
- source: 'string' == typeof startOptions.source ? startOptions.source : startOptions.source,
773
- watchSource: startOptions.watchSource,
774
- logLevel: logsOption || startOptions.logLevel || 'off',
775
- logContexts,
776
- logFormat: startOptions.logFormat || 'pretty',
777
- logTimestamps: false !== startOptions.logTimestamps,
778
- logColor: false !== startOptions.logColor,
779
- logUrl: startOptions.logUrl,
780
- logTab: startOptions.logTab
823
+ const list = vendors(browser);
824
+ validateVendorsOrExit(list, (invalid, supported)=>{
825
+ console.error(unsupportedBrowserFlag(invalid, supported));
781
826
  });
782
- telemetry.track('cli_vendor_finish', {
827
+ const { extensionStart } = await import("extension-develop");
828
+ for (const vendor of list){
829
+ const vendorStart = Date.now();
830
+ telemetry.track('cli_vendor_start', {
831
+ command: 'start',
832
+ vendor
833
+ });
834
+ const logsOption = startOptions.logs;
835
+ const logContextOption = startOptions.logContext;
836
+ const logContexts = parseLogContexts(logContextOption);
837
+ await extensionStart(pathOrRemoteUrl, {
838
+ mode: 'production',
839
+ profile: startOptions.profile,
840
+ browser: vendor,
841
+ chromiumBinary: startOptions.chromiumBinary,
842
+ geckoBinary: startOptions.geckoBinary,
843
+ startingUrl: startOptions.startingUrl,
844
+ port: startOptions.port,
845
+ install: startOptions.install,
846
+ source: 'string' == typeof startOptions.source ? startOptions.source : startOptions.source,
847
+ watchSource: startOptions.watchSource,
848
+ logLevel: logsOption || startOptions.logLevel || 'off',
849
+ logContexts,
850
+ logFormat: startOptions.logFormat || 'pretty',
851
+ logTimestamps: false !== startOptions.logTimestamps,
852
+ logColor: false !== startOptions.logColor,
853
+ logUrl: startOptions.logUrl,
854
+ logTab: startOptions.logTab
855
+ });
856
+ telemetry.track('cli_vendor_finish', {
857
+ command: 'start',
858
+ vendor,
859
+ duration_ms: Date.now() - vendorStart
860
+ });
861
+ }
862
+ telemetry.track('cli_command_finish', {
783
863
  command: 'start',
784
- vendor,
785
- duration_ms: Date.now() - vendorStart
864
+ duration_ms: Date.now() - cmdStart,
865
+ success: 0 === process.exitCode || null == process.exitCode,
866
+ exit_code: process.exitCode ?? 0
786
867
  });
787
- }
788
- telemetry.track('cli_command_finish', {
789
- command: 'start',
790
- duration_ms: Date.now() - cmdStart,
791
- success: 0 === process.exitCode || null == process.exitCode,
792
- exit_code: process.exitCode ?? 0
793
868
  });
794
- });
795
- }
796
- function registerPreviewCommand(program, telemetry) {
797
- program.command('preview').arguments('[project-name]').usage('preview [path-to-remote-extension] [options]').description(commandDescriptions.preview).option('--profile <path-to-file | boolean>', 'what path to use for the browser profile. A boolean value of false sets the profile to the default user profile. Defaults to a fresh profile').option('--browser <chrome | chromium | edge | firefox | chromium-based | gecko-based | firefox-based>', 'specify a browser/engine to run. Defaults to `chromium`').option('--chromium-binary <path-to-binary>', 'specify a path to the Chromium binary. This option overrides the --browser setting. Defaults to the system default').option('--gecko-binary, --firefox-binary <path-to-binary>', 'specify a path to the Gecko binary. This option overrides the --browser setting. Defaults to the system default').option('--starting-url <url>', 'specify the starting URL for the browser. Defaults to `undefined`').option('--port <port>', 'specify the port to use for the development server. Defaults to `8080`').option('--log-context <list>', '[experimental] comma-separated contexts to include (background,content,page,sidebar,popup,options,devtools). Use `all` to include all contexts (default)').option('--logs <off|error|warn|info|debug|trace|all>', '[experimental] minimum centralized logger level to display in terminal (default: off)').option('--log-format <pretty|json>', '[experimental] output format for logger events. Defaults to `pretty`').option('--no-log-timestamps', 'disable ISO timestamps in pretty output').option('--no-log-color', 'disable color in pretty output').option('--log-url <pattern>', '[experimental] only show logs where event.url matches this substring or regex (/re/i)').option('--log-tab <id>', 'only show logs for a specific tabId (number)').option('--source [url]', "[experimental] opens the provided URL in Chrome and prints the full, live HTML of the page after content scripts are injected").option('--author, --author-mode', '[internal] enable maintainer diagnostics (does not affect user runtime logs)').action(async function(pathOrRemoteUrl, { browser = 'chromium', ...previewOptions }) {
798
- if (previewOptions.author || previewOptions['authorMode']) {
799
- process.env.EXTENSION_AUTHOR_MODE = 'true';
800
- if (!process.env.EXTENSION_VERBOSE) process.env.EXTENSION_VERBOSE = '1';
801
- }
802
- const cmdStart = Date.now();
803
- telemetry.track('cli_command_start', {
804
- command: 'preview',
805
- vendors: vendors(browser)
806
- });
807
- const list = vendors(browser);
808
- validateVendorsOrExit(list, (invalid, supported)=>{
809
- console.error(unsupportedBrowserFlag(invalid, supported));
810
- });
811
- if (!process.env.EXTJS_LIGHT) {
812
- const isRemote = 'string' == typeof pathOrRemoteUrl && /^https?:/i.test(pathOrRemoteUrl);
813
- if (isRemote) process.env.EXTJS_LIGHT = '1';
814
- }
815
- const { extensionPreview } = await import("extension-develop");
816
- for (const vendor of list){
817
- const vendorStart = Date.now();
818
- telemetry.track('cli_vendor_start', {
869
+ }
870
+ function registerPreviewCommand(program, telemetry) {
871
+ program.command('preview').arguments('[project-name]').usage('preview [path-to-remote-extension] [options]').description(commandDescriptions.preview).option('--profile <path-to-file | boolean>', 'what path to use for the browser profile. A boolean value of false sets the profile to the default user profile. Defaults to a fresh profile').option('--browser <chrome | chromium | edge | firefox | chromium-based | gecko-based | firefox-based>', 'specify a browser/engine to run. Defaults to `chromium`').option('--chromium-binary <path-to-binary>', 'specify a path to the Chromium binary. This option overrides the --browser setting. Defaults to the system default').option('--gecko-binary, --firefox-binary <path-to-binary>', 'specify a path to the Gecko binary. This option overrides the --browser setting. Defaults to the system default').option('--starting-url <url>', 'specify the starting URL for the browser. Defaults to `undefined`').option('--port <port>', 'specify the port to use for the development server. Defaults to `8080`').option('--log-context <list>', '[experimental] comma-separated contexts to include (background,content,page,sidebar,popup,options,devtools). Use `all` to include all contexts (default)').option('--logs <off|error|warn|info|debug|trace|all>', '[experimental] minimum centralized logger level to display in terminal (default: off)').option('--log-format <pretty|json>', '[experimental] output format for logger events. Defaults to `pretty`').option('--no-log-timestamps', 'disable ISO timestamps in pretty output').option('--no-log-color', 'disable color in pretty output').option('--log-url <pattern>', '[experimental] only show logs where event.url matches this substring or regex (/re/i)').option('--log-tab <id>', 'only show logs for a specific tabId (number)').option('--source [url]', "[experimental] opens the provided URL in Chrome and prints the full, live HTML of the page after content scripts are injected").option('--author, --author-mode', '[internal] enable maintainer diagnostics (does not affect user runtime logs)').action(async function(pathOrRemoteUrl, { browser = 'chromium', ...previewOptions }) {
872
+ if (previewOptions.author || previewOptions['authorMode']) {
873
+ process.env.EXTENSION_AUTHOR_MODE = 'true';
874
+ if (!process.env.EXTENSION_VERBOSE) process.env.EXTENSION_VERBOSE = '1';
875
+ }
876
+ const cmdStart = Date.now();
877
+ telemetry.track('cli_command_start', {
819
878
  command: 'preview',
820
- vendor
879
+ vendors: vendors(browser)
821
880
  });
822
- const logsOption = previewOptions.logs;
823
- const logContextOption = previewOptions.logContext;
824
- const logContexts = parseLogContexts(logContextOption);
825
- await extensionPreview(pathOrRemoteUrl, {
826
- mode: 'production',
827
- profile: previewOptions.profile,
828
- browser: vendor,
829
- chromiumBinary: previewOptions.chromiumBinary,
830
- geckoBinary: previewOptions.geckoBinary,
831
- startingUrl: previewOptions.startingUrl,
832
- port: previewOptions.port,
833
- source: 'string' == typeof previewOptions.source ? previewOptions.source : previewOptions.source,
834
- watchSource: previewOptions.watchSource,
835
- logLevel: logsOption || previewOptions.logLevel || 'off',
836
- logContexts,
837
- logFormat: previewOptions.logFormat || 'pretty',
838
- logTimestamps: false !== previewOptions.logTimestamps,
839
- logColor: false !== previewOptions.logColor,
840
- logUrl: previewOptions.logUrl,
841
- logTab: previewOptions.logTab
881
+ const list = vendors(browser);
882
+ validateVendorsOrExit(list, (invalid, supported)=>{
883
+ console.error(unsupportedBrowserFlag(invalid, supported));
842
884
  });
843
- telemetry.track('cli_vendor_finish', {
885
+ if (!process.env.EXTJS_LIGHT) {
886
+ const isRemote = 'string' == typeof pathOrRemoteUrl && /^https?:/i.test(pathOrRemoteUrl);
887
+ if (isRemote) process.env.EXTJS_LIGHT = '1';
888
+ }
889
+ const { extensionPreview } = await import("extension-develop");
890
+ for (const vendor of list){
891
+ const vendorStart = Date.now();
892
+ telemetry.track('cli_vendor_start', {
893
+ command: 'preview',
894
+ vendor
895
+ });
896
+ const logsOption = previewOptions.logs;
897
+ const logContextOption = previewOptions.logContext;
898
+ const logContexts = parseLogContexts(logContextOption);
899
+ await extensionPreview(pathOrRemoteUrl, {
900
+ mode: 'production',
901
+ profile: previewOptions.profile,
902
+ browser: vendor,
903
+ chromiumBinary: previewOptions.chromiumBinary,
904
+ geckoBinary: previewOptions.geckoBinary,
905
+ startingUrl: previewOptions.startingUrl,
906
+ port: previewOptions.port,
907
+ source: 'string' == typeof previewOptions.source ? previewOptions.source : previewOptions.source,
908
+ watchSource: previewOptions.watchSource,
909
+ logLevel: logsOption || previewOptions.logLevel || 'off',
910
+ logContexts,
911
+ logFormat: previewOptions.logFormat || 'pretty',
912
+ logTimestamps: false !== previewOptions.logTimestamps,
913
+ logColor: false !== previewOptions.logColor,
914
+ logUrl: previewOptions.logUrl,
915
+ logTab: previewOptions.logTab
916
+ });
917
+ telemetry.track('cli_vendor_finish', {
918
+ command: 'preview',
919
+ vendor,
920
+ duration_ms: Date.now() - vendorStart
921
+ });
922
+ }
923
+ telemetry.track('cli_command_finish', {
844
924
  command: 'preview',
845
- vendor,
846
- duration_ms: Date.now() - vendorStart
925
+ duration_ms: Date.now() - cmdStart,
926
+ success: 0 === process.exitCode || null == process.exitCode,
927
+ exit_code: process.exitCode ?? 0
847
928
  });
848
- }
849
- telemetry.track('cli_command_finish', {
850
- command: 'preview',
851
- duration_ms: Date.now() - cmdStart,
852
- success: 0 === process.exitCode || null == process.exitCode,
853
- exit_code: process.exitCode ?? 0
854
- });
855
- });
856
- }
857
- function registerBuildCommand(program, telemetry) {
858
- program.command('build').arguments('[project-name]').usage('build [path-to-remote-extension] [options]').description(commandDescriptions.build).option('--browser <chrome | chromium | edge | firefox | chromium-based | gecko-based | firefox-based>', 'specify a browser/engine to run. Defaults to `chromium`').option('--polyfill [boolean]', 'whether or not to apply the cross-browser polyfill. Defaults to `false`').option('--zip [boolean]', 'whether or not to compress the extension into a ZIP file. Defaults to `false`').option('--zip-source [boolean]', 'whether or not to include the source files in the ZIP file. Defaults to `false`').option('--zip-filename <string>', 'specify the name of the ZIP file. Defaults to the extension name and version').option('--silent [boolean]', 'whether or not to open the browser automatically. Defaults to `false`').option('--author, --author-mode', '[internal] enable maintainer diagnostics (does not affect user runtime logs)').action(async function(pathOrRemoteUrl, { browser = 'chromium', ...buildOptions }) {
859
- if (buildOptions.author || buildOptions['authorMode']) {
860
- process.env.EXTENSION_AUTHOR_MODE = 'true';
861
- if (!process.env.EXTENSION_VERBOSE) process.env.EXTENSION_VERBOSE = '1';
862
- }
863
- const cmdStart = Date.now();
864
- telemetry.track('cli_command_start', {
865
- command: 'build',
866
- vendors: vendors(browser),
867
- polyfill_used: buildOptions.polyfill || false,
868
- zip: buildOptions.zip || false,
869
- zip_source: buildOptions.zipSource || false
870
929
  });
871
- const list = vendors(browser);
872
- validateVendorsOrExit(list, (invalid, supported)=>{
873
- console.error(unsupportedBrowserFlag(invalid, supported));
874
- });
875
- const { extensionBuild } = await import("extension-develop");
876
- for (const vendor of list){
877
- const vendorStart = Date.now();
878
- telemetry.track('cli_vendor_start', {
930
+ }
931
+ function registerBuildCommand(program, telemetry) {
932
+ program.command('build').arguments('[project-name]').usage('build [path-to-remote-extension] [options]').description(commandDescriptions.build).option('--browser <chrome | chromium | edge | firefox | chromium-based | gecko-based | firefox-based>', 'specify a browser/engine to run. Defaults to `chromium`').option('--polyfill [boolean]', 'whether or not to apply the cross-browser polyfill. Defaults to `false`').option('--zip [boolean]', 'whether or not to compress the extension into a ZIP file. Defaults to `false`').option('--zip-source [boolean]', 'whether or not to include the source files in the ZIP file. Defaults to `false`').option('--zip-filename <string>', 'specify the name of the ZIP file. Defaults to the extension name and version').option('--silent [boolean]', 'whether or not to open the browser automatically. Defaults to `false`').option('--install [boolean]', '[internal] install project dependencies when missing', parseOptionalBoolean).option('--author, --author-mode', '[internal] enable maintainer diagnostics (does not affect user runtime logs)').action(async function(pathOrRemoteUrl, { browser = 'chromium', ...buildOptions }) {
933
+ if (buildOptions.author || buildOptions['authorMode']) {
934
+ process.env.EXTENSION_AUTHOR_MODE = 'true';
935
+ if (!process.env.EXTENSION_VERBOSE) process.env.EXTENSION_VERBOSE = '1';
936
+ }
937
+ const cmdStart = Date.now();
938
+ telemetry.track('cli_command_start', {
879
939
  command: 'build',
880
- vendor
881
- });
882
- const buildSummary = await extensionBuild(pathOrRemoteUrl, {
883
- browser: vendor,
884
- polyfill: buildOptions.polyfill,
885
- zip: buildOptions.zip,
886
- zipSource: buildOptions.zipSource,
887
- zipFilename: buildOptions.zipFilename,
888
- silent: buildOptions.silent
940
+ vendors: vendors(browser),
941
+ polyfill_used: buildOptions.polyfill || false,
942
+ zip: buildOptions.zip || false,
943
+ zip_source: buildOptions.zipSource || false
889
944
  });
890
- telemetry.track('cli_build_summary', {
891
- ...buildSummary
945
+ const list = vendors(browser);
946
+ validateVendorsOrExit(list, (invalid, supported)=>{
947
+ console.error(unsupportedBrowserFlag(invalid, supported));
892
948
  });
893
- telemetry.track('cli_vendor_finish', {
949
+ const { extensionBuild } = await import("extension-develop");
950
+ for (const vendor of list){
951
+ const vendorStart = Date.now();
952
+ telemetry.track('cli_vendor_start', {
953
+ command: 'build',
954
+ vendor
955
+ });
956
+ const buildSummary = await extensionBuild(pathOrRemoteUrl, {
957
+ browser: vendor,
958
+ polyfill: buildOptions.polyfill,
959
+ zip: buildOptions.zip,
960
+ zipSource: buildOptions.zipSource,
961
+ zipFilename: buildOptions.zipFilename,
962
+ silent: buildOptions.silent,
963
+ install: buildOptions.install
964
+ });
965
+ telemetry.track('cli_build_summary', {
966
+ ...buildSummary
967
+ });
968
+ telemetry.track('cli_vendor_finish', {
969
+ command: 'build',
970
+ vendor,
971
+ duration_ms: Date.now() - vendorStart
972
+ });
973
+ }
974
+ telemetry.track('cli_command_finish', {
894
975
  command: 'build',
895
- vendor,
896
- duration_ms: Date.now() - vendorStart
976
+ duration_ms: Date.now() - cmdStart,
977
+ success: 0 === process.exitCode || null == process.exitCode,
978
+ exit_code: process.exitCode ?? 0
897
979
  });
898
- }
899
- telemetry.track('cli_command_finish', {
900
- command: 'build',
901
- duration_ms: Date.now() - cmdStart,
902
- success: 0 === process.exitCode || null == process.exitCode,
903
- exit_code: process.exitCode ?? 0
904
980
  });
981
+ }
982
+ const cliPackageJson = getCliPackageJson();
983
+ function developVersion() {
984
+ try {
985
+ const pkg = __webpack_require__("extension-develop/package.json");
986
+ return pkg?.version || cliPackageJson.version;
987
+ } catch {
988
+ return cliPackageJson.version;
989
+ }
990
+ }
991
+ process.env.EXTENSION_DEVELOP_VERSION = developVersion();
992
+ check_updates_checkUpdates().then((updateMessage)=>{
993
+ if (!updateMessage) return;
994
+ if ('true' === process.env.EXTENSION_CLI_BANNER_PRINTED) return void console.log(updateMessage.message);
995
+ process.env.EXTENSION_CLI_UPDATE_SUFFIX = updateMessage.suffix;
905
996
  });
906
- }
907
- const cliPackageJson = getCliPackageJson();
908
- process.env.EXTENSION_CLI_VERSION = cliPackageJson.version;
909
- check_updates_checkUpdates().then((updateMessage)=>{
910
- if (!updateMessage) return;
911
- if ('true' === process.env.EXTENSION_CLI_BANNER_PRINTED) return void console.log(updateMessage);
912
- process.env.EXTENSION_CLI_UPDATE_MESSAGE = updateMessage;
913
- });
914
- const extensionJs = external_commander_namespaceObject.program;
915
- extensionJs.name(cliPackageJson.name).description(cliPackageJson.description).version(cliPackageJson.version).option('--no-telemetry', 'disable anonymous telemetry for this run').option('--ai-help', 'show AI-assistant oriented help and tips').addHelpText('after', programUserHelp()).showHelpAfterError(true).showSuggestionAfterError(true);
916
- registerCreateCommand(extensionJs, telemetry_cli_telemetry);
917
- registerDevCommand(extensionJs, telemetry_cli_telemetry);
918
- registerStartCommand(extensionJs, telemetry_cli_telemetry);
919
- registerPreviewCommand(extensionJs, telemetry_cli_telemetry);
920
- registerBuildCommand(extensionJs, telemetry_cli_telemetry);
921
- extensionJs.on('option:ai-help', function() {
922
- console.log(programAIHelp());
923
- process.exit(0);
924
- });
925
- if (process.argv.length <= 2) {
926
- extensionJs.outputHelp();
927
- process.exit(0);
928
- }
929
- extensionJs.parseAsync().catch((err)=>{
930
- console.error(unhandledError(err));
931
- process.exit(1);
932
- });
997
+ const extensionJs = external_commander_namespaceObject.program;
998
+ extensionJs.name(cliPackageJson.name).description(cliPackageJson.description).version(cliPackageJson.version).option('--no-telemetry', 'disable anonymous telemetry for this run').option('--ai-help', 'show AI-assistant oriented help and tips').addHelpText('after', programUserHelp()).showHelpAfterError(true).showSuggestionAfterError(true);
999
+ registerCreateCommand(extensionJs, telemetry_cli_telemetry);
1000
+ registerDevCommand(extensionJs, telemetry_cli_telemetry);
1001
+ registerStartCommand(extensionJs, telemetry_cli_telemetry);
1002
+ registerPreviewCommand(extensionJs, telemetry_cli_telemetry);
1003
+ registerBuildCommand(extensionJs, telemetry_cli_telemetry);
1004
+ extensionJs.on('option:ai-help', function() {
1005
+ console.log(programAIHelp());
1006
+ process.exit(0);
1007
+ });
1008
+ if (process.argv.length <= 2) {
1009
+ extensionJs.outputHelp();
1010
+ process.exit(0);
1011
+ }
1012
+ extensionJs.parseAsync().catch((err)=>{
1013
+ console.error(unhandledError(err));
1014
+ process.exit(1);
1015
+ });
1016
+ })();
933
1017
  for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
934
1018
  Object.defineProperty(exports, '__esModule', {
935
1019
  value: true