rollup 3.0.0-3 → 3.0.0-4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v3.0.0-2
4
- Sat, 30 Jul 2022 12:51:34 GMT - commit 41906cedefbc03640d6e8ca23ce6975f3bb5c6a1
3
+ Rollup.js v3.0.0-3
4
+ Mon, 15 Aug 2022 04:43:13 GMT - commit 84a4a595851ef71494b6f2ab558968bfbc148bdb
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
@@ -9,12 +9,13 @@
9
9
  */
10
10
  'use strict';
11
11
 
12
+ const node_path = require('node:path');
12
13
  const require$$0 = require('path');
13
- const process$1 = require('process');
14
- const perf_hooks = require('perf_hooks');
15
- const crypto = require('crypto');
16
- const require$$0$1 = require('fs');
17
- const require$$0$2 = require('events');
14
+ const process$1 = require('node:process');
15
+ const node_perf_hooks = require('node:perf_hooks');
16
+ const node_crypto = require('node:crypto');
17
+ const node_fs = require('node:fs');
18
+ const node_events = require('node:events');
18
19
 
19
20
  function _interopNamespaceDefault(e) {
20
21
  const n = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } });
@@ -27,7 +28,7 @@ function _interopNamespaceDefault(e) {
27
28
  return n;
28
29
  }
29
30
 
30
- var version$1 = "3.0.0-2";
31
+ var version$1 = "3.0.0-3";
31
32
 
