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/README.md
CHANGED
|
@@ -74,7 +74,7 @@ version on the command line with this:
|
|
|
74
74
|
## Installation from source
|
|
75
75
|
|
|
76
76
|
You'll need:
|
|
77
|
-
* [Node.js](https://nodejs.org/en/),
|
|
77
|
+
* [Node.js](https://nodejs.org/en/), 14.0.0 or higher
|
|
78
78
|
* [npm](https://www.npmjs.com/), 6.9.0 or higher is recommended
|
|
79
79
|
|
|
80
80
|
Optionally, you may like:
|
|
@@ -89,7 +89,7 @@ Change into the source and install all dependencies:
|
|
|
89
89
|
|
|
90
90
|
git clone https://github.com/mozilla/web-ext.git
|
|
91
91
|
cd web-ext
|
|
92
|
-
npm
|
|
92
|
+
npm ci
|
|
93
93
|
|
|
94
94
|
Build the command:
|
|
95
95
|
|
|
@@ -112,13 +112,17 @@ need to relink it.
|
|
|
112
112
|
|
|
113
113
|
## Using web-ext in NodeJS code
|
|
114
114
|
|
|
115
|
-
|
|
115
|
+
**Note:** There is limited support for this API.
|
|
116
|
+
|
|
117
|
+
Aside from [using web-ext on the command line][web-ext-user-docs], you may wish to execute `web-ext` in NodeJS code.
|
|
118
|
+
|
|
119
|
+
As of version `7.0.0`, the `web-ext` npm package exports NodeJS native ES modules only. If you are using CommonJS, you will have to use [dynamic imports][dynamic-imports].
|
|
120
|
+
|
|
121
|
+
### Examples
|
|
116
122
|
|
|
117
123
|
You are able to execute command functions without any argument validation. If you want to execute `web-ext run` you would do so like this:
|
|
118
124
|
|
|
119
125
|
```js
|
|
120
|
-
// const webExt = require('web-ext');
|
|
121
|
-
// or...
|
|
122
126
|
import webExt from 'web-ext';
|
|
123
127
|
|
|
124
128
|
webExt.cmd.run({
|
|
@@ -145,13 +149,15 @@ webExt.cmd.run({
|
|
|
145
149
|
If you would like to run an extension on Firefox for Android:
|
|
146
150
|
|
|
147
151
|
```js
|
|
152
|
+
import adbUtils from "web-ext/util/adb";
|
|
153
|
+
|
|
148
154
|
// Path to adb binary (optional parameter, auto-detected if missing)
|
|
149
155
|
const adbBin = "/path/to/adb";
|
|
150
156
|
// Get an array of device ids (Array<string>)
|
|
151
|
-
const deviceIds = await
|
|
157
|
+
const deviceIds = await adbUtils.listADBDevices(adbBin);
|
|
152
158
|
const adbDevice = ...
|
|
153
159
|
// Get an array of Firefox APKs (Array<string>)
|
|
154
|
-
const firefoxAPKs = await
|
|
160
|
+
const firefoxAPKs = await adbUtils.listADBFirefoxAPKs(
|
|
155
161
|
deviceId, adbBin
|
|
156
162
|
);
|
|
157
163
|
const firefoxApk = ...
|
|
@@ -167,7 +173,9 @@ webExt.cmd.run({
|
|
|
167
173
|
If you would like to control logging, you can access the logger object. Here is an example of turning on verbose logging:
|
|
168
174
|
|
|
169
175
|
```js
|
|
170
|
-
|
|
176
|
+
import webExtLogger from "web-ext/util/logger";
|
|
177
|
+
|
|
178
|
+
webExtLogger.consoleStream.makeVerbose();
|
|
171
179
|
webExt.cmd.run({sourceDir: './src'}, {shouldExitProgram: false});
|
|
172
180
|
```
|
|
173
181
|
|
|
@@ -226,3 +234,4 @@ Here is a partial list of examples:
|
|
|
226
234
|
extensions.
|
|
227
235
|
|
|
228
236
|
[web-ext-user-docs]: https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Getting_started_with_web-ext
|
|
237
|
+
[dynamic-imports]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#dynamic_imports
|
package/bin/web-ext.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
5
|
+
|
|
6
|
+
import webExt from '../lib/main.js';
|
|
7
|
+
|
|
8
|
+
const absolutePackageDir = path.join(
|
|
9
|
+
path.dirname(fileURLToPath(import.meta.url)),
|
|
10
|
+
'..'
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
await webExt.main(absolutePackageDir);
|
package/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// This file is loaded when developers import 'web-ext' in their own code.
|
|
2
|
+
|
|
3
|
+
// NOTE: disabled eslint rules:
|
|
4
|
+
// - import/no-unresolved: in the CI jobs, the `lib/main.js` file has likely not been built yet. It's fine to
|
|
5
|
+
// disable this rule because we have automated tests (which would catch an unresolved import issue
|
|
6
|
+
// here).
|
|
7
|
+
//
|
|
8
|
+
// eslint-disable-next-line import/no-unresolved
|
|
9
|
+
import webext from './lib/main.js';
|
|
10
|
+
|
|
11
|
+
export default webext;
|
|
12
|
+
export const {cmd, main} = webext;
|
package/lib/cmd/build.js
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { createWriteStream } from 'fs';
|
|
3
|
+
import { fs } from 'mz';
|
|
4
|
+
import parseJSON from 'parse-json';
|
|
5
|
+
import stripBom from 'strip-bom';
|
|
6
|
+
import defaultFromEvent from 'promise-toolbox/fromEvent';
|
|
7
|
+
import zipDir from 'zip-dir';
|
|
8
|
+
import defaultSourceWatcher from '../watcher.js';
|
|
9
|
+
import getValidatedManifest, { getManifestId } from '../util/manifest.js';
|
|
10
|
+
import { prepareArtifactsDir } from '../util/artifacts.js';
|
|
11
|
+
import { createLogger } from '../util/logger.js';
|
|
12
|
+
import { UsageError, isErrorWithCode } from '../errors.js';
|
|
13
|
+
import { createFileFilter as defaultFileFilterCreator, FileFilter } from '../util/file-filter.js'; // Import flow types.
|
|
14
|
+
|
|
15
|
+
const log = createLogger(import.meta.url);
|
|
16
|
+
const DEFAULT_FILENAME_TEMPLATE = '{name}-{version}.zip';
|
|
17
|
+
export function safeFileName(name) {
|
|
18
|
+
return name.toLowerCase().replace(/[^a-z0-9.-]+/g, '_');
|
|
19
|
+
} // defaultPackageCreator types and implementation.
|
|
20
|
+
|
|
21
|
+
export async function getDefaultLocalizedName({
|
|
22
|
+
messageFile,
|
|
23
|
+
manifestData
|
|
24
|
+
}) {
|
|
25
|
+
let messageData;
|
|
26
|
+
let messageContents;
|
|
27
|
+
let extensionName = manifestData.name;
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
messageContents = await fs.readFile(messageFile, {
|
|
31
|
+
encoding: 'utf-8'
|
|
32
|
+
});
|
|
33
|
+
} catch (error) {
|
|
34
|
+
throw new UsageError(`Error reading messages.json file at ${messageFile}: ${error}`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
messageContents = stripBom(messageContents);
|
|
38
|
+
const {
|
|
39
|
+
default: stripJsonComments
|
|
40
|
+
} = await import('strip-json-comments');
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
messageData = parseJSON(stripJsonComments(messageContents));
|
|
44
|
+
} catch (error) {
|
|
45
|
+
throw new UsageError(`Error parsing messages.json file at ${messageFile}: ${error}`);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
extensionName = manifestData.name.replace(/__MSG_([A-Za-z0-9@_]+?)__/g, (match, messageName) => {
|
|
49
|
+
if (!(messageData[messageName] && messageData[messageName].message)) {
|
|
50
|
+
const error = new UsageError(`The locale file ${messageFile} ` + `is missing key: ${messageName}`);
|
|
51
|
+
throw error;
|
|
52
|
+
} else {
|
|
53
|
+
return messageData[messageName].message;
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
return Promise.resolve(extensionName);
|
|
57
|
+
} // https://stackoverflow.com/a/22129960
|
|
58
|
+
|
|
59
|
+
export function getStringPropertyValue(prop, obj) {
|
|
60
|
+
const properties = prop.split('.');
|
|
61
|
+
const value = properties.reduce((prev, curr) => prev && prev[curr], obj);
|
|
62
|
+
|
|
63
|
+
if (!['string', 'number'].includes(typeof value)) {
|
|
64
|
+
throw new UsageError(`Manifest key "${prop}" is missing or has an invalid type: ${value}`);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const stringValue = `${value}`;
|
|
68
|
+
|
|
69
|
+
if (!stringValue.length) {
|
|
70
|
+
throw new UsageError(`Manifest key "${prop}" value is an empty string`);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return stringValue;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function getPackageNameFromTemplate(filenameTemplate, manifestData) {
|
|
77
|
+
const packageName = filenameTemplate.replace(/{([A-Za-z0-9._]+?)}/g, (match, manifestProperty) => {
|
|
78
|
+
return safeFileName(getStringPropertyValue(manifestProperty, manifestData));
|
|
79
|
+
}); // Validate the resulting packageName string, after interpolating the manifest property
|
|
80
|
+
// specified in the template string.
|
|
81
|
+
|
|
82
|
+
const parsed = path.parse(packageName);
|
|
83
|
+
|
|
84
|
+
if (parsed.dir) {
|
|
85
|
+
throw new UsageError(`Invalid filename template "${filenameTemplate}". ` + `Filename "${packageName}" should not contain a path`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (!['.zip', '.xpi'].includes(parsed.ext)) {
|
|
89
|
+
throw new UsageError(`Invalid filename template "${filenameTemplate}". ` + `Filename "${packageName}" should have a zip or xpi extension`);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return packageName;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export async function defaultPackageCreator({
|
|
96
|
+
manifestData,
|
|
97
|
+
sourceDir,
|
|
98
|
+
fileFilter,
|
|
99
|
+
artifactsDir,
|
|
100
|
+
overwriteDest,
|
|
101
|
+
showReadyMessage,
|
|
102
|
+
filename = DEFAULT_FILENAME_TEMPLATE
|
|
103
|
+
}, {
|
|
104
|
+
fromEvent = defaultFromEvent
|
|
105
|
+
} = {}) {
|
|
106
|
+
let id;
|
|
107
|
+
|
|
108
|
+
if (manifestData) {
|
|
109
|
+
id = getManifestId(manifestData);
|
|
110
|
+
log.debug(`Using manifest id=${id || '[not specified]'}`);
|
|
111
|
+
} else {
|
|
112
|
+
manifestData = await getValidatedManifest(sourceDir);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const buffer = await zipDir(sourceDir, {
|
|
116
|
+
filter: (...args) => fileFilter.wantFile(...args)
|
|
117
|
+
});
|
|
118
|
+
let filenameTemplate = filename;
|
|
119
|
+
let {
|
|
120
|
+
default_locale
|
|
121
|
+
} = manifestData;
|
|
122
|
+
|
|
123
|
+
if (default_locale) {
|
|
124
|
+
default_locale = default_locale.replace(/-/g, '_');
|
|
125
|
+
const messageFile = path.join(sourceDir, '_locales', default_locale, 'messages.json');
|
|
126
|
+
log.debug('Manifest declared default_locale, localizing extension name');
|
|
127
|
+
const extensionName = await getDefaultLocalizedName({
|
|
128
|
+
messageFile,
|
|
129
|
+
manifestData
|
|
130
|
+
}); // allow for a localized `{name}`, without mutating `manifestData`
|
|
131
|
+
|
|
132
|
+
filenameTemplate = filenameTemplate.replace(/{name}/g, extensionName);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const packageName = safeFileName(getPackageNameFromTemplate(filenameTemplate, manifestData));
|
|
136
|
+
const extensionPath = path.join(artifactsDir, packageName); // Added 'wx' flags to avoid overwriting of existing package.
|
|
137
|
+
|
|
138
|
+
const stream = createWriteStream(extensionPath, {
|
|
139
|
+
flags: 'wx'
|
|
140
|
+
});
|
|
141
|
+
stream.write(buffer, () => {
|
|
142
|
+
stream.end();
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
try {
|
|
146
|
+
await fromEvent(stream, 'close');
|
|
147
|
+
} catch (error) {
|
|
148
|
+
if (!isErrorWithCode('EEXIST', error)) {
|
|
149
|
+
throw error;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (!overwriteDest) {
|
|
153
|
+
throw new UsageError(`Extension exists at the destination path: ${extensionPath}\n` + 'Use --overwrite-dest to enable overwriting.');
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
log.info(`Destination exists, overwriting: ${extensionPath}`);
|
|
157
|
+
const overwriteStream = createWriteStream(extensionPath);
|
|
158
|
+
overwriteStream.write(buffer, () => {
|
|
159
|
+
overwriteStream.end();
|
|
160
|
+
});
|
|
161
|
+
await fromEvent(overwriteStream, 'close');
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (showReadyMessage) {
|
|
165
|
+
log.info(`Your web extension is ready: ${extensionPath}`);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return {
|
|
169
|
+
extensionPath
|
|
170
|
+
};
|
|
171
|
+
} // Build command types and implementation.
|
|
172
|
+
|
|
173
|
+
export default async function build({
|
|
174
|
+
sourceDir,
|
|
175
|
+
artifactsDir,
|
|
176
|
+
asNeeded = false,
|
|
177
|
+
overwriteDest = false,
|
|
178
|
+
ignoreFiles = [],
|
|
179
|
+
filename = DEFAULT_FILENAME_TEMPLATE
|
|
180
|
+
}, {
|
|
181
|
+
manifestData,
|
|
182
|
+
createFileFilter = defaultFileFilterCreator,
|
|
183
|
+
fileFilter = createFileFilter({
|
|
184
|
+
sourceDir,
|
|
185
|
+
artifactsDir,
|
|
186
|
+
ignoreFiles
|
|
187
|
+
}),
|
|
188
|
+
onSourceChange = defaultSourceWatcher,
|
|
189
|
+
packageCreator = defaultPackageCreator,
|
|
190
|
+
showReadyMessage = true
|
|
191
|
+
} = {}) {
|
|
192
|
+
const rebuildAsNeeded = asNeeded; // alias for `build --as-needed`
|
|
193
|
+
|
|
194
|
+
log.info(`Building web extension from ${sourceDir}`);
|
|
195
|
+
|
|
196
|
+
const createPackage = () => packageCreator({
|
|
197
|
+
manifestData,
|
|
198
|
+
sourceDir,
|
|
199
|
+
fileFilter,
|
|
200
|
+
artifactsDir,
|
|
201
|
+
overwriteDest,
|
|
202
|
+
showReadyMessage,
|
|
203
|
+
filename
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
await prepareArtifactsDir(artifactsDir);
|
|
207
|
+
const result = await createPackage();
|
|
208
|
+
|
|
209
|
+
if (rebuildAsNeeded) {
|
|
210
|
+
log.info('Rebuilding when files change...');
|
|
211
|
+
onSourceChange({
|
|
212
|
+
sourceDir,
|
|
213
|
+
artifactsDir,
|
|
214
|
+
onChange: () => {
|
|
215
|
+
return createPackage().catch(error => {
|
|
216
|
+
log.error(error.stack);
|
|
217
|
+
throw error;
|
|
218
|
+
});
|
|
219
|
+
},
|
|
220
|
+
shouldWatchFile: (...args) => fileFilter.wantFile(...args)
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return result;
|
|
225
|
+
}
|
|
226
|
+
//# sourceMappingURL=build.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.js","names":["path","createWriteStream","fs","parseJSON","stripBom","defaultFromEvent","zipDir","defaultSourceWatcher","getValidatedManifest","getManifestId","prepareArtifactsDir","createLogger","UsageError","isErrorWithCode","createFileFilter","defaultFileFilterCreator","FileFilter","log","import","meta","url","DEFAULT_FILENAME_TEMPLATE","safeFileName","name","toLowerCase","replace","getDefaultLocalizedName","messageFile","manifestData","messageData","messageContents","extensionName","readFile","encoding","error","default","stripJsonComments","match","messageName","message","Promise","resolve","getStringPropertyValue","prop","obj","properties","split","value","reduce","prev","curr","includes","stringValue","length","getPackageNameFromTemplate","filenameTemplate","packageName","manifestProperty","parsed","parse","dir","ext","defaultPackageCreator","sourceDir","fileFilter","artifactsDir","overwriteDest","showReadyMessage","filename","fromEvent","id","debug","buffer","filter","args","wantFile","default_locale","join","extensionPath","stream","flags","write","end","info","overwriteStream","build","asNeeded","ignoreFiles","onSourceChange","packageCreator","rebuildAsNeeded","createPackage","result","onChange","catch","stack","shouldWatchFile"],"sources":["../../src/cmd/build.js"],"sourcesContent":["/* @flow */\nimport path from 'path';\nimport {createWriteStream} from 'fs';\n\nimport {fs} from 'mz';\nimport parseJSON from 'parse-json';\nimport stripBom from 'strip-bom';\nimport defaultFromEvent from 'promise-toolbox/fromEvent';\nimport zipDir from 'zip-dir';\n\nimport defaultSourceWatcher from '../watcher.js';\nimport getValidatedManifest, {getManifestId} from '../util/manifest.js';\nimport {prepareArtifactsDir} from '../util/artifacts.js';\nimport {createLogger} from '../util/logger.js';\nimport {UsageError, isErrorWithCode} from '../errors.js';\nimport {\n createFileFilter as defaultFileFilterCreator,\n FileFilter,\n} from '../util/file-filter.js';\n// Import flow types.\nimport type {OnSourceChangeFn} from '../watcher.js';\nimport type {ExtensionManifest} from '../util/manifest.js';\nimport type {FileFilterCreatorFn} from '../util/file-filter.js';\n\nconst log = createLogger(import.meta.url);\nconst DEFAULT_FILENAME_TEMPLATE = '{name}-{version}.zip';\n\nexport function safeFileName(name: string): string {\n return name.toLowerCase().replace(/[^a-z0-9.-]+/g, '_');\n}\n\n\n// defaultPackageCreator types and implementation.\n\nexport type ExtensionBuildResult = {|\n extensionPath: string,\n|};\n\nexport type PackageCreatorParams = {|\n manifestData?: ExtensionManifest,\n sourceDir: string,\n fileFilter: FileFilter,\n artifactsDir: string,\n overwriteDest: boolean,\n showReadyMessage: boolean,\n filename?: string,\n|};\n\nexport type LocalizedNameParams = {|\n messageFile: string,\n manifestData: ExtensionManifest,\n|}\n\nexport type PackageCreatorOptions = {\n fromEvent: typeof defaultFromEvent,\n};\n\n// This defines the _locales/messages.json type. See:\n// https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Internationalization#Providing_localized_strings_in__locales\ntype LocalizedMessageData = {|\n [messageName: string]: {|\n description: string,\n message: string,\n |},\n|}\n\nexport async function getDefaultLocalizedName(\n {messageFile, manifestData}: LocalizedNameParams\n): Promise<string> {\n\n let messageData: LocalizedMessageData;\n let messageContents: string | Buffer;\n let extensionName: string = manifestData.name;\n\n try {\n messageContents = await fs.readFile(messageFile, {encoding: 'utf-8'});\n } catch (error) {\n throw new UsageError(\n `Error reading messages.json file at ${messageFile}: ${error}`);\n }\n\n messageContents = stripBom(messageContents);\n\n const {default: stripJsonComments } = await import('strip-json-comments');\n try {\n messageData = parseJSON(stripJsonComments(messageContents));\n } catch (error) {\n throw new UsageError(\n `Error parsing messages.json file at ${messageFile}: ${error}`);\n }\n\n extensionName = manifestData.name.replace(\n /__MSG_([A-Za-z0-9@_]+?)__/g,\n (match, messageName) => {\n if (!(messageData[messageName]\n && messageData[messageName].message)) {\n const error = new UsageError(\n `The locale file ${messageFile} ` +\n `is missing key: ${messageName}`);\n throw error;\n } else {\n return messageData[messageName].message;\n }\n });\n return Promise.resolve(extensionName);\n}\n\n// https://stackoverflow.com/a/22129960\nexport function getStringPropertyValue(\n prop: string,\n obj: Object,\n): string {\n const properties = prop.split('.');\n const value = properties.reduce((prev, curr) => prev && prev[curr], obj);\n if (!['string', 'number'].includes(typeof value)) {\n throw new UsageError(\n `Manifest key \"${prop}\" is missing or has an invalid type: ${value}`\n );\n }\n const stringValue = `${value}`;\n if (!stringValue.length) {\n throw new UsageError(`Manifest key \"${prop}\" value is an empty string`);\n }\n return stringValue;\n}\n\nfunction getPackageNameFromTemplate(\n filenameTemplate: string,\n manifestData: ExtensionManifest\n): string {\n const packageName = filenameTemplate.replace(\n /{([A-Za-z0-9._]+?)}/g,\n (match, manifestProperty) => {\n return safeFileName(\n getStringPropertyValue(manifestProperty, manifestData));\n }\n );\n\n // Validate the resulting packageName string, after interpolating the manifest property\n // specified in the template string.\n const parsed = path.parse(packageName);\n if (parsed.dir) {\n throw new UsageError(\n `Invalid filename template \"${filenameTemplate}\". ` +\n `Filename \"${packageName}\" should not contain a path`\n );\n }\n if (!['.zip', '.xpi'].includes(parsed.ext)) {\n throw new UsageError(\n `Invalid filename template \"${filenameTemplate}\". ` +\n `Filename \"${packageName}\" should have a zip or xpi extension`\n );\n }\n\n return packageName;\n}\n\nexport type PackageCreatorFn =\n (params: PackageCreatorParams) => Promise<ExtensionBuildResult>;\n\nexport async function defaultPackageCreator(\n {\n manifestData,\n sourceDir,\n fileFilter,\n artifactsDir,\n overwriteDest,\n showReadyMessage,\n filename = DEFAULT_FILENAME_TEMPLATE,\n }: PackageCreatorParams,\n {\n fromEvent = defaultFromEvent,\n }: PackageCreatorOptions = {}\n): Promise<ExtensionBuildResult> {\n let id;\n if (manifestData) {\n id = getManifestId(manifestData);\n log.debug(`Using manifest id=${id || '[not specified]'}`);\n } else {\n manifestData = await getValidatedManifest(sourceDir);\n }\n\n const buffer = await zipDir(sourceDir, {\n filter: (...args) => fileFilter.wantFile(...args),\n });\n\n let filenameTemplate = filename;\n\n let {default_locale} = manifestData;\n if (default_locale) {\n default_locale = default_locale.replace(/-/g, '_');\n const messageFile = path.join(\n sourceDir, '_locales',\n default_locale, 'messages.json'\n );\n log.debug('Manifest declared default_locale, localizing extension name');\n const extensionName = await getDefaultLocalizedName({\n messageFile, manifestData,\n });\n // allow for a localized `{name}`, without mutating `manifestData`\n filenameTemplate = filenameTemplate.replace(/{name}/g, extensionName);\n }\n\n const packageName = safeFileName(\n getPackageNameFromTemplate(filenameTemplate, manifestData)\n );\n const extensionPath = path.join(artifactsDir, packageName);\n\n // Added 'wx' flags to avoid overwriting of existing package.\n const stream = createWriteStream(extensionPath, {flags: 'wx'});\n\n stream.write(buffer, () => {\n stream.end();\n });\n\n try {\n await fromEvent(stream, 'close');\n } catch (error) {\n if (!isErrorWithCode('EEXIST', error)) {\n throw error;\n }\n if (!overwriteDest) {\n throw new UsageError(\n `Extension exists at the destination path: ${extensionPath}\\n` +\n 'Use --overwrite-dest to enable overwriting.');\n }\n log.info(`Destination exists, overwriting: ${extensionPath}`);\n const overwriteStream = createWriteStream(extensionPath);\n overwriteStream.write(buffer, () => {\n overwriteStream.end();\n });\n await fromEvent(overwriteStream, 'close');\n }\n\n if (showReadyMessage) {\n log.info(`Your web extension is ready: ${extensionPath}`);\n }\n return {extensionPath};\n}\n\n\n// Build command types and implementation.\n\nexport type BuildCmdParams = {|\n sourceDir: string,\n artifactsDir: string,\n asNeeded?: boolean,\n overwriteDest?: boolean,\n ignoreFiles?: Array<string>,\n filename?: string,\n|};\n\nexport type BuildCmdOptions = {\n manifestData?: ExtensionManifest,\n fileFilter?: FileFilter,\n onSourceChange?: OnSourceChangeFn,\n packageCreator?: PackageCreatorFn,\n showReadyMessage?: boolean,\n createFileFilter?: FileFilterCreatorFn,\n shouldExitProgram?: boolean,\n};\n\nexport default async function build(\n {\n sourceDir,\n artifactsDir,\n asNeeded = false,\n overwriteDest = false,\n ignoreFiles = [],\n filename = DEFAULT_FILENAME_TEMPLATE,\n }: BuildCmdParams,\n {\n manifestData,\n createFileFilter = defaultFileFilterCreator,\n fileFilter = createFileFilter({\n sourceDir,\n artifactsDir,\n ignoreFiles,\n }),\n onSourceChange = defaultSourceWatcher,\n packageCreator = defaultPackageCreator,\n showReadyMessage = true,\n }: BuildCmdOptions = {}\n): Promise<ExtensionBuildResult> {\n\n const rebuildAsNeeded = asNeeded; // alias for `build --as-needed`\n log.info(`Building web extension from ${sourceDir}`);\n\n const createPackage = () => packageCreator({\n manifestData,\n sourceDir,\n fileFilter,\n artifactsDir,\n overwriteDest,\n showReadyMessage,\n filename,\n });\n\n await prepareArtifactsDir(artifactsDir);\n const result = await createPackage();\n\n if (rebuildAsNeeded) {\n log.info('Rebuilding when files change...');\n onSourceChange({\n sourceDir,\n artifactsDir,\n onChange: () => {\n return createPackage().catch((error) => {\n log.error(error.stack);\n throw error;\n });\n },\n shouldWatchFile: (...args) => fileFilter.wantFile(...args),\n });\n }\n\n return result;\n}\n"],"mappings":"AACA,OAAOA,IAAP,MAAiB,MAAjB;AACA,SAAQC,iBAAR,QAAgC,IAAhC;AAEA,SAAQC,EAAR,QAAiB,IAAjB;AACA,OAAOC,SAAP,MAAsB,YAAtB;AACA,OAAOC,QAAP,MAAqB,WAArB;AACA,OAAOC,gBAAP,MAA6B,2BAA7B;AACA,OAAOC,MAAP,MAAmB,SAAnB;AAEA,OAAOC,oBAAP,MAAiC,eAAjC;AACA,OAAOC,oBAAP,IAA8BC,aAA9B,QAAkD,qBAAlD;AACA,SAAQC,mBAAR,QAAkC,sBAAlC;AACA,SAAQC,YAAR,QAA2B,mBAA3B;AACA,SAAQC,UAAR,EAAoBC,eAApB,QAA0C,cAA1C;AACA,SACEC,gBAAgB,IAAIC,wBADtB,EAEEC,UAFF,QAGO,wBAHP,C,CAIA;;AAKA,MAAMC,GAAG,GAAGN,YAAY,CAACO,MAAM,CAACC,IAAP,CAAYC,GAAb,CAAxB;AACA,MAAMC,yBAAyB,GAAG,sBAAlC;AAEA,OAAO,SAASC,YAAT,CAAsBC,IAAtB,EAA4C;EAC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,GAAG,EALhB;EAMEnB,QAAQ,GAAG/C;AANb,CADa,EASb;EACEO,YADF;EAEEd,gBAAgB,GAAGC,wBAFrB;EAGEiD,UAAU,GAAGlD,gBAAgB,CAAC;IAC5BiD,SAD4B;IAE5BE,YAF4B;IAG5BsB;EAH4B,CAAD,CAH/B;EAQEC,cAAc,GAAGjF,oBARnB;EASEkF,cAAc,GAAG3B,qBATnB;EAUEK,gBAAgB,GAAG;AAVrB,IAWqB,EApBR,EAqBkB;EAE/B,MAAMuB,eAAe,GAAGJ,QAAxB,CAF+B,CAEG;;EAClCrE,GAAG,CAACkE,IAAJ,CAAU,+BAA8BpB,SAAU,EAAlD;;EAEA,MAAM4B,aAAa,GAAG,MAAMF,cAAc,CAAC;IACzC7D,YADyC;IAEzCmC,SAFyC;IAGzCC,UAHyC;IAIzCC,YAJyC;IAKzCC,aALyC;IAMzCC,gBANyC;IAOzCC;EAPyC,CAAD,CAA1C;;EAUA,MAAM1D,mBAAmB,CAACuD,YAAD,CAAzB;EACA,MAAM2B,MAAM,GAAG,MAAMD,aAAa,EAAlC;;EAEA,IAAID,eAAJ,EAAqB;IACnBzE,GAAG,CAACkE,IAAJ,CAAS,iCAAT;IACAK,cAAc,CAAC;MACbzB,SADa;MAEbE,YAFa;MAGb4B,QAAQ,EAAE,MAAM;QACd,OAAOF,aAAa,GAAGG,KAAhB,CAAuB5D,KAAD,IAAW;UACtCjB,GAAG,CAACiB,KAAJ,CAAUA,KAAK,CAAC6D,KAAhB;UACA,MAAM7D,KAAN;QACD,CAHM,CAAP;MAID,CARY;MASb8D,eAAe,EAAE,CAAC,GAAGtB,IAAJ,KAAaV,UAAU,CAACW,QAAX,CAAoB,GAAGD,IAAvB;IATjB,CAAD,CAAd;EAWD;;EAED,OAAOkB,MAAP;AACD"}
|
package/lib/cmd/docs.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import open from 'open';
|
|
2
|
+
import { createLogger } from '../util/logger.js';
|
|
3
|
+
const log = createLogger(import.meta.url);
|
|
4
|
+
// eslint-disable-next-line max-len
|
|
5
|
+
export const url = 'https://extensionworkshop.com/documentation/develop/getting-started-with-web-ext/';
|
|
6
|
+
export default async function docs(params, {
|
|
7
|
+
openUrl = open
|
|
8
|
+
} = {}) {
|
|
9
|
+
try {
|
|
10
|
+
await openUrl(url);
|
|
11
|
+
} catch (error) {
|
|
12
|
+
log.debug(`Encountered an error while opening URL ${url}`, error);
|
|
13
|
+
throw error;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=docs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docs.js","names":["open","createLogger","log","import","meta","url","docs","params","openUrl","error","debug"],"sources":["../../src/cmd/docs.js"],"sourcesContent":["/* @flow */\nimport open from 'open';\n\nimport {createLogger} from '../util/logger.js';\n\nconst log = createLogger(import.meta.url);\n\nexport type DocsParams = {\n noInput?: boolean,\n shouldExitProgram?: boolean,\n}\n\nexport type DocsOptions = {\n openUrl?: typeof open,\n}\n\n// eslint-disable-next-line max-len\nexport const url = 'https://extensionworkshop.com/documentation/develop/getting-started-with-web-ext/';\n\nexport default async function docs(\n params: DocsParams, {openUrl = open}: DocsOptions = {}\n): Promise<void> {\n try {\n await openUrl(url);\n } catch (error) {\n log.debug(`Encountered an error while opening URL ${url}`, error);\n throw error;\n }\n}\n"],"mappings":"AACA,OAAOA,IAAP,MAAiB,MAAjB;AAEA,SAAQC,YAAR,QAA2B,mBAA3B;AAEA,MAAMC,GAAG,GAAGD,YAAY,CAACE,MAAM,CAACC,IAAP,CAAYC,GAAb,CAAxB;AAWA;AACA,OAAO,MAAMA,GAAG,GAAG,mFAAZ;AAEP,eAAe,eAAeC,IAAf,CACbC,MADa,EACO;EAACC,OAAO,GAAGR;AAAX,IAAgC,EADvC,EAEE;EACf,IAAI;IACF,MAAMQ,OAAO,CAACH,GAAD,CAAb;EACD,CAFD,CAEE,OAAOI,KAAP,EAAc;IACdP,GAAG,CAACQ,KAAJ,CAAW,0CAAyCL,GAAI,EAAxD,EAA2DI,KAA3D;IACA,MAAMA,KAAN;EACD;AACF"}
|
package/lib/cmd/index.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// This module exports entry points for all supported commands. For performance
|
|
2
|
+
// reasons (faster start-up), the implementations are not statically imported
|
|
3
|
+
// at the top of the file, but lazily loaded in the (exported) functions.
|
|
4
|
+
// The latter would slow down start-up by several seconds, as seen in #1302 .
|
|
5
|
+
async function build(params, options) {
|
|
6
|
+
const {
|
|
7
|
+
default: runCommand
|
|
8
|
+
} = await import('./build.js');
|
|
9
|
+
return runCommand(params, options);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async function lint(params, options) {
|
|
13
|
+
const {
|
|
14
|
+
default: runCommand
|
|
15
|
+
} = await import('./lint.js');
|
|
16
|
+
return runCommand(params, options);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async function run(params, options) {
|
|
20
|
+
const {
|
|
21
|
+
default: runCommand
|
|
22
|
+
} = await import('./run.js');
|
|
23
|
+
return runCommand(params, options);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function sign(params, options) {
|
|
27
|
+
const {
|
|
28
|
+
default: runCommand
|
|
29
|
+
} = await import('./sign.js');
|
|
30
|
+
return runCommand(params, options);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function docs(params, options) {
|
|
34
|
+
const {
|
|
35
|
+
default: runCommand
|
|
36
|
+
} = await import('./docs.js');
|
|
37
|
+
return runCommand(params, options);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export default {
|
|
41
|
+
build,
|
|
42
|
+
lint,
|
|
43
|
+
run,
|
|
44
|
+
sign,
|
|
45
|
+
docs
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["build","params","options","default","runCommand","lint","run","sign","docs"],"sources":["../../src/cmd/index.js"],"sourcesContent":["/* @flow */\n\nimport type {\n BuildCmdParams, BuildCmdOptions, ExtensionBuildResult,\n} from './build.js';\nimport type {LintCmdParams, LintCmdOptions} from './lint.js';\nimport type {CmdRunParams, CmdRunOptions} from './run.js';\nimport type {MultiExtensionRunner} from '../extension-runners/index.js';\nimport type {SignParams, SignOptions, SignResult} from './sign.js';\nimport type {DocsParams, DocsOptions} from './docs.js';\n\n// This module exports entry points for all supported commands. For performance\n// reasons (faster start-up), the implementations are not statically imported\n// at the top of the file, but lazily loaded in the (exported) functions.\n// The latter would slow down start-up by several seconds, as seen in #1302 .\n\nasync function build(\n params: BuildCmdParams, options: BuildCmdOptions\n): Promise<ExtensionBuildResult> {\n const {default: runCommand} = await import('./build.js');\n return runCommand(params, options);\n}\n\nasync function lint(\n params: LintCmdParams, options: LintCmdOptions\n): Promise<void> {\n const {default: runCommand} = await import('./lint.js');\n return runCommand(params, options);\n}\n\nasync function run(\n params: CmdRunParams, options: CmdRunOptions\n): Promise<MultiExtensionRunner> {\n const {default: runCommand} = await import('./run.js');\n return runCommand(params, options);\n}\n\nasync function sign(\n params: SignParams, options: SignOptions\n): Promise<SignResult> {\n const {default: runCommand} = await import('./sign.js');\n return runCommand(params, options);\n}\n\nasync function docs(\n params: DocsParams, options: DocsOptions\n): Promise<void> {\n const {default: runCommand} = await import('./docs.js');\n return runCommand(params, options);\n}\n\nexport default {build, lint, run, sign, docs};\n"],"mappings":"AAWA;AACA;AACA;AACA;AAEA,eAAeA,KAAf,CACEC,MADF,EAC0BC,OAD1B,EAEiC;EAC/B,MAAM;IAACC,OAAO,EAAEC;EAAV,IAAwB,MAAM,OAAO,YAAP,CAApC;EACA,OAAOA,UAAU,CAACH,MAAD,EAASC,OAAT,CAAjB;AACD;;AAED,eAAeG,IAAf,CACEJ,MADF,EACyBC,OADzB,EAEiB;EACf,MAAM;IAACC,OAAO,EAAEC;EAAV,IAAwB,MAAM,OAAO,WAAP,CAApC;EACA,OAAOA,UAAU,CAACH,MAAD,EAASC,OAAT,CAAjB;AACD;;AAED,eAAeI,GAAf,CACEL,MADF,EACwBC,OADxB,EAEiC;EAC/B,MAAM;IAACC,OAAO,EAAEC;EAAV,IAAwB,MAAM,OAAO,UAAP,CAApC;EACA,OAAOA,UAAU,CAACH,MAAD,EAASC,OAAT,CAAjB;AACD;;AAED,eAAeK,IAAf,CACEN,MADF,EACsBC,OADtB,EAEuB;EACrB,MAAM;IAACC,OAAO,EAAEC;EAAV,IAAwB,MAAM,OAAO,WAAP,CAApC;EACA,OAAOA,UAAU,CAACH,MAAD,EAASC,OAAT,CAAjB;AACD;;AAED,eAAeM,IAAf,CACEP,MADF,EACsBC,OADtB,EAEiB;EACf,MAAM;IAACC,OAAO,EAAEC;EAAV,IAAwB,MAAM,OAAO,WAAP,CAApC;EACA,OAAOA,UAAU,CAACH,MAAD,EAASC,OAAT,CAAjB;AACD;;AAED,eAAe;EAACF,KAAD;EAAQK,IAAR;EAAcC,GAAd;EAAmBC,IAAnB;EAAyBC;AAAzB,CAAf"}
|
package/lib/cmd/lint.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { createInstance as defaultLinterCreator } from 'addons-linter';
|
|
2
|
+
import { createLogger } from '../util/logger.js';
|
|
3
|
+
import { createFileFilter as defaultFileFilterCreator } from '../util/file-filter.js'; // import flow types
|
|
4
|
+
|
|
5
|
+
const log = createLogger(import.meta.url); // Define the needed 'addons-linter' module flow types.
|
|
6
|
+
|
|
7
|
+
export default function lint({
|
|
8
|
+
artifactsDir,
|
|
9
|
+
boring,
|
|
10
|
+
ignoreFiles,
|
|
11
|
+
metadata,
|
|
12
|
+
output,
|
|
13
|
+
pretty,
|
|
14
|
+
privileged,
|
|
15
|
+
sourceDir,
|
|
16
|
+
selfHosted,
|
|
17
|
+
verbose,
|
|
18
|
+
warningsAsErrors
|
|
19
|
+
}, {
|
|
20
|
+
createLinter = defaultLinterCreator,
|
|
21
|
+
createFileFilter = defaultFileFilterCreator,
|
|
22
|
+
shouldExitProgram = true
|
|
23
|
+
} = {}) {
|
|
24
|
+
const fileFilter = createFileFilter({
|
|
25
|
+
sourceDir,
|
|
26
|
+
ignoreFiles,
|
|
27
|
+
artifactsDir
|
|
28
|
+
});
|
|
29
|
+
log.debug(`Running addons-linter on ${sourceDir}`);
|
|
30
|
+
const linter = createLinter({
|
|
31
|
+
config: {
|
|
32
|
+
logLevel: verbose ? 'debug' : 'fatal',
|
|
33
|
+
stack: Boolean(verbose),
|
|
34
|
+
pretty,
|
|
35
|
+
privileged,
|
|
36
|
+
warningsAsErrors,
|
|
37
|
+
metadata,
|
|
38
|
+
output,
|
|
39
|
+
boring,
|
|
40
|
+
selfHosted,
|
|
41
|
+
shouldScanFile: fileName => fileFilter.wantFile(fileName),
|
|
42
|
+
// This mimics the first command line argument from yargs,
|
|
43
|
+
// which should be the directory to the extension.
|
|
44
|
+
_: [sourceDir]
|
|
45
|
+
},
|
|
46
|
+
runAsBinary: shouldExitProgram
|
|
47
|
+
});
|
|
48
|
+
return linter.run();
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=lint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lint.js","names":["createInstance","defaultLinterCreator","createLogger","createFileFilter","defaultFileFilterCreator","log","import","meta","url","lint","artifactsDir","boring","ignoreFiles","metadata","output","pretty","privileged","sourceDir","selfHosted","verbose","warningsAsErrors","createLinter","shouldExitProgram","fileFilter","debug","linter","config","logLevel","stack","Boolean","shouldScanFile","fileName","wantFile","_","runAsBinary","run"],"sources":["../../src/cmd/lint.js"],"sourcesContent":["/* @flow */\nimport {createInstance as defaultLinterCreator} from 'addons-linter';\n\nimport {createLogger} from '../util/logger.js';\nimport {\n createFileFilter as defaultFileFilterCreator,\n} from '../util/file-filter.js';\n// import flow types\nimport type {FileFilterCreatorFn} from '../util/file-filter.js';\n\nconst log = createLogger(import.meta.url);\n\n\n// Define the needed 'addons-linter' module flow types.\n\nexport type LinterOutputType = 'text' | 'json';\n\nexport type LinterCreatorParams = {|\n config: {|\n logLevel: 'debug' | 'fatal',\n stack: boolean,\n pretty?: boolean,\n warningsAsErrors?: boolean,\n metadata?: boolean,\n output?: LinterOutputType,\n privileged?: boolean,\n boring?: boolean,\n selfHosted?: boolean,\n shouldScanFile: (fileName: string) => boolean,\n _: Array<string>,\n |},\n runAsBinary: boolean,\n|};\n\nexport type Linter = {|\n run: () => Promise<void>,\n|};\n\nexport type LinterCreatorFn = (params: LinterCreatorParams) => Linter;\n\n\n// Lint command types and implementation.\n\nexport type LintCmdParams = {|\n artifactsDir?: string,\n boring?: boolean,\n ignoreFiles?: Array<string>,\n metadata?: boolean,\n output?: LinterOutputType,\n pretty?: boolean,\n privileged?: boolean,\n selfHosted?: boolean,\n sourceDir: string,\n verbose?: boolean,\n warningsAsErrors?: boolean,\n|};\n\nexport type LintCmdOptions = {\n createLinter?: LinterCreatorFn,\n createFileFilter?: FileFilterCreatorFn,\n shouldExitProgram?: boolean,\n};\n\nexport default function lint(\n {\n artifactsDir,\n boring,\n ignoreFiles,\n metadata,\n output,\n pretty,\n privileged,\n sourceDir,\n selfHosted,\n verbose,\n warningsAsErrors,\n }: LintCmdParams,\n {\n createLinter = defaultLinterCreator,\n createFileFilter = defaultFileFilterCreator,\n shouldExitProgram = true,\n }: LintCmdOptions = {}\n): Promise<void> {\n const fileFilter = createFileFilter({sourceDir, ignoreFiles, artifactsDir});\n\n log.debug(`Running addons-linter on ${sourceDir}`);\n const linter = createLinter({\n config: {\n logLevel: verbose ? 'debug' : 'fatal',\n stack: Boolean(verbose),\n pretty,\n privileged,\n warningsAsErrors,\n metadata,\n output,\n boring,\n selfHosted,\n shouldScanFile: (fileName) => fileFilter.wantFile(fileName),\n // This mimics the first command line argument from yargs,\n // which should be the directory to the extension.\n _: [sourceDir],\n },\n runAsBinary: shouldExitProgram,\n });\n return linter.run();\n}\n"],"mappings":"AACA,SAAQA,cAAc,IAAIC,oBAA1B,QAAqD,eAArD;AAEA,SAAQC,YAAR,QAA2B,mBAA3B;AACA,SACEC,gBAAgB,IAAIC,wBADtB,QAEO,wBAFP,C,CAGA;;AAGA,MAAMC,GAAG,GAAGH,YAAY,CAACI,MAAM,CAACC,IAAP,CAAYC,GAAb,CAAxB,C,CAGA;;AAkDA,eAAe,SAASC,IAAT,CACb;EACEC,YADF;EAEEC,MAFF;EAGEC,WAHF;EAIEC,QAJF;EAKEC,MALF;EAMEC,MANF;EAOEC,UAPF;EAQEC,SARF;EASEC,UATF;EAUEC,OAVF;EAWEC;AAXF,CADa,EAcb;EACEC,YAAY,GAAGpB,oBADjB;EAEEE,gBAAgB,GAAGC,wBAFrB;EAGEkB,iBAAiB,GAAG;AAHtB,IAIoB,EAlBP,EAmBE;EACf,MAAMC,UAAU,GAAGpB,gBAAgB,CAAC;IAACc,SAAD;IAAYL,WAAZ;IAAyBF;EAAzB,CAAD,CAAnC;EAEAL,GAAG,CAACmB,KAAJ,CAAW,4BAA2BP,SAAU,EAAhD;EACA,MAAMQ,MAAM,GAAGJ,YAAY,CAAC;IAC1BK,MAAM,EAAE;MACNC,QAAQ,EAAER,OAAO,GAAG,OAAH,GAAa,OADxB;MAENS,KAAK,EAAEC,OAAO,CAACV,OAAD,CAFR;MAGNJ,MAHM;MAINC,UAJM;MAKNI,gBALM;MAMNP,QANM;MAONC,MAPM;MAQNH,MARM;MASNO,UATM;MAUNY,cAAc,EAAGC,QAAD,IAAcR,UAAU,CAACS,QAAX,CAAoBD,QAApB,CAVxB;MAWN;MACA;MACAE,CAAC,EAAE,CAAChB,SAAD;IAbG,CADkB;IAgB1BiB,WAAW,EAAEZ;EAhBa,CAAD,CAA3B;EAkBA,OAAOG,MAAM,CAACU,GAAP,EAAP;AACD"}
|