slicejs-cli 4.4.0 → 4.6.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/client.js +192 -82
- package/commands/Print.js +158 -164
- package/commands/build/build.js +27 -1
- package/commands/buildProduction/buildProduction.js +42 -71
- package/commands/bundle/bundle.js +65 -60
- package/commands/docs/agents.js +260 -0
- package/commands/docs/events.js +365 -0
- package/commands/docs/index.js +123 -0
- package/commands/doctor/doctor.js +99 -12
- package/commands/export/checkExport.js +163 -0
- package/commands/export/clientRedirects.js +72 -0
- package/commands/export/copyDist.js +180 -0
- package/commands/export/export.js +236 -0
- package/commands/export/files.js +33 -0
- package/commands/export/hosts/cloudflare.js +48 -0
- package/commands/export/hosts/github.js +31 -0
- package/commands/export/hosts/index.js +69 -0
- package/commands/export/hosts/netlify.js +42 -0
- package/commands/export/hosts/nginx.js +73 -0
- package/commands/export/hosts/none.js +23 -0
- package/commands/export/hosts/s3.js +24 -0
- package/commands/export/hosts/shared.js +62 -0
- package/commands/export/hosts/vercel.js +69 -0
- package/commands/export/outDir.js +91 -0
- package/commands/export/prerender.js +121 -0
- package/commands/getComponent/getComponent.js +44 -40
- package/commands/init/init.js +32 -22
- package/commands/lint/lint.js +2 -2
- package/commands/lint/types.js +1 -1
- package/commands/listComponents/listComponents.js +205 -172
- package/commands/seo/check.js +7 -4
- package/commands/seo/images.js +77 -22
- package/commands/seo/sitemap.js +6 -3
- package/commands/seo/support.js +62 -0
- package/commands/setup/lint.js +1 -1
- package/commands/skill/skill.js +2 -2
- package/commands/startServer/startServer.js +60 -21
- package/commands/startServer/watchServer.js +3 -3
- package/commands/translator/check.js +32 -0
- package/commands/translator/init.js +125 -0
- package/commands/translator/scan.js +444 -0
- package/commands/typecheck/typecheck.js +2 -2
- package/commands/types/types.js +22 -3
- package/commands/utils/VersionChecker.js +14 -14
- package/commands/utils/bundling/BundleGenerator.js +45 -27
- package/commands/utils/bundling/DependencyAnalyzer.js +1007 -976
- package/commands/utils/componentCatalog.js +120 -0
- package/commands/utils/publicEnv.js +74 -0
- package/commands/utils/sliceConfigSchema.js +34 -0
- package/commands/utils/updateManager.js +12 -12
- package/package.json +22 -23
|
@@ -35,6 +35,10 @@ export default class BundleGenerator {
|
|
|
35
35
|
this.srcPath = getSrcPath(moduleUrl);
|
|
36
36
|
this.distPath = getDistPath(moduleUrl);
|
|
37
37
|
this.output = options.output || 'dist';
|
|
38
|
+
this.verbose = !!options.verbose;
|
|
39
|
+
// Import warnings are deduped: the same missing import can be reached from
|
|
40
|
+
// several bundled modules, and each occurrence is not a new problem.
|
|
41
|
+
this.warningMessages = new Set();
|
|
38
42
|
this.bundlesPath = this.output === 'dist'
|
|
39
43
|
? path.join(this.distPath, 'bundles')
|
|
40
44
|
: path.join(this.srcPath, 'bundles');
|
|
@@ -170,8 +174,6 @@ export default class BundleGenerator {
|
|
|
170
174
|
* Generates all bundles
|
|
171
175
|
*/
|
|
172
176
|
async generate() {
|
|
173
|
-
console.log('🔨 Generating bundles...');
|
|
174
|
-
|
|
175
177
|
// 0. Create bundles directory
|
|
176
178
|
await fs.ensureDir(this.bundlesPath);
|
|
177
179
|
if (this.output === 'dist') {
|
|
@@ -214,8 +216,6 @@ export default class BundleGenerator {
|
|
|
214
216
|
console.warn(`Warning: emitted bundle(s) never referenced by any route: ${integrity.orphans.join(', ')}`);
|
|
215
217
|
}
|
|
216
218
|
|
|
217
|
-
console.log('✅ Bundles generated successfully');
|
|
218
|
-
|
|
219
219
|
return {
|
|
220
220
|
bundles: this.bundles,
|
|
221
221
|
config,
|
|
@@ -233,13 +233,13 @@ export default class BundleGenerator {
|
|
|
233
233
|
// Strategy based on size and usage pattern
|
|
234
234
|
if (totalComponents < 20 || sharedPercentage > 60) {
|
|
235
235
|
this.config.strategy = 'global';
|
|
236
|
-
console.log('
|
|
236
|
+
if (this.verbose) console.log('Strategy: global bundle (small project or highly shared)');
|
|
237
237
|
} else if (totalComponents < 100) {
|
|
238
238
|
this.config.strategy = 'hybrid';
|
|
239
|
-
console.log('
|
|
239
|
+
if (this.verbose) console.log('Strategy: hybrid (critical + grouped routes)');
|
|
240
240
|
} else {
|
|
241
241
|
this.config.strategy = 'per-route';
|
|
242
|
-
console.log('
|
|
242
|
+
if (this.verbose) console.log('Strategy: per route (large project)');
|
|
243
243
|
}
|
|
244
244
|
}
|
|
245
245
|
|
|
@@ -307,7 +307,7 @@ export default class BundleGenerator {
|
|
|
307
307
|
this.bundles.critical.size = this.componentsBudgetSize(this.bundles.critical.components);
|
|
308
308
|
}
|
|
309
309
|
|
|
310
|
-
console.log(
|
|
310
|
+
if (this.verbose) console.log(`✔ Critical bundle: ${this.bundles.critical.components.length} components, ${(this.bundles.critical.size / 1024).toFixed(1)} KB`);
|
|
311
311
|
}
|
|
312
312
|
|
|
313
313
|
/**
|
|
@@ -368,7 +368,7 @@ export default class BundleGenerator {
|
|
|
368
368
|
file: `slice-bundle.${routeKey}.js`
|
|
369
369
|
};
|
|
370
370
|
|
|
371
|
-
console.log(
|
|
371
|
+
if (this.verbose) console.log(`✔ Bundle ${routeKey}: ${uniqueComponents.length} components, ${(totalSize / 1024).toFixed(1)} KB`);
|
|
372
372
|
}
|
|
373
373
|
}
|
|
374
374
|
|
|
@@ -439,7 +439,7 @@ export default class BundleGenerator {
|
|
|
439
439
|
file: `slice-bundle.${this.routeToFileName(groupKey)}.js`
|
|
440
440
|
};
|
|
441
441
|
|
|
442
|
-
console.log(
|
|
442
|
+
if (this.verbose) console.log(`✔ Bundle ${groupKey}: ${uniqueComponents.length} components, ${(totalSize / 1024).toFixed(1)} KB (${groupData.routes.length} routes)`);
|
|
443
443
|
}
|
|
444
444
|
}
|
|
445
445
|
}
|
|
@@ -496,7 +496,7 @@ export default class BundleGenerator {
|
|
|
496
496
|
file: `slice-bundle.${this.routeToFileName(category)}.js`
|
|
497
497
|
};
|
|
498
498
|
|
|
499
|
-
console.log(
|
|
499
|
+
if (this.verbose) console.log(`✔ Bundle ${category}: ${uniqueComponents.length} components, ${(totalSize / 1024).toFixed(1)} KB (${routes.length} routes)`);
|
|
500
500
|
}
|
|
501
501
|
}
|
|
502
502
|
|
|
@@ -1584,14 +1584,14 @@ export default class BundleGenerator {
|
|
|
1584
1584
|
|
|
1585
1585
|
if (needsDefault.size === 0) return;
|
|
1586
1586
|
|
|
1587
|
-
console.log(
|
|
1587
|
+
if (this.verbose) console.log(`Resolving ${needsDefault.size} external dependenc${needsDefault.size === 1 ? 'y' : 'ies'} from node_modules...`);
|
|
1588
1588
|
|
|
1589
1589
|
for (const [name, nd] of needsDefault) {
|
|
1590
1590
|
try {
|
|
1591
1591
|
const { expression, warnings } = await this.getExternalBundler().bundle(name, { needsDefault: nd });
|
|
1592
1592
|
this.externalModulesByName.set(name, expression);
|
|
1593
1593
|
warnings.forEach((w) => console.warn(`Warning: [external:${name}] ${w}`));
|
|
1594
|
-
console.log(`
|
|
1594
|
+
if (this.verbose) console.log(` ✔ ${name}`);
|
|
1595
1595
|
} catch (error) {
|
|
1596
1596
|
this.externalResolutionErrors.set(name, error.message);
|
|
1597
1597
|
console.warn(`Warning: ${error.message}`);
|
|
@@ -2730,10 +2730,10 @@ if (window.slice && window.slice.controller) {
|
|
|
2730
2730
|
&& options.handledSpecifiers.has(specifier);
|
|
2731
2731
|
|
|
2732
2732
|
if (!handled && !options.silent) {
|
|
2733
|
-
|
|
2733
|
+
this.recordImportWarning(
|
|
2734
2734
|
`Warning: Stripping unsupported import inside bundled dependency: ${specifier}`,
|
|
2735
2735
|
moduleName
|
|
2736
|
-
)
|
|
2736
|
+
);
|
|
2737
2737
|
}
|
|
2738
2738
|
return '';
|
|
2739
2739
|
}
|
|
@@ -2744,10 +2744,10 @@ if (window.slice && window.slice.controller) {
|
|
|
2744
2744
|
// object. The source module is registered earlier by the topological order.
|
|
2745
2745
|
const depExpr = this.reexportDependencyExpression(moduleName, node.source?.value, preferShared, specifierToKey);
|
|
2746
2746
|
if (!depExpr) {
|
|
2747
|
-
|
|
2747
|
+
this.recordImportWarning(
|
|
2748
2748
|
`Warning: Dropping unresolvable 'export *' inside bundled dependency: ${node.source?.value}`,
|
|
2749
2749
|
moduleName
|
|
2750
|
-
)
|
|
2750
|
+
);
|
|
2751
2751
|
return '';
|
|
2752
2752
|
}
|
|
2753
2753
|
const tmp = `__sliceReexportAll_${node.start}`;
|
|
@@ -2774,10 +2774,10 @@ if (window.slice && window.slice.controller) {
|
|
|
2774
2774
|
// the corresponding member of the resolved module's exports object.
|
|
2775
2775
|
const depExpr = this.reexportDependencyExpression(moduleName, node.source.value, preferShared, specifierToKey);
|
|
2776
2776
|
if (!depExpr) {
|
|
2777
|
-
|
|
2777
|
+
this.recordImportWarning(
|
|
2778
2778
|
`Warning: Dropping unresolvable re-export inside bundled dependency: ${node.source.value}`,
|
|
2779
2779
|
moduleName
|
|
2780
|
-
)
|
|
2780
|
+
);
|
|
2781
2781
|
return '';
|
|
2782
2782
|
}
|
|
2783
2783
|
const tmp = `__sliceReexport_${node.start}`;
|
|
@@ -3275,8 +3275,26 @@ if (window.slice && window.slice.controller) {
|
|
|
3275
3275
|
}
|
|
3276
3276
|
|
|
3277
3277
|
buildImportWarningMessage(baseMessage, sourceContext) {
|
|
3278
|
-
|
|
3279
|
-
return
|
|
3278
|
+
const message = String(baseMessage).replace(/^Warning:\s*/, '');
|
|
3279
|
+
if (!sourceContext) return `! ${message}`;
|
|
3280
|
+
// Keep warnings readable: the full absolute path of a framework dependency
|
|
3281
|
+
// adds noise without helping identify the file. Two trailing segments are
|
|
3282
|
+
// enough (`Controller/Controller.js`).
|
|
3283
|
+
const short = sourceContext.includes(path.sep)
|
|
3284
|
+
? sourceContext.split(path.sep).slice(-2).join('/')
|
|
3285
|
+
: sourceContext;
|
|
3286
|
+
return `! ${message} (${short})`;
|
|
3287
|
+
}
|
|
3288
|
+
|
|
3289
|
+
/**
|
|
3290
|
+
* Prints one `!` warning per unique import problem. Duplicates are common when
|
|
3291
|
+
* the same module is reached from several bundles.
|
|
3292
|
+
*/
|
|
3293
|
+
recordImportWarning(baseMessage, sourceContext) {
|
|
3294
|
+
const message = this.buildImportWarningMessage(baseMessage, sourceContext);
|
|
3295
|
+
if (this.warningMessages.has(message)) return;
|
|
3296
|
+
this.warningMessages.add(message);
|
|
3297
|
+
console.warn(message);
|
|
3280
3298
|
}
|
|
3281
3299
|
|
|
3282
3300
|
extractLocalBindingsFromImportStatement(statement) {
|
|
@@ -3437,7 +3455,7 @@ if (window.slice && window.slice.controller) {
|
|
|
3437
3455
|
cleanedCode += statement;
|
|
3438
3456
|
}
|
|
3439
3457
|
} else if (classification.warning) {
|
|
3440
|
-
|
|
3458
|
+
this.recordImportWarning(classification.warning, sourceContext);
|
|
3441
3459
|
}
|
|
3442
3460
|
cursor = end;
|
|
3443
3461
|
}
|
|
@@ -3474,7 +3492,7 @@ if (window.slice && window.slice.controller) {
|
|
|
3474
3492
|
cleaned += statement;
|
|
3475
3493
|
}
|
|
3476
3494
|
} else if (classification.warning) {
|
|
3477
|
-
|
|
3495
|
+
this.recordImportWarning(classification.warning, sourceContext);
|
|
3478
3496
|
}
|
|
3479
3497
|
|
|
3480
3498
|
cursor = node.end;
|
|
@@ -3574,10 +3592,10 @@ if (window.slice && window.slice.controller) {
|
|
|
3574
3592
|
// attach one to. Dropping it costs nothing inside the bundle, but it means
|
|
3575
3593
|
// this file is acting as a barrel — worth saying so out loud.
|
|
3576
3594
|
if (node.source) {
|
|
3577
|
-
|
|
3595
|
+
this.recordImportWarning(
|
|
3578
3596
|
`Warning: Dropping re-export '${code.slice(node.start, node.end).split('\n')[0].trim()}' from a component file (not supported in bundles)`,
|
|
3579
3597
|
sourceContext
|
|
3580
|
-
)
|
|
3598
|
+
);
|
|
3581
3599
|
return '';
|
|
3582
3600
|
}
|
|
3583
3601
|
|
|
@@ -3699,8 +3717,8 @@ if (window.slice && window.slice.controller) {
|
|
|
3699
3717
|
const jsConfig = this.generateBundleConfigJS(config);
|
|
3700
3718
|
await fs.writeFile(jsConfigPath, jsConfig, 'utf-8');
|
|
3701
3719
|
|
|
3702
|
-
console.log(
|
|
3703
|
-
console.log(
|
|
3720
|
+
if (this.verbose) console.log(`✔ Configuration saved to ${configPath}`);
|
|
3721
|
+
if (this.verbose) console.log(`✔ JavaScript config generated: ${jsConfigPath}`);
|
|
3704
3722
|
}
|
|
3705
3723
|
|
|
3706
3724
|
/**
|