Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c624dc6

Browse files
committed
Merge remote-tracking branch 'origin/main' into feat/esquery-in-playground
2 parents 14066fa + 4fbf0f0 commit c624dc6

File tree

5 files changed

+250
-13
lines changed

5 files changed

+250
-13
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,6 @@ jobs:
288288
git fetch --prune --unshallow
289289
290290
- name: Publish all packages to npm
291-
run: npx lerna publish premajor --loglevel=verbose --canary --exact --force-publish --yes --dist-tag rc-v${major}
291+
run: npx lerna publish premajor --loglevel=verbose --canary --exact --force-publish --yes --dist-tag rc-v6
292292
env:
293293
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

packages/typescript-estree/src/create-program/createProjectProgram.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as ts from 'typescript';
44

55
import { firstDefined } from '../node-utils';
66
import type { ParseSettings } from '../parseSettings';
7+
import { describeFilePath } from './describeFilePath';
78
import { getWatchProgramsForProjects } from './getWatchProgramsForProjects';
89
import type { ASTAndProgram } from './shared';
910
import { getAstFromProgram } from './shared';
@@ -40,19 +41,14 @@ function createProjectProgram(
4041
return astAndProgram;
4142
}
4243

43-
const describeFilePath = (filePath: string): string => {
44-
const relative = path.relative(
45-
parseSettings.tsconfigRootDir || process.cwd(),
46-
filePath,
47-
);
48-
if (parseSettings.tsconfigRootDir) {
49-
return `<tsconfigRootDir>/${relative}`;
50-
}
51-
return `<cwd>/${relative}`;
52-
};
44+
const describeProjectFilePath = (projectFile: string): string =>
45+
describeFilePath(projectFile, parseSettings.tsconfigRootDir);
5346

