weapp-vite 4.0.1 → 4.0.2
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/{chunk-ZT6ITV3W.cjs → chunk-4RA3EKOJ.cjs} +239 -8
- package/dist/{chunk-3XZWLVEW.mjs → chunk-X6MUD4OM.mjs} +239 -8
- package/dist/cli.cjs +13 -13
- package/dist/cli.mjs +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.mjs +1 -1
- package/package.json +4 -4
|
@@ -9631,7 +9631,7 @@ var PathScurryBase = class {
|
|
|
9631
9631
|
results.push(withFileTypes ? entry : entry.fullpath());
|
|
9632
9632
|
}
|
|
9633
9633
|
const dirs = /* @__PURE__ */ new Set();
|
|
9634
|
-
const
|
|
9634
|
+
const walk2 = /* @__PURE__ */ _chunkWAO6ZIROcjs.__name.call(void 0, (dir, cb) => {
|
|
9635
9635
|
dirs.add(dir);
|
|
9636
9636
|
dir.readdirCB((er, entries) => {
|
|
9637
9637
|
if (er) {
|
|
@@ -9649,10 +9649,10 @@ var PathScurryBase = class {
|
|
|
9649
9649
|
results.push(withFileTypes ? e2 : e2.fullpath());
|
|
9650
9650
|
}
|
|
9651
9651
|
if (follow && e2.isSymbolicLink()) {
|
|
9652
|
-
e2.realpath().then((r4) => _optionalChain([r4, 'optionalAccess', _170 => _170.isUnknown, 'call', _171 => _171()]) ? r4.lstat() : r4).then((r4) => _optionalChain([r4, 'optionalAccess', _172 => _172.shouldWalk, 'call', _173 => _173(dirs, walkFilter)]) ?
|
|
9652
|
+
e2.realpath().then((r4) => _optionalChain([r4, 'optionalAccess', _170 => _170.isUnknown, 'call', _171 => _171()]) ? r4.lstat() : r4).then((r4) => _optionalChain([r4, 'optionalAccess', _172 => _172.shouldWalk, 'call', _173 => _173(dirs, walkFilter)]) ? walk2(r4, next) : next());
|
|
9653
9653
|
} else {
|
|
9654
9654
|
if (e2.shouldWalk(dirs, walkFilter)) {
|
|
9655
|
-
|
|
9655
|
+
walk2(e2, next);
|
|
9656
9656
|
} else {
|
|
9657
9657
|
next();
|
|
9658
9658
|
}
|
|
@@ -9662,7 +9662,7 @@ var PathScurryBase = class {
|
|
|
9662
9662
|
}, "walk");
|
|
9663
9663
|
const start = entry;
|
|
9664
9664
|
return new Promise((res, rej) => {
|
|
9665
|
-
|
|
9665
|
+
walk2(start, (er) => {
|
|
9666
9666
|
if (er) return rej(er);
|
|
9667
9667
|
res(results);
|
|
9668
9668
|
});
|
|
@@ -13539,6 +13539,206 @@ function analyzeCommonJson(json) {
|
|
|
13539
13539
|
}
|
|
13540
13540
|
_chunkWAO6ZIROcjs.__name.call(void 0, analyzeCommonJson, "analyzeCommonJson");
|
|
13541
13541
|
|
|
13542
|
+
// src/plugins/utils/ast.ts
|
|
13543
|
+
_chunkWAO6ZIROcjs.init_cjs_shims.call(void 0, );
|
|
13544
|
+
|
|
13545
|
+
// ../../node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/index.js
|
|
13546
|
+
_chunkWAO6ZIROcjs.init_cjs_shims.call(void 0, );
|
|
13547
|
+
|
|
13548
|
+
// ../../node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/sync.js
|
|
13549
|
+
_chunkWAO6ZIROcjs.init_cjs_shims.call(void 0, );
|
|
13550
|
+
|
|
13551
|
+
// ../../node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/walker.js
|
|
13552
|
+
_chunkWAO6ZIROcjs.init_cjs_shims.call(void 0, );
|
|
13553
|
+
var WalkerBase = class {
|
|
13554
|
+
static {
|
|
13555
|
+
_chunkWAO6ZIROcjs.__name.call(void 0, this, "WalkerBase");
|
|
13556
|
+
}
|
|
13557
|
+
constructor() {
|
|
13558
|
+
this.should_skip = false;
|
|
13559
|
+
this.should_remove = false;
|
|
13560
|
+
this.replacement = null;
|
|
13561
|
+
this.context = {
|
|
13562
|
+
skip: /* @__PURE__ */ _chunkWAO6ZIROcjs.__name.call(void 0, () => this.should_skip = true, "skip"),
|
|
13563
|
+
remove: /* @__PURE__ */ _chunkWAO6ZIROcjs.__name.call(void 0, () => this.should_remove = true, "remove"),
|
|
13564
|
+
replace: /* @__PURE__ */ _chunkWAO6ZIROcjs.__name.call(void 0, (node) => this.replacement = node, "replace")
|
|
13565
|
+
};
|
|
13566
|
+
}
|
|
13567
|
+
/**
|
|
13568
|
+
* @template {Node} Parent
|
|
13569
|
+
* @param {Parent | null | undefined} parent
|
|
13570
|
+
* @param {keyof Parent | null | undefined} prop
|
|
13571
|
+
* @param {number | null | undefined} index
|
|
13572
|
+
* @param {Node} node
|
|
13573
|
+
*/
|
|
13574
|
+
replace(parent, prop, index, node) {
|
|
13575
|
+
if (parent && prop) {
|
|
13576
|
+
if (index != null) {
|
|
13577
|
+
parent[prop][index] = node;
|
|
13578
|
+
} else {
|
|
13579
|
+
parent[prop] = node;
|
|
13580
|
+
}
|
|
13581
|
+
}
|
|
13582
|
+
}
|
|
13583
|
+
/**
|
|
13584
|
+
* @template {Node} Parent
|
|
13585
|
+
* @param {Parent | null | undefined} parent
|
|
13586
|
+
* @param {keyof Parent | null | undefined} prop
|
|
13587
|
+
* @param {number | null | undefined} index
|
|
13588
|
+
*/
|
|
13589
|
+
remove(parent, prop, index) {
|
|
13590
|
+
if (parent && prop) {
|
|
13591
|
+
if (index !== null && index !== void 0) {
|
|
13592
|
+
parent[prop].splice(index, 1);
|
|
13593
|
+
} else {
|
|
13594
|
+
delete parent[prop];
|
|
13595
|
+
}
|
|
13596
|
+
}
|
|
13597
|
+
}
|
|
13598
|
+
};
|
|
13599
|
+
|
|
13600
|
+
// ../../node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/sync.js
|
|
13601
|
+
var SyncWalker = class extends WalkerBase {
|
|
13602
|
+
static {
|
|
13603
|
+
_chunkWAO6ZIROcjs.__name.call(void 0, this, "SyncWalker");
|
|
13604
|
+
}
|
|
13605
|
+
/**
|
|
13606
|
+
*
|
|
13607
|
+
* @param {SyncHandler} [enter]
|
|
13608
|
+
* @param {SyncHandler} [leave]
|
|
13609
|
+
*/
|
|
13610
|
+
constructor(enter, leave) {
|
|
13611
|
+
super();
|
|
13612
|
+
this.should_skip = false;
|
|
13613
|
+
this.should_remove = false;
|
|
13614
|
+
this.replacement = null;
|
|
13615
|
+
this.context = {
|
|
13616
|
+
skip: /* @__PURE__ */ _chunkWAO6ZIROcjs.__name.call(void 0, () => this.should_skip = true, "skip"),
|
|
13617
|
+
remove: /* @__PURE__ */ _chunkWAO6ZIROcjs.__name.call(void 0, () => this.should_remove = true, "remove"),
|
|
13618
|
+
replace: /* @__PURE__ */ _chunkWAO6ZIROcjs.__name.call(void 0, (node) => this.replacement = node, "replace")
|
|
13619
|
+
};
|
|
13620
|
+
this.enter = enter;
|
|
13621
|
+
this.leave = leave;
|
|
13622
|
+
}
|
|
13623
|
+
/**
|
|
13624
|
+
* @template {Node} Parent
|
|
13625
|
+
* @param {Node} node
|
|
13626
|
+
* @param {Parent | null} parent
|
|
13627
|
+
* @param {keyof Parent} [prop]
|
|
13628
|
+
* @param {number | null} [index]
|
|
13629
|
+
* @returns {Node | null}
|
|
13630
|
+
*/
|
|
13631
|
+
visit(node, parent, prop, index) {
|
|
13632
|
+
if (node) {
|
|
13633
|
+
if (this.enter) {
|
|
13634
|
+
const _should_skip = this.should_skip;
|
|
13635
|
+
const _should_remove = this.should_remove;
|
|
13636
|
+
const _replacement = this.replacement;
|
|
13637
|
+
this.should_skip = false;
|
|
13638
|
+
this.should_remove = false;
|
|
13639
|
+
this.replacement = null;
|
|
13640
|
+
this.enter.call(this.context, node, parent, prop, index);
|
|
13641
|
+
if (this.replacement) {
|
|
13642
|
+
node = this.replacement;
|
|
13643
|
+
this.replace(parent, prop, index, node);
|
|
13644
|
+
}
|
|
13645
|
+
if (this.should_remove) {
|
|
13646
|
+
this.remove(parent, prop, index);
|
|
13647
|
+
}
|
|
13648
|
+
const skipped = this.should_skip;
|
|
13649
|
+
const removed = this.should_remove;
|
|
13650
|
+
this.should_skip = _should_skip;
|
|
13651
|
+
this.should_remove = _should_remove;
|
|
13652
|
+
this.replacement = _replacement;
|
|
13653
|
+
if (skipped) return node;
|
|
13654
|
+
if (removed) return null;
|
|
13655
|
+
}
|
|
13656
|
+
let key;
|
|
13657
|
+
for (key in node) {
|
|
13658
|
+
const value = node[key];
|
|
13659
|
+
if (value && typeof value === "object") {
|
|
13660
|
+
if (Array.isArray(value)) {
|
|
13661
|
+
const nodes = (
|
|
13662
|
+
/** @type {Array<unknown>} */
|
|
13663
|
+
value
|
|
13664
|
+
);
|
|
13665
|
+
for (let i = 0; i < nodes.length; i += 1) {
|
|
13666
|
+
const item = nodes[i];
|
|
13667
|
+
if (isNode(item)) {
|
|
13668
|
+
if (!this.visit(item, node, key, i)) {
|
|
13669
|
+
i--;
|
|
13670
|
+
}
|
|
13671
|
+
}
|
|
13672
|
+
}
|
|
13673
|
+
} else if (isNode(value)) {
|
|
13674
|
+
this.visit(value, node, key, null);
|
|
13675
|
+
}
|
|
13676
|
+
}
|
|
13677
|
+
}
|
|
13678
|
+
if (this.leave) {
|
|
13679
|
+
const _replacement = this.replacement;
|
|
13680
|
+
const _should_remove = this.should_remove;
|
|
13681
|
+
this.replacement = null;
|
|
13682
|
+
this.should_remove = false;
|
|
13683
|
+
this.leave.call(this.context, node, parent, prop, index);
|
|
13684
|
+
if (this.replacement) {
|
|
13685
|
+
node = this.replacement;
|
|
13686
|
+
this.replace(parent, prop, index, node);
|
|
13687
|
+
}
|
|
13688
|
+
if (this.should_remove) {
|
|
13689
|
+
this.remove(parent, prop, index);
|
|
13690
|
+
}
|
|
13691
|
+
const removed = this.should_remove;
|
|
13692
|
+
this.replacement = _replacement;
|
|
13693
|
+
this.should_remove = _should_remove;
|
|
13694
|
+
if (removed) return null;
|
|
13695
|
+
}
|
|
13696
|
+
}
|
|
13697
|
+
return node;
|
|
13698
|
+
}
|
|
13699
|
+
};
|
|
13700
|
+
function isNode(value) {
|
|
13701
|
+
return value !== null && typeof value === "object" && "type" in value && typeof value.type === "string";
|
|
13702
|
+
}
|
|
13703
|
+
_chunkWAO6ZIROcjs.__name.call(void 0, isNode, "isNode");
|
|
13704
|
+
|
|
13705
|
+
// ../../node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/async.js
|
|
13706
|
+
_chunkWAO6ZIROcjs.init_cjs_shims.call(void 0, );
|
|
13707
|
+
|
|
13708
|
+
// ../../node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/index.js
|
|
13709
|
+
function walk(ast, { enter, leave }) {
|
|
13710
|
+
const instance = new SyncWalker(enter, leave);
|
|
13711
|
+
return instance.visit(ast, null);
|
|
13712
|
+
}
|
|
13713
|
+
_chunkWAO6ZIROcjs.__name.call(void 0, walk, "walk");
|
|
13714
|
+
|
|
13715
|
+
// src/plugins/utils/ast.ts
|
|
13716
|
+
function collectRequireTokens(ast) {
|
|
13717
|
+
const requireModules = [];
|
|
13718
|
+
walk(ast, {
|
|
13719
|
+
enter(node) {
|
|
13720
|
+
if (node.type === "CallExpression") {
|
|
13721
|
+
if (node.callee.type === "MemberExpression" && node.callee.object.type === "Identifier" && node.callee.object.name === "require" && node.callee.property.type === "Identifier" && node.callee.property.name === "async") {
|
|
13722
|
+
if (node.arguments[0] && node.arguments[0].type === "Literal" && typeof node.arguments[0].value === "string") {
|
|
13723
|
+
requireModules.push({
|
|
13724
|
+
// @ts-ignore
|
|
13725
|
+
start: node.arguments[0].start,
|
|
13726
|
+
// @ts-ignore
|
|
13727
|
+
end: node.arguments[0].end,
|
|
13728
|
+
value: node.arguments[0].value,
|
|
13729
|
+
async: true
|
|
13730
|
+
});
|
|
13731
|
+
}
|
|
13732
|
+
}
|
|
13733
|
+
}
|
|
13734
|
+
}
|
|
13735
|
+
});
|
|
13736
|
+
return {
|
|
13737
|
+
requireModules
|
|
13738
|
+
};
|
|
13739
|
+
}
|
|
13740
|
+
_chunkWAO6ZIROcjs.__name.call(void 0, collectRequireTokens, "collectRequireTokens");
|
|
13741
|
+
|
|
13542
13742
|
// src/plugins/core.ts
|
|
13543
13743
|
function weappVite(ctx, subPackageMeta) {
|
|
13544
13744
|
const { scanService, configService, jsonService, wxmlService, autoImportService, buildService, watcherService } = ctx;
|
|
@@ -13835,6 +14035,37 @@ function weappVite(ctx, subPackageMeta) {
|
|
|
13835
14035
|
return await loadEntry.call(this, id, "app");
|
|
13836
14036
|
}
|
|
13837
14037
|
},
|
|
14038
|
+
transform: {
|
|
14039
|
+
order: "post",
|
|
14040
|
+
async handler(code, id) {
|
|
14041
|
+
if (isJsOrTs(id)) {
|
|
14042
|
+
try {
|
|
14043
|
+
const ast = this.parse(code);
|
|
14044
|
+
const { requireModules } = collectRequireTokens(ast);
|
|
14045
|
+
for (const requireModule of requireModules) {
|
|
14046
|
+
const absPath = _pathe2.default.resolve(_pathe2.default.dirname(id), requireModule.value);
|
|
14047
|
+
const resolveId = await this.resolve(absPath, id);
|
|
14048
|
+
if (resolveId) {
|
|
14049
|
+
await this.load(resolveId);
|
|
14050
|
+
this.emitFile({
|
|
14051
|
+
type: "chunk",
|
|
14052
|
+
id: resolveId.id,
|
|
14053
|
+
fileName: configService.relativeAbsoluteSrcRoot(changeFileExtension(resolveId.id, ".js")),
|
|
14054
|
+
preserveSignature: "exports-only"
|
|
14055
|
+
});
|
|
14056
|
+
}
|
|
14057
|
+
}
|
|
14058
|
+
return {
|
|
14059
|
+
code,
|
|
14060
|
+
ast,
|
|
14061
|
+
map: null
|
|
14062
|
+
};
|
|
14063
|
+
} catch (error) {
|
|
14064
|
+
logger_default.error(error);
|
|
14065
|
+
}
|
|
14066
|
+
}
|
|
14067
|
+
}
|
|
14068
|
+
},
|
|
13838
14069
|
// shouldTransformCachedModule() {
|
|
13839
14070
|
// return true
|
|
13840
14071
|
// },
|
|
@@ -13871,10 +14102,6 @@ function weappVite(ctx, subPackageMeta) {
|
|
|
13871
14102
|
}
|
|
13872
14103
|
},
|
|
13873
14104
|
async generateBundle(_options, bundle) {
|
|
13874
|
-
if (_optionalChain([configService, 'access', _312 => _312.weappViteConfig, 'optionalAccess', _313 => _313.debug, 'optionalAccess', _314 => _314.watchFiles])) {
|
|
13875
|
-
const watchFiles = this.getWatchFiles();
|
|
13876
|
-
configService.weappViteConfig.debug.watchFiles(watchFiles, subPackageMeta);
|
|
13877
|
-
}
|
|
13878
14105
|
if (!subPackageMeta) {
|
|
13879
14106
|
const res = await Promise.all(pq);
|
|
13880
14107
|
const chunks = res.reduce((acc, { meta, rollup }) => {
|
|
@@ -13893,6 +14120,10 @@ function weappVite(ctx, subPackageMeta) {
|
|
|
13893
14120
|
}
|
|
13894
14121
|
}
|
|
13895
14122
|
}
|
|
14123
|
+
if (_optionalChain([configService, 'access', _312 => _312.weappViteConfig, 'optionalAccess', _313 => _313.debug, 'optionalAccess', _314 => _314.watchFiles])) {
|
|
14124
|
+
const watchFiles = this.getWatchFiles();
|
|
14125
|
+
configService.weappViteConfig.debug.watchFiles(watchFiles, subPackageMeta);
|
|
14126
|
+
}
|
|
13896
14127
|
}
|
|
13897
14128
|
}
|
|
13898
14129
|
];
|
|
@@ -9630,7 +9630,7 @@ var PathScurryBase = class {
|
|
|
9630
9630
|
results.push(withFileTypes ? entry : entry.fullpath());
|
|
9631
9631
|
}
|
|
9632
9632
|
const dirs = /* @__PURE__ */ new Set();
|
|
9633
|
-
const
|
|
9633
|
+
const walk2 = /* @__PURE__ */ __name((dir, cb) => {
|
|
9634
9634
|
dirs.add(dir);
|
|
9635
9635
|
dir.readdirCB((er, entries) => {
|
|
9636
9636
|
if (er) {
|
|
@@ -9648,10 +9648,10 @@ var PathScurryBase = class {
|
|
|
9648
9648
|
results.push(withFileTypes ? e2 : e2.fullpath());
|
|
9649
9649
|
}
|
|
9650
9650
|
if (follow && e2.isSymbolicLink()) {
|
|
9651
|
-
e2.realpath().then((r4) => r4?.isUnknown() ? r4.lstat() : r4).then((r4) => r4?.shouldWalk(dirs, walkFilter) ?
|
|
9651
|
+
e2.realpath().then((r4) => r4?.isUnknown() ? r4.lstat() : r4).then((r4) => r4?.shouldWalk(dirs, walkFilter) ? walk2(r4, next) : next());
|
|
9652
9652
|
} else {
|
|
9653
9653
|
if (e2.shouldWalk(dirs, walkFilter)) {
|
|
9654
|
-
|
|
9654
|
+
walk2(e2, next);
|
|
9655
9655
|
} else {
|
|
9656
9656
|
next();
|
|
9657
9657
|
}
|
|
@@ -9661,7 +9661,7 @@ var PathScurryBase = class {
|
|
|
9661
9661
|
}, "walk");
|
|
9662
9662
|
const start = entry;
|
|
9663
9663
|
return new Promise((res, rej) => {
|
|
9664
|
-
|
|
9664
|
+
walk2(start, (er) => {
|
|
9665
9665
|
if (er) return rej(er);
|
|
9666
9666
|
res(results);
|
|
9667
9667
|
});
|
|
@@ -13538,6 +13538,206 @@ function analyzeCommonJson(json) {
|
|
|
13538
13538
|
}
|
|
13539
13539
|
__name(analyzeCommonJson, "analyzeCommonJson");
|
|
13540
13540
|
|
|
13541
|
+
// src/plugins/utils/ast.ts
|
|
13542
|
+
init_esm_shims();
|
|
13543
|
+
|
|
13544
|
+
// ../../node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/index.js
|
|
13545
|
+
init_esm_shims();
|
|
13546
|
+
|
|
13547
|
+
// ../../node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/sync.js
|
|
13548
|
+
init_esm_shims();
|
|
13549
|
+
|
|
13550
|
+
// ../../node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/walker.js
|
|
13551
|
+
init_esm_shims();
|
|
13552
|
+
var WalkerBase = class {
|
|
13553
|
+
static {
|
|
13554
|
+
__name(this, "WalkerBase");
|
|
13555
|
+
}
|
|
13556
|
+
constructor() {
|
|
13557
|
+
this.should_skip = false;
|
|
13558
|
+
this.should_remove = false;
|
|
13559
|
+
this.replacement = null;
|
|
13560
|
+
this.context = {
|
|
13561
|
+
skip: /* @__PURE__ */ __name(() => this.should_skip = true, "skip"),
|
|
13562
|
+
remove: /* @__PURE__ */ __name(() => this.should_remove = true, "remove"),
|
|
13563
|
+
replace: /* @__PURE__ */ __name((node) => this.replacement = node, "replace")
|
|
13564
|
+
};
|
|
13565
|
+
}
|
|
13566
|
+
/**
|
|
13567
|
+
* @template {Node} Parent
|
|
13568
|
+
* @param {Parent | null | undefined} parent
|
|
13569
|
+
* @param {keyof Parent | null | undefined} prop
|
|
13570
|
+
* @param {number | null | undefined} index
|
|
13571
|
+
* @param {Node} node
|
|
13572
|
+
*/
|
|
13573
|
+
replace(parent, prop, index, node) {
|
|
13574
|
+
if (parent && prop) {
|
|
13575
|
+
if (index != null) {
|
|
13576
|
+
parent[prop][index] = node;
|
|
13577
|
+
} else {
|
|
13578
|
+
parent[prop] = node;
|
|
13579
|
+
}
|
|
13580
|
+
}
|
|
13581
|
+
}
|
|
13582
|
+
/**
|
|
13583
|
+
* @template {Node} Parent
|
|
13584
|
+
* @param {Parent | null | undefined} parent
|
|
13585
|
+
* @param {keyof Parent | null | undefined} prop
|
|
13586
|
+
* @param {number | null | undefined} index
|
|
13587
|
+
*/
|
|
13588
|
+
remove(parent, prop, index) {
|
|
13589
|
+
if (parent && prop) {
|
|
13590
|
+
if (index !== null && index !== void 0) {
|
|
13591
|
+
parent[prop].splice(index, 1);
|
|
13592
|
+
} else {
|
|
13593
|
+
delete parent[prop];
|
|
13594
|
+
}
|
|
13595
|
+
}
|
|
13596
|
+
}
|
|
13597
|
+
};
|
|
13598
|
+
|
|
13599
|
+
// ../../node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/sync.js
|
|
13600
|
+
var SyncWalker = class extends WalkerBase {
|
|
13601
|
+
static {
|
|
13602
|
+
__name(this, "SyncWalker");
|
|
13603
|
+
}
|
|
13604
|
+
/**
|
|
13605
|
+
*
|
|
13606
|
+
* @param {SyncHandler} [enter]
|
|
13607
|
+
* @param {SyncHandler} [leave]
|
|
13608
|
+
*/
|
|
13609
|
+
constructor(enter, leave) {
|
|
13610
|
+
super();
|
|
13611
|
+
this.should_skip = false;
|
|
13612
|
+
this.should_remove = false;
|
|
13613
|
+
this.replacement = null;
|
|
13614
|
+
this.context = {
|
|
13615
|
+
skip: /* @__PURE__ */ __name(() => this.should_skip = true, "skip"),
|
|
13616
|
+
remove: /* @__PURE__ */ __name(() => this.should_remove = true, "remove"),
|
|
13617
|
+
replace: /* @__PURE__ */ __name((node) => this.replacement = node, "replace")
|
|
13618
|
+
};
|
|
13619
|
+
this.enter = enter;
|
|
13620
|
+
this.leave = leave;
|
|
13621
|
+
}
|
|
13622
|
+
/**
|
|
13623
|
+
* @template {Node} Parent
|
|
13624
|
+
* @param {Node} node
|
|
13625
|
+
* @param {Parent | null} parent
|
|
13626
|
+
* @param {keyof Parent} [prop]
|
|
13627
|
+
* @param {number | null} [index]
|
|
13628
|
+
* @returns {Node | null}
|
|
13629
|
+
*/
|
|
13630
|
+
visit(node, parent, prop, index) {
|
|
13631
|
+
if (node) {
|
|
13632
|
+
if (this.enter) {
|
|
13633
|
+
const _should_skip = this.should_skip;
|
|
13634
|
+
const _should_remove = this.should_remove;
|
|
13635
|
+
const _replacement = this.replacement;
|
|
13636
|
+
this.should_skip = false;
|
|
13637
|
+
this.should_remove = false;
|
|
13638
|
+
this.replacement = null;
|
|
13639
|
+
this.enter.call(this.context, node, parent, prop, index);
|
|
13640
|
+
if (this.replacement) {
|
|
13641
|
+
node = this.replacement;
|
|
13642
|
+
this.replace(parent, prop, index, node);
|
|
13643
|
+
}
|
|
13644
|
+
if (this.should_remove) {
|
|
13645
|
+
this.remove(parent, prop, index);
|
|
13646
|
+
}
|
|
13647
|
+
const skipped = this.should_skip;
|
|
13648
|
+
const removed = this.should_remove;
|
|
13649
|
+
this.should_skip = _should_skip;
|
|
13650
|
+
this.should_remove = _should_remove;
|
|
13651
|
+
this.replacement = _replacement;
|
|
13652
|
+
if (skipped) return node;
|
|
13653
|
+
if (removed) return null;
|
|
13654
|
+
}
|
|
13655
|
+
let key;
|
|
13656
|
+
for (key in node) {
|
|
13657
|
+
const value = node[key];
|
|
13658
|
+
if (value && typeof value === "object") {
|
|
13659
|
+
if (Array.isArray(value)) {
|
|
13660
|
+
const nodes = (
|
|
13661
|
+
/** @type {Array<unknown>} */
|
|
13662
|
+
value
|
|
13663
|
+
);
|
|
13664
|
+
for (let i = 0; i < nodes.length; i += 1) {
|
|
13665
|
+
const item = nodes[i];
|
|
13666
|
+
if (isNode(item)) {
|
|
13667
|
+
if (!this.visit(item, node, key, i)) {
|
|
13668
|
+
i--;
|
|
13669
|
+
}
|
|
13670
|
+
}
|
|
13671
|
+
}
|
|
13672
|
+
} else if (isNode(value)) {
|
|
13673
|
+
this.visit(value, node, key, null);
|
|
13674
|
+
}
|
|
13675
|
+
}
|
|
13676
|
+
}
|
|
13677
|
+
if (this.leave) {
|
|
13678
|
+
const _replacement = this.replacement;
|
|
13679
|
+
const _should_remove = this.should_remove;
|
|
13680
|
+
this.replacement = null;
|
|
13681
|
+
this.should_remove = false;
|
|
13682
|
+
this.leave.call(this.context, node, parent, prop, index);
|
|
13683
|
+
if (this.replacement) {
|
|
13684
|
+
node = this.replacement;
|
|
13685
|
+
this.replace(parent, prop, index, node);
|
|
13686
|
+
}
|
|
13687
|
+
if (this.should_remove) {
|
|
13688
|
+
this.remove(parent, prop, index);
|
|
13689
|
+
}
|
|
13690
|
+
const removed = this.should_remove;
|
|
13691
|
+
this.replacement = _replacement;
|
|
13692
|
+
this.should_remove = _should_remove;
|
|
13693
|
+
if (removed) return null;
|
|
13694
|
+
}
|
|
13695
|
+
}
|
|
13696
|
+
return node;
|
|
13697
|
+
}
|
|
13698
|
+
};
|
|
13699
|
+
function isNode(value) {
|
|
13700
|
+
return value !== null && typeof value === "object" && "type" in value && typeof value.type === "string";
|
|
13701
|
+
}
|
|
13702
|
+
__name(isNode, "isNode");
|
|
13703
|
+
|
|
13704
|
+
// ../../node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/async.js
|
|
13705
|
+
init_esm_shims();
|
|
13706
|
+
|
|
13707
|
+
// ../../node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/index.js
|
|
13708
|
+
function walk(ast, { enter, leave }) {
|
|
13709
|
+
const instance = new SyncWalker(enter, leave);
|
|
13710
|
+
return instance.visit(ast, null);
|
|
13711
|
+
}
|
|
13712
|
+
__name(walk, "walk");
|
|
13713
|
+
|
|
13714
|
+
// src/plugins/utils/ast.ts
|
|
13715
|
+
function collectRequireTokens(ast) {
|
|
13716
|
+
const requireModules = [];
|
|
13717
|
+
walk(ast, {
|
|
13718
|
+
enter(node) {
|
|
13719
|
+
if (node.type === "CallExpression") {
|
|
13720
|
+
if (node.callee.type === "MemberExpression" && node.callee.object.type === "Identifier" && node.callee.object.name === "require" && node.callee.property.type === "Identifier" && node.callee.property.name === "async") {
|
|
13721
|
+
if (node.arguments[0] && node.arguments[0].type === "Literal" && typeof node.arguments[0].value === "string") {
|
|
13722
|
+
requireModules.push({
|
|
13723
|
+
// @ts-ignore
|
|
13724
|
+
start: node.arguments[0].start,
|
|
13725
|
+
// @ts-ignore
|
|
13726
|
+
end: node.arguments[0].end,
|
|
13727
|
+
value: node.arguments[0].value,
|
|
13728
|
+
async: true
|
|
13729
|
+
});
|
|
13730
|
+
}
|
|
13731
|
+
}
|
|
13732
|
+
}
|
|
13733
|
+
}
|
|
13734
|
+
});
|
|
13735
|
+
return {
|
|
13736
|
+
requireModules
|
|
13737
|
+
};
|
|
13738
|
+
}
|
|
13739
|
+
__name(collectRequireTokens, "collectRequireTokens");
|
|
13740
|
+
|
|
13541
13741
|
// src/plugins/core.ts
|
|
13542
13742
|
function weappVite(ctx, subPackageMeta) {
|
|
13543
13743
|
const { scanService, configService, jsonService, wxmlService, autoImportService, buildService, watcherService } = ctx;
|
|
@@ -13834,6 +14034,37 @@ function weappVite(ctx, subPackageMeta) {
|
|
|
13834
14034
|
return await loadEntry.call(this, id, "app");
|
|
13835
14035
|
}
|
|
13836
14036
|
},
|
|
14037
|
+
transform: {
|
|
14038
|
+
order: "post",
|
|
14039
|
+
async handler(code, id) {
|
|
14040
|
+
if (isJsOrTs(id)) {
|
|
14041
|
+
try {
|
|
14042
|
+
const ast = this.parse(code);
|
|
14043
|
+
const { requireModules } = collectRequireTokens(ast);
|
|
14044
|
+
for (const requireModule of requireModules) {
|
|
14045
|
+
const absPath = path8.resolve(path8.dirname(id), requireModule.value);
|
|
14046
|
+
const resolveId = await this.resolve(absPath, id);
|
|
14047
|
+
if (resolveId) {
|
|
14048
|
+
await this.load(resolveId);
|
|
14049
|
+
this.emitFile({
|
|
14050
|
+
type: "chunk",
|
|
14051
|
+
id: resolveId.id,
|
|
14052
|
+
fileName: configService.relativeAbsoluteSrcRoot(changeFileExtension(resolveId.id, ".js")),
|
|
14053
|
+
preserveSignature: "exports-only"
|
|
14054
|
+
});
|
|
14055
|
+
}
|
|
14056
|
+
}
|
|
14057
|
+
return {
|
|
14058
|
+
code,
|
|
14059
|
+
ast,
|
|
14060
|
+
map: null
|
|
14061
|
+
};
|
|
14062
|
+
} catch (error) {
|
|
14063
|
+
logger_default.error(error);
|
|
14064
|
+
}
|
|
14065
|
+
}
|
|
14066
|
+
}
|
|
14067
|
+
},
|
|
13837
14068
|
// shouldTransformCachedModule() {
|
|
13838
14069
|
// return true
|
|
13839
14070
|
// },
|
|
@@ -13870,10 +14101,6 @@ function weappVite(ctx, subPackageMeta) {
|
|
|
13870
14101
|
}
|
|
13871
14102
|
},
|
|
13872
14103
|
async generateBundle(_options, bundle) {
|
|
13873
|
-
if (configService.weappViteConfig?.debug?.watchFiles) {
|
|
13874
|
-
const watchFiles = this.getWatchFiles();
|
|
13875
|
-
configService.weappViteConfig.debug.watchFiles(watchFiles, subPackageMeta);
|
|
13876
|
-
}
|
|
13877
14104
|
if (!subPackageMeta) {
|
|
13878
14105
|
const res = await Promise.all(pq);
|
|
13879
14106
|
const chunks = res.reduce((acc, { meta, rollup }) => {
|
|
@@ -13892,6 +14119,10 @@ function weappVite(ctx, subPackageMeta) {
|
|
|
13892
14119
|
}
|
|
13893
14120
|
}
|
|
13894
14121
|
}
|
|
14122
|
+
if (configService.weappViteConfig?.debug?.watchFiles) {
|
|
14123
|
+
const watchFiles = this.getWatchFiles();
|
|
14124
|
+
configService.weappViteConfig.debug.watchFiles(watchFiles, subPackageMeta);
|
|
14125
|
+
}
|
|
13895
14126
|
}
|
|
13896
14127
|
}
|
|
13897
14128
|
];
|
package/dist/cli.cjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunk4RA3EKOJcjs = require('./chunk-4RA3EKOJ.cjs');
|
|
7
7
|
require('./chunk-T5OM6XSR.cjs');
|
|
8
8
|
require('./chunk-7K7GXEBV.cjs');
|
|
9
9
|
|
|
@@ -823,14 +823,14 @@ async function generate(options) {
|
|
|
823
823
|
for (const { code, fileName: fileName2 } of files) {
|
|
824
824
|
if (code !== void 0) {
|
|
825
825
|
await _fsextra2.default.outputFile(_pathe2.default.resolve(basepath, fileName2), code, "utf8");
|
|
826
|
-
|
|
826
|
+
_chunk4RA3EKOJcjs.logger_default.success(`${composePath(outDir, fileName2)} \u521B\u5EFA\u6210\u529F\uFF01`);
|
|
827
827
|
}
|
|
828
828
|
}
|
|
829
829
|
}
|
|
830
830
|
_chunkWAO6ZIROcjs.__name.call(void 0, generate, "generate");
|
|
831
831
|
|
|
832
832
|
// src/cli.ts
|
|
833
|
-
var import_reflect_metadata = _chunkWAO6ZIROcjs.__toESM.call(void 0,
|
|
833
|
+
var import_reflect_metadata = _chunkWAO6ZIROcjs.__toESM.call(void 0, _chunk4RA3EKOJcjs.require_Reflect.call(void 0, ), 1);
|
|
834
834
|
var cli = cac("weapp-vite");
|
|
835
835
|
function loadConfig() {
|
|
836
836
|
return _vite.loadConfigFromFile.call(void 0, {
|
|
@@ -852,9 +852,9 @@ function logBuildAppFinish(configService) {
|
|
|
852
852
|
]
|
|
853
853
|
}));
|
|
854
854
|
const devCommand = `${command} ${args.join(" ")}`;
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
855
|
+
_chunk4RA3EKOJcjs.logger_default.success("\u5E94\u7528\u6784\u5EFA\u5B8C\u6210\uFF01\u9884\u89C8\u65B9\u5F0F ( `2` \u79CD\u9009\u5176\u4E00\u5373\u53EF)\uFF1A");
|
|
856
|
+
_chunk4RA3EKOJcjs.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`);
|
|
857
|
+
_chunk4RA3EKOJcjs.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");
|
|
858
858
|
logBuildAppFinishOnlyShowOnce = true;
|
|
859
859
|
}
|
|
860
860
|
}
|
|
@@ -881,7 +881,7 @@ async function openIde() {
|
|
|
881
881
|
"-p"
|
|
882
882
|
]);
|
|
883
883
|
} catch (error) {
|
|
884
|
-
|
|
884
|
+
_chunk4RA3EKOJcjs.logger_default.error(error);
|
|
885
885
|
}
|
|
886
886
|
}
|
|
887
887
|
_chunkWAO6ZIROcjs.__name.call(void 0, openIde, "openIde");
|
|
@@ -892,7 +892,7 @@ cli.option("-c, --config <file>", `[string] use specified config file`).option("
|
|
|
892
892
|
}).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`);
|
|
893
893
|
cli.command("[root]", "start dev server").alias("serve").alias("dev").option("--skipNpm", `[boolean] if skip npm build`).option("-o, --open", `[boolean] open ide`).action(async (root, options) => {
|
|
894
894
|
filterDuplicateOptions(options);
|
|
895
|
-
const { buildService, configService } = await
|
|
895
|
+
const { buildService, configService } = await _chunk4RA3EKOJcjs.createCompilerContext.call(void 0, {
|
|
896
896
|
cwd: root,
|
|
897
897
|
mode: options.mode,
|
|
898
898
|
isDev: true
|
|
@@ -905,7 +905,7 @@ cli.command("[root]", "start dev server").alias("serve").alias("dev").option("--
|
|
|
905
905
|
});
|
|
906
906
|
cli.command("build [root]", "build for production").option("--target <target>", `[string] transpile target (default: 'modules')`).option("--outDir <dir>", `[string] output directory (default: dist)`).option("--sourcemap [output]", `[boolean | "inline" | "hidden"] output source maps for build (default: false)`).option("--minify [minifier]", `[boolean | "terser" | "esbuild"] enable/disable minification, or specify minifier to use (default: esbuild)`).option("--emptyOutDir", `[boolean] force empty outDir when it's outside of root`).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) => {
|
|
907
907
|
filterDuplicateOptions(options);
|
|
908
|
-
const { buildService, configService } = await
|
|
908
|
+
const { buildService, configService } = await _chunk4RA3EKOJcjs.createCompilerContext.call(void 0, {
|
|
909
909
|
cwd: root,
|
|
910
910
|
mode: options.mode
|
|
911
911
|
});
|
|
@@ -921,7 +921,7 @@ cli.command("init").action(async () => {
|
|
|
921
921
|
command: "weapp-vite"
|
|
922
922
|
});
|
|
923
923
|
} catch (error) {
|
|
924
|
-
|
|
924
|
+
_chunk4RA3EKOJcjs.logger_default.error(error);
|
|
925
925
|
}
|
|
926
926
|
});
|
|
927
927
|
cli.command("open").action(async () => {
|
|
@@ -934,7 +934,7 @@ cli.command("npm").alias("build:npm").alias("build-npm").action(async () => {
|
|
|
934
934
|
"-p"
|
|
935
935
|
]);
|
|
936
936
|
} catch (error) {
|
|
937
|
-
|
|
937
|
+
_chunk4RA3EKOJcjs.logger_default.error(error);
|
|
938
938
|
}
|
|
939
939
|
});
|
|
940
940
|
cli.command("gc [filepath]", "generate component").alias("g").alias("generate").option("-a, --app", "type app").option("-p, --page", "type app").option("-n, --name <name>", "filename").action(async (filepath, options) => {
|
|
@@ -949,7 +949,7 @@ cli.command("gc [filepath]", "generate component").alias("g").alias("generate").
|
|
|
949
949
|
fileName = "app";
|
|
950
950
|
}
|
|
951
951
|
if (filepath === void 0) {
|
|
952
|
-
|
|
952
|
+
_chunk4RA3EKOJcjs.logger_default.error("weapp-vite generate <outDir> \u547D\u4EE4\u5FC5\u987B\u4F20\u5165\u8DEF\u5F84\u53C2\u6570 outDir");
|
|
953
953
|
return;
|
|
954
954
|
}
|
|
955
955
|
if (options.page) {
|
|
@@ -968,5 +968,5 @@ cli.command("create [outDir]", "create project").option("-t, --template <type>",
|
|
|
968
968
|
await _init.createProject.call(void 0, outDir, options.template);
|
|
969
969
|
});
|
|
970
970
|
cli.help();
|
|
971
|
-
cli.version(
|
|
971
|
+
cli.version(_chunk4RA3EKOJcjs.VERSION);
|
|
972
972
|
cli.parse();
|
package/dist/cli.mjs
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunk4RA3EKOJcjs = require('./chunk-4RA3EKOJ.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
var _chunkT5OM6XSRcjs = require('./chunk-T5OM6XSR.cjs');
|
|
@@ -19,7 +19,7 @@ var _chunkWAO6ZIROcjs = require('./chunk-WAO6ZIRO.cjs');
|
|
|
19
19
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
_chunkWAO6ZIROcjs.init_cjs_shims.call(void 0, );
|
|
22
|
-
var import_reflect_metadata = _chunkWAO6ZIROcjs.__toESM.call(void 0,
|
|
22
|
+
var import_reflect_metadata = _chunkWAO6ZIROcjs.__toESM.call(void 0, _chunk4RA3EKOJcjs.require_Reflect.call(void 0, ), 1);
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
|
|
@@ -28,4 +28,4 @@ var import_reflect_metadata = _chunkWAO6ZIROcjs.__toESM.call(void 0, _chunkZT6IT
|
|
|
28
28
|
|
|
29
29
|
|
|
30
30
|
|
|
31
|
-
exports.createCompilerContext =
|
|
31
|
+
exports.createCompilerContext = _chunk4RA3EKOJcjs.createCompilerContext; exports.defineAppJson = _chunk7K7GXEBVcjs.defineAppJson; exports.defineComponentJson = _chunk7K7GXEBVcjs.defineComponentJson; exports.defineConfig = _chunkT5OM6XSRcjs.defineConfig; exports.definePageJson = _chunk7K7GXEBVcjs.definePageJson; exports.defineSitemapJson = _chunk7K7GXEBVcjs.defineSitemapJson; exports.defineThemeJson = _chunk7K7GXEBVcjs.defineThemeJson;
|
package/dist/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "weapp-vite",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.0.
|
|
4
|
+
"version": "4.0.2",
|
|
5
5
|
"description": "weapp-vite 一个现代化的小程序打包工具",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -92,14 +92,14 @@
|
|
|
92
92
|
"picomatch": "^4.0.2",
|
|
93
93
|
"postcss": "^8.5.3",
|
|
94
94
|
"tsup": "^8.4.0",
|
|
95
|
-
"vite": "^6.
|
|
95
|
+
"vite": "^6.3.0",
|
|
96
96
|
"vite-plugin-commonjs": "^0.10.4",
|
|
97
97
|
"vite-tsconfig-paths": "^5.1.4",
|
|
98
|
+
"@weapp-core/logger": "^1.0.3",
|
|
98
99
|
"@weapp-core/init": "^1.1.17",
|
|
99
|
-
"@weapp-core/shared": "^1.0.7",
|
|
100
100
|
"@weapp-core/schematics": "^1.0.12",
|
|
101
|
-
"@weapp-core/logger": "^1.0.3",
|
|
102
101
|
"@weapp-vite/volar": "^0.0.0",
|
|
102
|
+
"@weapp-core/shared": "^1.0.7",
|
|
103
103
|
"weapp-ide-cli": "^2.0.10"
|
|
104
104
|
},
|
|
105
105
|
"publishConfig": {
|