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