weapp-vite 5.6.3 → 5.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auto-routes.cjs +2 -2
- package/dist/auto-routes.mjs +1 -1
- package/dist/{chunk-LE4PAGI5.mjs → chunk-AKJEW44F.mjs} +647 -405
- package/dist/{chunk-OQYESMEY.cjs → chunk-FUJ4D6IR.cjs} +757 -515
- package/dist/{chunk-7EOV7C3M.mjs → chunk-GU7U5762.mjs} +1 -1
- package/dist/{chunk-WYNGNSLK.cjs → chunk-VRKZFXIZ.cjs} +4 -4
- package/dist/cli.cjs +879 -280
- package/dist/cli.mjs +880 -281
- package/dist/{config-BuTlQpli.d.cts → config-C-oMiscN.d.cts} +10 -0
- package/dist/{config-BB6bSUwe.d.ts → config-CbKHc1kT.d.ts} +10 -0
- package/dist/config.d.cts +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +2 -2
- package/dist/json.d.cts +1 -1
- package/dist/json.d.ts +1 -1
- package/dist/types.d.cts +1 -1
- package/dist/types.d.ts +1 -1
- package/package.json +2 -2
package/dist/cli.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict"; function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkVRKZFXIZcjs = require('./chunk-VRKZFXIZ.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
@@ -9,16 +9,15 @@ var _chunkWYNGNSLKcjs = require('./chunk-WYNGNSLK.cjs');
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
var _chunkFUJ4D6IRcjs = require('./chunk-FUJ4D6IR.cjs');
|
|
13
15
|
|
|
14
16
|
|
|
15
17
|
var _chunkA5DD7GKXcjs = require('./chunk-A5DD7GKX.cjs');
|
|
16
18
|
|
|
17
19
|
// src/cli.ts
|
|
18
20
|
_chunkA5DD7GKXcjs.init_cjs_shims.call(void 0, );
|
|
19
|
-
var _process = require('process'); var _process2 = _interopRequireDefault(_process);
|
|
20
|
-
var _init = require('@weapp-core/init');
|
|
21
|
-
var _shared = require('@weapp-core/shared');
|
|
22
21
|
|
|
23
22
|
// ../../node_modules/.pnpm/cac@6.7.14/node_modules/cac/dist/index.mjs
|
|
24
23
|
_chunkA5DD7GKXcjs.init_cjs_shims.call(void 0, );
|
|
@@ -123,7 +122,7 @@ var findAllBrackets = (v) => {
|
|
|
123
122
|
const ANGLED_BRACKET_RE_GLOBAL = /<([^>]+)>/g;
|
|
124
123
|
const SQUARE_BRACKET_RE_GLOBAL = /\[([^\]]+)\]/g;
|
|
125
124
|
const res = [];
|
|
126
|
-
const
|
|
125
|
+
const parse3 = (match) => {
|
|
127
126
|
let variadic = false;
|
|
128
127
|
let value = match[1];
|
|
129
128
|
if (value.startsWith("...")) {
|
|
@@ -138,11 +137,11 @@ var findAllBrackets = (v) => {
|
|
|
138
137
|
};
|
|
139
138
|
let angledMatch;
|
|
140
139
|
while (angledMatch = ANGLED_BRACKET_RE_GLOBAL.exec(v)) {
|
|
141
|
-
res.push(
|
|
140
|
+
res.push(parse3(angledMatch));
|
|
142
141
|
}
|
|
143
142
|
let squareMatch;
|
|
144
143
|
while (squareMatch = SQUARE_BRACKET_RE_GLOBAL.exec(v)) {
|
|
145
|
-
res.push(
|
|
144
|
+
res.push(parse3(squareMatch));
|
|
146
145
|
}
|
|
147
146
|
return res;
|
|
148
147
|
};
|
|
@@ -606,6 +605,627 @@ var CAC = class extends _events.EventEmitter {
|
|
|
606
605
|
};
|
|
607
606
|
var cac = (name = "") => new CAC(name);
|
|
608
607
|
|
|
608
|
+
// src/cli/commands/analyze.ts
|
|
609
|
+
_chunkA5DD7GKXcjs.init_cjs_shims.call(void 0, );
|
|
610
|
+
var _process = require('process'); var _process2 = _interopRequireDefault(_process);
|
|
611
|
+
var _fsextra = require('fs-extra'); var _fsextra2 = _interopRequireDefault(_fsextra);
|
|
612
|
+
var _pathe = require('pathe'); var _pathe2 = _interopRequireDefault(_pathe);
|
|
613
|
+
|
|
614
|
+
// src/analyze/subpackages.ts
|
|
615
|
+
_chunkA5DD7GKXcjs.init_cjs_shims.call(void 0, );
|
|
616
|
+
var _buffer = require('buffer');
|
|
617
|
+
|
|
618
|
+
var _vite = require('vite');
|
|
619
|
+
var VIRTUAL_MODULE_INDICATOR = "\0";
|
|
620
|
+
var VIRTUAL_PREFIX = `${_chunkFUJ4D6IRcjs.SHARED_CHUNK_VIRTUAL_PREFIX}/`;
|
|
621
|
+
function isPathInside(parent, candidate) {
|
|
622
|
+
if (!parent) {
|
|
623
|
+
return false;
|
|
624
|
+
}
|
|
625
|
+
const relative = _pathe.posix.relative(parent, candidate);
|
|
626
|
+
return relative === "" || !relative.startsWith("..") && !_pathe.posix.isAbsolute(relative);
|
|
627
|
+
}
|
|
628
|
+
function ensurePackage(packages, classification) {
|
|
629
|
+
const existing = packages.get(classification.id);
|
|
630
|
+
if (existing) {
|
|
631
|
+
return existing;
|
|
632
|
+
}
|
|
633
|
+
const created = {
|
|
634
|
+
...classification,
|
|
635
|
+
files: /* @__PURE__ */ new Map()
|
|
636
|
+
};
|
|
637
|
+
packages.set(classification.id, created);
|
|
638
|
+
return created;
|
|
639
|
+
}
|
|
640
|
+
function ensureModule(modules, id, source, sourceType) {
|
|
641
|
+
const existing = modules.get(id);
|
|
642
|
+
if (existing) {
|
|
643
|
+
return existing;
|
|
644
|
+
}
|
|
645
|
+
const created = {
|
|
646
|
+
id,
|
|
647
|
+
source,
|
|
648
|
+
sourceType,
|
|
649
|
+
packages: /* @__PURE__ */ new Map()
|
|
650
|
+
};
|
|
651
|
+
modules.set(id, created);
|
|
652
|
+
return created;
|
|
653
|
+
}
|
|
654
|
+
function registerModuleInPackage(modules, moduleId, source, sourceType, packageId, fileName) {
|
|
655
|
+
const moduleEntry = ensureModule(modules, moduleId, source, sourceType);
|
|
656
|
+
const files = _nullishCoalesce(moduleEntry.packages.get(packageId), () => ( /* @__PURE__ */ new Set()));
|
|
657
|
+
files.add(fileName);
|
|
658
|
+
moduleEntry.packages.set(packageId, files);
|
|
659
|
+
}
|
|
660
|
+
function classifyPackage(fileName, origin, context) {
|
|
661
|
+
if (fileName.startsWith(VIRTUAL_PREFIX)) {
|
|
662
|
+
const combination = fileName.slice(VIRTUAL_PREFIX.length).split("/")[0] || "shared";
|
|
663
|
+
return {
|
|
664
|
+
id: `virtual:${combination}`,
|
|
665
|
+
label: `\u5171\u4EAB\u865A\u62DF\u5305 ${combination}`,
|
|
666
|
+
type: "virtual"
|
|
667
|
+
};
|
|
668
|
+
}
|
|
669
|
+
const segments = fileName.split("/");
|
|
670
|
+
const rootCandidate = _nullishCoalesce(segments[0], () => ( ""));
|
|
671
|
+
if (rootCandidate && context.subPackageRoots.has(rootCandidate)) {
|
|
672
|
+
const isIndependent = context.independentRoots.has(rootCandidate);
|
|
673
|
+
return {
|
|
674
|
+
id: rootCandidate,
|
|
675
|
+
label: `${isIndependent ? "\u72EC\u7ACB\u5206\u5305" : "\u5206\u5305"} ${rootCandidate}`,
|
|
676
|
+
type: isIndependent || origin === "independent" ? "independent" : "subPackage"
|
|
677
|
+
};
|
|
678
|
+
}
|
|
679
|
+
return {
|
|
680
|
+
id: "__main__",
|
|
681
|
+
label: "\u4E3B\u5305",
|
|
682
|
+
type: "main"
|
|
683
|
+
};
|
|
684
|
+
}
|
|
685
|
+
function normalizeModuleId(id) {
|
|
686
|
+
if (!id || id.includes(VIRTUAL_MODULE_INDICATOR)) {
|
|
687
|
+
return void 0;
|
|
688
|
+
}
|
|
689
|
+
if (!_pathe.posix.isAbsolute(id)) {
|
|
690
|
+
return void 0;
|
|
691
|
+
}
|
|
692
|
+
return _pathe.posix.normalize(id);
|
|
693
|
+
}
|
|
694
|
+
function resolveModuleSourceType(absoluteId, ctx) {
|
|
695
|
+
const { configService } = ctx;
|
|
696
|
+
const isNodeModule = absoluteId.includes("/node_modules/") || absoluteId.includes("\\node_modules\\");
|
|
697
|
+
const pluginRoot = configService.absolutePluginRoot;
|
|
698
|
+
const srcRoot = configService.absoluteSrcRoot;
|
|
699
|
+
const inSrc = isPathInside(srcRoot, absoluteId);
|
|
700
|
+
const inPlugin = pluginRoot ? isPathInside(pluginRoot, absoluteId) : false;
|
|
701
|
+
let sourceType;
|
|
702
|
+
if (isNodeModule) {
|
|
703
|
+
sourceType = "node_modules";
|
|
704
|
+
} else if (inSrc) {
|
|
705
|
+
sourceType = "src";
|
|
706
|
+
} else if (inPlugin) {
|
|
707
|
+
sourceType = "plugin";
|
|
708
|
+
} else {
|
|
709
|
+
sourceType = "workspace";
|
|
710
|
+
}
|
|
711
|
+
return {
|
|
712
|
+
source: configService.relativeAbsoluteSrcRoot(absoluteId),
|
|
713
|
+
sourceType
|
|
714
|
+
};
|
|
715
|
+
}
|
|
716
|
+
function resolveAssetSource(fileName, ctx) {
|
|
717
|
+
const { configService } = ctx;
|
|
718
|
+
const normalized = _pathe.posix.normalize(fileName);
|
|
719
|
+
const srcCandidate = _pathe.posix.resolve(configService.absoluteSrcRoot, normalized);
|
|
720
|
+
if (isPathInside(configService.absoluteSrcRoot, srcCandidate)) {
|
|
721
|
+
return {
|
|
722
|
+
absolute: srcCandidate,
|
|
723
|
+
source: configService.relativeAbsoluteSrcRoot(srcCandidate),
|
|
724
|
+
sourceType: "src"
|
|
725
|
+
};
|
|
726
|
+
}
|
|
727
|
+
const pluginRoot = configService.absolutePluginRoot;
|
|
728
|
+
if (pluginRoot) {
|
|
729
|
+
const pluginBase = _pathe.posix.basename(pluginRoot);
|
|
730
|
+
if (normalized === pluginBase || normalized.startsWith(`${pluginBase}/`)) {
|
|
731
|
+
const relative = normalized === pluginBase ? "" : normalized.slice(pluginBase.length + 1);
|
|
732
|
+
const absolute = _pathe.posix.resolve(pluginRoot, relative);
|
|
733
|
+
if (isPathInside(pluginRoot, absolute)) {
|
|
734
|
+
return {
|
|
735
|
+
absolute,
|
|
736
|
+
source: configService.relativeAbsoluteSrcRoot(absolute),
|
|
737
|
+
sourceType: "plugin"
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
function toArray(value) {
|
|
744
|
+
return Array.from(value);
|
|
745
|
+
}
|
|
746
|
+
function getAssetSize(asset) {
|
|
747
|
+
if (typeof asset.source === "string") {
|
|
748
|
+
return _buffer.Buffer.byteLength(asset.source, "utf8");
|
|
749
|
+
}
|
|
750
|
+
if (asset.source instanceof Uint8Array) {
|
|
751
|
+
return asset.source.byteLength;
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
function processChunk(chunk, origin, ctx, classifierContext, packages, modules) {
|
|
755
|
+
const classification = classifyPackage(chunk.fileName, origin, classifierContext);
|
|
756
|
+
const packageEntry = ensurePackage(packages, classification);
|
|
757
|
+
const chunkEntry = {
|
|
758
|
+
file: chunk.fileName,
|
|
759
|
+
type: "chunk",
|
|
760
|
+
from: origin,
|
|
761
|
+
size: typeof chunk.code === "string" ? _buffer.Buffer.byteLength(chunk.code, "utf8") : void 0,
|
|
762
|
+
isEntry: chunk.isEntry,
|
|
763
|
+
modules: []
|
|
764
|
+
};
|
|
765
|
+
const moduleEntries = Object.entries(_nullishCoalesce(chunk.modules, () => ( {})));
|
|
766
|
+
for (const [rawModuleId, info] of moduleEntries) {
|
|
767
|
+
const absoluteId = normalizeModuleId(rawModuleId);
|
|
768
|
+
if (!absoluteId) {
|
|
769
|
+
continue;
|
|
770
|
+
}
|
|
771
|
+
const { source, sourceType } = resolveModuleSourceType(absoluteId, ctx);
|
|
772
|
+
const moduleEntry = {
|
|
773
|
+
id: absoluteId,
|
|
774
|
+
source,
|
|
775
|
+
sourceType,
|
|
776
|
+
bytes: _optionalChain([info, 'optionalAccess', _2 => _2.renderedLength])
|
|
777
|
+
};
|
|
778
|
+
if (typeof _optionalChain([info, 'optionalAccess', _3 => _3.code]) === "string") {
|
|
779
|
+
moduleEntry.originalBytes = _buffer.Buffer.byteLength(info.code, "utf8");
|
|
780
|
+
}
|
|
781
|
+
chunkEntry.modules.push(moduleEntry);
|
|
782
|
+
registerModuleInPackage(
|
|
783
|
+
modules,
|
|
784
|
+
absoluteId,
|
|
785
|
+
source,
|
|
786
|
+
sourceType,
|
|
787
|
+
classification.id,
|
|
788
|
+
chunk.fileName
|
|
789
|
+
);
|
|
790
|
+
}
|
|
791
|
+
if (chunkEntry.modules) {
|
|
792
|
+
chunkEntry.modules.sort((a, b) => a.source.localeCompare(b.source));
|
|
793
|
+
}
|
|
794
|
+
packageEntry.files.set(chunk.fileName, chunkEntry);
|
|
795
|
+
}
|
|
796
|
+
function processAsset(asset, origin, ctx, classifierContext, packages, modules) {
|
|
797
|
+
const classification = classifyPackage(asset.fileName, origin, classifierContext);
|
|
798
|
+
const packageEntry = ensurePackage(packages, classification);
|
|
799
|
+
const entry = {
|
|
800
|
+
file: asset.fileName,
|
|
801
|
+
type: "asset",
|
|
802
|
+
from: origin,
|
|
803
|
+
size: getAssetSize(asset)
|
|
804
|
+
};
|
|
805
|
+
const assetSource = resolveAssetSource(asset.fileName, ctx);
|
|
806
|
+
if (assetSource) {
|
|
807
|
+
entry.source = assetSource.source;
|
|
808
|
+
registerModuleInPackage(
|
|
809
|
+
modules,
|
|
810
|
+
assetSource.absolute,
|
|
811
|
+
assetSource.source,
|
|
812
|
+
assetSource.sourceType,
|
|
813
|
+
classification.id,
|
|
814
|
+
asset.fileName
|
|
815
|
+
);
|
|
816
|
+
}
|
|
817
|
+
packageEntry.files.set(asset.fileName, entry);
|
|
818
|
+
}
|
|
819
|
+
function processOutput(output, origin, ctx, classifierContext, packages, modules) {
|
|
820
|
+
if (!output) {
|
|
821
|
+
return;
|
|
822
|
+
}
|
|
823
|
+
for (const item of _nullishCoalesce(output.output, () => ( []))) {
|
|
824
|
+
if (item.type === "chunk") {
|
|
825
|
+
processChunk(item, origin, ctx, classifierContext, packages, modules);
|
|
826
|
+
} else if (item.type === "asset") {
|
|
827
|
+
processAsset(item, origin, ctx, classifierContext, packages, modules);
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
function summarizePackages(packages) {
|
|
832
|
+
const order = {
|
|
833
|
+
main: 0,
|
|
834
|
+
subPackage: 1,
|
|
835
|
+
independent: 2,
|
|
836
|
+
virtual: 3
|
|
837
|
+
};
|
|
838
|
+
const reports = toArray(packages.values()).map((pkg) => {
|
|
839
|
+
const files = toArray(pkg.files.values());
|
|
840
|
+
files.sort((a, b) => a.file.localeCompare(b.file));
|
|
841
|
+
return {
|
|
842
|
+
id: pkg.id,
|
|
843
|
+
label: pkg.label,
|
|
844
|
+
type: pkg.type,
|
|
845
|
+
files
|
|
846
|
+
};
|
|
847
|
+
});
|
|
848
|
+
reports.sort((a, b) => {
|
|
849
|
+
const delta = order[a.type] - order[b.type];
|
|
850
|
+
if (delta !== 0) {
|
|
851
|
+
return delta;
|
|
852
|
+
}
|
|
853
|
+
if (a.id === "__main__") {
|
|
854
|
+
return -1;
|
|
855
|
+
}
|
|
856
|
+
if (b.id === "__main__") {
|
|
857
|
+
return 1;
|
|
858
|
+
}
|
|
859
|
+
return a.id.localeCompare(b.id);
|
|
860
|
+
});
|
|
861
|
+
return reports;
|
|
862
|
+
}
|
|
863
|
+
function summarizeModules(modules) {
|
|
864
|
+
const usage = toArray(modules.values()).map((module) => {
|
|
865
|
+
const packages = toArray(module.packages.entries()).map(([packageId, files]) => {
|
|
866
|
+
const sortedFiles = toArray(files).sort((a, b) => a.localeCompare(b));
|
|
867
|
+
return {
|
|
868
|
+
packageId,
|
|
869
|
+
files: sortedFiles
|
|
870
|
+
};
|
|
871
|
+
}).sort((a, b) => {
|
|
872
|
+
if (a.packageId === b.packageId) {
|
|
873
|
+
return 0;
|
|
874
|
+
}
|
|
875
|
+
if (a.packageId === "__main__") {
|
|
876
|
+
return -1;
|
|
877
|
+
}
|
|
878
|
+
if (b.packageId === "__main__") {
|
|
879
|
+
return 1;
|
|
880
|
+
}
|
|
881
|
+
return a.packageId.localeCompare(b.packageId);
|
|
882
|
+
});
|
|
883
|
+
return {
|
|
884
|
+
id: module.id,
|
|
885
|
+
source: module.source,
|
|
886
|
+
sourceType: module.sourceType,
|
|
887
|
+
packages
|
|
888
|
+
};
|
|
889
|
+
});
|
|
890
|
+
usage.sort((a, b) => a.source.localeCompare(b.source));
|
|
891
|
+
return usage;
|
|
892
|
+
}
|
|
893
|
+
function expandVirtualModulePlacements(modules, packages, context) {
|
|
894
|
+
for (const moduleEntry of modules.values()) {
|
|
895
|
+
const virtualEntries = Array.from(moduleEntry.packages.entries()).filter(([packageId]) => packageId.startsWith("virtual:"));
|
|
896
|
+
if (!virtualEntries.length) {
|
|
897
|
+
continue;
|
|
898
|
+
}
|
|
899
|
+
const virtualFileBases = /* @__PURE__ */ new Map();
|
|
900
|
+
for (const [virtualPackageId, files] of virtualEntries) {
|
|
901
|
+
const combination = virtualPackageId.slice("virtual:".length);
|
|
902
|
+
if (!combination) {
|
|
903
|
+
continue;
|
|
904
|
+
}
|
|
905
|
+
const segments = combination.split(/[_+]/).map((segment) => segment.trim()).filter(Boolean);
|
|
906
|
+
if (!segments.length) {
|
|
907
|
+
continue;
|
|
908
|
+
}
|
|
909
|
+
let matchingBases = virtualFileBases.get(virtualPackageId);
|
|
910
|
+
if (!matchingBases) {
|
|
911
|
+
matchingBases = Array.from(files).map((file) => _pathe.posix.basename(file));
|
|
912
|
+
virtualFileBases.set(virtualPackageId, matchingBases);
|
|
913
|
+
}
|
|
914
|
+
for (const root of segments) {
|
|
915
|
+
if (!context.subPackageRoots.has(root)) {
|
|
916
|
+
continue;
|
|
917
|
+
}
|
|
918
|
+
const targetPackage = packages.get(root);
|
|
919
|
+
if (!targetPackage) {
|
|
920
|
+
continue;
|
|
921
|
+
}
|
|
922
|
+
const moduleFiles = _nullishCoalesce(moduleEntry.packages.get(root), () => ( /* @__PURE__ */ new Set()));
|
|
923
|
+
const targetFiles = Array.from(targetPackage.files.values()).filter((fileEntry) => {
|
|
924
|
+
if (!_optionalChain([matchingBases, 'optionalAccess', _4 => _4.length])) {
|
|
925
|
+
return true;
|
|
926
|
+
}
|
|
927
|
+
const base = _pathe.posix.basename(fileEntry.file);
|
|
928
|
+
return matchingBases.includes(base);
|
|
929
|
+
}).map((fileEntry) => fileEntry.file);
|
|
930
|
+
if (targetFiles.length === 0) {
|
|
931
|
+
const fallback = targetPackage.files.values().next().value;
|
|
932
|
+
if (fallback) {
|
|
933
|
+
moduleFiles.add(fallback.file);
|
|
934
|
+
}
|
|
935
|
+
} else {
|
|
936
|
+
for (const fileName of targetFiles) {
|
|
937
|
+
moduleFiles.add(fileName);
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
if (moduleFiles.size > 0) {
|
|
941
|
+
moduleEntry.packages.set(root, moduleFiles);
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
function summarizeSubPackages(metas) {
|
|
948
|
+
const descriptors = metas.map((meta) => {
|
|
949
|
+
const root = _nullishCoalesce(meta.subPackage.root, () => ( ""));
|
|
950
|
+
return {
|
|
951
|
+
root,
|
|
952
|
+
independent: Boolean(meta.subPackage.independent),
|
|
953
|
+
name: meta.subPackage.name
|
|
954
|
+
};
|
|
955
|
+
}).filter((descriptor) => descriptor.root);
|
|
956
|
+
descriptors.sort((a, b) => a.root.localeCompare(b.root));
|
|
957
|
+
return descriptors;
|
|
958
|
+
}
|
|
959
|
+
async function analyzeSubpackages(ctx) {
|
|
960
|
+
const { configService, scanService, buildService } = ctx;
|
|
961
|
+
if (!configService || !scanService || !buildService) {
|
|
962
|
+
throw new Error("analyzeSubpackages requires configService, scanService and buildService to be initialized");
|
|
963
|
+
}
|
|
964
|
+
await scanService.loadAppEntry();
|
|
965
|
+
const subPackageMetas = scanService.loadSubPackages();
|
|
966
|
+
const subPackageRoots = /* @__PURE__ */ new Set();
|
|
967
|
+
const independentRoots = /* @__PURE__ */ new Set();
|
|
968
|
+
for (const meta of subPackageMetas) {
|
|
969
|
+
const root = meta.subPackage.root;
|
|
970
|
+
if (root) {
|
|
971
|
+
subPackageRoots.add(root);
|
|
972
|
+
if (meta.subPackage.independent) {
|
|
973
|
+
independentRoots.add(root);
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
const classifierContext = {
|
|
978
|
+
subPackageRoots,
|
|
979
|
+
independentRoots
|
|
980
|
+
};
|
|
981
|
+
const analysisConfig = configService.merge(
|
|
982
|
+
void 0,
|
|
983
|
+
_chunkFUJ4D6IRcjs.createSharedBuildConfig.call(void 0, configService, scanService),
|
|
984
|
+
{
|
|
985
|
+
build: {
|
|
986
|
+
write: false,
|
|
987
|
+
watch: null
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
);
|
|
991
|
+
const mainResult = await _vite.build.call(void 0, analysisConfig);
|
|
992
|
+
const mainOutputs = Array.isArray(mainResult) ? mainResult : [mainResult];
|
|
993
|
+
const packages = /* @__PURE__ */ new Map();
|
|
994
|
+
const modules = /* @__PURE__ */ new Map();
|
|
995
|
+
for (const output of mainOutputs) {
|
|
996
|
+
processOutput(output, "main", ctx, classifierContext, packages, modules);
|
|
997
|
+
}
|
|
998
|
+
for (const root of independentRoots) {
|
|
999
|
+
const output = buildService.getIndependentOutput(root);
|
|
1000
|
+
processOutput(output, "independent", ctx, classifierContext, packages, modules);
|
|
1001
|
+
}
|
|
1002
|
+
expandVirtualModulePlacements(modules, packages, classifierContext);
|
|
1003
|
+
return {
|
|
1004
|
+
packages: summarizePackages(packages),
|
|
1005
|
+
modules: summarizeModules(modules),
|
|
1006
|
+
subPackages: summarizeSubPackages(subPackageMetas)
|
|
1007
|
+
};
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
// src/cli/options.ts
|
|
1011
|
+
_chunkA5DD7GKXcjs.init_cjs_shims.call(void 0, );
|
|
1012
|
+
function filterDuplicateOptions(options) {
|
|
1013
|
+
for (const [key, value] of Object.entries(options)) {
|
|
1014
|
+
if (Array.isArray(value)) {
|
|
1015
|
+
options[key] = value[value.length - 1];
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
function resolveConfigFile(options) {
|
|
1020
|
+
if (typeof options.config === "string") {
|
|
1021
|
+
return options.config;
|
|
1022
|
+
}
|
|
1023
|
+
if (typeof options.c === "string") {
|
|
1024
|
+
return options.c;
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
function convertBase(value) {
|
|
1028
|
+
if (value === 0) {
|
|
1029
|
+
return "";
|
|
1030
|
+
}
|
|
1031
|
+
return value;
|
|
1032
|
+
}
|
|
1033
|
+
function coerceBooleanOption(value) {
|
|
1034
|
+
if (value === void 0) {
|
|
1035
|
+
return void 0;
|
|
1036
|
+
}
|
|
1037
|
+
if (typeof value === "boolean") {
|
|
1038
|
+
return value;
|
|
1039
|
+
}
|
|
1040
|
+
if (typeof value === "string") {
|
|
1041
|
+
const normalized = value.trim().toLowerCase();
|
|
1042
|
+
if (normalized === "") {
|
|
1043
|
+
return true;
|
|
1044
|
+
}
|
|
1045
|
+
if (normalized === "false" || normalized === "0" || normalized === "off" || normalized === "no") {
|
|
1046
|
+
return false;
|
|
1047
|
+
}
|
|
1048
|
+
if (normalized === "true" || normalized === "1" || normalized === "on" || normalized === "yes") {
|
|
1049
|
+
return true;
|
|
1050
|
+
}
|
|
1051
|
+
return true;
|
|
1052
|
+
}
|
|
1053
|
+
if (typeof value === "number") {
|
|
1054
|
+
return value !== 0;
|
|
1055
|
+
}
|
|
1056
|
+
return Boolean(value);
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
// src/cli/runtime.ts
|
|
1060
|
+
_chunkA5DD7GKXcjs.init_cjs_shims.call(void 0, );
|
|
1061
|
+
function logRuntimeTarget(targets) {
|
|
1062
|
+
_chunkFUJ4D6IRcjs.logger_default.info(`\u76EE\u6807\u5E73\u53F0\uFF1A${targets.label}`);
|
|
1063
|
+
}
|
|
1064
|
+
function resolveRuntimeTargets(options) {
|
|
1065
|
+
const rawPlatform = typeof options.platform === "string" ? options.platform : typeof options.p === "string" ? options.p : void 0;
|
|
1066
|
+
if (!rawPlatform) {
|
|
1067
|
+
return {
|
|
1068
|
+
runMini: true,
|
|
1069
|
+
runWeb: false,
|
|
1070
|
+
mpPlatform: _chunkFUJ4D6IRcjs.DEFAULT_MP_PLATFORM,
|
|
1071
|
+
label: _chunkFUJ4D6IRcjs.DEFAULT_MP_PLATFORM
|
|
1072
|
+
};
|
|
1073
|
+
}
|
|
1074
|
+
const normalized = _chunkFUJ4D6IRcjs.normalizeMiniPlatform.call(void 0, rawPlatform);
|
|
1075
|
+
if (!normalized) {
|
|
1076
|
+
return {
|
|
1077
|
+
runMini: true,
|
|
1078
|
+
runWeb: false,
|
|
1079
|
+
mpPlatform: _chunkFUJ4D6IRcjs.DEFAULT_MP_PLATFORM,
|
|
1080
|
+
label: _chunkFUJ4D6IRcjs.DEFAULT_MP_PLATFORM
|
|
1081
|
+
};
|
|
1082
|
+
}
|
|
1083
|
+
if (normalized === "h5" || normalized === "web") {
|
|
1084
|
+
return {
|
|
1085
|
+
runMini: false,
|
|
1086
|
+
runWeb: true,
|
|
1087
|
+
mpPlatform: void 0,
|
|
1088
|
+
label: normalized === "h5" ? "h5" : "web"
|
|
1089
|
+
};
|
|
1090
|
+
}
|
|
1091
|
+
const mpPlatform = _chunkFUJ4D6IRcjs.resolveMiniPlatform.call(void 0, normalized);
|
|
1092
|
+
if (mpPlatform) {
|
|
1093
|
+
return {
|
|
1094
|
+
runMini: true,
|
|
1095
|
+
runWeb: false,
|
|
1096
|
+
mpPlatform,
|
|
1097
|
+
label: mpPlatform
|
|
1098
|
+
};
|
|
1099
|
+
}
|
|
1100
|
+
_chunkFUJ4D6IRcjs.logger_default.warn(`\u672A\u8BC6\u522B\u7684\u5E73\u53F0 "${rawPlatform}"\uFF0C\u5DF2\u56DE\u9000\u5230 ${_chunkFUJ4D6IRcjs.DEFAULT_MP_PLATFORM}`);
|
|
1101
|
+
return {
|
|
1102
|
+
runMini: true,
|
|
1103
|
+
runWeb: false,
|
|
1104
|
+
mpPlatform: _chunkFUJ4D6IRcjs.DEFAULT_MP_PLATFORM,
|
|
1105
|
+
label: _chunkFUJ4D6IRcjs.DEFAULT_MP_PLATFORM
|
|
1106
|
+
};
|
|
1107
|
+
}
|
|
1108
|
+
function createInlineConfig(mpPlatform) {
|
|
1109
|
+
if (!mpPlatform) {
|
|
1110
|
+
return void 0;
|
|
1111
|
+
}
|
|
1112
|
+
return {
|
|
1113
|
+
weapp: {
|
|
1114
|
+
platform: mpPlatform
|
|
1115
|
+
}
|
|
1116
|
+
};
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
// src/cli/commands/analyze.ts
|
|
1120
|
+
function printAnalysisSummary(result) {
|
|
1121
|
+
const packageLabelMap = /* @__PURE__ */ new Map();
|
|
1122
|
+
const packageModuleSet = /* @__PURE__ */ new Map();
|
|
1123
|
+
for (const pkg of result.packages) {
|
|
1124
|
+
packageLabelMap.set(pkg.id, pkg.label);
|
|
1125
|
+
}
|
|
1126
|
+
for (const module of result.modules) {
|
|
1127
|
+
for (const pkgRef of module.packages) {
|
|
1128
|
+
const set = _nullishCoalesce(packageModuleSet.get(pkgRef.packageId), () => ( /* @__PURE__ */ new Set()));
|
|
1129
|
+
set.add(module.id);
|
|
1130
|
+
packageModuleSet.set(pkgRef.packageId, set);
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
_chunkFUJ4D6IRcjs.logger_default.success("\u5206\u5305\u5206\u6790\u5B8C\u6210");
|
|
1134
|
+
for (const pkg of result.packages) {
|
|
1135
|
+
const chunkCount = pkg.files.filter((file) => file.type === "chunk").length;
|
|
1136
|
+
const assetCount = pkg.files.length - chunkCount;
|
|
1137
|
+
const moduleCount = _nullishCoalesce(_optionalChain([packageModuleSet, 'access', _5 => _5.get, 'call', _6 => _6(pkg.id), 'optionalAccess', _7 => _7.size]), () => ( 0));
|
|
1138
|
+
_chunkFUJ4D6IRcjs.logger_default.info(`- ${pkg.label}\uFF1A${chunkCount} \u4E2A\u6A21\u5757\u4EA7\u7269\uFF0C${assetCount} \u4E2A\u8D44\u6E90\uFF0C\u8986\u76D6 ${moduleCount} \u4E2A\u6E90\u7801\u6A21\u5757`);
|
|
1139
|
+
}
|
|
1140
|
+
if (result.subPackages.length > 0) {
|
|
1141
|
+
_chunkFUJ4D6IRcjs.logger_default.info("\u5206\u5305\u914D\u7F6E\uFF1A");
|
|
1142
|
+
for (const descriptor of result.subPackages) {
|
|
1143
|
+
const segments = [descriptor.root];
|
|
1144
|
+
if (descriptor.name) {
|
|
1145
|
+
segments.push(`\u522B\u540D\uFF1A${descriptor.name}`);
|
|
1146
|
+
}
|
|
1147
|
+
if (descriptor.independent) {
|
|
1148
|
+
segments.push("\u72EC\u7ACB\u6784\u5EFA");
|
|
1149
|
+
}
|
|
1150
|
+
_chunkFUJ4D6IRcjs.logger_default.info(`- ${segments.join("\uFF0C")}`);
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
const duplicates = result.modules.filter((module) => module.packages.length > 1);
|
|
1154
|
+
if (duplicates.length === 0) {
|
|
1155
|
+
_chunkFUJ4D6IRcjs.logger_default.info("\u672A\u68C0\u6D4B\u5230\u8DE8\u5305\u590D\u7528\u7684\u6E90\u7801\u6A21\u5757\u3002");
|
|
1156
|
+
return;
|
|
1157
|
+
}
|
|
1158
|
+
_chunkFUJ4D6IRcjs.logger_default.info(`\u8DE8\u5305\u590D\u7528/\u590D\u5236\u6E90\u7801\u5171 ${duplicates.length} \u9879\uFF1A`);
|
|
1159
|
+
const limit = 10;
|
|
1160
|
+
const entries = duplicates.slice(0, limit);
|
|
1161
|
+
for (const module of entries) {
|
|
1162
|
+
const placements = module.packages.map((pkgRef) => {
|
|
1163
|
+
const label = _nullishCoalesce(packageLabelMap.get(pkgRef.packageId), () => ( pkgRef.packageId));
|
|
1164
|
+
return `${label} \u2192 ${pkgRef.files.join(", ")}`;
|
|
1165
|
+
}).join("\uFF1B");
|
|
1166
|
+
_chunkFUJ4D6IRcjs.logger_default.info(`- ${module.source} (${module.sourceType})\uFF1A${placements}`);
|
|
1167
|
+
}
|
|
1168
|
+
if (duplicates.length > limit) {
|
|
1169
|
+
_chunkFUJ4D6IRcjs.logger_default.info(`- \u2026\u5176\u4F59 ${duplicates.length - limit} \u9879\u8BF7\u4F7F\u7528 \`weapp-vite analyze --json\` \u67E5\u770B`);
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
function registerAnalyzeCommand(cli2) {
|
|
1173
|
+
cli2.command("analyze [root]", "analyze \u4E24\u7AEF\u5305\u4F53\u4E0E\u6E90\u7801\u6620\u5C04").option("--json", `[boolean] \u8F93\u51FA JSON \u7ED3\u679C`).option("--output <file>", `[string] \u5C06\u5206\u6790\u7ED3\u679C\u5199\u5165\u6307\u5B9A\u6587\u4EF6\uFF08JSON\uFF09`).option("-p, --platform <platform>", `[string] target platform (weapp | h5)`).action(async (root, options) => {
|
|
1174
|
+
filterDuplicateOptions(options);
|
|
1175
|
+
const configFile = resolveConfigFile(options);
|
|
1176
|
+
const targets = resolveRuntimeTargets(options);
|
|
1177
|
+
logRuntimeTarget(targets);
|
|
1178
|
+
if (!targets.runMini) {
|
|
1179
|
+
_chunkFUJ4D6IRcjs.logger_default.warn("\u5F53\u524D\u547D\u4EE4\u4EC5\u652F\u6301\u5C0F\u7A0B\u5E8F\u5E73\u53F0\uFF0C\u8BF7\u901A\u8FC7 --platform weapp \u6307\u5B9A\u76EE\u6807\u3002");
|
|
1180
|
+
return;
|
|
1181
|
+
}
|
|
1182
|
+
if (targets.runWeb) {
|
|
1183
|
+
_chunkFUJ4D6IRcjs.logger_default.warn("\u5206\u6790\u547D\u4EE4\u6682\u4E0D\u652F\u6301 Web \u5E73\u53F0\uFF0C\u5C06\u5FFD\u7565\u76F8\u5173\u914D\u7F6E\u3002");
|
|
1184
|
+
}
|
|
1185
|
+
const inlineConfig = createInlineConfig(targets.mpPlatform);
|
|
1186
|
+
try {
|
|
1187
|
+
const ctx = await _chunkVRKZFXIZcjs.createCompilerContext.call(void 0, {
|
|
1188
|
+
cwd: root,
|
|
1189
|
+
mode: _nullishCoalesce(options.mode, () => ( "production")),
|
|
1190
|
+
configFile,
|
|
1191
|
+
inlineConfig
|
|
1192
|
+
});
|
|
1193
|
+
const result = await analyzeSubpackages(ctx);
|
|
1194
|
+
const outputJson = coerceBooleanOption(options.json);
|
|
1195
|
+
const outputOption = typeof options.output === "string" ? options.output.trim() : "";
|
|
1196
|
+
let writtenPath;
|
|
1197
|
+
if (outputOption) {
|
|
1198
|
+
const configService = ctx.configService;
|
|
1199
|
+
const baseDir = _nullishCoalesce(_optionalChain([configService, 'optionalAccess', _8 => _8.cwd]), () => ( _process2.default.cwd()));
|
|
1200
|
+
const resolvedOutputPath = _pathe2.default.isAbsolute(outputOption) ? outputOption : _pathe2.default.resolve(baseDir, outputOption);
|
|
1201
|
+
await _fsextra2.default.ensureDir(_pathe2.default.dirname(resolvedOutputPath));
|
|
1202
|
+
await _fsextra2.default.writeFile(resolvedOutputPath, `${JSON.stringify(result, null, 2)}
|
|
1203
|
+
`, "utf8");
|
|
1204
|
+
const relativeOutput = configService ? configService.relativeCwd(resolvedOutputPath) : resolvedOutputPath;
|
|
1205
|
+
_chunkFUJ4D6IRcjs.logger_default.success(`\u5206\u6790\u7ED3\u679C\u5DF2\u5199\u5165 ${relativeOutput}`);
|
|
1206
|
+
writtenPath = resolvedOutputPath;
|
|
1207
|
+
}
|
|
1208
|
+
if (outputJson) {
|
|
1209
|
+
if (!writtenPath) {
|
|
1210
|
+
_process2.default.stdout.write(`${JSON.stringify(result, null, 2)}
|
|
1211
|
+
`);
|
|
1212
|
+
}
|
|
1213
|
+
} else {
|
|
1214
|
+
printAnalysisSummary(result);
|
|
1215
|
+
}
|
|
1216
|
+
} catch (error) {
|
|
1217
|
+
_chunkFUJ4D6IRcjs.logger_default.error(error);
|
|
1218
|
+
_process2.default.exitCode = 1;
|
|
1219
|
+
}
|
|
1220
|
+
});
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
// src/cli/commands/build.ts
|
|
1224
|
+
_chunkA5DD7GKXcjs.init_cjs_shims.call(void 0, );
|
|
1225
|
+
|
|
1226
|
+
// src/cli/logBuildAppFinish.ts
|
|
1227
|
+
_chunkA5DD7GKXcjs.init_cjs_shims.call(void 0, );
|
|
1228
|
+
|
|
609
1229
|
// ../../node_modules/.pnpm/package-manager-detector@1.5.0/node_modules/package-manager-detector/dist/commands.mjs
|
|
610
1230
|
_chunkA5DD7GKXcjs.init_cjs_shims.call(void 0, );
|
|
611
1231
|
function dashDashArg(agent, agentCommand) {
|
|
@@ -740,17 +1360,133 @@ function constructCommand(value, args) {
|
|
|
740
1360
|
};
|
|
741
1361
|
}
|
|
742
1362
|
|
|
743
|
-
// src/cli.ts
|
|
744
|
-
var
|
|
745
|
-
|
|
1363
|
+
// src/cli/logBuildAppFinish.ts
|
|
1364
|
+
var logBuildAppFinishOnlyShowOnce = false;
|
|
1365
|
+
function logBuildAppFinish(configService, webServer, options = {}) {
|
|
1366
|
+
if (logBuildAppFinishOnlyShowOnce) {
|
|
1367
|
+
return;
|
|
1368
|
+
}
|
|
1369
|
+
const { skipMini = false, skipWeb = false } = options;
|
|
1370
|
+
if (skipMini) {
|
|
1371
|
+
if (webServer) {
|
|
1372
|
+
const urls = webServer.resolvedUrls;
|
|
1373
|
+
const candidates = urls ? [..._nullishCoalesce(urls.local, () => ( [])), ..._nullishCoalesce(urls.network, () => ( []))] : [];
|
|
1374
|
+
if (candidates.length > 0) {
|
|
1375
|
+
_chunkFUJ4D6IRcjs.logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8\uFF0C\u6D4F\u89C8\u5668\u8BBF\u95EE\uFF1A");
|
|
1376
|
+
for (const url of candidates) {
|
|
1377
|
+
_chunkFUJ4D6IRcjs.logger_default.info(` \u279C ${url}`);
|
|
1378
|
+
}
|
|
1379
|
+
} else {
|
|
1380
|
+
_chunkFUJ4D6IRcjs.logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8");
|
|
1381
|
+
}
|
|
1382
|
+
} else {
|
|
1383
|
+
_chunkFUJ4D6IRcjs.logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8");
|
|
1384
|
+
}
|
|
1385
|
+
logBuildAppFinishOnlyShowOnce = true;
|
|
1386
|
+
return;
|
|
1387
|
+
}
|
|
1388
|
+
const { command, args } = _nullishCoalesce(resolveCommand(
|
|
1389
|
+
configService.packageManager.agent,
|
|
1390
|
+
"run",
|
|
1391
|
+
["open"]
|
|
1392
|
+
), () => ( {
|
|
1393
|
+
command: "npm",
|
|
1394
|
+
args: ["run", "open"]
|
|
1395
|
+
}));
|
|
1396
|
+
const devCommand = `${command} ${args.join(" ")}`;
|
|
1397
|
+
_chunkFUJ4D6IRcjs.logger_default.success("\u5E94\u7528\u6784\u5EFA\u5B8C\u6210\uFF01\u9884\u89C8\u65B9\u5F0F ( `2` \u79CD\u9009\u5176\u4E00\u5373\u53EF)\uFF1A");
|
|
1398
|
+
_chunkFUJ4D6IRcjs.logger_default.info(`\u6267\u884C \`${devCommand}\` \u53EF\u4EE5\u76F4\u63A5\u5728 \`\u5FAE\u4FE1\u5F00\u53D1\u8005\u5DE5\u5177\` \u91CC\u6253\u5F00\u5F53\u524D\u5E94\u7528`);
|
|
1399
|
+
_chunkFUJ4D6IRcjs.logger_default.info("\u6216\u624B\u52A8\u6253\u5F00\u5FAE\u4FE1\u5F00\u53D1\u8005\u5DE5\u5177\uFF0C\u5BFC\u5165\u6839\u76EE\u5F55(`project.config.json` \u6587\u4EF6\u6240\u5728\u7684\u76EE\u5F55)\uFF0C\u5373\u53EF\u9884\u89C8\u6548\u679C");
|
|
1400
|
+
if (!skipWeb && webServer) {
|
|
1401
|
+
const urls = webServer.resolvedUrls;
|
|
1402
|
+
const candidates = urls ? [..._nullishCoalesce(urls.local, () => ( [])), ..._nullishCoalesce(urls.network, () => ( []))] : [];
|
|
1403
|
+
if (candidates.length > 0) {
|
|
1404
|
+
_chunkFUJ4D6IRcjs.logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8\uFF0C\u6D4F\u89C8\u5668\u8BBF\u95EE\uFF1A");
|
|
1405
|
+
for (const url of candidates) {
|
|
1406
|
+
_chunkFUJ4D6IRcjs.logger_default.info(` \u279C ${url}`);
|
|
1407
|
+
}
|
|
1408
|
+
} else {
|
|
1409
|
+
_chunkFUJ4D6IRcjs.logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8");
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
logBuildAppFinishOnlyShowOnce = true;
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1415
|
+
// src/cli/openIde.ts
|
|
1416
|
+
_chunkA5DD7GKXcjs.init_cjs_shims.call(void 0, );
|
|
746
1417
|
var _weappidecli = require('weapp-ide-cli');
|
|
1418
|
+
async function openIde() {
|
|
1419
|
+
try {
|
|
1420
|
+
await _weappidecli.parse.call(void 0, ["open", "-p"]);
|
|
1421
|
+
} catch (error) {
|
|
1422
|
+
_chunkFUJ4D6IRcjs.logger_default.error(error);
|
|
1423
|
+
}
|
|
1424
|
+
}
|
|
1425
|
+
|
|
1426
|
+
// src/cli/commands/build.ts
|
|
1427
|
+
function registerBuildCommand(cli2) {
|
|
1428
|
+
cli2.command("build [root]", "build for production").option("--target <target>", `[string] transpile target (default: 'modules')`).option("--outDir <dir>", `[string] output directory (default: dist)`).option("-p, --platform <platform>", `[string] target platform (weapp | h5)`).option(
|
|
1429
|
+
"--sourcemap [output]",
|
|
1430
|
+
`[boolean | "inline" | "hidden"] output source maps for build (default: false)`
|
|
1431
|
+
).option(
|
|
1432
|
+
"--minify [minifier]",
|
|
1433
|
+
`[boolean | "terser" | "esbuild"] enable/disable minification, or specify minifier to use (default: esbuild)`
|
|
1434
|
+
).option(
|
|
1435
|
+
"--emptyOutDir",
|
|
1436
|
+
`[boolean] force empty outDir when it's outside of root`
|
|
1437
|
+
).option("-w, --watch", `[boolean] rebuilds when modules have changed on disk`).option("--skipNpm", `[boolean] if skip npm build`).option("-o, --open", `[boolean] open ide`).action(async (root, options) => {
|
|
1438
|
+
filterDuplicateOptions(options);
|
|
1439
|
+
const configFile = resolveConfigFile(options);
|
|
1440
|
+
const targets = resolveRuntimeTargets(options);
|
|
1441
|
+
logRuntimeTarget(targets);
|
|
1442
|
+
const inlineConfig = createInlineConfig(targets.mpPlatform);
|
|
1443
|
+
const { buildService, configService, webService } = await _chunkVRKZFXIZcjs.createCompilerContext.call(void 0, {
|
|
1444
|
+
cwd: root,
|
|
1445
|
+
mode: _nullishCoalesce(options.mode, () => ( "production")),
|
|
1446
|
+
configFile,
|
|
1447
|
+
inlineConfig
|
|
1448
|
+
});
|
|
1449
|
+
if (targets.runMini) {
|
|
1450
|
+
await buildService.build(options);
|
|
1451
|
+
}
|
|
1452
|
+
const webConfig = configService.weappWebConfig;
|
|
1453
|
+
if (targets.runWeb && _optionalChain([webConfig, 'optionalAccess', _9 => _9.enabled])) {
|
|
1454
|
+
try {
|
|
1455
|
+
await _optionalChain([webService, 'optionalAccess', _10 => _10.build, 'call', _11 => _11()]);
|
|
1456
|
+
_chunkFUJ4D6IRcjs.logger_default.success(`Web \u6784\u5EFA\u5B8C\u6210\uFF0C\u8F93\u51FA\u76EE\u5F55\uFF1A${configService.relativeCwd(webConfig.outDir)}`);
|
|
1457
|
+
} catch (error) {
|
|
1458
|
+
_chunkFUJ4D6IRcjs.logger_default.error(error);
|
|
1459
|
+
throw error;
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
if (targets.runMini) {
|
|
1463
|
+
logBuildAppFinish(configService, void 0, { skipWeb: !targets.runWeb });
|
|
1464
|
+
}
|
|
1465
|
+
if (options.open && targets.runMini) {
|
|
1466
|
+
await openIde();
|
|
1467
|
+
}
|
|
1468
|
+
});
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1471
|
+
// src/cli/commands/create.ts
|
|
1472
|
+
_chunkA5DD7GKXcjs.init_cjs_shims.call(void 0, );
|
|
1473
|
+
var _init = require('@weapp-core/init');
|
|
1474
|
+
function registerCreateCommand(cli2) {
|
|
1475
|
+
cli2.command("create [outDir]", "create project").option("-t, --template <type>", "template type").action(async (outDir, options) => {
|
|
1476
|
+
await _init.createProject.call(void 0, outDir, options.template);
|
|
1477
|
+
});
|
|
1478
|
+
}
|
|
1479
|
+
|
|
1480
|
+
// src/cli/commands/generate.ts
|
|
1481
|
+
_chunkA5DD7GKXcjs.init_cjs_shims.call(void 0, );
|
|
1482
|
+
|
|
747
1483
|
|
|
748
1484
|
// src/schematics.ts
|
|
749
1485
|
_chunkA5DD7GKXcjs.init_cjs_shims.call(void 0, );
|
|
750
1486
|
|
|
751
1487
|
var _schematics = require('@weapp-core/schematics');
|
|
1488
|
+
var _shared = require('@weapp-core/shared');
|
|
752
1489
|
|
|
753
|
-
var _fsextra = require('fs-extra'); var _fsextra2 = _interopRequireDefault(_fsextra);
|
|
754
1490
|
|
|
755
1491
|
function composePath(outDir, filename) {
|
|
756
1492
|
return `${outDir}${outDir ? "/" : ""}${filename}`;
|
|
@@ -788,11 +1524,11 @@ async function loadTemplate(template, context) {
|
|
|
788
1524
|
return void 0;
|
|
789
1525
|
}
|
|
790
1526
|
function resolveTemplate(templates, type, fileType) {
|
|
791
|
-
const scoped = _optionalChain([templates, 'optionalAccess',
|
|
1527
|
+
const scoped = _optionalChain([templates, 'optionalAccess', _12 => _12[type], 'optionalAccess', _13 => _13[fileType]]);
|
|
792
1528
|
if (scoped !== void 0) {
|
|
793
1529
|
return scoped;
|
|
794
1530
|
}
|
|
795
|
-
return _optionalChain([templates, 'optionalAccess',
|
|
1531
|
+
return _optionalChain([templates, 'optionalAccess', _14 => _14.shared, 'optionalAccess', _15 => _15[fileType]]);
|
|
796
1532
|
}
|
|
797
1533
|
async function generate(options) {
|
|
798
1534
|
let { fileName, outDir, extensions, type, cwd, templates } = _shared.defu.call(void 0, options, {
|
|
@@ -847,21 +1583,17 @@ async function generate(options) {
|
|
|
847
1583
|
for (const { code, fileName: fileName2 } of files) {
|
|
848
1584
|
if (code !== void 0) {
|
|
849
1585
|
await _fsextra2.default.outputFile(_pathe2.default.resolve(basepath, fileName2), code, "utf8");
|
|
850
|
-
|
|
1586
|
+
_chunkFUJ4D6IRcjs.logger_default.success(`${composePath(outDir, fileName2)} \u521B\u5EFA\u6210\u529F\uFF01`);
|
|
851
1587
|
}
|
|
852
1588
|
}
|
|
853
1589
|
}
|
|
854
1590
|
|
|
855
|
-
// src/cli.ts
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
node: "20.19.0"
|
|
862
|
-
});
|
|
863
|
-
} catch (e) {
|
|
864
|
-
}
|
|
1591
|
+
// src/cli/loadConfig.ts
|
|
1592
|
+
_chunkA5DD7GKXcjs.init_cjs_shims.call(void 0, );
|
|
1593
|
+
|
|
1594
|
+
|
|
1595
|
+
|
|
1596
|
+
|
|
865
1597
|
async function loadConfig(configFile) {
|
|
866
1598
|
const cwd = _process2.default.cwd();
|
|
867
1599
|
let resolvedConfigFile = configFile;
|
|
@@ -873,14 +1605,14 @@ async function loadConfig(configFile) {
|
|
|
873
1605
|
mode: "development"
|
|
874
1606
|
};
|
|
875
1607
|
const loaded = await _vite.loadConfigFromFile.call(void 0, configEnv, resolvedConfigFile, cwd);
|
|
876
|
-
const weappConfigFilePath = await
|
|
1608
|
+
const weappConfigFilePath = await _chunkFUJ4D6IRcjs.resolveWeappConfigFile.call(void 0, {
|
|
877
1609
|
root: cwd,
|
|
878
1610
|
specified: resolvedConfigFile
|
|
879
1611
|
});
|
|
880
1612
|
let weappLoaded;
|
|
881
1613
|
if (weappConfigFilePath) {
|
|
882
1614
|
const normalizedWeappPath = _pathe2.default.resolve(weappConfigFilePath);
|
|
883
|
-
const normalizedLoadedPath = _optionalChain([loaded, 'optionalAccess',
|
|
1615
|
+
const normalizedLoadedPath = _optionalChain([loaded, 'optionalAccess', _16 => _16.path]) ? _pathe2.default.resolve(loaded.path) : void 0;
|
|
884
1616
|
if (normalizedLoadedPath && normalizedLoadedPath === normalizedWeappPath) {
|
|
885
1617
|
weappLoaded = loaded;
|
|
886
1618
|
} else {
|
|
@@ -890,289 +1622,156 @@ async function loadConfig(configFile) {
|
|
|
890
1622
|
if (!loaded && !weappLoaded) {
|
|
891
1623
|
return void 0;
|
|
892
1624
|
}
|
|
893
|
-
const config = _nullishCoalesce(_optionalChain([loaded, 'optionalAccess',
|
|
894
|
-
if (_optionalChain([weappLoaded, 'optionalAccess',
|
|
1625
|
+
const config = _nullishCoalesce(_optionalChain([loaded, 'optionalAccess', _17 => _17.config]), () => ( (_nullishCoalesce(_optionalChain([weappLoaded, 'optionalAccess', _18 => _18.config]), () => ( {})))));
|
|
1626
|
+
if (_optionalChain([weappLoaded, 'optionalAccess', _19 => _19.config, 'optionalAccess', _20 => _20.weapp])) {
|
|
895
1627
|
config.weapp = _shared.defu.call(void 0,
|
|
896
1628
|
weappLoaded.config.weapp,
|
|
897
1629
|
_nullishCoalesce(config.weapp, () => ( {}))
|
|
898
1630
|
);
|
|
899
1631
|
}
|
|
900
1632
|
const dependencySet = /* @__PURE__ */ new Set();
|
|
901
|
-
for (const dependency of _nullishCoalesce(_optionalChain([loaded, 'optionalAccess',
|
|
1633
|
+
for (const dependency of _nullishCoalesce(_optionalChain([loaded, 'optionalAccess', _21 => _21.dependencies]), () => ( []))) {
|
|
902
1634
|
dependencySet.add(dependency);
|
|
903
1635
|
}
|
|
904
|
-
for (const dependency of _nullishCoalesce(_optionalChain([weappLoaded, 'optionalAccess',
|
|
1636
|
+
for (const dependency of _nullishCoalesce(_optionalChain([weappLoaded, 'optionalAccess', _22 => _22.dependencies]), () => ( []))) {
|
|
905
1637
|
dependencySet.add(dependency);
|
|
906
1638
|
}
|
|
907
1639
|
return {
|
|
908
1640
|
config,
|
|
909
|
-
path: _nullishCoalesce(_nullishCoalesce(_optionalChain([weappLoaded, 'optionalAccess',
|
|
1641
|
+
path: _nullishCoalesce(_nullishCoalesce(_optionalChain([weappLoaded, 'optionalAccess', _23 => _23.path]), () => ( _optionalChain([loaded, 'optionalAccess', _24 => _24.path]))), () => ( resolvedConfigFile)),
|
|
910
1642
|
dependencies: Array.from(dependencySet)
|
|
911
1643
|
};
|
|
912
1644
|
}
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
if (
|
|
924
|
-
|
|
925
|
-
for (const url of candidates) {
|
|
926
|
-
_chunkOQYESMEYcjs.logger_default.info(` \u279C ${url}`);
|
|
927
|
-
}
|
|
928
|
-
} else {
|
|
929
|
-
_chunkOQYESMEYcjs.logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8");
|
|
1645
|
+
|
|
1646
|
+
// src/cli/commands/generate.ts
|
|
1647
|
+
function registerGenerateCommand(cli2) {
|
|
1648
|
+
cli2.command("g [filepath]", "generate component").alias("generate").option("-a, --app", "type app").option("-p, --page", "type app").option("-n, --name <name>", "filename").action(async (filepath, options) => {
|
|
1649
|
+
filterDuplicateOptions(options);
|
|
1650
|
+
const config = await loadConfig(resolveConfigFile(options));
|
|
1651
|
+
let type = "component";
|
|
1652
|
+
let fileName = options.name;
|
|
1653
|
+
if (options.app) {
|
|
1654
|
+
type = "app";
|
|
1655
|
+
if (filepath === void 0) {
|
|
1656
|
+
filepath = "";
|
|
930
1657
|
}
|
|
931
|
-
|
|
932
|
-
_chunkOQYESMEYcjs.logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8");
|
|
1658
|
+
fileName = "app";
|
|
933
1659
|
}
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
const { command, args } = _nullishCoalesce(resolveCommand(
|
|
938
|
-
configService.packageManager.agent,
|
|
939
|
-
"run",
|
|
940
|
-
["open"]
|
|
941
|
-
), () => ( {
|
|
942
|
-
command: "npm",
|
|
943
|
-
args: ["run", "open"]
|
|
944
|
-
}));
|
|
945
|
-
const devCommand = `${command} ${args.join(" ")}`;
|
|
946
|
-
_chunkOQYESMEYcjs.logger_default.success("\u5E94\u7528\u6784\u5EFA\u5B8C\u6210\uFF01\u9884\u89C8\u65B9\u5F0F ( `2` \u79CD\u9009\u5176\u4E00\u5373\u53EF)\uFF1A");
|
|
947
|
-
_chunkOQYESMEYcjs.logger_default.info(`\u6267\u884C \`${devCommand}\` \u53EF\u4EE5\u76F4\u63A5\u5728 \`\u5FAE\u4FE1\u5F00\u53D1\u8005\u5DE5\u5177\` \u91CC\u6253\u5F00\u5F53\u524D\u5E94\u7528`);
|
|
948
|
-
_chunkOQYESMEYcjs.logger_default.info("\u6216\u624B\u52A8\u6253\u5F00\u5FAE\u4FE1\u5F00\u53D1\u8005\u5DE5\u5177\uFF0C\u5BFC\u5165\u6839\u76EE\u5F55(`project.config.json` \u6587\u4EF6\u6240\u5728\u7684\u76EE\u5F55)\uFF0C\u5373\u53EF\u9884\u89C8\u6548\u679C");
|
|
949
|
-
if (!skipWeb && webServer) {
|
|
950
|
-
const urls = webServer.resolvedUrls;
|
|
951
|
-
const candidates = urls ? [..._nullishCoalesce(urls.local, () => ( [])), ..._nullishCoalesce(urls.network, () => ( []))] : [];
|
|
952
|
-
if (candidates.length > 0) {
|
|
953
|
-
_chunkOQYESMEYcjs.logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8\uFF0C\u6D4F\u89C8\u5668\u8BBF\u95EE\uFF1A");
|
|
954
|
-
for (const url of candidates) {
|
|
955
|
-
_chunkOQYESMEYcjs.logger_default.info(` \u279C ${url}`);
|
|
956
|
-
}
|
|
957
|
-
} else {
|
|
958
|
-
_chunkOQYESMEYcjs.logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8");
|
|
1660
|
+
if (filepath === void 0) {
|
|
1661
|
+
_chunkFUJ4D6IRcjs.logger_default.error("weapp-vite generate <outDir> \u547D\u4EE4\u5FC5\u987B\u4F20\u5165\u8DEF\u5F84\u53C2\u6570 outDir");
|
|
1662
|
+
return;
|
|
959
1663
|
}
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
}
|
|
963
|
-
function filterDuplicateOptions(options) {
|
|
964
|
-
for (const [key, value] of Object.entries(options)) {
|
|
965
|
-
if (Array.isArray(value)) {
|
|
966
|
-
options[key] = value[value.length - 1];
|
|
1664
|
+
if (options.page) {
|
|
1665
|
+
type = "page";
|
|
967
1666
|
}
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
}
|
|
978
|
-
function convertBase(v) {
|
|
979
|
-
if (v === 0) {
|
|
980
|
-
return "";
|
|
981
|
-
}
|
|
982
|
-
return v;
|
|
983
|
-
}
|
|
984
|
-
async function openIde() {
|
|
985
|
-
try {
|
|
986
|
-
await _weappidecli.parse.call(void 0, ["open", "-p"]);
|
|
987
|
-
} catch (error) {
|
|
988
|
-
_chunkOQYESMEYcjs.logger_default.error(error);
|
|
989
|
-
}
|
|
990
|
-
}
|
|
991
|
-
function logRuntimeTarget(targets) {
|
|
992
|
-
_chunkOQYESMEYcjs.logger_default.info(`\u76EE\u6807\u5E73\u53F0\uFF1A${targets.label}`);
|
|
993
|
-
}
|
|
994
|
-
function resolveRuntimeTargets(options) {
|
|
995
|
-
const rawPlatform = typeof options.platform === "string" ? options.platform : typeof options.p === "string" ? options.p : void 0;
|
|
996
|
-
if (!rawPlatform) {
|
|
997
|
-
return {
|
|
998
|
-
runMini: true,
|
|
999
|
-
runWeb: false,
|
|
1000
|
-
mpPlatform: _chunkOQYESMEYcjs.DEFAULT_MP_PLATFORM,
|
|
1001
|
-
label: _chunkOQYESMEYcjs.DEFAULT_MP_PLATFORM
|
|
1002
|
-
};
|
|
1003
|
-
}
|
|
1004
|
-
const normalized = _chunkOQYESMEYcjs.normalizeMiniPlatform.call(void 0, rawPlatform);
|
|
1005
|
-
if (!normalized) {
|
|
1006
|
-
return {
|
|
1007
|
-
runMini: true,
|
|
1008
|
-
runWeb: false,
|
|
1009
|
-
mpPlatform: _chunkOQYESMEYcjs.DEFAULT_MP_PLATFORM,
|
|
1010
|
-
label: _chunkOQYESMEYcjs.DEFAULT_MP_PLATFORM
|
|
1011
|
-
};
|
|
1012
|
-
}
|
|
1013
|
-
if (normalized === "h5" || normalized === "web") {
|
|
1014
|
-
return {
|
|
1015
|
-
runMini: false,
|
|
1016
|
-
runWeb: true,
|
|
1017
|
-
mpPlatform: void 0,
|
|
1018
|
-
label: normalized === "h5" ? "h5" : "web"
|
|
1019
|
-
};
|
|
1020
|
-
}
|
|
1021
|
-
const mpPlatform = _chunkOQYESMEYcjs.resolveMiniPlatform.call(void 0, normalized);
|
|
1022
|
-
if (mpPlatform) {
|
|
1023
|
-
return {
|
|
1024
|
-
runMini: true,
|
|
1025
|
-
runWeb: false,
|
|
1026
|
-
mpPlatform,
|
|
1027
|
-
label: mpPlatform
|
|
1028
|
-
};
|
|
1029
|
-
}
|
|
1030
|
-
_chunkOQYESMEYcjs.logger_default.warn(`\u672A\u8BC6\u522B\u7684\u5E73\u53F0 "${rawPlatform}"\uFF0C\u5DF2\u56DE\u9000\u5230 ${_chunkOQYESMEYcjs.DEFAULT_MP_PLATFORM}`);
|
|
1031
|
-
return {
|
|
1032
|
-
runMini: true,
|
|
1033
|
-
runWeb: false,
|
|
1034
|
-
mpPlatform: _chunkOQYESMEYcjs.DEFAULT_MP_PLATFORM,
|
|
1035
|
-
label: _chunkOQYESMEYcjs.DEFAULT_MP_PLATFORM
|
|
1036
|
-
};
|
|
1037
|
-
}
|
|
1038
|
-
function createInlineConfig(mpPlatform) {
|
|
1039
|
-
if (!mpPlatform) {
|
|
1040
|
-
return void 0;
|
|
1041
|
-
}
|
|
1042
|
-
return {
|
|
1043
|
-
weapp: {
|
|
1044
|
-
platform: mpPlatform
|
|
1045
|
-
}
|
|
1046
|
-
};
|
|
1047
|
-
}
|
|
1048
|
-
cli.option("-c, --config <file>", `[string] use specified config file`).option("--base <path>", `[string] public base path (default: /)`, {
|
|
1049
|
-
type: [convertBase]
|
|
1050
|
-
}).option("-l, --logLevel <level>", `[string] info | warn | error | silent`).option("--clearScreen", `[boolean] allow/disable clear screen when logging`).option("-d, --debug [feat]", `[string | boolean] show debug logs`).option("-f, --filter <filter>", `[string] filter debug logs`).option("-m, --mode <mode>", `[string] set env mode`);
|
|
1051
|
-
cli.command("[root]", "start dev server").alias("serve").alias("dev").option("--skipNpm", `[boolean] if skip npm build`).option("-o, --open", `[boolean] open ide`).option("-p, --platform <platform>", `[string] target platform (weapp | h5)`).action(async (root, options) => {
|
|
1052
|
-
filterDuplicateOptions(options);
|
|
1053
|
-
const configFile = resolveConfigFile(options);
|
|
1054
|
-
const targets = resolveRuntimeTargets(options);
|
|
1055
|
-
logRuntimeTarget(targets);
|
|
1056
|
-
const inlineConfig = createInlineConfig(targets.mpPlatform);
|
|
1057
|
-
const { buildService, configService, webService } = await _chunkWYNGNSLKcjs.createCompilerContext.call(void 0, {
|
|
1058
|
-
cwd: root,
|
|
1059
|
-
mode: _nullishCoalesce(options.mode, () => ( "development")),
|
|
1060
|
-
isDev: true,
|
|
1061
|
-
configFile,
|
|
1062
|
-
inlineConfig
|
|
1667
|
+
const generateOptions = _optionalChain([config, 'optionalAccess', _25 => _25.config, 'access', _26 => _26.weapp, 'optionalAccess', _27 => _27.generate]);
|
|
1668
|
+
fileName = _nullishCoalesce(_optionalChain([generateOptions, 'optionalAccess', _28 => _28.filenames, 'optionalAccess', _29 => _29[type]]), () => ( fileName));
|
|
1669
|
+
await generate({
|
|
1670
|
+
outDir: _pathe2.default.join(_nullishCoalesce(_optionalChain([generateOptions, 'optionalAccess', _30 => _30.dirs, 'optionalAccess', _31 => _31[type]]), () => ( "")), filepath),
|
|
1671
|
+
type,
|
|
1672
|
+
fileName,
|
|
1673
|
+
extensions: _optionalChain([generateOptions, 'optionalAccess', _32 => _32.extensions]),
|
|
1674
|
+
templates: _optionalChain([generateOptions, 'optionalAccess', _33 => _33.templates])
|
|
1675
|
+
});
|
|
1063
1676
|
});
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1677
|
+
}
|
|
1678
|
+
|
|
1679
|
+
// src/cli/commands/init.ts
|
|
1680
|
+
_chunkA5DD7GKXcjs.init_cjs_shims.call(void 0, );
|
|
1681
|
+
|
|
1682
|
+
function registerInitCommand(cli2) {
|
|
1683
|
+
cli2.command("init").action(async () => {
|
|
1069
1684
|
try {
|
|
1070
|
-
|
|
1685
|
+
await _init.initConfig.call(void 0, {
|
|
1686
|
+
command: "weapp-vite"
|
|
1687
|
+
});
|
|
1071
1688
|
} catch (error) {
|
|
1072
|
-
|
|
1073
|
-
throw error;
|
|
1689
|
+
_chunkFUJ4D6IRcjs.logger_default.error(error);
|
|
1074
1690
|
}
|
|
1075
|
-
}
|
|
1076
|
-
if (targets.runMini) {
|
|
1077
|
-
logBuildAppFinish(configService, webServer, { skipWeb: !targets.runWeb });
|
|
1078
|
-
} else if (targets.runWeb) {
|
|
1079
|
-
logBuildAppFinish(configService, webServer, { skipMini: true });
|
|
1080
|
-
}
|
|
1081
|
-
if (options.open && targets.runMini) {
|
|
1082
|
-
await openIde();
|
|
1083
|
-
}
|
|
1084
|
-
});
|
|
1085
|
-
cli.command("build [root]", "build for production").option("--target <target>", `[string] transpile target (default: 'modules')`).option("--outDir <dir>", `[string] output directory (default: dist)`).option("-p, --platform <platform>", `[string] target platform (weapp | h5)`).option(
|
|
1086
|
-
"--sourcemap [output]",
|
|
1087
|
-
`[boolean | "inline" | "hidden"] output source maps for build (default: false)`
|
|
1088
|
-
).option(
|
|
1089
|
-
"--minify [minifier]",
|
|
1090
|
-
`[boolean | "terser" | "esbuild"] enable/disable minification, or specify minifier to use (default: esbuild)`
|
|
1091
|
-
).option(
|
|
1092
|
-
"--emptyOutDir",
|
|
1093
|
-
`[boolean] force empty outDir when it's outside of root`
|
|
1094
|
-
).option("-w, --watch", `[boolean] rebuilds when modules have changed on disk`).option("--skipNpm", `[boolean] if skip npm build`).option("-o, --open", `[boolean] open ide`).action(async (root, options) => {
|
|
1095
|
-
filterDuplicateOptions(options);
|
|
1096
|
-
const configFile = resolveConfigFile(options);
|
|
1097
|
-
const targets = resolveRuntimeTargets(options);
|
|
1098
|
-
logRuntimeTarget(targets);
|
|
1099
|
-
const inlineConfig = createInlineConfig(targets.mpPlatform);
|
|
1100
|
-
const { buildService, configService, webService } = await _chunkWYNGNSLKcjs.createCompilerContext.call(void 0, {
|
|
1101
|
-
cwd: root,
|
|
1102
|
-
mode: _nullishCoalesce(options.mode, () => ( "production")),
|
|
1103
|
-
configFile,
|
|
1104
|
-
inlineConfig
|
|
1105
1691
|
});
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1692
|
+
}
|
|
1693
|
+
|
|
1694
|
+
// src/cli/commands/npm.ts
|
|
1695
|
+
_chunkA5DD7GKXcjs.init_cjs_shims.call(void 0, );
|
|
1696
|
+
|
|
1697
|
+
function registerNpmCommand(cli2) {
|
|
1698
|
+
cli2.command("npm").alias("build:npm").alias("build-npm").action(async () => {
|
|
1111
1699
|
try {
|
|
1112
|
-
await
|
|
1113
|
-
_chunkOQYESMEYcjs.logger_default.success(`Web \u6784\u5EFA\u5B8C\u6210\uFF0C\u8F93\u51FA\u76EE\u5F55\uFF1A${configService.relativeCwd(webConfig.outDir)}`);
|
|
1700
|
+
await _weappidecli.parse.call(void 0, ["build-npm", "-p"]);
|
|
1114
1701
|
} catch (error) {
|
|
1115
|
-
|
|
1116
|
-
throw error;
|
|
1702
|
+
_chunkFUJ4D6IRcjs.logger_default.error(error);
|
|
1117
1703
|
}
|
|
1118
|
-
}
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1704
|
+
});
|
|
1705
|
+
}
|
|
1706
|
+
|
|
1707
|
+
// src/cli/commands/open.ts
|
|
1708
|
+
_chunkA5DD7GKXcjs.init_cjs_shims.call(void 0, );
|
|
1709
|
+
function registerOpenCommand(cli2) {
|
|
1710
|
+
cli2.command("open").action(async () => {
|
|
1123
1711
|
await openIde();
|
|
1124
|
-
}
|
|
1125
|
-
}
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1712
|
+
});
|
|
1713
|
+
}
|
|
1714
|
+
|
|
1715
|
+
// src/cli/commands/serve.ts
|
|
1716
|
+
_chunkA5DD7GKXcjs.init_cjs_shims.call(void 0, );
|
|
1717
|
+
function registerServeCommand(cli2) {
|
|
1718
|
+
cli2.command("[root]", "start dev server").alias("serve").alias("dev").option("--skipNpm", `[boolean] if skip npm build`).option("-o, --open", `[boolean] open ide`).option("-p, --platform <platform>", `[string] target platform (weapp | h5)`).action(async (root, options) => {
|
|
1719
|
+
filterDuplicateOptions(options);
|
|
1720
|
+
const configFile = resolveConfigFile(options);
|
|
1721
|
+
const targets = resolveRuntimeTargets(options);
|
|
1722
|
+
logRuntimeTarget(targets);
|
|
1723
|
+
const inlineConfig = createInlineConfig(targets.mpPlatform);
|
|
1724
|
+
const { buildService, configService, webService } = await _chunkVRKZFXIZcjs.createCompilerContext.call(void 0, {
|
|
1725
|
+
cwd: root,
|
|
1726
|
+
mode: _nullishCoalesce(options.mode, () => ( "development")),
|
|
1727
|
+
isDev: true,
|
|
1728
|
+
configFile,
|
|
1729
|
+
inlineConfig
|
|
1130
1730
|
});
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
});
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
type = "app";
|
|
1151
|
-
if (filepath === void 0) {
|
|
1152
|
-
filepath = "";
|
|
1731
|
+
if (targets.runMini) {
|
|
1732
|
+
await buildService.build(options);
|
|
1733
|
+
}
|
|
1734
|
+
let webServer;
|
|
1735
|
+
if (targets.runWeb) {
|
|
1736
|
+
try {
|
|
1737
|
+
webServer = await _optionalChain([webService, 'optionalAccess', _34 => _34.startDevServer, 'call', _35 => _35()]);
|
|
1738
|
+
} catch (error) {
|
|
1739
|
+
_chunkFUJ4D6IRcjs.logger_default.error(error);
|
|
1740
|
+
throw error;
|
|
1741
|
+
}
|
|
1742
|
+
}
|
|
1743
|
+
if (targets.runMini) {
|
|
1744
|
+
logBuildAppFinish(configService, webServer, { skipWeb: !targets.runWeb });
|
|
1745
|
+
} else if (targets.runWeb) {
|
|
1746
|
+
logBuildAppFinish(configService, webServer, { skipMini: true });
|
|
1747
|
+
}
|
|
1748
|
+
if (options.open && targets.runMini) {
|
|
1749
|
+
await openIde();
|
|
1153
1750
|
}
|
|
1154
|
-
fileName = "app";
|
|
1155
|
-
}
|
|
1156
|
-
if (filepath === void 0) {
|
|
1157
|
-
_chunkOQYESMEYcjs.logger_default.error("weapp-vite generate <outDir> \u547D\u4EE4\u5FC5\u987B\u4F20\u5165\u8DEF\u5F84\u53C2\u6570 outDir");
|
|
1158
|
-
return;
|
|
1159
|
-
}
|
|
1160
|
-
if (options.page) {
|
|
1161
|
-
type = "page";
|
|
1162
|
-
}
|
|
1163
|
-
const generateOptions = _optionalChain([config, 'optionalAccess', _20 => _20.config, 'access', _21 => _21.weapp, 'optionalAccess', _22 => _22.generate]);
|
|
1164
|
-
fileName = _nullishCoalesce(_optionalChain([generateOptions, 'optionalAccess', _23 => _23.filenames, 'optionalAccess', _24 => _24[type]]), () => ( fileName));
|
|
1165
|
-
await generate({
|
|
1166
|
-
outDir: _pathe2.default.join(_nullishCoalesce(_optionalChain([generateOptions, 'optionalAccess', _25 => _25.dirs, 'optionalAccess', _26 => _26[type]]), () => ( "")), filepath),
|
|
1167
|
-
type,
|
|
1168
|
-
fileName,
|
|
1169
|
-
extensions: _optionalChain([generateOptions, 'optionalAccess', _27 => _27.extensions]),
|
|
1170
|
-
templates: _optionalChain([generateOptions, 'optionalAccess', _28 => _28.templates])
|
|
1171
1751
|
});
|
|
1172
|
-
}
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1752
|
+
}
|
|
1753
|
+
|
|
1754
|
+
// src/cli.ts
|
|
1755
|
+
var cli = cac("weapp-vite");
|
|
1756
|
+
try {
|
|
1757
|
+
_chunkFUJ4D6IRcjs.checkRuntime.call(void 0, {
|
|
1758
|
+
bun: "0.0.0",
|
|
1759
|
+
deno: "0.0.0",
|
|
1760
|
+
node: "20.19.0"
|
|
1761
|
+
});
|
|
1762
|
+
} catch (e) {
|
|
1763
|
+
}
|
|
1764
|
+
cli.option("-c, --config <file>", `[string] use specified config file`).option("--base <path>", `[string] public base path (default: /)`, {
|
|
1765
|
+
type: [convertBase]
|
|
1766
|
+
}).option("-l, --logLevel <level>", `[string] info | warn | error | silent`).option("--clearScreen", `[boolean] allow/disable clear screen when logging`).option("-d, --debug [feat]", `[string | boolean] show debug logs`).option("-f, --filter <filter>", `[string] filter debug logs`).option("-m, --mode <mode>", `[string] set env mode`);
|
|
1767
|
+
registerServeCommand(cli);
|
|
1768
|
+
registerBuildCommand(cli);
|
|
1769
|
+
registerAnalyzeCommand(cli);
|
|
1770
|
+
registerInitCommand(cli);
|
|
1771
|
+
registerOpenCommand(cli);
|
|
1772
|
+
registerNpmCommand(cli);
|
|
1773
|
+
registerGenerateCommand(cli);
|
|
1774
|
+
registerCreateCommand(cli);
|
|
1176
1775
|
cli.help();
|
|
1177
|
-
cli.version(
|
|
1776
|
+
cli.version(_chunkFUJ4D6IRcjs.VERSION);
|
|
1178
1777
|
cli.parse();
|