rollup 2.65.0 → 2.67.1

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 v2.65.0
4
- Fri, 21 Jan 2022 07:42:35 GMT - commit bebc50ddb613d240a03988d51787fd71b1a3914f
3
+ Rollup.js v2.67.1
4
+ Mon, 07 Feb 2022 05:29:30 GMT - commit efd71e930e86ab30f4911ed8caa7f78aca005729
5
5
 
6
6
 
7
7
  https://github.com/rollup/rollup
@@ -14,8 +14,8 @@ const require$$0 = require('path');
14
14
  const process$1 = require('process');
15
15
  const perf_hooks = require('perf_hooks');
16
16
  const crypto = require('crypto');
17
- const fs = require('fs');
18
- const require$$0$1 = require('events');
17
+ const require$$0$1 = require('fs');
18
+ const require$$0$2 = require('events');
19
19
 
20
20
  function _interopNamespaceDefault(e) {
21
21
  const n = Object.create(null);
@@ -28,7 +28,7 @@ function _interopNamespaceDefault(e) {
28
28
  return n;
29
29
  }
30
30
 
31
- var version$1 = "2.65.0";
31
+ var version$1 = "2.67.1";
32
32
 
33
33
  function ensureArray$1(items) {
34
34
  if (Array.isArray(items)) {
@@ -381,22 +381,22 @@ function errMixedExport(facadeModuleId, name) {
381
381
  url: `https://rollupjs.org/guide/en/#outputexports`
382
382
  };
383
383
  }
384
- function errNamespaceConflict(name, reexportingModule, additionalExportAllModule) {
384
+ function errNamespaceConflict(name, reexportingModuleId, sources) {
385
385
  return {
386
386
  code: Errors.NAMESPACE_CONFLICT,
387
- message: `Conflicting namespaces: "${relativeId(reexportingModule.id)}" re-exports "${name}" from both "${relativeId(reexportingModule.exportsAll[name])}" and "${relativeId(additionalExportAllModule.exportsAll[name])}" (will be ignored)`,
387
+ message: `Conflicting namespaces: "${relativeId(reexportingModuleId)}" re-exports "${name}" from one of the modules ${printQuotedStringList(sources.map(moduleId => relativeId(moduleId)))} (will be ignored)`,
388
388
  name,
389
- reexporter: reexportingModule.id,
390
- sources: [reexportingModule.exportsAll[name], additionalExportAllModule.exportsAll[name]]
389
+ reexporter: reexportingModuleId,
390
+ sources
391
391
  };
392
392
  }
393
- function errAmbiguousExternalNamespaces(name, reexportingModule, usedExternalModule, externalModules) {
393
+ function errAmbiguousExternalNamespaces(name, reexportingModule, usedModule, sources) {
394
394
  return {
395
395
  code: Errors.AMBIGUOUS_EXTERNAL_NAMESPACES,
396
- message: `Ambiguous external namespace resolution: "${relativeId(reexportingModule)}" re-exports "${name}" from one of the external modules ${printQuotedStringList(externalModules.map(module => relativeId(module)))}, guessing "${relativeId(usedExternalModule)}".`,
396
+ message: `Ambiguous external namespace resolution: "${relativeId(reexportingModule)}" re-exports "${name}" from one of the external modules ${printQuotedStringList(sources.map(module => relativeId(module)))}, guessing "${relativeId(usedModule)}".`,
397
397
  name,
398
398
  reexporter: reexportingModule,
399
- sources: externalModules
399
+ sources
400
400
  };
401
401
  }
402
402
  function errNoTransformMapOrAstWithoutCode(pluginName) {
@@ -420,7 +420,7 @@ function errSyntheticNamedExportsNeedNamespaceExport(id, syntheticNamedExportsOp
420
420
  code: Errors.SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT,
421
421
  id,
422
422
  message: `Module "${relativeId(id)}" that is marked with 'syntheticNamedExports: ${JSON.stringify(syntheticNamedExportsOption)}' needs ${typeof syntheticNamedExportsOption === 'string' && syntheticNamedExportsOption !== 'default'
423
- ? `an export named "${syntheticNamedExportsOption}"`
423
+ ? `an explicit export named "${syntheticNamedExportsOption}"`
424
424
  : 'a default export'} that does not reexport an unresolved named export of the same module.`
425
425
  };
426
426
  }
@@ -2322,7 +2322,7 @@ function makeLegal(str) {
2322
2322
  }
2323
2323
 
2324
2324
  class ExternalModule {
2325
- constructor(options, id, hasModuleSideEffects, meta, renormalizeRenderPath) {
2325
+ constructor(options, id, moduleSideEffects, meta, renormalizeRenderPath) {
2326
2326
  this.options = options;
2327
2327
  this.id = id;
2328
2328
  this.renormalizeRenderPath = renormalizeRenderPath;
@@ -2341,7 +2341,7 @@ class ExternalModule {
2341
2341
  this.variableName = '';
2342
2342
  this.suggestedVariableName = makeLegal(id.split(/[\\/]/).pop());
2343
2343
  const { importers, dynamicImporters } = this;
2344
- this.info = {
2344
+ const info = (this.info = {
2345
2345
  ast: null,
2346
2346
  code: null,
2347
2347
  dynamicallyImportedIdResolutions: EMPTY_ARRAY,
@@ -2349,7 +2349,11 @@ class ExternalModule {
2349
2349
  get dynamicImporters() {
2350
2350
  return dynamicImporters.sort();
2351
2351
  },
2352
- hasModuleSideEffects,
2352
+ hasDefaultExport: null,
2353
+ get hasModuleSideEffects() {
2354
+ warnDeprecation('Accessing ModuleInfo.hasModuleSideEffects from plugins is deprecated. Please use ModuleInfo.moduleSideEffects instead.', false, options);
2355
+ return info.moduleSideEffects;
2356
+ },
2353
2357
  id,
2354
2358
  implicitlyLoadedAfterOneOf: EMPTY_ARRAY,
2355
2359
  implicitlyLoadedBefore: EMPTY_ARRAY,
@@ -2362,16 +2366,22 @@ class ExternalModule {
2362
2366
  isExternal: true,
2363
2367
  isIncluded: null,
2364
2368
  meta,
2369
+ moduleSideEffects,
2365
2370
  syntheticNamedExports: false
2366
- };
2371
+ });
2372
+ // Hide the deprecated key so that it only warns when accessed explicitly
2373
+ Object.defineProperty(this.info, 'hasModuleSideEffects', {
2374
+ ...Object.getOwnPropertyDescriptor(this.info, 'hasModuleSideEffects'),
2375
+ enumerable: false
2376
+ });
2367
2377
  }
2368
2378
  getVariableForExportName(name) {
2369
2379
  let declaration = this.declarations[name];
2370
2380
  if (declaration)
2371
- return declaration;
2381
+ return [declaration];
2372
2382
  this.declarations[name] = declaration = new ExternalVariable(this, name);
2373
2383
  this.exportedVariables.set(declaration, name);
2374
- return declaration;
2384
+ return [declaration];
2375
2385
  }
2376
2386
  setRenderPath(options, inputBase) {
2377
2387
  this.renderPath =
@@ -4905,15 +4915,6 @@ exports.SOURCEMAPPING_URL += 'ppingURL';
4905
4915
  const whiteSpaceNoNewline = '[ \\f\\r\\t\\v\\u00a0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000\\ufeff]';
4906
4916
  const SOURCEMAPPING_URL_RE = new RegExp(`^#${whiteSpaceNoNewline}+${exports.SOURCEMAPPING_URL}=.+`);
4907
4917
 
4908
- // patch up acorn-walk until class-fields are officially supported
4909
- base$1.PropertyDefinition = function (node, st, c) {
4910
- if (node.computed) {
4911
- c(node.key, st, 'Expression');
4912
- }
4913
- if (node.value) {
4914
- c(node.value, st, 'Expression');
4915
- }
4916
- };
4917
4918
  const ANNOTATION_KEY = '_rollupAnnotations';
4918
4919
  const INVALID_COMMENT_KEY = '_rollupRemoved';
4919
4920
  function handlePureAnnotationsOfNode(node, state, type = node.type) {
@@ -8642,6 +8643,8 @@ const ARRAY_PROTOTYPE = new ObjectEntity({
8642
8643
  flat: METHOD_DEOPTS_SELF_RETURNS_NEW_ARRAY,
8643
8644
  flatMap: METHOD_CALLS_ARG_DEOPTS_SELF_RETURNS_NEW_ARRAY,
8644
8645
  forEach: METHOD_CALLS_ARG_DEOPTS_SELF_RETURNS_UNKNOWN,
8646
+ groupBy: METHOD_CALLS_ARG_DEOPTS_SELF_RETURNS_UNKNOWN,
8647
+ groupByToMap: METHOD_CALLS_ARG_DEOPTS_SELF_RETURNS_UNKNOWN,
8645
8648
  includes: METHOD_RETURNS_BOOLEAN,
8646
8649
  indexOf: METHOD_RETURNS_NUMBER,
8647
8650
  join: METHOD_RETURNS_STRING,
@@ -12252,7 +12255,7 @@ function markModuleAndImpureDependenciesAsExecuted(baseModule) {
12252
12255
  for (const dependency of [...module.dependencies, ...module.implicitlyLoadedBefore]) {
12253
12256
  if (!(dependency instanceof ExternalModule) &&
12254
12257
  !dependency.isExecuted &&
12255
- (dependency.info.hasModuleSideEffects || module.implicitlyLoadedBefore.has(dependency)) &&
12258
+ (dependency.info.moduleSideEffects || module.implicitlyLoadedBefore.has(dependency)) &&
12256
12259
  !visitedModules.has(dependency.id)) {
12257
12260
  dependency.isExecuted = true;
12258
12261
  visitedModules.add(dependency.id);
@@ -12266,11 +12269,11 @@ const MISSING_EXPORT_SHIM_DESCRIPTION = {
12266
12269
  identifier: null,
12267
12270
  localName: MISSING_EXPORT_SHIM_VARIABLE
12268
12271
  };
12269
- function getVariableForExportNameRecursive(target, name, importerForSideEffects, isExportAllSearch, searchedNamesAndModules = new Map(), skipExternalNamespaceReexports) {
12272
+ function getVariableForExportNameRecursive(target, name, importerForSideEffects, isExportAllSearch, searchedNamesAndModules = new Map()) {
12270
12273
  const searchedModules = searchedNamesAndModules.get(name);
12271
12274
  if (searchedModules) {
12272
12275
  if (searchedModules.has(target)) {
12273
- return isExportAllSearch ? null : error(errCircularReexport(name, target.id));
12276
+ return isExportAllSearch ? [null] : error(errCircularReexport(name, target.id));
12274
12277
  }
12275
12278
  searchedModules.add(target);
12276
12279
  }
@@ -12280,8 +12283,7 @@ function getVariableForExportNameRecursive(target, name, importerForSideEffects,
12280
12283
  return target.getVariableForExportName(name, {
12281
12284
  importerForSideEffects,
12282
12285
  isExportAllSearch,
12283
- searchedNamesAndModules,
12284
- skipExternalNamespaceReexports
12286
+ searchedNamesAndModules
12285
12287
  });
12286
12288
  }
12287
12289
  function getAndExtendSideEffectModules(variable, module) {
@@ -12311,14 +12313,14 @@ function getAndExtendSideEffectModules(variable, module) {
12311
12313
  return sideEffectModules;
12312
12314
  }
12313
12315
  class Module {
12314
- constructor(graph, id, options, isEntry, hasModuleSideEffects, syntheticNamedExports, meta) {
12316
+ constructor(graph, id, options, isEntry, moduleSideEffects, syntheticNamedExports, meta) {
12315
12317
  this.graph = graph;
12316
12318
  this.id = id;
12317
12319
  this.options = options;
12318
12320
  this.alternativeReexportModules = new Map();
12319
12321
  this.ast = null;
12320
12322
  this.chunkFileNames = new Set();
12321
- this.chunkName = null;
12323
+ this.chunkNames = [];
12322
12324
  this.cycles = new Set();
12323
12325
  this.dependencies = new Set();
12324
12326
  this.dynamicDependencies = new Set();
@@ -12327,7 +12329,6 @@ class Module {
12327
12329
  this.execIndex = Infinity;
12328
12330
  this.exportAllSources = new Set();
12329
12331
  this.exports = Object.create(null);
12330
- this.exportsAll = Object.create(null);
12331
12332
  this.implicitlyLoadedAfter = new Set();
12332
12333
  this.implicitlyLoadedBefore = new Set();
12333
12334
  this.importDescriptions = Object.create(null);
@@ -12342,7 +12343,6 @@ class Module {
12342
12343
  this.reexportDescriptions = Object.create(null);
12343
12344
  this.sideEffectDependenciesByVariable = new Map();
12344
12345
  this.sources = new Set();
12345
- this.userChunkNames = new Set();
12346
12346
  this.usesTopLevelAwait = false;
12347
12347
  this.allExportNames = null;
12348
12348
  this.exportAllModules = [];
@@ -12359,17 +12359,18 @@ class Module {
12359
12359
  this.preserveSignature = this.options.preserveEntrySignatures;
12360
12360
  // eslint-disable-next-line @typescript-eslint/no-this-alias
12361
12361
  const module = this;
12362
+ const { dynamicImports, dynamicImporters, reexportDescriptions, implicitlyLoadedAfter, implicitlyLoadedBefore, sources, importers } = this;
12362
12363
  this.info = {
12363
12364
  ast: null,
12364
12365
  code: null,
12365
12366
  get dynamicallyImportedIdResolutions() {
12366
- return module.dynamicImports
12367
+ return dynamicImports
12367
12368
  .map(({ argument }) => typeof argument === 'string' && module.resolvedIds[argument])
12368
12369
  .filter(Boolean);
12369
12370
  },
12370
12371
  get dynamicallyImportedIds() {
12371
12372
  const dynamicallyImportedIds = [];
12372
- for (const { id } of module.dynamicImports) {
12373
+ for (const { id } of dynamicImports) {
12373
12374
  if (id) {
12374
12375
  dynamicallyImportedIds.push(id);
12375
12376
  }
@@ -12377,36 +12378,52 @@ class Module {
12377
12378
  return dynamicallyImportedIds;
12378
12379
  },
12379
12380
  get dynamicImporters() {
12380
- return module.dynamicImporters.sort();
12381
+ return dynamicImporters.sort();
12382
+ },
12383
+ get hasDefaultExport() {
12384
+ // This information is only valid after parsing
12385
+ if (!module.ast) {
12386
+ return null;
12387
+ }
12388
+ return 'default' in module.exports || 'default' in reexportDescriptions;
12389
+ },
12390
+ get hasModuleSideEffects() {
12391
+ warnDeprecation('Accessing ModuleInfo.hasModuleSideEffects from plugins is deprecated. Please use ModuleInfo.moduleSideEffects instead.', false, options);
12392
+ return module.info.moduleSideEffects;
12381
12393
  },
12382
- hasModuleSideEffects,
12383
12394
  id,
12384
12395
  get implicitlyLoadedAfterOneOf() {
12385
- return Array.from(module.implicitlyLoadedAfter, getId).sort();
12396
+ return Array.from(implicitlyLoadedAfter, getId).sort();
12386
12397
  },
12387
12398
  get implicitlyLoadedBefore() {
12388
- return Array.from(module.implicitlyLoadedBefore, getId).sort();
12399
+ return Array.from(implicitlyLoadedBefore, getId).sort();
12389
12400
  },
12390
12401
  get importedIdResolutions() {
12391
- return Array.from(module.sources, source => module.resolvedIds[source]).filter(Boolean);
12402
+ return Array.from(sources, source => module.resolvedIds[source]).filter(Boolean);
12392
12403
  },
12393
12404
  get importedIds() {
12394
- return Array.from(module.sources, source => { var _a; return (_a = module.resolvedIds[source]) === null || _a === void 0 ? void 0 : _a.id; }).filter(Boolean);
12405
+ return Array.from(sources, source => { var _a; return (_a = module.resolvedIds[source]) === null || _a === void 0 ? void 0 : _a.id; }).filter(Boolean);
12395
12406
  },
12396
12407
  get importers() {
12397
- return module.importers.sort();
12408
+ return importers.sort();
12398
12409
  },
12399
12410
  isEntry,
12400
12411
  isExternal: false,
12401
12412
  get isIncluded() {
12402
- if (module.graph.phase !== BuildPhase.GENERATE) {
12413
+ if (graph.phase !== BuildPhase.GENERATE) {
12403
12414
  return null;
12404
12415
  }
12405
12416
  return module.isIncluded();
12406
12417
  },
12407
12418
  meta: { ...meta },
12419
+ moduleSideEffects,
12408
12420
  syntheticNamedExports
12409
12421
  };
12422
+ // Hide the deprecated key so that it only warns when accessed explicitly
12423
+ Object.defineProperty(this.info, 'hasModuleSideEffects', {
12424
+ ...Object.getOwnPropertyDescriptor(this.info, 'hasModuleSideEffects'),
12425
+ enumerable: false
12426
+ });
12410
12427
  }
12411
12428
  basename() {
12412
12429
  const base = require$$0.basename(this.id);
@@ -12441,6 +12458,11 @@ class Module {
12441
12458
  allExportNames.add(name);
12442
12459
  }
12443
12460
  }
12461
+ // We do not count the synthetic namespace as a regular export to hide it
12462
+ // from entry signatures and namespace objects
12463
+ if (typeof this.info.syntheticNamedExports === 'string') {
12464
+ allExportNames.delete(this.info.syntheticNamedExports);
12465
+ }
12444
12466
  return allExportNames;
12445
12467
  }
12446
12468
  getDependenciesToBeIncluded() {
@@ -12455,7 +12477,7 @@ class Module {
12455
12477
  this.namespace.included ||
12456
12478
  this.implicitlyLoadedAfter.size > 0) {
12457
12479
  for (const exportName of [...this.getReexports(), ...this.getExports()]) {
12458
- const exportedVariable = this.getVariableForExportName(exportName);
12480
+ const [exportedVariable] = this.getVariableForExportName(exportName);
12459
12481
  if (exportedVariable) {
12460
12482
  dependencyVariables.add(exportedVariable);
12461
12483
  }
@@ -12476,7 +12498,7 @@ class Module {
12476
12498
  }
12477
12499
  necessaryDependencies.add(variable.module);
12478
12500
  }
12479
- if (!this.options.treeshake || this.info.hasModuleSideEffects === 'no-treeshake') {
12501
+ if (!this.options.treeshake || this.info.moduleSideEffects === 'no-treeshake') {
12480
12502
  for (const dependency of this.dependencies) {
12481
12503
  relevantDependencies.add(dependency);
12482
12504
  }
@@ -12495,9 +12517,7 @@ class Module {
12495
12517
  }
12496
12518
  const exportNamesByVariable = new Map();
12497
12519
  for (const exportName of this.getAllExportNames()) {
12498
- if (exportName === this.info.syntheticNamedExports)
12499
- continue;
12500
- let tracedVariable = this.getVariableForExportName(exportName);
12520
+ let [tracedVariable] = this.getVariableForExportName(exportName);
12501
12521
  if (tracedVariable instanceof ExportDefaultVariable) {
12502
12522
  tracedVariable = tracedVariable.getOriginalVariable();
12503
12523
  }
@@ -12546,7 +12566,7 @@ class Module {
12546
12566
  const renderedExports = [];
12547
12567
  const removedExports = [];
12548
12568
  for (const exportName in this.exports) {
12549
- const variable = this.getVariableForExportName(exportName);
12569
+ const [variable] = this.getVariableForExportName(exportName);
12550
12570
  (variable && variable.included ? renderedExports : removedExports).push(exportName);
12551
12571
  }
12552
12572
  return { removedExports, renderedExports };
@@ -12554,20 +12574,20 @@ class Module {
12554
12574
  getSyntheticNamespace() {
12555
12575
  if (this.syntheticNamespace === null) {
12556
12576
  this.syntheticNamespace = undefined;
12557
- this.syntheticNamespace = this.getVariableForExportName(typeof this.info.syntheticNamedExports === 'string'
12577
+ [this.syntheticNamespace] = this.getVariableForExportName(typeof this.info.syntheticNamedExports === 'string'
12558
12578
  ? this.info.syntheticNamedExports
12559
- : 'default');
12579
+ : 'default', { onlyExplicit: true });
12560
12580
  }
12561
12581
  if (!this.syntheticNamespace) {
12562
12582
  return error(errSyntheticNamedExportsNeedNamespaceExport(this.id, this.info.syntheticNamedExports));
12563
12583
  }
12564
12584
  return this.syntheticNamespace;
12565
12585
  }
12566
- getVariableForExportName(name, { importerForSideEffects, isExportAllSearch, searchedNamesAndModules, skipExternalNamespaceReexports } = EMPTY_OBJECT) {
12586
+ getVariableForExportName(name, { importerForSideEffects, isExportAllSearch, onlyExplicit, searchedNamesAndModules } = EMPTY_OBJECT) {
12567
12587
  if (name[0] === '*') {
12568
12588
  if (name.length === 1) {
12569
12589
  // export * from './other'
12570
- return this.namespace;
12590
+ return [this.namespace];
12571
12591
  }
12572
12592
  else {
12573
12593
  // export * from 'external'
@@ -12578,19 +12598,19 @@ class Module {
12578
12598
  // export { foo } from './other'
12579
12599
  const reexportDeclaration = this.reexportDescriptions[name];
12580
12600
  if (reexportDeclaration) {
12581
- const variable = getVariableForExportNameRecursive(reexportDeclaration.module, reexportDeclaration.localName, importerForSideEffects, false, searchedNamesAndModules, false);
12601
+ const [variable] = getVariableForExportNameRecursive(reexportDeclaration.module, reexportDeclaration.localName, importerForSideEffects, false, searchedNamesAndModules);
12582
12602
  if (!variable) {
12583
12603
  return this.error(errMissingExport(reexportDeclaration.localName, this.id, reexportDeclaration.module.id), reexportDeclaration.start);
12584
12604
  }
12585
12605
  if (importerForSideEffects) {
12586
12606
  setAlternativeExporterIfCyclic(variable, importerForSideEffects, this);
12587
12607
  }
12588
- return variable;
12608
+ return [variable];
12589
12609
  }
12590
12610
  const exportDeclaration = this.exports[name];
12591
12611
  if (exportDeclaration) {
12592
12612
  if (exportDeclaration === MISSING_EXPORT_SHIM_DESCRIPTION) {
12593
- return this.exportShimVariable;
12613
+ return [this.exportShimVariable];
12594
12614
  }
12595
12615
  const name = exportDeclaration.localName;
12596
12616
  const variable = this.traceVariable(name, importerForSideEffects);
@@ -12598,41 +12618,37 @@ class Module {
12598
12618
  getOrCreate(importerForSideEffects.sideEffectDependenciesByVariable, variable, () => new Set()).add(this);
12599
12619
  setAlternativeExporterIfCyclic(variable, importerForSideEffects, this);
12600
12620
  }
12601
- return variable;
12621
+ return [variable];
12622
+ }
12623
+ if (onlyExplicit) {
12624
+ return [null];
12602
12625
  }
12603
12626
  if (name !== 'default') {
12604
12627
  const foundNamespaceReexport = name in this.namespaceReexportsByName
12605
12628
  ? this.namespaceReexportsByName[name]
12606
- : this.getVariableFromNamespaceReexports(name, importerForSideEffects, searchedNamesAndModules, skipExternalNamespaceReexports);
12607
- if (!skipExternalNamespaceReexports) {
12608
- this.namespaceReexportsByName[name] = foundNamespaceReexport;
12609
- }
12610
- if (foundNamespaceReexport) {
12629
+ : this.getVariableFromNamespaceReexports(name, importerForSideEffects, searchedNamesAndModules);
12630
+ this.namespaceReexportsByName[name] = foundNamespaceReexport;
12631
+ if (foundNamespaceReexport[0]) {
12611
12632
  return foundNamespaceReexport;
12612
12633
  }
12613
12634
  }
12614
12635
  if (this.info.syntheticNamedExports) {
12615
- let syntheticExport = this.syntheticExports.get(name);
12616
- if (!syntheticExport) {
12617
- const syntheticNamespace = this.getSyntheticNamespace();
12618
- syntheticExport = new SyntheticNamedExportVariable(this.astContext, name, syntheticNamespace);
12619
- this.syntheticExports.set(name, syntheticExport);
12620
- return syntheticExport;
12621
- }
12622
- return syntheticExport;
12636
+ return [
12637
+ getOrCreate(this.syntheticExports, name, () => new SyntheticNamedExportVariable(this.astContext, name, this.getSyntheticNamespace()))
12638
+ ];
12623
12639
  }
12624
12640
  // we don't want to create shims when we are just
12625
12641
  // probing export * modules for exports
12626
12642
  if (!isExportAllSearch) {
12627
12643
  if (this.options.shimMissingExports) {
12628
12644
  this.shimMissingExport(name);
12629
- return this.exportShimVariable;
12645
+ return [this.exportShimVariable];
12630
12646
  }
12631
12647
  }
12632
- return null;
12648
+ return [null];
12633
12649
  }
12634
12650
  hasEffects() {
12635
- return (this.info.hasModuleSideEffects === 'no-treeshake' ||
12651
+ return (this.info.moduleSideEffects === 'no-treeshake' ||
12636
12652
  (this.ast.included && this.ast.hasEffects(createHasEffectsContext())));
12637
12653
  }
12638
12654
  include() {
@@ -12647,7 +12663,7 @@ class Module {
12647
12663
  }
12648
12664
  for (const exportName of this.getExports()) {
12649
12665
  if (includeNamespaceMembers || exportName !== this.info.syntheticNamedExports) {
12650
- const variable = this.getVariableForExportName(exportName);
12666
+ const variable = this.getVariableForExportName(exportName)[0];
12651
12667
  variable.deoptimizePath(UNKNOWN_PATH);
12652
12668
  if (!variable.included) {
12653
12669
  this.includeVariable(variable);
@@ -12655,7 +12671,7 @@ class Module {
12655
12671
  }
12656
12672
  }
12657
12673
  for (const name of this.getReexports()) {
12658
- const variable = this.getVariableForExportName(name);
12674
+ const [variable] = this.getVariableForExportName(name);
12659
12675
  if (variable) {
12660
12676
  variable.deoptimizePath(UNKNOWN_PATH);
12661
12677
  if (!variable.included) {
@@ -12680,11 +12696,6 @@ class Module {
12680
12696
  linkImports() {
12681
12697
  this.addModulesToImportDescriptions(this.importDescriptions);
12682
12698
  this.addModulesToImportDescriptions(this.reexportDescriptions);
12683
- for (const name in this.exports) {
12684
- if (name !== 'default' && name !== this.info.syntheticNamedExports) {
12685
- this.exportsAll[name] = this.id;
12686
- }
12687
- }
12688
12699
  const externalExportAllModules = [];
12689
12700
  for (const source of this.exportAllSources) {
12690
12701
  const module = this.graph.modulesById.get(this.resolvedIds[source].id);
@@ -12693,14 +12704,6 @@ class Module {
12693
12704
  continue;
12694
12705
  }
12695
12706
  this.exportAllModules.push(module);
12696
- for (const name in module.exportsAll) {
12697
- if (name in this.exportsAll) {
12698
- this.options.onwarn(errNamespaceConflict(name, this, module));
12699
- }
12700
- else {
12701
- this.exportsAll[name] = module.exportsAll[name];
12702
- }
12703
- }
12704
12707
  }
12705
12708
  this.exportAllModules.push(...externalExportAllModules);
12706
12709
  }
@@ -12758,7 +12761,7 @@ class Module {
12758
12761
  moduleContext: this.context,
12759
12762
  options: this.options,
12760
12763
  requestTreeshakingPass: () => (this.graph.needsTreeshakingPass = true),
12761
- traceExport: this.getVariableForExportName.bind(this),
12764
+ traceExport: (name) => this.getVariableForExportName(name)[0],
12762
12765
  traceVariable: this.traceVariable.bind(this),
12763
12766
  usesTopLevelAwait: false,
12764
12767
  warn: this.warn.bind(this)
@@ -12777,7 +12780,7 @@ class Module {
12777
12780
  dependencies: Array.from(this.dependencies, getId),
12778
12781
  id: this.id,
12779
12782
  meta: this.info.meta,
12780
- moduleSideEffects: this.info.hasModuleSideEffects,
12783
+ moduleSideEffects: this.info.moduleSideEffects,
12781
12784
  originalCode: this.originalCode,
12782
12785
  originalSourcemap: this.originalSourcemap,
12783
12786
  resolvedIds: this.resolvedIds,
@@ -12798,7 +12801,7 @@ class Module {
12798
12801
  if (otherModule instanceof Module && importDeclaration.name === '*') {
12799
12802
  return otherModule.namespace;
12800
12803
  }
12801
- const declaration = otherModule.getVariableForExportName(importDeclaration.name, {
12804
+ const [declaration] = otherModule.getVariableForExportName(importDeclaration.name, {
12802
12805
  importerForSideEffects: importerForSideEffects || this
12803
12806
  });
12804
12807
  if (!declaration) {
@@ -12829,7 +12832,7 @@ class Module {
12829
12832
  }
12830
12833
  updateOptions({ meta, moduleSideEffects, syntheticNamedExports }) {
12831
12834
  if (moduleSideEffects != null) {
12832
- this.info.hasModuleSideEffects = moduleSideEffects;
12835
+ this.info.moduleSideEffects = moduleSideEffects;
12833
12836
  }
12834
12837
  if (syntheticNamedExports != null) {
12835
12838
  this.info.syntheticNamedExports = syntheticNamedExports;
@@ -12983,7 +12986,7 @@ class Module {
12983
12986
  relevantDependencies.add(dependency);
12984
12987
  continue;
12985
12988
  }
12986
- if (!(dependency.info.hasModuleSideEffects || alwaysCheckedDependencies.has(dependency))) {
12989
+ if (!(dependency.info.moduleSideEffects || alwaysCheckedDependencies.has(dependency))) {
12987
12990
  continue;
12988
12991
  }
12989
12992
  if (dependency instanceof ExternalModule || dependency.hasEffects()) {
@@ -12996,58 +12999,57 @@ class Module {
12996
12999
  addSideEffectDependencies(this.dependencies);
12997
13000
  addSideEffectDependencies(alwaysCheckedDependencies);
12998
13001
  }
12999
- getVariableFromNamespaceReexports(name, importerForSideEffects, searchedNamesAndModules, skipExternalNamespaceReexports = false) {
13002
+ getVariableFromNamespaceReexports(name, importerForSideEffects, searchedNamesAndModules) {
13000
13003
  let foundSyntheticDeclaration = null;
13001
- const skipExternalNamespaceValues = [{ searchedNamesAndModules, skipExternalNamespaces: true }];
13002
- if (!skipExternalNamespaceReexports) {
13003
- const clonedSearchedNamesAndModules = new Map();
13004
- for (const [name, modules] of searchedNamesAndModules || []) {
13005
- clonedSearchedNamesAndModules.set(name, new Set(modules));
13006
- }
13007
- skipExternalNamespaceValues.push({
13008
- searchedNamesAndModules: clonedSearchedNamesAndModules,
13009
- skipExternalNamespaces: false
13010
- });
13011
- }
13012
- for (const { skipExternalNamespaces, searchedNamesAndModules } of skipExternalNamespaceValues) {
13013
- const foundDeclarations = new Set();
13014
- for (const module of this.exportAllModules) {
13015
- if (module instanceof Module || !skipExternalNamespaces) {
13016
- const declaration = getVariableForExportNameRecursive(module, name, importerForSideEffects, true, searchedNamesAndModules, skipExternalNamespaces);
13017
- if (declaration) {
13018
- if (!(declaration instanceof SyntheticNamedExportVariable)) {
13019
- foundDeclarations.add(declaration);
13020
- }
13021
- else if (!foundSyntheticDeclaration) {
13022
- foundSyntheticDeclaration = declaration;
13023
- }
13024
- }
13025
- }
13004
+ const foundInternalDeclarations = new Map();
13005
+ const foundExternalDeclarations = new Set();
13006
+ for (const module of this.exportAllModules) {
13007
+ // Synthetic namespaces should not hide "regular" exports of the same name
13008
+ if (module.info.syntheticNamedExports === name) {
13009
+ continue;
13026
13010
  }
13027
- if (foundDeclarations.size === 1) {
13028
- return [...foundDeclarations][0];
13011
+ const [variable, indirectExternal] = getVariableForExportNameRecursive(module, name, importerForSideEffects, true, searchedNamesAndModules);
13012
+ if (module instanceof ExternalModule || indirectExternal) {
13013
+ foundExternalDeclarations.add(variable);
13029
13014
  }
13030
- if (foundDeclarations.size > 1) {
13031
- if (skipExternalNamespaces) {
13032
- return null;
13015
+ else if (variable instanceof SyntheticNamedExportVariable) {
13016
+ if (!foundSyntheticDeclaration) {
13017
+ foundSyntheticDeclaration = variable;
13033
13018
  }
13034
- const foundDeclarationList = [...foundDeclarations];
13035
- const usedDeclaration = foundDeclarationList[0];
13019
+ }
13020
+ else if (variable) {
13021
+ foundInternalDeclarations.set(variable, module);
13022
+ }
13023
+ }
13024
+ if (foundInternalDeclarations.size > 0) {
13025
+ const foundDeclarationList = [...foundInternalDeclarations];
13026
+ const usedDeclaration = foundDeclarationList[0][0];
13027
+ if (foundDeclarationList.length === 1) {
13028
+ return [usedDeclaration];
13029
+ }
13030
+ this.options.onwarn(errNamespaceConflict(name, this.id, foundDeclarationList.map(([, module]) => module.id)));
13031
+ // TODO we are pretending it was not found while it should behave like "undefined"
13032
+ return [null];
13033
+ }
13034
+ if (foundExternalDeclarations.size > 0) {
13035
+ const foundDeclarationList = [...foundExternalDeclarations];
13036
+ const usedDeclaration = foundDeclarationList[0];
13037
+ if (foundDeclarationList.length > 1) {
13036
13038
  this.options.onwarn(errAmbiguousExternalNamespaces(name, this.id, usedDeclaration.module.id, foundDeclarationList.map(declaration => declaration.module.id)));
13037
- return usedDeclaration;
13038
13039
  }
13040
+ return [usedDeclaration, true];
13039
13041
  }
13040
13042
  if (foundSyntheticDeclaration) {
13041
- return foundSyntheticDeclaration;
13043
+ return [foundSyntheticDeclaration];
13042
13044
  }
13043
- return null;
13045
+ return [null];
13044
13046
  }
13045
13047
  includeAndGetAdditionalMergedNamespaces() {
13046
13048
  const externalNamespaces = new Set();
13047
13049
  const syntheticNamespaces = new Set();
13048
13050
  for (const module of [this, ...this.exportAllModules]) {
13049
13051
  if (module instanceof ExternalModule) {
13050
- const externalVariable = module.getVariableForExportName('*');
13052
+ const [externalVariable] = module.getVariableForExportName('*');
13051
13053
  externalVariable.include();
13052
13054
  this.imports.add(externalVariable);
13053
13055
  externalNamespaces.add(externalVariable);
@@ -13128,12 +13130,10 @@ function removeJsExtension(name) {
13128
13130
  }
13129
13131
 
13130
13132
  function getCompleteAmdId(options, chunkId) {
13131
- if (!options.autoId) {
13132
- return options.id || '';
13133
- }
13134
- else {
13133
+ if (options.autoId) {
13135
13134
  return `${options.basePath ? options.basePath + '/' : ''}${removeJsExtension(chunkId)}`;
13136
13135
  }
13136
+ return options.id || '';
13137
13137
  }
13138
13138
 
13139
13139
  function getExportBlock$1(exports, dependencies, namedExportsMode, interop, snippets, t, externalLiveBindings, mechanism = 'return ') {
@@ -14035,10 +14035,8 @@ function collapseSourcemaps(file, map, modules, bundleSourcemapChain, excludeCon
14035
14035
  const moduleSources = modules
14036
14036
  .filter(module => !module.excludeFromSourcemap)
14037
14037
  .map(module => getCollapsedSourcemap(module.id, module.originalCode, module.originalSourcemap, module.sourcemapChain, linkMap));
14038
- // DecodedSourceMap (from magic-string) uses a number[] instead of the more
14039
- // correct SourceMapSegment tuples. Cast it here to gain type safety.
14040
- let source = new Link(map, moduleSources);
14041
- source = bundleSourcemapChain.reduce(linkMap, source);
14038
+ const link = new Link(map, moduleSources);
14039
+ const source = bundleSourcemapChain.reduce(linkMap, link);
14042
14040
  let { sources, sourcesContent, names, mappings } = source.traceMappings();
14043
14041
  if (file) {
14044
14042
  const directory = require$$0.dirname(file);
@@ -14190,7 +14188,7 @@ function assignExportsToMangledNames(exports, exportsByName, exportNamesByVariab
14190
14188
  let nameIndex = 0;
14191
14189
  for (const variable of exports) {
14192
14190
  let [exportName] = variable.name;
14193
- if (exportsByName[exportName]) {
14191
+ if (exportsByName.has(exportName)) {
14194
14192
  do {
14195
14193
  exportName = toBase64(++nameIndex);
14196
14194
  // skip past leading number identifiers
@@ -14198,9 +14196,9 @@ function assignExportsToMangledNames(exports, exportsByName, exportNamesByVariab
14198
14196
  nameIndex += 9 * 64 ** (exportName.length - 1);
14199
14197
  exportName = toBase64(nameIndex);
14200
14198
  }
14201
- } while (RESERVED_NAMES$1.has(exportName) || exportsByName[exportName]);
14199
+ } while (RESERVED_NAMES$1.has(exportName) || exportsByName.has(exportName));
14202
14200
  }
14203
- exportsByName[exportName] = variable;
14201
+ exportsByName.set(exportName, variable);
14204
14202
  exportNamesByVariable.set(variable, [exportName]);
14205
14203
  }
14206
14204
  }
@@ -14208,10 +14206,10 @@ function assignExportsToNames(exports, exportsByName, exportNamesByVariable) {
14208
14206
  for (const variable of exports) {
14209
14207
  let nameIndex = 0;
14210
14208
  let exportName = variable.name;
14211
- while (exportsByName[exportName]) {
14209
+ while (exportsByName.has(exportName)) {
14212
14210
  exportName = variable.name + '$' + ++nameIndex;
14213
14211
  }
14214
- exportsByName[exportName] = variable;
14212
+ exportsByName.set(exportName, variable);
14215
14213
  exportNamesByVariable.set(variable, [exportName]);
14216
14214
  }
14217
14215
  }
@@ -14329,13 +14327,7 @@ function decodedSourcemap(map) {
14329
14327
  version: 3
14330
14328
  };
14331
14329
  }
14332
- let mappings;
14333
- if (typeof map.mappings === 'string') {
14334
- mappings = decode(map.mappings);
14335
- }
14336
- else {
14337
- mappings = map.mappings;
14338
- }
14330
+ const mappings = typeof map.mappings === 'string' ? decode(map.mappings) : map.mappings;
14339
14331
  return { ...map, mappings };
14340
14332
  }
14341
14333
 
@@ -14425,7 +14417,7 @@ class Chunk {
14425
14417
  this.dynamicName = null;
14426
14418
  this.exportNamesByVariable = new Map();
14427
14419
  this.exports = new Set();
14428
- this.exportsByName = Object.create(null);
14420
+ this.exportsByName = new Map();
14429
14421
  this.fileName = null;
14430
14422
  this.implicitEntryModules = [];
14431
14423
  this.implicitlyLoadedBefore = new Set();
@@ -14481,7 +14473,7 @@ class Chunk {
14481
14473
  chunk.dependencies.add(dependency instanceof Module ? chunkByModule.get(dependency) : dependency);
14482
14474
  }
14483
14475
  if (!chunk.dependencies.has(chunkByModule.get(facadedModule)) &&
14484
- facadedModule.info.hasModuleSideEffects &&
14476
+ facadedModule.info.moduleSideEffects &&
14485
14477
  facadedModule.hasEffects()) {
14486
14478
  chunk.dependencies.add(chunkByModule.get(facadedModule));
14487
14479
  }
@@ -14524,7 +14516,7 @@ class Chunk {
14524
14516
  for (const [variable, exportNames] of exportNamesByVariable) {
14525
14517
  this.exportNamesByVariable.set(variable, [...exportNames]);
14526
14518
  for (const exportName of exportNames) {
14527
- this.exportsByName[exportName] = variable;
14519
+ this.exportsByName.set(exportName, variable);
14528
14520
  }
14529
14521
  remainingExports.delete(variable);
14530
14522
  }
@@ -14551,7 +14543,7 @@ class Chunk {
14551
14543
  }
14552
14544
  }
14553
14545
  for (const module of entryModules) {
14554
- const requiredFacades = Array.from(module.userChunkNames, name => ({
14546
+ const requiredFacades = Array.from(new Set(module.chunkNames.filter(({ isUserDefined }) => isUserDefined).map(({ name }) => name)), name => ({
14555
14547
  name
14556
14548
  }));
14557
14549
  if (requiredFacades.length === 0 && module.isUserDefinedEntryPoint) {
@@ -14618,15 +14610,15 @@ class Chunk {
14618
14610
  }
14619
14611
  generateIdPreserveModules(preserveModulesRelativeDir, options, existingNames, unsetOptions) {
14620
14612
  const [{ id }] = this.orderedModules;
14621
- const sanitizedId = this.outputOptions.sanitizeFileName(id);
14613
+ const sanitizedId = this.outputOptions.sanitizeFileName(id.split(QUERY_HASH_REGEX, 1)[0]);
14622
14614
  let path;
14623
14615
  const patternOpt = unsetOptions.has('entryFileNames')
14624
14616
  ? '[name][assetExtname].js'
14625
14617
  : options.entryFileNames;
14626
14618
  const pattern = typeof patternOpt === 'function' ? patternOpt(this.getChunkInfo()) : patternOpt;
14627
- if (isAbsolute(id)) {
14619
+ if (isAbsolute(sanitizedId)) {
14628
14620
  const currentDir = require$$0.dirname(sanitizedId);
14629
- const extension = require$$0.extname(id);
14621
+ const extension = require$$0.extname(sanitizedId);
14630
14622
  const fileName = renderNamePattern(pattern, 'output.entryFileNames', {
14631
14623
  assetExtname: () => (NON_ASSET_EXTENSIONS.includes(extension) ? '' : extension),
14632
14624
  ext: () => extension.substr(1),
@@ -14685,10 +14677,12 @@ class Chunk {
14685
14677
  });
14686
14678
  }
14687
14679
  getChunkName() {
14688
- return (this.name || (this.name = this.outputOptions.sanitizeFileName(this.getFallbackChunkName())));
14680
+ var _a;
14681
+ return ((_a = this.name) !== null && _a !== void 0 ? _a : (this.name = this.outputOptions.sanitizeFileName(this.getFallbackChunkName())));
14689
14682
  }
14690
14683
  getExportNames() {
14691
- return (this.sortedExportNames || (this.sortedExportNames = Object.keys(this.exportsByName).sort()));
14684
+ var _a;
14685
+ return ((_a = this.sortedExportNames) !== null && _a !== void 0 ? _a : (this.sortedExportNames = Array.from(this.exportsByName.keys()).sort()));
14692
14686
  }
14693
14687
  getRenderedHash() {
14694
14688
  if (this.renderedHash)
@@ -14704,7 +14698,7 @@ class Chunk {
14704
14698
  hash.update(this.renderedSource.toString());
14705
14699
  hash.update(this.getExportNames()
14706
14700
  .map(exportName => {
14707
- const variable = this.exportsByName[exportName];
14701
+ const variable = this.exportsByName.get(exportName);
14708
14702
  return `${relativeId(variable.module.id).replace(/\\/g, '/')}:${variable.name}:${exportName}`;
14709
14703
  })
14710
14704
  .join(','));
@@ -14963,12 +14957,12 @@ class Chunk {
14963
14957
  }
14964
14958
  computeContentHashWithDependencies(addons, options, existingNames) {
14965
14959
  const hash = createHash();
14966
- hash.update([addons.intro, addons.outro, addons.banner, addons.footer].map(addon => addon || '').join(':'));
14960
+ hash.update([addons.intro, addons.outro, addons.banner, addons.footer].join(':'));
14967
14961
  hash.update(options.format);
14968
14962
  const dependenciesForHashing = new Set([this]);
14969
14963
  for (const current of dependenciesForHashing) {
14970
14964
  if (current instanceof ExternalModule) {
14971
- hash.update(':' + current.renderPath);
14965
+ hash.update(`:${current.renderPath}`);
14972
14966
  }
14973
14967
  else {
14974
14968
  hash.update(current.getRenderedHash());
@@ -15042,7 +15036,7 @@ class Chunk {
15042
15036
  this.dynamicEntryModules[0] ||
15043
15037
  this.orderedModules[this.orderedModules.length - 1];
15044
15038
  if (moduleForNaming) {
15045
- return moduleForNaming.chunkName || getAliasName(moduleForNaming.id);
15039
+ return getChunkNameFromModule(moduleForNaming);
15046
15040
  }
15047
15041
  return 'chunk';
15048
15042
  }
@@ -15075,7 +15069,7 @@ class Chunk {
15075
15069
  for (const exportName of this.getExportNames()) {
15076
15070
  if (exportName[0] === '*')
15077
15071
  continue;
15078
- const variable = this.exportsByName[exportName];
15072
+ const variable = this.exportsByName.get(exportName);
15079
15073
  if (!(variable instanceof SyntheticNamedExportVariable)) {
15080
15074
  const module = variable.module;
15081
15075
  if (module && this.chunkByModule.get(module) !== this)
@@ -15223,7 +15217,7 @@ class Chunk {
15223
15217
  imported = exportName = '*';
15224
15218
  }
15225
15219
  else {
15226
- const variable = this.exportsByName[exportName];
15220
+ const variable = this.exportsByName.get(exportName);
15227
15221
  if (variable instanceof SyntheticNamedExportVariable)
15228
15222
  continue;
15229
15223
  const module = variable.module;
@@ -15324,7 +15318,7 @@ class Chunk {
15324
15318
  setIdentifierRenderResolutions({ format, interop, namespaceToStringTag }) {
15325
15319
  const syntheticExports = new Set();
15326
15320
  for (const exportName of this.getExportNames()) {
15327
- const exportVariable = this.exportsByName[exportName];
15321
+ const exportVariable = this.exportsByName.get(exportName);
15328
15322
  if (format !== 'es' &&
15329
15323
  format !== 'system' &&
15330
15324
  exportVariable.isReassigned &&
@@ -15414,8 +15408,10 @@ class Chunk {
15414
15408
  }
15415
15409
  }
15416
15410
  function getChunkNameFromModule(module) {
15417
- return module.chunkName || getAliasName(module.id);
15411
+ var _a, _b, _c, _d;
15412
+ return ((_d = (_b = (_a = module.chunkNames.find(({ isUserDefined }) => isUserDefined)) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : (_c = module.chunkNames[0]) === null || _c === void 0 ? void 0 : _c.name) !== null && _d !== void 0 ? _d : getAliasName(module.id));
15418
15413
  }
15414
+ const QUERY_HASH_REGEX = /[?#]/;
15419
15415
 
15420
15416
  function generateAssetFileName(name, source, outputOptions, bundle) {
15421
15417
  const emittedName = outputOptions.sanitizeFileName(name || 'asset');
@@ -21724,25 +21720,6 @@ Parser.acorn = {
21724
21720
  nonASCIIwhitespace: nonASCIIwhitespace
21725
21721
  };
21726
21722
 
21727
- const readFile = (file) => new Promise((fulfil, reject) => fs.readFile(file, 'utf-8', (err, contents) => (err ? reject(err) : fulfil(contents))));
21728
- function mkdirpath(path) {
21729
- const dir = require$$0.dirname(path);
21730
- fs.mkdirSync(dir, { recursive: true });
21731
- }
21732
- function writeFile(dest, data) {
21733
- return new Promise((fulfil, reject) => {
21734
- mkdirpath(dest);
21735
- fs.writeFile(dest, data, err => {
21736
- if (err) {
21737
- reject(err);
21738
- }
21739
- else {
21740
- fulfil();
21741
- }
21742
- });
21743
- });
21744
- }
21745
-
21746
21723
  class Queue {
21747
21724
  constructor(maxParallel) {
21748
21725
  this.maxParallel = maxParallel;
@@ -21808,26 +21785,20 @@ async function resolveId(source, importer, preserveSymlinks, pluginDriver, modul
21808
21785
  // See https://nodejs.org/api/path.html#path_path_resolve_paths
21809
21786
  return addJsExtensionIfNecessary(importer ? require$$0.resolve(require$$0.dirname(importer), source) : require$$0.resolve(source), preserveSymlinks);
21810
21787
  }
21811
- function addJsExtensionIfNecessary(file, preserveSymlinks) {
21812
- let found = findFile(file, preserveSymlinks);
21813
- if (found)
21814
- return found;
21815
- found = findFile(file + '.mjs', preserveSymlinks);
21816
- if (found)
21817
- return found;
21818
- found = findFile(file + '.js', preserveSymlinks);
21819
- return found;
21820
- }
21821
- function findFile(file, preserveSymlinks) {
21788
+ async function addJsExtensionIfNecessary(file, preserveSymlinks) {
21789
+ var _a, _b;
21790
+ return ((_b = (_a = (await findFile(file, preserveSymlinks))) !== null && _a !== void 0 ? _a : (await findFile(file + '.mjs', preserveSymlinks))) !== null && _b !== void 0 ? _b : (await findFile(file + '.js', preserveSymlinks)));
21791
+ }
21792
+ async function findFile(file, preserveSymlinks) {
21822
21793
  try {
21823
- const stats = fs.lstatSync(file);
21794
+ const stats = await require$$0$1.promises.lstat(file);
21824
21795
  if (!preserveSymlinks && stats.isSymbolicLink())
21825
- return findFile(fs.realpathSync(file), preserveSymlinks);
21796
+ return await findFile(await require$$0$1.promises.realpath(file), preserveSymlinks);
21826
21797
  if ((preserveSymlinks && stats.isSymbolicLink()) || stats.isFile()) {
21827
21798
  // check case
21828
21799
  const name = require$$0.basename(file);
21829
- const files = fs.readdirSync(require$$0.dirname(file));
21830
- if (files.indexOf(name) !== -1)
21800
+ const files = await require$$0$1.promises.readdir(require$$0.dirname(file));
21801
+ if (files.includes(name))
21831
21802
  return file;
21832
21803
  }
21833
21804
  }
@@ -22084,6 +22055,7 @@ async function transform(source, module, pluginDriver, warn) {
22084
22055
  };
22085
22056
  }
22086
22057
 
22058
+ const RESOLVE_DEPENDENCIES = 'resolveDependencies';
22087
22059
  class ModuleLoader {
22088
22060
  constructor(graph, modulesById, options, pluginDriver) {
22089
22061
  this.graph = graph;
@@ -22095,9 +22067,10 @@ class ModuleLoader {
22095
22067
  this.latestLoadModulesPromise = Promise.resolve();
22096
22068
  this.moduleLoadPromises = new Map();
22097
22069
  this.modulesWithLoadedDependencies = new Set();
22070
+ this.nextChunkNamePriority = 0;
22098
22071
  this.nextEntryModuleIndex = 0;
22099
22072
  this.resolveId = async (source, importer, customOptions, isEntry, skip = null) => {
22100
- return this.addDefaultsToResolvedId(this.getNormalizedResolvedIdWithoutDefaults(this.options.external(source, importer, false)
22073
+ return this.getResolvedIdWithDefaults(this.getNormalizedResolvedIdWithoutDefaults(this.options.external(source, importer, false)
22101
22074
  ? false
22102
22075
  : await resolveId(source, importer, this.options.preserveSymlinks, this.pluginDriver, this.resolveId, skip, customOptions, typeof isEntry === 'boolean' ? isEntry : !importer), importer, source));
22103
22076
  };
@@ -22114,21 +22087,24 @@ class ModuleLoader {
22114
22087
  async addEntryModules(unresolvedEntryModules, isUserDefined) {
22115
22088
  const firstEntryModuleIndex = this.nextEntryModuleIndex;
22116
22089
  this.nextEntryModuleIndex += unresolvedEntryModules.length;
22090
+ const firstChunkNamePriority = this.nextChunkNamePriority;
22091
+ this.nextChunkNamePriority += unresolvedEntryModules.length;
22117
22092
  const newEntryModules = await this.extendLoadModulesPromise(Promise.all(unresolvedEntryModules.map(({ id, importer }) => this.loadEntryModule(id, true, importer, null))).then(entryModules => {
22118
- let moduleIndex = firstEntryModuleIndex;
22119
22093
  for (let index = 0; index < entryModules.length; index++) {
22120
22094
  const entryModule = entryModules[index];
22121
22095
  entryModule.isUserDefinedEntryPoint =
22122
22096
  entryModule.isUserDefinedEntryPoint || isUserDefined;
22123
- addChunkNamesToModule(entryModule, unresolvedEntryModules[index], isUserDefined);
22097
+ addChunkNamesToModule(entryModule, unresolvedEntryModules[index], isUserDefined, firstChunkNamePriority + index);
22124
22098
  const existingIndexedModule = this.indexedEntryModules.find(indexedModule => indexedModule.module === entryModule);
22125
22099
  if (!existingIndexedModule) {
22126
- this.indexedEntryModules.push({ index: moduleIndex, module: entryModule });
22100
+ this.indexedEntryModules.push({
22101
+ index: firstEntryModuleIndex + index,
22102
+ module: entryModule
22103
+ });
22127
22104
  }
22128
22105
  else {
22129
- existingIndexedModule.index = Math.min(existingIndexedModule.index, moduleIndex);
22106
+ existingIndexedModule.index = Math.min(existingIndexedModule.index, firstEntryModuleIndex + index);
22130
22107
  }
22131
- moduleIndex++;
22132
22108
  }
22133
22109
  this.indexedEntryModules.sort(({ index: indexA }, { index: indexB }) => indexA > indexB ? 1 : -1);
22134
22110
  return entryModules;
@@ -22156,26 +22132,13 @@ class ModuleLoader {
22156
22132
  return module;
22157
22133
  }
22158
22134
  async preloadModule(resolvedId) {
22159
- const module = await this.fetchModule(this.addDefaultsToResolvedId(resolvedId), undefined, false, true);
22135
+ const module = await this.fetchModule(this.getResolvedIdWithDefaults(resolvedId), undefined, false, resolvedId.resolveDependencies ? RESOLVE_DEPENDENCIES : true);
22160
22136
  return module.info;
22161
22137
  }
22162
- addDefaultsToResolvedId(resolvedId) {
22163
- var _a, _b;
22164
- if (!resolvedId) {
22165
- return null;
22166
- }
22167
- const external = resolvedId.external || false;
22168
- return {
22169
- external,
22170
- id: resolvedId.id,
22171
- meta: resolvedId.meta || {},
22172
- moduleSideEffects: (_a = resolvedId.moduleSideEffects) !== null && _a !== void 0 ? _a : this.hasModuleSideEffects(resolvedId.id, !!external),
22173
- syntheticNamedExports: (_b = resolvedId.syntheticNamedExports) !== null && _b !== void 0 ? _b : false
22174
- };
22175
- }
22176
22138
  addEntryWithImplicitDependants(unresolvedModule, implicitlyLoadedAfter) {
22139
+ const chunkNamePriority = this.nextChunkNamePriority++;
22177
22140
  return this.extendLoadModulesPromise(this.loadEntryModule(unresolvedModule.id, false, unresolvedModule.importer, null).then(async (entryModule) => {
22178
- addChunkNamesToModule(entryModule, unresolvedModule, false);
22141
+ addChunkNamesToModule(entryModule, unresolvedModule, false, chunkNamePriority);
22179
22142
  if (!entryModule.info.isEntry) {
22180
22143
  this.implicitEntryModules.add(entryModule);
22181
22144
  const implicitlyLoadedAfterModules = await Promise.all(implicitlyLoadedAfter.map(id => this.loadEntryModule(id, false, unresolvedModule.importer, entryModule.id)));
@@ -22193,7 +22156,7 @@ class ModuleLoader {
22193
22156
  timeStart('load modules', 3);
22194
22157
  let source;
22195
22158
  try {
22196
- source = await this.readQueue.run(async () => { var _a; return (_a = (await this.pluginDriver.hookFirst('load', [id]))) !== null && _a !== void 0 ? _a : (await readFile(id)); });
22159
+ source = await this.readQueue.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')); });
22197
22160
  }
22198
22161
  catch (err) {
22199
22162
  timeEnd('load modules', 3);
@@ -22286,9 +22249,7 @@ class ModuleLoader {
22286
22249
  this.getResolveDynamicImportPromises(module),
22287
22250
  loadAndResolveDependenciesPromise
22288
22251
  ]);
22289
- const loadAndResolveDependenciesPromise = loadPromise
22290
- .then(([resolveStaticDependencyPromises, resolveDynamicImportPromises]) => Promise.all([...resolveStaticDependencyPromises, ...resolveDynamicImportPromises]))
22291
- .then(() => this.pluginDriver.hookParallel('moduleParsed', [module.info]));
22252
+ const loadAndResolveDependenciesPromise = waitForDependencyResolution(loadPromise).then(() => this.pluginDriver.hookParallel('moduleParsed', [module.info]));
22292
22253
  loadAndResolveDependenciesPromise.catch(() => {
22293
22254
  /* avoid unhandled promise rejections */
22294
22255
  });
@@ -22297,6 +22258,9 @@ class ModuleLoader {
22297
22258
  if (!isPreload) {
22298
22259
  await this.fetchModuleDependencies(module, ...resolveDependencyPromises);
22299
22260
  }
22261
+ else if (isPreload === RESOLVE_DEPENDENCIES) {
22262
+ await loadAndResolveDependenciesPromise;
22263
+ }
22300
22264
  return module;
22301
22265
  }
22302
22266
  async fetchModuleDependencies(module, resolveStaticDependencyPromises, resolveDynamicDependencyPromises, loadAndResolveDependenciesPromise) {
@@ -22333,7 +22297,7 @@ class ModuleLoader {
22333
22297
  module.dependencies.add(dependency);
22334
22298
  dependency.importers.push(module.id);
22335
22299
  }
22336
- if (!this.options.treeshake || module.info.hasModuleSideEffects === 'no-treeshake') {
22300
+ if (!this.options.treeshake || module.info.moduleSideEffects === 'no-treeshake') {
22337
22301
  for (const dependency of module.dependencies) {
22338
22302
  if (dependency instanceof Module) {
22339
22303
  dependency.importedFromNotTreeshaken = true;
@@ -22396,10 +22360,26 @@ class ModuleLoader {
22396
22360
  this.handleResolveId(await this.resolveId(source, module.id, EMPTY_OBJECT, false), source, module.id))
22397
22361
  ]);
22398
22362
  }
22363
+ getResolvedIdWithDefaults(resolvedId) {
22364
+ var _a, _b;
22365
+ if (!resolvedId) {
22366
+ return null;
22367
+ }
22368
+ const external = resolvedId.external || false;
22369
+ return {
22370
+ external,
22371
+ id: resolvedId.id,
22372
+ meta: resolvedId.meta || {},
22373
+ moduleSideEffects: (_a = resolvedId.moduleSideEffects) !== null && _a !== void 0 ? _a : this.hasModuleSideEffects(resolvedId.id, !!external),
22374
+ syntheticNamedExports: (_b = resolvedId.syntheticNamedExports) !== null && _b !== void 0 ? _b : false
22375
+ };
22376
+ }
22399
22377
  async handleExistingModule(module, isEntry, isPreload) {
22400
22378
  const loadPromise = this.moduleLoadPromises.get(module);
22401
22379
  if (isPreload) {
22402
- return loadPromise;
22380
+ return isPreload === RESOLVE_DEPENDENCIES
22381
+ ? waitForDependencyResolution(loadPromise)
22382
+ : loadPromise;
22403
22383
  }
22404
22384
  if (isEntry) {
22405
22385
  module.info.isEntry = true;
@@ -22425,10 +22405,8 @@ class ModuleLoader {
22425
22405
  syntheticNamedExports: false
22426
22406
  };
22427
22407
  }
22428
- else {
22429
- if (resolvedId.external && resolvedId.syntheticNamedExports) {
22430
- this.options.onwarn(errExternalSyntheticExports(source, importer));
22431
- }
22408
+ else if (resolvedId.external && resolvedId.syntheticNamedExports) {
22409
+ this.options.onwarn(errExternalSyntheticExports(source, importer));
22432
22410
  }
22433
22411
  return resolvedId;
22434
22412
  }
@@ -22445,7 +22423,7 @@ class ModuleLoader {
22445
22423
  ? errEntryCannotBeExternal(unresolvedId)
22446
22424
  : errImplicitDependantCannotBeExternal(unresolvedId, implicitlyLoadedBefore));
22447
22425
  }
22448
- return this.fetchModule(this.addDefaultsToResolvedId(typeof resolveIdResult === 'object'
22426
+ return this.fetchModule(this.getResolvedIdWithDefaults(typeof resolveIdResult === 'object'
22449
22427
  ? resolveIdResult
22450
22428
  : { id: resolveIdResult }), undefined, isEntry, false);
22451
22429
  }
@@ -22472,7 +22450,7 @@ class ModuleLoader {
22472
22450
  module.resolvedIds[specifier] ||
22473
22451
  this.handleResolveId(await this.resolveId(specifier, module.id, EMPTY_OBJECT, false), specifier, module.id));
22474
22452
  }
22475
- return this.handleResolveId(this.addDefaultsToResolvedId(this.getNormalizedResolvedIdWithoutDefaults(resolution, importer, specifier)), specifier, importer);
22453
+ return this.handleResolveId(this.getResolvedIdWithDefaults(this.getNormalizedResolvedIdWithoutDefaults(resolution, importer, specifier)), specifier, importer);
22476
22454
  }
22477
22455
  }
22478
22456
  function normalizeRelativeExternalId(source, importer) {
@@ -22482,17 +22460,17 @@ function normalizeRelativeExternalId(source, importer) {
22482
22460
  : require$$0.resolve(source)
22483
22461
  : source;
22484
22462
  }
22485
- function addChunkNamesToModule(module, { fileName, name }, isUserDefined) {
22463
+ function addChunkNamesToModule(module, { fileName, name }, isUserDefined, priority) {
22464
+ var _a;
22486
22465
  if (fileName !== null) {
22487
22466
  module.chunkFileNames.add(fileName);
22488
22467
  }
22489
22468
  else if (name !== null) {
22490
- if (module.chunkName === null) {
22491
- module.chunkName = name;
22492
- }
22493
- if (isUserDefined) {
22494
- module.userChunkNames.add(name);
22495
- }
22469
+ // Always keep chunkNames sorted by priority
22470
+ let namePosition = 0;
22471
+ while (((_a = module.chunkNames[namePosition]) === null || _a === void 0 ? void 0 : _a.priority) < priority)
22472
+ namePosition++;
22473
+ module.chunkNames.splice(namePosition, 0, { isUserDefined, name, priority });
22496
22474
  }
22497
22475
  }
22498
22476
  function isNotAbsoluteExternal(id, source, makeAbsoluteExternalsRelative) {
@@ -22500,6 +22478,10 @@ function isNotAbsoluteExternal(id, source, makeAbsoluteExternalsRelative) {
22500
22478
  (makeAbsoluteExternalsRelative === 'ifRelativeSource' && isRelative(source)) ||
22501
22479
  !isAbsolute(id));
22502
22480
  }
22481
+ async function waitForDependencyResolution(loadPromise) {
22482
+ const [resolveStaticDependencyPromises, resolveDynamicImportPromises] = await loadPromise;
22483
+ return Promise.all([...resolveStaticDependencyPromises, ...resolveDynamicImportPromises]);
22484
+ }
22503
22485
 
22504
22486
  class GlobalScope extends Scope$1 {
22505
22487
  constructor() {
@@ -22638,14 +22620,14 @@ function formatAction([pluginName, hookName, args]) {
22638
22620
  }
22639
22621
  return action;
22640
22622
  }
22641
- process.on('exit', () => {
22623
+ process$1.on('exit', () => {
22642
22624
  if (unfulfilledActions.size) {
22643
22625
  let err = '[!] Error: unfinished hook action(s) on exit:\n';
22644
22626
  for (const action of unfulfilledActions) {
22645
22627
  err += formatAction(action) + '\n';
22646
22628
  }
22647
22629
  console.error('%s', err);
22648
- process.exit(1);
22630
+ process$1.exit(1);
22649
22631
  }
22650
22632
  });
22651
22633
 
@@ -22674,7 +22656,6 @@ class PluginDriver {
22674
22656
  constructor(graph, options, userPlugins, pluginCache, basePluginDriver) {
22675
22657
  this.graph = graph;
22676
22658
  this.options = options;
22677
- this.pluginContexts = new Map();
22678
22659
  warnDeprecatedHooks(userPlugins, options);
22679
22660
  this.pluginCache = pluginCache;
22680
22661
  this.fileEmitter = new FileEmitter(graph, options, basePluginDriver && basePluginDriver.fileEmitter);
@@ -22684,9 +22665,10 @@ class PluginDriver {
22684
22665
  this.setOutputBundle = this.fileEmitter.setOutputBundle.bind(this.fileEmitter);
22685
22666
  this.plugins = userPlugins.concat(basePluginDriver ? basePluginDriver.plugins : []);
22686
22667
  const existingPluginNames = new Set();
22687
- for (const plugin of this.plugins) {
22688
- this.pluginContexts.set(plugin, getPluginContext(plugin, pluginCache, graph, options, this.fileEmitter, existingPluginNames));
22689
- }
22668
+ this.pluginContexts = new Map(this.plugins.map(plugin => [
22669
+ plugin,
22670
+ getPluginContext(plugin, pluginCache, graph, options, this.fileEmitter, existingPluginNames)
22671
+ ]));
22690
22672
  if (basePluginDriver) {
22691
22673
  for (const plugin of userPlugins) {
22692
22674
  for (const hook of inputHooks) {
@@ -23019,7 +23001,7 @@ class Graph {
23019
23001
  this.needsTreeshakingPass = false;
23020
23002
  for (const module of this.modules) {
23021
23003
  if (module.isExecuted) {
23022
- if (module.info.hasModuleSideEffects === 'no-treeshake') {
23004
+ if (module.info.moduleSideEffects === 'no-treeshake') {
23023
23005
  module.includeAllInBundle();
23024
23006
  }
23025
23007
  else {
@@ -23074,7 +23056,7 @@ class Graph {
23074
23056
  for (const module of this.modules) {
23075
23057
  for (const importDescription of Object.values(module.importDescriptions)) {
23076
23058
  if (importDescription.name !== '*' &&
23077
- !importDescription.module.getVariableForExportName(importDescription.name)) {
23059
+ !importDescription.module.getVariableForExportName(importDescription.name)[0]) {
23078
23060
  module.warn({
23079
23061
  code: 'NON_EXISTENT_EXPORT',
23080
23062
  message: `Non-existent export '${importDescription.name}' is imported from ${relativeId(importDescription.module.id)}`,
@@ -23269,13 +23251,14 @@ const getHasModuleSideEffects = (moduleSideEffectsOption, pureExternalModules) =
23269
23251
 
23270
23252
  // https://datatracker.ietf.org/doc/html/rfc2396
23271
23253
  // eslint-disable-next-line no-control-regex
23272
- const INVALID_CHAR_RE = /[\x00-\x1F\x7F<>*#"{}|^[\]`;?:&=+$,]/g;
23254
+ const INVALID_CHAR_REGEX = /[\x00-\x1F\x7F<>*#"{}|^[\]`;?:&=+$,]/g;
23255
+ const DRIVE_LETTER_REGEX = /^[a-z]:/i;
23273
23256
  function sanitizeFileName(name) {
23274
- const match = /^[a-z]:/i.exec(name);
23257
+ const match = DRIVE_LETTER_REGEX.exec(name);
23275
23258
  const driveLetter = match ? match[0] : '';
23276
23259
  // A `:` is only allowed as part of a windows drive letter (ex: C:\foo)
23277
23260
  // Otherwise, avoid them because they can refer to NTFS alternate data streams.
23278
- return driveLetter + name.substr(driveLetter.length).replace(INVALID_CHAR_RE, '_');
23261
+ return driveLetter + name.substr(driveLetter.length).replace(INVALID_CHAR_REGEX, '_');
23279
23262
  }
23280
23263
 
23281
23264
  function normalizeOutputOptions(config, inputOptions, unsetInputOptions) {
@@ -23496,7 +23479,14 @@ const getIndent = (config, compact) => {
23496
23479
  const configIndent = config.indent;
23497
23480
  return configIndent === false ? '' : configIndent !== null && configIndent !== void 0 ? configIndent : true;
23498
23481
  };
23499
- const ALLOWED_INTEROP_TYPES = new Set(['auto', 'esModule', 'default', 'defaultOnly', true, false]);
23482
+ const ALLOWED_INTEROP_TYPES = new Set([
23483
+ 'auto',
23484
+ 'esModule',
23485
+ 'default',
23486
+ 'defaultOnly',
23487
+ true,
23488
+ false
23489
+ ]);
23500
23490
  const getInterop = (config, inputOptions) => {
23501
23491
  const configInterop = config.interop;
23502
23492
  const validatedInteropTypes = new Set();
@@ -23681,8 +23671,10 @@ function getSortingFileType(file) {
23681
23671
  }
23682
23672
  return SortingFileType.SECONDARY_CHUNK;
23683
23673
  }
23684
- function writeOutputFile(outputFile, outputOptions) {
23674
+ async function writeOutputFile(outputFile, outputOptions) {
23685
23675
  const fileName = require$$0.resolve(outputOptions.dir || require$$0.dirname(outputOptions.file), outputFile.fileName);
23676
+ // 'recursive: true' does not throw if the folder structure, or parts of it, already exist
23677
+ await require$$0$1.promises.mkdir(require$$0.dirname(fileName), { recursive: true });
23686
23678
  let writeSourceMapPromise;
23687
23679
  let source;
23688
23680
  if (outputFile.type === 'asset') {
@@ -23697,14 +23689,14 @@ function writeOutputFile(outputFile, outputOptions) {
23697
23689
  }
23698
23690
  else {
23699
23691
  url = `${require$$0.basename(outputFile.fileName)}.map`;
23700
- writeSourceMapPromise = writeFile(`${fileName}.map`, outputFile.map.toString());
23692
+ writeSourceMapPromise = require$$0$1.promises.writeFile(`${fileName}.map`, outputFile.map.toString());
23701
23693
  }
23702
23694
  if (outputOptions.sourcemap !== 'hidden') {
23703
23695
  source += `//# ${exports.SOURCEMAPPING_URL}=${url}\n`;
23704
23696
  }
23705
23697
  }
23706
23698
  }
23707
- return Promise.all([writeFile(fileName, source), writeSourceMapPromise]);
23699
+ return Promise.all([require$$0$1.promises.writeFile(fileName, source), writeSourceMapPromise]);
23708
23700
  }
23709
23701
  /**
23710
23702
  * Auxiliary function for defining rollup configuration
@@ -23715,7 +23707,7 @@ function defineConfig(options) {
23715
23707
  return options;
23716
23708
  }
23717
23709
 
23718
- class WatchEmitter extends require$$0$1.EventEmitter {
23710
+ class WatchEmitter extends require$$0$2.EventEmitter {
23719
23711
  constructor() {
23720
23712
  super();
23721
23713
  // Allows more than 10 bundles to be watched without