worker.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.worker = undefined;
  6. let worker = exports.worker = (() => {
  7. var _ref = _asyncToGenerator(function* (data) {
  8. if (data.hasteImplModulePath && data.hasteImplModulePath !== hasteImplModulePath) {
  9. if (hasteImpl) {
  10. throw new Error('jest-haste-map: hasteImplModulePath changed');
  11. }
  12. hasteImplModulePath = data.hasteImplModulePath;
  13. // $FlowFixMe: dynamic require
  14. hasteImpl = require(hasteImplModulePath);
  15. }
  16. const filePath = data.filePath;
  17. let module;
  18. let id;
  19. let dependencies;
  20. if (filePath.endsWith(PACKAGE_JSON)) {
  21. const fileData = JSON.parse((_gracefulFs || _load_gracefulFs()).default.readFileSync(filePath, 'utf8'));
  22. if (fileData.name) {
  23. id = fileData.name;
  24. module = [filePath, (_constants || _load_constants()).default.PACKAGE];
  25. }
  26. return { dependencies, id, module };
  27. }
  28. if (!(_blacklist || _load_blacklist()).default.has(filePath.substr(filePath.lastIndexOf('.')))) {
  29. const content = (_gracefulFs || _load_gracefulFs()).default.readFileSync(filePath, 'utf8');
  30. if (hasteImpl) {
  31. id = hasteImpl.getHasteName(filePath);
  32. } else {
  33. const doc = (_jestDocblock || _load_jestDocblock()).parse((_jestDocblock || _load_jestDocblock()).extract(content));
  34. id = [].concat(doc.providesModule || doc.provides)[0];
  35. }
  36. dependencies = (0, (_extract_requires || _load_extract_requires()).default)(content);
  37. if (id) {
  38. module = [filePath, (_constants || _load_constants()).default.MODULE];
  39. }
  40. }
  41. return { dependencies, id, module };
  42. });
  43. return function worker(_x) {
  44. return _ref.apply(this, arguments);
  45. };
  46. })();
  47. var _path;
  48. function _load_path() {
  49. return _path = _interopRequireDefault(require('path'));
  50. }
  51. var _jestDocblock;
  52. function _load_jestDocblock() {
  53. return _jestDocblock = _interopRequireWildcard(require('jest-docblock'));
  54. }
  55. var _gracefulFs;
  56. function _load_gracefulFs() {
  57. return _gracefulFs = _interopRequireDefault(require('graceful-fs'));
  58. }
  59. var _blacklist;
  60. function _load_blacklist() {
  61. return _blacklist = _interopRequireDefault(require('./blacklist'));
  62. }
  63. var _constants;
  64. function _load_constants() {
  65. return _constants = _interopRequireDefault(require('./constants'));
  66. }
  67. var _extract_requires;
  68. function _load_extract_requires() {
  69. return _extract_requires = _interopRequireDefault(require('./lib/extract_requires'));
  70. }
  71. 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; } }
  72. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  73. function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } /**
  74. * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  75. *
  76. * This source code is licensed under the MIT license found in the
  77. * LICENSE file in the root directory of this source tree.
  78. *
  79. *
  80. */
  81. const PACKAGE_JSON = (_path || _load_path()).default.sep + 'package.json';
  82. let hasteImpl = null;
  83. let hasteImplModulePath = null;