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.

resolveConfigPath.js 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.default = void 0;
  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. var _constants = require('./constants');
  21. function _getRequireWildcardCache(nodeInterop) {
  22. if (typeof WeakMap !== 'function') return null;
  23. var cacheBabelInterop = new WeakMap();
  24. var cacheNodeInterop = new WeakMap();
  25. return (_getRequireWildcardCache = function (nodeInterop) {
  26. return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
  27. })(nodeInterop);
  28. }
  29. function _interopRequireWildcard(obj, nodeInterop) {
  30. if (!nodeInterop && obj && obj.__esModule) {
  31. return obj;
  32. }
  33. if (obj === null || (typeof obj !== 'object' && typeof obj !== 'function')) {
  34. return {default: obj};
  35. }
  36. var cache = _getRequireWildcardCache(nodeInterop);
  37. if (cache && cache.has(obj)) {
  38. return cache.get(obj);
  39. }
  40. var newObj = {};
  41. var hasPropertyDescriptor =
  42. Object.defineProperty && Object.getOwnPropertyDescriptor;
  43. for (var key in obj) {
  44. if (key !== 'default' && Object.prototype.hasOwnProperty.call(obj, key)) {
  45. var desc = hasPropertyDescriptor
  46. ? Object.getOwnPropertyDescriptor(obj, key)
  47. : null;
  48. if (desc && (desc.get || desc.set)) {
  49. Object.defineProperty(newObj, key, desc);
  50. } else {
  51. newObj[key] = obj[key];
  52. }
  53. }
  54. }
  55. newObj.default = obj;
  56. if (cache) {
  57. cache.set(obj, newObj);
  58. }
  59. return newObj;
  60. }
  61. /**
  62. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  63. *
  64. * This source code is licensed under the MIT license found in the
  65. * LICENSE file in the root directory of this source tree.
  66. */
  67. const isFile = filePath =>
  68. fs().existsSync(filePath) && !fs().lstatSync(filePath).isDirectory();
  69. const getConfigFilename = ext => _constants.JEST_CONFIG_BASE_NAME + ext;
  70. var _default = (pathToResolve, cwd) => {
  71. if (!path().isAbsolute(cwd)) {
  72. throw new Error(`"cwd" must be an absolute path. cwd: ${cwd}`);
  73. }
  74. const absolutePath = path().isAbsolute(pathToResolve)
  75. ? pathToResolve
  76. : path().resolve(cwd, pathToResolve);
  77. if (isFile(absolutePath)) {
  78. return absolutePath;
  79. } // This is a guard against passing non existing path as a project/config,
  80. // that will otherwise result in a very confusing situation.
  81. // e.g.
  82. // With a directory structure like this:
  83. // my_project/
  84. // packcage.json
  85. //
  86. // Passing a `my_project/some_directory_that_doesnt_exist` as a project
  87. // name will resolve into a (possibly empty) `my_project/package.json` and
  88. // try to run all tests it finds under `my_project` directory.
  89. if (!fs().existsSync(absolutePath)) {
  90. throw new Error(
  91. `Can't find a root directory while resolving a config file path.\n` +
  92. `Provided path to resolve: ${pathToResolve}\n` +
  93. `cwd: ${cwd}`
  94. );
  95. }
  96. return resolveConfigPathByTraversing(absolutePath, pathToResolve, cwd);
  97. };
  98. exports.default = _default;
  99. const resolveConfigPathByTraversing = (pathToResolve, initialPath, cwd) => {
  100. const jestConfig = _constants.JEST_CONFIG_EXT_ORDER.map(ext =>
  101. path().resolve(pathToResolve, getConfigFilename(ext))
  102. ).find(isFile);
  103. if (jestConfig) {
  104. return jestConfig;
  105. }
  106. const packageJson = path().resolve(pathToResolve, _constants.PACKAGE_JSON);
  107. if (isFile(packageJson)) {
  108. return packageJson;
  109. } // This is the system root.
  110. // We tried everything, config is nowhere to be found ¯\_(ツ)_/¯
  111. if (pathToResolve === path().dirname(pathToResolve)) {
  112. throw new Error(makeResolutionErrorMessage(initialPath, cwd));
  113. } // go up a level and try it again
  114. return resolveConfigPathByTraversing(
  115. path().dirname(pathToResolve),
  116. initialPath,
  117. cwd
  118. );
  119. };
  120. const makeResolutionErrorMessage = (initialPath, cwd) =>
  121. 'Could not find a config file based on provided values:\n' +
  122. `path: "${initialPath}"\n` +
  123. `cwd: "${cwd}"\n` +
  124. 'Config paths must be specified by either a direct path to a config\n' +
  125. 'file, or a path to a directory. If directory is given, Jest will try to\n' +
  126. `traverse directory tree up, until it finds one of those files in exact order: ${_constants.JEST_CONFIG_EXT_ORDER.map(
  127. ext => `"${getConfigFilename(ext)}"`
  128. ).join(' or ')}.`;