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.

index.js 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. const tests = {
  2. // ECMAScript 2018
  3. "object-rest-spread": ["({ ...{} })", "({ ...x } = {})"], // Babel 7.2.0
  4. "async-generators": ["async function* f() {}"], // Babel 7.2.0
  5. // ECMAScript 2019
  6. "optional-catch-binding": ["try {} catch {}"], // Babel 7.2.0
  7. "json-strings": ["'\\u2028'"], // Babel 7.2.0
  8. // ECMAScript 2020
  9. "bigint": ["1n"], // Babel 7.8.0
  10. "optional-chaining": ["a?.b"], // Babel 7.9.0
  11. "nullish-coalescing-operator": ["a ?? b"], // Babel 7.9.0
  12. // import.meta is handled manually
  13. // Stage 3
  14. "numeric-separator": ["1_2"],
  15. "class-properties": [
  16. "(class { x = 1 })",
  17. "(class { #x = 1 })",
  18. "(class { #x() {} })",
  19. ],
  20. "logical-assignment-operators": ["a ||= b", "a &&= b", "a ??= c"],
  21. };
  22. const plugins = [];
  23. const works = (test) => {
  24. try {
  25. // Wrap the test in a function to only test the syntax, without executing it
  26. (0, eval)(`(() => { ${test} })`);
  27. return true;
  28. } catch (_error) {
  29. return false;
  30. }
  31. };
  32. for (const [name, cases] of Object.entries(tests)) {
  33. if (cases.some(works)) {
  34. plugins.push(require.resolve(`@babel/plugin-syntax-${name}`));
  35. }
  36. }
  37. // import.meta is only allowed in modules, and modules can only be evaluated
  38. // synchronously. For this reason, we cannot detect import.meta support at
  39. // runtime. It is supported starting from 10.4, so we can check the version.
  40. const major = parseInt(process.versions.node, 10);
  41. const minor = parseInt(process.versions.node.match(/^\d+\.(\d+)/)[1], 10);
  42. if (major > 10 || (major === 10 && minor >= 4)) {
  43. plugins.push(require.resolve("@babel/plugin-syntax-import-meta"));
  44. }
  45. // Same for top level await - it is only supported in modules. It is supported
  46. // from 14.3.0
  47. if (major > 14 || (major === 14 && minor >= 3)) {
  48. plugins.push(require.resolve("@babel/plugin-syntax-top-level-await"));
  49. }
  50. module.exports = () => ({ plugins });