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/rollup.d.ts CHANGED
@@ -244,7 +244,7 @@ export type ResolveIdHook = (
244
244
  source: string,
245
245
  importer: string | undefined,
246
246
  options: { custom?: CustomPluginOptions; isEntry: boolean }
247
- ) => Promise<ResolveIdResult> | ResolveIdResult;
247
+ ) => ResolveIdResult;
248
248
 
249
249
  export type ShouldTransformCachedModuleHook = (
250
250
  this: PluginContext,
@@ -257,7 +257,7 @@ export type ShouldTransformCachedModuleHook = (
257
257
  resolvedSources: ResolvedIdMap;
258
258
  syntheticNamedExports: boolean | string;
259
259
  }
260
- ) => Promise<boolean> | boolean;
260
+ ) => boolean;
261
261
 
262
262
  export type IsExternal = (
263
263
  source: string,
@@ -269,9 +269,9 @@ export type IsPureModule = (id: string) => boolean | null | void;
269
269
 
270
270
  export type HasModuleSideEffects = (id: string, external: boolean) => boolean;
271
271
 
272
- type LoadResult = SourceDescription | string | null | void;
272
+ export type LoadResult = SourceDescription | string | null | void;
273
273
 
274
- export type LoadHook = (this: PluginContext, id: string) => Promise<LoadResult> | LoadResult;
274
+ export type LoadHook = (this: PluginContext, id: string) => LoadResult;
275
275
 
276
276
  export interface TransformPluginContext extends PluginContext {
277
277
  getCombinedSourcemap: () => SourceMap;
@@ -283,27 +283,22 @@ export type TransformHook = (
283
283
  this: TransformPluginContext,
284
284
  code: string,
285
285
  id: string
286
- ) => Promise<TransformResult> | TransformResult;
286
+ ) => TransformResult;
287
287
 
288
- export type ModuleParsedHook = (this: PluginContext, info: ModuleInfo) => Promise<void> | void;
288
+ export type ModuleParsedHook = (this: PluginContext, info: ModuleInfo) => void;
289
289
 
290
290
  export type RenderChunkHook = (
291
291
  this: PluginContext,
292
292
  code: string,
293
293
  chunk: RenderedChunk,
294
294
  options: NormalizedOutputOptions
295
- ) =>
296
- | Promise<{ code: string; map?: SourceMapInput } | null>
297
- | { code: string; map?: SourceMapInput }
298
- | string
299
- | null
300
- | undefined;
295
+ ) => { code: string; map?: SourceMapInput } | string | null | undefined;
301
296
 
302
297
  export type ResolveDynamicImportHook = (
303
298
  this: PluginContext,
304
299
  specifier: string | AcornNode,
305
300
  importer: string
306
- ) => Promise<ResolveIdResult> | ResolveIdResult;
301
+ ) => ResolveIdResult;
307
302
 
308
303
  export type ResolveImportMetaHook = (
309
304
  this: PluginContext,
@@ -344,7 +339,7 @@ export type WatchChangeHook = (
344
339
  this: PluginContext,
345
340
  id: string,
346
341
  change: { event: ChangeEvent }
347
- ) => Promise<void> | void;
342
+ ) => void;
348
343
 
