addons-scanner-utils 16.1.0 → 17.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/dist/functions/index.d.ts +13 -7
- package/dist/functions/index.js +21 -9
- package/dist/functions/logger.d.ts +52 -0
- package/dist/functions/logger.js +76 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/io/base.d.ts +4 -4
- package/dist/io/base.js +5 -2
- package/dist/io/crx.d.ts +1 -1
- package/dist/io/crx.js +3 -3
- package/dist/io/directory.d.ts +1 -1
- package/dist/io/directory.js +4 -4
- package/dist/io/index.d.ts +1 -0
- package/dist/io/index.js +1 -0
- package/dist/io/logger.d.ts +7 -0
- package/dist/io/logger.js +2 -0
- package/dist/io/utils.d.ts +3 -3
- package/dist/io/utils.js +2 -2
- package/dist/io/xpi.d.ts +1 -1
- package/dist/io/xpi.js +13 -6
- package/dist/test-helpers.d.ts +2 -3
- package/dist/test-helpers.js +3 -10
- package/package.json +7 -2
- package/dist/stdio.d.ts +0 -30
- package/dist/stdio.js +0 -70
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { ErrorRequestHandler, Request, RequestHandler } from 'express';
|
|
2
|
+
import { Logger } from './logger';
|
|
2
3
|
/**
|
|
3
4
|
* Express error handling middleware that serializes an {@link AppError} to a
|
|
4
|
-
* JSON response and logs it.
|
|
5
|
+
* JSON response and logs it. Server errors (5xx) are logged with their stack
|
|
6
|
+
* trace, client errors (4xx) are logged as warnings.
|
|
5
7
|
*
|
|
6
|
-
* @param
|
|
8
|
+
* @param _logger - Logger to use (default: {@link getLogger})
|
|
7
9
|
*/
|
|
8
|
-
export declare const createErrorHandler: ({
|
|
9
|
-
|
|
10
|
+
export declare const createErrorHandler: ({ _logger }?: {
|
|
11
|
+
_logger?: Logger;
|
|
10
12
|
}) => ErrorRequestHandler;
|
|
11
13
|
/**
|
|
12
14
|
* Extended Express request type with additional properties added by the
|
|
@@ -17,6 +19,8 @@ export declare const createErrorHandler: ({ _console, }?: {
|
|
|
17
19
|
* @property amoRequestId - Value of the incoming `X-AMO-Request-ID` header, or
|
|
18
20
|
* a generated UUID when the header is absent. Exposed for convenience (e.g.
|
|
19
21
|
* logging) in addition to being stored in the request context.
|
|
22
|
+
*
|
|
23
|
+
* `req.logger` is declared on the Express `Request` type (see `logger.ts`).
|
|
20
24
|
*/
|
|
21
25
|
export type RequestWithExtraProps = Request & {
|
|
22
26
|
rawBody?: Buffer;
|
|
@@ -25,7 +29,8 @@ export type RequestWithExtraProps = Request & {
|
|
|
25
29
|
/**
|
|
26
30
|
* Configuration options for creating an Express application.
|
|
27
31
|
*
|
|
28
|
-
* @property
|
|
32
|
+
* @property _logger - Logger used by the application (default:
|
|
33
|
+
* {@link getLogger})
|
|
29
34
|
* @property _process - Process object for environment variables (for testing
|
|
30
35
|
* purposes)
|
|
31
36
|
* @property apiKeyEnvVarName - Environment variable name for the API key
|
|
@@ -34,7 +39,7 @@ export type RequestWithExtraProps = Request & {
|
|
|
34
39
|
* string, the value is passed to the bytes library for parsing.
|
|
35
40
|
*/
|
|
36
41
|
export type FunctionConfig = {
|
|
37
|
-
|
|
42
|
+
_logger?: Logger;
|
|
38
43
|
_process?: typeof process;
|
|
39
44
|
apiKeyEnvVarName?: string;
|
|
40
45
|
maxRequestBodySize?: string | number;
|
|
@@ -61,9 +66,10 @@ export type FunctionConfig = {
|
|
|
61
66
|
* - HMAC-SHA256: `Authorization: HMAC-SHA256 <digest>` (digest of request
|
|
62
67
|
* body)
|
|
63
68
|
*/
|
|
64
|
-
export declare const createExpressApp: ({
|
|
69
|
+
export declare const createExpressApp: ({ _logger, _process, apiKeyEnvVarName, maxRequestBodySize, }?: FunctionConfig) => (handler: RequestHandler) => import("express-serve-static-core").Express;
|
|
65
70
|
export * from './api';
|
|
66
71
|
export * from './auth';
|
|
67
72
|
export * from './download';
|
|
68
73
|
export * from './error';
|
|
74
|
+
export * from './logger';
|
|
69
75
|
export * from './request-context';
|
package/dist/functions/index.js
CHANGED
|
@@ -31,14 +31,16 @@ const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
|
31
31
|
const express_1 = __importDefault(require("express"));
|
|
32
32
|
const safe_compare_1 = __importDefault(require("safe-compare"));
|
|
33
33
|
const error_1 = require("./error");
|
|
34
|
+
const logger_1 = require("./logger");
|
|
34
35
|
const request_context_1 = require("./request-context");
|
|
35
36
|
/**
|
|
36
37
|
* Express error handling middleware that serializes an {@link AppError} to a
|
|
37
|
-
* JSON response and logs it.
|
|
38
|
+
* JSON response and logs it. Server errors (5xx) are logged with their stack
|
|
39
|
+
* trace, client errors (4xx) are logged as warnings.
|
|
38
40
|
*
|
|
39
|
-
* @param
|
|
41
|
+
* @param _logger - Logger to use (default: {@link getLogger})
|
|
40
42
|
*/
|
|
41
|
-
const createErrorHandler = ({
|
|
43
|
+
const createErrorHandler = ({ _logger = (0, logger_1.getLogger)() } = {}) =>
|
|
42
44
|
// Even though we are not using `next`, it must be kept because the Express
|
|
43
45
|
// error handler signature requires 4 arguments.
|
|
44
46
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -47,10 +49,14 @@ const createErrorHandler = ({ _console = console, } = {}) =>
|
|
|
47
49
|
error: err.message,
|
|
48
50
|
extra_info: err.extraInfo || null,
|
|
49
51
|
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
const status = err.status || 500;
|
|
53
|
+
res.status(status).json(error);
|
|
54
|
+
if (status >= 500) {
|
|
55
|
+
_logger.error({ err, status, extra_info: error.extra_info }, err.message);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
_logger.warn({ status, extra_info: error.extra_info }, err.message);
|
|
59
|
+
}
|
|
54
60
|
};
|
|
55
61
|
exports.createErrorHandler = createErrorHandler;
|
|
56
62
|
/**
|
|
@@ -75,7 +81,7 @@ exports.createErrorHandler = createErrorHandler;
|
|
|
75
81
|
* - HMAC-SHA256: `Authorization: HMAC-SHA256 <digest>` (digest of request
|
|
76
82
|
* body)
|
|
77
83
|
*/
|
|
78
|
-
const createExpressApp = ({
|
|
84
|
+
const createExpressApp = ({ _logger = (0, logger_1.getLogger)(), _process = process, apiKeyEnvVarName = 'LAMBDA_API_KEY', maxRequestBodySize = '1mb', } = {}) => (handler) => {
|
|
79
85
|
const app = (0, express_1.default)();
|
|
80
86
|
const apiKey = _process.env[apiKeyEnvVarName] || null;
|
|
81
87
|
if (apiKey) {
|
|
@@ -83,6 +89,11 @@ const createExpressApp = ({ _console = console, _process = process, apiKeyEnvVar
|
|
|
83
89
|
// eslint-disable-next-line no-param-reassign
|
|
84
90
|
delete _process.env[apiKeyEnvVarName];
|
|
85
91
|
}
|
|
92
|
+
// Expose the logger to every subsequent middleware.
|
|
93
|
+
app.use((req, res, next) => {
|
|
94
|
+
req.logger = _logger;
|
|
95
|
+
next();
|
|
96
|
+
});
|
|
86
97
|
// This is the options we pass to the `json()` middleware.
|
|
87
98
|
const jsonOptions = {
|
|
88
99
|
limit: maxRequestBodySize,
|
|
@@ -161,7 +172,7 @@ const createExpressApp = ({ _console = console, _process = process, apiKeyEnvVar
|
|
|
161
172
|
next((0, error_1.createAppError)({ message: 'not found', status: 404 }));
|
|
162
173
|
});
|
|
163
174
|
// Error handler.
|
|
164
|
-
app.use((0, exports.createErrorHandler)({
|
|
175
|
+
app.use((0, exports.createErrorHandler)({ _logger }));
|
|
165
176
|
return app;
|
|
166
177
|
};
|
|
167
178
|
exports.createExpressApp = createExpressApp;
|
|
@@ -169,4 +180,5 @@ __exportStar(require("./api"), exports);
|
|
|
169
180
|
__exportStar(require("./auth"), exports);
|
|
170
181
|
__exportStar(require("./download"), exports);
|
|
171
182
|
__exportStar(require("./error"), exports);
|
|
183
|
+
__exportStar(require("./logger"), exports);
|
|
172
184
|
__exportStar(require("./request-context"), exports);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { DestinationStream, Logger } from 'pino';
|
|
2
|
+
export type { Logger } from 'pino';
|
|
3
|
+
declare global {
|
|
4
|
+
namespace Express {
|
|
5
|
+
interface Request {
|
|
6
|
+
/**
|
|
7
|
+
* The logger of the app, set by `createExpressApp()`. Entries include the
|
|
8
|
+
* request ID.
|
|
9
|
+
*/
|
|
10
|
+
logger: Logger;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Map pino levels to Google Cloud Logging severities.
|
|
16
|
+
*/
|
|
17
|
+
declare const SEVERITIES: {
|
|
18
|
+
readonly trace: "DEBUG";
|
|
19
|
+
readonly debug: "DEBUG";
|
|
20
|
+
readonly info: "INFO";
|
|
21
|
+
readonly warn: "WARNING";
|
|
22
|
+
readonly error: "ERROR";
|
|
23
|
+
readonly fatal: "CRITICAL";
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* A log level. `silent` disables logging.
|
|
27
|
+
*/
|
|
28
|
+
export type LogLevel = keyof typeof SEVERITIES | 'silent';
|
|
29
|
+
/**
|
|
30
|
+
* Options for creating a logger.
|
|
31
|
+
*
|
|
32
|
+
* @property level - Minimum log level (default: `LOG_LEVEL` env var, or
|
|
33
|
+
* `info`)
|
|
34
|
+
* @property destination - Where to write logs (default: stderr)
|
|
35
|
+
* @property _process - Process object (for testing purposes)
|
|
36
|
+
*/
|
|
37
|
+
export type CreateLoggerOptions = {
|
|
38
|
+
level?: LogLevel;
|
|
39
|
+
destination?: DestinationStream;
|
|
40
|
+
_process?: typeof process;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Create a pino logger writing single-line JSON logs for Google Cloud Logging.
|
|
44
|
+
* Most consumers should use {@link getLogger} instead.
|
|
45
|
+
*
|
|
46
|
+
* @see https://cloud.google.com/logging/docs/structured-logging
|
|
47
|
+
*/
|
|
48
|
+
export declare const createLogger: ({ level, destination, _process, }?: CreateLoggerOptions) => Logger;
|
|
49
|
+
/**
|
|
50
|
+
* Return the shared logger, used by {@link createExpressApp} by default.
|
|
51
|
+
*/
|
|
52
|
+
export declare const getLogger: () => Logger;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getLogger = exports.createLogger = void 0;
|
|
7
|
+
const pino_1 = __importDefault(require("pino"));
|
|
8
|
+
const request_context_1 = require("./request-context");
|
|
9
|
+
/**
|
|
10
|
+
* Map pino levels to Google Cloud Logging severities.
|
|
11
|
+
*/
|
|
12
|
+
const SEVERITIES = {
|
|
13
|
+
trace: 'DEBUG',
|
|
14
|
+
debug: 'DEBUG',
|
|
15
|
+
info: 'INFO',
|
|
16
|
+
warn: 'WARNING',
|
|
17
|
+
error: 'ERROR',
|
|
18
|
+
fatal: 'CRITICAL',
|
|
19
|
+
};
|
|
20
|
+
const LOG_LEVELS = [...Object.keys(SEVERITIES), 'silent'];
|
|
21
|
+
const isLogLevel = (value) => LOG_LEVELS.includes(value);
|
|
22
|
+
/**
|
|
23
|
+
* Create a pino logger writing single-line JSON logs for Google Cloud Logging.
|
|
24
|
+
* Most consumers should use {@link getLogger} instead.
|
|
25
|
+
*
|
|
26
|
+
* @see https://cloud.google.com/logging/docs/structured-logging
|
|
27
|
+
*/
|
|
28
|
+
const createLogger = ({ level, destination, _process = process, } = {}) => {
|
|
29
|
+
// The level can come from an env var, so we validate it at runtime too and
|
|
30
|
+
// fall back to `info` when it is invalid.
|
|
31
|
+
const requestedLevel = level || _process.env.LOG_LEVEL || 'info';
|
|
32
|
+
const logLevel = isLogLevel(requestedLevel) ? requestedLevel : 'info';
|
|
33
|
+
const logger = (0, pino_1.default)({
|
|
34
|
+
level: logLevel,
|
|
35
|
+
messageKey: 'message',
|
|
36
|
+
timestamp: pino_1.default.stdTimeFunctions.isoTime,
|
|
37
|
+
base: {
|
|
38
|
+
// `K_SERVICE` is set by Cloud Run.
|
|
39
|
+
serviceContext: {
|
|
40
|
+
service: _process.env.K_SERVICE || _process.env.npm_package_name || 'local',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
formatters: {
|
|
44
|
+
level: (label) => {
|
|
45
|
+
var _a;
|
|
46
|
+
return ({
|
|
47
|
+
severity: (_a = SEVERITIES[label]) !== null && _a !== void 0 ? _a : 'DEFAULT',
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
// Cloud Error Reporting needs the stack trace in `stack_trace`.
|
|
51
|
+
log: (entry) => entry.err instanceof Error
|
|
52
|
+
? Object.assign(Object.assign({}, entry), { stack_trace: entry.err.stack }) : entry,
|
|
53
|
+
},
|
|
54
|
+
// Add the request ID when it is set.
|
|
55
|
+
mixin: () => {
|
|
56
|
+
const requestId = (0, request_context_1.getRequestId)();
|
|
57
|
+
return requestId ? { request_id: requestId } : {};
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
// Synchronous so that logs aren't lost on `process.exit()`.
|
|
61
|
+
destination !== null && destination !== void 0 ? destination : pino_1.default.destination({ dest: 2, sync: true }));
|
|
62
|
+
if (logLevel !== requestedLevel) {
|
|
63
|
+
logger.warn(`Invalid log level "${requestedLevel}", using "${logLevel}"`);
|
|
64
|
+
}
|
|
65
|
+
return logger;
|
|
66
|
+
};
|
|
67
|
+
exports.createLogger = createLogger;
|
|
68
|
+
let defaultLogger = null;
|
|
69
|
+
/**
|
|
70
|
+
* Return the shared logger, used by {@link createExpressApp} by default.
|
|
71
|
+
*/
|
|
72
|
+
const getLogger = () => {
|
|
73
|
+
defaultLogger !== null && defaultLogger !== void 0 ? defaultLogger : (defaultLogger = (0, exports.createLogger)());
|
|
74
|
+
return defaultLogger;
|
|
75
|
+
};
|
|
76
|
+
exports.getLogger = getLogger;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -17,5 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./const"), exports);
|
|
18
18
|
__exportStar(require("./functions"), exports);
|
|
19
19
|
__exportStar(require("./io"), exports);
|
|
20
|
-
__exportStar(require("./stdio"), exports);
|
|
21
20
|
__exportStar(require("./errors"), exports);
|
package/dist/io/base.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { Readable } from 'stream';
|
|
2
|
-
import {
|
|
2
|
+
import { IOLogger } from './logger';
|
|
3
3
|
type ScanFileFunction = (_path: string, isDirectory: boolean) => boolean;
|
|
4
4
|
type Files = Record<string, unknown>;
|
|
5
5
|
export type IOBaseConstructorParams = {
|
|
6
6
|
filePath: string;
|
|
7
|
-
|
|
7
|
+
logger: IOLogger;
|
|
8
8
|
};
|
|
9
9
|
export declare class IOBase {
|
|
10
10
|
path: string;
|
|
11
|
-
|
|
11
|
+
logger: IOLogger;
|
|
12
12
|
files: Files;
|
|
13
13
|
entries: string[];
|
|
14
14
|
maxSizeBytes: number;
|
|
15
15
|
shouldScanFile: ScanFileFunction;
|
|
16
|
-
constructor({ filePath,
|
|
16
|
+
constructor({ filePath, logger }: IOBaseConstructorParams);
|
|
17
17
|
setScanFileCallback(callback: ScanFileFunction): void;
|
|
18
18
|
getFile(path: string, fileStreamType?: 'stream' | 'string' | 'chunk'): Promise<string> | Promise<Readable> | Promise<Buffer<ArrayBufferLike>>;
|
|
19
19
|
getFilesByExt(...extensions: string[]): Promise<string[]>;
|
package/dist/io/base.js
CHANGED
|
@@ -16,9 +16,12 @@ const const_1 = require("./const");
|
|
|
16
16
|
* Base class for io operations for both an Xpi or a directory.
|
|
17
17
|
*/
|
|
18
18
|
class IOBase {
|
|
19
|
-
constructor({ filePath,
|
|
19
|
+
constructor({ filePath, logger }) {
|
|
20
|
+
if (!logger) {
|
|
21
|
+
throw new Error('The "logger" option is required.');
|
|
22
|
+
}
|
|
20
23
|
this.path = filePath;
|
|
21
|
-
this.
|
|
24
|
+
this.logger = logger;
|
|
22
25
|
this.files = {};
|
|
23
26
|
this.entries = [];
|
|
24
27
|
// If this is too large the node process will hit a RangeError
|
package/dist/io/crx.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ type CrxConstructorParams = IOBaseConstructorParams & {
|
|
|
11
11
|
export declare class Crx extends Xpi {
|
|
12
12
|
fs: typeof defaultFs;
|
|
13
13
|
parseCRX: typeof defaultParseCRX;
|
|
14
|
-
constructor({ filePath,
|
|
14
|
+
constructor({ filePath, logger, fs, parseCRX, zipLib, }: CrxConstructorParams);
|
|
15
15
|
open(): Promise<ZipFile>;
|
|
16
16
|
}
|
|
17
17
|
export {};
|
package/dist/io/crx.js
CHANGED
|
@@ -32,8 +32,8 @@ function defaultParseCRX(buf) {
|
|
|
32
32
|
* like an XPI after that.
|
|
33
33
|
*/
|
|
34
34
|
class Crx extends xpi_1.Xpi {
|
|
35
|
-
constructor({ filePath,
|
|
36
|
-
super({ filePath,
|
|
35
|
+
constructor({ filePath, logger, fs = fs_1.default, parseCRX = defaultParseCRX, zipLib = yauzl_1.default, }) {
|
|
36
|
+
super({ filePath, logger, zipLib, autoClose: true });
|
|
37
37
|
this.fs = fs;
|
|
38
38
|
this.parseCRX = parseCRX;
|
|
39
39
|
}
|
|
@@ -48,7 +48,7 @@ class Crx extends xpi_1.Xpi {
|
|
|
48
48
|
let zipBuffer;
|
|
49
49
|
try {
|
|
50
50
|
zipBuffer = this.parseCRX(buf);
|
|
51
|
-
this.
|
|
51
|
+
this.logger.debug('obtained zip data from CRX file');
|
|
52
52
|
}
|
|
53
53
|
catch (err2) {
|
|
54
54
|
reject(err2);
|
package/dist/io/directory.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ type Files = {
|
|
|
9
9
|
type DirectoryConstructorParams = IOBaseConstructorParams;
|
|
10
10
|
export declare class Directory extends IOBase {
|
|
11
11
|
files: Files;
|
|
12
|
-
constructor({ filePath,
|
|
12
|
+
constructor({ filePath, logger }: DirectoryConstructorParams);
|
|
13
13
|
getFiles(_walkPromise?: typeof walkPromise): Promise<Files>;
|
|
14
14
|
getPath(_path: string): Promise<string>;
|
|
15
15
|
getFileAsStream(_path: string, { encoding }?: {
|
package/dist/io/directory.js
CHANGED
|
@@ -21,8 +21,8 @@ const common_tags_1 = require("common-tags");
|
|
|
21
21
|
const base_1 = require("./base");
|
|
22
22
|
const utils_1 = require("./utils");
|
|
23
23
|
class Directory extends base_1.IOBase {
|
|
24
|
-
constructor({ filePath,
|
|
25
|
-
super({ filePath,
|
|
24
|
+
constructor({ filePath, logger }) {
|
|
25
|
+
super({ filePath, logger });
|
|
26
26
|
this.files = {};
|
|
27
27
|
}
|
|
28
28
|
getFiles() {
|
|
@@ -30,7 +30,7 @@ class Directory extends base_1.IOBase {
|
|
|
30
30
|
// If we have already processed this directory and have data on this
|
|
31
31
|
// instance return that.
|
|
32
32
|
if (Object.keys(this.files).length) {
|
|
33
|
-
this.
|
|
33
|
+
this.logger.debug((0, common_tags_1.oneLine) `Files already exist for directory
|
|
34
34
|
"${this.path}" returning cached data`);
|
|
35
35
|
return this.files;
|
|
36
36
|
}
|
|
@@ -38,7 +38,7 @@ class Directory extends base_1.IOBase {
|
|
|
38
38
|
shouldIncludePath: (_path, isDirectory) => {
|
|
39
39
|
return this.shouldScanFile(_path, isDirectory);
|
|
40
40
|
},
|
|
41
|
-
|
|
41
|
+
logger: this.logger,
|
|
42
42
|
});
|
|
43
43
|
this.files = files;
|
|
44
44
|
this.entries = Object.keys(files);
|
package/dist/io/index.d.ts
CHANGED
package/dist/io/index.js
CHANGED
package/dist/io/utils.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
|
-
import {
|
|
2
|
+
import { IOLogger } from './logger';
|
|
3
3
|
export declare const lstat: typeof fs.lstat.__promisify__;
|
|
4
4
|
export declare const readFile: typeof fs.readFile.__promisify__;
|
|
5
5
|
export declare const readdir: typeof fs.readdir.__promisify__;
|
|
6
6
|
export type WalkPromiseOptions = {
|
|
7
7
|
shouldIncludePath?: (_path: string, isDirectory: boolean) => boolean;
|
|
8
|
-
|
|
8
|
+
logger: IOLogger;
|
|
9
9
|
};
|
|
10
|
-
export declare function walkPromise(curPath: string, { shouldIncludePath,
|
|
10
|
+
export declare function walkPromise(curPath: string, { shouldIncludePath, logger }: WalkPromiseOptions): Promise<{
|
|
11
11
|
[path: string]: {
|
|
12
12
|
size: number;
|
|
13
13
|
};
|
package/dist/io/utils.js
CHANGED
|
@@ -22,7 +22,7 @@ const upath_1 = __importDefault(require("upath"));
|
|
|
22
22
|
exports.lstat = (0, util_1.promisify)(fs_1.default.lstat);
|
|
23
23
|
exports.readFile = (0, util_1.promisify)(fs_1.default.readFile);
|
|
24
24
|
exports.readdir = (0, util_1.promisify)(fs_1.default.readdir);
|
|
25
|
-
function walkPromise(curPath, { shouldIncludePath = () => true,
|
|
25
|
+
function walkPromise(curPath, { shouldIncludePath = () => true, logger }) {
|
|
26
26
|
const result = {};
|
|
27
27
|
// Set a basePath var with the initial path so all file paths (the result
|
|
28
28
|
// keys) can be relative to the starting point.
|
|
@@ -32,7 +32,7 @@ function walkPromise(curPath, { shouldIncludePath = () => true, stderr }) {
|
|
|
32
32
|
const stat = yield (0, exports.lstat)(_curPath);
|
|
33
33
|
const relPath = upath_1.default.toUnix(path_1.default.relative(basePath, _curPath));
|
|
34
34
|
if (!shouldIncludePath(relPath, stat.isDirectory())) {
|
|
35
|
-
|
|
35
|
+
logger.debug(`Skipping file path: ${relPath}`);
|
|
36
36
|
}
|
|
37
37
|
else if (stat.isFile()) {
|
|
38
38
|
const { size } = stat;
|
package/dist/io/xpi.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export declare class Xpi extends IOBase {
|
|
|
14
14
|
processed: boolean;
|
|
15
15
|
zipLib: typeof yauzl;
|
|
16
16
|
zipfile: ZipFile | undefined;
|
|
17
|
-
constructor({ autoClose, filePath,
|
|
17
|
+
constructor({ autoClose, filePath, logger, zipLib, }: XpiConstructorParams);
|
|
18
18
|
open(): Promise<ZipFile>;
|
|
19
19
|
handleEntry(entry: Entry, reject: (error: Error) => void): void;
|
|
20
20
|
getFiles(_onEventsSubscribed?: () => void): Promise<Files>;
|
package/dist/io/xpi.js
CHANGED
|
@@ -35,8 +35,8 @@ const escapeEntryName = (fileName) => {
|
|
|
35
35
|
* feature, so we can disable it if needed.
|
|
36
36
|
*/
|
|
37
37
|
class Xpi extends base_1.IOBase {
|
|
38
|
-
constructor({ autoClose = true, filePath,
|
|
39
|
-
super({ filePath,
|
|
38
|
+
constructor({ autoClose = true, filePath, logger, zipLib = yauzl_1.default, }) {
|
|
39
|
+
super({ filePath, logger });
|
|
40
40
|
this.autoClose = autoClose;
|
|
41
41
|
this.files = {};
|
|
42
42
|
this.processed = false;
|
|
@@ -83,11 +83,11 @@ class Xpi extends base_1.IOBase {
|
|
|
83
83
|
return;
|
|
84
84
|
}
|
|
85
85
|
if (!this.shouldScanFile(entry.fileName, false)) {
|
|
86
|
-
this.
|
|
86
|
+
this.logger.debug(`skipping file: ${entry.fileName}`);
|
|
87
87
|
return;
|
|
88
88
|
}
|
|
89
89
|
if (this.entries.includes(entry.fileName)) {
|
|
90
|
-
this.
|
|
90
|
+
this.logger.info((0, common_tags_1.oneLine) `found duplicate file entry: "${entry.fileName}"
|
|
91
91
|
in package`);
|
|
92
92
|
reject(new errors_1.DuplicateZipEntryError((0, common_tags_1.oneLine) `Entry "${entry.fileName}" has already
|
|
93
93
|
been seen`));
|
|
@@ -107,7 +107,7 @@ class Xpi extends base_1.IOBase {
|
|
|
107
107
|
wantedFiles[fileName] = this.files[fileName];
|
|
108
108
|
}
|
|
109
109
|
else {
|
|
110
|
-
this.
|
|
110
|
+
this.logger.debug(`skipping cached file: ${fileName}`);
|
|
111
111
|
}
|
|
112
112
|
});
|
|
113
113
|
return wantedFiles;
|
|
@@ -118,7 +118,14 @@ class Xpi extends base_1.IOBase {
|
|
|
118
118
|
reject(new errors_1.InvalidZipFileError(err.message));
|
|
119
119
|
});
|
|
120
120
|
zipfile.on('entry', (entry) => {
|
|
121
|
-
|
|
121
|
+
// An exception thrown in an event handler would not reject the
|
|
122
|
+
// promise, and it would never settle.
|
|
123
|
+
try {
|
|
124
|
+
this.handleEntry(entry, reject);
|
|
125
|
+
}
|
|
126
|
+
catch (err) {
|
|
127
|
+
reject(err instanceof Error ? err : new Error(String(err)));
|
|
128
|
+
}
|
|
122
129
|
});
|
|
123
130
|
// When the last entry has been processed, resolve the promise.
|
|
124
131
|
//
|
package/dist/test-helpers.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Readable } from 'stream';
|
|
2
2
|
import { ZipFile, RandomAccessReader } from 'yauzl';
|
|
3
|
-
import {
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const createFakeStderr: () => Stderr;
|
|
3
|
+
import { IOLogger } from './io/logger';
|
|
4
|
+
export declare const createFakeLogger: () => IOLogger;
|
|
6
5
|
export declare const readStringFromStream: (readStream: Readable, encoding: string | undefined) => Promise<string>;
|
|
7
6
|
export declare const createFakeFsStats: ({ isFile, isDirectory, }?: {
|
|
8
7
|
isFile?: boolean | undefined;
|
package/dist/test-helpers.js
CHANGED
|
@@ -1,21 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createFakeZipFile = exports.createFakeFsStats = exports.readStringFromStream = exports.
|
|
3
|
+
exports.createFakeZipFile = exports.createFakeFsStats = exports.readStringFromStream = exports.createFakeLogger = void 0;
|
|
4
4
|
const yauzl_1 = require("yauzl");
|
|
5
|
-
const
|
|
6
|
-
return {
|
|
7
|
-
write: jest.fn(),
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
exports.createFakeStdout = createFakeStdout;
|
|
11
|
-
const createFakeStderr = () => {
|
|
5
|
+
const createFakeLogger = () => {
|
|
12
6
|
return {
|
|
13
7
|
debug: jest.fn(),
|
|
14
|
-
error: jest.fn(),
|
|
15
8
|
info: jest.fn(),
|
|
16
9
|
};
|
|
17
10
|
};
|
|
18
|
-
exports.
|
|
11
|
+
exports.createFakeLogger = createFakeLogger;
|
|
19
12
|
const readStringFromStream = (readStream, encoding) => {
|
|
20
13
|
return new Promise((resolve, reject) => {
|
|
21
14
|
let content = '';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "addons-scanner-utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "17.0.0",
|
|
4
4
|
"description": "Various addons related helpers to build CLIs.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -45,12 +45,16 @@
|
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"express": "5.3.0",
|
|
48
|
+
"pino": "10.4.0",
|
|
48
49
|
"safe-compare": "1.1.4"
|
|
49
50
|
},
|
|
50
51
|
"peerDependenciesMeta": {
|
|
51
52
|
"express": {
|
|
52
53
|
"optional": true
|
|
53
54
|
},
|
|
55
|
+
"pino": {
|
|
56
|
+
"optional": true
|
|
57
|
+
},
|
|
54
58
|
"safe-compare": {
|
|
55
59
|
"optional": true
|
|
56
60
|
}
|
|
@@ -72,7 +76,8 @@
|
|
|
72
76
|
"eslint-plugin-amo": "^3.0.0",
|
|
73
77
|
"express": "5.3.0",
|
|
74
78
|
"jest": "^30.2.0",
|
|
75
|
-
"prettier": "3.
|
|
79
|
+
"prettier": "3.10.1",
|
|
80
|
+
"pino": "10.4.0",
|
|
76
81
|
"pretty-quick": "4.2.2",
|
|
77
82
|
"rimraf": "^6.1.0",
|
|
78
83
|
"safe-compare": "1.1.4",
|
package/dist/stdio.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export type Stderr = {
|
|
2
|
-
debug: (message: string) => void;
|
|
3
|
-
error: (message: string) => void;
|
|
4
|
-
info: (message: string) => void;
|
|
5
|
-
};
|
|
6
|
-
type CreateConsoleStderrParams = {
|
|
7
|
-
_console?: typeof console;
|
|
8
|
-
programName: string;
|
|
9
|
-
verboseLevel: number;
|
|
10
|
-
};
|
|
11
|
-
export declare const createConsoleStderr: ({ _console, programName, verboseLevel, }: CreateConsoleStderrParams) => Stderr;
|
|
12
|
-
export type InMemoryStderr = Stderr & {
|
|
13
|
-
messages: {
|
|
14
|
-
debug: string[];
|
|
15
|
-
error: string[];
|
|
16
|
-
info: string[];
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
export declare const createInMemoryStderr: () => InMemoryStderr;
|
|
20
|
-
export type Stdout = {
|
|
21
|
-
write: (message: string) => void;
|
|
22
|
-
};
|
|
23
|
-
export declare const createConsoleStdout: ({ _console }?: {
|
|
24
|
-
_console?: Console | undefined;
|
|
25
|
-
}) => Stdout;
|
|
26
|
-
export type InMemoryStdout = Stdout & {
|
|
27
|
-
output: string;
|
|
28
|
-
};
|
|
29
|
-
export declare const createInMemoryStdout: () => InMemoryStdout;
|
|
30
|
-
export {};
|
package/dist/stdio.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createInMemoryStdout = exports.createConsoleStdout = exports.createInMemoryStderr = exports.createConsoleStderr = void 0;
|
|
4
|
-
// Logs (for humans) should be sent to `stderr` so that we can pipe the
|
|
5
|
-
// `stdout` output to other tools. Verbosity is controlled by the
|
|
6
|
-
// `verboseLevel` argument (and the number of `-v` passed to the CLI).
|
|
7
|
-
//
|
|
8
|
-
// By default, only errors are shown.
|
|
9
|
-
const createConsoleStderr = ({ _console = console, programName, verboseLevel = 0, }) => {
|
|
10
|
-
const logWithPrefix = (message) => {
|
|
11
|
-
_console.error(`${programName}: ${message}`);
|
|
12
|
-
};
|
|
13
|
-
const stderr = {
|
|
14
|
-
error(message) {
|
|
15
|
-
if (verboseLevel >= 0) {
|
|
16
|
-
logWithPrefix(message);
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
info(message) {
|
|
20
|
-
if (verboseLevel >= 1) {
|
|
21
|
-
logWithPrefix(message);
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
debug(message) {
|
|
25
|
-
if (verboseLevel >= 2) {
|
|
26
|
-
logWithPrefix(message);
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
return stderr;
|
|
31
|
-
};
|
|
32
|
-
exports.createConsoleStderr = createConsoleStderr;
|
|
33
|
-
const createInMemoryStderr = () => {
|
|
34
|
-
return {
|
|
35
|
-
messages: {
|
|
36
|
-
debug: [],
|
|
37
|
-
error: [],
|
|
38
|
-
info: [],
|
|
39
|
-
},
|
|
40
|
-
debug(message) {
|
|
41
|
-
this.messages.debug.push(message);
|
|
42
|
-
},
|
|
43
|
-
error(message) {
|
|
44
|
-
this.messages.error.push(message);
|
|
45
|
-
},
|
|
46
|
-
info(message) {
|
|
47
|
-
this.messages.info.push(message);
|
|
48
|
-
},
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
exports.createInMemoryStderr = createInMemoryStderr;
|
|
52
|
-
// `stdout` should be used for final outputs, and usually once at the end of
|
|
53
|
-
// the command.
|
|
54
|
-
const createConsoleStdout = ({ _console = console } = {}) => {
|
|
55
|
-
return {
|
|
56
|
-
write(message) {
|
|
57
|
-
_console.log(message);
|
|
58
|
-
},
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
|
-
exports.createConsoleStdout = createConsoleStdout;
|
|
62
|
-
const createInMemoryStdout = () => {
|
|
63
|
-
return {
|
|
64
|
-
output: '',
|
|
65
|
-
write(message) {
|
|
66
|
-
this.output = message;
|
|
67
|
-
},
|
|
68
|
-
};
|
|
69
|
-
};
|
|
70
|
-
exports.createInMemoryStdout = createInMemoryStdout;
|