extension 3.0.0-next.57 → 3.0.0-next.59
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 +605 -776
- package/dist/utils.d.ts +0 -1
- package/package.json +2 -1
- package/types/extension-develop-shim.d.ts +79 -0
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
-
var
|
|
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
|
+
}
|
|
4
20
|
(()=>{
|
|
5
21
|
__webpack_require__.n = (module)=>{
|
|
6
22
|
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
@@ -22,29 +38,30 @@ var __webpack_require__ = {};
|
|
|
22
38
|
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
23
39
|
})();
|
|
24
40
|
var __webpack_exports__ = {};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
41
|
+
(()=>{
|
|
42
|
+
const external_commander_namespaceObject = require("commander");
|
|
43
|
+
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.59","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":{"prepublishOnly":"pnpm run compile","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":{"extension-develop":"^3.0.0-next.59","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"}}');
|
|
44
|
+
const external_update_check_namespaceObject = require("update-check");
|
|
45
|
+
var external_update_check_default = /*#__PURE__*/ __webpack_require__.n(external_update_check_namespaceObject);
|
|
46
|
+
const external_pintor_namespaceObject = require("pintor");
|
|
47
|
+
var external_pintor_default = /*#__PURE__*/ __webpack_require__.n(external_pintor_namespaceObject);
|
|
48
|
+
function getLoggingPrefix(type) {
|
|
49
|
+
if ('true' === process.env.EXTENSION_AUTHOR_MODE) return external_pintor_default().brightMagenta('error' === type ? 'ERROR' : "\u25BA\u25BA\u25BA");
|
|
50
|
+
if ('error' === type) return external_pintor_default().red('ERROR');
|
|
51
|
+
if ('warn' === type) return external_pintor_default().brightYellow("\u25BA\u25BA\u25BA");
|
|
52
|
+
if ('info' === type) return external_pintor_default().gray("\u25BA\u25BA\u25BA");
|
|
53
|
+
return external_pintor_default().green("\u25BA\u25BA\u25BA");
|
|
54
|
+
}
|
|
55
|
+
const code = (text)=>external_pintor_default().blue(text);
|
|
56
|
+
const arg = (text)=>external_pintor_default().gray(text);
|
|
57
|
+
function updateFailed(err) {
|
|
58
|
+
return `${getLoggingPrefix('error')} Failed to check for updates.\n${external_pintor_default().red(String((null == err ? void 0 : err.message) || err))}`;
|
|
59
|
+
}
|
|
60
|
+
function checkUpdates(packageJson, update) {
|
|
61
|
+
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.`;
|
|
62
|
+
}
|
|
63
|
+
function programUserHelp() {
|
|
64
|
+
return `\n${getLoggingPrefix('info')} ${external_pintor_default().underline('Help center for the Extension.js program')}
|
|
48
65
|
|
|
49
66
|
Usage: extension [command] [options]
|
|
50
67
|
|
|
@@ -122,12 +139,12 @@ AI Assistants
|
|
|
122
139
|
|
|
123
140
|
Report issues
|
|
124
141
|
- ${external_pintor_default().underline('https://github.com/cezaraugusto/extension/issues/new')}`;
|
|
125
|
-
}
|
|
126
|
-
function unsupportedBrowserFlag(value, supported) {
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
function programAIHelp() {
|
|
130
|
-
|
|
142
|
+
}
|
|
143
|
+
function unsupportedBrowserFlag(value, supported) {
|
|
144
|
+
return `${getLoggingPrefix('error')} Unsupported --browser value: ${value}. Supported: ${supported.join(', ')}.`;
|
|
145
|
+
}
|
|
146
|
+
function programAIHelp() {
|
|
147
|
+
return `\n${getLoggingPrefix('info')} ${external_pintor_default().gray('Development tips for extension developers and AI assistants')}
|
|
131
148
|
|
|
132
149
|
Browser-Specific Configuration
|
|
133
150
|
- Use browser prefixes in manifest.json for browser-specific fields:
|
|
@@ -260,545 +277,425 @@ Cross-Browser Compatibility
|
|
|
260
277
|
- Use ${code('--polyfill')} flag to enable webextension-polyfill
|
|
261
278
|
- Automatically handles browser API differences
|
|
262
279
|
- 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));
|
|
275
280
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
const
|
|
279
|
-
|
|
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);
|
|
281
|
+
const external_semver_namespaceObject = require("semver");
|
|
282
|
+
function isStableVersion(version) {
|
|
283
|
+
const v = external_semver_namespaceObject.parse(version);
|
|
284
|
+
return Boolean(v && 0 === v.prerelease.length);
|
|
352
285
|
}
|
|
353
|
-
async
|
|
354
|
-
|
|
355
|
-
if (0 === this.buffer.length) return;
|
|
356
|
-
const batch = this.buffer.splice(0, this.buffer.length);
|
|
286
|
+
async function check_updates_checkUpdates(packageJson) {
|
|
287
|
+
let update = null;
|
|
357
288
|
try {
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
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
|
-
}
|
|
289
|
+
update = await external_update_check_default()(packageJson);
|
|
290
|
+
} catch (err) {
|
|
291
|
+
if ('true' === process.env.EXTENSION_AUTHOR_MODE) console.error(updateFailed(err));
|
|
417
292
|
}
|
|
293
|
+
if (update && isStableVersion(update.latest)) console.log(checkUpdates(packageJson, update));
|
|
418
294
|
}
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
const
|
|
424
|
-
|
|
425
|
-
const
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
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)
|
|
295
|
+
const external_fs_namespaceObject = require("fs");
|
|
296
|
+
var external_fs_default = /*#__PURE__*/ __webpack_require__.n(external_fs_namespaceObject);
|
|
297
|
+
const external_path_namespaceObject = require("path");
|
|
298
|
+
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
299
|
+
const external_node_os_namespaceObject = require("node:os");
|
|
300
|
+
var external_node_os_default = /*#__PURE__*/ __webpack_require__.n(external_node_os_namespaceObject);
|
|
301
|
+
const external_node_fs_namespaceObject = require("node:fs");
|
|
302
|
+
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
|
|
303
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
304
|
+
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
305
|
+
const external_node_crypto_namespaceObject = require("node:crypto");
|
|
306
|
+
var external_node_crypto_default = /*#__PURE__*/ __webpack_require__.n(external_node_crypto_namespaceObject);
|
|
307
|
+
function _define_property(obj, key, value) {
|
|
308
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
309
|
+
value: value,
|
|
310
|
+
enumerable: true,
|
|
311
|
+
configurable: true,
|
|
312
|
+
writable: true
|
|
500
313
|
});
|
|
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 copyIfExists(src, dest) {
|
|
507
|
-
try {
|
|
508
|
-
if (external_node_fs_default().existsSync(src)) external_node_fs_default().copyFileSync(src, dest);
|
|
509
|
-
} catch {}
|
|
510
|
-
}
|
|
511
|
-
function syncPackageManagerConfig(cacheDir) {
|
|
512
|
-
const cwd = process.cwd();
|
|
513
|
-
copyIfExists(external_node_path_default().join(cwd, '.npmrc'), external_node_path_default().join(cacheDir, '.npmrc'));
|
|
514
|
-
copyIfExists(external_node_path_default().join(cwd, '.pnpmfile.cjs'), external_node_path_default().join(cacheDir, '.pnpmfile.cjs'));
|
|
515
|
-
}
|
|
516
|
-
function resolveModuleEntry(modulePath, pkgJson) {
|
|
517
|
-
const exportsField = pkgJson.exports;
|
|
518
|
-
let main = pkgJson.main;
|
|
519
|
-
if (!main && 'string' == typeof exportsField) main = exportsField;
|
|
520
|
-
if (!main && exportsField && 'object' == typeof exportsField) {
|
|
521
|
-
const dotExport = exportsField['.'];
|
|
522
|
-
if ('string' == typeof dotExport) main = dotExport;
|
|
523
|
-
else if (dotExport && 'object' == typeof dotExport) main = dotExport.import || dotExport.require || dotExport.default || dotExport.node;
|
|
524
|
-
if (!main) {
|
|
525
|
-
const maybe = exportsField.import || exportsField.require || exportsField.default || exportsField.node;
|
|
526
|
-
if ('string' == typeof maybe) main = maybe;
|
|
527
|
-
}
|
|
314
|
+
else obj[key] = value;
|
|
315
|
+
return obj;
|
|
528
316
|
}
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
'0',
|
|
543
|
-
'no',
|
|
544
|
-
'off'
|
|
545
|
-
].includes(normalized);
|
|
546
|
-
}
|
|
547
|
-
async function requireOrDlx(moduleName, versionHint) {
|
|
548
|
-
try {
|
|
549
|
-
return await import(moduleName);
|
|
550
|
-
} catch {}
|
|
551
|
-
const spec = versionHint ? `${moduleName}@${versionHint}` : moduleName;
|
|
552
|
-
const cacheDir = external_node_path_default().join(external_node_os_default().tmpdir(), 'extensionjs-cache', spec);
|
|
553
|
-
const modulePath = external_node_path_default().join(cacheDir, 'node_modules', moduleName);
|
|
554
|
-
const pkgJsonPath = external_node_path_default().join(modulePath, 'package.json');
|
|
555
|
-
try {
|
|
556
|
-
const localDist = external_node_path_default().resolve(__dirname, '..', '..', 'develop', 'dist', 'module.js');
|
|
557
|
-
if (external_node_fs_default().existsSync(localDist)) return await import((0, external_node_url_namespaceObject.pathToFileURL)(localDist).href);
|
|
558
|
-
} catch {}
|
|
559
|
-
try {
|
|
560
|
-
const cwdDist = external_node_path_default().resolve(process.cwd(), 'programs', 'develop', 'dist', 'module.js');
|
|
561
|
-
if (external_node_fs_default().existsSync(cwdDist)) return await import((0, external_node_url_namespaceObject.pathToFileURL)(cwdDist).href);
|
|
562
|
-
} catch {}
|
|
563
|
-
let prefer = String(process.env.EXTENSION_DLX || '').trim().toLowerCase();
|
|
564
|
-
const isWin = 'win32' === process.platform;
|
|
565
|
-
const npmCmd = isWin ? 'npm.cmd' : 'npm';
|
|
566
|
-
const pnpmCmd = isWin ? 'pnpm.cmd' : 'pnpm';
|
|
567
|
-
const bunCmd = isWin ? 'bun.exe' : 'bun';
|
|
568
|
-
if (!prefer) try {
|
|
569
|
-
const pnpmCheck = (0, external_node_child_process_namespaceObject.spawnSync)(pnpmCmd, [
|
|
570
|
-
'--version'
|
|
571
|
-
], {
|
|
572
|
-
stdio: 'ignore'
|
|
573
|
-
});
|
|
574
|
-
if (0 === (pnpmCheck.status || 0)) prefer = 'pnpm';
|
|
575
|
-
} catch {}
|
|
576
|
-
try {
|
|
577
|
-
external_node_fs_default().mkdirSync(cacheDir, {
|
|
317
|
+
function isCI() {
|
|
318
|
+
const v = process.env;
|
|
319
|
+
return Boolean(v.CI || v.GITHUB_ACTIONS || v.GITLAB_CI || v.BUILDKITE || v.CIRCLECI || v.TRAVIS);
|
|
320
|
+
}
|
|
321
|
+
function configDir() {
|
|
322
|
+
const xdg = process.env.XDG_CONFIG_HOME;
|
|
323
|
+
if (xdg) return external_node_path_default().join(xdg, 'extensionjs');
|
|
324
|
+
if ('win32' === process.platform && process.env.APPDATA) return external_node_path_default().join(process.env.APPDATA, 'extensionjs');
|
|
325
|
+
return external_node_path_default().join(external_node_os_default().homedir(), '.config', 'extensionjs');
|
|
326
|
+
}
|
|
327
|
+
function ensureDir(p) {
|
|
328
|
+
if (external_node_fs_default().existsSync(p)) return;
|
|
329
|
+
external_node_fs_default().mkdirSync(p, {
|
|
578
330
|
recursive: true
|
|
579
331
|
});
|
|
580
|
-
} catch {}
|
|
581
|
-
syncPackageManagerConfig(cacheDir);
|
|
582
|
-
let preInstallPkgJson;
|
|
583
|
-
try {
|
|
584
|
-
preInstallPkgJson = JSON.parse(external_node_fs_default().readFileSync(pkgJsonPath, 'utf8'));
|
|
585
|
-
} catch {}
|
|
586
|
-
if (preInstallPkgJson) {
|
|
587
|
-
const entry = resolveModuleEntry(modulePath, preInstallPkgJson);
|
|
588
|
-
if (entry) return await import(entry);
|
|
589
|
-
}
|
|
590
|
-
if ('pnpm' === prefer) try {
|
|
591
|
-
external_node_fs_default().writeFileSync(external_node_path_default().join(cacheDir, 'package.json'), JSON.stringify({
|
|
592
|
-
name: 'extensionjs-cache',
|
|
593
|
-
private: true
|
|
594
|
-
}, null, 2));
|
|
595
|
-
} catch {}
|
|
596
|
-
let status = 0;
|
|
597
|
-
if ('pnpm' === prefer) {
|
|
598
|
-
const args = [
|
|
599
|
-
'add',
|
|
600
|
-
spec,
|
|
601
|
-
'--reporter',
|
|
602
|
-
'silent',
|
|
603
|
-
'--no-frozen-lockfile'
|
|
604
|
-
];
|
|
605
|
-
status = (0, external_node_child_process_namespaceObject.spawnSync)(pnpmCmd, args, {
|
|
606
|
-
cwd: cacheDir,
|
|
607
|
-
stdio: 'ignore'
|
|
608
|
-
}).status || 0;
|
|
609
|
-
} else if ('bun' === prefer) {
|
|
610
|
-
const args = [
|
|
611
|
-
'add',
|
|
612
|
-
spec
|
|
613
|
-
];
|
|
614
|
-
status = (0, external_node_child_process_namespaceObject.spawnSync)(bunCmd, args, {
|
|
615
|
-
cwd: cacheDir,
|
|
616
|
-
stdio: 'ignore'
|
|
617
|
-
}).status || 0;
|
|
618
|
-
} else {
|
|
619
|
-
const args = [
|
|
620
|
-
'i',
|
|
621
|
-
spec,
|
|
622
|
-
'--no-fund',
|
|
623
|
-
'--no-audit',
|
|
624
|
-
'--prefer-online',
|
|
625
|
-
'--omit=dev',
|
|
626
|
-
'--omit=optional',
|
|
627
|
-
'--no-package-lock'
|
|
628
|
-
];
|
|
629
|
-
status = (0, external_node_child_process_namespaceObject.spawnSync)(npmCmd, args, {
|
|
630
|
-
cwd: cacheDir,
|
|
631
|
-
stdio: 'ignore'
|
|
632
|
-
}).status || 0;
|
|
633
332
|
}
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
} catch {}
|
|
641
|
-
if ('pnpm' !== prefer) {
|
|
642
|
-
const args = [
|
|
643
|
-
'add',
|
|
644
|
-
spec,
|
|
645
|
-
'--reporter',
|
|
646
|
-
'silent',
|
|
647
|
-
'--no-frozen-lockfile'
|
|
648
|
-
];
|
|
649
|
-
status = (0, external_node_child_process_namespaceObject.spawnSync)(pnpmCmd, args, {
|
|
650
|
-
cwd: cacheDir,
|
|
651
|
-
stdio: 'ignore'
|
|
652
|
-
}).status || 0;
|
|
653
|
-
}
|
|
333
|
+
function loadOrCreateId(file) {
|
|
334
|
+
if (external_node_fs_default().existsSync(file)) return external_node_fs_default().readFileSync(file, 'utf8').trim();
|
|
335
|
+
const id = external_node_crypto_default().randomUUID();
|
|
336
|
+
ensureDir(external_node_path_default().dirname(file));
|
|
337
|
+
external_node_fs_default().writeFileSync(file, id, 'utf8');
|
|
338
|
+
return id;
|
|
654
339
|
}
|
|
655
|
-
|
|
656
|
-
const
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
];
|
|
660
|
-
status = (0, external_node_child_process_namespaceObject.spawnSync)(bunCmd, args, {
|
|
661
|
-
cwd: cacheDir,
|
|
662
|
-
stdio: 'ignore'
|
|
663
|
-
}).status || 0;
|
|
340
|
+
function auditFilePath() {
|
|
341
|
+
const dir = external_node_path_default().join(configDir(), 'telemetry');
|
|
342
|
+
ensureDir(dir);
|
|
343
|
+
return external_node_path_default().join(dir, 'events.jsonl');
|
|
664
344
|
}
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
345
|
+
const DEFAULT_FLUSH_AT = Number(process.env.EXTENSION_TELEMETRY_FLUSH_AT || 10);
|
|
346
|
+
const DEFAULT_FLUSH_INTERVAL = Number(process.env.EXTENSION_TELEMETRY_FLUSH_INTERVAL || 2000);
|
|
347
|
+
const DEFAULT_TIMEOUT_MS = Number(process.env.EXTENSION_TELEMETRY_TIMEOUT_MS || 200);
|
|
348
|
+
class Telemetry {
|
|
349
|
+
track(event, props = {}) {
|
|
350
|
+
if (this.disabled) return;
|
|
351
|
+
const payload = {
|
|
352
|
+
event,
|
|
353
|
+
properties: {
|
|
354
|
+
...this.common,
|
|
355
|
+
...props,
|
|
356
|
+
$ip: null
|
|
357
|
+
},
|
|
358
|
+
distinct_id: this.anonId
|
|
359
|
+
};
|
|
360
|
+
external_node_fs_default().appendFileSync(auditFilePath(), JSON.stringify(payload) + '\n');
|
|
361
|
+
if (this.debug) console.error('[telemetry]', JSON.stringify(payload));
|
|
362
|
+
if (!this.apiKey || !this.host) return;
|
|
363
|
+
this.buffer.push(payload);
|
|
364
|
+
if (this.buffer.length >= DEFAULT_FLUSH_AT) return void this.flush();
|
|
365
|
+
if (!this.timer) this.timer = setTimeout(()=>{
|
|
366
|
+
this.timer = null;
|
|
367
|
+
this.flush();
|
|
368
|
+
}, DEFAULT_FLUSH_INTERVAL);
|
|
369
|
+
}
|
|
370
|
+
async flush() {
|
|
371
|
+
if (this.disabled || !this.apiKey || !this.host) return;
|
|
372
|
+
if (0 === this.buffer.length) return;
|
|
373
|
+
const batch = this.buffer.splice(0, this.buffer.length);
|
|
374
|
+
try {
|
|
375
|
+
const ac = new AbortController();
|
|
376
|
+
const t = setTimeout(()=>ac.abort(), DEFAULT_TIMEOUT_MS);
|
|
377
|
+
const url = new URL('/capture/', this.host);
|
|
378
|
+
await fetch(url.toString(), {
|
|
379
|
+
method: 'POST',
|
|
380
|
+
headers: {
|
|
381
|
+
'content-type': 'application/json'
|
|
382
|
+
},
|
|
383
|
+
body: JSON.stringify({
|
|
384
|
+
api_key: this.apiKey,
|
|
385
|
+
batch: batch.map((e)=>({
|
|
386
|
+
event: e.event,
|
|
387
|
+
properties: e.properties,
|
|
388
|
+
distinct_id: e.distinct_id
|
|
389
|
+
}))
|
|
390
|
+
}),
|
|
391
|
+
signal: ac.signal,
|
|
392
|
+
keepalive: true
|
|
393
|
+
}).catch(()=>{});
|
|
394
|
+
clearTimeout(t);
|
|
395
|
+
} catch {}
|
|
396
|
+
}
|
|
397
|
+
shutdown() {}
|
|
398
|
+
constructor(init){
|
|
399
|
+
_define_property(this, "anonId", void 0);
|
|
400
|
+
_define_property(this, "common", void 0);
|
|
401
|
+
_define_property(this, "debug", void 0);
|
|
402
|
+
_define_property(this, "disabled", void 0);
|
|
403
|
+
_define_property(this, "apiKey", void 0);
|
|
404
|
+
_define_property(this, "host", void 0);
|
|
405
|
+
_define_property(this, "buffer", []);
|
|
406
|
+
_define_property(this, "timer", null);
|
|
407
|
+
this.debug = '1' === process.env.EXTENSION_TELEMETRY_DEBUG;
|
|
408
|
+
this.disabled = Boolean(init.disabled);
|
|
409
|
+
this.anonId = 'disabled';
|
|
410
|
+
if (!this.disabled) {
|
|
411
|
+
const idFile = external_node_path_default().join(configDir(), 'telemetry', 'anonymous-id');
|
|
412
|
+
this.anonId = loadOrCreateId(idFile);
|
|
413
|
+
}
|
|
414
|
+
this.common = {
|
|
415
|
+
app: init.app,
|
|
416
|
+
version: init.version,
|
|
417
|
+
os: process.platform,
|
|
418
|
+
arch: process.arch,
|
|
419
|
+
node: process.versions.node,
|
|
420
|
+
is_ci: isCI(),
|
|
421
|
+
schema_version: 1
|
|
422
|
+
};
|
|
423
|
+
this.apiKey = init.apiKey || process.env.EXTENSION_PUBLIC_POSTHOG_KEY;
|
|
424
|
+
this.host = init.host || process.env.EXTENSION_PUBLIC_POSTHOG_HOST;
|
|
425
|
+
if (!this.disabled) {
|
|
426
|
+
const consentPath = external_node_path_default().join(configDir(), 'telemetry', 'consent');
|
|
427
|
+
if (!external_node_fs_default().existsSync(consentPath)) {
|
|
428
|
+
external_node_fs_default().writeFileSync(consentPath, 'ok', 'utf8');
|
|
429
|
+
this.track('cli_telemetry_consent', {
|
|
430
|
+
value: 'implicit_opt_in'
|
|
431
|
+
});
|
|
432
|
+
console.log('[extension] anonymous telemetry helps us improve. Pass --no-telemetry to opt out. Read more in TELEMETRY.md.');
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}
|
|
686
436
|
}
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
const
|
|
692
|
-
|
|
437
|
+
function summarizeManifest(manifest) {
|
|
438
|
+
var _manifest_action;
|
|
439
|
+
const mv = (null == manifest ? void 0 : manifest.manifest_version) === 2 ? 2 : 3;
|
|
440
|
+
const permissions = Array.isArray(null == manifest ? void 0 : manifest.permissions) ? manifest.permissions : [];
|
|
441
|
+
const optionalPermissions = Array.isArray(null == manifest ? void 0 : manifest.optional_permissions) ? manifest.optional_permissions : [];
|
|
442
|
+
const hostPermissions = Array.isArray(null == manifest ? void 0 : manifest.host_permissions) ? manifest.host_permissions : [];
|
|
443
|
+
const usesAllUrls = [
|
|
444
|
+
...permissions,
|
|
445
|
+
...hostPermissions
|
|
446
|
+
].includes('<all_urls>');
|
|
447
|
+
const usesDeclarativeNetRequest = permissions.includes('declarativeNetRequest') || permissions.includes('declarativeNetRequestWithHostAccess');
|
|
448
|
+
const background = null == manifest ? void 0 : manifest.background;
|
|
449
|
+
let backgroundType = 'none';
|
|
450
|
+
if (3 === mv && (null == background ? void 0 : background.service_worker)) backgroundType = 'service_worker';
|
|
451
|
+
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';
|
|
452
|
+
const contentScriptsCount = Array.isArray(null == manifest ? void 0 : manifest.content_scripts) ? manifest.content_scripts.length : 0;
|
|
453
|
+
const hasDevtoolsPage = Boolean(null == manifest ? void 0 : manifest.devtools_page);
|
|
454
|
+
const hasActionPopup = Boolean(null == manifest ? void 0 : null == (_manifest_action = manifest.action) ? void 0 : _manifest_action.default_popup);
|
|
455
|
+
return {
|
|
456
|
+
mv,
|
|
457
|
+
permissions_count: permissions.length,
|
|
458
|
+
optional_permissions_count: optionalPermissions.length,
|
|
459
|
+
host_permissions_count: hostPermissions.length,
|
|
460
|
+
uses_all_urls: usesAllUrls,
|
|
461
|
+
uses_declarative_net_request: usesDeclarativeNetRequest,
|
|
462
|
+
background_type: backgroundType,
|
|
463
|
+
content_scripts_count: contentScriptsCount,
|
|
464
|
+
has_devtools_page: hasDevtoolsPage,
|
|
465
|
+
has_action_popup: hasActionPopup
|
|
466
|
+
};
|
|
693
467
|
}
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
const vendors = (browser)=>{
|
|
697
|
-
const value = browser ?? 'chromium';
|
|
698
|
-
return 'all' === value ? [
|
|
699
|
-
'chrome',
|
|
700
|
-
'edge',
|
|
701
|
-
'firefox'
|
|
702
|
-
] : String(value).split(',');
|
|
703
|
-
};
|
|
704
|
-
function validateVendorsOrExit(vendorsList, onInvalid) {
|
|
705
|
-
const supported = [
|
|
706
|
-
'chrome',
|
|
707
|
-
'edge',
|
|
708
|
-
'firefox',
|
|
709
|
-
'chromium',
|
|
710
|
-
'chromium-based',
|
|
711
|
-
'gecko-based',
|
|
712
|
-
'firefox-based'
|
|
713
|
-
];
|
|
714
|
-
for (const v of vendorsList)if (!supported.includes(v)) {
|
|
715
|
-
onInvalid(v, supported);
|
|
716
|
-
process.exit(1);
|
|
468
|
+
function isTelemetryDisabledFromArgs(argv) {
|
|
469
|
+
return argv.includes('--no-telemetry');
|
|
717
470
|
}
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
471
|
+
const telemetryDisabled = isTelemetryDisabledFromArgs(process.argv);
|
|
472
|
+
const telemetry_cli_telemetry = new Telemetry({
|
|
473
|
+
app: 'extension',
|
|
474
|
+
version: package_namespaceObject.version,
|
|
475
|
+
disabled: telemetryDisabled
|
|
476
|
+
});
|
|
477
|
+
if (!telemetryDisabled) {
|
|
721
478
|
const startedAt = Date.now();
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
479
|
+
const known = new Set([
|
|
480
|
+
'create',
|
|
481
|
+
'dev',
|
|
482
|
+
'start',
|
|
483
|
+
'preview',
|
|
484
|
+
'build',
|
|
485
|
+
'cleanup'
|
|
486
|
+
]);
|
|
487
|
+
const invoked = process.argv.slice(2).find((a)=>known.has(a)) || 'unknown';
|
|
488
|
+
telemetry_cli_telemetry.track('cli_boot', {
|
|
489
|
+
command_guess: invoked
|
|
726
490
|
});
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
491
|
+
const cwd = process.cwd();
|
|
492
|
+
const manifestPath = external_path_default().join(cwd, 'manifest.json');
|
|
493
|
+
if (external_fs_default().existsSync(manifestPath)) {
|
|
494
|
+
const raw = external_fs_default().readFileSync(manifestPath, 'utf8');
|
|
495
|
+
const json = JSON.parse(raw);
|
|
496
|
+
const summary = summarizeManifest(json);
|
|
497
|
+
telemetry_cli_telemetry.track('manifest_summary', summary);
|
|
498
|
+
}
|
|
499
|
+
process.on('beforeExit', async function() {
|
|
500
|
+
telemetry_cli_telemetry.track('cli_shutdown', {
|
|
501
|
+
command_guess: invoked,
|
|
735
502
|
duration_ms: Date.now() - startedAt,
|
|
736
|
-
|
|
737
|
-
exit_code: 0
|
|
503
|
+
exit_code: process.exitCode ?? 0
|
|
738
504
|
});
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
505
|
+
await telemetry_cli_telemetry.flush();
|
|
506
|
+
});
|
|
507
|
+
process.on('uncaughtException', function(err) {
|
|
508
|
+
telemetry_cli_telemetry.track('cli_error', {
|
|
509
|
+
command_guess: invoked,
|
|
510
|
+
error_name: String((null == err ? void 0 : err.name) || 'Error').slice(0, 64)
|
|
745
511
|
});
|
|
746
|
-
throw err;
|
|
747
|
-
}
|
|
748
|
-
});
|
|
749
|
-
}
|
|
750
|
-
function registerDevCommand(program, telemetry) {
|
|
751
|
-
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 }) {
|
|
752
|
-
var _devOptions_polyfill;
|
|
753
|
-
if (devOptions.author || devOptions['authorMode']) {
|
|
754
|
-
process.env.EXTENSION_AUTHOR_MODE = 'true';
|
|
755
|
-
if (!process.env.EXTENSION_VERBOSE) process.env.EXTENSION_VERBOSE = '1';
|
|
756
|
-
}
|
|
757
|
-
const cmdStart = Date.now();
|
|
758
|
-
telemetry.track('cli_command_start', {
|
|
759
|
-
command: 'dev',
|
|
760
|
-
vendors: vendors(browser),
|
|
761
|
-
polyfill_used: (null == (_devOptions_polyfill = devOptions.polyfill) ? void 0 : _devOptions_polyfill.toString()) !== 'false',
|
|
762
|
-
log_level: devOptions.logLevel || 'off',
|
|
763
|
-
log_format: devOptions.logFormat || 'pretty',
|
|
764
|
-
custom_binary_used: Boolean(devOptions.chromiumBinary || devOptions.geckoBinary)
|
|
765
512
|
});
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
513
|
+
process.on('unhandledRejection', function(reason) {
|
|
514
|
+
telemetry_cli_telemetry.track('cli_error', {
|
|
515
|
+
command_guess: invoked,
|
|
516
|
+
error_name: String((null == reason ? void 0 : reason.name) || 'PromiseRejection').slice(0, 64)
|
|
517
|
+
});
|
|
769
518
|
});
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
519
|
+
}
|
|
520
|
+
const external_extension_create_namespaceObject = require("extension-create");
|
|
521
|
+
require("node:url");
|
|
522
|
+
function parseOptionalBoolean(value) {
|
|
523
|
+
if (void 0 === value) return true;
|
|
524
|
+
const normalized = String(value).trim().toLowerCase();
|
|
525
|
+
return ![
|
|
526
|
+
'false',
|
|
527
|
+
'0',
|
|
528
|
+
'no',
|
|
529
|
+
'off'
|
|
530
|
+
].includes(normalized);
|
|
531
|
+
}
|
|
532
|
+
const vendors = (browser)=>{
|
|
533
|
+
const value = browser ?? 'chromium';
|
|
534
|
+
return 'all' === value ? [
|
|
535
|
+
'chrome',
|
|
536
|
+
'edge',
|
|
537
|
+
'firefox'
|
|
538
|
+
] : String(value).split(',');
|
|
539
|
+
};
|
|
540
|
+
function validateVendorsOrExit(vendorsList, onInvalid) {
|
|
541
|
+
const supported = [
|
|
542
|
+
'chrome',
|
|
543
|
+
'edge',
|
|
544
|
+
'firefox',
|
|
545
|
+
'chromium',
|
|
546
|
+
'chromium-based',
|
|
547
|
+
'gecko-based',
|
|
548
|
+
'firefox-based'
|
|
549
|
+
];
|
|
550
|
+
for (const v of vendorsList)if (!supported.includes(v)) {
|
|
551
|
+
onInvalid(v, supported);
|
|
552
|
+
process.exit(1);
|
|
775
553
|
}
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
(
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
554
|
+
}
|
|
555
|
+
function registerCreateCommand(program, telemetry) {
|
|
556
|
+
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 }) {
|
|
557
|
+
const startedAt = Date.now();
|
|
558
|
+
telemetry.track('cli_command_start', {
|
|
559
|
+
command: 'create',
|
|
560
|
+
template: template || 'default',
|
|
561
|
+
install: Boolean(install)
|
|
562
|
+
});
|
|
563
|
+
try {
|
|
564
|
+
await (0, external_extension_create_namespaceObject.extensionCreate)(pathOrRemoteUrl, {
|
|
565
|
+
template,
|
|
566
|
+
install,
|
|
567
|
+
cliVersion: package_namespaceObject.version
|
|
568
|
+
});
|
|
569
|
+
telemetry.track('cli_command_finish', {
|
|
570
|
+
command: 'create',
|
|
571
|
+
duration_ms: Date.now() - startedAt,
|
|
572
|
+
success: true,
|
|
573
|
+
exit_code: 0
|
|
574
|
+
});
|
|
575
|
+
} catch (err) {
|
|
576
|
+
telemetry.track('cli_command_finish', {
|
|
577
|
+
command: 'create',
|
|
578
|
+
duration_ms: Date.now() - startedAt,
|
|
579
|
+
success: false,
|
|
580
|
+
exit_code: 1
|
|
581
|
+
});
|
|
582
|
+
throw err;
|
|
583
|
+
}
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
function registerDevCommand(program, telemetry) {
|
|
587
|
+
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 }) {
|
|
588
|
+
var _devOptions_polyfill;
|
|
589
|
+
if (devOptions.author || devOptions['authorMode']) {
|
|
590
|
+
process.env.EXTENSION_AUTHOR_MODE = 'true';
|
|
591
|
+
if (!process.env.EXTENSION_VERBOSE) process.env.EXTENSION_VERBOSE = '1';
|
|
592
|
+
}
|
|
593
|
+
const cmdStart = Date.now();
|
|
594
|
+
telemetry.track('cli_command_start', {
|
|
595
|
+
command: 'dev',
|
|
596
|
+
vendors: vendors(browser),
|
|
597
|
+
polyfill_used: (null == (_devOptions_polyfill = devOptions.polyfill) ? void 0 : _devOptions_polyfill.toString()) !== 'false',
|
|
598
|
+
log_level: devOptions.logLevel || 'off',
|
|
599
|
+
log_format: devOptions.logFormat || 'pretty',
|
|
600
|
+
custom_binary_used: Boolean(devOptions.chromiumBinary || devOptions.geckoBinary)
|
|
601
|
+
});
|
|
602
|
+
const list = vendors(browser);
|
|
603
|
+
validateVendorsOrExit(list, (invalid, supported)=>{
|
|
604
|
+
console.error(unsupportedBrowserFlag(invalid, supported));
|
|
605
|
+
});
|
|
606
|
+
if (devOptions.source) {
|
|
607
|
+
const hasExplicitSourceString = 'string' == typeof devOptions.source && 'true' !== String(devOptions.source).trim().toLowerCase();
|
|
608
|
+
const hasStartingUrl = 'string' == typeof devOptions.startingUrl && String(devOptions.startingUrl).trim().length > 0;
|
|
609
|
+
if (!hasExplicitSourceString) devOptions.source = hasStartingUrl ? String(devOptions.startingUrl) : 'https://example.com';
|
|
610
|
+
devOptions.watchSource = true;
|
|
611
|
+
}
|
|
612
|
+
const { extensionDev } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "extension-develop"));
|
|
613
|
+
for (const vendor of list){
|
|
614
|
+
var _devOptions_polyfill1;
|
|
615
|
+
const vendorStart = Date.now();
|
|
616
|
+
telemetry.track('cli_vendor_start', {
|
|
617
|
+
command: 'dev',
|
|
618
|
+
vendor
|
|
619
|
+
});
|
|
620
|
+
const logsOption = devOptions.logs;
|
|
621
|
+
const logContextOption = devOptions.logContext;
|
|
622
|
+
const devArgs = {
|
|
623
|
+
...devOptions,
|
|
624
|
+
profile: devOptions.profile,
|
|
625
|
+
browser: vendor,
|
|
626
|
+
chromiumBinary: devOptions.chromiumBinary,
|
|
627
|
+
geckoBinary: devOptions.geckoBinary,
|
|
628
|
+
polyfill: (null == (_devOptions_polyfill1 = devOptions.polyfill) ? void 0 : _devOptions_polyfill1.toString()) !== 'false',
|
|
629
|
+
open: devOptions.open,
|
|
630
|
+
startingUrl: devOptions.startingUrl,
|
|
631
|
+
source: devOptions.source,
|
|
632
|
+
watchSource: devOptions.watchSource,
|
|
633
|
+
logLevel: logsOption || devOptions.logLevel || 'off',
|
|
634
|
+
logContexts: (()=>{
|
|
635
|
+
const raw = logContextOption || devOptions.logContexts;
|
|
636
|
+
if (!raw || 0 === String(raw).trim().length) return;
|
|
637
|
+
if ('all' === String(raw).trim().toLowerCase()) return;
|
|
638
|
+
const allowed = [
|
|
639
|
+
'background',
|
|
640
|
+
'content',
|
|
641
|
+
'page',
|
|
642
|
+
'sidebar',
|
|
643
|
+
'popup',
|
|
644
|
+
'options',
|
|
645
|
+
'devtools'
|
|
646
|
+
];
|
|
647
|
+
const values = String(raw).split(',').map((s)=>s.trim()).filter((s)=>s.length > 0).filter((c)=>allowed.includes(c));
|
|
648
|
+
return values.length ? values : void 0;
|
|
649
|
+
})(),
|
|
650
|
+
logFormat: devOptions.logFormat || 'pretty',
|
|
651
|
+
logTimestamps: false !== devOptions.logTimestamps,
|
|
652
|
+
logColor: false !== devOptions.logColor,
|
|
653
|
+
logUrl: devOptions.logUrl,
|
|
654
|
+
logTab: devOptions.logTab
|
|
655
|
+
};
|
|
656
|
+
await extensionDev(pathOrRemoteUrl, devArgs);
|
|
657
|
+
telemetry.track('cli_vendor_finish', {
|
|
658
|
+
command: 'dev',
|
|
659
|
+
vendor,
|
|
660
|
+
duration_ms: Date.now() - vendorStart
|
|
661
|
+
});
|
|
662
|
+
}
|
|
663
|
+
telemetry.track('cli_command_finish', {
|
|
783
664
|
command: 'dev',
|
|
784
|
-
|
|
665
|
+
duration_ms: Date.now() - cmdStart,
|
|
666
|
+
success: 0 === process.exitCode || null == process.exitCode,
|
|
667
|
+
exit_code: process.exitCode ?? 0
|
|
668
|
+
});
|
|
669
|
+
});
|
|
670
|
+
}
|
|
671
|
+
function registerStartCommand(program, telemetry) {
|
|
672
|
+
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 }) {
|
|
673
|
+
var _startOptions_polyfill;
|
|
674
|
+
if (startOptions.author || startOptions['authorMode']) {
|
|
675
|
+
process.env.EXTENSION_AUTHOR_MODE = 'true';
|
|
676
|
+
if (!process.env.EXTENSION_VERBOSE) process.env.EXTENSION_VERBOSE = '1';
|
|
677
|
+
}
|
|
678
|
+
const cmdStart = Date.now();
|
|
679
|
+
telemetry.track('cli_command_start', {
|
|
680
|
+
command: 'start',
|
|
681
|
+
vendors: vendors(browser),
|
|
682
|
+
polyfill_used: (null == (_startOptions_polyfill = startOptions.polyfill) ? void 0 : _startOptions_polyfill.toString()) !== 'false'
|
|
785
683
|
});
|
|
786
|
-
const
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
const raw = logContextOption || devOptions.logContexts;
|
|
684
|
+
const list = vendors(browser);
|
|
685
|
+
validateVendorsOrExit(list, (invalid, supported)=>{
|
|
686
|
+
console.error(unsupportedBrowserFlag(invalid, supported));
|
|
687
|
+
});
|
|
688
|
+
const { extensionStart } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "extension-develop"));
|
|
689
|
+
for (const vendor of list){
|
|
690
|
+
const vendorStart = Date.now();
|
|
691
|
+
telemetry.track('cli_vendor_start', {
|
|
692
|
+
command: 'start',
|
|
693
|
+
vendor
|
|
694
|
+
});
|
|
695
|
+
const logsOption = startOptions.logs;
|
|
696
|
+
const logContextOption = startOptions.logContext;
|
|
697
|
+
const logContexts = (()=>{
|
|
698
|
+
const raw = logContextOption || startOptions.logContexts;
|
|
802
699
|
if (!raw || 0 === String(raw).trim().length) return;
|
|
803
700
|
if ('all' === String(raw).trim().toLowerCase()) return;
|
|
804
701
|
const allowed = [
|
|
@@ -812,254 +709,186 @@ function registerDevCommand(program, telemetry) {
|
|
|
812
709
|
];
|
|
813
710
|
const values = String(raw).split(',').map((s)=>s.trim()).filter((s)=>s.length > 0).filter((c)=>allowed.includes(c));
|
|
814
711
|
return values.length ? values : void 0;
|
|
815
|
-
})()
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
process.env.EXTENSION_AUTHOR_MODE = 'true';
|
|
842
|
-
if (!process.env.EXTENSION_VERBOSE) process.env.EXTENSION_VERBOSE = '1';
|
|
843
|
-
}
|
|
844
|
-
const cmdStart = Date.now();
|
|
845
|
-
telemetry.track('cli_command_start', {
|
|
846
|
-
command: 'start',
|
|
847
|
-
vendors: vendors(browser),
|
|
848
|
-
polyfill_used: (null == (_startOptions_polyfill = startOptions.polyfill) ? void 0 : _startOptions_polyfill.toString()) !== 'false'
|
|
849
|
-
});
|
|
850
|
-
const list = vendors(browser);
|
|
851
|
-
validateVendorsOrExit(list, (invalid, supported)=>{
|
|
852
|
-
console.error(unsupportedBrowserFlag(invalid, supported));
|
|
853
|
-
});
|
|
854
|
-
const versionExact = String(package_namespaceObject.version);
|
|
855
|
-
let extensionStart;
|
|
856
|
-
({ extensionStart } = await requireOrDlx('extension-develop', versionExact));
|
|
857
|
-
for (const vendor of list){
|
|
858
|
-
const vendorStart = Date.now();
|
|
859
|
-
telemetry.track('cli_vendor_start', {
|
|
860
|
-
command: 'start',
|
|
861
|
-
vendor
|
|
862
|
-
});
|
|
863
|
-
const logsOption = startOptions.logs;
|
|
864
|
-
const logContextOption = startOptions.logContext;
|
|
865
|
-
const logContexts = (()=>{
|
|
866
|
-
const raw = logContextOption || startOptions.logContexts;
|
|
867
|
-
if (!raw || 0 === String(raw).trim().length) return;
|
|
868
|
-
if ('all' === String(raw).trim().toLowerCase()) return;
|
|
869
|
-
const allowed = [
|
|
870
|
-
'background',
|
|
871
|
-
'content',
|
|
872
|
-
'page',
|
|
873
|
-
'sidebar',
|
|
874
|
-
'popup',
|
|
875
|
-
'options',
|
|
876
|
-
'devtools'
|
|
877
|
-
];
|
|
878
|
-
const values = String(raw).split(',').map((s)=>s.trim()).filter((s)=>s.length > 0).filter((c)=>allowed.includes(c));
|
|
879
|
-
return values.length ? values : void 0;
|
|
880
|
-
})();
|
|
881
|
-
await extensionStart(pathOrRemoteUrl, {
|
|
882
|
-
mode: 'production',
|
|
883
|
-
profile: startOptions.profile,
|
|
884
|
-
browser: vendor,
|
|
885
|
-
chromiumBinary: startOptions.chromiumBinary,
|
|
886
|
-
geckoBinary: startOptions.geckoBinary,
|
|
887
|
-
startingUrl: startOptions.startingUrl,
|
|
888
|
-
port: startOptions.port,
|
|
889
|
-
source: 'string' == typeof startOptions.source ? startOptions.source : startOptions.source,
|
|
890
|
-
watchSource: startOptions.watchSource,
|
|
891
|
-
logLevel: logsOption || startOptions.logLevel || 'off',
|
|
892
|
-
logContexts,
|
|
893
|
-
logFormat: startOptions.logFormat || 'pretty',
|
|
894
|
-
logTimestamps: false !== startOptions.logTimestamps,
|
|
895
|
-
logColor: false !== startOptions.logColor,
|
|
896
|
-
logUrl: startOptions.logUrl,
|
|
897
|
-
logTab: startOptions.logTab
|
|
898
|
-
});
|
|
899
|
-
telemetry.track('cli_vendor_finish', {
|
|
712
|
+
})();
|
|
713
|
+
await extensionStart(pathOrRemoteUrl, {
|
|
714
|
+
mode: 'production',
|
|
715
|
+
profile: startOptions.profile,
|
|
716
|
+
browser: vendor,
|
|
717
|
+
chromiumBinary: startOptions.chromiumBinary,
|
|
718
|
+
geckoBinary: startOptions.geckoBinary,
|
|
719
|
+
startingUrl: startOptions.startingUrl,
|
|
720
|
+
port: startOptions.port,
|
|
721
|
+
source: 'string' == typeof startOptions.source ? startOptions.source : startOptions.source,
|
|
722
|
+
watchSource: startOptions.watchSource,
|
|
723
|
+
logLevel: logsOption || startOptions.logLevel || 'off',
|
|
724
|
+
logContexts,
|
|
725
|
+
logFormat: startOptions.logFormat || 'pretty',
|
|
726
|
+
logTimestamps: false !== startOptions.logTimestamps,
|
|
727
|
+
logColor: false !== startOptions.logColor,
|
|
728
|
+
logUrl: startOptions.logUrl,
|
|
729
|
+
logTab: startOptions.logTab
|
|
730
|
+
});
|
|
731
|
+
telemetry.track('cli_vendor_finish', {
|
|
732
|
+
command: 'start',
|
|
733
|
+
vendor,
|
|
734
|
+
duration_ms: Date.now() - vendorStart
|
|
735
|
+
});
|
|
736
|
+
}
|
|
737
|
+
telemetry.track('cli_command_finish', {
|
|
900
738
|
command: 'start',
|
|
901
|
-
|
|
902
|
-
|
|
739
|
+
duration_ms: Date.now() - cmdStart,
|
|
740
|
+
success: 0 === process.exitCode || null == process.exitCode,
|
|
741
|
+
exit_code: process.exitCode ?? 0
|
|
903
742
|
});
|
|
904
|
-
}
|
|
905
|
-
telemetry.track('cli_command_finish', {
|
|
906
|
-
command: 'start',
|
|
907
|
-
duration_ms: Date.now() - cmdStart,
|
|
908
|
-
success: 0 === process.exitCode || null == process.exitCode,
|
|
909
|
-
exit_code: process.exitCode ?? 0
|
|
910
|
-
});
|
|
911
|
-
});
|
|
912
|
-
}
|
|
913
|
-
function registerPreviewCommand(program, telemetry) {
|
|
914
|
-
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 }) {
|
|
915
|
-
if (previewOptions.author || previewOptions['authorMode']) {
|
|
916
|
-
process.env.EXTENSION_AUTHOR_MODE = 'true';
|
|
917
|
-
if (!process.env.EXTENSION_VERBOSE) process.env.EXTENSION_VERBOSE = '1';
|
|
918
|
-
}
|
|
919
|
-
const cmdStart = Date.now();
|
|
920
|
-
telemetry.track('cli_command_start', {
|
|
921
|
-
command: 'preview',
|
|
922
|
-
vendors: vendors(browser)
|
|
923
743
|
});
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
let extensionPreview;
|
|
934
|
-
({ extensionPreview } = await requireOrDlx('extension-develop', versionExact));
|
|
935
|
-
for (const vendor of list){
|
|
936
|
-
const vendorStart = Date.now();
|
|
937
|
-
telemetry.track('cli_vendor_start', {
|
|
744
|
+
}
|
|
745
|
+
function registerPreviewCommand(program, telemetry) {
|
|
746
|
+
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 }) {
|
|
747
|
+
if (previewOptions.author || previewOptions['authorMode']) {
|
|
748
|
+
process.env.EXTENSION_AUTHOR_MODE = 'true';
|
|
749
|
+
if (!process.env.EXTENSION_VERBOSE) process.env.EXTENSION_VERBOSE = '1';
|
|
750
|
+
}
|
|
751
|
+
const cmdStart = Date.now();
|
|
752
|
+
telemetry.track('cli_command_start', {
|
|
938
753
|
command: 'preview',
|
|
939
|
-
|
|
754
|
+
vendors: vendors(browser)
|
|
940
755
|
});
|
|
941
|
-
const
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
const raw = logContextOption || previewOptions.logContexts;
|
|
945
|
-
if (!raw || 0 === String(raw).trim().length) return;
|
|
946
|
-
if ('all' === String(raw).trim().toLowerCase()) return;
|
|
947
|
-
const allowed = [
|
|
948
|
-
'background',
|
|
949
|
-
'content',
|
|
950
|
-
'page',
|
|
951
|
-
'sidebar',
|
|
952
|
-
'popup',
|
|
953
|
-
'options',
|
|
954
|
-
'devtools'
|
|
955
|
-
];
|
|
956
|
-
const values = String(raw).split(',').map((s)=>s.trim()).filter((s)=>s.length > 0).filter((c)=>allowed.includes(c));
|
|
957
|
-
return values.length ? values : void 0;
|
|
958
|
-
})();
|
|
959
|
-
await extensionPreview(pathOrRemoteUrl, {
|
|
960
|
-
mode: 'production',
|
|
961
|
-
profile: previewOptions.profile,
|
|
962
|
-
browser: vendor,
|
|
963
|
-
chromiumBinary: previewOptions.chromiumBinary,
|
|
964
|
-
geckoBinary: previewOptions.geckoBinary,
|
|
965
|
-
startingUrl: previewOptions.startingUrl,
|
|
966
|
-
port: previewOptions.port,
|
|
967
|
-
source: 'string' == typeof previewOptions.source ? previewOptions.source : previewOptions.source,
|
|
968
|
-
watchSource: previewOptions.watchSource,
|
|
969
|
-
logLevel: logsOption || previewOptions.logLevel || 'off',
|
|
970
|
-
logContexts,
|
|
971
|
-
logFormat: previewOptions.logFormat || 'pretty',
|
|
972
|
-
logTimestamps: false !== previewOptions.logTimestamps,
|
|
973
|
-
logColor: false !== previewOptions.logColor,
|
|
974
|
-
logUrl: previewOptions.logUrl,
|
|
975
|
-
logTab: previewOptions.logTab
|
|
756
|
+
const list = vendors(browser);
|
|
757
|
+
validateVendorsOrExit(list, (invalid, supported)=>{
|
|
758
|
+
console.error(unsupportedBrowserFlag(invalid, supported));
|
|
976
759
|
});
|
|
977
|
-
|
|
760
|
+
if (!process.env.EXTJS_LIGHT) {
|
|
761
|
+
const isRemote = 'string' == typeof pathOrRemoteUrl && /^https?:/i.test(pathOrRemoteUrl);
|
|
762
|
+
if (isRemote) process.env.EXTJS_LIGHT = '1';
|
|
763
|
+
}
|
|
764
|
+
const { extensionPreview } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "extension-develop"));
|
|
765
|
+
for (const vendor of list){
|
|
766
|
+
const vendorStart = Date.now();
|
|
767
|
+
telemetry.track('cli_vendor_start', {
|
|
768
|
+
command: 'preview',
|
|
769
|
+
vendor
|
|
770
|
+
});
|
|
771
|
+
const logsOption = previewOptions.logs;
|
|
772
|
+
const logContextOption = previewOptions.logContext;
|
|
773
|
+
const logContexts = (()=>{
|
|
774
|
+
const raw = logContextOption || previewOptions.logContexts;
|
|
775
|
+
if (!raw || 0 === String(raw).trim().length) return;
|
|
776
|
+
if ('all' === String(raw).trim().toLowerCase()) return;
|
|
777
|
+
const allowed = [
|
|
778
|
+
'background',
|
|
779
|
+
'content',
|
|
780
|
+
'page',
|
|
781
|
+
'sidebar',
|
|
782
|
+
'popup',
|
|
783
|
+
'options',
|
|
784
|
+
'devtools'
|
|
785
|
+
];
|
|
786
|
+
const values = String(raw).split(',').map((s)=>s.trim()).filter((s)=>s.length > 0).filter((c)=>allowed.includes(c));
|
|
787
|
+
return values.length ? values : void 0;
|
|
788
|
+
})();
|
|
789
|
+
await extensionPreview(pathOrRemoteUrl, {
|
|
790
|
+
mode: 'production',
|
|
791
|
+
profile: previewOptions.profile,
|
|
792
|
+
browser: vendor,
|
|
793
|
+
chromiumBinary: previewOptions.chromiumBinary,
|
|
794
|
+
geckoBinary: previewOptions.geckoBinary,
|
|
795
|
+
startingUrl: previewOptions.startingUrl,
|
|
796
|
+
port: previewOptions.port,
|
|
797
|
+
source: 'string' == typeof previewOptions.source ? previewOptions.source : previewOptions.source,
|
|
798
|
+
watchSource: previewOptions.watchSource,
|
|
799
|
+
logLevel: logsOption || previewOptions.logLevel || 'off',
|
|
800
|
+
logContexts,
|
|
801
|
+
logFormat: previewOptions.logFormat || 'pretty',
|
|
802
|
+
logTimestamps: false !== previewOptions.logTimestamps,
|
|
803
|
+
logColor: false !== previewOptions.logColor,
|
|
804
|
+
logUrl: previewOptions.logUrl,
|
|
805
|
+
logTab: previewOptions.logTab
|
|
806
|
+
});
|
|
807
|
+
telemetry.track('cli_vendor_finish', {
|
|
808
|
+
command: 'preview',
|
|
809
|
+
vendor,
|
|
810
|
+
duration_ms: Date.now() - vendorStart
|
|
811
|
+
});
|
|
812
|
+
}
|
|
813
|
+
telemetry.track('cli_command_finish', {
|
|
978
814
|
command: 'preview',
|
|
979
|
-
|
|
980
|
-
|
|
815
|
+
duration_ms: Date.now() - cmdStart,
|
|
816
|
+
success: 0 === process.exitCode || null == process.exitCode,
|
|
817
|
+
exit_code: process.exitCode ?? 0
|
|
981
818
|
});
|
|
982
|
-
}
|
|
983
|
-
telemetry.track('cli_command_finish', {
|
|
984
|
-
command: 'preview',
|
|
985
|
-
duration_ms: Date.now() - cmdStart,
|
|
986
|
-
success: 0 === process.exitCode || null == process.exitCode,
|
|
987
|
-
exit_code: process.exitCode ?? 0
|
|
988
819
|
});
|
|
989
|
-
}
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
telemetry.track('cli_command_start', {
|
|
999
|
-
command: 'build',
|
|
1000
|
-
vendors: vendors(browser),
|
|
1001
|
-
polyfill_used: buildOptions.polyfill || false,
|
|
1002
|
-
zip: buildOptions.zip || false,
|
|
1003
|
-
zip_source: buildOptions.zipSource || false
|
|
1004
|
-
});
|
|
1005
|
-
const list = vendors(browser);
|
|
1006
|
-
validateVendorsOrExit(list, (invalid, supported)=>{
|
|
1007
|
-
console.error(unsupportedBrowserFlag(invalid, supported));
|
|
1008
|
-
});
|
|
1009
|
-
const versionExact = String(package_namespaceObject.version);
|
|
1010
|
-
let extensionBuild;
|
|
1011
|
-
({ extensionBuild } = await requireOrDlx('extension-develop', versionExact));
|
|
1012
|
-
for (const vendor of list){
|
|
1013
|
-
const vendorStart = Date.now();
|
|
1014
|
-
telemetry.track('cli_vendor_start', {
|
|
820
|
+
}
|
|
821
|
+
function registerBuildCommand(program, telemetry) {
|
|
822
|
+
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 }) {
|
|
823
|
+
if (buildOptions.author || buildOptions['authorMode']) {
|
|
824
|
+
process.env.EXTENSION_AUTHOR_MODE = 'true';
|
|
825
|
+
if (!process.env.EXTENSION_VERBOSE) process.env.EXTENSION_VERBOSE = '1';
|
|
826
|
+
}
|
|
827
|
+
const cmdStart = Date.now();
|
|
828
|
+
telemetry.track('cli_command_start', {
|
|
1015
829
|
command: 'build',
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
polyfill: buildOptions.polyfill,
|
|
1021
|
-
zip: buildOptions.zip,
|
|
1022
|
-
zipSource: buildOptions.zipSource,
|
|
1023
|
-
zipFilename: buildOptions.zipFilename,
|
|
1024
|
-
silent: buildOptions.silent
|
|
830
|
+
vendors: vendors(browser),
|
|
831
|
+
polyfill_used: buildOptions.polyfill || false,
|
|
832
|
+
zip: buildOptions.zip || false,
|
|
833
|
+
zip_source: buildOptions.zipSource || false
|
|
1025
834
|
});
|
|
1026
|
-
|
|
1027
|
-
|
|
835
|
+
const list = vendors(browser);
|
|
836
|
+
validateVendorsOrExit(list, (invalid, supported)=>{
|
|
837
|
+
console.error(unsupportedBrowserFlag(invalid, supported));
|
|
1028
838
|
});
|
|
1029
|
-
|
|
839
|
+
const { extensionBuild } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "extension-develop"));
|
|
840
|
+
for (const vendor of list){
|
|
841
|
+
const vendorStart = Date.now();
|
|
842
|
+
telemetry.track('cli_vendor_start', {
|
|
843
|
+
command: 'build',
|
|
844
|
+
vendor
|
|
845
|
+
});
|
|
846
|
+
const buildSummary = await extensionBuild(pathOrRemoteUrl, {
|
|
847
|
+
browser: vendor,
|
|
848
|
+
polyfill: buildOptions.polyfill,
|
|
849
|
+
zip: buildOptions.zip,
|
|
850
|
+
zipSource: buildOptions.zipSource,
|
|
851
|
+
zipFilename: buildOptions.zipFilename,
|
|
852
|
+
silent: buildOptions.silent
|
|
853
|
+
});
|
|
854
|
+
telemetry.track('cli_build_summary', {
|
|
855
|
+
...buildSummary
|
|
856
|
+
});
|
|
857
|
+
telemetry.track('cli_vendor_finish', {
|
|
858
|
+
command: 'build',
|
|
859
|
+
vendor,
|
|
860
|
+
duration_ms: Date.now() - vendorStart
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
telemetry.track('cli_command_finish', {
|
|
1030
864
|
command: 'build',
|
|
1031
|
-
|
|
1032
|
-
|
|
865
|
+
duration_ms: Date.now() - cmdStart,
|
|
866
|
+
success: 0 === process.exitCode || null == process.exitCode,
|
|
867
|
+
exit_code: process.exitCode ?? 0
|
|
1033
868
|
});
|
|
1034
|
-
}
|
|
1035
|
-
telemetry.track('cli_command_finish', {
|
|
1036
|
-
command: 'build',
|
|
1037
|
-
duration_ms: Date.now() - cmdStart,
|
|
1038
|
-
success: 0 === process.exitCode || null == process.exitCode,
|
|
1039
|
-
exit_code: process.exitCode ?? 0
|
|
1040
869
|
});
|
|
870
|
+
}
|
|
871
|
+
check_updates_checkUpdates(package_namespaceObject);
|
|
872
|
+
const extensionJs = external_commander_namespaceObject.program;
|
|
873
|
+
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);
|
|
874
|
+
registerCreateCommand(extensionJs, telemetry_cli_telemetry);
|
|
875
|
+
registerDevCommand(extensionJs, telemetry_cli_telemetry);
|
|
876
|
+
registerStartCommand(extensionJs, telemetry_cli_telemetry);
|
|
877
|
+
registerPreviewCommand(extensionJs, telemetry_cli_telemetry);
|
|
878
|
+
registerBuildCommand(extensionJs, telemetry_cli_telemetry);
|
|
879
|
+
extensionJs.on('option:ai-help', function() {
|
|
880
|
+
console.log(programAIHelp());
|
|
881
|
+
process.exit(0);
|
|
1041
882
|
});
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
extensionJs.on('option:ai-help', function() {
|
|
1052
|
-
console.log(programAIHelp());
|
|
1053
|
-
process.exit(0);
|
|
1054
|
-
});
|
|
1055
|
-
if (process.argv.length <= 2) {
|
|
1056
|
-
extensionJs.outputHelp();
|
|
1057
|
-
process.exit(0);
|
|
1058
|
-
}
|
|
1059
|
-
extensionJs.parseAsync().catch((err)=>{
|
|
1060
|
-
console.error(err);
|
|
1061
|
-
process.exit(1);
|
|
1062
|
-
});
|
|
883
|
+
if (process.argv.length <= 2) {
|
|
884
|
+
extensionJs.outputHelp();
|
|
885
|
+
process.exit(0);
|
|
886
|
+
}
|
|
887
|
+
extensionJs.parseAsync().catch((err)=>{
|
|
888
|
+
console.error(err);
|
|
889
|
+
process.exit(1);
|
|
890
|
+
});
|
|
891
|
+
})();
|
|
1063
892
|
for(var __webpack_i__ in __webpack_exports__)exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
1064
893
|
Object.defineProperty(exports, '__esModule', {
|
|
1065
894
|
value: true
|