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/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.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
 
@@ -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
 
@@ -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
 
@@ -27,7 +27,7 @@ function _interopNamespaceDefault(e) {
27
27
  return n;
28
28
  }
29
29
 
30
- var version$1 = "2.77.3";
30
+ var version$1 = "2.78.0";
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,
@@ -22602,7 +22618,7 @@ function getPluginContext(plugin, pluginCache, graph, options, fileEmitter, exis
22602
22618
  else {
22603
22619
  cacheInstance = getCacheForUncacheablePlugin(plugin.name);
22604
22620
  }
22605
- const context = {
22621
+ return {
22606
22622
  addWatchFile(id) {
22607
22623
  if (graph.phase >= BuildPhase.GENERATE) {
22608
22624
  return this.error(errInvalidRollupPhaseForAddWatchFile());
@@ -22660,9 +22676,9 @@ function getPluginContext(plugin, pluginCache, graph, options, fileEmitter, exis
22660
22676
  options.onwarn(warning);
22661
22677
  }
22662
22678
  };
22663
- return context;
22664
22679
  }
22665
22680
 
22681
+ // This will make sure no input hook is omitted
22666
22682
  const inputHookNames = {
22667
22683
  buildEnd: 1,
22668
22684
  buildStart: 1,
@@ -22678,19 +22694,14 @@ const inputHookNames = {
22678
22694
  watchChange: 1
22679
22695
  };
22680
22696
  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
22697
  class PluginDriver {
22688
22698
  constructor(graph, options, userPlugins, pluginCache, basePluginDriver) {
22689
22699
  this.graph = graph;
22690
22700
  this.options = options;
22701
+ this.pluginCache = pluginCache;
22702
+ this.sortedPlugins = new Map();
22691
22703
  this.unfulfilledActions = new Set();
22692
22704
  warnDeprecatedHooks(userPlugins, options);
22693
- this.pluginCache = pluginCache;
22694
22705
  this.fileEmitter = new FileEmitter(graph, options, basePluginDriver && basePluginDriver.fileEmitter);
22695
22706
  this.emitFile = this.fileEmitter.emitFile.bind(this.fileEmitter);
22696
22707
  this.getFileName = this.fileEmitter.getFileName.bind(this.fileEmitter);
@@ -22720,21 +22731,21 @@ class PluginDriver {
22720
22731
  }
22721
22732
  // chains, first non-null result stops and returns
22722
22733
  hookFirst(hookName, args, replaceContext, skipped) {
22723
- let promise = Promise.resolve(undefined);
22724
- for (const plugin of this.plugins) {
22734
+ let promise = Promise.resolve(null);
22735
+ for (const plugin of this.getSortedPlugins(hookName)) {
22725
22736
  if (skipped && skipped.has(plugin))
22726
22737
  continue;
22727
22738
  promise = promise.then(result => {
22728
22739
  if (result != null)
22729
22740
  return result;
22730
- return this.runHook(hookName, args, plugin, false, replaceContext);
22741
+ return this.runHook(hookName, args, plugin, replaceContext);
22731
22742
  });
22732
22743
  }
22733
22744
  return promise;
22734
22745
  }
22735
22746
  // chains synchronously, first non-null result stops and returns
22736
22747
  hookFirstSync(hookName, args, replaceContext) {
22737
- for (const plugin of this.plugins) {
22748
+ for (const plugin of this.getSortedPlugins(hookName)) {
22738
22749
  const result = this.runHookSync(hookName, args, plugin, replaceContext);
22739
22750
  if (result != null)
22740
22751
  return result;
@@ -22742,56 +22753,58 @@ class PluginDriver {
22742
22753
  return null;
22743
22754
  }
22744
22755
  // 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);
22756
+ async hookParallel(hookName, args, replaceContext) {
22757
+ const parallelPromises = [];
22758
+ for (const plugin of this.getSortedPlugins(hookName)) {
22759
+ if (plugin[hookName].sequential) {
22760
+ await Promise.all(parallelPromises);
22761
+ parallelPromises.length = 0;
22762
+ await this.runHook(hookName, args, plugin, replaceContext);
22763
+ }
22764
+ else {
22765
+ parallelPromises.push(this.runHook(hookName, args, plugin, replaceContext));
22766
+ }
22752
22767
  }
22753
- return Promise.all(promises).then(() => { });
22768
+ await Promise.all(parallelPromises);
22754
22769
  }
22755
22770
  // chains, reduces returned value, handling the reduced value as the first hook argument
22756
22771
  hookReduceArg0(hookName, [arg0, ...rest], reduce, replaceContext) {
22757
22772
  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
- });
22773
+ for (const plugin of this.getSortedPlugins(hookName)) {
22774
+ promise = promise.then(arg0 => this.runHook(hookName, [arg0, ...rest], plugin, replaceContext).then(result => reduce.call(this.pluginContexts.get(plugin), arg0, result, plugin)));
22766
22775
  }
22767
22776
  return promise;
22768
22777
  }
22769
22778
  // chains synchronously, reduces returned value, handling the reduced value as the first hook argument
22770
22779
  hookReduceArg0Sync(hookName, [arg0, ...rest], reduce, replaceContext) {
22771
- for (const plugin of this.plugins) {
22780
+ for (const plugin of this.getSortedPlugins(hookName)) {
22772
22781
  const args = [arg0, ...rest];
22773
22782
  const result = this.runHookSync(hookName, args, plugin, replaceContext);
22774
22783
  arg0 = reduce.call(this.pluginContexts.get(plugin), arg0, result, plugin);
22775
22784
  }
22776
22785
  return arg0;
22777
22786
  }
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
- });
22787
+ // chains, reduces returned value to type string, handling the reduced value separately. permits hooks as values.
22788
+ async hookReduceValue(hookName, initialValue, args, reducer) {
22789
+ const results = [];
22790
+ const parallelResults = [];
22791
+ for (const plugin of this.getSortedPlugins(hookName, validateAddonPluginHandler)) {
22792
+ if (plugin[hookName].sequential) {
22793
+ results.push(...(await Promise.all(parallelResults)));
22794
+ parallelResults.length = 0;
22795
+ results.push(await this.runHook(hookName, args, plugin));
22796
+ }
22797
+ else {
22798
+ parallelResults.push(this.runHook(hookName, args, plugin));
22799
+ }
22788
22800
  }
22789
- return promise;
22801
+ results.push(...(await Promise.all(parallelResults)));
22802
+ return results.reduce(reducer, await initialValue);
22790
22803
  }
22791
22804
  // chains synchronously, reduces returned value to type T, handling the reduced value separately. permits hooks as values.
22792
22805
  hookReduceValueSync(hookName, initialValue, args, reduce, replaceContext) {
22793
22806
  let acc = initialValue;
22794
- for (const plugin of this.plugins) {
22807
+ for (const plugin of this.getSortedPlugins(hookName)) {
22795
22808
  const result = this.runHookSync(hookName, args, plugin, replaceContext);
22796
22809
  acc = reduce.call(this.pluginContexts.get(plugin), acc, result, plugin);
22797
22810
  }
@@ -22800,31 +22813,32 @@ class PluginDriver {
22800
22813
  // chains, ignores returns
22801
22814
  hookSeq(hookName, args, replaceContext) {
22802
22815
  let promise = Promise.resolve();
22803
- for (const plugin of this.plugins) {
22804
- promise = promise.then(() => this.runHook(hookName, args, plugin, false, replaceContext));
22816
+ for (const plugin of this.getSortedPlugins(hookName)) {
22817
+ promise = promise.then(() => this.runHook(hookName, args, plugin, replaceContext));
22805
22818
  }
22806
- return promise;
22819
+ return promise.then(noReturn);
22820
+ }
22821
+ getSortedPlugins(hookName, validateHandler) {
22822
+ return getOrCreate(this.sortedPlugins, hookName, () => getSortedValidatedPlugins(hookName, this.plugins, validateHandler));
22807
22823
  }
22808
- runHook(hookName, args, plugin, permitValues, hookContext) {
22824
+ // Implementation signature
22825
+ runHook(hookName, args, plugin, replaceContext) {
22826
+ // We always filter for plugins that support the hook before running it
22809
22827
  const hook = plugin[hookName];
22810
- if (!hook)
22811
- return undefined;
22828
+ const handler = typeof hook === 'object' ? hook.handler : hook;
22812
22829
  let context = this.pluginContexts.get(plugin);
22813
- if (hookContext) {
22814
- context = hookContext(context, plugin);
22830
+ if (replaceContext) {
22831
+ context = replaceContext(context, plugin);
22815
22832
  }
22816
22833
  let action = null;
22817
22834
  return Promise.resolve()
22818
22835
  .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);
22836
+ if (typeof handler !== 'function') {
22837
+ return handler;
22824
22838
  }
22825
22839
  // eslint-disable-next-line @typescript-eslint/ban-types
22826
- const hookResult = hook.apply(context, args);
22827
- if (!hookResult || !hookResult.then) {
22840
+ const hookResult = handler.apply(context, args);
22841
+ if (!(hookResult === null || hookResult === void 0 ? void 0 : hookResult.then)) {
22828
22842
  // short circuit for non-thenables and non-Promises
22829
22843
  return hookResult;
22830
22844
  }
@@ -22857,29 +22871,61 @@ class PluginDriver {
22857
22871
  * @param hookName Name of the plugin hook. Must be in `PluginHooks`.
22858
22872
  * @param args Arguments passed to the plugin hook.
22859
22873
  * @param plugin The acutal plugin
22860
- * @param hookContext When passed, the plugin context can be overridden.
22874
+ * @param replaceContext When passed, the plugin context can be overridden.
22861
22875
  */
22862
- runHookSync(hookName, args, plugin, hookContext) {
22876
+ runHookSync(hookName, args, plugin, replaceContext) {
22863
22877
  const hook = plugin[hookName];
22864
- if (!hook)
22865
- return undefined;
22878
+ const handler = typeof hook === 'object' ? hook.handler : hook;
22866
22879
  let context = this.pluginContexts.get(plugin);
22867
- if (hookContext) {
22868
- context = hookContext(context, plugin);
22880
+ if (replaceContext) {
22881
+ context = replaceContext(context, plugin);
22869
22882
  }
22870
22883
  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
22884
  // eslint-disable-next-line @typescript-eslint/ban-types
22876
- return hook.apply(context, args);
22885
+ return handler.apply(context, args);
22877
22886
  }
22878
22887
  catch (err) {
22879
22888
  return throwPluginError(err, plugin.name, { hook: hookName });
22880
22889
  }
22881
22890
  }
22882
22891
  }
22892
+ function getSortedValidatedPlugins(hookName, plugins, validateHandler = validateFunctionPluginHandler) {
22893
+ const pre = [];
22894
+ const normal = [];
22895
+ const post = [];
22896
+ for (const plugin of plugins) {
22897
+ const hook = plugin[hookName];
22898
+ if (hook) {
22899
+ if (typeof hook === 'object') {
22900
+ validateHandler(hook.handler, hookName, plugin);
22901
+ if (hook.order === 'pre') {
22902
+ pre.push(plugin);
22903
+ continue;
22904
+ }
22905
+ if (hook.order === 'post') {
22906
+ post.push(plugin);
22907
+ continue;
22908
+ }
22909
+ }
22910
+ else {
22911
+ validateHandler(hook, hookName, plugin);
22912
+ }
22913
+ normal.push(plugin);
22914
+ }
22915
+ }
22916
+ return [...pre, ...normal, ...post];
22917
+ }
22918
+ function validateFunctionPluginHandler(handler, hookName, plugin) {
22919
+ if (typeof handler !== 'function') {
22920
+ error(errInvalidFunctionPluginHook(hookName, plugin.name));
22921
+ }
22922
+ }
22923
+ function validateAddonPluginHandler(handler, hookName, plugin) {
22924
+ if (typeof handler !== 'string' && typeof handler !== 'function') {
22925
+ return error(errInvalidAddonPluginHook(hookName, plugin.name));
22926
+ }
22927
+ }
22928
+ function noReturn() { }
22883
22929
 
22884
22930
  class Queue {
22885
22931
  constructor(maxParallel) {
@@ -23720,17 +23766,15 @@ async function getInputOptions(rawInputOptions, watchMode) {
23720
23766
  if (!rawInputOptions) {
23721
23767
  throw new Error('You must supply an options object to rollup');
23722
23768
  }
23723
- const rawPlugins = ensureArray$1(rawInputOptions.plugins);
23769
+ const rawPlugins = getSortedValidatedPlugins('options', ensureArray$1(rawInputOptions.plugins));
23724
23770
  const { options, unsetOptions } = normalizeInputOptions(await rawPlugins.reduce(applyOptionHook(watchMode), Promise.resolve(rawInputOptions)));
23725
23771
  normalizePlugins(options.plugins, ANONYMOUS_PLUGIN_PREFIX);
23726
23772
  return { options, unsetOptions };
23727
23773
  }
23728
23774
  function applyOptionHook(watchMode) {
23729
23775
  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;
23776
+ const handler = 'handler' in plugin.options ? plugin.options.handler : plugin.options;
23777
+ return ((await handler.call({ meta: { rollupVersion: version$1, watchMode } }, await inputOptions)) || inputOptions);
23734
23778
  };
23735
23779
  }
23736
23780
  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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rollup",
3
- "version": "2.77.3",
3
+ "version": "2.78.0",
4
4
  "description": "Next-generation ES module bundler",
5
5
  "main": "dist/rollup.js",
6
6
  "module": "dist/es/rollup.js",
@@ -23,8 +23,6 @@
23
23
  "perf:debug": "node --inspect-brk scripts/perf-debug.js",
24
24
  "perf:init": "node scripts/perf-init.js",
25
25
  "postpublish": "git push && git push --tags",
26
- "prepare": "husky install && npm run build",
27
- "prepublishOnly": "git pull --ff-only && npm ci && npm run lint:nofix && npm run security && npm run build:bootstrap && npm run test:all",
28
26
  "security": "npm audit",
29
27
  "test": "npm run build && npm run test:all",
30
28
  "test:cjs": "npm run build:cjs && npm run test:only",