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.
Files changed (94) hide show
  1. package/README.md +17 -8
  2. package/bin/web-ext.js +13 -0
  3. package/index.js +12 -0
  4. package/lib/cmd/build.js +226 -0
  5. package/lib/cmd/build.js.map +1 -0
  6. package/lib/cmd/docs.js +16 -0
  7. package/lib/cmd/docs.js.map +1 -0
  8. package/lib/cmd/index.js +47 -0
  9. package/lib/cmd/index.js.map +1 -0
  10. package/lib/cmd/lint.js +50 -0
  11. package/lib/cmd/lint.js.map +1 -0
  12. package/lib/cmd/run.js +199 -0
  13. package/lib/cmd/run.js.map +1 -0
  14. package/lib/cmd/sign.js +140 -0
  15. package/lib/cmd/sign.js.map +1 -0
  16. package/lib/config.js +144 -0
  17. package/lib/config.js.map +1 -0
  18. package/{src → lib}/errors.js +26 -35
  19. package/lib/errors.js.map +1 -0
  20. package/lib/extension-runners/base.js +2 -0
  21. package/lib/extension-runners/base.js.map +1 -0
  22. package/{src → lib}/extension-runners/chromium.js +121 -178
  23. package/lib/extension-runners/chromium.js.map +1 -0
  24. package/{src → lib}/extension-runners/firefox-android.js +168 -326
  25. package/lib/extension-runners/firefox-android.js.map +1 -0
  26. package/{src → lib}/extension-runners/firefox-desktop.js +73 -114
  27. package/lib/extension-runners/firefox-desktop.js.map +1 -0
  28. package/lib/extension-runners/index.js +311 -0
  29. package/lib/extension-runners/index.js.map +1 -0
  30. package/lib/firefox/index.js +362 -0
  31. package/lib/firefox/index.js.map +1 -0
  32. package/lib/firefox/package-identifiers.js +5 -0
  33. package/lib/firefox/package-identifiers.js.map +1 -0
  34. package/{src → lib}/firefox/preferences.js +27 -70
  35. package/lib/firefox/preferences.js.map +1 -0
  36. package/{src → lib}/firefox/rdp-client.js +98 -105
  37. package/lib/firefox/rdp-client.js.map +1 -0
  38. package/{src → lib}/firefox/remote.js +55 -129
  39. package/lib/firefox/remote.js.map +1 -0
  40. package/lib/main.js +9 -0
  41. package/lib/main.js.map +1 -0
  42. package/lib/program.js +663 -0
  43. package/lib/program.js.map +1 -0
  44. package/lib/util/adb.js +322 -0
  45. package/lib/util/adb.js.map +1 -0
  46. package/lib/util/artifacts.js +52 -0
  47. package/lib/util/artifacts.js.map +1 -0
  48. package/lib/util/desktop-notifier.js +27 -0
  49. package/lib/util/desktop-notifier.js.map +1 -0
  50. package/{src → lib}/util/file-exists.js +7 -14
  51. package/lib/util/file-exists.js.map +1 -0
  52. package/{src → lib}/util/file-filter.js +31 -59
  53. package/lib/util/file-filter.js.map +1 -0
  54. package/lib/util/is-directory.js +20 -0
  55. package/lib/util/is-directory.js.map +1 -0
  56. package/lib/util/logger.js +79 -0
  57. package/lib/util/logger.js.map +1 -0
  58. package/{src → lib}/util/manifest.js +18 -50
  59. package/lib/util/manifest.js.map +1 -0
  60. package/{src → lib}/util/promisify.js +6 -9
  61. package/lib/util/promisify.js.map +1 -0
  62. package/{src → lib}/util/stdin.js +3 -7
  63. package/lib/util/stdin.js.map +1 -0
  64. package/{src → lib}/util/temp-dir.js +47 -52
  65. package/lib/util/temp-dir.js.map +1 -0
  66. package/lib/util/updates.js +16 -0
  67. package/lib/util/updates.js.map +1 -0
  68. package/lib/watcher.js +78 -0
  69. package/lib/watcher.js.map +1 -0
  70. package/package.json +50 -52
  71. package/CODE_OF_CONDUCT.md +0 -10
  72. package/bin/web-ext +0 -7
  73. package/dist/web-ext.js +0 -2
  74. package/index.mjs +0 -13
  75. package/src/cmd/build.js +0 -319
  76. package/src/cmd/docs.js +0 -33
  77. package/src/cmd/index.js +0 -57
  78. package/src/cmd/lint.js +0 -102
  79. package/src/cmd/run.js +0 -266
  80. package/src/cmd/sign.js +0 -198
  81. package/src/config.js +0 -187
  82. package/src/extension-runners/base.js +0 -40
  83. package/src/extension-runners/index.js +0 -381
  84. package/src/firefox/index.js +0 -541
  85. package/src/firefox/package-identifiers.js +0 -14
  86. package/src/main.js +0 -19
  87. package/src/program.js +0 -765
  88. package/src/util/adb.js +0 -433
  89. package/src/util/artifacts.js +0 -69
  90. package/src/util/desktop-notifier.js +0 -41
  91. package/src/util/is-directory.js +0 -23
  92. package/src/util/logger.js +0 -131
  93. package/src/util/updates.js +0 -21
  94. package/src/watcher.js +0 -114
