slicejs-cli 4.0.0 → 4.0.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.
|
@@ -848,7 +848,8 @@ export default class BundleGenerator {
|
|
|
848
848
|
const routeFile = await this.createBundleFile(
|
|
849
849
|
bundle.components,
|
|
850
850
|
'route',
|
|
851
|
-
routeIdentifier
|
|
851
|
+
routeIdentifier,
|
|
852
|
+
routeKey
|
|
852
853
|
);
|
|
853
854
|
bundle.file = routeFile.file;
|
|
854
855
|
bundle.hash = routeFile.hash;
|
|
@@ -976,7 +977,9 @@ export default class BundleGenerator {
|
|
|
976
977
|
const measuredSize = entry?.external
|
|
977
978
|
? Buffer.byteLength(entry?.content || '', 'utf-8')
|
|
978
979
|
: Buffer.byteLength(
|
|
979
|
-
|
|
980
|
+
// Size probe only — nothing here is emitted, so it must stay quiet
|
|
981
|
+
// rather than double-report warnings the real emit already covers.
|
|
982
|
+
this.transformDependencyContent(entry?.content || '', '__sliceVendorSharedProbe', dependencyName, { silent: true }),
|
|
980
983
|
'utf-8'
|
|
981
984
|
);
|
|
982
985
|
if (measuredSize < this.config.minVendorSharedTransformedSize) continue;
|
|
@@ -1033,8 +1036,14 @@ export default class BundleGenerator {
|
|
|
1033
1036
|
/**
|
|
1034
1037
|
* Creates a bundle file
|
|
1035
1038
|
*/
|
|
1036
|
-
async createBundleFile(components, type, routePath) {
|
|
1037
|
-
|
|
1039
|
+
async createBundleFile(components, type, routePath, bundleKey = null) {
|
|
1040
|
+
// The key — not the route path — names the file. Size-split parts of one
|
|
1041
|
+
// route (`playground--p1`, `--p2`) share a `path`, so deriving the name from
|
|
1042
|
+
// the path makes every part collide on `slice-bundle.playground.js` and the
|
|
1043
|
+
// last one written wins, silently dropping the other parts' components.
|
|
1044
|
+
const routeKey = bundleKey
|
|
1045
|
+
? this.routeToFileName(bundleKey)
|
|
1046
|
+
: (routePath ? this.routeToFileName(routePath) : 'critical');
|
|
1038
1047
|
const baseFileName = `slice-bundle.${routeKey}.js`;
|
|
1039
1048
|
|
|
1040
1049
|
const bundleContent = await this.generateBundleContent(
|
|
@@ -1578,7 +1587,7 @@ export default class BundleGenerator {
|
|
|
1578
1587
|
});
|
|
1579
1588
|
}
|
|
1580
1589
|
|
|
1581
|
-
return this.generateBundleFileContent(fileName, type, this.sortComponentsByName(bundleComponents), routePath);
|
|
1590
|
+
return this.generateBundleFileContent(fileName, type, this.sortComponentsByName(bundleComponents), routePath, bundleKey);
|
|
1582
1591
|
}
|
|
1583
1592
|
|
|
1584
1593
|
classFactoryName(componentName) {
|
|
@@ -1593,13 +1602,19 @@ export default class BundleGenerator {
|
|
|
1593
1602
|
.join('\n');
|
|
1594
1603
|
}
|
|
1595
1604
|
|
|
1596
|
-
generateBundleFileContent(fileName, type, components, routePath = null) {
|
|
1605
|
+
generateBundleFileContent(fileName, type, components, routePath = null, bundleKeyOverride = null) {
|
|
1597
1606
|
const uniqueComponents = this.dedupeComponentsByName(components || []);
|
|
1607
|
+
// `bundleKeyOverride` carries the split-aware key (`playground--p1`) so the
|
|
1608
|
+
// emitted META matches the key the runtime looks up in `routeBundles`.
|
|
1598
1609
|
const bundleKey = type === 'critical'
|
|
1599
1610
|
? 'critical'
|
|
1600
1611
|
: type === 'framework'
|
|
1601
1612
|
? 'framework'
|
|
1602
|
-
: this.routeToFileName(
|
|
1613
|
+
: this.routeToFileName(
|
|
1614
|
+
bundleKeyOverride
|
|
1615
|
+
|| routePath
|
|
1616
|
+
|| fileName.replace('slice-bundle.', '').replace('.js', '')
|
|
1617
|
+
);
|
|
1603
1618
|
|
|
1604
1619
|
const dependencyModules = this.collectDependencyModulesFromComponents(uniqueComponents);
|
|
1605
1620
|
const isRouteBundle = type === 'route';
|
|
@@ -1745,11 +1760,21 @@ export default class BundleGenerator {
|
|
|
1745
1760
|
.filter((mi) => mi.specifier && mi.depName)
|
|
1746
1761
|
.map((mi) => [mi.specifier, mi.depName])
|
|
1747
1762
|
);
|
|
1763
|
+
// Every specifier this module's imports were analyzed under — bare ones by
|
|
1764
|
+
// name, relative ones by the specifier as written. Each has its module
|
|
1765
|
+
// emitted in this block and its bindings re-created below, so stripping the
|
|
1766
|
+
// original statement loses nothing and must not warn.
|
|
1767
|
+
const handledSpecifiers = new Set(
|
|
1768
|
+
(module.moduleImports || [])
|
|
1769
|
+
.map((mi) => (mi.external ? mi.depName : mi.specifier))
|
|
1770
|
+
.filter((specifier) => typeof specifier === 'string')
|
|
1771
|
+
);
|
|
1748
1772
|
const transformedContent = this.transformDependencyContent(module.content, '__sliceExports', module.name, {
|
|
1749
1773
|
// A re-export inside this helper must resolve its source through the same
|
|
1750
1774
|
// shared resolver the bundle uses, since the source may live in vendor-shared.
|
|
1751
1775
|
preferShared: !!options.includeSharedResolver,
|
|
1752
|
-
specifierToKey
|
|
1776
|
+
specifierToKey,
|
|
1777
|
+
handledSpecifiers
|
|
1753
1778
|
});
|
|
1754
1779
|
// Bind this module's own (transitive) imports inside its IIFE — they were
|
|
1755
1780
|
// registered by earlier modules in the topological order.
|
|
@@ -2234,12 +2259,21 @@ if (window.slice && window.slice.controller) {
|
|
|
2234
2259
|
const specifierToKey = options.specifierToKey || null;
|
|
2235
2260
|
|
|
2236
2261
|
if (node.type === 'ImportDeclaration') {
|
|
2237
|
-
//
|
|
2238
|
-
//
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2262
|
+
// An import listed in `handledSpecifiers` is not dropped: the caller
|
|
2263
|
+
// re-emits it as an IIFE-scoped binding (buildDependencyBindings), and
|
|
2264
|
+
// removing the original statement is the second half of that rewrite.
|
|
2265
|
+
// Only an import nothing rebinds is actually lost — warn for that one.
|
|
2266
|
+
const specifier = node.source?.value;
|
|
2267
|
+
const handled = options.handledSpecifiers instanceof Set
|
|
2268
|
+
&& typeof specifier === 'string'
|
|
2269
|
+
&& options.handledSpecifiers.has(specifier);
|
|
2270
|
+
|
|
2271
|
+
if (!handled && !options.silent) {
|
|
2272
|
+
console.warn(this.buildImportWarningMessage(
|
|
2273
|
+
`Warning: Stripping unsupported import inside bundled dependency: ${specifier}`,
|
|
2274
|
+
moduleName
|
|
2275
|
+
));
|
|
2276
|
+
}
|
|
2243
2277
|
return '';
|
|
2244
2278
|
}
|
|
2245
2279
|
|