Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

readConfigFileAndSetRootDir.js 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.default = readConfigFileAndSetRootDir;
  6. function path() {
  7. const data = _interopRequireWildcard(require('path'));
  8. path = function () {
  9. return data;
  10. };
  11. return data;
  12. }
  13. function fs() {
  14. const data = _interopRequireWildcard(require('graceful-fs'));
  15. fs = function () {
  16. return data;
  17. };
  18. return data;
  19. }
  20. function _jestUtil() {
  21. const data = require('jest-util');
  22. _jestUtil = function () {
  23. return data;
  24. };
  25. return data;
  26. }
  27. var _constants = require('./constants');
  28. var _jsonlint = _interopRequireDefault(require('./vendor/jsonlint'));
  29. function _interopRequireDefault(obj) {
  30. return obj && obj.__esModule ? obj : {default: obj};
  31. }
  32. function _getRequireWildcardCache(nodeInterop) {
  33. if (typeof WeakMap !== 'function') return null;
  34. var cacheBabelInterop = new WeakMap();
  35. var cacheNodeInterop = new WeakMap();
  36. return (_getRequireWildcardCache = function (nodeInterop) {
  37. return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
  38. })(nodeInterop);
  39. }
  40. function _interopRequireWildcard(obj, nodeInterop) {
  41. if (!nodeInterop && obj && obj.__esModule) {
  42. return obj;
  43. }
  44. if (obj === null || (typeof obj !== 'object' && typeof obj !== 'function')) {
  45. return {default: obj};
  46. }
  47. var cache = _getRequireWildcardCache(nodeInterop);
  48. if (cache && cache.has(obj)) {
  49. return cache.get(obj);
  50. }
  51. var newObj = {};
  52. var hasPropertyDescriptor =
  53. Object.defineProperty && Object.getOwnPropertyDescriptor;
  54. for (var key in obj) {
  55. if (key !== 'default' && Object.prototype.hasOwnProperty.call(obj, key)) {
  56. var desc = hasPropertyDescriptor
  57. ? Object.getOwnPropertyDescriptor(obj, key)
  58. : null;
  59. if (desc && (desc.get || desc.set)) {
  60. Object.defineProperty(newObj, key, desc);
  61. } else {
  62. newObj[key] = obj[key];
  63. }
  64. }
  65. }
  66. newObj.default = obj;
  67. if (cache) {
  68. cache.set(obj, newObj);
  69. }
  70. return newObj;
  71. }
  72. /**
  73. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  74. *
  75. * This source code is licensed under the MIT license found in the
  76. * LICENSE file in the root directory of this source tree.
  77. */
  78. // @ts-expect-error: vendored
  79. // Read the configuration and set its `rootDir`
  80. // 1. If it's a `package.json` file, we look into its "jest" property
  81. // 2. If it's a `jest.config.ts` file, we use `ts-node` to transpile & require it
  82. // 3. For any other file, we just require it. If we receive an 'ERR_REQUIRE_ESM'
  83. // from node, perform a dynamic import instead.
  84. async function readConfigFileAndSetRootDir(configPath) {
  85. const isTS = configPath.endsWith(_constants.JEST_CONFIG_EXT_TS);
  86. const isJSON = configPath.endsWith(_constants.JEST_CONFIG_EXT_JSON);
  87. let configObject;
  88. try {
  89. if (isTS) {
  90. configObject = await loadTSConfigFile(configPath);
  91. } else {
  92. configObject = await (0, _jestUtil().requireOrImportModule)(configPath);
  93. }
  94. } catch (error) {
  95. if (isJSON) {
  96. throw new Error(
  97. `Jest: Failed to parse config file ${configPath}\n` +
  98. ` ${_jsonlint.default.errors(fs().readFileSync(configPath, 'utf8'))}`
  99. );
  100. } else if (isTS) {
  101. throw new Error(
  102. `Jest: Failed to parse the TypeScript config file ${configPath}\n` +
  103. ` ${error}`
  104. );
  105. } else {
  106. throw error;
  107. }
  108. }
  109. if (configPath.endsWith(_constants.PACKAGE_JSON)) {
  110. // Event if there's no "jest" property in package.json we will still use
  111. // an empty object.
  112. configObject = configObject.jest || {};
  113. }
  114. if (typeof configObject === 'function') {
  115. configObject = await configObject();
  116. }
  117. if (configObject.rootDir) {
  118. // We don't touch it if it has an absolute path specified
  119. if (!path().isAbsolute(configObject.rootDir)) {
  120. // otherwise, we'll resolve it relative to the file's __dirname
  121. configObject.rootDir = path().resolve(
  122. path().dirname(configPath),
  123. configObject.rootDir
  124. );
  125. }
  126. } else {
  127. // If rootDir is not there, we'll set it to this file's __dirname
  128. configObject.rootDir = path().dirname(configPath);
  129. }
  130. return configObject;
  131. } // Load the TypeScript configuration
  132. const loadTSConfigFile = async configPath => {
  133. let registerer; // Register TypeScript compiler instance
  134. try {
  135. registerer = require('ts-node').register({
  136. compilerOptions: {
  137. module: 'CommonJS'
  138. }
  139. });
  140. } catch (e) {
  141. if (e.code === 'MODULE_NOT_FOUND') {
  142. throw new Error(
  143. `Jest: 'ts-node' is required for the TypeScript configuration files. Make sure it is installed\nError: ${e.message}`
  144. );
  145. }
  146. throw e;
  147. }
  148. registerer.enabled(true);
  149. let configObject = (0, _jestUtil().interopRequireDefault)(
  150. require(configPath)
  151. ).default; // In case the config is a function which imports more Typescript code
  152. if (typeof configObject === 'function') {
  153. configObject = await configObject();
  154. }
  155. registerer.enabled(false);
  156. return configObject;
  157. };