rollup 2.69.1 → 2.70.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.
package/dist/es/rollup.js CHANGED
@@ -1,8 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v2.69.1
4
- Fri, 04 Mar 2022 13:38:38 GMT - commit 994c1eccf4d53e416a010f47e54a2086f1a0f4e9
5
-
3
+ Rollup.js v2.70.1
4
+ Mon, 14 Mar 2022 05:50:08 GMT - commit b8315e03f9790d610a413316fbf6d565f9340cab
6
5
 
7
6
  https://github.com/rollup/rollup
8
7
 
@@ -1,8 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v2.69.1
4
- Fri, 04 Mar 2022 13:38:38 GMT - commit 994c1eccf4d53e416a010f47e54a2086f1a0f4e9
5
-
3
+ Rollup.js v2.70.1
4
+ Mon, 14 Mar 2022 05:50:08 GMT - commit b8315e03f9790d610a413316fbf6d565f9340cab
6
5
 
7
6
  https://github.com/rollup/rollup
8
7
 
@@ -15,7 +14,7 @@ import { createHash as createHash$1 } from 'crypto';
15
14
  import { promises } from 'fs';
16
15
  import { EventEmitter } from 'events';
17
16
 
18
- var version$1 = "2.69.1";
17
+ var version$1 = "2.70.1";
19
18
 
20
19
  var charToInteger = {};
21
20
  var chars$1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
@@ -5772,6 +5771,30 @@ class ObjectEntity extends ExpressionEntity {
5772
5771
  }
5773
5772
  }
5774
5773
 
5774
+ const isInteger = (prop) => typeof prop === 'string' && /^\d+$/.test(prop);
5775
+ // This makes sure unknown properties are not handled as "undefined" but as
5776
+ // "unknown" but without access side effects. An exception is done for numeric
5777
+ // properties as we do not expect new builtin properties to be numbers, this
5778
+ // will improve tree-shaking for out-of-bounds array properties
5779
+ const OBJECT_PROTOTYPE_FALLBACK = new (class ObjectPrototypeFallbackExpression extends ExpressionEntity {
5780
+ deoptimizeThisOnEventAtPath(event, path, thisParameter) {
5781
+ if (event === EVENT_CALLED && path.length === 1 && !isInteger(path[0])) {
5782
+ thisParameter.deoptimizePath(UNKNOWN_PATH);
5783
+ }
5784
+ }
5785
+ getLiteralValueAtPath(path) {
5786
+ // We ignore number properties as we do not expect new properties to be
5787
+ // numbers and also want to keep handling out-of-bound array elements as
5788
+ // "undefined"
5789
+ return path.length === 1 && isInteger(path[0]) ? undefined : UnknownValue;
5790
+ }
5791
+ hasEffectsWhenAccessedAtPath(path) {
5792
+ return path.length > 1;
5793
+ }
5794
+ hasEffectsWhenAssignedAtPath(path) {
5795
+ return path.length > 1;
5796
+ }
5797
+ })();
5775
5798
  const OBJECT_PROTOTYPE = new ObjectEntity({
5776
5799
  __proto__: null,
5777
5800
  hasOwnProperty: METHOD_RETURNS_BOOLEAN,
@@ -5780,7 +5803,7 @@ const OBJECT_PROTOTYPE = new ObjectEntity({
5780
5803
  toLocaleString: METHOD_RETURNS_STRING,
5781
5804
  toString: METHOD_RETURNS_STRING,
5782
5805
  valueOf: METHOD_RETURNS_UNKNOWN
5783
- }, null, true);
5806
+ }, OBJECT_PROTOTYPE_FALLBACK, true);
5784
5807
 
