/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/liftoff@5.0.1/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
var util=require("util"),path=require("path"),EE=require("events").EventEmitter,extend=require("extend"),resolve=require("resolve"),flaggedRespawn=require("flagged-respawn"),isPlainObject=require("is-plain-object").isPlainObject,fined=require("fined"),findCwd=require("./lib/find_cwd"),arrayFind=require("./lib/array_find"),findConfig=require("./lib/find_config"),fileSearch=require("./lib/file_search"),needsLookup=require("./lib/needs_lookup"),parseOptions=require("./lib/parse_options"),silentRequire=require("./lib/silent_require"),buildConfigName=require("./lib/build_config_name"),registerLoader=require("./lib/register_loader"),getNodeFlags=require("./lib/get_node_flags");function isString(e){return"string"==typeof e}function Liftoff(e){EE.call(this),extend(this,parseOptions(e))}function preloadModules(e,i){var r=i.cwd;i.preload.filter(toUnique).forEach((function(i){e.requireLocal(i,r)}))}function toUnique(e,i,r){return r.indexOf(e)===i}util.inherits(Liftoff,EE),Liftoff.prototype.requireLocal=function(e,i){try{this.emit("preload:before",e);var r=require(resolve.sync(e,{basedir:i}));return this.emit("preload:success",e,r),r}catch(i){this.emit("preload:failure",e,i)}},Liftoff.prototype.buildEnvironment=function(e){var i=(e=e||{}).preload||[];Array.isArray(i)||(i=[i]);var r=this.searchPaths.slice(),t=this.configName,n=findCwd(e),o=this.extensions,a=this;function s(e,i){var r=fined(e,i);return r?(isPlainObject(r.extension)&&registerLoader(a,r.extension,r.path,n),r.path):null}var f={};function l(e,i,r){var n,a=function(e,i){if(needsLookup(i)){var r=s(i,{cwd:e,extensions:o});if(!r){var t,n="Unable to locate one of your extends.";throw(t="string"==typeof i?i:i.path||i.name)&&(n+=" Looking for file: "+path.resolve(e,t)),new Error(n)}return r}return i}(e,i);if(f[a])throw new Error("We encountered a circular extend for file: "+a+". Please remove the recursive extends.");try{n=require(a)}catch(e){throw new Error("Encountered error when loading config file: "+a)}if(Object.prototype.hasOwnProperty.call(n,t)&&isString(n[t])&&(n[t]=path.resolve(path.dirname(a),n[t])),f[a]=!0,n&&n.extends)return l(path.dirname(a),n.extends,n);var c=extend(!0,{},n,r);return delete c.extends,c}var c=[];Array.isArray(this.configFiles)&&(c=this.configFiles.map((function(e){return s(e,{cwd:n,extensions:o})})));var u=c.map((function(e){var i={};return e?l(n,e,i):i})),d=arrayFind(u,(function(e){if(Object.prototype.hasOwnProperty.call(e,t)&&isString(e[t]))return e[t]})),p=arrayFind(u,(function(e){if(Object.prototype.hasOwnProperty.call(e,"preload")){if(Array.isArray(e.preload)&&e.preload.every(isString))return e.preload;if(isString(e.preload))return e.preload}}));e.cwd?r=[n]:r.unshift(n);var h,g,v,m=buildConfigName({configName:t,extensions:Object.keys(this.extensions)}),y=findConfig({configNameSearch:m,searchPaths:r,configPath:e.configPath||d});y&&(h=path.dirname(y),e.cwd||(n=h));try{var b=path.delimiter,w=process.env.NODE_PATH?process.env.NODE_PATH.split(b):[];g=resolve.sync(this.moduleName,{basedir:h||n,paths:w}),v=silentRequire(fileSearch("package.json",[g]))}catch(e){}if(!g&&y){var q=fileSearch("package.json",[h]);(v=silentRequire(q))&&v.name===this.moduleName?(g=path.join(path.dirname(q),v.main||"index.js"),n=h):v={}}return{cwd:n,preload:i.concat(p||[]),completion:e.completion,configNameSearch:m,configPath:y,configBase:h,modulePath:g,modulePackage:v||{},configFiles:c,config:u}},Liftoff.prototype.handleFlags=function(e){"function"==typeof this.v8flags?this.v8flags((function(i,r){i?e(i):e(null,r)})):process.nextTick(function(){e(null,this.v8flags)}.bind(this))},Liftoff.prototype.prepare=function(e,i){if("function"!=typeof i)throw new Error("You must provide a callback function.");process.title=this.processTitle;var r=this.buildEnvironment(e);i.call(this,r)},Liftoff.prototype.execute=function(e,i,r){var t=e.completion;if(t&&this.completions)return this.completions(t);if("function"==typeof i&&(r=i,i=void 0),"function"!=typeof r)throw new Error("You must provide a callback function.");this.handleFlags(function(t,n){if(t)throw t;flaggedRespawn(n=n||[],process.argv,i,function(i,t,n){if(t!==process){var o=getNodeFlags.fromReorderedArgv(n);this.emit("respawn",o,t)}i&&(preloadModules(this,e),registerLoader(this,this.extensions,e.configPath,e.cwd),r.call(this,e,n))}.bind(this))}.bind(this))},module.exports=Liftoff;
//# sourceMappingURL=/sm/fd277bdcd34826574f6a67039a5a0fac339326336e65aee6e3c0aca55abe99aa.map