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/es/rollup.js
CHANGED
package/dist/es/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
|
|
|
@@ -14,7 +14,7 @@ import { createHash as createHash$1 } from 'crypto';
|
|
|
14
14
|
import { promises } from 'fs';
|
|
15
15
|
import { EventEmitter } from 'events';
|
|
16
16
|
|
|
17
|
-
var version$1 = "2.
|
|
17
|
+
var version$1 = "2.78.0";
|
|
18
18
|
|
|
19
19
|
var charToInteger = {};
|
|
20
20
|
var chars$1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
|
@@ -2033,6 +2033,22 @@ function errInvalidOption(option, urlHash, explanation, value) {
|
|
|
2033
2033
|
url: `https://rollupjs.org/guide/en/#${urlHash}`
|
|
2034
2034
|
};
|
|
2035
2035
|
}
|
|
2036
|
+
function errInvalidAddonPluginHook(hook, plugin) {
|
|
2037
|
+
return {
|
|
2038
|
+
code: Errors.INVALID_PLUGIN_HOOK,
|
|
2039
|
+
hook,
|
|
2040
|
+
message: `Error running plugin hook ${hook} for plugin ${plugin}, expected a string, a function hook or an object with a "handler" string or function.`,
|
|
2041
|
+
plugin
|
|
2042
|
+
};
|
|
2043
|
+
}
|
|
2044
|
+
function errInvalidFunctionPluginHook(hook, plugin) {
|
|
2045
|
+
return {
|
|
2046
|
+
code: Errors.INVALID_PLUGIN_HOOK,
|
|
2047
|
+
hook,
|
|
2048
|
+
message: `Error running plugin hook ${hook} for plugin ${plugin}, expected a function hook or an object with a "handler" function.`,
|
|
2049
|
+
plugin
|
|
2050
|
+
};
|
|
2051
|
+
}
|
|
2036
2052
|
function errInvalidRollupPhaseForAddWatchFile() {
|
|
2037
2053
|
return {
|
|
2038
2054
|
code: Errors.INVALID_ROLLUP_PHASE,
|
|
@@ -10259,6 +10275,7 @@ class ImportExpression extends NodeBase {
|
|
|
10259
10275
|
}
|
|
10260
10276
|
setExternalResolution(exportMode, resolution, options, snippets, pluginDriver, accessedGlobalsByScope) {
|
|
10261
10277
|
const { format } = options;
|
|
10278
|
+
this.inlineNamespace = null;
|
|
10262
10279
|
this.resolution = resolution;
|
|
10263
10280
|
const accessedGlobals = [...(accessedImportGlobals[format] || [])];
|
|
10264
10281
|
let helper;
|
|
@@ -14603,7 +14620,7 @@ class Chunk {
|
|
|
14603
14620
|
});
|
|
14604
14621
|
const currentPath = `${currentDir}/${fileName}`;
|
|
14605
14622
|
const { preserveModulesRoot } = options;
|
|
14606
|
-
if (preserveModulesRoot && currentPath.startsWith(preserveModulesRoot)) {
|
|
14623
|
+
if (preserveModulesRoot && resolve(currentPath).startsWith(preserveModulesRoot)) {
|
|
14607
14624
|
path = currentPath.slice(preserveModulesRoot.length).replace(/^[\\/]/, '');
|
|
14608
14625
|
}
|
|
14609
14626
|
else {
|
|
@@ -22470,7 +22487,7 @@ function getPluginContext(plugin, pluginCache, graph, options, fileEmitter, exis
|
|
|
22470
22487
|
else {
|
|
22471
22488
|
cacheInstance = getCacheForUncacheablePlugin(plugin.name);
|
|
22472
22489
|
}
|
|
22473
|
-
|
|
22490
|
+
return {
|
|
22474
22491
|
addWatchFile(id) {
|
|
22475
22492
|
if (graph.phase >= BuildPhase.GENERATE) {
|
|
22476
22493
|
return this.error(errInvalidRollupPhaseForAddWatchFile());
|
|
@@ -22528,9 +22545,9 @@ function getPluginContext(plugin, pluginCache, graph, options, fileEmitter, exis
|
|
|
22528
22545
|
options.onwarn(warning);
|
|
22529
22546
|
}
|
|
22530
22547
|
};
|
|
22531
|
-
return context;
|
|
22532
22548
|
}
|
|
22533
22549
|
|
|
22550
|
+
// This will make sure no input hook is omitted
|
|
22534
22551
|
const inputHookNames = {
|
|
22535
22552
|
buildEnd: 1,
|
|
22536
22553
|
buildStart: 1,
|
|
@@ -22546,19 +22563,14 @@ const inputHookNames = {
|
|
|
22546
22563
|
watchChange: 1
|
|
22547
22564
|
};
|
|
22548
22565
|
const inputHooks = Object.keys(inputHookNames);
|
|
22549
|
-
function throwInvalidHookError(hookName, pluginName) {
|
|
22550
|
-
return error({
|
|
22551
|
-
code: 'INVALID_PLUGIN_HOOK',
|
|
22552
|
-
message: `Error running plugin hook ${hookName} for ${pluginName}, expected a function hook.`
|
|
22553
|
-
});
|
|
22554
|
-
}
|
|
22555
22566
|
class PluginDriver {
|
|
22556
22567
|
constructor(graph, options, userPlugins, pluginCache, basePluginDriver) {
|
|
22557
22568
|
this.graph = graph;
|
|
22558
22569
|
this.options = options;
|
|
22570
|
+
this.pluginCache = pluginCache;
|
|
22571
|
+
this.sortedPlugins = new Map();
|
|
22559
22572
|
this.unfulfilledActions = new Set();
|
|
22560
22573
|
warnDeprecatedHooks(userPlugins, options);
|
|
22561
|
-
this.pluginCache = pluginCache;
|
|
22562
22574
|
this.fileEmitter = new FileEmitter(graph, options, basePluginDriver && basePluginDriver.fileEmitter);
|
|
22563
22575
|
this.emitFile = this.fileEmitter.emitFile.bind(this.fileEmitter);
|
|
22564
22576
|
this.getFileName = this.fileEmitter.getFileName.bind(this.fileEmitter);
|
|
@@ -22588,21 +22600,21 @@ class PluginDriver {
|
|
|
22588
22600
|
}
|
|
22589
22601
|
// chains, first non-null result stops and returns
|
|
22590
22602
|
hookFirst(hookName, args, replaceContext, skipped) {
|
|
22591
|
-
let promise = Promise.resolve(
|
|
22592
|
-
for (const plugin of this.
|
|
22603
|
+
let promise = Promise.resolve(null);
|
|
22604
|
+
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
22593
22605
|
if (skipped && skipped.has(plugin))
|
|
22594
22606
|
continue;
|
|
22595
22607
|
promise = promise.then(result => {
|
|
22596
22608
|
if (result != null)
|
|
22597
22609
|
return result;
|
|
22598
|
-
return this.runHook(hookName, args, plugin,
|
|
22610
|
+
return this.runHook(hookName, args, plugin, replaceContext);
|
|
22599
22611
|
});
|
|
22600
22612
|
}
|
|
22601
22613
|
return promise;
|
|
22602
22614
|
}
|
|
22603
22615
|
// chains synchronously, first non-null result stops and returns
|
|
22604
22616
|
hookFirstSync(hookName, args, replaceContext) {
|
|
22605
|
-
for (const plugin of this.
|
|
22617
|
+
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
22606
22618
|
const result = this.runHookSync(hookName, args, plugin, replaceContext);
|
|
22607
22619
|
if (result != null)
|
|
22608
22620
|
return result;
|
|
@@ -22610,56 +22622,58 @@ class PluginDriver {
|
|
|
22610
22622
|
return null;
|
|
22611
22623
|
}
|
|
22612
22624
|
// parallel, ignores returns
|
|
22613
|
-
hookParallel(hookName, args, replaceContext) {
|
|
22614
|
-
const
|
|
22615
|
-
for (const plugin of this.
|
|
22616
|
-
|
|
22617
|
-
|
|
22618
|
-
|
|
22619
|
-
|
|
22625
|
+
async hookParallel(hookName, args, replaceContext) {
|
|
22626
|
+
const parallelPromises = [];
|
|
22627
|
+
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
22628
|
+
if (plugin[hookName].sequential) {
|
|
22629
|
+
await Promise.all(parallelPromises);
|
|
22630
|
+
parallelPromises.length = 0;
|
|
22631
|
+
await this.runHook(hookName, args, plugin, replaceContext);
|
|
22632
|
+
}
|
|
22633
|
+
else {
|
|
22634
|
+
parallelPromises.push(this.runHook(hookName, args, plugin, replaceContext));
|
|
22635
|
+
}
|
|
22620
22636
|
}
|
|
22621
|
-
|
|
22637
|
+
await Promise.all(parallelPromises);
|
|
22622
22638
|
}
|
|
22623
22639
|
// chains, reduces returned value, handling the reduced value as the first hook argument
|
|
22624
22640
|
hookReduceArg0(hookName, [arg0, ...rest], reduce, replaceContext) {
|
|
22625
22641
|
let promise = Promise.resolve(arg0);
|
|
22626
|
-
for (const plugin of this.
|
|
22627
|
-
promise = promise.then(arg0 =>
|
|
22628
|
-
const args = [arg0, ...rest];
|
|
22629
|
-
const hookPromise = this.runHook(hookName, args, plugin, false, replaceContext);
|
|
22630
|
-
if (!hookPromise)
|
|
22631
|
-
return arg0;
|
|
22632
|
-
return hookPromise.then(result => reduce.call(this.pluginContexts.get(plugin), arg0, result, plugin));
|
|
22633
|
-
});
|
|
22642
|
+
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
22643
|
+
promise = promise.then(arg0 => this.runHook(hookName, [arg0, ...rest], plugin, replaceContext).then(result => reduce.call(this.pluginContexts.get(plugin), arg0, result, plugin)));
|
|
22634
22644
|
}
|
|
22635
22645
|
return promise;
|
|
22636
22646
|
}
|
|
22637
22647
|
// chains synchronously, reduces returned value, handling the reduced value as the first hook argument
|
|
22638
22648
|
hookReduceArg0Sync(hookName, [arg0, ...rest], reduce, replaceContext) {
|
|
22639
|
-
for (const plugin of this.
|
|
22649
|
+
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
22640
22650
|
const args = [arg0, ...rest];
|
|
22641
22651
|
const result = this.runHookSync(hookName, args, plugin, replaceContext);
|
|
22642
22652
|
arg0 = reduce.call(this.pluginContexts.get(plugin), arg0, result, plugin);
|
|
22643
22653
|
}
|
|
22644
22654
|
return arg0;
|
|
22645
22655
|
}
|
|
22646
|
-
// chains, reduces returned value to type
|
|
22647
|
-
hookReduceValue(hookName, initialValue, args,
|
|
22648
|
-
|
|
22649
|
-
|
|
22650
|
-
|
|
22651
|
-
|
|
22652
|
-
|
|
22653
|
-
|
|
22654
|
-
|
|
22655
|
-
}
|
|
22656
|
+
// chains, reduces returned value to type string, handling the reduced value separately. permits hooks as values.
|
|
22657
|
+
async hookReduceValue(hookName, initialValue, args, reducer) {
|
|
22658
|
+
const results = [];
|
|
22659
|
+
const parallelResults = [];
|
|
22660
|
+
for (const plugin of this.getSortedPlugins(hookName, validateAddonPluginHandler)) {
|
|
22661
|
+
if (plugin[hookName].sequential) {
|
|
22662
|
+
results.push(...(await Promise.all(parallelResults)));
|
|
22663
|
+
parallelResults.length = 0;
|
|
22664
|
+
results.push(await this.runHook(hookName, args, plugin));
|
|
22665
|
+
}
|
|
22666
|
+
else {
|
|
22667
|
+
parallelResults.push(this.runHook(hookName, args, plugin));
|
|
22668
|
+
}
|
|
22656
22669
|
}
|
|
22657
|
-
|
|
22670
|
+
results.push(...(await Promise.all(parallelResults)));
|
|
22671
|
+
return results.reduce(reducer, await initialValue);
|
|
22658
22672
|
}
|
|
22659
22673
|
// chains synchronously, reduces returned value to type T, handling the reduced value separately. permits hooks as values.
|
|
22660
22674
|
hookReduceValueSync(hookName, initialValue, args, reduce, replaceContext) {
|
|
22661
22675
|
let acc = initialValue;
|
|
22662
|
-
for (const plugin of this.
|
|
22676
|
+
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
22663
22677
|
const result = this.runHookSync(hookName, args, plugin, replaceContext);
|
|
22664
22678
|
acc = reduce.call(this.pluginContexts.get(plugin), acc, result, plugin);
|
|
22665
22679
|
}
|
|
@@ -22668,31 +22682,32 @@ class PluginDriver {
|
|
|
22668
22682
|
// chains, ignores returns
|
|
22669
22683
|
hookSeq(hookName, args, replaceContext) {
|
|
22670
22684
|
let promise = Promise.resolve();
|
|
22671
|
-
for (const plugin of this.
|
|
22672
|
-
promise = promise.then(() => this.runHook(hookName, args, plugin,
|
|
22685
|
+
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
22686
|
+
promise = promise.then(() => this.runHook(hookName, args, plugin, replaceContext));
|
|
22673
22687
|
}
|
|
22674
|
-
return promise;
|
|
22688
|
+
return promise.then(noReturn);
|
|
22689
|
+
}
|
|
22690
|
+
getSortedPlugins(hookName, validateHandler) {
|
|
22691
|
+
return getOrCreate(this.sortedPlugins, hookName, () => getSortedValidatedPlugins(hookName, this.plugins, validateHandler));
|
|
22675
22692
|
}
|
|
22676
|
-
|
|
22693
|
+
// Implementation signature
|
|
22694
|
+
runHook(hookName, args, plugin, replaceContext) {
|
|
22695
|
+
// We always filter for plugins that support the hook before running it
|
|
22677
22696
|
const hook = plugin[hookName];
|
|
22678
|
-
|
|
22679
|
-
return undefined;
|
|
22697
|
+
const handler = typeof hook === 'object' ? hook.handler : hook;
|
|
22680
22698
|
let context = this.pluginContexts.get(plugin);
|
|
22681
|
-
if (
|
|
22682
|
-
context =
|
|
22699
|
+
if (replaceContext) {
|
|
22700
|
+
context = replaceContext(context, plugin);
|
|
22683
22701
|
}
|
|
22684
22702
|
let action = null;
|
|
22685
22703
|
return Promise.resolve()
|
|
22686
22704
|
.then(() => {
|
|
22687
|
-
|
|
22688
|
-
|
|
22689
|
-
if (permitValues)
|
|
22690
|
-
return hook;
|
|
22691
|
-
return throwInvalidHookError(hookName, plugin.name);
|
|
22705
|
+
if (typeof handler !== 'function') {
|
|
22706
|
+
return handler;
|
|
22692
22707
|
}
|
|
22693
22708
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
22694
|
-
const hookResult =
|
|
22695
|
-
if (!hookResult ||
|
|
22709
|
+
const hookResult = handler.apply(context, args);
|
|
22710
|
+
if (!(hookResult === null || hookResult === void 0 ? void 0 : hookResult.then)) {
|
|
22696
22711
|
// short circuit for non-thenables and non-Promises
|
|
22697
22712
|
return hookResult;
|
|
22698
22713
|
}
|
|
@@ -22725,29 +22740,61 @@ class PluginDriver {
|
|
|
22725
22740
|
* @param hookName Name of the plugin hook. Must be in `PluginHooks`.
|
|
22726
22741
|
* @param args Arguments passed to the plugin hook.
|
|
22727
22742
|
* @param plugin The acutal plugin
|
|
22728
|
-
* @param
|
|
22743
|
+
* @param replaceContext When passed, the plugin context can be overridden.
|
|
22729
22744
|
*/
|
|
22730
|
-
runHookSync(hookName, args, plugin,
|
|
22745
|
+
runHookSync(hookName, args, plugin, replaceContext) {
|
|
22731
22746
|
const hook = plugin[hookName];
|
|
22732
|
-
|
|
22733
|
-
return undefined;
|
|
22747
|
+
const handler = typeof hook === 'object' ? hook.handler : hook;
|
|
22734
22748
|
let context = this.pluginContexts.get(plugin);
|
|
22735
|
-
if (
|
|
22736
|
-
context =
|
|
22749
|
+
if (replaceContext) {
|
|
22750
|
+
context = replaceContext(context, plugin);
|
|
22737
22751
|
}
|
|
22738
22752
|
try {
|
|
22739
|
-
// permit values allows values to be returned instead of a functional hook
|
|
22740
|
-
if (typeof hook !== 'function') {
|
|
22741
|
-
return throwInvalidHookError(hookName, plugin.name);
|
|
22742
|
-
}
|
|
22743
22753
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
22744
|
-
return
|
|
22754
|
+
return handler.apply(context, args);
|
|
22745
22755
|
}
|
|
22746
22756
|
catch (err) {
|
|
22747
22757
|
return throwPluginError(err, plugin.name, { hook: hookName });
|
|
22748
22758
|
}
|
|
22749
22759
|
}
|
|
22750
22760
|
}
|
|
22761
|
+
function getSortedValidatedPlugins(hookName, plugins, validateHandler = validateFunctionPluginHandler) {
|
|
22762
|
+
const pre = [];
|
|
22763
|
+
const normal = [];
|
|
22764
|
+
const post = [];
|
|
22765
|
+
for (const plugin of plugins) {
|
|
22766
|
+
const hook = plugin[hookName];
|
|
22767
|
+
if (hook) {
|
|
22768
|
+
if (typeof hook === 'object') {
|
|
22769
|
+
validateHandler(hook.handler, hookName, plugin);
|
|
22770
|
+
if (hook.order === 'pre') {
|
|
22771
|
+
pre.push(plugin);
|
|
22772
|
+
continue;
|
|
22773
|
+
}
|
|
22774
|
+
if (hook.order === 'post') {
|
|
22775
|
+
post.push(plugin);
|
|
22776
|
+
continue;
|
|
22777
|
+
}
|
|
22778
|
+
}
|
|
22779
|
+
else {
|
|
22780
|
+
validateHandler(hook, hookName, plugin);
|
|
22781
|
+
}
|
|
22782
|
+
normal.push(plugin);
|
|
22783
|
+
}
|
|
22784
|
+
}
|
|
22785
|
+
return [...pre, ...normal, ...post];
|
|
22786
|
+
}
|
|
22787
|
+
function validateFunctionPluginHandler(handler, hookName, plugin) {
|
|
22788
|
+
if (typeof handler !== 'function') {
|
|
22789
|
+
error(errInvalidFunctionPluginHook(hookName, plugin.name));
|
|
22790
|
+
}
|
|
22791
|
+
}
|
|
22792
|
+
function validateAddonPluginHandler(handler, hookName, plugin) {
|
|
22793
|
+
if (typeof handler !== 'string' && typeof handler !== 'function') {
|
|
22794
|
+
return error(errInvalidAddonPluginHook(hookName, plugin.name));
|
|
22795
|
+
}
|
|
22796
|
+
}
|
|
22797
|
+
function noReturn() { }
|
|
22751
22798
|
|
|
22752
22799
|
class Queue {
|
|
22753
22800
|
constructor(maxParallel) {
|
|
@@ -23681,17 +23728,15 @@ async function getInputOptions(rawInputOptions, watchMode) {
|
|
|
23681
23728
|
if (!rawInputOptions) {
|
|
23682
23729
|
throw new Error('You must supply an options object to rollup');
|
|
23683
23730
|
}
|
|
23684
|
-
const rawPlugins = ensureArray(rawInputOptions.plugins);
|
|
23731
|
+
const rawPlugins = getSortedValidatedPlugins('options', ensureArray(rawInputOptions.plugins));
|
|
23685
23732
|
const { options, unsetOptions } = normalizeInputOptions(await rawPlugins.reduce(applyOptionHook(watchMode), Promise.resolve(rawInputOptions)));
|
|
23686
23733
|
normalizePlugins(options.plugins, ANONYMOUS_PLUGIN_PREFIX);
|
|
23687
23734
|
return { options, unsetOptions };
|
|
23688
23735
|
}
|
|
23689
23736
|
function applyOptionHook(watchMode) {
|
|
23690
23737
|
return async (inputOptions, plugin) => {
|
|
23691
|
-
|
|
23692
|
-
|
|
23693
|
-
}
|
|
23694
|
-
return inputOptions;
|
|
23738
|
+
const handler = 'handler' in plugin.options ? plugin.options.handler : plugin.options;
|
|
23739
|
+
return ((await handler.call({ meta: { rollupVersion: version$1, watchMode } }, await inputOptions)) || inputOptions);
|
|
23695
23740
|
};
|
|
23696
23741
|
}
|
|
23697
23742
|
function normalizePlugins(plugins, anonymousPrefix) {
|
package/dist/es/shared/watch.js
CHANGED
package/dist/loadConfigFile.js
CHANGED