@wevu/compiler 6.14.1 → 6.14.3
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.mjs +47 -23
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -411,12 +411,15 @@ function rewriteJsLikeImportsForTempDir(source, fromDir, tempDir) {
|
|
|
411
411
|
}
|
|
412
412
|
//#endregion
|
|
413
413
|
//#region src/plugins/vue/transform/wevuTempDir.ts
|
|
414
|
+
const PROJECT_WEVU_CONFIG_DIR = path.join(".weapp-vite", "wevu-config");
|
|
415
|
+
/**
|
|
416
|
+
* 优先把临时配置缓存放到项目内,避免宏求值时脱离项目根目录导致包名导入解析异常。
|
|
417
|
+
*/
|
|
414
418
|
function getWevuConfigCacheRoot() {
|
|
415
419
|
const env = process.env.WEAPP_VITE_WEVU_CONFIG_DIR?.trim();
|
|
416
420
|
if (env) return path.resolve(env);
|
|
417
|
-
const
|
|
418
|
-
|
|
419
|
-
if (fs.existsSync(projectCacheDir)) return projectCacheDir;
|
|
421
|
+
const projectRoot = process.cwd();
|
|
422
|
+
if (fs.existsSync(projectRoot)) return path.join(projectRoot, PROJECT_WEVU_CONFIG_DIR);
|
|
420
423
|
return path.join(os.tmpdir(), "weapp-vite", "wevu-config");
|
|
421
424
|
}
|
|
422
425
|
function resolveWevuConfigTempDir(fromDir) {
|
|
@@ -2175,18 +2178,19 @@ function createMacroVisitors(program, state) {
|
|
|
2175
2178
|
const setupExposeVisitors = createSetupExposeVisitors(state);
|
|
2176
2179
|
const stripTypesVisitors = createStripTypesVisitors(state);
|
|
2177
2180
|
const pageMetaVisitors = createPageMetaVisitors(state);
|
|
2178
|
-
|
|
2181
|
+
const mergedVisitors = {
|
|
2179
2182
|
...appSetupVisitors,
|
|
2180
2183
|
...setupExposeVisitors,
|
|
2181
2184
|
...stripTypesVisitors,
|
|
2182
|
-
...pageMetaVisitors
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2185
|
+
...pageMetaVisitors
|
|
2186
|
+
};
|
|
2187
|
+
mergedVisitors.CallExpression = (path) => {
|
|
2188
|
+
appSetupVisitors.CallExpression?.(path);
|
|
2189
|
+
setupExposeVisitors.CallExpression?.(path);
|
|
2190
|
+
stripTypesVisitors.CallExpression?.(path);
|
|
2191
|
+
if (!path.removed) pageMetaVisitors.CallExpression?.(path);
|
|
2189
2192
|
};
|
|
2193
|
+
return mergedVisitors;
|
|
2190
2194
|
}
|
|
2191
2195
|
//#endregion
|
|
2192
2196
|
//#region src/plugins/vue/transform/classStyleComputedBuilders.ts
|
|
@@ -7175,6 +7179,9 @@ async function inlineScriptSetupDefineOptionsArgs(content, filename, lang) {
|
|
|
7175
7179
|
const SETUP_CALL_RE = /\bsetup\s*\(/;
|
|
7176
7180
|
const DEFINE_OPTIONS_CALL_RE = /\bdefineOptions\s*\(/;
|
|
7177
7181
|
const APP_VUE_FILE_RE = /[\\/]app\.vue$/;
|
|
7182
|
+
const TEMPLATE_BLOCK_RE = /<template\b[\s\S]*?<\/template>/g;
|
|
7183
|
+
const TEMPLATE_IMPORT_META_RE = /\bimport\.meta\b/g;
|
|
7184
|
+
const TEMPLATE_IMPORT_META_PLACEHOLDER = "__im_meta__";
|
|
7178
7185
|
function resolveSfcScriptLangLabel(lang) {
|
|
7179
7186
|
return typeof lang === "string" && lang.length > 0 ? lang : "(default)";
|
|
7180
7187
|
}
|
|
@@ -7202,14 +7209,37 @@ function extractDefineOptionsHash(content) {
|
|
|
7202
7209
|
if (!macroSources.length) return;
|
|
7203
7210
|
return createHash("sha256").update(macroSources.join("\n")).digest("hex").slice(0, 12);
|
|
7204
7211
|
}
|
|
7212
|
+
function preprocessTemplateImportMeta(source) {
|
|
7213
|
+
return source.replace(TEMPLATE_BLOCK_RE, (block) => block.replace(TEMPLATE_IMPORT_META_RE, TEMPLATE_IMPORT_META_PLACEHOLDER));
|
|
7214
|
+
}
|
|
7215
|
+
function restoreTemplateImportMeta(content) {
|
|
7216
|
+
return content.replace(new RegExp(TEMPLATE_IMPORT_META_PLACEHOLDER, "g"), "import.meta");
|
|
7217
|
+
}
|
|
7218
|
+
function restoreTemplateImportMetaInDescriptor(descriptor) {
|
|
7219
|
+
if (!descriptor.template?.content?.includes(TEMPLATE_IMPORT_META_PLACEHOLDER)) return descriptor;
|
|
7220
|
+
return {
|
|
7221
|
+
...descriptor,
|
|
7222
|
+
template: {
|
|
7223
|
+
...descriptor.template,
|
|
7224
|
+
content: restoreTemplateImportMeta(descriptor.template.content)
|
|
7225
|
+
}
|
|
7226
|
+
};
|
|
7227
|
+
}
|
|
7228
|
+
function parseSfc(source, filename, ignoreEmpty) {
|
|
7229
|
+
const parsed = parse(preprocessTemplateImportMeta(source), {
|
|
7230
|
+
filename,
|
|
7231
|
+
ignoreEmpty
|
|
7232
|
+
});
|
|
7233
|
+
return {
|
|
7234
|
+
...parsed,
|
|
7235
|
+
descriptor: restoreTemplateImportMetaInDescriptor(parsed.descriptor)
|
|
7236
|
+
};
|
|
7237
|
+
}
|
|
7205
7238
|
async function parseVueFile(source, filename, options) {
|
|
7206
7239
|
const normalizedInputSource = normalizeLineEndings(source);
|
|
7207
7240
|
const normalizedSource = preprocessScriptSrc(preprocessScriptSetupSrc(normalizedInputSource));
|
|
7208
7241
|
let descriptorForCompileSource = normalizedSource;
|
|
7209
|
-
const { descriptor, errors } =
|
|
7210
|
-
filename,
|
|
7211
|
-
ignoreEmpty: normalizedSource === normalizedInputSource
|
|
7212
|
-
});
|
|
7242
|
+
const { descriptor, errors } = parseSfc(normalizedSource, filename, normalizedSource === normalizedInputSource);
|
|
7213
7243
|
restoreScriptSetupSrc(descriptor);
|
|
7214
7244
|
restoreScriptSrc(descriptor);
|
|
7215
7245
|
if (errors.length > 0) {
|
|
@@ -7257,10 +7287,7 @@ async function parseVueFile(source, filename, options) {
|
|
|
7257
7287
|
const startOffset = setupLoc.start.offset;
|
|
7258
7288
|
const endOffset = setupLoc.end.offset;
|
|
7259
7289
|
const nextSource = descriptorForCompileSource.slice(0, startOffset) + extracted.stripped + descriptorForCompileSource.slice(endOffset);
|
|
7260
|
-
const { descriptor: nextDescriptor, errors: nextErrors } =
|
|
7261
|
-
filename,
|
|
7262
|
-
ignoreEmpty: false
|
|
7263
|
-
});
|
|
7290
|
+
const { descriptor: nextDescriptor, errors: nextErrors } = parseSfc(nextSource, filename, false);
|
|
7264
7291
|
restoreScriptSetupSrc(nextDescriptor);
|
|
7265
7292
|
restoreScriptSrc(nextDescriptor);
|
|
7266
7293
|
if (nextErrors.length > 0) {
|
|
@@ -7297,10 +7324,7 @@ async function parseVueFile(source, filename, options) {
|
|
|
7297
7324
|
const startOffset = setupLoc.start.offset;
|
|
7298
7325
|
const endOffset = setupLoc.end.offset;
|
|
7299
7326
|
const nextSource = descriptorForCompileSource.slice(0, startOffset) + inlined.code + descriptorForCompileSource.slice(endOffset);
|
|
7300
|
-
const { descriptor: nextDescriptor, errors: nextErrors } =
|
|
7301
|
-
filename,
|
|
7302
|
-
ignoreEmpty: false
|
|
7303
|
-
});
|
|
7327
|
+
const { descriptor: nextDescriptor, errors: nextErrors } = parseSfc(nextSource, filename, false);
|
|
7304
7328
|
restoreScriptSetupSrc(nextDescriptor);
|
|
7305
7329
|
restoreScriptSrc(nextDescriptor);
|
|
7306
7330
|
if (nextErrors.length > 0) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wevu/compiler",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "6.14.
|
|
4
|
+
"version": "6.14.3",
|
|
5
5
|
"description": "wevu 编译器基础包,面向小程序模板的编译与转换",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"pathe": "^2.0.3",
|
|
51
51
|
"vue": "^3.5.32",
|
|
52
52
|
"@weapp-core/shared": "3.0.3",
|
|
53
|
-
"@weapp-vite/ast": "6.14.
|
|
53
|
+
"@weapp-vite/ast": "6.14.3",
|
|
54
54
|
"rolldown-require": "2.0.12"
|
|
55
55
|
},
|
|
56
56
|
"publishConfig": {
|