extension 2.1.3 → 3.0.0-next.29

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,22 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
- var __webpack_modules__ = {
4
- "extension-develop": function(module) {
5
- module.exports = import("extension-develop").then(function(module) {
6
- return module;
7
- });
8
- }
9
- };
10
- var __webpack_module_cache__ = {};
11
- function __webpack_require__(moduleId) {
12
- var cachedModule = __webpack_module_cache__[moduleId];
13
- if (void 0 !== cachedModule) return cachedModule.exports;
14
- var module = __webpack_module_cache__[moduleId] = {
15
- exports: {}
16
- };
17
- __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
18
- return module.exports;
19
- }
3
+ var __webpack_require__ = {};
20
4
  (()=>{
21
5
  __webpack_require__.n = (module)=>{
22
6
  var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
@@ -38,27 +22,29 @@ function __webpack_require__(moduleId) {
38
22
  __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
39
23
  })();
40
24
  var __webpack_exports__ = {};
41
- (()=>{
42
- const external_commander_namespaceObject = require("commander");
43
- const external_extension_create_namespaceObject = require("extension-create");
44
- const external_pintor_namespaceObject = require("pintor");
45
- var external_pintor_default = /*#__PURE__*/ __webpack_require__.n(external_pintor_namespaceObject);
46
- function getLoggingPrefix(type) {
47
- if ('error' === type) return external_pintor_default().red('ERROR');
48
- if ('warn' === type) return external_pintor_default().brightYellow("\u25BA\u25BA\u25BA");
49
- if ('info' === type) return external_pintor_default().blue("\u25BA\u25BA\u25BA");
50
- return external_pintor_default().green("\u25BA\u25BA\u25BA");
51
- }
52
- const code = (text)=>external_pintor_default().blue(text);
53
- const arg = (text)=>external_pintor_default().gray(text);
54
- function updateFailed(err) {
55
- return `${getLoggingPrefix('error')} Failed to check for updates.\n${external_pintor_default().red(String((null == err ? void 0 : err.message) || err))}`;
56
- }
57
- function checkUpdates(packageJson, update) {
58
- return `${external_pintor_default().blue('Extension.js')} update available.\nYou are currently using version ${external_pintor_default().gray(String(packageJson.version))}. Latest stable is ${external_pintor_default().gray(String(update.latest))}. Please update to enjoy new features and improvements.`;
59
- }
60
- function programUserHelp() {
61
- return `\n${getLoggingPrefix('info')} ${external_pintor_default().underline('Help center for the Extension.js program')}
25
+ const external_commander_namespaceObject = require("commander");
26
+ var package_namespaceObject = JSON.parse('{"license":"MIT","repository":{"type":"git","url":"git+https://github.com/extension-js/extension.js.git","directory":"programs/cli"},"engines":{"node":">=18"},"exports":{".":{"types":"./dist/cli.d.ts","import":"./dist/cli.js","require":"./dist/cli.js"}},"main":"./dist/cli.js","types":"./dist/cli.d.ts","typesVersions":{"*":{"types":["./types/index.d.ts"],"types/*":["./types/*"]}},"files":["dist","types"],"bin":{"extension":"./dist/cli.js"},"name":"extension","version":"3.0.0-next.29","description":"Create cross-browser extensions with no build configuration.","homepage":"https://extension.js.org/","author":{"name":"Cezar Augusto","email":"boss@cezaraugusto.net","url":"https://cezaraugusto.com"},"publishConfig":{"access":"public","registry":"https://registry.npmjs.org"},"scripts":{"prepare":"rslib build >/dev/null 2>&1 || true","postinstall":"rslib build >/dev/null 2>&1 || true","compile":"rslib build","watch":"rslib build --watch","test":"vitest run"},"keywords":["zero-config","build","develop","browser","extension","chrome extension","edge extension","firefox extension","safari extension","web","react","typescript","webextension","browser-extension","chrome-extension","firefox-addon","edge-extension","safari-web-extension","manifest-v3","mv3","cross-browser","content-script","background-script","devtools","create-extension","scaffold","starter-template","boilerplate","cli"],"dependencies":{"commander":"^12.1.0","extension-create":"^2.2.0","pintor":"0.3.0","semver":"^7.6.3","update-check":"^1.5.4"},"devDependencies":{"@rslib/core":"^0.6.9","@types/chrome":"^0.0.287","@types/node":"^22.10.1","@types/react":"^19.0.1","@types/react-dom":"^19.0.1","@types/webextension-polyfill":"0.12.3","@types/mock-fs":"^4.13.4","@types/semver":"^7.5.8","mock-fs":"^5.4.1","webextension-polyfill":"^0.12.0","tsconfig":"*","typescript":"5.7.2","vitest":"^3.2.4"}}');
27
+ const external_update_check_namespaceObject = require("update-check");
28
+ var external_update_check_default = /*#__PURE__*/ __webpack_require__.n(external_update_check_namespaceObject);
29
+ const external_pintor_namespaceObject = require("pintor");
30
+ var external_pintor_default = /*#__PURE__*/ __webpack_require__.n(external_pintor_namespaceObject);
31
+ function getLoggingPrefix(type) {
32
+ if ('true' === process.env.EXTENSION_AUTHOR_MODE) return external_pintor_default().brightMagenta('error' === type ? 'ERROR' : "\u25BA\u25BA\u25BA");
33
+ if ('error' === type) return external_pintor_default().red('ERROR');
34
+ if ('warn' === type) return external_pintor_default().brightYellow("\u25BA\u25BA\u25BA");
35
+ if ('info' === type) return external_pintor_default().gray("\u25BA\u25BA\u25BA");
36
+ return external_pintor_default().green("\u25BA\u25BA\u25BA");
37
+ }
38
+ const code = (text)=>external_pintor_default().blue(text);
39
+ const arg = (text)=>external_pintor_default().gray(text);
40
+ function updateFailed(err) {
41
+ return `${getLoggingPrefix('error')} Failed to check for updates.\n${external_pintor_default().red(String((null == err ? void 0 : err.message) || err))}`;
42
+ }
43
+ function checkUpdates(packageJson, update) {
44
+ return `${getLoggingPrefix('info')} \u{1F9E9} ${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))}.\nPlease update to enjoy new features and improvements.`;
45
+ }
46
+ function programUserHelp() {
47
+ return `\n${getLoggingPrefix('info')} ${external_pintor_default().underline('Help center for the Extension.js program')}
62
48
 
63
49
  Usage: extension [command] [options]
64
50
 
@@ -88,52 +74,103 @@ Available Commands
88
74
  Cleans up orphaned instances and frees unused ports
89
75
 
90
76
  Common Options
91
- - ${code('--browser')} ${arg('<chrome|edge|firefox>')} Target browser (default: chrome)
77
+ - ${code('--browser')} ${arg('<chrome|edge|firefox|chromium|chromium-based|gecko-based|firefox-based>')} Target browser/engine (default: chrome)
92
78
  - ${code('--profile')} ${arg('<path|boolean>')} Browser profile configuration
93
79
  - ${code('--polyfill')} ${arg('[boolean]')} Enable/disable cross-browser polyfill
80
+ - ${code('--no-telemetry')} Disable anonymous telemetry for this run
94
81
  - ${code('--port')} ${arg('<number>')} Development server port (default: 8080)
95
82
  - ${code('--starting-url')} ${arg('<url>')} Initial URL to load in browser
96
83
  - ${code('--silent')} ${arg('[boolean]')} Suppress console output during build
97
84
 
98
85
  Source Inspection
99
- - ${code('--source')} ${arg('<url>')} Open URL and print HTML after content scripts inject
100
- - ${code('--watch-source')} Monitor rebuild events and print HTML on reloads
86
+ - ${code('--source')} ${arg('<url|boolean>')} Open URL and print HTML after content scripts inject
87
+ - When provided without a URL, falls back to ${arg('--starting-url')} or ${arg('https://example.com')}
88
+ - Watch mode is enabled by default when ${code('--source')} is present
101
89
 
102
90
  Browser-Specific Options
103
91
  - ${code('--chromium-binary')} ${arg('<path>')} Custom Chromium binary path
104
- - ${code('--gecko-binary')} ${arg('<path>')} Custom Firefox/Gecko binary path
92
+ - ${code('--gecko-binary')}/${code('--firefox-binary')} ${arg('<path>')} Custom Firefox/Gecko binary path
105
93
 
106
94
  Build Options
107
95
  - ${code('--zip')} ${arg('[boolean]')} Create ZIP archive of built extension
108
96
  - ${code('--zip-source')} ${arg('[boolean]')} Include source files in ZIP
109
97
  - ${code('--zip-filename')} ${arg('<name>')} Custom ZIP filename
110
98
 
99
+ ${external_pintor_default().underline('Centralized Logger (terminal output)')}
100
+ - The manager extension embeds a centralized logger that streams events to the CLI.
101
+ - Enable and filter logs directly via ${code('extension dev')} flags:
102
+ - ${code('--logs')} ${arg('<off|error|warn|info|debug|trace>')} Minimum level (default: info)
103
+ - ${code('--log-context')} ${arg('<list|all>')} Contexts: background,content,page,sidebar,popup,options,devtools
104
+ - ${code('--log-format')} ${arg('<pretty|json>')} Output format (default: pretty)
105
+ - ${code('--no-log-timestamps')} Hide ISO timestamps in pretty output
106
+ - ${code('--no-log-color')} Disable color in pretty output
107
+ - ${code('--log-url')} ${arg('<substring|/regex/>')} Filter by event.url
108
+ - ${code('--log-tab')} ${arg('<id>')} Filter by tabId
109
+ - Example: ${code('extension dev ./my-ext --logs=debug --log-context=all --log-format=pretty')}
110
+
111
111
  ${code('extension --help')}
112
112
  This command outputs a help file with key command options.
113
113
 
114
+ ${external_pintor_default().underline('Path Resolution (important)')}
115
+ - Leading ${code('/')} in manifest/HTML means extension root (the directory containing ${code('manifest.json')}).
116
+ - Relative paths resolve from the ${code('manifest.json')} directory.
117
+ - Absolute OS paths are used as-is.
118
+
119
+
114
120
  AI Assistants
115
121
  - For AI-oriented guidance and deep-dive tips, run ${code('extension --ai-help')}
116
122
 
117
123
  Report issues
118
124
  - ${external_pintor_default().underline('https://github.com/cezaraugusto/extension/issues/new')}`;
119
- }
120
- function unsupportedBrowserFlag(value, supported) {
121
- return `${getLoggingPrefix('error')} Unsupported --browser value: ${value}. Supported: ${supported.join(', ')}.`;
122
- }
123
- function programAIHelp() {
124
- return `\n${getLoggingPrefix('info')} ${external_pintor_default().gray('Development tips for extension developers and AI assistants')}
125
+ }
126
+ function unsupportedBrowserFlag(value, supported) {
127
+ return `${getLoggingPrefix('error')} Unsupported --browser value: ${value}. Supported: ${supported.join(', ')}.`;
128
+ }
129
+ function programAIHelp() {
130
+ return `\n${getLoggingPrefix('info')} ${external_pintor_default().gray('Development tips for extension developers and AI assistants')}
125
131
 
126
132
  Browser-Specific Configuration
127
133
  - Use browser prefixes in manifest.json for browser-specific fields:
128
134
  ${code('{"firefox:manifest": 2, "chrome:manifest": 3}')}
129
135
  This applies manifest v2 to Firefox only, v3 to Chrome/Edge.
130
136
 
137
+ Centralized Logger (for AI & CI)
138
+ - Logs from all contexts are centralized by the manager extension and streamed to the CLI.
139
+ - Prefer these flags to control terminal logs during ${code('extension dev')}:
140
+ - ${code('--logs')} ${arg('<off|error|warn|info|debug|trace>')} Minimum level
141
+ - ${code('--log-context')} ${arg('<list|all>')} Contexts to include
142
+ - ${code('--log-format')} ${arg('<pretty|json>')} Pretty for humans; JSON for machines/NDJSON pipelines
143
+ - ${code('--no-log-timestamps')} ${arg(' ')} Disable timestamps (pretty)
144
+ - ${code('--no-log-color')} ${arg(' ')} Disable ANSI colors (pretty)
145
+ - ${code('--log-url')} ${arg('<substring|/regex/>')} Filter by URL
146
+ - ${code('--log-tab')} ${arg('<id>')} Filter by tabId
147
+ - Good CI pattern: ${code('EXTENSION_AUTHOR_MODE=development EXTENSION_AUTO_EXIT_MS=6000 extension dev ./ext --logs=info --log-format=json')}
148
+
131
149
  Special Folders for Entrypoints
132
150
  - Use special folders to handle entrypoints and assets not declared in manifest.json:
133
151
  - ${external_pintor_default().underline(code('public/'))} - Static assets automatically copied to build (resolves to output root)
134
152
  - ${external_pintor_default().underline(code('pages/'))} - HTML files not declared in manifest (e.g., welcome pages)
135
153
  - ${external_pintor_default().underline(code("scripts/"))} - JavaScript files not declared in manifest (e.g., executable scripts)
136
154
 
155
+ Predictable Output Paths
156
+ - Core HTML destinations are standardized across browsers so you can reference them safely in code/tests:
157
+ - ${code('devtools_page')} \u{2192} ${code('devtools/index.html')}
158
+ - ${code('sidebar_action.default_panel')} (MV2) and ${code('side_panel.default_path')} (MV3) \u{2192} ${code('sidebar/index.html')}
159
+ - ${code('options_ui.page')} and ${code('options_page')} \u{2192} ${code('options/index.html')}
160
+ - ${code('background.page')} \u{2192} ${code('background/index.html')}
161
+ - ${code('action.default_popup')}, ${code('browser_action.default_popup')}, ${code('page_action.default_popup')} \u{2192} ${code('action/index.html')}
162
+ - Other predictable outputs:
163
+ - ${code('chrome_url_overrides.*')} \u{2192} ${code('chrome_url_overrides/<key>.html')}
164
+ - ${code("content_scripts[n].js/css")} \u{2192} ${code("content_scripts/content-<n>.{js,css}")}
165
+ - ${code('sandbox.pages[]')} \u{2192} ${code('sandbox/page-<n>.html')}
166
+ - ${code("user_scripts.api_script")} \u{2192} ${code("user_scripts/api_script.js")}
167
+ - ${code('icons/*')} \u{2192} ${code('icons/')} (feature-specific icon folders preserved where applicable)
168
+
169
+ Public & Special Folders (Output Behavior)
170
+ - ${external_pintor_default().underline(code('public/'))} is the web root in output. Authors can use ${code('/foo')}, ${code('/public/foo')}, ${code('public/foo')}, or ${code('./public/foo')} and they all emit as ${code('dist/<browser>/foo')}.
171
+ - ${external_pintor_default().underline(code('pages/'))} files emit as ${code('pages/<name>.html')}. Relative assets referenced inside page HTML are emitted under ${code('assets/')} preserving relative structure; public-root URLs are preserved.
172
+ - ${external_pintor_default().underline(code("scripts/"))} files emit as ${code("scripts/<name>.js")} with extracted CSS when applicable.
173
+
137
174
  Shadow DOM for Content Scripts
138
175
  - Add ${code('use shadow-dom')} directive to content scripts for style isolation
139
176
  - Automatically creates ${code('#extension-root')} element with shadow DOM
@@ -191,15 +228,16 @@ Hot Module Replacement (HMR)
191
228
  - Service workers, _locales and manifest changes reload the extension
192
229
 
193
230
  Source Inspection & Real-Time Monitoring
194
- - Use ${code('--source')} ${arg('<url>')} to inspect page HTML after content script injection
195
- - Use ${code('--watch-source')} to monitor real-time changes in stdout
231
+ - Use ${code('--source')} ${arg('<url|boolean>')} to inspect page HTML after content script injection
232
+ - When no URL is provided, falls back to ${arg('--starting-url')} or ${arg('https://example.com')}
233
+ - Watch mode is enabled by default when ${code('--source')} is present
196
234
  - Automatically enables Chrome remote debugging (port 9222) when source inspection is active
197
- - Extracts Shadow DOM content from ${code('#extension-root')} elements
235
+ - Extracts Shadow DOM content from ${code('#extension-root')} or ${code('[data-extension-root=\"true\"]')} elements
198
236
  - Perfect for debugging content script behavior and style injection
199
- - Example: ${code('extension dev --source=' + arg('https://example.com') + ' --watch-source')}
237
+ - Example: ${code('extension dev --source=' + arg('https://example.com'))}
200
238
 
201
239
  Non-Destructive Testing in CI
202
- - Prefer ${code('EXTENSION_ENV=development')} to copy local templates and avoid network.
240
+ - Prefer ${code('EXTENSION_AUTHOR_MODE=development')} to copy local templates and avoid network.
203
241
  - Reuse Playwright's Chromium via ${code('--chromium-binary')} path when available.
204
242
  - Set ${code(arg('EXTENSION_AUTO_EXIT_MS'))} and ${code(arg('EXTENSION_FORCE_KILL_MS'))} for non-interactive dev sessions.
205
243
 
@@ -222,123 +260,757 @@ Cross-Browser Compatibility
222
260
  - Use ${code('--polyfill')} flag to enable webextension-polyfill
223
261
  - Automatically handles browser API differences
224
262
  - Supports Chrome, Edge, Firefox with single codebase`;
263
+ }
264
+ const external_semver_namespaceObject = require("semver");
265
+ function isStableVersion(version) {
266
+ const v = external_semver_namespaceObject.parse(version);
267
+ return Boolean(v && 0 === v.prerelease.length);
268
+ }
269
+ async function check_updates_checkUpdates(packageJson) {
270
+ let update = null;
271
+ try {
272
+ update = await external_update_check_default()(packageJson);
273
+ } catch (err) {
274
+ if ('true' === process.env.EXTENSION_AUTHOR_MODE) console.error(updateFailed(err));
225
275
  }
226
- const external_update_check_namespaceObject = require("update-check");
227
- var external_update_check_default = /*#__PURE__*/ __webpack_require__.n(external_update_check_namespaceObject);
228
- function isStableVersion(version) {
229
- return !/[a-zA-Z]/.test(version);
276
+ if (update && isStableVersion(update.latest)) console.log(checkUpdates(packageJson, update));
277
+ }
278
+ const external_fs_namespaceObject = require("fs");
279
+ var external_fs_default = /*#__PURE__*/ __webpack_require__.n(external_fs_namespaceObject);
280
+ const external_path_namespaceObject = require("path");
281
+ var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
282
+ const external_node_os_namespaceObject = require("node:os");
283
+ var external_node_os_default = /*#__PURE__*/ __webpack_require__.n(external_node_os_namespaceObject);
284
+ const external_node_fs_namespaceObject = require("node:fs");
285
+ var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
286
+ const external_node_path_namespaceObject = require("node:path");
287
+ var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
288
+ const external_node_crypto_namespaceObject = require("node:crypto");
289
+ var external_node_crypto_default = /*#__PURE__*/ __webpack_require__.n(external_node_crypto_namespaceObject);
290
+ function _define_property(obj, key, value) {
291
+ if (key in obj) Object.defineProperty(obj, key, {
292
+ value: value,
293
+ enumerable: true,
294
+ configurable: true,
295
+ writable: true
296
+ });
297
+ else obj[key] = value;
298
+ return obj;
299
+ }
300
+ function isCI() {
301
+ const v = process.env;
302
+ return Boolean(v.CI || v.GITHUB_ACTIONS || v.GITLAB_CI || v.BUILDKITE || v.CIRCLECI || v.TRAVIS);
303
+ }
304
+ function configDir() {
305
+ const xdg = process.env.XDG_CONFIG_HOME;
306
+ if (xdg) return external_node_path_default().join(xdg, 'extensionjs');
307
+ if ('win32' === process.platform && process.env.APPDATA) return external_node_path_default().join(process.env.APPDATA, 'extensionjs');
308
+ return external_node_path_default().join(external_node_os_default().homedir(), '.config', 'extensionjs');
309
+ }
310
+ function ensureDir(p) {
311
+ if (external_node_fs_default().existsSync(p)) return;
312
+ external_node_fs_default().mkdirSync(p, {
313
+ recursive: true
314
+ });
315
+ }
316
+ function loadOrCreateId(file) {
317
+ if (external_node_fs_default().existsSync(file)) return external_node_fs_default().readFileSync(file, 'utf8').trim();
318
+ const id = external_node_crypto_default().randomUUID();
319
+ ensureDir(external_node_path_default().dirname(file));
320
+ external_node_fs_default().writeFileSync(file, id, 'utf8');
321
+ return id;
322
+ }
323
+ function auditFilePath() {
324
+ const dir = external_node_path_default().join(configDir(), 'telemetry');
325
+ ensureDir(dir);
326
+ return external_node_path_default().join(dir, 'events.jsonl');
327
+ }
328
+ const DEFAULT_FLUSH_AT = Number(process.env.EXTENSION_TELEMETRY_FLUSH_AT || 10);
329
+ const DEFAULT_FLUSH_INTERVAL = Number(process.env.EXTENSION_TELEMETRY_FLUSH_INTERVAL || 2000);
330
+ const DEFAULT_TIMEOUT_MS = Number(process.env.EXTENSION_TELEMETRY_TIMEOUT_MS || 200);
331
+ class Telemetry {
332
+ track(event, props = {}) {
333
+ if (this.disabled) return;
334
+ const payload = {
335
+ event,
336
+ properties: {
337
+ ...this.common,
338
+ ...props,
339
+ $ip: null
340
+ },
341
+ distinct_id: this.anonId
342
+ };
343
+ external_node_fs_default().appendFileSync(auditFilePath(), JSON.stringify(payload) + '\n');
344
+ if (this.debug) console.error('[telemetry]', JSON.stringify(payload));
345
+ if (!this.apiKey || !this.host) return;
346
+ this.buffer.push(payload);
347
+ if (this.buffer.length >= DEFAULT_FLUSH_AT) return void this.flush();
348
+ if (!this.timer) this.timer = setTimeout(()=>{
349
+ this.timer = null;
350
+ this.flush();
351
+ }, DEFAULT_FLUSH_INTERVAL);
230
352
  }
231
- async function check_updates_checkUpdates(packageJson) {
232
- let update = null;
353
+ async flush() {
354
+ if (this.disabled || !this.apiKey || !this.host) return;
355
+ if (0 === this.buffer.length) return;
356
+ const batch = this.buffer.splice(0, this.buffer.length);
233
357
  try {
234
- update = await external_update_check_default()(packageJson);
235
- } catch (err) {
236
- if ('development' === process.env.EXTENSION_ENV) console.error(updateFailed(err));
358
+ const ac = new AbortController();
359
+ const t = setTimeout(()=>ac.abort(), DEFAULT_TIMEOUT_MS);
360
+ const url = new URL('/capture/', this.host);
361
+ await fetch(url.toString(), {
362
+ method: 'POST',
363
+ headers: {
364
+ 'content-type': 'application/json'
365
+ },
366
+ body: JSON.stringify({
367
+ api_key: this.apiKey,
368
+ batch: batch.map((e)=>({
369
+ event: e.event,
370
+ properties: e.properties,
371
+ distinct_id: e.distinct_id
372
+ }))
373
+ }),
374
+ signal: ac.signal,
375
+ keepalive: true
376
+ }).catch(()=>{});
377
+ clearTimeout(t);
378
+ } catch {}
379
+ }
380
+ shutdown() {}
381
+ constructor(init){
382
+ _define_property(this, "anonId", void 0);
383
+ _define_property(this, "common", void 0);
384
+ _define_property(this, "debug", void 0);
385
+ _define_property(this, "disabled", void 0);
386
+ _define_property(this, "apiKey", void 0);
387
+ _define_property(this, "host", void 0);
388
+ _define_property(this, "buffer", []);
389
+ _define_property(this, "timer", null);
390
+ this.debug = '1' === process.env.EXTENSION_TELEMETRY_DEBUG;
391
+ this.disabled = Boolean(init.disabled);
392
+ this.anonId = 'disabled';
393
+ if (!this.disabled) {
394
+ const idFile = external_node_path_default().join(configDir(), 'telemetry', 'anonymous-id');
395
+ this.anonId = loadOrCreateId(idFile);
396
+ }
397
+ this.common = {
398
+ app: init.app,
399
+ version: init.version,
400
+ os: process.platform,
401
+ arch: process.arch,
402
+ node: process.versions.node,
403
+ is_ci: isCI(),
404
+ schema_version: 1
405
+ };
406
+ this.apiKey = init.apiKey || process.env.EXTENSION_PUBLIC_POSTHOG_KEY;
407
+ this.host = init.host || process.env.EXTENSION_PUBLIC_POSTHOG_HOST;
408
+ if (!this.disabled) {
409
+ const consentPath = external_node_path_default().join(configDir(), 'telemetry', 'consent');
410
+ if (!external_node_fs_default().existsSync(consentPath)) {
411
+ external_node_fs_default().writeFileSync(consentPath, 'ok', 'utf8');
412
+ this.track('cli_telemetry_consent', {
413
+ value: 'implicit_opt_in'
414
+ });
415
+ console.log('[extension] anonymous telemetry helps us improve. Pass --no-telemetry to opt out. Read more in TELEMETRY.md.');
416
+ }
237
417
  }
238
- if (update && isStableVersion(update.latest)) console.log(checkUpdates(packageJson, update));
239
418
  }
240
- var package_namespaceObject = JSON.parse('{"license":"MIT","repository":{"type":"git","url":"https://github.com/extension-js/extension.js.git","directory":"programs/cli"},"engines":{"node":">=18"},"exports":{".":{"types":"./dist/cli.d.ts","import":"./dist/cli.js","require":"./dist/cli.js"}},"main":"./dist/cli.js","types":"./dist/cli.d.ts","files":["dist","types"],"bin":{"extension":"./dist/cli.js"},"name":"extension","version":"2.1.3","description":"Create cross-browser extensions with no build configuration.","homepage":"https://extension.js.org/","author":{"name":"Cezar Augusto","email":"boss@cezaraugusto.net","url":"https://cezaraugusto.com"},"publishConfig":{"access":"public","registry":"https://registry.npmjs.org","tag":"latest"},"scripts":{"watch":"rslib build --watch","compile":"rslib build","clean":"rm -rf dist","test":"echo \\"Note: no test specified\\" && exit 0","test:cli":"vitest run"},"keywords":["zero-config","build","develop","browser","extension","chrome extension","edge extension","firefox extension","safari extension","web","react","typescript","webextension","browser-extension","chrome-extension","firefox-addon","edge-extension","safari-web-extension","manifest-v3","mv3","cross-browser","content-script","background-script","devtools","create-extension","scaffold","starter-template","boilerplate","cli"],"dependencies":{"@types/chrome":"^0.0.287","@types/node":"^22.10.1","@types/react":"^19.0.1","@types/react-dom":"^19.0.1","@types/webextension-polyfill":"0.12.3","commander":"^12.1.0","extension-create":"workspace:*","extension-develop":"workspace:*","pintor":"0.3.0","semver":"^7.6.3","update-check":"^1.5.4","webextension-polyfill":"^0.12.0"},"devDependencies":{"@rslib/core":"^0.6.9","@types/mock-fs":"^4.13.4","@types/semver":"^7.5.8","mock-fs":"^5.4.1","tsconfig":"*","typescript":"5.7.2","vitest":"3.2.2"}}');
241
- function parseOptionalBoolean(value) {
242
- if (void 0 === value) return true;
243
- const normalized = String(value).trim().toLowerCase();
244
- return ![
245
- 'false',
246
- '0',
247
- 'no',
248
- 'off'
249
- ].includes(normalized);
419
+ }
420
+ function summarizeManifest(manifest) {
421
+ var _manifest_action;
422
+ const mv = (null == manifest ? void 0 : manifest.manifest_version) === 2 ? 2 : 3;
423
+ const permissions = Array.isArray(null == manifest ? void 0 : manifest.permissions) ? manifest.permissions : [];
424
+ const optionalPermissions = Array.isArray(null == manifest ? void 0 : manifest.optional_permissions) ? manifest.optional_permissions : [];
425
+ const hostPermissions = Array.isArray(null == manifest ? void 0 : manifest.host_permissions) ? manifest.host_permissions : [];
426
+ const usesAllUrls = [
427
+ ...permissions,
428
+ ...hostPermissions
429
+ ].includes('<all_urls>');
430
+ const usesDeclarativeNetRequest = permissions.includes('declarativeNetRequest') || permissions.includes('declarativeNetRequestWithHostAccess');
431
+ const background = null == manifest ? void 0 : manifest.background;
432
+ let backgroundType = 'none';
433
+ if (3 === mv && (null == background ? void 0 : background.service_worker)) backgroundType = 'service_worker';
434
+ else if (2 === mv && (Array.isArray(null == background ? void 0 : background.scripts) && background.scripts.length > 0 || (null == background ? void 0 : background.page))) backgroundType = 'event_page';
435
+ const contentScriptsCount = Array.isArray(null == manifest ? void 0 : manifest.content_scripts) ? manifest.content_scripts.length : 0;
436
+ const hasDevtoolsPage = Boolean(null == manifest ? void 0 : manifest.devtools_page);
437
+ const hasActionPopup = Boolean(null == manifest ? void 0 : null == (_manifest_action = manifest.action) ? void 0 : _manifest_action.default_popup);
438
+ return {
439
+ mv,
440
+ permissions_count: permissions.length,
441
+ optional_permissions_count: optionalPermissions.length,
442
+ host_permissions_count: hostPermissions.length,
443
+ uses_all_urls: usesAllUrls,
444
+ uses_declarative_net_request: usesDeclarativeNetRequest,
445
+ background_type: backgroundType,
446
+ content_scripts_count: contentScriptsCount,
447
+ has_devtools_page: hasDevtoolsPage,
448
+ has_action_popup: hasActionPopup
449
+ };
450
+ }
451
+ function isTelemetryDisabledFromArgs(argv) {
452
+ return argv.includes('--no-telemetry');
453
+ }
454
+ const telemetryDisabled = isTelemetryDisabledFromArgs(process.argv);
455
+ const telemetry_cli_telemetry = new Telemetry({
456
+ app: 'extension',
457
+ version: package_namespaceObject.version,
458
+ disabled: telemetryDisabled
459
+ });
460
+ if (!telemetryDisabled) {
461
+ const startedAt = Date.now();
462
+ const known = new Set([
463
+ 'create',
464
+ 'dev',
465
+ 'start',
466
+ 'preview',
467
+ 'build',
468
+ 'cleanup'
469
+ ]);
470
+ const invoked = process.argv.slice(2).find((a)=>known.has(a)) || 'unknown';
471
+ telemetry_cli_telemetry.track('cli_boot', {
472
+ command_guess: invoked
473
+ });
474
+ const cwd = process.cwd();
475
+ const manifestPath = external_path_default().join(cwd, 'manifest.json');
476
+ if (external_fs_default().existsSync(manifestPath)) {
477
+ const raw = external_fs_default().readFileSync(manifestPath, 'utf8');
478
+ const json = JSON.parse(raw);
479
+ const summary = summarizeManifest(json);
480
+ telemetry_cli_telemetry.track('manifest_summary', summary);
481
+ }
482
+ process.on('beforeExit', async function() {
483
+ telemetry_cli_telemetry.track('cli_shutdown', {
484
+ command_guess: invoked,
485
+ duration_ms: Date.now() - startedAt,
486
+ exit_code: process.exitCode ?? 0
487
+ });
488
+ await telemetry_cli_telemetry.flush();
489
+ });
490
+ process.on('uncaughtException', function(err) {
491
+ telemetry_cli_telemetry.track('cli_error', {
492
+ command_guess: invoked,
493
+ error_name: String((null == err ? void 0 : err.name) || 'Error').slice(0, 64)
494
+ });
495
+ });
496
+ process.on('unhandledRejection', function(reason) {
497
+ telemetry_cli_telemetry.track('cli_error', {
498
+ command_guess: invoked,
499
+ error_name: String((null == reason ? void 0 : reason.name) || 'PromiseRejection').slice(0, 64)
500
+ });
501
+ });
502
+ }
503
+ const external_extension_create_namespaceObject = require("extension-create");
504
+ const external_node_child_process_namespaceObject = require("node:child_process");
505
+ const external_node_url_namespaceObject = require("node:url");
506
+ function parseOptionalBoolean(value) {
507
+ if (void 0 === value) return true;
508
+ const normalized = String(value).trim().toLowerCase();
509
+ return ![
510
+ 'false',
511
+ '0',
512
+ 'no',
513
+ 'off'
514
+ ].includes(normalized);
515
+ }
516
+ async function requireOrDlx(moduleName, versionHint) {
517
+ try {
518
+ return await import(moduleName);
519
+ } catch {}
520
+ const spec = versionHint ? `${moduleName}@${versionHint}` : moduleName;
521
+ const cacheDir = external_node_path_default().join(external_node_os_default().tmpdir(), 'extensionjs-cache', spec);
522
+ const modulePath = external_node_path_default().join(cacheDir, 'node_modules', moduleName);
523
+ try {
524
+ const localDist = external_node_path_default().resolve(__dirname, '..', '..', 'develop', 'dist', 'module.js');
525
+ if (external_node_fs_default().existsSync(localDist)) return await import((0, external_node_url_namespaceObject.pathToFileURL)(localDist).href);
526
+ } catch {}
527
+ try {
528
+ const cwdDist = external_node_path_default().resolve(process.cwd(), 'programs', 'develop', 'dist', 'module.js');
529
+ if (external_node_fs_default().existsSync(cwdDist)) return await import((0, external_node_url_namespaceObject.pathToFileURL)(cwdDist).href);
530
+ } catch {}
531
+ let prefer = String(process.env.EXTENSION_DLX || '').trim().toLowerCase();
532
+ const isWin = 'win32' === process.platform;
533
+ const npmCmd = isWin ? 'npm.cmd' : 'npm';
534
+ const pnpmCmd = isWin ? 'pnpm.cmd' : 'pnpm';
535
+ const bunCmd = isWin ? 'bun.exe' : 'bun';
536
+ if (!prefer) try {
537
+ const pnpmCheck = (0, external_node_child_process_namespaceObject.spawnSync)(pnpmCmd, [
538
+ '--version'
539
+ ], {
540
+ stdio: 'ignore'
541
+ });
542
+ if (0 === (pnpmCheck.status || 0)) prefer = 'pnpm';
543
+ } catch {}
544
+ try {
545
+ external_node_fs_default().mkdirSync(cacheDir, {
546
+ recursive: true
547
+ });
548
+ } catch {}
549
+ try {
550
+ var _pkgJson_exports_, _pkgJson_exports, _pkgJson_exports_1, _pkgJson_exports1;
551
+ const pkgJson = JSON.parse(external_node_fs_default().readFileSync(external_node_path_default().join(modulePath, 'package.json'), 'utf8'));
552
+ const main = pkgJson.main || (null == (_pkgJson_exports = pkgJson.exports) ? void 0 : null == (_pkgJson_exports_ = _pkgJson_exports['.']) ? void 0 : _pkgJson_exports_.import) || (null == (_pkgJson_exports1 = pkgJson.exports) ? void 0 : null == (_pkgJson_exports_1 = _pkgJson_exports1['.']) ? void 0 : _pkgJson_exports_1.require);
553
+ if (main) {
554
+ const resolved = (0, external_node_url_namespaceObject.pathToFileURL)(external_node_path_default().join(modulePath, main)).href;
555
+ return await import(resolved);
556
+ }
557
+ } catch {}
558
+ if ('pnpm' === prefer) try {
559
+ external_node_fs_default().writeFileSync(external_node_path_default().join(cacheDir, 'package.json'), JSON.stringify({
560
+ name: 'extensionjs-cache',
561
+ private: true
562
+ }, null, 2));
563
+ } catch {}
564
+ let status = 0;
565
+ if ('pnpm' === prefer) {
566
+ const args = [
567
+ 'add',
568
+ spec,
569
+ '--reporter',
570
+ 'silent',
571
+ '--no-frozen-lockfile'
572
+ ];
573
+ status = (0, external_node_child_process_namespaceObject.spawnSync)(pnpmCmd, args, {
574
+ cwd: cacheDir,
575
+ stdio: 'ignore'
576
+ }).status || 0;
577
+ } else if ('bun' === prefer) {
578
+ const args = [
579
+ 'add',
580
+ spec
581
+ ];
582
+ status = (0, external_node_child_process_namespaceObject.spawnSync)(bunCmd, args, {
583
+ cwd: cacheDir,
584
+ stdio: 'ignore'
585
+ }).status || 0;
586
+ } else {
587
+ const args = [
588
+ 'i',
589
+ spec,
590
+ '--no-fund',
591
+ '--no-audit',
592
+ '--prefer-online',
593
+ '--omit=dev',
594
+ '--omit=optional',
595
+ '--no-package-lock'
596
+ ];
597
+ status = (0, external_node_child_process_namespaceObject.spawnSync)(npmCmd, args, {
598
+ cwd: cacheDir,
599
+ stdio: 'ignore'
600
+ }).status || 0;
601
+ }
602
+ if (0 !== status) {
603
+ try {
604
+ external_node_fs_default().writeFileSync(external_node_path_default().join(cacheDir, 'package.json'), JSON.stringify({
605
+ name: 'extensionjs-cache',
606
+ private: true
607
+ }, null, 2));
608
+ } catch {}
609
+ if ('pnpm' !== prefer) {
610
+ const args = [
611
+ 'add',
612
+ spec,
613
+ '--reporter',
614
+ 'silent',
615
+ '--no-frozen-lockfile'
616
+ ];
617
+ status = (0, external_node_child_process_namespaceObject.spawnSync)(pnpmCmd, args, {
618
+ cwd: cacheDir,
619
+ stdio: 'ignore'
620
+ }).status || 0;
621
+ }
250
622
  }
251
- check_updates_checkUpdates(package_namespaceObject);
252
- const extensionJs = external_commander_namespaceObject.program;
253
- const vendors = (browser)=>'all' === browser ? 'chrome,edge,firefox'.split(',') : browser.split(',');
254
- function validateVendorsOrExit(vendorsList) {
255
- const supported = [
256
- 'chrome',
257
- 'edge',
258
- 'firefox'
623
+ if (0 !== status && 'bun' !== prefer) {
624
+ const args = [
625
+ 'add',
626
+ spec
259
627
  ];
260
- for (const v of vendorsList)if (!supported.includes(v)) {
261
- console.error(unsupportedBrowserFlag(v, supported));
262
- process.exit(1);
628
+ status = (0, external_node_child_process_namespaceObject.spawnSync)(bunCmd, args, {
629
+ cwd: cacheDir,
630
+ stdio: 'ignore'
631
+ }).status || 0;
632
+ }
633
+ if (0 !== status) throw new Error(`Failed to install ${spec}`);
634
+ try {
635
+ var _pkgJson_exports_2, _pkgJson_exports2, _pkgJson_exports_3, _pkgJson_exports3;
636
+ const pkgJson = JSON.parse(external_node_fs_default().readFileSync(external_node_path_default().join(modulePath, 'package.json'), 'utf8'));
637
+ const main = pkgJson.main || (null == (_pkgJson_exports2 = pkgJson.exports) ? void 0 : null == (_pkgJson_exports_2 = _pkgJson_exports2['.']) ? void 0 : _pkgJson_exports_2.import) || (null == (_pkgJson_exports3 = pkgJson.exports) ? void 0 : null == (_pkgJson_exports_3 = _pkgJson_exports3['.']) ? void 0 : _pkgJson_exports_3.require);
638
+ if (main) {
639
+ const resolved = (0, external_node_url_namespaceObject.pathToFileURL)(external_node_path_default().join(modulePath, main)).href;
640
+ return await import(resolved);
263
641
  }
642
+ } catch {}
643
+ return await import((0, external_node_url_namespaceObject.pathToFileURL)(external_node_path_default().join(modulePath, 'dist', 'module.js')).href);
644
+ }
645
+ const vendors = (browser)=>{
646
+ const value = browser ?? 'chromium';
647
+ return 'all' === value ? [
648
+ 'chrome',
649
+ 'edge',
650
+ 'firefox'
651
+ ] : String(value).split(',');
652
+ };
653
+ function validateVendorsOrExit(vendorsList, onInvalid) {
654
+ const supported = [
655
+ 'chrome',
656
+ 'edge',
657
+ 'firefox',
658
+ 'chromium',
659
+ 'chromium-based',
660
+ 'gecko-based',
661
+ 'firefox-based'
662
+ ];
663
+ for (const v of vendorsList)if (!supported.includes(v)) {
664
+ onInvalid(v, supported);
665
+ process.exit(1);
264
666
  }
265
- extensionJs.name(package_namespaceObject.name).description(package_namespaceObject.description).version(package_namespaceObject.version).option('--ai-help', 'show AI-assistant oriented help and tips').addHelpText('after', programUserHelp());
266
- extensionJs.command('create').arguments('<project-name|project-path>').usage('create <project-name|project-path> [options]').description('Creates a new extension.').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 (disabled by default)', parseOptionalBoolean, false).action(async function(pathOrRemoteUrl, { template, install }) {
267
- await (0, external_extension_create_namespaceObject.extensionCreate)(pathOrRemoteUrl, {
268
- template,
269
- install,
270
- cliVersion: package_namespaceObject.version
667
+ }
668
+ function registerCreateCommand(program, telemetry) {
669
+ program.command('create').arguments('<project-name|project-path>').usage('create <project-name|project-path> [options]').description('Creates a new extension.').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 (disabled by default)', parseOptionalBoolean, false).action(async function(pathOrRemoteUrl, { template, install }) {
670
+ const startedAt = Date.now();
671
+ telemetry.track('cli_command_start', {
672
+ command: 'create',
673
+ template: template || 'default',
674
+ install: Boolean(install)
271
675
  });
676
+ try {
677
+ await (0, external_extension_create_namespaceObject.extensionCreate)(pathOrRemoteUrl, {
678
+ template,
679
+ install,
680
+ cliVersion: package_namespaceObject.version
681
+ });
682
+ telemetry.track('cli_command_finish', {
683
+ command: 'create',
684
+ duration_ms: Date.now() - startedAt,
685
+ success: true,
686
+ exit_code: 0
687
+ });
688
+ } catch (err) {
689
+ telemetry.track('cli_command_finish', {
690
+ command: 'create',
691
+ duration_ms: Date.now() - startedAt,
692
+ success: false,
693
+ exit_code: 1
694
+ });
695
+ throw err;
696
+ }
272
697
  });
273
- extensionJs.command('dev').arguments('[project-path|remote-url]').usage('dev [project-path|remote-url] [options]').description('Starts the development server (development mode)').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 | edge | firefox>', 'specify a browser to preview your extension in production mode. Defaults to `chrome`').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 <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('--open [boolean]', 'whether or not to open the browser automatically. Defaults to `true`').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('--source [url]', "opens the provided URL in Chrome and prints the full, live HTML of the page after content scripts are injected").option('--watch-source', 'continuously monitors rebuild events and prints updated HTML whenever the extension reloads and reinjects into the page').action(async function(pathOrRemoteUrl, { browser = 'chrome', ...devOptions }) {
698
+ }
699
+ function registerDevCommand(program, telemetry) {
700
+ program.command('dev').arguments('[project-path|remote-url]').usage('dev [project-path|remote-url] [options]').description('Starts the development server (development mode)').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 }) {
701
+ var _devOptions_polyfill;
702
+ if (devOptions.author || devOptions['authorMode']) {
703
+ process.env.EXTENSION_AUTHOR_MODE = 'true';
704
+ if (!process.env.EXTENSION_VERBOSE) process.env.EXTENSION_VERBOSE = '1';
705
+ }
706
+ const cmdStart = Date.now();
707
+ telemetry.track('cli_command_start', {
708
+ command: 'dev',
709
+ vendors: vendors(browser),
710
+ polyfill_used: (null == (_devOptions_polyfill = devOptions.polyfill) ? void 0 : _devOptions_polyfill.toString()) !== 'false',
711
+ log_level: devOptions.logLevel || 'off',
712
+ log_format: devOptions.logFormat || 'pretty',
713
+ custom_binary_used: Boolean(devOptions.chromiumBinary || devOptions.geckoBinary)
714
+ });
274
715
  const list = vendors(browser);
275
- validateVendorsOrExit(list);
276
- const { extensionDev } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "extension-develop"));
716
+ validateVendorsOrExit(list, (invalid, supported)=>{
717
+ console.error(unsupportedBrowserFlag(invalid, supported));
718
+ });
719
+ if (devOptions.source) {
720
+ const hasExplicitSourceString = 'string' == typeof devOptions.source && 'true' !== String(devOptions.source).trim().toLowerCase();
721
+ const hasStartingUrl = 'string' == typeof devOptions.startingUrl && String(devOptions.startingUrl).trim().length > 0;
722
+ if (!hasExplicitSourceString) devOptions.source = hasStartingUrl ? String(devOptions.startingUrl) : 'https://example.com';
723
+ devOptions.watchSource = true;
724
+ }
725
+ const versionExact = String(package_namespaceObject.version);
726
+ const major = String(package_namespaceObject.version).split('.')[0] || '2';
727
+ let extensionDev;
728
+ try {
729
+ ({ extensionDev } = await requireOrDlx('extension-develop', versionExact));
730
+ } catch {
731
+ ({ extensionDev } = await requireOrDlx('extension-develop', major));
732
+ }
277
733
  for (const vendor of list){
278
- var _devOptions_polyfill;
279
- await extensionDev(pathOrRemoteUrl, {
734
+ var _devOptions_polyfill1;
735
+ const vendorStart = Date.now();
736
+ telemetry.track('cli_vendor_start', {
737
+ command: 'dev',
738
+ vendor
739
+ });
740
+ const logsOption = devOptions.logs;
741
+ const logContextOption = devOptions.logContext;
742
+ const devArgs = {
280
743
  ...devOptions,
281
744
  profile: devOptions.profile,
282
745
  browser: vendor,
283
746
  chromiumBinary: devOptions.chromiumBinary,
284
747
  geckoBinary: devOptions.geckoBinary,
285
- polyfill: (null == (_devOptions_polyfill = devOptions.polyfill) ? void 0 : _devOptions_polyfill.toString()) !== 'false',
748
+ polyfill: (null == (_devOptions_polyfill1 = devOptions.polyfill) ? void 0 : _devOptions_polyfill1.toString()) !== 'false',
286
749
  open: devOptions.open,
287
750
  startingUrl: devOptions.startingUrl,
288
751
  source: devOptions.source,
289
- watchSource: devOptions.watchSource
752
+ watchSource: devOptions.watchSource,
753
+ logLevel: logsOption || devOptions.logLevel || 'off',
754
+ logContexts: (()=>{
755
+ const raw = logContextOption || devOptions.logContexts;
756
+ if (!raw || 0 === String(raw).trim().length) return;
757
+ if ('all' === String(raw).trim().toLowerCase()) return;
758
+ const allowed = [
759
+ 'background',
760
+ 'content',
761
+ 'page',
762
+ 'sidebar',
763
+ 'popup',
764
+ 'options',
765
+ 'devtools'
766
+ ];
767
+ const values = String(raw).split(',').map((s)=>s.trim()).filter((s)=>s.length > 0).filter((c)=>allowed.includes(c));
768
+ return values.length ? values : void 0;
769
+ })(),
770
+ logFormat: devOptions.logFormat || 'pretty',
771
+ logTimestamps: false !== devOptions.logTimestamps,
772
+ logColor: false !== devOptions.logColor,
773
+ logUrl: devOptions.logUrl,
774
+ logTab: devOptions.logTab
775
+ };
776
+ await extensionDev(pathOrRemoteUrl, devArgs);
777
+ telemetry.track('cli_vendor_finish', {
778
+ command: 'dev',
779
+ vendor,
780
+ duration_ms: Date.now() - vendorStart
290
781
  });
291
782
  }
783
+ telemetry.track('cli_command_finish', {
784
+ command: 'dev',
785
+ duration_ms: Date.now() - cmdStart,
786
+ success: 0 === process.exitCode || null == process.exitCode,
787
+ exit_code: process.exitCode ?? 0
788
+ });
292
789
  });
293
- extensionJs.command('start').arguments('[project-path|remote-url]').usage('start [project-path|remote-url] [options]').description('Starts the development server (production mode)').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 | edge | firefox>', 'specify a browser to preview your extension in production mode. Defaults to `chrome`').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 <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`').action(async function(pathOrRemoteUrl, { browser = 'chrome', ...startOptions }) {
790
+ }
791
+ function registerStartCommand(program, telemetry) {
792
+ program.command('start').arguments('[project-path|remote-url]').usage('start [project-path|remote-url] [options]').description('Starts the development server (production mode)').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 }) {
793
+ var _startOptions_polyfill;
794
+ if (startOptions.author || startOptions['authorMode']) {
795
+ process.env.EXTENSION_AUTHOR_MODE = 'true';
796
+ if (!process.env.EXTENSION_VERBOSE) process.env.EXTENSION_VERBOSE = '1';
797
+ }
798
+ const cmdStart = Date.now();
799
+ telemetry.track('cli_command_start', {
800
+ command: 'start',
801
+ vendors: vendors(browser),
802
+ polyfill_used: (null == (_startOptions_polyfill = startOptions.polyfill) ? void 0 : _startOptions_polyfill.toString()) !== 'false'
803
+ });
294
804
  const list = vendors(browser);
295
- validateVendorsOrExit(list);
296
- const { extensionStart } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "extension-develop"));
297
- for (const vendor of list)await extensionStart(pathOrRemoteUrl, {
298
- mode: 'production',
299
- profile: startOptions.profile,
300
- browser: vendor,
301
- chromiumBinary: startOptions.chromiumBinary,
302
- geckoBinary: startOptions.geckoBinary,
303
- startingUrl: startOptions.startingUrl
805
+ validateVendorsOrExit(list, (invalid, supported)=>{
806
+ console.error(unsupportedBrowserFlag(invalid, supported));
807
+ });
808
+ const major = String(package_namespaceObject.version).split('.')[0] || '2';
809
+ const { extensionStart } = await requireOrDlx('extension-develop', major);
810
+ for (const vendor of list){
811
+ const vendorStart = Date.now();
812
+ telemetry.track('cli_vendor_start', {
813
+ command: 'start',
814
+ vendor
815
+ });
816
+ const logsOption = startOptions.logs;
817
+ const logContextOption = startOptions.logContext;
818
+ const logContexts = (()=>{
819
+ const raw = logContextOption || startOptions.logContexts;
820
+ if (!raw || 0 === String(raw).trim().length) return;
821
+ if ('all' === String(raw).trim().toLowerCase()) return;
822
+ const allowed = [
823
+ 'background',
824
+ 'content',
825
+ 'page',
826
+ 'sidebar',
827
+ 'popup',
828
+ 'options',
829
+ 'devtools'
830
+ ];
831
+ const values = String(raw).split(',').map((s)=>s.trim()).filter((s)=>s.length > 0).filter((c)=>allowed.includes(c));
832
+ return values.length ? values : void 0;
833
+ })();
834
+ await extensionStart(pathOrRemoteUrl, {
835
+ mode: 'production',
836
+ profile: startOptions.profile,
837
+ browser: vendor,
838
+ chromiumBinary: startOptions.chromiumBinary,
839
+ geckoBinary: startOptions.geckoBinary,
840
+ startingUrl: startOptions.startingUrl,
841
+ port: startOptions.port,
842
+ source: 'string' == typeof startOptions.source ? startOptions.source : startOptions.source,
843
+ watchSource: startOptions.watchSource,
844
+ logLevel: logsOption || startOptions.logLevel || 'off',
845
+ logContexts,
846
+ logFormat: startOptions.logFormat || 'pretty',
847
+ logTimestamps: false !== startOptions.logTimestamps,
848
+ logColor: false !== startOptions.logColor,
849
+ logUrl: startOptions.logUrl,
850
+ logTab: startOptions.logTab
851
+ });
852
+ telemetry.track('cli_vendor_finish', {
853
+ command: 'start',
854
+ vendor,
855
+ duration_ms: Date.now() - vendorStart
856
+ });
857
+ }
858
+ telemetry.track('cli_command_finish', {
859
+ command: 'start',
860
+ duration_ms: Date.now() - cmdStart,
861
+ success: 0 === process.exitCode || null == process.exitCode,
862
+ exit_code: process.exitCode ?? 0
304
863
  });
305
864
  });
306
- extensionJs.command('preview').arguments('[project-name]').usage('preview [path-to-remote-extension] [options]').description('Preview the extension in production mode').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 | edge | firefox>', 'specify a browser to preview your extension in production mode. Defaults to `chrome`').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 <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`').action(async function(pathOrRemoteUrl, { browser = 'chrome', ...previewOptions }) {
865
+ }
866
+ function registerPreviewCommand(program, telemetry) {
867
+ program.command('preview').arguments('[project-name]').usage('preview [path-to-remote-extension] [options]').description('Preview the extension in production mode').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 }) {
868
+ if (previewOptions.author || previewOptions['authorMode']) {
869
+ process.env.EXTENSION_AUTHOR_MODE = 'true';
870
+ if (!process.env.EXTENSION_VERBOSE) process.env.EXTENSION_VERBOSE = '1';
871
+ }
872
+ const cmdStart = Date.now();
873
+ telemetry.track('cli_command_start', {
874
+ command: 'preview',
875
+ vendors: vendors(browser)
876
+ });
307
877
  const list = vendors(browser);
308
- validateVendorsOrExit(list);
309
- const { extensionPreview } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "extension-develop"));
310
- for (const vendor of list)await extensionPreview(pathOrRemoteUrl, {
311
- mode: 'production',
312
- profile: previewOptions.profile,
313
- browser: vendor,
314
- chromiumBinary: previewOptions.chromiumBinary,
315
- geckoBinary: previewOptions.geckoBinary,
316
- startingUrl: previewOptions.startingUrl
878
+ validateVendorsOrExit(list, (invalid, supported)=>{
879
+ console.error(unsupportedBrowserFlag(invalid, supported));
880
+ });
881
+ if (!process.env.EXTJS_LIGHT) {
882
+ const isRemote = 'string' == typeof pathOrRemoteUrl && /^https?:/i.test(pathOrRemoteUrl);
883
+ if (isRemote) process.env.EXTJS_LIGHT = '1';
884
+ }
885
+ const major = String(package_namespaceObject.version).split('.')[0] || '2';
886
+ const { extensionPreview } = await requireOrDlx('extension-develop', major);
887
+ for (const vendor of list){
888
+ const vendorStart = Date.now();
889
+ telemetry.track('cli_vendor_start', {
890
+ command: 'preview',
891
+ vendor
892
+ });
893
+ const logsOption = previewOptions.logs;
894
+ const logContextOption = previewOptions.logContext;
895
+ const logContexts = (()=>{
896
+ const raw = logContextOption || previewOptions.logContexts;
897
+ if (!raw || 0 === String(raw).trim().length) return;
898
+ if ('all' === String(raw).trim().toLowerCase()) return;
899
+ const allowed = [
900
+ 'background',
901
+ 'content',
902
+ 'page',
903
+ 'sidebar',
904
+ 'popup',
905
+ 'options',
906
+ 'devtools'
907
+ ];
908
+ const values = String(raw).split(',').map((s)=>s.trim()).filter((s)=>s.length > 0).filter((c)=>allowed.includes(c));
909
+ return values.length ? values : void 0;
910
+ })();
911
+ await extensionPreview(pathOrRemoteUrl, {
912
+ mode: 'production',
913
+ profile: previewOptions.profile,
914
+ browser: vendor,
915
+ chromiumBinary: previewOptions.chromiumBinary,
916
+ geckoBinary: previewOptions.geckoBinary,
917
+ startingUrl: previewOptions.startingUrl,
918
+ port: previewOptions.port,
919
+ source: 'string' == typeof previewOptions.source ? previewOptions.source : previewOptions.source,
920
+ watchSource: previewOptions.watchSource,
921
+ logLevel: logsOption || previewOptions.logLevel || 'off',
922
+ logContexts,
923
+ logFormat: previewOptions.logFormat || 'pretty',
924
+ logTimestamps: false !== previewOptions.logTimestamps,
925
+ logColor: false !== previewOptions.logColor,
926
+ logUrl: previewOptions.logUrl,
927
+ logTab: previewOptions.logTab
928
+ });
929
+ telemetry.track('cli_vendor_finish', {
930
+ command: 'preview',
931
+ vendor,
932
+ duration_ms: Date.now() - vendorStart
933
+ });
934
+ }
935
+ telemetry.track('cli_command_finish', {
936
+ command: 'preview',
937
+ duration_ms: Date.now() - cmdStart,
938
+ success: 0 === process.exitCode || null == process.exitCode,
939
+ exit_code: process.exitCode ?? 0
317
940
  });
318
941
  });
319
- extensionJs.command('build').arguments('[project-name]').usage('build [path-to-remote-extension] [options]').description('Builds the extension for production').option('--browser <chrome | edge | firefox>', 'specify a browser to preview your extension in production mode. Defaults to `chrome`').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`').action(async function(pathOrRemoteUrl, { browser = 'chrome', ...buildOptions }) {
942
+ }
943
+ function registerBuildCommand(program, telemetry) {
944
+ program.command('build').arguments('[project-name]').usage('build [path-to-remote-extension] [options]').description('Builds the extension for production').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 }) {
945
+ if (buildOptions.author || buildOptions['authorMode']) {
946
+ process.env.EXTENSION_AUTHOR_MODE = 'true';
947
+ if (!process.env.EXTENSION_VERBOSE) process.env.EXTENSION_VERBOSE = '1';
948
+ }
949
+ const cmdStart = Date.now();
950
+ telemetry.track('cli_command_start', {
951
+ command: 'build',
952
+ vendors: vendors(browser),
953
+ polyfill_used: buildOptions.polyfill || false,
954
+ zip: buildOptions.zip || false,
955
+ zip_source: buildOptions.zipSource || false
956
+ });
320
957
  const list = vendors(browser);
321
- validateVendorsOrExit(list);
322
- const { extensionBuild } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "extension-develop"));
323
- for (const vendor of list)await extensionBuild(pathOrRemoteUrl, {
324
- browser: vendor,
325
- polyfill: buildOptions.polyfill,
326
- zip: buildOptions.zip,
327
- zipSource: buildOptions.zipSource,
328
- zipFilename: buildOptions.zipFilename,
329
- silent: buildOptions.silent
958
+ validateVendorsOrExit(list, (invalid, supported)=>{
959
+ console.error(unsupportedBrowserFlag(invalid, supported));
960
+ });
961
+ const major = String(package_namespaceObject.version).split('.')[0] || '2';
962
+ const { extensionBuild } = await requireOrDlx('extension-develop', major);
963
+ for (const vendor of list){
964
+ const vendorStart = Date.now();
965
+ telemetry.track('cli_vendor_start', {
966
+ command: 'build',
967
+ vendor
968
+ });
969
+ const buildSummary = await extensionBuild(pathOrRemoteUrl, {
970
+ browser: vendor,
971
+ polyfill: buildOptions.polyfill,
972
+ zip: buildOptions.zip,
973
+ zipSource: buildOptions.zipSource,
974
+ zipFilename: buildOptions.zipFilename,
975
+ silent: buildOptions.silent
976
+ });
977
+ telemetry.track('cli_build_summary', {
978
+ ...buildSummary
979
+ });
980
+ telemetry.track('cli_vendor_finish', {
981
+ command: 'build',
982
+ vendor,
983
+ duration_ms: Date.now() - vendorStart
984
+ });
985
+ }
986
+ telemetry.track('cli_command_finish', {
987
+ command: 'build',
988
+ duration_ms: Date.now() - cmdStart,
989
+ success: 0 === process.exitCode || null == process.exitCode,
990
+ exit_code: process.exitCode ?? 0
330
991
  });
331
992
  });
332
- extensionJs.command('cleanup').description('Clean up orphaned instances and free unused ports').action(async function() {
333
- const { cleanupCommand } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "extension-develop"));
334
- await cleanupCommand();
335
- });
336
- extensionJs.on('option:ai-help', function() {
337
- console.log(programAIHelp());
338
- process.exit(0);
339
- });
340
- extensionJs.parse();
341
- })();
993
+ }
994
+ check_updates_checkUpdates(package_namespaceObject);
995
+ const extensionJs = external_commander_namespaceObject.program;
996
+ extensionJs.name(package_namespaceObject.name).description(package_namespaceObject.description).version(package_namespaceObject.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);
997
+ registerCreateCommand(extensionJs, telemetry_cli_telemetry);
998
+ registerDevCommand(extensionJs, telemetry_cli_telemetry);
999
+ registerStartCommand(extensionJs, telemetry_cli_telemetry);
1000
+ registerPreviewCommand(extensionJs, telemetry_cli_telemetry);
1001
+ registerBuildCommand(extensionJs, telemetry_cli_telemetry);
1002
+ extensionJs.on('option:ai-help', function() {
1003
+ console.log(programAIHelp());
1004
+ process.exit(0);
1005
+ });
1006
+ if (process.argv.length <= 2) {
1007
+ extensionJs.outputHelp();
1008
+ process.exit(0);
1009
+ }
1010
+ extensionJs.parseAsync().catch((err)=>{
1011
+ console.error(err);
1012
+ process.exit(1);
1013
+ });
342
1014
  for(var __webpack_i__ in __webpack_exports__)exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
343
1015
  Object.defineProperty(exports, '__esModule', {
344
1016
  value: true