@ulixee/commons
Advanced tools
Comparing version 2.0.0-alpha.19 to 2.0.0-alpha.20
@@ -6,2 +6,17 @@ # Change Log | ||
# [2.0.0-alpha.20](https://github.com/ulixee/shared/compare/v2.0.0-alpha.19...v2.0.0-alpha.20) (2023-04-19) | ||
### Bug Fixes | ||
* **commons:** always handle emitter errors ([1c5f60f](https://github.com/ulixee/shared/commit/1c5f60f21c4c174c99c10e9e9d2edb07b06c28a0)) | ||
* **commons:** global instance bug ([b895c0e](https://github.com/ulixee/shared/commit/b895c0e14602d92f42c559c6130d8a66b9b0770e)) | ||
* **commons:** global instance of check ([f51fed1](https://github.com/ulixee/shared/commit/f51fed1f93e4bfb2c603a0bced79e249ff76d003)) | ||
* **crypto:** disallow overwriting identity/address ([c14a185](https://github.com/ulixee/shared/commit/c14a1857c80ca800198d231236d5fcb6223026c9)) | ||
* tests + lint ([66e49ae](https://github.com/ulixee/shared/commit/66e49ae931b54fd8577711562c56e2494d8149bb)) | ||
# [2.0.0-alpha.19](https://github.com/ulixee/shared/compare/v2.0.0-alpha.18...v2.0.0-alpha.19) (2023-02-25) | ||
@@ -8,0 +23,0 @@ |
@@ -26,3 +26,3 @@ import { TypedEventEmitter } from '../lib/eventUtils'; | ||
nodePath: string; | ||
minerModulePath: string; | ||
cloudModulePath: string; | ||
} |
@@ -43,5 +43,5 @@ "use strict"; | ||
else { | ||
let minerModulePath; | ||
let cloudModulePath; | ||
try { | ||
minerModulePath = require.resolve('@ulixee/miner'); | ||
cloudModulePath = require.resolve('@ulixee/cloud'); | ||
} | ||
@@ -54,3 +54,3 @@ catch (err) { | ||
nodePath: process.execPath, | ||
minerModulePath, | ||
cloudModulePath, | ||
}; | ||
@@ -91,3 +91,6 @@ } | ||
const version = file.replace('.json', ''); | ||
this.hostByVersion[version] = JSON.parse(Fs.readFileSync(versionPath, 'utf8')); | ||
try { | ||
this.hostByVersion[version] = JSON.parse(Fs.readFileSync(versionPath, 'utf8')); | ||
} | ||
catch { } | ||
} | ||
@@ -94,0 +97,0 @@ } |
@@ -7,2 +7,3 @@ "use strict"; | ||
const fileUtils_1 = require("../lib/fileUtils"); | ||
const Callsite_1 = require("../lib/Callsite"); | ||
class UlixeeConfig { | ||
@@ -14,3 +15,5 @@ constructor(directoryPath) { | ||
if (data.datastoreOutDir) { | ||
this.datastoreOutDir = Path.isAbsolute(data.datastoreOutDir) ? data.datastoreOutDir : Path.resolve(this.directoryPath, data.datastoreOutDir); | ||
this.datastoreOutDir = Path.isAbsolute(data.datastoreOutDir) | ||
? data.datastoreOutDir | ||
: Path.resolve(this.directoryPath, data.datastoreOutDir); | ||
} | ||
@@ -61,3 +64,3 @@ } | ||
return { | ||
entrypoint: runtimeLocation?.entrypoint ?? require.main?.filename ?? process.argv[1], | ||
entrypoint: runtimeLocation?.entrypoint ?? Callsite_1.default.getEntrypoint(), | ||
workingDirectory: runtimeLocation?.workingDirectory ?? process.cwd(), | ||
@@ -64,0 +67,0 @@ }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CanceledPromiseError = void 0; | ||
const addGlobalInstance_1 = require("../lib/addGlobalInstance"); | ||
const TypeSerializer_1 = require("../lib/TypeSerializer"); | ||
@@ -12,3 +13,4 @@ class CanceledPromiseError extends Error { | ||
exports.CanceledPromiseError = CanceledPromiseError; | ||
(0, addGlobalInstance_1.default)(CanceledPromiseError); | ||
(0, TypeSerializer_1.registerSerializableErrorType)(CanceledPromiseError); | ||
//# sourceMappingURL=IPendingWaitEvent.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const TypeSerializer_1 = require("../lib/TypeSerializer"); | ||
const addGlobalInstance_1 = require("../lib/addGlobalInstance"); | ||
class TimeoutError extends Error { | ||
@@ -11,3 +12,4 @@ constructor(message) { | ||
exports.default = TimeoutError; | ||
(0, addGlobalInstance_1.default)(TimeoutError); | ||
(0, TypeSerializer_1.registerSerializableErrorType)(TimeoutError); | ||
//# sourceMappingURL=TimeoutError.js.map |
@@ -5,2 +5,3 @@ "use strict"; | ||
// eslint-disable-next-line max-classes-per-file | ||
const addGlobalInstance_1 = require("./addGlobalInstance"); | ||
class UlixeeError extends Error { | ||
@@ -36,2 +37,3 @@ constructor(message, code, data) { | ||
exports.APIError = APIError; | ||
(0, addGlobalInstance_1.default)(UlixeeError, APIError); | ||
//# sourceMappingURL=errors.js.map |
export declare function existsAsync(path: string): Promise<boolean>; | ||
export declare function copyDir(fromDir: string, toDir: string): Promise<void>; | ||
export declare function readFileAsJson<T>(path: string): Promise<T>; | ||
export declare function safeOverwriteFile(path: string, body: any): Promise<void>; | ||
export declare function cleanHomeDir(str: string): string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.cleanHomeDir = exports.safeOverwriteFile = exports.readFileAsJson = exports.existsAsync = void 0; | ||
exports.cleanHomeDir = exports.safeOverwriteFile = exports.readFileAsJson = exports.copyDir = exports.existsAsync = void 0; | ||
const fs_1 = require("fs"); | ||
@@ -17,2 +17,13 @@ const Os = require("os"); | ||
exports.existsAsync = existsAsync; | ||
async function copyDir(fromDir, toDir) { | ||
await fs_1.promises.mkdir(toDir, { recursive: true }); | ||
for (const file of await fs_1.promises.readdir(fromDir, { withFileTypes: true })) { | ||
const path = `${fromDir}/${file.name}`; | ||
if (file.isDirectory()) | ||
await copyDir(path, `${toDir}/${file.name}`); | ||
else | ||
await fs_1.promises.copyFile(path, `${toDir}/${file.name}`); | ||
} | ||
} | ||
exports.copyDir = copyDir; | ||
async function readFileAsJson(path) { | ||
@@ -19,0 +30,0 @@ const buffer = await fs_1.promises.readFile(path, 'utf8'); |
@@ -265,6 +265,6 @@ "use strict"; | ||
if (ns.includes('ulx:*') || ns.includes('ulx*') || ns === '*') { | ||
active.push(/desktop[/-]?.*/, /hero[/-].*/, /agent\/.*/, /plugins\/.*/, /net\/.*/, /datastore[/-].*/, /mainchain[/-].*/, /sidechain[/-].*/, /ramps[/-].*/, /DevtoolsSessionLogger/); | ||
active.push(/desktop[/-]?.*/, /hero[/-].*/, /agent\/.*/, /plugins\/.*/, /net\/.*/, /cloud\/.*/, /datastore[/-].*/, /mainchain[/-].*/, /sidechain[/-].*/, /ramps[/-].*/, /DevtoolsSessionLogger/); | ||
} | ||
else if (ns === 'ulx') { | ||
active.push(/hero[/-].*/, /agent\/.*/, /plugins\/.*/, /net\/.*/, /datastore[/-].*/, /mainchain[/-].*/, /sidechain[/-].*/, /ramps[/-].*/); | ||
active.push(/hero[/-].*/, /agent\/.*/, /plugins\/.*/, /net\/.*/, /cloud\/.*/, /datastore[/-].*/, /mainchain[/-].*/, /sidechain[/-].*/, /ramps[/-].*/); | ||
skip.push(/desktop[/-]?.*/, /DevtoolsSessionLogger/); | ||
@@ -271,0 +271,0 @@ } |
@@ -12,5 +12,5 @@ /// <reference types="node" /> | ||
static run(): Promise<void>; | ||
private static registerSignals; | ||
static registerSignals(): void; | ||
private static onSignal; | ||
} | ||
export {}; |
@@ -11,3 +11,6 @@ import { SourceMapConsumer } from 'source-map-js'; | ||
static install(): void; | ||
static getSourceFile(filename: string): string; | ||
static getSourceFile(filename: string): { | ||
path: string; | ||
content?: string; | ||
}; | ||
static getSourceFilePaths(filename: string): string[]; | ||
@@ -17,2 +20,3 @@ static getOriginalSourcePosition(position: ISourceCodeLocation, includeContent?: boolean): ISourceCodeLocation & { | ||
content?: string; | ||
source?: string; | ||
}; | ||
@@ -19,0 +23,0 @@ static retrieveSourceMap(source: string): { |
@@ -35,4 +35,7 @@ "use strict"; | ||
if (!this.sourceMapCache[filename].map) | ||
return filename; | ||
return { | ||
path: filename, | ||
}; | ||
let source = filename; | ||
let content; | ||
const sourceMap = this.sourceMapCache[filename]; | ||
@@ -42,5 +45,6 @@ sourceMap.map.eachMapping(mapping => { | ||
source = this.resolvePath(sourceMap.url, mapping.source); | ||
content = sourceMap.map.sourceContentFor(mapping.source, true); | ||
} | ||
}); | ||
return source; | ||
return { path: source, content }; | ||
} | ||
@@ -76,2 +80,3 @@ static getSourceFilePaths(filename) { | ||
return { | ||
source: originalPosition.source, | ||
filename, | ||
@@ -78,0 +83,0 @@ column: originalPosition.column, |
@@ -16,2 +16,3 @@ /// <reference types="node" /> | ||
private reemitterCountByEventType; | ||
constructor(); | ||
cancelPendingEvents(message?: string, excludeEvents?: (keyof T & string)[]): void; | ||
@@ -29,4 +30,5 @@ setEventsToLog<K extends keyof T & (string | symbol)>(logger: IBoundLog, events: K[]): void; | ||
prependOnceListener<K extends keyof T & (string | symbol)>(eventType: K, listenerFn: (this: this, event?: T[K]) => void, includeUnhandledEvents?: boolean): this; | ||
protected defaultErrorLogger(this: this, error: Error): void; | ||
private replayOrClearMissedEvents; | ||
private logEvent; | ||
} |
@@ -20,3 +20,3 @@ "use strict"; | ||
constructor() { | ||
super(...arguments); | ||
super(); | ||
this.storeEventsWithoutListeners = false; | ||
@@ -29,2 +29,7 @@ _TypedEventEmitter_logger.set(this, void 0); | ||
this.reemitterCountByEventType = {}; | ||
this.defaultErrorLogger = this.defaultErrorLogger.bind(this); | ||
if ('captureRejections' in this) | ||
this.captureRejections = true; | ||
// add an error logger as a backup | ||
super.on('error', this.defaultErrorLogger); | ||
} | ||
@@ -94,2 +99,6 @@ cancelPendingEvents(message, excludeEvents) { | ||
super.on(eventType, listenerFn); | ||
// if we're adding an error logger, we can remove the default logger | ||
if (eventType === 'error' && listenerFn !== this.defaultErrorLogger) { | ||
super.off('error', this.defaultErrorLogger); | ||
} | ||
this.onEventListenerAdded?.(eventType); | ||
@@ -99,2 +108,6 @@ return this.replayOrClearMissedEvents(includeUnhandledEvents, eventType); | ||
off(eventType, listenerFn) { | ||
// if we're adding an error logger, we can remove the default logger | ||
if (eventType === 'error' && listenerFn !== this.defaultErrorLogger) { | ||
super.on('error', this.defaultErrorLogger); | ||
} | ||
return super.off(eventType, listenerFn); | ||
@@ -134,2 +147,8 @@ } | ||
} | ||
defaultErrorLogger(error) { | ||
if (__classPrivateFieldGet(this, _TypedEventEmitter_logger, "f")) | ||
__classPrivateFieldGet(this, _TypedEventEmitter_logger, "f").error('EventListenerError', error); | ||
else | ||
console.warn('EventListenerError', error); | ||
} | ||
replayOrClearMissedEvents(shouldReplay, eventType) { | ||
@@ -136,0 +155,0 @@ const events = this.storedEventsByType.get(eventType); |
@@ -108,3 +108,6 @@ "use strict"; | ||
if (value instanceof Error || | ||
('stack' in value && 'name' in value && value.name?.endsWith?.('Error'))) { | ||
(type === 'object' && | ||
'stack' in value && | ||
'name' in value && | ||
value.name?.endsWith?.('Error'))) { | ||
const { name, message, stack, ...data } = value; | ||
@@ -166,3 +169,3 @@ const extras = this.replace(data, options); | ||
} | ||
if ('toJSON' in value) { | ||
if (type === 'object' && 'toJSON' in value) { | ||
return value.toJSON(); | ||
@@ -169,0 +172,0 @@ } |
import IResolvablePromise from '../interfaces/IResolvablePromise'; | ||
import ISourceCodeLocation from '../interfaces/ISourceCodeLocation'; | ||
export declare function assert(value: unknown, message?: string, reject?: any): void; | ||
export declare function isPortInUse(port: number | string): Promise<boolean>; | ||
export declare function getCallSite(priorToFilename?: string, endFilename?: string): ISourceCodeLocation[]; | ||
export declare function getCallsite(priorToFilename?: string, endFilename?: string): ISourceCodeLocation[]; | ||
export declare function escapeUnescapedChar(str: string, char: string): string; | ||
@@ -8,0 +5,0 @@ export declare function pickRandom<T>(array: T[]): T; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createPromise = exports.bindFunctions = exports.getPrototypeHierarchy = exports.getObjectFunctionProperties = exports.pickRandom = exports.escapeUnescapedChar = exports.getCallsite = exports.getCallSite = exports.isPortInUse = exports.assert = void 0; | ||
exports.createPromise = exports.bindFunctions = exports.getPrototypeHierarchy = exports.getObjectFunctionProperties = exports.pickRandom = exports.escapeUnescapedChar = exports.isPortInUse = exports.assert = void 0; | ||
const net = require("net"); | ||
@@ -39,45 +39,2 @@ const Resolvable_1 = require("./Resolvable"); | ||
exports.isPortInUse = isPortInUse; | ||
// @deprecated - change case... can't remove due to hero dependency | ||
function getCallSite(priorToFilename, endFilename) { | ||
return getCallsite(priorToFilename, endFilename); | ||
} | ||
exports.getCallSite = getCallSite; | ||
function getCallsite(priorToFilename, endFilename) { | ||
const startingPrepareStack = Error.prepareStackTrace; | ||
const startingTraceLimit = Error.stackTraceLimit; | ||
Error.stackTraceLimit = 25; | ||
Error.prepareStackTrace = (_, callsite) => { | ||
return callsite.map(x => ({ | ||
filename: x.getFileName(), | ||
line: x.getLineNumber(), | ||
column: x.getColumnNumber() - 1, | ||
})); | ||
}; | ||
const capture = {}; | ||
Error.captureStackTrace(capture); | ||
Error.stackTraceLimit = startingTraceLimit; | ||
let stack = capture.stack; | ||
Error.prepareStackTrace = startingPrepareStack; | ||
let startIndex = 1; | ||
if (priorToFilename) { | ||
const idx = stack.findIndex(x => x.filename === priorToFilename || x.filename?.endsWith(priorToFilename)); | ||
if (idx >= 0) | ||
startIndex = idx + 1; | ||
} | ||
stack = stack.slice(startIndex); | ||
if (endFilename) { | ||
let lastIdx = -1; | ||
for (let i = stack.length - 1; i >= 0; i -= 1) { | ||
const x = stack[i]; | ||
if (x.filename === endFilename || x.filename?.endsWith(endFilename)) { | ||
lastIdx = i; | ||
break; | ||
} | ||
} | ||
if (lastIdx >= 0) | ||
stack = stack.slice(0, lastIdx + 1); | ||
} | ||
return stack.filter(x => !!x.filename && !x.filename.startsWith('internal') && !x.filename.startsWith('node:internal')); | ||
} | ||
exports.getCallsite = getCallsite; | ||
function escapeUnescapedChar(str, char) { | ||
@@ -84,0 +41,0 @@ let i = str.indexOf(char); |
{ | ||
"name": "@ulixee/commons", | ||
"version": "2.0.0-alpha.19", | ||
"version": "2.0.0-alpha.20", | ||
"description": "Common utilities for Ulixee", | ||
@@ -19,3 +19,3 @@ "license": "MIT", | ||
}, | ||
"gitHead": "af8c0da6fa1440f18dcaf99c24461cce0990e838" | ||
"gitHead": "a37bbac9bb98e1e509cbff6b1324122eae62d1cc" | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const utils_1 = require("../lib/utils"); | ||
const Callsite_1 = require("../lib/Callsite"); | ||
const SourceLoader_1 = require("../lib/SourceLoader"); | ||
@@ -9,9 +9,9 @@ it('can lookup source code', () => { | ||
function loadCallsite() { | ||
callsite ?? (callsite = (0, utils_1.getCallsite)()); | ||
callsite ?? (callsite = Callsite_1.default.getSourceCodeLocation()); | ||
return callsite; | ||
} | ||
const site = loadCallsite(); | ||
expect(SourceLoader_1.default.getSource(site[0]).code).toBe(` callsite ??= getCallsite();`); | ||
expect(SourceLoader_1.default.getSource(site[0]).code).toBe(` callsite ??= Callsite.getSourceCodeLocation();`); | ||
expect(SourceLoader_1.default.getSource(site[1]).code).toBe(` const site = loadCallsite();`); | ||
}); | ||
//# sourceMappingURL=SourceLoader.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
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
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
Sorry, the diff of this file is not supported yet
247570
129
3468