This commit is contained in:
2024-03-22 03:47:51 +05:30
parent 8bcf3d211e
commit 89819f6fe2
28440 changed files with 3211033 additions and 2 deletions

19
node_modules/eval/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,19 @@
Copyright (c) 2012 Pierre Curto
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

60
node_modules/eval/README.md generated vendored Normal file
View File

@@ -0,0 +1,60 @@
# Eval - require() for module content!
## Overview
This module is a simple way to evaluate a module content in the same way as require() but without loading it from a file. Effectively, it mimicks the javascript evil `eval` function but leverages Node's VM module instead.
## Benefits
Why would you be using the `eval` module over the native`require`? Most of the time `require` is fine but in some situations, I have found myself wishing for the following:
* Ability to supply a context to a module
* Ability to load the module file(s) from non node standard places
Or simply to leverage JavaScript's `eval` but with sandboxing.
## Download
It is published on node package manager (npm). To install, do:
npm install eval
## Usage
```` javascript
var _eval = require('eval')
var res = _eval(content /*, filename, scope, includeGlobals */)
````
The following options are available:
* `content` (__String__): the content to be evaluated
* `filename` (__String__): optional dummy name to be given (used in stacktraces)
* `scope` (__Object__): scope properties are provided as variables to the content
* `includeGlobals` (__Boolean__): allow/disallow global variables (and require) to be supplied to the content (default=false)
## Examples
```` javascript
var _eval = require('eval')
var res = _eval('var x = 123; exports.x = x')
// => res === { x: 123 }
res = _eval('module.exports = function () { return 123 }')
// => res() === 123
res = _eval('module.exports = require("events")', true)
// => res === require('events')
res = _eval('exports.x = process', true)
// => res.x === process
````
## License
[Here](https://github.com/pierrec/node-eval/tree/master/LICENSE)

50
node_modules/eval/eval.d.ts generated vendored Normal file
View File

@@ -0,0 +1,50 @@
/// <reference types="node" />
import { Script } from "vm";
/**
* A simple way to evaluate a module content in the same way as require() but
* without loading it from a file. Effectively, it mimicks the javascript evil
* `eval` function but leverages Node's VM module instead.
*/
declare const nodeEval: {
(
/** The content to be evaluated. */
content: string | Buffer | Script,
): unknown;
(
/** The content to be evaluated. */
content: string | Buffer | Script,
/**
* Optional flag to allow/disallow global variables (and require) to be
* supplied to the content (default=false).
*/
includeGlobals?: boolean,
): unknown;
(
/** The content to be evaluated. */
content: string | Buffer | Script,
/** Optional scope properties are provided as variables to the content. */
scope?: Record<string, unknown>,
/**
* Optional flag to allow/disallow global variables (and require) to be
* supplied to the content (default=false).
*/
includeGlobals?: boolean,
): unknown;
(
/** The content to be evaluated. */
content: string | Buffer | Script,
/** Optional dummy name to be given (used in stacktraces). */
filename?: string,
/** Optional scope properties are provided as variables to the content. */
scope?: Record<string, unknown>,
/**
* Optional flag to allow/disallow global variables (and require) to be
* supplied to the content (default=false).
*/
includeGlobals?: boolean,
): unknown;
};
export = nodeEval;

90
node_modules/eval/eval.js generated vendored Normal file
View File

@@ -0,0 +1,90 @@
var vm = require('vm')
var isBuffer = Buffer.isBuffer
var requireLike = require('require-like')
function merge (a, b) {
if (!a || !b) return a
var keys = Object.keys(b)
for (var k, i = 0, n = keys.length; i < n; i++) {
k = keys[i]
a[k] = b[k]
}
return a
}
var vmGlobals = new vm.Script('Object.getOwnPropertyNames(globalThis)')
.runInNewContext()
// Return the exports/module.exports variable set in the content
// content (String|VmScript): required
module.exports = function (content, filename, scope, includeGlobals) {
if (typeof filename !== 'string') {
if (typeof filename === 'object') {
includeGlobals = scope
scope = filename
filename = ''
} else if (typeof filename === 'boolean') {
includeGlobals = filename
scope = {}
filename = ''
}
}
// Expose standard Node globals
var sandbox = {}
var exports = {}
var _filename = filename || module.parent.filename;
if (includeGlobals) {
// Merge enumerable variables on `global`
merge(sandbox, global)
// Merge all non-enumerable variables on `global`, including console (v10+),
// process (v12+), URL, etc. We first filter out anything that's already in
// the VM scope (i.e. those in the ES standard) so we don't have two copies
Object.getOwnPropertyNames(global).forEach((name) => {
if (!vmGlobals.includes(name)) {
sandbox[name] = global[name]
}
})
// `console` exists in VM scope, but we want to pipe the output to the
// process'
sandbox.console = console
sandbox.require = requireLike(_filename)
}
if (typeof scope === 'object') {
merge(sandbox, scope)
}
sandbox.exports = exports
sandbox.module = {
exports: exports,
filename: _filename,
id: _filename,
parent: module.parent,
require: sandbox.require || requireLike(_filename)
}
sandbox.global = sandbox
var options = {
filename: filename,
displayErrors: false
}
if (isBuffer(content)) {
content = content.toString()
}
// Evalutate the content with the given scope
if (typeof content === 'string') {
var stringScript = content.replace(/^\#\!.*/, '')
var script = new vm.Script(stringScript, options)
script.runInNewContext(sandbox, options)
} else {
content.runInNewContext(sandbox, options)
}
return sandbox.module.exports
}

33
node_modules/eval/package.json generated vendored Normal file
View File

@@ -0,0 +1,33 @@
{
"author": "Pierre Curto"
, "name": "eval"
, "description": "Evaluate node require() module content directly"
, "keywords": ["require","eval","vm","module"]
, "version": "0.1.8"
, "homepage": "http://github.com/pierrec/node-eval"
, "repository": {
"type": "git"
, "url": "git://github.com/pierrec/node-eval.git"
}
, "main": "eval.js"
, "types": "eval.d.ts"
, "bugs": { "url" : "http://github.com/pierrec/node-eval/issues" }
, "licenses":
[ {
"type": "MIT"
, "url": "http://github.com/pierrec/node-eval/raw/master/LICENSE"
}
]
, "engines": {
"node": ">= 0.8"
}
, "dependencies": {
"@types/node": "*"
, "require-like": ">= 0.1.1"
}
, "devDependencies": {
}
, "scripts": {
"test": "node test.js"
}
}

34
node_modules/eval/test.js generated vendored Normal file
View File

@@ -0,0 +1,34 @@
var assert = require('assert')
var _eval = require('./eval')
var res
res = _eval('var x = 123; exports.x = x')
assert.deepEqual( res, { x: 123 } )
res = _eval('module.exports = function () { return 123 }')
assert.deepEqual( res(), 123 )
res = _eval('module.exports = require("events")', true)
assert.deepEqual( res, require('events') )
res = _eval('exports.x = process', true)
assert.deepEqual( res.x, process )
// Lock down scope by default
global.add = function (a, b) { return a + b }
res = _eval('exports.add = function (x, y) { return add(x, y) }')
assert.throws(function () {
res.add(5, 6)
})
// Do not expose require by default
assert.throws(function () {
_eval('require("fs")')
})
// Verify that the console is available when globals are passed
res = _eval('exports.x = console', true)
assert.deepEqual(res.x, console)
console.log('All tests passed')