5785
5808
  const NEW_ARRAY_PROPERTIES = [
5786
5809
  { key: UnknownInteger, kind: 'init', property: UNKNOWN_EXPRESSION },
@@ -6848,6 +6871,8 @@ const knownGlobals = {
6848
6871
  isFrozen: PF,
6849
6872
  isSealed: PF,
6850
6873
  keys: PF,
6874
+ fromEntries: PF,
6875
+ entries: PF,
6851
6876
  prototype: O
6852
6877
  },
6853
6878
  parseFloat: PF,
@@ -22459,41 +22484,6 @@ function getPluginContext(plugin, pluginCache, graph, options, fileEmitter, exis
22459
22484
  return context;
22460
22485
  }
22461
22486
 
22462
- const unfulfilledActions = new Set();
22463
- function addUnresolvedAction(actionTuple) {
22464
- unfulfilledActions.add(actionTuple);
22465
- }
22466
- function resolveAction(actionTuple) {
22467
- unfulfilledActions.delete(actionTuple);
22468
- }
22469
- function formatAction([pluginName, hookName, args]) {
22470
- const action = `(${pluginName}) ${hookName}`;
22471
- const s = JSON.stringify;
22472
- switch (hookName) {
22473
- case 'resolveId':
22474
- return `${action} ${s(args[0])} ${s(args[1])}`;
22475
- case 'load':
22476
- return `${action} ${s(args[0])}`;
22477
- case 'transform':
22478
- return `${action} ${s(args[1])}`;
22479
- case 'shouldTransformCachedModule':
22480
- return `${action} ${s(args[0].id)}`;
22481
- case 'moduleParsed':
22482
- return `${action} ${s(args[0].id)}`;
22483
- }
22484
- return action;
22485
- }
22486
- process$1.on('exit', () => {
22487
- if (unfulfilledActions.size) {
22488
- let err = '[!] Error: unfinished hook action(s) on exit:\n';
22489
- for (const action of unfulfilledActions) {
22490
- err += formatAction(action) + '\n';
22491
- }
22492
- console.error('%s', err);
22493
- process$1.exitCode = 1;
22494
- }
22495
- });
22496
-
22497
22487
  const inputHookNames = {
22498
22488
  buildEnd: 1,
22499
22489
  buildStart: 1,
@@ -22519,6 +22509,7 @@ class PluginDriver {
22519
22509
  constructor(graph, options, userPlugins, pluginCache, basePluginDriver) {
22520
22510
  this.graph = graph;
22521
22511
  this.options = options;
22512
+ this.unfulfilledActions = new Set();
22522
22513
  warnDeprecatedHooks(userPlugins, options);
22523
22514
  this.pluginCache = pluginCache;
22524
22515
  this.fileEmitter = new FileEmitter(graph, options, basePluginDriver && basePluginDriver.fileEmitter);
@@ -22545,6 +22536,9 @@ class PluginDriver {
22545
22536
  createOutputPluginDriver(plugins) {
22546
22537
  return new PluginDriver(this.graph, this.options, plugins, this.pluginCache, this);
22547
22538
  }
22539
+ getUnfulfilledHookActions() {
22540
+ return this.unfulfilledActions;
22541
+ }
22548
22542
  // chains, first non-null result stops and returns
22549
22543
  hookFirst(hookName, args, replaceContext, skipped) {
22550
22544
  let promise = Promise.resolve(undefined);
@@ -22632,12 +22626,6 @@ class PluginDriver {
22632
22626
  }
22633
22627
  return promise;
22634
22628
  }
22635
- // chains synchronously, ignores returns
22636
- hookSeqSync(hookName, args, replaceContext) {
22637
- for (const plugin of this.plugins) {
22638
- this.runHookSync(hookName, args, plugin, replaceContext);
22639
- }
22640
- }
22641
22629
  runHook(hookName, args, plugin, permitValues, hookContext) {
22642
22630
  const hook = plugin[hookName];
22643
22631
  if (!hook)
@@ -22666,22 +22654,21 @@ class PluginDriver {
22666
22654
  // exit with a successful 0 return code but without producing any
22667
22655
  // output, errors or warnings.
22668
22656
  action = [plugin.name, hookName, args];
22669
- addUnresolvedAction(action);
22657
+ this.unfulfilledActions.add(action);
22670
22658
  // Although it would be more elegant to just return hookResult here
22671
22659
  // and put the .then() handler just above the .catch() handler below,
22672
22660
  // doing so would subtly change the defacto async event dispatch order
22673
22661
  // which at least one test and some plugins in the wild may depend on.
22674
- const promise = Promise.resolve(hookResult);
22675
- return promise.then(() => {
22662
+ return Promise.resolve(hookResult).then(result => {
22676
22663
  // action was fulfilled
22677
- resolveAction(action);
22678
- return promise;
22664
+ this.unfulfilledActions.delete(action);
22665
+ return result;
22679
22666
  });
22680
22667
  })
22681
22668
  .catch(err => {
22682
22669
  if (action !== null) {
22683
22670
  // action considered to be fulfilled since error being handled
22684
- resolveAction(action);
22671
+ this.unfulfilledActions.delete(action);
22685
22672
  }
22686
22673
  return throwPluginError(err, plugin.name, { hook: hookName });
22687
22674
  });
@@ -22770,14 +22757,10 @@ class Graph {
22770
22757
  }
22771
22758
  if (watcher) {
22772
22759
  this.watchMode = true;
22773
- const handleChange = (...args) => this.pluginDriver.hookSeqSync('watchChange', args);
22774
- const handleClose = () => this.pluginDriver.hookSeqSync('closeWatcher', []);
22775
- watcher.on('change', handleChange);
22776
- watcher.on('close', handleClose);
22777
- watcher.once('restart', () => {
22778
- watcher.removeListener('change', handleChange);
22779
- watcher.removeListener('close', handleClose);
22780
- });
22760
+ const handleChange = (...args) => this.pluginDriver.hookParallel('watchChange', args);
22761
+ const handleClose = () => this.pluginDriver.hookParallel('closeWatcher', []);
22762
+ watcher.onCurrentAwaited('change', handleChange);
22763
+ watcher.onCurrentAwaited('close', handleClose);
22781
22764
  }
22782
22765
  this.pluginDriver = new PluginDriver(this, options, options.plugins, this.pluginCache);
22783
22766
  this.acornParser = Parser.extend(...options.acornInjectPlugins);
@@ -22942,6 +22925,38 @@ function ensureArray(items) {
22942
22925
  return [];
22943
22926
  }
22944
22927
 
22928
+ function formatAction([pluginName, hookName, args]) {
22929
+ const action = `(${pluginName}) ${hookName}`;
22930
+ const s = JSON.stringify;
22931
+ switch (hookName) {
22932
+ case 'resolveId':
22933
+ return `${action} ${s(args[0])} ${s(args[1])}`;
22934
+ case 'load':
22935
+ return `${action} ${s(args[0])}`;
22936
+ case 'transform':
22937
+ return `${action} ${s(args[1])}`;
22938
+ case 'shouldTransformCachedModule':
22939
+ return `${action} ${s(args[0].id)}`;
22940
+ case 'moduleParsed':
22941
+ return `${action} ${s(args[0].id)}`;
22942
+ }
22943
+ return action;
22944
+ }
22945
+ async function catchUnfinishedHookActions(pluginDriver, callback) {
22946
+ let handleEmptyEventLoop;
22947
+ const emptyEventLoopPromise = new Promise((_, reject) => {
22948
+ handleEmptyEventLoop = () => {
22949
+ const unfulfilledActions = pluginDriver.getUnfulfilledHookActions();
22950
+ reject(new Error(`Unexpected early exit. This happens when Promises returned by plugins cannot resolve. Unfinished hook action(s) on exit:\n` +
22951
+ [...unfulfilledActions].map(formatAction).join('\n')));
22952
+ };
22953
+ process$1.once('beforeExit', handleEmptyEventLoop);
22954
+ });
22955
+ const result = await Promise.race([callback(), emptyEventLoopPromise]);
22956
+ process$1.off('beforeExit', handleEmptyEventLoop);
22957
+ return result;
22958
+ }
22959
+
22945
22960
  const defaultOnWarn = warning => console.warn(warning.message || warning);
22946
22961
  function warnUnknownOptions(passedOptions, validOptions, optionType, warn, ignoredKeys = /$./) {
22947
22962
  const validOptionSet = new Set(validOptions);
@@ -23509,20 +23524,22 @@ async function rollupInternal(rawInputOptions, watcher) {
23509
23524
  delete inputOptions.cache;
23510
23525
  delete rawInputOptions.cache;
23511
23526
  timeStart('BUILD', 1);
23512
- try {
23513
- await graph.pluginDriver.hookParallel('buildStart', [inputOptions]);
23514
- await graph.build();
23515
- }
23516
- catch (err) {
23517
- const watchFiles = Object.keys(graph.watchFiles);
23518
- if (watchFiles.length > 0) {
23519
- err.watchFiles = watchFiles;
23527
+ await catchUnfinishedHookActions(graph.pluginDriver, async () => {
23528
+ try {
23529
+ await graph.pluginDriver.hookParallel('buildStart', [inputOptions]);
23530
+ await graph.build();
23520
23531
  }
23521
- await graph.pluginDriver.hookParallel('buildEnd', [err]);
23522
- await graph.pluginDriver.hookParallel('closeBundle', []);
23523
- throw err;
23524
- }
23525
- await graph.pluginDriver.hookParallel('buildEnd', []);
23532
+ catch (err) {
23533
+ const watchFiles = Object.keys(graph.watchFiles);
23534
+ if (watchFiles.length > 0) {
23535
+ err.watchFiles = watchFiles;
23536
+ }
23537
+ await graph.pluginDriver.hookParallel('buildEnd', [err]);
23538
+ await graph.pluginDriver.hookParallel('closeBundle', []);
23539
+ throw err;
23540
+ }
23541
+ await graph.pluginDriver.hookParallel('buildEnd', []);
23542
+ });
23526
23543
  timeEnd('BUILD', 1);
23527
23544
  const result = {
23528
23545
  cache: useCache ? graph.getCache() : undefined,
@@ -23573,21 +23590,23 @@ function normalizePlugins(plugins, anonymousPrefix) {
23573
23590
  }
23574
23591
  });
23575
23592
  }
23576
- async function handleGenerateWrite(isWrite, inputOptions, unsetInputOptions, rawOutputOptions, graph) {
23593
+ function handleGenerateWrite(isWrite, inputOptions, unsetInputOptions, rawOutputOptions, graph) {
23577
23594
  const { options: outputOptions, outputPluginDriver, unsetOptions } = getOutputOptionsAndPluginDriver(rawOutputOptions, graph.pluginDriver, inputOptions, unsetInputOptions);
23578
- const bundle = new Bundle(outputOptions, unsetOptions, inputOptions, outputPluginDriver, graph);
23579
- const generated = await bundle.generate(isWrite);
23580
- if (isWrite) {
23581
- if (!outputOptions.dir && !outputOptions.file) {
23582
- return error({
23583
- code: 'MISSING_OPTION',
23584
- message: 'You must specify "output.file" or "output.dir" for the build.'
23585
- });
23595
+ return catchUnfinishedHookActions(outputPluginDriver, async () => {
23596
+ const bundle = new Bundle(outputOptions, unsetOptions, inputOptions, outputPluginDriver, graph);
23597
+ const generated = await bundle.generate(isWrite);
23598
+ if (isWrite) {
23599
+ if (!outputOptions.dir && !outputOptions.file) {
23600
+ return error({
23601
+ code: 'MISSING_OPTION',
23602
+ message: 'You must specify "output.file" or "output.dir" for the build.'
23603
+ });
23604
+ }
23605
+ await Promise.all(Object.values(generated).map(chunk => writeOutputFile(chunk, outputOptions)));
23606
+ await outputPluginDriver.hookParallel('writeBundle', [outputOptions, generated]);
23586
23607
  }
23587
- await Promise.all(Object.values(generated).map(chunk => writeOutputFile(chunk, outputOptions)));
23588
- await outputPluginDriver.hookParallel('writeBundle', [outputOptions, generated]);
23589
- }
23590
- return createOutput(generated);
23608
+ return createOutput(generated);
23609
+ });
23591
23610
  }
23592
23611
  function getOutputOptionsAndPluginDriver(rawOutputOptions, inputPluginDriver, inputOptions, unsetInputOptions) {
23593
23612
  if (!rawOutputOptions) {
@@ -23673,6 +23692,33 @@ function defineConfig(options) {
23673
23692
  return options;
23674
23693
  }
23675
23694
 
23695
+ class WatchEmitter extends EventEmitter {
23696
+ constructor() {
23697
+ super();
23698
+ this.awaitedHandlers = Object.create(null);
23699
+ // Allows more than 10 bundles to be watched without
23700
+ // showing the `MaxListenersExceededWarning` to the user.
23701
+ this.setMaxListeners(Infinity);
23702
+ }
23703
+ // Will be overwritten by Rollup
23704
+ async close() { }
23705
+ emitAndAwait(event, ...args) {
23706
+ this.emit(event, ...args);
23707
+ return Promise.all(this.getHandlers(event).map(handler => handler(...args)));
23708
+ }
23709
+ onCurrentAwaited(event, listener) {
23710
+ this.getHandlers(event).push(listener);
23711
+ return this;
23712
+ }
23713
+ removeAwaited() {
23714
+ this.awaitedHandlers = {};
23715
+ return this;
23716
+ }
23717
+ getHandlers(event) {
23718
+ return this.awaitedHandlers[event] || (this.awaitedHandlers[event] = []);
23719
+ }
23720
+ }
23721
+
23676
23722
  let fsEvents;
23677
23723
  let fsEventsImportError;
23678
23724
  async function loadFsEvents() {
@@ -23696,15 +23742,6 @@ const fseventsImporter = /*#__PURE__*/Object.defineProperty({
23696
23742
  getFsEvents
23697
23743
  }, Symbol.toStringTag, { value: 'Module' });
23698
23744
 
23699
- class WatchEmitter extends EventEmitter {
23700
- constructor() {
23701
- super();
23702
- // Allows more than 10 bundles to be watched without
23703
- // showing the `MaxListenersExceededWarning` to the user.
23704
- this.setMaxListeners(Infinity);
23705
- }
23706
- close() { }
23707
- }
23708
23745
  function watch(configs) {
23709
23746
  const emitter = new WatchEmitter();
23710
23747
  const configArray = ensureArray(configs);
@@ -1,8 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v2.69.1
4
- Fri, 04 Mar 2022 13:38:38 GMT - commit 994c1eccf4d53e416a010f47e54a2086f1a0f4e9
5
-
3
+ Rollup.js v2.70.1
4
+ Mon, 14 Mar 2022 05:50:08 GMT - commit b8315e03f9790d610a413316fbf6d565f9340cab
6
5
 
7
6
  https://github.com/rollup/rollup
8
7
 
@@ -4807,13 +4806,13 @@ class Watcher {
4807
4806
  : buildDelay, this.buildDelay);
4808
4807
  process$1.nextTick(() => this.run());
4809
4808
  }
4810
- close() {
4809
+ async close() {
4811
4810
  if (this.buildTimeout)
4812
4811
  clearTimeout(this.buildTimeout);
4813
4812
  for (const task of this.tasks) {
4814
4813
  task.close();
4815
4814
  }
4816
- this.emitter.emit('close');
4815
+ await this.emitter.emitAndAwait('close');
4817
4816
  this.emitter.removeAllListeners();
4818
4817
  }
4819
4818
  invalidate(file) {
@@ -4837,14 +4836,26 @@ class Watcher {
4837
4836
  }
4838
4837
  if (this.buildTimeout)
4839
4838
  clearTimeout(this.buildTimeout);
4840
- this.buildTimeout = setTimeout(() => {
4839
+ this.buildTimeout = setTimeout(async () => {
4841
4840
  this.buildTimeout = null;
4842
- for (const [id, event] of this.invalidatedIds) {
4843
- this.emitter.emit('change', id, { event });
4841
+ try {
4842
+ await Promise.all([...this.invalidatedIds].map(([id, event]) => this.emitter.emitAndAwait('change', id, { event })));
4843
+ this.invalidatedIds.clear();
4844
+ this.emitter.emit('restart');
4845
+ this.emitter.removeAwaited();
4846
+ this.run();
4847
+ }
4848
+ catch (error) {
4849
+ this.invalidatedIds.clear();
4850
+ this.emitter.emit('event', {
4851
+ code: 'ERROR',
4852
+ error,
4853
+ result: null
4854
+ });
4855
+ this.emitter.emit('event', {
4856
+ code: 'END'
4857
+ });
4844
4858
  }
4845
- this.invalidatedIds.clear();
4846
- this.emitter.emit('restart');
4847
- this.run();
4848
4859
  }, this.buildDelay);
4849
4860
  }
4850
4861
  async run() {
@@ -1,8 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v2.69.1
4
- Fri, 04 Mar 2022 13:38:38 GMT - commit 994c1eccf4d53e416a010f47e54a2086f1a0f4e9
5
-
3
+ Rollup.js v2.70.1
4
+ Mon, 14 Mar 2022 05:50:08 GMT - commit b8315e03f9790d610a413316fbf6d565f9340cab
6
5
 
7
6
  https://github.com/rollup/rollup
8
7