web-ext 6.7.0 → 7.1.0
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 +17 -8
- package/bin/web-ext.js +13 -0
- package/index.js +12 -0
- package/lib/cmd/build.js +226 -0
- package/lib/cmd/build.js.map +1 -0
- package/lib/cmd/docs.js +16 -0
- package/lib/cmd/docs.js.map +1 -0
- package/lib/cmd/index.js +47 -0
- package/lib/cmd/index.js.map +1 -0
- package/lib/cmd/lint.js +50 -0
- package/lib/cmd/lint.js.map +1 -0
- package/lib/cmd/run.js +199 -0
- package/lib/cmd/run.js.map +1 -0
- package/lib/cmd/sign.js +140 -0
- package/lib/cmd/sign.js.map +1 -0
- package/lib/config.js +144 -0
- package/lib/config.js.map +1 -0
- package/{src → lib}/errors.js +26 -35
- package/lib/errors.js.map +1 -0
- package/lib/extension-runners/base.js +2 -0
- package/lib/extension-runners/base.js.map +1 -0
- package/{src → lib}/extension-runners/chromium.js +121 -178
- package/lib/extension-runners/chromium.js.map +1 -0
- package/{src → lib}/extension-runners/firefox-android.js +168 -326
- package/lib/extension-runners/firefox-android.js.map +1 -0
- package/{src → lib}/extension-runners/firefox-desktop.js +73 -114
- package/lib/extension-runners/firefox-desktop.js.map +1 -0
- package/lib/extension-runners/index.js +311 -0
- package/lib/extension-runners/index.js.map +1 -0
- package/lib/firefox/index.js +362 -0
- package/lib/firefox/index.js.map +1 -0
- package/lib/firefox/package-identifiers.js +5 -0
- package/lib/firefox/package-identifiers.js.map +1 -0
- package/{src → lib}/firefox/preferences.js +27 -70
- package/lib/firefox/preferences.js.map +1 -0
- package/{src → lib}/firefox/rdp-client.js +98 -105
- package/lib/firefox/rdp-client.js.map +1 -0
- package/{src → lib}/firefox/remote.js +55 -129
- package/lib/firefox/remote.js.map +1 -0
- package/lib/main.js +9 -0
- package/lib/main.js.map +1 -0
- package/lib/program.js +663 -0
- package/lib/program.js.map +1 -0
- package/lib/util/adb.js +322 -0
- package/lib/util/adb.js.map +1 -0
- package/lib/util/artifacts.js +52 -0
- package/lib/util/artifacts.js.map +1 -0
- package/lib/util/desktop-notifier.js +27 -0
- package/lib/util/desktop-notifier.js.map +1 -0
- package/{src → lib}/util/file-exists.js +7 -14
- package/lib/util/file-exists.js.map +1 -0
- package/{src → lib}/util/file-filter.js +31 -59
- package/lib/util/file-filter.js.map +1 -0
- package/lib/util/is-directory.js +20 -0
- package/lib/util/is-directory.js.map +1 -0
- package/lib/util/logger.js +79 -0
- package/lib/util/logger.js.map +1 -0
- package/{src → lib}/util/manifest.js +18 -50
- package/lib/util/manifest.js.map +1 -0
- package/{src → lib}/util/promisify.js +6 -9
- package/lib/util/promisify.js.map +1 -0
- package/{src → lib}/util/stdin.js +3 -7
- package/lib/util/stdin.js.map +1 -0
- package/{src → lib}/util/temp-dir.js +47 -52
- package/lib/util/temp-dir.js.map +1 -0
- package/lib/util/updates.js +16 -0
- package/lib/util/updates.js.map +1 -0
- package/lib/watcher.js +78 -0
- package/lib/watcher.js.map +1 -0
- package/package.json +50 -52
- package/CODE_OF_CONDUCT.md +0 -10
- package/bin/web-ext +0 -7
- package/dist/web-ext.js +0 -2
- package/index.mjs +0 -13
- package/src/cmd/build.js +0 -319
- package/src/cmd/docs.js +0 -33
- package/src/cmd/index.js +0 -57
- package/src/cmd/lint.js +0 -102
- package/src/cmd/run.js +0 -266
- package/src/cmd/sign.js +0 -198
- package/src/config.js +0 -187
- package/src/extension-runners/base.js +0 -40
- package/src/extension-runners/index.js +0 -381
- package/src/firefox/index.js +0 -541
- package/src/firefox/package-identifiers.js +0 -14
- package/src/main.js +0 -19
- package/src/program.js +0 -765
- package/src/util/adb.js +0 -433
- package/src/util/artifacts.js +0 -69
- package/src/util/desktop-notifier.js +0 -41
- package/src/util/is-directory.js +0 -23
- package/src/util/logger.js +0 -131
- package/src/util/updates.js +0 -21
- package/src/watcher.js +0 -114
|
@@ -1,381 +0,0 @@
|
|
|
1
|
-
/* @flow */
|
|
2
|
-
|
|
3
|
-
import readline from 'readline';
|
|
4
|
-
|
|
5
|
-
import type Watchpack from 'watchpack';
|
|
6
|
-
|
|
7
|
-
import type {
|
|
8
|
-
IExtensionRunner, // eslint-disable-line import/named
|
|
9
|
-
ExtensionRunnerReloadResult,
|
|
10
|
-
} from './base';
|
|
11
|
-
import {WebExtError} from '../errors';
|
|
12
|
-
import {
|
|
13
|
-
showDesktopNotification as defaultDesktopNotifications,
|
|
14
|
-
} from '../util/desktop-notifier';
|
|
15
|
-
import type {FirefoxAndroidExtensionRunnerParams} from './firefox-android';
|
|
16
|
-
import type {FirefoxDesktopExtensionRunnerParams} from './firefox-desktop';
|
|
17
|
-
import type {ChromiumExtensionRunnerParams} from './chromium';
|
|
18
|
-
import {createLogger} from '../util/logger';
|
|
19
|
-
import type {FileFilterCreatorFn} from '../util/file-filter';
|
|
20
|
-
import {
|
|
21
|
-
createFileFilter as defaultFileFilterCreator,
|
|
22
|
-
} from '../util/file-filter';
|
|
23
|
-
import {
|
|
24
|
-
isTTY, setRawMode,
|
|
25
|
-
} from '../util/stdin';
|
|
26
|
-
import defaultSourceWatcher from '../watcher';
|
|
27
|
-
import type {OnSourceChangeFn} from '../watcher';
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const log = createLogger(__filename);
|
|
31
|
-
|
|
32
|
-
export type ExtensionRunnerConfig = {|
|
|
33
|
-
target: 'firefox-desktop',
|
|
34
|
-
params: FirefoxDesktopExtensionRunnerParams,
|
|
35
|
-
|} | {|
|
|
36
|
-
target: 'firefox-android',
|
|
37
|
-
params: FirefoxAndroidExtensionRunnerParams,
|
|
38
|
-
|} | {|
|
|
39
|
-
target: 'chromium',
|
|
40
|
-
params: ChromiumExtensionRunnerParams,
|
|
41
|
-
|};
|
|
42
|
-
|
|
43
|
-
export type MultiExtensionRunnerParams = {|
|
|
44
|
-
runners: Array<IExtensionRunner>,
|
|
45
|
-
desktopNotifications: typeof defaultDesktopNotifications,
|
|
46
|
-
|};
|
|
47
|
-
|
|
48
|
-
export async function createExtensionRunner(
|
|
49
|
-
config: ExtensionRunnerConfig
|
|
50
|
-
): Promise<IExtensionRunner> {
|
|
51
|
-
switch (config.target) {
|
|
52
|
-
case 'firefox-desktop': {
|
|
53
|
-
// TODO: use async import instead of require - https://github.com/mozilla/web-ext/issues/1306
|
|
54
|
-
const {FirefoxDesktopExtensionRunner} = require('./firefox-desktop');
|
|
55
|
-
return new FirefoxDesktopExtensionRunner(config.params);
|
|
56
|
-
}
|
|
57
|
-
case 'firefox-android': {
|
|
58
|
-
// TODO: use async import instead of require - https://github.com/mozilla/web-ext/issues/1306
|
|
59
|
-
const {FirefoxAndroidExtensionRunner} = require('./firefox-android');
|
|
60
|
-
return new FirefoxAndroidExtensionRunner(config.params);
|
|
61
|
-
}
|
|
62
|
-
case 'chromium': {
|
|
63
|
-
// TODO: use async import instead of require - https://github.com/mozilla/web-ext/issues/1306
|
|
64
|
-
const {ChromiumExtensionRunner} = require('./chromium');
|
|
65
|
-
return new ChromiumExtensionRunner(config.params);
|
|
66
|
-
}
|
|
67
|
-
default:
|
|
68
|
-
throw new WebExtError(`Unknown target: "${config.target}"`);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Implements an IExtensionRunner which allow the caller to
|
|
74
|
-
* manage multiple extension runners at the same time (e.g. by running
|
|
75
|
-
* a Firefox Desktop instance alongside to a Firefox for Android instance).
|
|
76
|
-
*/
|
|
77
|
-
export class MultiExtensionRunner {
|
|
78
|
-
extensionRunners: Array<IExtensionRunner>;
|
|
79
|
-
desktopNotifications: typeof defaultDesktopNotifications;
|
|
80
|
-
|
|
81
|
-
constructor(params: MultiExtensionRunnerParams) {
|
|
82
|
-
this.extensionRunners = params.runners;
|
|
83
|
-
this.desktopNotifications = params.desktopNotifications;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// Method exported from the IExtensionRunner interface.
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Returns the runner name.
|
|
90
|
-
*/
|
|
91
|
-
getName(): string {
|
|
92
|
-
return 'Multi Extension Runner';
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Call the `run` method on all the managed extension runners,
|
|
97
|
-
* and awaits that all the runners has been successfully started.
|
|
98
|
-
*/
|
|
99
|
-
async run(): Promise<void> {
|
|
100
|
-
const promises = [];
|
|
101
|
-
for (const runner of this.extensionRunners) {
|
|
102
|
-
promises.push(runner.run());
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
await Promise.all(promises);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Reloads all the extensions on all the managed extension runners,
|
|
110
|
-
* collect any reload error, and resolves to an array composed by
|
|
111
|
-
* a ExtensionRunnerReloadResult object per managed runner.
|
|
112
|
-
*
|
|
113
|
-
* Any detected reload error is also logged on the terminal and shows as a
|
|
114
|
-
* desktop notification.
|
|
115
|
-
*/
|
|
116
|
-
async reloadAllExtensions(): Promise<Array<ExtensionRunnerReloadResult>> {
|
|
117
|
-
log.debug('Reloading all reloadable add-ons');
|
|
118
|
-
|
|
119
|
-
const promises = [];
|
|
120
|
-
for (const runner of this.extensionRunners) {
|
|
121
|
-
const reloadPromise = runner.reloadAllExtensions().then(
|
|
122
|
-
() => {
|
|
123
|
-
return {runnerName: runner.getName()};
|
|
124
|
-
},
|
|
125
|
-
(error) => {
|
|
126
|
-
return {
|
|
127
|
-
runnerName: runner.getName(),
|
|
128
|
-
reloadError: error,
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
);
|
|
132
|
-
|
|
133
|
-
promises.push(reloadPromise);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return await Promise.all(promises).then((results) => {
|
|
137
|
-
this.handleReloadResults(results);
|
|
138
|
-
return results;
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Reloads a single extension on all the managed extension runners,
|
|
144
|
-
* collect any reload error and resolves to an array composed by
|
|
145
|
-
* a ExtensionRunnerReloadResult object per managed runner.
|
|
146
|
-
*
|
|
147
|
-
* Any detected reload error is also logged on the terminal and shows as a
|
|
148
|
-
* desktop notification.
|
|
149
|
-
*/
|
|
150
|
-
async reloadExtensionBySourceDir(
|
|
151
|
-
sourceDir: string
|
|
152
|
-
): Promise<Array<ExtensionRunnerReloadResult>> {
|
|
153
|
-
log.debug(`Reloading add-on at ${sourceDir}`);
|
|
154
|
-
|
|
155
|
-
const promises: Array<Promise<ExtensionRunnerReloadResult>> = [];
|
|
156
|
-
for (const runner of this.extensionRunners) {
|
|
157
|
-
const reloadPromise = runner.reloadExtensionBySourceDir(sourceDir).then(
|
|
158
|
-
() => {
|
|
159
|
-
return {runnerName: runner.getName(), sourceDir};
|
|
160
|
-
},
|
|
161
|
-
(error) => {
|
|
162
|
-
return {
|
|
163
|
-
runnerName: runner.getName(),
|
|
164
|
-
reloadError: error,
|
|
165
|
-
sourceDir,
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
);
|
|
169
|
-
|
|
170
|
-
promises.push(reloadPromise);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
return await Promise.all(promises).then((results) => {
|
|
174
|
-
this.handleReloadResults(results);
|
|
175
|
-
return results;
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Register a callback to be called when all the managed runners has been exited.
|
|
181
|
-
*/
|
|
182
|
-
registerCleanup(cleanupCallback: Function): void {
|
|
183
|
-
const promises = [];
|
|
184
|
-
|
|
185
|
-
// Create a promise for every extension runner managed by this instance,
|
|
186
|
-
// the promise will be resolved when the particular runner calls its
|
|
187
|
-
// registered cleanup callbacks.
|
|
188
|
-
for (const runner of this.extensionRunners) {
|
|
189
|
-
promises.push(new Promise((resolve) => {
|
|
190
|
-
runner.registerCleanup(resolve);
|
|
191
|
-
}));
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
// Wait for all the created promises to be resolved or rejected
|
|
195
|
-
// (once each one of the runners has cleaned up) and then call
|
|
196
|
-
// the cleanup callback registered to this runner.
|
|
197
|
-
Promise.all(promises).then(cleanupCallback, cleanupCallback);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* Exits all the managed runner has been exited.
|
|
202
|
-
*/
|
|
203
|
-
async exit(): Promise<void> {
|
|
204
|
-
const promises = [];
|
|
205
|
-
for (const runner of this.extensionRunners) {
|
|
206
|
-
promises.push(runner.exit());
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
await Promise.all(promises);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
// Private helper methods.
|
|
213
|
-
|
|
214
|
-
handleReloadResults(results: Array<ExtensionRunnerReloadResult>): void {
|
|
215
|
-
for (const {runnerName, reloadError, sourceDir} of results) {
|
|
216
|
-
if (reloadError instanceof Error) {
|
|
217
|
-
let message = 'Error occurred while reloading';
|
|
218
|
-
if (sourceDir) {
|
|
219
|
-
message += ` "${sourceDir}" `;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
message += `on "${runnerName}" - ${reloadError.message}`;
|
|
223
|
-
|
|
224
|
-
log.error(`\n${message}`);
|
|
225
|
-
log.debug(reloadError.stack);
|
|
226
|
-
|
|
227
|
-
this.desktopNotifications({
|
|
228
|
-
title: 'web-ext run: extension reload error',
|
|
229
|
-
message,
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// defaultWatcherCreator types and implementation.
|
|
237
|
-
|
|
238
|
-
export type WatcherCreatorParams = {|
|
|
239
|
-
reloadExtension: (string) => void,
|
|
240
|
-
sourceDir: string,
|
|
241
|
-
watchFile?: Array<string>,
|
|
242
|
-
watchIgnored?: Array<string>,
|
|
243
|
-
artifactsDir: string,
|
|
244
|
-
onSourceChange?: OnSourceChangeFn,
|
|
245
|
-
ignoreFiles?: Array<string>,
|
|
246
|
-
createFileFilter?: FileFilterCreatorFn,
|
|
247
|
-
|};
|
|
248
|
-
|
|
249
|
-
export type WatcherCreatorFn = (params: WatcherCreatorParams) => Watchpack;
|
|
250
|
-
|
|
251
|
-
export function defaultWatcherCreator(
|
|
252
|
-
{
|
|
253
|
-
reloadExtension, sourceDir, watchFile,
|
|
254
|
-
watchIgnored, artifactsDir, ignoreFiles,
|
|
255
|
-
onSourceChange = defaultSourceWatcher,
|
|
256
|
-
createFileFilter = defaultFileFilterCreator,
|
|
257
|
-
}: WatcherCreatorParams
|
|
258
|
-
): Watchpack {
|
|
259
|
-
const fileFilter = createFileFilter(
|
|
260
|
-
{sourceDir, artifactsDir, ignoreFiles}
|
|
261
|
-
);
|
|
262
|
-
return onSourceChange({
|
|
263
|
-
sourceDir,
|
|
264
|
-
watchFile,
|
|
265
|
-
watchIgnored,
|
|
266
|
-
artifactsDir,
|
|
267
|
-
onChange: () => reloadExtension(sourceDir),
|
|
268
|
-
shouldWatchFile: (file) => fileFilter.wantFile(file),
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
// defaultReloadStrategy types and implementation.
|
|
274
|
-
|
|
275
|
-
export type ReloadStrategyParams = {|
|
|
276
|
-
extensionRunner: IExtensionRunner,
|
|
277
|
-
sourceDir: string,
|
|
278
|
-
watchFile?: Array<string>,
|
|
279
|
-
watchIgnored?: Array<string>,
|
|
280
|
-
artifactsDir: string,
|
|
281
|
-
ignoreFiles?: Array<string>,
|
|
282
|
-
noInput?: boolean,
|
|
283
|
-
|};
|
|
284
|
-
|
|
285
|
-
export type ReloadStrategyOptions = {|
|
|
286
|
-
createWatcher?: WatcherCreatorFn,
|
|
287
|
-
stdin?: stream$Readable,
|
|
288
|
-
kill?: (pid: number, signal?: string | number) => void,
|
|
289
|
-
|};
|
|
290
|
-
|
|
291
|
-
export function defaultReloadStrategy(
|
|
292
|
-
{
|
|
293
|
-
artifactsDir,
|
|
294
|
-
extensionRunner,
|
|
295
|
-
ignoreFiles,
|
|
296
|
-
noInput = false,
|
|
297
|
-
sourceDir,
|
|
298
|
-
watchFile,
|
|
299
|
-
watchIgnored,
|
|
300
|
-
}: ReloadStrategyParams,
|
|
301
|
-
{
|
|
302
|
-
createWatcher = defaultWatcherCreator,
|
|
303
|
-
stdin = process.stdin,
|
|
304
|
-
// $FlowIgnore: ignore method-unbinding.
|
|
305
|
-
kill = process.kill,
|
|
306
|
-
}: ReloadStrategyOptions = {}
|
|
307
|
-
): void {
|
|
308
|
-
const allowInput = !noInput;
|
|
309
|
-
if (!allowInput) {
|
|
310
|
-
log.debug('Input has been disabled because of noInput==true');
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
const watcher: Watchpack = createWatcher({
|
|
314
|
-
reloadExtension: (watchedSourceDir) => {
|
|
315
|
-
extensionRunner.reloadExtensionBySourceDir(watchedSourceDir);
|
|
316
|
-
},
|
|
317
|
-
sourceDir,
|
|
318
|
-
watchFile,
|
|
319
|
-
watchIgnored,
|
|
320
|
-
artifactsDir,
|
|
321
|
-
ignoreFiles,
|
|
322
|
-
});
|
|
323
|
-
|
|
324
|
-
extensionRunner.registerCleanup(() => {
|
|
325
|
-
watcher.close();
|
|
326
|
-
if (allowInput) {
|
|
327
|
-
stdin.pause();
|
|
328
|
-
}
|
|
329
|
-
});
|
|
330
|
-
|
|
331
|
-
if (allowInput && isTTY(stdin)) {
|
|
332
|
-
readline.emitKeypressEvents(stdin);
|
|
333
|
-
setRawMode(stdin, true);
|
|
334
|
-
|
|
335
|
-
const keypressUsageInfo = 'Press R to reload (and Ctrl-C to quit)';
|
|
336
|
-
|
|
337
|
-
// NOTE: this `Promise.resolve().then(...)` is basically used to spawn a "co-routine"
|
|
338
|
-
// that is executed before the callback attached to the Promise returned by this function
|
|
339
|
-
// (and it allows the `run` function to not be stuck in the while loop).
|
|
340
|
-
Promise.resolve().then(async function() {
|
|
341
|
-
log.info(keypressUsageInfo);
|
|
342
|
-
|
|
343
|
-
let userExit = false;
|
|
344
|
-
|
|
345
|
-
while (!userExit) {
|
|
346
|
-
const keyPressed = await new Promise((resolve) => {
|
|
347
|
-
stdin.once('keypress', (str, key) => resolve(key));
|
|
348
|
-
});
|
|
349
|
-
|
|
350
|
-
if (keyPressed.ctrl && keyPressed.name === 'c') {
|
|
351
|
-
userExit = true;
|
|
352
|
-
} else if (keyPressed.name === 'z') {
|
|
353
|
-
// Prepare to suspend.
|
|
354
|
-
|
|
355
|
-
// NOTE: Switch the raw mode off before suspending (needed to make the keypress event
|
|
356
|
-
// to work correctly when the nodejs process is resumed).
|
|
357
|
-
setRawMode(stdin, false);
|
|
358
|
-
|
|
359
|
-
log.info('\nweb-ext has been suspended on user request');
|
|
360
|
-
kill(process.pid, 'SIGTSTP');
|
|
361
|
-
|
|
362
|
-
// Prepare to resume.
|
|
363
|
-
|
|
364
|
-
log.info(`\nweb-ext has been resumed. ${keypressUsageInfo}`);
|
|
365
|
-
|
|
366
|
-
// Switch the raw mode on on resume.
|
|
367
|
-
setRawMode(stdin, true);
|
|
368
|
-
} else if (keyPressed.name === 'r') {
|
|
369
|
-
log.debug('Reloading installed extensions on user request');
|
|
370
|
-
await extensionRunner.reloadAllExtensions().catch((err) => {
|
|
371
|
-
log.warn(`\nError reloading extension: ${err}`);
|
|
372
|
-
log.debug(`Reloading extension error stack: ${err.stack}`);
|
|
373
|
-
});
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
log.info('\nExiting web-ext on user request');
|
|
378
|
-
extensionRunner.exit();
|
|
379
|
-
});
|
|
380
|
-
}
|
|
381
|
-
}
|