Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@waiting/shared-core

Package Overview
Dependencies
Maintainers
1
Versions
199
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@waiting/shared-core - npm Package Compare versions

Comparing version 21.2.1 to 21.3.0

tsconfig.base.json

7

dist/lib/callstack/types.d.ts

@@ -1,3 +0,3 @@

export interface CallerInfo {
path: string;
export interface CallerInfo extends CallerInfoBase {
srcPath: string;
fileName: string;

@@ -11,2 +11,5 @@ className: string;

enclosingColNumber: number;
}
export interface CallerInfoBase {
path: string;
line: number;

@@ -13,0 +16,0 @@ column: number;

/// <reference types="node" resolution-mode="require"/>
import { CallerInfo } from './types.js';
/**
* Nodejs execution options
* @description from process.execArgv and process.evn.NODE_OPTIONS
* @example return new Set(['--loader ts-node/esm', '--no-warnings'])
*/
export declare function retrieveNodeExecOptions(): Set<string>;
export declare function isExecWithEnableSourceMaps(): boolean;
/**
* the dep "source-map-support" should be installed

@@ -5,0 +12,0 @@ */

/* eslint-disable @typescript-eslint/no-unsafe-call */
// import { findSourceMap, SourceMap } from 'module'
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import assert from 'node:assert/strict';
import { install } from 'source-map-support';
import { normalize } from 'node:path';
import semver from 'semver';
const maxStackDepth = 128;
const initInfoBase = {
path: '',
line: -1,
column: -1,
};
const initInfo = {
path: '',
srcPath: '',
line: -1,

@@ -19,5 +26,28 @@ column: -1,

};
// Save original Error.prepareStackTrace
const origPrepareStackTrace = Error.prepareStackTrace;
const nodeVersion = semver.coerce(process.version);
const isNodeGteV20 = nodeVersion ? semver.gte(nodeVersion, '20.0.0') : false;
/**
* Nodejs execution options
* @description from process.execArgv and process.evn.NODE_OPTIONS
* @example return new Set(['--loader ts-node/esm', '--no-warnings'])
*/
export function retrieveNodeExecOptions() {
const ret = new Set(process.execArgv);
const line = process.env['NODE_OPTIONS'] ?? '';
const opts = line.trim();
// opts: ' --loader ts-node/esm --no-warnings '
opts.split(/(?=--)/u).forEach((opt) => {
const txt = opt.trim();
if (txt.startsWith('--')) {
ret.add(txt.replace(/\s{2,}/ug, ' '));
}
});
return ret;
}
export function isExecWithEnableSourceMaps() {
const opts = retrieveNodeExecOptions();
const ret = opts.has('--enable-source-maps');
return ret;
}
/**
* the dep "source-map-support" should be installed

@@ -76,27 +106,27 @@ */

}
const stack = Error.prepareStackTrace?.(new Error(), [site]);
if (!stack) {
const stack = getStack();
if (!stack.length) {
return info;
}
// const stack = getStack()
const arr = stack.split('\n');
// const [line2] = arr.slice(depth + 1, depth + 2)
const line2 = arr[1];
if (!line2) {
throw new Error('Retrieve stack of caller failed, line empty.');
}
const path = retrievePath(line2);
const matched2 = /^(.+):(\d+):(\d+)$/u.exec(path);
if (!matched2 || matched2.length !== 4) {
throw new Error('Retrieve stack of caller failed. ' + (matched2 ? matched2.toString() : ''));
}
const [, , m2, m3] = matched2;
if (!m2 || !m3) {
throw new Error('Retrieved stack of caller empty. ' + matched2.toString());
}
const line2 = arr[depth + 1];
assert(line2, 'Retrieve stack of caller failed, line empty.');
const infoBase = retrieveInfoPathWithLineCol(line2);
const srcPath = infoBase.path && !infoBase.path.startsWith('file:///')
? 'file:///' + normalize(infoBase.path).replace(/\\/ug, '/')
: infoBase.path;
const caller = {
...info,
line: +m2,
column: +m3,
line: infoBase.line,
column: infoBase.column,
srcPath,
};
if (isNodeGteV20 && !isExecWithEnableSourceMaps()) {
const str = caller.path.toLowerCase();
if (str.endsWith('.ts') || str.endsWith('.mts')) {
if (caller.line === caller.lineNumber && caller.column === caller.columnNumber) {
console.warn(`Warning getCallerStack(): Nodejs >= 20.0.0, but not exec with --enable-source-maps. return line and column may incorrect. \n file: "${caller.path}"`);
}
}
}
return caller;

@@ -109,45 +139,56 @@ }

export function getStack() {
let fn = origPrepareStackTrace;
/* c8 ignore else */
if (!fn) {
// MUST installing inner getStack()
install();
/* c8 ignore else */
if (!Error.prepareStackTrace) {
throw new Error('Error.prepareStackTrace not defined');
}
fn = Error.prepareStackTrace;
const ret = isNodeGteV20
? getStackCurrent()
: getStackOld();
return ret;
}
/**
* For node < v20
*/
function getStackOld() {
const _prepareStackTrace = Error.prepareStackTrace;
const sites = getStackCallerSites(maxStackDepth).slice(2);
if (_prepareStackTrace && sites.length) {
const stack = _prepareStackTrace(new Error(), sites);
return stack;
}
// void else in debug hooked by source-map-support already
Error.prepareStackTrace = function (err, structuredStackTrace) {
const target = structuredStackTrace.slice(1);
// @ts-expect-error
const ret = fn(err, target);
return ret;
};
const limit = Error.stackTraceLimit;
// Error.stackTraceLimit = depth + 2
return '';
}
/**
* For node >= v20
*/
function getStackCurrent() {
const err = new Error();
const { stack } = err;
// Restore original `Error.prepareStackTrace`
Error.prepareStackTrace = origPrepareStackTrace;
Error.stackTraceLimit = limit;
if (!stack) {
throw new Error('stack EMPTY!');
assert(stack, 'stack EMPTY!');
const arr = stack.split('\n');
const arr2 = arr.slice(0, 1).concat(arr.slice(3));
const line = arr2[1];
const { path } = retrieveInfoPathWithLineCol(line ?? '');
if (path.endsWith('.ts') || path.endsWith('.mts')) {
if (isNodeGteV20 && !isExecWithEnableSourceMaps()) {
console.warn(`Warning getCallerStack(): Nodejs >= 20.0.0, but not exec with --enable-source-maps. return line and column may incorrect.
file: "${line ?? path}"`);
}
}
return stack;
// const sites = callsites()
// assert(sites?.length > 0, 'callsites() empty'
// console.info({ sites })
// const site1 = sites[1]
// const site2 = sites[2]
// const site3 = sites[3]
// const info1 = {
// path: site1.ge,
// }
// console.log({
// })
const ret = arr2.join('\n');
return ret;
}
export function getStackCallerSites(stackTraceLimit = 10) {
let fn = origPrepareStackTrace;
/* c8 ignore else */
if (!fn) {
// MUST installing inner getStack()
install();
/* c8 ignore else */
if (!Error.prepareStackTrace) {
throw new Error('Error.prepareStackTrace not defined');
}
fn = Error.prepareStackTrace;
}
// void else in debug hooked by source-map-support already
const _prepareStackTrace = Error.prepareStackTrace;
const limit = Error.stackTraceLimit;
// if (! _prepareStackTrace) {
// install()
// }
Error.prepareStackTrace = function (_, structuredStackTrace) {

@@ -157,3 +198,2 @@ const target = structuredStackTrace.slice(1);

};
const limit = Error.stackTraceLimit;
Error.stackTraceLimit = stackTraceLimit >= 0 ? stackTraceLimit + 1 : 11;

@@ -163,10 +203,8 @@ const err = new Error();

// Restore original `Error.prepareStackTrace`
Error.prepareStackTrace = fn;
Error.prepareStackTrace = _prepareStackTrace;
Error.stackTraceLimit = limit;
if (!stacks) {
throw new Error('stacks EMPTY!');
}
assert(stacks, 'stacks EMPTY!');
return stacks;
}
function retrievePath(line) {
function retrievePathWithLineCol(line) {
let path = '';

@@ -178,10 +216,14 @@ if (line.includes('(')) {

}
// else if (line.includes(' at ')) {
else if (line.startsWith('file://')) {
path = line;
}
else if (/^\s*at .+?\d+:\d+$/u.test(line) === true) {
// " at ...\\call-config.ts:24:12"
path = line.slice(line.indexOf('at') + 3, -1);
const txt = line.slice(line.indexOf('at') + 3);
const last = txt.slice(-1);
path = typeof +last === 'number'
? txt
: txt.slice(0, -1);
// console.log('debug01', { path, line })
}
else if (line.startsWith('file://')) {
path = line;
}
else {

@@ -195,2 +237,19 @@ throw new Error('Retrieve stack of caller failed. ' + line);

}
function retrieveInfoPathWithLineCol(line) {
const ret = {
...initInfoBase,
};
const path = retrievePathWithLineCol(line);
const matched2 = /^(.+):(\d+):(\d+)$/u.exec(path);
if (!matched2 || matched2.length !== 4) {
throw new Error('Retrieve stack of caller failed. ' + (matched2 ? matched2.toString() : ''));
}
const [, m1, m2, m3] = matched2;
assert(m1, 'path EMPTY!');
assert(m2 && m3, 'line or column EMPTY!' + matched2.toString());
ret.path = m1.trim();
ret.line = +m2;
ret.column = +m3;
return ret;
}
//# sourceMappingURL=util.js.map
{
"name": "@waiting/shared-core",
"author": "waiting",
"version": "21.2.1",
"version": "21.3.0",
"description": "node core function re export with Promise or Observable",

@@ -31,5 +31,5 @@ "keywords": [

"dependencies": {
"@waiting/shared-types": "^21.2.0",
"@waiting/shared-types": "^21.3.0",
"rxjs": "^7.8.0",
"source-map-support": "^0.5.21"
"semver": "^7.5.4"
},

@@ -42,7 +42,9 @@ "devDependencies": {

"engines": {
"node": ">=16.13.0 <=19.9.0"
"node": ">=16.13.0"
},
"files": [
"README.*.md",
"Dockerfile",
"tsconfig.json",
"Dockerfile",
"tsconfig.base.json",
"src/**/*.ts",

@@ -60,3 +62,3 @@ "bin/*.js",

"clean:lock": "rm package-lock.json -f",
"cov": "cross-env TS_NODE_PROJECT=test/tsconfig.json c8 mocha --loader=ts-node/esm --parallel=false",
"cov": "cross-env TS_NODE_PROJECT=test/tsconfig.json c8 mocha --parallel=false",
"lint": "eslint --fix --cache {src,test}/**/*.ts",

@@ -66,10 +68,10 @@ "lint:nofix": "eslint --cache {src,test}/**/*.ts",

"rp": "rollup -c rollup.config.js --context this",
"pretest": "npm run build",
"prepack": "rm -f dist/tsconfig.tsbuildinfo",
"pretest": "npm run build",
"pretest:local": "npm run build",
"test": "cross-env TS_NODE_PROJECT=test/tsconfig.json mocha --loader=ts-node/esm",
"test:local": "cross-env TS_NODE_PROJECT=test/tsconfig.json ../../node_modules/.bin/mocha --loader=ts-node/esm --parallel=false",
"test": "cross-env TS_NODE_PROJECT=test/tsconfig.json mocha ",
"test:local": "cross-env TS_NODE_PROJECT=test/tsconfig.json ../../node_modules/.bin/mocha --parallel=false",
"tsc": "tsc -b "
},
"gitHead": "973c7eea0bbddc15143086139e2a06ab6f34eae8"
"gitHead": "e4ddd8a76ca8c6f4482452d4e8386f0006ed06b2"
}
export interface CallerInfo {
path: string
export interface CallerInfo extends CallerInfoBase {
srcPath: string
// from StackFram

@@ -13,2 +13,6 @@ fileName: string

enclosingColNumber: number
}
export interface CallerInfoBase {
path: string
line: number

@@ -15,0 +19,0 @@ column: number

/* eslint-disable @typescript-eslint/no-unsafe-call */
// import { findSourceMap, SourceMap } from 'module'
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import assert from 'node:assert/strict'
import { normalize } from 'node:path'
import { install } from 'source-map-support'
import semver from 'semver'
// import { install } from 'source-map-support'
import { CallerInfo } from './types.js'
import { CallerInfo, CallerInfoBase } from './types.js'
const maxStackDepth = 128
const initInfoBase: CallerInfoBase = {
path: '',
line: -1,
column: -1,
}
const initInfo: CallerInfo = {
path: '',
srcPath: '',
line: -1,

@@ -26,6 +35,32 @@ column: -1,

// Save original Error.prepareStackTrace
const origPrepareStackTrace = Error.prepareStackTrace
const nodeVersion = semver.coerce(process.version)
const isNodeGteV20 = nodeVersion ? semver.gte(nodeVersion, '20.0.0') : false
/**
* Nodejs execution options
* @description from process.execArgv and process.evn.NODE_OPTIONS
* @example return new Set(['--loader ts-node/esm', '--no-warnings'])
*/
export function retrieveNodeExecOptions(): Set<string> {
const ret = new Set<string>(process.execArgv)
const line = process.env['NODE_OPTIONS'] ?? ''
const opts = line.trim()
// opts: ' --loader ts-node/esm --no-warnings '
opts.split(/(?=--)/u).forEach((opt) => {
const txt = opt.trim()
if (txt.startsWith('--')) {
ret.add(txt.replace(/\s{2,}/ug, ' '))
}
})
return ret
}
export function isExecWithEnableSourceMaps(): boolean {
const opts = retrieveNodeExecOptions()
const ret = opts.has('--enable-source-maps')
return ret
}
/**

@@ -92,2 +127,3 @@ * the dep "source-map-support" should be installed

}
if (! retrievePosition) {

@@ -97,30 +133,31 @@ return info

const stack = Error.prepareStackTrace?.(new Error(), [site]) as string | undefined
if (! stack) {
const stack = getStack()
if (! stack.length) {
return info
}
// const stack = getStack()
const arr = stack.split('\n')
// const [line2] = arr.slice(depth + 1, depth + 2)
const line2 = arr[1]
if (! line2) {
throw new Error('Retrieve stack of caller failed, line empty.')
}
const path = retrievePath(line2)
const matched2 = /^(.+):(\d+):(\d+)$/u.exec(path)
if (! matched2 || matched2.length !== 4) {
throw new Error('Retrieve stack of caller failed. ' + (matched2 ? matched2.toString() : ''))
}
const [, , m2, m3] = matched2
if (! m2 || ! m3) {
throw new Error('Retrieved stack of caller empty. ' + matched2.toString())
}
const line2 = arr[depth + 1]
assert(line2, 'Retrieve stack of caller failed, line empty.')
const infoBase = retrieveInfoPathWithLineCol(line2)
const srcPath = infoBase.path && ! infoBase.path.startsWith('file:///')
? 'file:///' + normalize(infoBase.path).replace(/\\/ug, '/')
: infoBase.path
const caller: CallerInfo = {
...info,
line: +m2,
column: +m3,
line: infoBase.line,
column: infoBase.column,
srcPath,
}
if (isNodeGteV20 && ! isExecWithEnableSourceMaps()) {
const str = caller.path.toLowerCase()
if (str.endsWith('.ts') || str.endsWith('.mts')) {
if (caller.line === caller.lineNumber && caller.column === caller.columnNumber) {
console.warn(
`Warning getCallerStack(): Nodejs >= 20.0.0, but not exec with --enable-source-maps. return line and column may incorrect. \n file: "${caller.path}"`,
)
}
}
}
return caller

@@ -134,55 +171,71 @@ }

export function getStack(): string {
let fn = origPrepareStackTrace
/* c8 ignore else */
if (! fn) {
// MUST installing inner getStack()
install()
const ret = isNodeGteV20
? getStackCurrent()
: getStackOld()
return ret
}
/* c8 ignore else */
if (! Error.prepareStackTrace) {
throw new Error('Error.prepareStackTrace not defined')
}
fn = Error.prepareStackTrace
}
// void else in debug hooked by source-map-support already
/**
* For node < v20
*/
function getStackOld(): string {
const _prepareStackTrace = Error.prepareStackTrace
const sites = getStackCallerSites(maxStackDepth).slice(2)
Error.prepareStackTrace = function(err: Error, structuredStackTrace: NodeJS.CallSite[]): string {
const target = structuredStackTrace.slice(1)
// @ts-expect-error
const ret = fn(err, target) as string
return ret
if (_prepareStackTrace && sites.length) {
const stack = _prepareStackTrace(new Error(), sites) as string
return stack
}
const limit = Error.stackTraceLimit
// Error.stackTraceLimit = depth + 2
return ''
}
/**
* For node >= v20
*/
function getStackCurrent(): string {
const err = new Error()
const { stack } = err
assert(stack, 'stack EMPTY!')
// Restore original `Error.prepareStackTrace`
Error.prepareStackTrace = origPrepareStackTrace
Error.stackTraceLimit = limit
if (! stack) {
throw new Error('stack EMPTY!')
const arr = stack.split('\n')
const arr2 = arr.slice(0, 1).concat(arr.slice(3))
const line = arr2[1]
const { path } = retrieveInfoPathWithLineCol(line ?? '')
if (path.endsWith('.ts') || path.endsWith('.mts')) {
if (isNodeGteV20 && ! isExecWithEnableSourceMaps()) {
console.warn(
`Warning getCallerStack(): Nodejs >= 20.0.0, but not exec with --enable-source-maps. return line and column may incorrect.
file: "${line ?? path}"`,
)
}
}
// const sites = callsites()
// assert(sites?.length > 0, 'callsites() empty'
// console.info({ sites })
// const site1 = sites[1]
// const site2 = sites[2]
// const site3 = sites[3]
return stack
// const info1 = {
// path: site1.ge,
// }
// console.log({
// })
const ret = arr2.join('\n')
return ret
}
export function getStackCallerSites(stackTraceLimit = 10): NodeJS.CallSite[] {
let fn = origPrepareStackTrace
/* c8 ignore else */
if (! fn) {
// MUST installing inner getStack()
install()
const _prepareStackTrace = Error.prepareStackTrace
const limit = Error.stackTraceLimit
/* c8 ignore else */
if (! Error.prepareStackTrace) {
throw new Error('Error.prepareStackTrace not defined')
}
fn = Error.prepareStackTrace
}
// void else in debug hooked by source-map-support already
// if (! _prepareStackTrace) {
// install()
// }

@@ -193,4 +246,2 @@ Error.prepareStackTrace = function(_: Error, structuredStackTrace: NodeJS.CallSite[]): NodeJS.CallSite[] {

}
const limit = Error.stackTraceLimit
Error.stackTraceLimit = stackTraceLimit >= 0 ? stackTraceLimit + 1 : 11

@@ -202,13 +253,10 @@

// Restore original `Error.prepareStackTrace`
Error.prepareStackTrace = fn
Error.prepareStackTrace = _prepareStackTrace
Error.stackTraceLimit = limit
if (! stacks) {
throw new Error('stacks EMPTY!')
}
assert(stacks, 'stacks EMPTY!')
return stacks
}
function retrievePath(line: string): string {
function retrievePathWithLineCol(line: string): string {
let path = ''

@@ -220,10 +268,14 @@ if (line.includes('(')) {

}
// else if (line.includes(' at ')) {
else if (line.startsWith('file://')) {
path = line
}
else if (/^\s*at .+?\d+:\d+$/u.test(line) === true) {
// " at ...\\call-config.ts:24:12"
path = line.slice(line.indexOf('at') + 3, -1)
const txt = line.slice(line.indexOf('at') + 3)
const last = txt.slice(-1)
path = typeof +last === 'number'
? txt
: txt.slice(0, -1)
// console.log('debug01', { path, line })
}
else if (line.startsWith('file://')) {
path = line
}
else {

@@ -239,1 +291,22 @@ throw new Error('Retrieve stack of caller failed. ' + line)

}
function retrieveInfoPathWithLineCol(line: string): CallerInfoBase {
const ret: CallerInfoBase = {
...initInfoBase,
}
const path = retrievePathWithLineCol(line)
const matched2 = /^(.+):(\d+):(\d+)$/u.exec(path)
if (! matched2 || matched2.length !== 4) {
throw new Error('Retrieve stack of caller failed. ' + (matched2 ? matched2.toString() : ''))
}
const [, m1, m2, m3] = matched2
assert(m1, 'path EMPTY!')
assert(m2 && m3, 'line or column EMPTY!' + matched2.toString())
ret.path = m1.trim()
ret.line = +m2
ret.column = +m3
return ret
}
{
"compilerOptions": {
"baseUrl": ".",
"declaration": true,
"declarationMap": true,
"emitDecoratorMetadata": true,
"esModuleInterop": true,
"exactOptionalPropertyTypes": true,
"experimentalDecorators": true,
"forceConsistentCasingInFileNames": true,
"incremental": true,
"module": "NodeNext",
"moduleResolution": "NodeNext",
"newLine": "lf",
"noFallthroughCasesInSwitch": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noUncheckedIndexedAccess": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"outDir": "dist",
"paths": {
"~/*": ["./src/*"],
"@/*": ["./test/*"]
},
"preserveConstEnums": true,
"pretty": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"strictPropertyInitialization": false,
"stripInternal": true,
"target": "ES2022",
"tsBuildInfoFile": ".vscode/.tsbuildinfo",
"types" : ["mocha", "node"]
},
"ts-node": {
"esm": true,
"experimentalResolver": true,
"experimentalSpecifierResolution": "node",
"preferTsExts": true,
"transpileOnly": false
},
"include": [
"src/**/*.ts"
],
"exclude": [
"asset",
"app/public",
"app/views",
"dist",
"node_modules*",
"test",
"**/*.d.ts",
"**/*.spec.ts"
]
"extends": "./tsconfig.base.json"
}

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc