rollup 3.26.3 → 4.0.0-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,316 +0,0 @@
1
- /*
2
- @license
3
- Rollup.js v3.26.3
4
- Mon, 17 Jul 2023 10:32:34 GMT - commit ce6f05843f6af9545fb2321c7ec99387ac1e2df0
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 node_path = require('node:path');
15
- const process = require('node:process');
16
- const rollup = require('./rollup.js');
17
- const node_os = require('node:os');
18
- const index = require('./index.js');
19
- require('tty');
20
- require('path');
21
- require('node:perf_hooks');
22
- require('node:crypto');
23
- require('node:fs/promises');
24
- require('fs');
25
- require('util');
26
- require('stream');
27
- require('os');
28
- require('./fsevents-importer.js');
29
- require('events');
30
-
31
- class FileWatcher {
32
- constructor(task, chokidarOptions) {
33
- this.transformWatchers = new Map();
34
- this.chokidarOptions = chokidarOptions;
35
- this.task = task;
36
- this.watcher = this.createWatcher(null);
37
- }
38
- close() {
39
- this.watcher.close();
40
- for (const watcher of this.transformWatchers.values()) {
41
- watcher.close();
42
- }
43
- }
44
- unwatch(id) {
45
- this.watcher.unwatch(id);
46
- const transformWatcher = this.transformWatchers.get(id);
47
- if (transformWatcher) {
48
- this.transformWatchers.delete(id);
49
- transformWatcher.close();
50
- }
51
- }
52
- watch(id, isTransformDependency) {
53
- if (isTransformDependency) {
54
- const watcher = this.transformWatchers.get(id) ?? this.createWatcher(id);
55
- watcher.add(id);
56
- this.transformWatchers.set(id, watcher);
57
- }
58
- else {
59
- this.watcher.add(id);
60
- }
61
- }
62
- createWatcher(transformWatcherId) {
63
- const task = this.task;
64
- const isLinux = node_os.platform() === 'linux';
65
- const isTransformDependency = transformWatcherId !== null;
66
- const handleChange = (id, event) => {
67
- const changedId = transformWatcherId || id;
68
- if (isLinux) {
69
- // unwatching and watching fixes an issue with chokidar where on certain systems,
70
- // a file that was unlinked and immediately recreated would create a change event
71
- // but then no longer any further events
72
- watcher.unwatch(changedId);
73
- watcher.add(changedId);
74
- }
75
- task.invalidate(changedId, { event, isTransformDependency });
76
- };
77
- const watcher = index.chokidar
78
- .watch([], this.chokidarOptions)
79
- .on('add', id => handleChange(id, 'create'))
80
- .on('change', id => handleChange(id, 'update'))
81
- .on('unlink', id => handleChange(id, 'delete'));
82
- return watcher;
83
- }
84
- }
85
-
86
- const eventsRewrites = {
87
- create: {
88
- create: 'buggy',
89
- delete: null,
90
- update: 'create'
91
- },
92
- delete: {
93
- create: 'update',
94
- delete: 'buggy',
95
- update: 'buggy'
96
- },
97
- update: {
98
- create: 'buggy',
99
- delete: 'delete',
100
- update: 'update'
101
- }
102
- };
103
- class Watcher {
104
- constructor(optionsList, emitter) {
105
- this.buildDelay = 0;
106
- this.buildTimeout = null;
107
- this.closed = false;
108
- this.invalidatedIds = new Map();
109
- this.rerun = false;
110
- this.running = true;
111
- this.emitter = emitter;
112
- emitter.close = this.close.bind(this);
113
- this.tasks = optionsList.map(options => new Task(this, options));
114
- for (const { watch } of optionsList) {
115
- if (watch && typeof watch.buildDelay === 'number') {
116
- this.buildDelay = Math.max(this.buildDelay, watch.buildDelay);
117
- }
118
- }
119
- process.nextTick(() => this.run());
120
- }
121
- async close() {
122
- if (this.closed)
123
- return;
124
- this.closed = true;
125
- if (this.buildTimeout)
126
- clearTimeout(this.buildTimeout);
127
- for (const task of this.tasks) {
128
- task.close();
129
- }
130
- await this.emitter.emit('close');
131
- this.emitter.removeAllListeners();
132
- }
133
- invalidate(file) {
134
- if (file) {
135
- const previousEvent = this.invalidatedIds.get(file.id);
136
- const event = previousEvent ? eventsRewrites[previousEvent][file.event] : file.event;
137
- if (event === 'buggy') {
138
- //TODO: throws or warn? Currently just ignore, uses new event
139
- this.invalidatedIds.set(file.id, file.event);
140
- }
141
- else if (event === null) {
142
- this.invalidatedIds.delete(file.id);
143
- }
144
- else {
145
- this.invalidatedIds.set(file.id, event);
146
- }
147
- }
148
- if (this.running) {
149
- this.rerun = true;
150
- return;
151
- }
152
- if (this.buildTimeout)
153
- clearTimeout(this.buildTimeout);
154
- this.buildTimeout = setTimeout(async () => {
155
- this.buildTimeout = null;
156
- try {
157
- await Promise.all([...this.invalidatedIds].map(([id, event]) => this.emitter.emit('change', id, { event })));
158
- this.invalidatedIds.clear();
159
- await this.emitter.emit('restart');
160
- this.emitter.removeListenersForCurrentRun();
161
- this.run();
162
- }
163
- catch (error) {
164
- this.invalidatedIds.clear();
165
- await this.emitter.emit('event', {
166
- code: 'ERROR',
167
- error,
168
- result: null
169
- });
170
- await this.emitter.emit('event', {
171
- code: 'END'
172
- });
173
- }
174
- }, this.buildDelay);
175
- }
176
- async run() {
177
- this.running = true;
178
- await this.emitter.emit('event', {
179
- code: 'START'
180
- });
181
- for (const task of this.tasks) {
182
- await task.run();
183
- }
184
- this.running = false;
185
- await this.emitter.emit('event', {
186
- code: 'END'
187
- });
188
- if (this.rerun) {
189
- this.rerun = false;
190
- this.invalidate();
191
- }
192
- }
193
- }
194
- class Task {
195
- constructor(watcher, options) {
196
- this.cache = { modules: [] };
197
- this.watchFiles = [];
198
- this.closed = false;
199
- this.invalidated = true;
200
- this.watched = new Set();
201
- this.watcher = watcher;
202
- this.options = options;
203
- this.skipWrite = Boolean(options.watch && options.watch.skipWrite);
204
- this.outputs = this.options.output;
205
- this.outputFiles = this.outputs.map(output => {
206
- if (output.file || output.dir)
207
- return node_path.resolve(output.file || output.dir);
208
- return undefined;
209
- });
210
- const watchOptions = this.options.watch || {};
211
- this.filter = rollup.createFilter(watchOptions.include, watchOptions.exclude);
212
- this.fileWatcher = new FileWatcher(this, {
213
- ...watchOptions.chokidar,
214
- disableGlobbing: true,
215
- ignoreInitial: true
216
- });
217
- }
218
- close() {
219
- this.closed = true;
220
- this.fileWatcher.close();
221
- }
222
- invalidate(id, details) {
223
- this.invalidated = true;
224
- if (details.isTransformDependency) {
225
- for (const module of this.cache.modules) {
226
- if (!module.transformDependencies.includes(id))
227
- continue;
228
- // effective invalidation
229
- module.originalCode = null;
230
- }
231
- }
232
- this.watcher.invalidate({ event: details.event, id });
233
- }
234
- async run() {
235
- if (!this.invalidated)
236
- return;
237
- this.invalidated = false;
238
- const options = {
239
- ...this.options,
240
- cache: this.cache
241
- };
242
- const start = Date.now();
243
- await this.watcher.emitter.emit('event', {
244
- code: 'BUNDLE_START',
245
- input: this.options.input,
246
- output: this.outputFiles
247
- });
248
- let result = null;
249
- try {
250
- result = await rollup.rollupInternal(options, this.watcher.emitter);
251
- if (this.closed) {
252
- return;
253
- }
254
- this.updateWatchedFiles(result);
255
- this.skipWrite || (await Promise.all(this.outputs.map(output => result.write(output))));
256
- await this.watcher.emitter.emit('event', {
257
- code: 'BUNDLE_END',
258
- duration: Date.now() - start,
259
- input: this.options.input,
260
- output: this.outputFiles,
261
- result
262
- });
263
- }
264
- catch (error) {
265
- if (!this.closed) {
266
- if (Array.isArray(error.watchFiles)) {
267
- for (const id of error.watchFiles) {
268
- this.watchFile(id);
269
- }
270
- }
271
- if (error.id) {
272
- this.cache.modules = this.cache.modules.filter(module => module.id !== error.id);
273
- }
274
- }
275
- await this.watcher.emitter.emit('event', {
276
- code: 'ERROR',
277
- error,
278
- result
279
- });
280
- }
281
- }
282
- updateWatchedFiles(result) {
283
- const previouslyWatched = this.watched;
284
- this.watched = new Set();
285
- this.watchFiles = result.watchFiles;
286
- this.cache = result.cache;
287
- for (const id of this.watchFiles) {
288
- this.watchFile(id);
289
- }
290
- for (const module of this.cache.modules) {
291
- for (const depId of module.transformDependencies) {
292
- this.watchFile(depId, true);
293
- }
294
- }
295
- for (const id of previouslyWatched) {
296
- if (!this.watched.has(id)) {
297
- this.fileWatcher.unwatch(id);
298
- }
299
- }
300
- }
301
- watchFile(id, isTransformDependency = false) {
302
- if (!this.filter(id))
303
- return;
304
- this.watched.add(id);
305
- if (this.outputFiles.includes(id)) {
306
- throw new Error('Cannot import the generated bundle');
307
- }
308
- // this is necessary to ensure that any 'renamed' files
309
- // continue to be watched following an error
310
- this.fileWatcher.watch(id, isTransformDependency);
311
- }
312
- }
313
-
314
- exports.Task = Task;
315
- exports.Watcher = Watcher;
316
- //# sourceMappingURL=watch.js.map