rollup 2.77.3 → 2.78.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.
package/dist/es/rollup.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v2.77.3
4
- Thu, 11 Aug 2022 05:48:58 GMT - commit 1165d46685ef3c70617b2f150ab245ff5de5e783
3
+ Rollup.js v2.78.0
4
+ Sun, 14 Aug 2022 04:30:34 GMT - commit 105b264847892c8f7966364d73f6900554178f58
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v2.77.3
4
- Thu, 11 Aug 2022 05:48:58 GMT - commit 1165d46685ef3c70617b2f150ab245ff5de5e783
3
+ Rollup.js v2.78.0
4
+ Sun, 14 Aug 2022 04:30:34 GMT - commit 105b264847892c8f7966364d73f6900554178f58
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
@@ -14,7 +14,7 @@ import { createHash as createHash$1 } from 'crypto';
14
14
  import { promises } from 'fs';
15
15
  import { EventEmitter } from 'events';
16
16
 
17
- var version$1 = "2.77.3";
17
+ var version$1 = "2.78.0";
18
18
 
19
19
  var charToInteger = {};
20
20
  var chars$1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
@@ -2033,6 +2033,22 @@ function errInvalidOption(option, urlHash, explanation, value) {
2033
2033
  url: `https://rollupjs.org/guide/en/#${urlHash}`
2034
2034
  };
2035
2035
  }
