@rollup/browser 3.0.0-3 → 3.0.0-6

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.
@@ -28,6 +28,7 @@ export interface RollupLog {
28
28
  pluginCode?: string;
29
29
  pos?: number;
30
30
  reexporter?: string;
31
+ stack?: string;
31
32
  url?: string;
32
33
  }
33
34
 
@@ -220,7 +221,7 @@ export type ResolveIdHook = (
220
221
  source: string,
221
222
  importer: string | undefined,
222
223
  options: { custom?: CustomPluginOptions; isEntry: boolean }
223
- ) => Promise<ResolveIdResult> | ResolveIdResult;
224
+ ) => ResolveIdResult;
224
225
 
225
226
  export type ShouldTransformCachedModuleHook = (
226
227
  this: PluginContext,
@@ -233,7 +234,7 @@ export type ShouldTransformCachedModuleHook = (
233
234
  resolvedSources: ResolvedIdMap;
234
235
  syntheticNamedExports: boolean | string;
235
236
  }
236
- ) => Promise<boolean> | boolean;
237
+ ) => boolean;
237
238
 
238
239
  export type IsExternal = (
239
240
  source: string,
@@ -245,9 +246,9 @@ export type IsPureModule = (id: string) => boolean | null | void;
245
246
 
246
247
  export type HasModuleSideEffects = (id: string, external: boolean) => boolean;
247
248
 
248
- type LoadResult = SourceDescription | string | null | void;
249
+ export type LoadResult = SourceDescription | string | null | void;
249
250
 
250
- export type LoadHook = (this: PluginContext, id: string) => Promise<LoadResult> | LoadResult;
251
+ export type LoadHook = (this: PluginContext, id: string) => LoadResult;
251
252
 
252
253
  export interface TransformPluginContext extends PluginContext {
253
254
  getCombinedSourcemap: () => SourceMap;
@@ -259,9 +260,9 @@ export type TransformHook = (
259
260
  this: TransformPluginContext,
260
261
  code: string,
261
262
  id: string
262
- ) => Promise<TransformResult> | TransformResult;
263
+ ) => TransformResult;
263
264
 
264
- export type ModuleParsedHook = (this: PluginContext, info: ModuleInfo) => Promise<void> | void;
265
+ export type ModuleParsedHook = (this: PluginContext, info: ModuleInfo) => void;
265
266
 
266
267
  export type RenderChunkHook = (
267
268
  this: PluginContext,
@@ -269,18 +270,13 @@ export type RenderChunkHook = (
269
270
  chunk: RenderedChunk,
270
271
  options: NormalizedOutputOptions,
271
272
  meta: { chunks: Record<string, RenderedChunk> }
272
- ) =>
273
- | Promise<{ code: string; map?: SourceMapInput } | null>
274
- | { code: string; map?: SourceMapInput }
275
- | string
276
- | null
277
- | undefined;
273
+ ) => { code: string; map?: SourceMapInput } | string | null | undefined;
278
274
 
279
275
  export type ResolveDynamicImportHook = (
280
276
  this: PluginContext,
281
277
  specifier: string | AcornNode,
282
278
  importer: string
283
- ) => Promise<ResolveIdResult> | ResolveIdResult;
279
+ ) => ResolveIdResult;
284
280
 
285
281
  export type ResolveImportMetaHook = (
286
282
  this: PluginContext,
@@ -311,7 +307,7 @@ export type WatchChangeHook = (
311
307
  this: PluginContext,
312
308
  id: string,
313
309
  change: { event: ChangeEvent }
314
- ) => Promise<void> | void;
310
+ ) => void;
315
311
 
