@vtj/local 0.17.7 → 0.18.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/index.cjs +53 -3
- package/dist/index.d.cts +39 -1
- package/dist/index.d.mts +39 -1
- package/dist/index.d.ts +39 -1
- package/dist/index.mjs +52 -4
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -26,7 +26,7 @@ const success = (data) => {
|
|
|
26
26
|
const fail = (msg, data = null, stack = null) => {
|
|
27
27
|
return {
|
|
28
28
|
code: 1 /* Fail */,
|
|
29
|
-
msg,
|
|
29
|
+
msg: msg?.message || msg,
|
|
30
30
|
data,
|
|
31
31
|
stack,
|
|
32
32
|
success: false
|
|
@@ -359,6 +359,16 @@ class UniRepository {
|
|
|
359
359
|
const { pagesJson = {} } = project.uniConfig || {};
|
|
360
360
|
const filePath = path.resolve("src/pages.json");
|
|
361
361
|
pagesJson.pages = pages;
|
|
362
|
+
const easycomDeps = (project.dependencies || []).filter(
|
|
363
|
+
(dep) => dep.easycom
|
|
364
|
+
);
|
|
365
|
+
if (easycomDeps.length) {
|
|
366
|
+
const easycom = pagesJson.easycom || (pagesJson.easycom = {});
|
|
367
|
+
const custom = easycom.custom || (easycom.custom = {});
|
|
368
|
+
for (const dep of easycomDeps) {
|
|
369
|
+
custom[dep.easycom.key] = dep.easycom.value;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
362
372
|
node.writeJsonSync(filePath, pagesJson, {
|
|
363
373
|
spaces: 2,
|
|
364
374
|
EOL: "\n"
|
|
@@ -1531,7 +1541,7 @@ async function parseVue(options) {
|
|
|
1531
1541
|
errors = e;
|
|
1532
1542
|
return null;
|
|
1533
1543
|
});
|
|
1534
|
-
return
|
|
1544
|
+
return errors ? fail(errors) : success(dsl);
|
|
1535
1545
|
}
|
|
1536
1546
|
async function createRawPage(file, opts) {
|
|
1537
1547
|
const repository = new VueRepository({
|
|
@@ -2104,7 +2114,7 @@ function createDevTools(options = {}) {
|
|
|
2104
2114
|
copyDevtools: true,
|
|
2105
2115
|
...options
|
|
2106
2116
|
};
|
|
2107
|
-
const plugins = [aliasPlugin(opts)];
|
|
2117
|
+
const plugins = [aliasPlugin(opts), createCompositionFixPlugin()];
|
|
2108
2118
|
const proPath = `${opts.nodeModulesDir}/${opts.packageName}/dist`;
|
|
2109
2119
|
const materialsPath1 = `${opts.nodeModulesDir}/@vtj/materials/dist`;
|
|
2110
2120
|
const materialsPath2 = `${opts.nodeModulesDir}/${opts.packageName}/${materialsPath1}`;
|
|
@@ -2225,7 +2235,47 @@ function createDevTools(options = {}) {
|
|
|
2225
2235
|
}
|
|
2226
2236
|
return plugins;
|
|
2227
2237
|
}
|
|
2238
|
+
function fixAxiosAdapterUploadConflict() {
|
|
2239
|
+
const UPLOAD_VAR_PATTERN = /const upload = \(/g;
|
|
2240
|
+
const UPLOAD_RETURN_PATTERN = /return upload;/g;
|
|
2241
|
+
const LET_TASK_TDZ_PATTERN = /(let task = )((uni|index)\.(downloadFile|request|uploadFile)\()/g;
|
|
2242
|
+
return {
|
|
2243
|
+
name: "vtj-axios-adapter-upload-fix",
|
|
2244
|
+
enforce: "pre",
|
|
2245
|
+
transform(code, id) {
|
|
2246
|
+
if (id.includes("@uni-helper/axios-adapter")) {
|
|
2247
|
+
const transformed = code.replace(UPLOAD_VAR_PATTERN, "const uploadRequest = (").replace(UPLOAD_RETURN_PATTERN, "return uploadRequest;").replace(LET_TASK_TDZ_PATTERN, "let task = null; task = $2");
|
|
2248
|
+
if (transformed !== code) {
|
|
2249
|
+
return { code: transformed, map: null };
|
|
2250
|
+
}
|
|
2251
|
+
}
|
|
2252
|
+
}
|
|
2253
|
+
};
|
|
2254
|
+
}
|
|
2255
|
+
function createCompositionFixPlugin() {
|
|
2256
|
+
return {
|
|
2257
|
+
name: "vtj-composition-fix",
|
|
2258
|
+
enforce: "pre",
|
|
2259
|
+
transform(code, id) {
|
|
2260
|
+
if (!id.endsWith(".vue"))
|
|
2261
|
+
return;
|
|
2262
|
+
if (!code.includes("useProvider") && !code.includes("__provider"))
|
|
2263
|
+
return;
|
|
2264
|
+
if (!code.includes("const __props") && !code.includes("const __emit"))
|
|
2265
|
+
return;
|
|
2266
|
+
return code.replace(
|
|
2267
|
+
/(<script[^>]*\bsetup\b[^>]*>)([\s\S]*?)(<\/script>)/,
|
|
2268
|
+
(_, open, body, close) => {
|
|
2269
|
+
const fixed = body.replace(/\bconst\s+__props\b/g, "const props").replace(/\bconst\s+__emit\b/g, "const emit").replace(/__props\./g, "props.").replace(/__emit\s*\(/g, "emit(");
|
|
2270
|
+
return open + fixed + close;
|
|
2271
|
+
}
|
|
2272
|
+
);
|
|
2273
|
+
}
|
|
2274
|
+
};
|
|
2275
|
+
}
|
|
2228
2276
|
|
|
2277
|
+
exports.createCompositionFixPlugin = createCompositionFixPlugin;
|
|
2229
2278
|
exports.createDevTools = createDevTools;
|
|
2279
|
+
exports.fixAxiosAdapterUploadConflict = fixAxiosAdapterUploadConflict;
|
|
2230
2280
|
exports.parsePresetPlugins = parsePresetPlugins;
|
|
2231
2281
|
exports.vtjModulesPlugin = vtjModulesPlugin;
|
package/dist/index.d.cts
CHANGED
|
@@ -46,6 +46,44 @@ declare function parsePresetPlugins(options: DevToolsOptions): {
|
|
|
46
46
|
staticDirs: StaticPluginOption[];
|
|
47
47
|
};
|
|
48
48
|
declare function createDevTools(options?: Partial<DevToolsOptions>): Plugin<any>[];
|
|
49
|
+
/**
|
|
50
|
+
* 修复 @uni-helper/axios-adapter 的两个问题:
|
|
51
|
+
* 1. const upload 变量名与微信小程序引擎冲突(引擎将 prototype.upload 属性赋值误判为变量声明)
|
|
52
|
+
* 2. let task = uni.xxxFile({...}) 的 TDZ 问题:若 fail 回调在赋值完成前同步触发,task 尚未初始化
|
|
53
|
+
*
|
|
54
|
+
* 必须在 uni() 插件之前注册(enforce: 'pre')。
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* // vite.config.ts
|
|
58
|
+
* import { fixAxiosAdapterUploadConflict } from '@vtj/local';
|
|
59
|
+
* export default createUniappViteConfig({
|
|
60
|
+
* plugins: [
|
|
61
|
+
* fixAxiosAdapterUploadConflict(), // ← 在 uni() 之前
|
|
62
|
+
* uni(),
|
|
63
|
+
* ]
|
|
64
|
+
* });
|
|
65
|
+
*/
|
|
66
|
+
declare function fixAxiosAdapterUploadConflict(): Plugin;
|
|
67
|
+
/**
|
|
68
|
+
* 修复 uni-app <script setup> 中 __props/__emit 变量名与编译器内部保留名冲突的问题。
|
|
69
|
+
*
|
|
70
|
+
* uni-app 编译器在处理 defineProps/defineEmits 宏时会在内部生成 __props/__emit 变量,
|
|
71
|
+
* 若 VTJ 生成的代码也使用 const __props = defineProps(...) 则会导致重复声明编译错误。
|
|
72
|
+
*
|
|
73
|
+
* 此插件应在 uni() 插件之前(enforce: 'pre')注册,将代码中的 __props/__emit
|
|
74
|
+
* 重命名为 props/emit,避免与编译器内部变量名冲突。
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* // vite.config.ts
|
|
78
|
+
* import { createCompositionFixPlugin } from '@vtj/local';
|
|
79
|
+
* export default createUniappViteConfig({
|
|
80
|
+
* plugins: [
|
|
81
|
+
* createCompositionFixPlugin(), // ← 在 uni() 之前
|
|
82
|
+
* uni(),
|
|
83
|
+
* ]
|
|
84
|
+
* });
|
|
85
|
+
*/
|
|
86
|
+
declare function createCompositionFixPlugin(): Plugin;
|
|
49
87
|
|
|
50
|
-
export { createDevTools, parsePresetPlugins, vtjModulesPlugin };
|
|
88
|
+
export { createCompositionFixPlugin, createDevTools, fixAxiosAdapterUploadConflict, parsePresetPlugins, vtjModulesPlugin };
|
|
51
89
|
export type { DevToolsOptions, EnhanceOptions, LinkOptions };
|
package/dist/index.d.mts
CHANGED
|
@@ -46,6 +46,44 @@ declare function parsePresetPlugins(options: DevToolsOptions): {
|
|
|
46
46
|
staticDirs: StaticPluginOption[];
|
|
47
47
|
};
|
|
48
48
|
declare function createDevTools(options?: Partial<DevToolsOptions>): Plugin<any>[];
|
|
49
|
+
/**
|
|
50
|
+
* 修复 @uni-helper/axios-adapter 的两个问题:
|
|
51
|
+
* 1. const upload 变量名与微信小程序引擎冲突(引擎将 prototype.upload 属性赋值误判为变量声明)
|
|
52
|
+
* 2. let task = uni.xxxFile({...}) 的 TDZ 问题:若 fail 回调在赋值完成前同步触发,task 尚未初始化
|
|
53
|
+
*
|
|
54
|
+
* 必须在 uni() 插件之前注册(enforce: 'pre')。
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* // vite.config.ts
|
|
58
|
+
* import { fixAxiosAdapterUploadConflict } from '@vtj/local';
|
|
59
|
+
* export default createUniappViteConfig({
|
|
60
|
+
* plugins: [
|
|
61
|
+
* fixAxiosAdapterUploadConflict(), // ← 在 uni() 之前
|
|
62
|
+
* uni(),
|
|
63
|
+
* ]
|
|
64
|
+
* });
|
|
65
|
+
*/
|
|
66
|
+
declare function fixAxiosAdapterUploadConflict(): Plugin;
|
|
67
|
+
/**
|
|
68
|
+
* 修复 uni-app <script setup> 中 __props/__emit 变量名与编译器内部保留名冲突的问题。
|
|
69
|
+
*
|
|
70
|
+
* uni-app 编译器在处理 defineProps/defineEmits 宏时会在内部生成 __props/__emit 变量,
|
|
71
|
+
* 若 VTJ 生成的代码也使用 const __props = defineProps(...) 则会导致重复声明编译错误。
|
|
72
|
+
*
|
|
73
|
+
* 此插件应在 uni() 插件之前(enforce: 'pre')注册,将代码中的 __props/__emit
|
|
74
|
+
* 重命名为 props/emit,避免与编译器内部变量名冲突。
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* // vite.config.ts
|
|
78
|
+
* import { createCompositionFixPlugin } from '@vtj/local';
|
|
79
|
+
* export default createUniappViteConfig({
|
|
80
|
+
* plugins: [
|
|
81
|
+
* createCompositionFixPlugin(), // ← 在 uni() 之前
|
|
82
|
+
* uni(),
|
|
83
|
+
* ]
|
|
84
|
+
* });
|
|
85
|
+
*/
|
|
86
|
+
declare function createCompositionFixPlugin(): Plugin;
|
|
49
87
|
|
|
50
|
-
export { createDevTools, parsePresetPlugins, vtjModulesPlugin };
|
|
88
|
+
export { createCompositionFixPlugin, createDevTools, fixAxiosAdapterUploadConflict, parsePresetPlugins, vtjModulesPlugin };
|
|
51
89
|
export type { DevToolsOptions, EnhanceOptions, LinkOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -46,6 +46,44 @@ declare function parsePresetPlugins(options: DevToolsOptions): {
|
|
|
46
46
|
staticDirs: StaticPluginOption[];
|
|
47
47
|
};
|
|
48
48
|
declare function createDevTools(options?: Partial<DevToolsOptions>): Plugin<any>[];
|
|
49
|
+
/**
|
|
50
|
+
* 修复 @uni-helper/axios-adapter 的两个问题:
|
|
51
|
+
* 1. const upload 变量名与微信小程序引擎冲突(引擎将 prototype.upload 属性赋值误判为变量声明)
|
|
52
|
+
* 2. let task = uni.xxxFile({...}) 的 TDZ 问题:若 fail 回调在赋值完成前同步触发,task 尚未初始化
|
|
53
|
+
*
|
|
54
|
+
* 必须在 uni() 插件之前注册(enforce: 'pre')。
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* // vite.config.ts
|
|
58
|
+
* import { fixAxiosAdapterUploadConflict } from '@vtj/local';
|
|
59
|
+
* export default createUniappViteConfig({
|
|
60
|
+
* plugins: [
|
|
61
|
+
* fixAxiosAdapterUploadConflict(), // ← 在 uni() 之前
|
|
62
|
+
* uni(),
|
|
63
|
+
* ]
|
|
64
|
+
* });
|
|
65
|
+
*/
|
|
66
|
+
declare function fixAxiosAdapterUploadConflict(): Plugin;
|
|
67
|
+
/**
|
|
68
|
+
* 修复 uni-app <script setup> 中 __props/__emit 变量名与编译器内部保留名冲突的问题。
|
|
69
|
+
*
|
|
70
|
+
* uni-app 编译器在处理 defineProps/defineEmits 宏时会在内部生成 __props/__emit 变量,
|
|
71
|
+
* 若 VTJ 生成的代码也使用 const __props = defineProps(...) 则会导致重复声明编译错误。
|
|
72
|
+
*
|
|
73
|
+
* 此插件应在 uni() 插件之前(enforce: 'pre')注册,将代码中的 __props/__emit
|
|
74
|
+
* 重命名为 props/emit,避免与编译器内部变量名冲突。
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* // vite.config.ts
|
|
78
|
+
* import { createCompositionFixPlugin } from '@vtj/local';
|
|
79
|
+
* export default createUniappViteConfig({
|
|
80
|
+
* plugins: [
|
|
81
|
+
* createCompositionFixPlugin(), // ← 在 uni() 之前
|
|
82
|
+
* uni(),
|
|
83
|
+
* ]
|
|
84
|
+
* });
|
|
85
|
+
*/
|
|
86
|
+
declare function createCompositionFixPlugin(): Plugin;
|
|
49
87
|
|
|
50
|
-
export { createDevTools, parsePresetPlugins, vtjModulesPlugin };
|
|
88
|
+
export { createCompositionFixPlugin, createDevTools, fixAxiosAdapterUploadConflict, parsePresetPlugins, vtjModulesPlugin };
|
|
51
89
|
export type { DevToolsOptions, EnhanceOptions, LinkOptions };
|
package/dist/index.mjs
CHANGED
|
@@ -19,7 +19,7 @@ const success = (data) => {
|
|
|
19
19
|
const fail = (msg, data = null, stack = null) => {
|
|
20
20
|
return {
|
|
21
21
|
code: 1 /* Fail */,
|
|
22
|
-
msg,
|
|
22
|
+
msg: msg?.message || msg,
|
|
23
23
|
data,
|
|
24
24
|
stack,
|
|
25
25
|
success: false
|
|
@@ -352,6 +352,16 @@ class UniRepository {
|
|
|
352
352
|
const { pagesJson = {} } = project.uniConfig || {};
|
|
353
353
|
const filePath = resolve("src/pages.json");
|
|
354
354
|
pagesJson.pages = pages;
|
|
355
|
+
const easycomDeps = (project.dependencies || []).filter(
|
|
356
|
+
(dep) => dep.easycom
|
|
357
|
+
);
|
|
358
|
+
if (easycomDeps.length) {
|
|
359
|
+
const easycom = pagesJson.easycom || (pagesJson.easycom = {});
|
|
360
|
+
const custom = easycom.custom || (easycom.custom = {});
|
|
361
|
+
for (const dep of easycomDeps) {
|
|
362
|
+
custom[dep.easycom.key] = dep.easycom.value;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
355
365
|
writeJsonSync(filePath, pagesJson, {
|
|
356
366
|
spaces: 2,
|
|
357
367
|
EOL: "\n"
|
|
@@ -1524,7 +1534,7 @@ async function parseVue(options) {
|
|
|
1524
1534
|
errors = e;
|
|
1525
1535
|
return null;
|
|
1526
1536
|
});
|
|
1527
|
-
return
|
|
1537
|
+
return errors ? fail(errors) : success(dsl);
|
|
1528
1538
|
}
|
|
1529
1539
|
async function createRawPage(file, opts) {
|
|
1530
1540
|
const repository = new VueRepository({
|
|
@@ -2097,7 +2107,7 @@ function createDevTools(options = {}) {
|
|
|
2097
2107
|
copyDevtools: true,
|
|
2098
2108
|
...options
|
|
2099
2109
|
};
|
|
2100
|
-
const plugins = [aliasPlugin(opts)];
|
|
2110
|
+
const plugins = [aliasPlugin(opts), createCompositionFixPlugin()];
|
|
2101
2111
|
const proPath = `${opts.nodeModulesDir}/${opts.packageName}/dist`;
|
|
2102
2112
|
const materialsPath1 = `${opts.nodeModulesDir}/@vtj/materials/dist`;
|
|
2103
2113
|
const materialsPath2 = `${opts.nodeModulesDir}/${opts.packageName}/${materialsPath1}`;
|
|
@@ -2218,5 +2228,43 @@ function createDevTools(options = {}) {
|
|
|
2218
2228
|
}
|
|
2219
2229
|
return plugins;
|
|
2220
2230
|
}
|
|
2231
|
+
function fixAxiosAdapterUploadConflict() {
|
|
2232
|
+
const UPLOAD_VAR_PATTERN = /const upload = \(/g;
|
|
2233
|
+
const UPLOAD_RETURN_PATTERN = /return upload;/g;
|
|
2234
|
+
const LET_TASK_TDZ_PATTERN = /(let task = )((uni|index)\.(downloadFile|request|uploadFile)\()/g;
|
|
2235
|
+
return {
|
|
2236
|
+
name: "vtj-axios-adapter-upload-fix",
|
|
2237
|
+
enforce: "pre",
|
|
2238
|
+
transform(code, id) {
|
|
2239
|
+
if (id.includes("@uni-helper/axios-adapter")) {
|
|
2240
|
+
const transformed = code.replace(UPLOAD_VAR_PATTERN, "const uploadRequest = (").replace(UPLOAD_RETURN_PATTERN, "return uploadRequest;").replace(LET_TASK_TDZ_PATTERN, "let task = null; task = $2");
|
|
2241
|
+
if (transformed !== code) {
|
|
2242
|
+
return { code: transformed, map: null };
|
|
2243
|
+
}
|
|
2244
|
+
}
|
|
2245
|
+
}
|
|
2246
|
+
};
|
|
2247
|
+
}
|
|
2248
|
+
function createCompositionFixPlugin() {
|
|
2249
|
+
return {
|
|
2250
|
+
name: "vtj-composition-fix",
|
|
2251
|
+
enforce: "pre",
|
|
2252
|
+
transform(code, id) {
|
|
2253
|
+
if (!id.endsWith(".vue"))
|
|
2254
|
+
return;
|
|
2255
|
+
if (!code.includes("useProvider") && !code.includes("__provider"))
|
|
2256
|
+
return;
|
|
2257
|
+
if (!code.includes("const __props") && !code.includes("const __emit"))
|
|
2258
|
+
return;
|
|
2259
|
+
return code.replace(
|
|
2260
|
+
/(<script[^>]*\bsetup\b[^>]*>)([\s\S]*?)(<\/script>)/,
|
|
2261
|
+
(_, open, body, close) => {
|
|
2262
|
+
const fixed = body.replace(/\bconst\s+__props\b/g, "const props").replace(/\bconst\s+__emit\b/g, "const emit").replace(/__props\./g, "props.").replace(/__emit\s*\(/g, "emit(");
|
|
2263
|
+
return open + fixed + close;
|
|
2264
|
+
}
|
|
2265
|
+
);
|
|
2266
|
+
}
|
|
2267
|
+
};
|
|
2268
|
+
}
|
|
2221
2269
|
|
|
2222
|
-
export { createDevTools, parsePresetPlugins, vtjModulesPlugin };
|
|
2270
|
+
export { createCompositionFixPlugin, createDevTools, fixAxiosAdapterUploadConflict, parsePresetPlugins, vtjModulesPlugin };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vtj/local",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.18.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"低代码引擎",
|
|
@@ -22,16 +22,16 @@
|
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"formidable": "~3.5.1",
|
|
25
|
-
"@vtj/coder": "~0.
|
|
26
|
-
"@vtj/node": "~0.
|
|
27
|
-
"@vtj/parser": "~0.
|
|
28
|
-
"@vtj/core": "~0.
|
|
25
|
+
"@vtj/coder": "~0.18.0",
|
|
26
|
+
"@vtj/node": "~0.13.0",
|
|
27
|
+
"@vtj/parser": "~0.18.0",
|
|
28
|
+
"@vtj/core": "~0.18.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/formidable": "~3.4.5",
|
|
32
32
|
"unbuild": "~2.0.0",
|
|
33
33
|
"vite": "~6.3.0",
|
|
34
|
-
"@vtj/cli": "~0.
|
|
34
|
+
"@vtj/cli": "~0.13.0"
|
|
35
35
|
},
|
|
36
36
|
"exports": {
|
|
37
37
|
".": {
|