@crawlee/utils
Advanced tools
Comparing version 3.12.3-beta.27 to 3.12.3-beta.28
@@ -15,3 +15,5 @@ export * from './internals/blocked'; | ||
export * from './internals/url'; | ||
export { getCurrentCpuTicksV2 } from './internals/systemInfoV2/cpu-info'; | ||
export { getMemoryInfoV2 } from './internals/systemInfoV2/memory-info'; | ||
export { Dictionary, Awaitable, Constructor } from '@crawlee/types'; | ||
//# sourceMappingURL=index.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.social = void 0; | ||
exports.getMemoryInfoV2 = exports.getCurrentCpuTicksV2 = exports.social = void 0; | ||
const tslib_1 = require("tslib"); | ||
@@ -19,2 +19,6 @@ tslib_1.__exportStar(require("./internals/blocked"), exports); | ||
tslib_1.__exportStar(require("./internals/url"), exports); | ||
var cpu_info_1 = require("./internals/systemInfoV2/cpu-info"); | ||
Object.defineProperty(exports, "getCurrentCpuTicksV2", { enumerable: true, get: function () { return cpu_info_1.getCurrentCpuTicksV2; } }); | ||
var memory_info_1 = require("./internals/systemInfoV2/memory-info"); | ||
Object.defineProperty(exports, "getMemoryInfoV2", { enumerable: true, get: function () { return memory_info_1.getMemoryInfoV2; } }); | ||
//# sourceMappingURL=index.js.map |
@@ -16,2 +16,12 @@ /** | ||
/** | ||
* Detects if crawlee is running in a containerized environment. | ||
*/ | ||
export declare function isContainerized(): Promise<boolean>; | ||
export declare function isLambda(): boolean; | ||
/** | ||
* gets the cgroup version by checking for a file at /sys/fs/cgroup/memory | ||
* @returns "V1" or "V2" for the version of cgroup or null if cgroup is not found. | ||
*/ | ||
export declare function getCgroupsVersion(forceReset?: boolean): Promise<"V1" | "V2" | null>; | ||
/** | ||
* Computes a weighted average of an array of numbers, complemented by an array of weights. | ||
@@ -18,0 +28,0 @@ * @ignore |
@@ -5,2 +5,5 @@ "use strict"; | ||
exports.isDocker = isDocker; | ||
exports.isContainerized = isContainerized; | ||
exports.isLambda = isLambda; | ||
exports.getCgroupsVersion = getCgroupsVersion; | ||
exports.weightedAvg = weightedAvg; | ||
@@ -45,3 +48,60 @@ exports.sleep = sleep; | ||
} | ||
let isContainerizedResult; | ||
/** | ||
* Detects if crawlee is running in a containerized environment. | ||
*/ | ||
async function isContainerized() { | ||
// Value is very unlikley to change. Cache the result after the first execution. | ||
if (isContainerizedResult !== undefined) { | ||
return isContainerizedResult; | ||
} | ||
// return false if running in aws lambda | ||
if (isLambda()) { | ||
isContainerizedResult = false; | ||
return isContainerizedResult; | ||
} | ||
const dockerenvCheck = promises_1.default | ||
.stat('/.dockerenv') | ||
.then(() => true) | ||
.catch(() => false); | ||
const cgroupCheck = promises_1.default | ||
.readFile('/proc/self/cgroup', 'utf8') | ||
.then((content) => content.includes('docker')) | ||
.catch(() => false); | ||
const [dockerenvResult, cgroupResult] = await Promise.all([dockerenvCheck, cgroupCheck]); | ||
isContainerizedResult = dockerenvResult || cgroupResult || !!process.env.KUBERNETES_SERVICE_HOST; | ||
return isContainerizedResult; | ||
} | ||
function isLambda() { | ||
return !!process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE; | ||
} | ||
let _cgroupsVersion; | ||
/** | ||
* gets the cgroup version by checking for a file at /sys/fs/cgroup/memory | ||
* @returns "V1" or "V2" for the version of cgroup or null if cgroup is not found. | ||
*/ | ||
async function getCgroupsVersion(forceReset) { | ||
// Parameter forceReset is just internal for unit tests. | ||
if (_cgroupsVersion !== undefined && !forceReset) { | ||
return _cgroupsVersion; | ||
} | ||
try { | ||
// If this directory does not exists, cgroups are not available | ||
await promises_1.default.access('/sys/fs/cgroup/'); | ||
} | ||
catch (e) { | ||
_cgroupsVersion = null; | ||
return null; | ||
} | ||
_cgroupsVersion = 'V1'; | ||
try { | ||
// If this directory does not exists, assume the container is using cgroups V2 | ||
await promises_1.default.access('/sys/fs/cgroup/memory/'); | ||
} | ||
catch (e) { | ||
_cgroupsVersion = 'V2'; | ||
} | ||
return _cgroupsVersion; | ||
} | ||
/** | ||
* Computes a weighted average of an array of numbers, complemented by an array of weights. | ||
@@ -48,0 +108,0 @@ * @ignore |
{ | ||
"name": "@crawlee/utils", | ||
"version": "3.12.3-beta.27", | ||
"version": "3.12.3-beta.28", | ||
"description": "A set of shared utilities that can be used by crawlers", | ||
@@ -52,3 +52,3 @@ "engines": { | ||
"@apify/ps-tree": "^1.2.0", | ||
"@crawlee/types": "3.12.3-beta.27", | ||
"@crawlee/types": "3.12.3-beta.28", | ||
"@types/sax": "^1.2.7", | ||
@@ -74,3 +74,3 @@ "cheerio": "1.0.0-rc.12", | ||
}, | ||
"gitHead": "5a175d070ad7451bc35dedc0e75511eece6e670d" | ||
"gitHead": "c0b3349a0b2d32e993ce341603e866c0126df1c7" | ||
} |
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
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
381631
77
3664
5
1
+ Added@crawlee/types@3.12.3-beta.28(transitive)
- Removed@crawlee/types@3.12.3-beta.27(transitive)