@justmpm/ai-tool 0.7.4 → 0.7.6

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.
@@ -3327,7 +3327,7 @@ function extractExports(sourceFile) {
3327
3327
  // src/ts/indexer.ts
3328
3328
  import { readdirSync as readdirSync2, statSync as statSync2 } from "fs";
3329
3329
  import { join as join4, extname as extname2, resolve } from "path";
3330
- import { Project as Project2, SyntaxKind as SyntaxKind2 } from "ts-morph";
3330
+ import { Project as Project2, SyntaxKind as SyntaxKind2, Node as Node2 } from "ts-morph";
3331
3331
  var CODE_EXTENSIONS2 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs"]);
3332
3332
  var DEBUG = process.env.DEBUG_ANALYZE === "true";
3333
3333
  var DEBUG_FUNCTIONS = process.env.DEBUG_FUNCTIONS === "true" || DEBUG;
@@ -3419,6 +3419,28 @@ var FIREBASE_V2_TRIGGERS = /* @__PURE__ */ new Set([
3419
3419
  // Test Lab (firebase-functions/v2/testLab)
3420
3420
  "onTestMatrixCompleted"
3421
3421
  ]);
3422
+ function buildImportMap(sourceFile) {
3423
+ const map2 = /* @__PURE__ */ new Map();
3424
+ if (!sourceFile.getImportDeclarations) return map2;
3425
+ for (const decl of sourceFile.getImportDeclarations()) {
3426
+ const module = decl.getModuleSpecifierValue();
3427
+ const ns = decl.getNamespaceImport();
3428
+ if (ns) {
3429
+ map2.set(ns.getText(), { name: "*", module });
3430
+ }
3431
+ for (const named of decl.getNamedImports()) {
3432
+ const alias = named.getAliasNode();
3433
+ const name = named.getName();
3434
+ const localName = alias ? alias.getText() : name;
3435
+ map2.set(localName, { name, module });
3436
+ }
3437
+ const def = decl.getDefaultImport();
3438
+ if (def) {
3439
+ map2.set(def.getText(), { name: "default", module });
3440
+ }
3441
+ }
3442
+ return map2;
3443
+ }
3422
3444
  function indexProject(cwd) {
3423
3445
  const allFiles = getAllCodeFiles(cwd);
3424
3446
  debugLog(`Indexando ${allFiles.length} arquivos em ${cwd}`);
@@ -3429,12 +3451,30 @@ function indexProject(cwd) {
3429
3451
  functionFiles.forEach((f) => debugFunctions(` - ${f}`));
3430
3452
  }
3431
3453
  const project = createProject2(cwd);
3454
+ let addedCount = 0;
3455
+ let errorCount = 0;
3432
3456
  for (const file of allFiles) {
3433
3457
  try {
3434
3458
  project.addSourceFileAtPath(resolve(cwd, file));
3459
+ addedCount++;
3435
3460
  } catch {
3461
+ errorCount++;
3462
+ if (DEBUG && file.includes("functions/src/")) {
3463
+ debugLog(`[indexer] Erro ao adicionar: ${file}`);
3464
+ }
3436
3465
  }
3437
3466
  }
3467
+ debugLog(`[indexer] Total de arquivos encontrados: ${allFiles.length}`);
3468
+ debugLog(`[indexer] Arquivos adicionados ao projeto: ${addedCount}`);
3469
+ debugLog(`[indexer] Arquivos com erro: ${errorCount}`);
3470
+ debugLog(`[indexer] SourceFiles no projeto: ${project.getSourceFiles().length}`);
3471
+ const functionsInProject = project.getSourceFiles().filter(
3472
+ (sf) => sf.getFilePath().includes("functions/src/")
3473
+ );
3474
+ debugFunctions(`[indexer] Arquivos functions/src/ no projeto: ${functionsInProject.length}`);
3475
+ functionsInProject.forEach((sf) => {
3476
+ debugFunctions(` - ${sf.getFilePath()}`);
3477
+ });
3438
3478
  const files = {};
3439
3479
  const symbolsByName = {};
3440
3480
  let symbolCount = 0;
@@ -3532,7 +3572,8 @@ function indexProject(cwd) {
3532
3572
  exports.push(name);
3533
3573
  }
3534
3574
  } else if (initKind === SyntaxKind2.CallExpression) {
3535
- const triggerName = extractFirebaseTriggerName(init, filePath, name);
3575
+ const importMap = buildImportMap(sourceFile);
3576
+ const triggerName = extractFirebaseTriggerName(init, filePath, name, importMap);
3536
3577
  if (DEBUG_FUNCTIONS && filePath.includes("functions/src/")) {
3537
3578
  const initText = init.getText().slice(0, 80).replace(/\s+/g, " ");
3538
3579
  debugFunctions(`Analisando: ${filePath}:${varDecl.getStartLineNumber()} - ${name} = ${initText}...`);
@@ -3687,16 +3728,25 @@ function indexProject(cwd) {
3687
3728
  }
3688
3729
  function createProject2(cwd) {
3689
3730
  try {
3690
- return new Project2({
3731
+ const project = new Project2({
3691
3732
  tsConfigFilePath: `${cwd}/tsconfig.json`,
3692
3733
  skipAddingFilesFromTsConfig: true
3693
3734
  });
3735
+ debugLog(`Projeto ts-morph criado com tsconfig: ${cwd}/tsconfig.json`);
3736
+ return project;
3694
3737
  } catch {
3738
+ debugLog(`Falha ao ler tsconfig, criando projeto b\xE1sico`);
3695
3739
  return new Project2({
3696
3740
  skipAddingFilesFromTsConfig: true,
3697
3741
  compilerOptions: {
3698
3742
  allowJs: true,
3699
- checkJs: false
3743
+ checkJs: false,
3744
+ target: 2,
3745
+ // ES2020
3746
+ module: 200,
3747
+ // ESNext
3748
+ moduleResolution: 100
3749
+ // Bundler
3700
3750
  }
3701
3751
  });
3702
3752
  }
@@ -3736,9 +3786,44 @@ function inferSymbolKind(name, context2) {
3736
3786
  }
3737
3787
  return context2 === "function" ? "function" : "const";
3738
3788
  }
3739
- function extractFirebaseTriggerName(init, filePath, varName) {
3789
+ function extractFirebaseTriggerName(init, filePath, varName, importMap) {
3740
3790
  const text = init.getText().trim();
3741
3791
  const shouldDebug = DEBUG_FUNCTIONS && filePath && filePath.includes("functions/src/");
3792
+ if (importMap && Node2.isCallExpression(init)) {
3793
+ const expr = init.getExpression();
3794
+ if (Node2.isIdentifier(expr)) {
3795
+ const name = expr.getText();
3796
+ const importInfo = importMap.get(name);
3797
+ if (importInfo && importInfo.module.includes("firebase-functions")) {
3798
+ if (FIREBASE_V2_TRIGGERS.has(importInfo.name)) {
3799
+ if (shouldDebug) debugFunctions(` [AST] Import detectado: ${name} -> ${importInfo.name} from ${importInfo.module}`);
3800
+ return importInfo.name;
3801
+ }
3802
+ }
3803
+ if (FIREBASE_V2_TRIGGERS.has(name)) {
3804
+ return name;
3805
+ }
3806
+ } else if (Node2.isPropertyAccessExpression(expr)) {
3807
+ const lastPart = expr.getName();
3808
+ if (FIREBASE_V2_TRIGGERS.has(lastPart)) {
3809
+ let root = expr.getExpression();
3810
+ while (Node2.isPropertyAccessExpression(root)) {
3811
+ root = root.getExpression();
3812
+ }
3813
+ if (Node2.isIdentifier(root)) {
3814
+ const rootName = root.getText();
3815
+ const importInfo = importMap.get(rootName);
3816
+ if (importInfo && importInfo.module.includes("firebase-functions")) {
3817
+ if (shouldDebug) debugFunctions(` [AST] Chain detectada: ${rootName}...${lastPart} from ${importInfo.module}`);
3818
+ return lastPart;
3819
+ }
3820
+ if (["v2", "functions", "firebase", "admin"].includes(rootName)) {
3821
+ return lastPart;
3822
+ }
3823
+ }
3824
+ }
3825
+ }
3826
+ }
3742
3827
  if (shouldDebug && varName) {
3743
3828
  debugFunctions(` [regex] Analisando texto: "${text.slice(0, 60)}..."`);
3744
3829
  }
package/dist/cli.js CHANGED
@@ -13,7 +13,7 @@ import {
13
13
  impact,
14
14
  map,
15
15
  suggest
16
- } from "./chunk-JUKU4SGB.js";
16
+ } from "./chunk-V625LOQR.js";
17
17
 
18
18
  // src/cli.ts
19
19
  import { resolve } from "path";
@@ -108,7 +108,7 @@ async function main() {
108
108
  }
109
109
  }
110
110
  if (flags.mcp) {
111
- const { startMcpServer } = await import("./server-52VHXRUA.js");
111
+ const { startMcpServer } = await import("./server-OEYAIVEP.js");
112
112
  await startMcpServer();
113
113
  return;
114
114
  }
package/dist/index.js CHANGED
@@ -47,7 +47,7 @@ import {
47
47
  setFileDescription,
48
48
  suggest,
49
49
  writeConfig
50
- } from "./chunk-JUKU4SGB.js";
50
+ } from "./chunk-V625LOQR.js";
51
51
  export {
52
52
  AREA_DESCRIPTIONS,
53
53
  AREA_NAMES,
@@ -11,7 +11,7 @@ import {
11
11
  impact,
12
12
  map,
13
13
  suggest
14
- } from "./chunk-JUKU4SGB.js";
14
+ } from "./chunk-V625LOQR.js";
15
15
 
16
16
  // src/mcp/server.ts
17
17
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@justmpm/ai-tool",
3
- "version": "0.7.4",
3
+ "version": "0.7.6",
4
4
  "description": "Ferramenta de análise de dependências e impacto para projetos TypeScript/JavaScript. Usa Skott + Knip internamente.",
5
5
  "keywords": [
6
6
  "dependency-analysis",