rollup 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.
- package/README.md +2 -2
- package/dist/bin/rollup +13 -21
- package/dist/es/rollup.js +8 -7
- package/dist/es/shared/rollup.js +168 -132
- package/dist/es/shared/watch.js +11 -7
- package/dist/loadConfigFile.js +10 -8
- package/dist/rollup.d.ts +69 -79
- package/dist/rollup.js +8 -7
- package/dist/shared/index.js +2 -2
- package/dist/shared/loadConfigFile.js +13 -12
- package/dist/shared/mergeOptions.js +2 -2
- package/dist/shared/rollup.js +212 -176
- package/dist/shared/watch-cli.js +13 -10
- package/dist/shared/watch.js +14 -10
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -76,7 +76,7 @@ For example, with CommonJS, the _entire tool or library must be imported_.
|
|
|
76
76
|
|
|
77
77
|
```js
|
|
78
78
|
// import the entire utils object with CommonJS
|
|
79
|
-
var utils = require('utils');
|
|
79
|
+
var utils = require('node:utils');
|
|
80
80
|
var query = 'Rollup';
|
|
81
81
|
// use the ajax method of the utils object
|
|
82
82
|
utils.ajax('https://api.example.com?search=' + query).then(handleResponse);
|
|
@@ -86,7 +86,7 @@ But with ES modules, instead of importing the whole `utils` object, we can just
|
|
|
86
86
|
|
|
87
87
|
```js
|
|
88
88
|
// import the ajax function with an ES import statement
|
|
89
|
-
import { ajax } from 'utils';
|
|
89
|
+
import { ajax } from 'node:utils';
|
|
90
90
|
var query = 'Rollup';
|
|
91
91
|
// call the ajax function
|
|
92
92
|
ajax('https://api.example.com?search=' + query).then(handleResponse);
|
package/dist/bin/rollup
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
/*
|
|
4
4
|
@license
|
|
5
|
-
Rollup.js v3.0.0-
|
|
6
|
-
|
|
5
|
+
Rollup.js v3.0.0-3
|
|
6
|
+
Mon, 15 Aug 2022 04:43:13 GMT - commit 84a4a595851ef71494b6f2ab558968bfbc148bdb
|
|
7
7
|
|
|
8
8
|
https://github.com/rollup/rollup
|
|
9
9
|
|
|
@@ -13,17 +13,19 @@
|
|
|
13
13
|
|
|
14
14
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
15
15
|
|
|
16
|
-
const process$1 = require('process');
|
|
16
|
+
const process$1 = require('node:process');
|
|
17
17
|
const rollup = require('../shared/rollup.js');
|
|
18
18
|
const require$$2 = require('util');
|
|
19
19
|
const require$$0 = require('path');
|
|
20
20
|
const require$$0$1 = require('fs');
|
|
21
21
|
const mergeOptions = require('../shared/mergeOptions.js');
|
|
22
22
|
const loadConfigFile_js = require('../shared/loadConfigFile.js');
|
|
23
|
-
require('
|
|
24
|
-
require('
|
|
25
|
-
require('
|
|
26
|
-
require('
|
|
23
|
+
const node_fs = require('node:fs');
|
|
24
|
+
const node_path = require('node:path');
|
|
25
|
+
require('node:perf_hooks');
|
|
26
|
+
require('node:crypto');
|
|
27
|
+
require('node:events');
|
|
28
|
+
require('node:url');
|
|
27
29
|
require('tty');
|
|
28
30
|
|
|
29
31
|
const help = "rollup version __VERSION__\n=====================================\n\nUsage: rollup [options] <entry file>\n\nBasic options:\n\n-c, --config <filename> Use this config file (if argument is used but value\n is unspecified, defaults to rollup.config.js)\n-d, --dir <dirname> Directory for chunks (if absent, prints to stdout)\n-e, --external <ids> Comma-separate list of module IDs to exclude\n-f, --format <format> Type of output (amd, cjs, es, iife, umd, system)\n-g, --globals <pairs> Comma-separate list of `moduleID:Global` pairs\n-h, --help Show this help message\n-i, --input <filename> Input (alternative to <entry file>)\n-m, --sourcemap Generate sourcemap (`-m inline` for inline map)\n-n, --name <name> Name for UMD export\n-o, --file <output> Single output file (if absent, prints to stdout)\n-p, --plugin <plugin> Use the plugin specified (may be repeated)\n-v, --version Show version number\n-w, --watch Watch files in bundle and rebuild on changes\n--amd.id <id> ID for AMD module (default is anonymous)\n--amd.autoId Generate the AMD ID based off the chunk name\n--amd.basePath <prefix> Path to prepend to auto generated AMD ID\n--amd.define <name> Function to use in place of `define`\n--assetFileNames <pattern> Name pattern for emitted assets\n--banner <text> Code to insert at top of bundle (outside wrapper)\n--chunkFileNames <pattern> Name pattern for emitted secondary chunks\n--compact Minify wrapper code\n--context <variable> Specify top-level `this` value\n--entryFileNames <pattern> Name pattern for emitted entry chunks\n--environment <values> Settings passed to config file (see example)\n--no-esModule Do not add __esModule property\n--exports <mode> Specify export mode (auto, default, named, none)\n--extend Extend global variable defined by --name\n--no-externalLiveBindings Do not generate code to support live bindings\n--failAfterWarnings Exit with an error if the build produced warnings\n--footer <text> Code to insert at end of bundle (outside wrapper)\n--no-freeze Do not freeze namespace objects\n--generatedCode <preset> Which code features to use (es5/es2015)\n--no-hoistTransitiveImports Do not hoist transitive imports into entry chunks\n--no-indent Don't indent result\n--no-interop Do not include interop block\n--inlineDynamicImports Create single bundle when using dynamic imports\n--intro <text> Code to insert at top of bundle (inside wrapper)\n--no-makeAbsoluteExternalsRelative Prevent normalization of external imports\n--maxParallelFileReads <value> How many files to read in parallel\n--minifyInternalExports Force or disable minification of internal exports\n--noConflict Generate a noConflict method for UMD globals\n--outro <text> Code to insert at end of bundle (inside wrapper)\n--perf Display performance timings\n--no-preserveEntrySignatures Avoid facade chunks for entry points\n--preserveModules Preserve module structure\n--preserveModulesRoot Put preserved modules under this path at root level\n--preserveSymlinks Do not follow symlinks when resolving files\n--no-sanitizeFileName Do not replace invalid characters in file names\n--shimMissingExports Create shim variables for missing exports\n--silent Don't print warnings\n--sourcemapBaseUrl <url> Emit absolute sourcemap URLs with given base\n--sourcemapExcludeSources Do not include source code in source maps\n--sourcemapFile <file> Specify bundle position for source maps\n--stdin=ext Specify file extension used for stdin input\n--no-stdin Do not read \"-\" from stdin\n--no-strict Don't emit `\"use strict\";` in the generated modules\n--strictDeprecations Throw errors for deprecated features\n--systemNullSetters Replace empty SystemJS setters with `null`\n--no-treeshake Disable tree-shaking optimisations\n--no-treeshake.annotations Ignore pure call annotations\n--no-treeshake.moduleSideEffects Assume modules have no side-effects\n--no-treeshake.propertyReadSideEffects Ignore property access side-effects\n--no-treeshake.tryCatchDeoptimization Do not turn off try-catch-tree-shaking\n--no-treeshake.unknownGlobalSideEffects Assume unknown globals do not throw\n--waitForBundleInput Wait for bundle input files\n--watch.buildDelay <number> Throttle watch rebuilds\n--no-watch.clearScreen Do not clear the screen when rebuilding\n--watch.skipWrite Do not write files to disk when watching\n--watch.exclude <files> Exclude files from being watched\n--watch.include <files> Limit watching to specified files\n--watch.onStart <cmd> Shell command to run on `\"START\"` event\n--watch.onBundleStart <cmd> Shell command to run on `\"BUNDLE_START\"` event\n--watch.onBundleEnd <cmd> Shell command to run on `\"BUNDLE_END\"` event\n--watch.onEnd <cmd> Shell command to run on `\"END\"` event\n--watch.onError <cmd> Shell command to run on `\"ERROR\"` event\n--validate Validate output\n\nExamples:\n\n# use settings in config file\nrollup -c\n\n# in config file, process.env.INCLUDE_DEPS === 'true'\n# and process.env.BUILD === 'production'\nrollup -c --environment INCLUDE_DEPS,BUILD:production\n\n# create CommonJS bundle.js from src/main.js\nrollup --format=cjs --file=bundle.js -- src/main.js\n\n# create self-executing IIFE using `window.jQuery`\n# and `window._` as external globals\nrollup -f iife --globals jquery:jQuery,lodash:_ \\\n -i src/app.js -o build/app.js -m build/app.js.map\n\nNotes:\n\n* When piping to stdout, only inline sourcemaps are permitted\n\nFor more information visit https://rollupjs.org\n";
|
|
@@ -1539,19 +1541,9 @@ async function build(inputOptions, warnings, silent = false) {
|
|
|
1539
1541
|
}
|
|
1540
1542
|
const { output: outputs } = await bundle.generate(output);
|
|
1541
1543
|
for (const file of outputs) {
|
|
1542
|
-
let source;
|
|
1543
|
-
if (file.type === 'asset') {
|
|
1544
|
-
source = file.source;
|
|
1545
|
-
}
|
|
1546
|
-
else {
|
|
1547
|
-
source = file.code;
|
|
1548
|
-
if (output.sourcemap === 'inline') {
|
|
1549
|
-
source += `\n//# ${rollup.SOURCEMAPPING_URL}=${file.map.toUrl()}\n`;
|
|
1550
|
-
}
|
|
1551
|
-
}
|
|
1552
1544
|
if (outputs.length > 1)
|
|
1553
1545
|
process$1.stdout.write(`\n${loadConfigFile_js.cyan(loadConfigFile_js.bold(`//→ ${file.fileName}:`))}\n`);
|
|
1554
|
-
process$1.stdout.write(source);
|
|
1546
|
+
process$1.stdout.write(file.type === 'asset' ? file.source : file.code);
|
|
1555
1547
|
}
|
|
1556
1548
|
if (!silent) {
|
|
1557
1549
|
warnings.flush();
|
|
@@ -1572,7 +1564,7 @@ async function build(inputOptions, warnings, silent = false) {
|
|
|
1572
1564
|
const DEFAULT_CONFIG_BASE = 'rollup.config';
|
|
1573
1565
|
async function getConfigPath(commandConfig) {
|
|
1574
1566
|
if (commandConfig === true) {
|
|
1575
|
-
return
|
|
1567
|
+
return node_path.resolve(await findConfigFileNameInCwd());
|
|
1576
1568
|
}
|
|
1577
1569
|
if (commandConfig.slice(0, 5) === 'node:') {
|
|
1578
1570
|
const pkgName = commandConfig.slice(5);
|
|
@@ -1591,10 +1583,10 @@ async function getConfigPath(commandConfig) {
|
|
|
1591
1583
|
}
|
|
1592
1584
|
}
|
|
1593
1585
|
}
|
|
1594
|
-
return
|
|
1586
|
+
return node_path.resolve(commandConfig);
|
|
1595
1587
|
}
|
|
1596
1588
|
async function findConfigFileNameInCwd() {
|
|
1597
|
-
const filesInWorkingDir = new Set(await
|
|
1589
|
+
const filesInWorkingDir = new Set(await node_fs.promises.readdir(process$1.cwd()));
|
|
1598
1590
|
for (const extension of ['mjs', 'cjs', 'ts']) {
|
|
1599
1591
|
const fileName = `${DEFAULT_CONFIG_BASE}.${extension}`;
|
|
1600
1592
|
if (filesInWorkingDir.has(fileName))
|
package/dist/es/rollup.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
/*
|
|
2
2
|
@license
|
|
3
|
-
Rollup.js v3.0.0-
|
|
4
|
-
|
|
3
|
+
Rollup.js v3.0.0-3
|
|
4
|
+
Mon, 15 Aug 2022 04:43:13 GMT - commit 84a4a595851ef71494b6f2ab558968bfbc148bdb
|
|
5
5
|
|
|
6
6
|
https://github.com/rollup/rollup
|
|
7
7
|
|
|
8
8
|
Released under the MIT License.
|
|
9
9
|
*/
|
|
10
10
|
export { version as VERSION, defineConfig, rollup, watch } from './shared/rollup.js';
|
|
11
|
+
import 'node:path';
|
|
11
12
|
import 'path';
|
|
12
|
-
import 'process';
|
|
13
|
-
import 'perf_hooks';
|
|
14
|
-
import 'crypto';
|
|
15
|
-
import 'fs';
|
|
16
|
-
import 'events';
|
|
13
|
+
import 'node:process';
|
|
14
|
+
import 'node:perf_hooks';
|
|
15
|
+
import 'node:crypto';
|
|
16
|
+
import 'node:fs';
|
|
17
|
+
import 'node:events';
|
package/dist/es/shared/rollup.js
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
/*
|
|
2
2
|
@license
|
|
3
|
-
Rollup.js v3.0.0-
|
|
4
|
-
|
|
3
|
+
Rollup.js v3.0.0-3
|
|
4
|
+
Mon, 15 Aug 2022 04:43:13 GMT - commit 84a4a595851ef71494b6f2ab558968bfbc148bdb
|
|
5
5
|
|
|
6
6
|
https://github.com/rollup/rollup
|
|
7
7
|
|
|
8
8
|
Released under the MIT License.
|
|
9
9
|
*/
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
10
|
+
import { resolve, basename, extname, dirname, relative as relative$1 } from 'node:path';
|
|
11
|
+
import require$$0, { win32, posix, isAbsolute as isAbsolute$1, resolve as resolve$1 } from 'path';
|
|
12
|
+
import process$1 from 'node:process';
|
|
13
|
+
import { performance } from 'node:perf_hooks';
|
|
14
|
+
import { createHash as createHash$1 } from 'node:crypto';
|
|
15
|
+
import { promises } from 'node:fs';
|
|
16
|
+
import { EventEmitter } from 'node:events';
|
|
16
17
|
|
|
17
|
-
var version$1 = "3.0.0-
|
|
18
|
+
var version$1 = "3.0.0-3";
|
|
18
19
|
|
|
19
20
|
var charToInteger = {};
|
|
20
21
|
var chars$1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
|
@@ -2120,11 +2121,19 @@ function errInvalidOption(option, urlHash, explanation, value) {
|
|
|
2120
2121
|
url: `https://rollupjs.org/guide/en/#${urlHash}`
|
|
2121
2122
|
};
|
|
2122
2123
|
}
|
|
2123
|
-
function
|
|
2124
|
+
function errInvalidAddonPluginHook(hook, plugin) {
|
|
2124
2125
|
return {
|
|
2125
2126
|
code: INVALID_PLUGIN_HOOK,
|
|
2126
2127
|
hook,
|
|
2127
|
-
message: `Error running plugin hook "${hook}" for "${plugin}", expected a function hook.`,
|
|
2128
|
+
message: `Error running plugin hook "${hook}" for plugin "${plugin}", expected a string, a function hook or an object with a "handler" string or function.`,
|
|
2129
|
+
plugin
|
|
2130
|
+
};
|
|
2131
|
+
}
|
|
2132
|
+
function errInvalidFunctionPluginHook(hook, plugin) {
|
|
2133
|
+
return {
|
|
2134
|
+
code: INVALID_PLUGIN_HOOK,
|
|
2135
|
+
hook,
|
|
2136
|
+
message: `Error running plugin hook "${hook}" for plugin "${plugin}", expected a function hook or an object with a "handler" function.`,
|
|
2128
2137
|
plugin
|
|
2129
2138
|
};
|
|
2130
2139
|
}
|
|
@@ -4721,7 +4730,7 @@ function getMatcherString(id, resolutionBase) {
|
|
|
4721
4730
|
return normalizePath(id);
|
|
4722
4731
|
}
|
|
4723
4732
|
// resolve('') is valid and will default to process.cwd()
|
|
4724
|
-
const basePath = normalizePath(resolve(resolutionBase || ''))
|
|
4733
|
+
const basePath = normalizePath(resolve$1(resolutionBase || ''))
|
|
4725
4734
|
// escape all possible (posix + win) path characters that might interfere with regex
|
|
4726
4735
|
.replace(/[-^$*+?.()|[\]{}]/g, '\\$&');
|
|
4727
4736
|
// Note that we use posix.join because:
|
|
@@ -13438,32 +13447,32 @@ function removeExtensionFromRelativeAmdId(id) {
|
|
|
13438
13447
|
}
|
|
13439
13448
|
|
|
13440
13449
|
const builtins = {
|
|
13441
|
-
assert:
|
|
13442
|
-
buffer:
|
|
13443
|
-
console:
|
|
13444
|
-
constants:
|
|
13445
|
-
domain:
|
|
13446
|
-
events:
|
|
13447
|
-
http:
|
|
13448
|
-
https:
|
|
13449
|
-
os:
|
|
13450
|
-
path:
|
|
13451
|
-
process:
|
|
13452
|
-
punycode:
|
|
13453
|
-
querystring:
|
|
13454
|
-
stream:
|
|
13455
|
-
string_decoder:
|
|
13456
|
-
timers:
|
|
13457
|
-
tty:
|
|
13458
|
-
url:
|
|
13459
|
-
util:
|
|
13460
|
-
vm:
|
|
13461
|
-
zlib:
|
|
13450
|
+
assert: 1,
|
|
13451
|
+
buffer: 1,
|
|
13452
|
+
console: 1,
|
|
13453
|
+
constants: 1,
|
|
13454
|
+
domain: 1,
|
|
13455
|
+
events: 1,
|
|
13456
|
+
http: 1,
|
|
13457
|
+
https: 1,
|
|
13458
|
+
os: 1,
|
|
13459
|
+
path: 1,
|
|
13460
|
+
process: 1,
|
|
13461
|
+
punycode: 1,
|
|
13462
|
+
querystring: 1,
|
|
13463
|
+
stream: 1,
|
|
13464
|
+
string_decoder: 1,
|
|
13465
|
+
timers: 1,
|
|
13466
|
+
tty: 1,
|
|
13467
|
+
url: 1,
|
|
13468
|
+
util: 1,
|
|
13469
|
+
vm: 1,
|
|
13470
|
+
zlib: 1
|
|
13462
13471
|
};
|
|
13463
13472
|
function warnOnBuiltins(warn, dependencies) {
|
|
13464
13473
|
const externalBuiltins = dependencies
|
|
13465
13474
|
.map(({ importPath }) => importPath)
|
|
13466
|
-
.filter(importPath => importPath in builtins);
|
|
13475
|
+
.filter(importPath => importPath in builtins || importPath.startsWith('node:'));
|
|
13467
13476
|
if (!externalBuiltins.length)
|
|
13468
13477
|
return;
|
|
13469
13478
|
warn(errMissingNodeBuiltins(externalBuiltins));
|
|
@@ -15188,7 +15197,7 @@ class Chunk {
|
|
|
15188
15197
|
? sanitizedId.slice(0, -extName.length)
|
|
15189
15198
|
: sanitizedId;
|
|
15190
15199
|
if (isAbsolute(idWithoutExtension)) {
|
|
15191
|
-
return preserveModulesRoot && idWithoutExtension.startsWith(preserveModulesRoot)
|
|
15200
|
+
return preserveModulesRoot && resolve(idWithoutExtension).startsWith(preserveModulesRoot)
|
|
15192
15201
|
? idWithoutExtension.slice(preserveModulesRoot.length).replace(/^[\\/]/, '')
|
|
15193
15202
|
: relative(this.inputBase, idWithoutExtension);
|
|
15194
15203
|
}
|
|
@@ -15981,7 +15990,7 @@ async function renderChunks(chunks, outputBundle, pluginDriver, outputOptions, o
|
|
|
15981
15990
|
const chunkGraph = getChunkGraph(chunks);
|
|
15982
15991
|
const { nonHashedChunksWithPlaceholders, renderedChunksByPlaceholder, hashDependenciesByPlaceholder } = await transformChunksAndGenerateContentHashes(renderedChunks, chunkGraph, outputOptions, pluginDriver, onwarn);
|
|
15983
15992
|
const hashesByPlaceholder = generateFinalHashes(renderedChunksByPlaceholder, hashDependenciesByPlaceholder, outputBundle);
|
|
15984
|
-
addChunksToBundle(renderedChunksByPlaceholder, hashesByPlaceholder, outputBundle, nonHashedChunksWithPlaceholders);
|
|
15993
|
+
addChunksToBundle(renderedChunksByPlaceholder, hashesByPlaceholder, outputBundle, nonHashedChunksWithPlaceholders, pluginDriver, outputOptions);
|
|
15985
15994
|
timeEnd('transform chunks', 2);
|
|
15986
15995
|
}
|
|
15987
15996
|
function reserveEntryChunksInBundle(chunks) {
|
|
@@ -16125,22 +16134,40 @@ function generateFinalHashes(renderedChunksByPlaceholder, hashDependenciesByPlac
|
|
|
16125
16134
|
}
|
|
16126
16135
|
return hashesByPlaceholder;
|
|
16127
16136
|
}
|
|
16128
|
-
function addChunksToBundle(renderedChunksByPlaceholder, hashesByPlaceholder, outputBundle, nonHashedChunksWithPlaceholders) {
|
|
16137
|
+
function addChunksToBundle(renderedChunksByPlaceholder, hashesByPlaceholder, outputBundle, nonHashedChunksWithPlaceholders, pluginDriver, options) {
|
|
16129
16138
|
for (const { chunk, code, fileName, map } of renderedChunksByPlaceholder.values()) {
|
|
16130
|
-
|
|
16139
|
+
let updatedCode = replacePlaceholders(code, hashesByPlaceholder);
|
|
16131
16140
|
const finalFileName = replacePlaceholders(fileName, hashesByPlaceholder);
|
|
16132
16141
|
if (map) {
|
|
16133
16142
|
map.file = replacePlaceholders(map.file, hashesByPlaceholder);
|
|
16143
|
+
updatedCode += emitSourceMapAndGetComment(finalFileName, map, pluginDriver, options);
|
|
16134
16144
|
}
|
|
16135
16145
|
outputBundle[finalFileName] = chunk.generateOutputChunk(updatedCode, map, hashesByPlaceholder);
|
|
16136
16146
|
}
|
|
16137
16147
|
for (const { chunk, code, fileName, map } of nonHashedChunksWithPlaceholders) {
|
|
16138
|
-
|
|
16148
|
+
let updatedCode = hashesByPlaceholder.size
|
|
16139
16149
|
? replacePlaceholders(code, hashesByPlaceholder)
|
|
16140
16150
|
: code;
|
|
16151
|
+
if (map) {
|
|
16152
|
+
updatedCode += emitSourceMapAndGetComment(fileName, map, pluginDriver, options);
|
|
16153
|
+
}
|
|
16141
16154
|
outputBundle[fileName] = chunk.generateOutputChunk(updatedCode, map, hashesByPlaceholder);
|
|
16142
16155
|
}
|
|
16143
16156
|
}
|
|
16157
|
+
function emitSourceMapAndGetComment(fileName, map, pluginDriver, { sourcemap, sourcemapBaseUrl }) {
|
|
16158
|
+
let url;
|
|
16159
|
+
if (sourcemap === 'inline') {
|
|
16160
|
+
url = map.toUrl();
|
|
16161
|
+
}
|
|
16162
|
+
else {
|
|
16163
|
+
const sourcemapFileName = `${basename(fileName)}.map`;
|
|
16164
|
+
url = sourcemapBaseUrl
|
|
16165
|
+
? new URL(sourcemapFileName, sourcemapBaseUrl).toString()
|
|
16166
|
+
: sourcemapFileName;
|
|
16167
|
+
pluginDriver.emitFile({ fileName: `${fileName}.map`, source: map.toString(), type: 'asset' });
|
|
16168
|
+
}
|
|
16169
|
+
return sourcemap === 'hidden' ? '' : `//# ${SOURCEMAPPING_URL}=${url}\n`;
|
|
16170
|
+
}
|
|
16144
16171
|
|
|
16145
16172
|
class Bundle {
|
|
16146
16173
|
constructor(outputOptions, unsetOptions, inputOptions, pluginDriver, graph) {
|
|
@@ -22582,7 +22609,7 @@ function getPluginContext(plugin, pluginCache, graph, options, fileEmitter, exis
|
|
|
22582
22609
|
else {
|
|
22583
22610
|
cacheInstance = getCacheForUncacheablePlugin(plugin.name);
|
|
22584
22611
|
}
|
|
22585
|
-
|
|
22612
|
+
return {
|
|
22586
22613
|
addWatchFile(id) {
|
|
22587
22614
|
if (graph.phase >= BuildPhase.GENERATE) {
|
|
22588
22615
|
return this.error(errInvalidRollupPhaseForAddWatchFile());
|
|
@@ -22632,9 +22659,9 @@ function getPluginContext(plugin, pluginCache, graph, options, fileEmitter, exis
|
|
|
22632
22659
|
options.onwarn(warning);
|
|
22633
22660
|
}
|
|
22634
22661
|
};
|
|
22635
|
-
return context;
|
|
22636
22662
|
}
|
|
22637
22663
|
|
|
22664
|
+
// This will make sure no input hook is omitted
|
|
22638
22665
|
const inputHookNames = {
|
|
22639
22666
|
buildEnd: 1,
|
|
22640
22667
|
buildStart: 1,
|
|
@@ -22654,8 +22681,9 @@ class PluginDriver {
|
|
|
22654
22681
|
constructor(graph, options, userPlugins, pluginCache, basePluginDriver) {
|
|
22655
22682
|
this.graph = graph;
|
|
22656
22683
|
this.options = options;
|
|
22657
|
-
this.unfulfilledActions = new Set();
|
|
22658
22684
|
this.pluginCache = pluginCache;
|
|
22685
|
+
this.sortedPlugins = new Map();
|
|
22686
|
+
this.unfulfilledActions = new Set();
|
|
22659
22687
|
this.fileEmitter = new FileEmitter(graph, options, basePluginDriver && basePluginDriver.fileEmitter);
|
|
22660
22688
|
this.emitFile = this.fileEmitter.emitFile.bind(this.fileEmitter);
|
|
22661
22689
|
this.getFileName = this.fileEmitter.getFileName.bind(this.fileEmitter);
|
|
@@ -22686,21 +22714,21 @@ class PluginDriver {
|
|
|
22686
22714
|
}
|
|
22687
22715
|
// chains, first non-null result stops and returns
|
|
22688
22716
|
hookFirst(hookName, args, replaceContext, skipped) {
|
|
22689
|
-
let promise = Promise.resolve(
|
|
22690
|
-
for (const plugin of this.
|
|
22717
|
+
let promise = Promise.resolve(null);
|
|
22718
|
+
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
22691
22719
|
if (skipped && skipped.has(plugin))
|
|
22692
22720
|
continue;
|
|
22693
22721
|
promise = promise.then(result => {
|
|
22694
22722
|
if (result != null)
|
|
22695
22723
|
return result;
|
|
22696
|
-
return this.runHook(hookName, args, plugin,
|
|
22724
|
+
return this.runHook(hookName, args, plugin, replaceContext);
|
|
22697
22725
|
});
|
|
22698
22726
|
}
|
|
22699
22727
|
return promise;
|
|
22700
22728
|
}
|
|
22701
22729
|
// chains synchronously, first non-null result stops and returns
|
|
22702
22730
|
hookFirstSync(hookName, args, replaceContext) {
|
|
22703
|
-
for (const plugin of this.
|
|
22731
|
+
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
22704
22732
|
const result = this.runHookSync(hookName, args, plugin, replaceContext);
|
|
22705
22733
|
if (result != null)
|
|
22706
22734
|
return result;
|
|
@@ -22708,56 +22736,58 @@ class PluginDriver {
|
|
|
22708
22736
|
return null;
|
|
22709
22737
|
}
|
|
22710
22738
|
// parallel, ignores returns
|
|
22711
|
-
hookParallel(hookName, args, replaceContext) {
|
|
22712
|
-
const
|
|
22713
|
-
for (const plugin of this.
|
|
22714
|
-
|
|
22715
|
-
|
|
22716
|
-
|
|
22717
|
-
|
|
22739
|
+
async hookParallel(hookName, args, replaceContext) {
|
|
22740
|
+
const parallelPromises = [];
|
|
22741
|
+
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
22742
|
+
if (plugin[hookName].sequential) {
|
|
22743
|
+
await Promise.all(parallelPromises);
|
|
22744
|
+
parallelPromises.length = 0;
|
|
22745
|
+
await this.runHook(hookName, args, plugin, replaceContext);
|
|
22746
|
+
}
|
|
22747
|
+
else {
|
|
22748
|
+
parallelPromises.push(this.runHook(hookName, args, plugin, replaceContext));
|
|
22749
|
+
}
|
|
22718
22750
|
}
|
|
22719
|
-
|
|
22751
|
+
await Promise.all(parallelPromises);
|
|
22720
22752
|
}
|
|
22721
22753
|
// chains, reduces returned value, handling the reduced value as the first hook argument
|
|
22722
22754
|
hookReduceArg0(hookName, [arg0, ...rest], reduce, replaceContext) {
|
|
22723
22755
|
let promise = Promise.resolve(arg0);
|
|
22724
|
-
for (const plugin of this.
|
|
22725
|
-
promise = promise.then(arg0 =>
|
|
22726
|
-
const args = [arg0, ...rest];
|
|
22727
|
-
const hookPromise = this.runHook(hookName, args, plugin, false, replaceContext);
|
|
22728
|
-
if (!hookPromise)
|
|
22729
|
-
return arg0;
|
|
22730
|
-
return hookPromise.then(result => reduce.call(this.pluginContexts.get(plugin), arg0, result, plugin));
|
|
22731
|
-
});
|
|
22756
|
+
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
22757
|
+
promise = promise.then(arg0 => this.runHook(hookName, [arg0, ...rest], plugin, replaceContext).then(result => reduce.call(this.pluginContexts.get(plugin), arg0, result, plugin)));
|
|
22732
22758
|
}
|
|
22733
22759
|
return promise;
|
|
22734
22760
|
}
|
|
22735
22761
|
// chains synchronously, reduces returned value, handling the reduced value as the first hook argument
|
|
22736
22762
|
hookReduceArg0Sync(hookName, [arg0, ...rest], reduce, replaceContext) {
|
|
22737
|
-
for (const plugin of this.
|
|
22763
|
+
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
22738
22764
|
const args = [arg0, ...rest];
|
|
22739
22765
|
const result = this.runHookSync(hookName, args, plugin, replaceContext);
|
|
22740
22766
|
arg0 = reduce.call(this.pluginContexts.get(plugin), arg0, result, plugin);
|
|
22741
22767
|
}
|
|
22742
22768
|
return arg0;
|
|
22743
22769
|
}
|
|
22744
|
-
// chains, reduces returned value to type
|
|
22745
|
-
hookReduceValue(hookName, initialValue, args,
|
|
22746
|
-
|
|
22747
|
-
|
|
22748
|
-
|
|
22749
|
-
|
|
22750
|
-
|
|
22751
|
-
|
|
22752
|
-
|
|
22753
|
-
}
|
|
22770
|
+
// chains, reduces returned value to type string, handling the reduced value separately. permits hooks as values.
|
|
22771
|
+
async hookReduceValue(hookName, initialValue, args, reducer) {
|
|
22772
|
+
const results = [];
|
|
22773
|
+
const parallelResults = [];
|
|
22774
|
+
for (const plugin of this.getSortedPlugins(hookName, validateAddonPluginHandler)) {
|
|
22775
|
+
if (plugin[hookName].sequential) {
|
|
22776
|
+
results.push(...(await Promise.all(parallelResults)));
|
|
22777
|
+
parallelResults.length = 0;
|
|
22778
|
+
results.push(await this.runHook(hookName, args, plugin));
|
|
22779
|
+
}
|
|
22780
|
+
else {
|
|
22781
|
+
parallelResults.push(this.runHook(hookName, args, plugin));
|
|
22782
|
+
}
|
|
22754
22783
|
}
|
|
22755
|
-
|
|
22784
|
+
results.push(...(await Promise.all(parallelResults)));
|
|
22785
|
+
return results.reduce(reducer, await initialValue);
|
|
22756
22786
|
}
|
|
22757
22787
|
// chains synchronously, reduces returned value to type T, handling the reduced value separately. permits hooks as values.
|
|
22758
22788
|
hookReduceValueSync(hookName, initialValue, args, reduce, replaceContext) {
|
|
22759
22789
|
let acc = initialValue;
|
|
22760
|
-
for (const plugin of this.
|
|
22790
|
+
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
22761
22791
|
const result = this.runHookSync(hookName, args, plugin, replaceContext);
|
|
22762
22792
|
acc = reduce.call(this.pluginContexts.get(plugin), acc, result, plugin);
|
|
22763
22793
|
}
|
|
@@ -22766,31 +22796,32 @@ class PluginDriver {
|
|
|
22766
22796
|
// chains, ignores returns
|
|
22767
22797
|
hookSeq(hookName, args, replaceContext) {
|
|
22768
22798
|
let promise = Promise.resolve();
|
|
22769
|
-
for (const plugin of this.
|
|
22770
|
-
promise = promise.then(() => this.runHook(hookName, args, plugin,
|
|
22799
|
+
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
22800
|
+
promise = promise.then(() => this.runHook(hookName, args, plugin, replaceContext));
|
|
22771
22801
|
}
|
|
22772
|
-
return promise;
|
|
22802
|
+
return promise.then(noReturn);
|
|
22803
|
+
}
|
|
22804
|
+
getSortedPlugins(hookName, validateHandler) {
|
|
22805
|
+
return getOrCreate(this.sortedPlugins, hookName, () => getSortedValidatedPlugins(hookName, this.plugins, validateHandler));
|
|
22773
22806
|
}
|
|
22774
|
-
|
|
22807
|
+
// Implementation signature
|
|
22808
|
+
runHook(hookName, args, plugin, replaceContext) {
|
|
22809
|
+
// We always filter for plugins that support the hook before running it
|
|
22775
22810
|
const hook = plugin[hookName];
|
|
22776
|
-
|
|
22777
|
-
return undefined;
|
|
22811
|
+
const handler = typeof hook === 'object' ? hook.handler : hook;
|
|
22778
22812
|
let context = this.pluginContexts.get(plugin);
|
|
22779
|
-
if (
|
|
22780
|
-
context =
|
|
22813
|
+
if (replaceContext) {
|
|
22814
|
+
context = replaceContext(context, plugin);
|
|
22781
22815
|
}
|
|
22782
22816
|
let action = null;
|
|
22783
22817
|
return Promise.resolve()
|
|
22784
22818
|
.then(() => {
|
|
22785
|
-
|
|
22786
|
-
|
|
22787
|
-
if (permitValues)
|
|
22788
|
-
return hook;
|
|
22789
|
-
return error(errInvalidPluginHook(hookName, plugin.name));
|
|
22819
|
+
if (typeof handler !== 'function') {
|
|
22820
|
+
return handler;
|
|
22790
22821
|
}
|
|
22791
22822
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
22792
|
-
const hookResult =
|
|
22793
|
-
if (!hookResult ||
|
|
22823
|
+
const hookResult = handler.apply(context, args);
|
|
22824
|
+
if (!(hookResult === null || hookResult === void 0 ? void 0 : hookResult.then)) {
|
|
22794
22825
|
// short circuit for non-thenables and non-Promises
|
|
22795
22826
|
return hookResult;
|
|
22796
22827
|
}
|
|
@@ -22823,29 +22854,61 @@ class PluginDriver {
|
|
|
22823
22854
|
* @param hookName Name of the plugin hook. Must be in `PluginHooks`.
|
|
22824
22855
|
* @param args Arguments passed to the plugin hook.
|
|
22825
22856
|
* @param plugin The acutal plugin
|
|
22826
|
-
* @param
|
|
22857
|
+
* @param replaceContext When passed, the plugin context can be overridden.
|
|
22827
22858
|
*/
|
|
22828
|
-
runHookSync(hookName, args, plugin,
|
|
22859
|
+
runHookSync(hookName, args, plugin, replaceContext) {
|
|
22829
22860
|
const hook = plugin[hookName];
|
|
22830
|
-
|
|
22831
|
-
return undefined;
|
|
22861
|
+
const handler = typeof hook === 'object' ? hook.handler : hook;
|
|
22832
22862
|
let context = this.pluginContexts.get(plugin);
|
|
22833
|
-
if (
|
|
22834
|
-
context =
|
|
22863
|
+
if (replaceContext) {
|
|
22864
|
+
context = replaceContext(context, plugin);
|
|
22835
22865
|
}
|
|
22836
22866
|
try {
|
|
22837
|
-
// permit values allows values to be returned instead of a functional hook
|
|
22838
|
-
if (typeof hook !== 'function') {
|
|
22839
|
-
return error(errInvalidPluginHook(hookName, plugin.name));
|
|
22840
|
-
}
|
|
22841
22867
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
22842
|
-
return
|
|
22868
|
+
return handler.apply(context, args);
|
|
22843
22869
|
}
|
|
22844
22870
|
catch (err) {
|
|
22845
22871
|
return error(errPluginError(err, plugin.name, { hook: hookName }));
|
|
22846
22872
|
}
|
|
22847
22873
|
}
|
|
22848
22874
|
}
|
|
22875
|
+
function getSortedValidatedPlugins(hookName, plugins, validateHandler = validateFunctionPluginHandler) {
|
|
22876
|
+
const pre = [];
|
|
22877
|
+
const normal = [];
|
|
22878
|
+
const post = [];
|
|
22879
|
+
for (const plugin of plugins) {
|
|
22880
|
+
const hook = plugin[hookName];
|
|
22881
|
+
if (hook) {
|
|
22882
|
+
if (typeof hook === 'object') {
|
|
22883
|
+
validateHandler(hook.handler, hookName, plugin);
|
|
22884
|
+
if (hook.order === 'pre') {
|
|
22885
|
+
pre.push(plugin);
|
|
22886
|
+
continue;
|
|
22887
|
+
}
|
|
22888
|
+
if (hook.order === 'post') {
|
|
22889
|
+
post.push(plugin);
|
|
22890
|
+
continue;
|
|
22891
|
+
}
|
|
22892
|
+
}
|
|
22893
|
+
else {
|
|
22894
|
+
validateHandler(hook, hookName, plugin);
|
|
22895
|
+
}
|
|
22896
|
+
normal.push(plugin);
|
|
22897
|
+
}
|
|
22898
|
+
}
|
|
22899
|
+
return [...pre, ...normal, ...post];
|
|
22900
|
+
}
|
|
22901
|
+
function validateFunctionPluginHandler(handler, hookName, plugin) {
|
|
22902
|
+
if (typeof handler !== 'function') {
|
|
22903
|
+
error(errInvalidFunctionPluginHook(hookName, plugin.name));
|
|
22904
|
+
}
|
|
22905
|
+
}
|
|
22906
|
+
function validateAddonPluginHandler(handler, hookName, plugin) {
|
|
22907
|
+
if (typeof handler !== 'string' && typeof handler !== 'function') {
|
|
22908
|
+
return error(errInvalidAddonPluginHook(hookName, plugin.name));
|
|
22909
|
+
}
|
|
22910
|
+
}
|
|
22911
|
+
function noReturn() { }
|
|
22849
22912
|
|
|
22850
22913
|
class Queue {
|
|
22851
22914
|
constructor(maxParallel) {
|
|
@@ -23754,17 +23817,15 @@ async function getInputOptions(rawInputOptions, watchMode) {
|
|
|
23754
23817
|
if (!rawInputOptions) {
|
|
23755
23818
|
throw new Error('You must supply an options object to rollup');
|
|
23756
23819
|
}
|
|
23757
|
-
const rawPlugins = ensureArray(rawInputOptions.plugins);
|
|
23820
|
+
const rawPlugins = getSortedValidatedPlugins('options', ensureArray(rawInputOptions.plugins));
|
|
23758
23821
|
const { options, unsetOptions } = normalizeInputOptions(await rawPlugins.reduce(applyOptionHook(watchMode), Promise.resolve(rawInputOptions)));
|
|
23759
23822
|
normalizePlugins(options.plugins, ANONYMOUS_PLUGIN_PREFIX);
|
|
23760
23823
|
return { options, unsetOptions };
|
|
23761
23824
|
}
|
|
23762
23825
|
function applyOptionHook(watchMode) {
|
|
23763
23826
|
return async (inputOptions, plugin) => {
|
|
23764
|
-
|
|
23765
|
-
|
|
23766
|
-
}
|
|
23767
|
-
return inputOptions;
|
|
23827
|
+
const handler = 'handler' in plugin.options ? plugin.options.handler : plugin.options;
|
|
23828
|
+
return ((await handler.call({ meta: { rollupVersion: version$1, watchMode } }, await inputOptions)) || inputOptions);
|
|
23768
23829
|
};
|
|
23769
23830
|
}
|
|
23770
23831
|
function normalizePlugins(plugins, anonymousPrefix) {
|
|
@@ -23843,32 +23904,7 @@ async function writeOutputFile(outputFile, outputOptions) {
|
|
|
23843
23904
|
const fileName = resolve(outputOptions.dir || dirname(outputOptions.file), outputFile.fileName);
|
|
23844
23905
|
// 'recursive: true' does not throw if the folder structure, or parts of it, already exist
|
|
23845
23906
|
await promises.mkdir(dirname(fileName), { recursive: true });
|
|
23846
|
-
|
|
23847
|
-
let source;
|
|
23848
|
-
if (outputFile.type === 'asset') {
|
|
23849
|
-
source = outputFile.source;
|
|
23850
|
-
}
|
|
23851
|
-
else {
|
|
23852
|
-
source = outputFile.code;
|
|
23853
|
-
if (outputOptions.sourcemap && outputFile.map) {
|
|
23854
|
-
let url;
|
|
23855
|
-
if (outputOptions.sourcemap === 'inline') {
|
|
23856
|
-
url = outputFile.map.toUrl();
|
|
23857
|
-
}
|
|
23858
|
-
else {
|
|
23859
|
-
const { sourcemapBaseUrl } = outputOptions;
|
|
23860
|
-
const sourcemapFileName = `${basename(outputFile.fileName)}.map`;
|
|
23861
|
-
url = sourcemapBaseUrl
|
|
23862
|
-
? new URL(sourcemapFileName, sourcemapBaseUrl).toString()
|
|
23863
|
-
: sourcemapFileName;
|
|
23864
|
-
writeSourceMapPromise = promises.writeFile(`${fileName}.map`, outputFile.map.toString());
|
|
23865
|
-
}
|
|
23866
|
-
if (outputOptions.sourcemap !== 'hidden') {
|
|
23867
|
-
source += `//# ${SOURCEMAPPING_URL}=${url}\n`;
|
|
23868
|
-
}
|
|
23869
|
-
}
|
|
23870
|
-
}
|
|
23871
|
-
return Promise.all([promises.writeFile(fileName, source), writeSourceMapPromise]);
|
|
23907
|
+
return promises.writeFile(fileName, outputFile.type === 'asset' ? outputFile.source : outputFile.code);
|
|
23872
23908
|
}
|
|
23873
23909
|
/**
|
|
23874
23910
|
* Auxiliary function for defining rollup configuration
|