source: frontend/node_modules/rollup/dist/shared/watch-cli.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 15.6 KB
Line 
1/*
2 @license
3 Rollup.js v2.80.0
4 Sun, 22 Feb 2026 06:16:40 GMT - commit d17ae15336a45c3c59b2a4aacac2b14186035d28
5
6 https://github.com/rollup/rollup
7
8 Released under the MIT License.
9*/
10'use strict';
11
12Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
13
14const require$$0$2 = require('fs');
15const process$2 = require('process');
16const index = require('./index.js');
17const cli = require('../bin/rollup');
18const rollup = require('./rollup.js');
19const require$$0 = require('assert');
20const require$$0$1 = require('events');
21const loadConfigFile_js = require('./loadConfigFile.js');
22const child_process = require('child_process');
23require('util');
24require('stream');
25require('path');
26require('os');
27require('./mergeOptions.js');
28require('perf_hooks');
29require('crypto');
30require('url');
31require('tty');
32
33function timeZone(date = new Date()) {
34 const offset = date.getTimezoneOffset();
35 const absOffset = Math.abs(offset);
36 const hours = Math.floor(absOffset / 60);
37 const minutes = absOffset % 60;
38 const minutesOut = minutes > 0 ? ':' + ('0' + minutes).slice(-2) : '';
39 return (offset < 0 ? '+' : '-') + hours + minutesOut;
40}
41
42function dateTime(options = {}) {
43 let {
44 date = new Date(),
45 local = true,
46 showTimeZone = false,
47 showMilliseconds = false
48 } = options;
49
50 if (local) {
51 // Offset the date so it will return the correct value when getting the ISO string.
52 date = new Date(date.getTime() - (date.getTimezoneOffset() * 60000));
53 }
54
55 let end = '';
56
57 if (showTimeZone) {
58 end = ' UTC' + (local ? timeZone(date) : '');
59 }
60
61 if (showMilliseconds && date.getUTCMilliseconds() > 0) {
62 end = ` ${date.getUTCMilliseconds()}ms${end}`;
63 }
64
65 return date
66 .toISOString()
67 .replace(/T/, ' ')
68 .replace(/\..+/, end);
69}
70
71var signalExit = {exports: {}};
72
73var signals$1 = {exports: {}};
74
75var hasRequiredSignals;
76
77function requireSignals () {
78 if (hasRequiredSignals) return signals$1.exports;
79 hasRequiredSignals = 1;
80 (function (module) {
81 // This is not the set of all possible signals.
82 //
83 // It IS, however, the set of all signals that trigger
84 // an exit on either Linux or BSD systems. Linux is a
85 // superset of the signal names supported on BSD, and
86 // the unknown signals just fail to register, so we can
87 // catch that easily enough.
88 //
89 // Don't bother with SIGKILL. It's uncatchable, which
90 // means that we can't fire any callbacks anyway.
91 //
92 // If a user does happen to register a handler on a non-
93 // fatal signal like SIGWINCH or something, and then
94 // exit, it'll end up firing `process.emit('exit')`, so
95 // the handler will be fired anyway.
96 //
97 // SIGBUS, SIGFPE, SIGSEGV and SIGILL, when not raised
98 // artificially, inherently leave the process in a
99 // state from which it is not safe to try and enter JS
100 // listeners.
101 module.exports = [
102 'SIGABRT',
103 'SIGALRM',
104 'SIGHUP',
105 'SIGINT',
106 'SIGTERM'
107 ];
108
109 if (process.platform !== 'win32') {
110 module.exports.push(
111 'SIGVTALRM',
112 'SIGXCPU',
113 'SIGXFSZ',
114 'SIGUSR2',
115 'SIGTRAP',
116 'SIGSYS',
117 'SIGQUIT',
118 'SIGIOT'
119 // should detect profiler and enable/disable accordingly.
120 // see #21
121 // 'SIGPROF'
122 );
123 }
124
125 if (process.platform === 'linux') {
126 module.exports.push(
127 'SIGIO',
128 'SIGPOLL',
129 'SIGPWR',
130 'SIGSTKFLT',
131 'SIGUNUSED'
132 );
133 }
134} (signals$1));
135 return signals$1.exports;
136}
137
138// Note: since nyc uses this module to output coverage, any lines
139// that are in the direct sync flow of nyc's outputCoverage are
140// ignored, since we can never get coverage for them.
141// grab a reference to node's real process object right away
142var process$1 = rollup.commonjsGlobal.process;
143
144const processOk = function (process) {
145 return process &&
146 typeof process === 'object' &&
147 typeof process.removeListener === 'function' &&
148 typeof process.emit === 'function' &&
149 typeof process.reallyExit === 'function' &&
150 typeof process.listeners === 'function' &&
151 typeof process.kill === 'function' &&
152 typeof process.pid === 'number' &&
153 typeof process.on === 'function'
154};
155
156// some kind of non-node environment, just no-op
157/* istanbul ignore if */
158if (!processOk(process$1)) {
159 signalExit.exports = function () {
160 return function () {}
161 };
162} else {
163 var assert = require$$0;
164 var signals = requireSignals();
165 var isWin = /^win/i.test(process$1.platform);
166
167 var EE = require$$0$1;
168 /* istanbul ignore if */
169 if (typeof EE !== 'function') {
170 EE = EE.EventEmitter;
171 }
172
173 var emitter;
174 if (process$1.__signal_exit_emitter__) {
175 emitter = process$1.__signal_exit_emitter__;
176 } else {
177 emitter = process$1.__signal_exit_emitter__ = new EE();
178 emitter.count = 0;
179 emitter.emitted = {};
180 }
181
182 // Because this emitter is a global, we have to check to see if a
183 // previous version of this library failed to enable infinite listeners.
184 // I know what you're about to say. But literally everything about
185 // signal-exit is a compromise with evil. Get used to it.
186 if (!emitter.infinite) {
187 emitter.setMaxListeners(Infinity);
188 emitter.infinite = true;
189 }
190
191 signalExit.exports = function (cb, opts) {
192 /* istanbul ignore if */
193 if (!processOk(rollup.commonjsGlobal.process)) {
194 return function () {}
195 }
196 assert.equal(typeof cb, 'function', 'a callback must be provided for exit handler');
197
198 if (loaded === false) {
199 load();
200 }
201
202 var ev = 'exit';
203 if (opts && opts.alwaysLast) {
204 ev = 'afterexit';
205 }
206
207 var remove = function () {
208 emitter.removeListener(ev, cb);
209 if (emitter.listeners('exit').length === 0 &&
210 emitter.listeners('afterexit').length === 0) {
211 unload();
212 }
213 };
214 emitter.on(ev, cb);
215
216 return remove
217 };
218
219 var unload = function unload () {
220 if (!loaded || !processOk(rollup.commonjsGlobal.process)) {
221 return
222 }
223 loaded = false;
224
225 signals.forEach(function (sig) {
226 try {
227 process$1.removeListener(sig, sigListeners[sig]);
228 } catch (er) {}
229 });
230 process$1.emit = originalProcessEmit;
231 process$1.reallyExit = originalProcessReallyExit;
232 emitter.count -= 1;
233 };
234 signalExit.exports.unload = unload;
235
236 var emit = function emit (event, code, signal) {
237 /* istanbul ignore if */
238 if (emitter.emitted[event]) {
239 return
240 }
241 emitter.emitted[event] = true;
242 emitter.emit(event, code, signal);
243 };
244
245 // { <signal>: <listener fn>, ... }
246 var sigListeners = {};
247 signals.forEach(function (sig) {
248 sigListeners[sig] = function listener () {
249 /* istanbul ignore if */
250 if (!processOk(rollup.commonjsGlobal.process)) {
251 return
252 }
253 // If there are no other listeners, an exit is coming!
254 // Simplest way: remove us and then re-send the signal.
255 // We know that this will kill the process, so we can
256 // safely emit now.
257 var listeners = process$1.listeners(sig);
258 if (listeners.length === emitter.count) {
259 unload();
260 emit('exit', null, sig);
261 /* istanbul ignore next */
262 emit('afterexit', null, sig);
263 /* istanbul ignore next */
264 if (isWin && sig === 'SIGHUP') {
265 // "SIGHUP" throws an `ENOSYS` error on Windows,
266 // so use a supported signal instead
267 sig = 'SIGINT';
268 }
269 /* istanbul ignore next */
270 process$1.kill(process$1.pid, sig);
271 }
272 };
273 });
274
275 signalExit.exports.signals = function () {
276 return signals
277 };
278
279 var loaded = false;
280
281 var load = function load () {
282 if (loaded || !processOk(rollup.commonjsGlobal.process)) {
283 return
284 }
285 loaded = true;
286
287 // This is the number of onSignalExit's that are in play.
288 // It's important so that we can count the correct number of
289 // listeners on signals, and don't wait for the other one to
290 // handle it instead of us.
291 emitter.count += 1;
292
293 signals = signals.filter(function (sig) {
294 try {
295 process$1.on(sig, sigListeners[sig]);
296 return true
297 } catch (er) {
298 return false
299 }
300 });
301
302 process$1.emit = processEmit;
303 process$1.reallyExit = processReallyExit;
304 };
305 signalExit.exports.load = load;
306
307 var originalProcessReallyExit = process$1.reallyExit;
308 var processReallyExit = function processReallyExit (code) {
309 /* istanbul ignore if */
310 if (!processOk(rollup.commonjsGlobal.process)) {
311 return
312 }
313 process$1.exitCode = code || /* istanbul ignore next */ 0;
314 emit('exit', process$1.exitCode, null);
315 /* istanbul ignore next */
316 emit('afterexit', process$1.exitCode, null);
317 /* istanbul ignore next */
318 originalProcessReallyExit.call(process$1, process$1.exitCode);
319 };
320
321 var originalProcessEmit = process$1.emit;
322 var processEmit = function processEmit (ev, arg) {
323 if (ev === 'exit' && processOk(rollup.commonjsGlobal.process)) {
324 /* istanbul ignore else */
325 if (arg !== undefined) {
326 process$1.exitCode = arg;
327 }
328 var ret = originalProcessEmit.apply(this, arguments);
329 /* istanbul ignore next */
330 emit('exit', process$1.exitCode, null);
331 /* istanbul ignore next */
332 emit('afterexit', process$1.exitCode, null);
333 /* istanbul ignore next */
334 return ret
335 } else {
336 return originalProcessEmit.apply(this, arguments)
337 }
338 };
339}
340
341const CLEAR_SCREEN = '\u001Bc';
342function getResetScreen(configs, allowClearScreen) {
343 let clearScreen = allowClearScreen;
344 for (const config of configs) {
345 if (config.watch && config.watch.clearScreen === false) {
346 clearScreen = false;
347 }
348 }
349 if (clearScreen) {
350 return (heading) => loadConfigFile_js.stderr(CLEAR_SCREEN + heading);
351 }
352 let firstRun = true;
353 return (heading) => {
354 if (firstRun) {
355 loadConfigFile_js.stderr(heading);
356 firstRun = false;
357 }
358 };
359}
360
361function extractWatchHooks(command) {
362 if (!Array.isArray(command.watch))
363 return {};
364 return command.watch
365 .filter(value => typeof value === 'object')
366 .reduce((acc, keyValueOption) => ({ ...acc, ...keyValueOption }), {});
367}
368function createWatchHooks(command) {
369 const watchHooks = extractWatchHooks(command);
370 return function (hook) {
371 if (watchHooks[hook]) {
372 const cmd = watchHooks[hook];
373 if (!command.silent) {
374 loadConfigFile_js.stderr(loadConfigFile_js.cyan(`watch.${hook} ${loadConfigFile_js.bold(`$ ${cmd}`)}`));
375 }
376 try {
377 // !! important - use stderr for all writes from execSync
378 const stdio = [process.stdin, process.stderr, process.stderr];
379 child_process.execSync(cmd, { stdio: command.silent ? 'ignore' : stdio });
380 }
381 catch (e) {
382 loadConfigFile_js.stderr(e.message);
383 }
384 }
385 };
386}
387
388async function watch(command) {
389 process$2.env.ROLLUP_WATCH = 'true';
390 const isTTY = process$2.stderr.isTTY;
391 const silent = command.silent;
392 let watcher;
393 let configWatcher;
394 let resetScreen;
395 const configFile = command.config ? await cli.getConfigPath(command.config) : null;
396 const runWatchHook = createWatchHooks(command);
397 signalExit.exports(close);
398 process$2.on('uncaughtException', close);
399 if (!process$2.stdin.isTTY) {
400 process$2.stdin.on('end', close);
401 process$2.stdin.resume();
402 }
403 async function loadConfigFromFileAndTrack(configFile) {
404 let configFileData = null;
405 let configFileRevision = 0;
406 configWatcher = index.chokidar.watch(configFile).on('change', reloadConfigFile);
407 await reloadConfigFile();
408 async function reloadConfigFile() {
409 try {
410 const newConfigFileData = await require$$0$2.promises.readFile(configFile, 'utf8');
411 if (newConfigFileData === configFileData) {
412 return;
413 }
414 configFileRevision++;
415 const currentConfigFileRevision = configFileRevision;
416 if (configFileData) {
417 loadConfigFile_js.stderr(`\nReloading updated config...`);
418 }
419 configFileData = newConfigFileData;
420 const { options, warnings } = await loadConfigFile_js.loadAndParseConfigFile(configFile, command);
421 if (currentConfigFileRevision !== configFileRevision) {
422 return;
423 }
424 if (watcher) {
425 await watcher.close();
426 }
427 start(options, warnings);
428 }
429 catch (err) {
430 loadConfigFile_js.handleError(err, true);
431 }
432 }
433 }
434 if (configFile) {
435 await loadConfigFromFileAndTrack(configFile);
436 }
437 else {
438 const { options, warnings } = await cli.loadConfigFromCommand(command);
439 start(options, warnings);
440 }
441 function start(configs, warnings) {
442 try {
443 watcher = rollup.watch(configs);
444 }
445 catch (err) {
446 return loadConfigFile_js.handleError(err);
447 }
448 watcher.on('event', event => {
449 switch (event.code) {
450 case 'ERROR':
451 warnings.flush();
452 loadConfigFile_js.handleError(event.error, true);
453 runWatchHook('onError');
454 break;
455 case 'START':
456 if (!silent) {
457 if (!resetScreen) {
458 resetScreen = getResetScreen(configs, isTTY);
459 }
460 resetScreen(loadConfigFile_js.underline(`rollup v${rollup.version}`));
461 }
462 runWatchHook('onStart');
463 break;
464 case 'BUNDLE_START':
465 if (!silent) {
466 let input = event.input;
467 if (typeof input !== 'string') {
468 input = Array.isArray(input)
469 ? input.join(', ')
470 : Object.values(input).join(', ');
471 }
472 loadConfigFile_js.stderr(loadConfigFile_js.cyan(`bundles ${loadConfigFile_js.bold(input)} → ${loadConfigFile_js.bold(event.output.map(rollup.relativeId).join(', '))}...`));
473 }
474 runWatchHook('onBundleStart');
475 break;
476 case 'BUNDLE_END':
477 warnings.flush();
478 if (!silent)
479 loadConfigFile_js.stderr(loadConfigFile_js.green(`created ${loadConfigFile_js.bold(event.output.map(rollup.relativeId).join(', '))} in ${loadConfigFile_js.bold(cli.ms(event.duration))}`));
480 runWatchHook('onBundleEnd');
481 if (event.result && event.result.getTimings) {
482 cli.printTimings(event.result.getTimings());
483 }
484 break;
485 case 'END':
486 runWatchHook('onEnd');
487 if (!silent && isTTY) {
488 loadConfigFile_js.stderr(`\n[${dateTime()}] waiting for changes...`);
489 }
490 }
491 if ('result' in event && event.result) {
492 event.result.close().catch(error => loadConfigFile_js.handleError(error, true));
493 }
494 });
495 }
496 async function close(code) {
497 process$2.removeListener('uncaughtException', close);
498 // removing a non-existent listener is a no-op
499 process$2.stdin.removeListener('end', close);
500 if (watcher)
501 await watcher.close();
502 if (configWatcher)
503 configWatcher.close();
504 if (code) {
505 process$2.exit(code);
506 }
507 }
508}
509
510exports.watch = watch;
511//# sourceMappingURL=watch-cli.js.map
Note: See TracBrowser for help on using the repository browser.