web-ext 6.8.0 → 7.0.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 +191 -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 +657 -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 -115
package/src/util/adb.js
DELETED
|
@@ -1,433 +0,0 @@
|
|
|
1
|
-
/* @flow */
|
|
2
|
-
import defaultADB from '@devicefarmer/adbkit';
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
isErrorWithCode,
|
|
6
|
-
UsageError,
|
|
7
|
-
WebExtError,
|
|
8
|
-
} from '../errors';
|
|
9
|
-
import {createLogger} from '../util/logger';
|
|
10
|
-
import packageIdentifiers, {
|
|
11
|
-
defaultApkComponents,
|
|
12
|
-
} from '../firefox/package-identifiers';
|
|
13
|
-
|
|
14
|
-
export const DEVICE_DIR_BASE = '/data/local/tmp/';
|
|
15
|
-
export const ARTIFACTS_DIR_PREFIX = 'web-ext-artifacts-';
|
|
16
|
-
|
|
17
|
-
const log = createLogger(__filename);
|
|
18
|
-
|
|
19
|
-
export type ADBUtilsParams = {|
|
|
20
|
-
adb?: typeof defaultADB,
|
|
21
|
-
// ADB configs.
|
|
22
|
-
adbBin?: string,
|
|
23
|
-
adbHost?: string,
|
|
24
|
-
adbPort?: string,
|
|
25
|
-
adbDevice?: string,
|
|
26
|
-
|};
|
|
27
|
-
|
|
28
|
-
export type DiscoveryParams = {|
|
|
29
|
-
maxDiscoveryTime: number,
|
|
30
|
-
retryInterval: number,
|
|
31
|
-
|};
|
|
32
|
-
|
|
33
|
-
// Helper function used to raise an UsageError when the adb binary has not been found.
|
|
34
|
-
async function wrapADBCall(asyncFn: (...any) => Promise<any>): Promise<any> {
|
|
35
|
-
try {
|
|
36
|
-
return await asyncFn();
|
|
37
|
-
} catch (error) {
|
|
38
|
-
if (isErrorWithCode('ENOENT', error) &&
|
|
39
|
-
error.message.includes('spawn adb')) {
|
|
40
|
-
throw new UsageError(
|
|
41
|
-
'No adb executable has been found. ' +
|
|
42
|
-
'You can Use --adb-bin, --adb-host/--adb-port ' +
|
|
43
|
-
'to configure it manually if needed.');
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
throw error;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export default class ADBUtils {
|
|
51
|
-
params: ADBUtilsParams;
|
|
52
|
-
adb: typeof defaultADB;
|
|
53
|
-
adbClient: any; // TODO: better flow typing here.
|
|
54
|
-
|
|
55
|
-
// Map<deviceId -> artifactsDir>
|
|
56
|
-
artifactsDirMap: Map<string, string>;
|
|
57
|
-
// Toggled when the user wants to abort the RDP Unix Socket discovery loop
|
|
58
|
-
// while it is still executing.
|
|
59
|
-
userAbortDiscovery: boolean;
|
|
60
|
-
|
|
61
|
-
constructor(params: ADBUtilsParams) {
|
|
62
|
-
this.params = params;
|
|
63
|
-
|
|
64
|
-
const {
|
|
65
|
-
adb,
|
|
66
|
-
adbBin,
|
|
67
|
-
adbHost,
|
|
68
|
-
adbPort,
|
|
69
|
-
} = params;
|
|
70
|
-
|
|
71
|
-
this.adb = adb || defaultADB;
|
|
72
|
-
|
|
73
|
-
this.adbClient = this.adb.createClient({
|
|
74
|
-
bin: adbBin,
|
|
75
|
-
host: adbHost,
|
|
76
|
-
port: adbPort,
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
this.artifactsDirMap = new Map();
|
|
80
|
-
|
|
81
|
-
this.userAbortDiscovery = false;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
runShellCommand(
|
|
85
|
-
deviceId: string, cmd: string | Array<string>
|
|
86
|
-
): Promise<string> {
|
|
87
|
-
const {adb, adbClient} = this;
|
|
88
|
-
|
|
89
|
-
log.debug(`Run adb shell command on ${deviceId}: ${JSON.stringify(cmd)}`);
|
|
90
|
-
|
|
91
|
-
return wrapADBCall(async () => {
|
|
92
|
-
return await adbClient.shell(deviceId, cmd).then(adb.util.readAll);
|
|
93
|
-
}).then((res) => res.toString());
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
async discoverDevices(): Promise<Array<string>> {
|
|
97
|
-
const {adbClient} = this;
|
|
98
|
-
|
|
99
|
-
let devices = [];
|
|
100
|
-
|
|
101
|
-
log.debug('Listing android devices');
|
|
102
|
-
devices = await wrapADBCall(async () => adbClient.listDevices());
|
|
103
|
-
|
|
104
|
-
return devices.map((dev) => dev.id);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
async discoverInstalledFirefoxAPKs(
|
|
108
|
-
deviceId: string,
|
|
109
|
-
firefoxApk?: string
|
|
110
|
-
): Promise<Array<string>> {
|
|
111
|
-
log.debug(`Listing installed Firefox APKs on ${deviceId}`);
|
|
112
|
-
|
|
113
|
-
const pmList = await this.runShellCommand(deviceId, [
|
|
114
|
-
'pm', 'list', 'packages',
|
|
115
|
-
]);
|
|
116
|
-
|
|
117
|
-
return pmList.split('\n')
|
|
118
|
-
.map((line) => line.replace('package:', '').trim())
|
|
119
|
-
.filter((line) => {
|
|
120
|
-
// Look for an exact match if firefoxApk is defined.
|
|
121
|
-
if (firefoxApk) {
|
|
122
|
-
return line === firefoxApk;
|
|
123
|
-
}
|
|
124
|
-
// Match any package name that starts with the package name of a Firefox for Android browser.
|
|
125
|
-
for (const browser of packageIdentifiers) {
|
|
126
|
-
if (line.startsWith(browser)) {
|
|
127
|
-
return true;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
return false;
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
async getAndroidVersionNumber(deviceId: string): Promise<number> {
|
|
136
|
-
const androidVersion = (await this.runShellCommand(deviceId, [
|
|
137
|
-
'getprop', 'ro.build.version.sdk',
|
|
138
|
-
])).trim();
|
|
139
|
-
|
|
140
|
-
const androidVersionNumber = parseInt(androidVersion);
|
|
141
|
-
|
|
142
|
-
// No need to check the granted runtime permissions on Android versions < Lollypop.
|
|
143
|
-
if (isNaN(androidVersionNumber)) {
|
|
144
|
-
throw new WebExtError(
|
|
145
|
-
'Unable to discovery android version on ' +
|
|
146
|
-
`${deviceId}: ${androidVersion}`
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
return androidVersionNumber;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// Raise an UsageError when the given APK does not have the required runtime permissions.
|
|
154
|
-
async ensureRequiredAPKRuntimePermissions(
|
|
155
|
-
deviceId: string, apk: string, permissions: Array<string>
|
|
156
|
-
): Promise<void> {
|
|
157
|
-
const permissionsMap = {};
|
|
158
|
-
|
|
159
|
-
// Initialize every permission to false in the permissions map.
|
|
160
|
-
for (const perm of permissions) {
|
|
161
|
-
permissionsMap[perm] = false;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// Retrieve the permissions information for the given apk.
|
|
165
|
-
const pmDumpLogs = (await this.runShellCommand(deviceId, [
|
|
166
|
-
'pm', 'dump', apk,
|
|
167
|
-
])).split('\n');
|
|
168
|
-
|
|
169
|
-
// Set to true the required permissions that have been granted.
|
|
170
|
-
for (const line of pmDumpLogs) {
|
|
171
|
-
for (const perm of permissions) {
|
|
172
|
-
if (line.includes(`${perm}: granted=true`) ||
|
|
173
|
-
line.includes(`${perm}, granted=true`)) {
|
|
174
|
-
permissionsMap[perm] = true;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
for (const perm of permissions) {
|
|
180
|
-
if (!permissionsMap[perm]) {
|
|
181
|
-
throw new UsageError(
|
|
182
|
-
`Required ${perm} has not be granted for ${apk}. ` +
|
|
183
|
-
'Please grant them using the Android Settings ' +
|
|
184
|
-
'or using the following adb command:\n' +
|
|
185
|
-
`\t adb shell pm grant ${apk} ${perm}\n`
|
|
186
|
-
);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
async amForceStopAPK(deviceId: string, apk: string): Promise<void> {
|
|
192
|
-
await this.runShellCommand(deviceId, [
|
|
193
|
-
'am', 'force-stop', apk,
|
|
194
|
-
]);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
async getOrCreateArtifactsDir(deviceId: string): Promise<string> {
|
|
198
|
-
let artifactsDir = this.artifactsDirMap.get(deviceId);
|
|
199
|
-
|
|
200
|
-
if (artifactsDir) {
|
|
201
|
-
return artifactsDir;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
artifactsDir = `${DEVICE_DIR_BASE}${ARTIFACTS_DIR_PREFIX}${Date.now()}`;
|
|
205
|
-
|
|
206
|
-
const testDirOut = (await this.runShellCommand(
|
|
207
|
-
deviceId, `test -d ${artifactsDir} ; echo $?`
|
|
208
|
-
)).trim();
|
|
209
|
-
|
|
210
|
-
if (testDirOut !== '1') {
|
|
211
|
-
throw new WebExtError(
|
|
212
|
-
`Cannot create artifacts directory ${artifactsDir} ` +
|
|
213
|
-
`because it exists on ${deviceId}.`
|
|
214
|
-
);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
await this.runShellCommand(deviceId, ['mkdir', '-p', artifactsDir]);
|
|
218
|
-
|
|
219
|
-
this.artifactsDirMap.set(deviceId, artifactsDir);
|
|
220
|
-
|
|
221
|
-
return artifactsDir;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
async detectOrRemoveOldArtifacts(
|
|
225
|
-
deviceId: string, removeArtifactDirs?: boolean = false
|
|
226
|
-
): Promise<boolean> {
|
|
227
|
-
const {adbClient} = this;
|
|
228
|
-
|
|
229
|
-
log.debug('Checking adb device for existing web-ext artifacts dirs');
|
|
230
|
-
|
|
231
|
-
return wrapADBCall(async () => {
|
|
232
|
-
const files = await adbClient.readdir(deviceId, DEVICE_DIR_BASE);
|
|
233
|
-
let found = false;
|
|
234
|
-
|
|
235
|
-
for (const file of files) {
|
|
236
|
-
if (!file.isDirectory() ||
|
|
237
|
-
!file.name.startsWith(ARTIFACTS_DIR_PREFIX)) {
|
|
238
|
-
continue;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
// Return earlier if we only need to warn the user that some
|
|
242
|
-
// existing artifacts dirs have been found on the adb device.
|
|
243
|
-
if (!removeArtifactDirs) {
|
|
244
|
-
return true;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
found = true;
|
|
248
|
-
|
|
249
|
-
const artifactsDir = `${DEVICE_DIR_BASE}${file.name}`;
|
|
250
|
-
|
|
251
|
-
log.debug(
|
|
252
|
-
`Removing artifacts directory ${artifactsDir} from device ${deviceId}`
|
|
253
|
-
);
|
|
254
|
-
|
|
255
|
-
await this.runShellCommand(deviceId, ['rm', '-rf', artifactsDir]);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
return found;
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
async clearArtifactsDir(deviceId: string): Promise<void> {
|
|
263
|
-
const artifactsDir = this.artifactsDirMap.get(deviceId);
|
|
264
|
-
|
|
265
|
-
if (!artifactsDir) {
|
|
266
|
-
// nothing to do here.
|
|
267
|
-
return;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
this.artifactsDirMap.delete(deviceId);
|
|
271
|
-
|
|
272
|
-
log.debug(
|
|
273
|
-
`Removing ${artifactsDir} artifacts directory on ${deviceId} device`
|
|
274
|
-
);
|
|
275
|
-
|
|
276
|
-
await this.runShellCommand(deviceId, ['rm', '-rf', artifactsDir]);
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
async pushFile(
|
|
280
|
-
deviceId: string, localPath: string, devicePath: string
|
|
281
|
-
): Promise<void> {
|
|
282
|
-
const {adbClient} = this;
|
|
283
|
-
|
|
284
|
-
log.debug(`Pushing ${localPath} to ${devicePath} on ${deviceId}`);
|
|
285
|
-
|
|
286
|
-
await wrapADBCall(async () => {
|
|
287
|
-
await adbClient.push(deviceId, localPath, devicePath)
|
|
288
|
-
.then(function(transfer) {
|
|
289
|
-
return new Promise((resolve) => {
|
|
290
|
-
transfer.on('end', resolve);
|
|
291
|
-
});
|
|
292
|
-
});
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
async startFirefoxAPK(
|
|
297
|
-
deviceId: string,
|
|
298
|
-
apk: string,
|
|
299
|
-
apkComponent: ?string,
|
|
300
|
-
deviceProfileDir: string,
|
|
301
|
-
): Promise<void> {
|
|
302
|
-
const {adbClient} = this;
|
|
303
|
-
|
|
304
|
-
log.debug(
|
|
305
|
-
`Starting ${apk} on ${deviceId}`
|
|
306
|
-
);
|
|
307
|
-
|
|
308
|
-
// Fenix does ignore the -profile parameter, on the contrary Fennec
|
|
309
|
-
// would run using the given path as the profile to be used during
|
|
310
|
-
// this execution.
|
|
311
|
-
const extras = [{
|
|
312
|
-
key: 'args',
|
|
313
|
-
value: `-profile ${deviceProfileDir}`,
|
|
314
|
-
}];
|
|
315
|
-
|
|
316
|
-
if (!apkComponent) {
|
|
317
|
-
apkComponent = '.App';
|
|
318
|
-
if (defaultApkComponents[apk]) {
|
|
319
|
-
apkComponent = defaultApkComponents[apk];
|
|
320
|
-
}
|
|
321
|
-
} else if (!apkComponent.includes('.')) {
|
|
322
|
-
apkComponent = `.${apkComponent}`;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
// if `apk` is a browser package or the `apk` has a
|
|
326
|
-
// browser package prefix: prepend the package identifier
|
|
327
|
-
// before `apkComponent`
|
|
328
|
-
if (apkComponent.startsWith('.')) {
|
|
329
|
-
for (const browser of packageIdentifiers) {
|
|
330
|
-
if (apk === browser || apk.startsWith(`${browser}.`)) {
|
|
331
|
-
apkComponent = browser + apkComponent;
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
// if `apkComponent` starts with a '.', then adb will expand
|
|
337
|
-
// the following to: `${apk}/${apk}.${apkComponent}`
|
|
338
|
-
const component = `${apk}/${apkComponent}`;
|
|
339
|
-
|
|
340
|
-
await wrapADBCall(async () => {
|
|
341
|
-
await adbClient.startActivity(deviceId, {
|
|
342
|
-
wait: true,
|
|
343
|
-
action: 'android.activity.MAIN',
|
|
344
|
-
component,
|
|
345
|
-
extras,
|
|
346
|
-
});
|
|
347
|
-
});
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
setUserAbortDiscovery(value: boolean) {
|
|
351
|
-
this.userAbortDiscovery = value;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
async discoverRDPUnixSocket(
|
|
355
|
-
deviceId: string, apk: string,
|
|
356
|
-
{maxDiscoveryTime, retryInterval}: DiscoveryParams = {}
|
|
357
|
-
): Promise<string> {
|
|
358
|
-
let rdpUnixSockets = [];
|
|
359
|
-
|
|
360
|
-
const discoveryStartedAt = Date.now();
|
|
361
|
-
const msg = (
|
|
362
|
-
`Waiting for ${apk} Remote Debugging Server...` +
|
|
363
|
-
'\nMake sure to enable "Remote Debugging via USB" ' +
|
|
364
|
-
'from Settings -> Developer Tools if it is not yet enabled.'
|
|
365
|
-
);
|
|
366
|
-
|
|
367
|
-
while (rdpUnixSockets.length === 0) {
|
|
368
|
-
log.info(msg);
|
|
369
|
-
if (this.userAbortDiscovery) {
|
|
370
|
-
throw new UsageError(
|
|
371
|
-
'Exiting Firefox Remote Debugging socket discovery on user request'
|
|
372
|
-
);
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
if (Date.now() - discoveryStartedAt > maxDiscoveryTime) {
|
|
376
|
-
throw new WebExtError(
|
|
377
|
-
'Timeout while waiting for the Android Firefox Debugger Socket'
|
|
378
|
-
);
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
rdpUnixSockets = (await this.runShellCommand(deviceId, [
|
|
382
|
-
'cat', '/proc/net/unix',
|
|
383
|
-
])).split('\n').filter((line) => {
|
|
384
|
-
// The RDP unix socket is expected to be a path in the form:
|
|
385
|
-
// /data/data/org.mozilla.fennec_rpl/firefox-debugger-socket
|
|
386
|
-
return line.trim().endsWith(`${apk}/firefox-debugger-socket`);
|
|
387
|
-
});
|
|
388
|
-
|
|
389
|
-
if (rdpUnixSockets.length === 0) {
|
|
390
|
-
await new Promise((resolve) => setTimeout(resolve, retryInterval));
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
// Convert into an array of unix socket filenames.
|
|
395
|
-
rdpUnixSockets = rdpUnixSockets.map((line) => {
|
|
396
|
-
return line.trim().split(/\s/).pop();
|
|
397
|
-
});
|
|
398
|
-
|
|
399
|
-
if (rdpUnixSockets.length > 1) {
|
|
400
|
-
throw new WebExtError(
|
|
401
|
-
'Unexpected multiple RDP sockets: ' +
|
|
402
|
-
`${JSON.stringify(rdpUnixSockets)}`
|
|
403
|
-
);
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
return rdpUnixSockets[0];
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
async setupForward(deviceId: string, remote: string, local: string) {
|
|
410
|
-
const {adbClient} = this;
|
|
411
|
-
|
|
412
|
-
// TODO(rpl): we should use adb.listForwards and reuse the existing one if any (especially
|
|
413
|
-
// because adbkit doesn't seem to support `adb forward --remote` yet).
|
|
414
|
-
log.debug(`Configuring ADB forward for ${deviceId}: ${remote} -> ${local}`);
|
|
415
|
-
|
|
416
|
-
await wrapADBCall(async () => {
|
|
417
|
-
await adbClient.forward(deviceId, local, remote);
|
|
418
|
-
});
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
export async function listADBDevices(adbBin?: string): Promise<Array<string>> {
|
|
423
|
-
const adbClient = new ADBUtils({adbBin});
|
|
424
|
-
return adbClient.discoverDevices();
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
export async function listADBFirefoxAPKs(
|
|
428
|
-
deviceId: string,
|
|
429
|
-
adbBin?: string
|
|
430
|
-
): Promise<Array<string>> {
|
|
431
|
-
const adbClient = new ADBUtils({adbBin});
|
|
432
|
-
return adbClient.discoverInstalledFirefoxAPKs(deviceId);
|
|
433
|
-
}
|
package/src/util/artifacts.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/* @flow */
|
|
2
|
-
import {fs} from 'mz';
|
|
3
|
-
import defaultAsyncMkdirp from 'mkdirp';
|
|
4
|
-
|
|
5
|
-
import {UsageError, isErrorWithCode} from '../errors';
|
|
6
|
-
import {createLogger} from './logger';
|
|
7
|
-
|
|
8
|
-
const log = createLogger(__filename);
|
|
9
|
-
|
|
10
|
-
const defaultAsyncFsAccess: typeof fs.access = fs.access.bind(fs);
|
|
11
|
-
|
|
12
|
-
type PrepareArtifactsDirOptions = {
|
|
13
|
-
asyncMkdirp?: typeof defaultAsyncMkdirp,
|
|
14
|
-
asyncFsAccess?: typeof defaultAsyncFsAccess,
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export async function prepareArtifactsDir(
|
|
18
|
-
artifactsDir: string,
|
|
19
|
-
{
|
|
20
|
-
asyncMkdirp = defaultAsyncMkdirp,
|
|
21
|
-
asyncFsAccess = defaultAsyncFsAccess,
|
|
22
|
-
}: PrepareArtifactsDirOptions = {},
|
|
23
|
-
): Promise<string> {
|
|
24
|
-
try {
|
|
25
|
-
const stats = await fs.stat(artifactsDir);
|
|
26
|
-
if (!stats.isDirectory()) {
|
|
27
|
-
throw new UsageError(
|
|
28
|
-
`--artifacts-dir="${artifactsDir}" exists but it is not a directory.`);
|
|
29
|
-
}
|
|
30
|
-
// If the artifactsDir already exists, check that we have the write permissions on it.
|
|
31
|
-
try {
|
|
32
|
-
await asyncFsAccess(artifactsDir, fs.W_OK);
|
|
33
|
-
} catch (accessErr) {
|
|
34
|
-
if (isErrorWithCode('EACCES', accessErr)) {
|
|
35
|
-
throw new UsageError(
|
|
36
|
-
`--artifacts-dir="${artifactsDir}" exists but the user lacks ` +
|
|
37
|
-
'permissions on it.');
|
|
38
|
-
} else {
|
|
39
|
-
throw accessErr;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
} catch (error) {
|
|
43
|
-
if (isErrorWithCode('EACCES', error)) {
|
|
44
|
-
// Handle errors when the artifactsDir cannot be accessed.
|
|
45
|
-
throw new UsageError(
|
|
46
|
-
`Cannot access --artifacts-dir="${artifactsDir}" because the user ` +
|
|
47
|
-
`lacks permissions: ${error}`);
|
|
48
|
-
} else if (isErrorWithCode('ENOENT', error)) {
|
|
49
|
-
// Create the artifact dir if it doesn't exist yet.
|
|
50
|
-
try {
|
|
51
|
-
log.debug(`Creating artifacts directory: ${artifactsDir}`);
|
|
52
|
-
await asyncMkdirp(artifactsDir);
|
|
53
|
-
} catch (mkdirErr) {
|
|
54
|
-
if (isErrorWithCode('EACCES', mkdirErr)) {
|
|
55
|
-
// Handle errors when the artifactsDir cannot be created for lack of permissions.
|
|
56
|
-
throw new UsageError(
|
|
57
|
-
`Cannot create --artifacts-dir="${artifactsDir}" because the ` +
|
|
58
|
-
`user lacks permissions: ${mkdirErr}`);
|
|
59
|
-
} else {
|
|
60
|
-
throw mkdirErr;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
} else {
|
|
64
|
-
throw error;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return artifactsDir;
|
|
69
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/* @flow */
|
|
2
|
-
import defaultNotifier from 'node-notifier';
|
|
3
|
-
|
|
4
|
-
import {createLogger} from './logger';
|
|
5
|
-
import type {Logger} from './logger';
|
|
6
|
-
|
|
7
|
-
const defaultLog = createLogger(__filename);
|
|
8
|
-
|
|
9
|
-
export type DesktopNotificationsParams = {|
|
|
10
|
-
title: string,
|
|
11
|
-
message: string,
|
|
12
|
-
icon?: string,
|
|
13
|
-
|};
|
|
14
|
-
|
|
15
|
-
export type DesktopNotificationsOptions = {|
|
|
16
|
-
notifier?: typeof defaultNotifier,
|
|
17
|
-
log?: Logger,
|
|
18
|
-
|};
|
|
19
|
-
|
|
20
|
-
export function showDesktopNotification(
|
|
21
|
-
{
|
|
22
|
-
title, message, icon,
|
|
23
|
-
}: DesktopNotificationsParams,
|
|
24
|
-
{
|
|
25
|
-
notifier = defaultNotifier,
|
|
26
|
-
log = defaultLog,
|
|
27
|
-
}: DesktopNotificationsOptions = {}
|
|
28
|
-
): Promise<void> {
|
|
29
|
-
|
|
30
|
-
return new Promise((resolve, reject) => {
|
|
31
|
-
notifier.notify({title, message, icon}, (err, res) => {
|
|
32
|
-
if (err) {
|
|
33
|
-
log.debug(`Desktop notifier error: ${err.message},` +
|
|
34
|
-
` response: ${res}`);
|
|
35
|
-
reject(err);
|
|
36
|
-
} else {
|
|
37
|
-
resolve();
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
}
|
package/src/util/is-directory.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/* @flow */
|
|
2
|
-
import {fs} from 'mz';
|
|
3
|
-
|
|
4
|
-
import {onlyErrorsWithCode} from '../errors';
|
|
5
|
-
|
|
6
|
-
/*
|
|
7
|
-
* Resolves true if the path is a readable directory.
|
|
8
|
-
*
|
|
9
|
-
* Usage:
|
|
10
|
-
*
|
|
11
|
-
* isDirectory('/some/path')
|
|
12
|
-
* .then((dirExists) => {
|
|
13
|
-
* // dirExists will be true or false.
|
|
14
|
-
* });
|
|
15
|
-
*
|
|
16
|
-
* */
|
|
17
|
-
export default function isDirectory(path: string): Promise<boolean> {
|
|
18
|
-
return fs.stat(path)
|
|
19
|
-
.then((stats) => stats.isDirectory())
|
|
20
|
-
.catch(onlyErrorsWithCode(['ENOENT', 'ENOTDIR'], () => {
|
|
21
|
-
return false;
|
|
22
|
-
}));
|
|
23
|
-
}
|
package/src/util/logger.js
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
/* @flow */
|
|
2
|
-
import bunyan, {nameFromLevel, createLogger as defaultLogCreator}
|
|
3
|
-
from 'bunyan';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
// Bunyan-related Flow types
|
|
7
|
-
|
|
8
|
-
export type TRACE = 10;
|
|
9
|
-
export type DEBUG = 20;
|
|
10
|
-
export type INFO = 30;
|
|
11
|
-
export type WARN = 40;
|
|
12
|
-
export type ERROR = 50;
|
|
13
|
-
export type FATAL = 60;
|
|
14
|
-
|
|
15
|
-
export type BunyanLogLevel =
|
|
16
|
-
TRACE | DEBUG | INFO | WARN | ERROR | FATAL;
|
|
17
|
-
|
|
18
|
-
export type BunyanLogEntry = {|
|
|
19
|
-
name: string,
|
|
20
|
-
msg: string,
|
|
21
|
-
level: BunyanLogLevel,
|
|
22
|
-
|};
|
|
23
|
-
|
|
24
|
-
export type Logger = {
|
|
25
|
-
debug: (msg: string, ...args: any) => void,
|
|
26
|
-
error: (msg: string, ...args: any) => void,
|
|
27
|
-
info: (msg: string, ...args: any) => void,
|
|
28
|
-
warn: (msg: string, ...args: any) => void,
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
// ConsoleStream types and implementation.
|
|
33
|
-
|
|
34
|
-
export type ConsoleStreamParams = {|
|
|
35
|
-
verbose?: boolean,
|
|
36
|
-
|};
|
|
37
|
-
|
|
38
|
-
export type ConsoleOptions = {|
|
|
39
|
-
localProcess?: typeof process,
|
|
40
|
-
|};
|
|
41
|
-
|
|
42
|
-
export class ConsoleStream {
|
|
43
|
-
verbose: boolean;
|
|
44
|
-
isCapturing: boolean;
|
|
45
|
-
capturedMessages: Array<string>;
|
|
46
|
-
|
|
47
|
-
constructor({verbose = false}: ConsoleStreamParams = {}) {
|
|
48
|
-
this.verbose = verbose;
|
|
49
|
-
this.isCapturing = false;
|
|
50
|
-
this.capturedMessages = [];
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
format({name, msg, level}: BunyanLogEntry): string {
|
|
54
|
-
const prefix = this.verbose ? `[${name}][${nameFromLevel[level]}] ` : '';
|
|
55
|
-
return `${prefix}${msg}\n`;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
makeVerbose() {
|
|
59
|
-
this.verbose = true;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
write(
|
|
63
|
-
packet: BunyanLogEntry,
|
|
64
|
-
{localProcess = process}: ConsoleOptions = {}
|
|
65
|
-
): void {
|
|
66
|
-
const thisLevel: BunyanLogLevel = this.verbose ? bunyan.TRACE : bunyan.INFO;
|
|
67
|
-
if (packet.level >= thisLevel) {
|
|
68
|
-
const msg = this.format(packet);
|
|
69
|
-
if (this.isCapturing) {
|
|
70
|
-
this.capturedMessages.push(msg);
|
|
71
|
-
} else {
|
|
72
|
-
localProcess.stdout.write(msg);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
startCapturing() {
|
|
78
|
-
this.isCapturing = true;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
stopCapturing() {
|
|
82
|
-
this.isCapturing = false;
|
|
83
|
-
this.capturedMessages = [];
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
flushCapturedLogs({localProcess = process}: ConsoleOptions = {}) {
|
|
87
|
-
for (const msg of this.capturedMessages) {
|
|
88
|
-
localProcess.stdout.write(msg);
|
|
89
|
-
}
|
|
90
|
-
this.capturedMessages = [];
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export const consoleStream: ConsoleStream = new ConsoleStream();
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
// createLogger types and implementation.
|
|
98
|
-
|
|
99
|
-
export type BunyanStreamConfig = {|
|
|
100
|
-
type: string,
|
|
101
|
-
stream: ConsoleStream,
|
|
102
|
-
|};
|
|
103
|
-
|
|
104
|
-
export type CreateBunyanLogParams = {|
|
|
105
|
-
name: string,
|
|
106
|
-
level: BunyanLogLevel,
|
|
107
|
-
streams: Array<BunyanStreamConfig>,
|
|
108
|
-
|};
|
|
109
|
-
|
|
110
|
-
export type CreateBunyanLogFn = (params: CreateBunyanLogParams) => Logger;
|
|
111
|
-
|
|
112
|
-
export type CreateLoggerOptions = {|
|
|
113
|
-
createBunyanLog: CreateBunyanLogFn,
|
|
114
|
-
|};
|
|
115
|
-
|
|
116
|
-
export function createLogger(
|
|
117
|
-
filename: string,
|
|
118
|
-
{createBunyanLog = defaultLogCreator}: CreateLoggerOptions = {}
|
|
119
|
-
): Logger {
|
|
120
|
-
return createBunyanLog({
|
|
121
|
-
// Strip the leading src/ from file names (which is in all file names) to
|
|
122
|
-
// make the name less redundant.
|
|
123
|
-
name: filename.replace(/^src\//, ''),
|
|
124
|
-
// Capture all log levels and let the stream filter them.
|
|
125
|
-
level: bunyan.TRACE,
|
|
126
|
-
streams: [{
|
|
127
|
-
type: 'raw',
|
|
128
|
-
stream: consoleStream,
|
|
129
|
-
}],
|
|
130
|
-
});
|
|
131
|
-
}
|