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.

99 lines
3.4 KiB

  1. /*
  2. @license
  3. Rollup.js v4.40.0
  4. Sat, 12 Apr 2025 08:39:04 GMT - commit 1f2d579ccd4b39f223fed14ac7d031a6c848cd80
  5. https://github.com/rollup/rollup
  6. Released under the MIT License.
  7. */
  8. 'use strict';
  9. Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  10. const rollup = require('./shared/rollup.js');
  11. const parseAst_js = require('./shared/parseAst.js');
  12. const fseventsImporter = require('./shared/fsevents-importer.js');
  13. require('node:process');
  14. require('node:path');
  15. require('path');
  16. require('./native.js');
  17. require('node:perf_hooks');
  18. require('node:fs/promises');
  19. class WatchEmitter {
  20. constructor() {
  21. this.currentHandlers = Object.create(null);
  22. this.persistentHandlers = Object.create(null);
  23. }
  24. // Will be overwritten by Rollup
  25. async close() { }
  26. emit(event, ...parameters) {
  27. return Promise.all([...this.getCurrentHandlers(event), ...this.getPersistentHandlers(event)].map(handler => handler(...parameters)));
  28. }
  29. off(event, listener) {
  30. const listeners = this.persistentHandlers[event];
  31. if (listeners) {
  32. // A hack stolen from "mitt": ">>> 0" does not change numbers >= 0, but -1
  33. // (which would remove the last array element if used unchanged) is turned
  34. // into max_int, which is outside the array and does not change anything.
  35. listeners.splice(listeners.indexOf(listener) >>> 0, 1);
  36. }
  37. return this;
  38. }
  39. on(event, listener) {
  40. this.getPersistentHandlers(event).push(listener);
  41. return this;
  42. }
  43. onCurrentRun(event, listener) {
  44. this.getCurrentHandlers(event).push(listener);
  45. return this;
  46. }
  47. once(event, listener) {
  48. const selfRemovingListener = (...parameters) => {
  49. this.off(event, selfRemovingListener);
  50. return listener(...parameters);
  51. };
  52. this.on(event, selfRemovingListener);
  53. return this;
  54. }
  55. removeAllListeners() {
  56. this.removeListenersForCurrentRun();
  57. this.persistentHandlers = Object.create(null);
  58. return this;
  59. }
  60. removeListenersForCurrentRun() {
  61. this.currentHandlers = Object.create(null);
  62. return this;
  63. }
  64. getCurrentHandlers(event) {
  65. return this.currentHandlers[event] || (this.currentHandlers[event] = []);
  66. }
  67. getPersistentHandlers(event) {
  68. return this.persistentHandlers[event] || (this.persistentHandlers[event] = []);
  69. }
  70. }
  71. function watch(configs) {
  72. const emitter = new WatchEmitter();
  73. watchInternal(configs, emitter).catch(error => {
  74. rollup.handleError(error);
  75. });
  76. return emitter;
  77. }
  78. async function watchInternal(configs, emitter) {
  79. const optionsList = await Promise.all(rollup.ensureArray(configs).map(config => rollup.mergeOptions(config, true)));
  80. const watchOptionsList = optionsList.filter(config => config.watch !== false);
  81. if (watchOptionsList.length === 0) {
  82. return parseAst_js.error(parseAst_js.logInvalidOption('watch', parseAst_js.URL_WATCH, 'there must be at least one config where "watch" is not set to "false"'));
  83. }
  84. await fseventsImporter.loadFsEvents();
  85. const { Watcher } = await Promise.resolve().then(() => require('./shared/watch.js'));
  86. new Watcher(watchOptionsList, emitter);
  87. }
  88. exports.VERSION = rollup.version;
  89. exports.defineConfig = rollup.defineConfig;
  90. exports.rollup = rollup.rollup;
  91. exports.watch = watch;
  92. //# sourceMappingURL=rollup.js.map