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