rollup 2.77.2 → 2.78.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,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v2.77.2
4
- Wed, 27 Jul 2022 05:18:41 GMT - commit 22b2f68aa8638ffaac4de69011e10480f5d50546
3
+ Rollup.js v2.78.1
4
+ Fri, 19 Aug 2022 05:19:43 GMT - commit 398d0c4970b679795025f36e320f8aecb2859d24
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.2
4
- Wed, 27 Jul 2022 05:18:41 GMT - commit 22b2f68aa8638ffaac4de69011e10480f5d50546
3
+ Rollup.js v2.78.1
4
+ Fri, 19 Aug 2022 05:19:43 GMT - commit 398d0c4970b679795025f36e320f8aecb2859d24
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.2";
17
+ var version$1 = "2.78.1";
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,
@@ -2254,15 +2270,16 @@ const RESERVED_NAMES$1 = RESERVED_NAMES;
2254
2270
 
2255
2271
  const illegalCharacters = /[^$_a-zA-Z0-9]/g;
2256
2272
  const startsWithDigit = (str) => /\d/.test(str[0]);
2273
+ const needsEscape = (str) => startsWithDigit(str) || RESERVED_NAMES$1.has(str) || str === 'arguments';
2257
2274
  function isLegal(str) {
2258
- if (startsWithDigit(str) || RESERVED_NAMES$1.has(str)) {
2275
+ if (needsEscape(str)) {
2259
2276
  return false;
2260
2277
  }
2261
2278
  return !illegalCharacters.test(str);
2262
2279
  }
2263
2280
  function makeLegal(str) {
2264
2281
  str = str.replace(/-(\w)/g, (_, letter) => letter.toUpperCase()).replace(illegalCharacters, '_');
2265
- if (startsWithDigit(str) || RESERVED_NAMES$1.has(str))
2282
+ if (needsEscape(str))
2266
2283
  str = `_${str}`;
2267
2284
  return str || '_';
2268
2285
  }
@@ -14604,7 +14621,7 @@ class Chunk {
14604
14621
  });
14605
14622
  const currentPath = `${currentDir}/${fileName}`;
14606
14623
  const { preserveModulesRoot } = options;