32
33
  function ensureArray$1(items) {
33
34
  if (Array.isArray(items)) {
@@ -162,13 +163,13 @@ function normalize(path) {
162
163
  }
163
164
 
164
165
  function getAliasName(id) {
165
- const base = require$$0.basename(id);
166
- return base.substring(0, base.length - require$$0.extname(id).length);
166
+ const base = node_path.basename(id);
167
+ return base.substring(0, base.length - node_path.extname(id).length);
167
168
  }
168
169
  function relativeId(id) {
169
170
  if (!isAbsolute(id))
170
171
  return id;
171
- return relative(require$$0.resolve(), id);
172
+ return relative(node_path.resolve(), id);
172
173
  }
173
174
  function isPathFragment(name) {
174
175
  // starting with "/", "./", "../", "C:/"
@@ -176,17 +177,17 @@ function isPathFragment(name) {
176
177
  }
177
178
  const UPPER_DIR_REGEX = /^(\.\.\/)*\.\.$/;
178
179
  function getImportPath(importerId, targetPath, stripJsExtension, ensureFileName) {
179
- let relativePath = normalize(relative(require$$0.dirname(importerId), targetPath));
180
+ let relativePath = normalize(relative(node_path.dirname(importerId), targetPath));
180
181
  if (stripJsExtension && relativePath.endsWith('.js')) {
181
182
  relativePath = relativePath.slice(0, -3);
182
183
  }
183
184
  if (ensureFileName) {
184
185
  if (relativePath === '')
185
- return '../' + require$$0.basename(targetPath);
186
+ return '../' + node_path.basename(targetPath);
186
187
  if (UPPER_DIR_REGEX.test(relativePath)) {
187
188
  return relativePath
188
189
  .split('/')
189
- .concat(['..', require$$0.basename(targetPath)])
190
+ .concat(['..', node_path.basename(targetPath)])
190
191
  .join('/');
191
192
  }
192
193
  }
@@ -435,11 +436,19 @@ function errInvalidOption(option, urlHash, explanation, value) {
435
436
  url: `https://rollupjs.org/guide/en/#${urlHash}`
436
437
  };
437
438
  }
438
- function errInvalidPluginHook(hook, plugin) {
439
+ function errInvalidAddonPluginHook(hook, plugin) {
439
440
  return {
440
441
  code: INVALID_PLUGIN_HOOK,
441
442
  hook,
442
- message: `Error running plugin hook "${hook}" for "${plugin}", expected a function hook.`,
443
+ message: `Error running plugin hook "${hook}" for plugin "${plugin}", expected a string, a function hook or an object with a "handler" string or function.`,
444
+ plugin
445
+ };
446
+ }
447
+ function errInvalidFunctionPluginHook(hook, plugin) {
448
+ return {
449
+ code: INVALID_PLUGIN_HOOK,
450
+ hook,
451
+ message: `Error running plugin hook "${hook}" for plugin "${plugin}", expected a function hook or an object with a "handler" function.`,
443
452
  plugin
444
453
  };
445
454
  }
@@ -2358,7 +2367,7 @@ class ExternalChunk {
2358
2367
  const { paths } = this.options;
2359
2368
  return (this.fileName =
2360
2369
  (typeof paths === 'function' ? paths(this.id) : paths[this.id]) ||
2361
- (this.renormalizeRenderPath ? normalize(require$$0.relative(this.inputBase, this.id)) : this.id));
2370
+ (this.renormalizeRenderPath ? normalize(node_path.relative(this.inputBase, this.id)) : this.id));
2362
2371
  }
2363
2372
  getImportPath(importer) {
2364
2373
  return escapeId(this.renormalizeRenderPath
@@ -5431,10 +5440,10 @@ const SequenceExpression$1 = 'SequenceExpression';
5431
5440
 
5432
5441
  // this looks ridiculous, but it prevents sourcemap tooling from mistaking
5433
5442
  // this for an actual sourceMappingURL
5434
- exports.SOURCEMAPPING_URL = 'sourceMa';
5435
- exports.SOURCEMAPPING_URL += 'ppingURL';
5443
+ let SOURCEMAPPING_URL = 'sourceMa';
5444
+ SOURCEMAPPING_URL += 'ppingURL';
5436
5445
  const whiteSpaceNoNewline = '[ \\f\\r\\t\\v\\u00a0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000\\ufeff]';
5437
- const SOURCEMAPPING_URL_RE = new RegExp(`^#${whiteSpaceNoNewline}+${exports.SOURCEMAPPING_URL}=.+`);
5446
+ const SOURCEMAPPING_URL_RE = new RegExp(`^#${whiteSpaceNoNewline}+${SOURCEMAPPING_URL}=.+`);
5438
5447
 
5439
5448
  const ANNOTATION_KEY = '_rollupAnnotations';
5440
5449
  const INVALID_COMMENT_KEY = '_rollupRemoved';
@@ -10943,7 +10952,7 @@ class MetaProperty extends NodeBase {
10943
10952
  const chunkId = this.preliminaryChunkId;
10944
10953
  if (referenceId) {
10945
10954
  const fileName = pluginDriver.getFileName(referenceId);
10946
- const relativePath = normalize(require$$0.relative(require$$0.dirname(chunkId), fileName));
10955
+ const relativePath = normalize(node_path.relative(node_path.dirname(chunkId), fileName));
10947
10956
  const replacement = pluginDriver.hookFirstSync('resolveFileUrl', [
10948
10957
  {
10949
10958
  chunkId,
@@ -12453,7 +12462,7 @@ function getPersistedLabel(label, level) {
12453
12462
  function timeStartImpl(label, level = 3) {
12454
12463
  label = getPersistedLabel(label, level);
12455
12464
  const startMemory = process$1.memoryUsage().heapUsed;
12456
- const startTime = perf_hooks.performance.now();
12465
+ const startTime = node_perf_hooks.performance.now();
12457
12466
  const timer = timers.get(label);
12458
12467
  if (timer === undefined) {
12459
12468
  timers.set(label, {
@@ -12475,7 +12484,7 @@ function timeEndImpl(label, level = 3) {
12475
12484
  if (timer !== undefined) {
12476
12485
  const currentMemory = process$1.memoryUsage().heapUsed;
12477
12486
  timer.memory += currentMemory - timer.startMemory;
12478
- timer.time += perf_hooks.performance.now() - timer.startTime;
12487
+ timer.time += node_perf_hooks.performance.now() - timer.startTime;
12479
12488
  timer.totalMemory = Math.max(timer.totalMemory, currentMemory);
12480
12489
  }
12481
12490
  }
@@ -12715,8 +12724,8 @@ class Module {
12715
12724
  });
12716
12725
  }
12717
12726
  basename() {
12718
- const base = require$$0.basename(this.id);
12719
- const ext = require$$0.extname(this.id);
12727
+ const base = node_path.basename(this.id);
12728
+ const ext = node_path.extname(this.id);
12720
12729
  return makeLegal(ext ? base.slice(0, -ext.length) : base);
12721
12730
  }
12722
12731
  bindReferences() {
@@ -13599,32 +13608,32 @@ function removeExtensionFromRelativeAmdId(id) {
13599
13608
  }
13600
13609
 
13601
13610
  const builtins = {
13602
- assert: true,
13603
- buffer: true,
13604
- console: true,
13605
- constants: true,
13606
- domain: true,
13607
- events: true,
13608
- http: true,
13609
- https: true,
13610
- os: true,
13611
- path: true,
13612
- process: true,
13613
- punycode: true,
13614
- querystring: true,
13615
- stream: true,
13616
- string_decoder: true,
13617
- timers: true,
13618
- tty: true,
13619
- url: true,
13620
- util: true,
13621
- vm: true,
13622
- zlib: true
13611
+ assert: 1,
13612
+ buffer: 1,
13613
+ console: 1,
13614
+ constants: 1,
13615
+ domain: 1,
13616
+ events: 1,
13617
+ http: 1,
13618
+ https: 1,
13619
+ os: 1,
13620
+ path: 1,
13621
+ process: 1,
13622
+ punycode: 1,
13623
+ querystring: 1,
13624
+ stream: 1,
13625
+ string_decoder: 1,
13626
+ timers: 1,
13627
+ tty: 1,
13628
+ url: 1,
13629
+ util: 1,
13630
+ vm: 1,
13631
+ zlib: 1
13623
13632
  };
13624
13633
  function warnOnBuiltins(warn, dependencies) {
13625
13634
  const externalBuiltins = dependencies
13626
13635
  .map(({ importPath }) => importPath)
13627
- .filter(importPath => importPath in builtins);
13636
+ .filter(importPath => importPath in builtins || importPath.startsWith('node:'));
13628
13637
  if (!externalBuiltins.length)
13629
13638
  return;
13630
13639
  warn(errMissingNodeBuiltins(externalBuiltins));
@@ -14161,7 +14170,7 @@ function umd(magicString, { accessedGlobals, dependencies, exports, hasExports,
14161
14170
 
14162
14171
  const finalisers = { amd, cjs, es, iife, system, umd };
14163
14172
 
14164
- const createHash = () => crypto.createHash('sha256');
14173
+ const createHash = () => node_crypto.createHash('sha256');
14165
14174
 
14166
14175
  // Four random characters from the private use area to minimize risk of conflicts
14167
14176
  const hashPlaceholderLeft = '\uf7f9\ue4d3';
@@ -14216,7 +14225,7 @@ function makeUnique(name, existingNames) {
14216
14225
  const existingNamesLowercase = new Set(Object.keys(existingNames).map(key => key.toLowerCase()));
14217
14226
  if (!existingNamesLowercase.has(name.toLocaleLowerCase()))
14218
14227
  return name;
14219
- const ext = require$$0.extname(name);
14228
+ const ext = node_path.extname(name);
14220
14229
  name = name.substring(0, name.length - ext.length);
14221
14230
  let uniqueName, uniqueIndex = 1;
14222
14231
  while (existingNamesLowercase.has((uniqueName = name + ++uniqueIndex + ext).toLowerCase()))
@@ -14229,13 +14238,13 @@ function generateAssetFileName(name, source, outputOptions, bundle) {
14229
14238
  return makeUnique(renderNamePattern(typeof outputOptions.assetFileNames === 'function'
14230
14239
  ? outputOptions.assetFileNames({ name, source, type: 'asset' })
14231
14240
  : outputOptions.assetFileNames, 'output.assetFileNames', {
14232
- ext: () => require$$0.extname(emittedName).substring(1),
14233
- extname: () => require$$0.extname(emittedName),
14241
+ ext: () => node_path.extname(emittedName).substring(1),
14242
+ extname: () => node_path.extname(emittedName),
14234
14243
  hash: size => createHash()
14235
14244
  .update(source)
14236
14245
  .digest('hex')
14237
14246
  .substring(0, size || defaultHashSize),
14238
- name: () => emittedName.substring(0, emittedName.length - require$$0.extname(emittedName).length)
14247
+ name: () => emittedName.substring(0, emittedName.length - node_path.extname(emittedName).length)
14239
14248
  }), bundle);
14240
14249
  }
14241
14250
  function reserveFileNameInBundle(fileName, bundle, warn) {
@@ -14979,7 +14988,7 @@ class Chunk {
14979
14988
  let hashPlaceholder = null;
14980
14989
  const { chunkFileNames, entryFileNames, file, format, preserveModules } = this.outputOptions;
14981
14990
  if (file) {
14982
- fileName = require$$0.basename(file);
14991
+ fileName = node_path.basename(file);
14983
14992
  }
14984
14993
  else if (this.fileName !== null) {
14985
14994
  fileName = this.fileName;
@@ -15344,17 +15353,17 @@ class Chunk {
15344
15353
  return predefinedChunkName;
15345
15354
  const { preserveModulesRoot, sanitizeFileName } = this.outputOptions;
15346
15355
  const sanitizedId = sanitizeFileName(module.id.split(QUERY_HASH_REGEX, 1)[0]);
15347
- const extName = require$$0.extname(sanitizedId);
15356
+ const extName = node_path.extname(sanitizedId);
15348
15357
  const idWithoutExtension = NON_ASSET_EXTENSIONS.includes(extName)
15349
15358
  ? sanitizedId.slice(0, -extName.length)
15350
15359
  : sanitizedId;
15351
15360
  if (isAbsolute(idWithoutExtension)) {
15352
- return preserveModulesRoot && idWithoutExtension.startsWith(preserveModulesRoot)
15361
+ return preserveModulesRoot && node_path.resolve(idWithoutExtension).startsWith(preserveModulesRoot)
15353
15362
  ? idWithoutExtension.slice(preserveModulesRoot.length).replace(/^[\\/]/, '')
15354
15363
  : relative(this.inputBase, idWithoutExtension);
15355
15364
  }
15356
15365
  else {
15357
- return `_virtual/${require$$0.basename(idWithoutExtension)}`;
15366
+ return `_virtual/${node_path.basename(idWithoutExtension)}`;
15358
15367
  }
15359
15368
  }
15360
15369
  getReexportSpecifiers() {
@@ -15826,7 +15835,7 @@ function commondir(files) {
15826
15835
  if (files.length === 0)
15827
15836
  return '/';
15828
15837
  if (files.length === 1)
15829
- return require$$0.dirname(files[0]);
15838
+ return node_path.dirname(files[0]);
15830
15839
  const commonSegments = files.slice(1).reduce((commonSegments, file) => {
15831
15840
  const pathSegements = file.split(/\/+|\\+/);
15832
15841
  let i;
@@ -16083,9 +16092,9 @@ function getCollapsedSourcemap(id, originalCode, originalSourcemap, sourcemapCha
16083
16092
  else {
16084
16093
  const sources = originalSourcemap.sources;
16085
16094
  const sourcesContent = originalSourcemap.sourcesContent || [];
16086
- const directory = require$$0.dirname(id) || '.';
16095
+ const directory = node_path.dirname(id) || '.';
16087
16096
  const sourceRoot = originalSourcemap.sourceRoot || '.';
16088
- const baseSources = sources.map((source, i) => new Source(require$$0.resolve(directory, sourceRoot, source), sourcesContent[i]));
16097
+ const baseSources = sources.map((source, i) => new Source(node_path.resolve(directory, sourceRoot, source), sourcesContent[i]));
16089
16098
  source = new Link(originalSourcemap, baseSources);
16090
16099
  }
16091
16100
  return sourcemapChain.reduce(linkMap, source);
@@ -16099,9 +16108,9 @@ function collapseSourcemaps(file, map, modules, bundleSourcemapChain, excludeCon
16099
16108
  const source = bundleSourcemapChain.reduce(linkMap, link);
16100
16109
  let { sources, sourcesContent, names, mappings } = source.traceMappings();
16101
16110
  if (file) {
16102
- const directory = require$$0.dirname(file);
16103
- sources = sources.map((source) => require$$0.relative(directory, source));
16104
- file = require$$0.basename(file);
16111
+ const directory = node_path.dirname(file);
16112
+ sources = sources.map((source) => node_path.relative(directory, source));
16113
+ file = node_path.basename(file);
16105
16114
  }
16106
16115
  sourcesContent = (excludeContent ? null : sourcesContent);
16107
16116
  return new SourceMap({ file, mappings, names, sources, sourcesContent });
@@ -16142,7 +16151,7 @@ async function renderChunks(chunks, outputBundle, pluginDriver, outputOptions, o
16142
16151
  const chunkGraph = getChunkGraph(chunks);
16143
16152
  const { nonHashedChunksWithPlaceholders, renderedChunksByPlaceholder, hashDependenciesByPlaceholder } = await transformChunksAndGenerateContentHashes(renderedChunks, chunkGraph, outputOptions, pluginDriver, onwarn);
16144
16153
  const hashesByPlaceholder = generateFinalHashes(renderedChunksByPlaceholder, hashDependenciesByPlaceholder, outputBundle);
16145
- addChunksToBundle(renderedChunksByPlaceholder, hashesByPlaceholder, outputBundle, nonHashedChunksWithPlaceholders);
16154
+ addChunksToBundle(renderedChunksByPlaceholder, hashesByPlaceholder, outputBundle, nonHashedChunksWithPlaceholders, pluginDriver, outputOptions);
16146
16155
  timeEnd('transform chunks', 2);
16147
16156
  }
16148
16157
  function reserveEntryChunksInBundle(chunks) {
@@ -16184,11 +16193,11 @@ async function transformChunk(magicString, fileName, usedModules, chunkGraph, op
16184
16193
  timeStart('sourcemaps', 3);
16185
16194
  let file;
16186
16195
  if (options.file)
16187
- file = require$$0.resolve(options.sourcemapFile || options.file);
16196
+ file = node_path.resolve(options.sourcemapFile || options.file);
16188
16197
  else if (options.dir)
16189
- file = require$$0.resolve(options.dir, fileName);
16198
+ file = node_path.resolve(options.dir, fileName);
16190
16199
  else
16191
- file = require$$0.resolve(fileName);
16200
+ file = node_path.resolve(fileName);
16192
16201
  const decodedMap = magicString.generateDecodedMap({});
16193
16202
  map = collapseSourcemaps(file, decodedMap, usedModules, sourcemapChain, options.sourcemapExcludeSources, onwarn);
16194
16203
  map.sources = map.sources
@@ -16286,22 +16295,40 @@ function generateFinalHashes(renderedChunksByPlaceholder, hashDependenciesByPlac
16286
16295
  }
16287
16296
  return hashesByPlaceholder;
16288
16297
  }
16289
- function addChunksToBundle(renderedChunksByPlaceholder, hashesByPlaceholder, outputBundle, nonHashedChunksWithPlaceholders) {
16298
+ function addChunksToBundle(renderedChunksByPlaceholder, hashesByPlaceholder, outputBundle, nonHashedChunksWithPlaceholders, pluginDriver, options) {
16290
16299
  for (const { chunk, code, fileName, map } of renderedChunksByPlaceholder.values()) {
16291
- const updatedCode = replacePlaceholders(code, hashesByPlaceholder);
16300
+ let updatedCode = replacePlaceholders(code, hashesByPlaceholder);
16292
16301
  const finalFileName = replacePlaceholders(fileName, hashesByPlaceholder);
16293
16302
  if (map) {
16294
16303
  map.file = replacePlaceholders(map.file, hashesByPlaceholder);
16304
+ updatedCode += emitSourceMapAndGetComment(finalFileName, map, pluginDriver, options);
16295
16305
  }
16296
16306
  outputBundle[finalFileName] = chunk.generateOutputChunk(updatedCode, map, hashesByPlaceholder);
16297
16307
  }
16298
16308
  for (const { chunk, code, fileName, map } of nonHashedChunksWithPlaceholders) {
16299
- const updatedCode = hashesByPlaceholder.size
16309
+ let updatedCode = hashesByPlaceholder.size
16300
16310
  ? replacePlaceholders(code, hashesByPlaceholder)
16301
16311
  : code;
16312
+ if (map) {
16313
+ updatedCode += emitSourceMapAndGetComment(fileName, map, pluginDriver, options);
16314
+ }
16302
16315
  outputBundle[fileName] = chunk.generateOutputChunk(updatedCode, map, hashesByPlaceholder);
16303
16316
  }
16304
16317
  }
16318
+ function emitSourceMapAndGetComment(fileName, map, pluginDriver, { sourcemap, sourcemapBaseUrl }) {
16319
+ let url;
16320
+ if (sourcemap === 'inline') {
16321
+ url = map.toUrl();
16322
+ }
16323
+ else {
16324
+ const sourcemapFileName = `${node_path.basename(fileName)}.map`;
16325
+ url = sourcemapBaseUrl
16326
+ ? new URL(sourcemapFileName, sourcemapBaseUrl).toString()
16327
+ : sourcemapFileName;
16328
+ pluginDriver.emitFile({ fileName: `${fileName}.map`, source: map.toString(), type: 'asset' });
16329
+ }
16330
+ return sourcemap === 'hidden' ? '' : `//# ${SOURCEMAPPING_URL}=${url}\n`;
16331
+ }
16305
16332
 
16306
16333
  class Bundle {
16307
16334
  constructor(outputOptions, unsetOptions, inputOptions, pluginDriver, graph) {
@@ -22057,7 +22084,7 @@ async function resolveId(source, importer, preserveSymlinks, pluginDriver, modul
22057
22084
  // absolute path is created. Absolute importees therefore shortcircuit the
22058
22085
  // resolve call and require no special handing on our part.
22059
22086
  // See https://nodejs.org/api/path.html#path_path_resolve_paths
22060
- return addJsExtensionIfNecessary(importer ? require$$0.resolve(require$$0.dirname(importer), source) : require$$0.resolve(source), preserveSymlinks);
22087
+ return addJsExtensionIfNecessary(importer ? node_path.resolve(node_path.dirname(importer), source) : node_path.resolve(source), preserveSymlinks);
22061
22088
  }
22062
22089
  async function addJsExtensionIfNecessary(file, preserveSymlinks) {
22063
22090
  var _a, _b;
@@ -22065,13 +22092,13 @@ async function addJsExtensionIfNecessary(file, preserveSymlinks) {
22065
22092
  }
22066
22093
  async function findFile(file, preserveSymlinks) {
22067
22094
  try {
22068
- const stats = await require$$0$1.promises.lstat(file);
22095
+ const stats = await node_fs.promises.lstat(file);
22069
22096
  if (!preserveSymlinks && stats.isSymbolicLink())
22070
- return await findFile(await require$$0$1.promises.realpath(file), preserveSymlinks);
22097
+ return await findFile(await node_fs.promises.realpath(file), preserveSymlinks);
22071
22098
  if ((preserveSymlinks && stats.isSymbolicLink()) || stats.isFile()) {
22072
22099
  // check case
22073
- const name = require$$0.basename(file);
22074
- const files = await require$$0$1.promises.readdir(require$$0.dirname(file));
22100
+ const name = node_path.basename(file);
22101
+ const files = await node_fs.promises.readdir(node_path.dirname(file));
22075
22102
  if (files.includes(name))
22076
22103
  return file;
22077
22104
  }
@@ -22380,7 +22407,7 @@ class ModuleLoader {
22380
22407
  async addModuleSource(id, importer, module) {
22381
22408
  let source;
22382
22409
  try {
22383
- source = await this.graph.fileOperationQueue.run(async () => { var _a; return (_a = (await this.pluginDriver.hookFirst('load', [id]))) !== null && _a !== void 0 ? _a : (await require$$0$1.promises.readFile(id, 'utf8')); });
22410
+ source = await this.graph.fileOperationQueue.run(async () => { var _a; return (_a = (await this.pluginDriver.hookFirst('load', [id]))) !== null && _a !== void 0 ? _a : (await node_fs.promises.readFile(id, 'utf8')); });
22384
22411
  }
22385
22412
  catch (err) {
22386
22413
  let msg = `Could not load ${id}`;
@@ -22677,8 +22704,8 @@ class ModuleLoader {
22677
22704
  function normalizeRelativeExternalId(source, importer) {
22678
22705
  return isRelative(source)
22679
22706
  ? importer
22680
- ? require$$0.resolve(importer, '..', source)
22681
- : require$$0.resolve(source)
22707
+ ? node_path.resolve(importer, '..', source)
22708
+ : node_path.resolve(source)
22682
22709
  : source;
22683
22710
  }
22684
22711
  function addChunkNamesToModule(module, { fileName, name }, isUserDefined, priority) {
@@ -22743,7 +22770,7 @@ function getPluginContext(plugin, pluginCache, graph, options, fileEmitter, exis
22743
22770
  else {
22744
22771
  cacheInstance = getCacheForUncacheablePlugin(plugin.name);
22745
22772
  }
22746
- const context = {
22773
+ return {
22747
22774
  addWatchFile(id) {
22748
22775
  if (graph.phase >= BuildPhase.GENERATE) {
22749
22776
  return this.error(errInvalidRollupPhaseForAddWatchFile());
@@ -22793,9 +22820,9 @@ function getPluginContext(plugin, pluginCache, graph, options, fileEmitter, exis
22793
22820
  options.onwarn(warning);
22794
22821
  }
22795
22822
  };
22796
- return context;
22797
22823
  }
22798
22824
 
22825
+ // This will make sure no input hook is omitted
22799
22826
  const inputHookNames = {
22800
22827
  buildEnd: 1,
22801
22828
  buildStart: 1,
@@ -22815,8 +22842,9 @@ class PluginDriver {
22815
22842
  constructor(graph, options, userPlugins, pluginCache, basePluginDriver) {
22816
22843
  this.graph = graph;
22817
22844
  this.options = options;
22818
- this.unfulfilledActions = new Set();
22819
22845
  this.pluginCache = pluginCache;
22846
+ this.sortedPlugins = new Map();
22847
+ this.unfulfilledActions = new Set();
22820
22848
  this.fileEmitter = new FileEmitter(graph, options, basePluginDriver && basePluginDriver.fileEmitter);
22821
22849
  this.emitFile = this.fileEmitter.emitFile.bind(this.fileEmitter);
22822
22850
  this.getFileName = this.fileEmitter.getFileName.bind(this.fileEmitter);
@@ -22847,21 +22875,21 @@ class PluginDriver {
22847
22875
  }
22848
22876
  // chains, first non-null result stops and returns
22849
22877
  hookFirst(hookName, args, replaceContext, skipped) {
22850
- let promise = Promise.resolve(undefined);
22851
- for (const plugin of this.plugins) {
22878
+ let promise = Promise.resolve(null);
22879
+ for (const plugin of this.getSortedPlugins(hookName)) {
22852
22880
  if (skipped && skipped.has(plugin))
22853
22881
  continue;
22854
22882
  promise = promise.then(result => {
22855
22883
  if (result != null)
22856
22884
  return result;
22857
- return this.runHook(hookName, args, plugin, false, replaceContext);
22885
+ return this.runHook(hookName, args, plugin, replaceContext);
22858
22886
  });
22859
22887
  }
22860
22888
  return promise;
22861
22889
  }
22862
22890
  // chains synchronously, first non-null result stops and returns
22863
22891
  hookFirstSync(hookName, args, replaceContext) {
22864
- for (const plugin of this.plugins) {
22892
+ for (const plugin of this.getSortedPlugins(hookName)) {
22865
22893
  const result = this.runHookSync(hookName, args, plugin, replaceContext);
22866
22894
  if (result != null)
22867
22895
  return result;
@@ -22869,56 +22897,58 @@ class PluginDriver {
22869
22897
  return null;
22870
22898
  }
22871
22899
  // parallel, ignores returns
22872
- hookParallel(hookName, args, replaceContext) {
22873
- const promises = [];
22874
- for (const plugin of this.plugins) {
22875
- const hookPromise = this.runHook(hookName, args, plugin, false, replaceContext);
22876
- if (!hookPromise)
22877
- continue;
22878
- promises.push(hookPromise);
22900
+ async hookParallel(hookName, args, replaceContext) {
22901
+ const parallelPromises = [];
22902
+ for (const plugin of this.getSortedPlugins(hookName)) {
22903
+ if (plugin[hookName].sequential) {
22904
+ await Promise.all(parallelPromises);
22905
+ parallelPromises.length = 0;
22906
+ await this.runHook(hookName, args, plugin, replaceContext);
22907
+ }
22908
+ else {
22909
+ parallelPromises.push(this.runHook(hookName, args, plugin, replaceContext));
22910
+ }
22879
22911
  }
22880
- return Promise.all(promises).then(() => { });
22912
+ await Promise.all(parallelPromises);
22881
22913
  }
22882
22914
  // chains, reduces returned value, handling the reduced value as the first hook argument
22883
22915
  hookReduceArg0(hookName, [arg0, ...rest], reduce, replaceContext) {
22884
22916
  let promise = Promise.resolve(arg0);
22885
- for (const plugin of this.plugins) {
22886
- promise = promise.then(arg0 => {
22887
- const args = [arg0, ...rest];
22888
- const hookPromise = this.runHook(hookName, args, plugin, false, replaceContext);
22889
- if (!hookPromise)
22890
- return arg0;
22891
- return hookPromise.then(result => reduce.call(this.pluginContexts.get(plugin), arg0, result, plugin));
22892
- });
22917
+ for (const plugin of this.getSortedPlugins(hookName)) {
22918
+ promise = promise.then(arg0 => this.runHook(hookName, [arg0, ...rest], plugin, replaceContext).then(result => reduce.call(this.pluginContexts.get(plugin), arg0, result, plugin)));
22893
22919
  }
22894
22920
  return promise;
22895
22921
  }
22896
22922
  // chains synchronously, reduces returned value, handling the reduced value as the first hook argument
22897
22923
  hookReduceArg0Sync(hookName, [arg0, ...rest], reduce, replaceContext) {
22898
- for (const plugin of this.plugins) {
22924
+ for (const plugin of this.getSortedPlugins(hookName)) {
22899
22925
  const args = [arg0, ...rest];
22900
22926
  const result = this.runHookSync(hookName, args, plugin, replaceContext);
22901
22927
  arg0 = reduce.call(this.pluginContexts.get(plugin), arg0, result, plugin);
22902
22928
  }
22903
22929
  return arg0;
22904
22930
  }
22905
- // chains, reduces returned value to type T, handling the reduced value separately. permits hooks as values.
22906
- hookReduceValue(hookName, initialValue, args, reduce, replaceContext) {
22907
- let promise = Promise.resolve(initialValue);
22908
- for (const plugin of this.plugins) {
22909
- promise = promise.then(value => {
22910
- const hookPromise = this.runHook(hookName, args, plugin, true, replaceContext);
22911
- if (!hookPromise)
22912
- return value;
22913
- return hookPromise.then(result => reduce.call(this.pluginContexts.get(plugin), value, result, plugin));
22914
- });
22931
+ // chains, reduces returned value to type string, handling the reduced value separately. permits hooks as values.
22932
+ async hookReduceValue(hookName, initialValue, args, reducer) {
22933
+ const results = [];
22934
+ const parallelResults = [];
22935
+ for (const plugin of this.getSortedPlugins(hookName, validateAddonPluginHandler)) {
22936
+ if (plugin[hookName].sequential) {
22937
+ results.push(...(await Promise.all(parallelResults)));
22938
+ parallelResults.length = 0;
22939
+ results.push(await this.runHook(hookName, args, plugin));
22940
+ }
22941
+ else {
22942
+ parallelResults.push(this.runHook(hookName, args, plugin));
22943
+ }
22915
22944
  }
22916
- return promise;
22945
+ results.push(...(await Promise.all(parallelResults)));
22946
+ return results.reduce(reducer, await initialValue);
22917
22947
  }
22918
22948
  // chains synchronously, reduces returned value to type T, handling the reduced value separately. permits hooks as values.
22919
22949
  hookReduceValueSync(hookName, initialValue, args, reduce, replaceContext) {
22920
22950
  let acc = initialValue;
22921
- for (const plugin of this.plugins) {
22951
+ for (const plugin of this.getSortedPlugins(hookName)) {
22922
22952
  const result = this.runHookSync(hookName, args, plugin, replaceContext);
22923
22953
  acc = reduce.call(this.pluginContexts.get(plugin), acc, result, plugin);
22924
22954
  }
@@ -22927,31 +22957,32 @@ class PluginDriver {
22927
22957
  // chains, ignores returns
22928
22958
  hookSeq(hookName, args, replaceContext) {
22929
22959
  let promise = Promise.resolve();
22930
- for (const plugin of this.plugins) {
22931
- promise = promise.then(() => this.runHook(hookName, args, plugin, false, replaceContext));
22960
+ for (const plugin of this.getSortedPlugins(hookName)) {
22961
+ promise = promise.then(() => this.runHook(hookName, args, plugin, replaceContext));
22932
22962
  }
22933
- return promise;
22963
+ return promise.then(noReturn);
22964
+ }
22965
+ getSortedPlugins(hookName, validateHandler) {
22966
+ return getOrCreate(this.sortedPlugins, hookName, () => getSortedValidatedPlugins(hookName, this.plugins, validateHandler));
22934
22967
  }
22935
- runHook(hookName, args, plugin, permitValues, hookContext) {
22968
+ // Implementation signature
22969
+ runHook(hookName, args, plugin, replaceContext) {
22970
+ // We always filter for plugins that support the hook before running it
22936
22971
  const hook = plugin[hookName];
22937
- if (!hook)
22938
- return undefined;
22972
+ const handler = typeof hook === 'object' ? hook.handler : hook;
22939
22973
  let context = this.pluginContexts.get(plugin);
22940
- if (hookContext) {
22941
- context = hookContext(context, plugin);
22974
+ if (replaceContext) {
22975
+ context = replaceContext(context, plugin);
22942
22976
  }
22943
22977
  let action = null;
22944
22978
  return Promise.resolve()
22945
22979
  .then(() => {
22946
- // permit values allows values to be returned instead of a functional hook
22947
- if (typeof hook !== 'function') {
22948
- if (permitValues)
22949
- return hook;
22950
- return error(errInvalidPluginHook(hookName, plugin.name));
22980
+ if (typeof handler !== 'function') {
22981
+ return handler;
22951
22982
  }
22952
22983
  // eslint-disable-next-line @typescript-eslint/ban-types
22953
- const hookResult = hook.apply(context, args);
22954
- if (!hookResult || !hookResult.then) {
22984
+ const hookResult = handler.apply(context, args);
22985
+ if (!(hookResult === null || hookResult === void 0 ? void 0 : hookResult.then)) {
22955
22986
  // short circuit for non-thenables and non-Promises
22956
22987
  return hookResult;
22957
22988
  }
@@ -22984,29 +23015,61 @@ class PluginDriver {
22984
23015
  * @param hookName Name of the plugin hook. Must be in `PluginHooks`.
22985
23016
  * @param args Arguments passed to the plugin hook.
22986
23017
  * @param plugin The acutal plugin
22987
- * @param hookContext When passed, the plugin context can be overridden.
23018
+ * @param replaceContext When passed, the plugin context can be overridden.
22988
23019
  */
22989
- runHookSync(hookName, args, plugin, hookContext) {
23020
+ runHookSync(hookName, args, plugin, replaceContext) {
22990
23021
  const hook = plugin[hookName];
22991
- if (!hook)
22992
- return undefined;
23022
+ const handler = typeof hook === 'object' ? hook.handler : hook;
22993
23023
  let context = this.pluginContexts.get(plugin);
22994
- if (hookContext) {
22995
- context = hookContext(context, plugin);
23024
+ if (replaceContext) {
23025
+ context = replaceContext(context, plugin);
22996
23026
  }
22997
23027
  try {
22998
- // permit values allows values to be returned instead of a functional hook
22999
- if (typeof hook !== 'function') {
23000
- return error(errInvalidPluginHook(hookName, plugin.name));
23001
- }
23002
23028
  // eslint-disable-next-line @typescript-eslint/ban-types
23003
- return hook.apply(context, args);
23029
+ return handler.apply(context, args);
23004
23030
  }
23005
23031
  catch (err) {
23006
23032
  return error(errPluginError(err, plugin.name, { hook: hookName }));
23007
23033
  }
23008
23034
  }
23009
23035
  }
23036
+ function getSortedValidatedPlugins(hookName, plugins, validateHandler = validateFunctionPluginHandler) {
23037
+ const pre = [];
23038
+ const normal = [];
23039
+ const post = [];
23040
+ for (const plugin of plugins) {
23041
+ const hook = plugin[hookName];
23042
+ if (hook) {
23043
+ if (typeof hook === 'object') {
23044
+ validateHandler(hook.handler, hookName, plugin);
23045
+ if (hook.order === 'pre') {
23046
+ pre.push(plugin);
23047
+ continue;
23048
+ }
23049
+ if (hook.order === 'post') {
23050
+ post.push(plugin);
23051
+ continue;
23052
+ }
23053
+ }
23054
+ else {
23055
+ validateHandler(hook, hookName, plugin);
23056
+ }
23057
+ normal.push(plugin);
23058
+ }
23059
+ }
23060
+ return [...pre, ...normal, ...post];
23061
+ }
23062
+ function validateFunctionPluginHandler(handler, hookName, plugin) {
23063
+ if (typeof handler !== 'function') {
23064
+ error(errInvalidFunctionPluginHook(hookName, plugin.name));
23065
+ }
23066
+ }
23067
+ function validateAddonPluginHandler(handler, hookName, plugin) {
23068
+ if (typeof handler !== 'string' && typeof handler !== 'function') {
23069
+ return error(errInvalidAddonPluginHook(hookName, plugin.name));
23070
+ }
23071
+ }
23072
+ function noReturn() { }
23010
23073
 
23011
23074
  class Queue {
23012
23075
  constructor(maxParallel) {
@@ -23263,7 +23326,7 @@ function formatAction([pluginName, hookName, args]) {
23263
23326
  // We do not directly listen on process to avoid max listeners warnings for
23264
23327
  // complicated build processes
23265
23328
  const beforeExitEvent = 'beforeExit';
23266
- const beforeExitEmitter = new require$$0$2.EventEmitter();
23329
+ const beforeExitEmitter = new node_events.EventEmitter();
23267
23330
  beforeExitEmitter.setMaxListeners(0);
23268
23331
  process$1.on(beforeExitEvent, () => beforeExitEmitter.emit(beforeExitEvent));
23269
23332
  async function catchUnfinishedHookActions(pluginDriver, callback) {
@@ -23405,7 +23468,7 @@ const getModuleContext = (config, context) => {
23405
23468
  if (configModuleContext) {
23406
23469
  const contextByModuleId = Object.create(null);
23407
23470
  for (const [key, moduleContext] of Object.entries(configModuleContext)) {
23408
- contextByModuleId[require$$0.resolve(key)] = moduleContext;
23471
+ contextByModuleId[node_path.resolve(key)] = moduleContext;
23409
23472
  }
23410
23473
  return id => contextByModuleId[id] || context;
23411
23474
  }
@@ -23611,7 +23674,7 @@ const getPreserveModulesRoot = (config) => {
23611
23674
  if (preserveModulesRoot === null || preserveModulesRoot === undefined) {
23612
23675
  return undefined;
23613
23676
  }
23614
- return require$$0.resolve(preserveModulesRoot);
23677
+ return node_path.resolve(preserveModulesRoot);
23615
23678
  };
23616
23679
  const getAmd = (config) => {
23617
23680
  const mergedOption = {
@@ -23829,17 +23892,15 @@ async function getInputOptions(rawInputOptions, watchMode) {
23829
23892
  if (!rawInputOptions) {
23830
23893
  throw new Error('You must supply an options object to rollup');
23831
23894
  }
23832
- const rawPlugins = ensureArray$1(rawInputOptions.plugins);
23895
+ const rawPlugins = getSortedValidatedPlugins('options', ensureArray$1(rawInputOptions.plugins));
23833
23896
  const { options, unsetOptions } = normalizeInputOptions(await rawPlugins.reduce(applyOptionHook(watchMode), Promise.resolve(rawInputOptions)));
23834
23897
  normalizePlugins(options.plugins, ANONYMOUS_PLUGIN_PREFIX);
23835
23898
  return { options, unsetOptions };
23836
23899
  }
23837
23900
  function applyOptionHook(watchMode) {
23838
23901
  return async (inputOptions, plugin) => {
23839
- if (plugin.options) {
23840
- return ((await plugin.options.call({ meta: { rollupVersion: version$1, watchMode } }, await inputOptions)) || inputOptions);
23841
- }
23842
- return inputOptions;
23902
+ const handler = 'handler' in plugin.options ? plugin.options.handler : plugin.options;
23903
+ return ((await handler.call({ meta: { rollupVersion: version$1, watchMode } }, await inputOptions)) || inputOptions);
23843
23904
  };
23844
23905
  }
23845
23906
  function normalizePlugins(plugins, anonymousPrefix) {
@@ -23915,35 +23976,10 @@ function getSortingFileType(file) {
23915
23976
  return SortingFileType.SECONDARY_CHUNK;
23916
23977
  }
23917
23978
  async function writeOutputFile(outputFile, outputOptions) {
23918
- const fileName = require$$0.resolve(outputOptions.dir || require$$0.dirname(outputOptions.file), outputFile.fileName);
23979
+ const fileName = node_path.resolve(outputOptions.dir || node_path.dirname(outputOptions.file), outputFile.fileName);
23919
23980
  // 'recursive: true' does not throw if the folder structure, or parts of it, already exist
23920
- await require$$0$1.promises.mkdir(require$$0.dirname(fileName), { recursive: true });
23921
- let writeSourceMapPromise;
23922
- let source;
23923
- if (outputFile.type === 'asset') {
23924
- source = outputFile.source;
23925
- }
23926
- else {
23927
- source = outputFile.code;
23928
- if (outputOptions.sourcemap && outputFile.map) {
23929
- let url;
23930
- if (outputOptions.sourcemap === 'inline') {
23931
- url = outputFile.map.toUrl();
23932
- }
23933
- else {
23934
- const { sourcemapBaseUrl } = outputOptions;
23935
- const sourcemapFileName = `${require$$0.basename(outputFile.fileName)}.map`;
23936
- url = sourcemapBaseUrl
23937
- ? new URL(sourcemapFileName, sourcemapBaseUrl).toString()
23938
- : sourcemapFileName;
23939
- writeSourceMapPromise = require$$0$1.promises.writeFile(`${fileName}.map`, outputFile.map.toString());
23940
- }
23941
- if (outputOptions.sourcemap !== 'hidden') {
23942
- source += `//# ${exports.SOURCEMAPPING_URL}=${url}\n`;
23943
- }
23944
- }
23945
- }
23946
- return Promise.all([require$$0$1.promises.writeFile(fileName, source), writeSourceMapPromise]);
23981
+ await node_fs.promises.mkdir(node_path.dirname(fileName), { recursive: true });
23982
+ return node_fs.promises.writeFile(fileName, outputFile.type === 'asset' ? outputFile.source : outputFile.code);
23947
23983
  }
23948
23984
  /**
23949
23985
  * Auxiliary function for defining rollup configuration
@@ -23954,7 +23990,7 @@ function defineConfig(options) {
23954
23990
  return options;
23955
23991
  }
23956
23992
 
23957
- class WatchEmitter extends require$$0$2.EventEmitter {
23993
+ class WatchEmitter extends node_events.EventEmitter {
23958
23994
  constructor() {
23959
23995
  super();
23960
23996
  this.awaitedHandlers = Object.create(null);