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.
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 +191 -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 +123 -179
  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 +657 -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 +52 -54
  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
package/src/cmd/run.js DELETED
@@ -1,266 +0,0 @@
1
- /* @flow */
2
- import { fs } from 'mz';
3
-
4
- import defaultBuildExtension from './build';
5
- import {
6
- showDesktopNotification as defaultDesktopNotifications,
7
- } from '../util/desktop-notifier';
8
- import * as defaultFirefoxApp from '../firefox';
9
- import {
10
- connectWithMaxRetries as defaultFirefoxClient,
11
- } from '../firefox/remote';
12
- import {createLogger} from '../util/logger';
13
- import defaultGetValidatedManifest from '../util/manifest';
14
- import {UsageError} from '../../src/errors';
15
- import {
16
- createExtensionRunner,
17
- defaultReloadStrategy,
18
- MultiExtensionRunner as DefaultMultiExtensionRunner,
19
- } from '../extension-runners';
20
- // Import objects that are only used as Flow types.
21
- import type {FirefoxPreferences} from '../firefox/preferences';
22
-
23
- const log = createLogger(__filename);
24
-
25
-
26
- // Run command types and implementation.
27
-
28
- export type CmdRunParams = {|
29
- artifactsDir: string,
30
- browserConsole: boolean,
31
- pref?: FirefoxPreferences,
32
- firefox: string,
33
- firefoxProfile?: string,
34
- profileCreateIfMissing?: boolean,
35
- ignoreFiles?: Array<string>,
36
- keepProfileChanges: boolean,
37
- noInput?: boolean,
38
- noReload: boolean,
39
- preInstall: boolean,
40
- sourceDir: string,
41
- watchFile?: Array<string>,
42
- watchIgnored?: Array<string>,
43
- startUrl?: Array<string>,
44
- target?: Array<string>,
45
- args?: Array<string>,
46
-
47
- // Android CLI options.
48
- adbBin?: string,
49
- adbHost?: string,
50
- adbPort?: string,
51
- adbDevice?: string,
52
- adbDiscoveryTimeout?: number,
53
- adbRemoveOldArtifacts?: boolean,
54
- firefoxApk?: string,
55
- firefoxApkComponent?: string,
56
-
57
- // Chromium Desktop CLI options.
58
- chromiumBinary?: string,
59
- chromiumProfile?: string,
60
- |};
61
-
62
- export type CmdRunOptions = {|
63
- buildExtension: typeof defaultBuildExtension,
64
- desktopNotifications: typeof defaultDesktopNotifications,
65
- firefoxApp: typeof defaultFirefoxApp,
66
- firefoxClient: typeof defaultFirefoxClient,
67
- reloadStrategy: typeof defaultReloadStrategy,
68
- shouldExitProgram?: boolean,
69
- MultiExtensionRunner?: typeof DefaultMultiExtensionRunner,
70
- getValidatedManifest?: typeof defaultGetValidatedManifest,
71
- |};
72
-
73
- export default async function run(
74
- {
75
- artifactsDir,
76
- browserConsole = false,
77
- pref,
78
- firefox,
79
- firefoxProfile,
80
- profileCreateIfMissing,
81
- keepProfileChanges = false,
82
- ignoreFiles,
83
- noInput = false,
84
- noReload = false,
85
- preInstall = false,
86
- sourceDir,
87
- watchFile,
88
- watchIgnored,
89
- startUrl,
90
- target,
91
- args,
92
- // Android CLI options.
93
- adbBin,
94
- adbHost,
95
- adbPort,
96
- adbDevice,
97
- adbDiscoveryTimeout,
98
- adbRemoveOldArtifacts,
99
- firefoxApk,
100
- firefoxApkComponent,
101
- // Chromium CLI options.
102
- chromiumBinary,
103
- chromiumProfile,
104
- }: CmdRunParams,
105
- {
106
- buildExtension = defaultBuildExtension,
107
- desktopNotifications = defaultDesktopNotifications,
108
- firefoxApp = defaultFirefoxApp,
109
- firefoxClient = defaultFirefoxClient,
110
- reloadStrategy = defaultReloadStrategy,
111
- MultiExtensionRunner = DefaultMultiExtensionRunner,
112
- getValidatedManifest = defaultGetValidatedManifest,
113
- }: CmdRunOptions = {}): Promise<DefaultMultiExtensionRunner> {
114
-
115
- log.info(`Running web extension from ${sourceDir}`);
116
- if (preInstall) {
117
- log.info('Disabled auto-reloading because it\'s not possible with ' +
118
- '--pre-install');
119
- noReload = true;
120
- }
121
-
122
- if (watchFile != null && (!Array.isArray(watchFile) ||
123
- !watchFile.every((el) => typeof el === 'string'))) {
124
- throw new UsageError('Unexpected watchFile type');
125
- }
126
-
127
- // Create an alias for --pref since it has been transformed into an
128
- // object containing one or more preferences.
129
- const customPrefs = pref;
130
- const manifestData = await getValidatedManifest(sourceDir);
131
-
132
- const profileDir = firefoxProfile || chromiumProfile;
133
-
134
- if (profileCreateIfMissing) {
135
- if (!profileDir) {
136
- throw new UsageError(
137
- '--profile-create-if-missing requires ' +
138
- '--firefox-profile or --chromium-profile'
139
- );
140
- }
141
- const isDir = fs.existsSync(profileDir);
142
- if (isDir) {
143
- log.info(`Profile directory ${profileDir} already exists`);
144
- } else {
145
- log.info(`Profile directory not found. Creating directory ${profileDir}`);
146
- await fs.mkdir(profileDir);
147
- }
148
- }
149
-
150
- const runners = [];
151
-
152
- const commonRunnerParams = {
153
- // Common options.
154
- extensions: [{sourceDir, manifestData}],
155
- keepProfileChanges,
156
- startUrl,
157
- args,
158
- desktopNotifications,
159
- };
160
-
161
- if (!target || target.length === 0 || target.includes('firefox-desktop')) {
162
- const firefoxDesktopRunnerParams = {
163
- ...commonRunnerParams,
164
-
165
- // Firefox specific CLI options.
166
- firefoxBinary: firefox,
167
- profilePath: firefoxProfile,
168
- customPrefs,
169
- browserConsole,
170
- preInstall,
171
-
172
- // Firefox runner injected dependencies.
173
- firefoxApp,
174
- firefoxClient,
175
- };
176
-
177
- const firefoxDesktopRunner = await createExtensionRunner({
178
- target: 'firefox-desktop',
179
- params: firefoxDesktopRunnerParams,
180
- });
181
- runners.push(firefoxDesktopRunner);
182
- }
183
-
184
- if (target && target.includes('firefox-android')) {
185
- const firefoxAndroidRunnerParams = {
186
- ...commonRunnerParams,
187
-
188
- // Firefox specific CLI options.
189
- profilePath: firefoxProfile,
190
- customPrefs,
191
- browserConsole,
192
- preInstall,
193
- firefoxApk,
194
- firefoxApkComponent,
195
- adbDevice,
196
- adbHost,
197
- adbPort,
198
- adbBin,
199
- adbDiscoveryTimeout,
200
- adbRemoveOldArtifacts,
201
-
202
- // Injected dependencies.
203
- firefoxApp,
204
- firefoxClient,
205
- desktopNotifications: defaultDesktopNotifications,
206
- buildSourceDir: (extensionSourceDir: string, tmpArtifactsDir: string) => {
207
- return buildExtension({
208
- sourceDir: extensionSourceDir,
209
- ignoreFiles,
210
- asNeeded: false,
211
- // Use a separate temporary directory for building the extension zip file
212
- // that we are going to upload on the android device.
213
- artifactsDir: tmpArtifactsDir,
214
- }, {
215
- // Suppress the message usually logged by web-ext build.
216
- showReadyMessage: false,
217
- });
218
- },
219
- };
220
-
221
- const firefoxAndroidRunner = await createExtensionRunner({
222
- target: 'firefox-android',
223
- params: firefoxAndroidRunnerParams,
224
- });
225
- runners.push(firefoxAndroidRunner);
226
- }
227
-
228
- if (target && target.includes('chromium')) {
229
- const chromiumRunnerParams = {
230
- ...commonRunnerParams,
231
- chromiumBinary,
232
- chromiumProfile,
233
- };
234
-
235
- const chromiumRunner = await createExtensionRunner({
236
- target: 'chromium',
237
- params: chromiumRunnerParams,
238
- });
239
- runners.push(chromiumRunner);
240
- }
241
-
242
- const extensionRunner = new MultiExtensionRunner({
243
- desktopNotifications,
244
- runners,
245
- });
246
-
247
- await extensionRunner.run();
248
-
249
- if (noReload) {
250
- log.info('Automatic extension reloading has been disabled');
251
- } else {
252
- log.info('The extension will reload if any source file changes');
253
-
254
- reloadStrategy({
255
- extensionRunner,
256
- sourceDir,
257
- watchFile,
258
- watchIgnored,
259
- artifactsDir,
260
- ignoreFiles,
261
- noInput,
262
- });
263
- }
264
-
265
- return extensionRunner;
266
- }
package/src/cmd/sign.js DELETED
@@ -1,198 +0,0 @@
1
- /* @flow */
2
- import path from 'path';
3
-
4
- import {fs} from 'mz';
5
- import {signAddon as defaultAddonSigner} from 'sign-addon';
6
-
7
- import defaultBuilder from './build';
8
- import getValidatedManifest, {getManifestId} from '../util/manifest';
9
- import {withTempDir} from '../util/temp-dir';
10
- import {isErrorWithCode, UsageError, WebExtError} from '../errors';
11
- import {prepareArtifactsDir} from '../util/artifacts';
12
- import {createLogger} from '../util/logger';
13
- import type {ExtensionManifest} from '../util/manifest';
14
-
15
-
16
- const log = createLogger(__filename);
17
-
18
- const defaultAsyncFsReadFile: (string) => Promise<Buffer> =
19
- fs.readFile.bind(fs);
20
-
21
- export const extensionIdFile = '.web-extension-id';
22
-
23
- // Sign command types and implementation.
24
-
25
- export type SignParams = {|
26
- apiKey: string,
27
- apiProxy: string,
28
- apiSecret: string,
29
- apiUrlPrefix: string,
30
- artifactsDir: string,
31
- id?: string,
32
- ignoreFiles?: Array<string>,
33
- sourceDir: string,
34
- timeout: number,
35
- verbose?: boolean,
36
- channel?: string,
37
- |};
38
-
39
- export type SignOptions = {
40
- build?: typeof defaultBuilder,
41
- signAddon?: typeof defaultAddonSigner,
42
- preValidatedManifest?: ExtensionManifest,
43
- shouldExitProgram?: boolean,
44
- };
45
-
46
- export type SignResult = {|
47
- success: boolean,
48
- id: string,
49
- downloadedFiles: Array<string>,
50
- |};
51
-
52
- export default function sign(
53
- {
54
- apiKey,
55
- apiProxy,
56
- apiSecret,
57
- apiUrlPrefix,
58
- artifactsDir,
59
- id,
60
- ignoreFiles = [],
61
- sourceDir,
62
- timeout,
63
- verbose,
64
- channel,
65
- }: SignParams,
66
- {
67
- build = defaultBuilder,
68
- preValidatedManifest,
69
- signAddon = defaultAddonSigner,
70
- }: SignOptions = {}
71
- ): Promise<SignResult> {
72
- return withTempDir(
73
- async function(tmpDir) {
74
- await prepareArtifactsDir(artifactsDir);
75
-
76
- let manifestData;
77
-
78
- if (preValidatedManifest) {
79
- manifestData = preValidatedManifest;
80
- } else {
81
- manifestData = await getValidatedManifest(sourceDir);
82
- }
83
-
84
- const [buildResult, idFromSourceDir] = await Promise.all([
85
- build({sourceDir, ignoreFiles, artifactsDir: tmpDir.path()},
86
- {manifestData, showReadyMessage: false}),
87
- getIdFromSourceDir(sourceDir),
88
- ]);
89
-
90
- const manifestId = getManifestId(manifestData);
91
-
92
- if (id && manifestId) {
93
- throw new UsageError(
94
- `Cannot set custom ID ${id} because manifest.json ` +
95
- `declares ID ${manifestId}`);
96
- }
97
- if (id) {
98
- log.debug(`Using custom ID declared as --id=${id}`);
99
- }
100
-
101
- if (manifestId) {
102
- id = manifestId;
103
- }
104
-
105
- if (!id && idFromSourceDir) {
106
- log.info(
107
- `Using previously auto-generated extension ID: ${idFromSourceDir}`);
108
- id = idFromSourceDir;
109
- }
110
-
111
- if (!id) {
112
- log.warn('No extension ID specified (it will be auto-generated)');
113
- }
114
-
115
- const signingResult = await signAddon({
116
- apiKey,
117
- apiSecret,
118
- apiUrlPrefix,
119
- apiProxy,
120
- timeout,
121
- verbose,
122
- id,
123
- xpiPath: buildResult.extensionPath,
124
- version: manifestData.version,
125
- downloadDir: artifactsDir,
126
- channel,
127
- });
128
-
129
- if (signingResult.id) {
130
- await saveIdToSourceDir(sourceDir, signingResult.id);
131
- }
132
-
133
- // All information about the downloaded files would have
134
- // already been logged by signAddon().
135
- if (signingResult.success) {
136
- log.info(`Extension ID: ${signingResult.id}`);
137
- log.info('SUCCESS');
138
- } else {
139
- log.info('FAIL');
140
- throw new WebExtError(
141
- 'The extension could not be signed');
142
- }
143
-
144
- return signingResult;
145
- }
146
- );
147
- }
148
-
149
-
150
- export async function getIdFromSourceDir(
151
- sourceDir: string,
152
- asyncFsReadFile: typeof defaultAsyncFsReadFile = defaultAsyncFsReadFile,
153
- ): Promise<string | void> {
154
- const filePath = path.join(sourceDir, extensionIdFile);
155
-
156
- let content;
157
-
158
- try {
159
- content = await asyncFsReadFile(filePath);
160
- } catch (error) {
161
- if (isErrorWithCode('ENOENT', error)) {
162
- log.debug(`No ID file found at: ${filePath}`);
163
- return;
164
- }
165
- throw error;
166
- }
167
-
168
- let lines = content.toString().split('\n');
169
- lines = lines.filter((line) => {
170
- line = line.trim();
171
- if (line && !line.startsWith('#')) {
172
- return line;
173
- }
174
- });
175
-
176
- const id = lines[0];
177
- log.debug(`Found extension ID ${id} in ${filePath}`);
178
-
179
- if (!id) {
180
- throw new UsageError(`No ID found in extension ID file ${filePath}`);
181
- }
182
-
183
- return id;
184
- }
185
-
186
-
187
- export async function saveIdToSourceDir(
188
- sourceDir: string, id: string
189
- ): Promise<void> {
190
- const filePath = path.join(sourceDir, extensionIdFile);
191
- await fs.writeFile(filePath, [
192
- '# This file was created by https://github.com/mozilla/web-ext',
193
- '# Your auto-generated extension ID for addons.mozilla.org is:',
194
- id.toString(),
195
- ].join('\n'));
196
-
197
- log.debug(`Saved auto-generated ID ${id} to ${filePath}`);
198
- }
package/src/config.js DELETED
@@ -1,187 +0,0 @@
1
- /* @flow */
2
- import os from 'os';
3
- import path from 'path';
4
-
5
- import importFresh from 'import-fresh';
6
- import camelCase from 'camelcase';
7
- import decamelize from 'decamelize';
8
-
9
- import fileExists from './util/file-exists';
10
- import {createLogger} from './util/logger';
11
- import {UsageError, WebExtError} from './errors';
12
-
13
- const log = createLogger(__filename);
14
-
15
- type ApplyConfigToArgvParams = {|
16
- // This is the argv object which will get updated by each
17
- // config applied.
18
- argv: Object,
19
- // This is the argv that only has CLI values applied to it.
20
- argvFromCLI: Object,
21
- configObject: Object,
22
- options: Object,
23
- configFileName: string,
24
- |};
25
-
26
- export function applyConfigToArgv({
27
- argv,
28
- argvFromCLI,
29
- configObject,
30
- options,
31
- configFileName,
32
- }: ApplyConfigToArgvParams): Object {
33
- let newArgv = {...argv};
34
-
35
- for (const option of Object.keys(configObject)) {
36
- if (camelCase(option) !== option) {
37
- throw new UsageError(
38
- `The config option "${option}" must be ` +
39
- `specified in camel case: "${camelCase(option)}"`);
40
- }
41
-
42
- // A config option cannot be a sub-command config
43
- // object if it is an array.
44
- if (!Array.isArray(configObject[option]) &&
45
- typeof options[option] === 'object' &&
46
- typeof configObject[option] === 'object') {
47
- // Descend into the nested configuration for a sub-command.
48
- newArgv = applyConfigToArgv({
49
- argv: newArgv,
50
- argvFromCLI,
51
- configObject: configObject[option],
52
- options: options[option],
53
- configFileName});
54
- continue;
55
- }
56
-
57
- const decamelizedOptName = decamelize(option, {separator: '-'});
58
-
59
- if (typeof options[decamelizedOptName] !== 'object') {
60
- throw new UsageError(`The config file at ${configFileName} specified ` +
61
- `an unknown option: "${option}"`);
62
- }
63
- if (options[decamelizedOptName].type === undefined) {
64
- // This means yargs option type wasn't not defined correctly
65
- throw new WebExtError(
66
- `Option: ${option} was defined without a type.`);
67
- }
68
-
69
- const expectedType = options[decamelizedOptName].type ===
70
- 'count' ? 'number' : options[decamelizedOptName].type;
71
-
72
- const optionType = (
73
- Array.isArray(configObject[option]) ?
74
- 'array' : typeof configObject[option]
75
- );
76
-
77
- if (optionType !== expectedType) {
78
- throw new UsageError(`The config file at ${configFileName} specified ` +
79
- `the type of "${option}" incorrectly as "${optionType}"` +
80
- ` (expected type "${expectedType}")`);
81
- }
82
-
83
- let defaultValue;
84
- if (options[decamelizedOptName]) {
85
- if (options[decamelizedOptName].default !== undefined) {
86
- defaultValue = options[decamelizedOptName].default;
87
- } else if (expectedType === 'boolean') {
88
- defaultValue = false;
89
- }
90
- }
91
-
92
- // This is our best effort (without patching yargs) to detect
93
- // if a value was set on the CLI instead of in the config.
94
- // It looks for a default value and if the argv value is
95
- // different, it assumes that the value was configured on the CLI.
96
-
97
- const wasValueSetOnCLI =
98
- typeof argvFromCLI[option] !== 'undefined' &&
99
- argvFromCLI[option] !== defaultValue;
100
- if (wasValueSetOnCLI) {
101
- log.debug(
102
- `Favoring CLI: ${option}=${argvFromCLI[option]} over ` +
103
- `configuration: ${option}=${configObject[option]}`);
104
- newArgv[option] = argvFromCLI[option];
105
- continue;
106
- }
107
-
108
- newArgv[option] = configObject[option];
109
-
110
- const coerce = options[decamelizedOptName].coerce;
111
- if (coerce) {
112
- log.debug(
113
- `Calling coerce() on configured value for ${option}`);
114
- newArgv[option] = coerce(newArgv[option]);
115
- }
116
-
117
- newArgv[decamelizedOptName] = newArgv[option];
118
- }
119
- return newArgv;
120
- }
121
-
122
- export function loadJSConfigFile(filePath: string): Object {
123
- const resolvedFilePath = path.resolve(filePath);
124
- log.debug(
125
- `Loading JS config file: "${filePath}" ` +
126
- `(resolved to "${resolvedFilePath}")`);
127
- let configObject;
128
- try {
129
- configObject = importFresh(resolvedFilePath);
130
- } catch (error) {
131
- log.debug('Handling error:', error);
132
- throw new UsageError(
133
- `Cannot read config file: ${resolvedFilePath}\n` +
134
- `Error: ${error.message}`);
135
- }
136
- if (filePath.endsWith('package.json')) {
137
- log.debug('Looking for webExt key inside package.json file');
138
- configObject = configObject.webExt || {};
139
- }
140
- if (Object.keys(configObject).length === 0) {
141
- log.debug(`Config file ${resolvedFilePath} did not define any options. ` +
142
- 'Did you set module.exports = {...}?');
143
- }
144
- return configObject;
145
- }
146
-
147
- type DiscoverConfigFilesParams = {|
148
- getHomeDir: () => string,
149
- |};
150
-
151
- export async function discoverConfigFiles(
152
- {getHomeDir = os.homedir}: DiscoverConfigFilesParams = {}
153
- ): Promise<Array<string>> {
154
- const magicConfigName = 'web-ext-config.js';
155
-
156
- // Config files will be loaded in this order.
157
- const possibleConfigs = [
158
- // Look for a magic hidden config (preceded by dot) in home dir.
159
- path.join(getHomeDir(), `.${magicConfigName}`),
160
- // Look for webExt key inside package.json file
161
- path.join(process.cwd(), 'package.json'),
162
- // Look for a magic config in the current working directory.
163
- path.join(process.cwd(), magicConfigName),
164
- ];
165
-
166
- const configs = await Promise.all(possibleConfigs.map(
167
- async (fileName) => {
168
- const resolvedFileName = path.resolve(fileName);
169
- if (await fileExists(resolvedFileName)) {
170
- return resolvedFileName;
171
- } else {
172
- log.debug(
173
- `Discovered config "${resolvedFileName}" does not ` +
174
- 'exist or is not readable');
175
- return undefined;
176
- }
177
- }
178
- ));
179
-
180
- const existingConfigs = [];
181
- configs.forEach((f) => {
182
- if (typeof f === 'string') {
183
- existingConfigs.push(f);
184
- }
185
- });
186
- return existingConfigs;
187
- }
@@ -1,40 +0,0 @@
1
- /* @flow */
2
-
3
- import {
4
- showDesktopNotification as defaultDesktopNotifications,
5
- } from '../util/desktop-notifier';
6
- import type {ExtensionManifest} from '../util/manifest';
7
-
8
- export type Extension = {|
9
- sourceDir: string,
10
- manifestData: ExtensionManifest,
11
- |};
12
-
13
- export type ExtensionRunnerParams = {|
14
- // Common cli params.
15
- extensions: Array<Extension>,
16
- profilePath?: string,
17
- keepProfileChanges: boolean,
18
- startUrl: ?string | ?Array<string>,
19
- args?: Array<string>,
20
-
21
- // Common injected dependencies.
22
- desktopNotifications: typeof defaultDesktopNotifications,
23
- |};
24
-
25
- export type ExtensionRunnerReloadResult = {|
26
- runnerName: string,
27
- reloadError?: Error,
28
- sourceDir?: string,
29
- |};
30
-
31
- export interface IExtensionRunner {
32
- getName(): string,
33
- run(): Promise<void>,
34
- reloadAllExtensions(): Promise<Array<ExtensionRunnerReloadResult>>,
35
- reloadExtensionBySourceDir(
36
- extensionSourceDir: string
37
- ): Promise<Array<ExtensionRunnerReloadResult>>,
38
- registerCleanup(fn: Function): void,
39
- exit(): Promise<void>,
40
- }