дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 17:21:13 +02:00
fix(project-tree): don't offer Python Package in a nested non-Python module's roots (#6028)
In a project with a root Python build file and a nested JavaScript app (frontend/package.json), New inside frontend/src offered Python Package: any folder under a Python build file counted as Python, even inside a root a deeper non-Python build file detected. The innermost claim now wins; folders outside those roots, and roots a Python build file claimed first, keep Python Package. Co-authored-by: audichuang <[email protected]>
Цей коміт міститься в:
1 джерело
aa1a027162
коміт
f8a148c06d
2 files changed
+31
-4
No files matched your search
@@ -20,8 +20,16 @@ export function packageKindAt(
|
||||
): PackageKind | null {
|
||||
if (rootFor(roots, rel)?.kind === "excluded") return null;
|
||||
if (isJvmSourcePackage(rel, roots)) return "jvm";
|
||||
const python = [...roots, ...detected].some(
|
||||
(r) => r.detectedFrom && PY_BUILD.test(r.detectedFrom) && within(rel, moduleDir(r.detectedFrom)),
|
||||
);
|
||||
return python ? "python" : null;
|
||||
// A root `pyproject.toml` must not claim `frontend/src`, a root that
|
||||
// `frontend/package.json` detected, unless a deeper Python module holds the folder.
|
||||
let python = -1;
|
||||
let other = -1;
|
||||
for (const r of [...roots, ...detected]) {
|
||||
if (!r.detectedFrom) continue;
|
||||
if (PY_BUILD.test(r.detectedFrom)) {
|
||||
const dir = moduleDir(r.detectedFrom);
|
||||
if (within(rel, dir)) python = Math.max(python, dir.length);
|
||||
} else if (within(rel, r.path)) other = Math.max(other, r.path.length);
|
||||
}
|
||||
return python >= 0 && python >= other ? "python" : null;
|
||||
}
|
||||
@@ -72,6 +72,25 @@ describe("New › Package", () => {
|
||||
expect(packageKindAt("build/classes", synced)).toBeNull();
|
||||
});
|
||||
|
||||
it("keeps a nested non-Python module out of a root-level Python project", () => {
|
||||
// The roots detection reports for a root `pyproject.toml` next to `frontend/package.json`.
|
||||
const mixed = [
|
||||
root("src", "source", "pyproject.toml"),
|
||||
root("frontend/src", "source", "frontend/package.json"),
|
||||
root("frontend/node_modules", "excluded", "frontend/package.json"),
|
||||
];
|
||||
expect(packageKindAt("frontend/src/components", mixed)).toBeNull();
|
||||
expect(packageKindAt("src/app", mixed)).toBe("python");
|
||||
expect(packageKindAt("scripts", mixed)).toBe("python");
|
||||
});
|
||||
|
||||
it("keeps Python packages next to a nested package.json outside its roots", () => {
|
||||
// A Django app folder with its own `package.json` for front-end tooling.
|
||||
const django = [root("", "source", "pyproject.toml"), root("web/node_modules", "excluded", "web/package.json")];
|
||||
expect(packageKindAt("web/blog", django)).toBe("python");
|
||||
expect(packageKindAt("web", django)).toBe("python");
|
||||
});
|
||||
|
||||
it("validates dotted package names", () => {
|
||||
expect(packageSegments("com.acme.util", "jvm")).toEqual({ segments: ["com", "acme", "util"], error: null });
|
||||
expect(packageSegments("com..x", "jvm").error).toMatch(/Not a valid package name/);
|
||||
|
||||
Reference in new issue
Заблокувати користувача