rollup 4.7.0 → 4.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/rollup +2 -2
- package/dist/es/getLogFilter.js +2 -2
- package/dist/es/parseAst.js +2 -2
- package/dist/es/rollup.js +2 -2
- package/dist/es/shared/node-entry.js +196 -165
- package/dist/es/shared/parseAst.js +2 -2
- package/dist/es/shared/watch.js +2 -2
- package/dist/getLogFilter.js +2 -2
- package/dist/loadConfigFile.js +2 -2
- package/dist/parseAst.js +2 -2
- package/dist/rollup.js +76 -8
- package/dist/shared/fsevents-importer.js +2 -2
- package/dist/shared/index.js +2 -2
- package/dist/shared/loadConfigFile.js +2 -2
- package/dist/shared/parseAst.js +2 -2
- package/dist/shared/rollup.js +196 -165
- package/dist/shared/watch-cli.js +4 -4
- package/dist/shared/watch.js +2 -2
- package/package.json +14 -14
- package/dist/shared/watch-proxy.js +0 -88
package/dist/bin/rollup
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/*
|
|
3
3
|
@license
|
|
4
|
-
Rollup.js v4.
|
|
5
|
-
|
|
4
|
+
Rollup.js v4.9.0
|
|
5
|
+
Wed, 13 Dec 2023 09:23:48 GMT - commit c5337ef28a71c796e768a9f0edb3d7259a93f1aa
|
|
6
6
|
|
|
7
7
|
https://github.com/rollup/rollup
|
|
8
8
|
|
package/dist/es/getLogFilter.js
CHANGED
package/dist/es/parseAst.js
CHANGED
package/dist/es/rollup.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
@license
|
|
3
|
-
Rollup.js v4.
|
|
4
|
-
|
|
3
|
+
Rollup.js v4.9.0
|
|
4
|
+
Wed, 13 Dec 2023 09:23:48 GMT - commit c5337ef28a71c796e768a9f0edb3d7259a93f1aa
|
|
5
5
|
|
|
6
6
|
https://github.com/rollup/rollup
|
|
7
7
|
|
|
@@ -16,7 +16,7 @@ import { xxhashBase64Url } from '../../native.js';
|
|
|
16
16
|
import { lstat, realpath, readdir, readFile, mkdir, writeFile } from 'node:fs/promises';
|
|
17
17
|
import * as tty from 'tty';
|
|
18
18
|
|
|
19
|
-
var version = "4.
|
|
19
|
+
var version = "4.9.0";
|
|
20
20
|
|
|
21
21
|
const comma = ','.charCodeAt(0);
|
|
22
22
|
const semicolon = ';'.charCodeAt(0);
|
|
@@ -2060,6 +2060,20 @@ function makeLegal(value) {
|
|
|
2060
2060
|
value = `_${value}`;
|
|
2061
2061
|
return value || '_';
|
|
2062
2062
|
}
|
|
2063
|
+
const VALID_IDENTIFIER_REGEXP = /^[$_\p{ID_Start}][$\u200C\u200D\p{ID_Continue}]*$/u;
|
|
2064
|
+
const NUMBER_REGEXP = /^\d+$/;
|
|
2065
|
+
function stringifyObjectKeyIfNeeded(key) {
|
|
2066
|
+
if (VALID_IDENTIFIER_REGEXP.test(key) || NUMBER_REGEXP.test(key)) {
|
|
2067
|
+
return key;
|
|
2068
|
+
}
|
|
2069
|
+
return JSON.stringify(key);
|
|
2070
|
+
}
|
|
2071
|
+
function stringifyIdentifierIfNeeded(key) {
|
|
2072
|
+
if (VALID_IDENTIFIER_REGEXP.test(key)) {
|
|
2073
|
+
return key;
|
|
2074
|
+
}
|
|
2075
|
+
return JSON.stringify(key);
|
|
2076
|
+
}
|
|
2063
2077
|
|
|
2064
2078
|
class ExternalModule {
|
|
2065
2079
|
constructor(options, id, moduleSideEffects, meta, renormalizeRenderPath, attributes) {
|
|
@@ -7849,7 +7863,7 @@ function getSystemExportStatement(exportedVariables, { exportNamesByVariable, sn
|
|
|
7849
7863
|
if (exportedVariables.length === 1 &&
|
|
7850
7864
|
exportNamesByVariable.get(exportedVariables[0]).length === 1) {
|
|
7851
7865
|
const variable = exportedVariables[0];
|
|
7852
|
-
return `exports(
|
|
7866
|
+
return `exports(${JSON.stringify(exportNamesByVariable.get(variable)[0])},${_}${variable.getName(getPropertyAccess)}${modifier})`;
|
|
7853
7867
|
}
|
|
7854
7868
|
else {
|
|
7855
7869
|
const fields = [];
|
|
@@ -7861,8 +7875,9 @@ function getSystemExportStatement(exportedVariables, { exportNamesByVariable, sn
|
|
|
7861
7875
|
return `exports(${getObject(fields, { lineBreakIndent: null })})`;
|
|
7862
7876
|
}
|
|
7863
7877
|
}
|
|
7878
|
+
// This is only invoked if there is exactly one export name
|
|
7864
7879
|
function renderSystemExportExpression(exportedVariable, expressionStart, expressionEnd, code, { exportNamesByVariable, snippets: { _ } }) {
|
|
7865
|
-
code.prependRight(expressionStart, `exports(
|
|
7880
|
+
code.prependRight(expressionStart, `exports(${JSON.stringify(exportNamesByVariable.get(exportedVariable)[0])},${_}`);
|
|
7866
7881
|
code.appendLeft(expressionEnd, ')');
|
|
7867
7882
|
}
|
|
7868
7883
|
function renderSystemExportFunction(exportedVariables, expressionStart, expressionEnd, needsParens, code, options) {
|
|
@@ -12182,7 +12197,7 @@ class NamespaceVariable extends Variable {
|
|
|
12182
12197
|
if (this.referencedEarly || variable.isReassigned || variable === this) {
|
|
12183
12198
|
return [
|
|
12184
12199
|
null,
|
|
12185
|
-
`get ${name}${_}()${_}{${_}return ${variable.getName(getPropertyAccess)}${s}${_}}`
|
|
12200
|
+
`get ${stringifyObjectKeyIfNeeded(name)}${_}()${_}{${_}return ${variable.getName(getPropertyAccess)}${s}${_}}`
|
|
12186
12201
|
];
|
|
12187
12202
|
}
|
|
12188
12203
|
return [name, variable.getName(getPropertyAccess)];
|
|
@@ -13220,7 +13235,7 @@ class Module {
|
|
|
13220
13235
|
this.addSource(source, node);
|
|
13221
13236
|
if (node.exported) {
|
|
13222
13237
|
// export * as name from './other'
|
|
13223
|
-
const name = node.exported.name;
|
|
13238
|
+
const name = node.exported instanceof Literal ? node.exported.value : node.exported.name;
|
|
13224
13239
|
this.assertUniqueExportName(name, node.exported.start);
|
|
13225
13240
|
this.reexportDescriptions.set(name, {
|
|
13226
13241
|
localName: '*',
|
|
@@ -13552,7 +13567,7 @@ function getExportBlock$1(exports, dependencies, namedExportsMode, interop, snip
|
|
|
13552
13567
|
name: null
|
|
13553
13568
|
});
|
|
13554
13569
|
exportBlock +=
|
|
13555
|
-
`Object.defineProperty(exports,${_}
|
|
13570
|
+
`Object.defineProperty(exports,${_}${JSON.stringify(specifier.reexported)},${_}{${n}` +
|
|
13556
13571
|
`${t}enumerable:${_}true,${n}` +
|
|
13557
13572
|
`${t}get:${_}${left}${importName}${right}${n}});`;
|
|
13558
13573
|
}
|
|
@@ -13930,7 +13945,7 @@ function getImportBlock(dependencies, { _ }) {
|
|
|
13930
13945
|
importBlock.push(`import ${defaultImport ? `${defaultImport.local},${_}` : ''}{${_}${importedNames
|
|
13931
13946
|
.map(specifier => specifier.imported === specifier.local
|
|
13932
13947
|
? specifier.imported
|
|
13933
|
-
: `${specifier.imported} as ${specifier.local}`)
|
|
13948
|
+
: `${stringifyIdentifierIfNeeded(specifier.imported)} as ${specifier.local}`)
|
|
13934
13949
|
.join(`,${_}`)}${_}}${_}from${_}${pathWithAssertion}`);
|
|
13935
13950
|
}
|
|
13936
13951
|
}
|
|
@@ -13958,14 +13973,16 @@ function getImportBlock(dependencies, { _ }) {
|
|
|
13958
13973
|
importBlock.push(`import${_}*${_}as ${name} from${_}${pathWithAssertion}`);
|
|
13959
13974
|
}
|
|
13960
13975
|
for (const specifier of namespaceReexports) {
|
|
13961
|
-
importBlock.push(`export${_}{${_}${name === specifier.reexported
|
|
13976
|
+
importBlock.push(`export${_}{${_}${name === specifier.reexported
|
|
13977
|
+
? name
|
|
13978
|
+
: `${name} as ${stringifyIdentifierIfNeeded(specifier.reexported)}`} };`);
|
|
13962
13979
|
}
|
|
13963
13980
|
}
|
|
13964
13981
|
if (namedReexports.length > 0) {
|
|
13965
13982
|
importBlock.push(`export${_}{${_}${namedReexports
|
|
13966
13983
|
.map(specifier => specifier.imported === specifier.reexported
|
|
13967
|
-
? specifier.imported
|
|
13968
|
-
: `${specifier.imported} as ${specifier.reexported}`)
|
|
13984
|
+
? stringifyIdentifierIfNeeded(specifier.imported)
|
|
13985
|
+
: `${stringifyIdentifierIfNeeded(specifier.imported)} as ${stringifyIdentifierIfNeeded(specifier.reexported)}`)
|
|
13969
13986
|
.join(`,${_}`)}${_}}${_}from${_}${pathWithAssertion}`);
|
|
13970
13987
|
}
|
|
13971
13988
|
}
|
|
@@ -13981,7 +13998,7 @@ function getExportBlock(exports, { _, cnst }) {
|
|
|
13981
13998
|
}
|
|
13982
13999
|
exportDeclaration.push(specifier.exported === specifier.local
|
|
13983
14000
|
? specifier.local
|
|
13984
|
-
: `${specifier.local} as ${specifier.exported}`);
|
|
14001
|
+
: `${specifier.local} as ${stringifyIdentifierIfNeeded(specifier.exported)}`);
|
|
13985
14002
|
}
|
|
13986
14003
|
if (exportDeclaration.length > 0) {
|
|
13987
14004
|
exportBlock.push(`export${_}{${_}${exportDeclaration.join(`,${_}`)}${_}};`);
|
|
@@ -14397,7 +14414,7 @@ function deconflictImportsEsmOrSystem(usedNames, imports, dependenciesToBeDeconf
|
|
|
14397
14414
|
: module.suggestedVariableName, usedNames, variable.forbiddenNames));
|
|
14398
14415
|
}
|
|
14399
14416
|
else {
|
|
14400
|
-
variable.setRenderNames(null, getSafeName(name, usedNames, variable.forbiddenNames));
|
|
14417
|
+
variable.setRenderNames(null, getSafeName(makeLegal(name), usedNames, variable.forbiddenNames));
|
|
14401
14418
|
}
|
|
14402
14419
|
}
|
|
14403
14420
|
for (const variable of syntheticExports) {
|
|
@@ -15913,11 +15930,15 @@ function getChunkAssignments(entries, manualChunkAliasByEntry, minChunkSize, log
|
|
|
15913
15930
|
const { chunkDefinitions, modulesInManualChunks } = getChunkDefinitionsFromManualChunks(manualChunkAliasByEntry);
|
|
15914
15931
|
const { allEntries, dependentEntriesByModule, dynamicallyDependentEntriesByDynamicEntry, dynamicImportsByEntry } = analyzeModuleGraph(entries);
|
|
15915
15932
|
// Each chunk is identified by its position in this array
|
|
15916
|
-
const
|
|
15917
|
-
|
|
15918
|
-
//
|
|
15919
|
-
|
|
15920
|
-
|
|
15933
|
+
const chunkAtoms = getChunksWithSameDependentEntries(getModulesWithDependentEntries(dependentEntriesByModule, modulesInManualChunks));
|
|
15934
|
+
const staticDependencyAtomsByEntry = getStaticDependencyAtomsByEntry(allEntries, chunkAtoms);
|
|
15935
|
+
// Warning: This will consume dynamicallyDependentEntriesByDynamicEntry.
|
|
15936
|
+
// If we no longer want this, we should make a copy here.
|
|
15937
|
+
const alreadyLoadedAtomsByEntry = getAlreadyLoadedAtomsByEntry(staticDependencyAtomsByEntry, dynamicallyDependentEntriesByDynamicEntry, dynamicImportsByEntry, allEntries);
|
|
15938
|
+
// This mutates the dependentEntries in chunkAtoms
|
|
15939
|
+
removeUnnecessaryDependentEntries(chunkAtoms, alreadyLoadedAtomsByEntry);
|
|
15940
|
+
const { chunks, sideEffectAtoms, sizeByAtom } = getChunksWithSameDependentEntriesAndCorrelatedAtoms(chunkAtoms, staticDependencyAtomsByEntry, alreadyLoadedAtomsByEntry, minChunkSize);
|
|
15941
|
+
chunkDefinitions.push(...getOptimizedChunks(chunks, minChunkSize, sideEffectAtoms, sizeByAtom, log).map(({ modules }) => ({
|
|
15921
15942
|
alias: null,
|
|
15922
15943
|
modules
|
|
15923
15944
|
})));
|
|
@@ -16026,7 +16047,7 @@ function getDynamicallyDependentEntriesByDynamicEntry(dependentEntriesByModule,
|
|
|
16026
16047
|
}
|
|
16027
16048
|
return dynamicallyDependentEntriesByDynamicEntry;
|
|
16028
16049
|
}
|
|
16029
|
-
function
|
|
16050
|
+
function getChunksWithSameDependentEntries(modulesWithDependentEntries) {
|
|
16030
16051
|
const chunkModules = Object.create(null);
|
|
16031
16052
|
for (const { dependentEntries, modules } of modulesWithDependentEntries) {
|
|
16032
16053
|
let chunkSignature = 0n;
|
|
@@ -16047,55 +16068,152 @@ function* getModulesWithDependentEntries(dependentEntriesByModule, modulesInManu
|
|
|
16047
16068
|
}
|
|
16048
16069
|
}
|
|
16049
16070
|
}
|
|
16050
|
-
|
|
16051
|
-
|
|
16052
|
-
* first argument. It will also consume its second argument, so if
|
|
16053
|
-
* dynamicallyDependentEntriesByDynamicEntry is ever needed after this, we
|
|
16054
|
-
* should make a copy.
|
|
16055
|
-
*/
|
|
16056
|
-
function removeUnnecessaryDependentEntries(chunks, dynamicallyDependentEntriesByDynamicEntry, dynamicImportsByEntry, allEntries) {
|
|
16057
|
-
// The indices correspond to the indices in allEntries. The chunks correspond
|
|
16071
|
+
function getStaticDependencyAtomsByEntry(allEntries, chunkAtoms) {
|
|
16072
|
+
// The indices correspond to the indices in allEntries. The atoms correspond
|
|
16058
16073
|
// to bits in the bigint values where chunk 0 is the lowest bit.
|
|
16059
|
-
const
|
|
16060
|
-
|
|
16061
|
-
|
|
16062
|
-
|
|
16063
|
-
for (const { dependentEntries } of chunks) {
|
|
16074
|
+
const staticDependencyAtomsByEntry = allEntries.map(() => 0n);
|
|
16075
|
+
// This toggles the bits for each atom that is a dependency of an entry
|
|
16076
|
+
let atomMask = 1n;
|
|
16077
|
+
for (const { dependentEntries } of chunkAtoms) {
|
|
16064
16078
|
for (const entryIndex of dependentEntries) {
|
|
16065
|
-
|
|
16066
|
-
}
|
|
16067
|
-
|
|
16068
|
-
}
|
|
16069
|
-
|
|
16070
|
-
|
|
16071
|
-
|
|
16072
|
-
|
|
16073
|
-
|
|
16074
|
-
|
|
16075
|
-
|
|
16076
|
-
|
|
16077
|
-
|
|
16078
|
-
|
|
16079
|
-
|
|
16080
|
-
|
|
16081
|
-
|
|
16079
|
+
staticDependencyAtomsByEntry[entryIndex] |= atomMask;
|
|
16080
|
+
}
|
|
16081
|
+
atomMask <<= 1n;
|
|
16082
|
+
}
|
|
16083
|
+
return staticDependencyAtomsByEntry;
|
|
16084
|
+
}
|
|
16085
|
+
// Warning: This will consume dynamicallyDependentEntriesByDynamicEntry.
|
|
16086
|
+
function getAlreadyLoadedAtomsByEntry(staticDependencyAtomsByEntry, dynamicallyDependentEntriesByDynamicEntry, dynamicImportsByEntry, allEntries) {
|
|
16087
|
+
// Dynamic entries have all atoms as already loaded initially because we then
|
|
16088
|
+
// intersect with the static dependency atoms of all dynamic importers.
|
|
16089
|
+
// Static entries cannot have already loaded atoms.
|
|
16090
|
+
const alreadyLoadedAtomsByEntry = allEntries.map((_entry, entryIndex) => dynamicallyDependentEntriesByDynamicEntry.has(entryIndex) ? -1n : 0n);
|
|
16091
|
+
for (const [dynamicEntryIndex, dynamicallyDependentEntries] of dynamicallyDependentEntriesByDynamicEntry) {
|
|
16092
|
+
// We delete here so that they can be added again if necessary to be handled
|
|
16093
|
+
// again by the loop
|
|
16094
|
+
dynamicallyDependentEntriesByDynamicEntry.delete(dynamicEntryIndex);
|
|
16095
|
+
const knownLoadedAtoms = alreadyLoadedAtomsByEntry[dynamicEntryIndex];
|
|
16096
|
+
let updatedLoadedAtoms = knownLoadedAtoms;
|
|
16097
|
+
for (const entryIndex of dynamicallyDependentEntries) {
|
|
16098
|
+
updatedLoadedAtoms &=
|
|
16099
|
+
staticDependencyAtomsByEntry[entryIndex] | alreadyLoadedAtomsByEntry[entryIndex];
|
|
16100
|
+
}
|
|
16101
|
+
// If the knownLoadedAtoms changed, all dependent dynamic entries need to be
|
|
16102
|
+
// updated again
|
|
16103
|
+
if (updatedLoadedAtoms !== knownLoadedAtoms) {
|
|
16104
|
+
alreadyLoadedAtomsByEntry[dynamicEntryIndex] = updatedLoadedAtoms;
|
|
16082
16105
|
for (const dynamicImport of dynamicImportsByEntry[dynamicEntryIndex]) {
|
|
16083
|
-
|
|
16106
|
+
// If this adds an entry that was deleted before, it will be handled
|
|
16107
|
+
// again. This is the reason why we delete every entry from this map
|
|
16108
|
+
// that we processed.
|
|
16109
|
+
getOrCreate(dynamicallyDependentEntriesByDynamicEntry, dynamicImport, (getNewSet)).add(dynamicEntryIndex);
|
|
16084
16110
|
}
|
|
16085
16111
|
}
|
|
16086
16112
|
}
|
|
16113
|
+
return alreadyLoadedAtomsByEntry;
|
|
16114
|
+
}
|
|
16115
|
+
/**
|
|
16116
|
+
* This removes all unnecessary dynamic entries from the dependentEntries in its
|
|
16117
|
+
* first argument if a chunk is already loaded without that entry.
|
|
16118
|
+
*/
|
|
16119
|
+
function removeUnnecessaryDependentEntries(chunkAtoms, alreadyLoadedAtomsByEntry) {
|
|
16087
16120
|
// Remove entries from dependent entries if a chunk is already loaded without
|
|
16088
16121
|
// that entry.
|
|
16089
|
-
chunkMask = 1n;
|
|
16090
|
-
for (const { dependentEntries } of
|
|
16122
|
+
let chunkMask = 1n;
|
|
16123
|
+
for (const { dependentEntries } of chunkAtoms) {
|
|
16091
16124
|
for (const entryIndex of dependentEntries) {
|
|
16092
|
-
if ((
|
|
16125
|
+
if ((alreadyLoadedAtomsByEntry[entryIndex] & chunkMask) === chunkMask) {
|
|
16093
16126
|
dependentEntries.delete(entryIndex);
|
|
16094
16127
|
}
|
|
16095
16128
|
}
|
|
16096
16129
|
chunkMask <<= 1n;
|
|
16097
16130
|
}
|
|
16098
16131
|
}
|
|
16132
|
+
function getChunksWithSameDependentEntriesAndCorrelatedAtoms(chunkAtoms, staticDependencyAtomsByEntry, alreadyLoadedAtomsByEntry, minChunkSize) {
|
|
16133
|
+
const chunksBySignature = Object.create(null);
|
|
16134
|
+
const chunkByModule = new Map();
|
|
16135
|
+
const sizeByAtom = [];
|
|
16136
|
+
let sideEffectAtoms = 0n;
|
|
16137
|
+
let atomMask = 1n;
|
|
16138
|
+
for (const { dependentEntries, modules } of chunkAtoms) {
|
|
16139
|
+
let chunkSignature = 0n;
|
|
16140
|
+
let correlatedAtoms = -1n;
|
|
16141
|
+
for (const entryIndex of dependentEntries) {
|
|
16142
|
+
chunkSignature |= 1n << BigInt(entryIndex);
|
|
16143
|
+
// Correlated atoms are the atoms that are guaranteed to be loaded as
|
|
16144
|
+
// well when a given atom is loaded. It is the intersection of the already
|
|
16145
|
+
// loaded modules of each chunk merged with its static dependencies.
|
|
16146
|
+
correlatedAtoms &=
|
|
16147
|
+
staticDependencyAtomsByEntry[entryIndex] | alreadyLoadedAtomsByEntry[entryIndex];
|
|
16148
|
+
}
|
|
16149
|
+
const chunk = (chunksBySignature[String(chunkSignature)] ||= {
|
|
16150
|
+
containedAtoms: 0n,
|
|
16151
|
+
correlatedAtoms,
|
|
16152
|
+
dependencies: new Set(),
|
|
16153
|
+
dependentChunks: new Set(),
|
|
16154
|
+
dependentEntries: new Set(dependentEntries),
|
|
16155
|
+
modules: [],
|
|
16156
|
+
pure: true,
|
|
16157
|
+
size: 0
|
|
16158
|
+
});
|
|
16159
|
+
let atomSize = 0;
|
|
16160
|
+
let pure = true;
|
|
16161
|
+
for (const module of modules) {
|
|
16162
|
+
chunkByModule.set(module, chunk);
|
|
16163
|
+
// Unfortunately, we cannot take tree-shaking into account here because
|
|
16164
|
+
// rendering did not happen yet, but we can detect empty modules
|
|
16165
|
+
if (module.isIncluded()) {
|
|
16166
|
+
pure &&= !module.hasEffects();
|
|
16167
|
+
// we use a trivial size for the default minChunkSize to improve
|
|
16168
|
+
// performance
|
|
16169
|
+
atomSize += minChunkSize > 1 ? module.estimateSize() : 1;
|
|
16170
|
+
}
|
|
16171
|
+
}
|
|
16172
|
+
if (!pure) {
|
|
16173
|
+
sideEffectAtoms |= atomMask;
|
|
16174
|
+
}
|
|
16175
|
+
sizeByAtom.push(atomSize);
|
|
16176
|
+
chunk.containedAtoms |= atomMask;
|
|
16177
|
+
chunk.modules.push(...modules);
|
|
16178
|
+
chunk.pure &&= pure;
|
|
16179
|
+
chunk.size += atomSize;
|
|
16180
|
+
atomMask <<= 1n;
|
|
16181
|
+
}
|
|
16182
|
+
const chunks = Object.values(chunksBySignature);
|
|
16183
|
+
sideEffectAtoms |= addChunkDependenciesAndGetExternalSideEffectAtoms(chunks, chunkByModule, atomMask);
|
|
16184
|
+
return { chunks, sideEffectAtoms, sizeByAtom };
|
|
16185
|
+
}
|
|
16186
|
+
function addChunkDependenciesAndGetExternalSideEffectAtoms(chunks, chunkByModule, nextAvailableAtomMask) {
|
|
16187
|
+
const signatureByExternalModule = new Map();
|
|
16188
|
+
let externalSideEffectAtoms = 0n;
|
|
16189
|
+
for (const chunk of chunks) {
|
|
16190
|
+
const { dependencies, modules } = chunk;
|
|
16191
|
+
for (const module of modules) {
|
|
16192
|
+
for (const dependency of module.getDependenciesToBeIncluded()) {
|
|
16193
|
+
if (dependency instanceof ExternalModule) {
|
|
16194
|
+
if (dependency.info.moduleSideEffects) {
|
|
16195
|
+
const signature = getOrCreate(signatureByExternalModule, dependency, () => {
|
|
16196
|
+
const signature = nextAvailableAtomMask;
|
|
16197
|
+
nextAvailableAtomMask <<= 1n;
|
|
16198
|
+
externalSideEffectAtoms |= signature;
|
|
16199
|
+
return signature;
|
|
16200
|
+
});
|
|
16201
|
+
chunk.containedAtoms |= signature;
|
|
16202
|
+
chunk.correlatedAtoms |= signature;
|
|
16203
|
+
}
|
|
16204
|
+
}
|
|
16205
|
+
else {
|
|
16206
|
+
const dependencyChunk = chunkByModule.get(dependency);
|
|
16207
|
+
if (dependencyChunk && dependencyChunk !== chunk) {
|
|
16208
|
+
dependencies.add(dependencyChunk);
|
|
16209
|
+
dependencyChunk.dependentChunks.add(chunk);
|
|
16210
|
+
}
|
|
16211
|
+
}
|
|
16212
|
+
}
|
|
16213
|
+
}
|
|
16214
|
+
}
|
|
16215
|
+
return externalSideEffectAtoms;
|
|
16216
|
+
}
|
|
16099
16217
|
/**
|
|
16100
16218
|
* This function tries to get rid of small chunks by merging them with other
|
|
16101
16219
|
* chunks.
|
|
@@ -16172,77 +16290,44 @@ function removeUnnecessaryDependentEntries(chunks, dynamicallyDependentEntriesBy
|
|
|
16172
16290
|
* following the rule (a), starting with the smallest chunks to look for
|
|
16173
16291
|
* possible merge targets.
|
|
16174
16292
|
*/
|
|
16175
|
-
function getOptimizedChunks(
|
|
16293
|
+
function getOptimizedChunks(chunks, minChunkSize, sideEffectAtoms, sizeByAtom, log) {
|
|
16176
16294
|
timeStart('optimize chunks', 3);
|
|
16177
|
-
const chunkPartition = getPartitionedChunks(
|
|
16295
|
+
const chunkPartition = getPartitionedChunks(chunks, minChunkSize);
|
|
16178
16296
|
if (!chunkPartition) {
|
|
16179
16297
|
timeEnd('optimize chunks', 3);
|
|
16180
|
-
return
|
|
16298
|
+
return chunks; // the actual modules
|
|
16181
16299
|
}
|
|
16182
16300
|
minChunkSize > 1 &&
|
|
16183
|
-
log('info', logOptimizeChunkStatus(
|
|
16184
|
-
mergeChunks(chunkPartition, minChunkSize);
|
|
16301
|
+
log('info', logOptimizeChunkStatus(chunks.length, chunkPartition.small.size, 'Initially'));
|
|
16302
|
+
mergeChunks(chunkPartition, minChunkSize, sideEffectAtoms, sizeByAtom);
|
|
16185
16303
|
minChunkSize > 1 &&
|
|
16186
16304
|
log('info', logOptimizeChunkStatus(chunkPartition.small.size + chunkPartition.big.size, chunkPartition.small.size, 'After merging chunks'));
|
|
16187
16305
|
timeEnd('optimize chunks', 3);
|
|
16188
16306
|
return [...chunkPartition.small, ...chunkPartition.big];
|
|
16189
16307
|
}
|
|
16190
|
-
function getPartitionedChunks(
|
|
16308
|
+
function getPartitionedChunks(chunks, minChunkSize) {
|
|
16191
16309
|
const smallChunks = [];
|
|
16192
16310
|
const bigChunks = [];
|
|
16193
|
-
const
|
|
16194
|
-
|
|
16195
|
-
let sideEffectAtoms = 0n;
|
|
16196
|
-
let containedAtoms = 1n;
|
|
16197
|
-
for (const { dependentEntries, modules } of initialChunks) {
|
|
16198
|
-
const chunkDescription = {
|
|
16199
|
-
containedAtoms,
|
|
16200
|
-
correlatedAtoms: 0n,
|
|
16201
|
-
dependencies: new Set(),
|
|
16202
|
-
dependentChunks: new Set(),
|
|
16203
|
-
dependentEntries,
|
|
16204
|
-
modules,
|
|
16205
|
-
pure: true,
|
|
16206
|
-
size: 0
|
|
16207
|
-
};
|
|
16208
|
-
let size = 0;
|
|
16209
|
-
let pure = true;
|
|
16210
|
-
for (const module of modules) {
|
|
16211
|
-
chunkByModule.set(module, chunkDescription);
|
|
16212
|
-
// Unfortunately, we cannot take tree-shaking into account here because
|
|
16213
|
-
// rendering did not happen yet, but we can detect empty modules
|
|
16214
|
-
if (module.isIncluded()) {
|
|
16215
|
-
pure &&= !module.hasEffects();
|
|
16216
|
-
// we use a trivial size for the default minChunkSize to improve
|
|
16217
|
-
// performance
|
|
16218
|
-
size += minChunkSize > 1 ? module.estimateSize() : 1;
|
|
16219
|
-
}
|
|
16220
|
-
}
|
|
16221
|
-
chunkDescription.pure = pure;
|
|
16222
|
-
chunkDescription.size = size;
|
|
16223
|
-
sizeByAtom.push(size);
|
|
16224
|
-
if (!pure) {
|
|
16225
|
-
sideEffectAtoms |= containedAtoms;
|
|
16226
|
-
}
|
|
16227
|
-
(size < minChunkSize ? smallChunks : bigChunks).push(chunkDescription);
|
|
16228
|
-
containedAtoms <<= 1n;
|
|
16311
|
+
for (const chunk of chunks) {
|
|
16312
|
+
(chunk.size < minChunkSize ? smallChunks : bigChunks).push(chunk);
|
|
16229
16313
|
}
|
|
16230
|
-
// If there are no small chunks, we will not optimize
|
|
16231
16314
|
if (smallChunks.length === 0) {
|
|
16232
16315
|
return null;
|
|
16233
16316
|
}
|
|
16234
|
-
|
|
16317
|
+
smallChunks.sort(compareChunkSize);
|
|
16318
|
+
bigChunks.sort(compareChunkSize);
|
|
16235
16319
|
return {
|
|
16236
16320
|
big: new Set(bigChunks),
|
|
16237
|
-
sideEffectAtoms,
|
|
16238
|
-
sizeByAtom,
|
|
16239
16321
|
small: new Set(smallChunks)
|
|
16240
16322
|
};
|
|
16241
16323
|
}
|
|
16242
|
-
function
|
|
16324
|
+
function compareChunkSize({ size: sizeA }, { size: sizeB }) {
|
|
16325
|
+
return sizeA - sizeB;
|
|
16326
|
+
}
|
|
16327
|
+
function mergeChunks(chunkPartition, minChunkSize, sideEffectAtoms, sizeByAtom) {
|
|
16243
16328
|
const { small } = chunkPartition;
|
|
16244
16329
|
for (const mergedChunk of small) {
|
|
16245
|
-
const bestTargetChunk = findBestMergeTarget(mergedChunk, chunkPartition,
|
|
16330
|
+
const bestTargetChunk = findBestMergeTarget(mergedChunk, chunkPartition, sideEffectAtoms, sizeByAtom,
|
|
16246
16331
|
// In the default case, we do not accept size increases
|
|
16247
16332
|
minChunkSize <= 1 ? 1 : Infinity);
|
|
16248
16333
|
if (bestTargetChunk) {
|
|
@@ -16274,57 +16359,7 @@ function mergeChunks(chunkPartition, minChunkSize) {
|
|
|
16274
16359
|
}
|
|
16275
16360
|
}
|
|
16276
16361
|
}
|
|
16277
|
-
function
|
|
16278
|
-
const signatureByExternalModule = new Map();
|
|
16279
|
-
let sideEffectAtoms = 0n;
|
|
16280
|
-
const atomsByEntry = [];
|
|
16281
|
-
for (let index = 0; index < numberOfEntries; index++) {
|
|
16282
|
-
atomsByEntry.push(0n);
|
|
16283
|
-
}
|
|
16284
|
-
for (const chunks of chunkLists) {
|
|
16285
|
-
chunks.sort(compareChunkSize);
|
|
16286
|
-
for (const chunk of chunks) {
|
|
16287
|
-
const { dependencies, dependentEntries, modules } = chunk;
|
|
16288
|
-
for (const module of modules) {
|
|
16289
|
-
for (const dependency of module.getDependenciesToBeIncluded()) {
|
|
16290
|
-
if (dependency instanceof ExternalModule) {
|
|
16291
|
-
if (dependency.info.moduleSideEffects) {
|
|
16292
|
-
chunk.containedAtoms |= getOrCreate(signatureByExternalModule, dependency, () => {
|
|
16293
|
-
const signature = nextAtomSignature;
|
|
16294
|
-
nextAtomSignature <<= 1n;
|
|
16295
|
-
sideEffectAtoms |= signature;
|
|
16296
|
-
return signature;
|
|
16297
|
-
});
|
|
16298
|
-
}
|
|
16299
|
-
}
|
|
16300
|
-
else {
|
|
16301
|
-
const dependencyChunk = chunkByModule.get(dependency);
|
|
16302
|
-
if (dependencyChunk && dependencyChunk !== chunk) {
|
|
16303
|
-
dependencies.add(dependencyChunk);
|
|
16304
|
-
dependencyChunk.dependentChunks.add(chunk);
|
|
16305
|
-
}
|
|
16306
|
-
}
|
|
16307
|
-
}
|
|
16308
|
-
}
|
|
16309
|
-
const { containedAtoms } = chunk;
|
|
16310
|
-
for (const entryIndex of dependentEntries) {
|
|
16311
|
-
atomsByEntry[entryIndex] |= containedAtoms;
|
|
16312
|
-
}
|
|
16313
|
-
}
|
|
16314
|
-
}
|
|
16315
|
-
for (const chunks of chunkLists) {
|
|
16316
|
-
for (const chunk of chunks) {
|
|
16317
|
-
const { dependentEntries } = chunk;
|
|
16318
|
-
// Correlated atoms are the intersection of all entry atoms
|
|
16319
|
-
chunk.correlatedAtoms = -1n;
|
|
16320
|
-
for (const entryIndex of dependentEntries) {
|
|
16321
|
-
chunk.correlatedAtoms &= atomsByEntry[entryIndex];
|
|
16322
|
-
}
|
|
16323
|
-
}
|
|
16324
|
-
}
|
|
16325
|
-
return sideEffectAtoms;
|
|
16326
|
-
}
|
|
16327
|
-
function findBestMergeTarget(mergedChunk, { big, sideEffectAtoms, sizeByAtom, small }, smallestAdditionalSize) {
|
|
16362
|
+
function findBestMergeTarget(mergedChunk, { big, small }, sideEffectAtoms, sizeByAtom, smallestAdditionalSize) {
|
|
16328
16363
|
let bestTargetChunk = null;
|
|
16329
16364
|
// In the default case, we do not accept size increases
|
|
16330
16365
|
for (const targetChunk of concatLazy([small, big])) {
|
|
@@ -16340,12 +16375,6 @@ function findBestMergeTarget(mergedChunk, { big, sideEffectAtoms, sizeByAtom, sm
|
|
|
16340
16375
|
}
|
|
16341
16376
|
return bestTargetChunk;
|
|
16342
16377
|
}
|
|
16343
|
-
function getChunksInPartition(chunk, minChunkSize, chunkPartition) {
|
|
16344
|
-
return chunk.size < minChunkSize ? chunkPartition.small : chunkPartition.big;
|
|
16345
|
-
}
|
|
16346
|
-
function compareChunkSize({ size: sizeA }, { size: sizeB }) {
|
|
16347
|
-
return sizeA - sizeB;
|
|
16348
|
-
}
|
|
16349
16378
|
/**
|
|
16350
16379
|
* Determine the additional unused code size that would be added by merging the
|
|
16351
16380
|
* two chunks. This is not an exact measurement but rather an upper bound. If
|
|
@@ -16403,6 +16432,9 @@ function getAtomsSizeIfBelowLimit(atoms, currentAdditionalSize, sizeByAtom) {
|
|
|
16403
16432
|
}
|
|
16404
16433
|
return size;
|
|
16405
16434
|
}
|
|
16435
|
+
function getChunksInPartition(chunk, minChunkSize, chunkPartition) {
|
|
16436
|
+
return chunk.size < minChunkSize ? chunkPartition.small : chunkPartition.big;
|
|
16437
|
+
}
|
|
16406
16438
|
|
|
16407
16439
|
// ported from https://github.com/substack/node-commondir
|
|
16408
16440
|
function commondir(files) {
|
|
@@ -16512,8 +16544,8 @@ function getGenerateCodeSnippets({ compact, generatedCode: { arrowFunctions, con
|
|
|
16512
16544
|
: `${s}${lineBreakIndent ? `${n}${lineBreakIndent.base}` : _}}`
|
|
16513
16545
|
];
|
|
16514
16546
|
const isValidPropertyName = reservedNamesAsProps
|
|
16515
|
-
? (name) =>
|
|
16516
|
-
: (name) => !RESERVED_NAMES$1.has(name) &&
|
|
16547
|
+
? (name) => VALID_IDENTIFIER_REGEXP.test(name)
|
|
16548
|
+
: (name) => !RESERVED_NAMES$1.has(name) && VALID_IDENTIFIER_REGEXP.test(name);
|
|
16517
16549
|
return {
|
|
16518
16550
|
_,
|
|
16519
16551
|
cnst,
|
|
@@ -16534,10 +16566,10 @@ function getGenerateCodeSnippets({ compact, generatedCode: { arrowFunctions, con
|
|
|
16534
16566
|
.map(([key, value]) => {
|
|
16535
16567
|
if (key === null)
|
|
16536
16568
|
return `${prefix}${value}`;
|
|
16537
|
-
const
|
|
16538
|
-
return key === value && objectShorthand &&
|
|
16569
|
+
const keyInObject = stringifyObjectKeyIfNeeded(key);
|
|
16570
|
+
return key === value && objectShorthand && key === keyInObject
|
|
16539
16571
|
? prefix + key
|
|
16540
|
-
: `${prefix}${
|
|
16572
|
+
: `${prefix}${keyInObject}:${_}${value}`;
|
|
16541
16573
|
})
|
|
16542
16574
|
.join(`,`)}${fields.length === 0 ? '' : lineBreakIndent ? `${n}${lineBreakIndent.base}` : _}}`;
|
|
16543
16575
|
},
|
|
@@ -16547,7 +16579,6 @@ function getGenerateCodeSnippets({ compact, generatedCode: { arrowFunctions, con
|
|
|
16547
16579
|
};
|
|
16548
16580
|
}
|
|
16549
16581
|
const wrapIfNeeded = (code, needsParens) => needsParens ? `(${code})` : code;
|
|
16550
|
-
const validPropertyName = /^(?!\d)[\w$]+$/;
|
|
16551
16582
|
|
|
16552
16583
|
class Source {
|
|
16553
16584
|
constructor(filename, content) {
|
package/dist/es/shared/watch.js
CHANGED
package/dist/getLogFilter.js
CHANGED
package/dist/loadConfigFile.js
CHANGED
package/dist/parseAst.js
CHANGED