@vureact/compiler-core 1.7.0 → 1.8.1

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @vureact/compiler-core v1.7.0
2
+ * @vureact/compiler-core v1.8.1
3
3
  * (c) 2025-present Ruihong Zhong (Ryan John)
4
4
  * @license MIT
5
5
  */
@@ -451,8 +451,8 @@ function getBabelParseOptions(lang = "js", context = "script", filename) {
451
451
  function stringToExpr(input, lang, filename = "") {
452
452
  return parseExpression(input, getBabelParseOptions(lang, "expression", filename));
453
453
  }
454
- function atComponentOrHookRoot(path9, rootScope, inScriptFile = false) {
455
- const { parentPath, scope } = path9;
454
+ function atComponentOrHookRoot(path8, rootScope, inScriptFile = false) {
455
+ const { parentPath, scope } = path8;
456
456
  const parentBlock = scope.block;
457
457
  if (!parentPath) return !inScriptFile;
458
458
  if (parentBlock === rootScope) {
@@ -1521,10 +1521,10 @@ import * as t16 from "@babel/types";
1521
1521
 
1522
1522
  // src/core/transform/sfc/script/shared/babel-utils.ts
1523
1523
  import * as t15 from "@babel/types";
1524
- function findRootVariablePath(path9) {
1525
- const rootId = findRootIdentifier(path9.node);
1524
+ function findRootVariablePath(path8) {
1525
+ const rootId = findRootIdentifier(path8.node);
1526
1526
  if (!rootId?.name) return null;
1527
- const binding = path9.scope.getBinding(rootId.name);
1527
+ const binding = path8.scope.getBinding(rootId.name);
1528
1528
  if (!binding) return null;
1529
1529
  const rootPath = getVariableDeclaratorPath(binding.path);
1530
1530
  return rootPath;
@@ -1536,14 +1536,14 @@ function findRootIdentifier(node) {
1536
1536
  }
1537
1537
  return t15.isIdentifier(current) ? current : null;
1538
1538
  }
1539
- function getVariableDeclaratorPath(path9) {
1540
- if (path9.isVariableDeclarator()) {
1541
- return path9;
1539
+ function getVariableDeclaratorPath(path8) {
1540
+ if (path8.isVariableDeclarator()) {
1541
+ return path8;
1542
1542
  }
1543
- return path9.findParent((p) => p.isVariableDeclarator());
1543
+ return path8.findParent((p) => p.isVariableDeclarator());
1544
1544
  }
1545
- function isVariableDeclTopLevel(path9) {
1546
- const variableDeclaratorPath = path9;
1545
+ function isVariableDeclTopLevel(path8) {
1546
+ const variableDeclaratorPath = path8;
1547
1547
  const variableDeclarationPath = variableDeclaratorPath.parentPath;
1548
1548
  if (!variableDeclarationPath) {
1549
1549
  return false;
@@ -1557,61 +1557,61 @@ function isVariableDeclTopLevel(path9) {
1557
1557
  }
1558
1558
  return false;
1559
1559
  }
1560
- function isRealVariableAccess(path9) {
1561
- return isIdentifierAccess(path9) && !isPropertyName(path9);
1560
+ function isRealVariableAccess(path8) {
1561
+ return isIdentifierAccess(path8) && !isPropertyName(path8);
1562
1562
  }
1563
- function isIdentifierAccess(path9) {
1564
- if (isIdentifierDeclaration(path9)) {
1563
+ function isIdentifierAccess(path8) {
1564
+ if (isIdentifierDeclaration(path8)) {
1565
1565
  return false;
1566
1566
  }
1567
- const binding = path9.scope.getBinding(path9.node.name);
1567
+ const binding = path8.scope.getBinding(path8.node.name);
1568
1568
  if (!binding) {
1569
1569
  return true;
1570
1570
  }
1571
- return binding.identifier !== path9.node;
1571
+ return binding.identifier !== path8.node;
1572
1572
  }
1573
- function isIdentifierDeclaration(path9) {
1574
- const parent = path9.parentPath;
1573
+ function isIdentifierDeclaration(path8) {
1574
+ const parent = path8.parentPath;
1575
1575
  if (!parent) return false;
1576
- if (parent.isVariableDeclarator() && parent.node.id === path9.node) {
1576
+ if (parent.isVariableDeclarator() && parent.node.id === path8.node) {
1577
1577
  return true;
1578
1578
  }
1579
- if (parent.isFunctionDeclaration() && parent.node.id === path9.node) {
1579
+ if (parent.isFunctionDeclaration() && parent.node.id === path8.node) {
1580
1580
  return true;
1581
1581
  }
1582
- if (parent.isFunctionExpression() && parent.node.id === path9.node) {
1582
+ if (parent.isFunctionExpression() && parent.node.id === path8.node) {
1583
1583
  return true;
1584
1584
  }
1585
- if (parent.isClassDeclaration() && parent.node.id === path9.node) {
1585
+ if (parent.isClassDeclaration() && parent.node.id === path8.node) {
1586
1586
  return true;
1587
1587
  }
1588
- if (parent.isImportSpecifier() && parent.node.local === path9.node) {
1588
+ if (parent.isImportSpecifier() && parent.node.local === path8.node) {
1589
1589
  return true;
1590
1590
  }
1591
- if (parent.isImportDefaultSpecifier() && parent.node.local === path9.node) {
1591
+ if (parent.isImportDefaultSpecifier() && parent.node.local === path8.node) {
1592
1592
  return true;
1593
1593
  }
1594
- if (parent.isImportNamespaceSpecifier() && parent.node.local === path9.node) {
1594
+ if (parent.isImportNamespaceSpecifier() && parent.node.local === path8.node) {
1595
1595
  return true;
1596
1596
  }
1597
- if (parent.isFunction() && parent.node.params.includes(path9.node)) {
1597
+ if (parent.isFunction() && parent.node.params.includes(path8.node)) {
1598
1598
  return true;
1599
1599
  }
1600
- if (parent.isCatchClause() && parent.node.param === path9.node) {
1600
+ if (parent.isCatchClause() && parent.node.param === path8.node) {
1601
1601
  return true;
1602
1602
  }
1603
1603
  return false;
1604
1604
  }
1605
- function isPropertyName(path9) {
1606
- const parent = path9.parentPath;
1605
+ function isPropertyName(path8) {
1606
+ const parent = path8.parentPath;
1607
1607
  if (!parent) return false;
1608
- if (parent.isObjectProperty() && parent.node.key === path9.node) {
1608
+ if (parent.isObjectProperty() && parent.node.key === path8.node) {
1609
1609
  return true;
1610
1610
  }
1611
- if (parent.isClassProperty() && parent.node.key === path9.node) {
1611
+ if (parent.isClassProperty() && parent.node.key === path8.node) {
1612
1612
  return true;
1613
1613
  }
1614
- if (parent.isMemberExpression() && parent.node.property === path9.node) {
1614
+ if (parent.isMemberExpression() && parent.node.property === path8.node) {
1615
1615
  return true;
1616
1616
  }
1617
1617
  return false;
@@ -1707,7 +1707,7 @@ function forkNode(node, deep = true) {
1707
1707
  cleanNodeComments(node);
1708
1708
  return newNode;
1709
1709
  }
1710
- function replaceNode(path9, target, source) {
1710
+ function replaceNode(path8, target, source) {
1711
1711
  const { start, end, loc, leadingComments, innerComments, trailingComments } = source;
1712
1712
  target.start = start;
1713
1713
  target.end = end;
@@ -1717,7 +1717,7 @@ function replaceNode(path9, target, source) {
1717
1717
  target.trailingComments = trailingComments;
1718
1718
  cleanNodeLoc(source);
1719
1719
  cleanNodeComments(source);
1720
- path9.replaceWith(target);
1720
+ path8.replaceWith(target);
1721
1721
  }
1722
1722
  function cleanNodeLoc(node) {
1723
1723
  node.start = null;
@@ -1731,8 +1731,8 @@ function cleanNodeComments(node) {
1731
1731
  }
1732
1732
 
1733
1733
  // src/core/parse/sfc/postprocess/resolve-script-metadata/resolve-declared-options.ts
1734
- function resolveDeclaredOptions(path9, ctx) {
1735
- const { node } = path9;
1734
+ function resolveDeclaredOptions(path8, ctx) {
1735
+ const { node } = path8;
1736
1736
  const { filename, scriptData } = ctx;
1737
1737
  if (!isCalleeNamed(node, MACRO_API_NAMES.options)) {
1738
1738
  return;
@@ -1854,11 +1854,11 @@ function resolveStaticName(key) {
1854
1854
  }
1855
1855
  return null;
1856
1856
  }
1857
- function resolveLocalTypeFromReference(path9, typeRef, ctx, macroName, visitedTypeRefs, warnedImportedTypeRefs) {
1857
+ function resolveLocalTypeFromReference(path8, typeRef, ctx, macroName, visitedTypeRefs, warnedImportedTypeRefs) {
1858
1858
  const refName = resolveTypeReferenceName(typeRef.typeName);
1859
1859
  if (!refName) return null;
1860
1860
  if (visitedTypeRefs.has(refName)) return null;
1861
- const binding = path9.scope.getBinding(refName);
1861
+ const binding = path8.scope.getBinding(refName);
1862
1862
  if (binding) {
1863
1863
  if (binding.path.isImportSpecifier() || binding.path.isImportDefaultSpecifier() || binding.path.isImportNamespaceSpecifier()) {
1864
1864
  const key = `${macroName}:${refName}`;
@@ -1869,7 +1869,7 @@ function resolveLocalTypeFromReference(path9, typeRef, ctx, macroName, visitedTy
1869
1869
  {
1870
1870
  file: ctx.filename,
1871
1871
  source: ctx.source,
1872
- loc: typeRef.loc || path9.node.loc
1872
+ loc: typeRef.loc || path8.node.loc
1873
1873
  }
1874
1874
  );
1875
1875
  }
@@ -1883,7 +1883,7 @@ function resolveLocalTypeFromReference(path9, typeRef, ctx, macroName, visitedTy
1883
1883
  return binding.path.node.typeAnnotation;
1884
1884
  }
1885
1885
  }
1886
- const programPath = path9.findParent((p) => p.isProgram());
1886
+ const programPath = path8.findParent((p) => p.isProgram());
1887
1887
  if (!programPath?.isProgram()) {
1888
1888
  return null;
1889
1889
  }
@@ -1902,7 +1902,7 @@ function resolveLocalTypeFromReference(path9, typeRef, ctx, macroName, visitedTy
1902
1902
  {
1903
1903
  file: ctx.filename,
1904
1904
  source: ctx.source,
1905
- loc: typeRef.loc || path9.node.loc
1905
+ loc: typeRef.loc || path8.node.loc
1906
1906
  }
1907
1907
  );
1908
1908
  }
@@ -1959,8 +1959,8 @@ function resolveImportedTypeSourceInProgram(body, typeName) {
1959
1959
  }
1960
1960
 
1961
1961
  // src/core/parse/sfc/postprocess/resolve-script-metadata/resolve-declared-props-emits/resolve-declared-emits.ts
1962
- function resolveDeclaredEmits(path9, ctx) {
1963
- const { node } = path9;
1962
+ function resolveDeclaredEmits(path8, ctx) {
1963
+ const { node } = path8;
1964
1964
  const { templateData, scriptData } = ctx;
1965
1965
  if (!isCalleeNamed(node, MACRO_API_NAMES.emits)) {
1966
1966
  return;
@@ -1971,28 +1971,28 @@ function resolveDeclaredEmits(path9, ctx) {
1971
1971
  mergeNames(templateData.declaredEmits, resolveObjectOrArrayLiteralNames(initValue));
1972
1972
  return;
1973
1973
  }
1974
- const namesFromType = resolveDeclaredEmitsFromTypeParams(tsTypeDef, path9, ctx);
1974
+ const namesFromType = resolveDeclaredEmitsFromTypeParams(tsTypeDef, path8, ctx);
1975
1975
  if (namesFromType.size) {
1976
1976
  mergeNames(templateData.declaredEmits, namesFromType);
1977
1977
  return;
1978
1978
  }
1979
1979
  mergeNames(templateData.declaredEmits, resolveObjectOrArrayLiteralNames(initValue));
1980
1980
  }
1981
- function resolveDeclaredEmitsFromTypeParams(typeParams, path9, ctx) {
1981
+ function resolveDeclaredEmitsFromTypeParams(typeParams, path8, ctx) {
1982
1982
  const names = /* @__PURE__ */ new Set();
1983
1983
  const visitedTypeRefs = /* @__PURE__ */ new Set();
1984
1984
  const warnedImportedTypeRefs = /* @__PURE__ */ new Set();
1985
1985
  for (const tsType of resolveTsTypes(typeParams)) {
1986
- collectEmitsFromTsType(tsType, names, path9, ctx, visitedTypeRefs, warnedImportedTypeRefs);
1986
+ collectEmitsFromTsType(tsType, names, path8, ctx, visitedTypeRefs, warnedImportedTypeRefs);
1987
1987
  }
1988
1988
  return names;
1989
1989
  }
1990
- function collectEmitsFromTsType(tsType, names, path9, ctx, visitedTypeRefs, warnedImportedTypeRefs) {
1990
+ function collectEmitsFromTsType(tsType, names, path8, ctx, visitedTypeRefs, warnedImportedTypeRefs) {
1991
1991
  if (t18.isTSParenthesizedType(tsType)) {
1992
1992
  collectEmitsFromTsType(
1993
1993
  tsType.typeAnnotation,
1994
1994
  names,
1995
- path9,
1995
+ path8,
1996
1996
  ctx,
1997
1997
  visitedTypeRefs,
1998
1998
  warnedImportedTypeRefs
@@ -2001,17 +2001,17 @@ function collectEmitsFromTsType(tsType, names, path9, ctx, visitedTypeRefs, warn
2001
2001
  }
2002
2002
  if (t18.isTSIntersectionType(tsType) || t18.isTSUnionType(tsType)) {
2003
2003
  for (const type of tsType.types) {
2004
- collectEmitsFromTsType(type, names, path9, ctx, visitedTypeRefs, warnedImportedTypeRefs);
2004
+ collectEmitsFromTsType(type, names, path8, ctx, visitedTypeRefs, warnedImportedTypeRefs);
2005
2005
  }
2006
2006
  return;
2007
2007
  }
2008
2008
  if (t18.isTSTypeReference(tsType)) {
2009
2009
  const innerTypes = tsType.typeParameters?.params || [];
2010
2010
  for (const type of innerTypes) {
2011
- collectEmitsFromTsType(type, names, path9, ctx, visitedTypeRefs, warnedImportedTypeRefs);
2011
+ collectEmitsFromTsType(type, names, path8, ctx, visitedTypeRefs, warnedImportedTypeRefs);
2012
2012
  }
2013
2013
  const localType = resolveLocalTypeFromReference(
2014
- path9,
2014
+ path8,
2015
2015
  tsType,
2016
2016
  ctx,
2017
2017
  MACRO_API_NAMES.emits,
@@ -2019,7 +2019,7 @@ function collectEmitsFromTsType(tsType, names, path9, ctx, visitedTypeRefs, warn
2019
2019
  warnedImportedTypeRefs
2020
2020
  );
2021
2021
  if (localType) {
2022
- collectEmitsFromTsType(localType, names, path9, ctx, visitedTypeRefs, warnedImportedTypeRefs);
2022
+ collectEmitsFromTsType(localType, names, path8, ctx, visitedTypeRefs, warnedImportedTypeRefs);
2023
2023
  }
2024
2024
  return;
2025
2025
  }
@@ -2095,8 +2095,8 @@ function resolveStringLiteralTypeNames(type) {
2095
2095
 
2096
2096
  // src/core/parse/sfc/postprocess/resolve-script-metadata/resolve-declared-props-emits/resolve-declared-props.ts
2097
2097
  import * as t19 from "@babel/types";
2098
- function resolveDeclaredProps(path9, ctx) {
2099
- const { node } = path9;
2098
+ function resolveDeclaredProps(path8, ctx) {
2099
+ const { node } = path8;
2100
2100
  const { templateData, scriptData } = ctx;
2101
2101
  if (!isCalleeNamed(node, MACRO_API_NAMES.props)) {
2102
2102
  return;
@@ -2107,28 +2107,28 @@ function resolveDeclaredProps(path9, ctx) {
2107
2107
  mergeNames(templateData.declaredProps, resolveObjectOrArrayLiteralNames(initValue));
2108
2108
  return;
2109
2109
  }
2110
- const namesFromType = resolveDeclaredPropsFromTypeParams(tsTypeDef, path9, ctx);
2110
+ const namesFromType = resolveDeclaredPropsFromTypeParams(tsTypeDef, path8, ctx);
2111
2111
  if (namesFromType.size) {
2112
2112
  mergeNames(templateData.declaredProps, namesFromType);
2113
2113
  return;
2114
2114
  }
2115
2115
  mergeNames(templateData.declaredProps, resolveObjectOrArrayLiteralNames(initValue));
2116
2116
  }
2117
- function resolveDeclaredPropsFromTypeParams(typeParams, path9, ctx) {
2117
+ function resolveDeclaredPropsFromTypeParams(typeParams, path8, ctx) {
2118
2118
  const names = /* @__PURE__ */ new Set();
2119
2119
  const visitedTypeRefs = /* @__PURE__ */ new Set();
2120
2120
  const warnedImportedTypeRefs = /* @__PURE__ */ new Set();
2121
2121
  for (const tsType of resolveTsTypes(typeParams)) {
2122
- collectPropsFromTsType(tsType, names, path9, ctx, visitedTypeRefs, warnedImportedTypeRefs);
2122
+ collectPropsFromTsType(tsType, names, path8, ctx, visitedTypeRefs, warnedImportedTypeRefs);
2123
2123
  }
2124
2124
  return names;
2125
2125
  }
2126
- function collectPropsFromTsType(tsType, names, path9, ctx, visitedTypeRefs, warnedImportedTypeRefs) {
2126
+ function collectPropsFromTsType(tsType, names, path8, ctx, visitedTypeRefs, warnedImportedTypeRefs) {
2127
2127
  if (t19.isTSParenthesizedType(tsType)) {
2128
2128
  collectPropsFromTsType(
2129
2129
  tsType.typeAnnotation,
2130
2130
  names,
2131
- path9,
2131
+ path8,
2132
2132
  ctx,
2133
2133
  visitedTypeRefs,
2134
2134
  warnedImportedTypeRefs
@@ -2137,17 +2137,17 @@ function collectPropsFromTsType(tsType, names, path9, ctx, visitedTypeRefs, warn
2137
2137
  }
2138
2138
  if (t19.isTSIntersectionType(tsType) || t19.isTSUnionType(tsType)) {
2139
2139
  for (const type of tsType.types) {
2140
- collectPropsFromTsType(type, names, path9, ctx, visitedTypeRefs, warnedImportedTypeRefs);
2140
+ collectPropsFromTsType(type, names, path8, ctx, visitedTypeRefs, warnedImportedTypeRefs);
2141
2141
  }
2142
2142
  return;
2143
2143
  }
2144
2144
  if (t19.isTSTypeReference(tsType)) {
2145
2145
  const innerTypes = tsType.typeParameters?.params || [];
2146
2146
  for (const type of innerTypes) {
2147
- collectPropsFromTsType(type, names, path9, ctx, visitedTypeRefs, warnedImportedTypeRefs);
2147
+ collectPropsFromTsType(type, names, path8, ctx, visitedTypeRefs, warnedImportedTypeRefs);
2148
2148
  }
2149
2149
  const localType = resolveLocalTypeFromReference(
2150
- path9,
2150
+ path8,
2151
2151
  tsType,
2152
2152
  ctx,
2153
2153
  MACRO_API_NAMES.props,
@@ -2155,7 +2155,7 @@ function collectPropsFromTsType(tsType, names, path9, ctx, visitedTypeRefs, warn
2155
2155
  warnedImportedTypeRefs
2156
2156
  );
2157
2157
  if (localType) {
2158
- collectPropsFromTsType(localType, names, path9, ctx, visitedTypeRefs, warnedImportedTypeRefs);
2158
+ collectPropsFromTsType(localType, names, path8, ctx, visitedTypeRefs, warnedImportedTypeRefs);
2159
2159
  }
2160
2160
  return;
2161
2161
  }
@@ -2174,15 +2174,15 @@ function collectPropsFromTsType(tsType, names, path9, ctx, visitedTypeRefs, warn
2174
2174
  }
2175
2175
 
2176
2176
  // src/core/parse/sfc/postprocess/resolve-script-metadata/resolve-declared-props-emits/index.ts
2177
- function resolveDeclaredPropsAndEmits(path9, ctx) {
2178
- resolveDeclaredProps(path9, ctx);
2179
- resolveDeclaredEmits(path9, ctx);
2177
+ function resolveDeclaredPropsAndEmits(path8, ctx) {
2178
+ resolveDeclaredProps(path8, ctx);
2179
+ resolveDeclaredEmits(path8, ctx);
2180
2180
  }
2181
2181
 
2182
2182
  // src/core/parse/sfc/postprocess/resolve-script-metadata/resolve-use-attrs-exists.ts
2183
2183
  import * as t20 from "@babel/types";
2184
- function resolveUseAttrsExists(path9, ctx) {
2185
- const { node } = path9;
2184
+ function resolveUseAttrsExists(path8, ctx) {
2185
+ const { node } = path8;
2186
2186
  const { templateData, scriptData } = ctx;
2187
2187
  if (!isCalleeNamed(node, VUE_API_MAP.useAttrs)) {
2188
2188
  return;
@@ -2191,7 +2191,7 @@ function resolveUseAttrsExists(path9, ctx) {
2191
2191
  return;
2192
2192
  }
2193
2193
  scriptData.hasUseAttrsCall = true;
2194
- const parent = path9.parentPath?.node;
2194
+ const parent = path8.parentPath?.node;
2195
2195
  if (parent && t20.isVariableDeclarator(parent) && t20.isIdentifier(parent.id)) {
2196
2196
  templateData.declaredAttrs = parent.id.name;
2197
2197
  }
@@ -2356,16 +2356,16 @@ function resolveScriptMeta(result, ctx) {
2356
2356
  return;
2357
2357
  }
2358
2358
  traverse(scriptAst, {
2359
- VariableDeclarator(path9) {
2360
- if (!atComponentOrHookRoot(path9, scriptAst.program)) {
2359
+ VariableDeclarator(path8) {
2360
+ if (!atComponentOrHookRoot(path8, scriptAst.program)) {
2361
2361
  return;
2362
2362
  }
2363
- resolveVarBindings(path9.node, ctx);
2363
+ resolveVarBindings(path8.node, ctx);
2364
2364
  },
2365
- CallExpression(path9) {
2366
- resolveDeclaredOptions(path9, ctx);
2367
- resolveDeclaredPropsAndEmits(path9, ctx);
2368
- resolveUseAttrsExists(path9, ctx);
2365
+ CallExpression(path8) {
2366
+ resolveDeclaredOptions(path8, ctx);
2367
+ resolveDeclaredPropsAndEmits(path8, ctx);
2368
+ resolveUseAttrsExists(path8, ctx);
2369
2369
  }
2370
2370
  });
2371
2371
  }
@@ -2877,25 +2877,25 @@ import { parse as babelParse3 } from "@babel/parser";
2877
2877
  import { traverse as traverse3 } from "@babel/core";
2878
2878
 
2879
2879
  // src/core/transform/sfc/script/syntax-processor/postprocess/resolve-ast-chunks/resolve-global-type-chunk.ts
2880
- function resolveGlobalTypeChunks(path9, ir) {
2881
- if (!path9.parentPath?.isProgram()) {
2880
+ function resolveGlobalTypeChunks(path8, ir) {
2881
+ if (!path8.parentPath?.isProgram()) {
2882
2882
  return;
2883
2883
  }
2884
- const forked = forkNode(path9.node);
2884
+ const forked = forkNode(path8.node);
2885
2885
  ir.tsTypes.push(forked);
2886
- path9.remove();
2886
+ path8.remove();
2887
2887
  }
2888
2888
 
2889
2889
  // src/core/transform/sfc/script/syntax-processor/postprocess/resolve-ast-chunks/resolve-module-chunk.ts
2890
2890
  import * as t22 from "@babel/types";
2891
- function resolveModuleChunks(path9, ir) {
2892
- const forked = forkNode(path9.node);
2891
+ function resolveModuleChunks(path8, ir) {
2892
+ const forked = forkNode(path8.node);
2893
2893
  if (t22.isImportDeclaration(forked)) {
2894
2894
  ir.imports.push(forked);
2895
2895
  } else if (t22.isExportDeclaration(forked)) {
2896
2896
  ir.exports.push(forked);
2897
2897
  }
2898
- path9.remove();
2898
+ path8.remove();
2899
2899
  }
2900
2900
 
2901
2901
  // src/core/transform/sfc/script/shared/metadata-utils.ts
@@ -2915,10 +2915,10 @@ function setScriptNodeMeta(node, opts) {
2915
2915
  }
2916
2916
 
2917
2917
  // src/core/transform/sfc/script/syntax-processor/postprocess/resolve-ast-chunks/resolve-static-const-chunk.ts
2918
- function resolveStaticConstChunks(path9, ir) {
2919
- const { node, parentPath } = path9;
2918
+ function resolveStaticConstChunks(path8, ir) {
2919
+ const { node, parentPath } = path8;
2920
2920
  const parent = parentPath.node;
2921
- if (!isVariableDeclTopLevel(path9) || !parentPath.isVariableDeclaration() || parent.kind !== "const" || !isSimpleLiteral(node.init) || getScriptNodeMeta(node)) {
2921
+ if (!isVariableDeclTopLevel(path8) || !parentPath.isVariableDeclaration() || parent.kind !== "const" || !isSimpleLiteral(node.init) || getScriptNodeMeta(node)) {
2922
2922
  return;
2923
2923
  }
2924
2924
  const forked = forkNode(parent);
@@ -2935,16 +2935,16 @@ function resolveASTChunks(ctx, ast) {
2935
2935
  scriptIR.statement.local = ast;
2936
2936
  return {
2937
2937
  // 提取 import/export
2938
- "ImportDeclaration|ExportDeclaration"(path9) {
2939
- resolveModuleChunks(path9, scriptIR);
2938
+ "ImportDeclaration|ExportDeclaration"(path8) {
2939
+ resolveModuleChunks(path8, scriptIR);
2940
2940
  },
2941
2941
  // 提取全局类型声明
2942
- "TSInterfaceDeclaration|TSTypeAliasDeclaration|TSEnumDeclaration|TSModuleDeclaration|TSModuleDeclaration"(path9) {
2943
- resolveGlobalTypeChunks(path9, scriptIR);
2942
+ "TSInterfaceDeclaration|TSTypeAliasDeclaration|TSEnumDeclaration|TSModuleDeclaration|TSModuleDeclaration"(path8) {
2943
+ resolveGlobalTypeChunks(path8, scriptIR);
2944
2944
  },
2945
2945
  // 提升顶层常量声明
2946
- VariableDeclarator(path9) {
2947
- resolveStaticConstChunks(path9, scriptIR);
2946
+ VariableDeclarator(path8) {
2947
+ resolveStaticConstChunks(path8, scriptIR);
2948
2948
  }
2949
2949
  };
2950
2950
  }
@@ -3030,11 +3030,11 @@ var StyleFileStrategy = class {
3030
3030
  matches(moduleName) {
3031
3031
  return this.regExp.test(moduleName);
3032
3032
  }
3033
- process(path9, ctx) {
3033
+ process(path8, ctx) {
3034
3034
  if (!ctx.preprocessStyles) {
3035
3035
  return {};
3036
3036
  }
3037
- const importSource = path9.node.source.value;
3037
+ const importSource = path8.node.source.value;
3038
3038
  if (typeof importSource !== "string") {
3039
3039
  return {};
3040
3040
  }
@@ -3079,25 +3079,25 @@ function resolveRuntimeImports(ctx) {
3079
3079
  const processedModules = /* @__PURE__ */ new Set();
3080
3080
  let hasImports = false;
3081
3081
  return {
3082
- ImportDeclaration(path9) {
3083
- const { node } = path9;
3082
+ ImportDeclaration(path8) {
3083
+ const { node } = path8;
3084
3084
  const originalModuleName = node.source.value.toLowerCase();
3085
3085
  const strategy = strategyManager.findStrategy(originalModuleName);
3086
3086
  let strategyResult = null;
3087
3087
  if (strategy) {
3088
- strategyResult = strategy.process(path9, ctx, originalModuleName);
3088
+ strategyResult = strategy.process(path8, ctx, originalModuleName);
3089
3089
  if (strategyResult.shouldReplaceSource && strategyResult.newSource) {
3090
3090
  node.source.value = strategyResult.newSource;
3091
3091
  }
3092
- if (strategyResult.shouldRemove && !path9.removed) {
3093
- path9.remove();
3092
+ if (strategyResult.shouldRemove && !path8.removed) {
3093
+ path8.remove();
3094
3094
  return;
3095
3095
  }
3096
3096
  }
3097
3097
  replaceVueSuffix(node.source);
3098
3098
  const finalModuleName = node.source.value.toLowerCase();
3099
- if (processedModules.has(finalModuleName) && !path9.removed) {
3100
- path9.remove();
3099
+ if (processedModules.has(finalModuleName) && !path8.removed) {
3100
+ path8.remove();
3101
3101
  return;
3102
3102
  }
3103
3103
  processedModules.add(finalModuleName);
@@ -3106,12 +3106,12 @@ function resolveRuntimeImports(ctx) {
3106
3106
  const importNodes = createImportNodes(ctx);
3107
3107
  if (importNodes.length) {
3108
3108
  if (strategyResult?.shouldInjectRuntimeImports) {
3109
- path9.insertAfter(importNodes);
3109
+ path8.insertAfter(importNodes);
3110
3110
  } else if (finalModuleName === PACKAGE_NAME.react) {
3111
- path9.insertAfter(importNodes);
3111
+ path8.insertAfter(importNodes);
3112
3112
  } else {
3113
3113
  forkFilePreambleLeadingComments(importNodes[0], node);
3114
- path9.insertBefore(importNodes);
3114
+ path8.insertBefore(importNodes);
3115
3115
  }
3116
3116
  }
3117
3117
  hasImports = true;
@@ -3119,14 +3119,14 @@ function resolveRuntimeImports(ctx) {
3119
3119
  },
3120
3120
  // 兜底:无 ImportDeclaration 的文件也要能注入必需依赖。
3121
3121
  Program: {
3122
- exit(path9) {
3122
+ exit(path8) {
3123
3123
  if (hasImports) return;
3124
3124
  hasImports = true;
3125
- const { node } = path9;
3125
+ const { node } = path8;
3126
3126
  const importNodes = createImportNodes(ctx);
3127
3127
  if (!importNodes.length) return;
3128
3128
  forkProgramTopLeadingComments(importNodes[0], node);
3129
- path9.unshiftContainer("body", importNodes);
3129
+ path8.unshiftContainer("body", importNodes);
3130
3130
  }
3131
3131
  }
3132
3132
  };
@@ -3227,8 +3227,8 @@ function resolveSfcCssImport(ctx) {
3227
3227
  import * as t25 from "@babel/types";
3228
3228
  function resolveDefineAsyncComponent(ctx) {
3229
3229
  return {
3230
- CallExpression(path9) {
3231
- const { node } = path9;
3230
+ CallExpression(path8) {
3231
+ const { node } = path8;
3232
3232
  if (!isCalleeNamed(node, VUE_API_MAP.defineAsyncComponent)) {
3233
3233
  return;
3234
3234
  }
@@ -3276,15 +3276,15 @@ function createUseImperativeHandle(refId, init) {
3276
3276
  function resolveDefineExpose(ctx) {
3277
3277
  if (ctx.inputType !== "sfc") return {};
3278
3278
  return {
3279
- CallExpression(path9) {
3280
- const { node } = path9;
3279
+ CallExpression(path8) {
3280
+ const { node } = path8;
3281
3281
  const { filename, scriptData } = ctx;
3282
3282
  if (!isCalleeNamed(node, MACRO_API_NAMES.expose)) {
3283
3283
  return;
3284
3284
  }
3285
3285
  const [expose] = node.arguments;
3286
3286
  if (!expose) {
3287
- path9.remove();
3287
+ path8.remove();
3288
3288
  return;
3289
3289
  }
3290
3290
  const adapter = ADAPTER_RULES.react[MACRO_API_NAMES.expose];
@@ -3301,7 +3301,7 @@ function resolveDefineExpose(ctx) {
3301
3301
  const { forwardRef } = scriptData;
3302
3302
  const newNode = createUseImperativeHandle(t27.identifier(forwardRef.refField), init);
3303
3303
  forwardRef.enabled = true;
3304
- replaceNode(path9, newNode, node);
3304
+ replaceNode(path8, newNode, node);
3305
3305
  }
3306
3306
  };
3307
3307
  }
@@ -3309,12 +3309,12 @@ function resolveDefineExpose(ctx) {
3309
3309
  // src/core/transform/sfc/script/syntax-processor/preprocess/resolve-define-options.ts
3310
3310
  function resolveDefineOptions(ctx) {
3311
3311
  return {
3312
- CallExpression(path9) {
3313
- const { node } = path9;
3312
+ CallExpression(path8) {
3313
+ const { node } = path8;
3314
3314
  if (!isCalleeNamed(node, MACRO_API_NAMES.options)) {
3315
3315
  return;
3316
3316
  }
3317
- path9.remove();
3317
+ path8.remove();
3318
3318
  }
3319
3319
  };
3320
3320
  }
@@ -3331,8 +3331,8 @@ function resolveEmitCalls(ctx) {
3331
3331
  return `on${capitalize(camelCase(normalized))}`;
3332
3332
  };
3333
3333
  return {
3334
- CallExpression(path9) {
3335
- const { node } = path9;
3334
+ CallExpression(path8) {
3335
+ const { node } = path8;
3336
3336
  const { filename, templateData, scriptData } = ctx;
3337
3337
  if (!t28.isIdentifier(node.callee)) return;
3338
3338
  const { name } = node.callee;
@@ -3343,7 +3343,7 @@ function resolveEmitCalls(ctx) {
3343
3343
  result = meta.source === MACRO_API_NAMES.emits;
3344
3344
  }
3345
3345
  if (!result) {
3346
- const binding = path9.scope.getBinding(name);
3346
+ const binding = path8.scope.getBinding(name);
3347
3347
  if (binding) {
3348
3348
  const parent = binding.path.node;
3349
3349
  if (t28.isVariableDeclarator(parent) && t28.isCallExpression(parent.init) && t28.isIdentifier(parent.init.callee)) {
@@ -3370,7 +3370,7 @@ function resolveEmitCalls(ctx) {
3370
3370
  }
3371
3371
  );
3372
3372
  }
3373
- replaceNode(path9, propCall, node);
3373
+ replaceNode(path8, propCall, node);
3374
3374
  }
3375
3375
  };
3376
3376
  }
@@ -3415,9 +3415,9 @@ function cloneCallableParams(params) {
3415
3415
  // src/core/transform/sfc/script/syntax-processor/preprocess/resolve-props-interface/resolve-emits.ts
3416
3416
  function resolveEmitsTopLevelTypes(ctx) {
3417
3417
  return {
3418
- "TSInterfaceDeclaration|TSTypeAliasDeclaration"(path9) {
3419
- if (!t30.isProgram(path9.parent)) return;
3420
- const { node } = path9;
3418
+ "TSInterfaceDeclaration|TSTypeAliasDeclaration"(path8) {
3419
+ if (!t30.isProgram(path8.parent)) return;
3420
+ const { node } = path8;
3421
3421
  if (t30.isTSInterfaceDeclaration(node)) {
3422
3422
  const typeLiteral = t30.tsTypeLiteral(node.body.body);
3423
3423
  if (!hasEmitsSignatureInType(typeLiteral)) return;
@@ -3482,8 +3482,8 @@ function resolveTopLevelEmitType(tsType) {
3482
3482
  }
3483
3483
  return tsType;
3484
3484
  }
3485
- function resolveDefineEmitsIface(path9, ctx) {
3486
- const { node } = path9;
3485
+ function resolveDefineEmitsIface(path8, ctx) {
3486
+ const { node } = path8;
3487
3487
  const [runtimeArg] = node.arguments;
3488
3488
  const tsParams = node.typeParameters?.params;
3489
3489
  if (tsParams?.length) {
@@ -3783,8 +3783,8 @@ function resolveTupleElementParam(element, index) {
3783
3783
 
3784
3784
  // src/core/transform/sfc/script/syntax-processor/preprocess/resolve-props-interface/resolve-props.ts
3785
3785
  import * as t31 from "@babel/types";
3786
- function resolveDefinePropsIface(path9, ctx) {
3787
- const { node } = path9;
3786
+ function resolveDefinePropsIface(path8, ctx) {
3787
+ const { node } = path8;
3788
3788
  const [runtimeArg] = node.arguments;
3789
3789
  const tsParams = node.typeParameters?.params;
3790
3790
  if (tsParams?.length) {
@@ -3972,9 +3972,9 @@ function recordReactNode(ctx) {
3972
3972
  }
3973
3973
  recordImport(ctx, PACKAGE_NAME.react, REACT_API_MAP.ReactNode);
3974
3974
  }
3975
- function collectLocalTypeDeclarations(path9) {
3975
+ function collectLocalTypeDeclarations(path8) {
3976
3976
  const declarations = /* @__PURE__ */ new Map();
3977
- const programPath = path9.findParent(
3977
+ const programPath = path8.findParent(
3978
3978
  (parentPath) => parentPath.isProgram()
3979
3979
  );
3980
3980
  if (!programPath) {
@@ -4244,14 +4244,14 @@ function resolveSlotPropFromMember(member) {
4244
4244
  }
4245
4245
 
4246
4246
  // src/core/transform/sfc/script/syntax-processor/preprocess/resolve-props-interface/resolve-slot/define-slots.ts
4247
- function resolveDefineSlotsIface(path9, ctx) {
4248
- const { node } = path9;
4247
+ function resolveDefineSlotsIface(path8, ctx) {
4248
+ const { node } = path8;
4249
4249
  const tsParams = node.typeParameters?.params;
4250
4250
  if (!tsParams?.length) return;
4251
4251
  const {
4252
4252
  propsTSIface: { slotTypes }
4253
4253
  } = ctx.scriptData;
4254
- const localTypeDeclarations = collectLocalTypeDeclarations(path9);
4254
+ const localTypeDeclarations = collectLocalTypeDeclarations(path8);
4255
4255
  let shouldRecordReactNode = false;
4256
4256
  for (const tsType of tsParams) {
4257
4257
  const { type: resolved, shouldRecordReactNode: needsReactNode } = resolveSlotType(tsType, {
@@ -4295,8 +4295,8 @@ function resolveTemplateSlotIface(ctx) {
4295
4295
  function resolvePropsIface(ctx) {
4296
4296
  const isTS = ctx.scriptData.lang.startsWith("ts");
4297
4297
  return {
4298
- CallExpression(path9) {
4299
- const { node, parentPath } = path9;
4298
+ CallExpression(path8) {
4299
+ const { node, parentPath } = path8;
4300
4300
  const name = node.callee.name;
4301
4301
  if (!isCalleeNamed(node, MACRO_API_NAMES.props) && !isCalleeNamed(node, MACRO_API_NAMES.emits) && !isCalleeNamed(node, MACRO_API_NAMES.slots)) {
4302
4302
  return;
@@ -4305,7 +4305,7 @@ function resolvePropsIface(ctx) {
4305
4305
  if (parentPath.isVariableDeclaration() || parentPath.isVariableDeclarator()) {
4306
4306
  parentPath.remove();
4307
4307
  } else {
4308
- path9.remove();
4308
+ path8.remove();
4309
4309
  }
4310
4310
  };
4311
4311
  if (ctx.inputType !== "sfc") {
@@ -4319,11 +4319,11 @@ function resolvePropsIface(ctx) {
4319
4319
  propsTSIface.hasPropsInJsEnv = true;
4320
4320
  } else {
4321
4321
  if (name === MACRO_API_NAMES.props) {
4322
- resolveDefinePropsIface(path9, ctx);
4322
+ resolveDefinePropsIface(path8, ctx);
4323
4323
  } else if (name === MACRO_API_NAMES.emits) {
4324
- resolveDefineEmitsIface(path9, ctx);
4324
+ resolveDefineEmitsIface(path8, ctx);
4325
4325
  } else if (name === MACRO_API_NAMES.slots) {
4326
- resolveDefineSlotsIface(path9, ctx);
4326
+ resolveDefineSlotsIface(path8, ctx);
4327
4327
  }
4328
4328
  }
4329
4329
  removePath();
@@ -4352,10 +4352,10 @@ function resolveCompIProps(ctx, ast) {
4352
4352
  import * as t37 from "@babel/types";
4353
4353
  function resolveUseAttrs(ctx) {
4354
4354
  return {
4355
- VariableDeclarator(path9) {
4356
- const { init, id } = path9.node;
4355
+ VariableDeclarator(path8) {
4356
+ const { init, id } = path8.node;
4357
4357
  if (!init) return;
4358
- const initPath = path9.get("init");
4358
+ const initPath = path8.get("init");
4359
4359
  const propsIdentifier = t37.identifier(ctx.propField);
4360
4360
  if (t37.isTSAsExpression(init) && isUseAttrsCall(init.expression)) {
4361
4361
  const typeAssertion = createPropsTypeAssertion(propsIdentifier, init.typeAnnotation);
@@ -4486,19 +4486,19 @@ function getDependencyKey(exp) {
4486
4486
 
4487
4487
  // src/core/transform/sfc/script/shared/dependency-analyzer/dep-normalizer.ts
4488
4488
  import * as t40 from "@babel/types";
4489
- function normalizeDependencyExpr(path9, rootName, ctx) {
4490
- if (t40.isIdentifier(path9.node)) {
4491
- return t40.identifier(path9.node.name);
4489
+ function normalizeDependencyExpr(path8, rootName, ctx) {
4490
+ if (t40.isIdentifier(path8.node)) {
4491
+ return t40.identifier(path8.node.name);
4492
4492
  }
4493
- if (t40.isMemberExpression(path9.node) || t40.isOptionalMemberExpression(path9.node)) {
4493
+ if (t40.isMemberExpression(path8.node) || t40.isOptionalMemberExpression(path8.node)) {
4494
4494
  if (rootName === ctx.propField) {
4495
- const safePropsExp = ensureOptionalForMemberChain(path9.node);
4495
+ const safePropsExp = ensureOptionalForMemberChain(path8.node);
4496
4496
  if (isReactValidDependencyExpr(safePropsExp)) {
4497
4497
  return t40.cloneNode(safePropsExp, true);
4498
4498
  }
4499
4499
  return t40.identifier(rootName);
4500
4500
  }
4501
- const normalizedExp = normalizeMemberForCallSite(path9, path9.node);
4501
+ const normalizedExp = normalizeMemberForCallSite(path8, path8.node);
4502
4502
  const safeExp = t40.isMemberExpression(normalizedExp) || t40.isOptionalMemberExpression(normalizedExp) ? ensureOptionalForMemberChain(normalizedExp) : normalizedExp;
4503
4503
  if (isReactValidDependencyExpr(safeExp)) {
4504
4504
  return t40.cloneNode(safeExp, true);
@@ -4522,8 +4522,8 @@ function normalizeSourcedDependency(exp) {
4522
4522
  }
4523
4523
  return null;
4524
4524
  }
4525
- function normalizeMemberForCallSite(path9, node) {
4526
- const parent = path9.parentPath;
4525
+ function normalizeMemberForCallSite(path8, node) {
4526
+ const parent = path8.parentPath;
4527
4527
  const isDirectCallee = !!parent && (parent.isCallExpression() && parent.node.callee === node || parent.isOptionalCallExpression() && parent.node.callee === node);
4528
4528
  if (!isDirectCallee) {
4529
4529
  return node;
@@ -4550,11 +4550,11 @@ function hasTrailingMemberAccess(node) {
4550
4550
 
4551
4551
  // src/core/transform/sfc/script/shared/dependency-analyzer/shared-utils.ts
4552
4552
  var TRACE_MAX_DEPTH = 20;
4553
- function isNestedMemberObject(path9) {
4554
- const parent = path9.parentPath;
4553
+ function isNestedMemberObject(path8) {
4554
+ const parent = path8.parentPath;
4555
4555
  if (!parent) return false;
4556
4556
  if (parent.isMemberExpression() || parent.isOptionalMemberExpression()) {
4557
- return parent.node.object === path9.node;
4557
+ return parent.node.object === path8.node;
4558
4558
  }
4559
4559
  return false;
4560
4560
  }
@@ -4657,11 +4657,11 @@ function analyzeDeps(node, ctx, parentPath) {
4657
4657
  analyzeTarget,
4658
4658
  {
4659
4659
  "MemberExpression|OptionalMemberExpression"(memberPath) {
4660
- const path9 = memberPath;
4661
- if (isNestedMemberObject(path9)) return;
4662
- const rootId = findRootIdentifier(path9.node);
4660
+ const path8 = memberPath;
4661
+ if (isNestedMemberObject(path8)) return;
4662
+ const rootId = findRootIdentifier(path8.node);
4663
4663
  if (!rootId) return;
4664
- tryAddDependency(path9, rootId.name, path9.scope);
4664
+ tryAddDependency(path8, rootId.name, path8.scope);
4665
4665
  processedIdentifiers.add(rootId);
4666
4666
  },
4667
4667
  Identifier(idPath) {
@@ -4707,18 +4707,18 @@ function analyzeDeps(node, ctx, parentPath) {
4707
4707
  // src/core/transform/sfc/script/syntax-processor/process/resolve-analysis-only-adapter.ts
4708
4708
  function resolveAnalysisOnlyAdapter(ctx) {
4709
4709
  return {
4710
- "CallExpression|Identifier"(path9) {
4711
- const node = path9.node;
4710
+ "CallExpression|Identifier"(path8) {
4711
+ const node = path8.node;
4712
4712
  const apiName = getApiName(node);
4713
4713
  const adapter = ADAPTER_RULES.runtime[apiName];
4714
4714
  if (!adapter || adapter.type !== "analyzed-deps") {
4715
4715
  return;
4716
4716
  }
4717
- if (!isVueApiReference(path9, apiName)) {
4717
+ if (!isVueApiReference(path8, apiName)) {
4718
4718
  return;
4719
4719
  }
4720
4720
  if (t43.isCallExpression(node)) {
4721
- resolveCallNode(path9, adapter, ctx);
4721
+ resolveCallNode(path8, adapter, ctx);
4722
4722
  } else {
4723
4723
  replaceIdName(node, adapter.target);
4724
4724
  }
@@ -4736,35 +4736,35 @@ function getApiName(node) {
4736
4736
  }
4737
4737
  return apiName;
4738
4738
  }
4739
- function resolveCallNode(path9, adapter, ctx) {
4740
- const { node } = path9;
4739
+ function resolveCallNode(path8, adapter, ctx) {
4740
+ const { node } = path8;
4741
4741
  const { arguments: args } = node;
4742
4742
  if (!args.length) return;
4743
4743
  const fn = args[0];
4744
4744
  if (!t43.isArrowFunctionExpression(fn) && !t43.isFunctionExpression(fn)) {
4745
4745
  return;
4746
4746
  }
4747
- const fnPath = path9.get("arguments")[0];
4747
+ const fnPath = path8.get("arguments")[0];
4748
4748
  const deps = analyzeDeps(fn, ctx, fnPath);
4749
4749
  args.push(deps);
4750
4750
  replaceCallName(node, adapter.target);
4751
4751
  recordImport(ctx, adapter.package, adapter.target);
4752
4752
  }
4753
- function isVueApiReference(path9, apiName) {
4754
- if (path9.isIdentifier()) {
4755
- if (path9.parentPath.isCallExpression() && path9.parentPath.node.callee === path9.node) {
4753
+ function isVueApiReference(path8, apiName) {
4754
+ if (path8.isIdentifier()) {
4755
+ if (path8.parentPath.isCallExpression() && path8.parentPath.node.callee === path8.node) {
4756
4756
  return false;
4757
4757
  }
4758
- if (!path9.isReferencedIdentifier()) {
4758
+ if (!path8.isReferencedIdentifier()) {
4759
4759
  return false;
4760
4760
  }
4761
4761
  }
4762
- if (path9.isCallExpression()) {
4763
- const callee = path9.get("callee");
4762
+ if (path8.isCallExpression()) {
4763
+ const callee = path8.get("callee");
4764
4764
  if (!callee.isIdentifier()) return false;
4765
4765
  return isVueImportBinding(callee.scope.getBinding(apiName));
4766
4766
  }
4767
- return isVueImportBinding(path9.scope.getBinding(apiName));
4767
+ return isVueImportBinding(path8.scope.getBinding(apiName));
4768
4768
  }
4769
4769
  function isVueImportBinding(binding) {
4770
4770
  if (!binding) return false;
@@ -4789,24 +4789,24 @@ function isVueImportBinding(binding) {
4789
4789
  // src/core/transform/sfc/script/syntax-processor/process/resolve-arrow-deps.ts
4790
4790
  function resolveArrowFnDeps(ctx, ast) {
4791
4791
  return {
4792
- ArrowFunctionExpression(path9) {
4793
- const { node, parentPath } = path9;
4794
- if (isSkip(path9) || !atComponentOrHookRoot(parentPath, ast.program)) {
4792
+ ArrowFunctionExpression(path8) {
4793
+ const { node, parentPath } = path8;
4794
+ if (isSkip(path8) || !atComponentOrHookRoot(parentPath, ast.program)) {
4795
4795
  return;
4796
4796
  }
4797
- const deps = analyzeDeps(node, ctx, path9);
4797
+ const deps = analyzeDeps(node, ctx, path8);
4798
4798
  if (!deps.elements.length) return;
4799
4799
  const newNode = createUseCallback(node, deps);
4800
- const declaratorPath = getVariableDeclaratorPath(path9);
4800
+ const declaratorPath = getVariableDeclaratorPath(path8);
4801
4801
  recordImport(ctx, PACKAGE_NAME.react, REACT_API_MAP.useCallback);
4802
4802
  setScriptNodeMeta(declaratorPath?.node, { is_reactive: true, reactive_type: "indirect" });
4803
- replaceNode(path9, newNode, node);
4803
+ replaceNode(path8, newNode, node);
4804
4804
  }
4805
4805
  };
4806
4806
  }
4807
- function isSkip(path9) {
4808
- const { parentPath } = path9;
4809
- const isVariableDecl = () => getVariableDeclaratorPath(path9) !== null;
4807
+ function isSkip(path8) {
4808
+ const { parentPath } = path8;
4809
+ const isVariableDecl = () => getVariableDeclaratorPath(path8) !== null;
4810
4810
  const isReturnFunc = () => !isVariableDecl() && parentPath.isReturnStatement();
4811
4811
  const isCallback = () => {
4812
4812
  if (!parentPath) {
@@ -4815,12 +4815,12 @@ function isSkip(path9) {
4815
4815
  if (parentPath.isCallExpression()) {
4816
4816
  const callExpressionPath = parentPath;
4817
4817
  const args = callExpressionPath.node.arguments;
4818
- return args.some((arg) => arg === path9.node);
4818
+ return args.some((arg) => arg === path8.node);
4819
4819
  }
4820
4820
  if (parentPath.isArrayExpression()) {
4821
4821
  const arrayExpressionPath = parentPath;
4822
4822
  const elements = arrayExpressionPath.node.elements;
4823
- return elements.some((element) => element === path9.node);
4823
+ return elements.some((element) => element === path8.node);
4824
4824
  }
4825
4825
  return false;
4826
4826
  };
@@ -4844,13 +4844,13 @@ function isSkip(path9) {
4844
4844
  import * as t44 from "@babel/types";
4845
4845
  function resolveElementRef(ctx) {
4846
4846
  return {
4847
- CallExpression(path9) {
4847
+ CallExpression(path8) {
4848
4848
  const {
4849
4849
  inputType,
4850
4850
  templateData: { refBindings }
4851
4851
  } = ctx;
4852
4852
  if (inputType !== "sfc") return;
4853
- const { node } = path9;
4853
+ const { node } = path8;
4854
4854
  const isUseTemplateRef = isCalleeNamed(node, VUE_API_MAP.useTemplateRef);
4855
4855
  const isCompRefBindings = Object.keys(refBindings.componentRefs).length > 0 && isCalleeNamed(node, VUE_API_MAP.ref);
4856
4856
  const shouldProcess = isUseTemplateRef || isCompRefBindings;
@@ -4858,7 +4858,7 @@ function resolveElementRef(ctx) {
4858
4858
  return;
4859
4859
  }
4860
4860
  if (isCompRefBindings) {
4861
- const varDeclaratorPath = getVariableDeclaratorPath(path9)?.node;
4861
+ const varDeclaratorPath = getVariableDeclaratorPath(path8)?.node;
4862
4862
  if (!t44.isIdentifier(varDeclaratorPath?.id)) {
4863
4863
  return;
4864
4864
  }
@@ -4867,22 +4867,22 @@ function resolveElementRef(ctx) {
4867
4867
  if (!compRef) return;
4868
4868
  }
4869
4869
  node.arguments[0] = t44.identifier("null");
4870
- resolveTypeParameters(ctx, path9);
4870
+ resolveTypeParameters(ctx, path8);
4871
4871
  replaceCallName(node, REACT_API_MAP.useRef);
4872
4872
  recordImport(ctx, PACKAGE_NAME.react, REACT_API_MAP.useRef);
4873
4873
  },
4874
- MemberExpression(path9) {
4875
- resolveRefValueToCurrent(path9);
4874
+ MemberExpression(path8) {
4875
+ resolveRefValueToCurrent(path8);
4876
4876
  }
4877
4877
  };
4878
4878
  }
4879
- function resolveTypeParameters(ctx, path9) {
4879
+ function resolveTypeParameters(ctx, path8) {
4880
4880
  const {
4881
4881
  templateData: { refBindings },
4882
4882
  scriptData
4883
4883
  } = ctx;
4884
- const { node } = path9;
4885
- const varDeclaratorNode = getVariableDeclaratorPath(path9)?.node;
4884
+ const { node } = path8;
4885
+ const varDeclaratorNode = getVariableDeclaratorPath(path8)?.node;
4886
4886
  if (!scriptData.lang.startsWith("ts") || !varDeclaratorNode) {
4887
4887
  return;
4888
4888
  }
@@ -4894,12 +4894,12 @@ function resolveTypeParameters(ctx, path9) {
4894
4894
  node.typeParameters = t44.tsTypeParameterInstantiation([t44.tsTypeReference(t44.identifier(type))]);
4895
4895
  }
4896
4896
  }
4897
- function resolveRefValueToCurrent(path9) {
4898
- const { node } = path9;
4897
+ function resolveRefValueToCurrent(path8) {
4898
+ const { node } = path8;
4899
4899
  if (node.computed || !t44.isIdentifier(node.property) || node.property.name !== "value") {
4900
4900
  return;
4901
4901
  }
4902
- const rootPath = findRootVariablePath(path9);
4902
+ const rootPath = findRootVariablePath(path8);
4903
4903
  if (!rootPath?.node || !t44.isCallExpression(rootPath.node.init) || !isCalleeNamed(rootPath.node.init, REACT_API_MAP.useRef)) {
4904
4904
  return;
4905
4905
  }
@@ -4915,15 +4915,15 @@ import * as t45 from "@babel/types";
4915
4915
  function resolveExprMemo(ctx, ast) {
4916
4916
  const isScriptFile = ctx.inputType !== "sfc";
4917
4917
  return {
4918
- VariableDeclarator(path9) {
4919
- const { node } = path9;
4918
+ VariableDeclarator(path8) {
4919
+ const { node } = path8;
4920
4920
  const { init } = node;
4921
4921
  const shouldMemo = () => {
4922
4922
  if (!init) return false;
4923
- if (!atComponentOrHookRoot(path9, ast.program, isScriptFile)) {
4923
+ if (!atComponentOrHookRoot(path8, ast.program, isScriptFile)) {
4924
4924
  return false;
4925
4925
  }
4926
- if (!t45.isVariableDeclaration(path9.parent) || path9.parent.kind !== "const") {
4926
+ if (!t45.isVariableDeclaration(path8.parent) || path8.parent.kind !== "const") {
4927
4927
  return false;
4928
4928
  }
4929
4929
  if (t45.isFunction(init)) return false;
@@ -4933,7 +4933,7 @@ function resolveExprMemo(ctx, ast) {
4933
4933
  return true;
4934
4934
  };
4935
4935
  if (!shouldMemo()) return;
4936
- const initPath = path9.get("init");
4936
+ const initPath = path8.get("init");
4937
4937
  if (!initPath.isExpression()) return;
4938
4938
  const deps = analyzeDeps(initPath.node, ctx, initPath);
4939
4939
  if (!deps.elements.length) return;
@@ -4950,8 +4950,8 @@ import * as t46 from "@babel/types";
4950
4950
  function resolveLintRules(ctx, ast) {
4951
4951
  const inScriptFile = ctx.inputType !== "sfc";
4952
4952
  return {
4953
- CallExpression(path9) {
4954
- const { node, parentPath } = path9;
4953
+ CallExpression(path8) {
4954
+ const { node, parentPath } = path8;
4955
4955
  if (!t46.isIdentifier(node.callee)) return;
4956
4956
  const { name: callName } = node.callee;
4957
4957
  const addLog = (t52) => {
@@ -4970,7 +4970,7 @@ function resolveLintRules(ctx, ast) {
4970
4970
  );
4971
4971
  return;
4972
4972
  }
4973
- if (!atComponentOrHookRoot(path9, ast.program)) {
4973
+ if (!atComponentOrHookRoot(path8, ast.program)) {
4974
4974
  addLog(
4975
4975
  `The ${macro} must be defined at the top level of the component, not inside blocks or functions.`
4976
4976
  );
@@ -4986,7 +4986,7 @@ function resolveLintRules(ctx, ast) {
4986
4986
  };
4987
4987
  const lintHooks = () => {
4988
4988
  if (!callName.startsWith("use")) return;
4989
- if (!atComponentOrHookRoot(path9, ast.program, inScriptFile)) {
4989
+ if (!atComponentOrHookRoot(path8, ast.program, inScriptFile)) {
4990
4990
  addLog(
4991
4991
  `The ${callName} hook must be called at the top level, not inside loops, conditions, or nested functions.`
4992
4992
  );
@@ -5004,8 +5004,8 @@ import * as t47 from "@babel/types";
5004
5004
  function resolveProvide(ctx) {
5005
5005
  if (ctx.inputType === "style") return {};
5006
5006
  return {
5007
- CallExpression(path9) {
5008
- const { node } = path9;
5007
+ CallExpression(path8) {
5008
+ const { node } = path8;
5009
5009
  const providerTarget = ADAPTER_RULES.runtime[VUE_API_MAP.provide]?.target;
5010
5010
  const isProvideCall = isCalleeNamed(node, VUE_API_MAP.provide) || providerTarget && isCalleeNamed(node, providerTarget);
5011
5011
  if (!isProvideCall) return;
@@ -5015,7 +5015,7 @@ function resolveProvide(ctx) {
5015
5015
  const adapter = ADAPTER_RULES.runtime[VUE_API_MAP.provide];
5016
5016
  assignProviderValue(target, key, value);
5017
5017
  recordImport(ctx, adapter.package, adapter.target);
5018
- path9.parentPath.remove();
5018
+ path8.parentPath.remove();
5019
5019
  }
5020
5020
  };
5021
5021
  }
@@ -5057,8 +5057,8 @@ function assignProviderValue(target, key, value) {
5057
5057
  import * as t48 from "@babel/types";
5058
5058
  function resolveRenameAdapter(ctx) {
5059
5059
  return {
5060
- "CallExpression|Identifier"(path9) {
5061
- const node = path9.node;
5060
+ "CallExpression|Identifier"(path8) {
5061
+ const node = path8.node;
5062
5062
  const isCallNode = t48.isCallExpression(node);
5063
5063
  let apiName = "";
5064
5064
  if (t48.isIdentifier(node)) {
@@ -5075,12 +5075,12 @@ function resolveRenameAdapter(ctx) {
5075
5075
  if (!adapter || adapter.type !== "rename") {
5076
5076
  return;
5077
5077
  }
5078
- if (!isVueApiReference2(path9, apiName)) {
5078
+ if (!isVueApiReference2(path8, apiName)) {
5079
5079
  return;
5080
5080
  }
5081
5081
  if (adapter.isTrackable) {
5082
5082
  const reactiveType = getReactiveType(apiName);
5083
- const declaratorPath = getVariableDeclaratorPath(path9);
5083
+ const declaratorPath = getVariableDeclaratorPath(path8);
5084
5084
  setScriptNodeMeta(declaratorPath?.node, {
5085
5085
  is_reactive: true,
5086
5086
  reactive_type: reactiveType
@@ -5098,25 +5098,25 @@ function resolveRenameAdapter(ctx) {
5098
5098
  }
5099
5099
  };
5100
5100
  }
5101
- function isVueApiReference2(path9, apiName) {
5101
+ function isVueApiReference2(path8, apiName) {
5102
5102
  const whitelist = [VUE_API_MAP.defineAsyncComponent];
5103
5103
  if (whitelist.includes(apiName)) {
5104
5104
  return true;
5105
5105
  }
5106
- if (path9.isIdentifier()) {
5107
- if (path9.parentPath.isCallExpression() && path9.parentPath.node.callee === path9.node) {
5106
+ if (path8.isIdentifier()) {
5107
+ if (path8.parentPath.isCallExpression() && path8.parentPath.node.callee === path8.node) {
5108
5108
  return false;
5109
5109
  }
5110
- if (!path9.isReferencedIdentifier()) {
5110
+ if (!path8.isReferencedIdentifier()) {
5111
5111
  return false;
5112
5112
  }
5113
5113
  }
5114
- if (path9.isCallExpression()) {
5115
- const callee = path9.get("callee");
5114
+ if (path8.isCallExpression()) {
5115
+ const callee = path8.get("callee");
5116
5116
  if (!callee.isIdentifier()) return false;
5117
5117
  return isVueImportBinding2(callee.scope.getBinding(apiName));
5118
5118
  }
5119
- return isVueImportBinding2(path9.scope.getBinding(apiName));
5119
+ return isVueImportBinding2(path8.scope.getBinding(apiName));
5120
5120
  }
5121
5121
  function isVueImportBinding2(binding) {
5122
5122
  if (!binding) return false;
@@ -6612,20 +6612,11 @@ function transform(ast, ctx, options) {
6612
6612
  }
6613
6613
 
6614
6614
  // package.json
6615
- var version = "1.7.0";
6615
+ var version = "1.8.1";
6616
6616
  var bin = {
6617
- vureact: "./bin/vureact.js"
6617
+ vureact: "bin/vureact.js"
6618
6618
  };
6619
6619
 
6620
- // src/compiler/shared/types/cache-types.ts
6621
- var CacheKey = /* @__PURE__ */ ((CacheKey2) => {
6622
- CacheKey2["SFC"] = "sfc";
6623
- CacheKey2["SCRIPT"] = "script";
6624
- CacheKey2["STYLE"] = "style";
6625
- CacheKey2["ASSET"] = "copied";
6626
- return CacheKey2;
6627
- })(CacheKey || {});
6628
-
6629
6620
  // src/plugins/prettier.ts
6630
6621
  async function formatWithPrettier(code, lang, opts) {
6631
6622
  try {
@@ -6826,13 +6817,6 @@ var Helper = class {
6826
6817
  const { input = "src" } = this.compilerOpts;
6827
6818
  return path3.resolve(this.getProjectRoot(), input);
6828
6819
  }
6829
- /**
6830
- * 检查 input 路径是否是单个文件
6831
- */
6832
- isSingleFile() {
6833
- const inputPath = this.getInputPath();
6834
- return fs2.existsSync(inputPath) && fs2.statSync(inputPath).isFile();
6835
- }
6836
6820
  /**
6837
6821
  * 获取输出文件的路径。如:'[root]/.vureact/dist/'
6838
6822
  * @param addInput 会输出如:'[root]/.vureact/dist/[input]/'
@@ -6891,6 +6875,13 @@ var Helper = class {
6891
6875
  getOutputPkgPath() {
6892
6876
  return path3.join(this.getOuputPath(), "package.json");
6893
6877
  }
6878
+ /**
6879
+ * 获取缓存文件路径
6880
+ */
6881
+ getCachePath() {
6882
+ const filename = "_metadata";
6883
+ return path3.resolve(this.getProjectRoot(), this.workspaceDir, "cache", `${filename}.json`);
6884
+ }
6894
6885
  /**
6895
6886
  * 返回文件相对工作区的路径
6896
6887
  */
@@ -6988,95 +6979,15 @@ var Helper = class {
6988
6979
  }
6989
6980
  async rmFile(filePath) {
6990
6981
  try {
6991
- await fs2.promises.rm(filePath, { recursive: true, force: true });
6992
- } catch {
6993
- }
6994
- }
6995
- async loadCache(key) {
6996
- const cacheFile = this.getCachePath();
6997
- const defaultData = this.createCacheData(key);
6998
- if (!fs2.existsSync(cacheFile)) {
6999
- return defaultData;
7000
- }
7001
- try {
7002
- const content = await fs2.promises.readFile(cacheFile, "utf-8");
7003
- const data = JSON.parse(content);
7004
- return {
7005
- key,
7006
- target: data[key] || [],
7007
- source: data
7008
- };
7009
- } catch {
7010
- return defaultData;
7011
- }
7012
- }
7013
- createCacheData(key) {
7014
- return {
7015
- key,
7016
- target: [],
7017
- source: {
7018
- ["sfc" /* SFC */]: [],
7019
- ["script" /* SCRIPT */]: [],
7020
- ["style" /* STYLE */]: [],
7021
- ["copied" /* ASSET */]: []
6982
+ if (fs2.existsSync(filePath)) {
6983
+ await fs2.promises.rm(filePath, { recursive: true, force: true });
7022
6984
  }
7023
- };
7024
- }
7025
- /**
7026
- * 获取缓存文件路径
7027
- */
7028
- getCachePath() {
7029
- const filename = "_metadata";
7030
- return path3.resolve(this.getProjectRoot(), this.workspaceDir, "cache", `${filename}.json`);
7031
- }
7032
- async saveCache(data) {
7033
- if (!this.getIsCache() || !data) {
7034
- return;
6985
+ } catch {
7035
6986
  }
7036
- const getDefaultValue = () => ({
7037
- ["sfc" /* SFC */]: [],
7038
- ["script" /* SCRIPT */]: [],
7039
- ["style" /* STYLE */]: [],
7040
- ["copied" /* ASSET */]: []
7041
- });
7042
- const cachePath = this.getCachePath();
7043
- await fileLock.updateFile(cachePath, (currentData) => {
7044
- const { key, target } = data;
7045
- const mergedData = currentData || getDefaultValue();
7046
- mergedData[key] = target;
7047
- return mergedData;
7048
- });
7049
6987
  }
7050
6988
  genHash(content) {
7051
6989
  return genHashByXXH(content);
7052
6990
  }
7053
- /**
7054
- * 扫描指定目录下的所有文件
7055
- * @param dir 目标目录
7056
- * @param filter 筛选指定的文件后缀名
7057
- */
7058
- scanFiles(dir, filter) {
7059
- const results = [];
7060
- if (!fs2.existsSync(dir)) {
7061
- return results;
7062
- }
7063
- const stats = fs2.statSync(dir);
7064
- if (stats.isFile()) {
7065
- return filter(dir) ? [dir] : [];
7066
- }
7067
- const list = fs2.readdirSync(dir);
7068
- for (const file of list) {
7069
- const fullPath = path3.resolve(dir, file);
7070
- if (this.shouldSkipPath(fullPath)) continue;
7071
- const stat = fs2.statSync(fullPath);
7072
- if (stat.isDirectory() && this.compilerOpts.recursive !== false) {
7073
- results.push(...this.scanFiles(fullPath, filter));
7074
- } else if (filter(fullPath)) {
7075
- results.push(fullPath);
7076
- }
7077
- }
7078
- return results;
7079
- }
7080
6991
  getAbsPath(filePath) {
7081
6992
  return path3.isAbsolute(filePath) ? filePath : path3.resolve(this.getProjectRoot(), filePath);
7082
6993
  }
@@ -7088,9 +6999,9 @@ var Helper = class {
7088
6999
  };
7089
7000
  }
7090
7001
  async removeOutputFile(filePath, resolveOutputPath) {
7091
- const path9 = resolveOutputPath ? this.resolveOutputPath(filePath) : filePath;
7092
- if (!fs2.existsSync(path9)) return;
7093
- await fs2.promises.unlink(path9);
7002
+ const path8 = resolveOutputPath ? this.resolveOutputPath(filePath) : filePath;
7003
+ if (!fs2.existsSync(path8)) return;
7004
+ await fs2.promises.unlink(path8);
7094
7005
  }
7095
7006
  updateCache(targetFile, newData, cache) {
7096
7007
  const index = cache.target.findIndex((c) => c.file === targetFile);
@@ -7143,18 +7054,18 @@ var Helper = class {
7143
7054
  /**
7144
7055
  * 读取 package.json 文件内容,并处理成对象返回
7145
7056
  */
7146
- async resolvePackageFile(path9) {
7147
- if (!fs2.existsSync(path9)) {
7057
+ async resolvePackageFile(path8) {
7058
+ if (!fs2.existsSync(path8)) {
7148
7059
  return {};
7149
7060
  }
7150
7061
  try {
7151
- const content = await fs2.promises.readFile(path9, "utf-8");
7062
+ const content = await fs2.promises.readFile(path8, "utf-8");
7152
7063
  if (!content.trim()) {
7153
7064
  return {};
7154
7065
  }
7155
7066
  return JSON.parse(content);
7156
7067
  } catch (error) {
7157
- console.error(kleur4.red("\u274C"), `Failed to parse JSON file ${path9}:
7068
+ console.error(kleur4.red("\u274C"), `Failed to parse JSON file ${path8}:
7158
7069
  `, error);
7159
7070
  return {};
7160
7071
  }
@@ -7414,6 +7325,15 @@ var BaseCompiler = class extends Helper {
7414
7325
  }
7415
7326
  };
7416
7327
 
7328
+ // src/compiler/shared/types/cache-types.ts
7329
+ var CacheKey = /* @__PURE__ */ ((CacheKey2) => {
7330
+ CacheKey2["SFC"] = "sfc";
7331
+ CacheKey2["SCRIPT"] = "script";
7332
+ CacheKey2["STYLE"] = "style";
7333
+ CacheKey2["ASSET"] = "copied";
7334
+ return CacheKey2;
7335
+ })(CacheKey || {});
7336
+
7417
7337
  // src/utils/calc-elapsed-time.ts
7418
7338
  function calcElapsedTime(start) {
7419
7339
  const end = performance.now();
@@ -7436,9 +7356,10 @@ import ora2 from "ora";
7436
7356
  import fs3 from "fs";
7437
7357
  import path5 from "path";
7438
7358
  var AssetManager = class {
7439
- constructor(fileCompiler, cleanupManager) {
7359
+ constructor(fileCompiler, cleanupManager, cacheManager) {
7440
7360
  this.fileCompiler = fileCompiler;
7441
7361
  this.cleanupManager = cleanupManager;
7362
+ this.cacheManager = cacheManager;
7442
7363
  }
7443
7364
  // 需要经过管线编译处理的文件类型
7444
7365
  pipelineFiles = [".js", ".ts", ".less", ".scss", ".sass"];
@@ -7446,70 +7367,40 @@ var AssetManager = class {
7446
7367
  /**
7447
7368
  * 运行资源文件处理管线
7448
7369
  */
7449
- async runAssetPipeline() {
7450
- const { options } = this.fileCompiler;
7451
- const rootPath = this.fileCompiler.getProjectRoot();
7452
- const inputPath = this.fileCompiler.getInputPath();
7453
- const exclusions = this.fileCompiler.getIgnoreAssets();
7454
- const assetFiles = this.fileCompiler.scanFiles(rootPath, (p) => {
7455
- if (this.fileCompiler.shouldSkipPath(p)) return false;
7456
- const relativeToRoot = normalizePath(this.fileCompiler.relativePath(p));
7457
- const filename = path5.basename(p).toLowerCase();
7458
- const ext = path5.extname(p).toLowerCase();
7459
- if (!options.output?.ignoreAssets) {
7460
- const shouldExclude = Array.from(exclusions).some((pattern) => {
7461
- if (pattern.endsWith(".")) {
7462
- return filename.startsWith(pattern);
7463
- }
7464
- if (pattern.startsWith(".")) {
7465
- return ext === pattern;
7466
- }
7467
- return relativeToRoot === pattern || filename === pattern;
7468
- });
7469
- if (shouldExclude) return false;
7470
- } else if (exclusions.has(relativeToRoot) || exclusions.has(filename)) {
7471
- return false;
7472
- }
7473
- if (ext === ".vue") return false;
7474
- const isInsideSrc = p.startsWith(inputPath + path5.sep);
7475
- if (isInsideSrc && this.pipelineFiles.includes(ext)) {
7476
- return false;
7477
- }
7478
- return true;
7479
- });
7480
- const absFiles = new Set(assetFiles.map((f) => this.fileCompiler.getAbsPath(f)));
7481
- await this.cleanupManager.cleanupOldOutput("copied" /* ASSET */, (u) => !absFiles.has(u.file));
7482
- if (!assetFiles.length) return 0;
7483
- const cache = await this.fileCompiler.loadCache("copied" /* ASSET */);
7484
- const copied = await Promise.all(
7485
- assetFiles.map((file) => {
7486
- return this.processAsset(file, cache);
7487
- })
7370
+ async runAsset(files, cacheMap) {
7371
+ const absPaths = new Set(files.map((f) => this.fileCompiler.getAbsPath(f)));
7372
+ const cache = cacheMap["copied" /* ASSET */];
7373
+ await this.cleanupManager.removeMatchedFromCache(
7374
+ "copied" /* ASSET */,
7375
+ cache,
7376
+ (u) => !absPaths.has(u.file)
7488
7377
  );
7489
- await this.fileCompiler.saveCache(cache);
7378
+ if (!files.length) return 0;
7379
+ const copied = await Promise.all(files.map((file) => this.processAsset(file, cache)));
7490
7380
  return copied.filter(Boolean).length;
7491
7381
  }
7492
7382
  /**
7493
7383
  * Process single asset file, compare with cache and decide whether to copy.
7494
7384
  */
7495
7385
  async processAsset(filePath, existingCache) {
7496
- const absPath = this.fileCompiler.getAbsPath(filePath);
7386
+ const { fileCompiler, cacheManager } = this;
7387
+ const absPath = fileCompiler.getAbsPath(filePath);
7497
7388
  const fileMeta = {
7498
7389
  file: absPath,
7499
- ...await this.fileCompiler.getFileMeta(absPath)
7390
+ ...await fileCompiler.getFileMeta(absPath)
7500
7391
  };
7501
- const cache = (this.fileCompiler.getIsCache() ? existingCache : void 0) || await this.fileCompiler.loadCache("copied" /* ASSET */);
7392
+ const cache = (fileCompiler.getIsCache() ? existingCache : void 0) || await cacheManager.loadCache("copied" /* ASSET */);
7502
7393
  const record = cache.target.find((f) => f.file === absPath);
7503
- if (record && this.fileCompiler.compareFileMeta(record, fileMeta)) {
7394
+ if (record && fileCompiler.compareFileMeta(record, fileMeta)) {
7504
7395
  this.skippedCount++;
7505
7396
  return;
7506
7397
  }
7507
- const outputPath = this.fileCompiler.resolveOutputPath(absPath);
7398
+ const outputPath = fileCompiler.resolveOutputPath(absPath);
7508
7399
  await fs3.promises.mkdir(path5.dirname(outputPath), { recursive: true });
7509
7400
  await fs3.promises.copyFile(absPath, outputPath);
7510
7401
  this.updateCache(absPath, fileMeta, cache);
7511
- if (this.fileCompiler.getIsCache() && !existingCache) {
7512
- await this.fileCompiler.saveCache(cache);
7402
+ if (fileCompiler.getIsCache() && !existingCache) {
7403
+ await cacheManager.saveCache(cache);
7513
7404
  }
7514
7405
  return fileMeta;
7515
7406
  }
@@ -7540,11 +7431,14 @@ var AssetManager = class {
7540
7431
  };
7541
7432
 
7542
7433
  // src/compiler/shared/file-compiler/cache-manager.ts
7434
+ import fs4 from "fs";
7543
7435
  var CacheManager = class {
7544
7436
  constructor(fileCompiler) {
7545
7437
  this.fileCompiler = fileCompiler;
7546
7438
  }
7547
7439
  pendingUpdates = /* @__PURE__ */ new Map();
7440
+ /** 缓存文件仅读取一次,之后复用此副本 */
7441
+ cachedData = null;
7548
7442
  /**
7549
7443
  * 批量更新缓存记录
7550
7444
  */
@@ -7566,94 +7460,200 @@ var CacheManager = class {
7566
7460
  this.pendingUpdates.get(key).push({ unit, meta });
7567
7461
  }
7568
7462
  /**
7569
- * 批量保存缓存
7463
+ * 一次性刷新所有缓存(只写一次文件)
7570
7464
  */
7571
- async flushCache(key) {
7572
- if (!this.fileCompiler.getIsCache() || !this.pendingUpdates.has(key)) {
7465
+ async flushAllCache() {
7466
+ if (!this.fileCompiler.getIsCache()) {
7573
7467
  return;
7574
7468
  }
7469
+ const keys = Object.values(CacheKey);
7470
+ if (!this.cachedData) {
7471
+ await this.loadAllCache();
7472
+ }
7473
+ for (const key of keys) {
7474
+ const updates = this.pendingUpdates.get(key);
7475
+ if (!updates?.length) continue;
7476
+ const entries = [...this.cachedData[key] || []];
7477
+ updates.forEach(({ unit, meta }) => {
7478
+ const idx = entries.findIndex((c) => c.file === unit.file);
7479
+ if (idx > -1) {
7480
+ entries[idx] = meta;
7481
+ } else {
7482
+ entries.push(meta);
7483
+ }
7484
+ });
7485
+ this.cachedData[key] = entries;
7486
+ this.pendingUpdates.set(key, []);
7487
+ }
7488
+ await fileLock.updateFile(this.fileCompiler.getCachePath(), () => this.cachedData);
7489
+ }
7490
+ /**
7491
+ * 一次性加载所有缓存(只读一次文件)
7492
+ */
7493
+ async loadAllCache() {
7494
+ const filePath = this.fileCompiler.getCachePath();
7495
+ const result = {};
7496
+ let raw = null;
7497
+ if (fs4.existsSync(filePath)) {
7498
+ try {
7499
+ const content = await fs4.promises.readFile(filePath, "utf-8");
7500
+ raw = JSON.parse(content);
7501
+ } catch {
7502
+ }
7503
+ }
7504
+ this.cachedData = raw || this.getEmptyList();
7505
+ const keys = Object.values(CacheKey);
7506
+ for (const key of keys) {
7507
+ result[key] = this.buildLoadedCache(key, raw);
7508
+ }
7509
+ return result;
7510
+ }
7511
+ /**
7512
+ * 加载指定类型的缓存(watch 等场景使用)
7513
+ */
7514
+ async loadCache(key) {
7515
+ if (this.cachedData) {
7516
+ return this.buildLoadedCache(key, this.cachedData);
7517
+ }
7518
+ const filePath = this.fileCompiler.getCachePath();
7519
+ if (fs4.existsSync(filePath)) {
7520
+ try {
7521
+ const content = await fs4.promises.readFile(filePath, "utf-8");
7522
+ const data = JSON.parse(content);
7523
+ return this.buildLoadedCache(key, data);
7524
+ } catch {
7525
+ }
7526
+ }
7527
+ return this.buildLoadedCache(key, null);
7528
+ }
7529
+ /**
7530
+ * 刷新指定 key 的缓存(统一由 flushAllCache 写入,此方法仅用于外部兼容调用)
7531
+ */
7532
+ async flushCache(key) {
7533
+ if (!this.fileCompiler.getIsCache()) return;
7534
+ if (!this.pendingUpdates.has(key)) return;
7575
7535
  const updates = this.pendingUpdates.get(key);
7576
- if (updates.length === 0) return;
7577
- const cache = await this.fileCompiler.loadCache(key);
7578
- for (const { unit, meta } of updates) {
7579
- this.updateCache(unit.file, meta, cache);
7536
+ if (!updates.length) return;
7537
+ if (!this.cachedData) {
7538
+ const filePath = this.fileCompiler.getCachePath();
7539
+ if (fs4.existsSync(filePath)) {
7540
+ try {
7541
+ const content = await fs4.promises.readFile(filePath, "utf-8");
7542
+ this.cachedData = JSON.parse(content);
7543
+ } catch {
7544
+ }
7545
+ }
7580
7546
  }
7581
- await this.fileCompiler.saveCache(cache);
7547
+ const entries = [...(this.cachedData || this.getEmptyList())[key] || []];
7548
+ updates.forEach(({ unit, meta }) => {
7549
+ const idx = entries.findIndex((c) => c.file === unit.file);
7550
+ if (idx > -1) {
7551
+ entries[idx] = meta;
7552
+ } else {
7553
+ entries.push(meta);
7554
+ }
7555
+ });
7556
+ (this.cachedData || this.getEmptyList())[key] = entries;
7582
7557
  this.pendingUpdates.set(key, []);
7558
+ await this.saveCache(this.buildLoadedCache(key, this.cachedData));
7559
+ }
7560
+ getEmptyList() {
7561
+ return {
7562
+ ["sfc" /* SFC */]: [],
7563
+ ["script" /* SCRIPT */]: [],
7564
+ ["style" /* STYLE */]: [],
7565
+ ["copied" /* ASSET */]: []
7566
+ };
7583
7567
  }
7584
7568
  /**
7585
- * 更新缓存
7569
+ * 保存缓存数据到文件(watch 等场景使用)
7586
7570
  */
7587
- updateCache(targetFile, newData, cache) {
7588
- const index = cache.target.findIndex((c) => c.file === targetFile);
7589
- if (index > -1) {
7590
- cache.target[index] = newData;
7591
- } else {
7592
- cache.target.push(newData);
7593
- }
7571
+ async saveCache(data) {
7572
+ if (!this.fileCompiler.getIsCache() || !data) return;
7573
+ if (this.cachedData) {
7574
+ this.cachedData[data.key] = data.target;
7575
+ }
7576
+ await fileLock.updateFile(this.fileCompiler.getCachePath(), (currentData) => {
7577
+ const merged = currentData || this.getEmptyList();
7578
+ merged[data.key] = data.target;
7579
+ return merged;
7580
+ });
7581
+ }
7582
+ buildLoadedCache(key, raw) {
7583
+ const emptySource = {
7584
+ ["sfc" /* SFC */]: [],
7585
+ ["script" /* SCRIPT */]: [],
7586
+ ["style" /* STYLE */]: [],
7587
+ ["copied" /* ASSET */]: []
7588
+ };
7589
+ const source = raw || emptySource;
7590
+ return {
7591
+ key,
7592
+ target: source[key] || [],
7593
+ source
7594
+ };
7594
7595
  }
7595
7596
  };
7596
7597
 
7597
7598
  // src/compiler/shared/file-compiler/cleanup-manager.ts
7598
7599
  import path6 from "path";
7599
7600
  var CleanupManager = class {
7600
- constructor(fileCompiler) {
7601
+ constructor(fileCompiler, cacheManager) {
7601
7602
  this.fileCompiler = fileCompiler;
7603
+ this.cacheManager = cacheManager;
7602
7604
  }
7603
7605
  /**
7604
- * Delete the build artifacts and cache corresponding to the specified path.
7606
+ * 删除指定路径对应的构建产物和缓存
7605
7607
  */
7606
7608
  async removeOutputPath(targetPath, type) {
7607
7609
  const absPath = this.fileCompiler.getAbsPath(targetPath);
7608
- await this.cleanupOldOutput(
7609
- type,
7610
- (u) => u.file === absPath || // path.sep 是因为假如删除了 src/components 文件夹,
7611
- // 为了防止误删名为 src/components-old 的文件夹,
7612
- // 所以必须确保路径后跟着一个分隔符,确保精准匹配子目录内容。
7613
- u.file.startsWith(absPath + path6.sep)
7614
- );
7610
+ const cache = await this.cacheManager.loadCache(type);
7611
+ await this.removeMatchedFromCache(type, cache, (m) => {
7612
+ return m.file === absPath || m.file.startsWith(absPath + path6.sep);
7613
+ });
7614
+ await this.cacheManager.saveCache(cache);
7615
7615
  }
7616
7616
  /**
7617
- * Delete the build artifacts or asset files and cache corresponding to the specified path.
7617
+ * 删除匹配的输出文件,并从内存缓存中移除对应条目(不写磁盘)
7618
7618
  */
7619
- async cleanupOldOutput(key, filter) {
7620
- const cache = await this.fileCompiler.loadCache(key);
7619
+ async removeMatchedFromCache(key, cache, filter) {
7621
7620
  if (!cache.target.length) return;
7622
7621
  const toRemove = cache.target.filter(filter);
7623
7622
  if (!toRemove.length) return;
7624
- const removeFn = async (m) => {
7625
- let meta;
7626
- switch (key) {
7627
- case "sfc" /* SFC */: {
7628
- meta = m;
7629
- const { jsx, css } = meta.output;
7630
- await this.fileCompiler.removeOutputFile(jsx.file);
7631
- if (css?.file) {
7632
- await this.fileCompiler.removeOutputFile(css.file);
7633
- }
7634
- break;
7635
- }
7636
- case "script" /* SCRIPT */: {
7637
- meta = m;
7638
- await this.fileCompiler.removeOutputFile(meta.output.script.file);
7639
- break;
7640
- }
7641
- case "style" /* STYLE */: {
7642
- meta = m;
7643
- await this.fileCompiler.removeOutputFile(meta.output.style.file);
7644
- break;
7645
- }
7646
- // 静态资产缓存直接删除对应文件
7647
- default: {
7648
- await this.fileCompiler.removeOutputFile(m.file, true);
7649
- break;
7650
- }
7651
- }
7652
- };
7653
- await Promise.all(toRemove.map(removeFn));
7623
+ await Promise.all(toRemove.map((m) => this.removeCacheMeta(key, m)));
7654
7624
  const removedFiles = new Set(toRemove.map((m) => m.file));
7655
7625
  cache.target = cache.target.filter((m) => !removedFiles.has(m.file));
7656
- await this.fileCompiler.saveCache(cache);
7626
+ }
7627
+ /**
7628
+ * 删除单个缓存元数据对应的输出文件(不操作缓存)
7629
+ */
7630
+ async removeCacheMeta(key, meta) {
7631
+ switch (key) {
7632
+ case "sfc" /* SFC */: {
7633
+ const sfcMeta = meta;
7634
+ const { jsx, css } = sfcMeta.output;
7635
+ await this.fileCompiler.removeOutputFile(jsx.file);
7636
+ if (css?.file) {
7637
+ await this.fileCompiler.removeOutputFile(css.file);
7638
+ }
7639
+ break;
7640
+ }
7641
+ case "script" /* SCRIPT */: {
7642
+ const scriptMeta = meta;
7643
+ await this.fileCompiler.removeOutputFile(scriptMeta.output.script.file);
7644
+ break;
7645
+ }
7646
+ case "style" /* STYLE */: {
7647
+ const styleMeta = meta;
7648
+ await this.fileCompiler.removeOutputFile(styleMeta.output.style.file);
7649
+ break;
7650
+ }
7651
+ // 静态资产缓存直接删除对应文件
7652
+ default: {
7653
+ await this.fileCompiler.removeOutputFile(meta.file, true);
7654
+ break;
7655
+ }
7656
+ }
7657
7657
  }
7658
7658
  };
7659
7659
 
@@ -7754,7 +7754,7 @@ var CompilationUnitProcessor = class {
7754
7754
  };
7755
7755
 
7756
7756
  // src/compiler/shared/file-compiler/file-processor.ts
7757
- import fs4 from "fs";
7757
+ import fs5 from "fs";
7758
7758
  import kleur6 from "kleur";
7759
7759
  import path7 from "path";
7760
7760
  var FileProcessor = class {
@@ -7785,18 +7785,18 @@ var FileProcessor = class {
7785
7785
  async processFile(key, filePath, existingCache) {
7786
7786
  const absPath = this.fileCompiler.getAbsPath(filePath);
7787
7787
  const fileMeta = await this.fileCompiler.getFileMeta(absPath);
7788
- const cache = (this.fileCompiler.getIsCache() ? existingCache : void 0) || await this.fileCompiler.loadCache(key);
7788
+ const cache = (this.fileCompiler.getIsCache() ? existingCache : void 0) || await this.cacheManager.loadCache(key);
7789
7789
  const record = cache?.target.find((c) => c.file === absPath);
7790
7790
  const { shouldCompile, hash } = await this.fileCompiler.checkCacheStatus(
7791
7791
  fileMeta,
7792
7792
  record,
7793
- () => fs4.promises.readFile(absPath, "utf-8")
7793
+ () => fs5.promises.readFile(absPath, "utf-8")
7794
7794
  );
7795
7795
  if (!shouldCompile) {
7796
7796
  this.skippedCount++;
7797
7797
  return;
7798
7798
  }
7799
- const source = await fs4.promises.readFile(absPath, "utf-8");
7799
+ const source = await fs5.promises.readFile(absPath, "utf-8");
7800
7800
  if (!source.trim()) return;
7801
7801
  const initUnit = {
7802
7802
  ...fileMeta,
@@ -7856,7 +7856,7 @@ var FileProcessor = class {
7856
7856
  const getMainFile = async (filename) => {
7857
7857
  const filePath = path7.resolve(outputPath, filename);
7858
7858
  try {
7859
- return { filePath, content: await fs4.promises.readFile(filePath, "utf-8") };
7859
+ return { filePath, content: await fs5.promises.readFile(filePath, "utf-8") };
7860
7860
  } catch {
7861
7861
  return;
7862
7862
  }
@@ -7910,64 +7910,160 @@ ${routerImport}`);
7910
7910
  resetSkippedCount() {
7911
7911
  this.skippedCount = 0;
7912
7912
  }
7913
+ /**
7914
+ * 扫描项目中的编译文件和资产文件
7915
+ * @param recursive 是否递归扫描子目录
7916
+ * @param ignoreAssets 需要忽略的资产文件列表
7917
+ */
7918
+ scanFiles() {
7919
+ const { fileCompiler } = this;
7920
+ const rootPath = fileCompiler.getProjectRoot();
7921
+ const inputPath = fileCompiler.getInputPath();
7922
+ const scriptExt = /\.(js|ts|jsx|tsx)$/i;
7923
+ const styleExt = /\.(css|less|sass|scss)$/i;
7924
+ const result = {
7925
+ assets: [],
7926
+ script: [],
7927
+ style: [],
7928
+ vue: []
7929
+ };
7930
+ const getInputStat = (path8) => {
7931
+ if (!fs5.existsSync(path8)) return;
7932
+ return fs5.statSync(path8);
7933
+ };
7934
+ const resolveDirectory = (file, walk, fallback) => {
7935
+ const directory = fs5.readdirSync(file);
7936
+ directory.forEach((p) => {
7937
+ const fullPath = path7.resolve(file, p);
7938
+ if (fileCompiler.shouldSkipPath(fullPath)) {
7939
+ return;
7940
+ }
7941
+ const stat = fs5.statSync(fullPath);
7942
+ if (stat.isDirectory() && fileCompiler.options.recursive !== false) {
7943
+ walk(fullPath);
7944
+ return;
7945
+ }
7946
+ fallback(fullPath);
7947
+ });
7948
+ };
7949
+ const scanCompilationFiles = (file, res) => {
7950
+ const stat = getInputStat(file);
7951
+ if (!stat) return;
7952
+ const classifyFile = (filePath) => {
7953
+ const fileExt = path7.extname(filePath);
7954
+ if (fileExt === ".vue") {
7955
+ res.vue.push(filePath);
7956
+ return;
7957
+ }
7958
+ if (scriptExt.test(fileExt)) {
7959
+ res.script.push(filePath);
7960
+ return;
7961
+ }
7962
+ if (styleExt.test(fileExt)) {
7963
+ res.style.push(filePath);
7964
+ }
7965
+ };
7966
+ if (stat.isFile()) {
7967
+ classifyFile(file);
7968
+ return;
7969
+ }
7970
+ resolveDirectory(
7971
+ file,
7972
+ (path8) => scanCompilationFiles(path8, res),
7973
+ (path8) => classifyFile(path8)
7974
+ );
7975
+ };
7976
+ const isAssetFile = (input) => {
7977
+ const fileExt = path7.extname(input).toLowerCase();
7978
+ const resolvedPath = normalizePath(fileCompiler.relativePath(input));
7979
+ const baseName = path7.basename(input).toLowerCase();
7980
+ const exclusions = fileCompiler.getIgnoreAssets();
7981
+ if (!fileCompiler.options.output?.ignoreAssets) {
7982
+ const shouldExclude = Array.from(exclusions).some((pattern) => {
7983
+ if (pattern.endsWith(".")) {
7984
+ return baseName.startsWith(pattern);
7985
+ }
7986
+ if (pattern.startsWith(".")) {
7987
+ return fileExt === pattern;
7988
+ }
7989
+ return resolvedPath === pattern || baseName === pattern;
7990
+ });
7991
+ if (shouldExclude) return false;
7992
+ } else {
7993
+ if (exclusions.has(resolvedPath) || exclusions.has(baseName) || fileExt === ".vue") {
7994
+ return false;
7995
+ }
7996
+ }
7997
+ const isInsideSrc = input.startsWith(inputPath + path7.sep);
7998
+ if (isInsideSrc && (scriptExt.test(fileExt) || styleExt.test(fileExt))) {
7999
+ return false;
8000
+ }
8001
+ return true;
8002
+ };
8003
+ const scanAssetFiles = (input, res) => {
8004
+ const stat = getInputStat(input);
8005
+ if (!stat || fileCompiler.shouldSkipPath(input)) {
8006
+ return;
8007
+ }
8008
+ if (stat.isFile()) {
8009
+ if (isAssetFile(input)) {
8010
+ res.assets.push(input);
8011
+ }
8012
+ return;
8013
+ }
8014
+ resolveDirectory(
8015
+ input,
8016
+ (path8) => scanAssetFiles(path8, res),
8017
+ (path8) => {
8018
+ if (isAssetFile(path8)) {
8019
+ res.assets.push(path8);
8020
+ }
8021
+ }
8022
+ );
8023
+ };
8024
+ scanCompilationFiles(inputPath, result);
8025
+ scanAssetFiles(rootPath, result);
8026
+ return result;
8027
+ }
7913
8028
  };
7914
8029
 
7915
8030
  // src/compiler/shared/file-compiler/pipeline-manager.ts
7916
- import path8 from "path";
7917
8031
  var PipelineManager = class {
7918
- constructor(fileCompiler, fileProcessor) {
8032
+ constructor(fileCompiler, fileProcessor, cleanupManager) {
7919
8033
  this.fileCompiler = fileCompiler;
7920
8034
  this.fileProcessor = fileProcessor;
7921
- this.cleanupManager = new CleanupManager(fileCompiler);
8035
+ this.cleanupManager = cleanupManager;
7922
8036
  }
7923
8037
  skippedCount = 0;
7924
- cleanupManager;
7925
8038
  /**
7926
8039
  * 运行 SFC 编译管线
7927
8040
  */
7928
- async runSfcPipeline() {
7929
- return this.runCorePipeline("sfc" /* SFC */);
8041
+ async runSFC(files, cacheMap) {
8042
+ return this.runCore(files, "sfc" /* SFC */, cacheMap);
7930
8043
  }
7931
8044
  /**
7932
8045
  * 运行 Script 编译管线
7933
8046
  */
7934
- async runScriptPipeline() {
7935
- return this.runCorePipeline("script" /* SCRIPT */);
8047
+ async runScript(files, cacheMap) {
8048
+ return this.runCore(files, "script" /* SCRIPT */, cacheMap);
7936
8049
  }
7937
8050
  /**
7938
8051
  * 运行 Style 编译管线
7939
8052
  */
7940
- async runStylePipeline() {
7941
- return this.runCorePipeline("style" /* STYLE */);
8053
+ async runStyle(files, cacheMap) {
8054
+ return this.runCore(files, "style" /* STYLE */, cacheMap);
7942
8055
  }
7943
8056
  /**
7944
8057
  * 核心编译管线
7945
8058
  */
7946
- async runCorePipeline(key) {
7947
- const inputPath = this.fileCompiler.getInputPath();
7948
- const scriptExtRegex = /\.(js|ts)$/i;
7949
- const styleExtRegex = /\.(css|less|sass|scss)$/i;
7950
- const files = this.fileCompiler.scanFiles(inputPath, (p) => {
7951
- const ext = path8.extname(p);
7952
- if (key === "sfc" /* SFC */) {
7953
- return ext === ".vue";
7954
- }
7955
- if (key === "script" /* SCRIPT */) {
7956
- return scriptExtRegex.test(ext);
7957
- }
7958
- if (key === "style" /* STYLE */) {
7959
- return styleExtRegex.test(ext);
7960
- }
7961
- return false;
7962
- });
7963
- const absFiles = new Set(files.map((f) => this.fileCompiler.getAbsPath(f)));
7964
- await this.cleanupManager.cleanupOldOutput(key, (c) => !absFiles.has(c.file));
8059
+ async runCore(files, key, cacheMap) {
8060
+ const absPaths = new Set(files.map((f) => this.fileCompiler.getAbsPath(f)));
8061
+ const cache = cacheMap[key];
8062
+ await this.cleanupManager.removeMatchedFromCache(key, cache, (c) => !absPaths.has(c.file));
7965
8063
  if (!files.length) return 0;
7966
- const cache = await this.fileCompiler.loadCache(key);
7967
8064
  const compiled = await Promise.all(
7968
- files.map(async (f) => this.fileProcessor.processFile(key, f, cache))
8065
+ files.map((f) => this.fileProcessor.processFile(key, f, cache))
7969
8066
  );
7970
- await this.fileCompiler.flushCache(key);
7971
8067
  return compiled.filter(Boolean).length;
7972
8068
  }
7973
8069
  /**
@@ -7981,12 +8077,13 @@ var PipelineManager = class {
7981
8077
  */
7982
8078
  resetSkippedCount() {
7983
8079
  this.skippedCount = 0;
8080
+ this.fileProcessor.resetSkippedCount();
7984
8081
  }
7985
8082
  };
7986
8083
 
7987
8084
  // src/compiler/shared/file-compiler/vite-bootstrapper.ts
7988
8085
  import { execSync } from "child_process";
7989
- import fs5 from "fs";
8086
+ import fs6 from "fs";
7990
8087
  import kleur7 from "kleur";
7991
8088
  import ora from "ora";
7992
8089
  var ViteBootstrapper = class {
@@ -8004,10 +8101,10 @@ var ViteBootstrapper = class {
8004
8101
  */
8005
8102
  isSingleFile() {
8006
8103
  const inputPath = this.fileCompiler.getInputPath();
8007
- if (!fs5.existsSync(inputPath)) {
8104
+ if (!fs6.existsSync(inputPath)) {
8008
8105
  return false;
8009
8106
  }
8010
- const stat = fs5.statSync(inputPath);
8107
+ const stat = fs6.statSync(inputPath);
8011
8108
  return stat.isFile();
8012
8109
  }
8013
8110
  /**
@@ -8016,30 +8113,20 @@ var ViteBootstrapper = class {
8016
8113
  async bootstrapIfNeeded() {
8017
8114
  const { output } = this.options;
8018
8115
  const workspaceDir = this.fileCompiler.getWorkspaceDir();
8019
- await fs5.promises.mkdir(workspaceDir, { recursive: true });
8116
+ await fs6.promises.mkdir(workspaceDir, { recursive: true });
8020
8117
  if (output?.bootstrapVite === false) {
8021
8118
  return false;
8022
8119
  }
8023
8120
  if (this.isSingleFile()) {
8024
- console.info("Skipping Vite initialization for single file compilation");
8121
+ console.info(kleur7.dim("Skip Vite init for single file"));
8122
+ console.info();
8025
8123
  return;
8026
8124
  }
8027
8125
  const outputPkgPath = this.fileCompiler.getOutputPkgPath();
8028
- if (fs5.existsSync(outputPkgPath)) {
8029
- return;
8030
- }
8031
- try {
8032
- this.spinner.start("Bootstrapping Vite React environment...");
8033
- await this.resolveViteCreateApp();
8034
- } catch (err) {
8035
- console.error(
8036
- kleur7.red("\u2716"),
8037
- "Failed to bootstrap Vite environment. Please check npm/network.\n",
8038
- err
8039
- );
8040
- this.spinner.stop();
8126
+ if (fs6.existsSync(outputPkgPath)) {
8041
8127
  return;
8042
8128
  }
8129
+ await this.resolveViteCreateApp();
8043
8130
  const removeVuePackages = (deps) => {
8044
8131
  for (const name in deps) {
8045
8132
  const isVueLike = VUE_PACKAGES.some((n) => name.includes(n));
@@ -8069,7 +8156,7 @@ var ViteBootstrapper = class {
8069
8156
  newPkg.devDependencies = newDevDeps;
8070
8157
  newPkg = output?.packageJson?.(newPkg) || newPkg;
8071
8158
  await this.fileCompiler.writeFileWithDir(outputPkgPath, JSON.stringify(newPkg, null, 2));
8072
- this.spinner.succeed("Standard Vite React environment initialized");
8159
+ this.spinner.succeed("Initialized Vite React environment");
8073
8160
  return true;
8074
8161
  }
8075
8162
  /**
@@ -8139,13 +8226,13 @@ var SetupManager = class {
8139
8226
  fileCompiler.manager = {};
8140
8227
  const manager = fileCompiler.manager;
8141
8228
  manager.cacheManager = new CacheManager(fileCompiler);
8142
- manager.cleanupManager = new CleanupManager(fileCompiler);
8143
8229
  }
8144
8230
  /**
8145
8231
  * 创建依赖基础管理器的管理器
8146
8232
  */
8147
8233
  setupManagedByBase(fileCompiler) {
8148
8234
  const manager = fileCompiler.manager;
8235
+ manager.cleanupManager = new CleanupManager(fileCompiler, manager.cacheManager);
8149
8236
  manager.fileProcessor = new FileProcessor(
8150
8237
  fileCompiler,
8151
8238
  new CompilationUnitProcessor(fileCompiler),
@@ -8158,8 +8245,16 @@ var SetupManager = class {
8158
8245
  setupCompositeManager(fileCompiler) {
8159
8246
  const manager = fileCompiler.manager;
8160
8247
  manager.viteBootstrapper = new ViteBootstrapper(fileCompiler, fileCompiler.options);
8161
- manager.pipelineManager = new PipelineManager(fileCompiler, manager.fileProcessor);
8162
- manager.assetManager = new AssetManager(fileCompiler, manager.cleanupManager);
8248
+ manager.pipelineManager = new PipelineManager(
8249
+ fileCompiler,
8250
+ manager.fileProcessor,
8251
+ manager.cleanupManager
8252
+ );
8253
+ manager.assetManager = new AssetManager(
8254
+ fileCompiler,
8255
+ manager.cleanupManager,
8256
+ manager.cacheManager
8257
+ );
8163
8258
  }
8164
8259
  };
8165
8260
 
@@ -8171,34 +8266,57 @@ var FileCompiler = class extends BaseCompiler {
8171
8266
  super(options);
8172
8267
  new SetupManager(() => this);
8173
8268
  }
8269
+ printTitle() {
8270
+ const purple = "\x1B[38;2;153;50;204m";
8271
+ const reset = "\x1B[0m";
8272
+ console.info();
8273
+ console.info();
8274
+ console.info(`${purple}${kleur8.bold("VUREACT")} v${this.version}${reset}`);
8275
+ console.info();
8276
+ }
8277
+ updateSpinner(text) {
8278
+ this.spinner.stop();
8279
+ this.spinner.start(text);
8280
+ }
8174
8281
  /** 执行完整的编译流程 */
8175
8282
  async execute() {
8176
- console.info("\n\n", kleur8.magenta(`${kleur8.bold("VUREACT")} v${this.version}`), "\n");
8177
- const startTime = performance.now();
8178
- const rmWorkspace = async () => {
8179
- await this.rmFile(this.getWorkspaceDir());
8180
- };
8283
+ this.printTitle();
8181
8284
  try {
8182
8285
  if (!this.getIsCache()) {
8183
- await rmWorkspace();
8286
+ await this.rmFile(this.getCachePath());
8184
8287
  }
8185
- await this.manager.viteBootstrapper.bootstrapIfNeeded();
8186
- const sfcCount = await this.runPipelineWithSpinner("sfc" /* SFC */);
8187
- const scriptCount = await this.runPipelineWithSpinner("script" /* SCRIPT */);
8188
- const styleCount = await this.runPipelineWithSpinner("style" /* STYLE */);
8189
- const assetCount = await this.runPipelineWithSpinner("copied" /* ASSET */);
8288
+ } catch (err) {
8289
+ console.warn(kleur8.yellow("\u26A0"), "Failed to clear cache");
8290
+ console.info();
8291
+ }
8292
+ const { viteBootstrapper, fileProcessor, cacheManager, pipelineManager, assetManager } = this.manager;
8293
+ let startTime = 0;
8294
+ try {
8295
+ this.updateSpinner("Initializing Vite React env...");
8296
+ await viteBootstrapper.bootstrapIfNeeded();
8297
+ const cacheMap = await cacheManager.loadAllCache();
8298
+ startTime = performance.now();
8299
+ this.updateSpinner("Scanning files...");
8300
+ const scanFiles = fileProcessor.scanFiles();
8301
+ this.updateSpinner("Compiling Vue to React...");
8302
+ const sfcCount = await pipelineManager.runSFC(scanFiles.vue, cacheMap);
8303
+ const scriptCount = await pipelineManager.runScript(scanFiles.script, cacheMap);
8304
+ const styleCount = await pipelineManager.runStyle(scanFiles.style, cacheMap);
8305
+ this.updateSpinner("Copying assets...");
8306
+ const assetCount = await assetManager.runAsset(scanFiles.assets, cacheMap);
8307
+ this.updateSpinner("Almost done...");
8308
+ await cacheManager.flushAllCache();
8190
8309
  await this.options.onSuccess?.();
8191
8310
  const endTime = calcElapsedTime(startTime);
8192
8311
  this.printCoreLogs();
8193
8312
  this.showCompileStats(endTime, sfcCount, scriptCount, styleCount, assetCount);
8194
8313
  } catch (error) {
8195
- const endTime = calcElapsedTime(startTime);
8196
- await rmWorkspace();
8197
- console.error(kleur8.red("\u2716"), `Build failed in ${endTime}`);
8314
+ this.spinner.stop();
8315
+ console.error(kleur8.red("\u2716"), `Build failed in ${calcElapsedTime(startTime)}`);
8198
8316
  console.error(error);
8317
+ await this.rmFile(this.getWorkspaceDir());
8199
8318
  process.exit(-1);
8200
8319
  } finally {
8201
- this.spinner.stop();
8202
8320
  this.resetSkippedCount();
8203
8321
  }
8204
8322
  }
@@ -8235,62 +8353,40 @@ var FileCompiler = class extends BaseCompiler {
8235
8353
  async processAsset(filePath, existingCache) {
8236
8354
  return this.manager.assetManager.processAsset(filePath, existingCache);
8237
8355
  }
8238
- /** 批量保存缓存 */
8239
- async flushCache(key) {
8240
- await this.manager.cacheManager.flushCache(key);
8241
- }
8242
8356
  /** 删除指定路径对应的输出文件和缓存 */
8243
8357
  async removeOutputPath(targetPath, type) {
8244
8358
  return await this.manager.cleanupManager.removeOutputPath(targetPath, type);
8245
8359
  }
8246
- async runPipelineWithSpinner(name) {
8247
- const options = {
8248
- ["sfc" /* SFC */]: {
8249
- text: "Compiling Vue files...",
8250
- pipeline: () => this.manager.pipelineManager.runSfcPipeline()
8251
- },
8252
- ["script" /* SCRIPT */]: {
8253
- text: "Compiling script files...",
8254
- pipeline: () => this.manager.pipelineManager.runScriptPipeline()
8255
- },
8256
- ["style" /* STYLE */]: {
8257
- text: "Compiling style files...",
8258
- pipeline: () => this.manager.pipelineManager.runStylePipeline()
8259
- },
8260
- ["copied" /* ASSET */]: {
8261
- text: "Copying assets...",
8262
- pipeline: () => this.manager.assetManager.runAssetPipeline()
8263
- }
8264
- };
8265
- const { text, pipeline } = options[name];
8266
- try {
8267
- this.spinner.start(text);
8268
- return await pipeline();
8269
- } catch (err) {
8270
- throw err;
8271
- } finally {
8272
- this.spinner.stop();
8273
- }
8274
- }
8275
8360
  showCompileStats(endTime, sfcCount, scriptCount, styleCount, assetCount) {
8276
8361
  this.spinner.succeed(`Build completed in ${endTime}`);
8277
- console.info();
8278
8362
  if (sfcCount || scriptCount || styleCount || assetCount) {
8279
8363
  const stats = [];
8280
- if (sfcCount) stats.push(`${sfcCount} SFC(s)`);
8281
- if (scriptCount) stats.push(`${scriptCount} script(s)`);
8282
- if (styleCount) stats.push(`${styleCount} style(s)`);
8283
- if (assetCount) stats.push(`${assetCount} asset(s)`);
8284
- this.spinner.succeed(`Processed: ${stats.join(", ")}`);
8364
+ if (sfcCount) stats.push(`${sfcCount} ${kleur8.dim("SFC(s)")}`);
8365
+ if (scriptCount) stats.push(`${scriptCount} ${kleur8.dim("script(s)")}`);
8366
+ if (styleCount) stats.push(`${styleCount} ${kleur8.dim("style(s)")}`);
8367
+ if (assetCount) stats.push(`${assetCount} ${kleur8.dim("asset(s)")}`);
8368
+ this.spinner.succeed(`${kleur8.bold("Processed")}: ${stats.join(", ")}`);
8285
8369
  }
8286
8370
  const skippedCount = this.manager.pipelineManager.getSkippedCount() + this.manager.assetManager.getSkippedCount();
8287
8371
  if (skippedCount) {
8288
- console.info(kleur8.gray(`\u21B7 Cached: ${kleur8.white(skippedCount)} unchanged file(s)`));
8372
+ console.info();
8373
+ console.info(
8374
+ kleur8.gray(`\u21B7 ${kleur8.bold("Cached")}: ${kleur8.white(skippedCount)} unchanged file(s)`)
8375
+ );
8289
8376
  this.resetSkippedCount();
8290
8377
  }
8291
8378
  const dir = normalizePath(this.relativePath(this.getOuputPath()));
8292
8379
  console.info();
8293
- console.info(`\u{1F4E6} Output: ${dir}`);
8380
+ console.info(`\u{1F4E6} ${kleur8.bold("Output")}: ${kleur8.cyan(dir)}`);
8381
+ console.info();
8382
+ console.info(` > cd ${dir}`);
8383
+ console.info(` > npm install`);
8384
+ console.info(` > npm run dev`);
8385
+ console.info();
8386
+ console.info(
8387
+ kleur8.dim("\u2B50 If you like VuReact, give us a star on GitHub:"),
8388
+ kleur8.gray(kleur8.underline("https://github.com/vureact-js/core"))
8389
+ );
8294
8390
  console.info();
8295
8391
  }
8296
8392
  resetSkippedCount() {
@@ -8321,9 +8417,9 @@ export {
8321
8417
  transform,
8322
8418
  version,
8323
8419
  bin,
8324
- CacheKey,
8325
8420
  Helper,
8326
8421
  BaseCompiler,
8422
+ CacheKey,
8327
8423
  FileCompiler,
8328
8424
  defineConfig,
8329
8425
  VuReact