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OACtC,CAEX,MAAO,GAAsB,wBAAnB,EAAU,OAClB,EAAU,aAAa,SAAQ,IAC7B,GAA2B,YAAvB,EAAW,GAAG,KAGhB,OAFA,KAAK,KAAO,MACZ,KAAK,qBAAqB,EAAW,KAAM,OACpC,CACT,IAGgB,QAAd,KAAK,MAAgB,OAAO,CAClC,IAIc,UAAd,KAAK,OACP,KAAK,OAAS,CAAC,GAGV,KAAK,MACd,CAEA,KAAA,GACE,IAAI,EAEJ,GAAkB,UAAd,KAAK,MAAkC,yBAAd,KAAK,KAChC,EAAW,KAAK,OAAO,mDAAoD,KAAK,mBAE3E,CAEL,IAAK,KAAK,MACR,MAAM,IAAI,MAAM,0KAGlB,EAAW,KAAK,SAAS,UAAU,EAAG,KAAK,MAAM,IAAM,KAAK,cAAgB,KAAK,SAAS,UAAU,KAAK,MAAM,GACjH,CAEA,eAAe,KAAK,SAAU,EAAU,KAAK,WAC/C,CAOA,iBAAA,CAAkB,EAAS,CAAC,GAC1B,KAAK,OAAS,EACd,KAAK,KAAO,sBACd,CAEA,WAAA,GACE,OAAO,gBACL,KAAK,OACL,CACE,OAAQ,MAGd,CAEA,oBAAA,CAAqB,iBAAkB,UAErC,GAAI,kBAA8C,qBAA1B,iBAAiB,KAA6B,CACpE,IACE,KAAK,OAAS,KAAK,IAAI,KAAK,SAAS,UAAU,iBAAiB,MAAM,GAAI,iBAAiB,MAAM,OAEnG,CAAE,MAAO,GACP,OAAO,SAAS,EAAa,KAC/B,CAGA,OADA,KAAK,MAAQ,iBAAiB,MACvB,SAAS,KAAM,KAAK,OAC7B,CAEA,OAAO,SAAS,qCAAqC,KAAK,QAAQ,kBACpE,EAGF,OAAO,QAAU,CAAC","file":"/npm/requirejs-config-file@4.0.0/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.37.0.\n * Original file: /npm/requirejs-config-file@4.0.0/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","'use strict';\n\nconst fs = require('fs');\nconst path = require('path');\nconst esprima = require('esprima');\nconst util = require('util');\nconst stringifyObject = require(\"stringify-object\");\n\nconst noop = function(){};\n\nfunction outputFileSync (filePath, contents, fileSystem = fs) {\n  const dir = path.dirname(filePath);\n  fileSystem.mkdirSync(dir, {recursive: true});\n  fileSystem.writeFileSync(filePath, contents);\n}\n\nclass ConfigFile {\n  constructor(filePath, fileSystem = fs) {\n    this.filePath = filePath;\n    this.fileSystem = fileSystem;\n    this.config = null;\n\n    /**\n     * null = never read\n     * var = config was read with var require = {...}\n     * requirejs = config was read with requirejs.config({...})\n     * require = config was read with require.config({...})\n     * empty = no config expression was found (but read() was called)\n     * create-if-not-exists = createIfNotExists() was called so it might not have an existing file\n     */\n    this.type = null;\n\n    /**\n     * The position where the object expression should be written back to\n     */\n    this.range = null;\n\n    this.contents = null;\n  }\n\n  /**\n   * returns the config object from the read file\n   */\n  read() {\n    try {\n      const data = this.fileSystem.readFileSync(this.filePath);\n\n      this.contents = data.toString();\n\n    } catch (err) {\n      if (err.code === 'ENOENT' && this.type === 'create-if-not-exists') {\n        return this.config;\n      } else {\n        throw err;\n      }\n    }\n\n    let program;\n\n    try {\n      program = esprima.parse(this.contents, {range: true});\n    } catch (ex) {\n      throw new Error(`could not read: ${this.filePath} because it has syntax errors: ${ex}`);\n    }\n\n    this.type = 'empty';\n    if (program.type === 'Program') {\n      program.body.forEach(statement => {\n\n        if (statement.expression && statement.expression.type === 'CallExpression') {\n          const call = statement.expression;\n\n          if (call.callee.type === 'MemberExpression' && (call.callee.object.name === 'requirejs' || call.callee.object.name === 'require') && call.callee.property.name === 'config') {\n            this.type = call.callee.object.name === 'require' ? 'require' : 'requirejs';\n            this.readObjectExpression(call.arguments[0], noop);\n            return false;\n          }\n        } else if(statement.type === 'VariableDeclaration') {\n          statement.declarations.forEach(declarator => {\n            if (declarator.id.name === 'require') {\n              this.type = 'var';\n              this.readObjectExpression(declarator.init, noop);\n              return false;\n            }\n          });\n\n          if (this.type === 'var') return false;\n        }\n      });\n    }\n\n    if (this.type === 'empty') {\n      this.config = {};\n    }\n\n    return this.config;\n  }\n\n  write() {\n    let contents;\n\n    if (this.type === 'empty' || this.type === 'create-if-not-exists') {\n      contents = util.format(\"/* globals requirejs */\\nrequirejs.config(%s);\\n\", this.buildConfig());\n\n    } else {\n\n      if (!this.range) {\n        throw new Error('The config cannot be written. Was it read() before? The config expression has to be found to allow writing. You can use createIfNotExists() to create an empty config.');\n      }\n\n      contents = this.contents.substring(0, this.range[0]) + this.buildConfig() + this.contents.substring(this.range[1]);\n    }\n\n    outputFileSync(this.filePath, contents, this.fileSystem);\n  }\n\n  /**\n   * Creates the config(File) if not already existing\n   *\n   * notice: you still need to write() it to have a physical existing file.\n   */\n  createIfNotExists(config = {}) {\n    this.config = config;\n    this.type = 'create-if-not-exists';\n  }\n\n  buildConfig() {\n    return stringifyObject(\n      this.config,\n      {\n        indent: '  '\n      }\n    );\n  }\n\n  readObjectExpression(objectExpression, callback) {\n    /* jshint evil:true */\n    if (objectExpression && objectExpression.type === 'ObjectExpression') {\n      try {\n        this.config = eval(`(${this.contents.substring(objectExpression.range[0], objectExpression.range[1])})`);\n\n      } catch (syntaxError) {\n        return callback(syntaxError, null);\n      }\n\n      this.range = objectExpression.range;\n      return callback(null, this.config);\n    }\n\n    return callback('cannot read objectExpression from '+util.inspect(objectExpression));\n  }\n}\n\nmodule.exports = {ConfigFile};\n"]}