rollup 2.57.0

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.
@@ -0,0 +1,304 @@
1
+ /*
2
+ @license
3
+ Rollup.js v2.57.0
4
+ Wed, 22 Sep 2021 04:43:07 GMT - commit b67ef301e8e44f9e0d9b144c0cce441e2a41c3da
5
+
6
+
7
+ https://github.com/rollup/rollup
8
+
9
+ Released under the MIT License.
10
+ */
11
+ 'use strict';
12
+
13
+ var path = require('path');
14
+ var rollup = require('./rollup.js');
15
+ var mergeOptions = require('./mergeOptions.js');
16
+ var require$$2 = require('os');
17
+ var index = require('./index.js');
18
+ require('crypto');
19
+ require('fs');
20
+ require('events');
21
+ require('util');
22
+ require('stream');
23
+
24
+ function _interopNamespaceDefault(e) {
25
+ var n = Object.create(null);
26
+ if (e) {
27
+ for (var k in e) {
28
+ n[k] = e[k];
29
+ }
30
+ }
31
+ n["default"] = e;
32
+ return n;
33
+ }
34
+
35
+ var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
36
+
37
+ class FileWatcher {
38
+ constructor(task, chokidarOptions) {
39
+ this.transformWatchers = new Map();
40
+ this.chokidarOptions = chokidarOptions;
41
+ this.task = task;
42
+ this.watcher = this.createWatcher(null);
43
+ }
44
+ close() {
45
+ this.watcher.close();
46
+ for (const watcher of this.transformWatchers.values()) {
47
+ watcher.close();
48
+ }
49
+ }
50
+ unwatch(id) {
51
+ this.watcher.unwatch(id);
52
+ const transformWatcher = this.transformWatchers.get(id);
53
+ if (transformWatcher) {
54
+ this.transformWatchers.delete(id);
55
+ transformWatcher.close();
56
+ }
57
+ }
58
+ watch(id, isTransformDependency) {
59
+ if (isTransformDependency) {
60
+ const watcher = this.transformWatchers.get(id) || this.createWatcher(id);
61
+ watcher.add(id);
62
+ this.transformWatchers.set(id, watcher);
63
+ }
64
+ else {
65
+ this.watcher.add(id);
66
+ }
67
+ }
68
+ createWatcher(transformWatcherId) {
69
+ const task = this.task;
70
+ const isLinux = require$$2.platform() === 'linux';
71
+ const isTransformDependency = transformWatcherId !== null;
72
+ const handleChange = (id, event) => {
73
+ const changedId = transformWatcherId || id;
74
+ if (isLinux) {
75
+ // unwatching and watching fixes an issue with chokidar where on certain systems,
76
+ // a file that was unlinked and immediately recreated would create a change event
77
+ // but then no longer any further events
78
+ watcher.unwatch(changedId);
79
+ watcher.add(changedId);
80
+ }
81
+ task.invalidate(changedId, { event, isTransformDependency });
82
+ };
83
+ const watcher = index.chokidar
84
+ .watch([], this.chokidarOptions)
85
+ .on('add', id => handleChange(id, 'create'))
86
+ .on('change', id => handleChange(id, 'update'))
87
+ .on('unlink', id => handleChange(id, 'delete'));
88
+ return watcher;
89
+ }
90
+ }
91
+
92
+ const eventsRewrites = {
93
+ create: {
94
+ create: 'buggy',
95
+ delete: null,
96
+ update: 'create'
97
+ },
98
+ delete: {
99
+ create: 'update',
100
+ delete: 'buggy',
101
+ update: 'buggy'
102
+ },
103
+ update: {
104
+ create: 'buggy',
105
+ delete: 'delete',
106
+ update: 'update'
107
+ }
108
+ };
109
+ class Watcher {
110
+ constructor(configs, emitter) {
111
+ this.buildDelay = 0;
112
+ this.buildTimeout = null;
113
+ this.invalidatedIds = new Map();
114
+ this.rerun = false;
115
+ this.running = true;
116
+ this.emitter = emitter;
117
+ emitter.close = this.close.bind(this);
118
+ this.tasks = configs.map(config => new Task(this, config));
119
+ this.buildDelay = configs.reduce((buildDelay, { watch }) => watch && typeof watch.buildDelay === 'number'
120
+ ? Math.max(buildDelay, watch.buildDelay)
121
+ : buildDelay, this.buildDelay);
122
+ process.nextTick(() => this.run());
123
+ }
124
+ close() {
125
+ if (this.buildTimeout)
126
+ clearTimeout(this.buildTimeout);
127
+ for (const task of this.tasks) {
128
+ task.close();
129
+ }
130
+ this.emitter.emit('close');
131
+ this.emitter.removeAllListeners();
132
+ }
133
+ invalidate(file) {
134
+ if (file) {
135
+ const prevEvent = this.invalidatedIds.get(file.id);
136
+ const event = prevEvent ? eventsRewrites[prevEvent][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(() => {
155
+ this.buildTimeout = null;
156
+ for (const [id, event] of this.invalidatedIds.entries()) {
157
+ this.emitter.emit('change', id, { event });
158
+ }
159
+ this.invalidatedIds.clear();
160
+ this.emitter.emit('restart');
161
+ this.run();
162
+ }, this.buildDelay);
163
+ }
164
+ async run() {
165
+ this.running = true;
166
+ this.emitter.emit('event', {
167
+ code: 'START'
168
+ });
169
+ for (const task of this.tasks) {
170
+ await task.run();
171
+ }
172
+ this.running = false;
173
+ this.emitter.emit('event', {
174
+ code: 'END'
175
+ });
176
+ if (this.rerun) {
177
+ this.rerun = false;
178
+ this.invalidate();
179
+ }
180
+ }
181
+ }
182
+ class Task {
183
+ constructor(watcher, config) {
184
+ this.cache = { modules: [] };
185
+ this.watchFiles = [];
186
+ this.closed = false;
187
+ this.invalidated = true;
188
+ this.watched = new Set();
189
+ this.watcher = watcher;
190
+ this.skipWrite = Boolean(config.watch && config.watch.skipWrite);
191
+ this.options = mergeOptions.mergeOptions(config);
192
+ this.outputs = this.options.output;
193
+ this.outputFiles = this.outputs.map(output => {
194
+ if (output.file || output.dir)
195
+ return path__namespace.resolve(output.file || output.dir);
196
+ return undefined;
197
+ });
198
+ const watchOptions = this.options.watch || {};
199
+ this.filter = rollup.createFilter(watchOptions.include, watchOptions.exclude);
200
+ this.fileWatcher = new FileWatcher(this, {
201
+ ...watchOptions.chokidar,
202
+ disableGlobbing: true,
203
+ ignoreInitial: true
204
+ });
205
+ }
206
+ close() {
207
+ this.closed = true;
208
+ this.fileWatcher.close();
209
+ }
210
+ invalidate(id, details) {
211
+ this.invalidated = true;
212
+ if (details.isTransformDependency) {
213
+ for (const module of this.cache.modules) {
214
+ if (module.transformDependencies.indexOf(id) === -1)
215
+ continue;
216
+ // effective invalidation
217
+ module.originalCode = null;
218
+ }
219
+ }
220
+ this.watcher.invalidate({ event: details.event, id });
221
+ }
222
+ async run() {
223
+ if (!this.invalidated)
224
+ return;
225
+ this.invalidated = false;
226
+ const options = {
227
+ ...this.options,
228
+ cache: this.cache
229
+ };
230
+ const start = Date.now();
231
+ this.watcher.emitter.emit('event', {
232
+ code: 'BUNDLE_START',
233
+ input: this.options.input,
234
+ output: this.outputFiles
235
+ });
236
+ let result = null;
237
+ try {
238
+ result = await rollup.rollupInternal(options, this.watcher.emitter);
239
+ if (this.closed) {
240
+ return;
241
+ }
242
+ this.updateWatchedFiles(result);
243
+ this.skipWrite || (await Promise.all(this.outputs.map(output => result.write(output))));
244
+ this.watcher.emitter.emit('event', {
245
+ code: 'BUNDLE_END',
246
+ duration: Date.now() - start,
247
+ input: this.options.input,
248
+ output: this.outputFiles,
249
+ result
250
+ });
251
+ }
252
+ catch (error) {
253
+ if (!this.closed) {
254
+ if (Array.isArray(error.watchFiles)) {
255
+ for (const id of error.watchFiles) {
256
+ this.watchFile(id);
257
+ }
258
+ }
259
+ if (error.id) {
260
+ this.cache.modules = this.cache.modules.filter(module => module.id !== error.id);
261
+ }
262
+ }
263
+ this.watcher.emitter.emit('event', {
264
+ code: 'ERROR',
265
+ error,
266
+ result
267
+ });
268
+ }
269
+ }
270
+ updateWatchedFiles(result) {
271
+ const previouslyWatched = this.watched;
272
+ this.watched = new Set();
273
+ this.watchFiles = result.watchFiles;
274
+ this.cache = result.cache;
275
+ for (const id of this.watchFiles) {
276
+ this.watchFile(id);
277
+ }
278
+ for (const module of this.cache.modules) {
279
+ for (const depId of module.transformDependencies) {
280
+ this.watchFile(depId, true);
281
+ }
282
+ }
283
+ for (const id of previouslyWatched) {
284
+ if (!this.watched.has(id)) {
285
+ this.fileWatcher.unwatch(id);
286
+ }
287
+ }
288
+ }
289
+ watchFile(id, isTransformDependency = false) {
290
+ if (!this.filter(id))
291
+ return;
292
+ this.watched.add(id);
293
+ if (this.outputFiles.some(file => file === id)) {
294
+ throw new Error('Cannot import the generated bundle');
295
+ }
296
+ // this is necessary to ensure that any 'renamed' files
297
+ // continue to be watched following an error
298
+ this.fileWatcher.watch(id, isTransformDependency);
299
+ }
300
+ }
301
+
302
+ exports.Task = Task;
303
+ exports.Watcher = Watcher;
304
+ //# sourceMappingURL=watch.js.map
package/package.json ADDED
@@ -0,0 +1,142 @@
1
+ {
2
+ "name": "rollup",
3
+ "version": "2.57.0",
4
+ "description": "Next-generation ES module bundler",
5
+ "main": "dist/rollup.js",
6
+ "module": "dist/es/rollup.js",
7
+ "typings": "dist/rollup.d.ts",
8
+ "bin": {
9
+ "rollup": "dist/bin/rollup"
10
+ },
11
+ "scripts": {
12
+ "build": "shx rm -rf dist && git rev-parse HEAD > .commithash && rollup --config rollup.config.ts --configPlugin typescript && shx cp src/rollup/types.d.ts dist/rollup.d.ts && shx chmod a+x dist/bin/rollup",
13
+ "build:cjs": "shx rm -rf dist && rollup --config rollup.config.ts --configPlugin typescript --configTest && shx cp src/rollup/types.d.ts dist/rollup.d.ts && shx chmod a+x dist/bin/rollup",
14
+ "build:bootstrap": "node dist/bin/rollup --config rollup.config.ts --configPlugin typescript && shx cp src/rollup/types.d.ts dist/rollup.d.ts && shx chmod a+x dist/bin/rollup",
15
+ "ci:lint": "npm run lint:nofix",
16
+ "ci:test": "npm run build:cjs && npm run build:bootstrap && npm run test:all",
17
+ "ci:test:only": "npm run build:cjs && npm run build:bootstrap && npm run test:only",
18
+ "ci:coverage": "npm run build:cjs && npm run build:bootstrap && nyc --reporter lcovonly mocha",
19
+ "lint": "eslint . --fix --cache && prettier --write \"**/*.md\"",
20
+ "lint:nofix": "eslint . && prettier --check \"**/*.md\"",
21
+ "lint:markdown": "prettier --write \"**/*.md\"",
22
+ "perf": "npm run build:cjs && node --expose-gc scripts/perf.js",
23
+ "perf:debug": "node --inspect-brk scripts/perf-debug.js",
24
+ "perf:init": "node scripts/perf-init.js",
25
+ "_postinstall": "husky install",
26
+ "postpublish": "pinst --enable && git push && git push --tags",
27
+ "prepare": "husky install && npm run build",
28
+ "prepublishOnly": "pinst --disable && npm ci && npm run lint:nofix && npm run security && npm run build:bootstrap && npm run test:all",
29
+ "security": "npm audit",
30
+ "test": "npm run build && npm run test:all",
31
+ "test:cjs": "npm run build:cjs && npm run test:only",
32
+ "test:quick": "mocha -b test/test.js",
33
+ "test:all": "npm run test:only && npm run test:browser && npm run test:typescript && npm run test:leak && npm run test:package",
34
+ "test:coverage": "npm run build:cjs && shx rm -rf coverage/* && nyc --reporter html mocha test/test.js",
35
+ "test:coverage:browser": "npm run build && shx rm -rf coverage/* && nyc mocha test/browser/index.js",
36
+ "test:leak": "node --expose-gc test/leak/index.js",
37
+ "test:package": "node scripts/test-package.js",
38
+ "test:only": "mocha test/test.js",
39
+ "test:typescript": "shx rm -rf test/typescript/dist && shx cp -r dist test/typescript/ && tsc --noEmit -p test/typescript && tsc --noEmit",
40
+ "test:browser": "mocha test/browser/index.js",
41
+ "watch": "rollup --config rollup.config.ts --configPlugin typescript --watch"
42
+ },
43
+ "repository": "rollup/rollup",
44
+ "keywords": [
45
+ "modules",
46
+ "bundler",
47
+ "bundling",
48
+ "es6",
49
+ "optimizer"
50
+ ],
51
+ "author": "Rich Harris",
52
+ "license": "MIT",
53
+ "bugs": {
54
+ "url": "https://github.com/rollup/rollup/issues"
55
+ },
56
+ "homepage": "https://rollupjs.org/",
57
+ "optionalDependencies": {
58
+ "fsevents": "~2.3.2"
59
+ },
60
+ "devDependencies": {
61
+ "@rollup/plugin-alias": "^3.1.5",
62
+ "@rollup/plugin-buble": "^0.21.3",
63
+ "@rollup/plugin-commonjs": "^20.0.0",
64
+ "@rollup/plugin-json": "^4.1.0",
65
+ "@rollup/plugin-node-resolve": "^13.0.4",
66
+ "@rollup/plugin-replace": "^3.0.0",
67
+ "@rollup/plugin-typescript": "^8.2.5",
68
+ "@rollup/pluginutils": "^4.1.1",
69
+ "@types/node": "^10.17.60",
70
+ "@types/require-relative": "^0.8.0",
71
+ "@types/signal-exit": "^3.0.1",
72
+ "@types/yargs-parser": "^20.2.1",
73
+ "@typescript-eslint/eslint-plugin": "^4.31.2",
74
+ "@typescript-eslint/parser": "^4.31.2",
75
+ "acorn": "^8.5.0",
76
+ "acorn-jsx": "^5.3.2",
77
+ "acorn-walk": "^8.2.0",
78
+ "buble": "^0.20.0",
79
+ "chokidar": "^3.5.2",
80
+ "colorette": "^1.4.0",
81
+ "core-js": "^3.18.0",
82
+ "date-time": "^4.0.0",
83
+ "es5-shim": "^4.6.2",
84
+ "es6-shim": "^0.35.6",
85
+ "eslint": "^7.32.0",
86
+ "eslint-config-prettier": "^8.3.0",
87
+ "eslint-plugin-import": "^2.24.2",
88
+ "eslint-plugin-prettier": "^3.4.1",
89
+ "execa": "^5.1.1",
90
+ "fixturify": "^2.1.1",
91
+ "hash.js": "^1.1.7",
92
+ "husky": "^6.0.0",
93
+ "is-reference": "^3.0.0",
94
+ "lint-staged": "^10.5.4",
95
+ "locate-character": "^2.0.5",
96
+ "magic-string": "^0.25.7",
97
+ "mocha": "^8.4.0",
98
+ "nyc": "^15.1.0",
99
+ "pinst": "^2.1.6",
100
+ "prettier": "^2.4.1",
101
+ "pretty-bytes": "^5.6.0",
102
+ "pretty-ms": "^7.0.1",
103
+ "require-relative": "^0.8.7",
104
+ "requirejs": "^2.3.6",
105
+ "rollup": "^2.56.3",
106
+ "rollup-plugin-license": "^2.5.0",
107
+ "rollup-plugin-string": "^3.0.0",
108
+ "rollup-plugin-terser": "^7.0.2",
109
+ "rollup-plugin-thatworks": "^1.0.4",
110
+ "sander": "^0.6.0",
111
+ "shx": "^0.3.3",
112
+ "signal-exit": "^3.0.4",
113
+ "source-map": "^0.7.3",
114
+ "source-map-support": "^0.5.20",
115
+ "sourcemap-codec": "^1.4.8",
116
+ "systemjs": "^6.10.3",
117
+ "terser": "^5.8.0",
118
+ "tslib": "^2.3.1",
119
+ "typescript": "^4.4.3",
120
+ "weak-napi": "^2.0.2",
121
+ "yargs-parser": "^20.2.9"
122
+ },
123
+ "files": [
124
+ "dist/**/*.js",
125
+ "dist/*.d.ts",
126
+ "dist/bin/rollup",
127
+ "dist/rollup.browser.js.map"
128
+ ],
129
+ "engines": {
130
+ "node": ">=10.0.0"
131
+ },
132
+ "exports": {
133
+ ".": {
134
+ "node": {
135
+ "require": "./dist/rollup.js",
136
+ "import": "./dist/es/rollup.js"
137
+ },
138
+ "default": "./dist/es/rollup.browser.js"
139
+ },
140
+ "./dist/": "./dist/"
141
+ }
142
+ }