@ripast/vue 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.mjs +58 -21
  2. package/package.json +3 -3
package/dist/index.mjs CHANGED
@@ -1432,26 +1432,59 @@ const NUXT_BUILTINS = new Set([
1432
1432
  ]);
1433
1433
  const PASCAL = /^[A-Z][A-Z0-9a-z]*$/;
1434
1434
  const NODE_ELEMENT = 1;
1435
- function extractTemplateBlock(source) {
1436
- const openStart = source.indexOf("<template");
1437
- if (openStart === -1) return void 0;
1438
- const contentStart = source.indexOf(">", openStart);
1439
- if (contentStart === -1) return void 0;
1440
- const start = contentStart + 1;
1441
- const end = source.indexOf("</template>", start);
1442
- if (end === -1) return void 0;
1443
- return {
1444
- content: source.slice(start, end),
1445
- start
1446
- };
1435
+ function listAppRoots(cwd) {
1436
+ const roots = [];
1437
+ const parent = join(cwd, "apps");
1438
+ if (!existsSync(parent)) return roots;
1439
+ for (const name of readdirSync(parent)) {
1440
+ const abs = join(parent, name);
1441
+ try {
1442
+ if (statSync(abs).isDirectory() && existsSync(join(abs, ".nuxt", "components.d.ts"))) roots.push(abs);
1443
+ } catch {}
1444
+ }
1445
+ return roots;
1447
1446
  }
1448
- function findPhantomComponents(cwd) {
1449
- const files = rgFilesMany(["*.vue"], { cwd });
1447
+ function scopeForFile(abs, roots, cwd) {
1448
+ let best = cwd;
1449
+ let bestLen = -1;
1450
+ for (const root of roots) if ((abs === root || abs.startsWith(`${root}/`)) && root.length > bestLen) {
1451
+ best = root;
1452
+ bestLen = root.length;
1453
+ }
1454
+ return best;
1455
+ }
1456
+ function buildKnownSet(root) {
1450
1457
  const known = new Set([...VUE_BUILTINS, ...NUXT_BUILTINS]);
1451
- for (const c of listComponents(cwd, { source: "auto" })) {
1458
+ for (const c of listComponents(root, {
1459
+ source: "auto",
1460
+ warn: () => {}
1461
+ })) {
1452
1462
  known.add(c.name);
1453
1463
  for (const alias of c.aliases ?? []) known.add(alias);
1454
1464
  }
1465
+ return known;
1466
+ }
1467
+ function buildUnionKnownSet(roots, cwd) {
1468
+ const known = new Set([...VUE_BUILTINS, ...NUXT_BUILTINS]);
1469
+ const sources = roots.length ? roots : [cwd];
1470
+ for (const root of sources) for (const c of listComponents(root, {
1471
+ source: "auto",
1472
+ warn: () => {}
1473
+ })) {
1474
+ known.add(c.name);
1475
+ for (const alias of c.aliases ?? []) known.add(alias);
1476
+ }
1477
+ return known;
1478
+ }
1479
+ function findPhantomComponents(cwd) {
1480
+ const files = rgFiles("", {
1481
+ cwd,
1482
+ glob: ["*.vue"],
1483
+ listAll: true
1484
+ });
1485
+ const appRoots = listAppRoots(cwd);
1486
+ const knownByRoot = /* @__PURE__ */ new Map();
1487
+ if (appRoots.length) knownByRoot.set(cwd, buildUnionKnownSet(appRoots, cwd));
1455
1488
  const out = [];
1456
1489
  for (const abs of files) {
1457
1490
  let source;
@@ -1460,11 +1493,14 @@ function findPhantomComponents(cwd) {
1460
1493
  } catch {
1461
1494
  continue;
1462
1495
  }
1463
- const template = extractTemplateBlock(source);
1464
- if (!template) continue;
1465
- const templateStart = template.start;
1466
- const ast = parseVueTemplateAst(template.content);
1496
+ const ast = parseVueTemplateAst(source);
1467
1497
  if (!ast) continue;
1498
+ const root = scopeForFile(abs, appRoots, cwd);
1499
+ let known = knownByRoot.get(root);
1500
+ if (!known) {
1501
+ known = buildKnownSet(root);
1502
+ knownByRoot.set(root, known);
1503
+ }
1468
1504
  const localImports = collectLocalImports(source);
1469
1505
  const seen = /* @__PURE__ */ new Set();
1470
1506
  walkTpl(ast, (node) => {
@@ -1477,7 +1513,7 @@ function findPhantomComponents(cwd) {
1477
1513
  const key = `${abs}::${tag}::${node.loc?.start?.offset ?? 0}`;
1478
1514
  if (seen.has(key)) return;
1479
1515
  seen.add(key);
1480
- const offset = templateStart + (node.loc?.start?.offset ?? 0);
1516
+ const offset = node.loc?.start?.offset ?? 0;
1481
1517
  const { line, col } = posToLineCol(source, offset);
1482
1518
  out.push({
1483
1519
  check: "phantom-component",
@@ -1486,7 +1522,8 @@ function findPhantomComponents(cwd) {
1486
1522
  message: `<${tag}> is not a known component (auto-import scope, local import, or built-in)`,
1487
1523
  detail: {
1488
1524
  name: tag,
1489
- col
1525
+ col,
1526
+ scope: relative(cwd, root) || "."
1490
1527
  }
1491
1528
  });
1492
1529
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ripast/vue",
3
3
  "type": "module",
4
- "version": "0.3.0",
4
+ "version": "0.4.0",
5
5
  "description": "Vue (and Nuxt) framework adapter for ripast. Provides Volar/Vue Language Service-backed rename, move, and template rewriting for .vue SFCs.",
6
6
  "author": {
7
7
  "name": "Harlan Wilton",
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "peerDependencies": {
44
44
  "typescript": ">=5.4",
45
- "@ripast/core": "0.3.0"
45
+ "@ripast/core": "0.4.0"
46
46
  },
47
47
  "dependencies": {
48
48
  "@volar/language-service": "^2.4.28",
@@ -55,7 +55,7 @@
55
55
  "vscode-uri": "^3.1.0"
56
56
  },
57
57
  "devDependencies": {
58
- "@ripast/core": "0.3.0"
58
+ "@ripast/core": "0.4.0"
59
59
  },
60
60
  "scripts": {
61
61
  "build": "obuild",