454 lines
16 KiB
JavaScript
454 lines
16 KiB
JavaScript
|
/*
|
||
|
@license
|
||
|
Rollup.js v2.3.3
|
||
|
Sat, 04 Apr 2020 22:17:48 GMT - commit d18cb37d7c328a63c36761583ce456275f164462
|
||
|
|
||
|
|
||
|
https://github.com/rollup/rollup
|
||
|
|
||
|
Released under the MIT License.
|
||
|
*/
|
||
|
'use strict';
|
||
|
|
||
|
var rollup_js = require('./rollup.js');
|
||
|
var path = require('path');
|
||
|
|
||
|
let enabled =
|
||
|
!("NO_COLOR" in process.env) &&
|
||
|
process.env.FORCE_COLOR !== "0" &&
|
||
|
(process.platform === "win32" ||
|
||
|
(process.stdout != null &&
|
||
|
process.stdout.isTTY &&
|
||
|
process.env.TERM &&
|
||
|
process.env.TERM !== "dumb"));
|
||
|
|
||
|
const rawInit = (open, close, searchRegex, replaceValue) => s =>
|
||
|
enabled
|
||
|
? open +
|
||
|
(~(s += "").indexOf(close, 4) // skip opening \x1b[
|
||
|
? s.replace(searchRegex, replaceValue)
|
||
|
: s) +
|
||
|
close
|
||
|
: s;
|
||
|
|
||
|
const init = (open, close) => {
|
||
|
return rawInit(
|
||
|
`\x1b[${open}m`,
|
||
|
`\x1b[${close}m`,
|
||
|
new RegExp(`\\x1b\\[${close}m`, "g"),
|
||
|
`\x1b[${open}m`
|
||
|
)
|
||
|
};
|
||
|
|
||
|
var colorette = {
|
||
|
options: Object.defineProperty({}, "enabled", {
|
||
|
get: () => enabled,
|
||
|
set: value => (enabled = value)
|
||
|
}),
|
||
|
reset: init(0, 0),
|
||
|
bold: rawInit("\x1b[1m", "\x1b[22m", /\x1b\[22m/g, "\x1b[22m\x1b[1m"),
|
||
|
dim: rawInit("\x1b[2m", "\x1b[22m", /\x1b\[22m/g, "\x1b[22m\x1b[2m"),
|
||
|
italic: init(3, 23),
|
||
|
underline: init(4, 24),
|
||
|
inverse: init(7, 27),
|
||
|
hidden: init(8, 28),
|
||
|
strikethrough: init(9, 29),
|
||
|
black: init(30, 39),
|
||
|
red: init(31, 39),
|
||
|
green: init(32, 39),
|
||
|
yellow: init(33, 39),
|
||
|
blue: init(34, 39),
|
||
|
magenta: init(35, 39),
|
||
|
cyan: init(36, 39),
|
||
|
white: init(37, 39),
|
||
|
gray: init(90, 39),
|
||
|
bgBlack: init(40, 49),
|
||
|
bgRed: init(41, 49),
|
||
|
bgGreen: init(42, 49),
|
||
|
bgYellow: init(43, 49),
|
||
|
bgBlue: init(44, 49),
|
||
|
bgMagenta: init(45, 49),
|
||
|
bgCyan: init(46, 49),
|
||
|
bgWhite: init(47, 49),
|
||
|
blackBright: init(90, 39),
|
||
|
redBright: init(91, 39),
|
||
|
greenBright: init(92, 39),
|
||
|
yellowBright: init(93, 39),
|
||
|
blueBright: init(94, 39),
|
||
|
magentaBright: init(95, 39),
|
||
|
cyanBright: init(96, 39),
|
||
|
whiteBright: init(97, 39),
|
||
|
bgBlackBright: init(100, 49),
|
||
|
bgRedBright: init(101, 49),
|
||
|
bgGreenBright: init(102, 49),
|
||
|
bgYellowBright: init(103, 49),
|
||
|
bgBlueBright: init(104, 49),
|
||
|
bgMagentaBright: init(105, 49),
|
||
|
bgCyanBright: init(106, 49),
|
||
|
bgWhiteBright: init(107, 49)
|
||
|
};
|
||
|
|
||
|
// @see https://no-color.org
|
||
|
// @see https://www.npmjs.com/package/chalk
|
||
|
if (process.env.FORCE_COLOR === '0' || process.env.NO_COLOR) {
|
||
|
colorette.options.enabled = false;
|
||
|
}
|
||
|
// log to stderr to keep `rollup main.js > bundle.js` from breaking
|
||
|
const stderr = console.error.bind(console);
|
||
|
function handleError(err, recover = false) {
|
||
|
let description = err.message || err;
|
||
|
if (err.name)
|
||
|
description = `${err.name}: ${description}`;
|
||
|
const message = (err.plugin
|
||
|
? `(plugin ${(err).plugin}) ${description}`
|
||
|
: description) || err;
|
||
|
stderr(colorette.bold(colorette.red(`[!] ${colorette.bold(message.toString())}`)));
|
||
|
if (err.url) {
|
||
|
stderr(colorette.cyan(err.url));
|
||
|
}
|
||
|
if (err.loc) {
|
||
|
stderr(`${rollup_js.relativeId((err.loc.file || err.id))} (${err.loc.line}:${err.loc.column})`);
|
||
|
}
|
||
|
else if (err.id) {
|
||
|
stderr(rollup_js.relativeId(err.id));
|
||
|
}
|
||
|
if (err.frame) {
|
||
|
stderr(colorette.dim(err.frame));
|
||
|
}
|
||
|
if (err.stack) {
|
||
|
stderr(colorette.dim(err.stack));
|
||
|
}
|
||
|
stderr('');
|
||
|
if (!recover)
|
||
|
process.exit(1);
|
||
|
}
|
||
|
|
||
|
function batchWarnings() {
|
||
|
let deferredWarnings = new Map();
|
||
|
let count = 0;
|
||
|
return {
|
||
|
get count() {
|
||
|
return count;
|
||
|
},
|
||
|
add: (warning) => {
|
||
|
count += 1;
|
||
|
if (warning.code in deferredHandlers) {
|
||
|
if (!deferredWarnings.has(warning.code))
|
||
|
deferredWarnings.set(warning.code, []);
|
||
|
deferredWarnings.get(warning.code).push(warning);
|
||
|
}
|
||
|
else if (warning.code in immediateHandlers) {
|
||
|
immediateHandlers[warning.code](warning);
|
||
|
}
|
||
|
else {
|
||
|
title(warning.message);
|
||
|
if (warning.url)
|
||
|
info(warning.url);
|
||
|
const id = (warning.loc && warning.loc.file) || warning.id;
|
||
|
if (id) {
|
||
|
const loc = warning.loc
|
||
|
? `${rollup_js.relativeId(id)}: (${warning.loc.line}:${warning.loc.column})`
|
||
|
: rollup_js.relativeId(id);
|
||
|
stderr(colorette.bold(rollup_js.relativeId(loc)));
|
||
|
}
|
||
|
if (warning.frame)
|
||
|
info(warning.frame);
|
||
|
}
|
||
|
},
|
||
|
flush: () => {
|
||
|
if (count === 0)
|
||
|
return;
|
||
|
const codes = Array.from(deferredWarnings.keys()).sort((a, b) => deferredWarnings.get(b).length - deferredWarnings.get(a).length);
|
||
|
for (const code of codes) {
|
||
|
deferredHandlers[code](deferredWarnings.get(code));
|
||
|
}
|
||
|
deferredWarnings = new Map();
|
||
|
count = 0;
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
const immediateHandlers = {
|
||
|
UNKNOWN_OPTION: warning => {
|
||
|
title(`You have passed an unrecognized option`);
|
||
|
stderr(warning.message);
|
||
|
},
|
||
|
MISSING_NODE_BUILTINS: warning => {
|
||
|
title(`Missing shims for Node.js built-ins`);
|
||
|
const detail = warning.modules.length === 1
|
||
|
? `'${warning.modules[0]}'`
|
||
|
: `${warning
|
||
|
.modules.slice(0, -1)
|
||
|
.map((name) => `'${name}'`)
|
||
|
.join(', ')} and '${warning.modules.slice(-1)}'`;
|
||
|
stderr(`Creating a browser bundle that depends on ${detail}. You might need to include https://www.npmjs.com/package/rollup-plugin-node-builtins`);
|
||
|
}
|
||
|
};
|
||
|
const deferredHandlers = {
|
||
|
CIRCULAR_DEPENDENCY(warnings) {
|
||
|
title(`Circular dependenc${warnings.length > 1 ? 'ies' : 'y'}`);
|
||
|
const displayed = warnings.length > 5 ? warnings.slice(0, 3) : warnings;
|
||
|
for (const warning of displayed) {
|
||
|
stderr(warning.cycle.join(' -> '));
|
||
|
}
|
||
|
if (warnings.length > displayed.length) {
|
||
|
stderr(`...and ${warnings.length - displayed.length} more`);
|
||
|
}
|
||
|
},
|
||
|
EMPTY_BUNDLE(warnings) {
|
||
|
title(`Generated${warnings.length === 1 ? ' an' : ''} empty ${warnings.length > 1 ? 'chunks' : 'chunk'}`);
|
||
|
stderr(warnings.map(warning => warning.chunkName).join(', '));
|
||
|
},
|
||
|
EVAL(warnings) {
|
||
|
title('Use of eval is strongly discouraged');
|
||
|
info('https://rollupjs.org/guide/en/#avoiding-eval');
|
||
|
showTruncatedWarnings(warnings);
|
||
|
},
|
||
|
MISSING_EXPORT(warnings) {
|
||
|
title('Missing exports');
|
||
|
info('https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module');
|
||
|
for (const warning of warnings) {
|
||
|
stderr(colorette.bold(warning.importer));
|
||
|
stderr(`${warning.missing} is not exported by ${warning.exporter}`);
|
||
|
stderr(colorette.gray(warning.frame));
|
||
|
}
|
||
|
},
|
||
|
MISSING_GLOBAL_NAME(warnings) {
|
||
|
title(`Missing global variable ${warnings.length > 1 ? 'names' : 'name'}`);
|
||
|
stderr(`Use output.globals to specify browser global variable names corresponding to external modules`);
|
||
|
for (const warning of warnings) {
|
||
|
stderr(`${colorette.bold(warning.source)} (guessing '${warning.guess}')`);
|
||
|
}
|
||
|
},
|
||
|
MIXED_EXPORTS: (warnings) => {
|
||
|
title('Mixing named and default exports');
|
||
|
info(`https://rollupjs.org/guide/en/#output-exports`);
|
||
|
stderr(colorette.bold('The following entry modules are using named and default exports together:'));
|
||
|
const displayedWarnings = warnings.length > 5 ? warnings.slice(0, 3) : warnings;
|
||
|
for (const warning of displayedWarnings) {
|
||
|
stderr(rollup_js.relativeId(warning.id));
|
||
|
}
|
||
|
if (displayedWarnings.length < warnings.length) {
|
||
|
stderr(`...and ${warnings.length - displayedWarnings.length} other entry modules`);
|
||
|
}
|
||
|
stderr(`\nConsumers of your bundle will have to use chunk['default'] to access their default export, which may not be what you want. Use \`output.exports: 'named'\` to disable this warning`);
|
||
|
},
|
||
|
NAMESPACE_CONFLICT(warnings) {
|
||
|
title(`Conflicting re-exports`);
|
||
|
for (const warning of warnings) {
|
||
|
stderr(`${colorette.bold(rollup_js.relativeId(warning.reexporter))} re-exports '${warning.name}' from both ${rollup_js.relativeId(warning.sources[0])} and ${rollup_js.relativeId(warning.sources[1])} (will be ignored)`);
|
||
|
}
|
||
|
},
|
||
|
NON_EXISTENT_EXPORT(warnings) {
|
||
|
title(`Import of non-existent ${warnings.length > 1 ? 'exports' : 'export'}`);
|
||
|
showTruncatedWarnings(warnings);
|
||
|
},
|
||
|
PLUGIN_WARNING(warnings) {
|
||
|
const nestedByPlugin = nest(warnings, 'plugin');
|
||
|
for (const { key: plugin, items } of nestedByPlugin) {
|
||
|
const nestedByMessage = nest(items, 'message');
|
||
|
let lastUrl = '';
|
||
|
for (const { key: message, items } of nestedByMessage) {
|
||
|
title(`Plugin ${plugin}: ${message}`);
|
||
|
for (const warning of items) {
|
||
|
if (warning.url && warning.url !== lastUrl)
|
||
|
info((lastUrl = warning.url));
|
||
|
if (warning.id) {
|
||
|
let loc = rollup_js.relativeId(warning.id);
|
||
|
if (warning.loc) {
|
||
|
loc += `: (${warning.loc.line}:${warning.loc.column})`;
|
||
|
}
|
||
|
stderr(colorette.bold(loc));
|
||
|
}
|
||
|
if (warning.frame)
|
||
|
info(warning.frame);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
SOURCEMAP_BROKEN(warnings) {
|
||
|
title(`Broken sourcemap`);
|
||
|
info('https://rollupjs.org/guide/en/#warning-sourcemap-is-likely-to-be-incorrect');
|
||
|
const plugins = Array.from(new Set(warnings.map(w => w.plugin).filter(Boolean)));
|
||
|
const detail = plugins.length > 1
|
||
|
? ` (such as ${plugins
|
||
|
.slice(0, -1)
|
||
|
.map(p => `'${p}'`)
|
||
|
.join(', ')} and '${plugins.slice(-1)}')`
|
||
|
: ` (such as '${plugins[0]}')`;
|
||
|
stderr(`Plugins that transform code${detail} should generate accompanying sourcemaps`);
|
||
|
},
|
||
|
THIS_IS_UNDEFINED(warnings) {
|
||
|
title('`this` has been rewritten to `undefined`');
|
||
|
info('https://rollupjs.org/guide/en/#error-this-is-undefined');
|
||
|
showTruncatedWarnings(warnings);
|
||
|
},
|
||
|
UNRESOLVED_IMPORT(warnings) {
|
||
|
title('Unresolved dependencies');
|
||
|
info('https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency');
|
||
|
const dependencies = new Map();
|
||
|
for (const warning of warnings) {
|
||
|
if (!dependencies.has(warning.source))
|
||
|
dependencies.set(warning.source, []);
|
||
|
dependencies.get(warning.source).push(warning.importer);
|
||
|
}
|
||
|
for (const dependency of dependencies.keys()) {
|
||
|
const importers = dependencies.get(dependency);
|
||
|
stderr(`${colorette.bold(dependency)} (imported by ${importers.join(', ')})`);
|
||
|
}
|
||
|
},
|
||
|
UNUSED_EXTERNAL_IMPORT(warnings) {
|
||
|
title('Unused external imports');
|
||
|
for (const warning of warnings) {
|
||
|
stderr(`${warning.names} imported from external module '${warning.source}' but never used`);
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
function title(str) {
|
||
|
stderr(colorette.bold(colorette.yellow(`(!) ${str}`)));
|
||
|
}
|
||
|
function info(url) {
|
||
|
stderr(colorette.gray(url));
|
||
|
}
|
||
|
function nest(array, prop) {
|
||
|
const nested = [];
|
||
|
const lookup = new Map();
|
||
|
for (const item of array) {
|
||
|
const key = item[prop];
|
||
|
if (!lookup.has(key)) {
|
||
|
lookup.set(key, {
|
||
|
items: [],
|
||
|
key
|
||
|
});
|
||
|
nested.push(lookup.get(key));
|
||
|
}
|
||
|
lookup.get(key).items.push(item);
|
||
|
}
|
||
|
return nested;
|
||
|
}
|
||
|
function showTruncatedWarnings(warnings) {
|
||
|
const nestedByModule = nest(warnings, 'id');
|
||
|
const displayedByModule = nestedByModule.length > 5 ? nestedByModule.slice(0, 3) : nestedByModule;
|
||
|
for (const { key: id, items } of displayedByModule) {
|
||
|
stderr(colorette.bold(rollup_js.relativeId(id)));
|
||
|
stderr(colorette.gray(items[0].frame));
|
||
|
if (items.length > 1) {
|
||
|
stderr(`...and ${items.length - 1} other ${items.length > 2 ? 'occurrences' : 'occurrence'}`);
|
||
|
}
|
||
|
}
|
||
|
if (nestedByModule.length > displayedByModule.length) {
|
||
|
stderr(`\n...and ${nestedByModule.length - displayedByModule.length} other files`);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
const stdinName = '-';
|
||
|
let stdinResult = null;
|
||
|
function stdinPlugin() {
|
||
|
return {
|
||
|
name: 'stdin',
|
||
|
resolveId(id) {
|
||
|
if (id === stdinName) {
|
||
|
return id;
|
||
|
}
|
||
|
},
|
||
|
load(id) {
|
||
|
if (id === stdinName) {
|
||
|
return stdinResult || (stdinResult = readStdin());
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
function readStdin() {
|
||
|
return new Promise((resolve, reject) => {
|
||
|
const chunks = [];
|
||
|
process.stdin.setEncoding('utf8');
|
||
|
process.stdin
|
||
|
.on('data', chunk => chunks.push(chunk))
|
||
|
.on('end', () => {
|
||
|
const result = chunks.join('');
|
||
|
resolve(result);
|
||
|
})
|
||
|
.on('error', err => {
|
||
|
reject(err);
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
|
||
|
function addCommandPluginsToInputOptions(inputOptions, command) {
|
||
|
if (command.stdin !== false) {
|
||
|
inputOptions.plugins.push(stdinPlugin());
|
||
|
}
|
||
|
const commandPlugin = command.plugin;
|
||
|
if (commandPlugin) {
|
||
|
const plugins = Array.isArray(commandPlugin) ? commandPlugin : [commandPlugin];
|
||
|
for (const plugin of plugins) {
|
||
|
if (/[={}]/.test(plugin)) {
|
||
|
// -p plugin=value
|
||
|
// -p "{transform(c,i){...}}"
|
||
|
loadAndRegisterPlugin(inputOptions, plugin);
|
||
|
}
|
||
|
else {
|
||
|
// split out plugins joined by commas
|
||
|
// -p node-resolve,commonjs,buble
|
||
|
plugin.split(',').forEach((plugin) => loadAndRegisterPlugin(inputOptions, plugin));
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
function loadAndRegisterPlugin(inputOptions, pluginText) {
|
||
|
let plugin = null;
|
||
|
let pluginArg = undefined;
|
||
|
if (pluginText[0] === '{') {
|
||
|
// -p "{transform(c,i){...}}"
|
||
|
plugin = new Function('return ' + pluginText);
|
||
|
}
|
||
|
else {
|
||
|
const match = pluginText.match(/^([@.\/\\\w|^{}|-]+)(=(.*))?$/);
|
||
|
if (match) {
|
||
|
// -p plugin
|
||
|
// -p plugin=arg
|
||
|
pluginText = match[1];
|
||
|
pluginArg = new Function('return ' + match[3])();
|
||
|
}
|
||
|
else {
|
||
|
throw new Error(`Invalid --plugin argument format: ${JSON.stringify(pluginText)}`);
|
||
|
}
|
||
|
if (!/^\.|^rollup-plugin-|[@\/\\]/.test(pluginText)) {
|
||
|
// Try using plugin prefix variations first if applicable.
|
||
|
// Prefix order is significant - left has higher precedence.
|
||
|
for (const prefix of ['@rollup/plugin-', 'rollup-plugin-']) {
|
||
|
try {
|
||
|
plugin = require(prefix + pluginText);
|
||
|
break;
|
||
|
}
|
||
|
catch (ex) {
|
||
|
// if this does not work, we try requiring the actual name below
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
if (!plugin) {
|
||
|
try {
|
||
|
if (pluginText[0] == '.')
|
||
|
pluginText = path.resolve(pluginText);
|
||
|
plugin = require(pluginText);
|
||
|
}
|
||
|
catch (ex) {
|
||
|
throw new Error(`Cannot load plugin "${pluginText}"`);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
if (typeof plugin === 'object' && pluginText in plugin) {
|
||
|
// some plugins do not use `export default` for their entry point.
|
||
|
// attempt to use the plugin name as the named import name.
|
||
|
plugin = plugin[pluginText];
|
||
|
}
|
||
|
inputOptions.plugins.push(typeof plugin === 'function' ? plugin.call(plugin, pluginArg) : plugin);
|
||
|
}
|
||
|
|
||
|
exports.addCommandPluginsToInputOptions = addCommandPluginsToInputOptions;
|
||
|
exports.batchWarnings = batchWarnings;
|
||
|
exports.color = colorette;
|
||
|
exports.handleError = handleError;
|
||
|
exports.stderr = stderr;
|
||
|
exports.stdinName = stdinName;
|
||
|
//# sourceMappingURL=commandPlugins.js.map
|