14607
- if (preserveModulesRoot && currentPath.startsWith(preserveModulesRoot)) {
14624
+ if (preserveModulesRoot && resolve(currentPath).startsWith(preserveModulesRoot)) {
14608
14625
  path = currentPath.slice(preserveModulesRoot.length).replace(/^[\\/]/, '');
14609
14626
  }
14610
14627
  else {
@@ -22471,7 +22488,7 @@ function getPluginContext(plugin, pluginCache, graph, options, fileEmitter, exis
22471
22488
  else {
22472
22489
  cacheInstance = getCacheForUncacheablePlugin(plugin.name);
22473
22490
  }
22474
- const context = {
22491
+ return {
22475
22492
  addWatchFile(id) {
22476
22493
  if (graph.phase >= BuildPhase.GENERATE) {
22477
22494
  return this.error(errInvalidRollupPhaseForAddWatchFile());
@@ -22529,9 +22546,9 @@ function getPluginContext(plugin, pluginCache, graph, options, fileEmitter, exis
22529
22546
  options.onwarn(warning);
22530
22547
  }
22531
22548
  };
22532
- return context;
22533
22549
  }
22534
22550
 
22551
+ // This will make sure no input hook is omitted
22535
22552
  const inputHookNames = {
22536
22553
  buildEnd: 1,
22537
22554
  buildStart: 1,
@@ -22547,19 +22564,14 @@ const inputHookNames = {
22547
22564
  watchChange: 1
22548
22565
  };
22549
22566
  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
22567
  class PluginDriver {
22557
22568
  constructor(graph, options, userPlugins, pluginCache, basePluginDriver) {
22558
22569
  this.graph = graph;
22559
22570
  this.options = options;
22571
+ this.pluginCache = pluginCache;
22572
+ this.sortedPlugins = new Map();
22560
22573
  this.unfulfilledActions = new Set();
22561
22574
  warnDeprecatedHooks(userPlugins, options);
22562
- this.pluginCache = pluginCache;
22563
22575
  this.fileEmitter = new FileEmitter(graph, options, basePluginDriver && basePluginDriver.fileEmitter);
22564
22576
  this.emitFile = this.fileEmitter.emitFile.bind(this.fileEmitter);
22565
22577
  this.getFileName = this.fileEmitter.getFileName.bind(this.fileEmitter);
@@ -22589,21 +22601,21 @@ class PluginDriver {
22589
22601
  }
22590
22602
  // chains, first non-null result stops and returns
22591
22603
  hookFirst(hookName, args, replaceContext, skipped) {
22592
- let promise = Promise.resolve(undefined);
22593
- for (const plugin of this.plugins) {
22604
+ let promise = Promise.resolve(null);
22605
+ for (const plugin of this.getSortedPlugins(hookName)) {
22594
22606
  if (skipped && skipped.has(plugin))
22595
22607
  continue;
22596
22608
  promise = promise.then(result => {
22597
22609
  if (result != null)
22598
22610
  return result;
22599
- return this.runHook(hookName, args, plugin, false, replaceContext);
22611
+ return this.runHook(hookName, args, plugin, replaceContext);
22600
22612
  });
22601
22613
  }
22602
22614
  return promise;
22603
22615
  }
22604
22616
  // chains synchronously, first non-null result stops and returns
22605
22617
  hookFirstSync(hookName, args, replaceContext) {
22606
- for (const plugin of this.plugins) {
22618
+ for (const plugin of this.getSortedPlugins(hookName)) {
22607
22619
  const result = this.runHookSync(hookName, args, plugin, replaceContext);
22608
22620
  if (result != null)
22609
22621
  return result;
@@ -22611,56 +22623,58 @@ class PluginDriver {
22611
22623
  return null;
22612
22624
  }
22613
22625
  // 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);
22626
+ async hookParallel(hookName, args, replaceContext) {
22627
+ const parallelPromises = [];
22628
+ for (const plugin of this.getSortedPlugins(hookName)) {
22629
+ if (plugin[hookName].sequential) {
22630
+ await Promise.all(parallelPromises);
22631
+ parallelPromises.length = 0;
22632
+ await this.runHook(hookName, args, plugin, replaceContext);
22633
+ }
22634
+ else {
22635
+ parallelPromises.push(this.runHook(hookName, args, plugin, replaceContext));
22636
+ }
22621
22637
  }
22622
- return Promise.all(promises).then(() => { });
22638
+ await Promise.all(parallelPromises);
22623
22639
  }
22624
22640
  // chains, reduces returned value, handling the reduced value as the first hook argument
22625
22641
  hookReduceArg0(hookName, [arg0, ...rest], reduce, replaceContext) {
22626
22642
  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
- });
22643
+ for (const plugin of this.getSortedPlugins(hookName)) {
22644
+ promise = promise.then(arg0 => this.runHook(hookName, [arg0, ...rest], plugin, replaceContext).then(result => reduce.call(this.pluginContexts.get(plugin), arg0, result, plugin)));
22635
22645
  }
22636
22646
  return promise;
22637
22647
  }
22638
22648
  // chains synchronously, reduces returned value, handling the reduced value as the first hook argument
22639
22649
  hookReduceArg0Sync(hookName, [arg0, ...rest], reduce, replaceContext) {
22640
- for (const plugin of this.plugins) {
22650
+ for (const plugin of this.getSortedPlugins(hookName)) {
22641
22651
  const args = [arg0, ...rest];
22642
22652
  const result = this.runHookSync(hookName, args, plugin, replaceContext);
22643
22653
  arg0 = reduce.call(this.pluginContexts.get(plugin), arg0, result, plugin);
22644
22654
  }
22645
22655
  return arg0;
22646
22656
  }
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
- });
22657
+ // chains, reduces returned value to type string, handling the reduced value separately. permits hooks as values.
22658
+ async hookReduceValue(hookName, initialValue, args, reducer) {
22659
+ const results = [];
22660
+ const parallelResults = [];
22661
+ for (const plugin of this.getSortedPlugins(hookName, validateAddonPluginHandler)) {
22662
+ if (plugin[hookName].sequential) {
22663
+ results.push(...(await Promise.all(parallelResults)));
22664
+ parallelResults.length = 0;
22665
+ results.push(await this.runHook(hookName, args, plugin));
22666
+ }
22667
+ else {
22668
+ parallelResults.push(this.runHook(hookName, args, plugin));
22669
+ }
22657
22670
  }
22658
- return promise;
22671
+ results.push(...(await Promise.all(parallelResults)));
22672
+ return results.reduce(reducer, await initialValue);
22659
22673
  }
22660
22674
  // chains synchronously, reduces returned value to type T, handling the reduced value separately. permits hooks as values.
22661
22675
  hookReduceValueSync(hookName, initialValue, args, reduce, replaceContext) {
22662
22676
  let acc = initialValue;
22663
- for (const plugin of this.plugins) {
22677
+ for (const plugin of this.getSortedPlugins(hookName)) {
22664
22678
  const result = this.runHookSync(hookName, args, plugin, replaceContext);
22665
22679
  acc = reduce.call(this.pluginContexts.get(plugin), acc, result, plugin);
22666
22680
  }
@@ -22669,31 +22683,32 @@ class PluginDriver {
22669
22683
  // chains, ignores returns
22670
22684
  hookSeq(hookName, args, replaceContext) {
22671
22685
  let promise = Promise.resolve();
22672
- for (const plugin of this.plugins) {
22673
- promise = promise.then(() => this.runHook(hookName, args, plugin, false, replaceContext));
22686
+ for (const plugin of this.getSortedPlugins(hookName)) {
22687
+ promise = promise.then(() => this.runHook(hookName, args, plugin, replaceContext));
22674
22688
  }
22675
- return promise;
22689
+ return promise.then(noReturn);
22690
+ }
22691
+ getSortedPlugins(hookName, validateHandler) {
22692
+ return getOrCreate(this.sortedPlugins, hookName, () => getSortedValidatedPlugins(hookName, this.plugins, validateHandler));
22676
22693
  }
22677
- runHook(hookName, args, plugin, permitValues, hookContext) {
22694
+ // Implementation signature
22695
+ runHook(hookName, args, plugin, replaceContext) {
22696
+ // We always filter for plugins that support the hook before running it
22678
22697
  const hook = plugin[hookName];
22679
- if (!hook)
22680
- return undefined;
22698
+ const handler = typeof hook === 'object' ? hook.handler : hook;
22681
22699
  let context = this.pluginContexts.get(plugin);
22682
- if (hookContext) {
22683
- context = hookContext(context, plugin);
22700
+ if (replaceContext) {
22701
+ context = replaceContext(context, plugin);
22684
22702
  }
22685
22703
  let action = null;
22686
22704
  return Promise.resolve()
22687
22705
  .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);
22706
+ if (typeof handler !== 'function') {
22707
+ return handler;
22693
22708
  }
22694
22709
  // eslint-disable-next-line @typescript-eslint/ban-types
22695
- const hookResult = hook.apply(context, args);
22696
- if (!hookResult || !hookResult.then) {
22710
+ const hookResult = handler.apply(context, args);
22711
+ if (!(hookResult === null || hookResult === void 0 ? void 0 : hookResult.then)) {
22697
22712
  // short circuit for non-thenables and non-Promises
22698
22713
  return hookResult;
22699
22714
  }
@@ -22726,29 +22741,61 @@ class PluginDriver {
22726
22741
  * @param hookName Name of the plugin hook. Must be in `PluginHooks`.
22727
22742
  * @param args Arguments passed to the plugin hook.
22728
22743
  * @param plugin The acutal plugin
22729
- * @param hookContext When passed, the plugin context can be overridden.
22744
+ * @param replaceContext When passed, the plugin context can be overridden.
22730
22745
  */
22731
- runHookSync(hookName, args, plugin, hookContext) {
22746
+ runHookSync(hookName, args, plugin, replaceContext) {
22732
22747
  const hook = plugin[hookName];
22733
- if (!hook)
22734
- return undefined;
22748
+ const handler = typeof hook === 'object' ? hook.handler : hook;
22735
22749
  let context = this.pluginContexts.get(plugin);
22736
- if (hookContext) {
22737
- context = hookContext(context, plugin);
22750
+ if (replaceContext) {
22751
+ context = replaceContext(context, plugin);
22738
22752
  }
22739
22753
  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
22754
  // eslint-disable-next-line @typescript-eslint/ban-types
22745
- return hook.apply(context, args);
22755
+ return handler.apply(context, args);
22746
22756
  }
22747
22757
  catch (err) {
22748
22758
  return throwPluginError(err, plugin.name, { hook: hookName });
22749
22759
  }
22750
22760
  }
22751
22761
  }
22762
+ function getSortedValidatedPlugins(hookName, plugins, validateHandler = validateFunctionPluginHandler) {
22763
+ const pre = [];
22764
+ const normal = [];
22765
+ const post = [];
22766
+ for (const plugin of plugins) {
22767
+ const hook = plugin[hookName];
22768
+ if (hook) {
22769
+ if (typeof hook === 'object') {
22770
+ validateHandler(hook.handler, hookName, plugin);
22771
+ if (hook.order === 'pre') {
22772
+ pre.push(plugin);
22773
+ continue;
22774
+ }
22775
+ if (hook.order === 'post') {
22776
+ post.push(plugin);
22777
+ continue;
22778
+ }
22779
+ }
22780
+ else {
22781
+ validateHandler(hook, hookName, plugin);
22782
+ }
22783
+ normal.push(plugin);
22784
+ }
22785
+ }
22786
+ return [...pre, ...normal, ...post];
22787
+ }
22788
+ function validateFunctionPluginHandler(handler, hookName, plugin) {
22789
+ if (typeof handler !== 'function') {
22790
+ error(errInvalidFunctionPluginHook(hookName, plugin.name));
22791
+ }
22792
+ }
22793
+ function validateAddonPluginHandler(handler, hookName, plugin) {
22794
+ if (typeof handler !== 'string' && typeof handler !== 'function') {
22795
+ return error(errInvalidAddonPluginHook(hookName, plugin.name));
22796
+ }
22797
+ }
22798
+ function noReturn() { }
22752
22799
 
22753
22800
  class Queue {
22754
22801
  constructor(maxParallel) {
@@ -23682,17 +23729,15 @@ async function getInputOptions(rawInputOptions, watchMode) {
23682
23729
  if (!rawInputOptions) {
23683
23730
  throw new Error('You must supply an options object to rollup');
23684
23731
  }
23685
- const rawPlugins = ensureArray(rawInputOptions.plugins);
23732
+ const rawPlugins = getSortedValidatedPlugins('options', ensureArray(rawInputOptions.plugins));
23686
23733
  const { options, unsetOptions } = normalizeInputOptions(await rawPlugins.reduce(applyOptionHook(watchMode), Promise.resolve(rawInputOptions)));
23687
23734
  normalizePlugins(options.plugins, ANONYMOUS_PLUGIN_PREFIX);
23688
23735
  return { options, unsetOptions };
23689
23736
  }
23690
23737
  function applyOptionHook(watchMode) {
23691
23738
  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;
23739
+ const handler = 'handler' in plugin.options ? plugin.options.handler : plugin.options;
23740
+ return ((await handler.call({ meta: { rollupVersion: version$1, watchMode } }, await inputOptions)) || inputOptions);
23696
23741
  };
23697
23742
  }
23698
23743
  function normalizePlugins(plugins, anonymousPrefix) {
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v2.77.2
4
- Wed, 27 Jul 2022 05:18:41 GMT - commit 22b2f68aa8638ffaac4de69011e10480f5d50546
3
+ Rollup.js v2.78.1
4
+ Fri, 19 Aug 2022 05:19:43 GMT - commit 398d0c4970b679795025f36e320f8aecb2859d24
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.2
4
- Wed, 27 Jul 2022 05:18:41 GMT - commit 22b2f68aa8638ffaac4de69011e10480f5d50546
3
+ Rollup.js v2.78.1
4
+ Fri, 19 Aug 2022 05:19:43 GMT - commit 398d0c4970b679795025f36e320f8aecb2859d24
5
5
 
6
6
  https://github.com/rollup/rollup
7
7