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.

dependencyExtractor.js 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.extract = extract;
  6. var _isRegExpSupported = _interopRequireDefault(require('./isRegExpSupported'));
  7. function _interopRequireDefault(obj) {
  8. return obj && obj.__esModule ? obj : {default: obj};
  9. }
  10. /**
  11. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  12. *
  13. * This source code is licensed under the MIT license found in the
  14. * LICENSE file in the root directory of this source tree.
  15. */
  16. // Negative look behind is only supported in Node 9+
  17. const NOT_A_DOT = (0, _isRegExpSupported.default)('(?<!\\.\\s*)')
  18. ? '(?<!\\.\\s*)'
  19. : '(?:^|[^.]\\s*)';
  20. const CAPTURE_STRING_LITERAL = pos => `([\`'"])([^'"\`]*?)(?:\\${pos})`;
  21. const WORD_SEPARATOR = '\\b';
  22. const LEFT_PARENTHESIS = '\\(';
  23. const RIGHT_PARENTHESIS = '\\)';
  24. const WHITESPACE = '\\s*';
  25. const OPTIONAL_COMMA = '(:?,\\s*)?';
  26. function createRegExp(parts, flags) {
  27. return new RegExp(parts.join(''), flags);
  28. }
  29. function alternatives(...parts) {
  30. return `(?:${parts.join('|')})`;
  31. }
  32. function functionCallStart(...names) {
  33. return [
  34. NOT_A_DOT,
  35. WORD_SEPARATOR,
  36. alternatives(...names),
  37. WHITESPACE,
  38. LEFT_PARENTHESIS,
  39. WHITESPACE
  40. ];
  41. }
  42. const BLOCK_COMMENT_RE = /\/\*[^]*?\*\//g;
  43. const LINE_COMMENT_RE = /\/\/.*/g;
  44. const REQUIRE_OR_DYNAMIC_IMPORT_RE = createRegExp(
  45. [
  46. ...functionCallStart('require', 'import'),
  47. CAPTURE_STRING_LITERAL(1),
  48. WHITESPACE,
  49. OPTIONAL_COMMA,
  50. RIGHT_PARENTHESIS
  51. ],
  52. 'g'
  53. );
  54. const IMPORT_OR_EXPORT_RE = createRegExp(
  55. [
  56. '\\b(?:import|export)\\s+(?!type(?:of)?\\s+)(?:[^\'"]+\\s+from\\s+)?',
  57. CAPTURE_STRING_LITERAL(1)
  58. ],
  59. 'g'
  60. );
  61. const JEST_EXTENSIONS_RE = createRegExp(
  62. [
  63. ...functionCallStart(
  64. 'jest\\s*\\.\\s*(?:requireActual|requireMock|genMockFromModule|createMockFromModule)'
  65. ),
  66. CAPTURE_STRING_LITERAL(1),
  67. WHITESPACE,
  68. OPTIONAL_COMMA,
  69. RIGHT_PARENTHESIS
  70. ],
  71. 'g'
  72. );
  73. function extract(code) {
  74. const dependencies = new Set();
  75. const addDependency = (match, _, dep) => {
  76. dependencies.add(dep);
  77. return match;
  78. };
  79. code
  80. .replace(BLOCK_COMMENT_RE, '')
  81. .replace(LINE_COMMENT_RE, '')
  82. .replace(IMPORT_OR_EXPORT_RE, addDependency)
  83. .replace(REQUIRE_OR_DYNAMIC_IMPORT_RE, addDependency)
  84. .replace(JEST_EXTENSIONS_RE, addDependency);
  85. return dependencies;
  86. }