1234567891011121314151617181920212223242526272829
  1. // Copyright 2014, 2017 Simon Lydell
  2. // X11 (“MIT”) Licensed. (See LICENSE.)
  3. var fs = require("fs")
  4. var template = fs.readFileSync("source-map-resolve.js.template").toString()
  5. var nodeCode = fs.readFileSync("lib/source-map-resolve-node.js").toString()
  6. nodeCode = nodeCode
  7. // Remove leading comments and `require`s.
  8. .replace(/^\s*(?:\/\/.+\s+|var\s+\w+\s*=\s*require\([^)]+\).*\s+)*/, "")
  9. // Remove `urix`.
  10. .replace(/(\w+)\s*=\s*urix\(\1\)\s*/g, "")
  11. // Remove `decode-uri-component`.
  12. .replace(/(var readUrl = )decodeUriComponent\(([\w.]+)\)/g, "$1$2")
  13. // Change `module.exports = {...}` to `return {...}`.
  14. .replace(/module\.exports = (\{[^}]+\})\s*$/, "return $1")
  15. // Indent.
  16. .replace(/^(?!$)/gm, " ")
  17. var code = template.replace(/[ \t]*\{\{source-map-resolve-node.js\}\}/, nodeCode)
  18. fs.writeFileSync("source-map-resolve.js", code)