rollup 3.24.1 → 3.25.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.
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v3.24.1
4
- Sat, 10 Jun 2023 04:40:07 GMT - commit be39a579ac40a1f97d1b8e491aade0cd8717d22b
3
+ Rollup.js v3.25.0
4
+ Sun, 11 Jun 2023 05:02:46 GMT - commit 23c111c87145d15b0de032a6c7eeb6596764d1cf
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
@@ -15,7 +15,7 @@ import { createHash as createHash$1 } from 'node:crypto';
15
15
  import { lstat, realpath, readdir, readFile, mkdir, writeFile } from 'node:fs/promises';
16
16
  import * as tty from 'tty';
17
17
 
18
- var version$1 = "3.24.1";
18
+ var version$1 = "3.25.0";
19
19
 
20
20
  const comma = ','.charCodeAt(0);
21
21
  const semicolon = ';'.charCodeAt(0);
@@ -1971,6 +1971,89 @@ const EMPTY_SET = Object.freeze(new (class extends Set {
1971
1971
  }
1972
1972
  })());
1973
1973
 
1974
+ const RESERVED_NAMES = new Set([
1975
+ 'await',
1976
+ 'break',
1977
+ 'case',
1978
+ 'catch',
1979
+ 'class',
1980
+ 'const',
1981
+ 'continue',
1982
+ 'debugger',
1983
+ 'default',
1984
+ 'delete',
1985
+ 'do',
1986
+ 'else',
1987
+ 'enum',
1988
+ 'eval',
1989
+ 'export',
1990
+ 'extends',
1991
+ 'false',
1992
+ 'finally',
1993
+ 'for',
1994
+ 'function',
1995
+ 'if',
1996
+ 'implements',
1997
+ 'import',
1998
+ 'in',
1999
+ 'instanceof',
2000
+ 'interface',
2001
+ 'let',
2002
+ 'NaN',
2003
+ 'new',
2004
+ 'null',
2005
+ 'package',
2006
+ 'private',
2007
+ 'protected',
2008
+ 'public',
2009
+ 'return',
2010
+ 'static',
2011
+ 'super',
2012
+ 'switch',
2013
+ 'this',
2014
+ 'throw',
2015
+ 'true',
2016
+ 'try',
2017
+ 'typeof',
2018
+ 'undefined',
2019
+ 'var',
2020
+ 'void',
2021
+ 'while',
2022
+ 'with',
2023
+ 'yield'
2024
+ ]);
2025
+ const RESERVED_NAMES$1 = RESERVED_NAMES;
2026
+
2027
+ const illegalCharacters = /[^\w$]/g;
2028
+ const startsWithDigit = (value) => /\d/.test(value[0]);
2029
+ const needsEscape = (value) => startsWithDigit(value) || RESERVED_NAMES$1.has(value) || value === 'arguments';
2030
+ function isLegal(value) {
2031
+ if (needsEscape(value)) {
2032
+ return false;
2033
+ }
2034
+ return !illegalCharacters.test(value);
2035
+ }
2036
+ function makeLegal(value) {
2037
+ value = value
2038
+ .replace(/-(\w)/g, (_, letter) => letter.toUpperCase())
2039
+ .replace(illegalCharacters, '_');
2040
+ if (needsEscape(value))
2041
+ value = `_${value}`;
2042
+ return value || '_';
2043
+ }
2044
+
2045
+ const LOGLEVEL_SILENT = 'silent';
2046
+ const LOGLEVEL_ERROR = 'error';
2047
+ const LOGLEVEL_WARN = 'warn';
2048
+ const LOGLEVEL_INFO = 'info';
2049
+ const LOGLEVEL_DEBUG = 'debug';
2050
+ const logLevelPriority = {
2051
+ [LOGLEVEL_DEBUG]: 0,
2052
+ [LOGLEVEL_INFO]: 1,
2053
+ [LOGLEVEL_SILENT]: 3,
2054
+ [LOGLEVEL_WARN]: 2
2055
+ };
2056
+
1974
2057
  function getLocator(source, options) {
1975
2058
  if (options === void 0) { options = {}; }
1976
2059
  var offsetLine = options.offsetLine || 0;
@@ -2149,21 +2232,21 @@ function augmentCodeLocation(properties, pos, source, id) {
2149
2232
  }
2150
2233
  // Error codes should be sorted alphabetically while errors should be sorted by
2151
2234
  // error code below
2152
- const ADDON_ERROR = 'ADDON_ERROR', ALREADY_CLOSED = 'ALREADY_CLOSED', AMBIGUOUS_EXTERNAL_NAMESPACES = 'AMBIGUOUS_EXTERNAL_NAMESPACES', ANONYMOUS_PLUGIN_CACHE = 'ANONYMOUS_PLUGIN_CACHE', ASSET_NOT_FINALISED = 'ASSET_NOT_FINALISED', ASSET_NOT_FOUND = 'ASSET_NOT_FOUND', ASSET_SOURCE_ALREADY_SET = 'ASSET_SOURCE_ALREADY_SET', ASSET_SOURCE_MISSING = 'ASSET_SOURCE_MISSING', BAD_LOADER = 'BAD_LOADER', CANNOT_CALL_NAMESPACE = 'CANNOT_CALL_NAMESPACE', CANNOT_EMIT_FROM_OPTIONS_HOOK = 'CANNOT_EMIT_FROM_OPTIONS_HOOK', CHUNK_NOT_GENERATED = 'CHUNK_NOT_GENERATED', CHUNK_INVALID = 'CHUNK_INVALID', CIRCULAR_DEPENDENCY = 'CIRCULAR_DEPENDENCY', CIRCULAR_REEXPORT = 'CIRCULAR_REEXPORT', CYCLIC_CROSS_CHUNK_REEXPORT = 'CYCLIC_CROSS_CHUNK_REEXPORT', DEPRECATED_FEATURE = 'DEPRECATED_FEATURE', DUPLICATE_PLUGIN_NAME = 'DUPLICATE_PLUGIN_NAME', EMPTY_BUNDLE = 'EMPTY_BUNDLE', EVAL = 'EVAL', EXTERNAL_SYNTHETIC_EXPORTS = 'EXTERNAL_SYNTHETIC_EXPORTS', FILE_NAME_CONFLICT = 'FILE_NAME_CONFLICT', FILE_NOT_FOUND = 'FILE_NOT_FOUND', ILLEGAL_IDENTIFIER_AS_NAME = 'ILLEGAL_IDENTIFIER_AS_NAME', ILLEGAL_REASSIGNMENT = 'ILLEGAL_REASSIGNMENT', INCONSISTENT_IMPORT_ASSERTIONS = 'INCONSISTENT_IMPORT_ASSERTIONS', INPUT_HOOK_IN_OUTPUT_PLUGIN = 'INPUT_HOOK_IN_OUTPUT_PLUGIN', INVALID_CHUNK = 'INVALID_CHUNK', INVALID_EXPORT_OPTION = 'INVALID_EXPORT_OPTION', INVALID_EXTERNAL_ID = 'INVALID_EXTERNAL_ID', INVALID_OPTION = 'INVALID_OPTION', INVALID_PLUGIN_HOOK = 'INVALID_PLUGIN_HOOK', INVALID_ROLLUP_PHASE = 'INVALID_ROLLUP_PHASE', INVALID_SETASSETSOURCE = 'INVALID_SETASSETSOURCE', INVALID_TLA_FORMAT = 'INVALID_TLA_FORMAT', MISSING_EXPORT = 'MISSING_EXPORT', MISSING_GLOBAL_NAME = 'MISSING_GLOBAL_NAME', MISSING_IMPLICIT_DEPENDANT = 'MISSING_IMPLICIT_DEPENDANT', MISSING_NAME_OPTION_FOR_IIFE_EXPORT = 'MISSING_NAME_OPTION_FOR_IIFE_EXPORT', MISSING_NODE_BUILTINS = 'MISSING_NODE_BUILTINS', MISSING_OPTION = 'MISSING_OPTION', MIXED_EXPORTS = 'MIXED_EXPORTS', MODULE_LEVEL_DIRECTIVE = 'MODULE_LEVEL_DIRECTIVE', NAMESPACE_CONFLICT = 'NAMESPACE_CONFLICT', NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE = 'NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE', PARSE_ERROR = 'PARSE_ERROR', PLUGIN_ERROR = 'PLUGIN_ERROR', SHIMMED_EXPORT = 'SHIMMED_EXPORT', SOURCEMAP_BROKEN = 'SOURCEMAP_BROKEN', SOURCEMAP_ERROR = 'SOURCEMAP_ERROR', SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT = 'SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT', THIS_IS_UNDEFINED = 'THIS_IS_UNDEFINED', UNEXPECTED_NAMED_IMPORT = 'UNEXPECTED_NAMED_IMPORT', UNKNOWN_OPTION = 'UNKNOWN_OPTION', UNRESOLVED_ENTRY = 'UNRESOLVED_ENTRY', UNRESOLVED_IMPORT = 'UNRESOLVED_IMPORT', UNUSED_EXTERNAL_IMPORT = 'UNUSED_EXTERNAL_IMPORT', VALIDATION_ERROR = 'VALIDATION_ERROR';
2153
- function errorAddonNotGenerated(message, hook, plugin) {
2235
+ const ADDON_ERROR = 'ADDON_ERROR', ALREADY_CLOSED = 'ALREADY_CLOSED', AMBIGUOUS_EXTERNAL_NAMESPACES = 'AMBIGUOUS_EXTERNAL_NAMESPACES', ANONYMOUS_PLUGIN_CACHE = 'ANONYMOUS_PLUGIN_CACHE', ASSET_NOT_FINALISED = 'ASSET_NOT_FINALISED', ASSET_NOT_FOUND = 'ASSET_NOT_FOUND', ASSET_SOURCE_ALREADY_SET = 'ASSET_SOURCE_ALREADY_SET', ASSET_SOURCE_MISSING = 'ASSET_SOURCE_MISSING', BAD_LOADER = 'BAD_LOADER', CANNOT_CALL_NAMESPACE = 'CANNOT_CALL_NAMESPACE', CANNOT_EMIT_FROM_OPTIONS_HOOK = 'CANNOT_EMIT_FROM_OPTIONS_HOOK', CHUNK_NOT_GENERATED = 'CHUNK_NOT_GENERATED', CHUNK_INVALID = 'CHUNK_INVALID', CIRCULAR_DEPENDENCY = 'CIRCULAR_DEPENDENCY', CIRCULAR_REEXPORT = 'CIRCULAR_REEXPORT', CYCLIC_CROSS_CHUNK_REEXPORT = 'CYCLIC_CROSS_CHUNK_REEXPORT', DEPRECATED_FEATURE = 'DEPRECATED_FEATURE', DUPLICATE_PLUGIN_NAME = 'DUPLICATE_PLUGIN_NAME', EMPTY_BUNDLE = 'EMPTY_BUNDLE', EVAL = 'EVAL', EXTERNAL_SYNTHETIC_EXPORTS = 'EXTERNAL_SYNTHETIC_EXPORTS', FILE_NAME_CONFLICT = 'FILE_NAME_CONFLICT', FILE_NOT_FOUND = 'FILE_NOT_FOUND', FIRST_SIDE_EFFECT = 'FIRST_SIDE_EFFECT', ILLEGAL_IDENTIFIER_AS_NAME = 'ILLEGAL_IDENTIFIER_AS_NAME', ILLEGAL_REASSIGNMENT = 'ILLEGAL_REASSIGNMENT', INCONSISTENT_IMPORT_ASSERTIONS = 'INCONSISTENT_IMPORT_ASSERTIONS', INPUT_HOOK_IN_OUTPUT_PLUGIN = 'INPUT_HOOK_IN_OUTPUT_PLUGIN', INVALID_CHUNK = 'INVALID_CHUNK', INVALID_EXPORT_OPTION = 'INVALID_EXPORT_OPTION', INVALID_EXTERNAL_ID = 'INVALID_EXTERNAL_ID', INVALID_LOG_POSITION = 'INVALID_LOG_POSITION', INVALID_OPTION = 'INVALID_OPTION', INVALID_PLUGIN_HOOK = 'INVALID_PLUGIN_HOOK', INVALID_ROLLUP_PHASE = 'INVALID_ROLLUP_PHASE', INVALID_SETASSETSOURCE = 'INVALID_SETASSETSOURCE', INVALID_TLA_FORMAT = 'INVALID_TLA_FORMAT', MISSING_EXPORT = 'MISSING_EXPORT', MISSING_GLOBAL_NAME = 'MISSING_GLOBAL_NAME', MISSING_IMPLICIT_DEPENDANT = 'MISSING_IMPLICIT_DEPENDANT', MISSING_NAME_OPTION_FOR_IIFE_EXPORT = 'MISSING_NAME_OPTION_FOR_IIFE_EXPORT', MISSING_NODE_BUILTINS = 'MISSING_NODE_BUILTINS', MISSING_OPTION = 'MISSING_OPTION', MIXED_EXPORTS = 'MIXED_EXPORTS', MODULE_LEVEL_DIRECTIVE = 'MODULE_LEVEL_DIRECTIVE', NAMESPACE_CONFLICT = 'NAMESPACE_CONFLICT', NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE = 'NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE', OPTIMIZE_CHUNK_STATUS = 'OPTIMIZE_CHUNK_STATUS', PARSE_ERROR = 'PARSE_ERROR', PLUGIN_ERROR = 'PLUGIN_ERROR', SHIMMED_EXPORT = 'SHIMMED_EXPORT', SOURCEMAP_BROKEN = 'SOURCEMAP_BROKEN', SOURCEMAP_ERROR = 'SOURCEMAP_ERROR', SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT = 'SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT', THIS_IS_UNDEFINED = 'THIS_IS_UNDEFINED', UNEXPECTED_NAMED_IMPORT = 'UNEXPECTED_NAMED_IMPORT', UNKNOWN_OPTION = 'UNKNOWN_OPTION', UNRESOLVED_ENTRY = 'UNRESOLVED_ENTRY', UNRESOLVED_IMPORT = 'UNRESOLVED_IMPORT', UNUSED_EXTERNAL_IMPORT = 'UNUSED_EXTERNAL_IMPORT', VALIDATION_ERROR = 'VALIDATION_ERROR';
2236
+ function logAddonNotGenerated(message, hook, plugin) {
2154
2237
  return {
2155
2238
  code: ADDON_ERROR,
2156
2239
  message: `Could not retrieve "${hook}". Check configuration of plugin "${plugin}".
2157
2240
  \tError Message: ${message}`
2158
2241
  };
2159
2242
  }
2160
- function errorAlreadyClosed() {
2243
+ function logAlreadyClosed() {
2161
2244
  return {
2162
2245
  code: ALREADY_CLOSED,
2163
2246
  message: 'Bundle is already closed, no more calls to "generate" or "write" are allowed.'
2164
2247
  };
2165
2248
  }
2166
- function errorAmbiguousExternalNamespaces(binding, reexportingModule, usedModule, sources) {
2249
+ function logAmbiguousExternalNamespaces(binding, reexportingModule, usedModule, sources) {
2167
2250
  return {
2168
2251
  binding,
2169
2252
  code: AMBIGUOUS_EXTERNAL_NAMESPACES,
@@ -2172,61 +2255,61 @@ function errorAmbiguousExternalNamespaces(binding, reexportingModule, usedModule
2172
2255
  reexporter: reexportingModule
2173
2256
  };
2174
2257
  }
2175
- function errorAnonymousPluginCache() {
2258
+ function logAnonymousPluginCache() {
2176
2259
  return {
2177
2260
  code: ANONYMOUS_PLUGIN_CACHE,
2178
2261
  message: 'A plugin is trying to use the Rollup cache but is not declaring a plugin name or cacheKey.'
2179
2262
  };
2180
2263
  }
2181
- function errorAssetNotFinalisedForFileName(name) {
2264
+ function logAssetNotFinalisedForFileName(name) {
2182
2265
  return {
2183
2266
  code: ASSET_NOT_FINALISED,
2184
2267
  message: `Plugin error - Unable to get file name for asset "${name}". Ensure that the source is set and that generate is called first. If you reference assets via import.meta.ROLLUP_FILE_URL_<referenceId>, you need to either have set their source after "renderStart" or need to provide an explicit "fileName" when emitting them.`
2185
2268
  };
2186
2269
  }
2187
- function errorAssetReferenceIdNotFoundForSetSource(assetReferenceId) {
2270
+ function logAssetReferenceIdNotFoundForSetSource(assetReferenceId) {
2188
2271
  return {
2189
2272
  code: ASSET_NOT_FOUND,
2190
2273
  message: `Plugin error - Unable to set the source for unknown asset "${assetReferenceId}".`
2191
2274
  };
2192
2275
  }
2193
- function errorAssetSourceAlreadySet(name) {
2276
+ function logAssetSourceAlreadySet(name) {
2194
2277
  return {
2195
2278
  code: ASSET_SOURCE_ALREADY_SET,
2196
2279
  message: `Unable to set the source for asset "${name}", source already set.`
2197
2280
  };
2198
2281
  }
2199
- function errorNoAssetSourceSet(assetName) {
2282
+ function logNoAssetSourceSet(assetName) {
2200
2283
  return {
2201
2284
  code: ASSET_SOURCE_MISSING,
2202
2285
  message: `Plugin error creating asset "${assetName}" - no asset source set.`
2203
2286
  };
2204
2287
  }
2205
- function errorBadLoader(id) {
2288
+ function logBadLoader(id) {
2206
2289
  return {
2207
2290
  code: BAD_LOADER,
2208
2291
  message: `Error loading "${relativeId(id)}": plugin load hook should return a string, a { code, map } object, or nothing/null.`
2209
2292
  };
2210
2293
  }
2211
- function errorCannotCallNamespace(name) {
2294
+ function logCannotCallNamespace(name) {
2212
2295
  return {
2213
2296
  code: CANNOT_CALL_NAMESPACE,
2214
2297
  message: `Cannot call a namespace ("${name}").`
2215
2298
  };
2216
2299
  }
2217
- function errorCannotEmitFromOptionsHook() {
2300
+ function logCannotEmitFromOptionsHook() {
2218
2301
  return {
2219
2302
  code: CANNOT_EMIT_FROM_OPTIONS_HOOK,
2220
2303
  message: `Cannot emit files or set asset sources in the "outputOptions" hook, use the "renderStart" hook instead.`
2221
2304
  };
2222
2305
  }
2223
- function errorChunkNotGeneratedForFileName(name) {
2306
+ function logChunkNotGeneratedForFileName(name) {
2224
2307
  return {
2225
2308
  code: CHUNK_NOT_GENERATED,
2226
2309
  message: `Plugin error - Unable to get file name for emitted chunk "${name}". You can only get file names once chunks have been generated after the "renderStart" hook.`
2227
2310
  };
2228
2311
  }
2229
- function errorChunkInvalid({ fileName, code }, exception) {
2312
+ function logChunkInvalid({ fileName, code }, exception) {
2230
2313
  const errorProperties = {
2231
2314
  code: CHUNK_INVALID,
2232
2315
  message: `Chunk "${fileName}" is not valid JavaScript: ${exception.message}.`
@@ -2234,21 +2317,21 @@ function errorChunkInvalid({ fileName, code }, exception) {
2234
2317
  augmentCodeLocation(errorProperties, exception.loc, code, fileName);
2235
2318
  return errorProperties;
2236
2319
  }
2237
- function errorCircularDependency(cyclePath) {
2320
+ function logCircularDependency(cyclePath) {
2238
2321
  return {
2239
2322
  code: CIRCULAR_DEPENDENCY,
2240
2323
  ids: cyclePath,
2241
2324
  message: `Circular dependency: ${cyclePath.map(relativeId).join(' -> ')}`
2242
2325
  };
2243
2326
  }
2244
- function errorCircularReexport(exportName, exporter) {
2327
+ function logCircularReexport(exportName, exporter) {
2245
2328
  return {
2246
2329
  code: CIRCULAR_REEXPORT,
2247
2330
  exporter,
2248
2331
  message: `"${exportName}" cannot be exported from "${relativeId(exporter)}" as it is a reexport that references itself.`
2249
2332
  };
2250
2333
  }
2251
- function errorCyclicCrossChunkReexport(exportName, exporter, reexporter, importer, preserveModules) {
2334
+ function logCyclicCrossChunkReexport(exportName, exporter, reexporter, importer, preserveModules) {
2252
2335
  return {
2253
2336
  code: CYCLIC_CROSS_CHUNK_REEXPORT,
2254
2337
  exporter,
@@ -2257,7 +2340,7 @@ function errorCyclicCrossChunkReexport(exportName, exporter, reexporter, importe
2257
2340
  reexporter
2258
2341
  };
2259
2342
  }
2260
- function errorDeprecation(deprecation, urlSnippet, plugin) {
2343
+ function logDeprecation(deprecation, urlSnippet, plugin) {
2261
2344
  return {
2262
2345
  code: DEPRECATED_FEATURE,
2263
2346
  message: deprecation,
@@ -2265,20 +2348,20 @@ function errorDeprecation(deprecation, urlSnippet, plugin) {
2265
2348
  ...(plugin ? { plugin } : {})
2266
2349
  };
2267
2350
  }
2268
- function errorDuplicatePluginName(plugin) {
2351
+ function logDuplicatePluginName(plugin) {
2269
2352
  return {
2270
2353
  code: DUPLICATE_PLUGIN_NAME,
2271
2354
  message: `The plugin name ${plugin} is being used twice in the same build. Plugin names must be distinct or provide a cacheKey (please post an issue to the plugin if you are a plugin user).`
2272
2355
  };
2273
2356
  }
2274
- function errorEmptyChunk(chunkName) {
2357
+ function logEmptyChunk(chunkName) {
2275
2358
  return {
2276
2359
  code: EMPTY_BUNDLE,
2277
2360
  message: `Generated an empty chunk: "${chunkName}".`,
2278
2361
  names: [chunkName]
2279
2362
  };
2280
2363
  }
2281
- function errorEval(id) {
2364
+ function logEval(id) {
2282
2365
  return {
2283
2366
  code: EVAL,
2284
2367
  id,
@@ -2286,39 +2369,45 @@ function errorEval(id) {
2286
2369
  url: getRollupUrl(URL_AVOIDING_EVAL)
2287
2370
  };
2288
2371
  }
2289
- function errorExternalSyntheticExports(id, importer) {
2372
+ function logExternalSyntheticExports(id, importer) {
2290
2373
  return {
2291
2374
  code: EXTERNAL_SYNTHETIC_EXPORTS,
2292
2375
  exporter: id,
2293
2376
  message: `External "${id}" cannot have "syntheticNamedExports" enabled (imported by "${relativeId(importer)}").`
2294
2377
  };
2295
2378
  }
2296
- function errorFileNameConflict(fileName) {
2379
+ function logFileNameConflict(fileName) {
2297
2380
  return {
2298
2381
  code: FILE_NAME_CONFLICT,
2299
2382
  message: `The emitted file "${fileName}" overwrites a previously emitted file of the same name.`
2300
2383
  };
2301
2384
  }
2302
- function errorFileReferenceIdNotFoundForFilename(assetReferenceId) {
2385
+ function logFileReferenceIdNotFoundForFilename(assetReferenceId) {
2303
2386
  return {
2304
2387
  code: FILE_NOT_FOUND,
2305
2388
  message: `Plugin error - Unable to get file name for unknown file "${assetReferenceId}".`
2306
2389
  };
2307
2390
  }
2308
- function errorIllegalIdentifierAsName(name) {
2391
+ function logFirstSideEffect(source, id, { line, column }) {
2392
+ return {
2393
+ code: FIRST_SIDE_EFFECT,
2394
+ message: `First side effect in ${relativeId(id)} is at (${line}:${column})\n${getCodeFrame(source, line, column)}`
2395
+ };
2396
+ }
2397
+ function logIllegalIdentifierAsName(name) {
2309
2398
  return {
2310
2399
  code: ILLEGAL_IDENTIFIER_AS_NAME,
2311
2400
  message: `Given name "${name}" is not a legal JS identifier. If you need this, you can try "output.extend: true".`,
2312
2401
  url: getRollupUrl(URL_OUTPUT_EXTEND)
2313
2402
  };
2314
2403
  }
2315
- function errorIllegalImportReassignment(name, importingId) {
2404
+ function logIllegalImportReassignment(name, importingId) {
2316
2405
  return {
2317
2406
  code: ILLEGAL_REASSIGNMENT,
2318
2407
  message: `Illegal reassignment of import "${name}" in "${relativeId(importingId)}".`
2319
2408
  };
2320
2409
  }
2321
- function errorInconsistentImportAssertions(existingAssertions, newAssertions, source, importer) {
2410
+ function logInconsistentImportAssertions(existingAssertions, newAssertions, source, importer) {
2322
2411
  return {
2323
2412
  code: INCONSISTENT_IMPORT_ASSERTIONS,
2324
2413
  message: `Module "${relativeId(importer)}" tried to import "${relativeId(source)}" with ${formatAssertions(newAssertions)} assertions, but it was already imported elsewhere with ${formatAssertions(existingAssertions)} assertions. Please ensure that import assertions for the same module are always consistent.`
@@ -2330,46 +2419,52 @@ const formatAssertions = (assertions) => {
2330
2419
  return 'no';
2331
2420
  return entries.map(([key, value]) => `"${key}": "${value}"`).join(', ');
2332
2421
  };
2333
- function errorInputHookInOutputPlugin(pluginName, hookName) {
2422
+ function logInputHookInOutputPlugin(pluginName, hookName) {
2334
2423
  return {
2335
2424
  code: INPUT_HOOK_IN_OUTPUT_PLUGIN,
2336
2425
  message: `The "${hookName}" hook used by the output plugin ${pluginName} is a build time hook and will not be run for that plugin. Either this plugin cannot be used as an output plugin, or it should have an option to configure it as an output plugin.`
2337
2426
  };
2338
2427
  }
2339
- function errorCannotAssignModuleToChunk(moduleId, assignToAlias, currentAlias) {
2428
+ function logCannotAssignModuleToChunk(moduleId, assignToAlias, currentAlias) {
2340
2429
  return {
2341
2430
  code: INVALID_CHUNK,
2342
2431
  message: `Cannot assign "${relativeId(moduleId)}" to the "${assignToAlias}" chunk as it is already in the "${currentAlias}" chunk.`
2343
2432
  };
2344
2433
  }
2345
- function errorInvalidExportOptionValue(optionValue) {
2434
+ function logInvalidExportOptionValue(optionValue) {
2346
2435
  return {
2347
2436
  code: INVALID_EXPORT_OPTION,
2348
2437
  message: `"output.exports" must be "default", "named", "none", "auto", or left unspecified (defaults to "auto"), received "${optionValue}".`,
2349
2438
  url: getRollupUrl(URL_OUTPUT_EXPORTS)
2350
2439
  };
2351
2440
  }
2352
- function errorIncompatibleExportOptionValue(optionValue, keys, entryModule) {
2441
+ function logIncompatibleExportOptionValue(optionValue, keys, entryModule) {
2353
2442
  return {
2354
2443
  code: INVALID_EXPORT_OPTION,
2355
2444
  message: `"${optionValue}" was specified for "output.exports", but entry module "${relativeId(entryModule)}" has the following exports: ${printQuotedStringList(keys)}`,
2356
2445
  url: getRollupUrl(URL_OUTPUT_EXPORTS)
2357
2446
  };
2358
2447
  }
2359
- function errorInternalIdCannotBeExternal(source, importer) {
2448
+ function logInternalIdCannotBeExternal(source, importer) {
2360
2449
  return {
2361
2450
  code: INVALID_EXTERNAL_ID,
2362
2451
  message: `"${source}" is imported as an external by "${relativeId(importer)}", but is already an existing non-external module id.`
2363
2452
  };
2364
2453
  }
2365
- function errorInvalidOption(option, urlSnippet, explanation, value) {
2454
+ function logInvalidLogPosition(plugin) {
2455
+ return {
2456
+ code: INVALID_LOG_POSITION,
2457
+ message: `Plugin "${plugin}" tried to add a file position to a log or warning. This is only supported in the "transform" hook at the moment and will be ignored.`
2458
+ };
2459
+ }
2460
+ function logInvalidOption(option, urlSnippet, explanation, value) {
2366
2461
  return {
2367
2462
  code: INVALID_OPTION,
2368
2463
  message: `Invalid value ${value === undefined ? '' : `${JSON.stringify(value)} `}for option "${option}" - ${explanation}.`,
2369
2464
  url: getRollupUrl(urlSnippet)
2370
2465
  };
2371
2466
  }
2372
- function errorInvalidAddonPluginHook(hook, plugin) {
2467
+ function logInvalidAddonPluginHook(hook, plugin) {
2373
2468
  return {
2374
2469
  code: INVALID_PLUGIN_HOOK,
2375
2470
  hook,
@@ -2377,7 +2472,7 @@ function errorInvalidAddonPluginHook(hook, plugin) {
2377
2472
  plugin
2378
2473
  };
2379
2474
  }
2380
- function errorInvalidFunctionPluginHook(hook, plugin) {
2475
+ function logInvalidFunctionPluginHook(hook, plugin) {
2381
2476
  return {
2382
2477
  code: INVALID_PLUGIN_HOOK,
2383
2478
  hook,
@@ -2385,32 +2480,32 @@ function errorInvalidFunctionPluginHook(hook, plugin) {
2385
2480
  plugin
2386
2481
  };
2387
2482
  }
2388
- function errorInvalidRollupPhaseForAddWatchFile() {
2483
+ function logInvalidRollupPhaseForAddWatchFile() {
2389
2484
  return {
2390
2485
  code: INVALID_ROLLUP_PHASE,
2391
2486
  message: `Cannot call "addWatchFile" after the build has finished.`
2392
2487
  };
2393
2488
  }
2394
- function errorInvalidRollupPhaseForChunkEmission() {
2489
+ function logInvalidRollupPhaseForChunkEmission() {
2395
2490
  return {
2396
2491
  code: INVALID_ROLLUP_PHASE,
2397
2492
  message: `Cannot emit chunks after module loading has finished.`
2398
2493
  };
2399
2494
  }
2400
- function errorInvalidSetAssetSourceCall() {
2495
+ function logInvalidSetAssetSourceCall() {
2401
2496
  return {
2402
2497
  code: INVALID_SETASSETSOURCE,
2403
2498
  message: `setAssetSource cannot be called in transform for caching reasons. Use emitFile with a source, or call setAssetSource in another hook.`
2404
2499
  };
2405
2500
  }
2406
- function errorInvalidFormatForTopLevelAwait(id, format) {
2501
+ function logInvalidFormatForTopLevelAwait(id, format) {
2407
2502
  return {
2408
2503
  code: INVALID_TLA_FORMAT,
2409
2504
  id,
2410
2505
  message: `Module format "${format}" does not support top-level await. Use the "es" or "system" output formats rather.`
2411
2506
  };
2412
2507
  }
2413
- function errorMissingExport(binding, importingModule, exporter) {
2508
+ function logMissingExport(binding, importingModule, exporter) {
2414
2509
  const isJson = extname(exporter) === '.json';
2415
2510
  return {
2416
2511
  binding,
@@ -2421,7 +2516,7 @@ function errorMissingExport(binding, importingModule, exporter) {
2421
2516
  url: getRollupUrl(URL_NAME_IS_NOT_EXPORTED)
2422
2517
  };
2423
2518
  }
2424
- function errorMissingGlobalName(externalId, guess) {
2519
+ function logMissingGlobalName(externalId, guess) {
2425
2520
  return {
2426
2521
  code: MISSING_GLOBAL_NAME,
2427
2522
  id: externalId,
@@ -2430,19 +2525,19 @@ function errorMissingGlobalName(externalId, guess) {
2430
2525
  url: getRollupUrl(URL_OUTPUT_GLOBALS)
2431
2526
  };
2432
2527
  }
2433
- function errorImplicitDependantCannotBeExternal(unresolvedId, implicitlyLoadedBefore) {
2528
+ function logImplicitDependantCannotBeExternal(unresolvedId, implicitlyLoadedBefore) {
2434
2529
  return {
2435
2530
  code: MISSING_IMPLICIT_DEPENDANT,
2436
2531
  message: `Module "${relativeId(unresolvedId)}" that should be implicitly loaded before "${relativeId(implicitlyLoadedBefore)}" cannot be external.`
2437
2532
  };
2438
2533
  }
2439
- function errorUnresolvedImplicitDependant(unresolvedId, implicitlyLoadedBefore) {
2534
+ function logUnresolvedImplicitDependant(unresolvedId, implicitlyLoadedBefore) {
2440
2535
  return {
2441
2536
  code: MISSING_IMPLICIT_DEPENDANT,
2442
2537
  message: `Module "${relativeId(unresolvedId)}" that should be implicitly loaded before "${relativeId(implicitlyLoadedBefore)}" could not be resolved.`
2443
2538
  };
2444
2539
  }
2445
- function errorImplicitDependantIsNotIncluded(module) {
2540
+ function logImplicitDependantIsNotIncluded(module) {
2446
2541
  const implicitDependencies = [...module.implicitlyLoadedBefore]
2447
2542
  .map(dependency => relativeId(dependency.id))
2448
2543
  .sort();
@@ -2451,21 +2546,21 @@ function errorImplicitDependantIsNotIncluded(module) {
2451
2546
  message: `Module "${relativeId(module.id)}" that should be implicitly loaded before ${printQuotedStringList(implicitDependencies)} is not included in the module graph. Either it was not imported by an included module or only via a tree-shaken dynamic import, or no imported bindings were used and it had otherwise no side-effects.`
2452
2547
  };
2453
2548
  }
2454
- function errorMissingNameOptionForIifeExport() {
2549
+ function logMissingNameOptionForIifeExport() {
2455
2550
  return {
2456
2551
  code: MISSING_NAME_OPTION_FOR_IIFE_EXPORT,
2457
2552
  message: `If you do not supply "output.name", you may not be able to access the exports of an IIFE bundle.`,
2458
2553
  url: getRollupUrl(URL_OUTPUT_NAME)
2459
2554
  };
2460
2555
  }
2461
- function errorMissingNameOptionForUmdExport() {
2556
+ function logMissingNameOptionForUmdExport() {
2462
2557
  return {
2463
2558
  code: MISSING_NAME_OPTION_FOR_IIFE_EXPORT,
2464
2559
  message: 'You must supply "output.name" for UMD bundles that have exports so that the exports are accessible in environments without a module loader.',
2465
2560
  url: getRollupUrl(URL_OUTPUT_NAME)
2466
2561
  };
2467
2562
  }
2468
- function errorMissingNodeBuiltins(externalBuiltins) {
2563
+ function logMissingNodeBuiltins(externalBuiltins) {
2469
2564
  return {
2470
2565
  code: MISSING_NODE_BUILTINS,
2471
2566
  ids: externalBuiltins,
@@ -2473,14 +2568,14 @@ function errorMissingNodeBuiltins(externalBuiltins) {
2473
2568
  };
2474
2569
  }
2475
2570
  // eslint-disable-next-line unicorn/prevent-abbreviations
2476
- function errorMissingFileOrDirOption() {
2571
+ function logMissingFileOrDirOption() {
2477
2572
  return {
2478
2573
  code: MISSING_OPTION,
2479
2574
  message: 'You must specify "output.file" or "output.dir" for the build.',
2480
2575
  url: getRollupUrl(URL_OUTPUT_DIR)
2481
2576
  };
2482
2577
  }
2483
- function errorMixedExport(facadeModuleId, name) {
2578
+ function logMixedExport(facadeModuleId, name) {
2484
2579
  return {
2485
2580
  code: MIXED_EXPORTS,
2486
2581
  id: facadeModuleId,
@@ -2488,14 +2583,14 @@ function errorMixedExport(facadeModuleId, name) {
2488
2583
  url: getRollupUrl(URL_OUTPUT_EXPORTS)
2489
2584
  };
2490
2585
  }
2491
- function errorModuleLevelDirective(directive, id) {
2586
+ function logModuleLevelDirective(directive, id) {
2492
2587
  return {
2493
2588
  code: MODULE_LEVEL_DIRECTIVE,
2494
2589
  id,
2495
2590
  message: `Module level directives cause errors when bundled, "${directive}" in "${relativeId(id)}" was ignored.`
2496
2591
  };
2497
2592
  }
2498
- function errorNamespaceConflict(binding, reexportingModuleId, sources) {
2593
+ function logNamespaceConflict(binding, reexportingModuleId, sources) {
2499
2594
  return {
2500
2595
  binding,
2501
2596
  code: NAMESPACE_CONFLICT,
@@ -2504,14 +2599,22 @@ function errorNamespaceConflict(binding, reexportingModuleId, sources) {
2504
2599
  reexporter: reexportingModuleId
2505
2600
  };
2506
2601
  }
2507
- function errorNoTransformMapOrAstWithoutCode(pluginName) {
2602
+ function logNoTransformMapOrAstWithoutCode(pluginName) {
2508
2603
  return {
2509
2604
  code: NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE,
2510
2605
  message: `The plugin "${pluginName}" returned a "map" or "ast" without returning ` +
2511
2606
  'a "code". This will be ignored.'
2512
2607
  };
2513
2608
  }
2514
- function errorParseError(error, moduleId) {
2609
+ function logOptimizeChunkStatus(chunks, smallChunks, pointInTime) {
2610
+ return {
2611
+ code: OPTIMIZE_CHUNK_STATUS,
2612
+ message: `${pointInTime}, there are\n` +
2613
+ `${chunks} chunks, of which\n` +
2614
+ `${smallChunks} are below minChunkSize.`
2615
+ };
2616
+ }
2617
+ function logParseError(error, moduleId) {
2515
2618
  let message = error.message.replace(/ \(\d+:\d+\)$/, '');
2516
2619
  if (moduleId.endsWith('.json')) {
2517
2620
  message += ' (Note that you need @rollup/plugin-json to import JSON files)';
@@ -2526,10 +2629,8 @@ function errorParseError(error, moduleId) {
2526
2629
  message
2527
2630
  };
2528
2631
  }
2529
- function errorPluginError(error, plugin, { hook, id } = {}) {
2530
- if (typeof error === 'string')
2531
- error = { message: error };
2532
- if (error.code && error.code !== PLUGIN_ERROR) {
2632
+ function logPluginError(error, plugin, { hook, id } = {}) {
2633
+ if (error.code && !error.code.startsWith('PLUGIN_') && !error.pluginCode) {
2533
2634
  error.pluginCode = error.code;
2534
2635
  }
2535
2636
  error.code = PLUGIN_ERROR;
@@ -2542,7 +2643,7 @@ function errorPluginError(error, plugin, { hook, id } = {}) {
2542
2643
  }
2543
2644
  return error;
2544
2645
  }
2545
- function errorShimmedExport(id, binding) {
2646
+ function logShimmedExport(id, binding) {
2546
2647
  return {
2547
2648
  binding,
2548
2649
  code: SHIMMED_EXPORT,
@@ -2550,7 +2651,7 @@ function errorShimmedExport(id, binding) {
2550
2651
  message: `Missing export "${binding}" has been shimmed in module "${relativeId(id)}".`
2551
2652
  };
2552
2653
  }
2553
- function errorSourcemapBroken(plugin) {
2654
+ function logSourcemapBroken(plugin) {
2554
2655
  return {
2555
2656
  code: SOURCEMAP_BROKEN,
2556
2657
  message: `Sourcemap is likely to be incorrect: a plugin (${plugin}) was used to transform files, but didn't generate a sourcemap for the transformation. Consult the plugin documentation for help`,
@@ -2558,13 +2659,13 @@ function errorSourcemapBroken(plugin) {
2558
2659
  url: getRollupUrl(URL_SOURCEMAP_IS_LIKELY_TO_BE_INCORRECT)
2559
2660
  };
2560
2661
  }
2561
- function errorConflictingSourcemapSources(filename) {
2662
+ function logConflictingSourcemapSources(filename) {
2562
2663
  return {
2563
2664
  code: SOURCEMAP_BROKEN,
2564
2665
  message: `Multiple conflicting contents for sourcemap source ${filename}`
2565
2666
  };
2566
2667
  }
2567
- function errorInvalidSourcemapForError(error, id, column, line, pos) {
2668
+ function logInvalidSourcemapForError(error, id, column, line, pos) {
2568
2669
  return {
2569
2670
  cause: error,
2570
2671
  code: SOURCEMAP_ERROR,
@@ -2578,7 +2679,7 @@ function errorInvalidSourcemapForError(error, id, column, line, pos) {
2578
2679
  pos
2579
2680
  };
2580
2681
  }
2581
- function errorSyntheticNamedExportsNeedNamespaceExport(id, syntheticNamedExportsOption) {
2682
+ function logSyntheticNamedExportsNeedNamespaceExport(id, syntheticNamedExportsOption) {
2582
2683
  return {
2583
2684
  code: SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT,
2584
2685
  exporter: id,
@@ -2587,14 +2688,14 @@ function errorSyntheticNamedExportsNeedNamespaceExport(id, syntheticNamedExports
2587
2688
  : 'a default export'} that does not reexport an unresolved named export of the same module.`
2588
2689
  };
2589
2690
  }
2590
- function errorThisIsUndefined() {
2691
+ function logThisIsUndefined() {
2591
2692
  return {
2592
2693
  code: THIS_IS_UNDEFINED,
2593
2694
  message: `The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten`,
2594
2695
  url: getRollupUrl(URL_THIS_IS_UNDEFINED)
2595
2696
  };
2596
2697
  }
2597
- function errorUnexpectedNamedImport(id, imported, isReexport) {
2698
+ function logUnexpectedNamedImport(id, imported, isReexport) {
2598
2699
  const importType = isReexport ? 'reexport' : 'import';
2599
2700
  return {
2600
2701
  code: UNEXPECTED_NAMED_IMPORT,
@@ -2603,7 +2704,7 @@ function errorUnexpectedNamedImport(id, imported, isReexport) {
2603
2704
  url: getRollupUrl(URL_OUTPUT_INTEROP)
2604
2705
  };
2605
2706
  }
2606
- function errorUnexpectedNamespaceReexport(id) {
2707
+ function logUnexpectedNamespaceReexport(id) {
2607
2708
  return {
2608
2709
  code: UNEXPECTED_NAMED_IMPORT,
2609
2710
  exporter: id,
@@ -2611,25 +2712,25 @@ function errorUnexpectedNamespaceReexport(id) {
2611
2712
  url: getRollupUrl(URL_OUTPUT_INTEROP)
2612
2713
  };
2613
2714
  }
2614
- function errorUnknownOption(optionType, unknownOptions, validOptions) {
2715
+ function logUnknownOption(optionType, unknownOptions, validOptions) {
2615
2716
  return {
2616
2717
  code: UNKNOWN_OPTION,
2617
2718
  message: `Unknown ${optionType}: ${unknownOptions.join(', ')}. Allowed options: ${validOptions.join(', ')}`
2618
2719
  };
2619
2720
  }
2620
- function errorEntryCannotBeExternal(unresolvedId) {
2721
+ function logEntryCannotBeExternal(unresolvedId) {
2621
2722
  return {
2622
2723
  code: UNRESOLVED_ENTRY,
2623
2724
  message: `Entry module "${relativeId(unresolvedId)}" cannot be external.`
2624
2725
  };
2625
2726
  }
2626
- function errorUnresolvedEntry(unresolvedId) {
2727
+ function logUnresolvedEntry(unresolvedId) {
2627
2728
  return {
2628
2729
  code: UNRESOLVED_ENTRY,
2629
2730
  message: `Could not resolve entry module "${relativeId(unresolvedId)}".`
2630
2731
  };
2631
2732
  }
2632
- function errorUnresolvedImport(source, importer) {
2733
+ function logUnresolvedImport(source, importer) {
2633
2734
  return {
2634
2735
  code: UNRESOLVED_IMPORT,
2635
2736
  exporter: source,
@@ -2637,7 +2738,7 @@ function errorUnresolvedImport(source, importer) {
2637
2738
  message: `Could not resolve "${source}" from "${relativeId(importer)}"`
2638
2739
  };
2639
2740
  }
2640
- function errorUnresolvedImportTreatedAsExternal(source, importer) {
2741
+ function logUnresolvedImportTreatedAsExternal(source, importer) {
2641
2742
  return {
2642
2743
  code: UNRESOLVED_IMPORT,
2643
2744
  exporter: source,
@@ -2646,7 +2747,7 @@ function errorUnresolvedImportTreatedAsExternal(source, importer) {
2646
2747
  url: getRollupUrl(URL_TREATING_MODULE_AS_EXTERNAL_DEPENDENCY)
2647
2748
  };
2648
2749
  }
2649
- function errorUnusedExternalImports(externalId, names, importers) {
2750
+ function logUnusedExternalImports(externalId, names, importers) {
2650
2751
  return {
2651
2752
  code: UNUSED_EXTERNAL_IMPORT,
2652
2753
  exporter: externalId,
@@ -2658,96 +2759,25 @@ function errorUnusedExternalImports(externalId, names, importers) {
2658
2759
  names
2659
2760
  };
2660
2761
  }
2661
- function errorFailedValidation(message) {
2762
+ function logFailedValidation(message) {
2662
2763
  return {
2663
2764
  code: VALIDATION_ERROR,
2664
2765
  message
2665
2766
  };
2666
2767
  }
2667
2768
  function warnDeprecation(deprecation, urlSnippet, activeDeprecation, options, plugin) {
2668
- warnDeprecationWithOptions(deprecation, urlSnippet, activeDeprecation, options.onwarn, options.strictDeprecations, plugin);
2769
+ warnDeprecationWithOptions(deprecation, urlSnippet, activeDeprecation, options.onLog, options.strictDeprecations, plugin);
2669
2770
  }
2670
- function warnDeprecationWithOptions(deprecation, urlSnippet, activeDeprecation, warn, strictDeprecations, plugin) {
2771
+ function warnDeprecationWithOptions(deprecation, urlSnippet, activeDeprecation, log, strictDeprecations, plugin) {
2671
2772
  if (activeDeprecation || strictDeprecations) {
2672
- const warning = errorDeprecation(deprecation, urlSnippet, plugin);
2773
+ const warning = logDeprecation(deprecation, urlSnippet, plugin);
2673
2774
  if (strictDeprecations) {
2674
2775
  return error(warning);
2675
2776
  }
2676
- warn(warning);
2777
+ log(LOGLEVEL_WARN, warning);
2677
2778
  }
2678
2779
  }
2679
2780
 
2680
- const RESERVED_NAMES = new Set([
2681
- 'await',
2682
- 'break',
2683
- 'case',
2684
- 'catch',
2685
- 'class',
2686
- 'const',
2687
- 'continue',
2688
- 'debugger',
2689
- 'default',
2690
- 'delete',
2691
- 'do',
2692
- 'else',
2693
- 'enum',
2694
- 'eval',
2695
- 'export',
2696
- 'extends',
2697
- 'false',
2698
- 'finally',
2699
- 'for',
2700
- 'function',
2701
- 'if',
2702
- 'implements',
2703
- 'import',
2704
- 'in',
2705
- 'instanceof',
2706
- 'interface',
2707
- 'let',
2708
- 'NaN',
2709
- 'new',
2710
- 'null',
2711
- 'package',
2712
- 'private',
2713
- 'protected',
2714
- 'public',
2715
- 'return',
2716
- 'static',
2717
- 'super',
2718
- 'switch',
2719
- 'this',
2720
- 'throw',
2721
- 'true',
2722
- 'try',
2723
- 'typeof',
2724
- 'undefined',
2725
- 'var',
2726
- 'void',
2727
- 'while',
2728
- 'with',
2729
- 'yield'
2730
- ]);
2731
- const RESERVED_NAMES$1 = RESERVED_NAMES;
2732
-
2733
- const illegalCharacters = /[^\w$]/g;
2734
- const startsWithDigit = (value) => /\d/.test(value[0]);
2735
- const needsEscape = (value) => startsWithDigit(value) || RESERVED_NAMES$1.has(value) || value === 'arguments';
2736
- function isLegal(value) {
2737
- if (needsEscape(value)) {
2738
- return false;
2739
- }
2740
- return !illegalCharacters.test(value);
2741
- }
2742
- function makeLegal(value) {
2743
- value = value
2744
- .replace(/-(\w)/g, (_, letter) => letter.toUpperCase())
2745
- .replace(illegalCharacters, '_');
2746
- if (needsEscape(value))
2747
- value = `_${value}`;
2748
- return value || '_';
2749
- }
2750
-
2751
2781
  class ExternalModule {
2752
2782
  constructor(options, id, moduleSideEffects, meta, renormalizeRenderPath, assertions) {
2753
2783
  this.options = options;
@@ -2830,7 +2860,7 @@ class ExternalModule {
2830
2860
  }
2831
2861
  }
2832
2862
  const importersArray = [...importersSet];
2833
- this.options.onwarn(errorUnusedExternalImports(this.id, unused, importersArray));
2863
+ this.options.onLog(LOGLEVEL_WARN, logUnusedExternalImports(this.id, unused, importersArray));
2834
2864
  }
2835
2865
  }
2836
2866
 
@@ -8325,7 +8355,7 @@ class Identifier extends NodeBase {
8325
8355
  }
8326
8356
  }
8327
8357
  disallowImportReassignment() {
8328
- return this.context.error(errorIllegalImportReassignment(this.name, this.context.module.id), this.start);
8358
+ return this.context.error(logIllegalImportReassignment(this.name, this.context.module.id), this.start);
8329
8359
  }
8330
8360
  getVariableRespectingTDZ() {
8331
8361
  if (this.isPossibleTDZ()) {
@@ -8533,9 +8563,9 @@ class ExpressionStatement extends NodeBase {
8533
8563
  if (this.directive &&
8534
8564
  this.directive !== 'use strict' &&
8535
8565
  this.parent.type === Program$1) {
8536
- this.context.warn(
8566
+ this.context.log(LOGLEVEL_WARN,
8537
8567
  // This is necessary, because either way (deleting or not) can lead to errors.
8538
- errorModuleLevelDirective(this.directive, this.context.module.id), this.start);
8568
+ logModuleLevelDirective(this.directive, this.context.module.id), this.start);
8539
8569
  }
8540
8570
  }
8541
8571
  render(code, options) {
@@ -9580,7 +9610,7 @@ class MemberExpression extends NodeBase {
9580
9610
  if (this.variable) {
9581
9611
  this.context.includeVariableInModule(this.variable);
9582
9612
  }
9583
- this.context.warn(errorIllegalImportReassignment(this.object.name, this.context.module.id), this.start);
9613
+ this.context.log(LOGLEVEL_WARN, logIllegalImportReassignment(this.object.name, this.context.module.id), this.start);
9584
9614
  }
9585
9615
  }
9586
9616
  }
@@ -9626,7 +9656,7 @@ function resolveNamespaceVariables(baseVariable, path, astContext) {
9626
9656
  if (!variable) {
9627
9657
  if (path.length === 1) {
9628
9658
  const fileName = baseVariable.context.fileName;
9629
- astContext.warn(errorMissingExport(exportName, astContext.module.id, fileName), path[0].pos);
9659
+ astContext.log(LOGLEVEL_WARN, logMissingExport(exportName, astContext.module.id, fileName), path[0].pos);
9630
9660
  return 'undefined';
9631
9661
  }
9632
9662
  return null;
@@ -9733,10 +9763,10 @@ class CallExpression extends CallExpressionBase {
9733
9763
  if (this.callee instanceof Identifier) {
9734
9764
  const variable = this.scope.findVariable(this.callee.name);
9735
9765
  if (variable.isNamespace) {
9736
- this.context.warn(errorCannotCallNamespace(this.callee.name), this.start);
9766
+ this.context.log(LOGLEVEL_WARN, logCannotCallNamespace(this.callee.name), this.start);
9737
9767
  }
9738
9768
  if (this.callee.name === 'eval') {
9739
- this.context.warn(errorEval(this.context.module.id), this.start);
9769
+ this.context.log(LOGLEVEL_WARN, logEval(this.context.module.id), this.start);
9740
9770
  }
9741
9771
  }
9742
9772
  this.interaction = {
@@ -11849,29 +11879,6 @@ class ObjectExpression extends NodeBase {
11849
11879
  class PrivateIdentifier extends NodeBase {
11850
11880
  }
11851
11881
 
11852
- function getOriginalLocation(sourcemapChain, location) {
11853
- const filteredSourcemapChain = sourcemapChain.filter((sourcemap) => !!sourcemap.mappings);
11854
- traceSourcemap: while (filteredSourcemapChain.length > 0) {
11855
- const sourcemap = filteredSourcemapChain.pop();
11856
- const line = sourcemap.mappings[location.line - 1];
11857
- if (line) {
11858
- const filteredLine = line.filter((segment) => segment.length > 1);
11859
- const lastSegment = filteredLine[filteredLine.length - 1];
11860
- for (const segment of filteredLine) {
11861
- if (segment[0] >= location.column || segment === lastSegment) {
11862
- location = {
11863
- column: segment[3],
11864
- line: segment[2] + 1
11865
- };
11866
- continue traceSourcemap;
11867
- }
11868
- }
11869
- }
11870
- throw new Error("Can't resolve original location of error.");
11871
- }
11872
- return location;
11873
- }
11874
-
11875
11882
  class Program extends NodeBase {
11876
11883
  constructor() {
11877
11884
  super(...arguments);
@@ -11891,19 +11898,8 @@ class Program extends NodeBase {
11891
11898
  if (node.hasEffects(context)) {
11892
11899
  if (this.context.options.experimentalLogSideEffects && !this.hasLoggedEffect) {
11893
11900
  this.hasLoggedEffect = true;
11894
- const { code, module } = this.context;
11895
- const { line, column } = locate(code, node.start, { offsetLine: 1 });
11896
- console.log(`First side effect in ${relativeId(module.id)} is at (${line}:${column})\n${getCodeFrame(code, line, column)}`);
11897
- try {
11898
- const { column: originalColumn, line: originalLine } = getOriginalLocation(module.sourcemapChain, { column, line });
11899
- if (originalLine !== line) {
11900
- console.log(`Original location is at (${originalLine}:${originalColumn})\n${getCodeFrame(module.originalCode, originalLine, originalColumn)}\n`);
11901
- }
11902
- }
11903
- catch {
11904
- /* ignored */
11905
- }
11906
- console.log();
11901
+ const { code, log, module } = this.context;
11902
+ log(LOGLEVEL_INFO, logFirstSideEffect(code, module.id, locate(code, node.start, { offsetLine: 1 })), node.start);
11907
11903
  }
11908
11904
  return (this.hasCachedEffect = true);
11909
11905
  }
@@ -12264,7 +12260,7 @@ class TaggedTemplateExpression extends CallExpressionBase {
12264
12260
  const name = this.tag.name;
12265
12261
  const variable = this.scope.findVariable(name);
12266
12262
  if (variable.isNamespace) {
12267
- this.context.warn(errorCannotCallNamespace(name), this.start);
12263
+ this.context.log(LOGLEVEL_WARN, logCannotCallNamespace(name), this.start);
12268
12264
  }
12269
12265
  }
12270
12266
  }
@@ -12511,7 +12507,7 @@ class ThisExpression extends NodeBase {
12511
12507
  this.alias =
12512
12508
  this.scope.findLexicalBoundary() instanceof ModuleScope ? this.context.moduleContext : null;
12513
12509
  if (this.alias === 'undefined') {
12514
- this.context.warn(errorThisIsUndefined(), this.start);
12510
+ this.context.log(LOGLEVEL_WARN, logThisIsUndefined(), this.start);
12515
12511
  }
12516
12512
  }
12517
12513
  render(code) {
@@ -13154,6 +13150,29 @@ function getId(m) {
13154
13150
  return m.id;
13155
13151
  }
13156
13152
 
13153
+ function getOriginalLocation(sourcemapChain, location) {
13154
+ const filteredSourcemapChain = sourcemapChain.filter((sourcemap) => !!sourcemap.mappings);
13155
+ traceSourcemap: while (filteredSourcemapChain.length > 0) {
13156
+ const sourcemap = filteredSourcemapChain.pop();
13157
+ const line = sourcemap.mappings[location.line - 1];
13158
+ if (line) {
13159
+ const filteredLine = line.filter((segment) => segment.length > 1);
13160
+ const lastSegment = filteredLine[filteredLine.length - 1];
13161
+ for (const segment of filteredLine) {
13162
+ if (segment[0] >= location.column || segment === lastSegment) {
13163
+ location = {
13164
+ column: segment[3],
13165
+ line: segment[2] + 1
13166
+ };
13167
+ continue traceSourcemap;
13168
+ }
13169
+ }
13170
+ }
13171
+ throw new Error("Can't resolve original location of error.");
13172
+ }
13173
+ return location;
13174
+ }
13175
+
13157
13176
  function getAssertionsFromImportExpression(node) {
13158
13177
  const assertProperty = node.arguments?.[0]?.properties.find((property) => getPropertyKey(property) === 'assert')?.value;
13159
13178
  if (!assertProperty) {
@@ -13330,7 +13349,7 @@ function getVariableForExportNameRecursive(target, name, importerForSideEffects,
13330
13349
  const searchedModules = searchedNamesAndModules.get(name);
13331
13350
  if (searchedModules) {
13332
13351
  if (searchedModules.has(target)) {
13333
- return isExportAllSearch ? [null] : error(errorCircularReexport(name, target.id));
13352
+ return isExportAllSearch ? [null] : error(logCircularReexport(name, target.id));
13334
13353
  }
13335
13354
  searchedModules.add(target);
13336
13355
  }
@@ -13656,7 +13675,7 @@ class Module {
13656
13675
  : 'default', { onlyExplicit: true });
13657
13676
  }
13658
13677
  if (!this.syntheticNamespace) {
13659
- return error(errorSyntheticNamedExportsNeedNamespaceExport(this.id, this.info.syntheticNamedExports));
13678
+ return error(logSyntheticNamedExportsNeedNamespaceExport(this.id, this.info.syntheticNamedExports));
13660
13679
  }
13661
13680
  return this.syntheticNamespace;
13662
13681
  }
@@ -13675,7 +13694,7 @@ class Module {
13675
13694
  if (reexportDeclaration) {
13676
13695
  const [variable] = getVariableForExportNameRecursive(reexportDeclaration.module, reexportDeclaration.localName, importerForSideEffects, false, searchedNamesAndModules);
13677
13696
  if (!variable) {
13678
- return this.error(errorMissingExport(reexportDeclaration.localName, this.id, reexportDeclaration.module.id), reexportDeclaration.start);
13697
+ return this.error(logMissingExport(reexportDeclaration.localName, this.id, reexportDeclaration.module.id), reexportDeclaration.start);
13679
13698
  }
13680
13699
  if (importerForSideEffects) {
13681
13700
  setAlternativeExporterIfCyclic(variable, importerForSideEffects, this);
@@ -13812,13 +13831,17 @@ class Module {
13812
13831
  }
13813
13832
  this.exportAllModules.push(...externalExportAllModules);
13814
13833
  }
13834
+ log(level, properties, pos) {
13835
+ this.addLocationToLogProps(properties, pos);
13836
+ this.options.onLog(level, properties);
13837
+ }
13815
13838
  render(options) {
13816
13839
  const source = this.magicString.clone();
13817
13840
  this.ast.render(source, options);
13818
13841
  source.trim();
13819
13842
  const { usesTopLevelAwait } = this.astContext;
13820
13843
  if (usesTopLevelAwait && options.format !== 'es' && options.format !== 'system') {
13821
- return error(errorInvalidFormatForTopLevelAwait(this.id, options.format));
13844
+ return error(logInvalidFormatForTopLevelAwait(this.id, options.format));
13822
13845
  }
13823
13846
  return { source, usesTopLevelAwait };
13824
13847
  }
@@ -13863,6 +13886,7 @@ class Module {
13863
13886
  includeAllExports: () => this.includeAllExports(true),
13864
13887
  includeDynamicImport: this.includeDynamicImport.bind(this),
13865
13888
  includeVariableInModule: this.includeVariableInModule.bind(this),
13889
+ log: this.log.bind(this),
13866
13890
  magicString: this.magicString,
13867
13891
  manualPureFunctions: this.graph.pureFunctions,
13868
13892
  module: this,
@@ -13871,8 +13895,7 @@ class Module {
13871
13895
  requestTreeshakingPass: () => (this.graph.needsTreeshakingPass = true),
13872
13896
  traceExport: (name) => this.getVariableForExportName(name)[0],
13873
13897
  traceVariable: this.traceVariable.bind(this),
13874
- usesTopLevelAwait: false,
13875
- warn: this.warn.bind(this)
13898
+ usesTopLevelAwait: false
13876
13899
  };
13877
13900
  this.scope = new ModuleScope(this.graph.scope, this.astContext);
13878
13901
  this.namespace = new NamespaceVariable(this.astContext);
@@ -13932,7 +13955,7 @@ class Module {
13932
13955
  }
13933
13956
  const [declaration] = getVariableForExportNameRecursive(otherModule, importDescription.name, importerForSideEffects || this, isExportAllSearch, searchedNamesAndModules);
13934
13957
  if (!declaration) {
13935
- return this.error(errorMissingExport(importDescription.name, this.id, otherModule.id), importDescription.start);
13958
+ return this.error(logMissingExport(importDescription.name, this.id, otherModule.id), importDescription.start);
13936
13959
  }
13937
13960
  return declaration;
13938
13961
  }
@@ -13949,10 +13972,6 @@ class Module {
13949
13972
  Object.assign(this.info.meta, meta);
13950
13973
  }
13951
13974
  }
13952
- warn(properties, pos) {
13953
- this.addLocationToLogProps(properties, pos);
13954
- this.options.onwarn(properties);
13955
- }
13956
13975
  addDynamicImport(node) {
13957
13976
  let argument = node.source;
13958
13977
  if (argument instanceof TemplateLiteral) {
@@ -14066,7 +14085,7 @@ class Module {
14066
14085
  code = this.originalCode;
14067
14086
  }
14068
14087
  catch (error_) {
14069
- this.options.onwarn(errorInvalidSourcemapForError(error_, this.id, column, line, pos));
14088
+ this.options.onLog(LOGLEVEL_WARN, logInvalidSourcemapForError(error_, this.id, column, line, pos));
14070
14089
  }
14071
14090
  augmentCodeLocation(properties, { column, line }, code, this.id);
14072
14091
  }
@@ -14107,7 +14126,7 @@ class Module {
14107
14126
  const existingAssertions = this.sourcesWithAssertions.get(source);
14108
14127
  if (existingAssertions) {
14109
14128
  if (doAssertionsDiffer(existingAssertions, parsedAssertions)) {
14110
- this.warn(errorInconsistentImportAssertions(existingAssertions, parsedAssertions, source, this.id), declaration.start);
14129
+ this.log(LOGLEVEL_WARN, logInconsistentImportAssertions(existingAssertions, parsedAssertions, source, this.id), declaration.start);
14111
14130
  }
14112
14131
  }
14113
14132
  else {
@@ -14145,7 +14164,7 @@ class Module {
14145
14164
  if (foundDeclarationList.length === 1) {
14146
14165
  return [usedDeclaration];
14147
14166
  }
14148
- this.options.onwarn(errorNamespaceConflict(name, this.id, foundDeclarationList.map(([, module]) => module.id)));
14167
+ this.options.onLog(LOGLEVEL_WARN, logNamespaceConflict(name, this.id, foundDeclarationList.map(([, module]) => module.id)));
14149
14168
  // TODO we are pretending it was not found while it should behave like "undefined"
14150
14169
  return [null];
14151
14170
  }
@@ -14153,7 +14172,7 @@ class Module {
14153
14172
  const foundDeclarationList = [...foundExternalDeclarations];
14154
14173
  const usedDeclaration = foundDeclarationList[0];
14155
14174
  if (foundDeclarationList.length > 1) {
14156
- this.options.onwarn(errorAmbiguousExternalNamespaces(name, this.id, usedDeclaration.module.id, foundDeclarationList.map(declaration => declaration.module.id)));
14175
+ this.options.onLog(LOGLEVEL_WARN, logAmbiguousExternalNamespaces(name, this.id, usedDeclaration.module.id, foundDeclarationList.map(declaration => declaration.module.id)));
14157
14176
  }
14158
14177
  return [usedDeclaration, true];
14159
14178
  }
@@ -14229,7 +14248,7 @@ class Module {
14229
14248
  }
14230
14249
  }
14231
14250
  shimMissingExport(name) {
14232
- this.options.onwarn(errorShimmedExport(this.id, name));
14251
+ this.options.onLog(LOGLEVEL_WARN, logShimmedExport(this.id, name));
14233
14252
  this.exports.set(name, MISSING_EXPORT_SHIM_DESCRIPTION);
14234
14253
  }
14235
14254
  tryParse() {
@@ -14237,7 +14256,7 @@ class Module {
14237
14256
  return this.graph.contextParse(this.info.code);
14238
14257
  }
14239
14258
  catch (error_) {
14240
- return this.error(errorParseError(error_, this.id), error_.pos);
14259
+ return this.error(logParseError(error_, this.id), error_.pos);
14241
14260
  }
14242
14261
  }
14243
14262
  }
@@ -14538,17 +14557,17 @@ const nodeBuiltins = new Set([
14538
14557
  'timers/promises',
14539
14558
  'util/types'
14540
14559
  ]);
14541
- function warnOnBuiltins(warn, dependencies) {
14560
+ function warnOnBuiltins(log, dependencies) {
14542
14561
  const externalBuiltins = dependencies
14543
14562
  .map(({ importPath }) => importPath)
14544
14563
  .filter(importPath => nodeBuiltins.has(importPath) || importPath.startsWith('node:'));
14545
14564
  if (externalBuiltins.length === 0)
14546
14565
  return;
14547
- warn(errorMissingNodeBuiltins(externalBuiltins));
14566
+ log(LOGLEVEL_WARN, logMissingNodeBuiltins(externalBuiltins));
14548
14567
  }
14549
14568
 
14550
- function amd(magicString, { accessedGlobals, dependencies, exports, hasDefaultExport, hasExports, id, indent: t, intro, isEntryFacade, isModuleFacade, namedExportsMode, outro, snippets, onwarn }, { amd, esModule, externalLiveBindings, freeze, interop, namespaceToStringTag, strict }) {
14551
- warnOnBuiltins(onwarn, dependencies);
14569
+ function amd(magicString, { accessedGlobals, dependencies, exports, hasDefaultExport, hasExports, id, indent: t, intro, isEntryFacade, isModuleFacade, namedExportsMode, log, outro, snippets }, { amd, esModule, externalLiveBindings, freeze, interop, namespaceToStringTag, strict }) {
14570
+ warnOnBuiltins(log, dependencies);
14552
14571
  const deps = dependencies.map(m => `'${updateExtensionForRelativeAmdId(m.importPath, amd.forceJsExtensionForImports)}'`);
14553
14572
  const parameters = dependencies.map(m => m.name);
14554
14573
  const { n, getNonArrowFunctionIntro, _ } = snippets;
@@ -14773,19 +14792,19 @@ function trimEmptyImports(dependencies) {
14773
14792
  return [];
14774
14793
  }
14775
14794
 
14776
- function iife(magicString, { accessedGlobals, dependencies, exports, hasDefaultExport, hasExports, indent: t, intro, namedExportsMode, outro, snippets, onwarn }, { compact, esModule, extend, freeze, externalLiveBindings, globals, interop, name, namespaceToStringTag, strict }) {
14795
+ function iife(magicString, { accessedGlobals, dependencies, exports, hasDefaultExport, hasExports, indent: t, intro, namedExportsMode, log, outro, snippets }, { compact, esModule, extend, freeze, externalLiveBindings, globals, interop, name, namespaceToStringTag, strict }) {
14777
14796
  const { _, getNonArrowFunctionIntro, getPropertyAccess, n } = snippets;
14778
14797
  const isNamespaced = name && name.includes('.');
14779
14798
  const useVariableAssignment = !extend && !isNamespaced;
14780
14799
  if (name && useVariableAssignment && !isLegal(name)) {
14781
- return error(errorIllegalIdentifierAsName(name));
14800
+ return error(logIllegalIdentifierAsName(name));
14782
14801
  }
14783
- warnOnBuiltins(onwarn, dependencies);
14802
+ warnOnBuiltins(log, dependencies);
14784
14803
  const external = trimEmptyImports(dependencies);
14785
14804
  const deps = external.map(dep => dep.globalName || 'null');
14786
14805
  const parameters = external.map(m => m.name);
14787
14806
  if (hasExports && !name) {
14788
- onwarn(errorMissingNameOptionForIifeExport());
14807
+ log(LOGLEVEL_WARN, logMissingNameOptionForIifeExport());
14789
14808
  }
14790
14809
  if (namedExportsMode && hasExports) {
14791
14810
  if (extend) {
@@ -14977,14 +14996,14 @@ function safeAccess(name, globalVariable, { _, getPropertyAccess }) {
14977
14996
  .map(part => (propertyPath += getPropertyAccess(part)))
14978
14997
  .join(`${_}&&${_}`);
14979
14998
  }
14980
- function umd(magicString, { accessedGlobals, dependencies, exports, hasDefaultExport, hasExports, id, indent: t, intro, namedExportsMode, outro, snippets, onwarn }, { amd, compact, esModule, extend, externalLiveBindings, freeze, interop, name, namespaceToStringTag, globals, noConflict, strict }) {
14999
+ function umd(magicString, { accessedGlobals, dependencies, exports, hasDefaultExport, hasExports, id, indent: t, intro, namedExportsMode, log, outro, snippets }, { amd, compact, esModule, extend, externalLiveBindings, freeze, interop, name, namespaceToStringTag, globals, noConflict, strict }) {
14981
15000
  const { _, cnst, getFunctionIntro, getNonArrowFunctionIntro, getPropertyAccess, n, s } = snippets;
14982
15001
  const factoryVariable = compact ? 'f' : 'factory';
14983
15002
  const globalVariable = compact ? 'g' : 'global';
14984
15003
  if (hasExports && !name) {
14985
- return error(errorMissingNameOptionForUmdExport());
15004
+ return error(logMissingNameOptionForUmdExport());
14986
15005
  }
14987
- warnOnBuiltins(onwarn, dependencies);
15006
+ warnOnBuiltins(log, dependencies);
14988
15007
  const amdDeps = dependencies.map(m => `'${updateExtensionForRelativeAmdId(m.importPath, amd.forceJsExtensionForImports)}'`);
14989
15008
  const cjsDeps = dependencies.map(m => `require('${m.importPath}')`);
14990
15009
  const trimmedImports = trimEmptyImports(dependencies);
@@ -15094,7 +15113,7 @@ async function createAddons(options, outputPluginDriver, chunk) {
15094
15113
  return { banner, footer, intro, outro };
15095
15114
  }
15096
15115
  catch (error_) {
15097
- return error(errorAddonNotGenerated(error_.message, error_.hook, error_.plugin));
15116
+ return error(logAddonNotGenerated(error_.message, error_.hook, error_.plugin));
15098
15117
  }
15099
15118
  }
15100
15119
 
@@ -15247,15 +15266,15 @@ function assignExportsToNames(exports, exportsByName, exportNamesByVariable) {
15247
15266
  }
15248
15267
  }
15249
15268
 
15250
- function getExportMode(chunk, { exports: exportMode, name, format }, facadeModuleId, warn) {
15269
+ function getExportMode(chunk, { exports: exportMode, name, format }, facadeModuleId, log) {
15251
15270
  const exportKeys = chunk.getExportNames();
15252
15271
  if (exportMode === 'default') {
15253
15272
  if (exportKeys.length !== 1 || exportKeys[0] !== 'default') {
15254
- return error(errorIncompatibleExportOptionValue('default', exportKeys, facadeModuleId));
15273
+ return error(logIncompatibleExportOptionValue('default', exportKeys, facadeModuleId));
15255
15274
  }
15256
15275
  }
15257
15276
  else if (exportMode === 'none' && exportKeys.length > 0) {
15258
- return error(errorIncompatibleExportOptionValue('none', exportKeys, facadeModuleId));
15277
+ return error(logIncompatibleExportOptionValue('none', exportKeys, facadeModuleId));
15259
15278
  }
15260
15279
  if (exportMode === 'auto') {
15261
15280
  if (exportKeys.length === 0) {
@@ -15266,7 +15285,7 @@ function getExportMode(chunk, { exports: exportMode, name, format }, facadeModul
15266
15285
  }
15267
15286
  else {
15268
15287
  if (format !== 'es' && format !== 'system' && exportKeys.includes('default')) {
15269
- warn(errorMixedExport(facadeModuleId, name));
15288
+ log(LOGLEVEL_WARN, logMixedExport(facadeModuleId, name));
15270
15289
  }
15271
15290
  exportMode = 'named';
15272
15291
  }
@@ -15343,7 +15362,8 @@ function addStaticDependencies(module, staticDependencies, handledModules, chunk
15343
15362
  }
15344
15363
  }
15345
15364
 
15346
- // Four random characters from the private use area to minimize risk of conflicts
15365
+ // Four random characters from the private use area to minimize risk of
15366
+ // conflicts
15347
15367
  const hashPlaceholderLeft = '!~{';
15348
15368
  const hashPlaceholderRight = '}~';
15349
15369
  const hashPlaceholderOverhead = hashPlaceholderLeft.length + hashPlaceholderRight.length;
@@ -15354,11 +15374,11 @@ const getHashPlaceholderGenerator = () => {
15354
15374
  let nextIndex = 0;
15355
15375
  return (optionName, hashSize = defaultHashSize) => {
15356
15376
  if (hashSize > maxHashSize) {
15357
- return error(errorFailedValidation(`Hashes cannot be longer than ${maxHashSize} characters, received ${hashSize}. Check the "${optionName}" option.`));
15377
+ return error(logFailedValidation(`Hashes cannot be longer than ${maxHashSize} characters, received ${hashSize}. Check the "${optionName}" option.`));
15358
15378
  }
15359
15379
  const placeholder = `${hashPlaceholderLeft}${toBase64(++nextIndex).padStart(hashSize - hashPlaceholderOverhead, '0')}${hashPlaceholderRight}`;
15360
15380
  if (placeholder.length > hashSize) {
15361
- return error(errorFailedValidation(`To generate hashes for this number of chunks (currently ${nextIndex}), you need a minimum hash size of ${placeholder.length}, received ${hashSize}. Check the "${optionName}" option.`));
15381
+ return error(logFailedValidation(`To generate hashes for this number of chunks (currently ${nextIndex}), you need a minimum hash size of ${placeholder.length}, received ${hashSize}. Check the "${optionName}" option.`));
15362
15382
  }
15363
15383
  return placeholder;
15364
15384
  };
@@ -15425,14 +15445,14 @@ const removeUnreferencedAssets = (outputBundle) => {
15425
15445
 
15426
15446
  function renderNamePattern(pattern, patternName, replacements) {
15427
15447
  if (isPathFragment(pattern))
15428
- return error(errorFailedValidation(`Invalid pattern "${pattern}" for "${patternName}", patterns can be neither absolute nor relative paths. If you want your files to be stored in a subdirectory, write its name without a leading slash like this: subdirectory/pattern.`));
15448
+ return error(logFailedValidation(`Invalid pattern "${pattern}" for "${patternName}", patterns can be neither absolute nor relative paths. If you want your files to be stored in a subdirectory, write its name without a leading slash like this: subdirectory/pattern.`));
15429
15449
  return pattern.replace(/\[(\w+)(:\d+)?]/g, (_match, type, size) => {
15430
15450
  if (!replacements.hasOwnProperty(type) || (size && type !== 'hash')) {
15431
- return error(errorFailedValidation(`"[${type}${size || ''}]" is not a valid placeholder in the "${patternName}" pattern.`));
15451
+ return error(logFailedValidation(`"[${type}${size || ''}]" is not a valid placeholder in the "${patternName}" pattern.`));
15432
15452
  }
15433
15453
  const replacement = replacements[type](size && Number.parseInt(size.slice(1)));
15434
15454
  if (isPathFragment(replacement))
15435
- return error(errorFailedValidation(`Invalid substitution "${replacement}" for placeholder "[${type}]" in "${patternName}" pattern, can be neither absolute nor relative path.`));
15455
+ return error(logFailedValidation(`Invalid substitution "${replacement}" for placeholder "[${type}]" in "${patternName}" pattern, can be neither absolute nor relative path.`));
15436
15456
  return replacement;
15437
15457
  });
15438
15458
  }
@@ -15457,13 +15477,13 @@ const NON_ASSET_EXTENSIONS = new Set([
15457
15477
  '.cjs',
15458
15478
  '.cts'
15459
15479
  ]);
15460
- function getGlobalName(chunk, globals, hasExports, warn) {
15480
+ function getGlobalName(chunk, globals, hasExports, log) {
15461
15481
  const globalName = typeof globals === 'function' ? globals(chunk.id) : globals[chunk.id];
15462
15482
  if (globalName) {
15463
15483
  return globalName;
15464
15484
  }
15465
15485
  if (hasExports) {
15466
- warn(errorMissingGlobalName(chunk.id, chunk.variableName));
15486
+ log(LOGLEVEL_WARN, logMissingGlobalName(chunk.id, chunk.variableName));
15467
15487
  return chunk.variableName;
15468
15488
  }
15469
15489
  }
@@ -15622,7 +15642,7 @@ class Chunk {
15622
15642
  assignExportsToNames(remainingExports, this.exportsByName, this.exportNamesByVariable);
15623
15643
  }
15624
15644
  if (this.outputOptions.preserveModules || (this.facadeModule && this.facadeModule.info.isEntry))
15625
- this.exportMode = getExportMode(this, this.outputOptions, this.facadeModule.id, this.inputOptions.onwarn);
15645
+ this.exportMode = getExportMode(this, this.outputOptions, this.facadeModule.id, this.inputOptions.onLog);
15626
15646
  }
15627
15647
  generateFacades() {
15628
15648
  const facades = [];
@@ -15770,7 +15790,7 @@ class Chunk {
15770
15790
  }
15771
15791
  }
15772
15792
  async render() {
15773
- const { dependencies, exportMode, facadeModule, inputOptions: { onwarn }, outputOptions, pluginDriver, snippets } = this;
15793
+ const { dependencies, exportMode, facadeModule, inputOptions: { onLog }, outputOptions, pluginDriver, snippets } = this;
15774
15794
  const { format, hoistTransitiveImports, preserveModules } = outputOptions;
15775
15795
  // for static and dynamic entry points, add transitive dependencies to this
15776
15796
  // chunk's dependencies to avoid loading latency
@@ -15820,8 +15840,8 @@ class Chunk {
15820
15840
  intro,
15821
15841
  isEntryFacade: preserveModules || (facadeModule !== null && facadeModule.info.isEntry),
15822
15842
  isModuleFacade: facadeModule !== null,
15843
+ log: onLog,
15823
15844
  namedExportsMode: exportMode !== 'default',
15824
- onwarn,
15825
15845
  outro,
15826
15846
  snippets,
15827
15847
  usesTopLevelAwait
@@ -15876,7 +15896,7 @@ class Chunk {
15876
15896
  if (alternativeReexportModule) {
15877
15897
  const exportingChunk = this.chunkByModule.get(alternativeReexportModule);
15878
15898
  if (exportingChunk !== exportChunk) {
15879
- this.inputOptions.onwarn(errorCyclicCrossChunkReexport(
15899
+ this.inputOptions.onLog(LOGLEVEL_WARN, logCyclicCrossChunkReexport(
15880
15900
  // Namespaces do not have an export name
15881
15901
  variableModule.getExportNamesByVariable().get(variable)?.[0] || '*', variableModule.id, alternativeReexportModule.id, importingModule.id, this.outputOptions.preserveModules));
15882
15902
  }
@@ -16064,7 +16084,7 @@ class Chunk {
16064
16084
  dependency = this.externalChunkByModule.get(module);
16065
16085
  imported = variable.name;
16066
16086
  if (imported !== 'default' && imported !== '*' && interop(module.id) === 'defaultOnly') {
16067
- return error(errorUnexpectedNamedImport(module.id, imported, false));
16087
+ return error(logUnexpectedNamedImport(module.id, imported, false));
16068
16088
  }
16069
16089
  }
16070
16090
  else {
@@ -16154,7 +16174,7 @@ class Chunk {
16154
16174
  if (exportName[0] === '*') {
16155
16175
  const id = exportName.slice(1);
16156
16176
  if (interop(id) === 'defaultOnly') {
16157
- this.inputOptions.onwarn(errorUnexpectedNamespaceReexport(id));
16177
+ this.inputOptions.onLog(LOGLEVEL_WARN, logUnexpectedNamespaceReexport(id));
16158
16178
  }
16159
16179
  needsLiveBinding = externalLiveBindings;
16160
16180
  dependency = this.externalChunkByModule.get(this.modulesById.get(id));
@@ -16176,7 +16196,7 @@ class Chunk {
16176
16196
  dependency = this.externalChunkByModule.get(module);
16177
16197
  imported = variable.name;
16178
16198
  if (imported !== 'default' && imported !== '*' && interop(module.id) === 'defaultOnly') {
16179
- return error(errorUnexpectedNamedImport(module.id, imported, true));
16199
+ return error(logUnexpectedNamedImport(module.id, imported, true));
16180
16200
  }
16181
16201
  needsLiveBinding =
16182
16202
  externalLiveBindings &&
@@ -16221,7 +16241,7 @@ class Chunk {
16221
16241
  defaultVariableName: dep.defaultVariableName,
16222
16242
  globalName: dep instanceof ExternalChunk &&
16223
16243
  (this.outputOptions.format === 'umd' || this.outputOptions.format === 'iife') &&
16224
- getGlobalName(dep, this.outputOptions.globals, (imports || reexports) !== null, this.inputOptions.onwarn),
16244
+ getGlobalName(dep, this.outputOptions.globals, (imports || reexports) !== null, this.inputOptions.onLog),
16225
16245
  importPath,
16226
16246
  imports,
16227
16247
  isChunk: dep instanceof Chunk,
@@ -16245,7 +16265,7 @@ class Chunk {
16245
16265
  }
16246
16266
  // This method changes properties on the AST before rendering and must not be async
16247
16267
  renderModules(fileName) {
16248
- const { accessedGlobalsByScope, dependencies, exportNamesByVariable, includedNamespaces, inputOptions: { onwarn }, isEmpty, orderedModules, outputOptions, pluginDriver, renderedModules, snippets } = this;
16268
+ const { accessedGlobalsByScope, dependencies, exportNamesByVariable, includedNamespaces, inputOptions: { onLog }, isEmpty, orderedModules, outputOptions, pluginDriver, renderedModules, snippets } = this;
16249
16269
  const { compact, dynamicImportFunction, format, freeze, namespaceToStringTag } = outputOptions;
16250
16270
  const { _, cnst, n } = snippets;
16251
16271
  this.setDynamicImportResolutions(fileName);
@@ -16318,7 +16338,7 @@ class Chunk {
16318
16338
  }
16319
16339
  const renderedSource = compact ? magicString : magicString.trim();
16320
16340
  if (isEmpty && this.getExportNames().length === 0 && dependencies.size === 0) {
16321
- onwarn(errorEmptyChunk(this.getChunkName()));
16341
+ onLog(LOGLEVEL_WARN, logEmptyChunk(this.getChunkName()));
16322
16342
  }
16323
16343
  return { accessedGlobals, indent, magicString, renderedSource, usedModules, usesTopLevelAwait };
16324
16344
  }
@@ -16607,7 +16627,7 @@ function* concatLazy(iterables) {
16607
16627
  * those chunks that are already loaded for that dynamic entry and create
16608
16628
  * another round of chunks.
16609
16629
  */
16610
- function getChunkAssignments(entries, manualChunkAliasByEntry, minChunkSize) {
16630
+ function getChunkAssignments(entries, manualChunkAliasByEntry, minChunkSize, log) {
16611
16631
  const { chunkDefinitions, modulesInManualChunks } = getChunkDefinitionsFromManualChunks(manualChunkAliasByEntry);
16612
16632
  const { allEntries, dependentEntriesByModule, dynamicallyDependentEntriesByDynamicEntry, dynamicImportsByEntry } = analyzeModuleGraph(entries);
16613
16633
  // Each chunk is identified by its position in this array
@@ -16615,7 +16635,7 @@ function getChunkAssignments(entries, manualChunkAliasByEntry, minChunkSize) {
16615
16635
  // This mutates initialChunks but also clears
16616
16636
  // dynamicallyDependentEntriesByDynamicEntry as side effect
16617
16637
  removeUnnecessaryDependentEntries(initialChunks, dynamicallyDependentEntriesByDynamicEntry, dynamicImportsByEntry, allEntries);
16618
- chunkDefinitions.push(...getOptimizedChunks(getChunksFromDependentEntries(initialChunks), allEntries.length, minChunkSize).map(({ modules }) => ({
16638
+ chunkDefinitions.push(...getOptimizedChunks(getChunksFromDependentEntries(initialChunks), allEntries.length, minChunkSize, log).map(({ modules }) => ({
16619
16639
  alias: null,
16620
16640
  modules
16621
16641
  })));
@@ -16871,7 +16891,7 @@ function removeUnnecessaryDependentEntries(chunks, dynamicallyDependentEntriesBy
16871
16891
  * following the rule (a), starting with the smallest chunks to look for
16872
16892
  * possible merge targets.
16873
16893
  */
16874
- function getOptimizedChunks(initialChunks, numberOfEntries, minChunkSize) {
16894
+ function getOptimizedChunks(initialChunks, numberOfEntries, minChunkSize, log) {
16875
16895
  timeStart('optimize chunks', 3);
16876
16896
  const chunkPartition = getPartitionedChunks(initialChunks, numberOfEntries, minChunkSize);
16877
16897
  if (!chunkPartition) {
@@ -16879,10 +16899,10 @@ function getOptimizedChunks(initialChunks, numberOfEntries, minChunkSize) {
16879
16899
  return initialChunks; // the actual modules
16880
16900
  }
16881
16901
  minChunkSize > 1 &&
16882
- console.log('Before eliminating small chunks, there were\n', initialChunks.length, 'chunks, of which\n', chunkPartition.small.size, 'were below minChunkSize.');
16902
+ log('info', logOptimizeChunkStatus(initialChunks.length, chunkPartition.small.size, 'Initially'));
16883
16903
  mergeChunks(chunkPartition, minChunkSize);
16884
16904
  minChunkSize > 1 &&
16885
- console.log('After merging chunks,\n', chunkPartition.small.size + chunkPartition.big.size, 'chunks remain, of which\n', chunkPartition.small.size, 'are below minChunkSize.');
16905
+ log('info', logOptimizeChunkStatus(chunkPartition.small.size + chunkPartition.big.size, chunkPartition.small.size, 'After merging chunks'));
16886
16906
  timeEnd('optimize chunks', 3);
16887
16907
  return [...chunkPartition.small, ...chunkPartition.big];
16888
16908
  }
@@ -17293,7 +17313,7 @@ class Link {
17293
17313
  sourcesContent[sourceIndex] = content;
17294
17314
  }
17295
17315
  else if (content != null && sourcesContent[sourceIndex] !== content) {
17296
- return error(errorConflictingSourcemapSources(filename));
17316
+ return error(logConflictingSourcemapSources(filename));
17297
17317
  }
17298
17318
  const tracedSegment = [segment[0], sourceIndex, line, column];
17299
17319
  if (name) {
@@ -17343,12 +17363,12 @@ class Link {
17343
17363
  return null;
17344
17364
  }
17345
17365
  }
17346
- function getLinkMap(warn) {
17366
+ function getLinkMap(log) {
17347
17367
  return function linkMap(source, map) {
17348
17368
  if (map.mappings) {
17349
17369
  return new Link(map, [source]);
17350
17370
  }
17351
- warn(errorSourcemapBroken(map.plugin));
17371
+ log(LOGLEVEL_WARN, logSourcemapBroken(map.plugin));
17352
17372
  return new Link({
17353
17373
  mappings: [],
17354
17374
  names: []
@@ -17370,8 +17390,8 @@ function getCollapsedSourcemap(id, originalCode, originalSourcemap, sourcemapCha
17370
17390
  }
17371
17391
  return sourcemapChain.reduce(linkMap, source);
17372
17392
  }
17373
- function collapseSourcemaps(file, map, modules, bundleSourcemapChain, excludeContent, warn) {
17374
- const linkMap = getLinkMap(warn);
17393
+ function collapseSourcemaps(file, map, modules, bundleSourcemapChain, excludeContent, log) {
17394
+ const linkMap = getLinkMap(log);
17375
17395
  const moduleSources = modules
17376
17396
  .filter(module => !module.excludeFromSourcemap)
17377
17397
  .map(module => getCollapsedSourcemap(module.id, module.originalCode, module.originalSourcemap, module.sourcemapChain, linkMap));
@@ -17386,11 +17406,11 @@ function collapseSourcemaps(file, map, modules, bundleSourcemapChain, excludeCon
17386
17406
  sourcesContent = (excludeContent ? null : sourcesContent);
17387
17407
  return new SourceMap({ file, mappings, names, sources, sourcesContent });
17388
17408
  }
17389
- function collapseSourcemap(id, originalCode, originalSourcemap, sourcemapChain, warn) {
17409
+ function collapseSourcemap(id, originalCode, originalSourcemap, sourcemapChain, log) {
17390
17410
  if (sourcemapChain.length === 0) {
17391
17411
  return originalSourcemap;
17392
17412
  }
17393
- const source = getCollapsedSourcemap(id, originalCode, originalSourcemap, sourcemapChain, getLinkMap(warn));
17413
+ const source = getCollapsedSourcemap(id, originalCode, originalSourcemap, sourcemapChain, getLinkMap(log));
17394
17414
  const map = source.traceMappings();
17395
17415
  return { version: 3, ...map };
17396
17416
  }
@@ -17415,14 +17435,14 @@ function decodedSourcemap(map) {
17415
17435
  return { ...map, mappings };
17416
17436
  }
17417
17437
 
17418
- async function renderChunks(chunks, bundle, pluginDriver, outputOptions, onwarn) {
17438
+ async function renderChunks(chunks, bundle, pluginDriver, outputOptions, log) {
17419
17439
  timeStart('render chunks', 2);
17420
17440
  reserveEntryChunksInBundle(chunks);
17421
17441
  const renderedChunks = await Promise.all(chunks.map(chunk => chunk.render()));
17422
17442
  timeEnd('render chunks', 2);
17423
17443
  timeStart('transform chunks', 2);
17424
17444
  const chunkGraph = getChunkGraph(chunks);
17425
- const { nonHashedChunksWithPlaceholders, renderedChunksByPlaceholder, hashDependenciesByPlaceholder } = await transformChunksAndGenerateContentHashes(renderedChunks, chunkGraph, outputOptions, pluginDriver, onwarn);
17445
+ const { nonHashedChunksWithPlaceholders, renderedChunksByPlaceholder, hashDependenciesByPlaceholder } = await transformChunksAndGenerateContentHashes(renderedChunks, chunkGraph, outputOptions, pluginDriver, log);
17426
17446
  const hashesByPlaceholder = generateFinalHashes(renderedChunksByPlaceholder, hashDependenciesByPlaceholder, bundle);
17427
17447
  addChunksToBundle(renderedChunksByPlaceholder, hashesByPlaceholder, bundle, nonHashedChunksWithPlaceholders, pluginDriver, outputOptions);
17428
17448
  timeEnd('transform chunks', 2);
@@ -17441,7 +17461,7 @@ function getChunkGraph(chunks) {
17441
17461
  return [renderedChunkInfo.fileName, renderedChunkInfo];
17442
17462
  }));
17443
17463
  }
17444
- async function transformChunk(magicString, fileName, usedModules, chunkGraph, options, outputPluginDriver, onwarn) {
17464
+ async function transformChunk(magicString, fileName, usedModules, chunkGraph, options, outputPluginDriver, log) {
17445
17465
  let map = null;
17446
17466
  const sourcemapChain = [];
17447
17467
  let code = await outputPluginDriver.hookReduceArg0('renderChunk', [magicString.toString(), chunkGraph[fileName], options, { chunks: chunkGraph }], (code, result, plugin) => {
@@ -17472,13 +17492,13 @@ async function transformChunk(magicString, fileName, usedModules, chunkGraph, op
17472
17492
  else
17473
17493
  resultingFile = resolve(fileName);
17474
17494
  const decodedMap = magicString.generateDecodedMap({});
17475
- map = collapseSourcemaps(resultingFile, decodedMap, usedModules, sourcemapChain, sourcemapExcludeSources, onwarn);
17495
+ map = collapseSourcemaps(resultingFile, decodedMap, usedModules, sourcemapChain, sourcemapExcludeSources, log);
17476
17496
  for (let sourcesIndex = 0; sourcesIndex < map.sources.length; ++sourcesIndex) {
17477
17497
  let sourcePath = map.sources[sourcesIndex];
17478
17498
  const sourcemapPath = `${resultingFile}.map`;
17479
17499
  const ignoreList = sourcemapIgnoreList(sourcePath, sourcemapPath);
17480
17500
  if (typeof ignoreList !== 'boolean') {
17481
- error(errorFailedValidation('sourcemapIgnoreList function must return a boolean.'));
17501
+ error(logFailedValidation('sourcemapIgnoreList function must return a boolean.'));
17482
17502
  }
17483
17503
  if (ignoreList) {
17484
17504
  if (map.x_google_ignoreList === undefined) {
@@ -17491,7 +17511,7 @@ async function transformChunk(magicString, fileName, usedModules, chunkGraph, op
17491
17511
  if (sourcemapPathTransform) {
17492
17512
  sourcePath = sourcemapPathTransform(sourcePath, sourcemapPath);
17493
17513
  if (typeof sourcePath !== 'string') {
17494
- error(errorFailedValidation(`sourcemapPathTransform function must return a string.`));
17514
+ error(logFailedValidation(`sourcemapPathTransform function must return a string.`));
17495
17515
  }
17496
17516
  }
17497
17517
  map.sources[sourcesIndex] = normalize(sourcePath);
@@ -17503,7 +17523,7 @@ async function transformChunk(magicString, fileName, usedModules, chunkGraph, op
17503
17523
  map
17504
17524
  };
17505
17525
  }
17506
- async function transformChunksAndGenerateContentHashes(renderedChunks, chunkGraph, outputOptions, pluginDriver, onwarn) {
17526
+ async function transformChunksAndGenerateContentHashes(renderedChunks, chunkGraph, outputOptions, pluginDriver, log) {
17507
17527
  const nonHashedChunksWithPlaceholders = [];
17508
17528
  const renderedChunksByPlaceholder = new Map();
17509
17529
  const hashDependenciesByPlaceholder = new Map();
@@ -17516,7 +17536,7 @@ async function transformChunksAndGenerateContentHashes(renderedChunks, chunkGrap
17516
17536
  const transformedChunk = {
17517
17537
  chunk,
17518
17538
  fileName,
17519
- ...(await transformChunk(magicString, fileName, usedModules, chunkGraph, outputOptions, pluginDriver, onwarn))
17539
+ ...(await transformChunk(magicString, fileName, usedModules, chunkGraph, outputOptions, pluginDriver, log))
17520
17540
  };
17521
17541
  const { code } = transformedChunk;
17522
17542
  if (hashPlaceholder) {
@@ -17633,14 +17653,14 @@ class Bundle {
17633
17653
  const getHashPlaceholder = getHashPlaceholderGenerator();
17634
17654
  const chunks = await this.generateChunks(outputBundle, getHashPlaceholder);
17635
17655
  if (chunks.length > 1) {
17636
- validateOptionsForMultiChunkOutput(this.outputOptions, this.inputOptions.onwarn);
17656
+ validateOptionsForMultiChunkOutput(this.outputOptions, this.inputOptions.onLog);
17637
17657
  }
17638
17658
  this.pluginDriver.setChunkInformation(this.facadeChunkByModule);
17639
17659
  for (const chunk of chunks) {
17640
17660
  chunk.generateExports();
17641
17661
  }
17642
17662
  timeEnd('generate chunks', 2);
17643
- await renderChunks(chunks, outputBundle, this.pluginDriver, this.outputOptions, this.inputOptions.onwarn);
17663
+ await renderChunks(chunks, outputBundle, this.pluginDriver, this.outputOptions, this.inputOptions.onLog);
17644
17664
  }
17645
17665
  catch (error_) {
17646
17666
  await this.pluginDriver.hookParallel('renderError', [error_]);
@@ -17703,7 +17723,7 @@ class Bundle {
17703
17723
  });
17704
17724
  }
17705
17725
  catch (error_) {
17706
- this.inputOptions.onwarn(errorChunkInvalid(file, error_));
17726
+ this.inputOptions.onLog(LOGLEVEL_WARN, logChunkInvalid(file, error_));
17707
17727
  }
17708
17728
  }
17709
17729
  }
@@ -17725,7 +17745,7 @@ class Bundle {
17725
17745
  ? [{ alias: null, modules: includedModules }]
17726
17746
  : preserveModules
17727
17747
  ? includedModules.map(module => ({ alias: null, modules: [module] }))
17728
- : getChunkAssignments(this.graph.entryModules, manualChunkAliasByEntry, experimentalMinChunkSize)) {
17748
+ : getChunkAssignments(this.graph.entryModules, manualChunkAliasByEntry, experimentalMinChunkSize, this.inputOptions.onLog)) {
17729
17749
  sortByExecutionOrder(modules);
17730
17750
  const chunk = new Chunk(modules, this.inputOptions, this.outputOptions, this.unsetOptions, this.pluginDriver, this.graph.modulesById, chunkByModule, externalChunkByModule, this.facadeChunkByModule, this.includedNamespaces, alias, getHashPlaceholder, bundle, inputBase, snippets);
17731
17751
  chunks.push(chunk);
@@ -17740,15 +17760,15 @@ class Bundle {
17740
17760
  return [...chunks, ...facades];
17741
17761
  }
17742
17762
  }
17743
- function validateOptionsForMultiChunkOutput(outputOptions, onWarn) {
17763
+ function validateOptionsForMultiChunkOutput(outputOptions, log) {
17744
17764
  if (outputOptions.format === 'umd' || outputOptions.format === 'iife')
17745
- return error(errorInvalidOption('output.format', URL_OUTPUT_FORMAT, 'UMD and IIFE output formats are not supported for code-splitting builds', outputOptions.format));
17765
+ return error(logInvalidOption('output.format', URL_OUTPUT_FORMAT, 'UMD and IIFE output formats are not supported for code-splitting builds', outputOptions.format));
17746
17766
  if (typeof outputOptions.file === 'string')
17747
- return error(errorInvalidOption('output.file', URL_OUTPUT_DIR, 'when building multiple chunks, the "output.dir" option must be used, not "output.file". To inline dynamic imports, set the "inlineDynamicImports" option'));
17767
+ return error(logInvalidOption('output.file', URL_OUTPUT_DIR, 'when building multiple chunks, the "output.dir" option must be used, not "output.file". To inline dynamic imports, set the "inlineDynamicImports" option'));
17748
17768
  if (outputOptions.sourcemapFile)
17749
- return error(errorInvalidOption('output.sourcemapFile', URL_OUTPUT_SOURCEMAPFILE, '"output.sourcemapFile" is only supported for single-file builds'));
17769
+ return error(logInvalidOption('output.sourcemapFile', URL_OUTPUT_SOURCEMAPFILE, '"output.sourcemapFile" is only supported for single-file builds'));
17750
17770
  if (!outputOptions.amd.autoId && outputOptions.amd.id)
17751
- onWarn(errorInvalidOption('output.amd.id', URL_OUTPUT_AMD_ID, 'this option is only properly supported for single-file builds. Use "output.amd.autoId" and "output.amd.basePath" instead'));
17771
+ log(LOGLEVEL_WARN, logInvalidOption('output.amd.id', URL_OUTPUT_AMD_ID, 'this option is only properly supported for single-file builds. Use "output.amd.autoId" and "output.amd.basePath" instead'));
17752
17772
  }
17753
17773
  function getIncludedModules(modulesById) {
17754
17774
  const includedModules = [];
@@ -17781,7 +17801,7 @@ function getExternalChunkByModule(modulesById, outputOptions, inputBase) {
17781
17801
  function addModuleToManualChunk(alias, module, manualChunkAliasByEntry) {
17782
17802
  const existingAlias = manualChunkAliasByEntry.get(module);
17783
17803
  if (typeof existingAlias === 'string' && existingAlias !== alias) {
17784
- return error(errorCannotAssignModuleToChunk(module.id, alias, existingAlias));
17804
+ return error(logCannotAssignModuleToChunk(module.id, alias, existingAlias));
17785
17805
  }
17786
17806
  manualChunkAliasByEntry.set(module, alias);
17787
17807
  }
@@ -23565,9 +23585,9 @@ const NO_CACHE = {
23565
23585
  function uncacheablePluginError(pluginName) {
23566
23586
  if (pluginName.startsWith(ANONYMOUS_PLUGIN_PREFIX) ||
23567
23587
  pluginName.startsWith(ANONYMOUS_OUTPUT_PLUGIN_PREFIX)) {
23568
- return error(errorAnonymousPluginCache());
23588
+ return error(logAnonymousPluginCache());
23569
23589
  }
23570
- return error(errorDuplicatePluginName(pluginName));
23590
+ return error(logDuplicatePluginName(pluginName));
23571
23591
  }
23572
23592
  function getCacheForUncacheablePlugin(pluginName) {
23573
23593
  return {
@@ -23586,7 +23606,154 @@ function getCacheForUncacheablePlugin(pluginName) {
23586
23606
  };
23587
23607
  }
23588
23608
 
23589
- async function transform(source, module, pluginDriver, warn) {
23609
+ async function asyncFlatten(array) {
23610
+ do {
23611
+ array = (await Promise.all(array)).flat(Infinity);
23612
+ } while (array.some((v) => v?.then));
23613
+ return array;
23614
+ }
23615
+
23616
+ const getOnLog = (config, logLevel, printLog = defaultPrintLog) => {
23617
+ const { onwarn, onLog } = config;
23618
+ const defaultOnLog = getDefaultOnLog(printLog, onwarn);
23619
+ if (onLog) {
23620
+ const minimalPriority = logLevelPriority[logLevel];
23621
+ return (level, log) => onLog(level, addLogToString(log), (level, handledLog) => {
23622
+ if (level === LOGLEVEL_ERROR) {
23623
+ return error(normalizeLog(handledLog));
23624
+ }
23625
+ if (logLevelPriority[level] >= minimalPriority) {
23626
+ defaultOnLog(level, normalizeLog(handledLog));
23627
+ }
23628
+ });
23629
+ }
23630
+ return defaultOnLog;
23631
+ };
23632
+ const getDefaultOnLog = (printLog, onwarn) => onwarn
23633
+ ? (level, log) => {
23634
+ if (level === LOGLEVEL_WARN) {
23635
+ onwarn(addLogToString(log), warning => printLog(LOGLEVEL_WARN, normalizeLog(warning)));
23636
+ }
23637
+ else {
23638
+ printLog(level, log);
23639
+ }
23640
+ }
23641
+ : printLog;
23642
+ const addLogToString = (log) => {
23643
+ Object.defineProperty(log, 'toString', {
23644
+ value: () => getExtendedLogMessage(log),
23645
+ writable: true
23646
+ });
23647
+ return log;
23648
+ };
23649
+ const normalizeLog = (log) => typeof log === 'string'
23650
+ ? { message: log }
23651
+ : typeof log === 'function'
23652
+ ? normalizeLog(log())
23653
+ : log;
23654
+ const getExtendedLogMessage = (log) => {
23655
+ let prefix = '';
23656
+ if (log.plugin) {
23657
+ prefix += `(${log.plugin} plugin) `;
23658
+ }
23659
+ if (log.loc) {
23660
+ prefix += `${relativeId(log.loc.file)} (${log.loc.line}:${log.loc.column}) `;
23661
+ }
23662
+ return prefix + log.message;
23663
+ };
23664
+ const defaultPrintLog = (level, log) => {
23665
+ const message = getExtendedLogMessage(log);
23666
+ switch (level) {
23667
+ case LOGLEVEL_WARN: {
23668
+ return console.warn(message);
23669
+ }
23670
+ case LOGLEVEL_DEBUG: {
23671
+ return console.debug(message);
23672
+ }
23673
+ default: {
23674
+ return console.info(message);
23675
+ }
23676
+ }
23677
+ };
23678
+ function warnUnknownOptions(passedOptions, validOptions, optionType, log, ignoredKeys = /$./) {
23679
+ const validOptionSet = new Set(validOptions);
23680
+ const unknownOptions = Object.keys(passedOptions).filter(key => !(validOptionSet.has(key) || ignoredKeys.test(key)));
23681
+ if (unknownOptions.length > 0) {
23682
+ log(LOGLEVEL_WARN, logUnknownOption(optionType, unknownOptions, [...validOptionSet].sort()));
23683
+ }
23684
+ }
23685
+ const treeshakePresets = {
23686
+ recommended: {
23687
+ annotations: true,
23688
+ correctVarValueBeforeDeclaration: false,
23689
+ manualPureFunctions: EMPTY_ARRAY,
23690
+ moduleSideEffects: () => true,
23691
+ propertyReadSideEffects: true,
23692
+ tryCatchDeoptimization: true,
23693
+ unknownGlobalSideEffects: false
23694
+ },
23695
+ safest: {
23696
+ annotations: true,
23697
+ correctVarValueBeforeDeclaration: true,
23698
+ manualPureFunctions: EMPTY_ARRAY,
23699
+ moduleSideEffects: () => true,
23700
+ propertyReadSideEffects: true,
23701
+ tryCatchDeoptimization: true,
23702
+ unknownGlobalSideEffects: true
23703
+ },
23704
+ smallest: {
23705
+ annotations: true,
23706
+ correctVarValueBeforeDeclaration: false,
23707
+ manualPureFunctions: EMPTY_ARRAY,
23708
+ moduleSideEffects: () => false,
23709
+ propertyReadSideEffects: false,
23710
+ tryCatchDeoptimization: false,
23711
+ unknownGlobalSideEffects: false
23712
+ }
23713
+ };
23714
+ const generatedCodePresets = {
23715
+ es2015: {
23716
+ arrowFunctions: true,
23717
+ constBindings: true,
23718
+ objectShorthand: true,
23719
+ reservedNamesAsProps: true,
23720
+ symbols: true
23721
+ },
23722
+ es5: {
23723
+ arrowFunctions: false,
23724
+ constBindings: false,
23725
+ objectShorthand: false,
23726
+ reservedNamesAsProps: true,
23727
+ symbols: false
23728
+ }
23729
+ };
23730
+ const objectifyOption = (value) => value && typeof value === 'object' ? value : {};
23731
+ const objectifyOptionWithPresets = (presets, optionName, urlSnippet, additionalValues) => (value) => {
23732
+ if (typeof value === 'string') {
23733
+ const preset = presets[value];
23734
+ if (preset) {
23735
+ return preset;
23736
+ }
23737
+ error(logInvalidOption(optionName, urlSnippet, `valid values are ${additionalValues}${printQuotedStringList(Object.keys(presets))}. You can also supply an object for more fine-grained control`, value));
23738
+ }
23739
+ return objectifyOption(value);
23740
+ };
23741
+ const getOptionWithPreset = (value, presets, optionName, urlSnippet, additionalValues) => {
23742
+ const presetName = value?.preset;
23743
+ if (presetName) {
23744
+ const preset = presets[presetName];
23745
+ if (preset) {
23746
+ return { ...preset, ...value };
23747
+ }
23748
+ else {
23749
+ error(logInvalidOption(`${optionName}.preset`, urlSnippet, `valid values are ${printQuotedStringList(Object.keys(presets))}`, presetName));
23750
+ }
23751
+ }
23752
+ return objectifyOptionWithPresets(presets, optionName, urlSnippet, additionalValues)(value);
23753
+ };
23754
+ const normalizePluginOption = async (plugins) => (await asyncFlatten([plugins])).filter(Boolean);
23755
+
23756
+ async function transform(source, module, pluginDriver, log) {
23590
23757
  const id = module.id;
23591
23758
  const sourcemapChain = [];
23592
23759
  let originalSourcemap = source.map === null ? null : decodedSourcemap(source.map);
@@ -23608,7 +23775,7 @@ async function transform(source, module, pluginDriver, warn) {
23608
23775
  module.updateOptions(result);
23609
23776
  if (result.code == null) {
23610
23777
  if (result.map || result.ast) {
23611
- warn(errorNoTransformMapOrAstWithoutCode(plugin.name));
23778
+ log(LOGLEVEL_WARN, logNoTransformMapOrAstWithoutCode(plugin.name));
23612
23779
  }
23613
23780
  return previousCode;
23614
23781
  }
@@ -23627,6 +23794,14 @@ async function transform(source, module, pluginDriver, warn) {
23627
23794
  }
23628
23795
  return code;
23629
23796
  }
23797
+ const getLogHandler = (handler) => (log, pos) => {
23798
+ log = normalizeLog(log);
23799
+ if (pos)
23800
+ augmentCodeLocation(log, pos, currentSource, id);
23801
+ log.id = id;
23802
+ log.hook = 'transform';
23803
+ handler(log);
23804
+ };
23630
23805
  let code;
23631
23806
  try {
23632
23807
  code = await pluginDriver.hookReduceArg0('transform', [currentSource, id], transformReducer, (pluginContext, plugin) => {
@@ -23640,6 +23815,7 @@ async function transform(source, module, pluginDriver, warn) {
23640
23815
  cache: customTransformCache
23641
23816
  ? pluginContext.cache
23642
23817
  : getTrackedPluginCache(pluginContext.cache, useCustomTransformCache),
23818
+ debug: getLogHandler(pluginContext.debug),
23643
23819
  emitFile(emittedFile) {
23644
23820
  emittedFiles.push(emittedFile);
23645
23821
  return pluginDriver.emitFile(emittedFile);
@@ -23654,7 +23830,7 @@ async function transform(source, module, pluginDriver, warn) {
23654
23830
  return pluginContext.error(error_);
23655
23831
  },
23656
23832
  getCombinedSourcemap() {
23657
- const combinedMap = collapseSourcemap(id, originalCode, originalSourcemap, sourcemapChain, warn);
23833
+ const combinedMap = collapseSourcemap(id, originalCode, originalSourcemap, sourcemapChain, log);
23658
23834
  if (!combinedMap) {
23659
23835
  const magicString = new MagicString(originalCode);
23660
23836
  return magicString.generateMap({ hires: true, includeContent: true, source: id });
@@ -23669,23 +23845,16 @@ async function transform(source, module, pluginDriver, warn) {
23669
23845
  sourcesContent: combinedMap.sourcesContent
23670
23846
  });
23671
23847
  },
23848
+ info: getLogHandler(pluginContext.info),
23672
23849
  setAssetSource() {
23673
- return this.error(errorInvalidSetAssetSourceCall());
23850
+ return this.error(logInvalidSetAssetSourceCall());
23674
23851
  },
23675
- warn(warning, pos) {
23676
- if (typeof warning === 'string')
23677
- warning = { message: warning };
23678
- if (pos)
23679
- augmentCodeLocation(warning, pos, currentSource, id);
23680
- warning.id = id;
23681
- warning.hook = 'transform';
23682
- pluginContext.warn(warning);
23683
- }
23852
+ warn: getLogHandler(pluginContext.warn)
23684
23853
  };
23685
23854
  });
23686
23855
  }
23687
23856
  catch (error_) {
23688
- return error(errorPluginError(error_, pluginName, { hook: 'transform', id }));
23857
+ return error(logPluginError(error_, pluginName, { hook: 'transform', id }));
23689
23858
  }
23690
23859
  if (!customTransformCache && // files emitted by a transform hook need to be emitted again if the hook is skipped
23691
23860
  emittedFiles.length > 0)
@@ -23811,7 +23980,7 @@ class ModuleLoader {
23811
23980
  ? { code: source }
23812
23981
  : source != null && typeof source === 'object' && typeof source.code === 'string'
23813
23982
  ? source
23814
- : error(errorBadLoader(id));
23983
+ : error(logBadLoader(id));
23815
23984
  const cachedModule = this.graph.cachedModules.get(id);
23816
23985
  if (cachedModule &&
23817
23986
  !cachedModule.customTransformCache &&
@@ -23835,7 +24004,7 @@ class ModuleLoader {
23835
24004
  }
23836
24005
  else {
23837
24006
  module.updateOptions(sourceDescription);
23838
- module.setSource(await transform(sourceDescription, module, this.pluginDriver, this.options.onwarn));
24007
+ module.setSource(await transform(sourceDescription, module, this.pluginDriver, this.options.onLog));
23839
24008
  }
23840
24009
  }
23841
24010
  async awaitLoadModulesPromise() {
@@ -23881,7 +24050,7 @@ class ModuleLoader {
23881
24050
  const existingModule = this.modulesById.get(id);
23882
24051
  if (existingModule instanceof Module) {
23883
24052
  if (importer && doAssertionsDiffer(assertions, existingModule.info.assertions)) {
23884
- this.options.onwarn(errorInconsistentImportAssertions(existingModule.info.assertions, assertions, id, importer));
24053
+ this.options.onLog(LOGLEVEL_WARN, logInconsistentImportAssertions(existingModule.info.assertions, assertions, id, importer));
23885
24054
  }
23886
24055
  await this.handleExistingModule(existingModule, isEntry, isPreload);
23887
24056
  return existingModule;
@@ -23930,10 +24099,10 @@ class ModuleLoader {
23930
24099
  this.modulesById.set(id, externalModule);
23931
24100
  }
23932
24101
  else if (!(externalModule instanceof ExternalModule)) {
23933
- return error(errorInternalIdCannotBeExternal(source, importer));
24102
+ return error(logInternalIdCannotBeExternal(source, importer));
23934
24103
  }
23935
24104
  else if (doAssertionsDiffer(externalModule.info.assertions, assertions)) {
23936
- this.options.onwarn(errorInconsistentImportAssertions(externalModule.info.assertions, assertions, source, importer));
24105
+ this.options.onLog(LOGLEVEL_WARN, logInconsistentImportAssertions(externalModule.info.assertions, assertions, source, importer));
23937
24106
  }
23938
24107
  return Promise.resolve(externalModule);
23939
24108
  }
@@ -24043,9 +24212,9 @@ class ModuleLoader {
24043
24212
  handleInvalidResolvedId(resolvedId, source, importer, assertions) {
24044
24213
  if (resolvedId === null) {
24045
24214
  if (isRelative(source)) {
24046
- return error(errorUnresolvedImport(source, importer));
24215
+ return error(logUnresolvedImport(source, importer));
24047
24216
  }
24048
- this.options.onwarn(errorUnresolvedImportTreatedAsExternal(source, importer));
24217
+ this.options.onLog(LOGLEVEL_WARN, logUnresolvedImportTreatedAsExternal(source, importer));
24049
24218
  return {
24050
24219
  assertions,
24051
24220
  external: true,
@@ -24057,7 +24226,7 @@ class ModuleLoader {
24057
24226
  };
24058
24227
  }
24059
24228
  else if (resolvedId.external && resolvedId.syntheticNamedExports) {
24060
- this.options.onwarn(errorExternalSyntheticExports(source, importer));
24229
+ this.options.onLog(LOGLEVEL_WARN, logExternalSyntheticExports(source, importer));
24061
24230
  }
24062
24231
  return resolvedId;
24063
24232
  }
@@ -24065,14 +24234,14 @@ class ModuleLoader {
24065
24234
  const resolveIdResult = await resolveId(unresolvedId, importer, this.options.preserveSymlinks, this.pluginDriver, this.resolveId, null, EMPTY_OBJECT, true, EMPTY_OBJECT);
24066
24235
  if (resolveIdResult == null) {
24067
24236
  return error(implicitlyLoadedBefore === null
24068
- ? errorUnresolvedEntry(unresolvedId)
24069
- : errorUnresolvedImplicitDependant(unresolvedId, implicitlyLoadedBefore));
24237
+ ? logUnresolvedEntry(unresolvedId)
24238
+ : logUnresolvedImplicitDependant(unresolvedId, implicitlyLoadedBefore));
24070
24239
  }
24071
24240
  if (resolveIdResult === false ||
24072
24241
  (typeof resolveIdResult === 'object' && resolveIdResult.external)) {
24073
24242
  return error(implicitlyLoadedBefore === null
24074
- ? errorEntryCannotBeExternal(unresolvedId)
24075
- : errorImplicitDependantCannotBeExternal(unresolvedId, implicitlyLoadedBefore));
24243
+ ? logEntryCannotBeExternal(unresolvedId)
24244
+ : logImplicitDependantCannotBeExternal(unresolvedId, implicitlyLoadedBefore));
24076
24245
  }
24077
24246
  return this.fetchModule(this.getResolvedIdWithDefaults(typeof resolveIdResult === 'object'
24078
24247
  ? resolveIdResult
@@ -24097,7 +24266,7 @@ class ModuleLoader {
24097
24266
  const existingResolution = module.resolvedIds[specifier];
24098
24267
  if (existingResolution) {
24099
24268
  if (doAssertionsDiffer(existingResolution.assertions, assertions)) {
24100
- this.options.onwarn(errorInconsistentImportAssertions(existingResolution.assertions, assertions, specifier, importer));
24269
+ this.options.onLog(LOGLEVEL_WARN, logInconsistentImportAssertions(existingResolution.assertions, assertions, specifier, importer));
24101
24270
  }
24102
24271
  return existingResolution;
24103
24272
  }
@@ -24165,9 +24334,9 @@ function generateAssetFileName(name, source, sourceHash, outputOptions, bundle)
24165
24334
  name: () => emittedName.slice(0, Math.max(0, emittedName.length - extname(emittedName).length))
24166
24335
  }), bundle);
24167
24336
  }
24168
- function reserveFileNameInBundle(fileName, { bundle }, warn) {
24337
+ function reserveFileNameInBundle(fileName, { bundle }, log) {
24169
24338
  if (bundle[lowercaseBundleKeys].has(fileName.toLowerCase())) {
24170
- warn(errorFileNameConflict(fileName));
24339
+ log(LOGLEVEL_WARN, logFileNameConflict(fileName));
24171
24340
  }
24172
24341
  else {
24173
24342
  bundle[fileName] = FILE_PLACEHOLDER;
@@ -24185,13 +24354,13 @@ function hasValidName(emittedFile) {
24185
24354
  function getValidSource(source, emittedFile, fileReferenceId) {
24186
24355
  if (!(typeof source === 'string' || source instanceof Uint8Array)) {
24187
24356
  const assetName = emittedFile.fileName || emittedFile.name || fileReferenceId;
24188
- return error(errorFailedValidation(`Could not set source for ${typeof assetName === 'string' ? `asset "${assetName}"` : 'unnamed asset'}, asset source needs to be a string, Uint8Array or Buffer.`));
24357
+ return error(logFailedValidation(`Could not set source for ${typeof assetName === 'string' ? `asset "${assetName}"` : 'unnamed asset'}, asset source needs to be a string, Uint8Array or Buffer.`));
24189
24358
  }
24190
24359
  return source;
24191
24360
  }
24192
24361
  function getAssetFileName(file, referenceId) {
24193
24362
  if (typeof file.fileName !== 'string') {
24194
- return error(errorAssetNotFinalisedForFileName(file.name || referenceId));
24363
+ return error(logAssetNotFinalisedForFileName(file.name || referenceId));
24195
24364
  }
24196
24365
  return file.fileName;
24197
24366
  }
@@ -24202,7 +24371,7 @@ function getChunkFileName(file, facadeChunkByModule) {
24202
24371
  if (facadeChunkByModule) {
24203
24372
  return facadeChunkByModule.get(file.module).getFileName();
24204
24373
  }
24205
- return error(errorChunkNotGeneratedForFileName(file.fileName || file.name));
24374
+ return error(logChunkNotGeneratedForFileName(file.fileName || file.name));
24206
24375
  }
24207
24376
  class FileEmitter {
24208
24377
  constructor(graph, options, baseFileEmitter) {
@@ -24214,13 +24383,13 @@ class FileEmitter {
24214
24383
  this.outputFileEmitters = [];
24215
24384
  this.emitFile = (emittedFile) => {
24216
24385
  if (!hasValidType(emittedFile)) {
24217
- return error(errorFailedValidation(`Emitted files must be of type "asset", "chunk" or "prebuilt-chunk", received "${emittedFile && emittedFile.type}".`));
24386
+ return error(logFailedValidation(`Emitted files must be of type "asset", "chunk" or "prebuilt-chunk", received "${emittedFile && emittedFile.type}".`));
24218
24387
  }
24219
24388
  if (emittedFile.type === 'prebuilt-chunk') {
24220
24389
  return this.emitPrebuiltChunk(emittedFile);
24221
24390
  }
24222
24391
  if (!hasValidName(emittedFile)) {
24223
- return error(errorFailedValidation(`The "fileName" or "name" properties of emitted chunks and assets must be strings that are neither absolute nor relative paths, received "${emittedFile.fileName || emittedFile.name}".`));
24392
+ return error(logFailedValidation(`The "fileName" or "name" properties of emitted chunks and assets must be strings that are neither absolute nor relative paths, received "${emittedFile.fileName || emittedFile.name}".`));
24224
24393
  }
24225
24394
  if (emittedFile.type === 'chunk') {
24226
24395
  return this.emitChunk(emittedFile);
@@ -24230,13 +24399,13 @@ class FileEmitter {
24230
24399
  this.finaliseAssets = () => {
24231
24400
  for (const [referenceId, emittedFile] of this.filesByReferenceId) {
24232
24401
  if (emittedFile.type === 'asset' && typeof emittedFile.fileName !== 'string')
24233
- return error(errorNoAssetSourceSet(emittedFile.name || referenceId));
24402
+ return error(logNoAssetSourceSet(emittedFile.name || referenceId));
24234
24403
  }
24235
24404
  };
24236
24405
  this.getFileName = (fileReferenceId) => {
24237
24406
  const emittedFile = this.filesByReferenceId.get(fileReferenceId);
24238
24407
  if (!emittedFile)
24239
- return error(errorFileReferenceIdNotFoundForFilename(fileReferenceId));
24408
+ return error(logFileReferenceIdNotFoundForFilename(fileReferenceId));
24240
24409
  if (emittedFile.type === 'chunk') {
24241
24410
  return getChunkFileName(emittedFile, this.facadeChunkByModule);
24242
24411
  }
@@ -24248,12 +24417,12 @@ class FileEmitter {
24248
24417
  this.setAssetSource = (referenceId, requestedSource) => {
24249
24418
  const consumedFile = this.filesByReferenceId.get(referenceId);
24250
24419
  if (!consumedFile)
24251
- return error(errorAssetReferenceIdNotFoundForSetSource(referenceId));
24420
+ return error(logAssetReferenceIdNotFoundForSetSource(referenceId));
24252
24421
  if (consumedFile.type !== 'asset') {
24253
- return error(errorFailedValidation(`Asset sources can only be set for emitted assets but "${referenceId}" is an emitted chunk.`));
24422
+ return error(logFailedValidation(`Asset sources can only be set for emitted assets but "${referenceId}" is an emitted chunk.`));
24254
24423
  }
24255
24424
  if (consumedFile.source !== undefined) {
24256
- return error(errorAssetSourceAlreadySet(consumedFile.name || referenceId));
24425
+ return error(logAssetSourceAlreadySet(consumedFile.name || referenceId));
24257
24426
  }
24258
24427
  const source = getValidSource(requestedSource, consumedFile, referenceId);
24259
24428
  if (this.output) {
@@ -24277,7 +24446,7 @@ class FileEmitter {
24277
24446
  });
24278
24447
  for (const emittedFile of this.filesByReferenceId.values()) {
24279
24448
  if (emittedFile.fileName) {
24280
- reserveFileNameInBundle(emittedFile.fileName, output, this.options.onwarn);
24449
+ reserveFileNameInBundle(emittedFile.fileName, output, this.options.onLog);
24281
24450
  }
24282
24451
  }
24283
24452
  const consumedAssetsByHash = new Map();
@@ -24367,7 +24536,7 @@ class FileEmitter {
24367
24536
  emitAssetWithReferenceId(consumedAsset, output) {
24368
24537
  const { fileName, source } = consumedAsset;
24369
24538
  if (fileName) {
24370
- reserveFileNameInBundle(fileName, output, this.options.onwarn);
24539
+ reserveFileNameInBundle(fileName, output, this.options.onLog);
24371
24540
  }
24372
24541
  if (source !== undefined) {
24373
24542
  this.finalizeAdditionalAsset(consumedAsset, source, output);
@@ -24375,10 +24544,10 @@ class FileEmitter {
24375
24544
  }
24376
24545
  emitChunk(emittedChunk) {
24377
24546
  if (this.graph.phase > BuildPhase.LOAD_AND_PARSE) {
24378
- return error(errorInvalidRollupPhaseForChunkEmission());
24547
+ return error(logInvalidRollupPhaseForChunkEmission());
24379
24548
  }
24380
24549
  if (typeof emittedChunk.id !== 'string') {
24381
- return error(errorFailedValidation(`Emitted chunks need to have a valid string id, received "${emittedChunk.id}"`));
24550
+ return error(logFailedValidation(`Emitted chunks need to have a valid string id, received "${emittedChunk.id}"`));
24382
24551
  }
24383
24552
  const consumedChunk = {
24384
24553
  fileName: emittedChunk.fileName,
@@ -24398,11 +24567,11 @@ class FileEmitter {
24398
24567
  }
24399
24568
  emitPrebuiltChunk(emitPrebuiltChunk) {
24400
24569
  if (typeof emitPrebuiltChunk.code !== 'string') {
24401
- return error(errorFailedValidation(`Emitted prebuilt chunks need to have a valid string code, received "${emitPrebuiltChunk.code}".`));
24570
+ return error(logFailedValidation(`Emitted prebuilt chunks need to have a valid string code, received "${emitPrebuiltChunk.code}".`));
24402
24571
  }
24403
24572
  if (typeof emitPrebuiltChunk.fileName !== 'string' ||
24404
24573
  isPathFragment(emitPrebuiltChunk.fileName)) {
24405
- return error(errorFailedValidation(`The "fileName" property of emitted prebuilt chunks must be strings that are neither absolute nor relative paths, received "${emitPrebuiltChunk.fileName}".`));
24574
+ return error(logFailedValidation(`The "fileName" property of emitted prebuilt chunks must be strings that are neither absolute nor relative paths, received "${emitPrebuiltChunk.fileName}".`));
24406
24575
  }
24407
24576
  const consumedPrebuiltChunk = {
24408
24577
  code: emitPrebuiltChunk.code,
@@ -24477,7 +24646,26 @@ class FileEmitter {
24477
24646
  }
24478
24647
  }
24479
24648
 
24649
+ function getLogHandler(level, code, logger, pluginName, logLevel) {
24650
+ if (logLevelPriority[level] < logLevelPriority[logLevel]) {
24651
+ return doNothing;
24652
+ }
24653
+ return (log, pos) => {
24654
+ if (pos != null) {
24655
+ logger(LOGLEVEL_WARN, logInvalidLogPosition(pluginName));
24656
+ }
24657
+ log = normalizeLog(log);
24658
+ if (log.code && !log.pluginCode) {
24659
+ log.pluginCode = log.code;
24660
+ }
24661
+ log.code = code;
24662
+ log.plugin = pluginName;
24663
+ logger(level, log);
24664
+ };
24665
+ }
24666
+
24480
24667
  function getPluginContext(plugin, pluginCache, graph, options, fileEmitter, existingPluginNames) {
24668
+ const { logLevel, onLog } = options;
24481
24669
  let cacheable = true;
24482
24670
  if (typeof plugin.cacheKey !== 'string') {
24483
24671
  if (plugin.name.startsWith(ANONYMOUS_PLUGIN_PREFIX) ||
@@ -24503,19 +24691,21 @@ function getPluginContext(plugin, pluginCache, graph, options, fileEmitter, exis
24503
24691
  return {
24504
24692
  addWatchFile(id) {
24505
24693
  if (graph.phase >= BuildPhase.GENERATE) {
24506
- return this.error(errorInvalidRollupPhaseForAddWatchFile());
24694
+ return this.error(logInvalidRollupPhaseForAddWatchFile());
24507
24695
  }
24508
24696
  graph.watchFiles[id] = true;
24509
24697
  },
24510
24698
  cache: cacheInstance,
24699
+ debug: getLogHandler(LOGLEVEL_DEBUG, 'PLUGIN_LOG', onLog, plugin.name, logLevel),
24511
24700
  emitFile: fileEmitter.emitFile.bind(fileEmitter),
24512
24701
  error(error_) {
24513
- return error(errorPluginError(error_, plugin.name));
24702
+ return error(logPluginError(normalizeLog(error_), plugin.name));
24514
24703
  },
24515
24704
  getFileName: fileEmitter.getFileName,
24516
24705
  getModuleIds: () => graph.modulesById.keys(),
24517
24706
  getModuleInfo: graph.getModuleInfo,
24518
24707
  getWatchFiles: () => Object.keys(graph.watchFiles),
24708
+ info: getLogHandler(LOGLEVEL_INFO, 'PLUGIN_LOG', onLog, plugin.name, logLevel),
24519
24709
  load(resolvedId) {
24520
24710
  return graph.moduleLoader.preloadModule(resolvedId);
24521
24711
  },
@@ -24537,15 +24727,7 @@ function getPluginContext(plugin, pluginCache, graph, options, fileEmitter, exis
24537
24727
  return graph.moduleLoader.resolveId(source, importer, custom, isEntry, assertions || EMPTY_OBJECT, skipSelf ? [{ importer, plugin, source }] : null);
24538
24728
  },
24539
24729
  setAssetSource: fileEmitter.setAssetSource,
24540
- warn(warning) {
24541
- if (typeof warning === 'string')
24542
- warning = { message: warning };
24543
- if (warning.code)
24544
- warning.pluginCode = warning.code;
24545
- warning.code = 'PLUGIN_WARNING';
24546
- warning.plugin = plugin.name;
24547
- options.onwarn(warning);
24548
- }
24730
+ warn: getLogHandler(LOGLEVEL_WARN, 'PLUGIN_WARNING', onLog, plugin.name, logLevel)
24549
24731
  };
24550
24732
  }
24551
24733
 
@@ -24557,6 +24739,7 @@ const inputHookNames = {
24557
24739
  closeWatcher: 1,
24558
24740
  load: 1,
24559
24741
  moduleParsed: 1,
24742
+ onLog: 1,
24560
24743
  options: 1,
24561
24744
  resolveDynamicImport: 1,
24562
24745
  resolveId: 1,
@@ -24588,7 +24771,7 @@ class PluginDriver {
24588
24771
  for (const plugin of userPlugins) {
24589
24772
  for (const hook of inputHooks) {
24590
24773
  if (hook in plugin) {
24591
- options.onwarn(errorInputHookInOutputPlugin(plugin.name, hook));
24774
+ options.onLog(LOGLEVEL_WARN, logInputHookInOutputPlugin(plugin.name, hook));
24592
24775
  }
24593
24776
  }
24594
24777
  }
@@ -24735,7 +24918,7 @@ class PluginDriver {
24735
24918
  // action considered to be fulfilled since error being handled
24736
24919
  this.unfulfilledActions.delete(action);
24737
24920
  }
24738
- return error(errorPluginError(error_, plugin.name, { hook: hookName }));
24921
+ return error(logPluginError(error_, plugin.name, { hook: hookName }));
24739
24922
  });
24740
24923
  }
24741
24924
  /**
@@ -24757,7 +24940,7 @@ class PluginDriver {
24757
24940
  return handler.apply(context, parameters);
24758
24941
  }
24759
24942
  catch (error_) {
24760
- return error(errorPluginError(error_, plugin.name, { hook: hookName }));
24943
+ return error(logPluginError(error_, plugin.name, { hook: hookName }));
24761
24944
  }
24762
24945
  }
24763
24946
  }
@@ -24789,12 +24972,12 @@ function getSortedValidatedPlugins(hookName, plugins, validateHandler = validate
24789
24972
  }
24790
24973
  function validateFunctionPluginHandler(handler, hookName, plugin) {
24791
24974
  if (typeof handler !== 'function') {
24792
- error(errorInvalidFunctionPluginHook(hookName, plugin.name));
24975
+ error(logInvalidFunctionPluginHook(hookName, plugin.name));
24793
24976
  }
24794
24977
  }
24795
24978
  function validateAddonPluginHandler(handler, hookName, plugin) {
24796
24979
  if (typeof handler !== 'string' && typeof handler !== 'function') {
24797
- return error(errorInvalidAddonPluginHook(hookName, plugin.name));
24980
+ return error(logInvalidAddonPluginHook(hookName, plugin.name));
24798
24981
  }
24799
24982
  }
24800
24983
  function noReturn() { }
@@ -25006,7 +25189,7 @@ class Graph {
25006
25189
  for (const module of this.implicitEntryModules) {
25007
25190
  for (const dependant of module.implicitlyLoadedAfter) {
25008
25191
  if (!(dependant.info.isEntry || dependant.isIncluded())) {
25009
- error(errorImplicitDependantIsNotIncluded(dependant));
25192
+ error(logImplicitDependantIsNotIncluded(dependant));
25010
25193
  }
25011
25194
  }
25012
25195
  }
@@ -25014,7 +25197,7 @@ class Graph {
25014
25197
  sortModules() {
25015
25198
  const { orderedModules, cyclePaths } = analyseModuleExecution(this.entryModules);
25016
25199
  for (const cyclePath of cyclePaths) {
25017
- this.options.onwarn(errorCircularDependency(cyclePath));
25200
+ this.options.onLog(LOGLEVEL_WARN, logCircularDependency(cyclePath));
25018
25201
  }
25019
25202
  this.modules = orderedModules;
25020
25203
  for (const module of this.modules) {
@@ -25027,7 +25210,7 @@ class Graph {
25027
25210
  for (const importDescription of module.importDescriptions.values()) {
25028
25211
  if (importDescription.name !== '*' &&
25029
25212
  !importDescription.module.getVariableForExportName(importDescription.name)[0]) {
25030
- module.warn(errorMissingExport(importDescription.name, module.id, importDescription.module.id), importDescription.start);
25213
+ module.log(LOGLEVEL_WARN, logMissingExport(importDescription.name, module.id, importDescription.module.id), importDescription.start);
25031
25214
  }
25032
25215
  }
25033
25216
  }
@@ -25086,6 +25269,40 @@ async function catchUnfinishedHookActions(pluginDriver, callback) {
25086
25269
  }
25087
25270
  }
25088
25271
 
25272
+ function getLogger(plugins, onLog, watchMode, logLevel) {
25273
+ plugins = getSortedValidatedPlugins('onLog', plugins);
25274
+ const minimalPriority = logLevelPriority[logLevel];
25275
+ const logger = (level, log, skipped = EMPTY_SET) => {
25276
+ const logPriority = logLevelPriority[level];
25277
+ if (logPriority < minimalPriority) {
25278
+ return;
25279
+ }
25280
+ for (const plugin of plugins) {
25281
+ if (skipped.has(plugin))
25282
+ continue;
25283
+ const { onLog: pluginOnLog } = plugin;
25284
+ const getLogHandler = (level) => {
25285
+ if (logLevelPriority[level] < minimalPriority) {
25286
+ return doNothing;
25287
+ }
25288
+ return log => logger(level, normalizeLog(log), new Set(skipped).add(plugin));
25289
+ };
25290
+ const handler = 'handler' in pluginOnLog ? pluginOnLog.handler : pluginOnLog;
25291
+ if (handler.call({
25292
+ debug: getLogHandler(LOGLEVEL_DEBUG),
25293
+ error: (log) => error(normalizeLog(log)),
25294
+ info: getLogHandler(LOGLEVEL_INFO),
25295
+ meta: { rollupVersion: version$1, watchMode },
25296
+ warn: getLogHandler(LOGLEVEL_WARN)
25297
+ }, level, log) === false) {
25298
+ return;
25299
+ }
25300
+ }
25301
+ onLog(level, log);
25302
+ };
25303
+ return logger;
25304
+ }
25305
+
25089
25306
  const leftCurlyBrace = "{".charCodeAt(0);
25090
25307
  const space = " ".charCodeAt(0);
25091
25308
 
@@ -25337,100 +25554,16 @@ function ensureArray(items) {
25337
25554
  return [];
25338
25555
  }
25339
25556
 
25340
- async function asyncFlatten(array) {
25341
- do {
25342
- array = (await Promise.all(array)).flat(Infinity);
25343
- } while (array.some((v) => v?.then));
25344
- return array;
25345
- }
25346
-
25347
- const defaultOnWarn = warning => console.warn(warning.message || warning);
25348
- function warnUnknownOptions(passedOptions, validOptions, optionType, warn, ignoredKeys = /$./) {
25349
- const validOptionSet = new Set(validOptions);
25350
- const unknownOptions = Object.keys(passedOptions).filter(key => !(validOptionSet.has(key) || ignoredKeys.test(key)));
25351
- if (unknownOptions.length > 0) {
25352
- warn(errorUnknownOption(optionType, unknownOptions, [...validOptionSet].sort()));
25353
- }
25354
- }
25355
- const treeshakePresets = {
25356
- recommended: {
25357
- annotations: true,
25358
- correctVarValueBeforeDeclaration: false,
25359
- manualPureFunctions: EMPTY_ARRAY,
25360
- moduleSideEffects: () => true,
25361
- propertyReadSideEffects: true,
25362
- tryCatchDeoptimization: true,
25363
- unknownGlobalSideEffects: false
25364
- },
25365
- safest: {
25366
- annotations: true,
25367
- correctVarValueBeforeDeclaration: true,
25368
- manualPureFunctions: EMPTY_ARRAY,
25369
- moduleSideEffects: () => true,
25370
- propertyReadSideEffects: true,
25371
- tryCatchDeoptimization: true,
25372
- unknownGlobalSideEffects: true
25373
- },
25374
- smallest: {
25375
- annotations: true,
25376
- correctVarValueBeforeDeclaration: false,
25377
- manualPureFunctions: EMPTY_ARRAY,
25378
- moduleSideEffects: () => false,
25379
- propertyReadSideEffects: false,
25380
- tryCatchDeoptimization: false,
25381
- unknownGlobalSideEffects: false
25382
- }
25383
- };
25384
- const generatedCodePresets = {
25385
- es2015: {
25386
- arrowFunctions: true,
25387
- constBindings: true,
25388
- objectShorthand: true,
25389
- reservedNamesAsProps: true,
25390
- symbols: true
25391
- },
25392
- es5: {
25393
- arrowFunctions: false,
25394
- constBindings: false,
25395
- objectShorthand: false,
25396
- reservedNamesAsProps: true,
25397
- symbols: false
25398
- }
25399
- };
25400
- const objectifyOption = (value) => value && typeof value === 'object' ? value : {};
25401
- const objectifyOptionWithPresets = (presets, optionName, urlSnippet, additionalValues) => (value) => {
25402
- if (typeof value === 'string') {
25403
- const preset = presets[value];
25404
- if (preset) {
25405
- return preset;
25406
- }
25407
- error(errorInvalidOption(optionName, urlSnippet, `valid values are ${additionalValues}${printQuotedStringList(Object.keys(presets))}. You can also supply an object for more fine-grained control`, value));
25408
- }
25409
- return objectifyOption(value);
25410
- };
25411
- const getOptionWithPreset = (value, presets, optionName, urlSnippet, additionalValues) => {
25412
- const presetName = value?.preset;
25413
- if (presetName) {
25414
- const preset = presets[presetName];
25415
- if (preset) {
25416
- return { ...preset, ...value };
25417
- }
25418
- else {
25419
- error(errorInvalidOption(`${optionName}.preset`, urlSnippet, `valid values are ${printQuotedStringList(Object.keys(presets))}`, presetName));
25420
- }
25421
- }
25422
- return objectifyOptionWithPresets(presets, optionName, urlSnippet, additionalValues)(value);
25423
- };
25424
- const normalizePluginOption = async (plugins) => (await asyncFlatten([plugins])).filter(Boolean);
25425
-
25426
- async function normalizeInputOptions(config) {
25557
+ async function normalizeInputOptions(config, watchMode) {
25427
25558
  // These are options that may trigger special warnings or behaviour later
25428
25559
  // if the user did not select an explicit value
25429
25560
  const unsetOptions = new Set();
25430
25561
  const context = config.context ?? 'undefined';
25431
- const onwarn = getOnwarn(config);
25562
+ const plugins = await normalizePluginOption(config.plugins);
25563
+ const logLevel = config.logLevel || LOGLEVEL_INFO;
25564
+ const onLog = getLogger(plugins, getOnLog(config, logLevel), watchMode, logLevel);
25432
25565
  const strictDeprecations = config.strictDeprecations || false;
25433
- const maxParallelFileOps = getmaxParallelFileOps(config, onwarn, strictDeprecations);
25566
+ const maxParallelFileOps = getMaxParallelFileOps(config, onLog, strictDeprecations);
25434
25567
  const options = {
25435
25568
  acorn: getAcorn(config),
25436
25569
  acornInjectPlugins: getAcornInjectPlugins(config),
@@ -25439,43 +25572,28 @@ async function normalizeInputOptions(config) {
25439
25572
  experimentalCacheExpiry: config.experimentalCacheExpiry ?? 10,
25440
25573
  experimentalLogSideEffects: config.experimentalLogSideEffects || false,
25441
25574
  external: getIdMatcher(config.external),
25442
- inlineDynamicImports: getInlineDynamicImports$1(config, onwarn, strictDeprecations),
25575
+ inlineDynamicImports: getInlineDynamicImports$1(config, onLog, strictDeprecations),
25443
25576
  input: getInput(config),
25577
+ logLevel,
25444
25578
  makeAbsoluteExternalsRelative: config.makeAbsoluteExternalsRelative ?? 'ifRelativeSource',
25445
- manualChunks: getManualChunks$1(config, onwarn, strictDeprecations),
25579
+ manualChunks: getManualChunks$1(config, onLog, strictDeprecations),
25446
25580
  maxParallelFileOps,
25447
25581
  maxParallelFileReads: maxParallelFileOps,
25448
25582
  moduleContext: getModuleContext(config, context),
25449
- onwarn,
25583
+ onLog,
25584
+ onwarn: warning => onLog(LOGLEVEL_WARN, warning),
25450
25585
  perf: config.perf || false,
25451
- plugins: await normalizePluginOption(config.plugins),
25586
+ plugins,
25452
25587
  preserveEntrySignatures: config.preserveEntrySignatures ?? 'exports-only',
25453
- preserveModules: getPreserveModules$1(config, onwarn, strictDeprecations),
25588
+ preserveModules: getPreserveModules$1(config, onLog, strictDeprecations),
25454
25589
  preserveSymlinks: config.preserveSymlinks || false,
25455
25590
  shimMissingExports: config.shimMissingExports || false,
25456
25591
  strictDeprecations,
25457
25592
  treeshake: getTreeshake(config)
25458
25593
  };
25459
- warnUnknownOptions(config, [...Object.keys(options), 'watch'], 'input options', options.onwarn, /^(output)$/);
25594
+ warnUnknownOptions(config, [...Object.keys(options), 'watch'], 'input options', onLog, /^(output)$/);
25460
25595
  return { options, unsetOptions };
25461
25596
  }
25462
- const getOnwarn = (config) => {
25463
- const { onwarn } = config;
25464
- return onwarn
25465
- ? warning => {
25466
- warning.toString = () => {
25467
- let warningString = '';
25468
- if (warning.plugin)
25469
- warningString += `(${warning.plugin} plugin) `;
25470
- if (warning.loc)
25471
- warningString += `${relativeId(warning.loc.file)} (${warning.loc.line}:${warning.loc.column}) `;
25472
- warningString += warning.message;
25473
- return warningString;
25474
- };
25475
- onwarn(warning, defaultOnWarn);
25476
- }
25477
- : defaultOnWarn;
25478
- };
25479
25597
  const getAcorn = (config) => ({
25480
25598
  ecmaVersion: 'latest',
25481
25599
  sourceType: 'module',
@@ -25510,10 +25628,10 @@ const getIdMatcher = (option) => {
25510
25628
  }
25511
25629
  return () => false;
25512
25630
  };
25513
- const getInlineDynamicImports$1 = (config, warn, strictDeprecations) => {
25631
+ const getInlineDynamicImports$1 = (config, log, strictDeprecations) => {
25514
25632
  const configInlineDynamicImports = config.inlineDynamicImports;
25515
25633
  if (configInlineDynamicImports) {
25516
- warnDeprecationWithOptions('The "inlineDynamicImports" option is deprecated. Use the "output.inlineDynamicImports" option instead.', URL_OUTPUT_INLINEDYNAMICIMPORTS, true, warn, strictDeprecations);
25634
+ warnDeprecationWithOptions('The "inlineDynamicImports" option is deprecated. Use the "output.inlineDynamicImports" option instead.', URL_OUTPUT_INLINEDYNAMICIMPORTS, true, log, strictDeprecations);
25517
25635
  }
25518
25636
  return configInlineDynamicImports;
25519
25637
  };
@@ -25521,17 +25639,17 @@ const getInput = (config) => {
25521
25639
  const configInput = config.input;
25522
25640
  return configInput == null ? [] : typeof configInput === 'string' ? [configInput] : configInput;
25523
25641
  };
25524
- const getManualChunks$1 = (config, warn, strictDeprecations) => {
25642
+ const getManualChunks$1 = (config, log, strictDeprecations) => {
25525
25643
  const configManualChunks = config.manualChunks;
25526
25644
  if (configManualChunks) {
25527
- warnDeprecationWithOptions('The "manualChunks" option is deprecated. Use the "output.manualChunks" option instead.', URL_OUTPUT_MANUALCHUNKS, true, warn, strictDeprecations);
25645
+ warnDeprecationWithOptions('The "manualChunks" option is deprecated. Use the "output.manualChunks" option instead.', URL_OUTPUT_MANUALCHUNKS, true, log, strictDeprecations);
25528
25646
  }
25529
25647
  return configManualChunks;
25530
25648
  };
25531
- const getmaxParallelFileOps = (config, warn, strictDeprecations) => {
25649
+ const getMaxParallelFileOps = (config, log, strictDeprecations) => {
25532
25650
  const maxParallelFileReads = config.maxParallelFileReads;
25533
25651
  if (typeof maxParallelFileReads === 'number') {
25534
- warnDeprecationWithOptions('The "maxParallelFileReads" option is deprecated. Use the "maxParallelFileOps" option instead.', URL_MAXPARALLELFILEOPS, true, warn, strictDeprecations);
25652
+ warnDeprecationWithOptions('The "maxParallelFileReads" option is deprecated. Use the "maxParallelFileOps" option instead.', URL_MAXPARALLELFILEOPS, true, log, strictDeprecations);
25535
25653
  }
25536
25654
  const maxParallelFileOps = config.maxParallelFileOps ?? maxParallelFileReads;
25537
25655
  if (typeof maxParallelFileOps === 'number') {
@@ -25555,10 +25673,10 @@ const getModuleContext = (config, context) => {
25555
25673
  }
25556
25674
  return () => context;
25557
25675
  };
25558
- const getPreserveModules$1 = (config, warn, strictDeprecations) => {
25676
+ const getPreserveModules$1 = (config, log, strictDeprecations) => {
25559
25677
  const configPreserveModules = config.preserveModules;
25560
25678
  if (configPreserveModules) {
25561
- warnDeprecationWithOptions('The "preserveModules" option is deprecated. Use the "output.preserveModules" option instead.', URL_OUTPUT_PRESERVEMODULES, true, warn, strictDeprecations);
25679
+ warnDeprecationWithOptions('The "preserveModules" option is deprecated. Use the "output.preserveModules" option instead.', URL_OUTPUT_PRESERVEMODULES, true, log, strictDeprecations);
25562
25680
  }
25563
25681
  return configPreserveModules;
25564
25682
  };
@@ -25595,7 +25713,7 @@ const getHasModuleSideEffects = (moduleSideEffectsOption) => {
25595
25713
  return id => ids.has(id);
25596
25714
  }
25597
25715
  if (moduleSideEffectsOption) {
25598
- error(errorInvalidOption('treeshake.moduleSideEffects', URL_TREESHAKE_MODULESIDEEFFECTS, 'please use one of false, "no-external", a function or an array'));
25716
+ error(logInvalidOption('treeshake.moduleSideEffects', URL_TREESHAKE_MODULESIDEEFFECTS, 'please use one of false, "no-external", a function or an array'));
25599
25717
  }
25600
25718
  return () => true;
25601
25719
  };
@@ -25681,17 +25799,17 @@ async function normalizeOutputOptions(config, inputOptions, unsetInputOptions) {
25681
25799
  systemNullSetters: config.systemNullSetters ?? true,
25682
25800
  validate: config.validate || false
25683
25801
  };
25684
- warnUnknownOptions(config, Object.keys(outputOptions), 'output options', inputOptions.onwarn);
25802
+ warnUnknownOptions(config, Object.keys(outputOptions), 'output options', inputOptions.onLog);
25685
25803
  return { options: outputOptions, unsetOptions };
25686
25804
  }
25687
25805
  const getFile = (config, preserveModules, inputOptions) => {
25688
25806
  const { file } = config;
25689
25807
  if (typeof file === 'string') {
25690
25808
  if (preserveModules) {
25691
- return error(errorInvalidOption('output.file', URL_OUTPUT_DIR, 'you must set "output.dir" instead of "output.file" when using the "output.preserveModules" option'));
25809
+ return error(logInvalidOption('output.file', URL_OUTPUT_DIR, 'you must set "output.dir" instead of "output.file" when using the "output.preserveModules" option'));
25692
25810
  }
25693
25811
  if (!Array.isArray(inputOptions.input))
25694
- return error(errorInvalidOption('output.file', URL_OUTPUT_DIR, 'you must set "output.dir" instead of "output.file" when providing named inputs'));
25812
+ return error(logInvalidOption('output.file', URL_OUTPUT_DIR, 'you must set "output.dir" instead of "output.file" when providing named inputs'));
25695
25813
  }
25696
25814
  return file;
25697
25815
  };
@@ -25718,7 +25836,7 @@ const getFormat = (config) => {
25718
25836
  return configFormat;
25719
25837
  }
25720
25838
  default: {
25721
- return error(errorInvalidOption('output.format', URL_OUTPUT_FORMAT, `Valid values are "amd", "cjs", "system", "es", "iife" or "umd"`, configFormat));
25839
+ return error(logInvalidOption('output.format', URL_OUTPUT_FORMAT, `Valid values are "amd", "cjs", "system", "es", "iife" or "umd"`, configFormat));
25722
25840
  }
25723
25841
  }
25724
25842
  };
@@ -25726,7 +25844,7 @@ const getInlineDynamicImports = (config, inputOptions) => {
25726
25844
  const inlineDynamicImports = (config.inlineDynamicImports ?? inputOptions.inlineDynamicImports) || false;
25727
25845
  const { input } = inputOptions;
25728
25846
  if (inlineDynamicImports && (Array.isArray(input) ? input : Object.keys(input)).length > 1) {
25729
- return error(errorInvalidOption('output.inlineDynamicImports', URL_OUTPUT_INLINEDYNAMICIMPORTS, 'multiple inputs are not supported when "output.inlineDynamicImports" is true'));
25847
+ return error(logInvalidOption('output.inlineDynamicImports', URL_OUTPUT_INLINEDYNAMICIMPORTS, 'multiple inputs are not supported when "output.inlineDynamicImports" is true'));
25730
25848
  }
25731
25849
  return inlineDynamicImports;
25732
25850
  };
@@ -25734,10 +25852,10 @@ const getPreserveModules = (config, inlineDynamicImports, inputOptions) => {
25734
25852
  const preserveModules = (config.preserveModules ?? inputOptions.preserveModules) || false;
25735
25853
  if (preserveModules) {
25736
25854
  if (inlineDynamicImports) {
25737
- return error(errorInvalidOption('output.inlineDynamicImports', URL_OUTPUT_INLINEDYNAMICIMPORTS, `this option is not supported for "output.preserveModules"`));
25855
+ return error(logInvalidOption('output.inlineDynamicImports', URL_OUTPUT_INLINEDYNAMICIMPORTS, `this option is not supported for "output.preserveModules"`));
25738
25856
  }
25739
25857
  if (inputOptions.preserveEntrySignatures === false) {
25740
- return error(errorInvalidOption('preserveEntrySignatures', URL_PRESERVEENTRYSIGNATURES, 'setting this option to false is not supported for "output.preserveModules"'));
25858
+ return error(logInvalidOption('preserveEntrySignatures', URL_PRESERVEENTRYSIGNATURES, 'setting this option to false is not supported for "output.preserveModules"'));
25741
25859
  }
25742
25860
  }
25743
25861
  return preserveModules;
@@ -25765,10 +25883,10 @@ const getAmd = (config) => {
25765
25883
  ...config.amd
25766
25884
  };
25767
25885
  if ((mergedOption.autoId || mergedOption.basePath) && mergedOption.id) {
25768
- return error(errorInvalidOption('output.amd.id', URL_OUTPUT_AMD_ID, 'this option cannot be used together with "output.amd.autoId"/"output.amd.basePath"'));
25886
+ return error(logInvalidOption('output.amd.id', URL_OUTPUT_AMD_ID, 'this option cannot be used together with "output.amd.autoId"/"output.amd.basePath"'));
25769
25887
  }
25770
25888
  if (mergedOption.basePath && !mergedOption.autoId) {
25771
- return error(errorInvalidOption('output.amd.basePath', URL_OUTPUT_AMD_BASEPATH, 'this option only works with "output.amd.autoId"'));
25889
+ return error(logInvalidOption('output.amd.basePath', URL_OUTPUT_AMD_BASEPATH, 'this option only works with "output.amd.autoId"'));
25772
25890
  }
25773
25891
  return mergedOption.autoId
25774
25892
  ? {
@@ -25795,7 +25913,7 @@ const getAddon = (config, name) => {
25795
25913
  const getDir = (config, file) => {
25796
25914
  const { dir } = config;
25797
25915
  if (typeof dir === 'string' && typeof file === 'string') {
25798
- return error(errorInvalidOption('output.dir', URL_OUTPUT_DIR, 'you must set either "output.file" for a single-file build or "output.dir" when generating multiple chunks'));
25916
+ return error(logInvalidOption('output.dir', URL_OUTPUT_DIR, 'you must set either "output.file" for a single-file build or "output.dir" when generating multiple chunks'));
25799
25917
  }
25800
25918
  return dir;
25801
25919
  };
@@ -25804,7 +25922,7 @@ const getDynamicImportFunction = (config, inputOptions, format) => {
25804
25922
  if (configDynamicImportFunction) {
25805
25923
  warnDeprecation(`The "output.dynamicImportFunction" option is deprecated. Use the "renderDynamicImport" plugin hook instead.`, URL_RENDERDYNAMICIMPORT, true, inputOptions);
25806
25924
  if (format !== 'es') {
25807
- inputOptions.onwarn(errorInvalidOption('output.dynamicImportFunction', URL_OUTPUT_DYNAMICIMPORTFUNCTION, 'this option is ignored for formats other than "es"'));
25925
+ inputOptions.onLog(LOGLEVEL_WARN, logInvalidOption('output.dynamicImportFunction', URL_OUTPUT_DYNAMICIMPORTFUNCTION, 'this option is ignored for formats other than "es"'));
25808
25926
  }
25809
25927
  }
25810
25928
  return configDynamicImportFunction;
@@ -25829,7 +25947,7 @@ function getExports(config, unsetOptions) {
25829
25947
  unsetOptions.add('exports');
25830
25948
  }
25831
25949
  else if (!['default', 'named', 'none', 'auto'].includes(configExports)) {
25832
- return error(errorInvalidExportOptionValue(configExports));
25950
+ return error(logInvalidExportOptionValue(configExports));
25833
25951
  }
25834
25952
  return configExports || 'auto';
25835
25953
  }
@@ -25872,7 +25990,7 @@ const getInterop = (config) => {
25872
25990
  };
25873
25991
  const validateInterop = (interop) => {
25874
25992
  if (!ALLOWED_INTEROP_TYPES.has(interop)) {
25875
- return error(errorInvalidOption('output.interop', URL_OUTPUT_INTEROP,
25993
+ return error(logInvalidOption('output.interop', URL_OUTPUT_INTEROP,
25876
25994
  // eslint-disable-next-line unicorn/prefer-spread
25877
25995
  `use one of ${Array.from(ALLOWED_INTEROP_TYPES, value => JSON.stringify(value)).join(', ')}`, interop));
25878
25996
  }
@@ -25882,10 +26000,10 @@ const getManualChunks = (config, inlineDynamicImports, preserveModules, inputOpt
25882
26000
  const configManualChunks = config.manualChunks || inputOptions.manualChunks;
25883
26001
  if (configManualChunks) {
25884
26002
  if (inlineDynamicImports) {
25885
- return error(errorInvalidOption('output.manualChunks', URL_OUTPUT_MANUALCHUNKS, 'this option is not supported for "output.inlineDynamicImports"'));
26003
+ return error(logInvalidOption('output.manualChunks', URL_OUTPUT_MANUALCHUNKS, 'this option is not supported for "output.inlineDynamicImports"'));
25886
26004
  }
25887
26005
  if (preserveModules) {
25888
- return error(errorInvalidOption('output.manualChunks', URL_OUTPUT_MANUALCHUNKS, 'this option is not supported for "output.preserveModules"'));
26006
+ return error(logInvalidOption('output.manualChunks', URL_OUTPUT_MANUALCHUNKS, 'this option is not supported for "output.preserveModules"'));
25889
26007
  }
25890
26008
  }
25891
26009
  return configManualChunks || {};
@@ -25905,7 +26023,7 @@ const getSourcemapBaseUrl = (config) => {
25905
26023
  if (isValidUrl(sourcemapBaseUrl)) {
25906
26024
  return addTrailingSlashIfMissed(sourcemapBaseUrl);
25907
26025
  }
25908
- return error(errorInvalidOption('output.sourcemapBaseUrl', URL_OUTPUT_SOURCEMAPBASEURL, `must be a valid URL, received ${JSON.stringify(sourcemapBaseUrl)}`));
26026
+ return error(logInvalidOption('output.sourcemapBaseUrl', URL_OUTPUT_SOURCEMAPBASEURL, `must be a valid URL, received ${JSON.stringify(sourcemapBaseUrl)}`));
25909
26027
  }
25910
26028
  };
25911
26029
 
@@ -25953,13 +26071,13 @@ async function rollupInternal(rawInputOptions, watcher) {
25953
26071
  closed: false,
25954
26072
  async generate(rawOutputOptions) {
25955
26073
  if (result.closed)
25956
- return error(errorAlreadyClosed());
26074
+ return error(logAlreadyClosed());
25957
26075
  return handleGenerateWrite(false, inputOptions, unsetInputOptions, rawOutputOptions, graph);
25958
26076
  },
25959
26077
  watchFiles: Object.keys(graph.watchFiles),
25960
26078
  async write(rawOutputOptions) {
25961
26079
  if (result.closed)
25962
- return error(errorAlreadyClosed());
26080
+ return error(logAlreadyClosed());
25963
26081
  return handleGenerateWrite(true, inputOptions, unsetInputOptions, rawOutputOptions, graph);
25964
26082
  }
25965
26083
  };
@@ -25967,21 +26085,34 @@ async function rollupInternal(rawInputOptions, watcher) {
25967
26085
  result.getTimings = getTimings;
25968
26086
  return result;
25969
26087
  }
25970
- async function getInputOptions(rawInputOptions, watchMode) {
25971
- if (!rawInputOptions) {
26088
+ async function getInputOptions(initialInputOptions, watchMode) {
26089
+ if (!initialInputOptions) {
25972
26090
  throw new Error('You must supply an options object to rollup');
25973
26091
  }
25974
- const rawPlugins = getSortedValidatedPlugins('options', await normalizePluginOption(rawInputOptions.plugins));
25975
- const { options, unsetOptions } = await normalizeInputOptions(await rawPlugins.reduce(applyOptionHook(watchMode), Promise.resolve(rawInputOptions)));
26092
+ const processedInputOptions = await getProcessedInputOptions(initialInputOptions, watchMode);
26093
+ const { options, unsetOptions } = await normalizeInputOptions(processedInputOptions, watchMode);
25976
26094
  normalizePlugins(options.plugins, ANONYMOUS_PLUGIN_PREFIX);
25977
26095
  return { options, unsetOptions };
25978
26096
  }
25979
- function applyOptionHook(watchMode) {
25980
- return async (inputOptions, plugin) => {
25981
- const handler = 'handler' in plugin.options ? plugin.options.handler : plugin.options;
25982
- return ((await handler.call({ meta: { rollupVersion: version$1, watchMode } }, await inputOptions)) ||
25983
- inputOptions);
25984
- };
26097
+ async function getProcessedInputOptions(inputOptions, watchMode) {
26098
+ const plugins = getSortedValidatedPlugins('options', await normalizePluginOption(inputOptions.plugins));
26099
+ const logLevel = inputOptions.logLevel || LOGLEVEL_INFO;
26100
+ const logger = getLogger(plugins, getOnLog(inputOptions, logLevel), watchMode, logLevel);
26101
+ for (const plugin of plugins) {
26102
+ const { name, options } = plugin;
26103
+ const handler = 'handler' in options ? options.handler : options;
26104
+ const processedOptions = await handler.call({
26105
+ debug: getLogHandler(LOGLEVEL_DEBUG, 'PLUGIN_LOG', logger, name, logLevel),
26106
+ error: (error_) => error(logPluginError(normalizeLog(error_), name, { hook: 'onLog' })),
26107
+ info: getLogHandler(LOGLEVEL_INFO, 'PLUGIN_LOG', logger, name, logLevel),
26108
+ meta: { rollupVersion: version$1, watchMode },
26109
+ warn: getLogHandler(LOGLEVEL_WARN, 'PLUGIN_WARNING', logger, name, logLevel)
26110
+ }, inputOptions);
26111
+ if (processedOptions) {
26112
+ inputOptions = processedOptions;
26113
+ }
26114
+ }
26115
+ return inputOptions;
25985
26116
  }
25986
26117
  function normalizePlugins(plugins, anonymousPrefix) {
25987
26118
  for (const [index, plugin] of plugins.entries()) {
@@ -25998,7 +26129,7 @@ async function handleGenerateWrite(isWrite, inputOptions, unsetInputOptions, raw
25998
26129
  if (isWrite) {
25999
26130
  timeStart('WRITE', 1);
26000
26131
  if (!outputOptions.dir && !outputOptions.file) {
26001
- return error(errorMissingFileOrDirOption());
26132
+ return error(logMissingFileOrDirOption());
26002
26133
  }
26003
26134
  await Promise.all(Object.values(generated).map(chunk => graph.fileOperationQueue.run(() => writeOutputFile(chunk, outputOptions))));
26004
26135
  await outputPluginDriver.hookParallel('writeBundle', [outputOptions, generated]);
@@ -26021,7 +26152,7 @@ async function getOutputOptionsAndPluginDriver(rawOutputOptions, inputPluginDriv
26021
26152
  }
26022
26153
  function getOutputOptions(inputOptions, unsetInputOptions, rawOutputOptions, outputPluginDriver) {
26023
26154
  return normalizeOutputOptions(outputPluginDriver.hookReduceArg0Sync('outputOptions', [rawOutputOptions], (outputOptions, result) => result || outputOptions, pluginContext => {
26024
- const emitError = () => pluginContext.error(errorCannotEmitFromOptionsHook());
26155
+ const emitError = () => pluginContext.error(logCannotEmitFromOptionsHook());
26025
26156
  return {
26026
26157
  ...pluginContext,
26027
26158
  emitFile: emitError,
@@ -26057,7 +26188,8 @@ async function writeOutputFile(outputFile, outputOptions) {
26057
26188
  }
26058
26189
  /**
26059
26190
  * Auxiliary function for defining rollup configuration
26060
- * Mainly to facilitate IDE code prompts, after all, export default does not prompt, even if you add @type annotations, it is not accurate
26191
+ * Mainly to facilitate IDE code prompts, after all, export default does not
26192
+ * prompt, even if you add @type annotations, it is not accurate
26061
26193
  * @param options
26062
26194
  */
26063
26195
  function defineConfig(options) {
@@ -26222,17 +26354,20 @@ const commandAliases = {
26222
26354
  w: 'watch'
26223
26355
  };
26224
26356
  const EMPTY_COMMAND_OPTIONS = { external: [], globals: undefined };
26225
- async function mergeOptions(config, rawCommandOptions = EMPTY_COMMAND_OPTIONS, defaultOnWarnHandler = defaultOnWarn) {
26357
+ async function mergeOptions(config, watchMode, rawCommandOptions = EMPTY_COMMAND_OPTIONS, printLog) {
26226
26358
  const command = getCommandOptions(rawCommandOptions);
26227
- const inputOptions = await mergeInputOptions(config, command, defaultOnWarnHandler);
26228
- const warn = inputOptions.onwarn;
26359
+ const plugins = await normalizePluginOption(config.plugins);
26360
+ const logLevel = config.logLevel || LOGLEVEL_INFO;
26361
+ const onLog = getOnLog(config, logLevel, printLog);
26362
+ const log = getLogger(plugins, onLog, watchMode, logLevel);
26363
+ const inputOptions = await mergeInputOptions(config, command, plugins, log, onLog);
26229
26364
  if (command.output) {
26230
26365
  Object.assign(command, command.output);
26231
26366
  }
26232
26367
  const outputOptionsArray = ensureArray(config.output);
26233
26368
  if (outputOptionsArray.length === 0)
26234
26369
  outputOptionsArray.push({});
26235
- const outputOptions = await Promise.all(outputOptionsArray.map(singleOutputOptions => mergeOutputOptions(singleOutputOptions, command, warn)));
26370
+ const outputOptions = await Promise.all(outputOptionsArray.map(singleOutputOptions => mergeOutputOptions(singleOutputOptions, command, log)));
26236
26371
  warnUnknownOptions(command, [
26237
26372
  ...Object.keys(inputOptions),
26238
26373
  ...Object.keys(outputOptions[0]).filter(option => option !== 'sourcemapIgnoreList' && option !== 'sourcemapPathTransform'),
@@ -26246,7 +26381,7 @@ async function mergeOptions(config, rawCommandOptions = EMPTY_COMMAND_OPTIONS, d
26246
26381
  'stdin',
26247
26382
  'waitForBundleInput',
26248
26383
  'configPlugin'
26249
- ], 'CLI flags', warn, /^_$|output$|config/);
26384
+ ], 'CLI flags', log, /^_$|output$|config/);
26250
26385
  inputOptions.output = outputOptions;
26251
26386
  return inputOptions;
26252
26387
  }
@@ -26269,7 +26404,7 @@ function getCommandOptions(rawCommandOptions) {
26269
26404
  : undefined
26270
26405
  };
26271
26406
  }
26272
- async function mergeInputOptions(config, overrides, defaultOnWarnHandler) {
26407
+ function mergeInputOptions(config, overrides, plugins, log, onLog) {
26273
26408
  const getOption = (name) => overrides[name] ?? config[name];
26274
26409
  const inputOptions = {
26275
26410
  acorn: getOption('acorn'),
@@ -26281,14 +26416,16 @@ async function mergeInputOptions(config, overrides, defaultOnWarnHandler) {
26281
26416
  external: getExternal(config, overrides),
26282
26417
  inlineDynamicImports: getOption('inlineDynamicImports'),
26283
26418
  input: getOption('input') || [],
26419
+ logLevel: getOption('logLevel'),
26284
26420
  makeAbsoluteExternalsRelative: getOption('makeAbsoluteExternalsRelative'),
26285
26421
  manualChunks: getOption('manualChunks'),
26286
26422
  maxParallelFileOps: getOption('maxParallelFileOps'),
26287
26423
  maxParallelFileReads: getOption('maxParallelFileReads'),
26288
26424
  moduleContext: getOption('moduleContext'),
26289
- onwarn: getOnWarn(config, defaultOnWarnHandler),
26425
+ onLog,
26426
+ onwarn: undefined,
26290
26427
  perf: getOption('perf'),
26291
- plugins: await normalizePluginOption(config.plugins),
26428
+ plugins,
26292
26429
  preserveEntrySignatures: getOption('preserveEntrySignatures'),
26293
26430
  preserveModules: getOption('preserveModules'),
26294
26431
  preserveSymlinks: getOption('preserveSymlinks'),
@@ -26297,7 +26434,7 @@ async function mergeInputOptions(config, overrides, defaultOnWarnHandler) {
26297
26434
  treeshake: getObjectOption(config, overrides, 'treeshake', objectifyOptionWithPresets(treeshakePresets, 'treeshake', URL_TREESHAKE, 'false, true, ')),
26298
26435
  watch: getWatch(config, overrides)
26299
26436
  };
26300
- warnUnknownOptions(config, Object.keys(inputOptions), 'input options', inputOptions.onwarn, /^output$/);
26437
+ warnUnknownOptions(config, Object.keys(inputOptions), 'input options', log, /^output$/);
26301
26438
  return inputOptions;
26302
26439
  }
26303
26440
  const getExternal = (config, overrides) => {
@@ -26306,7 +26443,6 @@ const getExternal = (config, overrides) => {
26306
26443
  ? (source, importer, isResolved) => configExternal(source, importer, isResolved) || overrides.external.includes(source)
26307
26444
  : [...ensureArray(configExternal), ...overrides.external];
26308
26445
  };
26309
- const getOnWarn = (config, defaultOnWarnHandler) => config.onwarn ? warning => config.onwarn(warning, defaultOnWarnHandler) : defaultOnWarnHandler;
26310
26446
  const getObjectOption = (config, overrides, name, objectifyValue = objectifyOption) => {
26311
26447
  const commandOption = normalizeObjectOptionValue(overrides[name], objectifyValue);
26312
26448
  const configOption = normalizeObjectOptionValue(config[name], objectifyValue);
@@ -26325,7 +26461,7 @@ const normalizeObjectOptionValue = (optionValue, objectifyValue) => {
26325
26461
  }
26326
26462
  return objectifyValue(optionValue);
26327
26463
  };
26328
- async function mergeOutputOptions(config, overrides, warn) {
26464
+ async function mergeOutputOptions(config, overrides, log) {
26329
26465
  const getOption = (name) => overrides[name] ?? config[name];
26330
26466
  const outputOptions = {
26331
26467
  amd: getObjectOption(config, overrides, 'amd'),
@@ -26377,7 +26513,7 @@ async function mergeOutputOptions(config, overrides, warn) {
26377
26513
  systemNullSetters: getOption('systemNullSetters'),
26378
26514
  validate: getOption('validate')
26379
26515
  };
26380
- warnUnknownOptions(config, Object.keys(outputOptions), 'output options', warn);
26516
+ warnUnknownOptions(config, Object.keys(outputOptions), 'output options', log);
26381
26517
  return outputOptions;
26382
26518
  }
26383
26519
 
@@ -26465,10 +26601,10 @@ function watch(configs) {
26465
26601
  return emitter;
26466
26602
  }
26467
26603
  async function watchInternal(configs, emitter) {
26468
- const optionsList = await Promise.all(ensureArray(configs).map(config => mergeOptions(config)));
26604
+ const optionsList = await Promise.all(ensureArray(configs).map(config => mergeOptions(config, true)));
26469
26605
  const watchOptionsList = optionsList.filter(config => config.watch !== false);
26470
26606
  if (watchOptionsList.length === 0) {
26471
- return error(errorInvalidOption('watch', URL_WATCH, 'there must be at least one config where "watch" is not set to "false"'));
26607
+ return error(logInvalidOption('watch', URL_WATCH, 'there must be at least one config where "watch" is not set to "false"'));
26472
26608
  }
26473
26609
  await loadFsEvents();
26474
26610
  const { Watcher } = await import('./watch.js');