@rollup/browser 3.0.0-3 → 3.0.0-4

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.
@@ -220,7 +220,7 @@ export type ResolveIdHook = (
220
220
  source: string,
221
221
  importer: string | undefined,
222
222
  options: { custom?: CustomPluginOptions; isEntry: boolean }
223
- ) => Promise<ResolveIdResult> | ResolveIdResult;
223
+ ) => ResolveIdResult;
224
224
 
225
225
  export type ShouldTransformCachedModuleHook = (
226
226
  this: PluginContext,
@@ -233,7 +233,7 @@ export type ShouldTransformCachedModuleHook = (
233
233
  resolvedSources: ResolvedIdMap;
234
234
  syntheticNamedExports: boolean | string;
235
235
  }
236
- ) => Promise<boolean> | boolean;
236
+ ) => boolean;
237
237
 
238
238
  export type IsExternal = (
239
239
  source: string,
@@ -245,9 +245,9 @@ export type IsPureModule = (id: string) => boolean | null | void;
245
245
 
246
246
  export type HasModuleSideEffects = (id: string, external: boolean) => boolean;
247
247
 
248
- type LoadResult = SourceDescription | string | null | void;
248
+ export type LoadResult = SourceDescription | string | null | void;
249
249
 
250
- export type LoadHook = (this: PluginContext, id: string) => Promise<LoadResult> | LoadResult;
250
+ export type LoadHook = (this: PluginContext, id: string) => LoadResult;
251
251
 
252
252
  export interface TransformPluginContext extends PluginContext {
253
253
  getCombinedSourcemap: () => SourceMap;
@@ -259,9 +259,9 @@ export type TransformHook = (
259
259
  this: TransformPluginContext,
260
260
  code: string,
261
261
  id: string
262
- ) => Promise<TransformResult> | TransformResult;
262
+ ) => TransformResult;
263
263
 
264
- export type ModuleParsedHook = (this: PluginContext, info: ModuleInfo) => Promise<void> | void;
264
+ export type ModuleParsedHook = (this: PluginContext, info: ModuleInfo) => void;
265
265
 
266
266
  export type RenderChunkHook = (
267
267
  this: PluginContext,
@@ -269,18 +269,13 @@ export type RenderChunkHook = (
269
269
  chunk: RenderedChunk,
270
270
  options: NormalizedOutputOptions,
271
271
  meta: { chunks: Record<string, RenderedChunk> }
272
- ) =>
273
- | Promise<{ code: string; map?: SourceMapInput } | null>
274
- | { code: string; map?: SourceMapInput }
275
- | string
276
- | null
277
- | undefined;
272
+ ) => { code: string; map?: SourceMapInput } | string | null | undefined;
278
273
 
279
274
  export type ResolveDynamicImportHook = (
280
275
  this: PluginContext,
281
276
  specifier: string | AcornNode,
282
277
  importer: string
283
- ) => Promise<ResolveIdResult> | ResolveIdResult;
278
+ ) => ResolveIdResult;
284
279
 
285
280
  export type ResolveImportMetaHook = (
286
281
  this: PluginContext,
@@ -311,7 +306,7 @@ export type WatchChangeHook = (
311
306
  this: PluginContext,
312
307
  id: string,
313
308
  change: { event: ChangeEvent }
314
- ) => Promise<void> | void;
309
+ ) => void;
315
310
 
