1 | /*
|
---|
2 | @license
|
---|
3 | Rollup.js v4.20.0
|
---|
4 | Sat, 03 Aug 2024 04:48:21 GMT - commit df12edfea6e9c1a71bda1a01bed1ab787b7514d5
|
---|
5 |
|
---|
6 | https://github.com/rollup/rollup
|
---|
7 |
|
---|
8 | Released under the MIT License.
|
---|
9 | */
|
---|
10 | 'use strict';
|
---|
11 |
|
---|
12 | const promises = require('node:fs/promises');
|
---|
13 | const path = require('node:path');
|
---|
14 | const process$1 = require('node:process');
|
---|
15 | const node_url = require('node:url');
|
---|
16 | const rollup = require('./rollup.js');
|
---|
17 | const parseAst_js = require('./parseAst.js');
|
---|
18 | const getLogFilter_js = require('../getLogFilter.js');
|
---|
19 |
|
---|
20 | function batchWarnings(command) {
|
---|
21 | const silent = !!command.silent;
|
---|
22 | const logFilter = generateLogFilter(command);
|
---|
23 | let count = 0;
|
---|
24 | const deferredWarnings = new Map();
|
---|
25 | let warningOccurred = false;
|
---|
26 | const add = (warning) => {
|
---|
27 | count += 1;
|
---|
28 | warningOccurred = true;
|
---|
29 | if (silent)
|
---|
30 | return;
|
---|
31 | if (warning.code in deferredHandlers) {
|
---|
32 | rollup.getOrCreate(deferredWarnings, warning.code, rollup.getNewArray).push(warning);
|
---|
33 | }
|
---|
34 | else if (warning.code in immediateHandlers) {
|
---|
35 | immediateHandlers[warning.code](warning);
|
---|
36 | }
|
---|
37 | else {
|
---|
38 | title(warning.message);
|
---|
39 | defaultBody(warning);
|
---|
40 | }
|
---|
41 | };
|
---|
42 | return {
|
---|
43 | add,
|
---|
44 | get count() {
|
---|
45 | return count;
|
---|
46 | },
|
---|
47 | flush() {
|
---|
48 | if (count === 0 || silent)
|
---|
49 | return;
|
---|
50 | const codes = [...deferredWarnings.keys()].sort((a, b) => deferredWarnings.get(b).length - deferredWarnings.get(a).length);
|
---|
51 | for (const code of codes) {
|
---|
52 | deferredHandlers[code](deferredWarnings.get(code));
|
---|
53 | }
|
---|
54 | deferredWarnings.clear();
|
---|
55 | count = 0;
|
---|
56 | },
|
---|
57 | log(level, log) {
|
---|
58 | if (!logFilter(log))
|
---|
59 | return;
|
---|
60 | switch (level) {
|
---|
61 | case parseAst_js.LOGLEVEL_WARN: {
|
---|
62 | return add(log);
|
---|
63 | }
|
---|
64 | case parseAst_js.LOGLEVEL_DEBUG: {
|
---|
65 | if (!silent) {
|
---|
66 | rollup.stderr(rollup.bold(rollup.blue(log.message)));
|
---|
67 | defaultBody(log);
|
---|
68 | }
|
---|
69 | return;
|
---|
70 | }
|
---|
71 | default: {
|
---|
72 | if (!silent) {
|
---|
73 | rollup.stderr(rollup.bold(rollup.cyan(log.message)));
|
---|
74 | defaultBody(log);
|
---|
75 | }
|
---|
76 | }
|
---|
77 | }
|
---|
78 | },
|
---|
79 | get warningOccurred() {
|
---|
80 | return warningOccurred;
|
---|
81 | }
|
---|
82 | };
|
---|
83 | }
|
---|
84 | const immediateHandlers = {
|
---|
85 | MISSING_NODE_BUILTINS(warning) {
|
---|
86 | title(`Missing shims for Node.js built-ins`);
|
---|
87 | rollup.stderr(`Creating a browser bundle that depends on ${parseAst_js.printQuotedStringList(warning.ids)}. You might need to include https://github.com/FredKSchott/rollup-plugin-polyfill-node`);
|
---|
88 | },
|
---|
89 | UNKNOWN_OPTION(warning) {
|
---|
90 | title(`You have passed an unrecognized option`);
|
---|
91 | rollup.stderr(warning.message);
|
---|
92 | }
|
---|
93 | };
|
---|
94 | const deferredHandlers = {
|
---|
95 | CIRCULAR_DEPENDENCY(warnings) {
|
---|
96 | title(`Circular dependenc${warnings.length > 1 ? 'ies' : 'y'}`);
|
---|
97 | const displayed = warnings.length > 5 ? warnings.slice(0, 3) : warnings;
|
---|
98 | for (const warning of displayed) {
|
---|
99 | rollup.stderr(warning.ids.map(parseAst_js.relativeId).join(' -> '));
|
---|
100 | }
|
---|
101 | if (warnings.length > displayed.length) {
|
---|
102 | rollup.stderr(`...and ${warnings.length - displayed.length} more`);
|
---|
103 | }
|
---|
104 | },
|
---|
105 | EMPTY_BUNDLE(warnings) {
|
---|
106 | title(`Generated${warnings.length === 1 ? ' an' : ''} empty ${warnings.length > 1 ? 'chunks' : 'chunk'}`);
|
---|
107 | rollup.stderr(parseAst_js.printQuotedStringList(warnings.map(warning => warning.names[0])));
|
---|
108 | },
|
---|
109 | EVAL(warnings) {
|
---|
110 | title('Use of eval is strongly discouraged');
|
---|
111 | info(parseAst_js.getRollupUrl(parseAst_js.URL_AVOIDING_EVAL));
|
---|
112 | showTruncatedWarnings(warnings);
|
---|
113 | },
|
---|
114 | MISSING_EXPORT(warnings) {
|
---|
115 | title('Missing exports');
|
---|
116 | info(parseAst_js.getRollupUrl(parseAst_js.URL_NAME_IS_NOT_EXPORTED));
|
---|
117 | for (const warning of warnings) {
|
---|
118 | rollup.stderr(rollup.bold(parseAst_js.relativeId(warning.id)));
|
---|
119 | rollup.stderr(`${warning.binding} is not exported by ${parseAst_js.relativeId(warning.exporter)}`);
|
---|
120 | rollup.stderr(rollup.gray(warning.frame));
|
---|
121 | }
|
---|
122 | },
|
---|
123 | MISSING_GLOBAL_NAME(warnings) {
|
---|
124 | title(`Missing global variable ${warnings.length > 1 ? 'names' : 'name'}`);
|
---|
125 | info(parseAst_js.getRollupUrl(parseAst_js.URL_OUTPUT_GLOBALS));
|
---|
126 | rollup.stderr(`Use "output.globals" to specify browser global variable names corresponding to external modules:`);
|
---|
127 | for (const warning of warnings) {
|
---|
128 | rollup.stderr(`${rollup.bold(warning.id)} (guessing "${warning.names[0]}")`);
|
---|
129 | }
|
---|
130 | },
|
---|
131 | MIXED_EXPORTS(warnings) {
|
---|
132 | title('Mixing named and default exports');
|
---|
133 | info(parseAst_js.getRollupUrl(parseAst_js.URL_OUTPUT_EXPORTS));
|
---|
134 | rollup.stderr(rollup.bold('The following entry modules are using named and default exports together:'));
|
---|
135 | warnings.sort((a, b) => (a.id < b.id ? -1 : 1));
|
---|
136 | const displayedWarnings = warnings.length > 5 ? warnings.slice(0, 3) : warnings;
|
---|
137 | for (const warning of displayedWarnings) {
|
---|
138 | rollup.stderr(parseAst_js.relativeId(warning.id));
|
---|
139 | }
|
---|
140 | if (displayedWarnings.length < warnings.length) {
|
---|
141 | rollup.stderr(`...and ${warnings.length - displayedWarnings.length} other entry modules`);
|
---|
142 | }
|
---|
143 | rollup.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.`);
|
---|
144 | },
|
---|
145 | NAMESPACE_CONFLICT(warnings) {
|
---|
146 | title(`Conflicting re-exports`);
|
---|
147 | for (const warning of warnings) {
|
---|
148 | rollup.stderr(`"${rollup.bold(parseAst_js.relativeId(warning.reexporter))}" re-exports "${warning.binding}" from both "${parseAst_js.relativeId(warning.ids[0])}" and "${parseAst_js.relativeId(warning.ids[1])}" (will be ignored).`);
|
---|
149 | }
|
---|
150 | },
|
---|
151 | PLUGIN_WARNING(warnings) {
|
---|
152 | const nestedByPlugin = nest(warnings, 'plugin');
|
---|
153 | for (const { items } of nestedByPlugin) {
|
---|
154 | const nestedByMessage = nest(items, 'message');
|
---|
155 | let lastUrl = '';
|
---|
156 | for (const { key: message, items } of nestedByMessage) {
|
---|
157 | title(message);
|
---|
158 | for (const warning of items) {
|
---|
159 | if (warning.url && warning.url !== lastUrl)
|
---|
160 | info((lastUrl = warning.url));
|
---|
161 | const loc = formatLocation(warning);
|
---|
162 | if (loc) {
|
---|
163 | rollup.stderr(rollup.bold(loc));
|
---|
164 | }
|
---|
165 | if (warning.frame)
|
---|
166 | info(warning.frame);
|
---|
167 | }
|
---|
168 | }
|
---|
169 | }
|
---|
170 | },
|
---|
171 | SOURCEMAP_BROKEN(warnings) {
|
---|
172 | title(`Broken sourcemap`);
|
---|
173 | info(parseAst_js.getRollupUrl(parseAst_js.URL_SOURCEMAP_IS_LIKELY_TO_BE_INCORRECT));
|
---|
174 | const plugins = [...new Set(warnings.map(({ plugin }) => plugin).filter(Boolean))];
|
---|
175 | rollup.stderr(`Plugins that transform code (such as ${parseAst_js.printQuotedStringList(plugins)}) should generate accompanying sourcemaps.`);
|
---|
176 | },
|
---|
177 | THIS_IS_UNDEFINED(warnings) {
|
---|
178 | title('"this" has been rewritten to "undefined"');
|
---|
179 | info(parseAst_js.getRollupUrl(parseAst_js.URL_THIS_IS_UNDEFINED));
|
---|
180 | showTruncatedWarnings(warnings);
|
---|
181 | },
|
---|
182 | UNRESOLVED_IMPORT(warnings) {
|
---|
183 | title('Unresolved dependencies');
|
---|
184 | info(parseAst_js.getRollupUrl(parseAst_js.URL_TREATING_MODULE_AS_EXTERNAL_DEPENDENCY));
|
---|
185 | const dependencies = new Map();
|
---|
186 | for (const warning of warnings) {
|
---|
187 | rollup.getOrCreate(dependencies, parseAst_js.relativeId(warning.exporter), rollup.getNewArray).push(parseAst_js.relativeId(warning.id));
|
---|
188 | }
|
---|
189 | for (const [dependency, importers] of dependencies) {
|
---|
190 | rollup.stderr(`${rollup.bold(dependency)} (imported by ${parseAst_js.printQuotedStringList(importers)})`);
|
---|
191 | }
|
---|
192 | },
|
---|
193 | UNUSED_EXTERNAL_IMPORT(warnings) {
|
---|
194 | title('Unused external imports');
|
---|
195 | for (const warning of warnings) {
|
---|
196 | rollup.stderr(warning.names +
|
---|
197 | ' imported from external module "' +
|
---|
198 | warning.exporter +
|
---|
199 | '" but never used in ' +
|
---|
200 | parseAst_js.printQuotedStringList(warning.ids.map(parseAst_js.relativeId)) +
|
---|
201 | '.');
|
---|
202 | }
|
---|
203 | }
|
---|
204 | };
|
---|
205 | function defaultBody(log) {
|
---|
206 | if (log.url) {
|
---|
207 | info(parseAst_js.getRollupUrl(log.url));
|
---|
208 | }
|
---|
209 | const loc = formatLocation(log);
|
---|
210 | if (loc) {
|
---|
211 | rollup.stderr(rollup.bold(loc));
|
---|
212 | }
|
---|
213 | if (log.frame)
|
---|
214 | info(log.frame);
|
---|
215 | }
|
---|
216 | function title(string_) {
|
---|
217 | rollup.stderr(rollup.bold(rollup.yellow(`(!) ${string_}`)));
|
---|
218 | }
|
---|
219 | function info(url) {
|
---|
220 | rollup.stderr(rollup.gray(url));
|
---|
221 | }
|
---|
222 | function nest(array, property) {
|
---|
223 | const nested = [];
|
---|
224 | const lookup = new Map();
|
---|
225 | for (const item of array) {
|
---|
226 | const key = item[property];
|
---|
227 | rollup.getOrCreate(lookup, key, () => {
|
---|
228 | const items = {
|
---|
229 | items: [],
|
---|
230 | key
|
---|
231 | };
|
---|
232 | nested.push(items);
|
---|
233 | return items;
|
---|
234 | }).items.push(item);
|
---|
235 | }
|
---|
236 | return nested;
|
---|
237 | }
|
---|
238 | function showTruncatedWarnings(warnings) {
|
---|
239 | const nestedByModule = nest(warnings, 'id');
|
---|
240 | const displayedByModule = nestedByModule.length > 5 ? nestedByModule.slice(0, 3) : nestedByModule;
|
---|
241 | for (const { key: id, items } of displayedByModule) {
|
---|
242 | rollup.stderr(rollup.bold(parseAst_js.relativeId(id)));
|
---|
243 | rollup.stderr(rollup.gray(items[0].frame));
|
---|
244 | if (items.length > 1) {
|
---|
245 | rollup.stderr(`...and ${items.length - 1} other ${items.length > 2 ? 'occurrences' : 'occurrence'}`);
|
---|
246 | }
|
---|
247 | }
|
---|
248 | if (nestedByModule.length > displayedByModule.length) {
|
---|
249 | rollup.stderr(`\n...and ${nestedByModule.length - displayedByModule.length} other files`);
|
---|
250 | }
|
---|
251 | }
|
---|
252 | function generateLogFilter(command) {
|
---|
253 | const filters = rollup.ensureArray(command.filterLogs).flatMap(filter => String(filter).split(','));
|
---|
254 | if (process.env.ROLLUP_FILTER_LOGS) {
|
---|
255 | filters.push(...process.env.ROLLUP_FILTER_LOGS.split(','));
|
---|
256 | }
|
---|
257 | return getLogFilter_js.getLogFilter(filters);
|
---|
258 | }
|
---|
259 | function formatLocation(log) {
|
---|
260 | const id = log.loc?.file || log.id;
|
---|
261 | if (!id)
|
---|
262 | return null;
|
---|
263 | return log.loc ? `${id}:${log.loc.line}:${log.loc.column}` : id;
|
---|
264 | }
|
---|
265 |
|
---|
266 | const stdinName = '-';
|
---|
267 | let stdinResult = null;
|
---|
268 | function stdinPlugin(argument) {
|
---|
269 | const suffix = typeof argument == 'string' && argument.length > 0 ? '.' + argument : '';
|
---|
270 | return {
|
---|
271 | load(id) {
|
---|
272 | if (id === stdinName || id.startsWith(stdinName + '.')) {
|
---|
273 | return stdinResult || (stdinResult = readStdin());
|
---|
274 | }
|
---|
275 | },
|
---|
276 | name: 'stdin',
|
---|
277 | resolveId(id) {
|
---|
278 | if (id === stdinName) {
|
---|
279 | return id + suffix;
|
---|
280 | }
|
---|
281 | }
|
---|
282 | };
|
---|
283 | }
|
---|
284 | function readStdin() {
|
---|
285 | return new Promise((resolve, reject) => {
|
---|
286 | const chunks = [];
|
---|
287 | process$1.stdin.setEncoding('utf8');
|
---|
288 | process$1.stdin
|
---|
289 | .on('data', chunk => chunks.push(chunk))
|
---|
290 | .on('end', () => {
|
---|
291 | const result = chunks.join('');
|
---|
292 | resolve(result);
|
---|
293 | })
|
---|
294 | .on('error', error => {
|
---|
295 | reject(error);
|
---|
296 | });
|
---|
297 | });
|
---|
298 | }
|
---|
299 |
|
---|
300 | function waitForInputPlugin() {
|
---|
301 | return {
|
---|
302 | async buildStart(options) {
|
---|
303 | const inputSpecifiers = Array.isArray(options.input)
|
---|
304 | ? options.input
|
---|
305 | : Object.keys(options.input);
|
---|
306 | let lastAwaitedSpecifier = null;
|
---|
307 | checkSpecifiers: while (true) {
|
---|
308 | for (const specifier of inputSpecifiers) {
|
---|
309 | if ((await this.resolve(specifier)) === null) {
|
---|
310 | if (lastAwaitedSpecifier !== specifier) {
|
---|
311 | rollup.stderr(`waiting for input ${rollup.bold(specifier)}...`);
|
---|
312 | lastAwaitedSpecifier = specifier;
|
---|
313 | }
|
---|
314 | await new Promise(resolve => setTimeout(resolve, 500));
|
---|
315 | continue checkSpecifiers;
|
---|
316 | }
|
---|
317 | }
|
---|
318 | break;
|
---|
319 | }
|
---|
320 | },
|
---|
321 | name: 'wait-for-input'
|
---|
322 | };
|
---|
323 | }
|
---|
324 |
|
---|
325 | async function addCommandPluginsToInputOptions(inputOptions, command) {
|
---|
326 | if (command.stdin !== false) {
|
---|
327 | inputOptions.plugins.push(stdinPlugin(command.stdin));
|
---|
328 | }
|
---|
329 | if (command.waitForBundleInput === true) {
|
---|
330 | inputOptions.plugins.push(waitForInputPlugin());
|
---|
331 | }
|
---|
332 | await addPluginsFromCommandOption(command.plugin, inputOptions);
|
---|
333 | }
|
---|
334 | async function addPluginsFromCommandOption(commandPlugin, inputOptions) {
|
---|
335 | if (commandPlugin) {
|
---|
336 | const plugins = await rollup.normalizePluginOption(commandPlugin);
|
---|
337 | for (const plugin of plugins) {
|
---|
338 | if (/[={}]/.test(plugin)) {
|
---|
339 | // -p plugin=value
|
---|
340 | // -p "{transform(c,i){...}}"
|
---|
341 | await loadAndRegisterPlugin(inputOptions, plugin);
|
---|
342 | }
|
---|
343 | else {
|
---|
344 | // split out plugins joined by commas
|
---|
345 | // -p node-resolve,commonjs,buble
|
---|
346 | for (const p of plugin.split(',')) {
|
---|
347 | await loadAndRegisterPlugin(inputOptions, p);
|
---|
348 | }
|
---|
349 | }
|
---|
350 | }
|
---|
351 | }
|
---|
352 | }
|
---|
353 | async function loadAndRegisterPlugin(inputOptions, pluginText) {
|
---|
354 | let plugin = null;
|
---|
355 | let pluginArgument = undefined;
|
---|
356 | if (pluginText[0] === '{') {
|
---|
357 | // -p "{transform(c,i){...}}"
|
---|
358 | plugin = new Function('return ' + pluginText);
|
---|
359 | }
|
---|
360 | else {
|
---|
361 | const match = pluginText.match(/^([\w./:@\\^{|}-]+)(=(.*))?$/);
|
---|
362 | if (match) {
|
---|
363 | // -p plugin
|
---|
364 | // -p plugin=arg
|
---|
365 | pluginText = match[1];
|
---|
366 | pluginArgument = new Function('return ' + match[3])();
|
---|
367 | }
|
---|
368 | else {
|
---|
369 | throw new Error(`Invalid --plugin argument format: ${JSON.stringify(pluginText)}`);
|
---|
370 | }
|
---|
371 | if (!/^\.|^rollup-plugin-|[/@\\]/.test(pluginText)) {
|
---|
372 | // Try using plugin prefix variations first if applicable.
|
---|
373 | // Prefix order is significant - left has higher precedence.
|
---|
374 | for (const prefix of ['@rollup/plugin-', 'rollup-plugin-']) {
|
---|
375 | try {
|
---|
376 | plugin = await requireOrImport(prefix + pluginText);
|
---|
377 | break;
|
---|
378 | }
|
---|
379 | catch {
|
---|
380 | // if this does not work, we try requiring the actual name below
|
---|
381 | }
|
---|
382 | }
|
---|
383 | }
|
---|
384 | if (!plugin) {
|
---|
385 | try {
|
---|
386 | if (pluginText[0] == '.')
|
---|
387 | pluginText = path.resolve(pluginText);
|
---|
388 | // Windows absolute paths must be specified as file:// protocol URL
|
---|
389 | // Note that we do not have coverage for Windows-only code paths
|
---|
390 | else if (/^[A-Za-z]:\\/.test(pluginText)) {
|
---|
391 | pluginText = node_url.pathToFileURL(path.resolve(pluginText)).href;
|
---|
392 | }
|
---|
393 | plugin = await requireOrImport(pluginText);
|
---|
394 | }
|
---|
395 | catch (error) {
|
---|
396 | throw new Error(`Cannot load plugin "${pluginText}": ${error.message}.`);
|
---|
397 | }
|
---|
398 | }
|
---|
399 | }
|
---|
400 | // some plugins do not use `module.exports` for their entry point,
|
---|
401 | // in which case we try the named default export and the plugin name
|
---|
402 | if (typeof plugin === 'object') {
|
---|
403 | plugin = plugin.default || plugin[getCamelizedPluginBaseName(pluginText)];
|
---|
404 | }
|
---|
405 | if (!plugin) {
|
---|
406 | throw new Error(`Cannot find entry for plugin "${pluginText}". The plugin needs to export a function either as "default" or "${getCamelizedPluginBaseName(pluginText)}" for Rollup to recognize it.`);
|
---|
407 | }
|
---|
408 | inputOptions.plugins.push(typeof plugin === 'function' ? plugin.call(plugin, pluginArgument) : plugin);
|
---|
409 | }
|
---|
410 | function getCamelizedPluginBaseName(pluginText) {
|
---|
411 | return (pluginText.match(/(@rollup\/plugin-|rollup-plugin-)(.+)$/)?.[2] || pluginText)
|
---|
412 | .split(/[/\\]/)
|
---|
413 | .slice(-1)[0]
|
---|
414 | .split('.')[0]
|
---|
415 | .split('-')
|
---|
416 | .map((part, index) => (index === 0 || !part ? part : part[0].toUpperCase() + part.slice(1)))
|
---|
417 | .join('');
|
---|
418 | }
|
---|
419 | async function requireOrImport(pluginPath) {
|
---|
420 | try {
|
---|
421 | // eslint-disable-next-line unicorn/prefer-module
|
---|
422 | return require(pluginPath);
|
---|
423 | }
|
---|
424 | catch {
|
---|
425 | return import(pluginPath);
|
---|
426 | }
|
---|
427 | }
|
---|
428 |
|
---|
429 | const loadConfigFile = async (fileName, commandOptions = {}, watchMode = false) => {
|
---|
430 | const configs = await getConfigList(getDefaultFromCjs(await getConfigFileExport(fileName, commandOptions, watchMode)), commandOptions);
|
---|
431 | const warnings = batchWarnings(commandOptions);
|
---|
432 | try {
|
---|
433 | const normalizedConfigs = [];
|
---|
434 | for (const config of configs) {
|
---|
435 | const options = await rollup.mergeOptions(config, watchMode, commandOptions, warnings.log);
|
---|
436 | await addCommandPluginsToInputOptions(options, commandOptions);
|
---|
437 | normalizedConfigs.push(options);
|
---|
438 | }
|
---|
439 | return { options: normalizedConfigs, warnings };
|
---|
440 | }
|
---|
441 | catch (error_) {
|
---|
442 | warnings.flush();
|
---|
443 | throw error_;
|
---|
444 | }
|
---|
445 | };
|
---|
446 | async function getConfigFileExport(fileName, commandOptions, watchMode) {
|
---|
447 | if (commandOptions.configPlugin || commandOptions.bundleConfigAsCjs) {
|
---|
448 | try {
|
---|
449 | return await loadTranspiledConfigFile(fileName, commandOptions);
|
---|
450 | }
|
---|
451 | catch (error_) {
|
---|
452 | if (error_.message.includes('not defined in ES module scope')) {
|
---|
453 | return parseAst_js.error(parseAst_js.logCannotBundleConfigAsEsm(error_));
|
---|
454 | }
|
---|
455 | throw error_;
|
---|
456 | }
|
---|
457 | }
|
---|
458 | let cannotLoadEsm = false;
|
---|
459 | const handleWarning = (warning) => {
|
---|
460 | if (warning.message.includes('To load an ES module')) {
|
---|
461 | cannotLoadEsm = true;
|
---|
462 | }
|
---|
463 | };
|
---|
464 | process$1.on('warning', handleWarning);
|
---|
465 | try {
|
---|
466 | const fileUrl = node_url.pathToFileURL(fileName);
|
---|
467 | if (watchMode) {
|
---|
468 | // We are adding the current date to allow reloads in watch mode
|
---|
469 | fileUrl.search = `?${Date.now()}`;
|
---|
470 | }
|
---|
471 | return (await import(fileUrl.href)).default;
|
---|
472 | }
|
---|
473 | catch (error_) {
|
---|
474 | if (cannotLoadEsm) {
|
---|
475 | return parseAst_js.error(parseAst_js.logCannotLoadConfigAsCjs(error_));
|
---|
476 | }
|
---|
477 | if (error_.message.includes('not defined in ES module scope')) {
|
---|
478 | return parseAst_js.error(parseAst_js.logCannotLoadConfigAsEsm(error_));
|
---|
479 | }
|
---|
480 | throw error_;
|
---|
481 | }
|
---|
482 | finally {
|
---|
483 | process$1.off('warning', handleWarning);
|
---|
484 | }
|
---|
485 | }
|
---|
486 | function getDefaultFromCjs(namespace) {
|
---|
487 | return namespace.default || namespace;
|
---|
488 | }
|
---|
489 | async function loadTranspiledConfigFile(fileName, commandOptions) {
|
---|
490 | const { bundleConfigAsCjs, configPlugin, silent } = commandOptions;
|
---|
491 | const warnings = batchWarnings(commandOptions);
|
---|
492 | const inputOptions = {
|
---|
493 | external: (id) => (id[0] !== '.' && !path.isAbsolute(id)) || id.slice(-5) === '.json',
|
---|
494 | input: fileName,
|
---|
495 | onwarn: warnings.add,
|
---|
496 | plugins: [],
|
---|
497 | treeshake: false
|
---|
498 | };
|
---|
499 | await addPluginsFromCommandOption(configPlugin, inputOptions);
|
---|
500 | const bundle = await rollup.rollup(inputOptions);
|
---|
501 | const { output: [{ code }] } = await bundle.generate({
|
---|
502 | exports: 'named',
|
---|
503 | format: bundleConfigAsCjs ? 'cjs' : 'es',
|
---|
504 | plugins: [
|
---|
505 | {
|
---|
506 | name: 'transpile-import-meta',
|
---|
507 | resolveImportMeta(property, { moduleId }) {
|
---|
508 | if (property === 'url') {
|
---|
509 | return `'${node_url.pathToFileURL(moduleId).href}'`;
|
---|
510 | }
|
---|
511 | if (property == 'filename') {
|
---|
512 | return `'${moduleId}'`;
|
---|
513 | }
|
---|
514 | if (property == 'dirname') {
|
---|
515 | return `'${path.dirname(moduleId)}'`;
|
---|
516 | }
|
---|
517 | if (property == null) {
|
---|
518 | return `{url:'${node_url.pathToFileURL(moduleId).href}', filename: '${moduleId}', dirname: '${path.dirname(moduleId)}'}`;
|
---|
519 | }
|
---|
520 | }
|
---|
521 | }
|
---|
522 | ]
|
---|
523 | });
|
---|
524 | if (!silent && warnings.count > 0) {
|
---|
525 | rollup.stderr(rollup.bold(`loaded ${parseAst_js.relativeId(fileName)} with warnings`));
|
---|
526 | warnings.flush();
|
---|
527 | }
|
---|
528 | return loadConfigFromWrittenFile(path.join(path.dirname(fileName), `rollup.config-${Date.now()}.${bundleConfigAsCjs ? 'cjs' : 'mjs'}`), code);
|
---|
529 | }
|
---|
530 | async function loadConfigFromWrittenFile(bundledFileName, bundledCode) {
|
---|
531 | await promises.writeFile(bundledFileName, bundledCode);
|
---|
532 | try {
|
---|
533 | return (await import(node_url.pathToFileURL(bundledFileName).href)).default;
|
---|
534 | }
|
---|
535 | finally {
|
---|
536 | promises.unlink(bundledFileName).catch(error => console.warn(error?.message || error));
|
---|
537 | }
|
---|
538 | }
|
---|
539 | async function getConfigList(configFileExport, commandOptions) {
|
---|
540 | const config = await (typeof configFileExport === 'function'
|
---|
541 | ? configFileExport(commandOptions)
|
---|
542 | : configFileExport);
|
---|
543 | if (Object.keys(config).length === 0) {
|
---|
544 | return parseAst_js.error(parseAst_js.logMissingConfig());
|
---|
545 | }
|
---|
546 | return Array.isArray(config) ? config : [config];
|
---|
547 | }
|
---|
548 |
|
---|
549 | exports.addCommandPluginsToInputOptions = addCommandPluginsToInputOptions;
|
---|
550 | exports.batchWarnings = batchWarnings;
|
---|
551 | exports.loadConfigFile = loadConfigFile;
|
---|
552 | exports.stdinName = stdinName;
|
---|
553 | //# sourceMappingURL=loadConfigFile.js.map
|
---|