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.

shouldLoadAsEsm.js 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.clearCachedLookups = clearCachedLookups;
  6. exports.default = cachedShouldLoadAsEsm;
  7. function _path() {
  8. const data = require('path');
  9. _path = function () {
  10. return data;
  11. };
  12. return data;
  13. }
  14. function _vm() {
  15. const data = require('vm');
  16. _vm = function () {
  17. return data;
  18. };
  19. return data;
  20. }
  21. function _sync() {
  22. const data = _interopRequireDefault(require('escalade/sync'));
  23. _sync = function () {
  24. return data;
  25. };
  26. return data;
  27. }
  28. function _gracefulFs() {
  29. const data = require('graceful-fs');
  30. _gracefulFs = function () {
  31. return data;
  32. };
  33. return data;
  34. }
  35. function _interopRequireDefault(obj) {
  36. return obj && obj.__esModule ? obj : {default: obj};
  37. }
  38. /**
  39. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  40. *
  41. * This source code is licensed under the MIT license found in the
  42. * LICENSE file in the root directory of this source tree.
  43. */
  44. // @ts-expect-error: experimental, not added to the types
  45. const runtimeSupportsVmModules = typeof _vm().SyntheticModule === 'function';
  46. const cachedFileLookups = new Map();
  47. const cachedDirLookups = new Map();
  48. const cachedChecks = new Map();
  49. function clearCachedLookups() {
  50. cachedFileLookups.clear();
  51. cachedDirLookups.clear();
  52. cachedChecks.clear();
  53. }
  54. function cachedShouldLoadAsEsm(path, extensionsToTreatAsEsm) {
  55. if (!runtimeSupportsVmModules) {
  56. return false;
  57. }
  58. let cachedLookup = cachedFileLookups.get(path);
  59. if (cachedLookup === undefined) {
  60. cachedLookup = shouldLoadAsEsm(path, extensionsToTreatAsEsm);
  61. cachedFileLookups.set(path, cachedLookup);
  62. }
  63. return cachedLookup;
  64. } // this is a bad version of what https://github.com/nodejs/modules/issues/393 would provide
  65. function shouldLoadAsEsm(path, extensionsToTreatAsEsm) {
  66. const extension = (0, _path().extname)(path);
  67. if (extension === '.mjs') {
  68. return true;
  69. }
  70. if (extension === '.cjs') {
  71. return false;
  72. }
  73. if (extension !== '.js') {
  74. return extensionsToTreatAsEsm.includes(extension);
  75. }
  76. const cwd = (0, _path().dirname)(path);
  77. let cachedLookup = cachedDirLookups.get(cwd);
  78. if (cachedLookup === undefined) {
  79. cachedLookup = cachedPkgCheck(cwd);
  80. cachedFileLookups.set(cwd, cachedLookup);
  81. }
  82. return cachedLookup;
  83. }
  84. function cachedPkgCheck(cwd) {
  85. const pkgPath = (0, _sync().default)(cwd, (_dir, names) => {
  86. if (names.includes('package.json')) {
  87. // will be resolved into absolute
  88. return 'package.json';
  89. }
  90. return false;
  91. });
  92. if (!pkgPath) {
  93. return false;
  94. }
  95. let hasModuleField = cachedChecks.get(pkgPath);
  96. if (hasModuleField != null) {
  97. return hasModuleField;
  98. }
  99. try {
  100. const pkg = JSON.parse((0, _gracefulFs().readFileSync)(pkgPath, 'utf-8'));
  101. hasModuleField = pkg.type === 'module';
  102. } catch {
  103. hasModuleField = false;
  104. }
  105. cachedChecks.set(pkgPath, hasModuleField);
  106. return hasModuleField;
  107. }