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.

full.js 9.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. function _gensync() {
  7. const data = require("gensync");
  8. _gensync = function () {
  9. return data;
  10. };
  11. return data;
  12. }
  13. var _async = require("../gensync-utils/async");
  14. var _util = require("./util");
  15. var context = require("../index");
  16. var _plugin = require("./plugin");
  17. var _item = require("./item");
  18. var _configChain = require("./config-chain");
  19. function _traverse() {
  20. const data = require("@babel/traverse");
  21. _traverse = function () {
  22. return data;
  23. };
  24. return data;
  25. }
  26. var _caching = require("./caching");
  27. var _options = require("./validation/options");
  28. var _plugins = require("./validation/plugins");
  29. var _configApi = require("./helpers/config-api");
  30. var _partial = require("./partial");
  31. var Context = require("./cache-contexts");
  32. var _default = _gensync()(function* loadFullConfig(inputOpts) {
  33. var _opts$assumptions;
  34. const result = yield* (0, _partial.default)(inputOpts);
  35. if (!result) {
  36. return null;
  37. }
  38. const {
  39. options,
  40. context,
  41. fileHandling
  42. } = result;
  43. if (fileHandling === "ignored") {
  44. return null;
  45. }
  46. const optionDefaults = {};
  47. const {
  48. plugins,
  49. presets
  50. } = options;
  51. if (!plugins || !presets) {
  52. throw new Error("Assertion failure - plugins and presets exist");
  53. }
  54. const presetContext = Object.assign({}, context, {
  55. targets: options.targets
  56. });
  57. const toDescriptor = item => {
  58. const desc = (0, _item.getItemDescriptor)(item);
  59. if (!desc) {
  60. throw new Error("Assertion failure - must be config item");
  61. }
  62. return desc;
  63. };
  64. const presetsDescriptors = presets.map(toDescriptor);
  65. const initialPluginsDescriptors = plugins.map(toDescriptor);
  66. const pluginDescriptorsByPass = [[]];
  67. const passes = [];
  68. const ignored = yield* enhanceError(context, function* recursePresetDescriptors(rawPresets, pluginDescriptorsPass) {
  69. const presets = [];
  70. for (let i = 0; i < rawPresets.length; i++) {
  71. const descriptor = rawPresets[i];
  72. if (descriptor.options !== false) {
  73. try {
  74. if (descriptor.ownPass) {
  75. presets.push({
  76. preset: yield* loadPresetDescriptor(descriptor, presetContext),
  77. pass: []
  78. });
  79. } else {
  80. presets.unshift({
  81. preset: yield* loadPresetDescriptor(descriptor, presetContext),
  82. pass: pluginDescriptorsPass
  83. });
  84. }
  85. } catch (e) {
  86. if (e.code === "BABEL_UNKNOWN_OPTION") {
  87. (0, _options.checkNoUnwrappedItemOptionPairs)(rawPresets, i, "preset", e);
  88. }
  89. throw e;
  90. }
  91. }
  92. }
  93. if (presets.length > 0) {
  94. pluginDescriptorsByPass.splice(1, 0, ...presets.map(o => o.pass).filter(p => p !== pluginDescriptorsPass));
  95. for (const {
  96. preset,
  97. pass
  98. } of presets) {
  99. if (!preset) return true;
  100. pass.push(...preset.plugins);
  101. const ignored = yield* recursePresetDescriptors(preset.presets, pass);
  102. if (ignored) return true;
  103. preset.options.forEach(opts => {
  104. (0, _util.mergeOptions)(optionDefaults, opts);
  105. });
  106. }
  107. }
  108. })(presetsDescriptors, pluginDescriptorsByPass[0]);
  109. if (ignored) return null;
  110. const opts = optionDefaults;
  111. (0, _util.mergeOptions)(opts, options);
  112. const pluginContext = Object.assign({}, presetContext, {
  113. assumptions: (_opts$assumptions = opts.assumptions) != null ? _opts$assumptions : {}
  114. });
  115. yield* enhanceError(context, function* loadPluginDescriptors() {
  116. pluginDescriptorsByPass[0].unshift(...initialPluginsDescriptors);
  117. for (const descs of pluginDescriptorsByPass) {
  118. const pass = [];
  119. passes.push(pass);
  120. for (let i = 0; i < descs.length; i++) {
  121. const descriptor = descs[i];
  122. if (descriptor.options !== false) {
  123. try {
  124. pass.push(yield* loadPluginDescriptor(descriptor, pluginContext));
  125. } catch (e) {
  126. if (e.code === "BABEL_UNKNOWN_PLUGIN_PROPERTY") {
  127. (0, _options.checkNoUnwrappedItemOptionPairs)(descs, i, "plugin", e);
  128. }
  129. throw e;
  130. }
  131. }
  132. }
  133. }
  134. })();
  135. opts.plugins = passes[0];
  136. opts.presets = passes.slice(1).filter(plugins => plugins.length > 0).map(plugins => ({
  137. plugins
  138. }));
  139. opts.passPerPreset = opts.presets.length > 0;
  140. return {
  141. options: opts,
  142. passes: passes
  143. };
  144. });
  145. exports.default = _default;
  146. function enhanceError(context, fn) {
  147. return function* (arg1, arg2) {
  148. try {
  149. return yield* fn(arg1, arg2);
  150. } catch (e) {
  151. if (!/^\[BABEL\]/.test(e.message)) {
  152. e.message = `[BABEL] ${context.filename || "unknown"}: ${e.message}`;
  153. }
  154. throw e;
  155. }
  156. };
  157. }
  158. const makeDescriptorLoader = apiFactory => (0, _caching.makeWeakCache)(function* ({
  159. value,
  160. options,
  161. dirname,
  162. alias
  163. }, cache) {
  164. if (options === false) throw new Error("Assertion failure");
  165. options = options || {};
  166. let item = value;
  167. if (typeof value === "function") {
  168. const factory = (0, _async.maybeAsync)(value, `You appear to be using an async plugin/preset, but Babel has been called synchronously`);
  169. const api = Object.assign({}, context, apiFactory(cache));
  170. try {
  171. item = yield* factory(api, options, dirname);
  172. } catch (e) {
  173. if (alias) {
  174. e.message += ` (While processing: ${JSON.stringify(alias)})`;
  175. }
  176. throw e;
  177. }
  178. }
  179. if (!item || typeof item !== "object") {
  180. throw new Error("Plugin/Preset did not return an object.");
  181. }
  182. if ((0, _async.isThenable)(item)) {
  183. yield* [];
  184. throw new Error(`You appear to be using a promise as a plugin, ` + `which your current version of Babel does not support. ` + `If you're using a published plugin, ` + `you may need to upgrade your @babel/core version. ` + `As an alternative, you can prefix the promise with "await". ` + `(While processing: ${JSON.stringify(alias)})`);
  185. }
  186. return {
  187. value: item,
  188. options,
  189. dirname,
  190. alias
  191. };
  192. });
  193. const pluginDescriptorLoader = makeDescriptorLoader(_configApi.makePluginAPI);
  194. const presetDescriptorLoader = makeDescriptorLoader(_configApi.makePresetAPI);
  195. function* loadPluginDescriptor(descriptor, context) {
  196. if (descriptor.value instanceof _plugin.default) {
  197. if (descriptor.options) {
  198. throw new Error("Passed options to an existing Plugin instance will not work.");
  199. }
  200. return descriptor.value;
  201. }
  202. return yield* instantiatePlugin(yield* pluginDescriptorLoader(descriptor, context), context);
  203. }
  204. const instantiatePlugin = (0, _caching.makeWeakCache)(function* ({
  205. value,
  206. options,
  207. dirname,
  208. alias
  209. }, cache) {
  210. const pluginObj = (0, _plugins.validatePluginObject)(value);
  211. const plugin = Object.assign({}, pluginObj);
  212. if (plugin.visitor) {
  213. plugin.visitor = _traverse().default.explode(Object.assign({}, plugin.visitor));
  214. }
  215. if (plugin.inherits) {
  216. const inheritsDescriptor = {
  217. name: undefined,
  218. alias: `${alias}$inherits`,
  219. value: plugin.inherits,
  220. options,
  221. dirname
  222. };
  223. const inherits = yield* (0, _async.forwardAsync)(loadPluginDescriptor, run => {
  224. return cache.invalidate(data => run(inheritsDescriptor, data));
  225. });
  226. plugin.pre = chain(inherits.pre, plugin.pre);
  227. plugin.post = chain(inherits.post, plugin.post);
  228. plugin.manipulateOptions = chain(inherits.manipulateOptions, plugin.manipulateOptions);
  229. plugin.visitor = _traverse().default.visitors.merge([inherits.visitor || {}, plugin.visitor || {}]);
  230. }
  231. return new _plugin.default(plugin, options, alias);
  232. });
  233. const validateIfOptionNeedsFilename = (options, descriptor) => {
  234. if (options.test || options.include || options.exclude) {
  235. const formattedPresetName = descriptor.name ? `"${descriptor.name}"` : "/* your preset */";
  236. throw new Error([`Preset ${formattedPresetName} requires a filename to be set when babel is called directly,`, `\`\`\``, `babel.transform(code, { filename: 'file.ts', presets: [${formattedPresetName}] });`, `\`\`\``, `See https://babeljs.io/docs/en/options#filename for more information.`].join("\n"));
  237. }
  238. };
  239. const validatePreset = (preset, context, descriptor) => {
  240. if (!context.filename) {
  241. const {
  242. options
  243. } = preset;
  244. validateIfOptionNeedsFilename(options, descriptor);
  245. if (options.overrides) {
  246. options.overrides.forEach(overrideOptions => validateIfOptionNeedsFilename(overrideOptions, descriptor));
  247. }
  248. }
  249. };
  250. function* loadPresetDescriptor(descriptor, context) {
  251. const preset = instantiatePreset(yield* presetDescriptorLoader(descriptor, context));
  252. validatePreset(preset, context, descriptor);
  253. return yield* (0, _configChain.buildPresetChain)(preset, context);
  254. }
  255. const instantiatePreset = (0, _caching.makeWeakCacheSync)(({
  256. value,
  257. dirname,
  258. alias
  259. }) => {
  260. return {
  261. options: (0, _options.validate)("preset", value),
  262. alias,
  263. dirname
  264. };
  265. });
  266. function chain(a, b) {
  267. const fns = [a, b].filter(Boolean);
  268. if (fns.length <= 1) return fns[0];
  269. return function (...args) {
  270. for (const fn of fns) {
  271. fn.apply(this, args);
  272. }
  273. };
  274. }