@ulixee/commons
Advanced tools
Comparing version 1.5.11 to 2.0.0-alpha.1
@@ -49,2 +49,3 @@ "use strict"; | ||
cancelPendingEvents(message, excludeEvents) { | ||
this.storedEventsByType.clear(); | ||
const events = [...this.pendingWaitEventsById.values()]; | ||
@@ -51,0 +52,0 @@ this.pendingWaitEventsById.clear(); |
@@ -5,7 +5,6 @@ /// <reference types="node" /> | ||
declare class Log implements ILog { | ||
readonly level: string; | ||
readonly level: LogLevel; | ||
useColors: boolean; | ||
protected readonly boundContext: any; | ||
private readonly module; | ||
private readonly logLevel; | ||
constructor(module: NodeModule, boundContext?: any); | ||
@@ -28,2 +27,8 @@ stats(action: string, data?: ILogData): number; | ||
}; | ||
declare const logLevels: { | ||
stats: number; | ||
info: number; | ||
warn: number; | ||
error: number; | ||
}; | ||
export default function logger(module: NodeModule): ILogBuilder; | ||
@@ -49,5 +54,5 @@ declare const loggerSessionIdNames: Map<string, string>; | ||
} | ||
declare type LogLevel = 'stats' | 'info' | 'warn' | 'error'; | ||
declare type LogLevel = keyof typeof logLevels; | ||
interface ILogBuilder { | ||
log: ILog; | ||
} |
@@ -8,12 +8,16 @@ "use strict"; | ||
exports.hasBeenLoggedSymbol = hasBeenLoggedSymbol; | ||
const logFilters = { | ||
active: [], | ||
skip: [], | ||
enabledNamesCache: {}, | ||
}; | ||
let logId = 0; | ||
class Log { | ||
constructor(module, boundContext) { | ||
this.level = process.env.DEBUG ? 'stats' : 'error'; | ||
this.useColors = process.env.NODE_DISABLE_COLORS !== 'true' && process.env.NODE_DISABLE_COLORS !== '1'; | ||
this.boundContext = {}; | ||
this.logLevel = logLevels.indexOf(this.level); | ||
this.module = module ? extractPathFromModule(module) : ''; | ||
if (boundContext) | ||
this.boundContext = boundContext; | ||
this.level = isEnabled(this.module) ? 'stats' : 'error'; | ||
} | ||
@@ -86,3 +90,3 @@ stats(action, data) { | ||
}; | ||
if (logLevels.indexOf(level) >= this.logLevel) { | ||
if (logLevels[level] >= logLevels[this.level]) { | ||
this.logToConsole(level, entry); | ||
@@ -143,3 +147,3 @@ } | ||
exports.translateToPrintable = translateToPrintable; | ||
const logLevels = ['stats', 'info', 'warn', 'error']; | ||
const logLevels = { stats: 0, info: 1, warn: 2, error: 3 }; | ||
let logCreator = (module) => { | ||
@@ -181,2 +185,3 @@ const log = new Log(module); | ||
return fullPath | ||
.replace(/^(.*)[/\\]unblocked[/\\](.+)$/, '$2') | ||
.replace(/^(.*)[/\\]ulixee[/\\](.+)$/, '$2') | ||
@@ -186,2 +191,50 @@ .replace(/^(.*)[/\\]@ulixee[/\\](.+)$/, '$2') | ||
} | ||
/// LOG FILTERING ////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
function isEnabled(name) { | ||
if (name in logFilters.enabledNamesCache) | ||
return logFilters.enabledNamesCache[name]; | ||
if (name[name.length - 1] === '*') { | ||
return true; | ||
} | ||
for (const ns of logFilters.skip) { | ||
if (ns.test(name)) { | ||
logFilters.enabledNamesCache[name] = false; | ||
return false; | ||
} | ||
} | ||
for (const ns of logFilters.active) { | ||
if (ns.test(name)) { | ||
logFilters.enabledNamesCache[name] = true; | ||
return true; | ||
} | ||
} | ||
logFilters.enabledNamesCache[name] = false; | ||
return false; | ||
} | ||
function enable(namespaces) { | ||
const split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/); | ||
for (let part of split) { | ||
if (!part) | ||
continue; | ||
part = part.replace(/\*/g, '.*?'); | ||
if (part[0] === '-') { | ||
logFilters.skip.push(new RegExp('^' + part.slice(1) + '$')); | ||
} | ||
else { | ||
logFilters.active.push(new RegExp('^' + part + '$')); | ||
if (part.includes('sa:*') || part.includes('sa*')) { | ||
logFilters.active.push(/agent\/*/); | ||
} | ||
else if (part === 'sa') { | ||
logFilters.active.push(/agent\/*/); | ||
logFilters.skip.push(new RegExp('DevtoolsSessionLogger')); | ||
logFilters.skip.push(new RegExp(/agent\/mitm*/)); | ||
} | ||
else if (part.includes('sa:devtools')) { | ||
logFilters.active.push(new RegExp('DevtoolsSessionLogger')); | ||
} | ||
} | ||
} | ||
} | ||
enable(process.env.DEBUG); | ||
//# sourceMappingURL=Logger.js.map |
@@ -10,5 +10,6 @@ import IResolvablePromise from '../interfaces/IResolvablePromise'; | ||
get isActive(): boolean; | ||
get size(): number; | ||
activeCount: number; | ||
private abortPromise; | ||
private idleTimout; | ||
private activeCount; | ||
private stopDequeuing; | ||
@@ -15,0 +16,0 @@ private queue; |
@@ -13,4 +13,4 @@ "use strict"; | ||
this.idlePromise = (0, utils_1.createPromise)(); | ||
this.activeCount = 0; | ||
this.abortPromise = new Resolvable_1.default(); | ||
this.activeCount = 0; | ||
this.stopDequeuing = false; | ||
@@ -24,2 +24,5 @@ this.queue = []; | ||
} | ||
get size() { | ||
return this.queue.length; | ||
} | ||
run(cb, timeoutMillis) { | ||
@@ -26,0 +29,0 @@ const promise = (0, utils_1.createPromise)(timeoutMillis); |
{ | ||
"name": "@ulixee/commons", | ||
"version": "1.5.11", | ||
"version": "2.0.0-alpha.1", | ||
"description": "Common utilities for Ulixee", | ||
"repository": "git@github.com:ulixee/devenv.git", | ||
"repository": "git@github.com:ulixee/ulixee.git", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/ulixee/devenv/issues" | ||
"url": "https://github.com/ulixee/ulixee/issues" | ||
}, | ||
@@ -23,7 +23,7 @@ "author": "Data Liberation Foundation", | ||
"dependencies": { | ||
"devtools-protocol": "^0.0.981744", | ||
"https-proxy-agent": "^5.0.0", | ||
"source-map-js": "^1.0.1", | ||
"devtools-protocol": "^0.0.981744", | ||
"semver": "^7.3.7" | ||
"semver": "^7.3.7", | ||
"source-map-js": "^1.0.1" | ||
} | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// suppressing this error since including it requires puppet to be published | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
const hero_puppet_1 = require("@ulixee/hero-puppet"); | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
const default_browser_emulator_1 = require("@ulixee/default-browser-emulator"); | ||
const TypeSerializer_1 = require("../lib/TypeSerializer"); | ||
const IPendingWaitEvent_1 = require("../interfaces/IPendingWaitEvent"); | ||
const Logger_1 = require("../lib/Logger"); | ||
const { log } = (0, Logger_1.default)(module); | ||
let testObject; | ||
@@ -38,32 +31,2 @@ beforeAll(() => { | ||
}); | ||
test('should be able to serialize and deserialize in a browser window', async () => { | ||
const { browserEngine } = default_browser_emulator_1.default.selectBrowserMeta(); | ||
const puppet = new hero_puppet_1.default(browserEngine); | ||
try { | ||
await puppet.start(); | ||
const context = await puppet.newContext({ | ||
userAgentString: 'Page tests', | ||
// eslint-disable-next-line require-await | ||
async onNewPuppetPage() { | ||
return null; | ||
}, | ||
onNewPuppetContext() { | ||
return null; | ||
}, | ||
}, log); | ||
const page = await context.newPage(); | ||
await page.evaluate(`${TypeSerializer_1.stringifiedTypeSerializerClass}`); | ||
const serialized = TypeSerializer_1.default.stringify(testObject); | ||
const result = await page.evaluate(`(function() { | ||
const decodedInClient = TypeSerializer.parse(JSON.stringify(${serialized})); | ||
return TypeSerializer.stringify(decodedInClient); | ||
})()`); | ||
expect(typeof result).toBe('string'); | ||
const decoded = TypeSerializer_1.default.parse(result); | ||
expect(decoded).toEqual(testObject); | ||
} | ||
finally { | ||
await puppet.close(); | ||
} | ||
}); | ||
//# sourceMappingURL=TypeSerializer.test.js.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
191629
2767
1