349
344
  /**
350
345
  * use this type for plugin annotation
@@ -371,32 +366,21 @@ export interface OutputBundleWithPlaceholders {
371
366
  [fileName: string]: OutputAsset | OutputChunk | FilePlaceholder;
372
367
  }
373
368
 
374
- export interface PluginHooks extends OutputPluginHooks {
375
- buildEnd: (this: PluginContext, err?: Error) => Promise<void> | void;
376
- buildStart: (this: PluginContext, options: NormalizedInputOptions) => Promise<void> | void;
377
- closeBundle: (this: PluginContext) => Promise<void> | void;
378
- closeWatcher: (this: PluginContext) => Promise<void> | void;
379
- load: LoadHook;
380
- moduleParsed: ModuleParsedHook;
381
- options: (
382
- this: MinimalPluginContext,
383
- options: InputOptions
384
- ) => Promise<InputOptions | null | void> | InputOptions | null | void;
385
- resolveDynamicImport: ResolveDynamicImportHook;
386
- resolveId: ResolveIdHook;
387
- shouldTransformCachedModule: ShouldTransformCachedModuleHook;
388
- transform: TransformHook;
389
- watchChange: WatchChangeHook;
390
- }
391
-
392
- interface OutputPluginHooks {
369
+ export interface FunctionPluginHooks {
393
370
  augmentChunkHash: (this: PluginContext, chunk: PreRenderedChunk) => string | void;
371
+ buildEnd: (this: PluginContext, err?: Error) => void;
372
+ buildStart: (this: PluginContext, options: NormalizedInputOptions) => void;
373
+ closeBundle: (this: PluginContext) => void;
374
+ closeWatcher: (this: PluginContext) => void;
394
375
  generateBundle: (
395
376
  this: PluginContext,
396
377
  options: NormalizedOutputOptions,
397
378
  bundle: OutputBundle,
398
379
  isWrite: boolean
399
- ) => void | Promise<void>;
380
+ ) => void;
381
+ load: LoadHook;
382
+ moduleParsed: ModuleParsedHook;
383
+ options: (this: MinimalPluginContext, options: InputOptions) => InputOptions | null | void;
400
384
  outputOptions: (this: PluginContext, options: OutputOptions) => OutputOptions | null | void;
401
385
  renderChunk: RenderChunkHook;
402
386
  renderDynamicImport: (
@@ -408,45 +392,52 @@ interface OutputPluginHooks {
408
392
  targetModuleId: string | null;
409
393
  }
410
394
  ) => { left: string; right: string } | null | void;
411
- renderError: (this: PluginContext, err?: Error) => Promise<void> | void;
395
+ renderError: (this: PluginContext, err?: Error) => void;
412
396
  renderStart: (
413
397
  this: PluginContext,
414
398
  outputOptions: NormalizedOutputOptions,
415
399
  inputOptions: NormalizedInputOptions
416
- ) => Promise<void> | void;
400
+ ) => void;
417
401
  /** @deprecated Use `resolveFileUrl` instead */
418
402
  resolveAssetUrl: ResolveAssetUrlHook;
403
+ resolveDynamicImport: ResolveDynamicImportHook;
419
404
  resolveFileUrl: ResolveFileUrlHook;
405
+ resolveId: ResolveIdHook;
420
406
  resolveImportMeta: ResolveImportMetaHook;
407
+ shouldTransformCachedModule: ShouldTransformCachedModuleHook;
408
+ transform: TransformHook;
409
+ watchChange: WatchChangeHook;
421
410
  writeBundle: (
422
411
  this: PluginContext,
423
412
  options: NormalizedOutputOptions,
424
413
  bundle: OutputBundle
425
- ) => void | Promise<void>;
414
+ ) => void;
426
415
  }
427
416
 
428
- export type AsyncPluginHooks =
429
- | 'options'
430
- | 'buildEnd'
431
- | 'buildStart'
417
+ export type OutputPluginHooks =
418
+ | 'augmentChunkHash'
432
419
  | 'generateBundle'
433
- | 'load'
434
- | 'moduleParsed'
420
+ | 'outputOptions'
435
421
  | 'renderChunk'
422
+ | 'renderDynamicImport'
436
423
  | 'renderError'
437
424
  | 'renderStart'
438
- | 'resolveDynamicImport'
439
- | 'resolveId'
440
- | 'shouldTransformCachedModule'
441
- | 'transform'
442
- | 'writeBundle'
443
- | 'closeBundle'
444
- | 'closeWatcher'
445
- | 'watchChange';
425
+ | 'resolveAssetUrl'
426
+ | 'resolveFileUrl'
427
+ | 'resolveImportMeta'
428
+ | 'writeBundle';
429
+
430
+ export type InputPluginHooks = Exclude<keyof FunctionPluginHooks, OutputPluginHooks>;
446
431
 
447
- export type PluginValueHooks = 'banner' | 'footer' | 'intro' | 'outro';
432
+ export type SyncPluginHooks =
433
+ | 'augmentChunkHash'
434
+ | 'outputOptions'
435
+ | 'renderDynamicImport'
436
+ | 'resolveAssetUrl'
437
+ | 'resolveFileUrl'
438
+ | 'resolveImportMeta';
448
439
 
449
- export type SyncPluginHooks = Exclude<keyof PluginHooks, AsyncPluginHooks>;
440
+ export type AsyncPluginHooks = Exclude<keyof FunctionPluginHooks, SyncPluginHooks>;
450
441
 
451
442
  export type FirstPluginHooks =
452
443
  | 'load'