2036
+ function errInvalidAddonPluginHook(hook, plugin) {
2037
+ return {
2038
+ code: Errors.INVALID_PLUGIN_HOOK,
2039
+ hook,
2040
+ message: `Error running plugin hook ${hook} for plugin ${plugin}, expected a string, a function hook or an object with a "handler" string or function.`,
2041
+ plugin
2042
+ };
2043
+ }
2044
+ function errInvalidFunctionPluginHook(hook, plugin) {
2045
+ return {
2046
+ code: Errors.INVALID_PLUGIN_HOOK,
2047
+ hook,
2048
+ message: `Error running plugin hook ${hook} for plugin ${plugin}, expected a function hook or an object with a "handler" function.`,
2049
+ plugin
2050
+ };
2051
+ }
2036
2052
  function errInvalidRollupPhaseForAddWatchFile() {
2037
2053
  return {
2038
2054
  code: Errors.INVALID_ROLLUP_PHASE,
@@ -22471,7 +22487,7 @@ function getPluginContext(plugin, pluginCache, graph, options, fileEmitter, exis
22471
22487
  else {
22472
22488
  cacheInstance = getCacheForUncacheablePlugin(plugin.name);
22473
22489
  }
22474
- const context = {
22490
+ return {
22475
22491
  addWatchFile(id) {
22476
22492
  if (graph.phase >= BuildPhase.GENERATE) {
22477
22493
  return this.error(errInvalidRollupPhaseForAddWatchFile());
@@ -22529,9 +22545,9 @@ function getPluginContext(plugin, pluginCache, graph, options, fileEmitter, exis
22529
22545
  options.onwarn(warning);
22530
22546
  }
22531
22547
  };
22532
- return context;
22533
22548
  }
22534
22549
 
22550
+ // This will make sure no input hook is omitted
22535
22551
  const inputHookNames = {
22536
22552
  buildEnd: 1,
22537
22553
  buildStart: 1,
@@ -22547,19 +22563,14 @@ const inputHookNames = {
22547
22563
  watchChange: 1
22548
22564
  };
22549
22565
  const inputHooks = Object.keys(inputHookNames);
22550
- function throwInvalidHookError(hookName, pluginName) {
22551
- return error({
22552
- code: 'INVALID_PLUGIN_HOOK',
22553
- message: `Error running plugin hook ${hookName} for ${pluginName}, expected a function hook.`
22554
- });
22555
- }
22556
22566
  class PluginDriver {
22557
22567
  constructor(graph, options, userPlugins, pluginCache, basePluginDriver) {
22558
22568
  this.graph = graph;
22559
22569
  this.options = options;
22570
+ this.pluginCache = pluginCache;
22571
+ this.sortedPlugins = new Map();
22560
22572
  this.unfulfilledActions = new Set();
22561
22573
  warnDeprecatedHooks(userPlugins, options);
22562
- this.pluginCache = pluginCache;
22563
22574
  this.fileEmitter = new FileEmitter(graph, options, basePluginDriver && basePluginDriver.fileEmitter);
22564
22575
  this.emitFile = this.fileEmitter.emitFile.bind(this.fileEmitter);
22565
22576
  this.getFileName = this.fileEmitter.getFileName.bind(this.fileEmitter);
@@ -22589,21 +22600,21 @@ class PluginDriver {
22589
22600
  }
22590
22601
  // chains, first non-null result stops and returns
22591
22602
  hookFirst(hookName, args, replaceContext, skipped) {
22592
- let promise = Promise.resolve(undefined);
22593
- for (const plugin of this.plugins) {
22603
+ let promise = Promise.resolve(null);
22604
+ for (const plugin of this.getSortedPlugins(hookName)) {
22594
22605
  if (skipped && skipped.has(plugin))
22595
22606
  continue;
22596
22607
  promise = promise.then(result => {
22597
22608
  if (result != null)
22598
22609
  return result;
22599
- return this.runHook(hookName, args, plugin, false, replaceContext);
22610
+ return this.runHook(hookName, args, plugin, replaceContext);
22600
22611
  });
22601
22612
  }
22602
22613
  return promise;
22603
22614
  }
22604
22615
  // chains synchronously, first non-null result stops and returns
22605
22616
  hookFirstSync(hookName, args, replaceContext) {
22606
- for (const plugin of this.plugins) {
22617
+ for (const plugin of this.getSortedPlugins(hookName)) {
22607
22618
  const result = this.runHookSync(hookName, args, plugin, replaceContext);
22608
22619
  if (result != null)
22609
22620
  return result;
@@ -22611,56 +22622,58 @@ class PluginDriver {
22611
22622
  return null;
22612
22623
  }
22613
22624
  // parallel, ignores returns
22614
- hookParallel(hookName, args, replaceContext) {
22615
- const promises = [];
22616
- for (const plugin of this.plugins) {
22617
- const hookPromise = this.runHook(hookName, args, plugin, false, replaceContext);
22618
- if (!hookPromise)
22619
- continue;
22620
- promises.push(hookPromise);
22625
+ async hookParallel(hookName, args, replaceContext) {
22626
+ const parallelPromises = [];
22627
+ for (const plugin of this.getSortedPlugins(hookName)) {
22628
+ if (plugin[hookName].sequential) {
22629
+ await Promise.all(parallelPromises);
22630
+ parallelPromises.length = 0;
22631
+ await this.runHook(hookName, args, plugin, replaceContext);
22632
+ }
22633
+ else {
22634
+ parallelPromises.push(this.runHook(hookName, args, plugin, replaceContext));
22635
+ }
22621
22636
  }
22622
- return Promise.all(promises).then(() => { });
22637
+ await Promise.all(parallelPromises);
22623
22638
  }
22624
22639
  // chains, reduces returned value, handling the reduced value as the first hook argument
22625
22640
  hookReduceArg0(hookName, [arg0, ...rest], reduce, replaceContext) {
22626
22641
  let promise = Promise.resolve(arg0);
22627
- for (const plugin of this.plugins) {
22628
- promise = promise.then(arg0 => {
22629
- const args = [arg0, ...rest];
22630
- const hookPromise = this.runHook(hookName, args, plugin, false, replaceContext);
22631
- if (!hookPromise)
22632
- return arg0;
22633
- return hookPromise.then(result => reduce.call(this.pluginContexts.get(plugin), arg0, result, plugin));
22634
- });
22642
+ for (const plugin of this.getSortedPlugins(hookName)) {
22643
+ promise = promise.then(arg0 => this.runHook(hookName, [arg0, ...rest], plugin, replaceContext).then(result => reduce.call(this.pluginContexts.get(plugin), arg0, result, plugin)));
22635
22644
  }
22636
22645
  return promise;
22637
22646
  }
22638
22647
  // chains synchronously, reduces returned value, handling the reduced value as the first hook argument
22639
22648
  hookReduceArg0Sync(hookName, [arg0, ...rest], reduce, replaceContext) {
22640
- for (const plugin of this.plugins) {
22649
+ for (const plugin of this.getSortedPlugins(hookName)) {
22641
22650
  const args = [arg0, ...rest];
22642
22651
  const result = this.runHookSync(hookName, args, plugin, replaceContext);
22643
22652
  arg0 = reduce.call(this.pluginContexts.get(plugin), arg0, result, plugin);
22644
22653
  }
22645
22654
  return arg0;
22646
22655
  }
22647
- // chains, reduces returned value to type T, handling the reduced value separately. permits hooks as values.
22648
- hookReduceValue(hookName, initialValue, args, reduce, replaceContext) {
22649
- let promise = Promise.resolve(initialValue);
22650
- for (const plugin of this.plugins) {
22651
- promise = promise.then(value => {
22652
- const hookPromise = this.runHook(hookName, args, plugin, true, replaceContext);
22653
- if (!hookPromise)
22654
- return value;
22655
- return hookPromise.then(result => reduce.call(this.pluginContexts.get(plugin), value, result, plugin));
22656
- });
22656
+ // chains, reduces returned value to type string, handling the reduced value separately. permits hooks as values.
22657
+ async hookReduceValue(hookName, initialValue, args, reducer) {
22658
+ const results = [];
22659
+ const parallelResults = [];
22660
+ for (const plugin of this.getSortedPlugins(hookName, validateAddonPluginHandler)) {
22661
+ if (plugin[hookName].sequential) {
22662
+ results.push(...(await Promise.all(parallelResults)));
22663
+ parallelResults.length = 0;
22664
+ results.push(await this.runHook(hookName, args, plugin));
22665
+ }
22666
+ else {
22667
+ parallelResults.push(this.runHook(hookName, args, plugin));
22668
+ }
22657
22669
  }
22658
- return promise;
22670
+ results.push(...(await Promise.all(parallelResults)));
22671
+ return results.reduce(reducer, await initialValue);
22659
22672
  }
22660
22673
  // chains synchronously, reduces returned value to type T, handling the reduced value separately. permits hooks as values.
22661
22674
  hookReduceValueSync(hookName, initialValue, args, reduce, replaceContext) {
22662
22675
  let acc = initialValue;
22663
- for (const plugin of this.plugins) {
22676
+ for (const plugin of this.getSortedPlugins(hookName)) {
22664
22677
  const result = this.runHookSync(hookName, args, plugin, replaceContext);
22665
22678
  acc = reduce.call(this.pluginContexts.get(plugin), acc, result, plugin);
22666
22679
  }
@@ -22669,31 +22682,32 @@ class PluginDriver {
22669
22682
  // chains, ignores returns
22670
22683
  hookSeq(hookName, args, replaceContext) {
22671
22684
  let promise = Promise.resolve();
22672
- for (const plugin of this.plugins) {
22673
- promise = promise.then(() => this.runHook(hookName, args, plugin, false, replaceContext));
22685
+ for (const plugin of this.getSortedPlugins(hookName)) {
22686
+ promise = promise.then(() => this.runHook(hookName, args, plugin, replaceContext));
22674
22687
  }
22675
- return promise;
22688
+ return promise.then(noReturn);
22689
+ }
22690
+ getSortedPlugins(hookName, validateHandler) {
22691
+ return getOrCreate(this.sortedPlugins, hookName, () => getSortedValidatedPlugins(hookName, this.plugins, validateHandler));
22676
22692
  }
22677
- runHook(hookName, args, plugin, permitValues, hookContext) {
22693
+ // Implementation signature
22694
+ runHook(hookName, args, plugin, replaceContext) {
22695
+ // We always filter for plugins that support the hook before running it
22678
22696
  const hook = plugin[hookName];
22679
- if (!hook)
22680
- return undefined;
22697
+ const handler = typeof hook === 'object' ? hook.handler : hook;
22681
22698
  let context = this.pluginContexts.get(plugin);
22682
- if (hookContext) {
22683
- context = hookContext(context, plugin);
22699
+ if (replaceContext) {
22700
+ context = replaceContext(context, plugin);
22684
22701
  }
22685
22702
  let action = null;
22686
22703
  return Promise.resolve()
22687
22704
  .then(() => {
22688
- // permit values allows values to be returned instead of a functional hook
22689
- if (typeof hook !== 'function') {
22690
- if (permitValues)
22691
- return hook;
22692
- return throwInvalidHookError(hookName, plugin.name);
22705
+ if (typeof handler !== 'function') {
22706
+ return handler;
22693
22707
  }
22694
22708
  // eslint-disable-next-line @typescript-eslint/ban-types
22695
- const hookResult = hook.apply(context, args);
22696
- if (!hookResult || !hookResult.then) {
22709
+ const hookResult = handler.apply(context, args);
22710
+ if (!(hookResult === null || hookResult === void 0 ? void 0 : hookResult.then)) {
22697
22711
  // short circuit for non-thenables and non-Promises
22698
22712
  return hookResult;
22699
22713
  }
@@ -22726,29 +22740,61 @@ class PluginDriver {
22726
22740
  * @param hookName Name of the plugin hook. Must be in `PluginHooks`.
22727
22741
  * @param args Arguments passed to the plugin hook.
22728
22742
  * @param plugin The acutal plugin
22729
- * @param hookContext When passed, the plugin context can be overridden.
22743
+ * @param replaceContext When passed, the plugin context can be overridden.
22730
22744
  */
22731
- runHookSync(hookName, args, plugin, hookContext) {
22745
+ runHookSync(hookName, args, plugin, replaceContext) {
22732
22746
  const hook = plugin[hookName];
22733
- if (!hook)
22734
- return undefined;
22747
+ const handler = typeof hook === 'object' ? hook.handler : hook;
22735
22748
  let context = this.pluginContexts.get(plugin);
22736
- if (hookContext) {
22737
- context = hookContext(context, plugin);
22749
+ if (replaceContext) {
22750
+ context = replaceContext(context, plugin);
22738
22751
  }
22739
22752
  try {
22740
- // permit values allows values to be returned instead of a functional hook
22741
- if (typeof hook !== 'function') {
22742
- return throwInvalidHookError(hookName, plugin.name);
22743
- }
22744
22753
  // eslint-disable-next-line @typescript-eslint/ban-types
22745
- return hook.apply(context, args);
22754
+ return handler.apply(context, args);
22746
22755
  }
22747
22756
  catch (err) {
22748
22757
  return throwPluginError(err, plugin.name, { hook: hookName });
22749
22758
  }
22750
22759
  }
22751
22760
  }
22761
+ function getSortedValidatedPlugins(hookName, plugins, validateHandler = validateFunctionPluginHandler) {
22762
+ const pre = [];
22763
+ const normal = [];
22764
+ const post = [];
22765
+ for (const plugin of plugins) {
22766
+ const hook = plugin[hookName];
22767
+ if (hook) {
22768
+ if (typeof hook === 'object') {
22769
+ validateHandler(hook.handler, hookName, plugin);
22770
+ if (hook.order === 'pre') {
22771
+ pre.push(plugin);
22772
+ continue;
22773
+ }
22774
+ if (hook.order === 'post') {
22775
+ post.push(plugin);
22776
+ continue;
22777
+ }
22778
+ }
22779
+ else {
22780
+ validateHandler(hook, hookName, plugin);
22781
+ }
22782
+ normal.push(plugin);
22783
+ }
22784
+ }
22785
+ return [...pre, ...normal, ...post];
22786
+ }
22787
+ function validateFunctionPluginHandler(handler, hookName, plugin) {
22788
+ if (typeof handler !== 'function') {
22789
+ error(errInvalidFunctionPluginHook(hookName, plugin.name));
22790
+ }
22791
+ }
22792
+ function validateAddonPluginHandler(handler, hookName, plugin) {
22793
+ if (typeof handler !== 'string' && typeof handler !== 'function') {
22794
+ return error(errInvalidAddonPluginHook(hookName, plugin.name));
22795
+ }
22796
+ }
22797
+ function noReturn() { }
22752
22798
 
22753
22799
  class Queue {
22754
22800
  constructor(maxParallel) {
@@ -23682,17 +23728,15 @@ async function getInputOptions(rawInputOptions, watchMode) {
23682
23728
  if (!rawInputOptions) {
23683
23729
  throw new Error('You must supply an options object to rollup');
23684
23730
  }
23685
- const rawPlugins = ensureArray(rawInputOptions.plugins);
23731
+ const rawPlugins = getSortedValidatedPlugins('options', ensureArray(rawInputOptions.plugins));
23686
23732
  const { options, unsetOptions } = normalizeInputOptions(await rawPlugins.reduce(applyOptionHook(watchMode), Promise.resolve(rawInputOptions)));
23687
23733
  normalizePlugins(options.plugins, ANONYMOUS_PLUGIN_PREFIX);
23688
23734
  return { options, unsetOptions };
23689
23735
  }
23690
23736
  function applyOptionHook(watchMode) {
23691
23737
  return async (inputOptions, plugin) => {
23692
- if (plugin.options) {
23693
- return ((await plugin.options.call({ meta: { rollupVersion: version$1, watchMode } }, await inputOptions)) || inputOptions);
23694
- }
23695
- return inputOptions;
23738
+ const handler = 'handler' in plugin.options ? plugin.options.handler : plugin.options;
23739
+ return ((await handler.call({ meta: { rollupVersion: version$1, watchMode } }, await inputOptions)) || inputOptions);
23696
23740
  };
23697
23741
  }
23698
23742
  function normalizePlugins(plugins, anonymousPrefix) {
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v2.77.3
4
- Thu, 11 Aug 2022 05:48:58 GMT - commit 1165d46685ef3c70617b2f150ab245ff5de5e783
3
+ Rollup.js v2.78.0
4
+ Sun, 14 Aug 2022 04:30:34 GMT - commit 105b264847892c8f7966364d73f6900554178f58
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v2.77.3
4
- Thu, 11 Aug 2022 05:48:58 GMT - commit 1165d46685ef3c70617b2f150ab245ff5de5e783
3
+ Rollup.js v2.78.0
4
+ Sun, 14 Aug 2022 04:30:34 GMT - commit 105b264847892c8f7966364d73f6900554178f58
5
5
 
6
6
  https://github.com/rollup/rollup
7
7