54-
const describedFilePath = describeFilePath(parseSettings.filePath);
55-
const relativeProjects = parseSettings.projects.map(describeFilePath);
47+
const describedFilePath = describeFilePath(
48+
parseSettings.filePath,
49+
parseSettings.tsconfigRootDir,
50+
);
51+
const relativeProjects = parseSettings.projects.map(describeProjectFilePath);
5652
const describedPrograms =
5753
relativeProjects.length === 1
5854
? relativeProjects[0]
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import path from 'path';
2+
3+
export function describeFilePath(
4+
filePath: string,
5+
tsconfigRootDir: string,
6+
): string {
7+
// If the TSConfig root dir is a parent of the filePath, use
8+
// `<tsconfigRootDir>` as a prefix for the path.
9+
const relative = path.relative(tsconfigRootDir, filePath);
10+
if (relative && !relative.startsWith('..') && !path.isAbsolute(relative)) {
11+
return `<tsconfigRootDir>/${relative}`;
12+
}
13+
14+
// Root-like Mac/Linux (~/*, ~*) or Windows (C:/*, /) paths that aren't
15+
// relative to the TSConfig root dir should be fully described.
16+
// This avoids strings like <tsconfigRootDir>/../../../../repo/file.ts.
17+
// https://github.com/typescript-eslint/typescript-eslint/issues/6289
18+
if (/^[(\w+:)\\/~]/.test(filePath)) {
19+
return filePath;
20+
}
21+
22+
// Similarly, if the relative path would contain a lot of ../.., then
23+
// ignore it and print the file path directly.
24+
if (/\.\.[/\\]\.\./.test(relative)) {
25+
return filePath;
26+
}
27+
28+
// Lastly, since we've eliminated all special cases, we know the cleanest
29+
// path to print is probably the prefixed relative one.
30+
return `<tsconfigRootDir>/${relative}`;
31+
}
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`describeFilePath tsconfigRootDir ./repos/repo filePath ./elsewhere/repo/file.ts 1`] = `"./elsewhere/repo/file.ts"`;
4+
5+
exports[`describeFilePath tsconfigRootDir ./repos/repo filePath ./elsewhere/repo/nested/file.ts 1`] = `"./elsewhere/repo/nested/file.ts"`;
6+
7+
exports[`describeFilePath tsconfigRootDir ./repos/repo filePath ./repos/file.ts 1`] = `"<tsconfigRootDir>/../file.ts"`;
8+
9+
exports[`describeFilePath tsconfigRootDir ./repos/repo filePath ./repos/other/file.ts 1`] = `"<tsconfigRootDir>/../other/file.ts"`;
10+
11+
exports[`describeFilePath tsconfigRootDir ./repos/repo filePath ./repos/repo/file.ts 1`] = `"<tsconfigRootDir>/file.ts"`;
12+
13+
exports[`describeFilePath tsconfigRootDir ./repos/repo filePath ./repos/repo/nested/file.ts 1`] = `"<tsconfigRootDir>/nested/file.ts"`;
14+
15+
exports[`describeFilePath tsconfigRootDir ./repos/repo filePath /elsewhere/repo/file.ts 1`] = `"/elsewhere/repo/file.ts"`;
16+
17+
exports[`describeFilePath tsconfigRootDir ./repos/repo filePath /elsewhere/repo/nested/file.ts 1`] = `"/elsewhere/repo/nested/file.ts"`;
18+
19+
exports[`describeFilePath tsconfigRootDir ./repos/repo filePath /file.ts 1`] = `"/file.ts"`;
20+
21+
exports[`describeFilePath tsconfigRootDir ./repos/repo filePath /nested/file.ts 1`] = `"/nested/file.ts"`;
22+
23+
exports[`describeFilePath tsconfigRootDir ./repos/repo filePath /repos/repo/file.ts 1`] = `"/repos/repo/file.ts"`;
24+
25+
exports[`describeFilePath tsconfigRootDir ./repos/repo filePath /repos/repo/nested/file.ts 1`] = `"/repos/repo/nested/file.ts"`;
26+
27+
exports[`describeFilePath tsconfigRootDir ./repos/repo filePath ~/file.ts 1`] = `"~/file.ts"`;
28+
29+
exports[`describeFilePath tsconfigRootDir ./repos/repo filePath ~/nested/file.ts 1`] = `"~/nested/file.ts"`;
30+
31+
exports[`describeFilePath tsconfigRootDir ./repos/repo filePath ~/nested/file.ts 2`] = `"~/nested/file.ts"`;
32+
33+
exports[`describeFilePath tsconfigRootDir ./repos/repo filePath ~/other/nested/path/to/file.ts 1`] = `"~/other/nested/path/to/file.ts"`;
34+
35+
exports[`describeFilePath tsconfigRootDir ./repos/repo filePath ~/other/repo/file.ts 1`] = `"~/other/repo/file.ts"`;
36+
37+
exports[`describeFilePath tsconfigRootDir ./repos/repo filePath ~/repos/file.ts 1`] = `"~/repos/file.ts"`;
38+
39+
exports[`describeFilePath tsconfigRootDir ./repos/repo filePath ~/repos/other/file.ts 1`] = `"~/repos/other/file.ts"`;
40+
41+
exports[`describeFilePath tsconfigRootDir ./repos/repo filePath ~/repos/other/nested/file.ts 1`] = `"~/repos/other/nested/file.ts"`;
42+
43+
exports[`describeFilePath tsconfigRootDir ./repos/repo filePath ~/repos/repo/file.ts 1`] = `"~/repos/repo/file.ts"`;
44+
45+
exports[`describeFilePath tsconfigRootDir ./repos/repo filePath ~/repos/repo/nested/file.ts 1`] = `"~/repos/repo/nested/file.ts"`;
46+
47+
exports[`describeFilePath tsconfigRootDir ./repos/repo filePath A:/file.ts 1`] = `"A:/file.ts"`;
48+
49+
exports[`describeFilePath tsconfigRootDir ./repos/repo filePath A:/nested/file.ts 1`] = `"A:/nested/file.ts"`;
50+
51+
exports[`describeFilePath tsconfigRootDir ./repos/repo filePath ABC:/file.ts 1`] = `"ABC:/file.ts"`;
52+
53+
exports[`describeFilePath tsconfigRootDir ./repos/repo filePath C:/file.ts 1`] = `"C:/file.ts"`;
54+
55+
exports[`describeFilePath tsconfigRootDir ./repos/repo filePath file.ts 1`] = `"file.ts"`;
56+
57+
exports[`describeFilePath tsconfigRootDir ./repos/repo filePath nested/file.ts 1`] = `"nested/file.ts"`;
58+
59+
exports[`describeFilePath tsconfigRootDir /repos/repo filePath ./elsewhere/repo/file.ts 1`] = `"./elsewhere/repo/file.ts"`;
60+
61+
exports[`describeFilePath tsconfigRootDir /repos/repo filePath ./elsewhere/repo/nested/file.ts 1`] = `"./elsewhere/repo/nested/file.ts"`;
62+
63+
exports[`describeFilePath tsconfigRootDir /repos/repo filePath ./repos/file.ts 1`] = `"./repos/file.ts"`;
64+
65+
exports[`describeFilePath tsconfigRootDir /repos/repo filePath ./repos/other/file.ts 1`] = `"./repos/other/file.ts"`;
66+
67+
exports[`describeFilePath tsconfigRootDir /repos/repo filePath ./repos/repo/file.ts 1`] = `"./repos/repo/file.ts"`;
68+
69+
exports[`describeFilePath tsconfigRootDir /repos/repo filePath ./repos/repo/nested/file.ts 1`] = `"./repos/repo/nested/file.ts"`;
70+
71+
exports[`describeFilePath tsconfigRootDir /repos/repo filePath /elsewhere/repo/file.ts 1`] = `"/elsewhere/repo/file.ts"`;
72+
73+
exports[`describeFilePath tsconfigRootDir /repos/repo filePath /elsewhere/repo/nested/file.ts 1`] = `"/elsewhere/repo/nested/file.ts"`;
74+
75+
exports[`describeFilePath tsconfigRootDir /repos/repo filePath /file.ts 1`] = `"/file.ts"`;
76+
77+
exports[`describeFilePath tsconfigRootDir /repos/repo filePath /nested/file.ts 1`] = `"/nested/file.ts"`;
78+
79+
exports[`describeFilePath tsconfigRootDir /repos/repo filePath /repos/repo/file.ts 1`] = `"<tsconfigRootDir>/file.ts"`;
80+
81+
exports[`describeFilePath tsconfigRootDir /repos/repo filePath /repos/repo/nested/file.ts 1`] = `"<tsconfigRootDir>/nested/file.ts"`;
82+
83+
exports[`describeFilePath tsconfigRootDir /repos/repo filePath ~/file.ts 1`] = `"~/file.ts"`;
84+
85+
exports[`describeFilePath tsconfigRootDir /repos/repo filePath ~/nested/file.ts 1`] = `"~/nested/file.ts"`;
86+
87+
exports[`describeFilePath tsconfigRootDir /repos/repo filePath ~/nested/file.ts 2`] = `"~/nested/file.ts"`;
88+
89+
exports[`describeFilePath tsconfigRootDir /repos/repo filePath ~/other/nested/path/to/file.ts 1`] = `"~/other/nested/path/to/file.ts"`;
90+
91+
exports[`describeFilePath tsconfigRootDir /repos/repo filePath ~/other/repo/file.ts 1`] = `"~/other/repo/file.ts"`;
92+
93+
exports[`describeFilePath tsconfigRootDir /repos/repo filePath ~/repos/file.ts 1`] = `"~/repos/file.ts"`;
94+
95+
exports[`describeFilePath tsconfigRootDir /repos/repo filePath ~/repos/other/file.ts 1`] = `"~/repos/other/file.ts"`;
96+
97+
exports[`describeFilePath tsconfigRootDir /repos/repo filePath ~/repos/other/nested/file.ts 1`] = `"~/repos/other/nested/file.ts"`;
98+
99+
exports[`describeFilePath tsconfigRootDir /repos/repo filePath ~/repos/repo/file.ts 1`] = `"~/repos/repo/file.ts"`;
100+
101+
exports[`describeFilePath tsconfigRootDir /repos/repo filePath ~/repos/repo/nested/file.ts 1`] = `"~/repos/repo/nested/file.ts"`;
102+
103+
exports[`describeFilePath tsconfigRootDir /repos/repo filePath A:/file.ts 1`] = `"A:/file.ts"`;
104+
105+
exports[`describeFilePath tsconfigRootDir /repos/repo filePath A:/nested/file.ts 1`] = `"A:/nested/file.ts"`;
106+
107+
exports[`describeFilePath tsconfigRootDir /repos/repo filePath ABC:/file.ts 1`] = `"ABC:/file.ts"`;
108+
109+
exports[`describeFilePath tsconfigRootDir /repos/repo filePath C:/file.ts 1`] = `"C:/file.ts"`;
110+
111+
exports[`describeFilePath tsconfigRootDir /repos/repo filePath file.ts 1`] = `"file.ts"`;
112+
113+
exports[`describeFilePath tsconfigRootDir /repos/repo filePath nested/file.ts 1`] = `"nested/file.ts"`;
114+
115+
exports[`describeFilePath tsconfigRootDir ~/repos/repo filePath ./elsewhere/repo/file.ts 1`] = `"./elsewhere/repo/file.ts"`;
116+
117+
exports[`describeFilePath tsconfigRootDir ~/repos/repo filePath ./elsewhere/repo/nested/file.ts 1`] = `"./elsewhere/repo/nested/file.ts"`;
118+
119+
exports[`describeFilePath tsconfigRootDir ~/repos/repo filePath ./repos/file.ts 1`] = `"./repos/file.ts"`;
120+
121+
exports[`describeFilePath tsconfigRootDir ~/repos/repo filePath ./repos/other/file.ts 1`] = `"./repos/other/file.ts"`;
122+
123+
exports[`describeFilePath tsconfigRootDir ~/repos/repo filePath ./repos/repo/file.ts 1`] = `"./repos/repo/file.ts"`;
124+
125+
exports[`describeFilePath tsconfigRootDir ~/repos/repo filePath ./repos/repo/nested/file.ts 1`] = `"./repos/repo/nested/file.ts"`;
126+
127+
exports[`describeFilePath tsconfigRootDir ~/repos/repo filePath /elsewhere/repo/file.ts 1`] = `"/elsewhere/repo/file.ts"`;
128+
129+
exports[`describeFilePath tsconfigRootDir ~/repos/repo filePath /elsewhere/repo/nested/file.ts 1`] = `"/elsewhere/repo/nested/file.ts"`;
130+
131+
exports[`describeFilePath tsconfigRootDir ~/repos/repo filePath /file.ts 1`] = `"/file.ts"`;
132+
133+
exports[`describeFilePath tsconfigRootDir ~/repos/repo filePath /nested/file.ts 1`] = `"/nested/file.ts"`;
134+
135+
exports[`describeFilePath tsconfigRootDir ~/repos/repo filePath /repos/repo/file.ts 1`] = `"/repos/repo/file.ts"`;
136+
137+
exports[`describeFilePath tsconfigRootDir ~/repos/repo filePath /repos/repo/nested/file.ts 1`] = `"/repos/repo/nested/file.ts"`;
138+
139+
exports[`describeFilePath tsconfigRootDir ~/repos/repo filePath ~/file.ts 1`] = `"~/file.ts"`;
140+
141+
exports[`describeFilePath tsconfigRootDir ~/repos/repo filePath ~/nested/file.ts 1`] = `"~/nested/file.ts"`;
142+
143+
exports[`describeFilePath tsconfigRootDir ~/repos/repo filePath ~/nested/file.ts 2`] = `"~/nested/file.ts"`;
144+
145+
exports[`describeFilePath tsconfigRootDir ~/repos/repo filePath ~/other/nested/path/to/file.ts 1`] = `"~/other/nested/path/to/file.ts"`;
146+
147+
exports[`describeFilePath tsconfigRootDir ~/repos/repo filePath ~/other/repo/file.ts 1`] = `"~/other/repo/file.ts"`;
148+
149+
exports[`describeFilePath tsconfigRootDir ~/repos/repo filePath ~/repos/file.ts 1`] = `"~/repos/file.ts"`;
150+
151+
exports[`describeFilePath tsconfigRootDir ~/repos/repo filePath ~/repos/other/file.ts 1`] = `"~/repos/other/file.ts"`;
152+
153+
exports[`describeFilePath tsconfigRootDir ~/repos/repo filePath ~/repos/other/nested/file.ts 1`] = `"~/repos/other/nested/file.ts"`;
154+
155+
exports[`describeFilePath tsconfigRootDir ~/repos/repo filePath ~/repos/repo/file.ts 1`] = `"<tsconfigRootDir>/file.ts"`;
156+
157+
exports[`describeFilePath tsconfigRootDir ~/repos/repo filePath ~/repos/repo/nested/file.ts 1`] = `"<tsconfigRootDir>/nested/file.ts"`;
158+
159+
exports[`describeFilePath tsconfigRootDir ~/repos/repo filePath A:/file.ts 1`] = `"A:/file.ts"`;
160+
161+
exports[`describeFilePath tsconfigRootDir ~/repos/repo filePath A:/nested/file.ts 1`] = `"A:/nested/file.ts"`;
162+
163+
exports[`describeFilePath tsconfigRootDir ~/repos/repo filePath ABC:/file.ts 1`] = `"ABC:/file.ts"`;
164+
165+
exports[`describeFilePath tsconfigRootDir ~/repos/repo filePath C:/file.ts 1`] = `"C:/file.ts"`;
166+
167+
exports[`describeFilePath tsconfigRootDir ~/repos/repo filePath file.ts 1`] = `"file.ts"`;
168+
169+
exports[`describeFilePath tsconfigRootDir ~/repos/repo filePath nested/file.ts 1`] = `"nested/file.ts"`;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { describeFilePath } from '../../src/create-program/describeFilePath';
2+
3+
describe('describeFilePath', () => {
4+
describe.each(['./repos/repo', '/repos/repo', '~/repos/repo'])(
5+
'tsconfigRootDir %s',
6+
tsconfigRootDir => {
7+
test.each([
8+
'./elsewhere/repo/file.ts',
9+
'./elsewhere/repo/nested/file.ts',
10+
'./repos/file.ts',
11+
'./repos/other/file.ts',
12+
'./repos/repo/file.ts',
13+
'./repos/repo/nested/file.ts',
14+
'/elsewhere/repo/file.ts',
15+
'/elsewhere/repo/nested/file.ts',
16+
'/file.ts',
17+
'/nested/file.ts',
18+
'/repos/repo/file.ts',
19+
'/repos/repo/nested/file.ts',
20+
'~/file.ts',
21+
'~/nested/file.ts',
22+
'~/nested/file.ts',
23+
'~/other/nested/path/to/file.ts',
24+
'~/other/repo/file.ts',
25+
'~/repos/file.ts',
26+
'~/repos/other/file.ts',
27+
'~/repos/other/nested/file.ts',
28+
'~/repos/repo/file.ts',
29+
'~/repos/repo/nested/file.ts',
30+
'A:/file.ts',
31+
'A:/nested/file.ts',
32+
'ABC:/file.ts',
33+
'C:/file.ts',
34+
'file.ts',
35+
'nested/file.ts',
36+
])('filePath %s', filePath => {
37+
expect(describeFilePath(filePath, tsconfigRootDir)).toMatchSnapshot();
38+
});
39+
},
40+
);
41+
});

0 commit comments

Comments
 (0)