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BAAwB,EAAQ,EAAU,EAAY,GACxE,EAAK,KAAK,MAAM,EAAM,EACxB,MACE,EAAK,KAAK,GAUZ,GAPI,eAAiB,iBAAiB,IAIpC,cAAc,KAAK,WAGI,UAArB,QAAQ,SAAsB,CA0ChC,MAAM,EAAgB,CAAC,KAAW,EAAK,KAnBvC,SAAwB,GACtB,OAAO,EAAQ,QAAQ,gBAAiB,MAC1C,KAkBG,KAXH,SAA6B,GAC3B,OAAI,EAAI,SAAS,KAGR,KAAK,MACH,EAAI,SAAS,KACf,IAAI,KAEN,CACT,IAGG,KAAK,KAER,cAAgB,aAAa,KAAK,EAAe,CAC/C,MAAO,UACP,OAAO,GAEX,MACE,cAAgB,aAAa,MAAM,EAAQ,EAAM,CAAE,MAAO,YAE5D,cAAc,GAAG,QAAQ,SAAU,GACjC,cAAgB,KAEZ,GACF,EAAgB,EAAU,SAAW,EAAY,IAErD,IAEA,cAAc,GAAG,SAAS,SAAU,GAClC,IAAI,KAAE,EAAI,QAAE,GAAY,EACpB,WAAa,IACf,EAAU,GAAG,OAAa,wCAE5B,EAAgB,EAAU,EAC5B,GAjGA,MAFE,EAAgB,EAAU,KAoG9B,CAEA,OAAO,QAAU","file":"/npm/launch-editor@2.13.2/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/launch-editor@2.13.2/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","/**\n * Copyright (c) 2015-present, Facebook, Inc.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file at\n * https://github.com/facebookincubator/create-react-app/blob/master/LICENSE\n *\n * Modified by Yuxi Evan You\n */\n\nconst fs = require('fs')\nconst os = require('os')\nconst path = require('path')\nconst colors = require('picocolors')\nconst childProcess = require('child_process')\n\nconst guessEditor = require('./guess')\nconst getArgumentsForPosition = require('./get-args')\n\nfunction wrapErrorCallback (cb) {\n  return (fileName, errorMessage) => {\n    console.log()\n    console.log(\n      colors.red('Could not open ' + path.basename(fileName) + ' in the editor.')\n    )\n    if (errorMessage) {\n      if (errorMessage[errorMessage.length - 1] !== '.') {\n        errorMessage += '.'\n      }\n      console.log(\n        colors.red('The editor process exited with an error: ' + errorMessage)\n      )\n    }\n    console.log()\n    if (cb) cb(fileName, errorMessage)\n  }\n}\n\nfunction isTerminalEditor (editor) {\n  switch (editor) {\n    case 'vim':\n    case 'emacs':\n    case 'nano':\n      return true\n  }\n  return false\n}\n\nconst positionRE = /:(\\d+)(:(\\d+))?$/\nfunction parseFile (file) {\n  // support `file://` protocol\n  if (file.startsWith('file://')) {\n    file = require('url').fileURLToPath(file)\n  }\n\n  const fileName = file.replace(positionRE, '')\n  const match = file.match(positionRE)\n  const lineNumber = match && match[1]\n  const columnNumber = match && match[3]\n  return {\n    fileName,\n    lineNumber,\n    columnNumber\n  }\n}\n\nlet _childProcess = null\n\nfunction launchEditor (file, specifiedEditor, onErrorCallback) {\n  const parsed = parseFile(file)\n  let { fileName } = parsed\n  const { lineNumber, columnNumber } = parsed\n\n  if (!fs.existsSync(fileName)) {\n    return\n  }\n\n  if (typeof specifiedEditor === 'function') {\n    onErrorCallback = specifiedEditor\n    specifiedEditor = undefined\n  }\n\n  onErrorCallback = wrapErrorCallback(onErrorCallback)\n\n  const [editor, ...args] = guessEditor(specifiedEditor)\n  if (!editor) {\n    onErrorCallback(fileName, null)\n    return\n  }\n\n  if (\n    process.platform === 'linux' &&\n    fileName.startsWith('/mnt/') &&\n    /Microsoft/i.test(os.release())\n  ) {\n    // Assume WSL / \"Bash on Ubuntu on Windows\" is being used, and\n    // that the file exists on the Windows file system.\n    // `os.release()` is \"4.4.0-43-Microsoft\" in the current release\n    // build of WSL, see: https://github.com/Microsoft/BashOnWindows/issues/423#issuecomment-221627364\n    // When a Windows editor is specified, interop functionality can\n    // handle the path translation, but only if a relative path is used.\n    fileName = path.relative('', fileName)\n  }\n\n  if (lineNumber) {\n    const extraArgs = getArgumentsForPosition(editor, fileName, lineNumber, columnNumber)\n    args.push.apply(args, extraArgs)\n  } else {\n    args.push(fileName)\n  }\n\n  if (_childProcess && isTerminalEditor(editor)) {\n    // There's an existing editor process already and it's attached\n    // to the terminal, so go kill it. Otherwise two separate editor\n    // instances attach to the stdin/stdout which gets confusing.\n    _childProcess.kill('SIGKILL')\n  }\n\n  if (process.platform === 'win32') {\n    // On Windows, we need to use `exec` with the `shell: true` option,\n    // and some more sanitization is required.\n\n    // However, CMD.exe on Windows is vulnerable to RCE attacks given a file name of the\n    // form \"C:\\Users\\myusername\\Downloads\\& curl 172.21.93.52\".\n    // `create-react-app` used a safe file name pattern to validate user-provided file names:\n    // - https://github.com/facebook/create-react-app/pull/4866\n    // - https://github.com/facebook/create-react-app/pull/5431\n    // But that's not a viable solution for this package because\n    // it's depended on by so many meta frameworks that heavily rely on\n    // special characters in file names for filesystem-based routing.\n    // We need to at least:\n    // - Support `+` because it's used in SvelteKit and Vike\n    // - Support `$` because it's used in Remix\n    // - Support `(` and `)` because they are used in Analog, SolidStart, and Vike\n    // - Support `@` because it's used in Vike\n    // - Support `[` and `]` because they are widely used for [slug]\n    // So here we choose to use `^` to escape special characters instead.\n\n    // According to https://ss64.com/nt/syntax-esc.html,\n    // we can use `^` to escape `&`, `<`, `>`, `|`, `%`, and `^`\n    // I'm not sure if we have to escape all of these, but let's do it anyway\n    function escapeCmdArgs (cmdArgs) {\n      return cmdArgs.replace(/([&|<>,;=^])/g, '^$1')\n    }\n\n    // Need to double quote the editor path in case it contains spaces;\n    // If the fileName contains spaces, we also need to double quote it in the arguments\n    // However, there's a case that it's concatenated with line number and column number\n    // which is separated by `:`. We need to double quote the whole string in this case.\n    // Also, if the string contains the escape character `^`, it needs to be quoted, too.\n    function doubleQuoteIfNeeded(str) {\n      if (str.includes('^')) {\n        // If a string includes an escaped character, not only does it need to be quoted,\n        // but the quotes need to be escaped too.\n        return `^\"${str}^\"`\n      } else if (str.includes(' ')) {\n        return `\"${str}\"`\n      } \n      return str\n    }\n    const launchCommand = [editor, ...args.map(escapeCmdArgs)]\n      .map(doubleQuoteIfNeeded)\n      .join(' ')\n\n    _childProcess = childProcess.exec(launchCommand, {\n      stdio: 'inherit',\n      shell: true\n    })\n  } else {\n    _childProcess = childProcess.spawn(editor, args, { stdio: 'inherit' })\n  }\n  _childProcess.on('exit', function (errorCode) {\n    _childProcess = null\n\n    if (errorCode) {\n      onErrorCallback(fileName, '(code ' + errorCode + ')')\n    }\n  })\n\n  _childProcess.on('error', function (error) {\n    let { code, message } = error\n    if ('ENOENT' === code) {\n      message = `${message} ('${editor}' command does not exist in 'PATH')`\n    }\n    onErrorCallback(fileName, message);\n  })\n}\n\nmodule.exports = launchEditor\n"]}