316
312
  /**
317
313
  * use this type for plugin annotation
@@ -338,32 +334,21 @@ export interface OutputBundleWithPlaceholders {
338
334
  [fileName: string]: OutputAsset | OutputChunk | FilePlaceholder;
339
335
  }
340
336
 
341
- export interface PluginHooks extends OutputPluginHooks {
342
- buildEnd: (this: PluginContext, err?: Error) => Promise<void> | void;
343
- buildStart: (this: PluginContext, options: NormalizedInputOptions) => Promise<void> | void;
344
- closeBundle: (this: PluginContext) => Promise<void> | void;
345
- closeWatcher: (this: PluginContext) => Promise<void> | void;
346
- load: LoadHook;
347
- moduleParsed: ModuleParsedHook;
348
- options: (
349
- this: MinimalPluginContext,
350
- options: InputOptions
351
- ) => Promise<InputOptions | null | void> | InputOptions | null | void;
352
- resolveDynamicImport: ResolveDynamicImportHook;
353
- resolveId: ResolveIdHook;
354
- shouldTransformCachedModule: ShouldTransformCachedModuleHook;
355
- transform: TransformHook;
356
- watchChange: WatchChangeHook;
357
- }
358
-
359
- interface OutputPluginHooks {
337
+ export interface FunctionPluginHooks {
360
338
  augmentChunkHash: (this: PluginContext, chunk: RenderedChunk) => string | void;
339
+ buildEnd: (this: PluginContext, err?: Error) => void;
340
+ buildStart: (this: PluginContext, options: NormalizedInputOptions) => void;
341
+ closeBundle: (this: PluginContext) => void;
342
+ closeWatcher: (this: PluginContext) => void;
361
343
  generateBundle: (
362
344
  this: PluginContext,
363
345
  options: NormalizedOutputOptions,
364
346
  bundle: OutputBundle,
365
347
  isWrite: boolean
366
- ) => void | Promise<void>;
348
+ ) => void;
349
+ load: LoadHook;
350
+ moduleParsed: ModuleParsedHook;
351
+ options: (this: MinimalPluginContext, options: InputOptions) => InputOptions | null | void;
367
352
  outputOptions: (this: PluginContext, options: OutputOptions) => OutputOptions | null | void;
368
353
  renderChunk: RenderChunkHook;
369
354
  renderDynamicImport: (
@@ -375,43 +360,48 @@ interface OutputPluginHooks {
375
360
  targetModuleId: string | null;
376
361
  }
377
362
  ) => { left: string; right: string } | null | void;
378
- renderError: (this: PluginContext, err?: Error) => Promise<void> | void;
363
+ renderError: (this: PluginContext, err?: Error) => void;
379
364
  renderStart: (
380
365
  this: PluginContext,
381
366
  outputOptions: NormalizedOutputOptions,
382
367
  inputOptions: NormalizedInputOptions
383
- ) => Promise<void> | void;
368
+ ) => void;
369
+ resolveDynamicImport: ResolveDynamicImportHook;
384
370
  resolveFileUrl: ResolveFileUrlHook;
371
+ resolveId: ResolveIdHook;
385
372
  resolveImportMeta: ResolveImportMetaHook;
373
+ shouldTransformCachedModule: ShouldTransformCachedModuleHook;
374
+ transform: TransformHook;
375
+ watchChange: WatchChangeHook;
386
376
  writeBundle: (
387
377
  this: PluginContext,
388
378
  options: NormalizedOutputOptions,
389
379
  bundle: OutputBundle
390
- ) => void | Promise<void>;
380
+ ) => void;
391
381
  }
392
382
 
393
- export type AsyncPluginHooks =
394
- | 'options'
395
- | 'buildEnd'
396
- | 'buildStart'
383
+ export type OutputPluginHooks =
384
+ | 'augmentChunkHash'
397
385
  | 'generateBundle'
398
- | 'load'
399
- | 'moduleParsed'
386
+ | 'outputOptions'
400
387
  | 'renderChunk'
388
+ | 'renderDynamicImport'
401
389
  | 'renderError'
402
390
  | 'renderStart'
403
- | 'resolveDynamicImport'
404
- | 'resolveId'
405
- | 'shouldTransformCachedModule'
406
- | 'transform'
407
- | 'writeBundle'
408
- | 'closeBundle'
409
- | 'closeWatcher'
410
- | 'watchChange';
391
+ | 'resolveFileUrl'
392
+ | 'resolveImportMeta'
393
+ | 'writeBundle';
411
394
 
412
- export type PluginValueHooks = 'banner' | 'footer' | 'intro' | 'outro';
395
+ export type InputPluginHooks = Exclude<keyof FunctionPluginHooks, OutputPluginHooks>;
413
396
 
414
- export type SyncPluginHooks = Exclude<keyof PluginHooks, AsyncPluginHooks>;
397
+ export type SyncPluginHooks =
398
+ | 'augmentChunkHash'
399
+ | 'outputOptions'
400
+ | 'renderDynamicImport'
401
+ | 'resolveFileUrl'
402
+ | 'resolveImportMeta';
403
+
404
+ export type AsyncPluginHooks = Exclude<keyof FunctionPluginHooks, SyncPluginHooks>;
415
405
 
416
406
  export type FirstPluginHooks =
417
407
  | 'load'
@@ -430,37 +420,38 @@ export type SequentialPluginHooks =
430
420
  | 'renderChunk'
431
421
  | 'transform';
432
422
 
433
- export type ParallelPluginHooks =
434
- | 'banner'
435
- | 'buildEnd'
436
- | 'buildStart'
437
- | 'footer'
438
- | 'intro'
439
- | 'moduleParsed'
440
- | 'outro'
441
- | 'renderError'
442
- | 'renderStart'
443
- | 'writeBundle'
444
- | 'closeBundle'
445
- | 'closeWatcher'
446
- | 'watchChange';
423
+ export type ParallelPluginHooks = Exclude<
424
+ keyof FunctionPluginHooks | AddonHooks,
425
+ FirstPluginHooks | SequentialPluginHooks
426
+ >;
447
427
 
448
- interface OutputPluginValueHooks {
449
- banner: AddonHook;
450
- cacheKey: string;
451
- footer: AddonHook;
452
- intro: AddonHook;
453
- outro: AddonHook;
454
- }
428
+ export type AddonHooks = 'banner' | 'footer' | 'intro' | 'outro';
455
429
 
456
- export interface Plugin extends Partial<PluginHooks>, Partial<OutputPluginValueHooks> {
457
- // for inter-plugin communication
458
- api?: any;
430
+ type MakeAsync<Fn> = Fn extends (this: infer This, ...args: infer Args) => infer Return
431
+ ? (this: This, ...args: Args) => Return | Promise<Return>
432
+ : never;
433
+
434
+ // eslint-disable-next-line @typescript-eslint/ban-types
435
+ type ObjectHook<T, O = {}> = T | ({ handler: T; order?: 'pre' | 'post' | null } & O);
436
+
437
+ export type PluginHooks = {
438
+ [K in keyof FunctionPluginHooks]: ObjectHook<
439
+ K extends AsyncPluginHooks ? MakeAsync<FunctionPluginHooks[K]> : FunctionPluginHooks[K],
440
+ // eslint-disable-next-line @typescript-eslint/ban-types
441
+ K extends ParallelPluginHooks ? { sequential?: boolean } : {}
442
+ >;
443
+ };
444
+
445
+ export interface OutputPlugin
446
+ extends Partial<{ [K in OutputPluginHooks]: PluginHooks[K] }>,
447
+ Partial<{ [K in AddonHooks]: ObjectHook<AddonHook> }> {
448
+ cacheKey?: string;
459
449
  name: string;
460
450
  }
461
451
 
462
- export interface OutputPlugin extends Partial<OutputPluginHooks>, Partial<OutputPluginValueHooks> {
463
- name: string;
452
+ export interface Plugin extends OutputPlugin, Partial<PluginHooks> {
453
+ // for inter-plugin communication
454
+ api?: any;
464
455
  }
465
456
 
466
457
  type TreeshakingPreset = 'smallest' | 'safest' | 'recommended';
@@ -581,7 +572,7 @@ interface GeneratedCodeOptions extends Partial<NormalizedGeneratedCodeOptions> {
581
572
 
582
573
  export type OptionsPaths = Record<string, string> | ((id: string) => string);
583
574
 
584
- export type InteropType = boolean | 'auto' | 'esModule' | 'default' | 'defaultOnly';
575
+ export type InteropType = 'compat' | 'auto' | 'esModule' | 'default' | 'defaultOnly';
585
576
 
586
577
  export type GetInterop = (id: string | null) => InteropType;
587
578
 
@@ -601,6 +592,7 @@ export type AmdOptions = (
601
592
  }
602
593
  ) & {
603
594
  define?: string;
595
+ forceJsExtensionForImports?: boolean;
604
596
  };
605
597
 
606
598
  export type NormalizedAmdOptions = (
@@ -614,6 +606,7 @@ export type NormalizedAmdOptions = (
614
606
  }
615
607
  ) & {
616
608
  define: string;
609
+ forceJsExtensionForImports: boolean;
617
610
  };
618
611
 
619
612
  type AddonFunction = (chunk: RenderedChunk) => string | Promise<string>;
@@ -629,7 +622,7 @@ export interface OutputOptions {
629
622
  /** @deprecated Use the "renderDynamicImport" plugin hook instead. */
