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