|
1 | 1 | import { dirname } from "path";
|
2 |
| -import { findCommonParentDir } from "../common/files"; |
| 2 | +import { containsPath, findCommonParentDir } from "../common/files"; |
3 | 3 | import { findPackRoot } from "../common/ql";
|
4 | 4 |
|
5 | 5 | /**
|
@@ -62,26 +62,15 @@ function findQlPackRootForQueriesWithNoPack(
|
62 | 62 | queryFiles: string[],
|
63 | 63 | workspaceFolders: string[],
|
64 | 64 | ): string {
|
65 |
| - const queryFileWorkspaceFolders = queryFiles.map((queryFile) => |
66 |
| - workspaceFolders.find((workspaceFolder) => |
67 |
| - queryFile.startsWith(workspaceFolder), |
68 |
| - ), |
69 |
| - ); |
70 |
| - |
71 |
| - // Check if any query file is not part of the workspace. |
72 |
| - if (queryFileWorkspaceFolders.includes(undefined)) { |
73 |
| - throw Error( |
74 |
| - "Queries that are not part of a pack need to be part of the workspace", |
75 |
| - ); |
76 |
| - } |
| 65 | + const commonParentDir = findCommonParentDir(...queryFiles); |
77 | 66 |
|
78 |
| - // Check if query files are not in the same workspace folder. |
79 |
| - if (new Set(queryFileWorkspaceFolders).size > 1) { |
80 |
| - throw Error( |
81 |
| - "Queries that are not part of a pack need to be in the same workspace folder", |
82 |
| - ); |
| 67 | + for (const workspaceFolder of workspaceFolders) { |
| 68 | + if (containsPath(workspaceFolder, commonParentDir)) { |
| 69 | + return commonParentDir; |
| 70 | + } |
83 | 71 | }
|
84 | 72 |
|
85 |
| - // They're in the same workspace folder, so we can find a common parent dir. |
86 |
| - return findCommonParentDir(...queryFiles); |
| 73 | + throw Error( |
| 74 | + "All queries must be within the workspace and within the same workspace root", |
| 75 | + ); |
87 | 76 | }
|
0 commit comments