630
623
  dynamicImportFunction?: string;
631
624
  entryFileNames?: string | ((chunkInfo: PreRenderedChunk) => string);
632
- esModule?: boolean;
625
+ esModule?: boolean | 'if-default-prop';
633
626
  exports?: 'default' | 'named' | 'none' | 'auto';
634
627
  extend?: boolean;
635
628
  externalLiveBindings?: boolean;
@@ -679,7 +672,7 @@ export interface NormalizedOutputOptions {
679
672
  /** @deprecated Use the "renderDynamicImport" plugin hook instead. */
680
673
  dynamicImportFunction: string | undefined;
681
674
  entryFileNames: string | ((chunkInfo: PreRenderedChunk) => string);
682
- esModule: boolean;
675
+ esModule: boolean | 'if-default-prop';
683
676
  exports: 'default' | 'named' | 'none' | 'auto';
684
677
  extend: boolean;
685
678
  externalLiveBindings: boolean;
@@ -849,40 +842,37 @@ export interface RollupWatchOptions extends InputOptions {
849
842
  watch?: WatcherOptions | false;
850
843
  }
851
844
 
852
- interface TypedEventEmitter<T extends { [event: string]: (...args: any) => any }> {
853
- addListener<K extends keyof T>(event: K, listener: T[K]): this;
854
- emit<K extends keyof T>(event: K, ...args: Parameters<T[K]>): boolean;
855
- eventNames(): Array<keyof T>;
856
- getMaxListeners(): number;
857
- listenerCount(type: keyof T): number;
858
- listeners<K extends keyof T>(event: K): Array<T[K]>;
859
- off<K extends keyof T>(event: K, listener: T[K]): this;
860
- on<K extends keyof T>(event: K, listener: T[K]): this;
861
- once<K extends keyof T>(event: K, listener: T[K]): this;
862
- prependListener<K extends keyof T>(event: K, listener: T[K]): this;
863
- prependOnceListener<K extends keyof T>(event: K, listener: T[K]): this;
864
- rawListeners<K extends keyof T>(event: K): Array<T[K]>;
865
- removeAllListeners<K extends keyof T>(event?: K): this;
866
- removeListener<K extends keyof T>(event: K, listener: T[K]): this;
867
- setMaxListeners(n: number): this;
868
- }
869
-
870
- export interface RollupAwaitingEmitter<T extends { [event: string]: (...args: any) => any }>
871
- extends TypedEventEmitter<T> {
845
+ export type AwaitedEventListener<
846
+ T extends { [event: string]: (...args: any) => any },
847
+ K extends keyof T
848
+ > = (...args: Parameters<T[K]>) => void | Promise<void>;
849
+
850
+ export interface AwaitingEventEmitter<T extends { [event: string]: (...args: any) => any }> {
872
851
  close(): Promise<void>;
873
- emitAndAwait<K extends keyof T>(event: K, ...args: Parameters<T[K]>): Promise<ReturnType<T[K]>[]>;
852
+ emit<K extends keyof T>(event: K, ...args: Parameters<T[K]>): Promise<unknown>;
853
+ /**
854
+ * Removes an event listener.
855
+ */
856
+ off<K extends keyof T>(event: K, listener: AwaitedEventListener<T, K>): this;
857
+ /**
858
+ * Registers an event listener that will be awaited before Rollup continues.
859
+ * All listeners will be awaited in parallel while rejections are tracked via
860
+ * Promise.all.
861
+ */
862
+ on<K extends keyof T>(event: K, listener: AwaitedEventListener<T, K>): this;
874
863
  /**
875
- * Registers an event listener that will be awaited before Rollup continues
876
- * for events emitted via emitAndAwait. All listeners will be awaited in
877
- * parallel while rejections are tracked via Promise.all.
878
- * Listeners are removed automatically when removeAwaited is called, which
879
- * happens automatically after each run.
864
+ * Registers an event listener that will be awaited before Rollup continues.
865
+ * All listeners will be awaited in parallel while rejections are tracked via
866
+ * Promise.all.
867
+ * Listeners are removed automatically when removeListenersForCurrentRun is
868
+ * called, which happens automatically after each run.
880
869
  */
881
- onCurrentAwaited<K extends keyof T>(
870
+ onCurrentRun<K extends keyof T>(
882
871
  event: K,
883
872
  listener: (...args: Parameters<T[K]>) => Promise<ReturnType<T[K]>>
884
873
  ): this;
885
- removeAwaited(): this;
874
+ removeAllListeners(): this;
875
+ removeListenersForCurrentRun(): this;
886
876
  }
887
877
 
888
878
  export type RollupWatcherEvent =
@@ -898,7 +888,7 @@ export type RollupWatcherEvent =
898
888
  | { code: 'END' }
899
889
  | { code: 'ERROR'; error: RollupError; result: RollupBuild | null };
900
890
 
901
- export type RollupWatcher = RollupAwaitingEmitter<{
891
+ export type RollupWatcher = AwaitingEventEmitter<{
902
892
  change: (id: string, change: { event: ChangeEvent }) => void;
903
893
  close: () => void;
904
894
  event: (event: RollupWatcherEvent) => void;