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.

66 lines
1.9 KiB

2 years ago
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. Object.defineProperty(exports, "default", {
  6. enumerable: true,
  7. get: ()=>parseDependency
  8. });
  9. const _isGlob = /*#__PURE__*/ _interopRequireDefault(require("is-glob"));
  10. const _globParent = /*#__PURE__*/ _interopRequireDefault(require("glob-parent"));
  11. const _path = /*#__PURE__*/ _interopRequireDefault(require("path"));
  12. function _interopRequireDefault(obj) {
  13. return obj && obj.__esModule ? obj : {
  14. default: obj
  15. };
  16. }
  17. // Based on `glob-base`
  18. // https://github.com/micromatch/glob-base/blob/master/index.js
  19. function parseGlob(pattern) {
  20. let glob = pattern;
  21. let base = (0, _globParent.default)(pattern);
  22. if (base !== ".") {
  23. glob = pattern.substr(base.length);
  24. if (glob.charAt(0) === "/") {
  25. glob = glob.substr(1);
  26. }
  27. }
  28. if (glob.substr(0, 2) === "./") {
  29. glob = glob.substr(2);
  30. }
  31. if (glob.charAt(0) === "/") {
  32. glob = glob.substr(1);
  33. }
  34. return {
  35. base,
  36. glob
  37. };
  38. }
  39. function parseDependency(normalizedFileOrGlob) {
  40. if (normalizedFileOrGlob.startsWith("!")) {
  41. return null;
  42. }
  43. let message;
  44. if ((0, _isGlob.default)(normalizedFileOrGlob)) {
  45. let { base , glob } = parseGlob(normalizedFileOrGlob);
  46. message = {
  47. type: "dir-dependency",
  48. dir: _path.default.resolve(base),
  49. glob
  50. };
  51. } else {
  52. message = {
  53. type: "dependency",
  54. file: _path.default.resolve(normalizedFileOrGlob)
  55. };
  56. }
  57. // rollup-plugin-postcss does not support dir-dependency messages
  58. // but directories can be watched in the same way as files
  59. if (message.type === "dir-dependency" && process.env.ROLLUP_WATCH === "true") {
  60. message = {
  61. type: "dependency",
  62. file: message.dir
  63. };
  64. }
  65. return message;
  66. }