@@ -1,193 +1,115 @@
1
- /* @flow */
2
-
3
1
  /**
4
2
  * This module provide an ExtensionRunner subclass that manage an extension executed
5
3
  * in a Firefox for Android instance.
6
4
  */
7
-
8
5
  import path from 'path';
9
6
  import readline from 'readline';
10
-
11
- import {withTempDir} from '../util/temp-dir';
12
- import DefaultADBUtils from '../util/adb';
13
- import {
14
- showDesktopNotification as defaultDesktopNotifications,
15
- } from '../util/desktop-notifier';
16
- import {
17
- MultiExtensionsReloadError,
18
- UsageError,
19
- WebExtError,
20
- } from '../errors';
21
- import * as defaultFirefoxApp from '../firefox';
22
- import {
23
- connectWithMaxRetries as defaultFirefoxConnector,
24
- findFreeTcpPort,
25
- } from '../firefox/remote';
26
- import {createLogger} from '../util/logger';
27
- import {isTTY, setRawMode} from '../util/stdin';
28
- import type {
29
- ExtensionRunnerParams,
30
- ExtensionRunnerReloadResult,
31
- } from './base';
32
- import type {
33
- FirefoxPreferences,
34
- } from '../firefox/preferences';
35
- import type {
36
- FirefoxRDPResponseAddon,
37
- RemoteFirefox,
38
- } from '../firefox/remote';
39
- import type {
40
- ExtensionBuildResult,
41
- } from '../cmd/build';
42
-
43
- const log = createLogger(__filename);
44
-
7
+ import { withTempDir } from '../util/temp-dir.js';
8
+ import DefaultADBUtils from '../util/adb.js';
9
+ import { showDesktopNotification as defaultDesktopNotifications } from '../util/desktop-notifier.js';
10
+ import { MultiExtensionsReloadError, UsageError, WebExtError } from '../errors.js';
11
+ import * as defaultFirefoxApp from '../firefox/index.js';
12
+ import { connectWithMaxRetries as defaultFirefoxConnector, findFreeTcpPort } from '../firefox/remote.js';
13
+ import { createLogger } from '../util/logger.js';
14
+ import { isTTY, setRawMode } from '../util/stdin.js';
15
+ const log = createLogger(import.meta.url);
45
16
  const ignoredParams = {
46
17
  profilePath: '--profile-path',
47
18
  keepProfileChanges: '--keep-profile-changes',
48
19
  browserConsole: '--browser-console',
49
20
  preInstall: '--pre-install',
50
21
  startUrl: '--start-url',
51
- args: '--args',
52
- };
53
-
54
- // Default adbHost to 127.0.0.1 to prevent issues with nodejs 17
22
+ args: '--args'
23
+ }; // Default adbHost to 127.0.0.1 to prevent issues with nodejs 17
55
24
  // (because if not specified adbkit may default to ipv6 while
56
25
  // adb may still only be listening on the ipv4 address),
57
26
  // see https://github.com/mozilla/web-ext/issues/2337.
27
+
58
28
  const DEFAULT_ADB_HOST = '127.0.0.1';
59
29
 
