@wevu/compiler 6.14.2 → 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.
Files changed (2) hide show
  1. package/dist/index.mjs +46 -23
  2. package/package.json +2 -2
package/dist/index.mjs CHANGED
@@ -412,12 +412,14 @@ function rewriteJsLikeImportsForTempDir(source, fromDir, tempDir) {
412
412
  //#endregion
413
413
  //#region src/plugins/vue/transform/wevuTempDir.ts
414
414
  const PROJECT_WEVU_CONFIG_DIR = path.join(".weapp-vite", "wevu-config");
415
+ /**
416
+ * 优先把临时配置缓存放到项目内,避免宏求值时脱离项目根目录导致包名导入解析异常。
417
+ */
415
418
  function getWevuConfigCacheRoot() {
416
419
  const env = process.env.WEAPP_VITE_WEVU_CONFIG_DIR?.trim();
417
420
  if (env) return path.resolve(env);
418
- const cwd = process.cwd();
419
- const projectCacheDir = path.join(cwd, PROJECT_WEVU_CONFIG_DIR);
420
- if (fs.existsSync(projectCacheDir)) return projectCacheDir;
421
+ const projectRoot = process.cwd();
422
+ if (fs.existsSync(projectRoot)) return path.join(projectRoot, PROJECT_WEVU_CONFIG_DIR);
421
423
  return path.join(os.tmpdir(), "weapp-vite", "wevu-config");
422
424
  }
423
425
  function resolveWevuConfigTempDir(fromDir) {
@@ -2176,18 +2178,19 @@ function createMacroVisitors(program, state) {
2176
2178
  const setupExposeVisitors = createSetupExposeVisitors(state);
2177
2179
  const stripTypesVisitors = createStripTypesVisitors(state);
2178
2180
  const pageMetaVisitors = createPageMetaVisitors(state);
2179
- return {
2181
+ const mergedVisitors = {
2180
2182
  ...appSetupVisitors,
2181
2183
  ...setupExposeVisitors,
2182
2184
  ...stripTypesVisitors,
2183
- ...pageMetaVisitors,
2184
- CallExpression(path) {
2185
- appSetupVisitors.CallExpression?.(path);
2186
- setupExposeVisitors.CallExpression?.(path);
2187
- stripTypesVisitors.CallExpression?.(path);
2188
- if (!path.removed) pageMetaVisitors.CallExpression?.(path);
2189
- }
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);
2190
2192
  };
2193
+ return mergedVisitors;
2191
2194
  }
2192
2195
  //#endregion
2193
2196
  //#region src/plugins/vue/transform/classStyleComputedBuilders.ts
@@ -7176,6 +7179,9 @@ async function inlineScriptSetupDefineOptionsArgs(content, filename, lang) {
7176
7179
  const SETUP_CALL_RE = /\bsetup\s*\(/;
7177
7180
  const DEFINE_OPTIONS_CALL_RE = /\bdefineOptions\s*\(/;
7178
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__";
7179
7185
  function resolveSfcScriptLangLabel(lang) {
7180
7186
  return typeof lang === "string" && lang.length > 0 ? lang : "(default)";
7181
7187
  }
@@ -7203,14 +7209,37 @@ function extractDefineOptionsHash(content) {
7203
7209
  if (!macroSources.length) return;
7204
7210
  return createHash("sha256").update(macroSources.join("\n")).digest("hex").slice(0, 12);
7205
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
+ }
7206
7238
  async function parseVueFile(source, filename, options) {
7207
7239
  const normalizedInputSource = normalizeLineEndings(source);
7208
7240
  const normalizedSource = preprocessScriptSrc(preprocessScriptSetupSrc(normalizedInputSource));
7209
7241
  let descriptorForCompileSource = normalizedSource;
7210
- const { descriptor, errors } = parse(normalizedSource, {
7211
- filename,
7212
- ignoreEmpty: normalizedSource === normalizedInputSource
7213
- });
7242
+ const { descriptor, errors } = parseSfc(normalizedSource, filename, normalizedSource === normalizedInputSource);
7214
7243
  restoreScriptSetupSrc(descriptor);
7215
7244
  restoreScriptSrc(descriptor);
7216
7245
  if (errors.length > 0) {
@@ -7258,10 +7287,7 @@ async function parseVueFile(source, filename, options) {
7258
7287
  const startOffset = setupLoc.start.offset;
7259
7288
  const endOffset = setupLoc.end.offset;
7260
7289
  const nextSource = descriptorForCompileSource.slice(0, startOffset) + extracted.stripped + descriptorForCompileSource.slice(endOffset);
7261
- const { descriptor: nextDescriptor, errors: nextErrors } = parse(nextSource, {
7262
- filename,
7263
- ignoreEmpty: false
7264
- });
7290
+ const { descriptor: nextDescriptor, errors: nextErrors } = parseSfc(nextSource, filename, false);
7265
7291
  restoreScriptSetupSrc(nextDescriptor);
7266
7292
  restoreScriptSrc(nextDescriptor);
7267
7293
  if (nextErrors.length > 0) {
@@ -7298,10 +7324,7 @@ async function parseVueFile(source, filename, options) {
7298
7324
  const startOffset = setupLoc.start.offset;
7299
7325
  const endOffset = setupLoc.end.offset;
7300
7326
  const nextSource = descriptorForCompileSource.slice(0, startOffset) + inlined.code + descriptorForCompileSource.slice(endOffset);
7301
- const { descriptor: nextDescriptor, errors: nextErrors } = parse(nextSource, {
7302
- filename,
7303
- ignoreEmpty: false
7304
- });
7327
+ const { descriptor: nextDescriptor, errors: nextErrors } = parseSfc(nextSource, filename, false);
7305
7328
  restoreScriptSetupSrc(nextDescriptor);
7306
7329
  restoreScriptSrc(nextDescriptor);
7307
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.2",
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.2",
53
+ "@weapp-vite/ast": "6.14.3",
54
54
  "rolldown-require": "2.0.12"
55
55
  },
56
56
  "publishConfig": {