web-ext 6.7.0 → 7.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +199 -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 +663 -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 -114
|
@@ -1,92 +1,65 @@
|
|
|
1
|
-
/* @flow */
|
|
2
1
|
import path from 'path';
|
|
3
|
-
|
|
4
2
|
import multimatch from 'multimatch';
|
|
3
|
+
import { createLogger } from './logger.js';
|
|
4
|
+
const log = createLogger(import.meta.url); // check if target is a sub directory of src
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const log = createLogger(__filename);
|
|
6
|
+
export const isSubPath = (src, target) => {
|
|
7
|
+
const relate = path.relative(src, target); // same dir
|
|
9
8
|
|
|
10
|
-
// check if target is a sub directory of src
|
|
11
|
-
export const isSubPath = (src: string, target: string): boolean => {
|
|
12
|
-
const relate = path.relative(src, target);
|
|
13
|
-
// same dir
|
|
14
9
|
if (!relate) {
|
|
15
10
|
return false;
|
|
16
11
|
}
|
|
12
|
+
|
|
17
13
|
if (relate === '..') {
|
|
18
14
|
return false;
|
|
19
15
|
}
|
|
20
|
-
return !relate.startsWith(`..${path.sep}`);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
// FileFilter types and implementation.
|
|
24
16
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
ignoreFiles?: Array<string>,
|
|
28
|
-
sourceDir: string,
|
|
29
|
-
artifactsDir?: string,
|
|
30
|
-
|};
|
|
17
|
+
return !relate.startsWith(`..${path.sep}`);
|
|
18
|
+
}; // FileFilter types and implementation.
|
|
31
19
|
|
|
32
20
|
/*
|
|
33
21
|
* Allows or ignores files.
|
|
34
22
|
*/
|
|
35
23
|
export class FileFilter {
|
|
36
|
-
filesToIgnore: Array<string>;
|
|
37
|
-
sourceDir: string;
|
|
38
|
-
|
|
39
24
|
constructor({
|
|
40
|
-
baseIgnoredPatterns = [
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
'**/.*', // any hidden file and folder
|
|
44
|
-
'**/.*/**/*', // and the content inside hidden folder
|
|
45
|
-
'**/node_modules',
|
|
46
|
-
'**/node_modules/**/*',
|
|
47
|
-
],
|
|
25
|
+
baseIgnoredPatterns = ['**/*.xpi', '**/*.zip', '**/.*', // any hidden file and folder
|
|
26
|
+
'**/.*/**/*', // and the content inside hidden folder
|
|
27
|
+
'**/node_modules', '**/node_modules/**/*'],
|
|
48
28
|
ignoreFiles = [],
|
|
49
29
|
sourceDir,
|
|
50
|
-
artifactsDir
|
|
51
|
-
}
|
|
30
|
+
artifactsDir
|
|
31
|
+
} = {}) {
|
|
52
32
|
sourceDir = path.resolve(sourceDir);
|
|
53
|
-
|
|
54
33
|
this.filesToIgnore = [];
|
|
55
34
|
this.sourceDir = sourceDir;
|
|
56
|
-
|
|
57
35
|
this.addToIgnoreList(baseIgnoredPatterns);
|
|
36
|
+
|
|
58
37
|
if (ignoreFiles) {
|
|
59
38
|
this.addToIgnoreList(ignoreFiles);
|
|
60
39
|
}
|
|
40
|
+
|
|
61
41
|
if (artifactsDir && isSubPath(sourceDir, artifactsDir)) {
|
|
62
42
|
artifactsDir = path.resolve(artifactsDir);
|
|
63
|
-
log.debug(
|
|
64
|
-
|
|
65
|
-
'and all its subdirectories'
|
|
66
|
-
);
|
|
67
|
-
this.addToIgnoreList([
|
|
68
|
-
artifactsDir,
|
|
69
|
-
path.join(artifactsDir, '**', '*'),
|
|
70
|
-
]);
|
|
43
|
+
log.debug(`Ignoring artifacts directory "${artifactsDir}" ` + 'and all its subdirectories');
|
|
44
|
+
this.addToIgnoreList([artifactsDir, path.join(artifactsDir, '**', '*')]);
|
|
71
45
|
}
|
|
72
46
|
}
|
|
73
|
-
|
|
74
47
|
/**
|
|
75
48
|
* Resolve relative path to absolute path with sourceDir.
|
|
76
49
|
*/
|
|
77
|
-
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
resolveWithSourceDir(file) {
|
|
78
53
|
const resolvedPath = path.resolve(this.sourceDir, file);
|
|
79
|
-
log.debug(
|
|
80
|
-
`Resolved path ${file} with sourceDir ${this.sourceDir} ` +
|
|
81
|
-
`to ${resolvedPath}`
|
|
82
|
-
);
|
|
54
|
+
log.debug(`Resolved path ${file} with sourceDir ${this.sourceDir} ` + `to ${resolvedPath}`);
|
|
83
55
|
return resolvedPath;
|
|
84
56
|
}
|
|
85
|
-
|
|
86
57
|
/**
|
|
87
58
|
* Insert more files into filesToIgnore array.
|
|
88
59
|
*/
|
|
89
|
-
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
addToIgnoreList(files) {
|
|
90
63
|
for (const file of files) {
|
|
91
64
|
if (file.charAt(0) === '!') {
|
|
92
65
|
const resolvedFile = this.resolveWithSourceDir(file.substr(1));
|
|
@@ -96,7 +69,6 @@ export class FileFilter {
|
|
|
96
69
|
}
|
|
97
70
|
}
|
|
98
71
|
}
|
|
99
|
-
|
|
100
72
|
/*
|
|
101
73
|
* Returns true if the file is wanted.
|
|
102
74
|
*
|
|
@@ -107,21 +79,21 @@ export class FileFilter {
|
|
|
107
79
|
* Example: this is called by zipdir as wantFile(filePath) for each
|
|
108
80
|
* file in the folder that is being archived.
|
|
109
81
|
*/
|
|
110
|
-
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
wantFile(filePath) {
|
|
111
85
|
const resolvedPath = this.resolveWithSourceDir(filePath);
|
|
112
86
|
const matches = multimatch(resolvedPath, this.filesToIgnore);
|
|
87
|
+
|
|
113
88
|
if (matches.length > 0) {
|
|
114
89
|
log.debug(`FileFilter: ignoring file ${resolvedPath}`);
|
|
115
90
|
return false;
|
|
116
91
|
}
|
|
92
|
+
|
|
117
93
|
return true;
|
|
118
94
|
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// a helper function to make mocking easier
|
|
122
95
|
|
|
123
|
-
|
|
124
|
-
(params: FileFilterOptions): FileFilter => new FileFilter(params)
|
|
125
|
-
);
|
|
96
|
+
} // a helper function to make mocking easier
|
|
126
97
|
|
|
127
|
-
export
|
|
98
|
+
export const createFileFilter = params => new FileFilter(params);
|
|
99
|
+
//# sourceMappingURL=file-filter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-filter.js","names":["path","multimatch","createLogger","log","import","meta","url","isSubPath","src","target","relate","relative","startsWith","sep","FileFilter","constructor","baseIgnoredPatterns","ignoreFiles","sourceDir","artifactsDir","resolve","filesToIgnore","addToIgnoreList","debug","join","resolveWithSourceDir","file","resolvedPath","files","charAt","resolvedFile","substr","push","wantFile","filePath","matches","length","createFileFilter","params"],"sources":["../../src/util/file-filter.js"],"sourcesContent":["/* @flow */\nimport path from 'path';\n\nimport multimatch from 'multimatch';\n\nimport {createLogger} from './logger.js';\n\nconst log = createLogger(import.meta.url);\n\n// check if target is a sub directory of src\nexport const isSubPath = (src: string, target: string): boolean => {\n const relate = path.relative(src, target);\n // same dir\n if (!relate) {\n return false;\n }\n if (relate === '..') {\n return false;\n }\n return !relate.startsWith(`..${path.sep}`);\n};\n\n// FileFilter types and implementation.\n\nexport type FileFilterOptions = {\n baseIgnoredPatterns?: Array<string>,\n ignoreFiles?: Array<string>,\n sourceDir: string,\n artifactsDir?: string,\n};\n\n/*\n * Allows or ignores files.\n */\nexport class FileFilter {\n filesToIgnore: Array<string>;\n sourceDir: string;\n\n constructor({\n baseIgnoredPatterns = [\n '**/*.xpi',\n '**/*.zip',\n '**/.*', // any hidden file and folder\n '**/.*/**/*', // and the content inside hidden folder\n '**/node_modules',\n '**/node_modules/**/*',\n ],\n ignoreFiles = [],\n sourceDir,\n artifactsDir,\n }: FileFilterOptions = {}) {\n sourceDir = path.resolve(sourceDir);\n\n this.filesToIgnore = [];\n this.sourceDir = sourceDir;\n\n this.addToIgnoreList(baseIgnoredPatterns);\n if (ignoreFiles) {\n this.addToIgnoreList(ignoreFiles);\n }\n if (artifactsDir && isSubPath(sourceDir, artifactsDir)) {\n artifactsDir = path.resolve(artifactsDir);\n log.debug(\n `Ignoring artifacts directory \"${artifactsDir}\" ` +\n 'and all its subdirectories'\n );\n this.addToIgnoreList([\n artifactsDir,\n path.join(artifactsDir, '**', '*'),\n ]);\n }\n }\n\n /**\n * Resolve relative path to absolute path with sourceDir.\n */\n resolveWithSourceDir(file: string): string {\n const resolvedPath = path.resolve(this.sourceDir, file);\n log.debug(\n `Resolved path ${file} with sourceDir ${this.sourceDir} ` +\n `to ${resolvedPath}`\n );\n return resolvedPath;\n }\n\n /**\n * Insert more files into filesToIgnore array.\n */\n addToIgnoreList(files: Array<string>) {\n for (const file of files) {\n if (file.charAt(0) === '!') {\n const resolvedFile = this.resolveWithSourceDir(file.substr(1));\n this.filesToIgnore.push(`!${resolvedFile}`);\n } else {\n this.filesToIgnore.push(this.resolveWithSourceDir(file));\n }\n }\n }\n\n /*\n * Returns true if the file is wanted.\n *\n * If filePath does not start with a slash, it will be treated as a path\n * relative to sourceDir when matching it against all configured\n * ignore-patterns.\n *\n * Example: this is called by zipdir as wantFile(filePath) for each\n * file in the folder that is being archived.\n */\n wantFile(filePath: string): boolean {\n const resolvedPath = this.resolveWithSourceDir(filePath);\n const matches = multimatch(resolvedPath, this.filesToIgnore);\n if (matches.length > 0) {\n log.debug(`FileFilter: ignoring file ${resolvedPath}`);\n return false;\n }\n return true;\n }\n}\n\n// a helper function to make mocking easier\n\nexport const createFileFilter = (\n (params: FileFilterOptions): FileFilter => new FileFilter(params)\n);\n\nexport type FileFilterCreatorFn = typeof createFileFilter;\n"],"mappings":"AACA,OAAOA,IAAP,MAAiB,MAAjB;AAEA,OAAOC,UAAP,MAAuB,YAAvB;AAEA,SAAQC,YAAR,QAA2B,aAA3B;AAEA,MAAMC,GAAG,GAAGD,YAAY,CAACE,MAAM,CAACC,IAAP,CAAYC,GAAb,CAAxB,C,CAEA;;AACA,OAAO,MAAMC,SAAS,GAAG,CAACC,GAAD,EAAcC,MAAd,KAA0C;EACjE,MAAMC,MAAM,GAAGV,IAAI,CAACW,QAAL,CAAcH,GAAd,EAAmBC,MAAnB,CAAf,CADiE,CAEjE;;EACA,IAAI,CAACC,MAAL,EAAa;IACX,OAAO,KAAP;EACD;;EACD,IAAIA,MAAM,KAAK,IAAf,EAAqB;IACnB,OAAO,KAAP;EACD;;EACD,OAAO,CAACA,MAAM,CAACE,UAAP,CAAmB,KAAIZ,IAAI,CAACa,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F,IAAI,CAACG,MAAL,CAAY,CAAZ,MAAmB,GAAvB,EAA4B;QAC1B,MAAMC,YAAY,GAAG,KAAKL,oBAAL,CAA0BC,IAAI,CAACK,MAAL,CAAY,CAAZ,CAA1B,CAArB;QACA,KAAKV,aAAL,CAAmBW,IAAnB,CAAyB,IAAGF,YAAa,EAAzC;MACD,CAHD,MAGO;QACL,KAAKT,aAAL,CAAmBW,IAAnB,CAAwB,KAAKP,oBAAL,CAA0BC,IAA1B,CAAxB;MACD;IACF;EACF;EAED;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;EACEO,QAAQ,CAACC,QAAD,EAA4B;IAClC,MAAMP,YAAY,GAAG,KAAKF,oBAAL,CAA0BS,QAA1B,CAArB;IACA,MAAMC,OAAO,GAAGlC,UAAU,CAAC0B,YAAD,EAAe,KAAKN,aAApB,CAA1B;;IACA,IAAIc,OAAO,CAACC,MAAR,GAAiB,CAArB,EAAwB;MACtBjC,GAAG,CAACoB,KAAJ,CAAW,6BAA4BI,YAAa,EAApD;MACA,OAAO,KAAP;IACD;;IACD,OAAO,IAAP;EACD;;AAnFqB,C,CAsFxB;;AAEA,OAAO,MAAMU,gBAAgB,GAC1BC,MAAD,IAA2C,IAAIxB,UAAJ,CAAewB,MAAf,CADtC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { fs } from 'mz';
|
|
2
|
+
import { onlyErrorsWithCode } from '../errors.js';
|
|
3
|
+
/*
|
|
4
|
+
* Resolves true if the path is a readable directory.
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
*
|
|
8
|
+
* isDirectory('/some/path')
|
|
9
|
+
* .then((dirExists) => {
|
|
10
|
+
* // dirExists will be true or false.
|
|
11
|
+
* });
|
|
12
|
+
*
|
|
13
|
+
* */
|
|
14
|
+
|
|
15
|
+
export default function isDirectory(path) {
|
|
16
|
+
return fs.stat(path).then(stats => stats.isDirectory()).catch(onlyErrorsWithCode(['ENOENT', 'ENOTDIR'], () => {
|
|
17
|
+
return false;
|
|
18
|
+
}));
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=is-directory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-directory.js","names":["fs","onlyErrorsWithCode","isDirectory","path","stat","then","stats","catch"],"sources":["../../src/util/is-directory.js"],"sourcesContent":["/* @flow */\nimport {fs} from 'mz';\n\nimport {onlyErrorsWithCode} from '../errors.js';\n\n/*\n * Resolves true if the path is a readable directory.\n *\n * Usage:\n *\n * isDirectory('/some/path')\n * .then((dirExists) => {\n * // dirExists will be true or false.\n * });\n *\n * */\nexport default function isDirectory(path: string): Promise<boolean> {\n return fs.stat(path)\n .then((stats) => stats.isDirectory())\n .catch(onlyErrorsWithCode(['ENOENT', 'ENOTDIR'], () => {\n return false;\n }));\n}\n"],"mappings":"AACA,SAAQA,EAAR,QAAiB,IAAjB;AAEA,SAAQC,kBAAR,QAAiC,cAAjC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,WAAT,CAAqBC,IAArB,EAAqD;EAClE,OAAOH,EAAE,CAACI,IAAH,CAAQD,IAAR,EACJE,IADI,CACEC,KAAD,IAAWA,KAAK,CAACJ,WAAN,EADZ,EAEJK,KAFI,CAEEN,kBAAkB,CAAC,CAAC,QAAD,EAAW,SAAX,CAAD,EAAwB,MAAM;IACrD,OAAO,KAAP;EACD,CAFwB,CAFpB,CAAP;AAKD"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { fileURLToPath } from 'url';
|
|
2
|
+
import bunyan, { nameFromLevel, createLogger as defaultLogCreator } from 'bunyan'; // Bunyan-related Flow types
|
|
3
|
+
|
|
4
|
+
export class ConsoleStream {
|
|
5
|
+
constructor({
|
|
6
|
+
verbose = false
|
|
7
|
+
} = {}) {
|
|
8
|
+
this.verbose = verbose;
|
|
9
|
+
this.isCapturing = false;
|
|
10
|
+
this.capturedMessages = [];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
format({
|
|
14
|
+
name,
|
|
15
|
+
msg,
|
|
16
|
+
level
|
|
17
|
+
}) {
|
|
18
|
+
const prefix = this.verbose ? `[${name}][${nameFromLevel[level]}] ` : '';
|
|
19
|
+
return `${prefix}${msg}\n`;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
makeVerbose() {
|
|
23
|
+
this.verbose = true;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
write(packet, {
|
|
27
|
+
localProcess = process
|
|
28
|
+
} = {}) {
|
|
29
|
+
const thisLevel = this.verbose ? bunyan.TRACE : bunyan.INFO;
|
|
30
|
+
|
|
31
|
+
if (packet.level >= thisLevel) {
|
|
32
|
+
const msg = this.format(packet);
|
|
33
|
+
|
|
34
|
+
if (this.isCapturing) {
|
|
35
|
+
this.capturedMessages.push(msg);
|
|
36
|
+
} else {
|
|
37
|
+
localProcess.stdout.write(msg);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
startCapturing() {
|
|
43
|
+
this.isCapturing = true;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
stopCapturing() {
|
|
47
|
+
this.isCapturing = false;
|
|
48
|
+
this.capturedMessages = [];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
flushCapturedLogs({
|
|
52
|
+
localProcess = process
|
|
53
|
+
} = {}) {
|
|
54
|
+
for (const msg of this.capturedMessages) {
|
|
55
|
+
localProcess.stdout.write(msg);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
this.capturedMessages = [];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
}
|
|
62
|
+
export const consoleStream = new ConsoleStream(); // createLogger types and implementation.
|
|
63
|
+
|
|
64
|
+
export function createLogger(moduleURL, {
|
|
65
|
+
createBunyanLog = defaultLogCreator
|
|
66
|
+
} = {}) {
|
|
67
|
+
return createBunyanLog({
|
|
68
|
+
// Strip the leading src/ from file names (which is in all file names) to
|
|
69
|
+
// make the name less redundant.
|
|
70
|
+
name: moduleURL ? fileURLToPath(moduleURL).replace(/^src\//, '') : 'unknown-module',
|
|
71
|
+
// Capture all log levels and let the stream filter them.
|
|
72
|
+
level: bunyan.TRACE,
|
|
73
|
+
streams: [{
|
|
74
|
+
type: 'raw',
|
|
75
|
+
stream: consoleStream
|
|
76
|
+
}]
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","names":["fileURLToPath","bunyan","nameFromLevel","createLogger","defaultLogCreator","ConsoleStream","constructor","verbose","isCapturing","capturedMessages","format","name","msg","level","prefix","makeVerbose","write","packet","localProcess","process","thisLevel","TRACE","INFO","push","stdout","startCapturing","stopCapturing","flushCapturedLogs","consoleStream","moduleURL","createBunyanLog","replace","streams","type","stream"],"sources":["../../src/util/logger.js"],"sourcesContent":["/* @flow */\nimport { fileURLToPath } from 'url';\n\nimport bunyan, {nameFromLevel, createLogger as defaultLogCreator}\n from 'bunyan';\n\n// Bunyan-related Flow types\n\nexport type TRACE = 10;\nexport type DEBUG = 20;\nexport type INFO = 30;\nexport type WARN = 40;\nexport type ERROR = 50;\nexport type FATAL = 60;\n\nexport type BunyanLogLevel =\n TRACE | DEBUG | INFO | WARN | ERROR | FATAL;\n\nexport type BunyanLogEntry = {|\n name: string,\n msg: string,\n level: BunyanLogLevel,\n|};\n\nexport type Logger = {\n debug: (msg: string, ...args: any) => void,\n error: (msg: string, ...args: any) => void,\n info: (msg: string, ...args: any) => void,\n warn: (msg: string, ...args: any) => void,\n};\n\n\n// ConsoleStream types and implementation.\n\nexport type ConsoleStreamParams = {\n verbose?: boolean,\n};\n\nexport type ConsoleOptions = {\n localProcess?: typeof process,\n};\n\nexport class ConsoleStream {\n verbose: boolean;\n isCapturing: boolean;\n capturedMessages: Array<string>;\n\n constructor({verbose = false}: ConsoleStreamParams = {}) {\n this.verbose = verbose;\n this.isCapturing = false;\n this.capturedMessages = [];\n }\n\n format({name, msg, level}: BunyanLogEntry): string {\n const prefix = this.verbose ? `[${name}][${nameFromLevel[level]}] ` : '';\n return `${prefix}${msg}\\n`;\n }\n\n makeVerbose() {\n this.verbose = true;\n }\n\n write(\n packet: BunyanLogEntry,\n {localProcess = process}: ConsoleOptions = {}\n ): void {\n const thisLevel: BunyanLogLevel = this.verbose ? bunyan.TRACE : bunyan.INFO;\n if (packet.level >= thisLevel) {\n const msg = this.format(packet);\n if (this.isCapturing) {\n this.capturedMessages.push(msg);\n } else {\n localProcess.stdout.write(msg);\n }\n }\n }\n\n startCapturing() {\n this.isCapturing = true;\n }\n\n stopCapturing() {\n this.isCapturing = false;\n this.capturedMessages = [];\n }\n\n flushCapturedLogs({localProcess = process}: ConsoleOptions = {}) {\n for (const msg of this.capturedMessages) {\n localProcess.stdout.write(msg);\n }\n this.capturedMessages = [];\n }\n}\n\nexport const consoleStream: ConsoleStream = new ConsoleStream();\n\n\n// createLogger types and implementation.\n\nexport type BunyanStreamConfig = {\n type: string,\n stream: ConsoleStream,\n};\n\nexport type CreateBunyanLogParams = {\n name: string,\n level: BunyanLogLevel,\n streams: Array<BunyanStreamConfig>,\n};\n\nexport type CreateBunyanLogFn = (params: CreateBunyanLogParams) => Logger;\n\nexport type CreateLoggerOptions = {\n createBunyanLog: CreateBunyanLogFn,\n};\n\nexport function createLogger(\n moduleURL?: string,\n {createBunyanLog = defaultLogCreator}: CreateLoggerOptions = {}\n): Logger {\n return createBunyanLog({\n // Strip the leading src/ from file names (which is in all file names) to\n // make the name less redundant.\n name: moduleURL\n ? fileURLToPath(moduleURL).replace(/^src\\//, '')\n : 'unknown-module',\n // Capture all log levels and let the stream filter them.\n level: bunyan.TRACE,\n streams: [{\n type: 'raw',\n stream: consoleStream,\n }],\n });\n}\n"],"mappings":"AACA,SAASA,aAAT,QAA8B,KAA9B;AAEA,OAAOC,MAAP,IAAgBC,aAAhB,EAA+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D,KAAK,MAAMP,GAAX,IAAkB,KAAKH,gBAAvB,EAAyC;MACvCS,YAAY,CAACM,MAAb,CAAoBR,KAApB,CAA0BJ,GAA1B;IACD;;IACD,KAAKH,gBAAL,GAAwB,EAAxB;EACD;;AAjDwB;AAoD3B,OAAO,MAAMmB,aAA4B,GAAG,IAAIvB,aAAJ,EAArC,C,CAGP;;AAmBA,OAAO,SAASF,YAAT,CACL0B,SADK,EAEL;EAACC,eAAe,GAAG1B;AAAnB,IAA6D,EAFxD,EAGG;EACR,OAAO0B,eAAe,CAAC;IACrB;IACA;IACAnB,IAAI,EAAEkB,SAAS,GACX7B,aAAa,CAAC6B,SAAD,CAAb,CAAyBE,OAAzB,CAAiC,QAAjC,EAA2C,EAA3C,CADW,GAEX,gBALiB;IAMrB;IACAlB,KAAK,EAAEZ,MAAM,CAACoB,KAPO;IAQrBW,OAAO,EAAE,CAAC;MACRC,IAAI,EAAE,KADE;MAERC,MAAM,EAAEN;IAFA,CAAD;EARY,CAAD,CAAtB;AAaD"}
|
|
@@ -1,70 +1,42 @@
|
|
|
1
|
-
/* @flow */
|
|
2
1
|
import path from 'path';
|
|
3
|
-
|
|
4
|
-
import {fs} from 'mz';
|
|
2
|
+
import { fs } from 'mz';
|
|
5
3
|
import parseJSON from 'parse-json';
|
|
6
4
|
import stripBom from 'strip-bom';
|
|
7
5
|
import stripJsonComments from 'strip-json-comments';
|
|
6
|
+
import { InvalidManifest } from '../errors.js';
|
|
7
|
+
import { createLogger } from './logger.js';
|
|
8
|
+
const log = createLogger(import.meta.url); // getValidatedManifest helper types and implementation
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
import {createLogger} from './logger';
|
|
11
|
-
|
|
12
|
-
const log = createLogger(__filename);
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
// getValidatedManifest helper types and implementation
|
|
16
|
-
|
|
17
|
-
export type ExtensionManifestApplications = {|
|
|
18
|
-
gecko?: {|
|
|
19
|
-
id?: string,
|
|
20
|
-
strict_min_version?: string,
|
|
21
|
-
strict_max_version?: string,
|
|
22
|
-
update_url?: string,
|
|
23
|
-
|},
|
|
24
|
-
|};
|
|
25
|
-
|
|
26
|
-
export type ExtensionManifest = {|
|
|
27
|
-
name: string,
|
|
28
|
-
version: string,
|
|
29
|
-
default_locale?: string,
|
|
30
|
-
applications?: ExtensionManifestApplications,
|
|
31
|
-
browser_specific_settings?: ExtensionManifestApplications,
|
|
32
|
-
permissions?: Array<string>,
|
|
33
|
-
|};
|
|
34
|
-
|
|
35
|
-
export default async function getValidatedManifest(
|
|
36
|
-
sourceDir: string
|
|
37
|
-
): Promise<ExtensionManifest> {
|
|
10
|
+
export default async function getValidatedManifest(sourceDir) {
|
|
38
11
|
const manifestFile = path.join(sourceDir, 'manifest.json');
|
|
39
12
|
log.debug(`Validating manifest at ${manifestFile}`);
|
|
40
|
-
|
|
41
13
|
let manifestContents;
|
|
42
14
|
|
|
43
15
|
try {
|
|
44
|
-
manifestContents = await fs.readFile(manifestFile, {
|
|
16
|
+
manifestContents = await fs.readFile(manifestFile, {
|
|
17
|
+
encoding: 'utf-8'
|
|
18
|
+
});
|
|
45
19
|
} catch (error) {
|
|
46
|
-
throw new InvalidManifest(
|
|
47
|
-
`Could not read manifest.json file at ${manifestFile}: ${error}`);
|
|
20
|
+
throw new InvalidManifest(`Could not read manifest.json file at ${manifestFile}: ${error}`);
|
|
48
21
|
}
|
|
49
22
|
|
|
50
23
|
manifestContents = stripBom(manifestContents);
|
|
51
|
-
|
|
52
24
|
let manifestData;
|
|
53
25
|
|
|
54
26
|
try {
|
|
55
27
|
manifestData = parseJSON(stripJsonComments(manifestContents));
|
|
56
28
|
} catch (error) {
|
|
57
|
-
throw new InvalidManifest(
|
|
58
|
-
`Error parsing manifest.json file at ${manifestFile}: ${error}`);
|
|
29
|
+
throw new InvalidManifest(`Error parsing manifest.json file at ${manifestFile}: ${error}`);
|
|
59
30
|
}
|
|
60
31
|
|
|
61
|
-
const errors = [];
|
|
62
|
-
// This is just some basic validation of what web-ext needs, not
|
|
32
|
+
const errors = []; // This is just some basic validation of what web-ext needs, not
|
|
63
33
|
// what Firefox will need to run the extension.
|
|
64
34
|
// TODO: integrate with the addons-linter for actual validation.
|
|
35
|
+
|
|
65
36
|
if (!manifestData.name) {
|
|
66
37
|
errors.push('missing "name" property');
|
|
67
38
|
}
|
|
39
|
+
|
|
68
40
|
if (!manifestData.version) {
|
|
69
41
|
errors.push('missing "version" property');
|
|
70
42
|
}
|
|
@@ -77,28 +49,24 @@ export default async function getValidatedManifest(
|
|
|
77
49
|
}
|
|
78
50
|
|
|
79
51
|
if (errors.length) {
|
|
80
|
-
throw new InvalidManifest(
|
|
81
|
-
`Manifest at ${manifestFile} is invalid: ${errors.join('; ')}`);
|
|
52
|
+
throw new InvalidManifest(`Manifest at ${manifestFile} is invalid: ${errors.join('; ')}`);
|
|
82
53
|
}
|
|
83
54
|
|
|
84
55
|
return manifestData;
|
|
85
56
|
}
|
|
57
|
+
export function getManifestId(manifestData) {
|
|
58
|
+
const manifestApps = [manifestData.browser_specific_settings, manifestData.applications];
|
|
86
59
|
|
|
87
|
-
|
|
88
|
-
export function getManifestId(manifestData: ExtensionManifest): string | void {
|
|
89
|
-
const manifestApps = [
|
|
90
|
-
manifestData.browser_specific_settings,
|
|
91
|
-
manifestData.applications,
|
|
92
|
-
];
|
|
93
60
|
for (const apps of manifestApps) {
|
|
94
61
|
// If both bss and applicants contains a defined gecko property,
|
|
95
62
|
// we prefer bss even if the id property isn't available.
|
|
96
63
|
// This match what Firefox does in this particular scenario, see
|
|
97
64
|
// https://searchfox.org/mozilla-central/rev/828f2319c0195d7f561ed35533aef6fe183e68e3/toolkit/mozapps/extensions/internal/XPIInstall.jsm#470-474,488
|
|
98
|
-
if (apps
|
|
65
|
+
if (apps !== null && apps !== void 0 && apps.gecko) {
|
|
99
66
|
return apps.gecko.id;
|
|
100
67
|
}
|
|
101
68
|
}
|
|
102
69
|
|
|
103
70
|
return undefined;
|
|
104
71
|
}
|
|
72
|
+
//# sourceMappingURL=manifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest.js","names":["path","fs","parseJSON","stripBom","stripJsonComments","InvalidManifest","createLogger","log","import","meta","url","getValidatedManifest","sourceDir","manifestFile","join","debug","manifestContents","readFile","encoding","error","manifestData","errors","name","push","version","applications","gecko","length","getManifestId","manifestApps","browser_specific_settings","apps","id","undefined"],"sources":["../../src/util/manifest.js"],"sourcesContent":["/* @flow */\nimport path from 'path';\n\nimport {fs} from 'mz';\nimport parseJSON from 'parse-json';\nimport stripBom from 'strip-bom';\nimport stripJsonComments from 'strip-json-comments';\n\nimport {InvalidManifest} from '../errors.js';\nimport {createLogger} from './logger.js';\n\nconst log = createLogger(import.meta.url);\n\n\n// getValidatedManifest helper types and implementation\n\nexport type ExtensionManifestApplications = {|\n gecko?: {|\n id?: string,\n strict_min_version?: string,\n strict_max_version?: string,\n update_url?: string,\n |},\n|};\n\nexport type ExtensionManifest = {|\n name: string,\n version: string,\n default_locale?: string,\n applications?: ExtensionManifestApplications,\n browser_specific_settings?: ExtensionManifestApplications,\n permissions?: Array<string>,\n|};\n\nexport default async function getValidatedManifest(\n sourceDir: string\n): Promise<ExtensionManifest> {\n const manifestFile = path.join(sourceDir, 'manifest.json');\n log.debug(`Validating manifest at ${manifestFile}`);\n\n let manifestContents;\n\n try {\n manifestContents = await fs.readFile(manifestFile, {encoding: 'utf-8'});\n } catch (error) {\n throw new InvalidManifest(\n `Could not read manifest.json file at ${manifestFile}: ${error}`);\n }\n\n manifestContents = stripBom(manifestContents);\n\n let manifestData;\n\n try {\n manifestData = parseJSON(stripJsonComments(manifestContents));\n } catch (error) {\n throw new InvalidManifest(\n `Error parsing manifest.json file at ${manifestFile}: ${error}`);\n }\n\n const errors = [];\n // This is just some basic validation of what web-ext needs, not\n // what Firefox will need to run the extension.\n // TODO: integrate with the addons-linter for actual validation.\n if (!manifestData.name) {\n errors.push('missing \"name\" property');\n }\n if (!manifestData.version) {\n errors.push('missing \"version\" property');\n }\n\n if (manifestData.applications && !manifestData.applications.gecko) {\n // Since the applications property only applies to gecko, make\n // sure 'gecko' exists when 'applications' is defined. This should\n // make introspection of gecko properties easier.\n errors.push('missing \"applications.gecko\" property');\n }\n\n if (errors.length) {\n throw new InvalidManifest(\n `Manifest at ${manifestFile} is invalid: ${errors.join('; ')}`);\n }\n\n return manifestData;\n}\n\n\nexport function getManifestId(manifestData: ExtensionManifest): string | void {\n const manifestApps = [\n manifestData.browser_specific_settings,\n manifestData.applications,\n ];\n for (const apps of manifestApps) {\n // If both bss and applicants contains a defined gecko property,\n // we prefer bss even if the id property isn't available.\n // This match what Firefox does in this particular scenario, see\n // https://searchfox.org/mozilla-central/rev/828f2319c0195d7f561ed35533aef6fe183e68e3/toolkit/mozapps/extensions/internal/XPIInstall.jsm#470-474,488\n if (apps?.gecko) {\n return apps.gecko.id;\n }\n }\n\n return undefined;\n}\n"],"mappings":"AACA,OAAOA,IAAP,MAAiB,MAAjB;AAEA,SAAQC,EAAR,QAAiB,IAAjB;AACA,OAAOC,SAAP,MAAsB,YAAtB;AACA,OAAOC,QAAP,MAAqB,WAArB;AACA,OAAOC,iBAAP,MAA8B,qBAA9B;AAEA,SAAQC,eAAR,QAA8B,cAA9B;AACA,SAAQC,YAAR,QAA2B,aAA3B;AAEA,MAAMC,GAAG,GAAGD,YAAY,CAACE,MAAM,CAACC,IAAP,CAAYC,GAAb,CAAxB,C,CAGA;;AAoBA,eAAe,eAAeC,oBAAf,CACbC,SADa,EAEe;EAC5B,MAAMC,YAAY,GAAGb,IAAI,CAACc,IAAL,CAAUF,SAAV,EAAqB,eAArB,CAArB;EACAL,GAAG,CAACQ,KAAJ,CAAW,0BAAyBF,YAAa,EAAjD;EAEA,IAAIG,gBAAJ;;EAEA,IAAI;IACFA,gBAAgB,GAAG,MAAMf,EAAE,CAACgB,QAAH,CAAYJ,YAAZ,EAA0B;MAACK,QAAQ,EAAE;IAAX,CAA1B,CAAzB;E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AAWM,EAAlB;IACD;EACF;;EAED,OAAOC,SAAP;AACD"}
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import {promisify} from 'util';
|
|
4
|
-
|
|
5
|
-
// promisify.custom is missing from the node types know to flow,
|
|
1
|
+
import { promisify } from 'util'; // promisify.custom is missing from the node types know to flow,
|
|
6
2
|
// and it triggers flow-check errors if used directly.
|
|
7
3
|
// By using the value exported here, flow-check passes successfully
|
|
8
4
|
// using a single FLOW_IGNORE suppress comment.
|
|
9
|
-
|
|
10
5
|
// $FlowIgnore: promisify.custom is missing in flow type signatures.
|
|
11
|
-
export const promisifyCustom = promisify.custom;
|
|
12
6
|
|
|
7
|
+
export const promisifyCustom = promisify.custom;
|
|
13
8
|
/*
|
|
14
9
|
* A small promisify helper to make it easier to customize a
|
|
15
10
|
* function promisified (using the 'util' module available in
|
|
@@ -21,8 +16,9 @@ export const promisifyCustom = promisify.custom;
|
|
|
21
16
|
* aCallbackBasedFn[promisify.custom] = multiArgsPromisedFn(tmp.dir);
|
|
22
17
|
* ...
|
|
23
18
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
|
|
20
|
+
export function multiArgsPromisedFn(fn) {
|
|
21
|
+
return (...callerArgs) => {
|
|
26
22
|
return new Promise((resolve, reject) => {
|
|
27
23
|
fn(...callerArgs, (err, ...rest) => {
|
|
28
24
|
if (err) {
|
|
@@ -34,3 +30,4 @@ export function multiArgsPromisedFn(fn: Function): Function {
|
|
|
34
30
|
});
|
|
35
31
|
};
|
|
36
32
|
}
|
|
33
|
+
//# sourceMappingURL=promisify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promisify.js","names":["promisify","promisifyCustom","custom","multiArgsPromisedFn","fn","callerArgs","Promise","resolve","reject","err","rest"],"sources":["../../src/util/promisify.js"],"sourcesContent":["/* @flow */\n\nimport {promisify} from 'util';\n\n// promisify.custom is missing from the node types know to flow,\n// and it triggers flow-check errors if used directly.\n// By using the value exported here, flow-check passes successfully\n// using a single FLOW_IGNORE suppress comment.\n\n// $FlowIgnore: promisify.custom is missing in flow type signatures.\nexport const promisifyCustom = promisify.custom;\n\n/*\n * A small promisify helper to make it easier to customize a\n * function promisified (using the 'util' module available in\n * nodejs >= 8) to resolve to an array of results:\n *\n * import {promisify} from 'util';\n * import {multiArgsPromisedFn} from '../util/promisify';\n *\n * aCallbackBasedFn[promisify.custom] = multiArgsPromisedFn(tmp.dir);\n * ...\n */\nexport function multiArgsPromisedFn(fn: Function): Function {\n return (...callerArgs: Array<any>): Promise<any> => {\n return new Promise((resolve, reject) => {\n fn(...callerArgs, (err, ...rest) => {\n if (err) {\n reject(err);\n } else {\n resolve(rest);\n }\n });\n });\n };\n}\n"],"mappings":"AAEA,SAAQA,SAAR,QAAwB,MAAxB,C,CAEA;AACA;AACA;AACA;AAEA;;AACA,OAAO,MAAMC,eAAe,GAAGD,SAAS,CAACE,MAAlC;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,mBAAT,CAA6BC,EAA7B,EAAqD;EAC1D,OAAO,CAAC,GAAGC,UAAJ,KAA6C;IAClD,OAAO,IAAIC,OAAJ,CAAY,CAACC,OAAD,EAAUC,MAAV,KAAqB;MACtCJ,EAAE,CAAC,GAAGC,UAAJ,EAAgB,CAACI,GAAD,EAAM,GAAGC,IAAT,KAAkB;QAClC,IAAID,GAAJ,EAAS;UACPD,MAAM,CAACC,GAAD,CAAN;QACD,CAFD,MAEO;UACLF,OAAO,CAACG,IAAD,CAAP;QACD;MACF,CANC,CAAF;IAOD,CARM,CAAP;EASD,CAVD;AAWD"}
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import type {Readable} from 'stream';
|
|
4
|
-
|
|
5
|
-
export function isTTY(stream: Readable): boolean {
|
|
1
|
+
export function isTTY(stream) {
|
|
6
2
|
// $FlowFixMe: flow complains that stream may not provide isTTY as a property.
|
|
7
3
|
return stream.isTTY;
|
|
8
4
|
}
|
|
9
|
-
|
|
10
|
-
export function setRawMode(stream: Readable, rawMode: boolean) {
|
|
5
|
+
export function setRawMode(stream, rawMode) {
|
|
11
6
|
// $FlowFixMe: flow complains that stdin may not provide setRawMode.
|
|
12
7
|
stream.setRawMode(rawMode);
|
|
13
8
|
}
|
|
9
|
+
//# sourceMappingURL=stdin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stdin.js","names":["isTTY","stream","setRawMode","rawMode"],"sources":["../../src/util/stdin.js"],"sourcesContent":["/* @flow */\n\nimport type {Readable} from 'stream';\n\nexport function isTTY(stream: Readable): boolean {\n // $FlowFixMe: flow complains that stream may not provide isTTY as a property.\n return stream.isTTY;\n}\n\nexport function setRawMode(stream: Readable, rawMode: boolean) {\n // $FlowFixMe: flow complains that stdin may not provide setRawMode.\n stream.setRawMode(rawMode);\n}\n"],"mappings":"AAIA,OAAO,SAASA,KAAT,CAAeC,MAAf,EAA0C;EAC/C;EACA,OAAOA,MAAM,CAACD,KAAd;AACD;AAED,OAAO,SAASE,UAAT,CAAoBD,MAApB,EAAsCE,OAAtC,EAAwD;EAC7D;EACAF,MAAM,CAACC,UAAP,CAAkBC,OAAlB;AACD"}
|
|
@@ -1,19 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
import {promisify} from 'util';
|
|
3
|
-
|
|
1
|
+
import { promisify } from 'util';
|
|
4
2
|
import tmp from 'tmp';
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const log = createLogger(__filename);
|
|
10
|
-
|
|
11
|
-
export type MakePromiseCallback = (tmpDir: TempDir) => any;
|
|
12
|
-
|
|
3
|
+
import { createLogger } from './logger.js';
|
|
4
|
+
import { multiArgsPromisedFn, promisifyCustom } from './promisify.js';
|
|
5
|
+
const log = createLogger(import.meta.url);
|
|
13
6
|
tmp.dir[promisifyCustom] = multiArgsPromisedFn(tmp.dir);
|
|
14
|
-
|
|
15
7
|
const createTempDir = promisify(tmp.dir);
|
|
16
|
-
|
|
17
8
|
/*
|
|
18
9
|
* Work with a self-destructing temporary directory in a promise chain.
|
|
19
10
|
*
|
|
@@ -29,16 +20,13 @@ const createTempDir = promisify(tmp.dir);
|
|
|
29
20
|
* );
|
|
30
21
|
*
|
|
31
22
|
*/
|
|
32
|
-
|
|
23
|
+
|
|
24
|
+
export function withTempDir(makePromise) {
|
|
33
25
|
const tmpDir = new TempDir();
|
|
34
|
-
return tmpDir.create()
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
})
|
|
38
|
-
.catch(tmpDir.errorHandler())
|
|
39
|
-
.then(tmpDir.successHandler());
|
|
26
|
+
return tmpDir.create().then(() => {
|
|
27
|
+
return makePromise(tmpDir);
|
|
28
|
+
}).catch(tmpDir.errorHandler()).then(tmpDir.successHandler());
|
|
40
29
|
}
|
|
41
|
-
|
|
42
30
|
/*
|
|
43
31
|
* Work with a self-destructing temporary directory object.
|
|
44
32
|
*
|
|
@@ -54,49 +42,50 @@ export function withTempDir(makePromise: MakePromiseCallback): Promise<any> {
|
|
|
54
42
|
* .then(tmpDir.successHandler());
|
|
55
43
|
*
|
|
56
44
|
*/
|
|
57
|
-
export class TempDir {
|
|
58
|
-
_path: string | void;
|
|
59
|
-
_removeTempDir: Function | void;
|
|
60
45
|
|
|
46
|
+
export class TempDir {
|
|
61
47
|
constructor() {
|
|
62
48
|
this._path = undefined;
|
|
63
49
|
this._removeTempDir = undefined;
|
|
64
50
|
}
|
|
65
|
-
|
|
66
51
|
/*
|
|
67
52
|
* Returns a promise that is fulfilled when the temp directory has
|
|
68
53
|
* been created.
|
|
69
54
|
*/
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return this;
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
create() {
|
|
58
|
+
return createTempDir({
|
|
59
|
+
prefix: 'tmp-web-ext-',
|
|
60
|
+
// This allows us to remove a non-empty tmp dir.
|
|
61
|
+
unsafeCleanup: true
|
|
62
|
+
}).then(([tmpPath, removeTempDir]) => {
|
|
63
|
+
this._path = tmpPath;
|
|
64
|
+
|
|
65
|
+
this._removeTempDir = () => new Promise((resolve, reject) => {
|
|
66
|
+
// `removeTempDir` parameter is a `next` callback which
|
|
67
|
+
// is called once the dir has been removed.
|
|
68
|
+
const next = err => err ? reject(err) : resolve();
|
|
69
|
+
|
|
70
|
+
removeTempDir(next);
|
|
87
71
|
});
|
|
88
|
-
}
|
|
89
72
|
|
|
73
|
+
log.debug(`Created temporary directory: ${this.path()}`);
|
|
74
|
+
return this;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
90
77
|
/*
|
|
91
78
|
* Get the absolute path of the temp directory.
|
|
92
79
|
*/
|
|
93
|
-
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
path() {
|
|
94
83
|
if (!this._path) {
|
|
95
84
|
throw new Error('You cannot access path() before calling create()');
|
|
96
85
|
}
|
|
86
|
+
|
|
97
87
|
return this._path;
|
|
98
88
|
}
|
|
99
|
-
|
|
100
89
|
/*
|
|
101
90
|
* Returns a callback that will catch an error, remove
|
|
102
91
|
* the temporary directory, and throw the error.
|
|
@@ -104,35 +93,41 @@ export class TempDir {
|
|
|
104
93
|
* This is intended for use in a promise like
|
|
105
94
|
* Promise().catch(tmp.errorHandler())
|
|
106
95
|
*/
|
|
107
|
-
|
|
108
|
-
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
errorHandler() {
|
|
99
|
+
return async error => {
|
|
109
100
|
await this.remove();
|
|
110
101
|
throw error;
|
|
111
102
|
};
|
|
112
103
|
}
|
|
113
|
-
|
|
114
104
|
/*
|
|
115
105
|
* Returns a callback that will remove the temporary direcotry.
|
|
116
106
|
*
|
|
117
107
|
* This is intended for use in a promise like
|
|
118
108
|
* Promise().then(tmp.successHandler())
|
|
119
109
|
*/
|
|
120
|
-
|
|
121
|
-
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
successHandler() {
|
|
113
|
+
return async promiseResult => {
|
|
122
114
|
await this.remove();
|
|
123
115
|
return promiseResult;
|
|
124
116
|
};
|
|
125
117
|
}
|
|
126
|
-
|
|
127
118
|
/*
|
|
128
119
|
* Remove the temp directory.
|
|
129
120
|
*/
|
|
130
|
-
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
remove() {
|
|
131
124
|
if (!this._removeTempDir) {
|
|
132
125
|
return;
|
|
133
126
|
}
|
|
127
|
+
|
|
134
128
|
log.debug(`Removing temporary directory: ${this.path()}`);
|
|
135
129
|
return this._removeTempDir && this._removeTempDir();
|
|
136
130
|
}
|
|
137
131
|
|
|
138
132
|
}
|
|
133
|
+
//# sourceMappingURL=temp-dir.js.map
|