@gosukiwi/eslint-plugin-colocate 0.0.2
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.
- package/LICENSE +21 -0
- package/README.md +197 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +12 -0
- package/dist/lib/derived.d.ts +4 -0
- package/dist/lib/derived.js +15 -0
- package/dist/lib/findings.d.ts +9 -0
- package/dist/lib/findings.js +96 -0
- package/dist/lib/fs-safe.d.ts +8 -0
- package/dist/lib/fs-safe.js +55 -0
- package/dist/lib/gates.d.ts +10 -0
- package/dist/lib/gates.js +46 -0
- package/dist/lib/graph-cache.d.ts +5 -0
- package/dist/lib/graph-cache.js +162 -0
- package/dist/lib/graph.d.ts +20 -0
- package/dist/lib/graph.js +109 -0
- package/dist/lib/named-door.d.ts +6 -0
- package/dist/lib/named-door.js +361 -0
- package/dist/lib/owners.d.ts +22 -0
- package/dist/lib/owners.js +386 -0
- package/dist/lib/parse.d.ts +4 -0
- package/dist/lib/parse.js +59 -0
- package/dist/lib/paths.d.ts +2 -0
- package/dist/lib/paths.js +8 -0
- package/dist/lib/require-binding.d.ts +5 -0
- package/dist/lib/require-binding.js +72 -0
- package/dist/lib/resolve.d.ts +9 -0
- package/dist/lib/resolve.js +161 -0
- package/dist/lib/root.d.ts +1 -0
- package/dist/lib/root.js +27 -0
- package/dist/lib/scope.d.ts +8 -0
- package/dist/lib/scope.js +58 -0
- package/dist/lib/subject.d.ts +16 -0
- package/dist/lib/subject.js +61 -0
- package/dist/lib/walk.d.ts +10 -0
- package/dist/lib/walk.js +97 -0
- package/dist/rules/entry.d.ts +3 -0
- package/dist/rules/entry.js +141 -0
- package/dist/rules/ownership.d.ts +3 -0
- package/dist/rules/ownership.js +45 -0
- package/package.json +45 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type ResolutionSettings } from "./resolve.js";
|
|
2
|
+
export interface Graph {
|
|
3
|
+
readonly importers: ReadonlyMap<string, readonly string[]>;
|
|
4
|
+
readonly files: readonly string[];
|
|
5
|
+
}
|
|
6
|
+
export declare function graphHasFile(graph: Graph, filePath: string): boolean;
|
|
7
|
+
export declare function graphFilesInDir(graph: Graph, dir: string): readonly string[];
|
|
8
|
+
export declare function canonicalGraphPath(graph: Graph, filePath: string): string;
|
|
9
|
+
export declare const getGraphResolutionSettings: ((graph: Graph) => ResolutionSettings) & {
|
|
10
|
+
prime: (graph: Graph, value: ResolutionSettings) => void;
|
|
11
|
+
};
|
|
12
|
+
export declare function buildGraph(rootDir: string, ignoreGlobs: string[]): Graph;
|
|
13
|
+
export declare function buildGraphFromFiles(files: readonly string[], resolvedRoot: string): {
|
|
14
|
+
graph: Graph;
|
|
15
|
+
configPaths: string[];
|
|
16
|
+
};
|
|
17
|
+
export declare function buildGraphWithConfigs(rootDir: string, ignoreGlobs: string[]): {
|
|
18
|
+
graph: Graph;
|
|
19
|
+
configPaths: string[];
|
|
20
|
+
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
import { derivedFromGraph } from "./derived.js";
|
|
4
|
+
import { safeReadFile, safeRealpath } from "./fs-safe.js";
|
|
5
|
+
import { extractSpecifiers } from "./parse.js";
|
|
6
|
+
import { createResolutionSettings, resolveSpecifier } from "./resolve.js";
|
|
7
|
+
import { collectSourceFiles } from "./walk.js";
|
|
8
|
+
const graphFileSet = derivedFromGraph((graph) => new Set(graph.files));
|
|
9
|
+
export function graphHasFile(graph, filePath) {
|
|
10
|
+
return graphFileSet(graph).has(filePath);
|
|
11
|
+
}
|
|
12
|
+
function filesByParentDir(files) {
|
|
13
|
+
const byDir = new Map();
|
|
14
|
+
for (const file of files) {
|
|
15
|
+
const dir = path.dirname(file);
|
|
16
|
+
const list = byDir.get(dir);
|
|
17
|
+
if (list === undefined) {
|
|
18
|
+
byDir.set(dir, [file]);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
list.push(file);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return byDir;
|
|
25
|
+
}
|
|
26
|
+
const graphFilesByDir = derivedFromGraph((graph) => filesByParentDir(graph.files));
|
|
27
|
+
export function graphFilesInDir(graph, dir) {
|
|
28
|
+
return graphFilesByDir(graph).get(dir) ?? [];
|
|
29
|
+
}
|
|
30
|
+
function foldGraphPath(filePath) {
|
|
31
|
+
const normalized = filePath.normalize("NFC");
|
|
32
|
+
return ts.sys.useCaseSensitiveFileNames
|
|
33
|
+
? normalized
|
|
34
|
+
: normalized.toLowerCase();
|
|
35
|
+
}
|
|
36
|
+
const graphFilesByFoldedPath = derivedFromGraph((graph) => new Map(graph.files.map((file) => [foldGraphPath(file), file])));
|
|
37
|
+
function graphFileForPath(fileSet, filesByFoldedPath, filePath) {
|
|
38
|
+
if (fileSet.has(filePath)) {
|
|
39
|
+
return filePath;
|
|
40
|
+
}
|
|
41
|
+
return filesByFoldedPath.get(foldGraphPath(filePath));
|
|
42
|
+
}
|
|
43
|
+
export function canonicalGraphPath(graph, filePath) {
|
|
44
|
+
return (graphFileForPath(graphFileSet(graph), graphFilesByFoldedPath(graph), filePath) ?? filePath);
|
|
45
|
+
}
|
|
46
|
+
function noProjectResolutionSettings() {
|
|
47
|
+
const resolutionOptions = {
|
|
48
|
+
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
49
|
+
allowJs: true,
|
|
50
|
+
};
|
|
51
|
+
return {
|
|
52
|
+
options: resolutionOptions,
|
|
53
|
+
cache: ts.createModuleResolutionCache("/", (fileName) => fileName, resolutionOptions),
|
|
54
|
+
configPaths: [],
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export const getGraphResolutionSettings = derivedFromGraph((_graph) => noProjectResolutionSettings());
|
|
58
|
+
export function buildGraph(rootDir, ignoreGlobs) {
|
|
59
|
+
return buildGraphWithConfigs(rootDir, ignoreGlobs).graph;
|
|
60
|
+
}
|
|
61
|
+
export function buildGraphFromFiles(files, resolvedRoot) {
|
|
62
|
+
const fileSet = new Set(files);
|
|
63
|
+
const filesByFoldedPath = new Map(files.map((file) => [foldGraphPath(file), file]));
|
|
64
|
+
const importers = new Map();
|
|
65
|
+
const settings = createResolutionSettings(resolvedRoot);
|
|
66
|
+
for (const file of files) {
|
|
67
|
+
const realFile = safeRealpath(file);
|
|
68
|
+
if (realFile !== undefined && realFile !== file) {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
const content = safeReadFile(file);
|
|
72
|
+
if (content === undefined) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const fromDir = path.dirname(file);
|
|
76
|
+
for (const specifier of extractSpecifiers(content, file)) {
|
|
77
|
+
const resolved = resolveSpecifier(specifier, fromDir, settings);
|
|
78
|
+
if (resolved === undefined) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
const target = graphFileForPath(fileSet, filesByFoldedPath, resolved);
|
|
82
|
+
if (target === undefined || target === file) {
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
const existing = importers.get(target);
|
|
86
|
+
if (existing === undefined) {
|
|
87
|
+
importers.set(target, [file]);
|
|
88
|
+
}
|
|
89
|
+
else if (!existing.includes(file)) {
|
|
90
|
+
existing.push(file);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const graph = { importers, files };
|
|
95
|
+
getGraphResolutionSettings.prime(graph, settings);
|
|
96
|
+
graphFileSet.prime(graph, fileSet);
|
|
97
|
+
graphFilesByFoldedPath.prime(graph, filesByFoldedPath);
|
|
98
|
+
graphFilesByDir.prime(graph, filesByParentDir(files));
|
|
99
|
+
return { graph, configPaths: settings.configPaths };
|
|
100
|
+
}
|
|
101
|
+
export function buildGraphWithConfigs(rootDir, ignoreGlobs) {
|
|
102
|
+
const resolvedRoot = safeRealpath(rootDir);
|
|
103
|
+
if (resolvedRoot === undefined) {
|
|
104
|
+
return { graph: { importers: new Map(), files: [] }, configPaths: [] };
|
|
105
|
+
}
|
|
106
|
+
const { files } = collectSourceFiles(resolvedRoot, ignoreGlobs);
|
|
107
|
+
const { graph, configPaths } = buildGraphFromFiles(files, resolvedRoot);
|
|
108
|
+
return { graph, configPaths };
|
|
109
|
+
}
|
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
import { isEntryFile } from "./gates.js";
|
|
4
|
+
import { safeReadFile } from "./fs-safe.js";
|
|
5
|
+
import { canonicalGraphPath, getGraphResolutionSettings, graphHasFile, } from "./graph.js";
|
|
6
|
+
import { parseSourceFile, stringLiteralText } from "./parse.js";
|
|
7
|
+
import { scopeBindsRequire } from "./require-binding.js";
|
|
8
|
+
import { resolveSpecifier } from "./resolve.js";
|
|
9
|
+
export function isNamedDoor(filePath) {
|
|
10
|
+
if (!isEntryFile(filePath)) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
return path.basename(filePath, path.extname(filePath)) !== "index";
|
|
14
|
+
}
|
|
15
|
+
function isValueReexport(node) {
|
|
16
|
+
if (node.isTypeOnly) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
if (node.exportClause === undefined) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
if (ts.isNamedExports(node.exportClause)) {
|
|
23
|
+
return node.exportClause.elements.some((element) => !element.isTypeOnly);
|
|
24
|
+
}
|
|
25
|
+
if (ts.isNamespaceExport(node.exportClause)) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
function peelValueExpression(node) {
|
|
31
|
+
let current = node;
|
|
32
|
+
for (;;) {
|
|
33
|
+
if (ts.isParenthesizedExpression(current)) {
|
|
34
|
+
current = current.expression;
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (ts.isAsExpression(current)) {
|
|
38
|
+
current = current.expression;
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (ts.isTypeAssertionExpression(current)) {
|
|
42
|
+
current = current.expression;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (ts.isNonNullExpression(current)) {
|
|
46
|
+
current = current.expression;
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (ts.isSatisfiesExpression(current)) {
|
|
50
|
+
current = current.expression;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
return current;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function isRealRequire(node, requireIsCjs) {
|
|
57
|
+
return (requireIsCjs &&
|
|
58
|
+
ts.isIdentifier(node.expression) &&
|
|
59
|
+
node.expression.text === "require" &&
|
|
60
|
+
node.arguments.length === 1 &&
|
|
61
|
+
ts.isStringLiteralLike(node.arguments[0]));
|
|
62
|
+
}
|
|
63
|
+
function bindRequireNames(name, target, origins) {
|
|
64
|
+
if (ts.isIdentifier(name)) {
|
|
65
|
+
origins.set(name.text, target);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (ts.isObjectBindingPattern(name)) {
|
|
69
|
+
for (const element of name.elements) {
|
|
70
|
+
if (ts.isOmittedExpression(element)) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
bindRequireNames(element.name, target, origins);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function hasExportModifier(node) {
|
|
78
|
+
return (ts.canHaveModifiers(node) &&
|
|
79
|
+
node.modifiers !== undefined &&
|
|
80
|
+
node.modifiers.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword));
|
|
81
|
+
}
|
|
82
|
+
function originFromBindingName(name, origins) {
|
|
83
|
+
if (ts.isIdentifier(name)) {
|
|
84
|
+
return origins.get(name.text);
|
|
85
|
+
}
|
|
86
|
+
if (ts.isObjectBindingPattern(name)) {
|
|
87
|
+
for (const element of name.elements) {
|
|
88
|
+
if (ts.isOmittedExpression(element)) {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
const target = originFromBindingName(element.name, origins);
|
|
92
|
+
if (target !== undefined) {
|
|
93
|
+
return target;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
function recordClauseBindings(clause, target, origins) {
|
|
100
|
+
if (clause.name !== undefined) {
|
|
101
|
+
origins.set(clause.name.text, target);
|
|
102
|
+
}
|
|
103
|
+
const bindings = clause.namedBindings;
|
|
104
|
+
if (bindings === undefined) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (ts.isNamespaceImport(bindings)) {
|
|
108
|
+
origins.set(bindings.name.text, target);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (ts.isNamedImports(bindings)) {
|
|
112
|
+
for (const element of bindings.elements) {
|
|
113
|
+
if (!element.isTypeOnly) {
|
|
114
|
+
origins.set(element.name.text, target);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function recordImportOrigins(node, scan) {
|
|
120
|
+
const clause = node.importClause;
|
|
121
|
+
if (clause === undefined || clause.isTypeOnly) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const specifier = stringLiteralText(node.moduleSpecifier);
|
|
125
|
+
if (specifier === undefined) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const target = scan.resolve(specifier);
|
|
129
|
+
if (target === undefined) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
recordClauseBindings(clause, target, scan.origins);
|
|
133
|
+
}
|
|
134
|
+
function recordImportEqualsOrigins(node, scan) {
|
|
135
|
+
if (!ts.isExternalModuleReference(node.moduleReference) ||
|
|
136
|
+
!ts.isIdentifier(node.name)) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const specifier = stringLiteralText(node.moduleReference.expression);
|
|
140
|
+
if (specifier === undefined) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const target = scan.resolve(specifier);
|
|
144
|
+
if (target === undefined) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
scan.origins.set(node.name.text, target);
|
|
148
|
+
}
|
|
149
|
+
function recordRequireDeclaration(declaration, call, scan) {
|
|
150
|
+
if (!isRealRequire(call, scan.requireIsCjs)) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const specifier = stringLiteralText(call.arguments[0]);
|
|
154
|
+
if (specifier === undefined) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
const target = scan.resolve(specifier);
|
|
158
|
+
if (target === undefined) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
bindRequireNames(declaration.name, target, scan.origins);
|
|
162
|
+
}
|
|
163
|
+
function recordAliasDeclaration(declaration, peeled, scan) {
|
|
164
|
+
if (!ts.isIdentifier(declaration.name) || !ts.isIdentifier(peeled)) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
const target = scan.origins.get(peeled.text);
|
|
168
|
+
if (target === undefined) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
scan.origins.set(declaration.name.text, target);
|
|
172
|
+
}
|
|
173
|
+
function recordDeclarationOrigin(declaration, scan) {
|
|
174
|
+
if (declaration.initializer === undefined) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
const peeled = peelValueExpression(declaration.initializer);
|
|
178
|
+
if (ts.isCallExpression(peeled)) {
|
|
179
|
+
recordRequireDeclaration(declaration, peeled, scan);
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
recordAliasDeclaration(declaration, peeled, scan);
|
|
183
|
+
}
|
|
184
|
+
function recordVariableOrigins(node, scan) {
|
|
185
|
+
for (const declaration of node.declarationList.declarations) {
|
|
186
|
+
recordDeclarationOrigin(declaration, scan);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
function collectOrigins(node, scan) {
|
|
190
|
+
if (ts.isImportDeclaration(node)) {
|
|
191
|
+
recordImportOrigins(node, scan);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
if (ts.isImportEqualsDeclaration(node)) {
|
|
195
|
+
recordImportEqualsOrigins(node, scan);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
if (ts.isVariableStatement(node)) {
|
|
199
|
+
recordVariableOrigins(node, scan);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
function pushExportTarget(scan, node, target) {
|
|
203
|
+
scan.results.push({ target, pos: node.getStart(scan.sourceFile) });
|
|
204
|
+
}
|
|
205
|
+
function firstValueNamedExportTarget(elements, origins) {
|
|
206
|
+
for (const element of elements) {
|
|
207
|
+
if (element.isTypeOnly) {
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
const localName = (element.propertyName !== undefined &&
|
|
211
|
+
ts.isIdentifier(element.propertyName)
|
|
212
|
+
? element.propertyName.text
|
|
213
|
+
: undefined) ?? element.name.text;
|
|
214
|
+
const target = origins.get(localName);
|
|
215
|
+
if (target !== undefined) {
|
|
216
|
+
return target;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return undefined;
|
|
220
|
+
}
|
|
221
|
+
function recordModuleReexport(node, scan) {
|
|
222
|
+
if (node.moduleSpecifier === undefined ||
|
|
223
|
+
!ts.isStringLiteralLike(node.moduleSpecifier) ||
|
|
224
|
+
!isValueReexport(node)) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
const target = scan.resolve(node.moduleSpecifier.text);
|
|
228
|
+
if (target === undefined) {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
pushExportTarget(scan, node, target);
|
|
232
|
+
}
|
|
233
|
+
function recordLocalExport(node, scan) {
|
|
234
|
+
if (node.exportClause === undefined ||
|
|
235
|
+
!ts.isNamedExports(node.exportClause) ||
|
|
236
|
+
node.isTypeOnly) {
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
const target = firstValueNamedExportTarget(node.exportClause.elements, scan.origins);
|
|
240
|
+
if (target === undefined) {
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
pushExportTarget(scan, node, target);
|
|
244
|
+
}
|
|
245
|
+
function recordExportDeclaration(node, scan) {
|
|
246
|
+
if (node.moduleSpecifier !== undefined) {
|
|
247
|
+
recordModuleReexport(node, scan);
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
recordLocalExport(node, scan);
|
|
251
|
+
}
|
|
252
|
+
function recordIdentifierExport(node, name, scan) {
|
|
253
|
+
const target = scan.origins.get(name);
|
|
254
|
+
if (target === undefined) {
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
pushExportTarget(scan, node, target);
|
|
258
|
+
}
|
|
259
|
+
function recordRequireExport(node, call, scan) {
|
|
260
|
+
if (!isRealRequire(call, scan.requireIsCjs)) {
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
const specifier = stringLiteralText(call.arguments[0]);
|
|
264
|
+
if (specifier === undefined) {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
const target = scan.resolve(specifier);
|
|
268
|
+
if (target === undefined) {
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
pushExportTarget(scan, node, target);
|
|
272
|
+
}
|
|
273
|
+
function recordExportAssignment(node, scan) {
|
|
274
|
+
const peeled = peelValueExpression(node.expression);
|
|
275
|
+
if (ts.isIdentifier(peeled)) {
|
|
276
|
+
recordIdentifierExport(node, peeled.text, scan);
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
if (ts.isCallExpression(peeled)) {
|
|
280
|
+
recordRequireExport(node, peeled, scan);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
function recordExportedImportEquals(node, scan) {
|
|
284
|
+
if (!ts.isImportEqualsDeclaration(node) || !ts.isIdentifier(node.name)) {
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
const target = scan.origins.get(node.name.text);
|
|
288
|
+
if (target === undefined) {
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
pushExportTarget(scan, node, target);
|
|
292
|
+
}
|
|
293
|
+
function recordExportedVariable(node, scan) {
|
|
294
|
+
if (!ts.isVariableStatement(node)) {
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
for (const declaration of node.declarationList.declarations) {
|
|
298
|
+
const target = originFromBindingName(declaration.name, scan.origins);
|
|
299
|
+
if (target === undefined) {
|
|
300
|
+
continue;
|
|
301
|
+
}
|
|
302
|
+
pushExportTarget(scan, node, target);
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
function checkExports(node, scan) {
|
|
307
|
+
if (ts.isExportDeclaration(node)) {
|
|
308
|
+
recordExportDeclaration(node, scan);
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
if (ts.isExportAssignment(node)) {
|
|
312
|
+
recordExportAssignment(node, scan);
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
if (hasExportModifier(node)) {
|
|
316
|
+
recordExportedImportEquals(node, scan);
|
|
317
|
+
recordExportedVariable(node, scan);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
export function namedDoorReexports(filePath, graph, content) {
|
|
321
|
+
if (!isNamedDoor(filePath)) {
|
|
322
|
+
return [];
|
|
323
|
+
}
|
|
324
|
+
const source = typeof content === "string"
|
|
325
|
+
? content
|
|
326
|
+
: safeReadFile(filePath);
|
|
327
|
+
if (source === undefined) {
|
|
328
|
+
return [];
|
|
329
|
+
}
|
|
330
|
+
const sourceFile = parseSourceFile(filePath, source);
|
|
331
|
+
const settings = getGraphResolutionSettings(graph);
|
|
332
|
+
const fromDir = path.dirname(filePath);
|
|
333
|
+
const results = [];
|
|
334
|
+
const origins = new Map();
|
|
335
|
+
const resolveInGraph = (specifier) => {
|
|
336
|
+
const resolved = resolveSpecifier(specifier, fromDir, settings);
|
|
337
|
+
if (resolved === undefined) {
|
|
338
|
+
return undefined;
|
|
339
|
+
}
|
|
340
|
+
const target = canonicalGraphPath(graph, resolved);
|
|
341
|
+
if (!graphHasFile(graph, target)) {
|
|
342
|
+
return undefined;
|
|
343
|
+
}
|
|
344
|
+
return target;
|
|
345
|
+
};
|
|
346
|
+
const requireIsCjs = !scopeBindsRequire(sourceFile);
|
|
347
|
+
const scan = {
|
|
348
|
+
resolve: resolveInGraph,
|
|
349
|
+
origins,
|
|
350
|
+
results,
|
|
351
|
+
sourceFile,
|
|
352
|
+
requireIsCjs,
|
|
353
|
+
};
|
|
354
|
+
for (const statement of sourceFile.statements) {
|
|
355
|
+
collectOrigins(statement, scan);
|
|
356
|
+
}
|
|
357
|
+
for (const statement of sourceFile.statements) {
|
|
358
|
+
checkExports(statement, scan);
|
|
359
|
+
}
|
|
360
|
+
return results;
|
|
361
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type Graph } from "./graph.js";
|
|
2
|
+
export interface OwnershipContext {
|
|
3
|
+
graph: Graph;
|
|
4
|
+
rootDir: string;
|
|
5
|
+
layerDirs: string[];
|
|
6
|
+
}
|
|
7
|
+
export declare function collectReExports(indexFile: string, dir: string, graph: Graph): string[];
|
|
8
|
+
export interface Owner {
|
|
9
|
+
kind: "folder" | "standalone";
|
|
10
|
+
path: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function getOwner(filePath: string, graph: Graph, rootDir: string): Owner;
|
|
13
|
+
export declare const getShells: ((graph: Graph) => Set<string>) & {
|
|
14
|
+
prime: (graph: Graph, value: Set<string>) => void;
|
|
15
|
+
};
|
|
16
|
+
export declare function getColocationConsumers(filePath: string, graph: Graph, shells: Set<string>): string[];
|
|
17
|
+
export declare function collectLayerDirectories(cwd: string, layerGlobs: string[], rootDir?: string): string[];
|
|
18
|
+
export declare function resolveLayerDirectories(graph: Graph, cwd: string, layerGlobs: string[], rootDir?: string): string[];
|
|
19
|
+
export declare function isLayerPublicModule(filePath: string, layerDirs: string[]): boolean;
|
|
20
|
+
export declare function shouldSkipColocation(filePath: string, ctx: OwnershipContext): boolean;
|
|
21
|
+
export declare function isPrivateOutsideOwner(filePath: string, ctx: OwnershipContext): boolean;
|
|
22
|
+
export declare function getSharedColocationIssue(filePath: string, ctx: OwnershipContext): "sharedTooHigh" | "sharedInsideOwner" | undefined;
|