60
- const getIgnoredParamsWarningsMessage = (optionName) => {
30
+ const getIgnoredParamsWarningsMessage = optionName => {
61
31
  return `The Firefox for Android target does not support ${optionName}`;
62
32
  };
63
33
 
64
- export type FirefoxAndroidExtensionRunnerParams = {|
65
- ...ExtensionRunnerParams,
66
-
67
- // Firefox specific.
68
- customPrefs?: FirefoxPreferences,
69
-
70
- // Not supported (currently ignored with logged warning).
71
- preInstall?: boolean,
72
- browserConsole?: boolean,
73
-
74
- // Firefox android injected dependencies.
75
- adbBin?: string,
76
- adbHost?: string,
77
- adbPort?: string,
78
- adbDevice?: string,
79
- adbDiscoveryTimeout?: number,
80
- adbRemoveOldArtifacts?: boolean,
81
- firefoxApk?: string,
82
- firefoxApkComponent?: string,
83
-
84
- // Injected Dependencies.
85
- firefoxApp: typeof defaultFirefoxApp,
86
- firefoxClient: typeof defaultFirefoxConnector,
87
- ADBUtils?: typeof DefaultADBUtils,
88
- buildSourceDir: (string, string) => Promise<ExtensionBuildResult>,
89
- desktopNotifications: typeof defaultDesktopNotifications,
90
- stdin?: stream$Readable,
91
- |};
92
-
93
34
  /**
94
35
  * Implements an IExtensionRunner which manages a Firefox for Android instance.
95
36
  */
96
37
  export class FirefoxAndroidExtensionRunner {
97
38
  // Wait 3s before the next unix socket discovery loop.
98
- static unixSocketDiscoveryRetryInterval: number = 3 * 1000;
99
- // Wait for at most 3 minutes before giving up.
100
- static unixSocketDiscoveryMaxTime: number = 3 * 60 * 1000;
101
-
102
- params: FirefoxAndroidExtensionRunnerParams;
103
- adbUtils: DefaultADBUtils;
104
- exiting: boolean;
105
- selectedAdbDevice: string;
106
- selectedFirefoxApk: string;
107
- selectedArtifactsDir: string;
108
- selectedRDPSocketFile: string;
109
- selectedTCPPort: number;
110
- cleanupCallbacks: Set<Function>;
111
- adbExtensionsPathBySourceDir: Map<string, string>;
112
- reloadableExtensions: Map<string, string>;
113
- remoteFirefox: RemoteFirefox;
114
-
115
- constructor(params: FirefoxAndroidExtensionRunnerParams) {
39
+ static unixSocketDiscoveryRetryInterval = 3 * 1000; // Wait for at most 3 minutes before giving up.
40
+
41
+ static unixSocketDiscoveryMaxTime = 3 * 60 * 1000;
42
+
43
+ constructor(params) {
116
44
  this.params = params;
117
45
  this.cleanupCallbacks = new Set();
118
46
  this.adbExtensionsPathBySourceDir = new Map();
119
- this.reloadableExtensions = new Map();
120
-
121
- // Print warning for not currently supported options (e.g. preInstall,
47
+ this.reloadableExtensions = new Map(); // Print warning for not currently supported options (e.g. preInstall,
122
48
  // cloned profiles, browser console).
49
+
123
50
  this.printIgnoredParamsWarnings();
124
51
  }
125
52
 
126
- async run(): Promise<void> {
53
+ async run() {
127
54
  const {
128
55
  adbBin,
129
56
  adbHost = DEFAULT_ADB_HOST,
130
57
  adbPort,
131
- ADBUtils = DefaultADBUtils,
58
+ ADBUtils = DefaultADBUtils
132
59
  } = this.params;
133
-
134
60
  this.adbUtils = new ADBUtils({
135
- adbBin, adbHost, adbPort,
61
+ adbBin,
62
+ adbHost,
63
+ adbPort
136
64
  });
137
-
138
65
  await this.adbDevicesDiscoveryAndSelect();
139
66
  await this.apkPackagesDiscoveryAndSelect();
140
67
  await this.adbCheckRuntimePermissions();
141
- await this.adbForceStopSelectedPackage();
142
-
143
- // Create profile prefs (with enabled remote RDP server), prepare the
68
+ await this.adbForceStopSelectedPackage(); // Create profile prefs (with enabled remote RDP server), prepare the
144
69
  // artifacts and temporary directory on the selected device, and
145
70
  // push the profile preferences to the remote profile dir.
146
- await this.adbPrepareProfileDir();
147
71
 
148
- // NOTE: running Firefox for Android on the Android Emulator can be
72
+ await this.adbPrepareProfileDir(); // NOTE: running Firefox for Android on the Android Emulator can be
149
73
  // pretty slow, we can run the following 3 steps in parallel to speed up
150
74
  // it a bit.
151
- await Promise.all([
152
- // Start Firefox for Android instance if not started yet.
153
- // (Fennec would run in an temporary profile and so it is explicitly
154
- // stopped, Fenix runs on its usual profile and so it may be already
155
- // running).
156
- this.adbStartSelectedPackage(),
157
-
158
- // Build and push to devices all the extension xpis
159
- // and keep track of the xpi built and uploaded by extension sourceDir.
160
- this.buildAndPushExtensions(),
161
-
162
- // Wait for RDP unix socket file created and
163
- // Create an ADB forward connection on a free tcp port
164
- this.adbDiscoveryAndForwardRDPUnixSocket(),
165
- ]);
166
-
167
- // Connect to RDP socket on the local tcp server, install all the pushed extension
75
+
76
+ await Promise.all([// Start Firefox for Android instance if not started yet.
77
+ // (Fennec would run in an temporary profile and so it is explicitly
78
+ // stopped, Fenix runs on its usual profile and so it may be already
79
+ // running).
80
+ this.adbStartSelectedPackage(), // Build and push to devices all the extension xpis
81
+ // and keep track of the xpi built and uploaded by extension sourceDir.
82
+ this.buildAndPushExtensions(), // Wait for RDP unix socket file created and
83
+ // Create an ADB forward connection on a free tcp port
84
+ this.adbDiscoveryAndForwardRDPUnixSocket()]); // Connect to RDP socket on the local tcp server, install all the pushed extension
168
85
  // and keep track of the built and installed extension by extension sourceDir.
169
- await this.rdpInstallExtensions();
170
- }
171
86
 
172
- // Method exported from the IExtensionRunner interface.
87
+ await this.rdpInstallExtensions();
88
+ } // Method exported from the IExtensionRunner interface.
173
89
 
174
90
  /**
175
91
  * Returns the runner name.
176
92
  */
177
- getName(): string {
93
+
94
+
95
+ getName() {
178
96
  return 'Firefox Android';
179
97
  }
180
-
181
98
  /**
182
99
  * Reloads all the extensions, collect any reload error and resolves to
183
100
  * an array composed by a single ExtensionRunnerReloadResult object.
184
101
  */
185
- async reloadAllExtensions(): Promise<Array<ExtensionRunnerReloadResult>> {
102
+
103
+
104
+ async reloadAllExtensions() {
186
105
  const runnerName = this.getName();
187
106
  const reloadErrors = new Map();
188
107
 
189
- for (const {sourceDir} of this.params.extensions) {
108
+ for (const {
109
+ sourceDir
110
+ } of this.params.extensions) {
190
111
  const [res] = await this.reloadExtensionBySourceDir(sourceDir);
112
+
191
113
  if (res.reloadError instanceof Error) {
192
114
  reloadErrors.set(sourceDir, res.reloadError);
193
115
  }
@@ -196,31 +118,29 @@ export class FirefoxAndroidExtensionRunner {
196
118
  if (reloadErrors.size > 0) {
197
119
  return [{
198
120
  runnerName,
199
- reloadError: new MultiExtensionsReloadError(reloadErrors),
121
+ reloadError: new MultiExtensionsReloadError(reloadErrors)
200
122
  }];
201
123
  }
202
124
 
203
- return [{runnerName}];
125
+ return [{
126
+ runnerName
127
+ }];
204
128
  }
205
-
206
129
  /**
207
130
  * Reloads a single extension, collect any reload error and resolves to
208
131
  * an array composed by a single ExtensionRunnerReloadResult object.
209
132
  */
210
- async reloadExtensionBySourceDir(
211
- extensionSourceDir: string
212
- ): Promise<Array<ExtensionRunnerReloadResult>> {
133
+
134
+
135
+ async reloadExtensionBySourceDir(extensionSourceDir) {
213
136
  const runnerName = this.getName();
214
137
  const addonId = this.reloadableExtensions.get(extensionSourceDir);
215
138
 
216
139
  if (!addonId) {
217
140
  return [{
218
141
  sourceDir: extensionSourceDir,
219
- reloadError: new WebExtError(
220
- 'Extension not reloadable: ' +
221
- `no addonId has been mapped to "${extensionSourceDir}"`
222
- ),
223
- runnerName,
142
+ reloadError: new WebExtError('Extension not reloadable: ' + `no addonId has been mapped to "${extensionSourceDir}"`),
143
+ runnerName
224
144
  }];
225
145
  }
226
146
 
@@ -231,44 +151,47 @@ export class FirefoxAndroidExtensionRunner {
231
151
  return [{
232
152
  sourceDir: extensionSourceDir,
233
153
  reloadError: error,
234
- runnerName,
154
+ runnerName
235
155
  }];
236
156
  }
237
157
 
238
- return [{runnerName, sourceDir: extensionSourceDir}];
158
+ return [{
159
+ runnerName,
160
+ sourceDir: extensionSourceDir
161
+ }];
239
162
  }
240
-
241
163
  /**
242
164
  * Register a callback to be called when the runner has been exited
243
165
  * (e.g. the Firefox instance exits or the user has requested web-ext
244
166
  * to exit).
245
167
  */
246
- registerCleanup(fn: Function): void {
168
+
169
+
170
+ registerCleanup(fn) {
247
171
  this.cleanupCallbacks.add(fn);
248
172
  }
249
-
250
173
  /**
251
174
  * Exits the runner, by closing the managed Firefox instance.
252
175
  */
253
- async exit(): Promise<void> {
176
+
177
+
178
+ async exit() {
254
179
  const {
255
180
  adbUtils,
256
181
  selectedAdbDevice,
257
- selectedArtifactsDir,
182
+ selectedArtifactsDir
258
183
  } = this;
259
-
260
- this.exiting = true;
261
-
262
- // If a Firefox for Android instance has been started,
184
+ this.exiting = true; // If a Firefox for Android instance has been started,
263
185
  // we should ensure that it has been stopped when we exit.
186
+
264
187
  await this.adbForceStopSelectedPackage();
265
188
 
266
189
  if (selectedArtifactsDir) {
267
190
  log.debug('Cleaning up artifacts directory on the Android device...');
268
191
  await adbUtils.clearArtifactsDir(selectedAdbDevice);
269
- }
192
+ } // Call all the registered cleanup callbacks.
193
+
270
194
 
271
- // Call all the registered cleanup callbacks.
272
195
  for (const fn of this.cleanupCallbacks) {
273
196
  try {
274
197
  fn();
@@ -276,54 +199,49 @@ export class FirefoxAndroidExtensionRunner {
276
199
  log.error(error);
277
200
  }
278
201
  }
279
- }
202
+ } // Private helper methods.
280
203
 
281
- // Private helper methods.
282
204
 
283
- getDeviceProfileDir(): string {
205
+ getDeviceProfileDir() {
284
206
  return `${this.selectedArtifactsDir}/profile`;
285
207
  }
286
208
 
287
209
  printIgnoredParamsWarnings() {
288
- Object.keys(ignoredParams).forEach((ignoredParam) => {
210
+ Object.keys(ignoredParams).forEach(ignoredParam => {
289
211
  if (this.params[ignoredParam]) {
290
- log.warn(
291
- getIgnoredParamsWarningsMessage(ignoredParams[ignoredParam])
292
- );
212
+ log.warn(getIgnoredParamsWarningsMessage(ignoredParams[ignoredParam]));
293
213
  }
294
214
  });
295
215
  }
296
216
 
297
217
  async adbDevicesDiscoveryAndSelect() {
298
- const {adbUtils} = this;
299
- const {adbDevice} = this.params;
218
+ const {
219
+ adbUtils
220
+ } = this;
221
+ const {
222
+ adbDevice
223
+ } = this.params;
300
224
  let devices = [];
301
-
302
225
  log.debug('Listing android devices');
303
226
  devices = await adbUtils.discoverDevices();
304
227
 
305
228
  if (devices.length === 0) {
306
- throw new UsageError(
307
- 'No Android device found through ADB. ' +
308
- 'Make sure the device is connected and USB debugging is enabled.'
309
- );
229
+ throw new UsageError('No Android device found through ADB. ' + 'Make sure the device is connected and USB debugging is enabled.');
310
230
  }
311
231
 
312
232
  if (!adbDevice) {
313
- const devicesMsg = devices.map((dev) => ` - ${dev}`).join('\n');
233
+ const devicesMsg = devices.map(dev => ` - ${dev}`).join('\n');
314
234
  log.info(`\nAndroid devices found:\n${devicesMsg}`);
315
- throw new UsageError(
316
- 'Select an android device using --android-device=<name>');
235
+ throw new UsageError('Select an android device using --android-device=<name>');
317
236
  }
318
237
 
319
- const foundDevices = devices.filter((device) => {
238
+ const foundDevices = devices.filter(device => {
320
239
  return device === adbDevice;
321
240
  });
322
241
 
323
242
  if (foundDevices.length === 0) {
324
243
  const devicesMsg = JSON.stringify(devices);
325
- throw new UsageError(
326
- `Android device ${adbDevice} was not found in list: ${devicesMsg}`);
244
+ throw new UsageError(`Android device ${adbDevice} was not found in list: ${devicesMsg}`);
327
245
  }
328
246
 
329
247
  this.selectedAdbDevice = foundDevices[0];
@@ -335,22 +253,18 @@ export class FirefoxAndroidExtensionRunner {
335
253
  adbUtils,
336
254
  selectedAdbDevice,
337
255
  params: {
338
- firefoxApk,
339
- },
340
- } = this;
341
- // Discovery and select a Firefox for Android version.
342
- const packages = await adbUtils.discoverInstalledFirefoxAPKs(
343
- selectedAdbDevice,
344
- firefoxApk
345
- );
256
+ firefoxApk
257
+ }
258
+ } = this; // Discovery and select a Firefox for Android version.
259
+
260
+ const packages = await adbUtils.discoverInstalledFirefoxAPKs(selectedAdbDevice, firefoxApk);
346
261
 
347
262
  if (packages.length === 0) {
348
- throw new UsageError(
349
- 'No Firefox packages were found on the selected Android device');
263
+ throw new UsageError('No Firefox packages were found on the selected Android device');
350
264
  }
351
265
 
352
- const pkgsListMsg = (pkgs) => {
353
- return pkgs.map((pkg) => ` - ${ pkg}`).join('\n');
266
+ const pkgsListMsg = pkgs => {
267
+ return pkgs.map(pkg => ` - ${pkg}`).join('\n');
354
268
  };
355
269
 
356
270
  if (!firefoxApk) {
@@ -358,22 +272,20 @@ export class FirefoxAndroidExtensionRunner {
358
272
 
359
273
  if (packages.length > 1) {
360
274
  throw new UsageError('Select one of the packages using --firefox-apk');
361
- }
362
-
363
- // If only one APK has been found, select it even if it has not been
275
+ } // If only one APK has been found, select it even if it has not been
364
276
  // specified explicitly on the comment line.
277
+
278
+
365
279
  this.selectedFirefoxApk = packages[0];
366
280
  log.info(`Selected Firefox for Android APK: ${this.selectedFirefoxApk}`);
367
281
  return;
368
282
  }
369
283
 
370
- const filteredPackages = packages.filter((line) => line === firefoxApk);
284
+ const filteredPackages = packages.filter(line => line === firefoxApk);
371
285
 
372
286
  if (filteredPackages.length === 0) {
373
287
  const pkgsList = pkgsListMsg(filteredPackages);
374
- throw new UsageError(
375
- `Package ${firefoxApk} was not found in list: ${pkgsList}`
376
- );
288
+ throw new UsageError(`Package ${firefoxApk} was not found in list: ${pkgsList}`);
377
289
  }
378
290
 
379
291
  this.selectedFirefoxApk = filteredPackages[0];
@@ -384,9 +296,8 @@ export class FirefoxAndroidExtensionRunner {
384
296
  const {
385
297
  adbUtils,
386
298
  selectedAdbDevice,
387
- selectedFirefoxApk,
299
+ selectedFirefoxApk
388
300
  } = this;
389
-
390
301
  log.info(`Stopping existing instances of ${selectedFirefoxApk}...`);
391
302
  await adbUtils.amForceStopAPK(selectedAdbDevice, selectedFirefoxApk);
392
303
  }
@@ -395,14 +306,10 @@ export class FirefoxAndroidExtensionRunner {
395
306
  const {
396
307
  adbUtils,
397
308
  selectedAdbDevice,
398
- selectedFirefoxApk,
309
+ selectedFirefoxApk
399
310
  } = this;
400
-
401
311
  log.debug(`Discovering Android version for ${selectedAdbDevice}...`);
402
-
403
- const androidVersion = await adbUtils.getAndroidVersionNumber(
404
- selectedAdbDevice
405
- );
312
+ const androidVersion = await adbUtils.getAndroidVersionNumber(selectedAdbDevice);
406
313
 
407
314
  if (typeof androidVersion !== 'number' || Number.isNaN(androidVersion)) {
408
315
  throw new WebExtError(`Invalid Android version: ${androidVersion}`);
@@ -414,18 +321,11 @@ export class FirefoxAndroidExtensionRunner {
414
321
  return;
415
322
  }
416
323
 
417
- log.debug('Checking read/write permissions needed for web-ext' +
418
- `on ${selectedFirefoxApk}...`);
419
-
420
- // Runtime permissions needed to Firefox to be able to access the
324
+ log.debug('Checking read/write permissions needed for web-ext' + `on ${selectedFirefoxApk}...`); // Runtime permissions needed to Firefox to be able to access the
421
325
  // xpi file uploaded to the android device or emulator.
422
- const requiredPermissions = [
423
- 'android.permission.READ_EXTERNAL_STORAGE',
424
- ];
425
326
 
426
- await adbUtils.ensureRequiredAPKRuntimePermissions(
427
- selectedAdbDevice, selectedFirefoxApk, requiredPermissions
428
- );
327
+ const requiredPermissions = ['android.permission.READ_EXTERNAL_STORAGE'];
328
+ await adbUtils.ensureRequiredAPKRuntimePermissions(selectedAdbDevice, selectedFirefoxApk, requiredPermissions);
429
329
  }
430
330
 
431
331
  async adbPrepareProfileDir() {
@@ -436,50 +336,33 @@ export class FirefoxAndroidExtensionRunner {
436
336
  params: {
437
337
  customPrefs,
438
338
  firefoxApp,
439
- adbRemoveOldArtifacts,
440
- },
441
- } = this;
442
- // Create the preferences file and the Fennec temporary profile.
443
- log.debug(`Preparing a temporary profile for ${selectedFirefoxApk}...`);
339
+ adbRemoveOldArtifacts
340
+ }
341
+ } = this; // Create the preferences file and the Fennec temporary profile.
444
342
 
343
+ log.debug(`Preparing a temporary profile for ${selectedFirefoxApk}...`);
445
344
  const profile = await firefoxApp.createProfile({
446
345
  app: 'fennec',
447
- customPrefs,
448
- });
449
-
450
- // Check if there are any artifacts dirs from previous runs and
346
+ customPrefs
347
+ }); // Check if there are any artifacts dirs from previous runs and
451
348
  // automatically remove them if adbRemoteOldArtifacts is true.
452
- const foundOldArtifacts = await adbUtils.detectOrRemoveOldArtifacts(
453
- selectedAdbDevice, adbRemoveOldArtifacts
454
- );
349
+
350
+ const foundOldArtifacts = await adbUtils.detectOrRemoveOldArtifacts(selectedAdbDevice, adbRemoveOldArtifacts);
455
351
 
456
352
  if (foundOldArtifacts) {
457
353
  if (adbRemoveOldArtifacts) {
458
- log.info('Old web-ext artifacts have been found and removed ' +
459
- `from ${selectedAdbDevice} device`);
354
+ log.info('Old web-ext artifacts have been found and removed ' + `from ${selectedAdbDevice} device`);
460
355
  } else {
461
- log.warn(
462
- `Old artifacts directories have been found on ${selectedAdbDevice} ` +
463
- 'device. Use --adb-remove-old-artifacts to remove them automatically.'
464
- );
356
+ log.warn(`Old artifacts directories have been found on ${selectedAdbDevice} ` + 'device. Use --adb-remove-old-artifacts to remove them automatically.');
465
357
  }
466
- }
467
-
468
- // Choose a artifacts dir name for the assets pushed to the
358
+ } // Choose a artifacts dir name for the assets pushed to the
469
359
  // Android device.
470
- this.selectedArtifactsDir = await adbUtils.getOrCreateArtifactsDir(
471
- selectedAdbDevice
472
- );
473
-
474
- const deviceProfileDir = this.getDeviceProfileDir();
475
360
 
476
- await adbUtils.runShellCommand(selectedAdbDevice, [
477
- 'mkdir', '-p', deviceProfileDir,
478
- ]);
479
- await adbUtils.pushFile(selectedAdbDevice,
480
- path.join(profile.profileDir, 'user.js'),
481
- `${deviceProfileDir}/user.js`);
482
361
 
362
+ this.selectedArtifactsDir = await adbUtils.getOrCreateArtifactsDir(selectedAdbDevice);
363
+ const deviceProfileDir = this.getDeviceProfileDir();
364
+ await adbUtils.runShellCommand(selectedAdbDevice, ['mkdir', '-p', deviceProfileDir]);
365
+ await adbUtils.pushFile(selectedAdbDevice, path.join(profile.profileDir, 'user.js'), `${deviceProfileDir}/user.js`);
483
366
  log.debug(`Created temporary profile at ${deviceProfileDir}.`);
484
367
  }
485
368
 
@@ -489,39 +372,29 @@ export class FirefoxAndroidExtensionRunner {
489
372
  selectedFirefoxApk,
490
373
  selectedAdbDevice,
491
374
  params: {
492
- firefoxApkComponent,
493
- },
375
+ firefoxApkComponent
376
+ }
494
377
  } = this;
495
-
496
378
  const deviceProfileDir = this.getDeviceProfileDir();
497
-
498
379
  log.info(`Starting ${selectedFirefoxApk}...`);
499
-
500
380
  log.debug(`Using profile ${deviceProfileDir} (ignored by Fenix)`);
501
-
502
- await adbUtils.startFirefoxAPK(
503
- selectedAdbDevice,
504
- selectedFirefoxApk,
505
- firefoxApkComponent,
506
- deviceProfileDir,
507
- );
381
+ await adbUtils.startFirefoxAPK(selectedAdbDevice, selectedFirefoxApk, firefoxApkComponent, deviceProfileDir);
508
382
  }
509
383
 
510
- async buildAndPushExtension(sourceDir: string) {
384
+ async buildAndPushExtension(sourceDir) {
511
385
  const {
512
386
  adbUtils,
513
387
  selectedAdbDevice,
514
388
  selectedArtifactsDir,
515
389
  params: {
516
- buildSourceDir,
517
- },
390
+ buildSourceDir
391
+ }
518
392
  } = this;
519
-
520
- await withTempDir(async (tmpDir) => {
521
- const {extensionPath} = await buildSourceDir(sourceDir, tmpDir.path());
522
-
393
+ await withTempDir(async tmpDir => {
394
+ const {
395
+ extensionPath
396
+ } = await buildSourceDir(sourceDir, tmpDir.path());
523
397
  const extFileName = path.basename(extensionPath, '.zip');
524
-
525
398
  let adbExtensionPath = this.adbExtensionsPathBySourceDir.get(sourceDir);
526
399
 
527
400
  if (!adbExtensionPath) {
@@ -529,19 +402,16 @@ export class FirefoxAndroidExtensionRunner {
529
402
  }
530
403
 
531
404
  log.debug(`Uploading ${extFileName} on the android device`);
532
-
533
- await adbUtils.pushFile(
534
- selectedAdbDevice, extensionPath, adbExtensionPath
535
- );
536
-
405
+ await adbUtils.pushFile(selectedAdbDevice, extensionPath, adbExtensionPath);
537
406
  log.debug(`Upload completed: ${adbExtensionPath}`);
538
-
539
407
  this.adbExtensionsPathBySourceDir.set(sourceDir, adbExtensionPath);
540
408
  });
541
409
  }
542
410
 
543
411
  async buildAndPushExtensions() {
544
- for (const {sourceDir} of this.params.extensions) {
412
+ for (const {
413
+ sourceDir
414
+ } of this.params.extensions) {
545
415
  await this.buildAndPushExtension(sourceDir);
546
416
  }
547
417
  }
@@ -552,18 +422,15 @@ export class FirefoxAndroidExtensionRunner {
552
422
  selectedAdbDevice,
553
423
  selectedFirefoxApk,
554
424
  params: {
555
- adbDiscoveryTimeout,
556
- },
425
+ adbDiscoveryTimeout
426
+ }
557
427
  } = this;
558
-
559
428
  const stdin = this.params.stdin || process.stdin;
560
-
561
429
  const {
562
- unixSocketDiscoveryRetryInterval,
430
+ unixSocketDiscoveryRetryInterval
563
431
  } = FirefoxAndroidExtensionRunner;
564
-
565
432
  let {
566
- unixSocketDiscoveryMaxTime,
433
+ unixSocketDiscoveryMaxTime
567
434
  } = FirefoxAndroidExtensionRunner;
568
435
 
569
436
  if (typeof adbDiscoveryTimeout === 'number') {
@@ -574,27 +441,22 @@ export class FirefoxAndroidExtensionRunner {
574
441
  if (key.ctrl && key.name === 'c') {
575
442
  adbUtils.setUserAbortDiscovery(true);
576
443
  }
577
- };
578
-
579
- // TODO: use noInput property to decide if we should
444
+ }; // TODO: use noInput property to decide if we should
580
445
  // disable direct keypress handling.
446
+
447
+
581
448
  if (isTTY(stdin)) {
582
449
  readline.emitKeypressEvents(stdin);
583
450
  setRawMode(stdin, true);
584
-
585
451
  stdin.on('keypress', handleCtrlC);
586
452
  }
587
453
 
588
454
  try {
589
455
  // Got a debugger socket file to connect.
590
- this.selectedRDPSocketFile = (
591
- await adbUtils.discoverRDPUnixSocket(
592
- selectedAdbDevice, selectedFirefoxApk, {
593
- maxDiscoveryTime: unixSocketDiscoveryMaxTime,
594
- retryInterval: unixSocketDiscoveryRetryInterval,
595
- }
596
- )
597
- );
456
+ this.selectedRDPSocketFile = await adbUtils.discoverRDPUnixSocket(selectedAdbDevice, selectedFirefoxApk, {
457
+ maxDiscoveryTime: unixSocketDiscoveryMaxTime,
458
+ retryInterval: unixSocketDiscoveryRetryInterval
459
+ });
598
460
  } finally {
599
461
  if (isTTY(stdin)) {
600
462
  stdin.removeListener('keypress', handleCtrlC);
@@ -602,23 +464,12 @@ export class FirefoxAndroidExtensionRunner {
602
464
  }
603
465
 
604
466
  log.debug(`RDP Socket File selected: ${this.selectedRDPSocketFile}`);
605
-
606
- const tcpPort = await findFreeTcpPort();
607
-
608
- // Log the choosen tcp port at info level (useful to the user to be able
467
+ const tcpPort = await findFreeTcpPort(); // Log the choosen tcp port at info level (useful to the user to be able
609
468
  // to connect the Firefox DevTools to the Firefox for Android instance).
610
- log.info(`You can connect to this Android device on TCP port ${tcpPort}`);
611
-
612
- const forwardSocketSpec = this.selectedRDPSocketFile.startsWith('@') ?
613
- `localabstract:${this.selectedRDPSocketFile.substr(1)}`
614
- : `localfilesystem:${this.selectedRDPSocketFile}`;
615
-
616
- await adbUtils.setupForward(
617
- selectedAdbDevice,
618
- forwardSocketSpec,
619
- `tcp:${tcpPort}`
620
- );
621
469
 
470
+ log.info(`You can connect to this Android device on TCP port ${tcpPort}`);
471
+ const forwardSocketSpec = this.selectedRDPSocketFile.startsWith('@') ? `localabstract:${this.selectedRDPSocketFile.substr(1)}` : `localfilesystem:${this.selectedRDPSocketFile}`;
472
+ await adbUtils.setupForward(selectedAdbDevice, forwardSocketSpec, `tcp:${tcpPort}`);
622
473
  this.selectedTCPPort = tcpPort;
623
474
  }
624
475
 
@@ -627,51 +478,42 @@ export class FirefoxAndroidExtensionRunner {
627
478
  selectedTCPPort,
628
479
  params: {
629
480
  extensions,
630
- firefoxClient,
631
- },
481
+ firefoxClient
482
+ }
632
483
  } = this;
633
-
634
484
  const remoteFirefox = this.remoteFirefox = await firefoxClient({
635
- port: selectedTCPPort,
636
- });
637
-
638
- // Exit and cleanup the extension runner if the connection to the
485
+ port: selectedTCPPort
486
+ }); // Exit and cleanup the extension runner if the connection to the
639
487
  // remote Firefox for Android instance has been closed.
488
+
640
489
  remoteFirefox.client.on('end', () => {
641
490
  if (!this.exiting) {
642
491
  log.info('Exiting the device because Firefox for Android disconnected');
643
492
  this.exit();
644
493
  }
645
- });
494
+ }); // Install all the temporary addons.
646
495
 
647
- // Install all the temporary addons.
648
496
  for (const extension of extensions) {
649
- const {sourceDir} = extension;
650
- const adbExtensionPath = this.adbExtensionsPathBySourceDir.get(
497
+ const {
651
498
  sourceDir
652
- );
499
+ } = extension;
500
+ const adbExtensionPath = this.adbExtensionsPathBySourceDir.get(sourceDir);
653
501
 
654
502
  if (!adbExtensionPath) {
655
- throw new WebExtError(
656
- `ADB extension path for "${sourceDir}" was unexpectedly empty`
657
- );
503
+ throw new WebExtError(`ADB extension path for "${sourceDir}" was unexpectedly empty`);
658
504
  }
659
505
 
660
- const addonId = await (
661
- remoteFirefox.installTemporaryAddon(adbExtensionPath)
662
- .then((installResult: FirefoxRDPResponseAddon) => {
663
- return installResult.addon.id;
664
- })
665
- );
506
+ const addonId = await remoteFirefox.installTemporaryAddon(adbExtensionPath).then(installResult => {
507
+ return installResult.addon.id;
508
+ });
666
509
 
667
510
  if (!addonId) {
668
- throw new WebExtError(
669
- 'Received an empty addonId from ' +
670
- `remoteFirefox.installTemporaryAddon("${adbExtensionPath}")`
671
- );
511
+ throw new WebExtError('Received an empty addonId from ' + `remoteFirefox.installTemporaryAddon("${adbExtensionPath}")`);
672
512
  }
673
513
 
674
514
  this.reloadableExtensions.set(extension.sourceDir, addonId);
675
515
  }
676
516
  }
517
+
677
518
  }
519
+ //# sourceMappingURL=firefox-android.js.map