BVB Source Codes

reactide Show node.js Source code

Return Download reactide: download node.js Source code - Download reactide Source code - Type:.js
  1. "use strict";
  2.  
  3. exports.__esModule = true;
  4.  
  5. var _keys = require("babel-runtime/core-js/object/keys");
  6.  
  7. var _keys2 = _interopRequireDefault(_keys);
  8.  
  9. var _stringify = require("babel-runtime/core-js/json/stringify");
  10.  
  11. var _stringify2 = _interopRequireDefault(_stringify);
  12.  
  13. exports.default = function () {
  14.   var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  15.  
  16.   if (opts.only != null) only = _babelCore.util.arrayify(opts.only, _babelCore.util.regexify);
  17.   if (opts.ignore != null) ignore = _babelCore.util.arrayify(opts.ignore, _babelCore.util.regexify);
  18.  
  19.   if (opts.extensions) hookExtensions(_babelCore.util.arrayify(opts.extensions));
  20.  
  21.   if (opts.cache === false) cache = null;
  22.  
  23.   delete opts.extensions;
  24.   delete opts.ignore;
  25.   delete opts.cache;
  26.   delete opts.only;
  27.  
  28.   (0, _extend2.default)(transformOpts, opts);
  29. };
  30.  
  31. var _cloneDeep = require("lodash/cloneDeep");
  32.  
  33. var _cloneDeep2 = _interopRequireDefault(_cloneDeep);
  34.  
  35. var _sourceMapSupport = require("source-map-support");
  36.  
  37. var _sourceMapSupport2 = _interopRequireDefault(_sourceMapSupport);
  38.  
  39. var _cache = require("./cache");
  40.  
  41. var registerCache = _interopRequireWildcard(_cache);
  42.  
  43. var _extend = require("lodash/extend");
  44.  
  45. var _extend2 = _interopRequireDefault(_extend);
  46.  
  47. var _babelCore = require("babel-core");
  48.  
  49. var babel = _interopRequireWildcard(_babelCore);
  50.  
  51. var _fs = require("fs");
  52.  
  53. var _fs2 = _interopRequireDefault(_fs);
  54.  
  55. var _path = require("path");
  56.  
  57. var _path2 = _interopRequireDefault(_path);
  58.  
  59. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  60.  
  61. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  62.  
  63. _sourceMapSupport2.default.install({
  64.   handleUncaughtExceptions: false,
  65.   environment: "node",
  66.   retrieveSourceMap: function retrieveSourceMap(source) {
  67.     var map = maps && maps[source];
  68.     if (map) {
  69.       return {
  70.         url: null,
  71.         map: map
  72.       };
  73.     } else {
  74.       return null;
  75.     }
  76.   }
  77. });
  78.  
  79. registerCache.load();
  80. var cache = registerCache.get();
  81.  
  82. var transformOpts = {};
  83.  
  84. var ignore = void 0;
  85. var only = void 0;
  86.  
  87. var oldHandlers = {};
  88. var maps = {};
  89.  
  90. var cwd = process.cwd();
  91.  
  92. function getRelativePath(filename) {
  93.   return _path2.default.relative(cwd, filename);
  94. }
  95.  
  96. function mtime(filename) {
  97.   return +_fs2.default.statSync(filename).mtime;
  98. }
  99.  
  100. function compile(filename) {
  101.   var result = void 0;
  102.  
  103.   var opts = new _babelCore.OptionManager().init((0, _extend2.default)({ sourceRoot: _path2.default.dirname(filename) }, (0, _cloneDeep2.default)(transformOpts), { filename: filename }));
  104.  
  105.   var cacheKey = (0, _stringify2.default)(opts) + ":" + babel.version;
  106.  
  107.   var env = process.env.BABEL_ENV || process.env.NODE_ENV;
  108.   if (env) cacheKey += ":" + env;
  109.  
  110.   if (cache) {
  111.     var cached = cache[cacheKey];
  112.     if (cached && cached.mtime === mtime(filename)) {
  113.       result = cached;
  114.     }
  115.   }
  116.  
  117.   if (!result) {
  118.     result = babel.transformFileSync(filename, (0, _extend2.default)(opts, {
  119.       babelrc: false,
  120.       sourceMaps: "both",
  121.       ast: false
  122.     }));
  123.   }
  124.  
  125.   if (cache) {
  126.     cache[cacheKey] = result;
  127.     result.mtime = mtime(filename);
  128.   }
  129.  
  130.   maps[filename] = result.map;
  131.  
  132.   return result.code;
  133. }
  134.  
  135. function shouldIgnore(filename) {
  136.   if (!ignore && !only) {
  137.     return getRelativePath(filename).split(_path2.default.sep).indexOf("node_modules") >= 0;
  138.   } else {
  139.     return _babelCore.util.shouldIgnore(filename, ignore || [], only);
  140.   }
  141. }
  142.  
  143. function loader(m, filename) {
  144.   m._compile(compile(filename), filename);
  145. }
  146.  
  147. function registerExtension(ext) {
  148.   var old = oldHandlers[ext] || oldHandlers[".js"] || require.extensions[".js"];
  149.  
  150.   require.extensions[ext] = function (m, filename) {
  151.     if (shouldIgnore(filename)) {
  152.       old(m, filename);
  153.     } else {
  154.       loader(m, filename, old);
  155.     }
  156.   };
  157. }
  158.  
  159. function hookExtensions(_exts) {
  160.   (0, _keys2.default)(oldHandlers).forEach(function (ext) {
  161.     var old = oldHandlers[ext];
  162.     if (old === undefined) {
  163.       delete require.extensions[ext];
  164.     } else {
  165.       require.extensions[ext] = old;
  166.     }
  167.   });
  168.  
  169.   oldHandlers = {};
  170.  
  171.   _exts.forEach(function (ext) {
  172.     oldHandlers[ext] = require.extensions[ext];
  173.     registerExtension(ext);
  174.   });
  175. }
  176.  
  177. hookExtensions(_babelCore.util.canCompile.EXTENSIONS);
  178.  
  179. module.exports = exports["default"];
downloadnode.js Source code - Download reactide Source code
Related Source Codes/Software:
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
postal - 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top