@@ -466,37 +457,38 @@ export type SequentialPluginHooks =
466
457
  | 'renderChunk'
467
458
  | 'transform';
468
459
 
469
- export type ParallelPluginHooks =
470
- | 'banner'
471
- | 'buildEnd'
472
- | 'buildStart'
473
- | 'footer'
474
- | 'intro'
475
- | 'moduleParsed'
476
- | 'outro'
477
- | 'renderError'
478
- | 'renderStart'
479
- | 'writeBundle'
480
- | 'closeBundle'
481
- | 'closeWatcher'
482
- | 'watchChange';
460
+ export type ParallelPluginHooks = Exclude<
461
+ keyof FunctionPluginHooks | AddonHooks,
462
+ FirstPluginHooks | SequentialPluginHooks
463
+ >;
483
464
 
484
- interface OutputPluginValueHooks {
485
- banner: AddonHook;
486
- cacheKey: string;
487
- footer: AddonHook;
488
- intro: AddonHook;
489
- outro: AddonHook;
490
- }
465
+ export type AddonHooks = 'banner' | 'footer' | 'intro' | 'outro';
491
466
 
492
- export interface Plugin extends Partial<PluginHooks>, Partial<OutputPluginValueHooks> {
493
- // for inter-plugin communication
494
- api?: any;
467
+ type MakeAsync<Fn> = Fn extends (this: infer This, ...args: infer Args) => infer Return
468
+ ? (this: This, ...args: Args) => Return | Promise<Return>
469
+ : never;
470
+
471
+ // eslint-disable-next-line @typescript-eslint/ban-types
472
+ type ObjectHook<T, O = {}> = T | ({ handler: T; order?: 'pre' | 'post' | null } & O);
473
+
474
+ export type PluginHooks = {
475
+ [K in keyof FunctionPluginHooks]: ObjectHook<
476
+ K extends AsyncPluginHooks ? MakeAsync<FunctionPluginHooks[K]> : FunctionPluginHooks[K],
477
+ // eslint-disable-next-line @typescript-eslint/ban-types
478
+ K extends ParallelPluginHooks ? { sequential?: boolean } : {}
479
+ >;
480
+ };
481
+
482
+ export interface OutputPlugin
483
+ extends Partial<{ [K in OutputPluginHooks]: PluginHooks[K] }>,
484
+ Partial<{ [K in AddonHooks]: ObjectHook<AddonHook> }> {
485
+ cacheKey?: string;
495
486
  name: string;
496
487
  }
497
488
 
498
- export interface OutputPlugin extends Partial<OutputPluginHooks>, Partial<OutputPluginValueHooks> {
499
- name: string;
489
+ export interface Plugin extends OutputPlugin, Partial<PluginHooks> {
490
+ // for inter-plugin communication
491
+ api?: any;
500
492
  }
501
493
 
502
494
  type TreeshakingPreset = 'smallest' | 'safest' | 'recommended';
package/dist/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
 
@@ -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
 
@@ -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
 
@@ -27,7 +27,7 @@ function _interopNamespaceDefault(e) {
27
27
  return n;
28
28
  }
29
29
 
30
- var version$1 = "2.77.2";
30
+ var version$1 = "2.78.1";
31
31
 
32
32
  function ensureArray$1(items) {
33
33
  if (Array.isArray(items)) {
@@ -373,6 +373,22 @@ function errInvalidOption(option, urlHash, explanation, value) {
373
373
  url: `https://rollupjs.org/guide/en/#${urlHash}`
374
374
  };
375
375
  }
376
+ function errInvalidAddonPluginHook(hook, plugin) {
377
+ return {
378
+ code: Errors.INVALID_PLUGIN_HOOK,
379
+ hook,
380
+ message: `Error running plugin hook ${hook} for plugin ${plugin}, expected a string, a function hook or an object with a "handler" string or function.`,
381
+ plugin
382
+ };
383
+ }
384
+ function errInvalidFunctionPluginHook(hook, plugin) {
385
+ return {
386
+ code: Errors.INVALID_PLUGIN_HOOK,
387
+ hook,
388
+ message: `Error running plugin hook ${hook} for plugin ${plugin}, expected a function hook or an object with a "handler" function.`,
389
+ plugin
390
+ };
391
+ }
376
392
  function errInvalidRollupPhaseForAddWatchFile() {
377
393
  return {
378
394
  code: Errors.INVALID_ROLLUP_PHASE,
@@ -2410,15 +2426,16 @@ const RESERVED_NAMES$1 = RESERVED_NAMES;
2410
2426
 
2411
2427
  const illegalCharacters = /[^$_a-zA-Z0-9]/g;
2412
2428
  const startsWithDigit = (str) => /\d/.test(str[0]);
2429
+ const needsEscape = (str) => startsWithDigit(str) || RESERVED_NAMES$1.has(str) || str === 'arguments';
2413
2430
  function isLegal(str) {
2414
- if (startsWithDigit(str) || RESERVED_NAMES$1.has(str)) {
2431
+ if (needsEscape(str)) {
2415
2432
  return false;
2416
2433
  }
2417
2434
  return !illegalCharacters.test(str);
2418
2435
  }
2419
2436
  function makeLegal(str) {
2420
2437
  str = str.replace(/-(\w)/g, (_, letter) => letter.toUpperCase()).replace(illegalCharacters, '_');
2421
- if (startsWithDigit(str) || RESERVED_NAMES$1.has(str))
2438
+ if (needsEscape(str))
2422
2439
  str = `_${str}`;
2423
2440
  return str || '_';
2424
2441
  }
@@ -14735,7 +14752,7 @@ class Chunk {
14735
14752
  });
14736
14753
  const currentPath = `${currentDir}/${fileName}`;
14737
14754
  const { preserveModulesRoot } = options;
14738
- if (preserveModulesRoot && currentPath.startsWith(preserveModulesRoot)) {
14755
+ if (preserveModulesRoot && require$$0.resolve(currentPath).startsWith(preserveModulesRoot)) {
14739
14756
  path = currentPath.slice(preserveModulesRoot.length).replace(/^[\\/]/, '');
14740
14757
  }
14741
14758
  else {
@@ -22602,7 +22619,7 @@ function getPluginContext(plugin, pluginCache, graph, options, fileEmitter, exis
22602
22619
  else {
22603
22620
  cacheInstance = getCacheForUncacheablePlugin(plugin.name);
22604
22621
  }
22605
- const context = {
22622
+ return {
22606
22623
  addWatchFile(id) {
22607
22624
  if (graph.phase >= BuildPhase.GENERATE) {
22608
22625
  return this.error(errInvalidRollupPhaseForAddWatchFile());
@@ -22660,9 +22677,9 @@ function getPluginContext(plugin, pluginCache, graph, options, fileEmitter, exis
22660
22677
  options.onwarn(warning);
22661
22678
  }
22662
22679
  };
22663
- return context;
22664
22680
  }
22665
22681
 
22682
+ // This will make sure no input hook is omitted
22666
22683
  const inputHookNames = {
22667
22684
  buildEnd: 1,
22668
22685
  buildStart: 1,
@@ -22678,19 +22695,14 @@ const inputHookNames = {
22678
22695
  watchChange: 1
22679
22696
  };
22680
22697
  const inputHooks = Object.keys(inputHookNames);
22681
- function throwInvalidHookError(hookName, pluginName) {
22682
- return error({
22683
- code: 'INVALID_PLUGIN_HOOK',
22684
- message: `Error running plugin hook ${hookName} for ${pluginName}, expected a function hook.`
22685
- });
22686
- }
22687
22698
  class PluginDriver {
22688
22699
  constructor(graph, options, userPlugins, pluginCache, basePluginDriver) {
22689
22700
  this.graph = graph;
22690
22701
  this.options = options;
22702
+ this.pluginCache = pluginCache;
22703
+ this.sortedPlugins = new Map();
22691
22704
  this.unfulfilledActions = new Set();
22692
22705
  warnDeprecatedHooks(userPlugins, options);
22693
- this.pluginCache = pluginCache;
22694
22706
  this.fileEmitter = new FileEmitter(graph, options, basePluginDriver && basePluginDriver.fileEmitter);
22695
22707
  this.emitFile = this.fileEmitter.emitFile.bind(this.fileEmitter);
22696
22708
  this.getFileName = this.fileEmitter.getFileName.bind(this.fileEmitter);
@@ -22720,21 +22732,21 @@ class PluginDriver {
22720
22732
  }
22721
22733
  // chains, first non-null result stops and returns
22722
22734
  hookFirst(hookName, args, replaceContext, skipped) {
22723
- let promise = Promise.resolve(undefined);
22724
- for (const plugin of this.plugins) {
22735
+ let promise = Promise.resolve(null);
22736
+ for (const plugin of this.getSortedPlugins(hookName)) {
22725
22737
  if (skipped && skipped.has(plugin))
22726
22738
  continue;
22727
22739
  promise = promise.then(result => {
22728
22740
  if (result != null)
22729
22741
  return result;
22730
- return this.runHook(hookName, args, plugin, false, replaceContext);
22742
+ return this.runHook(hookName, args, plugin, replaceContext);
22731
22743
  });
22732
22744
  }
22733
22745
  return promise;
22734
22746
  }
22735
22747
  // chains synchronously, first non-null result stops and returns
22736
22748
  hookFirstSync(hookName, args, replaceContext) {
22737
- for (const plugin of this.plugins) {
22749
+ for (const plugin of this.getSortedPlugins(hookName)) {
22738
22750
  const result = this.runHookSync(hookName, args, plugin, replaceContext);
22739
22751
  if (result != null)
22740
22752
  return result;
@@ -22742,56 +22754,58 @@ class PluginDriver {
22742
22754
  return null;
22743
22755
  }
22744
22756
  // parallel, ignores returns
22745
- hookParallel(hookName, args, replaceContext) {
22746
- const promises = [];
22747
- for (const plugin of this.plugins) {
22748
- const hookPromise = this.runHook(hookName, args, plugin, false, replaceContext);
22749
- if (!hookPromise)
22750
- continue;
22751
- promises.push(hookPromise);
22757
+ async hookParallel(hookName, args, replaceContext) {
22758
+ const parallelPromises = [];
22759
+ for (const plugin of this.getSortedPlugins(hookName)) {
22760
+ if (plugin[hookName].sequential) {
22761
+ await Promise.all(parallelPromises);
22762
+ parallelPromises.length = 0;
22763
+ await this.runHook(hookName, args, plugin, replaceContext);
22764
+ }
22765
+ else {
22766
+ parallelPromises.push(this.runHook(hookName, args, plugin, replaceContext));
22767
+ }
22752
22768
  }
22753
- return Promise.all(promises).then(() => { });
22769
+ await Promise.all(parallelPromises);
22754
22770
  }
22755
22771
  // chains, reduces returned value, handling the reduced value as the first hook argument
22756
22772
  hookReduceArg0(hookName, [arg0, ...rest], reduce, replaceContext) {
22757
22773
  let promise = Promise.resolve(arg0);
22758
- for (const plugin of this.plugins) {
22759
- promise = promise.then(arg0 => {
22760
- const args = [arg0, ...rest];
22761
- const hookPromise = this.runHook(hookName, args, plugin, false, replaceContext);
22762
- if (!hookPromise)
22763
- return arg0;
22764
- return hookPromise.then(result => reduce.call(this.pluginContexts.get(plugin), arg0, result, plugin));
22765
- });
22774
+ for (const plugin of this.getSortedPlugins(hookName)) {
22775
+ promise = promise.then(arg0 => this.runHook(hookName, [arg0, ...rest], plugin, replaceContext).then(result => reduce.call(this.pluginContexts.get(plugin), arg0, result, plugin)));
22766
22776
  }
22767
22777
  return promise;
22768
22778
  }
22769
22779
  // chains synchronously, reduces returned value, handling the reduced value as the first hook argument
22770
22780
  hookReduceArg0Sync(hookName, [arg0, ...rest], reduce, replaceContext) {
22771
- for (const plugin of this.plugins) {
22781
+ for (const plugin of this.getSortedPlugins(hookName)) {
22772
22782
  const args = [arg0, ...rest];
22773
22783
  const result = this.runHookSync(hookName, args, plugin, replaceContext);
22774
22784
  arg0 = reduce.call(this.pluginContexts.get(plugin), arg0, result, plugin);
22775
22785
  }
22776
22786
  return arg0;
22777
22787
  }
22778
- // chains, reduces returned value to type T, handling the reduced value separately. permits hooks as values.
22779
- hookReduceValue(hookName, initialValue, args, reduce, replaceContext) {
22780
- let promise = Promise.resolve(initialValue);
22781
- for (const plugin of this.plugins) {
22782
- promise = promise.then(value => {
22783
- const hookPromise = this.runHook(hookName, args, plugin, true, replaceContext);
22784
- if (!hookPromise)
22785
- return value;
22786
- return hookPromise.then(result => reduce.call(this.pluginContexts.get(plugin), value, result, plugin));
22787
- });
22788
+ // chains, reduces returned value to type string, handling the reduced value separately. permits hooks as values.
22789
+ async hookReduceValue(hookName, initialValue, args, reducer) {
22790
+ const results = [];
22791
+ const parallelResults = [];
22792
+ for (const plugin of this.getSortedPlugins(hookName, validateAddonPluginHandler)) {
22793
+ if (plugin[hookName].sequential) {
22794
+ results.push(...(await Promise.all(parallelResults)));
22795
+ parallelResults.length = 0;
22796
+ results.push(await this.runHook(hookName, args, plugin));
22797
+ }
22798
+ else {
22799
+ parallelResults.push(this.runHook(hookName, args, plugin));
22800
+ }
22788
22801
  }
22789
- return promise;
22802
+ results.push(...(await Promise.all(parallelResults)));
22803
+ return results.reduce(reducer, await initialValue);
22790
22804
  }
22791
22805
  // chains synchronously, reduces returned value to type T, handling the reduced value separately. permits hooks as values.
22792
22806
  hookReduceValueSync(hookName, initialValue, args, reduce, replaceContext) {
22793
22807
  let acc = initialValue;
22794
- for (const plugin of this.plugins) {
22808
+ for (const plugin of this.getSortedPlugins(hookName)) {
22795
22809
  const result = this.runHookSync(hookName, args, plugin, replaceContext);
22796
22810
  acc = reduce.call(this.pluginContexts.get(plugin), acc, result, plugin);
22797
22811
  }
@@ -22800,31 +22814,32 @@ class PluginDriver {
22800
22814
  // chains, ignores returns
22801
22815
  hookSeq(hookName, args, replaceContext) {
22802
22816
  let promise = Promise.resolve();
22803
- for (const plugin of this.plugins) {
22804
- promise = promise.then(() => this.runHook(hookName, args, plugin, false, replaceContext));
22817
+ for (const plugin of this.getSortedPlugins(hookName)) {
22818
+ promise = promise.then(() => this.runHook(hookName, args, plugin, replaceContext));
22805
22819
  }
22806
- return promise;
22820
+ return promise.then(noReturn);
22821
+ }
22822
+ getSortedPlugins(hookName, validateHandler) {
22823
+ return getOrCreate(this.sortedPlugins, hookName, () => getSortedValidatedPlugins(hookName, this.plugins, validateHandler));
22807
22824
  }
22808
- runHook(hookName, args, plugin, permitValues, hookContext) {
22825
+ // Implementation signature
22826
+ runHook(hookName, args, plugin, replaceContext) {
22827
+ // We always filter for plugins that support the hook before running it
22809
22828
  const hook = plugin[hookName];
22810
- if (!hook)
22811
- return undefined;
22829
+ const handler = typeof hook === 'object' ? hook.handler : hook;
22812
22830
  let context = this.pluginContexts.get(plugin);
22813
- if (hookContext) {
22814
- context = hookContext(context, plugin);
22831
+ if (replaceContext) {
22832
+ context = replaceContext(context, plugin);
22815
22833
  }
22816
22834
  let action = null;
22817
22835
  return Promise.resolve()
22818
22836
  .then(() => {
22819
- // permit values allows values to be returned instead of a functional hook
22820
- if (typeof hook !== 'function') {
22821
- if (permitValues)
22822
- return hook;
22823
- return throwInvalidHookError(hookName, plugin.name);
22837
+ if (typeof handler !== 'function') {
22838
+ return handler;
22824
22839
  }
22825
22840
  // eslint-disable-next-line @typescript-eslint/ban-types
22826
- const hookResult = hook.apply(context, args);
22827
- if (!hookResult || !hookResult.then) {
22841
+ const hookResult = handler.apply(context, args);
22842
+ if (!(hookResult === null || hookResult === void 0 ? void 0 : hookResult.then)) {
22828
22843
  // short circuit for non-thenables and non-Promises
22829
22844
  return hookResult;
22830
22845
  }
@@ -22857,29 +22872,61 @@ class PluginDriver {
22857
22872
  * @param hookName Name of the plugin hook. Must be in `PluginHooks`.
22858
22873
  * @param args Arguments passed to the plugin hook.
22859
22874
  * @param plugin The acutal plugin
22860
- * @param hookContext When passed, the plugin context can be overridden.
22875
+ * @param replaceContext When passed, the plugin context can be overridden.
22861
22876
  */
22862
- runHookSync(hookName, args, plugin, hookContext) {
22877
+ runHookSync(hookName, args, plugin, replaceContext) {
22863
22878
  const hook = plugin[hookName];
22864
- if (!hook)
22865
- return undefined;
22879
+ const handler = typeof hook === 'object' ? hook.handler : hook;
22866
22880
  let context = this.pluginContexts.get(plugin);
22867
- if (hookContext) {
22868
- context = hookContext(context, plugin);
22881
+ if (replaceContext) {
22882
+ context = replaceContext(context, plugin);
22869
22883
  }
22870
22884
  try {
22871
- // permit values allows values to be returned instead of a functional hook
22872
- if (typeof hook !== 'function') {
22873
- return throwInvalidHookError(hookName, plugin.name);
22874
- }
22875
22885
  // eslint-disable-next-line @typescript-eslint/ban-types
22876
- return hook.apply(context, args);
22886
+ return handler.apply(context, args);
22877
22887
  }
22878
22888
  catch (err) {
22879
22889
  return throwPluginError(err, plugin.name, { hook: hookName });
22880
22890
  }
22881
22891
  }
22882
22892
  }
22893
+ function getSortedValidatedPlugins(hookName, plugins, validateHandler = validateFunctionPluginHandler) {
22894
+ const pre = [];
22895
+ const normal = [];
22896
+ const post = [];
22897
+ for (const plugin of plugins) {
22898
+ const hook = plugin[hookName];
22899
+ if (hook) {
22900
+ if (typeof hook === 'object') {
22901
+ validateHandler(hook.handler, hookName, plugin);
22902
+ if (hook.order === 'pre') {
22903
+ pre.push(plugin);
22904
+ continue;
22905
+ }
22906
+ if (hook.order === 'post') {
22907
+ post.push(plugin);
22908
+ continue;
22909
+ }
22910
+ }
22911
+ else {
22912
+ validateHandler(hook, hookName, plugin);
22913
+ }
22914
+ normal.push(plugin);
22915
+ }
22916
+ }
22917
+ return [...pre, ...normal, ...post];
22918
+ }
22919
+ function validateFunctionPluginHandler(handler, hookName, plugin) {
22920
+ if (typeof handler !== 'function') {
22921
+ error(errInvalidFunctionPluginHook(hookName, plugin.name));
22922
+ }
22923
+ }
22924
+ function validateAddonPluginHandler(handler, hookName, plugin) {
22925
+ if (typeof handler !== 'string' && typeof handler !== 'function') {
22926
+ return error(errInvalidAddonPluginHook(hookName, plugin.name));
22927
+ }
22928
+ }
22929
+ function noReturn() { }
22883
22930
 
22884
22931
  class Queue {
22885
22932
  constructor(maxParallel) {
@@ -23720,17 +23767,15 @@ async function getInputOptions(rawInputOptions, watchMode) {
23720
23767
  if (!rawInputOptions) {
23721
23768
  throw new Error('You must supply an options object to rollup');
23722
23769
  }
23723
- const rawPlugins = ensureArray$1(rawInputOptions.plugins);
23770
+ const rawPlugins = getSortedValidatedPlugins('options', ensureArray$1(rawInputOptions.plugins));
23724
23771
  const { options, unsetOptions } = normalizeInputOptions(await rawPlugins.reduce(applyOptionHook(watchMode), Promise.resolve(rawInputOptions)));
23725
23772
  normalizePlugins(options.plugins, ANONYMOUS_PLUGIN_PREFIX);
23726
23773
  return { options, unsetOptions };
23727
23774
  }
23728
23775
  function applyOptionHook(watchMode) {
23729
23776
  return async (inputOptions, plugin) => {
23730
- if (plugin.options) {
23731
- return ((await plugin.options.call({ meta: { rollupVersion: version$1, watchMode } }, await inputOptions)) || inputOptions);
23732
- }
23733
- return inputOptions;
23777
+ const handler = 'handler' in plugin.options ? plugin.options.handler : plugin.options;
23778
+ return ((await handler.call({ meta: { rollupVersion: version$1, watchMode } }, await inputOptions)) || inputOptions);
23734
23779
  };
23735
23780
  }
23736
23781
  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