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.

patch-postcss.js 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. "use strict";
  2. const path = require("path");
  3. const patched = {};
  4. function isPromise (obj) {
  5. return typeof obj === "object" && typeof obj.then === "function";
  6. }
  7. function runDocument (plugin) {
  8. const result = this.result;
  9. result.lastPlugin = plugin;
  10. const promise = result.root.nodes.map(root => {
  11. try {
  12. return plugin(root, result);
  13. } catch (error) {
  14. this.handleError(error, plugin);
  15. throw error;
  16. }
  17. });
  18. if (promise.some(isPromise)) {
  19. return Promise.all(promise);
  20. }
  21. }
  22. function patchDocument (Document, LazyResult) {
  23. LazyResult = LazyResult.prototype;
  24. const runRoot = LazyResult.run;
  25. LazyResult.run = function run () {
  26. return (this.result.root instanceof Document ? runDocument : runRoot).apply(this, arguments);
  27. };
  28. }
  29. function patchNode (Node) {
  30. Node = Node.prototype;
  31. const NodeToString = Node.toString;
  32. Node.toString = function toString (stringifier) {
  33. return NodeToString.call(this, stringifier || this.root().source.syntax);
  34. };
  35. }
  36. function patch (Document) {
  37. let fn;
  38. let file;
  39. if (Document) {
  40. patch();
  41. fn = patchDocument.bind(this, Document);
  42. file = "lazy-result";
  43. } else {
  44. fn = patchNode;
  45. file = "node";
  46. }
  47. findPostcss().map(dir => (
  48. [dir + "lib", file].join(path.sep)
  49. )).filter(file => (
  50. !patched[file]
  51. )).forEach(file => {
  52. try {
  53. fn(require(file));
  54. } catch (ex) {
  55. //
  56. }
  57. patched[file] = true;
  58. });
  59. }
  60. function findPostcss () {
  61. const result = {};
  62. for (const file in require.cache) {
  63. if (/^(.+?(\\|\/))postcss(\2)/.test(file)) {
  64. result[RegExp.lastMatch] = true;
  65. }
  66. }
  67. return Object.keys(result);
  68. }
  69. module.exports = patch;