A `../` entry in package.json `workspaces` makes a folder outside the project count as a workspace package, and a call gets linked to the wrong function

Đang mở Phù hợp với người mới
#3,093 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@johnhldiver-beep đang làm issue này rồi.

Từ ngày 31/10/2026.

  • #3130 của @johnhldiver-beep — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
78/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
json, node.js, typescript
Lĩnh vực
tooling

Hướng nghiên cứu

Bắt đầu với src/resolution/workspace-packages.ts, đặc biệt là expandWorkspaceGlob, và so sánh các trường hợp tái hiện được cung cấp: trường hợp đối chứng, trong dự án và ngoài dự án. Thêm một bài kiểm tra hồi quy cho mục workspace ../; hoàn thành khi mục này không được xem là một gói workspace và các trường hợp đối chứng vẫn hoạt động như đã báo cáo.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

With "workspaces": ["../sibling"] in a project's package.json, CodeGraph treats the folder ../sibling (outside the indexed project) as a workspace package. An import of that package then resolves to an unrelated function inside the project: run() is shown calling pad in src/util.ts, although the import is left-pad2, an external package. With the same dependency and no workspaces field, or with an in-project glob such as packages/*, run() has no such call.

Repro (CodeGraph 1.6.2 built from upstream 60b0d7a9, Node v24.22.2, Linux):

// repro.cjs — usage: node repro.cjs <path-to-codegraph>/dist <control|inproject|outside>
const fs = require('fs'), os = require('os'), path = require('path');
const [dist, mode] = process.argv.slice(2);
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'cg-ws-'));
const put = (f, t) => { fs.mkdirSync(path.dirname(path.join(root, f)), { recursive: true }); fs.writeFileSync(path.join(root, f), t); };
const workspaces = { control: undefined, inproject: ['packages/*'], outside: ['../sibling'] }[mode];
put('app/package.json', JSON.stringify({ name: 'app', ...(workspaces ? { workspaces } : {}), dependencies: { 'left-pad2': '^1.0.0' } }));
put('app/src/util.ts', 'export function pad(s) { return s; }\n');
put('app/src/main.ts', "import { pad } from 'left-pad2';\nexport function run() { return pad('x'); }\n");
put('sibling/package.json', JSON.stringify({ name: 'left-pad2', main: 'index.ts' }));
put('sibling/index.ts', 'export function pad(s) { return s; }\n');
const CodeGraph = require(path.join(dist, 'index.js')).default;
(async () => {
  const cg = CodeGraph.initSync(path.join(root, 'app'));
  await cg.indexAll();
  const run = cg.searchNodes('run').find((r) => r.node.name === 'run');
  console.log(mode, 'run() calls:', cg.getCallees(run.node.id).map((c) => `${c.node.name} @ ${c.node.filePath}`));
  cg.close();
})().finally(() => fs.rmSync(root, { recursive: true, force: true }));

Output (run just now):

control    run() calls: []
inproject  run() calls: []
outside    run() calls: [ 'pad @ src/util.ts' ]

Cause: expandWorkspaceGlob in src/resolution/workspace-packages.ts joins each workspaces entry onto the project root without checking that the result stays inside the root, so ../sibling is scanned as a package folder. (The same file was last verified identical at upstream cd04b21a.)

Suggested fix: skip any entry that has a .. segment, and add a test with a ../ workspace entry. A matching guard is small (three lines); I can send it as a PR if you want one.

Not claimed: this does not read or index files outside the project, and I found no way to expose their contents. Only .. segments escape; an absolute path in workspaces did not (tried). I did not trace why the wrong edge lands on src/util.ts rather than on no edge; I only observed that it does and that the control cases do not.

Ngôn ngữ chính
C
Star
73.2k
Fork
4.7k
Merge trung bình
3 giờ 37 phút
Pull request đã merge (30 ngày)
533

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của colbymchenry/codegraph

Tất cả issue của colbymchenry/codegraph

Issue tương tự

Thêm issue về C

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.