316
311
  /**
317
312
  * use this type for plugin annotation
@@ -338,32 +333,21 @@ export interface OutputBundleWithPlaceholders {
338
333
  [fileName: string]: OutputAsset | OutputChunk | FilePlaceholder;
339
334
  }
340
335
 
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 {
336
+ export interface FunctionPluginHooks {
360
337
  augmentChunkHash: (this: PluginContext, chunk: RenderedChunk) => string | void;
338
+ buildEnd: (this: PluginContext, err?: Error) => void;
339
+ buildStart: (this: PluginContext, options: NormalizedInputOptions) => void;
340
+ closeBundle: (this: PluginContext) => void;
341
+ closeWatcher: (this: PluginContext) => void;
361
342
  generateBundle: (
362
343
  this: PluginContext,
363
344
  options: NormalizedOutputOptions,
364
345
  bundle: OutputBundle,
365
346
  isWrite: boolean
366
- ) => void | Promise<void>;
347
+ ) => void;
348
+ load: LoadHook;
349
+ moduleParsed: ModuleParsedHook;
350
+ options: (this: MinimalPluginContext, options: InputOptions) => InputOptions | null | void;
367
351
  outputOptions: (this: PluginContext, options: OutputOptions) => OutputOptions | null | void;
368
352
  renderChunk: RenderChunkHook;
369
353
  renderDynamicImport: (
@@ -375,43 +359,48 @@ interface OutputPluginHooks {
375
359
  targetModuleId: string | null;
376
360
  }
377
361
  ) => { left: string; right: string } | null | void;
378
- renderError: (this: PluginContext, err?: Error) => Promise<void> | void;
362
+ renderError: (this: PluginContext, err?: Error) => void;
379
363
  renderStart: (
380
364
  this: PluginContext,
381
365
  outputOptions: NormalizedOutputOptions,
382
366
  inputOptions: NormalizedInputOptions
383
- ) => Promise<void> | void;
367
+ ) => void;
368
+ resolveDynamicImport: ResolveDynamicImportHook;
384
369
  resolveFileUrl: ResolveFileUrlHook;
370
+ resolveId: ResolveIdHook;
385
371
  resolveImportMeta: ResolveImportMetaHook;
372
+ shouldTransformCachedModule: ShouldTransformCachedModuleHook;
373
+ transform: TransformHook;
374
+ watchChange: WatchChangeHook;
386
375
  writeBundle: (
387
376
  this: PluginContext,
388
377
  options: NormalizedOutputOptions,
389
378
  bundle: OutputBundle
390
- ) => void | Promise<void>;
379
+ ) => void;
391
380
  }
392
381
 
393
- export type AsyncPluginHooks =
394
- | 'options'
395
- | 'buildEnd'
396
- | 'buildStart'
382
+ export type OutputPluginHooks =
383
+ | 'augmentChunkHash'
397
384
  | 'generateBundle'
398
- | 'load'
399
- | 'moduleParsed'
385
+ | 'outputOptions'
400
386
  | 'renderChunk'
387
+ | 'renderDynamicImport'
401
388
  | 'renderError'
402
389
  | 'renderStart'
403
- | 'resolveDynamicImport'
404
- | 'resolveId'
405
- | 'shouldTransformCachedModule'
406
- | 'transform'
407
- | 'writeBundle'
408
- | 'closeBundle'
409
- | 'closeWatcher'
410
- | 'watchChange';
390
+ | 'resolveFileUrl'
391
+ | 'resolveImportMeta'
392
+ | 'writeBundle';
411
393
 
412
- export type PluginValueHooks = 'banner' | 'footer' | 'intro' | 'outro';
394
+ export type InputPluginHooks = Exclude<keyof FunctionPluginHooks, OutputPluginHooks>;
413
395
 
414
- export type SyncPluginHooks = Exclude<keyof PluginHooks, AsyncPluginHooks>;
396
+ export type SyncPluginHooks =
397
+ | 'augmentChunkHash'
398
+ | 'outputOptions'
399
+ | 'renderDynamicImport'
400
+ | 'resolveFileUrl'
401
+ | 'resolveImportMeta';
402
+
403
+ export type AsyncPluginHooks = Exclude<keyof FunctionPluginHooks, SyncPluginHooks>;
415
404
 
416
405
  export type FirstPluginHooks =
417
406
  | 'load'
@@ -430,37 +419,38 @@ export type SequentialPluginHooks =
430
419
  | 'renderChunk'
431
420
  | 'transform';
432
421
 
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';
422
+ export type ParallelPluginHooks = Exclude<
423
+ keyof FunctionPluginHooks | AddonHooks,
424
+ FirstPluginHooks | SequentialPluginHooks
425
+ >;
447
426
 
448
- interface OutputPluginValueHooks {
449
- banner: AddonHook;
450
- cacheKey: string;
451
- footer: AddonHook;
452
- intro: AddonHook;
453
- outro: AddonHook;
454
- }
427
+ export type AddonHooks = 'banner' | 'footer' | 'intro' | 'outro';
455
428
 
456
- export interface Plugin extends Partial<PluginHooks>, Partial<OutputPluginValueHooks> {
457
- // for inter-plugin communication
458
- api?: any;
429
+ type MakeAsync<Fn> = Fn extends (this: infer This, ...args: infer Args) => infer Return
430
+ ? (this: This, ...args: Args) => Return | Promise<Return>
431
+ : never;
432
+
433
+ // eslint-disable-next-line @typescript-eslint/ban-types
434
+ type ObjectHook<T, O = {}> = T | ({ handler: T; order?: 'pre' | 'post' | null } & O);
435
+
436
+ export type PluginHooks = {
437
+ [K in keyof FunctionPluginHooks]: ObjectHook<
438
+ K extends AsyncPluginHooks ? MakeAsync<FunctionPluginHooks[K]> : FunctionPluginHooks[K],
439
+ // eslint-disable-next-line @typescript-eslint/ban-types
440
+ K extends ParallelPluginHooks ? { sequential?: boolean } : {}
441
+ >;
442
+ };
443
+
444
+ export interface OutputPlugin
445
+ extends Partial<{ [K in OutputPluginHooks]: PluginHooks[K] }>,
446
+ Partial<{ [K in AddonHooks]: ObjectHook<AddonHook> }> {
447
+ cacheKey?: string;
459
448
  name: string;
460
449
  }
461
450
 
462
- export interface OutputPlugin extends Partial<OutputPluginHooks>, Partial<OutputPluginValueHooks> {
463
- name: string;
451
+ export interface Plugin extends OutputPlugin, Partial<PluginHooks> {
452
+ // for inter-plugin communication
453
+ api?: any;
464
454
  }
465
455
 
466
456
  type TreeshakingPreset = 'smallest' | 'safest' | 'recommended';