rollup.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. @license
  3. Rollup.js v4.24.2
  4. Sun, 27 Oct 2024 15:39:37 GMT - commit 32d0e7dae85121ac0850ec28576a10a6302f84a9
  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('tty');
  15. require('node:path');
  16. require('path');
  17. require('./native.js');
  18. require('node:perf_hooks');
  19. require('node:fs/promises');
  20. class WatchEmitter {
  21. constructor() {
  22. this.currentHandlers = Object.create(null);
  23. this.persistentHandlers = Object.create(null);
  24. }
  25. // Will be overwritten by Rollup
  26. async close() { }
  27. emit(event, ...parameters) {
  28. return Promise.all([...this.getCurrentHandlers(event), ...this.getPersistentHandlers(event)].map(handler => handler(...parameters)));
  29. }
  30. off(event, listener) {
  31. const listeners = this.persistentHandlers[event];
  32. if (listeners) {
  33. // A hack stolen from "mitt": ">>> 0" does not change numbers >= 0, but -1
  34. // (which would remove the last array element if used unchanged) is turned
  35. // into max_int, which is outside the array and does not change anything.
  36. listeners.splice(listeners.indexOf(listener) >>> 0, 1);
  37. }
  38. return this;
  39. }
  40. on(event, listener) {
  41. this.getPersistentHandlers(event).push(listener);
  42. return this;
  43. }
  44. onCurrentRun(event, listener) {
  45. this.getCurrentHandlers(event).push(listener);
  46. return this;
  47. }
  48. once(event, listener) {
  49. const selfRemovingListener = (...parameters) => {
  50. this.off(event, selfRemovingListener);
  51. return listener(...parameters);
  52. };
  53. this.on(event, selfRemovingListener);
  54. return this;
  55. }
  56. removeAllListeners() {
  57. this.removeListenersForCurrentRun();
  58. this.persistentHandlers = Object.create(null);
  59. return this;
  60. }
  61. removeListenersForCurrentRun() {
  62. this.currentHandlers = Object.create(null);
  63. return this;
  64. }
  65. getCurrentHandlers(event) {
  66. return this.currentHandlers[event] || (this.currentHandlers[event] = []);
  67. }
  68. getPersistentHandlers(event) {
  69. return this.persistentHandlers[event] || (this.persistentHandlers[event] = []);
  70. }
  71. }
  72. function watch(configs) {
  73. const emitter = new WatchEmitter();
  74. watchInternal(configs, emitter).catch(error => {
  75. rollup.handleError(error);
  76. });
  77. return emitter;
  78. }
  79. async function watchInternal(configs, emitter) {
  80. const optionsList = await Promise.all(rollup.ensureArray(configs).map(config => rollup.mergeOptions(config, true)));
  81. const watchOptionsList = optionsList.filter(config => config.watch !== false);
  82. if (watchOptionsList.length === 0) {
  83. 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"'));
  84. }
  85. await fseventsImporter.loadFsEvents();
  86. const { Watcher } = await Promise.resolve().then(() => require('./shared/watch.js'));
  87. new Watcher(watchOptionsList, emitter);
  88. }
  89. exports.VERSION = rollup.version;
  90. exports.defineConfig = rollup.defineConfig;
  91. exports.rollup = rollup.rollup;
  92. exports.watch = watch;
  93. //# sourceMappingURL=rollup.js.map