rollup 2.77.1 → 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/CHANGELOG.md +39 -0
- package/README.md +1 -1
- package/dist/bin/rollup +2 -2
- package/dist/es/rollup.browser.js +3 -3
- package/dist/es/rollup.js +2 -2
- package/dist/es/shared/rollup.js +122 -77
- package/dist/es/shared/watch.js +2 -2
- package/dist/loadConfigFile.js +2 -2
- package/dist/rollup.browser.js +3 -3
- package/dist/rollup.browser.js.map +1 -1
- package/dist/rollup.d.ts +71 -79
- package/dist/rollup.js +2 -2
- package/dist/shared/index.js +2 -2
- package/dist/shared/loadConfigFile.js +2 -2
- package/dist/shared/mergeOptions.js +2 -2
- package/dist/shared/rollup.js +122 -77
- package/dist/shared/watch-cli.js +2 -2
- package/dist/shared/watch.js +2 -2
- package/package.json +2 -4
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
|
-
) =>
|
|
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
|
-
) =>
|
|
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) =>
|
|
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
|
-
) =>
|
|
286
|
+
) => TransformResult;
|
|
287
287
|
|
|
288
|
-
export type ModuleParsedHook = (this: PluginContext, info: ModuleInfo) =>
|
|
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
|
-
) =>
|
|
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
|
-
) =>
|
|
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
|
|
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
|
|
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) =>
|
|
395
|
+
renderError: (this: PluginContext, err?: Error) => void;
|
|
412
396
|
renderStart: (
|
|
413
397
|
this: PluginContext,
|
|
414
398
|
outputOptions: NormalizedOutputOptions,
|
|
415
399
|
inputOptions: NormalizedInputOptions
|
|
416
|
-
) =>
|
|
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
|
|
414
|
+
) => void;
|
|
426
415
|
}
|
|
427
416
|
|
|
428
|
-
export type
|
|
429
|
-
| '
|
|
430
|
-
| 'buildEnd'
|
|
431
|
-
| 'buildStart'
|
|
417
|
+
export type OutputPluginHooks =
|
|
418
|
+
| 'augmentChunkHash'
|
|
432
419
|
| 'generateBundle'
|
|
433
|
-
| '
|
|
434
|
-
| 'moduleParsed'
|
|
420
|
+
| 'outputOptions'
|
|
435
421
|
| 'renderChunk'
|
|
422
|
+
| 'renderDynamicImport'
|
|
436
423
|
| 'renderError'
|
|
437
424
|
| 'renderStart'
|
|
438
|
-
| '
|
|
439
|
-
| '
|
|
440
|
-
| '
|
|
441
|
-
| '
|
|
442
|
-
|
|
443
|
-
|
|
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
|
|
432
|
+
export type SyncPluginHooks =
|
|
433
|
+
| 'augmentChunkHash'
|
|
434
|
+
| 'outputOptions'
|
|
435
|
+
| 'renderDynamicImport'
|
|
436
|
+
| 'resolveAssetUrl'
|
|
437
|
+
| 'resolveFileUrl'
|
|
438
|
+
| 'resolveImportMeta';
|
|
448
439
|
|
|
449
|
-
export type
|
|
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
|
-
|
|
|
471
|
-
|
|
|
472
|
-
|
|
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
|
-
|
|
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
|
-
|
|
493
|
-
|
|
494
|
-
|
|
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
|
|
499
|
-
|
|
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
package/dist/shared/index.js
CHANGED
package/dist/shared/rollup.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
@license
|
|
3
|
-
Rollup.js v2.
|
|
4
|
-
|
|
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.
|
|
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,
|
|
@@ -10390,6 +10406,7 @@ class ImportExpression extends NodeBase {
|
|
|
10390
10406
|
}
|
|
10391
10407
|
setExternalResolution(exportMode, resolution, options, snippets, pluginDriver, accessedGlobalsByScope) {
|
|
10392
10408
|
const { format } = options;
|
|
10409
|
+
this.inlineNamespace = null;
|
|
10393
10410
|
this.resolution = resolution;
|
|
10394
10411
|
const accessedGlobals = [...(accessedImportGlobals[format] || [])];
|
|
10395
10412
|
let helper;
|
|
@@ -14734,7 +14751,7 @@ class Chunk {
|
|
|
14734
14751
|
});
|
|
14735
14752
|
const currentPath = `${currentDir}/${fileName}`;
|
|
14736
14753
|
const { preserveModulesRoot } = options;
|
|
14737
|
-
if (preserveModulesRoot && currentPath.startsWith(preserveModulesRoot)) {
|
|
14754
|
+
if (preserveModulesRoot && require$$0.resolve(currentPath).startsWith(preserveModulesRoot)) {
|
|
14738
14755
|
path = currentPath.slice(preserveModulesRoot.length).replace(/^[\\/]/, '');
|
|
14739
14756
|
}
|
|
14740
14757
|
else {
|
|
@@ -22601,7 +22618,7 @@ function getPluginContext(plugin, pluginCache, graph, options, fileEmitter, exis
|
|
|
22601
22618
|
else {
|
|
22602
22619
|
cacheInstance = getCacheForUncacheablePlugin(plugin.name);
|
|
22603
22620
|
}
|
|
22604
|
-
|
|
22621
|
+
return {
|
|
22605
22622
|
addWatchFile(id) {
|
|
22606
22623
|
if (graph.phase >= BuildPhase.GENERATE) {
|
|
22607
22624
|
return this.error(errInvalidRollupPhaseForAddWatchFile());
|
|
@@ -22659,9 +22676,9 @@ function getPluginContext(plugin, pluginCache, graph, options, fileEmitter, exis
|
|
|
22659
22676
|
options.onwarn(warning);
|
|
22660
22677
|
}
|
|
22661
22678
|
};
|
|
22662
|
-
return context;
|
|
22663
22679
|
}
|
|
22664
22680
|
|
|
22681
|
+
// This will make sure no input hook is omitted
|
|
22665
22682
|
const inputHookNames = {
|
|
22666
22683
|
buildEnd: 1,
|
|
22667
22684
|
buildStart: 1,
|
|
@@ -22677,19 +22694,14 @@ const inputHookNames = {
|
|
|
22677
22694
|
watchChange: 1
|
|
22678
22695
|
};
|
|
22679
22696
|
const inputHooks = Object.keys(inputHookNames);
|
|
22680
|
-
function throwInvalidHookError(hookName, pluginName) {
|
|
22681
|
-
return error({
|
|
22682
|
-
code: 'INVALID_PLUGIN_HOOK',
|
|
22683
|
-
message: `Error running plugin hook ${hookName} for ${pluginName}, expected a function hook.`
|
|
22684
|
-
});
|
|
22685
|
-
}
|
|
22686
22697
|
class PluginDriver {
|
|
22687
22698
|
constructor(graph, options, userPlugins, pluginCache, basePluginDriver) {
|
|
22688
22699
|
this.graph = graph;
|
|
22689
22700
|
this.options = options;
|
|
22701
|
+
this.pluginCache = pluginCache;
|
|
22702
|
+
this.sortedPlugins = new Map();
|
|
22690
22703
|
this.unfulfilledActions = new Set();
|
|
22691
22704
|
warnDeprecatedHooks(userPlugins, options);
|
|
22692
|
-
this.pluginCache = pluginCache;
|
|
22693
22705
|
this.fileEmitter = new FileEmitter(graph, options, basePluginDriver && basePluginDriver.fileEmitter);
|
|
22694
22706
|
this.emitFile = this.fileEmitter.emitFile.bind(this.fileEmitter);
|
|
22695
22707
|
this.getFileName = this.fileEmitter.getFileName.bind(this.fileEmitter);
|
|
@@ -22719,21 +22731,21 @@ class PluginDriver {
|
|
|
22719
22731
|
}
|
|
22720
22732
|
// chains, first non-null result stops and returns
|
|
22721
22733
|
hookFirst(hookName, args, replaceContext, skipped) {
|
|
22722
|
-
let promise = Promise.resolve(
|
|
22723
|
-
for (const plugin of this.
|
|
22734
|
+
let promise = Promise.resolve(null);
|
|
22735
|
+
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
22724
22736
|
if (skipped && skipped.has(plugin))
|
|
22725
22737
|
continue;
|
|
22726
22738
|
promise = promise.then(result => {
|
|
22727
22739
|
if (result != null)
|
|
22728
22740
|
return result;
|
|
22729
|
-
return this.runHook(hookName, args, plugin,
|
|
22741
|
+
return this.runHook(hookName, args, plugin, replaceContext);
|
|
22730
22742
|
});
|
|
22731
22743
|
}
|
|
22732
22744
|
return promise;
|
|
22733
22745
|
}
|
|
22734
22746
|
// chains synchronously, first non-null result stops and returns
|
|
22735
22747
|
hookFirstSync(hookName, args, replaceContext) {
|
|
22736
|
-
for (const plugin of this.
|
|
22748
|
+
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
22737
22749
|
const result = this.runHookSync(hookName, args, plugin, replaceContext);
|
|
22738
22750
|
if (result != null)
|
|
22739
22751
|
return result;
|
|
@@ -22741,56 +22753,58 @@ class PluginDriver {
|
|
|
22741
22753
|
return null;
|
|
22742
22754
|
}
|
|
22743
22755
|
// parallel, ignores returns
|
|
22744
|
-
hookParallel(hookName, args, replaceContext) {
|
|
22745
|
-
const
|
|
22746
|
-
for (const plugin of this.
|
|
22747
|
-
|
|
22748
|
-
|
|
22749
|
-
|
|
22750
|
-
|
|
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
|
+
}
|
|
22751
22767
|
}
|
|
22752
|
-
|
|
22768
|
+
await Promise.all(parallelPromises);
|
|
22753
22769
|
}
|
|
22754
22770
|
// chains, reduces returned value, handling the reduced value as the first hook argument
|
|
22755
22771
|
hookReduceArg0(hookName, [arg0, ...rest], reduce, replaceContext) {
|
|
22756
22772
|
let promise = Promise.resolve(arg0);
|
|
22757
|
-
for (const plugin of this.
|
|
22758
|
-
promise = promise.then(arg0 =>
|
|
22759
|
-
const args = [arg0, ...rest];
|
|
22760
|
-
const hookPromise = this.runHook(hookName, args, plugin, false, replaceContext);
|
|
22761
|
-
if (!hookPromise)
|
|
22762
|
-
return arg0;
|
|
22763
|
-
return hookPromise.then(result => reduce.call(this.pluginContexts.get(plugin), arg0, result, plugin));
|
|
22764
|
-
});
|
|
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)));
|
|
22765
22775
|
}
|
|
22766
22776
|
return promise;
|
|
22767
22777
|
}
|
|
22768
22778
|
// chains synchronously, reduces returned value, handling the reduced value as the first hook argument
|
|
22769
22779
|
hookReduceArg0Sync(hookName, [arg0, ...rest], reduce, replaceContext) {
|
|
22770
|
-
for (const plugin of this.
|
|
22780
|
+
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
22771
22781
|
const args = [arg0, ...rest];
|
|
22772
22782
|
const result = this.runHookSync(hookName, args, plugin, replaceContext);
|
|
22773
22783
|
arg0 = reduce.call(this.pluginContexts.get(plugin), arg0, result, plugin);
|
|
22774
22784
|
}
|
|
22775
22785
|
return arg0;
|
|
22776
22786
|
}
|
|
22777
|
-
// chains, reduces returned value to type
|
|
22778
|
-
hookReduceValue(hookName, initialValue, args,
|
|
22779
|
-
|
|
22780
|
-
|
|
22781
|
-
|
|
22782
|
-
|
|
22783
|
-
|
|
22784
|
-
|
|
22785
|
-
|
|
22786
|
-
}
|
|
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
|
+
}
|
|
22787
22800
|
}
|
|
22788
|
-
|
|
22801
|
+
results.push(...(await Promise.all(parallelResults)));
|
|
22802
|
+
return results.reduce(reducer, await initialValue);
|
|
22789
22803
|
}
|
|
22790
22804
|
// chains synchronously, reduces returned value to type T, handling the reduced value separately. permits hooks as values.
|
|
22791
22805
|
hookReduceValueSync(hookName, initialValue, args, reduce, replaceContext) {
|
|
22792
22806
|
let acc = initialValue;
|
|
22793
|
-
for (const plugin of this.
|
|
22807
|
+
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
22794
22808
|
const result = this.runHookSync(hookName, args, plugin, replaceContext);
|
|
22795
22809
|
acc = reduce.call(this.pluginContexts.get(plugin), acc, result, plugin);
|
|
22796
22810
|
}
|
|
@@ -22799,31 +22813,32 @@ class PluginDriver {
|
|
|
22799
22813
|
// chains, ignores returns
|
|
22800
22814
|
hookSeq(hookName, args, replaceContext) {
|
|
22801
22815
|
let promise = Promise.resolve();
|
|
22802
|
-
for (const plugin of this.
|
|
22803
|
-
promise = promise.then(() => this.runHook(hookName, args, plugin,
|
|
22816
|
+
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
22817
|
+
promise = promise.then(() => this.runHook(hookName, args, plugin, replaceContext));
|
|
22804
22818
|
}
|
|
22805
|
-
return promise;
|
|
22819
|
+
return promise.then(noReturn);
|
|
22820
|
+
}
|
|
22821
|
+
getSortedPlugins(hookName, validateHandler) {
|
|
22822
|
+
return getOrCreate(this.sortedPlugins, hookName, () => getSortedValidatedPlugins(hookName, this.plugins, validateHandler));
|
|
22806
22823
|
}
|
|
22807
|
-
|
|
22824
|
+
// Implementation signature
|
|
22825
|
+
runHook(hookName, args, plugin, replaceContext) {
|
|
22826
|
+
// We always filter for plugins that support the hook before running it
|
|
22808
22827
|
const hook = plugin[hookName];
|
|
22809
|
-
|
|
22810
|
-
return undefined;
|
|
22828
|
+
const handler = typeof hook === 'object' ? hook.handler : hook;
|
|
22811
22829
|
let context = this.pluginContexts.get(plugin);
|
|
22812
|
-
if (
|
|
22813
|
-
context =
|
|
22830
|
+
if (replaceContext) {
|
|
22831
|
+
context = replaceContext(context, plugin);
|
|
22814
22832
|
}
|
|
22815
22833
|
let action = null;
|
|
22816
22834
|
return Promise.resolve()
|
|
22817
22835
|
.then(() => {
|
|
22818
|
-
|
|
22819
|
-
|
|
22820
|
-
if (permitValues)
|
|
22821
|
-
return hook;
|
|
22822
|
-
return throwInvalidHookError(hookName, plugin.name);
|
|
22836
|
+
if (typeof handler !== 'function') {
|
|
22837
|
+
return handler;
|
|
22823
22838
|
}
|
|
22824
22839
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
22825
|
-
const hookResult =
|
|
22826
|
-
if (!hookResult ||
|
|
22840
|
+
const hookResult = handler.apply(context, args);
|
|
22841
|
+
if (!(hookResult === null || hookResult === void 0 ? void 0 : hookResult.then)) {
|
|
22827
22842
|
// short circuit for non-thenables and non-Promises
|
|
22828
22843
|
return hookResult;
|
|
22829
22844
|
}
|
|
@@ -22856,29 +22871,61 @@ class PluginDriver {
|
|
|
22856
22871
|
* @param hookName Name of the plugin hook. Must be in `PluginHooks`.
|
|
22857
22872
|
* @param args Arguments passed to the plugin hook.
|
|
22858
22873
|
* @param plugin The acutal plugin
|
|
22859
|
-
* @param
|
|
22874
|
+
* @param replaceContext When passed, the plugin context can be overridden.
|
|
22860
22875
|
*/
|
|
22861
|
-
runHookSync(hookName, args, plugin,
|
|
22876
|
+
runHookSync(hookName, args, plugin, replaceContext) {
|
|
22862
22877
|
const hook = plugin[hookName];
|
|
22863
|
-
|
|
22864
|
-
return undefined;
|
|
22878
|
+
const handler = typeof hook === 'object' ? hook.handler : hook;
|
|
22865
22879
|
let context = this.pluginContexts.get(plugin);
|
|
22866
|
-
if (
|
|
22867
|
-
context =
|
|
22880
|
+
if (replaceContext) {
|
|
22881
|
+
context = replaceContext(context, plugin);
|
|
22868
22882
|
}
|
|
22869
22883
|
try {
|
|
22870
|
-
// permit values allows values to be returned instead of a functional hook
|
|
22871
|
-
if (typeof hook !== 'function') {
|
|
22872
|
-
return throwInvalidHookError(hookName, plugin.name);
|
|
22873
|
-
}
|
|
22874
22884
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
22875
|
-
return
|
|
22885
|
+
return handler.apply(context, args);
|
|
22876
22886
|
}
|
|
22877
22887
|
catch (err) {
|
|
22878
22888
|
return throwPluginError(err, plugin.name, { hook: hookName });
|
|
22879
22889
|
}
|
|
22880
22890
|
}
|
|
22881
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() { }
|
|
22882
22929
|
|
|
22883
22930
|
class Queue {
|
|
22884
22931
|
constructor(maxParallel) {
|
|
@@ -23719,17 +23766,15 @@ async function getInputOptions(rawInputOptions, watchMode) {
|
|
|
23719
23766
|
if (!rawInputOptions) {
|
|
23720
23767
|
throw new Error('You must supply an options object to rollup');
|
|
23721
23768
|
}
|
|
23722
|
-
const rawPlugins = ensureArray$1(rawInputOptions.plugins);
|
|
23769
|
+
const rawPlugins = getSortedValidatedPlugins('options', ensureArray$1(rawInputOptions.plugins));
|
|
23723
23770
|
const { options, unsetOptions } = normalizeInputOptions(await rawPlugins.reduce(applyOptionHook(watchMode), Promise.resolve(rawInputOptions)));
|
|
23724
23771
|
normalizePlugins(options.plugins, ANONYMOUS_PLUGIN_PREFIX);
|
|
23725
23772
|
return { options, unsetOptions };
|
|
23726
23773
|
}
|
|
23727
23774
|
function applyOptionHook(watchMode) {
|
|
23728
23775
|
return async (inputOptions, plugin) => {
|
|
23729
|
-
|
|
23730
|
-
|
|
23731
|
-
}
|
|
23732
|
-
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);
|
|
23733
23778
|
};
|
|
23734
23779
|
}
|
|
23735
23780
|
function normalizePlugins(plugins, anonymousPrefix) {
|
package/dist/shared/watch-cli.js
CHANGED
package/dist/shared/watch.js
CHANGED