function-exec-sync
Advanced tools
| // Patched for backwards compatiblity from: https://github.com/yahoo/serialize-javascript/blob/main/LICENSE | ||
| "use strict"; | ||
| function _instanceof(left, right) { | ||
| if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) { | ||
| return !!right[Symbol.hasInstance](left); | ||
| } else { | ||
| return left instanceof right; | ||
| } | ||
| } | ||
| function _type_of(obj) { | ||
| "@swc/helpers - typeof"; | ||
| return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; | ||
| } | ||
| var hasMap = typeof Map !== 'undefined'; | ||
| var hasSet = typeof Set !== 'undefined'; | ||
| var hasURL = typeof URL !== 'undefined'; | ||
| var hasBigInt = typeof BigInt !== 'undefined'; | ||
| /* | ||
| Copyright (c) 2014, Yahoo! Inc. All rights reserved. | ||
| Copyrights licensed under the New BSD License. | ||
| See the accompanying LICENSE file for terms. | ||
| */ 'use strict'; | ||
| var randomBytes = require('randombytes'); | ||
| // Generate an internal UID to make the regexp pattern harder to guess. | ||
| var UID_LENGTH = 16; | ||
| var UID = generateUID(); | ||
| var PLACE_HOLDER_REGEXP = new RegExp('(\\\\)?"@__(F|R|D|M|S|A|U|I|B|L)-'.concat(UID, '-(\\d+)__@"'), 'g'); | ||
| var IS_NATIVE_CODE_REGEXP = /\{\s*\[native code\]\s*\}/g; | ||
| var IS_PURE_FUNCTION = /function.*?\(/; | ||
| var IS_ARROW_FUNCTION = /.*?=>.*?/; | ||
| var UNSAFE_CHARS_REGEXP = /[<>/\u2028\u2029]/g; | ||
| var RESERVED_SYMBOLS = [ | ||
| '*', | ||
| 'async' | ||
| ]; | ||
| // Mapping of unsafe HTML and invalid JavaScript line terminator chars to their | ||
| // Unicode char counterparts which are safe to use in JavaScript strings. | ||
| var ESCAPED_CHARS = { | ||
| '<': '\\u003C', | ||
| '>': '\\u003E', | ||
| '/': '\\u002F', | ||
| '\u2028': '\\u2028', | ||
| '\u2029': '\\u2029' | ||
| }; | ||
| function escapeUnsafeChars(unsafeChar) { | ||
| return ESCAPED_CHARS[unsafeChar]; | ||
| } | ||
| function generateUID() { | ||
| var bytes = randomBytes(UID_LENGTH); | ||
| var result = ''; | ||
| for(var i = 0; i < UID_LENGTH; ++i){ | ||
| result += bytes[i].toString(16); | ||
| } | ||
| return result; | ||
| } | ||
| function deleteFunctions(obj) { | ||
| var functionKeys = []; | ||
| for(var key in obj){ | ||
| if (typeof obj[key] === 'function') { | ||
| functionKeys.push(key); | ||
| } | ||
| } | ||
| for(var i = 0; i < functionKeys.length; i++){ | ||
| delete obj[functionKeys[i]]; | ||
| } | ||
| } | ||
| module.exports = function serialize(obj, options) { | ||
| options = options || {}; | ||
| // Backwards-compatibility for `space` as the second argument. | ||
| if (typeof options === 'number' || typeof options === 'string') { | ||
| options = { | ||
| space: options | ||
| }; | ||
| } | ||
| var functions = []; | ||
| var regexps = []; | ||
| var dates = []; | ||
| var maps = []; | ||
| var sets = []; | ||
| var arrays = []; | ||
| var undefs = []; | ||
| var infinities = []; | ||
| var bigInts = []; | ||
| var urls = []; | ||
| // Returns placeholders for functions and regexps (identified by index) | ||
| // which are later replaced by their string representation. | ||
| function replacer(key, value) { | ||
| // For nested function | ||
| if (options.ignoreFunction) { | ||
| deleteFunctions(value); | ||
| } | ||
| if (hasBigInt && !value && value !== undefined && value !== BigInt(0)) { | ||
| return value; | ||
| } | ||
| // If the value is an object w/ a toJSON method, toJSON is called before | ||
| // the replacer runs, so we use this[key] to get the non-toJSONed value. | ||
| var origValue = this[key]; | ||
| var type = typeof origValue === "undefined" ? "undefined" : _type_of(origValue); | ||
| if (type === 'object') { | ||
| if (_instanceof(origValue, RegExp)) { | ||
| return "@__R-".concat(UID, "-").concat(regexps.push(origValue) - 1, "__@"); | ||
| } | ||
| if (_instanceof(origValue, Date)) { | ||
| return "@__D-".concat(UID, "-").concat(dates.push(origValue) - 1, "__@"); | ||
| } | ||
| if (hasMap && _instanceof(origValue, Map)) { | ||
| return "@__M-".concat(UID, "-").concat(maps.push(origValue) - 1, "__@"); | ||
| } | ||
| if (hasSet && _instanceof(origValue, Set)) { | ||
| return "@__S-".concat(UID, "-").concat(sets.push(origValue) - 1, "__@"); | ||
| } | ||
| if (Array.isArray(origValue)) { | ||
| var isSparse = origValue.filter(function() { | ||
| return true; | ||
| }).length !== origValue.length; | ||
| if (isSparse) { | ||
| return "@__A-".concat(UID, "-").concat(arrays.push(origValue) - 1, "__@"); | ||
| } | ||
| } | ||
| if (hasURL && _instanceof(origValue, URL)) { | ||
| return "@__L-".concat(UID, "-").concat(urls.push(origValue) - 1, "__@"); | ||
| } | ||
| } | ||
| if (type === 'function') { | ||
| return "@__F-".concat(UID, "-").concat(functions.push(origValue) - 1, "__@"); | ||
| } | ||
| if (type === 'undefined') { | ||
| return "@__U-".concat(UID, "-").concat(undefs.push(origValue) - 1, "__@"); | ||
| } | ||
| if (type === 'number' && !Number.isNaN(origValue) && !Number.isFinite(origValue)) { | ||
| return "@__I-".concat(UID, "-").concat(infinities.push(origValue) - 1, "__@"); | ||
| } | ||
| if (type === 'bigint') { | ||
| return "@__B-".concat(UID, "-").concat(bigInts.push(origValue) - 1, "__@"); | ||
| } | ||
| return value; | ||
| } | ||
| function serializeFunc(fn) { | ||
| var serializedFn = fn.toString(); | ||
| if (IS_NATIVE_CODE_REGEXP.test(serializedFn)) { | ||
| throw new TypeError("Serializing native function: ".concat(fn.name)); | ||
| } | ||
| // pure functions, example: {key: function() {}} | ||
| if (IS_PURE_FUNCTION.test(serializedFn)) { | ||
| return serializedFn; | ||
| } | ||
| // arrow functions, example: arg1 => arg1+5 | ||
| if (IS_ARROW_FUNCTION.test(serializedFn)) { | ||
| return serializedFn; | ||
| } | ||
| var argsStartsAt = serializedFn.indexOf('('); | ||
| var def = serializedFn.substr(0, argsStartsAt).trim().split(' ').filter(function(val) { | ||
| return val.length > 0; | ||
| }); | ||
| var nonReservedSymbols = def.filter(function(val) { | ||
| return RESERVED_SYMBOLS.indexOf(val) === -1; | ||
| }); | ||
| // enhanced literal objects, example: {key() {}} | ||
| if (nonReservedSymbols.length > 0) { | ||
| return "".concat(def.indexOf('async') > -1 ? 'async ' : '', "function").concat(def.join('').indexOf('*') > -1 ? '*' : '').concat(serializedFn.substr(argsStartsAt)); | ||
| } | ||
| // arrow functions | ||
| return serializedFn; | ||
| } | ||
| // Check if the parameter is function | ||
| if (options.ignoreFunction && typeof obj === 'function') { | ||
| obj = undefined; | ||
| } | ||
| // Protects against `JSON.stringify()` returning `undefined`, by serializing | ||
| // to the literal string: "undefined". | ||
| if (obj === undefined) { | ||
| return String(obj); | ||
| } | ||
| var str; | ||
| // Creates a JSON string representation of the value. | ||
| // NOTE: Node 0.12 goes into slow mode with extra JSON.stringify() args. | ||
| if (options.isJSON && !options.space) { | ||
| str = JSON.stringify(obj); | ||
| } else { | ||
| str = JSON.stringify(obj, options.isJSON ? null : replacer, options.space); | ||
| } | ||
| // Protects against `JSON.stringify()` returning `undefined`, by serializing | ||
| // to the literal string: "undefined". | ||
| if (typeof str !== 'string') { | ||
| return String(str); | ||
| } | ||
| // Replace unsafe HTML and invalid JavaScript line terminator chars with | ||
| // their safe Unicode char counterpart. This _must_ happen before the | ||
| // regexps and functions are serialized and added back to the string. | ||
| if (options.unsafe !== true) { | ||
| str = str.replace(UNSAFE_CHARS_REGEXP, escapeUnsafeChars); | ||
| } | ||
| if (functions.length === 0 && regexps.length === 0 && dates.length === 0 && maps.length === 0 && sets.length === 0 && arrays.length === 0 && undefs.length === 0 && infinities.length === 0 && bigInts.length === 0 && urls.length === 0) { | ||
| return str; | ||
| } | ||
| // Replaces all occurrences of function, regexp, date, map and set placeholders in the | ||
| // JSON string with their string representations. If the original value can | ||
| // not be found, then `undefined` is used. | ||
| return str.replace(PLACE_HOLDER_REGEXP, function(match, backSlash, type, valueIndex) { | ||
| // The placeholder may not be preceded by a backslash. This is to prevent | ||
| // replacing things like `"a\"@__R-<UID>-0__@"` and thus outputting | ||
| // invalid JS. | ||
| if (backSlash) { | ||
| return match; | ||
| } | ||
| if (type === 'D') { | ||
| return 'new Date("'.concat(dates[valueIndex].toISOString(), '")'); | ||
| } | ||
| if (type === 'R') { | ||
| return "new RegExp(".concat(serialize(regexps[valueIndex].source), ', "').concat(regexps[valueIndex].flags, '")'); | ||
| } | ||
| if (type === 'M') { | ||
| return "new Map(".concat(serialize(Array.from(maps[valueIndex].entries()), options), ")"); | ||
| } | ||
| if (type === 'S') { | ||
| return "new Set(".concat(serialize(Array.from(sets[valueIndex].values()), options), ")"); | ||
| } | ||
| if (type === 'A') { | ||
| return "Array.prototype.slice.call(".concat(serialize(Object.assign({ | ||
| length: arrays[valueIndex].length | ||
| }, arrays[valueIndex]), options), ")"); | ||
| } | ||
| if (type === 'U') { | ||
| return 'undefined'; | ||
| } | ||
| if (type === 'I') { | ||
| return infinities[valueIndex]; | ||
| } | ||
| if (type === 'B') { | ||
| return 'BigInt("'.concat(bigInts[valueIndex], '")'); | ||
| } | ||
| if (type === 'L') { | ||
| return "new URL(".concat(serialize(urls[valueIndex].toString(), options), ")"); | ||
| } | ||
| var fn = functions[valueIndex]; | ||
| return serializeFunc(fn); | ||
| }); | ||
| }; | ||
| /* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; } |
| {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/function-exec-sync/src/serialize-javascript.cjs"],"sourcesContent":["// Patched for backwards compatiblity from: https://github.com/yahoo/serialize-javascript/blob/main/LICENSE\n\nvar hasMap = typeof Map !== 'undefined';\nvar hasSet = typeof Set !== 'undefined';\nvar hasURL = typeof URL !== 'undefined';\nvar hasBigInt = typeof BigInt !== 'undefined';\n\n/*\nCopyright (c) 2014, Yahoo! Inc. All rights reserved.\nCopyrights licensed under the New BSD License.\nSee the accompanying LICENSE file for terms.\n*/\n\n('use strict');\n\nvar randomBytes = require('randombytes');\n\n// Generate an internal UID to make the regexp pattern harder to guess.\nvar UID_LENGTH = 16;\nvar UID = generateUID();\nvar PLACE_HOLDER_REGEXP = new RegExp(`(\\\\\\\\)?\"@__(F|R|D|M|S|A|U|I|B|L)-${UID}-(\\\\d+)__@\"`, 'g');\n\nvar IS_NATIVE_CODE_REGEXP = /\\{\\s*\\[native code\\]\\s*\\}/g;\nvar IS_PURE_FUNCTION = /function.*?\\(/;\nvar IS_ARROW_FUNCTION = /.*?=>.*?/;\nvar UNSAFE_CHARS_REGEXP = /[<>/\\u2028\\u2029]/g;\n\nvar RESERVED_SYMBOLS = ['*', 'async'];\n\n// Mapping of unsafe HTML and invalid JavaScript line terminator chars to their\n// Unicode char counterparts which are safe to use in JavaScript strings.\nvar ESCAPED_CHARS = {\n '<': '\\\\u003C',\n '>': '\\\\u003E',\n '/': '\\\\u002F',\n '\\u2028': '\\\\u2028',\n '\\u2029': '\\\\u2029',\n};\n\nfunction escapeUnsafeChars(unsafeChar) {\n return ESCAPED_CHARS[unsafeChar];\n}\n\nfunction generateUID() {\n var bytes = randomBytes(UID_LENGTH);\n var result = '';\n for (var i = 0; i < UID_LENGTH; ++i) {\n result += bytes[i].toString(16);\n }\n return result;\n}\n\nfunction deleteFunctions(obj) {\n var functionKeys = [];\n for (var key in obj) {\n if (typeof obj[key] === 'function') {\n functionKeys.push(key);\n }\n }\n for (var i = 0; i < functionKeys.length; i++) {\n delete obj[functionKeys[i]];\n }\n}\n\nmodule.exports = function serialize(obj, options) {\n options = options || {};\n\n // Backwards-compatibility for `space` as the second argument.\n if (typeof options === 'number' || typeof options === 'string') {\n options = { space: options };\n }\n\n var functions = [];\n var regexps = [];\n var dates = [];\n var maps = [];\n var sets = [];\n var arrays = [];\n var undefs = [];\n var infinities = [];\n var bigInts = [];\n var urls = [];\n\n // Returns placeholders for functions and regexps (identified by index)\n // which are later replaced by their string representation.\n function replacer(key, value) {\n // For nested function\n if (options.ignoreFunction) {\n deleteFunctions(value);\n }\n\n if (hasBigInt && !value && value !== undefined && value !== BigInt(0)) {\n return value;\n }\n\n // If the value is an object w/ a toJSON method, toJSON is called before\n // the replacer runs, so we use this[key] to get the non-toJSONed value.\n var origValue = this[key];\n var type = typeof origValue;\n\n if (type === 'object') {\n if (origValue instanceof RegExp) {\n return `@__R-${UID}-${regexps.push(origValue) - 1}__@`;\n }\n\n if (origValue instanceof Date) {\n return `@__D-${UID}-${dates.push(origValue) - 1}__@`;\n }\n\n if (hasMap && origValue instanceof Map) {\n return `@__M-${UID}-${maps.push(origValue) - 1}__@`;\n }\n\n if (hasSet && origValue instanceof Set) {\n return `@__S-${UID}-${sets.push(origValue) - 1}__@`;\n }\n\n if (Array.isArray(origValue)) {\n var isSparse = origValue.filter(() => true).length !== origValue.length;\n if (isSparse) {\n return `@__A-${UID}-${arrays.push(origValue) - 1}__@`;\n }\n }\n\n if (hasURL && origValue instanceof URL) {\n return `@__L-${UID}-${urls.push(origValue) - 1}__@`;\n }\n }\n\n if (type === 'function') {\n return `@__F-${UID}-${functions.push(origValue) - 1}__@`;\n }\n\n if (type === 'undefined') {\n return `@__U-${UID}-${undefs.push(origValue) - 1}__@`;\n }\n\n if (type === 'number' && !Number.isNaN(origValue) && !Number.isFinite(origValue)) {\n return `@__I-${UID}-${infinities.push(origValue) - 1}__@`;\n }\n\n if (type === 'bigint') {\n return `@__B-${UID}-${bigInts.push(origValue) - 1}__@`;\n }\n\n return value;\n }\n\n function serializeFunc(fn) {\n var serializedFn = fn.toString();\n if (IS_NATIVE_CODE_REGEXP.test(serializedFn)) {\n throw new TypeError(`Serializing native function: ${fn.name}`);\n }\n\n // pure functions, example: {key: function() {}}\n if (IS_PURE_FUNCTION.test(serializedFn)) {\n return serializedFn;\n }\n\n // arrow functions, example: arg1 => arg1+5\n if (IS_ARROW_FUNCTION.test(serializedFn)) {\n return serializedFn;\n }\n\n var argsStartsAt = serializedFn.indexOf('(');\n var def = serializedFn\n .substr(0, argsStartsAt)\n .trim()\n .split(' ')\n .filter((val) => val.length > 0);\n\n var nonReservedSymbols = def.filter((val) => RESERVED_SYMBOLS.indexOf(val) === -1);\n\n // enhanced literal objects, example: {key() {}}\n if (nonReservedSymbols.length > 0) {\n return `${def.indexOf('async') > -1 ? 'async ' : ''}function${def.join('').indexOf('*') > -1 ? '*' : ''}${serializedFn.substr(argsStartsAt)}`;\n }\n\n // arrow functions\n return serializedFn;\n }\n\n // Check if the parameter is function\n if (options.ignoreFunction && typeof obj === 'function') {\n obj = undefined;\n }\n // Protects against `JSON.stringify()` returning `undefined`, by serializing\n // to the literal string: \"undefined\".\n if (obj === undefined) {\n return String(obj);\n }\n\n var str;\n\n // Creates a JSON string representation of the value.\n // NOTE: Node 0.12 goes into slow mode with extra JSON.stringify() args.\n if (options.isJSON && !options.space) {\n str = JSON.stringify(obj);\n } else {\n str = JSON.stringify(obj, options.isJSON ? null : replacer, options.space);\n }\n\n // Protects against `JSON.stringify()` returning `undefined`, by serializing\n // to the literal string: \"undefined\".\n if (typeof str !== 'string') {\n return String(str);\n }\n\n // Replace unsafe HTML and invalid JavaScript line terminator chars with\n // their safe Unicode char counterpart. This _must_ happen before the\n // regexps and functions are serialized and added back to the string.\n if (options.unsafe !== true) {\n str = str.replace(UNSAFE_CHARS_REGEXP, escapeUnsafeChars);\n }\n\n if (functions.length === 0 && regexps.length === 0 && dates.length === 0 && maps.length === 0 && sets.length === 0 && arrays.length === 0 && undefs.length === 0 && infinities.length === 0 && bigInts.length === 0 && urls.length === 0) {\n return str;\n }\n\n // Replaces all occurrences of function, regexp, date, map and set placeholders in the\n // JSON string with their string representations. If the original value can\n // not be found, then `undefined` is used.\n return str.replace(PLACE_HOLDER_REGEXP, (match, backSlash, type, valueIndex) => {\n // The placeholder may not be preceded by a backslash. This is to prevent\n // replacing things like `\"a\\\"@__R-<UID>-0__@\"` and thus outputting\n // invalid JS.\n if (backSlash) {\n return match;\n }\n\n if (type === 'D') {\n return `new Date(\\\"${dates[valueIndex].toISOString()}\\\")`;\n }\n\n if (type === 'R') {\n return `new RegExp(${serialize(regexps[valueIndex].source)}, \\\"${regexps[valueIndex].flags}\\\")`;\n }\n\n if (type === 'M') {\n return `new Map(${serialize(Array.from(maps[valueIndex].entries()), options)})`;\n }\n\n if (type === 'S') {\n return `new Set(${serialize(Array.from(sets[valueIndex].values()), options)})`;\n }\n\n if (type === 'A') {\n return `Array.prototype.slice.call(${serialize(Object.assign({ length: arrays[valueIndex].length }, arrays[valueIndex]), options)})`;\n }\n\n if (type === 'U') {\n return 'undefined';\n }\n\n if (type === 'I') {\n return infinities[valueIndex];\n }\n\n if (type === 'B') {\n return `BigInt(\\\"${bigInts[valueIndex]}\\\")`;\n }\n\n if (type === 'L') {\n return `new URL(${serialize(urls[valueIndex].toString(), options)})`;\n }\n\n var fn = functions[valueIndex];\n\n return serializeFunc(fn);\n });\n};\n"],"names":["hasMap","Map","hasSet","Set","hasURL","URL","hasBigInt","BigInt","randomBytes","require","UID_LENGTH","UID","generateUID","PLACE_HOLDER_REGEXP","RegExp","IS_NATIVE_CODE_REGEXP","IS_PURE_FUNCTION","IS_ARROW_FUNCTION","UNSAFE_CHARS_REGEXP","RESERVED_SYMBOLS","ESCAPED_CHARS","escapeUnsafeChars","unsafeChar","bytes","result","i","toString","deleteFunctions","obj","functionKeys","key","push","length","module","exports","serialize","options","space","functions","regexps","dates","maps","sets","arrays","undefs","infinities","bigInts","urls","replacer","value","ignoreFunction","undefined","origValue","type","Date","Array","isArray","isSparse","filter","Number","isNaN","isFinite","serializeFunc","fn","serializedFn","test","TypeError","name","argsStartsAt","indexOf","def","substr","trim","split","val","nonReservedSymbols","join","String","str","isJSON","JSON","stringify","unsafe","replace","match","backSlash","valueIndex","toISOString","source","flags","from","entries","values","Object","assign"],"mappings":"AAAA,2GAA2G;;;;;;;;;;;;;AAE3G,IAAIA,SAAS,OAAOC,QAAQ;AAC5B,IAAIC,SAAS,OAAOC,QAAQ;AAC5B,IAAIC,SAAS,OAAOC,QAAQ;AAC5B,IAAIC,YAAY,OAAOC,WAAW;AAElC;;;;AAIA,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QACT;QAEA,IAAIA,SAAS,KAAK;YAChB,OAAOR,UAAU,CAACyC,WAAW;QAC/B;QAEA,IAAIjC,SAAS,KAAK;YAChB,OAAO,AAAC,WAA+B,OAApBP,OAAO,CAACwC,WAAW,EAAC;QACzC;QAEA,IAAIjC,SAAS,KAAK;YAChB,OAAO,AAAC,WAA0D,OAAhDlB,UAAUY,IAAI,CAACuC,WAAW,CAAC5D,QAAQ,IAAIU,UAAS;QACpE;QAEA,IAAI2B,KAAKzB,SAAS,CAACgD,WAAW;QAE9B,OAAOxB,cAAcC;IACvB;AACF"} |
| declare function _exports(obj: any, options: any): any; | ||
| export = _exports; |
| // Patched for backwards compatiblity from: https://github.com/yahoo/serialize-javascript/blob/main/LICENSE | ||
| var hasMap = typeof Map !== 'undefined'; | ||
| var hasSet = typeof Set !== 'undefined'; | ||
| var hasURL = typeof URL !== 'undefined'; | ||
| var hasBigInt = typeof BigInt !== 'undefined'; | ||
| /* | ||
| Copyright (c) 2014, Yahoo! Inc. All rights reserved. | ||
| Copyrights licensed under the New BSD License. | ||
| See the accompanying LICENSE file for terms. | ||
| */ 'use strict'; | ||
| var randomBytes = require('randombytes'); | ||
| // Generate an internal UID to make the regexp pattern harder to guess. | ||
| var UID_LENGTH = 16; | ||
| var UID = generateUID(); | ||
| var PLACE_HOLDER_REGEXP = new RegExp(`(\\\\)?"@__(F|R|D|M|S|A|U|I|B|L)-${UID}-(\\d+)__@"`, 'g'); | ||
| var IS_NATIVE_CODE_REGEXP = /\{\s*\[native code\]\s*\}/g; | ||
| var IS_PURE_FUNCTION = /function.*?\(/; | ||
| var IS_ARROW_FUNCTION = /.*?=>.*?/; | ||
| var UNSAFE_CHARS_REGEXP = /[<>/\u2028\u2029]/g; | ||
| var RESERVED_SYMBOLS = [ | ||
| '*', | ||
| 'async' | ||
| ]; | ||
| // Mapping of unsafe HTML and invalid JavaScript line terminator chars to their | ||
| // Unicode char counterparts which are safe to use in JavaScript strings. | ||
| var ESCAPED_CHARS = { | ||
| '<': '\\u003C', | ||
| '>': '\\u003E', | ||
| '/': '\\u002F', | ||
| '\u2028': '\\u2028', | ||
| '\u2029': '\\u2029' | ||
| }; | ||
| function escapeUnsafeChars(unsafeChar) { | ||
| return ESCAPED_CHARS[unsafeChar]; | ||
| } | ||
| function generateUID() { | ||
| var bytes = randomBytes(UID_LENGTH); | ||
| var result = ''; | ||
| for(var i = 0; i < UID_LENGTH; ++i){ | ||
| result += bytes[i].toString(16); | ||
| } | ||
| return result; | ||
| } | ||
| function deleteFunctions(obj) { | ||
| var functionKeys = []; | ||
| for(var key in obj){ | ||
| if (typeof obj[key] === 'function') { | ||
| functionKeys.push(key); | ||
| } | ||
| } | ||
| for(var i = 0; i < functionKeys.length; i++){ | ||
| delete obj[functionKeys[i]]; | ||
| } | ||
| } | ||
| module.exports = function serialize(obj, options) { | ||
| options = options || {}; | ||
| // Backwards-compatibility for `space` as the second argument. | ||
| if (typeof options === 'number' || typeof options === 'string') { | ||
| options = { | ||
| space: options | ||
| }; | ||
| } | ||
| var functions = []; | ||
| var regexps = []; | ||
| var dates = []; | ||
| var maps = []; | ||
| var sets = []; | ||
| var arrays = []; | ||
| var undefs = []; | ||
| var infinities = []; | ||
| var bigInts = []; | ||
| var urls = []; | ||
| // Returns placeholders for functions and regexps (identified by index) | ||
| // which are later replaced by their string representation. | ||
| function replacer(key, value) { | ||
| // For nested function | ||
| if (options.ignoreFunction) { | ||
| deleteFunctions(value); | ||
| } | ||
| if (hasBigInt && !value && value !== undefined && value !== BigInt(0)) { | ||
| return value; | ||
| } | ||
| // If the value is an object w/ a toJSON method, toJSON is called before | ||
| // the replacer runs, so we use this[key] to get the non-toJSONed value. | ||
| var origValue = this[key]; | ||
| var type = typeof origValue; | ||
| if (type === 'object') { | ||
| if (origValue instanceof RegExp) { | ||
| return `@__R-${UID}-${regexps.push(origValue) - 1}__@`; | ||
| } | ||
| if (origValue instanceof Date) { | ||
| return `@__D-${UID}-${dates.push(origValue) - 1}__@`; | ||
| } | ||
| if (hasMap && origValue instanceof Map) { | ||
| return `@__M-${UID}-${maps.push(origValue) - 1}__@`; | ||
| } | ||
| if (hasSet && origValue instanceof Set) { | ||
| return `@__S-${UID}-${sets.push(origValue) - 1}__@`; | ||
| } | ||
| if (Array.isArray(origValue)) { | ||
| var isSparse = origValue.filter(()=>true).length !== origValue.length; | ||
| if (isSparse) { | ||
| return `@__A-${UID}-${arrays.push(origValue) - 1}__@`; | ||
| } | ||
| } | ||
| if (hasURL && origValue instanceof URL) { | ||
| return `@__L-${UID}-${urls.push(origValue) - 1}__@`; | ||
| } | ||
| } | ||
| if (type === 'function') { | ||
| return `@__F-${UID}-${functions.push(origValue) - 1}__@`; | ||
| } | ||
| if (type === 'undefined') { | ||
| return `@__U-${UID}-${undefs.push(origValue) - 1}__@`; | ||
| } | ||
| if (type === 'number' && !Number.isNaN(origValue) && !Number.isFinite(origValue)) { | ||
| return `@__I-${UID}-${infinities.push(origValue) - 1}__@`; | ||
| } | ||
| if (type === 'bigint') { | ||
| return `@__B-${UID}-${bigInts.push(origValue) - 1}__@`; | ||
| } | ||
| return value; | ||
| } | ||
| function serializeFunc(fn) { | ||
| var serializedFn = fn.toString(); | ||
| if (IS_NATIVE_CODE_REGEXP.test(serializedFn)) { | ||
| throw new TypeError(`Serializing native function: ${fn.name}`); | ||
| } | ||
| // pure functions, example: {key: function() {}} | ||
| if (IS_PURE_FUNCTION.test(serializedFn)) { | ||
| return serializedFn; | ||
| } | ||
| // arrow functions, example: arg1 => arg1+5 | ||
| if (IS_ARROW_FUNCTION.test(serializedFn)) { | ||
| return serializedFn; | ||
| } | ||
| var argsStartsAt = serializedFn.indexOf('('); | ||
| var def = serializedFn.substr(0, argsStartsAt).trim().split(' ').filter((val)=>val.length > 0); | ||
| var nonReservedSymbols = def.filter((val)=>RESERVED_SYMBOLS.indexOf(val) === -1); | ||
| // enhanced literal objects, example: {key() {}} | ||
| if (nonReservedSymbols.length > 0) { | ||
| return `${def.indexOf('async') > -1 ? 'async ' : ''}function${def.join('').indexOf('*') > -1 ? '*' : ''}${serializedFn.substr(argsStartsAt)}`; | ||
| } | ||
| // arrow functions | ||
| return serializedFn; | ||
| } | ||
| // Check if the parameter is function | ||
| if (options.ignoreFunction && typeof obj === 'function') { | ||
| obj = undefined; | ||
| } | ||
| // Protects against `JSON.stringify()` returning `undefined`, by serializing | ||
| // to the literal string: "undefined". | ||
| if (obj === undefined) { | ||
| return String(obj); | ||
| } | ||
| var str; | ||
| // Creates a JSON string representation of the value. | ||
| // NOTE: Node 0.12 goes into slow mode with extra JSON.stringify() args. | ||
| if (options.isJSON && !options.space) { | ||
| str = JSON.stringify(obj); | ||
| } else { | ||
| str = JSON.stringify(obj, options.isJSON ? null : replacer, options.space); | ||
| } | ||
| // Protects against `JSON.stringify()` returning `undefined`, by serializing | ||
| // to the literal string: "undefined". | ||
| if (typeof str !== 'string') { | ||
| return String(str); | ||
| } | ||
| // Replace unsafe HTML and invalid JavaScript line terminator chars with | ||
| // their safe Unicode char counterpart. This _must_ happen before the | ||
| // regexps and functions are serialized and added back to the string. | ||
| if (options.unsafe !== true) { | ||
| str = str.replace(UNSAFE_CHARS_REGEXP, escapeUnsafeChars); | ||
| } | ||
| if (functions.length === 0 && regexps.length === 0 && dates.length === 0 && maps.length === 0 && sets.length === 0 && arrays.length === 0 && undefs.length === 0 && infinities.length === 0 && bigInts.length === 0 && urls.length === 0) { | ||
| return str; | ||
| } | ||
| // Replaces all occurrences of function, regexp, date, map and set placeholders in the | ||
| // JSON string with their string representations. If the original value can | ||
| // not be found, then `undefined` is used. | ||
| return str.replace(PLACE_HOLDER_REGEXP, (match, backSlash, type, valueIndex)=>{ | ||
| // The placeholder may not be preceded by a backslash. This is to prevent | ||
| // replacing things like `"a\"@__R-<UID>-0__@"` and thus outputting | ||
| // invalid JS. | ||
| if (backSlash) { | ||
| return match; | ||
| } | ||
| if (type === 'D') { | ||
| return `new Date(\"${dates[valueIndex].toISOString()}\")`; | ||
| } | ||
| if (type === 'R') { | ||
| return `new RegExp(${serialize(regexps[valueIndex].source)}, \"${regexps[valueIndex].flags}\")`; | ||
| } | ||
| if (type === 'M') { | ||
| return `new Map(${serialize(Array.from(maps[valueIndex].entries()), options)})`; | ||
| } | ||
| if (type === 'S') { | ||
| return `new Set(${serialize(Array.from(sets[valueIndex].values()), options)})`; | ||
| } | ||
| if (type === 'A') { | ||
| return `Array.prototype.slice.call(${serialize(Object.assign({ | ||
| length: arrays[valueIndex].length | ||
| }, arrays[valueIndex]), options)})`; | ||
| } | ||
| if (type === 'U') { | ||
| return 'undefined'; | ||
| } | ||
| if (type === 'I') { | ||
| return infinities[valueIndex]; | ||
| } | ||
| if (type === 'B') { | ||
| return `BigInt(\"${bigInts[valueIndex]}\")`; | ||
| } | ||
| if (type === 'L') { | ||
| return `new URL(${serialize(urls[valueIndex].toString(), options)})`; | ||
| } | ||
| var fn = functions[valueIndex]; | ||
| return serializeFunc(fn); | ||
| }); | ||
| }; |
| {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/function-exec-sync/src/serialize-javascript.cjs"],"sourcesContent":["// Patched for backwards compatiblity from: https://github.com/yahoo/serialize-javascript/blob/main/LICENSE\n\nvar hasMap = typeof Map !== 'undefined';\nvar hasSet = typeof Set !== 'undefined';\nvar hasURL = typeof URL !== 'undefined';\nvar hasBigInt = typeof BigInt !== 'undefined';\n\n/*\nCopyright (c) 2014, Yahoo! Inc. All rights reserved.\nCopyrights licensed under the New BSD License.\nSee the accompanying LICENSE file for terms.\n*/\n\n('use strict');\n\nvar randomBytes = require('randombytes');\n\n// Generate an internal UID to make the regexp pattern harder to guess.\nvar UID_LENGTH = 16;\nvar UID = generateUID();\nvar PLACE_HOLDER_REGEXP = new RegExp(`(\\\\\\\\)?\"@__(F|R|D|M|S|A|U|I|B|L)-${UID}-(\\\\d+)__@\"`, 'g');\n\nvar IS_NATIVE_CODE_REGEXP = /\\{\\s*\\[native code\\]\\s*\\}/g;\nvar IS_PURE_FUNCTION = /function.*?\\(/;\nvar IS_ARROW_FUNCTION = /.*?=>.*?/;\nvar UNSAFE_CHARS_REGEXP = /[<>/\\u2028\\u2029]/g;\n\nvar RESERVED_SYMBOLS = ['*', 'async'];\n\n// Mapping of unsafe HTML and invalid JavaScript line terminator chars to their\n// Unicode char counterparts which are safe to use in JavaScript strings.\nvar ESCAPED_CHARS = {\n '<': '\\\\u003C',\n '>': '\\\\u003E',\n '/': '\\\\u002F',\n '\\u2028': '\\\\u2028',\n '\\u2029': '\\\\u2029',\n};\n\nfunction escapeUnsafeChars(unsafeChar) {\n return ESCAPED_CHARS[unsafeChar];\n}\n\nfunction generateUID() {\n var bytes = randomBytes(UID_LENGTH);\n var result = '';\n for (var i = 0; i < UID_LENGTH; ++i) {\n result += bytes[i].toString(16);\n }\n return result;\n}\n\nfunction deleteFunctions(obj) {\n var functionKeys = [];\n for (var key in obj) {\n if (typeof obj[key] === 'function') {\n functionKeys.push(key);\n }\n }\n for (var i = 0; i < functionKeys.length; i++) {\n delete obj[functionKeys[i]];\n }\n}\n\nmodule.exports = function serialize(obj, options) {\n options = options || {};\n\n // Backwards-compatibility for `space` as the second argument.\n if (typeof options === 'number' || typeof options === 'string') {\n options = { space: options };\n }\n\n var functions = [];\n var regexps = [];\n var dates = [];\n var maps = [];\n var sets = [];\n var arrays = [];\n var undefs = [];\n var infinities = [];\n var bigInts = [];\n var urls = [];\n\n // Returns placeholders for functions and regexps (identified by index)\n // which are later replaced by their string representation.\n function replacer(key, value) {\n // For nested function\n if (options.ignoreFunction) {\n deleteFunctions(value);\n }\n\n if (hasBigInt && !value && value !== undefined && value !== BigInt(0)) {\n return value;\n }\n\n // If the value is an object w/ a toJSON method, toJSON is called before\n // the replacer runs, so we use this[key] to get the non-toJSONed value.\n var origValue = this[key];\n var type = typeof origValue;\n\n if (type === 'object') {\n if (origValue instanceof RegExp) {\n return `@__R-${UID}-${regexps.push(origValue) - 1}__@`;\n }\n\n if (origValue instanceof Date) {\n return `@__D-${UID}-${dates.push(origValue) - 1}__@`;\n }\n\n if (hasMap && origValue instanceof Map) {\n return `@__M-${UID}-${maps.push(origValue) - 1}__@`;\n }\n\n if (hasSet && origValue instanceof Set) {\n return `@__S-${UID}-${sets.push(origValue) - 1}__@`;\n }\n\n if (Array.isArray(origValue)) {\n var isSparse = origValue.filter(() => true).length !== origValue.length;\n if (isSparse) {\n return `@__A-${UID}-${arrays.push(origValue) - 1}__@`;\n }\n }\n\n if (hasURL && origValue instanceof URL) {\n return `@__L-${UID}-${urls.push(origValue) - 1}__@`;\n }\n }\n\n if (type === 'function') {\n return `@__F-${UID}-${functions.push(origValue) - 1}__@`;\n }\n\n if (type === 'undefined') {\n return `@__U-${UID}-${undefs.push(origValue) - 1}__@`;\n }\n\n if (type === 'number' && !Number.isNaN(origValue) && !Number.isFinite(origValue)) {\n return `@__I-${UID}-${infinities.push(origValue) - 1}__@`;\n }\n\n if (type === 'bigint') {\n return `@__B-${UID}-${bigInts.push(origValue) - 1}__@`;\n }\n\n return value;\n }\n\n function serializeFunc(fn) {\n var serializedFn = fn.toString();\n if (IS_NATIVE_CODE_REGEXP.test(serializedFn)) {\n throw new TypeError(`Serializing native function: ${fn.name}`);\n }\n\n // pure functions, example: {key: function() {}}\n if (IS_PURE_FUNCTION.test(serializedFn)) {\n return serializedFn;\n }\n\n // arrow functions, example: arg1 => arg1+5\n if (IS_ARROW_FUNCTION.test(serializedFn)) {\n return serializedFn;\n }\n\n var argsStartsAt = serializedFn.indexOf('(');\n var def = serializedFn\n .substr(0, argsStartsAt)\n .trim()\n .split(' ')\n .filter((val) => val.length > 0);\n\n var nonReservedSymbols = def.filter((val) => RESERVED_SYMBOLS.indexOf(val) === -1);\n\n // enhanced literal objects, example: {key() {}}\n if (nonReservedSymbols.length > 0) {\n return `${def.indexOf('async') > -1 ? 'async ' : ''}function${def.join('').indexOf('*') > -1 ? '*' : ''}${serializedFn.substr(argsStartsAt)}`;\n }\n\n // arrow functions\n return serializedFn;\n }\n\n // Check if the parameter is function\n if (options.ignoreFunction && typeof obj === 'function') {\n obj = undefined;\n }\n // Protects against `JSON.stringify()` returning `undefined`, by serializing\n // to the literal string: \"undefined\".\n if (obj === undefined) {\n return String(obj);\n }\n\n var str;\n\n // Creates a JSON string representation of the value.\n // NOTE: Node 0.12 goes into slow mode with extra JSON.stringify() args.\n if (options.isJSON && !options.space) {\n str = JSON.stringify(obj);\n } else {\n str = JSON.stringify(obj, options.isJSON ? null : replacer, options.space);\n }\n\n // Protects against `JSON.stringify()` returning `undefined`, by serializing\n // to the literal string: \"undefined\".\n if (typeof str !== 'string') {\n return String(str);\n }\n\n // Replace unsafe HTML and invalid JavaScript line terminator chars with\n // their safe Unicode char counterpart. This _must_ happen before the\n // regexps and functions are serialized and added back to the string.\n if (options.unsafe !== true) {\n str = str.replace(UNSAFE_CHARS_REGEXP, escapeUnsafeChars);\n }\n\n if (functions.length === 0 && regexps.length === 0 && dates.length === 0 && maps.length === 0 && sets.length === 0 && arrays.length === 0 && undefs.length === 0 && infinities.length === 0 && bigInts.length === 0 && urls.length === 0) {\n return str;\n }\n\n // Replaces all occurrences of function, regexp, date, map and set placeholders in the\n // JSON string with their string representations. If the original value can\n // not be found, then `undefined` is used.\n return str.replace(PLACE_HOLDER_REGEXP, (match, backSlash, type, valueIndex) => {\n // The placeholder may not be preceded by a backslash. This is to prevent\n // replacing things like `\"a\\\"@__R-<UID>-0__@\"` and thus outputting\n // invalid JS.\n if (backSlash) {\n return match;\n }\n\n if (type === 'D') {\n return `new Date(\\\"${dates[valueIndex].toISOString()}\\\")`;\n }\n\n if (type === 'R') {\n return `new RegExp(${serialize(regexps[valueIndex].source)}, \\\"${regexps[valueIndex].flags}\\\")`;\n }\n\n if (type === 'M') {\n return `new Map(${serialize(Array.from(maps[valueIndex].entries()), options)})`;\n }\n\n if (type === 'S') {\n return `new Set(${serialize(Array.from(sets[valueIndex].values()), options)})`;\n }\n\n if (type === 'A') {\n return `Array.prototype.slice.call(${serialize(Object.assign({ length: arrays[valueIndex].length }, arrays[valueIndex]), options)})`;\n }\n\n if (type === 'U') {\n return 'undefined';\n }\n\n if (type === 'I') {\n return infinities[valueIndex];\n }\n\n if (type === 'B') {\n return `BigInt(\\\"${bigInts[valueIndex]}\\\")`;\n }\n\n if (type === 'L') {\n return `new URL(${serialize(urls[valueIndex].toString(), options)})`;\n }\n\n var fn = functions[valueIndex];\n\n return serializeFunc(fn);\n });\n};\n"],"names":["hasMap","Map","hasSet","Set","hasURL","URL","hasBigInt","BigInt","randomBytes","require","UID_LENGTH","UID","generateUID","PLACE_HOLDER_REGEXP","RegExp","IS_NATIVE_CODE_REGEXP","IS_PURE_FUNCTION","IS_ARROW_FUNCTION","UNSAFE_CHARS_REGEXP","RESERVED_SYMBOLS","ESCAPED_CHARS","escapeUnsafeChars","unsafeChar","bytes","result","i","toString","deleteFunctions","obj","functionKeys","key","push","length","module","exports","serialize","options","space","functions","regexps","dates","maps","sets","arrays","undefs","infinities","bigInts","urls","replacer","value","ignoreFunction","undefined","origValue","type","Date","Array","isArray","isSparse","filter","Number","isNaN","isFinite","serializeFunc","fn","serializedFn","test","TypeError","name","argsStartsAt","indexOf","def","substr","trim","split","val","nonReservedSymbols","join","String","str","isJSON","JSON","stringify","unsafe","replace","match","backSlash","valueIndex","toISOString","source","flags","from","entries","values","Object","assign"],"mappings":"AAAA,2GAA2G;AAE3G,IAAIA,SAAS,OAAOC,QAAQ;AAC5B,IAAIC,SAAS,OAAOC,QAAQ;AAC5B,IAAIC,SAAS,OAAOC,QAAQ;AAC5B,IAAIC,YAAY,OAAOC,WAAW;AAElC;;;;AAIA,GAEC;AAED,IAAIC,cAAcC,QAAQ;AAE1B,uEAAuE;AACvE,IAAIC,aAAa;AACjB,IAAIC,MAAMC;AACV,IAAIC,sBAAsB,IAAIC,OAAO,CAAC,iCAAiC,EAAEH,IAAI,WAAW,CAAC,EAAE;AAE3F,IAAII,wBAAwB;AAC5B,IAAIC,mBAAmB;AACvB,IAAIC,oBAAoB;AACxB,IAAIC,sBAAs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,CAAC,QAAQ,EAAElB,UAAUY,IAAI,CAACuC,WAAW,CAAC5D,QAAQ,IAAIU,SAAS,CAAC,CAAC;QACtE;QAEA,IAAI2B,KAAKzB,SAAS,CAACgD,WAAW;QAE9B,OAAOxB,cAAcC;IACvB;AACF"} |
| declare function _exports(obj: any, options: any): any; | ||
| export = _exports; |
@@ -17,3 +17,2 @@ "use strict"; | ||
| var _path = /*#__PURE__*/ _interop_require_default(require("path")); | ||
| var _serializejavascript = /*#__PURE__*/ _interop_require_default(require("serialize-javascript")); | ||
| var _shorthash = /*#__PURE__*/ _interop_require_default(require("short-hash")); | ||
@@ -23,2 +22,3 @@ var _tempsuffix = /*#__PURE__*/ _interop_require_default(require("temp-suffix")); | ||
| var _url = /*#__PURE__*/ _interop_require_default(require("url")); | ||
| var _serializejavascriptcjs = /*#__PURE__*/ _interop_require_default(require("./serialize-javascript.cjs")); | ||
| var _unlinkSafets = /*#__PURE__*/ _interop_require_default(require("./unlinkSafe.js")); | ||
@@ -103,3 +103,3 @@ function _define_property(obj, key, value) { | ||
| _mkdirpclassic.default.sync(_path.default.dirname(input)); | ||
| _fs.default.writeFileSync(input, (0, _serializejavascript.default)(workerData), 'utf8'); | ||
| _fs.default.writeFileSync(input, (0, _serializejavascriptcjs.default)(workerData), 'utf8'); | ||
| (0, _unlinkSafets.default)(output); | ||
@@ -106,0 +106,0 @@ // call the function |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/function-exec-sync/src/index.ts"],"sourcesContent":["import cp from 'child_process';\nimport fs from 'fs';\nimport mkdirp from 'mkdirp-classic';\nimport os from 'os';\nimport osShim from 'os-shim';\nimport path from 'path';\nimport serialize from 'serialize-javascript';\nimport shortHash from 'short-hash';\nimport suffix from 'temp-suffix';\nimport sleep from 'thread-sleep-compat';\nimport url from 'url';\n\nconst tmpdir = os.tmpdir || osShim.tmpdir;\n\nconst DEFAULT_SLEEP_MS = 100;\nconst NODES = ['node', 'node.exe', 'node.cmd'];\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst worker = path.join(__dirname, 'workers', 'runFunction.cjs');\n\nimport unlinkSafe from './unlinkSafe.ts';\n\nconst existsSync = (test: string): boolean => {\n try {\n (fs.accessSync || fs.statSync)(test);\n return true;\n } catch (_) {\n return false;\n }\n};\n\nimport type { ExecWorkerOptions } from './types.ts';\n\ninterface NodeJSEnv extends NodeJS.ProcessEnv {\n NODE_OPTIONS: string;\n}\n\nexport type * from './types.ts';\nexport default function functionExecSync(filePath: string, ...args: unknown[]);\nexport default function functionExecSync(options: ExecWorkerOptions, filePath: string, ...args: unknown[]);\nexport default function functionExecSync(options: ExecWorkerOptions | string, filePath?: string | unknown[], ...args: unknown[]): unknown {\n if (typeof options === 'string') {\n args.unshift(filePath);\n filePath = options;\n options = null;\n }\n if (!filePath) throw new Error('function-exec-sync missing file');\n options = (options || {}) as ExecWorkerOptions;\n\n const env = { ...(options.env || process.env) } as NodeJSEnv;\n delete env.NODE_OPTIONS;\n const workerData = {\n filePath,\n args,\n callbacks: options.callbacks === undefined ? false : options.callbacks,\n env,\n cwd: options.cwd === undefined ? process.cwd() : options.cwd,\n };\n\n const name = options.name === undefined ? 'function-exec-sync' : options.name;\n const temp = path.join(tmpdir(), name, shortHash(workerData.cwd));\n const input = path.join(temp, suffix('input'));\n const output = path.join(temp, suffix('output'));\n const done = path.join(temp, suffix('done'));\n\n // store data to a file\n mkdirp.sync(path.dirname(input));\n fs.writeFileSync(input, serialize(workerData), 'utf8');\n unlinkSafe(output);\n\n // call the function\n const execPath = options.execPath || process.execPath;\n\n // only node\n if (NODES.indexOf(path.basename(execPath).toLowerCase()) < 0) throw new Error(`Expecting node executable. Received: ${path.basename(execPath)}`);\n\n // exec and start polling\n if (!cp.execFileSync) {\n const sleepMS = options.sleep === undefined ? DEFAULT_SLEEP_MS : options.sleep;\n let cmd = `\"${execPath}\" \"${worker}\" \"${input}\" \"${output}\"`;\n cmd += `${isWindows ? '&' : ';'} echo \"done\" > ${done}`;\n cp.exec(cmd, { env });\n while (!existsSync(done)) {\n sleep(sleepMS);\n }\n } else {\n cp.execFileSync(execPath, [worker, input, output], { env });\n }\n unlinkSafe(input);\n unlinkSafe(done);\n\n // get data and clean up\n let res: { error?: Error; value: unknown };\n try {\n // biome-ignore lint/security/noGlobalEval: Serialize\n res = eval(`(${fs.readFileSync(output, 'utf8')})`);\n unlinkSafe(output);\n } catch (err) {\n throw new Error(`function-exec-sync: Error: ${err.message}. Function: ${filePath}. Exec path: ${execPath}`);\n }\n\n // throw error from the worker\n if (res.error) {\n const error = new Error(res.error.message);\n for (const key in res.error) error[key] = res.error[key];\n throw error;\n }\n // return the result\n return res.value;\n}\n"],"names":["functionExecSync","tmpdir","os","osShim","DEFAULT_SLEEP_MS","NODES","isWindows","process","platform","test","env","OSTYPE","__dirname","path","dirname","__filename","url","fileURLToPath","worker","join","existsSync","fs","accessSync","statSync","_","options","filePath","args","unshift","Error","NODE_OPTIONS","workerData","callbacks","undefined","cwd","name","temp","shortHash","input","suffix","output","done","mkdirp","sync","writeFileSync","serialize","unlinkSafe","execPath","indexOf","basename","toLowerCase","cp","execFileSync","sleepMS","sleep","cmd","exec","res","eval","readFileSync","err","message","error","key","value"],"mappings":";;;;+BAwCA;;;eAAwBA;;;oEAxCT;yDACA;oEACI;yDACJ;6DACI;2DACF;0EACK;gEACA;iEACH;wEACD;0DACF;mEAUO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AARvB,IAAMC,SAASC,WAAE,CAACD,MAAM,IAAIE,eAAM,CAACF,MAAM;AAEzC,IAAMG,mBAAmB;AACzB,IAAMC,QAAQ;IAAC;IAAQ;IAAY;CAAW;AAC9C,IAAMC,YAAYC,QAAQC,QAAQ,KAAK,WAAW,kBAAkBC,IAAI,CAACF,QAAQG,GAAG,CAACC,MAAM;AAC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A,MAAMC,KAAK,AAAC,IAAmC,OAAhCrC,WAAE,CAACsC,YAAY,CAACnB,QAAQ,SAAQ;QAC/CM,IAAAA,qBAAU,EAACN;IACb,EAAE,OAAOoB,KAAK;QACZ,MAAM,IAAI/B,MAAM,AAAC,8BAAuDH,OAA1BkC,IAAIC,OAAO,EAAC,gBAAsCd,OAAxBrB,UAAS,iBAAwB,OAATqB;IAClG;IAEA,8BAA8B;IAC9B,IAAIU,IAAIK,KAAK,EAAE;QACb,IAAMA,QAAQ,IAAIjC,MAAM4B,IAAIK,KAAK,CAACD,OAAO;QACzC,IAAK,IAAME,OAAON,IAAIK,KAAK,CAAEA,KAAK,CAACC,IAAI,GAAGN,IAAIK,KAAK,CAACC,IAAI;QACxD,MAAMD;IACR;IACA,oBAAoB;IACpB,OAAOL,IAAIO,KAAK;AAClB"} | ||
| {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/function-exec-sync/src/index.ts"],"sourcesContent":["import cp from 'child_process';\nimport fs from 'fs';\nimport mkdirp from 'mkdirp-classic';\nimport os from 'os';\nimport osShim from 'os-shim';\nimport path from 'path';\nimport shortHash from 'short-hash';\nimport suffix from 'temp-suffix';\nimport sleep from 'thread-sleep-compat';\nimport url from 'url';\nimport serialize from './serialize-javascript.cjs';\n\nconst tmpdir = os.tmpdir || osShim.tmpdir;\n\nconst DEFAULT_SLEEP_MS = 100;\nconst NODES = ['node', 'node.exe', 'node.cmd'];\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst worker = path.join(__dirname, 'workers', 'runFunction.cjs');\n\nimport unlinkSafe from './unlinkSafe.ts';\n\nconst existsSync = (test: string): boolean => {\n try {\n (fs.accessSync || fs.statSync)(test);\n return true;\n } catch (_) {\n return false;\n }\n};\n\nimport type { ExecWorkerOptions } from './types.ts';\n\ninterface NodeJSEnv extends NodeJS.ProcessEnv {\n NODE_OPTIONS: string;\n}\n\nexport type * from './types.ts';\nexport default function functionExecSync(filePath: string, ...args: unknown[]);\nexport default function functionExecSync(options: ExecWorkerOptions, filePath: string, ...args: unknown[]);\nexport default function functionExecSync(options: ExecWorkerOptions | string, filePath?: string | unknown[], ...args: unknown[]): unknown {\n if (typeof options === 'string') {\n args.unshift(filePath);\n filePath = options;\n options = null;\n }\n if (!filePath) throw new Error('function-exec-sync missing file');\n options = (options || {}) as ExecWorkerOptions;\n\n const env = { ...(options.env || process.env) } as NodeJSEnv;\n delete env.NODE_OPTIONS;\n const workerData = {\n filePath,\n args,\n callbacks: options.callbacks === undefined ? false : options.callbacks,\n env,\n cwd: options.cwd === undefined ? process.cwd() : options.cwd,\n };\n\n const name = options.name === undefined ? 'function-exec-sync' : options.name;\n const temp = path.join(tmpdir(), name, shortHash(workerData.cwd));\n const input = path.join(temp, suffix('input'));\n const output = path.join(temp, suffix('output'));\n const done = path.join(temp, suffix('done'));\n\n // store data to a file\n mkdirp.sync(path.dirname(input));\n fs.writeFileSync(input, serialize(workerData), 'utf8');\n unlinkSafe(output);\n\n // call the function\n const execPath = options.execPath || process.execPath;\n\n // only node\n if (NODES.indexOf(path.basename(execPath).toLowerCase()) < 0) throw new Error(`Expecting node executable. Received: ${path.basename(execPath)}`);\n\n // exec and start polling\n if (!cp.execFileSync) {\n const sleepMS = options.sleep === undefined ? DEFAULT_SLEEP_MS : options.sleep;\n let cmd = `\"${execPath}\" \"${worker}\" \"${input}\" \"${output}\"`;\n cmd += `${isWindows ? '&' : ';'} echo \"done\" > ${done}`;\n cp.exec(cmd, { env });\n while (!existsSync(done)) {\n sleep(sleepMS);\n }\n } else {\n cp.execFileSync(execPath, [worker, input, output], { env });\n }\n unlinkSafe(input);\n unlinkSafe(done);\n\n // get data and clean up\n let res: { error?: Error; value: unknown };\n try {\n // biome-ignore lint/security/noGlobalEval: Serialize\n res = eval(`(${fs.readFileSync(output, 'utf8')})`);\n unlinkSafe(output);\n } catch (err) {\n throw new Error(`function-exec-sync: Error: ${err.message}. Function: ${filePath}. Exec path: ${execPath}`);\n }\n\n // throw error from the worker\n if (res.error) {\n const error = new Error(res.error.message);\n for (const key in res.error) error[key] = res.error[key];\n throw error;\n }\n // return the result\n return res.value;\n}\n"],"names":["functionExecSync","tmpdir","os","osShim","DEFAULT_SLEEP_MS","NODES","isWindows","process","platform","test","env","OSTYPE","__dirname","path","dirname","__filename","url","fileURLToPath","worker","join","existsSync","fs","accessSync","statSync","_","options","filePath","args","unshift","Error","NODE_OPTIONS","workerData","callbacks","undefined","cwd","name","temp","shortHash","input","suffix","output","done","mkdirp","sync","writeFileSync","serialize","unlinkSafe","execPath","indexOf","basename","toLowerCase","cp","execFileSync","sleepMS","sleep","cmd","exec","res","eval","readFileSync","err","message","error","key","value"],"mappings":";;;;+BAwCA;;;eAAwBA;;;oEAxCT;yDACA;oEACI;yDACJ;6DACI;2DACF;gEACK;iEACH;wEACD;0DACF;6EACM;mEAUC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AARvB,IAAMC,SAASC,WAAE,CAACD,MAAM,IAAIE,eAAM,CAACF,MAAM;AAEzC,IAAMG,mBAAmB;AACzB,IAAMC,QAAQ;IAAC;IAAQ;IAAY;CAAW;AAC9C,IAAMC,YAAYC,QAAQC,QAAQ,KAAK,WAAW,kBAAkBC,IAAI,CAACF,QAAQG,GAAG,CAACC,MAAM;AAC3F,IAAMC,YAAYC,aAAI,CAACC,OAAO,CAAC,OAAOC,eAAe,cAAcC,YAAG,CAACC,aAAa,CAAC,uDAAmBF;AACxG,IAAMG,SAASL,aAAI,CAACM,IAAI,CAACP,WAAW,WAAW;AAI/C,IAAMQ,aAAa,SAACX;IAClB,IAAI;QACDY,CAAAA,WAAE,CAACC,UAAU,IAAID,WAAE,CAACE,QAAQ,AAAD,EAAGd;QAC/B,OAAO;IACT,EAAE,OAAOe,GAAG;QACV,OAAO;IACT;AACF;AAWe,SAASxB,iBAAiByB,OAAmC,EAAEC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OAAO;QACzC,IAAK,IAAME,OAAON,IAAIK,KAAK,CAAEA,KAAK,CAACC,IAAI,GAAGN,IAAIK,KAAK,CAACC,IAAI;QACxD,MAAMD;IACR;IACA,oBAAoB;IACpB,OAAOL,IAAIO,KAAK;AAClB"} |
| "use strict"; | ||
| var fs = require('fs'); | ||
| var serialize = require('serialize-javascript'); | ||
| var serialize = require('../serialize-javascript.cjs'); | ||
| var compat = require('async-compat'); | ||
@@ -5,0 +5,0 @@ var input = process.argv[2]; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/function-exec-sync/src/workers/runFunction.cjs"],"sourcesContent":["const fs = require('fs');\nconst serialize = require('serialize-javascript');\nconst compat = require('async-compat');\n\nconst input = process.argv[2];\nconst output = process.argv[3];\n\nfunction writeResult(result) {\n fs.writeFile(output, serialize(result), 'utf8', () => {\n process.exit(0);\n });\n}\n\nfunction writeError(error) {\n const result = { error: { message: error.message, stack: error.stack } };\n for (const key in error) result.error[key] = error[key];\n writeResult(result);\n}\n\n// get data\ntry {\n // biome-ignore lint/security/noGlobalEval: Serialize\n const workerData = eval(`(${fs.readFileSync(input, 'utf8')})`);\n\n // set up env\n if (process.cwd() !== workerData.cwd) process.chdir(workerData.cwd);\n for (const key in workerData.env) process.env[key] = workerData.env[key];\n\n // call function\n const fn = require(workerData.filePath);\n if (typeof fn !== 'function') {\n writeResult({ value: fn });\n } else {\n const args = [fn, workerData.callbacks].concat(workerData.args);\n args.push((err, value) => {\n err ? writeError(err) : writeResult({ value });\n });\n compat.asyncFunction.apply(null, args);\n }\n} catch (err) {\n writeError(err);\n}\n"],"names":["fs","require","serialize","compat","input","process","argv","output","writeResult","result","writeFile","exit","writeError","error","message","stack","key","workerData","eval","readFileSync","cwd","chdir","env","fn","filePath","value","args","callbacks","concat","push","err","asyncFunction","apply"],"mappings":";AAAA,IAAMA,KAAKC,QAAQ;AACnB,IAAMC,YAAYD,QAAQ;AAC1B,IAAME,SAASF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kevin/Dev/OpenSource/node-version/function-exec-sync/src/workers/runFunction.cjs"],"sourcesContent":["const fs = require('fs');\nconst serialize = require('../serialize-javascript.cjs');\nconst compat = require('async-compat');\n\nconst input = process.argv[2];\nconst output = process.argv[3];\n\nfunction writeResult(result) {\n fs.writeFile(output, serialize(result), 'utf8', () => {\n process.exit(0);\n });\n}\n\nfunction writeError(error) {\n const result = { error: { message: error.message, stack: error.stack } };\n for (const key in error) result.error[key] = error[key];\n writeResult(result);\n}\n\n// get data\ntry {\n // biome-ignore lint/security/noGlobalEval: Serialize\n const workerData = eval(`(${fs.readFileSync(input, 'utf8')})`);\n\n // set up env\n if (process.cwd() !== workerData.cwd) process.chdir(workerData.cwd);\n for (const key in workerData.env) process.env[key] = workerData.env[key];\n\n // call function\n const fn = require(workerData.filePath);\n if (typeof fn !== 'function') {\n writeResult({ value: fn });\n } else {\n const args = [fn, workerData.callbacks].concat(workerData.args);\n args.push((err, value) => {\n err ? writeError(err) : writeResult({ value });\n });\n compat.asyncFunction.apply(null, args);\n }\n} catch (err) {\n writeError(err);\n}\n"],"names":["fs","require","serialize","compat","input","process","argv","output","writeResult","result","writeFile","exit","writeError","error","message","stack","key","workerData","eval","readFileSync","cwd","chdir","env","fn","filePath","value","args","callbacks","concat","push","err","asyncFunction","apply"],"mappings":";AAAA,IAAMA,KAAKC,QAAQ;AACnB,IAAMC,YAAYD,QAAQ;AAC1B,IAAME,SAASF,QAAQ;AAEvB,IAAMG,QAAQC,QAAQC,IAAI,CAAC,EAAE;AAC7B,IAAMC,SAASF,QAAQC,IAAI,CAAC,EAAE;AAE9B,SAASE,YAAYC,MAAM;IACzBT,GAAGU,SAAS,CAACH,QAAQL,UAAUO,SAAS,QAAQ;QAC9CJ,QAAQM,IAAI,CAAC;IACf;AACF;AAEA,SAASC,WAAWC,KAAK;IACvB,IAAMJ,SAAS;QAAEI,OAAO;YAAEC,SAASD,MAAMC,OAAO;YAAEC,OAAOF,MAAME,KAAK;QAAC;IAAE;IACvE,IAAK,IAAMC,OAAOH,MAAOJ,OAAOI,KAAK,CAACG,IAAI,GAAGH,KAAK,CAACG,IAAI;IACvDR,YAAYC;AACd;AAEA,WAAW;AACX,IAAI;IACF,qDAAqD;IACrD,IAAMQ,aAAaC,KAAK,AAAC,IAAkC,OAA/BlB,GAAGmB,YAAY,CAACf,OAAO,SAAQ;IAE3D,aAAa;IACb,IAAIC,QAAQe,GAAG,OAAOH,WAAWG,GAAG,EAAEf,QAAQgB,KAAK,CAACJ,WAAWG,GAAG;IAClE,IAAK,IAAMJ,OAAOC,WAAWK,GAAG,CAAEjB,QAAQiB,GAAG,CAACN,IAAI,GAAGC,WAAWK,GAAG,CAACN,IAAI;IAExE,gBAAgB;IAChB,IAAMO,KAAKtB,QAAQgB,WAAWO,QAAQ;IACtC,IAAI,OAAOD,OAAO,YAAY;QAC5Bf,YAAY;YAAEiB,OAAOF;QAAG;IAC1B,OAAO;QACL,IAAMG,OAAO;YAACH;YAAIN,WAAWU,SAAS;SAAC,CAACC,MAAM,CAACX,WAAWS,IAAI;QAC9DA,KAAKG,IAAI,CAAC,SAACC,KAAKL;YACdK,MAAMlB,WAAWkB,OAAOtB,YAAY;gBAAEiB,OAAAA;YAAM;QAC9C;QACAtB,OAAO4B,aAAa,CAACC,KAAK,CAAC,MAAMN;IACnC;AACF,EAAE,OAAOI,KAAK;IACZlB,WAAWkB;AACb"} |
@@ -7,3 +7,2 @@ import cp from 'child_process'; | ||
| import path from 'path'; | ||
| import serialize from 'serialize-javascript'; | ||
| import shortHash from 'short-hash'; | ||
@@ -13,2 +12,3 @@ import suffix from 'temp-suffix'; | ||
| import url from 'url'; | ||
| import serialize from './serialize-javascript.cjs'; | ||
| const tmpdir = os.tmpdir || osShim.tmpdir; | ||
@@ -15,0 +15,0 @@ const DEFAULT_SLEEP_MS = 100; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/function-exec-sync/src/index.ts"],"sourcesContent":["import cp from 'child_process';\nimport fs from 'fs';\nimport mkdirp from 'mkdirp-classic';\nimport os from 'os';\nimport osShim from 'os-shim';\nimport path from 'path';\nimport serialize from 'serialize-javascript';\nimport shortHash from 'short-hash';\nimport suffix from 'temp-suffix';\nimport sleep from 'thread-sleep-compat';\nimport url from 'url';\n\nconst tmpdir = os.tmpdir || osShim.tmpdir;\n\nconst DEFAULT_SLEEP_MS = 100;\nconst NODES = ['node', 'node.exe', 'node.cmd'];\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst worker = path.join(__dirname, 'workers', 'runFunction.cjs');\n\nimport unlinkSafe from './unlinkSafe.ts';\n\nconst existsSync = (test: string): boolean => {\n try {\n (fs.accessSync || fs.statSync)(test);\n return true;\n } catch (_) {\n return false;\n }\n};\n\nimport type { ExecWorkerOptions } from './types.ts';\n\ninterface NodeJSEnv extends NodeJS.ProcessEnv {\n NODE_OPTIONS: string;\n}\n\nexport type * from './types.ts';\nexport default function functionExecSync(filePath: string, ...args: unknown[]);\nexport default function functionExecSync(options: ExecWorkerOptions, filePath: string, ...args: unknown[]);\nexport default function functionExecSync(options: ExecWorkerOptions | string, filePath?: string | unknown[], ...args: unknown[]): unknown {\n if (typeof options === 'string') {\n args.unshift(filePath);\n filePath = options;\n options = null;\n }\n if (!filePath) throw new Error('function-exec-sync missing file');\n options = (options || {}) as ExecWorkerOptions;\n\n const env = { ...(options.env || process.env) } as NodeJSEnv;\n delete env.NODE_OPTIONS;\n const workerData = {\n filePath,\n args,\n callbacks: options.callbacks === undefined ? false : options.callbacks,\n env,\n cwd: options.cwd === undefined ? process.cwd() : options.cwd,\n };\n\n const name = options.name === undefined ? 'function-exec-sync' : options.name;\n const temp = path.join(tmpdir(), name, shortHash(workerData.cwd));\n const input = path.join(temp, suffix('input'));\n const output = path.join(temp, suffix('output'));\n const done = path.join(temp, suffix('done'));\n\n // store data to a file\n mkdirp.sync(path.dirname(input));\n fs.writeFileSync(input, serialize(workerData), 'utf8');\n unlinkSafe(output);\n\n // call the function\n const execPath = options.execPath || process.execPath;\n\n // only node\n if (NODES.indexOf(path.basename(execPath).toLowerCase()) < 0) throw new Error(`Expecting node executable. Received: ${path.basename(execPath)}`);\n\n // exec and start polling\n if (!cp.execFileSync) {\n const sleepMS = options.sleep === undefined ? DEFAULT_SLEEP_MS : options.sleep;\n let cmd = `\"${execPath}\" \"${worker}\" \"${input}\" \"${output}\"`;\n cmd += `${isWindows ? '&' : ';'} echo \"done\" > ${done}`;\n cp.exec(cmd, { env });\n while (!existsSync(done)) {\n sleep(sleepMS);\n }\n } else {\n cp.execFileSync(execPath, [worker, input, output], { env });\n }\n unlinkSafe(input);\n unlinkSafe(done);\n\n // get data and clean up\n let res: { error?: Error; value: unknown };\n try {\n // biome-ignore lint/security/noGlobalEval: Serialize\n res = eval(`(${fs.readFileSync(output, 'utf8')})`);\n unlinkSafe(output);\n } catch (err) {\n throw new Error(`function-exec-sync: Error: ${err.message}. Function: ${filePath}. Exec path: ${execPath}`);\n }\n\n // throw error from the worker\n if (res.error) {\n const error = new Error(res.error.message);\n for (const key in res.error) error[key] = res.error[key];\n throw error;\n }\n // return the result\n return res.value;\n}\n"],"names":["cp","fs","mkdirp","os","osShim","path","serialize","shortHash","suffix","sleep","url","tmpdir","DEFAULT_SLEEP_MS","NODES","isWindows","process","platform","test","env","OSTYPE","__dirname","dirname","__filename","fileURLToPath","worker","join","unlinkSafe","existsSync","accessSync","statSync","_","functionExecSync","options","filePath","args","unshift","Error","NODE_OPTIONS","workerData","callbacks","undefined","cwd","name","temp","input","output","done","sync","writeFileSync","execPath","indexOf","basename","toLowerCase","execFileSync","sleepMS","cmd","exec","res","eval","readFileSync","err","message","error","key","value"],"mappings":"AAAA,OAAOA,QAAQ,gBAAgB;AAC/B,OAAOC,QAAQ,KAAK;AACpB,OAAOC,YAAY,iBAAiB;AACpC,OAAOC,QAA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oB;YAAOC;SAAO,EAAE;YAAE3B;QAAI;IAC3D;IACAQ,WAAWkB;IACXlB,WAAWoB;IAEX,wBAAwB;IACxB,IAAIW;IACJ,IAAI;QACF,qDAAqD;QACrDA,MAAMC,KAAK,CAAC,CAAC,EAAEzD,GAAG0D,YAAY,CAACd,QAAQ,QAAQ,CAAC,CAAC;QACjDnB,WAAWmB;IACb,EAAE,OAAOe,KAAK;QACZ,MAAM,IAAIxB,MAAM,CAAC,2BAA2B,EAAEwB,IAAIC,OAAO,CAAC,YAAY,EAAE5B,SAAS,aAAa,EAAEgB,UAAU;IAC5G;IAEA,8BAA8B;IAC9B,IAAIQ,IAAIK,KAAK,EAAE;QACb,MAAMA,QAAQ,IAAI1B,MAAMqB,IAAIK,KAAK,CAACD,OAAO;QACzC,IAAK,MAAME,OAAON,IAAIK,KAAK,CAAEA,KAAK,CAACC,IAAI,GAAGN,IAAIK,KAAK,CAACC,IAAI;QACxD,MAAMD;IACR;IACA,oBAAoB;IACpB,OAAOL,IAAIO,KAAK;AAClB"} | ||
| {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/function-exec-sync/src/index.ts"],"sourcesContent":["import cp from 'child_process';\nimport fs from 'fs';\nimport mkdirp from 'mkdirp-classic';\nimport os from 'os';\nimport osShim from 'os-shim';\nimport path from 'path';\nimport shortHash from 'short-hash';\nimport suffix from 'temp-suffix';\nimport sleep from 'thread-sleep-compat';\nimport url from 'url';\nimport serialize from './serialize-javascript.cjs';\n\nconst tmpdir = os.tmpdir || osShim.tmpdir;\n\nconst DEFAULT_SLEEP_MS = 100;\nconst NODES = ['node', 'node.exe', 'node.cmd'];\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst worker = path.join(__dirname, 'workers', 'runFunction.cjs');\n\nimport unlinkSafe from './unlinkSafe.ts';\n\nconst existsSync = (test: string): boolean => {\n try {\n (fs.accessSync || fs.statSync)(test);\n return true;\n } catch (_) {\n return false;\n }\n};\n\nimport type { ExecWorkerOptions } from './types.ts';\n\ninterface NodeJSEnv extends NodeJS.ProcessEnv {\n NODE_OPTIONS: string;\n}\n\nexport type * from './types.ts';\nexport default function functionExecSync(filePath: string, ...args: unknown[]);\nexport default function functionExecSync(options: ExecWorkerOptions, filePath: string, ...args: unknown[]);\nexport default function functionExecSync(options: ExecWorkerOptions | string, filePath?: string | unknown[], ...args: unknown[]): unknown {\n if (typeof options === 'string') {\n args.unshift(filePath);\n filePath = options;\n options = null;\n }\n if (!filePath) throw new Error('function-exec-sync missing file');\n options = (options || {}) as ExecWorkerOptions;\n\n const env = { ...(options.env || process.env) } as NodeJSEnv;\n delete env.NODE_OPTIONS;\n const workerData = {\n filePath,\n args,\n callbacks: options.callbacks === undefined ? false : options.callbacks,\n env,\n cwd: options.cwd === undefined ? process.cwd() : options.cwd,\n };\n\n const name = options.name === undefined ? 'function-exec-sync' : options.name;\n const temp = path.join(tmpdir(), name, shortHash(workerData.cwd));\n const input = path.join(temp, suffix('input'));\n const output = path.join(temp, suffix('output'));\n const done = path.join(temp, suffix('done'));\n\n // store data to a file\n mkdirp.sync(path.dirname(input));\n fs.writeFileSync(input, serialize(workerData), 'utf8');\n unlinkSafe(output);\n\n // call the function\n const execPath = options.execPath || process.execPath;\n\n // only node\n if (NODES.indexOf(path.basename(execPath).toLowerCase()) < 0) throw new Error(`Expecting node executable. Received: ${path.basename(execPath)}`);\n\n // exec and start polling\n if (!cp.execFileSync) {\n const sleepMS = options.sleep === undefined ? DEFAULT_SLEEP_MS : options.sleep;\n let cmd = `\"${execPath}\" \"${worker}\" \"${input}\" \"${output}\"`;\n cmd += `${isWindows ? '&' : ';'} echo \"done\" > ${done}`;\n cp.exec(cmd, { env });\n while (!existsSync(done)) {\n sleep(sleepMS);\n }\n } else {\n cp.execFileSync(execPath, [worker, input, output], { env });\n }\n unlinkSafe(input);\n unlinkSafe(done);\n\n // get data and clean up\n let res: { error?: Error; value: unknown };\n try {\n // biome-ignore lint/security/noGlobalEval: Serialize\n res = eval(`(${fs.readFileSync(output, 'utf8')})`);\n unlinkSafe(output);\n } catch (err) {\n throw new Error(`function-exec-sync: Error: ${err.message}. Function: ${filePath}. Exec path: ${execPath}`);\n }\n\n // throw error from the worker\n if (res.error) {\n const error = new Error(res.error.message);\n for (const key in res.error) error[key] = res.error[key];\n throw error;\n }\n // return the result\n return res.value;\n}\n"],"names":["cp","fs","mkdirp","os","osShim","path","shortHash","suffix","sleep","url","serialize","tmpdir","DEFAULT_SLEEP_MS","NODES","isWindows","process","platform","test","env","OSTYPE","__dirname","dirname","__filename","fileURLToPath","worker","join","unlinkSafe","existsSync","accessSync","statSync","_","functionExecSync","options","filePath","args","unshift","Error","NODE_OPTIONS","workerData","callbacks","undefined","cwd","name","temp","input","output","done","sync","writeFileSync","execPath","indexOf","basename","toLowerCase","execFileSync","sleepMS","cmd","exec","res","eval","readFileSync","err","message","error","key","value"],"mappings":"AAAA,OAAOA,QAAQ,gBAAgB;AAC/B,OAAOC,QAAQ,KAAK;AACpB,OAAOC,YAAY,iBAAiB;AACpC,OAAOC,QAAQ,KAAK;AACpB,OAAOC,YAAY,UAAU;AAC7B,OAAOC,UAAU,OAAO;AACxB,OAAOC,eAAe,aAAa;AACnC,OAAOC,YAAY,cAAc;AACjC,OAAOC,WAAW,sBAAsB;AACxC,OAAOC,SAAS,MAAM;AACtB,OAAOC,eAAe,6BAA6B;AAEnD,MAAMC,SAASR,GAAGQ,MAAM,IAAIP,OAAOO,MAAM;AAEzC,MAAMC,mBAAmB;AACzB,MAAMC,QAAQ;IAAC;IAAQ;IAAY;CAAW;AAC9C,MAAMC,YAAYC,QAAQC,QAAQ,KAAK,WAAW,kBAAkBC,IAAI,CAACF,QAAQG,GAAG,CAACC,MAAM;AAC3F,MAAMC,YAAYf,KAAKgB,OAAO,CAAC,OAAOC,eAAe,cAAcb,IAAIc,aAAa,CAAC,YAAYd,G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AAON,IAAIK,KAAK,CAAEA,KAAK,CAACC,IAAI,GAAGN,IAAIK,KAAK,CAACC,IAAI;QACxD,MAAMD;IACR;IACA,oBAAoB;IACpB,OAAOL,IAAIO,KAAK;AAClB"} |
| const fs = require('fs'); | ||
| const serialize = require('serialize-javascript'); | ||
| const serialize = require('../serialize-javascript.cjs'); | ||
| const compat = require('async-compat'); | ||
@@ -4,0 +4,0 @@ const input = process.argv[2]; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/function-exec-sync/src/workers/runFunction.cjs"],"sourcesContent":["const fs = require('fs');\nconst serialize = require('serialize-javascript');\nconst compat = require('async-compat');\n\nconst input = process.argv[2];\nconst output = process.argv[3];\n\nfunction writeResult(result) {\n fs.writeFile(output, serialize(result), 'utf8', () => {\n process.exit(0);\n });\n}\n\nfunction writeError(error) {\n const result = { error: { message: error.message, stack: error.stack } };\n for (const key in error) result.error[key] = error[key];\n writeResult(result);\n}\n\n// get data\ntry {\n // biome-ignore lint/security/noGlobalEval: Serialize\n const workerData = eval(`(${fs.readFileSync(input, 'utf8')})`);\n\n // set up env\n if (process.cwd() !== workerData.cwd) process.chdir(workerData.cwd);\n for (const key in workerData.env) process.env[key] = workerData.env[key];\n\n // call function\n const fn = require(workerData.filePath);\n if (typeof fn !== 'function') {\n writeResult({ value: fn });\n } else {\n const args = [fn, workerData.callbacks].concat(workerData.args);\n args.push((err, value) => {\n err ? writeError(err) : writeResult({ value });\n });\n compat.asyncFunction.apply(null, args);\n }\n} catch (err) {\n writeError(err);\n}\n"],"names":["fs","require","serialize","compat","input","process","argv","output","writeResult","result","writeFile","exit","writeError","error","message","stack","key","workerData","eval","readFileSync","cwd","chdir","env","fn","filePath","value","args","callbacks","concat","push","err","asyncFunction","apply"],"mappings":"AAAA,MAAMA,KAAKC,QAAQ;AACnB,MAAMC,YAAYD,QAAQ;AAC1B,MAAME,SAASF,QAAQ;AAEvB,MAAMG,QAAQC,QAAQC,I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runFunction.cjs"],"sourcesContent":["const fs = require('fs');\nconst serialize = require('../serialize-javascript.cjs');\nconst compat = require('async-compat');\n\nconst input = process.argv[2];\nconst output = process.argv[3];\n\nfunction writeResult(result) {\n fs.writeFile(output, serialize(result), 'utf8', () => {\n process.exit(0);\n });\n}\n\nfunction writeError(error) {\n const result = { error: { message: error.message, stack: error.stack } };\n for (const key in error) result.error[key] = error[key];\n writeResult(result);\n}\n\n// get data\ntry {\n // biome-ignore lint/security/noGlobalEval: Serialize\n const workerData = eval(`(${fs.readFileSync(input, 'utf8')})`);\n\n // set up env\n if (process.cwd() !== workerData.cwd) process.chdir(workerData.cwd);\n for (const key in workerData.env) process.env[key] = workerData.env[key];\n\n // call function\n const fn = require(workerData.filePath);\n if (typeof fn !== 'function') {\n writeResult({ value: fn });\n } else {\n const args = [fn, workerData.callbacks].concat(workerData.args);\n args.push((err, value) => {\n err ? writeError(err) : writeResult({ value });\n });\n compat.asyncFunction.apply(null, args);\n }\n} catch (err) {\n writeError(err);\n}\n"],"names":["fs","require","serialize","compat","input","process","argv","output","writeResult","result","writeFile","exit","writeError","error","message","stack","key","workerData","eval","readFileSync","cwd","chdir","env","fn","filePath","value","args","callbacks","concat","push","err","asyncFunction","apply"],"mappings":"AAAA,MAAMA,KAAKC,QAAQ;AACnB,MAAMC,YAAYD,QAAQ;AAC1B,MAAME,SAASF,QAAQ;AAEvB,MAAMG,QAAQC,QAAQC,IAAI,CAAC,EAAE;AAC7B,MAAMC,SAASF,QAAQC,IAAI,CAAC,EAAE;AAE9B,SAASE,YAAYC,MAAM;IACzBT,GAAGU,SAAS,CAACH,QAAQL,UAAUO,SAAS,QAAQ;QAC9CJ,QAAQM,IAAI,CAAC;IACf;AACF;AAEA,SAASC,WAAWC,KAAK;IACvB,MAAMJ,SAAS;QAAEI,OAAO;YAAEC,SAASD,MAAMC,OAAO;YAAEC,OAAOF,MAAME,KAAK;QAAC;IAAE;IACvE,IAAK,MAAMC,OAAOH,MAAOJ,OAAOI,KAAK,CAACG,IAAI,GAAGH,KAAK,CAACG,IAAI;IACvDR,YAAYC;AACd;AAEA,WAAW;AACX,IAAI;IACF,qDAAqD;IACrD,MAAMQ,aAAaC,KAAK,CAAC,CAAC,EAAElB,GAAGmB,YAAY,CAACf,OAAO,QAAQ,CAAC,CAAC;IAE7D,aAAa;IACb,IAAIC,QAAQe,GAAG,OAAOH,WAAWG,GAAG,EAAEf,QAAQgB,KAAK,CAACJ,WAAWG,GAAG;IAClE,IAAK,MAAMJ,OAAOC,WAAWK,GAAG,CAAEjB,QAAQiB,GAAG,CAACN,IAAI,GAAGC,WAAWK,GAAG,CAACN,IAAI;IAExE,gBAAgB;IAChB,MAAMO,KAAKtB,QAAQgB,WAAWO,QAAQ;IACtC,IAAI,OAAOD,OAAO,YAAY;QAC5Bf,YAAY;YAAEiB,OAAOF;QAAG;IAC1B,OAAO;QACL,MAAMG,OAAO;YAACH;YAAIN,WAAWU,SAAS;SAAC,CAACC,MAAM,CAACX,WAAWS,IAAI;QAC9DA,KAAKG,IAAI,CAAC,CAACC,KAAKL;YACdK,MAAMlB,WAAWkB,OAAOtB,YAAY;gBAAEiB;YAAM;QAC9C;QACAtB,OAAO4B,aAAa,CAACC,KAAK,CAAC,MAAMN;IACnC;AACF,EAAE,OAAOI,KAAK;IACZlB,WAAWkB;AACb"} |
+3
-5
| { | ||
| "name": "function-exec-sync", | ||
| "version": "1.4.1", | ||
| "version": "1.4.2", | ||
| "description": "Run a function in a node process", | ||
@@ -37,4 +37,3 @@ "keywords": [ | ||
| "files": [ | ||
| "dist", | ||
| "patches" | ||
| "dist" | ||
| ], | ||
@@ -44,3 +43,2 @@ "scripts": { | ||
| "format": "biome check --write --unsafe", | ||
| "postinstall": "patch-package", | ||
| "test": "mocha --no-timeouts test/**/*.test.*", | ||
@@ -55,3 +53,3 @@ "test:engines": "nvu engines tsds test:node --no-timeouts", | ||
| "patch-package": "^8.0.0", | ||
| "serialize-javascript": "6.0.2", | ||
| "randombytes": "^2.1.0", | ||
| "short-hash": "^1.0.0", | ||
@@ -58,0 +56,0 @@ "temp-suffix": "^0.1.20", |
| diff --git a/node_modules/serialize-javascript/index.js b/node_modules/serialize-javascript/index.js | ||
| index 156f8f9..322a68a 100644 | ||
| --- a/node_modules/serialize-javascript/index.js | ||
| +++ b/node_modules/serialize-javascript/index.js | ||
| @@ -55,6 +55,11 @@ function deleteFunctions(obj){ | ||
| } | ||
| } | ||
| +var hasMap = typeof Map !== 'undefined'; | ||
| +var hasSet = typeof Set !== 'undefined'; | ||
| +var hasURL = typeof URL !== 'undefined'; | ||
| +var hasBigInt = typeof BigInt !== 'undefined'; | ||
| + | ||
| module.exports = function serialize(obj, options) { | ||
| options || (options = {}); | ||
| @@ -83,7 +88,7 @@ module.exports = function serialize(obj, options) { | ||
| deleteFunctions(value); | ||
| } | ||
| - if (!value && value !== undefined && value !== BigInt(0)) { | ||
| + if (hasBigInt && !value && value !== undefined && value !== BigInt(0)) { | ||
| return value; | ||
| } | ||
| @@ -101,11 +106,11 @@ module.exports = function serialize(obj, options) { | ||
| return '@__D-' + UID + '-' + (dates.push(origValue) - 1) + '__@'; | ||
| } | ||
| - if(origValue instanceof Map) { | ||
| + if(hasMap && origValue instanceof Map) { | ||
| return '@__M-' + UID + '-' + (maps.push(origValue) - 1) + '__@'; | ||
| } | ||
| - if(origValue instanceof Set) { | ||
| + if(hasSet && origValue instanceof Set) { | ||
| return '@__S-' + UID + '-' + (sets.push(origValue) - 1) + '__@'; | ||
| } | ||
| @@ -116,7 +121,7 @@ module.exports = function serialize(obj, options) { | ||
| } | ||
| } | ||
| - if(origValue instanceof URL) { | ||
| + if(hasURL && origValue instanceof URL) { | ||
| return '@__L-' + UID + '-' + (urls.push(origValue) - 1) + '__@'; | ||
| } | ||
| } |
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
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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 2 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
Install scripts
Supply chain riskInstall scripts are run when the package is installed or built. Malicious packages often use scripts that run automatically to execute payloads or fetch additional code.
Found 1 instance in 1 package
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
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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 2 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
89771
112.49%38
15.15%865
112.53%0
-100%15
7.14%+ Added
- Removed
- Removed