web-ext 6.6.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 +123 -179
- 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 +52 -54
- 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
package/src/program.js
DELETED
|
@@ -1,765 +0,0 @@
|
|
|
1
|
-
/* @flow */
|
|
2
|
-
import os from 'os';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import {readFileSync} from 'fs';
|
|
5
|
-
|
|
6
|
-
import camelCase from 'camelcase';
|
|
7
|
-
import decamelize from 'decamelize';
|
|
8
|
-
import yargs from 'yargs';
|
|
9
|
-
import { Parser as yargsParser } from 'yargs/helpers';
|
|
10
|
-
|
|
11
|
-
import defaultCommands from './cmd';
|
|
12
|
-
import {UsageError} from './errors';
|
|
13
|
-
import {createLogger, consoleStream as defaultLogStream} from './util/logger';
|
|
14
|
-
import {coerceCLICustomPreference} from './firefox/preferences';
|
|
15
|
-
import {checkForUpdates as defaultUpdateChecker} from './util/updates';
|
|
16
|
-
import {
|
|
17
|
-
discoverConfigFiles as defaultConfigDiscovery,
|
|
18
|
-
loadJSConfigFile as defaultLoadJSConfigFile,
|
|
19
|
-
applyConfigToArgv as defaultApplyConfigToArgv,
|
|
20
|
-
} from './config';
|
|
21
|
-
|
|
22
|
-
const log = createLogger(__filename);
|
|
23
|
-
const envPrefix = 'WEB_EXT';
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
type ProgramOptions = {|
|
|
27
|
-
absolutePackageDir?: string,
|
|
28
|
-
|}
|
|
29
|
-
|
|
30
|
-
export type VersionGetterFn = (absolutePackageDir: string) => string;
|
|
31
|
-
|
|
32
|
-
// TODO: add pipes to Flow type after https://github.com/facebook/flow/issues/2405 is fixed
|
|
33
|
-
|
|
34
|
-
type ExecuteOptions = {
|
|
35
|
-
checkForUpdates?: Function,
|
|
36
|
-
systemProcess?: typeof process,
|
|
37
|
-
logStream?: typeof defaultLogStream,
|
|
38
|
-
getVersion?: VersionGetterFn,
|
|
39
|
-
applyConfigToArgv?: typeof defaultApplyConfigToArgv,
|
|
40
|
-
discoverConfigFiles?: typeof defaultConfigDiscovery,
|
|
41
|
-
loadJSConfigFile?: typeof defaultLoadJSConfigFile,
|
|
42
|
-
shouldExitProgram?: boolean,
|
|
43
|
-
globalEnv?: string,
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
/*
|
|
48
|
-
* The command line program.
|
|
49
|
-
*/
|
|
50
|
-
export class Program {
|
|
51
|
-
absolutePackageDir: string;
|
|
52
|
-
yargs: any;
|
|
53
|
-
commands: { [key: string]: Function };
|
|
54
|
-
shouldExitProgram: boolean;
|
|
55
|
-
verboseEnabled: boolean;
|
|
56
|
-
options: Object;
|
|
57
|
-
programArgv: Array<string>;
|
|
58
|
-
|
|
59
|
-
constructor(
|
|
60
|
-
argv: ?Array<string>,
|
|
61
|
-
{
|
|
62
|
-
absolutePackageDir = process.cwd(),
|
|
63
|
-
}: ProgramOptions = {}
|
|
64
|
-
) {
|
|
65
|
-
// This allows us to override the process argv which is useful for
|
|
66
|
-
// testing.
|
|
67
|
-
// NOTE: process.argv.slice(2) removes the path to node and web-ext
|
|
68
|
-
// executables from the process.argv array.
|
|
69
|
-
argv = argv || process.argv.slice(2);
|
|
70
|
-
this.programArgv = argv;
|
|
71
|
-
|
|
72
|
-
// NOTE: always initialize yargs explicitly with the package dir
|
|
73
|
-
// to avoid side-effects due to yargs looking for its configuration
|
|
74
|
-
// section from a package.json file stored in an arbitrary directory
|
|
75
|
-
// (e.g. in tests yargs would end up loading yargs config from the
|
|
76
|
-
// mocha package.json). web-ext package.json doesn't contain any yargs
|
|
77
|
-
// section as it is deprecated and we configure yargs using
|
|
78
|
-
// yargs.parserConfiguration. See web-ext#469 for rationale.
|
|
79
|
-
const yargsInstance = yargs(argv, absolutePackageDir);
|
|
80
|
-
|
|
81
|
-
this.absolutePackageDir = absolutePackageDir;
|
|
82
|
-
this.verboseEnabled = false;
|
|
83
|
-
this.shouldExitProgram = true;
|
|
84
|
-
|
|
85
|
-
this.yargs = yargsInstance;
|
|
86
|
-
this.yargs.parserConfiguration({
|
|
87
|
-
'boolean-negation': true,
|
|
88
|
-
});
|
|
89
|
-
this.yargs.strict();
|
|
90
|
-
this.yargs.wrap(this.yargs.terminalWidth());
|
|
91
|
-
|
|
92
|
-
this.commands = {};
|
|
93
|
-
this.options = {};
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
command(
|
|
97
|
-
name: string, description: string, executor: Function,
|
|
98
|
-
commandOptions: Object = {}
|
|
99
|
-
): Program {
|
|
100
|
-
this.options[camelCase(name)] = commandOptions;
|
|
101
|
-
|
|
102
|
-
this.yargs.command(name, description, (yargsForCmd) => {
|
|
103
|
-
if (!commandOptions) {
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
return yargsForCmd
|
|
107
|
-
// Make sure the user does not add any extra commands. For example,
|
|
108
|
-
// this would be a mistake because lint does not accept arguments:
|
|
109
|
-
// web-ext lint ./src/path/to/file.js
|
|
110
|
-
.demandCommand(0, 0, undefined,
|
|
111
|
-
'This command does not take any arguments')
|
|
112
|
-
.strict()
|
|
113
|
-
.exitProcess(this.shouldExitProgram)
|
|
114
|
-
// Calling env() will be unnecessary after
|
|
115
|
-
// https://github.com/yargs/yargs/issues/486 is fixed
|
|
116
|
-
.env(envPrefix)
|
|
117
|
-
.options(commandOptions);
|
|
118
|
-
});
|
|
119
|
-
this.commands[name] = executor;
|
|
120
|
-
return this;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
setGlobalOptions(options: Object): Program {
|
|
124
|
-
// This is a convenience for setting global options.
|
|
125
|
-
// An option is only global (i.e. available to all sub commands)
|
|
126
|
-
// with the `global` flag so this makes sure every option has it.
|
|
127
|
-
this.options = {...this.options, ...options};
|
|
128
|
-
Object.keys(options).forEach((key) => {
|
|
129
|
-
options[key].global = true;
|
|
130
|
-
if (options[key].demandOption === undefined) {
|
|
131
|
-
// By default, all options should be "demanded" otherwise
|
|
132
|
-
// yargs.strict() will think they are missing when declared.
|
|
133
|
-
options[key].demandOption = true;
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
this.yargs.options(options);
|
|
137
|
-
return this;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
enableVerboseMode(
|
|
141
|
-
logStream: typeof defaultLogStream,
|
|
142
|
-
version: string
|
|
143
|
-
): void {
|
|
144
|
-
if (this.verboseEnabled) {
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
logStream.makeVerbose();
|
|
149
|
-
log.info('Version:', version);
|
|
150
|
-
this.verboseEnabled = true;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// Retrieve the yargs argv object and apply any further fix needed
|
|
154
|
-
// on the output of the yargs options parsing.
|
|
155
|
-
getArguments(): Object {
|
|
156
|
-
// To support looking up required parameters via config files, we need to
|
|
157
|
-
// temporarily disable the requiredArguments validation. Otherwise yargs
|
|
158
|
-
// would exit early. Validation is enforced by the checkRequiredArguments()
|
|
159
|
-
// method, after reading configuration files.
|
|
160
|
-
//
|
|
161
|
-
// This is an undocumented internal API of yargs! Unit tests to avoid
|
|
162
|
-
// regressions are located at: tests/functional/test.cli.sign.js
|
|
163
|
-
//
|
|
164
|
-
// Replace hack if possible: https://github.com/mozilla/web-ext/issues/1930
|
|
165
|
-
const validationInstance = this.yargs.getValidationInstance();
|
|
166
|
-
const { requiredArguments } = validationInstance;
|
|
167
|
-
validationInstance.requiredArguments = () => {};
|
|
168
|
-
const argv = this.yargs.argv;
|
|
169
|
-
validationInstance.requiredArguments = requiredArguments;
|
|
170
|
-
|
|
171
|
-
// Yargs boolean options doesn't define the no* counterpart
|
|
172
|
-
// with negate-boolean on Yargs 15. Define as expected by the
|
|
173
|
-
// web-ext execute method.
|
|
174
|
-
if (argv.configDiscovery != null) {
|
|
175
|
-
argv.noConfigDiscovery = !argv.configDiscovery;
|
|
176
|
-
}
|
|
177
|
-
if (argv.reload != null) {
|
|
178
|
-
argv.noReload = !argv.reload;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// Yargs doesn't accept --no-input as a valid option if there isn't a
|
|
182
|
-
// --input option defined to be negated, to fix that the --input is
|
|
183
|
-
// defined and hidden from the yargs help output and we define here
|
|
184
|
-
// the negated argument name that we expect to be set in the parsed
|
|
185
|
-
// arguments (and fix https://github.com/mozilla/web-ext/issues/1860).
|
|
186
|
-
if (argv.input != null) {
|
|
187
|
-
argv.noInput = !argv.input;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
// Replacement for the "requiresArg: true" parameter until the following bug
|
|
191
|
-
// is fixed: https://github.com/yargs/yargs/issues/1098
|
|
192
|
-
if (argv.ignoreFiles && !argv.ignoreFiles.length) {
|
|
193
|
-
throw new UsageError('Not enough arguments following: ignore-files');
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
if (argv.startUrl && !argv.startUrl.length) {
|
|
197
|
-
throw new UsageError('Not enough arguments following: start-url');
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
return argv;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// getArguments() disables validation of required parameters, to allow us to
|
|
204
|
-
// read parameters from config files first. Before the program continues, it
|
|
205
|
-
// must call checkRequiredArguments() to ensure that required parameters are
|
|
206
|
-
// defined (in the CLI or in a config file).
|
|
207
|
-
checkRequiredArguments(adjustedArgv: Object): void {
|
|
208
|
-
const validationInstance = this.yargs.getValidationInstance();
|
|
209
|
-
validationInstance.requiredArguments(adjustedArgv);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
// Remove WEB_EXT_* environment vars that are not a global cli options
|
|
213
|
-
// or an option supported by the current command (See #793).
|
|
214
|
-
cleanupProcessEnvConfigs(systemProcess: typeof process) {
|
|
215
|
-
const cmd = yargsParser(this.programArgv)._[0];
|
|
216
|
-
const env = systemProcess.env || {};
|
|
217
|
-
const toOptionKey = (k) => decamelize(
|
|
218
|
-
camelCase(k.replace(envPrefix, '')), {separator: '-'}
|
|
219
|
-
);
|
|
220
|
-
|
|
221
|
-
if (cmd) {
|
|
222
|
-
Object.keys(env)
|
|
223
|
-
.filter((k) => k.startsWith(envPrefix))
|
|
224
|
-
.forEach((k) => {
|
|
225
|
-
const optKey = toOptionKey(k);
|
|
226
|
-
const globalOpt = this.options[optKey];
|
|
227
|
-
const cmdOpt = this.options[cmd] && this.options[cmd][optKey];
|
|
228
|
-
|
|
229
|
-
if (!globalOpt && !cmdOpt) {
|
|
230
|
-
log.debug(`Environment ${k} not supported by web-ext ${cmd}`);
|
|
231
|
-
delete env[k];
|
|
232
|
-
}
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
async execute(
|
|
238
|
-
{
|
|
239
|
-
checkForUpdates = defaultUpdateChecker,
|
|
240
|
-
systemProcess = process,
|
|
241
|
-
logStream = defaultLogStream,
|
|
242
|
-
getVersion = defaultVersionGetter,
|
|
243
|
-
applyConfigToArgv = defaultApplyConfigToArgv,
|
|
244
|
-
discoverConfigFiles = defaultConfigDiscovery,
|
|
245
|
-
loadJSConfigFile = defaultLoadJSConfigFile,
|
|
246
|
-
shouldExitProgram = true,
|
|
247
|
-
globalEnv = WEBEXT_BUILD_ENV,
|
|
248
|
-
}: ExecuteOptions = {}
|
|
249
|
-
): Promise<void> {
|
|
250
|
-
this.shouldExitProgram = shouldExitProgram;
|
|
251
|
-
this.yargs.exitProcess(this.shouldExitProgram);
|
|
252
|
-
|
|
253
|
-
this.cleanupProcessEnvConfigs(systemProcess);
|
|
254
|
-
const argv = this.getArguments();
|
|
255
|
-
|
|
256
|
-
const cmd = argv._[0];
|
|
257
|
-
|
|
258
|
-
const version = getVersion(this.absolutePackageDir);
|
|
259
|
-
const runCommand = this.commands[cmd];
|
|
260
|
-
|
|
261
|
-
if (argv.verbose) {
|
|
262
|
-
this.enableVerboseMode(logStream, version);
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
let adjustedArgv = {...argv};
|
|
266
|
-
|
|
267
|
-
try {
|
|
268
|
-
if (cmd === undefined) {
|
|
269
|
-
throw new UsageError('No sub-command was specified in the args');
|
|
270
|
-
}
|
|
271
|
-
if (!runCommand) {
|
|
272
|
-
throw new UsageError(`Unknown command: ${cmd}`);
|
|
273
|
-
}
|
|
274
|
-
if (globalEnv === 'production') {
|
|
275
|
-
checkForUpdates({version});
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
const configFiles = [];
|
|
279
|
-
|
|
280
|
-
if (argv.configDiscovery) {
|
|
281
|
-
log.debug(
|
|
282
|
-
'Discovering config files. ' +
|
|
283
|
-
'Set --no-config-discovery to disable');
|
|
284
|
-
const discoveredConfigs = await discoverConfigFiles();
|
|
285
|
-
configFiles.push(...discoveredConfigs);
|
|
286
|
-
} else {
|
|
287
|
-
log.debug('Not discovering config files');
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
if (argv.config) {
|
|
291
|
-
configFiles.push(path.resolve(argv.config));
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
if (configFiles.length) {
|
|
295
|
-
const niceFileList = configFiles
|
|
296
|
-
.map((f) => f.replace(process.cwd(), '.'))
|
|
297
|
-
.map((f) => f.replace(os.homedir(), '~'))
|
|
298
|
-
.join(', ');
|
|
299
|
-
log.info(
|
|
300
|
-
'Applying config file' +
|
|
301
|
-
`${configFiles.length !== 1 ? 's' : ''}: ` +
|
|
302
|
-
`${niceFileList}`);
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
configFiles.forEach((configFileName) => {
|
|
306
|
-
const configObject = loadJSConfigFile(configFileName);
|
|
307
|
-
adjustedArgv = applyConfigToArgv({
|
|
308
|
-
argv: adjustedArgv,
|
|
309
|
-
argvFromCLI: argv,
|
|
310
|
-
configFileName,
|
|
311
|
-
configObject,
|
|
312
|
-
options: this.options,
|
|
313
|
-
});
|
|
314
|
-
});
|
|
315
|
-
|
|
316
|
-
if (adjustedArgv.verbose) {
|
|
317
|
-
// Ensure that the verbose is enabled when specified in a config file.
|
|
318
|
-
this.enableVerboseMode(logStream, version);
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
this.checkRequiredArguments(adjustedArgv);
|
|
322
|
-
|
|
323
|
-
await runCommand(adjustedArgv, {shouldExitProgram});
|
|
324
|
-
|
|
325
|
-
} catch (error) {
|
|
326
|
-
if (!(error instanceof UsageError) || adjustedArgv.verbose) {
|
|
327
|
-
log.error(`\n${error.stack}\n`);
|
|
328
|
-
} else {
|
|
329
|
-
log.error(`\n${error}\n`);
|
|
330
|
-
}
|
|
331
|
-
if (error.code) {
|
|
332
|
-
log.error(`Error code: ${error.code}\n`);
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
log.debug(`Command executed: ${cmd}`);
|
|
336
|
-
|
|
337
|
-
if (this.shouldExitProgram) {
|
|
338
|
-
systemProcess.exit(1);
|
|
339
|
-
} else {
|
|
340
|
-
throw error;
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
// A global variable generated by DefinePlugin, generated in webpack.config.js
|
|
347
|
-
declare var WEBEXT_BUILD_ENV: string;
|
|
348
|
-
|
|
349
|
-
//A defintion of type of argument for defaultVersionGetter
|
|
350
|
-
type VersionGetterOptions = {
|
|
351
|
-
globalEnv?: string,
|
|
352
|
-
};
|
|
353
|
-
|
|
354
|
-
export function defaultVersionGetter(
|
|
355
|
-
absolutePackageDir: string,
|
|
356
|
-
{globalEnv = WEBEXT_BUILD_ENV}: VersionGetterOptions = {}
|
|
357
|
-
): string {
|
|
358
|
-
if (globalEnv === 'production') {
|
|
359
|
-
log.debug('Getting the version from package.json');
|
|
360
|
-
const packageData: any = readFileSync(
|
|
361
|
-
path.join(absolutePackageDir, 'package.json'));
|
|
362
|
-
return JSON.parse(packageData).version;
|
|
363
|
-
} else {
|
|
364
|
-
log.debug('Getting version from the git revision');
|
|
365
|
-
// This branch is only reached during development.
|
|
366
|
-
// git-rev-sync is in devDependencies, and lazily imported using require.
|
|
367
|
-
// This also avoids logspam from https://github.com/mozilla/web-ext/issues/1916
|
|
368
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
369
|
-
const git = require('git-rev-sync');
|
|
370
|
-
return `${git.branch(absolutePackageDir)}-${git.long(absolutePackageDir)}`;
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
// TODO: add pipes to Flow type after https://github.com/facebook/flow/issues/2405 is fixed
|
|
375
|
-
|
|
376
|
-
type MainParams = {
|
|
377
|
-
getVersion?: VersionGetterFn,
|
|
378
|
-
commands?: Object,
|
|
379
|
-
argv: Array<any>,
|
|
380
|
-
runOptions?: Object,
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
export function throwUsageErrorIfArray(errorMessage: string): any {
|
|
384
|
-
return (value: any): any => {
|
|
385
|
-
if (Array.isArray(value)) {
|
|
386
|
-
throw new UsageError(errorMessage);
|
|
387
|
-
}
|
|
388
|
-
return value;
|
|
389
|
-
};
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
export function main(
|
|
393
|
-
absolutePackageDir: string,
|
|
394
|
-
{
|
|
395
|
-
getVersion = defaultVersionGetter, commands = defaultCommands, argv,
|
|
396
|
-
runOptions = {},
|
|
397
|
-
}: MainParams = {}
|
|
398
|
-
): Promise<any> {
|
|
399
|
-
const program = new Program(argv, {absolutePackageDir});
|
|
400
|
-
const version = getVersion(absolutePackageDir);
|
|
401
|
-
|
|
402
|
-
// yargs uses magic camel case expansion to expose options on the
|
|
403
|
-
// final argv object. For example, the 'artifacts-dir' option is alternatively
|
|
404
|
-
// available as argv.artifactsDir.
|
|
405
|
-
program.yargs
|
|
406
|
-
.usage(`Usage: $0 [options] command
|
|
407
|
-
|
|
408
|
-
Option values can also be set by declaring an environment variable prefixed
|
|
409
|
-
with $${envPrefix}_. For example: $${envPrefix}_SOURCE_DIR=/path is the same as
|
|
410
|
-
--source-dir=/path.
|
|
411
|
-
|
|
412
|
-
To view specific help for any given command, add the command name.
|
|
413
|
-
Example: $0 --help run.
|
|
414
|
-
`)
|
|
415
|
-
.help('help')
|
|
416
|
-
.alias('h', 'help')
|
|
417
|
-
.env(envPrefix)
|
|
418
|
-
.version(version)
|
|
419
|
-
.demandCommand(1, 'You must specify a command')
|
|
420
|
-
.strict()
|
|
421
|
-
.recommendCommands();
|
|
422
|
-
|
|
423
|
-
program.setGlobalOptions({
|
|
424
|
-
'source-dir': {
|
|
425
|
-
alias: 's',
|
|
426
|
-
describe: 'Web extension source directory.',
|
|
427
|
-
default: process.cwd(),
|
|
428
|
-
requiresArg: true,
|
|
429
|
-
type: 'string',
|
|
430
|
-
coerce: path.resolve,
|
|
431
|
-
},
|
|
432
|
-
'artifacts-dir': {
|
|
433
|
-
alias: 'a',
|
|
434
|
-
describe: 'Directory where artifacts will be saved.',
|
|
435
|
-
default: path.join(process.cwd(), 'web-ext-artifacts'),
|
|
436
|
-
normalize: true,
|
|
437
|
-
requiresArg: true,
|
|
438
|
-
type: 'string',
|
|
439
|
-
},
|
|
440
|
-
'verbose': {
|
|
441
|
-
alias: 'v',
|
|
442
|
-
describe: 'Show verbose output',
|
|
443
|
-
type: 'boolean',
|
|
444
|
-
demandOption: false,
|
|
445
|
-
},
|
|
446
|
-
'ignore-files': {
|
|
447
|
-
alias: 'i',
|
|
448
|
-
describe: 'A list of glob patterns to define which files should be ' +
|
|
449
|
-
'ignored. (Example: --ignore-files=path/to/first.js ' +
|
|
450
|
-
'path/to/second.js "**/*.log")',
|
|
451
|
-
demandOption: false,
|
|
452
|
-
// The following option prevents yargs>=11 from parsing multiple values,
|
|
453
|
-
// so the minimum value requirement is enforced in execute instead.
|
|
454
|
-
// Upstream bug: https://github.com/yargs/yargs/issues/1098
|
|
455
|
-
// requiresArg: true,
|
|
456
|
-
type: 'array',
|
|
457
|
-
},
|
|
458
|
-
'no-input': {
|
|
459
|
-
describe: 'Disable all features that require standard input',
|
|
460
|
-
type: 'boolean',
|
|
461
|
-
demandOption: false,
|
|
462
|
-
},
|
|
463
|
-
'input': {
|
|
464
|
-
// This option is defined to make yargs to accept the --no-input
|
|
465
|
-
// defined above, but we hide it from the yargs help output.
|
|
466
|
-
hidden: true,
|
|
467
|
-
type: 'boolean',
|
|
468
|
-
demandOption: false,
|
|
469
|
-
},
|
|
470
|
-
'config': {
|
|
471
|
-
alias: 'c',
|
|
472
|
-
describe: 'Path to a CommonJS config file to set ' +
|
|
473
|
-
'option defaults',
|
|
474
|
-
default: undefined,
|
|
475
|
-
demandOption: false,
|
|
476
|
-
requiresArg: true,
|
|
477
|
-
type: 'string',
|
|
478
|
-
},
|
|
479
|
-
'config-discovery': {
|
|
480
|
-
describe: 'Discover config files in home directory and ' +
|
|
481
|
-
'working directory. Disable with --no-config-discovery.',
|
|
482
|
-
demandOption: false,
|
|
483
|
-
default: true,
|
|
484
|
-
type: 'boolean',
|
|
485
|
-
},
|
|
486
|
-
});
|
|
487
|
-
|
|
488
|
-
program
|
|
489
|
-
.command(
|
|
490
|
-
'build',
|
|
491
|
-
'Create an extension package from source',
|
|
492
|
-
commands.build, {
|
|
493
|
-
'as-needed': {
|
|
494
|
-
describe: 'Watch for file changes and re-build as needed',
|
|
495
|
-
type: 'boolean',
|
|
496
|
-
},
|
|
497
|
-
'filename': {
|
|
498
|
-
alias: 'n',
|
|
499
|
-
describe: 'Name of the created extension package file.',
|
|
500
|
-
default: undefined,
|
|
501
|
-
normalize: false,
|
|
502
|
-
demandOption: false,
|
|
503
|
-
requiresArg: true,
|
|
504
|
-
type: 'string',
|
|
505
|
-
coerce: throwUsageErrorIfArray(
|
|
506
|
-
'Multiple --filename/-n option are not allowed'
|
|
507
|
-
),
|
|
508
|
-
},
|
|
509
|
-
'overwrite-dest': {
|
|
510
|
-
alias: 'o',
|
|
511
|
-
describe: 'Overwrite destination package if it exists.',
|
|
512
|
-
type: 'boolean',
|
|
513
|
-
},
|
|
514
|
-
})
|
|
515
|
-
.command(
|
|
516
|
-
'sign',
|
|
517
|
-
'Sign the extension so it can be installed in Firefox',
|
|
518
|
-
commands.sign, {
|
|
519
|
-
'api-key': {
|
|
520
|
-
describe: 'API key (JWT issuer) from addons.mozilla.org',
|
|
521
|
-
demandOption: true,
|
|
522
|
-
type: 'string',
|
|
523
|
-
},
|
|
524
|
-
'api-secret': {
|
|
525
|
-
describe: 'API secret (JWT secret) from addons.mozilla.org',
|
|
526
|
-
demandOption: true,
|
|
527
|
-
type: 'string',
|
|
528
|
-
},
|
|
529
|
-
'api-url-prefix': {
|
|
530
|
-
describe: 'Signing API URL prefix',
|
|
531
|
-
default: 'https://addons.mozilla.org/api/v4',
|
|
532
|
-
demandOption: true,
|
|
533
|
-
type: 'string',
|
|
534
|
-
},
|
|
535
|
-
'api-proxy': {
|
|
536
|
-
describe:
|
|
537
|
-
'Use a proxy to access the signing API. ' +
|
|
538
|
-
'Example: https://yourproxy:6000 ',
|
|
539
|
-
demandOption: false,
|
|
540
|
-
type: 'string',
|
|
541
|
-
},
|
|
542
|
-
'id': {
|
|
543
|
-
describe:
|
|
544
|
-
'A custom ID for the extension. This has no effect if the ' +
|
|
545
|
-
'extension already declares an explicit ID in its manifest.',
|
|
546
|
-
demandOption: false,
|
|
547
|
-
type: 'string',
|
|
548
|
-
},
|
|
549
|
-
'timeout': {
|
|
550
|
-
describe: 'Number of milliseconds to wait before giving up',
|
|
551
|
-
type: 'number',
|
|
552
|
-
},
|
|
553
|
-
'channel': {
|
|
554
|
-
describe: 'The channel for which to sign the addon. Either ' +
|
|
555
|
-
'\'listed\' or \'unlisted\'',
|
|
556
|
-
type: 'string',
|
|
557
|
-
},
|
|
558
|
-
})
|
|
559
|
-
.command('run', 'Run the extension', commands.run, {
|
|
560
|
-
'target': {
|
|
561
|
-
alias: 't',
|
|
562
|
-
describe: 'The extensions runners to enable. Specify this option ' +
|
|
563
|
-
'multiple times to run against multiple targets.',
|
|
564
|
-
default: 'firefox-desktop',
|
|
565
|
-
demandOption: false,
|
|
566
|
-
type: 'array',
|
|
567
|
-
choices: ['firefox-desktop', 'firefox-android', 'chromium'],
|
|
568
|
-
},
|
|
569
|
-
'firefox': {
|
|
570
|
-
alias: ['f', 'firefox-binary'],
|
|
571
|
-
describe: 'Path or alias to a Firefox executable such as firefox-bin ' +
|
|
572
|
-
'or firefox.exe. ' +
|
|
573
|
-
'If not specified, the default Firefox will be used. ' +
|
|
574
|
-
'You can specify the following aliases in lieu of a path: ' +
|
|
575
|
-
'firefox, beta, nightly, firefoxdeveloperedition.',
|
|
576
|
-
demandOption: false,
|
|
577
|
-
type: 'string',
|
|
578
|
-
},
|
|
579
|
-
'firefox-profile': {
|
|
580
|
-
alias: 'p',
|
|
581
|
-
describe: 'Run Firefox using a copy of this profile. The profile ' +
|
|
582
|
-
'can be specified as a directory or a name, such as one ' +
|
|
583
|
-
'you would see in the Profile Manager. If not specified, ' +
|
|
584
|
-
'a new temporary profile will be created.',
|
|
585
|
-
demandOption: false,
|
|
586
|
-
type: 'string',
|
|
587
|
-
},
|
|
588
|
-
'chromium-binary': {
|
|
589
|
-
describe: 'Path or alias to a Chromium executable such as ' +
|
|
590
|
-
'google-chrome, google-chrome.exe or opera.exe etc. ' +
|
|
591
|
-
'If not specified, the default Google Chrome will be used.',
|
|
592
|
-
demandOption: false,
|
|
593
|
-
type: 'string',
|
|
594
|
-
},
|
|
595
|
-
'chromium-profile': {
|
|
596
|
-
describe: 'Path to a custom Chromium profile',
|
|
597
|
-
demandOption: false,
|
|
598
|
-
type: 'string',
|
|
599
|
-
},
|
|
600
|
-
'profile-create-if-missing': {
|
|
601
|
-
describe: 'Create the profile directory if it does not already exist',
|
|
602
|
-
demandOption: false,
|
|
603
|
-
type: 'boolean',
|
|
604
|
-
},
|
|
605
|
-
'keep-profile-changes': {
|
|
606
|
-
describe: 'Run Firefox directly in custom profile. Any changes to ' +
|
|
607
|
-
'the profile will be saved.',
|
|
608
|
-
demandOption: false,
|
|
609
|
-
type: 'boolean',
|
|
610
|
-
},
|
|
611
|
-
'reload': {
|
|
612
|
-
describe: 'Reload the extension when source files change.' +
|
|
613
|
-
'Disable with --no-reload.',
|
|
614
|
-
demandOption: false,
|
|
615
|
-
default: true,
|
|
616
|
-
type: 'boolean',
|
|
617
|
-
},
|
|
618
|
-
'watch-file': {
|
|
619
|
-
alias: ['watch-files'],
|
|
620
|
-
describe: 'Reload the extension only when the contents of this' +
|
|
621
|
-
' file changes. This is useful if you use a custom' +
|
|
622
|
-
' build process for your extension',
|
|
623
|
-
demandOption: false,
|
|
624
|
-
type: 'array',
|
|
625
|
-
},
|
|
626
|
-
'watch-ignored': {
|
|
627
|
-
describe: 'Paths and globs patterns that should not be ' +
|
|
628
|
-
'watched for changes. This is useful if you want ' +
|
|
629
|
-
'to explicitly prevent web-ext from watching part ' +
|
|
630
|
-
'of the extension directory tree, ' +
|
|
631
|
-
'e.g. the node_modules folder.',
|
|
632
|
-
demandOption: false,
|
|
633
|
-
type: 'array',
|
|
634
|
-
},
|
|
635
|
-
'pre-install': {
|
|
636
|
-
describe: 'Pre-install the extension into the profile before ' +
|
|
637
|
-
'startup. This is only needed to support older versions ' +
|
|
638
|
-
'of Firefox.',
|
|
639
|
-
demandOption: false,
|
|
640
|
-
type: 'boolean',
|
|
641
|
-
},
|
|
642
|
-
'pref': {
|
|
643
|
-
describe: 'Launch firefox with a custom preference ' +
|
|
644
|
-
'(example: --pref=general.useragent.locale=fr-FR). ' +
|
|
645
|
-
'You can repeat this option to set more than one ' +
|
|
646
|
-
'preference.',
|
|
647
|
-
demandOption: false,
|
|
648
|
-
requiresArg: true,
|
|
649
|
-
type: 'array',
|
|
650
|
-
coerce: coerceCLICustomPreference,
|
|
651
|
-
},
|
|
652
|
-
'start-url': {
|
|
653
|
-
alias: ['u', 'url'],
|
|
654
|
-
describe: 'Launch firefox at specified page',
|
|
655
|
-
demandOption: false,
|
|
656
|
-
type: 'array',
|
|
657
|
-
},
|
|
658
|
-
'browser-console': {
|
|
659
|
-
alias: ['bc'],
|
|
660
|
-
describe: 'Open the DevTools Browser Console.',
|
|
661
|
-
demandOption: false,
|
|
662
|
-
type: 'boolean',
|
|
663
|
-
},
|
|
664
|
-
'args': {
|
|
665
|
-
alias: ['arg'],
|
|
666
|
-
describe: 'Additional CLI options passed to the Browser binary',
|
|
667
|
-
demandOption: false,
|
|
668
|
-
type: 'array',
|
|
669
|
-
},
|
|
670
|
-
// Firefox for Android CLI options.
|
|
671
|
-
'adb-bin': {
|
|
672
|
-
describe: 'Specify a custom path to the adb binary',
|
|
673
|
-
demandOption: false,
|
|
674
|
-
type: 'string',
|
|
675
|
-
requiresArg: true,
|
|
676
|
-
},
|
|
677
|
-
'adb-host': {
|
|
678
|
-
describe: 'Connect to adb on the specified host',
|
|
679
|
-
demandOption: false,
|
|
680
|
-
type: 'string',
|
|
681
|
-
requiresArg: true,
|
|
682
|
-
},
|
|
683
|
-
'adb-port': {
|
|
684
|
-
describe: 'Connect to adb on the specified port',
|
|
685
|
-
demandOption: false,
|
|
686
|
-
type: 'string',
|
|
687
|
-
requiresArg: true,
|
|
688
|
-
},
|
|
689
|
-
'adb-device': {
|
|
690
|
-
alias: ['android-device'],
|
|
691
|
-
describe: 'Connect to the specified adb device name',
|
|
692
|
-
demandOption: false,
|
|
693
|
-
type: 'string',
|
|
694
|
-
requiresArg: true,
|
|
695
|
-
},
|
|
696
|
-
'adb-discovery-timeout': {
|
|
697
|
-
describe: 'Number of milliseconds to wait before giving up',
|
|
698
|
-
demandOption: false,
|
|
699
|
-
type: 'number',
|
|
700
|
-
requiresArg: true,
|
|
701
|
-
},
|
|
702
|
-
'adb-remove-old-artifacts': {
|
|
703
|
-
describe: 'Remove old artifacts directories from the adb device',
|
|
704
|
-
demandOption: false,
|
|
705
|
-
type: 'boolean',
|
|
706
|
-
},
|
|
707
|
-
'firefox-apk': {
|
|
708
|
-
describe: (
|
|
709
|
-
'Run a specific Firefox for Android APK. ' +
|
|
710
|
-
'Example: org.mozilla.fennec_aurora'
|
|
711
|
-
),
|
|
712
|
-
demandOption: false,
|
|
713
|
-
type: 'string',
|
|
714
|
-
requiresArg: true,
|
|
715
|
-
},
|
|
716
|
-
'firefox-apk-component': {
|
|
717
|
-
describe:
|
|
718
|
-
'Run a specific Android Component (defaults to <firefox-apk>/.App)',
|
|
719
|
-
demandOption: false,
|
|
720
|
-
type: 'string',
|
|
721
|
-
requiresArg: true,
|
|
722
|
-
},
|
|
723
|
-
})
|
|
724
|
-
.command('lint', 'Validate the extension source', commands.lint, {
|
|
725
|
-
'output': {
|
|
726
|
-
alias: 'o',
|
|
727
|
-
describe: 'The type of output to generate',
|
|
728
|
-
type: 'string',
|
|
729
|
-
default: 'text',
|
|
730
|
-
choices: ['json', 'text'],
|
|
731
|
-
},
|
|
732
|
-
'metadata': {
|
|
733
|
-
describe: 'Output only metadata as JSON',
|
|
734
|
-
type: 'boolean',
|
|
735
|
-
default: false,
|
|
736
|
-
},
|
|
737
|
-
'warnings-as-errors': {
|
|
738
|
-
describe: 'Treat warnings as errors by exiting non-zero for warnings',
|
|
739
|
-
alias: 'w',
|
|
740
|
-
type: 'boolean',
|
|
741
|
-
default: false,
|
|
742
|
-
},
|
|
743
|
-
'pretty': {
|
|
744
|
-
describe: 'Prettify JSON output',
|
|
745
|
-
type: 'boolean',
|
|
746
|
-
default: false,
|
|
747
|
-
},
|
|
748
|
-
'self-hosted': {
|
|
749
|
-
describe:
|
|
750
|
-
'Your extension will be self-hosted. This disables messages ' +
|
|
751
|
-
'related to hosting on addons.mozilla.org.',
|
|
752
|
-
type: 'boolean',
|
|
753
|
-
default: false,
|
|
754
|
-
},
|
|
755
|
-
'boring': {
|
|
756
|
-
describe: 'Disables colorful shell output',
|
|
757
|
-
type: 'boolean',
|
|
758
|
-
default: false,
|
|
759
|
-
},
|
|
760
|
-
})
|
|
761
|
-
.command('docs', 'Open the web-ext documentation in a browser',
|
|
762
|
-
commands.docs, {});
|
|
763
|
-
|
|
764
|
-
return program.execute({getVersion, ...runOptions});
|
|
765
|
-
}
|