@module-federation/treeshake-server 0.0.1 → 0.23.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/bin/treeshake-server.js +35 -0
- package/dist/domain/build/normalize-config.d.ts +1 -0
- package/dist/frontend/index.html +1 -1
- package/dist/frontend/static/js/{954.dfe166a3.js → 296.084d1b43.js} +2 -2
- package/dist/frontend/static/js/async/873.21368adc.js +2 -0
- package/dist/frontend/static/js/async/{987.6bf8e9b0.js → 987.86ff6794.js} +2 -2
- package/dist/frontend/static/js/{index.db4e73c6.js → index.5488f626.js} +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +96 -46
- package/dist/index.mjs +92 -44
- package/dist/server.js +94 -44
- package/dist/server.mjs +91 -43
- package/dist/services/buildService.d.ts +2 -2
- package/dist/services/uploadService.d.ts +1 -1
- package/dist/template/re-shake-share/package.json +2 -2
- package/package.json +18 -11
- package/dist/frontend/static/js/async/873.6ccd5409.js +0 -2
- /package/dist/frontend/static/js/{954.dfe166a3.js.LICENSE.txt → 296.084d1b43.js.LICENSE.txt} +0 -0
- /package/dist/frontend/static/js/async/{987.6bf8e9b0.js.LICENSE.txt → 987.86ff6794.js.LICENSE.txt} +0 -0
package/dist/server.mjs
CHANGED
|
@@ -4,11 +4,13 @@ import node_path from "node:path";
|
|
|
4
4
|
import pino from "pino";
|
|
5
5
|
import { Hono } from "hono";
|
|
6
6
|
import { cors } from "hono/cors";
|
|
7
|
+
import node_os from "node:os";
|
|
7
8
|
import { zValidator } from "@hono/zod-validator";
|
|
8
9
|
import { nanoid } from "nanoid";
|
|
10
|
+
import p_limit from "p-limit";
|
|
9
11
|
import { z } from "zod";
|
|
10
12
|
import { createHash } from "node:crypto";
|
|
11
|
-
import
|
|
13
|
+
import promises from "node:fs/promises";
|
|
12
14
|
import { spawn } from "node:child_process";
|
|
13
15
|
import json_stable_stringify from "json-stable-stringify";
|
|
14
16
|
import { serve } from "@hono/node-server";
|
|
@@ -71,7 +73,8 @@ class LocalObjectStore {
|
|
|
71
73
|
_define_property(this, "rootDir", void 0);
|
|
72
74
|
_define_property(this, "publicBaseUrl", void 0);
|
|
73
75
|
this.rootDir = (null == opts ? void 0 : opts.rootDir) ?? node_path.join(process.cwd(), 'log', 'static');
|
|
74
|
-
const
|
|
76
|
+
const port = process.env.PORT || 3000;
|
|
77
|
+
const base = (null == opts ? void 0 : opts.publicBaseUrl) === '/' ? `http://localhost:${port}/` : (null == opts ? void 0 : opts.publicBaseUrl) ?? '/';
|
|
75
78
|
this.publicBaseUrl = base.endsWith('/') ? base : `${base}/`;
|
|
76
79
|
}
|
|
77
80
|
}
|
|
@@ -238,14 +241,15 @@ function normalizeConfig(config) {
|
|
|
238
241
|
return normalizedConfig;
|
|
239
242
|
}
|
|
240
243
|
function extractBuildConfig(config, type) {
|
|
241
|
-
const { shared, plugins, target, libraryType, usedExports } = config;
|
|
244
|
+
const { shared, plugins, target, libraryType, usedExports, hostName } = config;
|
|
242
245
|
return {
|
|
243
246
|
shared,
|
|
244
247
|
plugins,
|
|
245
248
|
target,
|
|
246
249
|
libraryType,
|
|
247
250
|
usedExports,
|
|
248
|
-
type
|
|
251
|
+
type,
|
|
252
|
+
hostName
|
|
249
253
|
};
|
|
250
254
|
}
|
|
251
255
|
const UploadOptionsSchema = z.object({
|
|
@@ -374,11 +378,11 @@ const startPeriodicPrune = (intervalMs = DEFAULT_INTERVAL)=>{
|
|
|
374
378
|
maybePrune();
|
|
375
379
|
}, intervalMs);
|
|
376
380
|
};
|
|
377
|
-
const createUniqueTempDirByKey = (key)=>{
|
|
381
|
+
const createUniqueTempDirByKey = async (key)=>{
|
|
378
382
|
const base = node_path.join(node_os.tmpdir(), `re-shake-share-${key}`);
|
|
379
383
|
let candidate = base;
|
|
380
384
|
for(;;)try {
|
|
381
|
-
|
|
385
|
+
await promises.mkdir(candidate, {
|
|
382
386
|
recursive: false
|
|
383
387
|
});
|
|
384
388
|
return candidate;
|
|
@@ -387,15 +391,22 @@ const createUniqueTempDirByKey = (key)=>{
|
|
|
387
391
|
candidate = `${base}-${rand}`;
|
|
388
392
|
}
|
|
389
393
|
};
|
|
390
|
-
const prepareProject = (config, excludeShared)=>{
|
|
394
|
+
const prepareProject = async (config, excludeShared)=>{
|
|
391
395
|
const key = createHash('sha256').update(JSON.stringify(config)).digest('hex');
|
|
392
|
-
const dir = createUniqueTempDirByKey(key);
|
|
393
|
-
const templateDir = node_path.join(__dirname, '
|
|
394
|
-
|
|
396
|
+
const dir = await createUniqueTempDirByKey(key);
|
|
397
|
+
const templateDir = node_path.join(__dirname, '.', 'template', 're-shake-share');
|
|
398
|
+
await promises.cp(templateDir, dir, {
|
|
395
399
|
recursive: true
|
|
396
400
|
});
|
|
397
401
|
const pkgPath = node_path.join(dir, 'package.json');
|
|
398
|
-
const
|
|
402
|
+
const indexPath = node_path.join(dir, 'index.ts');
|
|
403
|
+
const rspackConfigPath = node_path.join(dir, 'rspack.config.ts');
|
|
404
|
+
const [pkgContent, indexContent, rspackConfigContent] = await Promise.all([
|
|
405
|
+
promises.readFile(pkgPath, 'utf-8'),
|
|
406
|
+
promises.readFile(indexPath, 'utf-8'),
|
|
407
|
+
promises.readFile(rspackConfigPath, 'utf-8')
|
|
408
|
+
]);
|
|
409
|
+
const pkg = JSON.parse(pkgContent);
|
|
399
410
|
const deps = {
|
|
400
411
|
...pkg.dependencies || {}
|
|
401
412
|
};
|
|
@@ -436,25 +447,26 @@ const prepareProject = (config, excludeShared)=>{
|
|
|
436
447
|
});
|
|
437
448
|
pluginOptionStr += '\n]';
|
|
438
449
|
pkg.dependencies = deps;
|
|
439
|
-
|
|
450
|
+
const newPkgContent = JSON.stringify(pkg, null, 2);
|
|
440
451
|
const sharedImportPlaceholder = "${SHARED_IMPORT}";
|
|
452
|
+
const newIndexContent = indexContent.replace(sharedImportPlaceholder, sharedImport);
|
|
441
453
|
const pluginsPlaceholder = "${ PLUGINS }";
|
|
442
454
|
const mfConfigPlaceholder = "${ MF_CONFIG }";
|
|
443
|
-
|
|
444
|
-
const indexContent = node_fs.readFileSync(indexPath, 'utf-8');
|
|
445
|
-
node_fs.writeFileSync(indexPath, indexContent.replace(sharedImportPlaceholder, sharedImport));
|
|
446
|
-
const rspackConfigPath = node_path.join(dir, 'rspack.config.ts');
|
|
447
|
-
let cfg = node_fs.readFileSync(rspackConfigPath, 'utf-8');
|
|
455
|
+
let cfg = rspackConfigContent;
|
|
448
456
|
cfg += pluginImportStr;
|
|
449
457
|
cfg = cfg.replace(pluginsPlaceholder, pluginOptionStr);
|
|
450
458
|
cfg = cfg.replace(mfConfigPlaceholder, JSON.stringify(mfConfig, null, 2));
|
|
451
|
-
|
|
459
|
+
await Promise.all([
|
|
460
|
+
promises.writeFile(pkgPath, newPkgContent),
|
|
461
|
+
promises.writeFile(indexPath, newIndexContent),
|
|
462
|
+
promises.writeFile(rspackConfigPath, cfg)
|
|
463
|
+
]);
|
|
452
464
|
return dir;
|
|
453
465
|
};
|
|
454
466
|
const installDependencies = async (cwd)=>{
|
|
455
467
|
markInstallStart();
|
|
456
468
|
try {
|
|
457
|
-
await runCommand(
|
|
469
|
+
await runCommand("pnpm i --ignore-scripts --prefer-offline --reporter=silent ", {
|
|
458
470
|
cwd,
|
|
459
471
|
env: {
|
|
460
472
|
npm_config_registry: 'https://registry.npmjs.org/'
|
|
@@ -472,12 +484,13 @@ const buildProject = async (cwd, type)=>{
|
|
|
472
484
|
cwd
|
|
473
485
|
})));
|
|
474
486
|
};
|
|
475
|
-
const retrieveSharedFilepaths = (projectDir, type)=>{
|
|
487
|
+
const retrieveSharedFilepaths = async (projectDir, type)=>{
|
|
476
488
|
const sharedFilepaths = [];
|
|
477
|
-
const collectSharedFilepaths = (t)=>{
|
|
489
|
+
const collectSharedFilepaths = async (t)=>{
|
|
478
490
|
const dir = 'full' === t ? 'full-shared' : 'dist';
|
|
479
491
|
const distDir = node_path.join(projectDir, dir);
|
|
480
|
-
const
|
|
492
|
+
const statsContent = await promises.readFile(node_path.join(distDir, STATS_NAME), 'utf-8');
|
|
493
|
+
const stats = JSON.parse(statsContent);
|
|
481
494
|
stats.shared.forEach((s)=>{
|
|
482
495
|
const { name, version, fallback, fallbackName } = s;
|
|
483
496
|
if (fallback && fallbackName) {
|
|
@@ -495,22 +508,31 @@ const retrieveSharedFilepaths = (projectDir, type)=>{
|
|
|
495
508
|
}
|
|
496
509
|
});
|
|
497
510
|
};
|
|
498
|
-
collectSharedFilepaths(type);
|
|
511
|
+
await collectSharedFilepaths(type);
|
|
499
512
|
return sharedFilepaths;
|
|
500
513
|
};
|
|
501
514
|
const runBuild = async (normalizedConfig, excludeShared, type)=>{
|
|
502
|
-
const
|
|
515
|
+
const tStart = Date.now();
|
|
516
|
+
const tmpDir = await prepareProject(normalizedConfig, excludeShared);
|
|
517
|
+
const tPrepare = Date.now();
|
|
518
|
+
logger_logger.info(`prepareProject took ${tPrepare - tStart}ms`);
|
|
503
519
|
await installDependencies(tmpDir);
|
|
520
|
+
const tInstall = Date.now();
|
|
521
|
+
logger_logger.info(`installDependencies took ${tInstall - tPrepare}ms`);
|
|
504
522
|
await buildProject(tmpDir, type);
|
|
505
|
-
const
|
|
523
|
+
const tBuild = Date.now();
|
|
524
|
+
logger_logger.info(`buildProject took ${tBuild - tInstall}ms`);
|
|
525
|
+
const sharedFilePaths = await retrieveSharedFilepaths(tmpDir, type);
|
|
526
|
+
const tRetrieve = Date.now();
|
|
527
|
+
logger_logger.info(`retrieveSharedFilepaths took ${tRetrieve - tBuild}ms`);
|
|
506
528
|
return {
|
|
507
529
|
sharedFilePaths,
|
|
508
530
|
dir: tmpDir
|
|
509
531
|
};
|
|
510
532
|
};
|
|
511
|
-
function cleanUp(tmpDir) {
|
|
533
|
+
async function cleanUp(tmpDir) {
|
|
512
534
|
if (!tmpDir) return;
|
|
513
|
-
|
|
535
|
+
await promises.rm(tmpDir, {
|
|
514
536
|
recursive: true,
|
|
515
537
|
force: true
|
|
516
538
|
});
|
|
@@ -608,7 +630,7 @@ async function uploadToCacheStore(sharedFilePaths, normalizedConfig, store) {
|
|
|
608
630
|
const jsonFilePath = filepath.replace(/\.js$/, '.json');
|
|
609
631
|
const jsonFile = JSON.stringify(res);
|
|
610
632
|
const jsonCdnUrl = cdnPath.replace(/\.js$/, '.json');
|
|
611
|
-
|
|
633
|
+
await promises.writeFile(jsonFilePath, jsonFile);
|
|
612
634
|
await store.uploadFile(jsonFilePath, jsonCdnUrl);
|
|
613
635
|
} catch (error) {
|
|
614
636
|
logger_logger.error(`Failed to upload ${name}@${version} json file: ${error}`);
|
|
@@ -626,25 +648,26 @@ const downloadToFile = async (url, destPath)=>{
|
|
|
626
648
|
const res = await fetch(url);
|
|
627
649
|
if (!res.ok) throw new Error(`Download failed: ${res.status} ${res.statusText} - ${url}`);
|
|
628
650
|
const buf = Buffer.from(await res.arrayBuffer());
|
|
629
|
-
await
|
|
651
|
+
await promises.mkdir(node_path.dirname(destPath), {
|
|
630
652
|
recursive: true
|
|
631
653
|
});
|
|
632
|
-
await
|
|
654
|
+
await promises.writeFile(destPath, buf);
|
|
633
655
|
return destPath;
|
|
634
656
|
};
|
|
635
|
-
async function uploadProject(uploadResults, sharedFilePaths, normalizedConfig, publisher) {
|
|
636
|
-
const tmpDir = createUniqueTempDirByKey(`upload-project${Date.now().toString()}`);
|
|
657
|
+
async function uploadProject(uploadResults, sharedFilePaths, normalizedConfig, publisher, store) {
|
|
658
|
+
const tmpDir = await createUniqueTempDirByKey(`upload-project${Date.now().toString()}`);
|
|
637
659
|
const uploaded = [];
|
|
638
660
|
try {
|
|
639
661
|
for (const item of uploadResults)try {
|
|
640
|
-
const
|
|
662
|
+
const sharedKey = normalizedKey(item.name, item.version);
|
|
663
|
+
const config = normalizedConfig[sharedKey];
|
|
641
664
|
if (!config) {
|
|
642
665
|
logger_logger.error(`No config found for ${item.name}`);
|
|
643
666
|
continue;
|
|
644
667
|
}
|
|
645
668
|
const { uploadOptions } = config;
|
|
646
669
|
if (!uploadOptions) throw new Error(`No uploadOptions found for ${item.name}`);
|
|
647
|
-
const filename = node_path.basename(new URL(item.cdnUrl).pathname);
|
|
670
|
+
const filename = node_path.basename(new URL(item.cdnUrl, 'http://dummy.com').pathname);
|
|
648
671
|
const localPath = node_path.join(tmpDir, filename);
|
|
649
672
|
const hash = createCacheHash({
|
|
650
673
|
...config,
|
|
@@ -713,9 +736,11 @@ async function uploadProject(uploadResults, sharedFilePaths, normalizedConfig, p
|
|
|
713
736
|
}
|
|
714
737
|
return uploaded;
|
|
715
738
|
} finally{
|
|
716
|
-
|
|
739
|
+
promises.rm(tmpDir, {
|
|
717
740
|
recursive: true,
|
|
718
741
|
force: true
|
|
742
|
+
}).catch((err)=>{
|
|
743
|
+
logger_logger.error(`Failed to cleanup dir ${tmpDir}: ${err}`);
|
|
719
744
|
});
|
|
720
745
|
}
|
|
721
746
|
}
|
|
@@ -724,14 +749,14 @@ async function upload(sharedFilePaths, uploadResults, normalizedConfig, uploadOp
|
|
|
724
749
|
if (!uploadOptions) {
|
|
725
750
|
const hydrated = await Promise.all(uploadResults.map(async (item)=>{
|
|
726
751
|
if ('full' !== item.type) return item;
|
|
727
|
-
const tmpDir = createUniqueTempDirByKey(`download-full-json${Date.now().toString()}`);
|
|
752
|
+
const tmpDir = await createUniqueTempDirByKey(`download-full-json${Date.now().toString()}`);
|
|
728
753
|
const jsonPath = node_path.join(tmpDir, `${item.name}-${item.version}.json`);
|
|
729
754
|
try {
|
|
730
755
|
const tJson0 = Date.now();
|
|
731
756
|
await downloadToFile(item.cdnUrl.replace('.js', '.json'), jsonPath);
|
|
732
757
|
const tJson = Date.now() - tJson0;
|
|
733
758
|
logger_logger.info(`Downloaded ${item.name}@${item.version} json in ${tJson}ms`);
|
|
734
|
-
const jsonContent = JSON.parse(
|
|
759
|
+
const jsonContent = JSON.parse(await promises.readFile(jsonPath, 'utf8'));
|
|
735
760
|
return {
|
|
736
761
|
...item,
|
|
737
762
|
canTreeShaking: jsonContent.canTreeShaking,
|
|
@@ -744,7 +769,7 @@ async function upload(sharedFilePaths, uploadResults, normalizedConfig, uploadOp
|
|
|
744
769
|
canTreeShaking: item.canTreeShaking ?? true
|
|
745
770
|
};
|
|
746
771
|
} finally{
|
|
747
|
-
|
|
772
|
+
await promises.rm(tmpDir, {
|
|
748
773
|
recursive: true,
|
|
749
774
|
force: true
|
|
750
775
|
});
|
|
@@ -756,9 +781,10 @@ async function upload(sharedFilePaths, uploadResults, normalizedConfig, uploadOp
|
|
|
756
781
|
];
|
|
757
782
|
}
|
|
758
783
|
if (!publisher) throw new Error('uploadOptions provided but no projectPublisher configured (configure the selected adapter to enable it or omit uploadOptions)');
|
|
759
|
-
const projectUploadResults = await uploadProject(uploadResults, sharedFilePaths, normalizedConfig, publisher);
|
|
784
|
+
const projectUploadResults = await uploadProject(uploadResults, sharedFilePaths, normalizedConfig, publisher, store);
|
|
760
785
|
return projectUploadResults;
|
|
761
786
|
}
|
|
787
|
+
const buildLimit = p_limit(Math.max(1, node_os.cpus().length));
|
|
762
788
|
const buildRoute = new Hono();
|
|
763
789
|
buildRoute.post('/', zValidator('json', ConfigSchema), async (c)=>{
|
|
764
790
|
const logger = c.get('logger');
|
|
@@ -771,16 +797,27 @@ buildRoute.post('/', zValidator('json', ConfigSchema), async (c)=>{
|
|
|
771
797
|
const store = c.get('objectStore');
|
|
772
798
|
const publisher = c.get('projectPublisher');
|
|
773
799
|
try {
|
|
800
|
+
const t0 = Date.now();
|
|
774
801
|
const { cacheItems, excludeShared, restConfig } = await retrieveCacheItems(normalizedConfig, 're-shake', store);
|
|
802
|
+
const tRetrieveCache = Date.now();
|
|
803
|
+
logger.info(`retrieveCacheItems took ${tRetrieveCache - t0}ms`);
|
|
775
804
|
let sharedFilePaths = [];
|
|
776
805
|
let dir;
|
|
777
806
|
if (Object.keys(restConfig).length > 0) {
|
|
778
|
-
const buildResult = await runBuild(normalizedConfig, excludeShared, 're-shake');
|
|
807
|
+
const buildResult = await buildLimit(()=>runBuild(normalizedConfig, excludeShared, 're-shake'));
|
|
779
808
|
sharedFilePaths = buildResult.sharedFilePaths;
|
|
780
809
|
dir = buildResult.dir;
|
|
781
810
|
}
|
|
811
|
+
const tBuild = Date.now();
|
|
812
|
+
logger.info(`runBuild took ${tBuild - tRetrieveCache}ms`);
|
|
782
813
|
const uploadResults = await upload(sharedFilePaths, cacheItems, normalizedConfig, body.uploadOptions, store, publisher);
|
|
783
|
-
|
|
814
|
+
const tUpload = Date.now();
|
|
815
|
+
logger.info(`upload took ${tUpload - tBuild}ms`);
|
|
816
|
+
cleanUp(dir).catch((err)=>{
|
|
817
|
+
logger.error(`Failed to cleanup dir ${dir}: ${err}`);
|
|
818
|
+
});
|
|
819
|
+
const tCleanUp = Date.now();
|
|
820
|
+
logger.info(`cleanUp scheduled (non-blocking) took ${tCleanUp - tUpload}ms`);
|
|
784
821
|
return c.json({
|
|
785
822
|
jobId,
|
|
786
823
|
status: 'success',
|
|
@@ -818,16 +855,27 @@ async function handleCheckTreeshake(c, body) {
|
|
|
818
855
|
const store = c.get('objectStore');
|
|
819
856
|
const publisher = c.get('projectPublisher');
|
|
820
857
|
try {
|
|
858
|
+
const t0 = Date.now();
|
|
821
859
|
const { cacheItems, excludeShared, restConfig } = await retrieveCacheItems(normalizedConfig, 'full', store);
|
|
860
|
+
const tRetrieveCache = Date.now();
|
|
861
|
+
logger.info(`retrieveCacheItems took ${tRetrieveCache - t0}ms`);
|
|
822
862
|
let sharedFilePaths = [];
|
|
823
863
|
let dir;
|
|
824
864
|
if (Object.keys(restConfig).length > 0) {
|
|
825
|
-
const buildResult = await runBuild(normalizedConfig, excludeShared, 'full');
|
|
865
|
+
const buildResult = await buildLimit(()=>runBuild(normalizedConfig, excludeShared, 'full'));
|
|
826
866
|
sharedFilePaths = buildResult.sharedFilePaths;
|
|
827
867
|
dir = buildResult.dir;
|
|
828
868
|
}
|
|
869
|
+
const tBuild = Date.now();
|
|
870
|
+
logger.info(`runBuild took ${tBuild - tRetrieveCache}ms`);
|
|
829
871
|
const uploadResults = await upload(sharedFilePaths, cacheItems, normalizedConfig, body.uploadOptions, store, publisher);
|
|
830
|
-
|
|
872
|
+
const tUpload = Date.now();
|
|
873
|
+
logger.info(`upload took ${tUpload - tBuild}ms`);
|
|
874
|
+
cleanUp(dir).catch((err)=>{
|
|
875
|
+
logger.error(`Failed to cleanup dir ${dir}: ${err}`);
|
|
876
|
+
});
|
|
877
|
+
const tCleanUp = Date.now();
|
|
878
|
+
logger.info(`cleanUp scheduled (non-blocking) took ${tCleanUp - tUpload}ms`);
|
|
831
879
|
return c.json({
|
|
832
880
|
jobId,
|
|
833
881
|
status: 'success',
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type BuildType, type NormalizedConfig } from '../domain/build/normalize-config';
|
|
2
2
|
import type { SharedFilePath } from './uploadService';
|
|
3
|
-
export declare const createUniqueTempDirByKey: (key: string) => string
|
|
3
|
+
export declare const createUniqueTempDirByKey: (key: string) => Promise<string>;
|
|
4
4
|
export declare const runBuild: (normalizedConfig: NormalizedConfig, excludeShared: Array<[string, string]>, type: BuildType) => Promise<{
|
|
5
5
|
sharedFilePaths: SharedFilePath[];
|
|
6
6
|
dir: string;
|
|
7
7
|
}>;
|
|
8
|
-
export declare function cleanUp(tmpDir?: string): void
|
|
8
|
+
export declare function cleanUp(tmpDir?: string): Promise<void>;
|
|
@@ -32,5 +32,5 @@ export interface UploadOpts {
|
|
|
32
32
|
cdnRegion: string;
|
|
33
33
|
publicRoot: string;
|
|
34
34
|
}
|
|
35
|
-
export declare function uploadProject(uploadResults: UploadResult[], sharedFilePaths: SharedFilePath[], normalizedConfig: NormalizedConfig, publisher: ProjectPublisher): Promise<UploadResult[]>;
|
|
35
|
+
export declare function uploadProject(uploadResults: UploadResult[], sharedFilePaths: SharedFilePath[], normalizedConfig: NormalizedConfig, publisher: ProjectPublisher, store: ObjectStore): Promise<UploadResult[]>;
|
|
36
36
|
export declare function upload(sharedFilePaths: SharedFilePath[], uploadResults: UploadResult[], normalizedConfig: NormalizedConfig, uploadOptions: Config['uploadOptions'], store: ObjectStore, publisher?: ProjectPublisher): Promise<UploadResult[]>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/treeshake-server",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"description": "Build service powered by Hono that installs dependencies, builds with Rspack, and uploads artifacts.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -13,17 +13,10 @@
|
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
15
|
"bin": {
|
|
16
|
-
"treeshake-server": "
|
|
17
|
-
},
|
|
18
|
-
"scripts": {
|
|
19
|
-
"build": "pnpm -C ../treeshake-frontend build && rslib build && node scripts/copy-frontend.js",
|
|
20
|
-
"lint": "biome lint src scripts",
|
|
21
|
-
"prestart": "npm run build",
|
|
22
|
-
"dev": "node scripts/dev.js",
|
|
23
|
-
"start": "node dist/server.js",
|
|
24
|
-
"test": "rstest"
|
|
16
|
+
"treeshake-server": "bin/treeshake-server.js"
|
|
25
17
|
},
|
|
26
18
|
"files": [
|
|
19
|
+
"bin/",
|
|
27
20
|
"dist/",
|
|
28
21
|
"README.md"
|
|
29
22
|
],
|
|
@@ -37,6 +30,7 @@
|
|
|
37
30
|
"hono": "4.10.2",
|
|
38
31
|
"json-stable-stringify": "1.3.0",
|
|
39
32
|
"nanoid": "5.1.6",
|
|
33
|
+
"p-limit": "^7.2.0",
|
|
40
34
|
"pino": "10.1.0",
|
|
41
35
|
"undici": "5.29.0",
|
|
42
36
|
"zod": "4.1.12"
|
|
@@ -57,5 +51,18 @@
|
|
|
57
51
|
},
|
|
58
52
|
"publishConfig": {
|
|
59
53
|
"access": "public"
|
|
54
|
+
},
|
|
55
|
+
"repository": {
|
|
56
|
+
"type": "git",
|
|
57
|
+
"url": "git+https://github.com/module-federation/core.git",
|
|
58
|
+
"directory": "packages/treeshake-server"
|
|
59
|
+
},
|
|
60
|
+
"scripts": {
|
|
61
|
+
"build": "pnpm -C ../treeshake-frontend build && rslib build && node scripts/copy-frontend.js",
|
|
62
|
+
"lint": "biome lint src scripts",
|
|
63
|
+
"prestart": "npm run build",
|
|
64
|
+
"dev": "node scripts/dev.js",
|
|
65
|
+
"start": "node dist/server.js",
|
|
66
|
+
"test": "node ../../scripts/ensure-playwright.js && rstest"
|
|
60
67
|
}
|
|
61
|
-
}
|
|
68
|
+
}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";(self.webpackChunk_module_federation_treeshake_frontend=self.webpackChunk_module_federation_treeshake_frontend||[]).push([["873"],{4723(e,t,a){a.d(t,{E:()=>i});var s=a(5723);a(2155);var r=a(5445),l=a(8207);let n=(0,r.F)("inline-flex items-center rounded-md border border-zinc-200 px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-zinc-950 focus:ring-offset-2 dark:border-zinc-800 dark:focus:ring-zinc-300",{variants:{variant:{default:"border-transparent bg-zinc-900 text-zinc-50 shadow hover:bg-zinc-900/80 dark:bg-zinc-50 dark:text-zinc-900 dark:hover:bg-zinc-50/80",secondary:"border-transparent bg-zinc-100 text-zinc-900 hover:bg-zinc-100/80 dark:bg-zinc-800 dark:text-zinc-50 dark:hover:bg-zinc-800/80",destructive:"border-transparent bg-red-500 text-zinc-50 shadow hover:bg-red-500/80 dark:bg-red-900 dark:text-zinc-50 dark:hover:bg-red-900/80",outline:"text-zinc-950 dark:text-zinc-50"}},defaultVariants:{variant:"default"}});function i(e){let{className:t,variant:a,...r}=e;return(0,s.jsx)("div",{className:(0,l.cn)(n({variant:a}),t),...r})}},4704(e,t,a){a.r(t),a.d(t,{default:()=>eV});var s=a(5723),r=a(2155),l=a(7938),n=a(3760),i=a(8207);let d=r.forwardRef((e,t)=>{let{className:a,...r}=e;return(0,s.jsx)("div",{ref:t,className:(0,i.cn)("rounded-xl border border-zinc-200 bg-white text-zinc-950 shadow dark:border-zinc-800 dark:bg-zinc-950 dark:text-zinc-50",a),...r})});d.displayName="Card";let o=r.forwardRef((e,t)=>{let{className:a,...r}=e;return(0,s.jsx)("div",{ref:t,className:(0,i.cn)("flex flex-col space-y-1.5 p-6",a),...r})});o.displayName="CardHeader";let c=r.forwardRef((e,t)=>{let{className:a,...r}=e;return(0,s.jsx)("div",{ref:t,className:(0,i.cn)("font-semibold leading-none tracking-tight",a),...r})});c.displayName="CardTitle";let m=r.forwardRef((e,t)=>{let{className:a,...r}=e;return(0,s.jsx)("div",{ref:t,className:(0,i.cn)("text-sm text-zinc-500 dark:text-zinc-400",a),...r})});m.displayName="CardDescription";let x=r.forwardRef((e,t)=>{let{className:a,...r}=e;return(0,s.jsx)("div",{ref:t,className:(0,i.cn)("p-6 pt-0",a),...r})});x.displayName="CardContent",r.forwardRef((e,t)=>{let{className:a,...r}=e;return(0,s.jsx)("div",{ref:t,className:(0,i.cn)("flex items-center p-6 pt-0",a),...r})}).displayName="CardFooter";let h=r.forwardRef((e,t)=>{let{className:a,type:r,...l}=e;return(0,s.jsx)("input",{type:r,className:(0,i.cn)("flex h-9 w-full rounded-md border border-zinc-200 bg-transparent px-3 py-1 text-base shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-zinc-950 placeholder:text-zinc-500 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-zinc-950 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm dark:border-zinc-800 dark:file:text-zinc-50 dark:placeholder:text-zinc-400 dark:focus-visible:ring-zinc-300",a),ref:t,...l})});h.displayName="Input";let u=r.forwardRef((e,t)=>{let{className:a,...r}=e;return(0,s.jsx)("textarea",{className:(0,i.cn)("flex min-h-[60px] w-full rounded-md border border-zinc-200 bg-transparent px-3 py-2 text-base shadow-sm placeholder:text-zinc-500 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-zinc-950 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm dark:border-zinc-800 dark:placeholder:text-zinc-400 dark:focus-visible:ring-zinc-300",a),ref:t,...r})});u.displayName="Textarea";var p=a(8546);let f=p.bL,g=p.R6,b=p.Ke;var v=a(2423),j=a(6317),y=a(970),k=a(4712),N=a(841),w=a(5436),z=a(1048),S=a(4723),C=a(1481),E=a(6886),R=a(6584),T=a(1784);let B=R.bL;R.l9;let $=R.ZL;R.bm;let D=r.forwardRef((e,t)=>{let{className:a,...r}=e;return(0,s.jsx)(R.hJ,{ref:t,className:(0,i.cn)("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",a),...r})});D.displayName=R.hJ.displayName;let A=r.forwardRef((e,t)=>{let{className:a,children:r,...l}=e;return(0,s.jsxs)($,{children:[(0,s.jsx)(D,{}),(0,s.jsxs)(R.UC,{ref:t,className:(0,i.cn)("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border border-zinc-200 bg-white p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg dark:border-zinc-800 dark:bg-zinc-950",a),...l,children:[r,(0,s.jsxs)(R.bm,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-white transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-zinc-950 focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-zinc-100 data-[state=open]:text-zinc-500 dark:ring-offset-zinc-950 dark:focus:ring-zinc-300 dark:data-[state=open]:bg-zinc-800 dark:data-[state=open]:text-zinc-400 dark:text-zinc-100",children:[(0,s.jsx)(T.A,{className:"h-4 w-4"}),(0,s.jsx)("span",{className:"sr-only",children:"Close"})]})]})]})});A.displayName=R.UC.displayName;let U=e=>{let{className:t,...a}=e;return(0,s.jsx)("div",{className:(0,i.cn)("flex flex-col space-y-1.5 text-center sm:text-left",t),...a})};U.displayName="DialogHeader";let L=e=>{let{className:t,...a}=e;return(0,s.jsx)("div",{className:(0,i.cn)("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",t),...a})};L.displayName="DialogFooter";let F=r.forwardRef((e,t)=>{let{className:a,...r}=e;return(0,s.jsx)(R.hE,{ref:t,className:(0,i.cn)("text-lg font-semibold leading-none tracking-tight",a),...r})});F.displayName=R.hE.displayName;let P=r.forwardRef((e,t)=>{let{className:a,...r}=e;return(0,s.jsx)(R.VY,{ref:t,className:(0,i.cn)("text-sm text-zinc-500 dark:text-zinc-400",a),...r})});P.displayName=R.VY.displayName;let I=r.forwardRef((e,t)=>{let{className:a,...r}=e;return(0,s.jsx)(C.uB,{ref:t,className:(0,i.cn)("flex h-full w-full flex-col overflow-hidden rounded-md bg-white text-zinc-950 dark:bg-zinc-950 dark:text-zinc-50",a),...r})});I.displayName=C.uB.displayName;let M=r.forwardRef((e,t)=>{let{className:a,...r}=e;return(0,s.jsxs)("div",{className:"flex items-center border-b px-3 flex-1","cmdk-input-wrapper":"",children:[(0,s.jsx)(E.A,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),(0,s.jsx)(C.uB.Input,{ref:t,className:(0,i.cn)("flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-zinc-500 disabled:cursor-not-allowed disabled:opacity-50 dark:placeholder:text-zinc-400",a),...r})]})});M.displayName=C.uB.Input.displayName;let _=r.forwardRef((e,t)=>{let{className:a,...r}=e;return(0,s.jsx)(C.uB.List,{ref:t,className:(0,i.cn)("max-h-[300px] overflow-y-auto overflow-x-hidden",a),...r})});_.displayName=C.uB.List.displayName;let O=r.forwardRef((e,t)=>(0,s.jsx)(C.uB.Empty,{ref:t,className:"py-6 text-center text-sm",...e}));O.displayName=C.uB.Empty.displayName;let V=r.forwardRef((e,t)=>{let{className:a,...r}=e;return(0,s.jsx)(C.uB.Group,{ref:t,className:(0,i.cn)("overflow-hidden p-1 text-zinc-950 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-zinc-500 dark:text-zinc-50 dark:[&_[cmdk-group-heading]]:text-zinc-400",a),...r})});V.displayName=C.uB.Group.displayName,r.forwardRef((e,t)=>{let{className:a,...r}=e;return(0,s.jsx)(C.uB.Separator,{ref:t,className:(0,i.cn)("-mx-1 h-px bg-zinc-200 dark:bg-zinc-800",a),...r})}).displayName=C.uB.Separator.displayName;let H=r.forwardRef((e,t)=>{let{className:a,...r}=e;return(0,s.jsx)(C.uB.Item,{ref:t,className:(0,i.cn)("relative flex cursor-default gap-2 select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[disabled=true]:pointer-events-none data-[selected=true]:bg-zinc-100 data-[selected=true]:text-zinc-900 data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 dark:data-[selected=true]:bg-zinc-800 dark:data-[selected=true]:text-zinc-50",a),...r})});H.displayName=C.uB.Item.displayName;var K=a(2150);let q=K.bL,J=K.l9;K.Mz;let W=r.forwardRef((e,t)=>{let{className:a,align:r="center",sideOffset:l=4,...n}=e;return(0,s.jsx)(K.ZL,{children:(0,s.jsx)(K.UC,{ref:t,align:r,sideOffset:l,className:(0,i.cn)("z-50 w-72 rounded-md border border-zinc-200 bg-white p-4 text-zinc-950 shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 dark:border-zinc-800 dark:bg-zinc-950 dark:text-zinc-50",a),...n})})});W.displayName=K.UC.displayName;var Y=a(6078),G=a(3587),Z=a(4313);let X=("u">typeof window?window.localStorage.getItem("treeshake_server_url"):null)||void 0||"http://localhost:3000/tree-shaking-shared";async function Q(e){let t=new Headers;t.append("Content-Type","application/json");let{shared:a,target:s,plugins:r,sharedName:l,sharedVersion:n}=e,i=JSON.stringify({shared:a,target:s,plugins:r,libraryType:"global",hostName:"@treeshake/shared-host"}),d=await window.fetch(`${X}/build/check-tree-shaking`,{method:"POST",headers:t,body:i});if(!d.ok)throw Error(`HTTP ${d.status}`);let{status:o,data:c}=await d.json();if("success"!==o)throw Error(c);let m=c.find(e=>e.name===l&&e.version===n);if(!m)throw Error(`未能正常获取到目标${l}@${n}信息`);return!!m.canTreeShaking&&m}var ee=a(836);function et(e){return e?e.split(/[\n,]/).map(e=>e.trim()).filter(Boolean).map(e=>{let t=e.split("@");if(t.length<2)throw Error(ee.A.t("analyze.sharedVersionRequired",{name:e}));let a=t.pop();return[t.join("@"),a,[]]}):[]}function ea(e){let{values:t,onChange:a,error:d,disabled:o,options:c,placeholder:m,loading:x,item:h,onMoveToShared:u}=e,[p,f]=(0,r.useState)(""),[g,b]=(0,r.useState)(!1),{t:v}=(0,l.Bd)(),j=e=>{let s=e.trim();!s||t.includes(s)||(a([...t,s]),f(""))},y=e=>{o||a(t.filter(t=>t!==e))},k="This module does not support treeshake"===m;return x?(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsxs)("div",{className:"flex min-h-12 w-full items-center justify-center gap-2 rounded-xl border border-zinc-200/70 bg-white/70 px-3 py-2 text-sm shadow-sm backdrop-blur-md dark:border-zinc-800/80 dark:bg-zinc-900/70 opacity-80 cursor-not-allowed",children:[(0,s.jsx)(Y.A,{className:"h-4 w-4 animate-spin text-zinc-500"}),(0,s.jsx)("span",{className:"text-zinc-500",children:m||"Loading..."})]}),d&&(0,s.jsx)("p",{className:"text-xs text-red-500",children:d})]}):c&&c.length>0?(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsxs)(q,{open:g,onOpenChange:b,children:[(0,s.jsx)(J,{asChild:!0,children:(0,s.jsxs)("div",{className:(0,i.cn)("flex min-h-12 w-full flex-wrap items-center gap-2 rounded-xl border bg-white/70 px-3 py-2 text-sm shadow-sm backdrop-blur-md transition-colors dark:bg-zinc-900/70 cursor-pointer",d?"border-red-500/70 ring-1 ring-red-500/40":"border-zinc-200/70 hover:border-zinc-300 dark:border-zinc-800/80 dark:hover:border-zinc-700",o&&"opacity-60 cursor-not-allowed"),children:[t.map(e=>(0,s.jsxs)(S.E,{variant:"secondary",className:"flex items-center gap-1 rounded-full bg-zinc-900/90 px-2 py-1 text-xs text-zinc-50 shadow-sm dark:bg-zinc-100 dark:text-zinc-900",children:[(0,s.jsx)("span",{children:e}),(0,s.jsx)("button",{type:"button",className:"inline-flex h-4 w-4 items-center justify-center rounded-full bg-zinc-800/80 text-[10px] text-zinc-50 transition hover:bg-zinc-700 dark:bg-zinc-200 dark:text-zinc-900 dark:hover:bg-zinc-300",onClick:t=>{t.stopPropagation(),y(e)},children:"✕"})]},e)),(0,s.jsx)("div",{className:(0,i.cn)("flex-1 min-w-20 text-sm text-zinc-500 dark:text-zinc-400",k&&"text-red-500"),children:0===t.length&&(m||"Select exports...")}),(0,s.jsx)(G.A,{className:"ml-auto h-4 w-4 shrink-0 opacity-50"})]})}),(0,s.jsx)(W,{className:"w-[--radix-popover-trigger-width] p-0",align:"start",children:(0,s.jsxs)(I,{children:[(0,s.jsxs)("div",{className:"flex items-center border-b pr-3",children:[(0,s.jsx)(M,{placeholder:"Search exports...",className:"flex-1 border-0 focus:ring-0"}),(0,s.jsx)("button",{type:"button",className:"ml-2 whitespace-nowrap text-xs font-medium text-slate-500 hover:text-slate-800 dark:text-slate-400 dark:hover:text-slate-200",onClick:()=>{t.length===c.length?a([]):a([...c])},children:t.length===c.length?"Unselect All":"Select All"})]}),(0,s.jsxs)(_,{children:[(0,s.jsx)(O,{children:"No export found."}),(0,s.jsx)(V,{className:"max-h-64 overflow-y-auto",children:c.map(e=>(0,s.jsxs)(H,{value:e,onSelect:()=>{t.includes(e)?a(t.filter(t=>t!==e)):a([...t,e])},children:[(0,s.jsx)(z.A,{className:(0,i.cn)("mr-2 h-4 w-4",t.includes(e)?"opacity-100":"opacity-0")}),e]},e))})]})]})})]}),d&&(0,s.jsx)("p",{className:"text-xs text-red-500",children:d})]}):(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsxs)("div",{className:(0,i.cn)("flex min-h-12 w-full flex-wrap items-center gap-2 rounded-xl border bg-white/70 px-3 py-2 text-sm shadow-sm backdrop-blur-md transition-colors dark:bg-zinc-900/70",d?"border-red-500/70 ring-1 ring-red-500/40":"border-zinc-200/70 hover:border-zinc-300 dark:border-zinc-800/80 dark:hover:border-zinc-700",o&&"opacity-60 cursor-not-allowed"),children:[t.map(e=>(0,s.jsxs)(S.E,{variant:"secondary",className:"flex items-center gap-1 rounded-full bg-zinc-900/90 px-2 py-1 text-xs text-zinc-50 shadow-sm dark:bg-zinc-100 dark:text-zinc-900",children:[(0,s.jsx)("span",{children:e}),(0,s.jsx)("button",{type:"button",className:"inline-flex h-4 w-4 items-center justify-center rounded-full bg-zinc-800/80 text-[10px] text-zinc-50 transition hover:bg-zinc-700 dark:bg-zinc-200 dark:text-zinc-900 dark:hover:bg-zinc-300",onClick:t=>{t.stopPropagation(),y(e)},children:"✕"})]},e)),(0,s.jsx)("input",{disabled:o,value:p,onChange:e=>f(e.target.value),onKeyDown:e=>{o||("Enter"===e.key||","===e.key||" "===e.key?(e.preventDefault(),j(p)):"Backspace"===e.key&&!p&&t.length&&(e.preventDefault(),a(t.slice(0,-1))))},onBlur:()=>{!o&&p.trim()&&j(p)},placeholder:t.length?v("analyze.fieldExportsPlaceholderMore"):m||v("analyze.fieldExportsPlaceholderEmpty"),className:(0,i.cn)("flex-1 min-w-20 border-none bg-transparent text-sm text-zinc-900 outline-none placeholder:text-zinc-400 dark:text-zinc-50 dark:placeholder:text-zinc-500 disabled:cursor-not-allowed",k&&"placeholder:text-red-500")})]}),d&&(0,s.jsx)("p",{className:"text-xs text-red-500",children:d}),k&&h&&u&&(0,s.jsxs)("div",{className:"mt-1 flex items-center justify-between rounded-md bg-yellow-50 p-2 text-xs text-yellow-700 dark:bg-yellow-900/20 dark:text-yellow-400",children:[(0,s.jsx)("span",{children:v("analyze.suggestionMoveToShared")}),(0,s.jsx)(n.$,{type:"button",variant:"ghost",size:"sm",className:"h-6 px-2 text-xs hover:bg-yellow-100 hover:text-yellow-800 dark:hover:bg-yellow-900/40 dark:hover:text-yellow-300",onClick:u,children:v("analyze.btnMoveToShared")})]})]})}function es(e){var t,a;let{item:d,updateItem:o,config:c,setConfig:m,removeItem:x,formErrors:u,loading:p,setFullTreeshakeResult:f,allItems:g}=e,{t:b}=(0,l.Bd)(),[v,j]=(0,r.useState)([]),[y,k]=(0,r.useState)(!1),[N,w]=(0,r.useState)(!1),[S,C]=(0,r.useState)(!1),[E,R]=(0,r.useState)(null),[T,B]=(0,r.useState)([]),[$,D]=(0,r.useState)(null);return(0,r.useEffect)(()=>{if(!d.name||!d.version){R(null),B([]);return}(async()=>{C(!0);try{let e={sharedName:d.name.trim(),sharedVersion:d.version.trim(),shared:[[d.name.trim(),d.version.trim(),[]]],target:c.target?c.target.split("\n").map(e=>e.trim()).filter(Boolean):["web","browserslist:> 0.01%,not dead,not op_mini all"],plugins:c.plugins?c.plugins.split(",").map(e=>e.trim()).filter(Boolean):[]},t=g.filter(e=>e.id!==d.id&&e.name&&e.version).map(e=>[e.name.trim(),e.version.trim(),e.exports]);if(e.shared.push(...t),c.shared)try{let t=et(c.shared);e.shared.push(...t)}catch(e){console.warn("Failed to parse shared config for check",e)}let a=e.shared.map(e=>e[0]);if(new Set(a).size!==a.length){let e=a.filter((e,t)=>a.indexOf(e)!==t),t=[...new Set(e)];t.includes(d.name.trim())?D(b("analyze.errorDuplicateSharedCurrent",{name:d.name.trim()})):(Z.oR.error(b("analyze.errorDuplicateSharedDeps",{names:t.join(", ")})),D(b("analyze.errorDuplicateSharedDeps",{names:t.join(", ")}))),R(null),f&&f(null),C(!1);return}let s=await Q(e);!1===s?(R(!1),B([]),f&&f(null)):(R(!0),f&&f(s),s.modules&&B(s.modules))}catch(e){console.error("Check treeshake failed",e),R(null),f&&f(null),Z.oR.error(e.message||"Failed to check treeshake support")}finally{C(!1)}})()},[d.name,d.version,c.target,c.plugins,c.shared,b]),(0,r.useEffect)(()=>{if(!d.name){j([]),D(null);return}let e=d.name.trim(),t=g.filter(e=>e.id!==d.id&&e.name).map(e=>e.name.trim()),a=[];if(c.shared)try{a=et(c.shared).map(e=>e[0])}catch(e){}if(new Set([...t,...a]).has(e)){j([]),D(b("analyze.errorDuplicateSharedCurrent",{name:e}));return}let s=setTimeout(async()=>{k(!0),D(null);try{let e=await fetch(`https://data.jsdelivr.com/v1/package/npm/${d.name}`);if(e.ok){let t=await e.json(),a=(t.versions||[]).map(e=>({version:e})),s=t.tags||{};Object.entries(s).forEach(e=>{let[t,s]=e,r=a.find(e=>e.version===s);r&&(r.tag=t)}),j(a)}else 404===e.status?(j([]),D(`Package "${d.name}" not found or has no versions`),Z.oR.error(`Package "${d.name}" not found`)):j([])}catch(e){console.error("Failed to fetch versions",e),j([])}finally{k(!1)}},500);return()=>clearTimeout(s)},[d.name,g,c.shared]),(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{className:"grid gap-3 md:grid-cols-2",children:[(0,s.jsxs)("div",{className:"space-y-1.5",children:[(0,s.jsxs)("label",{className:"flex items-center justify-between text-xs font-medium text-slate-700 dark:text-slate-200",children:[(0,s.jsx)("span",{children:b("analyze.fieldSharedLabel")}),(null==u?void 0:u.name)&&(0,s.jsx)("span",{className:"text-[11px] text-red-500",children:u.name})]}),(0,s.jsx)(h,{value:d.name,onChange:e=>{o(d.id,"name",e.target.value),o(d.id,"version",""),o(d.id,"exports",[])},placeholder:b("analyze.fieldSharedPlaceholder"),className:(0,i.cn)("h-9 bg-white/70 text-sm backdrop-blur-sm dark:bg-slate-900/70",((null==u?void 0:u.name)||$)&&"border-red-500/70 ring-1 ring-red-500/40")}),$&&(0,s.jsx)("span",{className:"text-[11px] text-red-500",children:$})]}),(0,s.jsxs)("div",{className:"space-y-1.5",children:[(0,s.jsxs)("label",{className:"flex items-center justify-between text-xs font-medium text-slate-700 dark:text-slate-200",children:[(0,s.jsx)("span",{children:b("analyze.fieldVersionLabel")}),(null==u?void 0:u.version)&&(0,s.jsx)("span",{className:"text-[11px] text-red-500",children:u.version})]}),(0,s.jsxs)(q,{open:N,onOpenChange:w,children:[(0,s.jsx)(J,{asChild:!0,children:(0,s.jsxs)(n.$,{variant:"outline",role:"combobox","aria-expanded":N,className:(0,i.cn)("h-9 w-full justify-between bg-white/70 text-sm font-normal backdrop-blur-sm dark:bg-slate-900/70",!d.version&&"text-muted-foreground",(null==u?void 0:u.version)&&"border-red-500/70 ring-1 ring-red-500/40"),disabled:!d.name||y,children:[d.version?(null==(t=v.find(e=>e.version===d.version))?void 0:t.tag)?`${d.version} (${null==(a=v.find(e=>e.version===d.version))?void 0:a.tag})`:d.version:y?"Loading versions...":b("analyze.fieldVersionPlaceholder"),(0,s.jsx)(G.A,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),(0,s.jsx)(W,{className:"w-[--radix-popover-trigger-width] p-0",children:(0,s.jsxs)(I,{children:[(0,s.jsx)(M,{placeholder:"Search version..."}),(0,s.jsxs)(_,{children:[(0,s.jsx)(O,{children:"No version found."}),(0,s.jsx)(V,{children:v.map(e=>(0,s.jsxs)(H,{value:e.version,onSelect:e=>{o(d.id,"version",e===d.version?"":e),w(!1)},children:[(0,s.jsx)(z.A,{className:(0,i.cn)("mr-2 h-4 w-4",d.version===e.version?"opacity-100":"opacity-0")}),e.version,e.tag&&(0,s.jsx)("span",{className:"ml-2 rounded bg-slate-100 px-1.5 py-0.5 text-[10px] text-slate-500 dark:bg-slate-800 dark:text-slate-400",children:e.tag})]},e.version))})]})]})})]})]})]}),(0,s.jsxs)("div",{className:"space-y-1.5",children:[(0,s.jsxs)("label",{className:"flex items-center justify-between text-xs font-medium text-slate-700 dark:text-slate-200",children:[(0,s.jsx)("span",{children:b("analyze.fieldExportsLabel")}),(null==u?void 0:u.exports)&&(0,s.jsx)("span",{className:"text-[11px] text-red-500",children:u.exports})]}),(0,s.jsx)(ea,{values:d.exports,onChange:e=>o(d.id,"exports",e),error:null==u?void 0:u.exports,disabled:p||S||!1===E||!E,options:E?T:void 0,placeholder:!1===E?"This module does not support treeshake":S?"Checking treeshake support...":E?void 0:"Please select a version first",loading:S,item:d,onMoveToShared:()=>{if(!d.name||!d.version)return;let e=`${d.name}@${d.version}`;m(t=>({...t,shared:t.shared?`${t.shared}
|
|
2
|
-
${e}`:e})),g.length>1?x(d.id):(o(d.id,"name",""),o(d.id,"version",""),o(d.id,"exports",[])),Z.oR.success(`Moved ${d.name} to shared config`)}}),(0,s.jsx)("p",{className:"text-[11px] text-slate-500 dark:text-slate-400",children:b("analyze.fieldExportsHelp")})]})]})}var er=a(98);let el=(0,a(5445).F)("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),en=r.forwardRef((e,t)=>{let{className:a,...r}=e;return(0,s.jsx)(er.b,{ref:t,className:(0,i.cn)(el(),a),...r})});en.displayName=er.b.displayName;var ei=a(2314);async function ed(e,t){try{if("u"<typeof window||"u"<typeof AbortController){let t=await fetch(e.href,{method:"HEAD"}),a=t.headers.get("Content-Length")??t.headers.get("content-length");if(!a)return null;let s=Number(a);if(Number.isNaN(s)||s<=0)return null;return s}let a=new AbortController,s=window.setTimeout(()=>a.abort(),t);try{let t=await fetch(e.href,{method:"HEAD",signal:a.signal}),s=t.headers.get("Content-Length")??t.headers.get("content-length");if(!s)return null;let r=Number(s);if(Number.isNaN(r)||r<=0)return null;return r}finally{window.clearTimeout(s)}}catch{return null}}async function eo(e,t,a){let s,r=e.transferSize||0,l=e.encodedBodySize||0,n=e.decodedBodySize||0,i=e.duration||0,d="unknown",o="ok";if(r>0||l>0||n>0)d="performance";else{let e=await ed(t,5e3);if(null!==e)r=r||e,l=l||e,d="head",o="restricted",s="Performance 体积为 0,使用 HEAD Content-Length 作为回退。";else if(a)try{let e=new TextEncoder().encode(a).length;e>0?(r=r||e,l=l||e,n=n||e,d="estimated",o="restricted",s="无法从浏览器获取准确体积,使用 TextEncoder 估算字节数。"):(o="unavailable",s="无法从 Performance、HEAD 或估算中获取脚本体积。")}catch{o="unavailable",s="当前环境不支持 TextEncoder 估算脚本体积。"}}return r||l||n||(o="unavailable"),{transferSize:r||null,encodedBodySize:l||null,decodedBodySize:n||null,sizeSource:d,sizeStatus:o,notes:s,duration:i}}async function ec(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];if("u"<typeof window||"u"<typeof performance)throw Error("当前环境不支持 Performance API,无法读取资源体积。");if(!("getEntriesByType"in performance))throw Error("当前浏览器未暴露 performance.getEntriesByType,无法扫描资源。");let t=performance.getEntriesByType("resource").filter(e=>{if("script"===e.initiatorType)return!0;if("other"===e.initiatorType){let t=e.name||"";return t.endsWith(".js")||t.includes(".js?")}return!1}).map(async t=>{let a;try{a=new URL(t.name,window.location.href)}catch{return null}let s=a.href.toLowerCase(),r=new Set;if(e.forEach(e=>{s.includes(e.toLowerCase())&&r.add(e)}),!r.size)return null;let l="";try{let e=await fetch(a.href);e.ok&&(l=await e.text())}catch(e){console.warn("Failed to fetch script content:",a.href,e)}let n=await eo(t,a,l);return{id:a.href,url:a.href,libraries:Array.from(r),transferSize:n.transferSize,encodedBodySize:n.encodedBodySize,decodedBodySize:n.decodedBodySize,sizeSource:n.sizeSource,sizeStatus:n.sizeStatus,notes:n.notes,duration:n.duration,content:l||void 0}}),a=(await Promise.all(t)).filter(e=>!!e);return a.sort((e,t)=>{let a=e.transferSize??e.encodedBodySize??0;return(t.transferSize??t.encodedBodySize??0)-a}),a}let em=e=>e.startsWith("//")?window.location.protocol+e:e,ex=e=>new Promise((t,a)=>{if(document.querySelector(`script[src="${e}"]`))return void t();let s=document.createElement("script");s.src=e,s.crossOrigin="anonymous",s.onload=()=>t(),s.onerror=()=>a(Error(`Failed to load script: ${e}`)),document.body.appendChild(s)}),eh=async e=>{let{sharedName:t,sharedVersion:a,raw:s,treeshakeModules:r,fullTreeshakeResult:l}=e,n=s.find(e=>e.name===t&&e.version===a);if(!l||!n)throw Error(ee.A.t("analyze.responseMissingJs"));l.cdnUrl=em(l.cdnUrl),n.cdnUrl=em(n.cdnUrl),await Promise.all([ex(l.cdnUrl),ex(n.cdnUrl)]);let i=await ec([l.cdnUrl,n.cdnUrl]),d=e=>i.find(t=>t.url===e)||{id:e,url:e,libraries:[],transferSize:0,encodedBodySize:0,decodedBodySize:0,sizeSource:"unknown",sizeStatus:"unavailable",duration:0},o=d(l.cdnUrl),c=d(n.cdnUrl),m={js:o.content||l.cdnUrl,size:o.encodedBodySize||0,modules:{names:l.modules},resourcePerf:o},x={js:c.content||n.cdnUrl,size:c.encodedBodySize||0,modules:{names:r||n.modules},resourcePerf:c};return console.log("fullRecord: ",o),console.log("treeshakeRecord: ",c),{full:m,treeshake:x}};async function eu(e,t){let a=new Headers;a.append("Content-Type","application/json");let{shared:s,target:r,plugins:l,sharedName:n,sharedVersion:i}=e,d=JSON.stringify({shared:s,target:r,plugins:l,libraryType:"global",hostName:"@treeshake/shared-host"}),o=await window.fetch(`${X}/build`,{method:"POST",headers:a,body:d});if(!o.ok)throw Error(`HTTP ${o.status}`);let{status:c,data:m}=await o.json();if("success"!==c)throw Error(m);let x=[];for(let e of s){let a=e[0],s=e[1],r=e[2],l=a===n&&s===i,d=m.find(e=>e.name===a&&e.version===s);if(!d)continue;let o=l?t:d;try{let e=await eh({sharedName:a,sharedVersion:s,raw:m,treeshakeModules:r,fullTreeshakeResult:o});x.push({...e,sharedName:a})}catch(e){console.error(`Failed to normalize response for ${a}`,e)}}return x}let ep=async e=>{var t,a;let s=em(e),r=[],l=[],n=[],i=await fetch(s);if(!i.ok)throw Error(`Failed to fetch manifest: HTTP ${i.status}`);let d=await i.json();if(null==(t=d.shared)?void 0:t.length){let e=d.shared.some(e=>e.usedExports&&e.usedExports.length>0);d.shared.forEach(t=>{e&&(!t.usedExports||0===t.usedExports.length)?l.push(`${t.name}@${t.version}`):r.push({id:`${t.name}@${t.version}`,name:t.name,version:t.version,exports:t.usedExports??[]})})}return(null==(a=d.remotes)?void 0:a.length)&&d.remotes.forEach(e=>{let t=e.federationContainerName??e.name??"";if(!t)return;let a=t.replace(/^(app|bnpm):/,""),s=e.version??(e.entry?String(e.entry):void 0);n.push({name:a,version:s})}),{pureShared:l,sharedItems:r,remotes:n}};async function ef(e){return ep(e)}var eg=a(5880);let eb=r.forwardRef((e,t)=>{let{className:a,...r}=e;return(0,s.jsx)(eg.bL,{ref:t,className:(0,i.cn)("peer h-4 w-4 shrink-0 rounded-sm border border-zinc-200 border-zinc-900 shadow focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-zinc-950 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-zinc-900 data-[state=checked]:text-zinc-50 dark:border-zinc-800 dark:border-zinc-50 dark:focus-visible:ring-zinc-300 dark:data-[state=checked]:bg-zinc-50 dark:data-[state=checked]:text-zinc-900",a),...r,children:(0,s.jsx)(eg.C1,{className:(0,i.cn)("flex items-center justify-center text-current"),children:(0,s.jsx)(z.A,{className:"h-4 w-4"})})})});function ev(e){let{open:t,onOpenChange:a,remotes:l,onConfirm:i}=e,[d,o]=(0,r.useState)([]);return(0,r.useEffect)(()=>{t&&o(l.map(e=>e.name))},[t,l]),(0,s.jsx)(B,{open:t,onOpenChange:a,children:(0,s.jsxs)(A,{className:"sm:max-w-[425px] dark:bg-slate-900 dark:border-slate-800",children:[(0,s.jsxs)(U,{children:[(0,s.jsx)(F,{className:"dark:text-slate-100",children:"Select Remotes to Add"}),(0,s.jsx)(P,{children:"Choose which remote modules you want to add to the analysis."})]}),(0,s.jsx)("div",{className:"grid gap-4 py-4 max-h-[60vh] overflow-y-auto",children:l.map(e=>(0,s.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,s.jsx)(eb,{id:`remote-${e.name}`,checked:d.includes(e.name),onCheckedChange:()=>{var t;return t=e.name,void o(e=>e.includes(t)?e.filter(e=>e!==t):[...e,t])}}),(0,s.jsxs)("label",{htmlFor:`remote-${e.name}`,className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70 dark:text-slate-200",children:[e.name," ",e.version?(0,s.jsxs)("span",{className:"text-muted-foreground text-xs dark:text-slate-400",children:["(",e.version,")"]}):null]})]},e.name))}),(0,s.jsxs)(L,{children:[(0,s.jsx)(n.$,{variant:"outline",onClick:()=>a(!1),className:"dark:border-slate-700 dark:text-slate-300 dark:hover:bg-slate-800",children:"Cancel"}),(0,s.jsxs)(n.$,{onClick:()=>{i(l.filter(e=>d.includes(e.name))),a(!1)},children:["Confirm (",d.length,")"]})]})]})})}eb.displayName=eg.bL.displayName;let ej=e=>e.startsWith("http://")||e.startsWith("https://")||e.startsWith("//");function ey(e){let{open:t,onOpenChange:a,setSharedItems:l,setConfig:d}=e,[o,c]=(0,r.useState)([{id:"1",name:"",manifestUrl:""}]),[m,x]=(0,r.useState)(!1),u=(0,r.useRef)({}),[p,f]=(0,r.useState)(!1),[g,b]=(0,r.useState)([]),v=(0,r.useCallback)((e,t)=>{if(!ej(t))return;let a=`${e}-config`;u.current[a]&&clearTimeout(u.current[a]),u.current[a]=setTimeout(()=>{k(e,t),delete u.current[a]},500)},[]),k=(0,r.useCallback)(async(e,t)=>{if(t){c(t=>t.map(t=>t.id===e?{...t,error:null}:t));try{let a=await ef(t);c(t=>t.map(t=>t.id===e?{...t,error:null,configData:a?{pureShared:a.pureShared,sharedItems:a.sharedItems||[],remotes:a.remotes}:null}:t))}catch(r){console.error(`Failed to fetch config for ${t}`,r);let s="Failed to load config";if("object"==typeof r&&null!==r){var a;"response"in r&&(null==(a=r.response)?void 0:a.status)===404?s="Manifest not found":"message"in r&&"string"==typeof r.message&&(s=r.message)}c(t=>t.map(t=>t.id===e?{...t,configData:null,error:s}:t))}}},[]),N=(e,t)=>{c(a=>{let s=a.map(a=>{if(a.id!==e)return a;let s={...a,...t};return(void 0!==t.name&&t.name!==a.name||void 0!==t.manifestUrl&&t.manifestUrl!==a.manifestUrl)&&(s.configData=null),s}),r=s.find(t=>t.id===e);return(null==r?void 0:r.manifestUrl)&&v(e,r.manifestUrl),s})},w=async()=>{let e=o.filter(e=>e.name&&e.manifestUrl);if(0===e.length)return void Z.oR.error("Please fill in at least one module");x(!0);try{let t=[],s={},r=[],n=0;for(let a of e)a.configData?(t.push(...a.configData.sharedItems),a.configData.pureShared&&r.push(...a.configData.pureShared)):n++;if(n>0){let a=e.filter(e=>!e.configData);(await Promise.all(a.map(e=>ef(e.manifestUrl).catch(()=>null)))).forEach(e=>{e&&(e.sharedItems&&t.push(...e.sharedItems),e.pureShared.length>0&&r.push(...e.pureShared))})}if(r.length>0){let e=new Set(t.map(e=>e.name)),a=r.filter(t=>{let a=t.split("@"),s=t;return a.length>1&&(s=t.startsWith("@")?a.length>2?"@"+a[1]:t:a[0]),!e.has(s)});a.length>0&&(s.shared=a.join("\n"))}s.target||(s.target="web,\nbrowserslist:> 0.01%,not dead,not op_mini all"),t.length>0?(l(t),d(e=>({...e,...s})),a(!1),Z.oR.success(`Loaded config for ${e.length} modules`)):Z.oR.error("Failed to load manifest config or no data returned")}catch(e){console.error(e),Z.oR.error("Error loading manifest config")}finally{x(!1)}},z=o.every(e=>e.name&&e.manifestUrl&&!e.error);return(0,s.jsxs)(B,{open:t,onOpenChange:a,children:[(0,s.jsx)(ev,{open:p,onOpenChange:f,remotes:g,onConfirm:e=>{c(t=>{let a=[...t],s=new Set(t.map(e=>e.name)),r=[];return e.forEach(e=>{if(!s.has(e.name)){let t=ej(e.version??"")?e.version:"",l={id:crypto.randomUUID(),name:e.name,manifestUrl:t};a.push(l),r.push(l),s.add(e.name)}}),setTimeout(()=>{r.forEach(e=>{e.manifestUrl&&v(e.id,e.manifestUrl)})},0),a}),Z.oR.success(`Added ${e.length} remote modules`)}}),(0,s.jsxs)(A,{className:"sm:max-w-[650px] dark:bg-slate-900 dark:border-slate-800",children:[(0,s.jsxs)(U,{children:[(0,s.jsx)(F,{className:"dark:text-slate-100",children:"Import Manifest Config"}),(0,s.jsx)(P,{children:"Provide a manifest stats URL to prefill shared exports."})]}),(0,s.jsxs)("div",{className:"grid gap-4 py-4 max-h-[60vh] overflow-y-auto",children:[o.map(e=>{var t;return(0,s.jsxs)("div",{className:(0,i.cn)("relative grid gap-4 rounded-lg border border-slate-200/60 bg-white/50 px-8 py-6 dark:border-slate-800/60 dark:bg-slate-900/50",e.error&&"border-red-500/50 dark:border-red-500/50 bg-red-50/10 dark:bg-red-900/10"),children:[o.length>1&&(0,s.jsx)("button",{type:"button",onClick:()=>{var t;return t=e.id,void c(e=>e.length<=1?e:e.filter(e=>e.id!==t))},className:"absolute right-2 top-2 z-10 text-slate-400 hover:text-red-500 dark:text-slate-500 dark:hover:text-red-400",children:(0,s.jsx)(j.A,{className:"h-4 w-4"})}),(0,s.jsxs)("div",{className:"grid grid-cols-4 items-center gap-4",children:[(0,s.jsx)(en,{htmlFor:`registry-name-${e.id}`,className:"text-right dark:text-slate-300",children:"Name"}),(0,s.jsx)(h,{id:`registry-name-${e.id}`,value:e.name,onChange:t=>N(e.id,{name:t.target.value}),placeholder:"@scope/name",className:"col-span-3 dark:bg-slate-900/50 dark:border-slate-800/60 dark:text-slate-200 dark:placeholder:text-slate-500"})]}),(0,s.jsxs)("div",{className:"grid grid-cols-4 items-center gap-4",children:[(0,s.jsx)(en,{className:"text-right dark:text-slate-300",children:"Manifest URL"}),(0,s.jsx)(h,{value:e.manifestUrl,onChange:t=>N(e.id,{manifestUrl:t.target.value}),placeholder:"https://.../mf-manifest-stats.json",className:"col-span-3 dark:bg-slate-900/50 dark:border-slate-800/60 dark:text-slate-200 dark:placeholder:text-slate-500"})]}),e.error&&(0,s.jsx)("div",{className:"text-xs text-red-500 mt-2",children:e.error}),(null==(t=e.configData)?void 0:t.remotes)&&e.configData.remotes.length>0?(0,s.jsx)("div",{className:"mt-2",children:(0,s.jsxs)(n.$,{type:"button",variant:"outline",size:"sm",className:"h-7 text-xs flex items-center gap-1 w-full dark:border-slate-700 dark:text-slate-300 dark:hover:bg-slate-800",onClick:()=>{b(e.configData.remotes),f(!0)},children:[(0,s.jsx)(ei.A,{className:"h-3 w-3"}),"Add Remotes (",e.configData.remotes.length,")"]})}):null]},e.id)}),(0,s.jsxs)(n.$,{type:"button",variant:"outline",size:"sm",onClick:()=>{c(e=>[...e,{id:crypto.randomUUID(),name:"",manifestUrl:""}])},className:"w-full border-dashed dark:border-slate-700 dark:bg-slate-900/50 dark:text-slate-300 dark:hover:bg-slate-800",children:[(0,s.jsx)(y.A,{className:"mr-2 h-4 w-4"})," Add another module"]})]}),(0,s.jsx)(L,{children:(0,s.jsx)(n.$,{type:"button",onClick:w,disabled:m||!z,children:m?"Loading...":"Load Config"})})]})]})}function ek(e){let{sharedItems:t,setSharedItems:a,config:p,setConfig:S,formErrors:C,loading:E,advancedOpen:R,setAdvancedOpen:T,onSubmit:B,onReset:$,setFullTreeshakeResult:D}=e,{t:A}=(0,l.Bd)(),[U,L]=(0,r.useState)(!1),F=(e,t,s)=>{a(a=>a.map(a=>a.id===e?{...a,[t]:s}:a))},P=e=>{a(t=>t.length<=1?t:t.filter(t=>t.id!==e))};return(0,s.jsxs)(d,{className:"relative border-slate-200/80 bg-white/80 shadow-xl shadow-sky-500/20 backdrop-blur-2xl dark:border-slate-800/80 dark:bg-slate-900/90",children:[(0,s.jsx)(o,{className:"pb-4",children:(0,s.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,s.jsxs)("div",{children:[(0,s.jsxs)(c,{className:"flex items-center gap-2 text-sm font-semibold",children:[(0,s.jsx)(v.A,{className:"h-4 w-4 text-sky-500"}),A("analyze.formCardTitle")]}),(0,s.jsx)(m,{className:"mt-1 text-xs",children:A("analyze.formCardDesc")})]}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)(n.$,{type:"button",size:"sm",variant:"ghost",className:"h-8 text-xs text-slate-500 hover:text-slate-800 dark:text-slate-400 dark:hover:text-slate-200",onClick:()=>{a([{id:"1",name:"antd",version:"6.1.0",exports:["Button","List","Badge"]}]),S(e=>({...e,shared:"react@18.2.0\nreact-dom@18.2.0",target:"web\nbrowserslist:> 0.01%,not dead,not op_mini all",plugins:""}))},children:A("common.fillDemo")}),(0,s.jsx)(n.$,{type:"button",size:"sm",variant:"ghost",className:"h-8 text-xs text-slate-500 hover:text-slate-800 dark:text-slate-400 dark:hover:text-slate-200",onClick:()=>L(!0),children:A("common.importManifest")}),(0,s.jsx)(n.$,{type:"button",size:"sm",variant:"outline",className:"h-8 text-xs",onClick:$,children:A("common.reset")})]})]})}),(0,s.jsxs)(x,{className:"space-y-4 pb-5 text-sm",children:[(0,s.jsx)(ey,{open:U,onOpenChange:L,setSharedItems:a,setConfig:S}),(0,s.jsxs)("form",{className:"space-y-4",onSubmit:B,children:[t.map((e,a)=>{var r;return(0,s.jsxs)("div",{className:"relative rounded-lg border border-slate-200/60 bg-white/50 p-3 dark:border-slate-800/60 dark:bg-slate-900/50",children:[t.length>1&&(0,s.jsx)("button",{type:"button",onClick:()=>P(e.id),className:"absolute right-2 top-2 text-slate-400 hover:text-red-500",children:(0,s.jsx)(j.A,{className:"h-4 w-4"})}),(0,s.jsx)(es,{item:e,updateItem:F,config:p,setConfig:S,removeItem:P,formErrors:null==(r=C.items)?void 0:r[e.id],loading:E,setFullTreeshakeResult:0===a?D:void 0,allItems:t})]},e.id)}),(0,s.jsxs)(n.$,{type:"button",variant:"outline",size:"sm",className:"w-full border-dashed text-xs",onClick:()=>{a(e=>[...e,{id:crypto.randomUUID(),name:"",version:"",exports:[]}])},children:[(0,s.jsx)(y.A,{className:"mr-2 h-3 w-3"})," Add another shared module"]}),(0,s.jsxs)(f,{open:R,onOpenChange:T,children:[(0,s.jsxs)("div",{className:"flex items-center justify-between gap-2 rounded-xl bg-slate-50/90 px-3 py-2 text-xs shadow-sm dark:bg-slate-900/80",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("div",{className:"flex h-6 w-6 items-center justify-center rounded-full bg-sky-500/10 text-sky-600 dark:bg-sky-500/20 dark:text-sky-300",children:(0,s.jsx)(k.A,{className:"h-3 w-3"})}),(0,s.jsxs)("div",{className:"flex flex-col",children:[(0,s.jsx)("span",{className:"font-medium text-slate-700 dark:text-slate-200",children:A("advanced.title")}),(0,s.jsx)("span",{className:"text-[11px] text-slate-500 dark:text-slate-400",children:A("advanced.subtitle")})]})]}),(0,s.jsx)("div",{className:"flex items-center gap-2",children:(0,s.jsx)(g,{asChild:!0,children:(0,s.jsx)(n.$,{type:"button",size:"sm",variant:"ghost",className:"h-7 px-2 text-[11px]",children:R?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(s.Fragment,{children:A("advanced.collapse")}),(0,s.jsx)(N.A,{className:"ml-1 h-3 w-3"})]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(s.Fragment,{children:A("advanced.expand")}),(0,s.jsx)(w.A,{className:"ml-1 h-3 w-3"})]})})})})]}),(0,s.jsxs)(b,{className:"mt-3 space-y-3 rounded-xl border border-slate-200/80 bg-white/90 p-3 text-xs shadow-sm dark:border-slate-700 dark:bg-slate-900/90",children:[(0,s.jsxs)("div",{className:"space-y-1.5",children:[(0,s.jsxs)("label",{className:"flex items-center justify-between text-[11px] font-medium text-slate-600 dark:text-slate-300",children:[(0,s.jsx)("span",{children:A("advanced.sharedLabel")}),C.sharedConfig&&(0,s.jsx)("span",{className:"text-[11px] text-red-500",children:C.sharedConfig})]}),(0,s.jsx)(u,{value:p.shared||"",onChange:e=>S(t=>({...t,shared:e.target.value})),placeholder:A("advanced.sharedPlaceholder"),className:(0,i.cn)("h-20 bg-slate-50/80 text-xs dark:bg-slate-900/80",C.sharedConfig&&"border-red-500/70 ring-1 ring-red-500/40")}),(0,s.jsx)("p",{className:"text-[11px] text-slate-500 dark:text-slate-400",children:A("advanced.sharedDesc")})]}),(0,s.jsxs)("div",{className:"space-y-1.5",children:[(0,s.jsx)("label",{className:"text-[11px] font-medium text-slate-600 dark:text-slate-300",children:A("advanced.targetLabel")}),(0,s.jsx)(u,{value:p.target,onChange:e=>S(t=>({...t,target:e.target.value})),placeholder:A("advanced.targetPlaceholder"),className:"h-20 bg-slate-50/80 text-xs dark:bg-slate-900/80"}),(0,s.jsx)("p",{className:"text-[11px] text-slate-500 dark:text-slate-400",children:A("advanced.targetDesc")})]}),(0,s.jsxs)("div",{className:"space-y-1.5",children:[(0,s.jsx)("label",{className:"text-[11px] font-medium text-slate-600 dark:text-slate-300",children:A("advanced.pluginsLabel")}),(0,s.jsx)(h,{value:p.plugins||"",onChange:e=>S(t=>({...t,plugins:e.target.value})),placeholder:A("advanced.pluginsPlaceholder"),className:"h-8 bg-slate-50/80 text-xs dark:bg-slate-900/80"}),(0,s.jsx)("p",{className:"text-[11px] text-slate-500 dark:text-slate-400",children:A("advanced.pluginsDesc")})]})]})]}),(0,s.jsxs)("div",{className:"flex flex-col gap-3 pt-2 sm:flex-row sm:items-center sm:justify-between",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 text-[11px] text-slate-500 dark:text-slate-400",children:[(0,s.jsx)("div",{className:"flex h-5 w-5 items-center justify-center rounded-full bg-emerald-500/10 text-emerald-600 dark:bg-emerald-500/20 dark:text-emerald-300",children:(0,s.jsx)(z.A,{className:"h-3 w-3"})}),(0,s.jsx)("span",{children:A("common.formSubmitHint")})]}),(0,s.jsx)("div",{className:"flex items-center gap-2",children:(0,s.jsx)(n.$,{type:"submit",className:"inline-flex items-center gap-2 rounded-full bg-gradient-to-r from-sky-500 via-fuchsia-500 to-emerald-500 px-5 text-sm font-medium text-white shadow-lg shadow-sky-500/40 transition-transform hover:translate-y-0.5 hover:shadow-xl disabled:opacity-70",disabled:E,children:E?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(v.A,{className:"h-4 w-4 animate-spin"}),A("common.submitLoading")]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(v.A,{className:"h-4 w-4"}),A("common.submitIdle")]})})})]})]})]})]})}var eN=a(4203);let ew=r.forwardRef((e,t)=>{let{className:a,value:r,...l}=e;return(0,s.jsx)(eN.bL,{ref:t,className:(0,i.cn)("relative h-2 w-full overflow-hidden rounded-full bg-zinc-900/20 dark:bg-zinc-50/20",a),...l,children:(0,s.jsx)(eN.C1,{className:"h-full w-full flex-1 bg-zinc-900 transition-all dark:bg-zinc-50",style:{transform:`translateX(-${100-(r||0)}%)`}})})});ew.displayName=eN.bL.displayName;var ez=a(2446);let eS=r.forwardRef((e,t)=>{let{className:a,children:r,...l}=e;return(0,s.jsxs)(ez.bL,{ref:t,className:(0,i.cn)("relative overflow-hidden",a),...l,children:[(0,s.jsx)(ez.LM,{className:"h-full w-full rounded-[inherit]",children:r}),(0,s.jsx)(eC,{}),(0,s.jsx)(ez.OK,{})]})});eS.displayName=ez.bL.displayName;let eC=r.forwardRef((e,t)=>{let{className:a,orientation:r="vertical",...l}=e;return(0,s.jsx)(ez.VM,{ref:t,orientation:r,className:(0,i.cn)("flex touch-none select-none transition-colors","vertical"===r&&"h-full w-2.5 border-l border-l-transparent p-[1px]","horizontal"===r&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",a),...l,children:(0,s.jsx)(ez.lr,{className:"relative flex-1 rounded-full bg-zinc-200 dark:bg-zinc-800"})})});eC.displayName=ez.VM.displayName;var eE=a(7528);let eR=eE.bL,eT=r.forwardRef((e,t)=>{let{className:a,...r}=e;return(0,s.jsx)(eE.B8,{ref:t,className:(0,i.cn)("inline-flex h-9 items-center justify-center rounded-lg bg-zinc-100 p-1 text-zinc-500 dark:bg-zinc-800 dark:text-zinc-400",a),...r})});eT.displayName=eE.B8.displayName;let eB=r.forwardRef((e,t)=>{let{className:a,...r}=e;return(0,s.jsx)(eE.l9,{ref:t,className:(0,i.cn)("inline-flex items-center justify-center whitespace-nowrap rounded-md px-3 py-1 text-sm font-medium ring-offset-white transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-zinc-950 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-white data-[state=active]:text-zinc-950 data-[state=active]:shadow dark:ring-offset-zinc-950 dark:focus-visible:ring-zinc-300 dark:data-[state=active]:bg-zinc-950 dark:data-[state=active]:text-zinc-50",a),...r})});eB.displayName=eE.l9.displayName;let e$=r.forwardRef((e,t)=>{let{className:a,...r}=e;return(0,s.jsx)(eE.UC,{ref:t,className:(0,i.cn)("mt-2 ring-offset-white focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-zinc-950 focus-visible:ring-offset-2 dark:ring-offset-zinc-950 dark:focus-visible:ring-zinc-300",a),...r})});e$.displayName=eE.UC.displayName;var eD=a(2547),eA=a(559),eU=a(7654),eL=a(6425),eF=a(3226),eP=a(9980);function eI(e){let{title:t,code:a,fileName:i}=e,[h,u]=(0,r.useState)(!1),[p,f]=(0,r.useState)(!1),{t:g}=(0,l.Bd)(),{displayCode:b,truncated:v}=(0,r.useMemo)(()=>{let e=a?a.split("\n"):[];return e.length?p||e.length<=80?{displayCode:a,truncated:!1}:{displayCode:e.slice(0,80).join("\n"),truncated:!0}:{displayCode:g("common.bundleEmptyPlaceholder"),truncated:!1}},[a,p,g]),j=(0,r.useMemo)(()=>b.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/(\/\/.*$)|(".*?"|'.*?'|`.*?`)|\b(export|import|from|const|let|var|function|return|if|else|class|extends|new|async|await|try|catch|finally|switch|case|default)\b|\b(string|number|boolean|Promise|Array|Record|any|void|unknown)\b/gm,(e,t,a,s,r)=>t?`<span class="text-zinc-500">${t}</span>`:a?`<span class="text-emerald-400">${a}</span>`:s?`<span class="text-sky-400 font-semibold">${s}</span>`:r?`<span class="text-purple-300">${r}</span>`:e),[b]),y=async()=>{try{await navigator.clipboard.writeText(a),u(!0),(0,eP.oR)({title:g("common.copySuccessTitle"),description:g("common.copySuccessDescFile",{file:i})}),setTimeout(()=>u(!1),1200)}catch{(0,eP.oR)({title:g("common.copyErrorTitle"),description:g("common.copyErrorDesc"),variant:"destructive"})}};return(0,s.jsxs)(d,{className:"flex h-full flex-col border-zinc-200/70 bg-white/80 shadow-lg shadow-sky-500/5 backdrop-blur-xl dark:border-zinc-800/80 dark:bg-zinc-900/80",children:[(0,s.jsxs)(o,{className:"flex flex-row items-center justify-between pb-3",children:[(0,s.jsxs)("div",{className:"space-y-1",children:[(0,s.jsxs)(c,{className:"flex items-center gap-2 text-sm font-semibold",children:[(0,s.jsx)(eD.A,{className:"h-4 w-4 text-sky-500"}),t]}),(0,s.jsx)(m,{className:"text-xs",children:i})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsxs)(n.$,{type:"button",size:"sm",variant:"ghost",className:"h-8 px-2 text-xs",onClick:y,children:[(0,s.jsx)(eA.A,{className:"mr-1 h-3 w-3"}),h?g("common.copied"):g("common.copy")]}),(0,s.jsxs)(n.$,{type:"button",size:"sm",variant:"outline",className:"h-8 px-2 text-xs",onClick:()=>{try{let e=new Blob([a||""],{type:"text/javascript;charset=utf-8"}),t=URL.createObjectURL(e),s=document.createElement("a");s.href=t,s.download=i,document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(t)}catch{(0,eP.oR)({title:g("common.downloadErrorTitle"),description:g("common.downloadErrorDesc"),variant:"destructive"})}},children:[(0,s.jsx)(eU.A,{className:"mr-1 h-3 w-3"}),g("common.download")]})]})]}),(0,s.jsxs)(x,{className:"flex-1 space-y-3 pb-4",children:[(0,s.jsxs)("div",{className:"relative max-h-96 overflow-auto rounded-xl bg-gradient-to-b from-zinc-900 via-zinc-950 to-black p-4 text-xs leading-relaxed text-zinc-50 shadow-inner",children:[(0,s.jsx)("pre",{className:"whitespace-pre text-[11px]",children:(0,s.jsx)("code",{dangerouslySetInnerHTML:{__html:j}})}),v&&(0,s.jsx)("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-12 bg-gradient-to-t from-black/90 to-transparent"})]}),v&&(0,s.jsx)(n.$,{type:"button",variant:"ghost",size:"sm",className:"mt-1 h-8 w-full text-xs",onClick:()=>f(!0),children:g("common.showAllCode")})]})]})}function eM(e){var t,a,r,i,h,u,p,f;let{result:g}=e,{t:b}=(0,l.Bd)(),v=g.full.size??0,j=g.treeshake.size??0,y=Math.max(v-j,0),k=v>0?y/v*100:0,N=v/1024,w=j/1024;return(0,s.jsxs)("div",{className:"space-y-6",children:[(0,s.jsx)("div",{className:"flex justify-center",children:(0,s.jsxs)("div",{className:"w-full overflow-hidden rounded-2xl border border-slate-200/80 bg-white/90 shadow-lg shadow-sky-500/10 backdrop-blur-xl dark:border-slate-800/80 dark:bg-slate-900/90",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between border-b border-slate-200/70 px-4 py-2.5 text-[11px] font-medium tracking-wide text-slate-600 dark:border-slate-700 dark:text-slate-300",children:[(0,s.jsx)("span",{children:b("results.overviewTitle")}),(0,s.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full bg-emerald-500/10 px-2 py-0.5 text-[10px] text-emerald-700 dark:bg-emerald-500/15 dark:text-emerald-300",children:[(0,s.jsx)(eL.A,{className:"h-3 w-3"}),b("results.overviewDoneBadge")]})]}),(0,s.jsx)("div",{className:"overflow-x-auto",children:(0,s.jsxs)("table",{className:"min-w-full border-separate border-spacing-0 text-xs",children:[(0,s.jsx)("thead",{children:(0,s.jsxs)("tr",{className:"bg-slate-50/90 text-slate-500 dark:bg-slate-900/80 dark:text-slate-400",children:[(0,s.jsx)("th",{className:"w-32 px-4 py-2 text-left font-medium",children:b("results.tableMetric")}),(0,s.jsx)("th",{className:"px-4 py-2 text-left font-medium",children:b("results.tableFull")}),(0,s.jsx)("th",{className:"px-4 py-2 text-left font-medium",children:b("results.tableTreeshake")})]})}),(0,s.jsxs)("tbody",{children:[(0,s.jsxs)("tr",{className:"border-t border-slate-100/90 dark:border-slate-800/90",children:[(0,s.jsx)("td",{className:"px-4 py-2 text-slate-500 dark:text-slate-400",children:b("results.metricSize")}),(0,s.jsx)("td",{className:"px-4 py-2 font-mono text-[11px] text-slate-800 dark:text-slate-100",children:N?`${N.toFixed(1)} KB`:"--"}),(0,s.jsx)("td",{className:"px-4 py-2 font-mono text-[11px] text-emerald-500 dark:text-emerald-300",children:w?`${w.toFixed(1)} KB`:"--"})]}),(0,s.jsxs)("tr",{className:"border-t border-slate-100/90 dark:border-slate-800/90",children:[(0,s.jsx)("td",{className:"px-4 py-2 text-slate-500 dark:text-slate-400",children:b("results.metricLoadTime")}),(0,s.jsx)("td",{className:"px-4 py-2 font-mono text-[11px] text-slate-800 dark:text-slate-100",children:`~${Math.round(g.full.resourcePerf.duration||0)} ms`}),(0,s.jsx)("td",{className:"px-4 py-2 font-mono text-[11px] text-emerald-500 dark:text-emerald-300",children:`~${Math.round(g.treeshake.resourcePerf.duration||0)} ms`})]}),(0,s.jsxs)("tr",{className:"border-t border-slate-100/90 dark:border-slate-800/90",children:[(0,s.jsx)("td",{className:"px-4 py-2 text-slate-500 dark:text-slate-400",children:b("results.metricModules")}),(0,s.jsx)("td",{className:"px-4 py-2 font-mono text-[11px] text-slate-800 dark:text-slate-100",children:null==(t=g.full.modules.names)?void 0:t.length}),(0,s.jsx)("td",{className:"px-4 py-2 font-mono text-[11px] text-emerald-500 dark:text-emerald-300",children:null==(a=g.treeshake.modules.names)?void 0:a.length})]}),(0,s.jsxs)("tr",{className:"border-t border-slate-100/90 dark:border-slate-800/90",children:[(0,s.jsx)("td",{className:"px-4 py-2 text-slate-500 dark:text-slate-400",children:b("results.metricSavedPercent")}),(0,s.jsx)("td",{className:"px-4 py-2 text-[11px] text-slate-400",children:b("results.metricSavedPercentNA")}),(0,s.jsx)("td",{className:"px-4 py-2 font-mono text-[11px] text-fuchsia-500 dark:text-fuchsia-300",children:k>0?`${k.toFixed(1)}%`:"--"})]})]})]})})]})}),(0,s.jsxs)("div",{className:"grid gap-4 md:grid-cols-4",children:[(0,s.jsxs)(d,{className:"border-zinc-200/80 bg-white/90 shadow-md shadow-sky-500/10 backdrop-blur-xl dark:border-zinc-800/80 dark:bg-zinc-900/90",children:[(0,s.jsxs)(o,{className:"pb-3",children:[(0,s.jsx)(m,{className:"text-[11px] uppercase tracking-wide text-slate-500 dark:text-slate-400",children:b("results.cardFullTitle")}),(0,s.jsxs)(c,{className:"flex items-baseline gap-2 text-xl",children:[(0,s.jsx)("span",{children:N>0?N.toFixed(1):"--"}),(0,s.jsx)("span",{className:"text-xs font-normal text-slate-500 dark:text-slate-400",children:"KB"})]})]}),(0,s.jsxs)(x,{className:"space-y-2 text-xs text-slate-500 dark:text-slate-400",children:[(0,s.jsx)("p",{children:b("results.cardFullDesc")}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("p",{children:b("results.cardFullModules",{count:null==(r=g.full.modules.names)?void 0:r.length})}),(null==(i=g.full.modules.names)?void 0:i.length)&&(0,s.jsxs)(q,{children:[(0,s.jsx)(J,{asChild:!0,children:(0,s.jsxs)(n.$,{variant:"ghost",size:"icon",className:"h-4 w-4 rounded-full hover:bg-slate-100 dark:hover:bg-slate-800",children:[(0,s.jsx)(eF.A,{className:"h-3 w-3 text-slate-400"}),(0,s.jsx)("span",{className:"sr-only",children:"View modules"})]})}),(0,s.jsxs)(W,{className:"w-64 p-0",align:"start",children:[(0,s.jsx)("div",{className:"border-b border-slate-100 px-3 py-2 text-xs font-medium text-slate-600 dark:border-slate-800 dark:text-slate-300",children:"Module Exports"}),(0,s.jsx)(eS,{className:"h-64",children:(0,s.jsx)("div",{className:"p-2",children:g.full.modules.names.map((e,t)=>(0,s.jsx)("div",{className:"rounded px-2 py-1 text-[11px] text-slate-600 hover:bg-slate-50 dark:text-slate-400 dark:hover:bg-slate-900",children:e},t))})})]})]})]})]})]}),(0,s.jsxs)(d,{className:"border-zinc-200/80 bg-white/90 shadow-md shadow-emerald-500/10 backdrop-blur-xl dark:border-zinc-800/80 dark:bg-zinc-900/90",children:[(0,s.jsxs)(o,{className:"pb-3",children:[(0,s.jsx)(m,{className:"text-[11px] uppercase tracking-wide text-slate-500 dark:text-slate-400",children:b("results.cardTreeshakeTitle")}),(0,s.jsxs)(c,{className:"flex items-baseline gap-2 text-xl",children:[(0,s.jsx)("span",{children:w>0?w.toFixed(1):"--"}),(0,s.jsx)("span",{className:"text-xs font-normal text-slate-500 dark:text-slate-400",children:"KB"})]})]}),(0,s.jsxs)(x,{className:"space-y-2 text-xs text-slate-500 dark:text-slate-400",children:[(0,s.jsx)("p",{children:b("results.cardTreeshakeDesc")}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("p",{children:b("results.cardTreeshakeModules",{count:null==(h=g.treeshake.modules.names)?void 0:h.length})}),(null==(u=g.treeshake.modules.names)?void 0:u.length)&&(0,s.jsxs)(q,{children:[(0,s.jsx)(J,{asChild:!0,children:(0,s.jsxs)(n.$,{variant:"ghost",size:"icon",className:"h-4 w-4 rounded-full hover:bg-slate-100 dark:hover:bg-slate-800",children:[(0,s.jsx)(eF.A,{className:"h-3 w-3 text-slate-400"}),(0,s.jsx)("span",{className:"sr-only",children:"View modules"})]})}),(0,s.jsxs)(W,{className:"w-64 p-0",align:"start",children:[(0,s.jsx)("div",{className:"border-b border-slate-100 px-3 py-2 text-xs font-medium text-slate-600 dark:border-slate-800 dark:text-slate-300",children:"Module Exports"}),(0,s.jsx)(eS,{className:"h-64",children:(0,s.jsx)("div",{className:"p-2",children:g.treeshake.modules.names.map((e,t)=>(0,s.jsx)("div",{className:"rounded px-2 py-1 text-[11px] text-slate-600 hover:bg-slate-50 dark:text-slate-400 dark:hover:bg-slate-900",children:e},t))})})]})]})]})]})]}),(0,s.jsxs)(d,{className:"border-zinc-200/80 bg-white/90 shadow-md shadow-fuchsia-500/10 backdrop-blur-xl dark:border-zinc-800/80 dark:bg-zinc-900/90",children:[(0,s.jsxs)(o,{className:"pb-3",children:[(0,s.jsx)(m,{className:"text-[11px] uppercase tracking-wide text-slate-500 dark:text-slate-400",children:b("results.cardSavedTitle")}),(0,s.jsxs)(c,{className:"flex items-baseline gap-2 text-xl",children:[(0,s.jsx)("span",{children:y>0?(y/1024).toFixed(1):"--"}),(0,s.jsx)("span",{className:"text-xs font-normal text-slate-500 dark:text-slate-400",children:"KB"})]})]}),(0,s.jsxs)(x,{className:"space-y-2 text-xs text-slate-500 dark:text-slate-400",children:[(0,s.jsx)("p",{children:b("results.cardSavedDesc")}),(0,s.jsxs)("div",{className:"space-y-1",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between text-[11px]",children:[(0,s.jsx)("span",{children:b("results.cardSavedPercentLabel")}),(0,s.jsxs)("span",{children:[k>0?k.toFixed(1):"--",b("results.cardSavedPercentUnit")]})]}),(0,s.jsx)(ew,{value:k,className:"h-2 bg-fuchsia-500/10"})]})]})]}),(0,s.jsxs)(d,{className:"border-zinc-200/80 bg-white/90 shadow-md shadow-emerald-500/10 backdrop-blur-xl dark:border-zinc-800/80 dark:bg-zinc-900/90",children:[(0,s.jsxs)(o,{className:"pb-3",children:[(0,s.jsx)(m,{className:"text-[11px] uppercase tracking-wide text-slate-500 dark:text-slate-400",children:b("results.cardKeptTitle")}),(0,s.jsxs)(c,{className:"flex items-baseline gap-2 text-xl",children:[(0,s.jsx)("span",{children:null==(p=g.treeshake.modules.names)?void 0:p.length}),(0,s.jsx)("span",{className:"text-xs font-normal text-slate-500 dark:text-slate-400",children:b("results.cardKeptExportsUnit")})]})]}),(0,s.jsxs)(x,{className:"space-y-2 text-xs text-slate-500 dark:text-slate-400",children:[(0,s.jsx)("p",{children:b("results.cardKeptDesc")}),(0,s.jsx)("p",{children:b("results.cardKeptFullCount",{count:null==(f=g.full.modules.names)?void 0:f.length})})]})]})]}),(0,s.jsxs)("section",{className:"space-y-4",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,s.jsx)("h2",{className:"text-sm font-semibold tracking-tight text-slate-800 dark:text-slate-100",children:b("results.codeCompareTitle")}),(0,s.jsx)("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:b("results.codeCompareDesc")})]}),(0,s.jsxs)("div",{className:"grid gap-4 lg:grid-cols-2",children:[(0,s.jsx)(eI,{title:b("results.cardFullTitle"),code:g.full.js??"",fileName:"shared.full.js"}),(0,s.jsx)(eI,{title:b("results.cardTreeshakeTitle"),code:g.treeshake.js??"",fileName:"shared.treeshake.js"})]})]})]})}function e_(e){let{result:t}=e;return t&&0!==t.length?(0,s.jsx)("section",{id:"results",className:"space-y-6",children:(0,s.jsxs)(eR,{defaultValue:t[0].sharedName,className:"w-full",children:[(0,s.jsx)(eT,{className:"w-full justify-start overflow-x-auto",children:t.map(e=>(0,s.jsx)(eB,{value:e.sharedName,children:e.sharedName},e.sharedName))}),t.map(e=>(0,s.jsx)(e$,{value:e.sharedName,children:(0,s.jsx)(eM,{result:e})},e.sharedName))]})}):null}var eO=a(8855);function eV(){let{t:e}=(0,l.Bd)(),[t,a]=(0,r.useState)([{id:"1",name:"",version:"",exports:[]}]),[n,i]=(0,r.useState)(()=>(function(){let e={target:"web,\nbrowserslist:> 0.01%,not dead,not op_mini all",plugins:"",shared:""};if("u"<typeof window)return e;try{let t=window.localStorage.getItem("tree-shaking-config-v1");if(!t)return e;let a=JSON.parse(t);return{...e,...a}}catch{return e}})()),[d,o]=(0,r.useState)({}),[c,m]=(0,r.useState)(!1),[x,h]=(0,r.useState)(null),[u,p]=(0,r.useState)(!1),[f,g]=(0,r.useState)(null),b=()=>{if("u"<typeof document)return;let e=document.getElementById("results");if(e){let t=e.getBoundingClientRect().top+window.scrollY-96;window.scrollTo({top:t,behavior:"smooth"})}},v=e=>{if("u"<typeof window)return;let{x:t=.5,y:a=.5}=e||{};(0,eO.A)({origin:{x:t,y:a},zIndex:100,particleCount:150,spread:180,startVelocity:45,angle:90,gravity:1.2,drift:0,ticks:300})},j=async a=>{let s;if(a){a.preventDefault();let e=a.nativeEvent;e.submitter&&(s=e.submitter.getBoundingClientRect())}let r={items:{}},l=!1;if(t.forEach(t=>{let a={};t.name.trim()||(a.name=e("analyze.formErrorSharedRequired")),t.version.trim()||(a.version=e("analyze.formErrorVersionRequired")),t.exports.length||(a.exports=e("analyze.formErrorExportsRequired")),Object.keys(a).length>0&&(l=!0,r.items[t.id]=a)}),n.shared){for(let t of n.shared.split(/[\n,]/).map(e=>e.trim()).filter(Boolean))if(t.split("@").length<2){r.sharedConfig=e("analyze.sharedVersionRequired",{name:t}),l=!0;break}}if(o(r),l)return void(0,eP.oR)({title:e("analyze.formErrorTitleIncomplete"),description:e("analyze.formErrorDescIncomplete"),variant:"destructive"});try{let a=t[0],r=t.slice(1).map(e=>[e.name.trim(),e.version.trim(),e.exports.map(e=>e.trim()).filter(Boolean)]),l={sharedName:a.name.trim(),sharedVersion:a.version.trim(),shared:[[a.name.trim(),a.version.trim(),a.exports.map(e=>e.trim()).filter(Boolean)]],target:n.target?n.target.split("\n").map(e=>e.trim()).filter(Boolean):["web","browserslist:> 0.01%,not dead,not op_mini all"],plugins:n.plugins?n.plugins.split(",").map(e=>e.trim()).filter(Boolean):[]};if(l.shared.push(...r),n.shared){let e=et(n.shared);l.shared.push(...e)}let i=l.shared.map(e=>e[0]);if(new Set(i).size!==i.length){let t=i.filter((e,t)=>i.indexOf(e)!==t),a=[...new Set(t)];throw Error(e("analyze.errorDuplicateSharedDeps",{names:a.join(", ")}))}if(m(!0),!f)throw Error(e("analyze.errorNoFullResult"));let d=await eu(l,f);if(!d||0===d.length)throw Error(e("analyze.errorRequestFailed"));if(h(d),(0,eP.oR)({title:e("analyze.analyzeSuccessTitle"),description:e("analyze.analyzeSuccessDesc")}),s){let e=(s.top+s.height/2)/window.innerHeight;v({x:.5,y:e})}else v();setTimeout(b,300)}catch(a){let t=a instanceof Error?a.message:e("analyze.analyzeErrorDescFallback");(0,eP.oR)({title:e("analyze.analyzeErrorTitle"),description:t,variant:"destructive"})}finally{m(!1)}};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("section",{className:"mx-auto flex min-h-[calc(100vh-12rem)] w-full max-w-3xl flex-col justify-center pb-24 pt-10",children:(0,s.jsx)(ek,{sharedItems:t,setSharedItems:a,config:n,setConfig:i,formErrors:d,loading:c,advancedOpen:u,setAdvancedOpen:p,onSubmit:j,onReset:()=>{a([{id:"1",name:"",version:"",exports:[]}]),o({}),h(null)},setFullTreeshakeResult:g})}),x&&(0,s.jsx)(e_,{result:x})]})}}}]);
|
/package/dist/frontend/static/js/{954.dfe166a3.js.LICENSE.txt → 296.084d1b43.js.LICENSE.txt}
RENAMED
|
File without changes
|
/package/dist/frontend/static/js/async/{987.6bf8e9b0.js.LICENSE.txt → 987.86ff6794.js.LICENSE.txt}
RENAMED
|
File without changes
|