@atlaskit/eslint-plugin-platform 2.7.2 → 2.9.0
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/CHANGELOG.md +16 -0
- package/dist/cjs/index.js +19 -3
- package/dist/cjs/rules/ensure-use-sync-external-store-server-snapshot/index.js +41 -0
- package/dist/cjs/rules/feature-gating/valid-gate-name/index.js +60 -0
- package/dist/cjs/rules/import/no-barrel-entry-imports/index.js +1279 -0
- package/dist/cjs/rules/import/no-barrel-entry-jest-mock/index.js +1659 -0
- package/dist/cjs/rules/import/no-conversation-assistant-barrel-imports/index.js +43 -0
- package/dist/cjs/rules/import/no-jest-mock-barrel-files/index.js +1402 -0
- package/dist/cjs/rules/import/no-relative-barrel-file-imports/index.js +781 -0
- package/dist/cjs/rules/import/shared/barrel-parsing.js +511 -0
- package/dist/cjs/rules/import/shared/file-system.js +186 -0
- package/dist/cjs/rules/import/shared/jest-utils.js +244 -0
- package/dist/cjs/rules/import/shared/package-registry.js +263 -0
- package/dist/cjs/rules/import/shared/package-resolution.js +318 -0
- package/dist/cjs/rules/import/shared/perf.js +89 -0
- package/dist/cjs/rules/import/shared/types.js +67 -0
- package/dist/cjs/rules/visit-example-type-import-required/index.js +409 -0
- package/dist/es2019/index.js +19 -3
- package/dist/es2019/rules/ensure-use-sync-external-store-server-snapshot/index.js +43 -0
- package/dist/es2019/rules/feature-gating/valid-gate-name/index.js +52 -0
- package/dist/es2019/rules/import/no-barrel-entry-imports/index.js +1158 -0
- package/dist/es2019/rules/import/no-barrel-entry-jest-mock/index.js +1341 -0
- package/dist/es2019/rules/import/no-conversation-assistant-barrel-imports/index.js +37 -0
- package/dist/es2019/rules/import/no-jest-mock-barrel-files/index.js +1180 -0
- package/dist/es2019/rules/import/no-relative-barrel-file-imports/index.js +742 -0
- package/dist/es2019/rules/import/shared/barrel-parsing.js +433 -0
- package/dist/es2019/rules/import/shared/file-system.js +174 -0
- package/dist/es2019/rules/import/shared/jest-utils.js +203 -0
- package/dist/es2019/rules/import/shared/package-registry.js +240 -0
- package/dist/es2019/rules/import/shared/package-resolution.js +253 -0
- package/dist/es2019/rules/import/shared/perf.js +83 -0
- package/dist/es2019/rules/import/shared/types.js +57 -0
- package/dist/es2019/rules/visit-example-type-import-required/index.js +375 -0
- package/dist/esm/index.js +19 -3
- package/dist/esm/rules/ensure-use-sync-external-store-server-snapshot/index.js +35 -0
- package/dist/esm/rules/feature-gating/valid-gate-name/index.js +53 -0
- package/dist/esm/rules/import/no-barrel-entry-imports/index.js +1272 -0
- package/dist/esm/rules/import/no-barrel-entry-jest-mock/index.js +1650 -0
- package/dist/esm/rules/import/no-conversation-assistant-barrel-imports/index.js +37 -0
- package/dist/esm/rules/import/no-jest-mock-barrel-files/index.js +1392 -0
- package/dist/esm/rules/import/no-relative-barrel-file-imports/index.js +774 -0
- package/dist/esm/rules/import/shared/barrel-parsing.js +500 -0
- package/dist/esm/rules/import/shared/file-system.js +176 -0
- package/dist/esm/rules/import/shared/jest-utils.js +231 -0
- package/dist/esm/rules/import/shared/package-registry.js +256 -0
- package/dist/esm/rules/import/shared/package-resolution.js +306 -0
- package/dist/esm/rules/import/shared/perf.js +80 -0
- package/dist/esm/rules/import/shared/types.js +61 -0
- package/dist/esm/rules/visit-example-type-import-required/index.js +402 -0
- package/dist/types/index.d.ts +28 -2
- package/dist/types/rules/ensure-use-sync-external-store-server-snapshot/index.d.ts +3 -0
- package/dist/types/rules/feature-gating/valid-gate-name/index.d.ts +3 -0
- package/dist/types/rules/import/no-barrel-entry-imports/index.d.ts +9 -0
- package/dist/types/rules/import/no-barrel-entry-jest-mock/index.d.ts +9 -0
- package/dist/types/rules/import/no-conversation-assistant-barrel-imports/index.d.ts +3 -0
- package/dist/types/rules/import/no-jest-mock-barrel-files/index.d.ts +22 -0
- package/dist/types/rules/import/no-relative-barrel-file-imports/index.d.ts +5 -0
- package/dist/types/rules/import/shared/barrel-parsing.d.ts +30 -0
- package/dist/types/rules/import/shared/file-system.d.ts +38 -0
- package/dist/types/rules/import/shared/jest-utils.d.ts +55 -0
- package/dist/types/rules/import/shared/package-registry.d.ts +26 -0
- package/dist/types/rules/import/shared/package-resolution.d.ts +58 -0
- package/dist/types/rules/import/shared/perf.d.ts +13 -0
- package/dist/types/rules/import/shared/types.d.ts +131 -0
- package/dist/types/rules/visit-example-type-import-required/index.d.ts +4 -0
- package/dist/types-ts4.5/index.d.ts +28 -2
- package/dist/types-ts4.5/rules/import/no-barrel-entry-imports/index.d.ts +9 -0
- package/dist/types-ts4.5/rules/import/no-barrel-entry-jest-mock/index.d.ts +9 -0
- package/dist/types-ts4.5/rules/import/no-conversation-assistant-barrel-imports/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/import/no-jest-mock-barrel-files/index.d.ts +22 -0
- package/dist/types-ts4.5/rules/import/no-relative-barrel-file-imports/index.d.ts +5 -0
- package/dist/types-ts4.5/rules/import/shared/barrel-parsing.d.ts +30 -0
- package/dist/types-ts4.5/rules/import/shared/file-system.d.ts +38 -0
- package/dist/types-ts4.5/rules/import/shared/jest-utils.d.ts +55 -0
- package/dist/types-ts4.5/rules/import/shared/package-registry.d.ts +26 -0
- package/dist/types-ts4.5/rules/import/shared/package-resolution.d.ts +58 -0
- package/dist/types-ts4.5/rules/import/shared/perf.d.ts +13 -0
- package/dist/types-ts4.5/rules/import/shared/types.d.ts +131 -0
- package/dist/types-ts4.5/rules/visit-example-type-import-required/index.d.ts +4 -0
- package/package.json +6 -2
- package/dist/cjs/rules/ensure-native-and-af-exports-synced/index.js +0 -158
- package/dist/es2019/rules/ensure-native-and-af-exports-synced/index.js +0 -146
- package/dist/esm/rules/ensure-native-and-af-exports-synced/index.js +0 -151
- /package/dist/types-ts4.5/rules/{ensure-native-and-af-exports-synced → ensure-use-sync-external-store-server-snapshot}/index.d.ts +0 -0
- /package/dist/{types/rules/ensure-native-and-af-exports-synced → types-ts4.5/rules/feature-gating/valid-gate-name}/index.d.ts +0 -0
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import _typeof from "@babel/runtime/helpers/typeof";
|
|
3
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
4
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
5
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
6
|
+
import { dirname, join } from 'path';
|
|
7
|
+
import * as ts from 'typescript';
|
|
8
|
+
import { isRelativeImport, readFileContent, resolveImportPath } from './file-system';
|
|
9
|
+
import { findPackageInRegistry } from './package-registry';
|
|
10
|
+
var ENTRY_POINT_FOLDER_NAMES = new Set(['entry-points', 'entrypoints', 'entrypoint', 'entry-point']);
|
|
11
|
+
function isInEntryPointsFolder(filePath) {
|
|
12
|
+
var parts = filePath.split(/[/\\]/);
|
|
13
|
+
return parts.some(function (part) {
|
|
14
|
+
return ENTRY_POINT_FOLDER_NAMES.has(part);
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Parse an entry-point wrapper file and resolve the source files it re-exports from,
|
|
19
|
+
* along with name mappings (source export name → entry-point export name).
|
|
20
|
+
*/
|
|
21
|
+
function resolveEntryPointReExports(_ref) {
|
|
22
|
+
var entryPointFilePath = _ref.entryPointFilePath,
|
|
23
|
+
fs = _ref.fs;
|
|
24
|
+
var content = readFileContent({
|
|
25
|
+
filePath: entryPointFilePath,
|
|
26
|
+
fs: fs
|
|
27
|
+
});
|
|
28
|
+
if (!content) {
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
var sourceFile = ts.createSourceFile(entryPointFilePath, content, ts.ScriptTarget.Latest, true);
|
|
33
|
+
var basedir = dirname(entryPointFilePath);
|
|
34
|
+
var results = [];
|
|
35
|
+
var _iterator = _createForOfIteratorHelper(sourceFile.statements),
|
|
36
|
+
_step;
|
|
37
|
+
try {
|
|
38
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
39
|
+
var statement = _step.value;
|
|
40
|
+
if (ts.isExportDeclaration(statement) && statement.moduleSpecifier && ts.isStringLiteral(statement.moduleSpecifier)) {
|
|
41
|
+
var modulePath = statement.moduleSpecifier.text;
|
|
42
|
+
if (!isRelativeImport(modulePath)) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
var resolved = resolveImportPath({
|
|
46
|
+
basedir: basedir,
|
|
47
|
+
importPath: modulePath,
|
|
48
|
+
fs: fs
|
|
49
|
+
});
|
|
50
|
+
if (!resolved) {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
var nameMap = new Map();
|
|
54
|
+
if (statement.exportClause && ts.isNamedExports(statement.exportClause)) {
|
|
55
|
+
var _iterator2 = _createForOfIteratorHelper(statement.exportClause.elements),
|
|
56
|
+
_step2;
|
|
57
|
+
try {
|
|
58
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
59
|
+
var element = _step2.value;
|
|
60
|
+
var exportedName = element.name.text;
|
|
61
|
+
var sourceName = element.propertyName ? element.propertyName.text : exportedName;
|
|
62
|
+
nameMap.set(sourceName, exportedName);
|
|
63
|
+
}
|
|
64
|
+
} catch (err) {
|
|
65
|
+
_iterator2.e(err);
|
|
66
|
+
} finally {
|
|
67
|
+
_iterator2.f();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
results.push({
|
|
71
|
+
sourcePath: resolved,
|
|
72
|
+
nameMap: nameMap
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
} catch (err) {
|
|
77
|
+
_iterator.e(err);
|
|
78
|
+
} finally {
|
|
79
|
+
_iterator.f();
|
|
80
|
+
}
|
|
81
|
+
return results;
|
|
82
|
+
} catch (_unused) {
|
|
83
|
+
return [];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Parse the package.json exports field and return a map of export paths to resolved file paths.
|
|
89
|
+
*/
|
|
90
|
+
export function parsePackageExports(_ref2) {
|
|
91
|
+
var packageDir = _ref2.packageDir,
|
|
92
|
+
fs = _ref2.fs;
|
|
93
|
+
// Memoize per-package to avoid repeated reads/parses during IDE lint runs.
|
|
94
|
+
// Additionally, invalidate per-package if the package.json mtime changes
|
|
95
|
+
// (covers unstaged local edits in IDE).
|
|
96
|
+
if (!fs.cache.packageExportsByDir) {
|
|
97
|
+
fs.cache.packageExportsByDir = new Map();
|
|
98
|
+
}
|
|
99
|
+
var packageJsonPath = join(packageDir, 'package.json');
|
|
100
|
+
var currentMtimeMs = null;
|
|
101
|
+
try {
|
|
102
|
+
var _fs$statSync$mtimeMs;
|
|
103
|
+
currentMtimeMs = (_fs$statSync$mtimeMs = fs.statSync(packageJsonPath).mtimeMs) !== null && _fs$statSync$mtimeMs !== void 0 ? _fs$statSync$mtimeMs : null;
|
|
104
|
+
} catch (_unused2) {
|
|
105
|
+
// If package.json can't be stat'ed (missing/inaccessible), use null to force re-read
|
|
106
|
+
currentMtimeMs = null;
|
|
107
|
+
}
|
|
108
|
+
var cached = fs.cache.packageExportsByDir.get(packageDir);
|
|
109
|
+
// Only use cache if we have a valid mtime and it matches
|
|
110
|
+
if (cached && currentMtimeMs !== null && cached.packageJsonMtimeMs === currentMtimeMs) {
|
|
111
|
+
return cached.exportsMap;
|
|
112
|
+
}
|
|
113
|
+
var exportsMap = new Map();
|
|
114
|
+
try {
|
|
115
|
+
var content = readFileContent({
|
|
116
|
+
filePath: packageJsonPath,
|
|
117
|
+
fs: fs
|
|
118
|
+
});
|
|
119
|
+
if (!content) {
|
|
120
|
+
return exportsMap;
|
|
121
|
+
}
|
|
122
|
+
var packageJson = JSON.parse(content);
|
|
123
|
+
var exports = packageJson.exports;
|
|
124
|
+
if (!exports || _typeof(exports) !== 'object') {
|
|
125
|
+
return exportsMap;
|
|
126
|
+
}
|
|
127
|
+
for (var _i = 0, _Object$entries = Object.entries(exports); _i < _Object$entries.length; _i++) {
|
|
128
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
129
|
+
exportPath = _Object$entries$_i[0],
|
|
130
|
+
exportValue = _Object$entries$_i[1];
|
|
131
|
+
// Handle both simple string values and conditional exports objects
|
|
132
|
+
var resolvedPath = null;
|
|
133
|
+
if (typeof exportValue === 'string') {
|
|
134
|
+
resolvedPath = exportValue;
|
|
135
|
+
} else if (_typeof(exportValue) === 'object' && exportValue !== null) {
|
|
136
|
+
// Handle conditional exports like { "import": "./...", "require": "./..." }
|
|
137
|
+
// Prefer "import" or "default" or first available
|
|
138
|
+
var condExports = exportValue;
|
|
139
|
+
resolvedPath = condExports['import'] || condExports['default'] || Object.values(condExports)[0];
|
|
140
|
+
}
|
|
141
|
+
if (resolvedPath && typeof resolvedPath === 'string') {
|
|
142
|
+
// Resolve the path relative to the package directory
|
|
143
|
+
var absolutePath = resolveImportPath({
|
|
144
|
+
basedir: packageDir,
|
|
145
|
+
importPath: resolvedPath,
|
|
146
|
+
fs: fs
|
|
147
|
+
});
|
|
148
|
+
if (absolutePath) {
|
|
149
|
+
exportsMap.set(exportPath, absolutePath);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
} catch (_unused3) {
|
|
154
|
+
// Ignore parsing errors
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Cache even empty maps to avoid re-reading invalid/missing exports repeatedly.
|
|
158
|
+
fs.cache.packageExportsByDir.set(packageDir, {
|
|
159
|
+
packageJsonMtimeMs: currentMtimeMs,
|
|
160
|
+
exportsMap: exportsMap
|
|
161
|
+
});
|
|
162
|
+
return exportsMap;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Find a matching export entry for a given source file path.
|
|
166
|
+
* Returns the export path (e.g., "./controllers/analytics") or null if not found.
|
|
167
|
+
*
|
|
168
|
+
* When `fs` is provided, also checks entry-point wrapper files. If an export resolves
|
|
169
|
+
* to a file inside a recognized entry-points folder (entry-points, entrypoints, etc.),
|
|
170
|
+
* the wrapper is parsed to see if it re-exports from `sourceFilePath`.
|
|
171
|
+
*
|
|
172
|
+
* `sourceExportName` is the name under which the symbol is exported from the source file
|
|
173
|
+
* (e.g. `'default'`). Used to look up the corresponding entry-point export name so the
|
|
174
|
+
* caller can generate the correct import style.
|
|
175
|
+
*/
|
|
176
|
+
export function findExportForSourceFile(_ref3) {
|
|
177
|
+
var sourceFilePath = _ref3.sourceFilePath,
|
|
178
|
+
exportsMap = _ref3.exportsMap,
|
|
179
|
+
fs = _ref3.fs,
|
|
180
|
+
sourceExportName = _ref3.sourceExportName;
|
|
181
|
+
var _iterator3 = _createForOfIteratorHelper(exportsMap),
|
|
182
|
+
_step3;
|
|
183
|
+
try {
|
|
184
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
185
|
+
var _step3$value = _slicedToArray(_step3.value, 2),
|
|
186
|
+
_exportPath = _step3$value[0],
|
|
187
|
+
_resolvedPath = _step3$value[1];
|
|
188
|
+
if (_resolvedPath === sourceFilePath) {
|
|
189
|
+
return {
|
|
190
|
+
exportPath: _exportPath
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
} catch (err) {
|
|
195
|
+
_iterator3.e(err);
|
|
196
|
+
} finally {
|
|
197
|
+
_iterator3.f();
|
|
198
|
+
}
|
|
199
|
+
if (fs) {
|
|
200
|
+
var _iterator4 = _createForOfIteratorHelper(exportsMap),
|
|
201
|
+
_step4;
|
|
202
|
+
try {
|
|
203
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
204
|
+
var _step4$value = _slicedToArray(_step4.value, 2),
|
|
205
|
+
exportPath = _step4$value[0],
|
|
206
|
+
resolvedPath = _step4$value[1];
|
|
207
|
+
if (isInEntryPointsFolder(resolvedPath)) {
|
|
208
|
+
var reExports = resolveEntryPointReExports({
|
|
209
|
+
entryPointFilePath: resolvedPath,
|
|
210
|
+
fs: fs
|
|
211
|
+
});
|
|
212
|
+
var _iterator5 = _createForOfIteratorHelper(reExports),
|
|
213
|
+
_step5;
|
|
214
|
+
try {
|
|
215
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
216
|
+
var reExport = _step5.value;
|
|
217
|
+
if (reExport.sourcePath === sourceFilePath) {
|
|
218
|
+
var entryPointExportName = void 0;
|
|
219
|
+
if (sourceExportName !== undefined && reExport.nameMap.has(sourceExportName)) {
|
|
220
|
+
entryPointExportName = reExport.nameMap.get(sourceExportName);
|
|
221
|
+
}
|
|
222
|
+
return {
|
|
223
|
+
exportPath: exportPath,
|
|
224
|
+
entryPointExportName: entryPointExportName
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
} catch (err) {
|
|
229
|
+
_iterator5.e(err);
|
|
230
|
+
} finally {
|
|
231
|
+
_iterator5.f();
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
} catch (err) {
|
|
236
|
+
_iterator4.e(err);
|
|
237
|
+
} finally {
|
|
238
|
+
_iterator4.f();
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Extract the package name and subpath from an import specifier.
|
|
246
|
+
* Returns null if the import is not a scoped package import.
|
|
247
|
+
*/
|
|
248
|
+
export function extractPackageNameFromImport(moduleSpecifier) {
|
|
249
|
+
var match = moduleSpecifier.match(/^(@[^/]+\/[^/]+)(\/.*)?$/);
|
|
250
|
+
if (!match) {
|
|
251
|
+
return null;
|
|
252
|
+
}
|
|
253
|
+
return {
|
|
254
|
+
packageName: match[1],
|
|
255
|
+
subPath: match[2] || ''
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Resolve a cross-package import to its package directory and export info.
|
|
261
|
+
* Returns null if the package is not in the target folder or cannot be resolved.
|
|
262
|
+
*/
|
|
263
|
+
export function resolveCrossPackageImport(_ref4) {
|
|
264
|
+
var moduleSpecifier = _ref4.moduleSpecifier,
|
|
265
|
+
workspaceRoot = _ref4.workspaceRoot,
|
|
266
|
+
fs = _ref4.fs;
|
|
267
|
+
// Only handle @atlassian/* scoped packages
|
|
268
|
+
var parsed = extractPackageNameFromImport(moduleSpecifier);
|
|
269
|
+
if (!parsed) {
|
|
270
|
+
return null;
|
|
271
|
+
}
|
|
272
|
+
var packageName = parsed.packageName,
|
|
273
|
+
subPath = parsed.subPath;
|
|
274
|
+
|
|
275
|
+
// Check if package is in target folder
|
|
276
|
+
var packageDir = findPackageInRegistry({
|
|
277
|
+
packageName: packageName,
|
|
278
|
+
workspaceRoot: workspaceRoot,
|
|
279
|
+
fs: fs
|
|
280
|
+
});
|
|
281
|
+
if (!packageDir) {
|
|
282
|
+
return null;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// Parse package.json exports
|
|
286
|
+
var exportsMap = parsePackageExports({
|
|
287
|
+
packageDir: packageDir,
|
|
288
|
+
fs: fs
|
|
289
|
+
});
|
|
290
|
+
if (exportsMap.size === 0) {
|
|
291
|
+
return null;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// Determine the export path (e.g., '.' or './utils')
|
|
295
|
+
var exportPath = subPath ? '.' + subPath : '.';
|
|
296
|
+
var entryFilePath = exportsMap.get(exportPath);
|
|
297
|
+
if (!entryFilePath) {
|
|
298
|
+
return null;
|
|
299
|
+
}
|
|
300
|
+
return {
|
|
301
|
+
packageName: packageName,
|
|
302
|
+
packageDir: packageDir,
|
|
303
|
+
exportPath: exportPath,
|
|
304
|
+
entryFilePath: entryFilePath
|
|
305
|
+
};
|
|
306
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
export var PERF_ENV_VAR = 'INTERNAL_ESLINT_BARREL_PERF';
|
|
2
|
+
function nowMs() {
|
|
3
|
+
// eslint-disable-next-line no-restricted-globals
|
|
4
|
+
return typeof performance !== 'undefined' && performance.now ? performance.now() : Date.now();
|
|
5
|
+
}
|
|
6
|
+
export function isPerfEnabled() {
|
|
7
|
+
return process.env[PERF_ENV_VAR] === '1' || process.env[PERF_ENV_VAR] === 'true';
|
|
8
|
+
}
|
|
9
|
+
function ensurePerfInitialized(_ref) {
|
|
10
|
+
var fs = _ref.fs;
|
|
11
|
+
if (!fs.cache.perf) {
|
|
12
|
+
fs.cache.perf = {
|
|
13
|
+
installedExitHook: false,
|
|
14
|
+
counters: {},
|
|
15
|
+
timers: {}
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function ensureExitHookInstalled(_ref2) {
|
|
20
|
+
var fs = _ref2.fs;
|
|
21
|
+
if (!isPerfEnabled()) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
ensurePerfInitialized({
|
|
25
|
+
fs: fs
|
|
26
|
+
});
|
|
27
|
+
if (fs.cache.perf.installedExitHook) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
fs.cache.perf.installedExitHook = true;
|
|
31
|
+
// eslint-disable-next-line no-console
|
|
32
|
+
console.error("[eslint-plugin-internal] perf enabled via ".concat(PERF_ENV_VAR));
|
|
33
|
+
process.once('exit', function () {
|
|
34
|
+
var _fs$cache$perf$counte, _fs$cache$perf, _fs$cache$perf$timers, _fs$cache$perf2;
|
|
35
|
+
// eslint-disable-next-line no-console
|
|
36
|
+
console.error("[eslint-plugin-internal] perf exit hook fired (".concat(PERF_ENV_VAR, ")"));
|
|
37
|
+
// eslint-disable-next-line no-console
|
|
38
|
+
console.log("[eslint-plugin-internal] perf summary (".concat(PERF_ENV_VAR, ")"));
|
|
39
|
+
// eslint-disable-next-line no-console
|
|
40
|
+
console.log(JSON.stringify({
|
|
41
|
+
counters: (_fs$cache$perf$counte = (_fs$cache$perf = fs.cache.perf) === null || _fs$cache$perf === void 0 ? void 0 : _fs$cache$perf.counters) !== null && _fs$cache$perf$counte !== void 0 ? _fs$cache$perf$counte : {},
|
|
42
|
+
timers: (_fs$cache$perf$timers = (_fs$cache$perf2 = fs.cache.perf) === null || _fs$cache$perf2 === void 0 ? void 0 : _fs$cache$perf2.timers) !== null && _fs$cache$perf$timers !== void 0 ? _fs$cache$perf$timers : {}
|
|
43
|
+
}, null, 2));
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
export function perfInc(_ref3) {
|
|
47
|
+
var _perf$counters$key;
|
|
48
|
+
var fs = _ref3.fs,
|
|
49
|
+
key = _ref3.key,
|
|
50
|
+
_ref3$by = _ref3.by,
|
|
51
|
+
by = _ref3$by === void 0 ? 1 : _ref3$by;
|
|
52
|
+
if (!isPerfEnabled()) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
ensureExitHookInstalled({
|
|
56
|
+
fs: fs
|
|
57
|
+
});
|
|
58
|
+
var perf = fs.cache.perf;
|
|
59
|
+
perf.counters[key] = ((_perf$counters$key = perf.counters[key]) !== null && _perf$counters$key !== void 0 ? _perf$counters$key : 0) + by;
|
|
60
|
+
}
|
|
61
|
+
export function perfTime(_ref4) {
|
|
62
|
+
var fs = _ref4.fs,
|
|
63
|
+
key = _ref4.key,
|
|
64
|
+
fn = _ref4.fn;
|
|
65
|
+
if (!isPerfEnabled()) {
|
|
66
|
+
return fn();
|
|
67
|
+
}
|
|
68
|
+
ensureExitHookInstalled({
|
|
69
|
+
fs: fs
|
|
70
|
+
});
|
|
71
|
+
var perf = fs.cache.perf;
|
|
72
|
+
var start = nowMs();
|
|
73
|
+
try {
|
|
74
|
+
return fn();
|
|
75
|
+
} finally {
|
|
76
|
+
var _perf$timers$key;
|
|
77
|
+
var duration = nowMs() - start;
|
|
78
|
+
perf.timers[key] = ((_perf$timers$key = perf.timers[key]) !== null && _perf$timers$key !== void 0 ? _perf$timers$key : 0) + duration;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
import { execSync as _execSync } from 'child_process';
|
|
5
|
+
import { existsSync, readdirSync as _readdirSync, readFileSync, realpathSync, statSync } from 'fs';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Directory entry returned by readdirSync with withFileTypes option.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* State for the package registry cache.
|
|
13
|
+
* This is used to cache package name to directory mappings for efficient lookups.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Cache structure for file system operations.
|
|
18
|
+
* Contains both package registry cache and workspace root cache.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* File system abstraction for testability.
|
|
23
|
+
* This interface allows the core logic to be tested with mock file systems.
|
|
24
|
+
* The cache property holds package resolution state and can be passed as an empty
|
|
25
|
+
* object for tests to ensure fresh state for each test case.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Real file system implementation using Node.js fs module.
|
|
30
|
+
*/
|
|
31
|
+
export var realFileSystem = {
|
|
32
|
+
existsSync: existsSync,
|
|
33
|
+
readFileSync: readFileSync,
|
|
34
|
+
realpathSync: realpathSync,
|
|
35
|
+
statSync: statSync,
|
|
36
|
+
readdirSync: function readdirSync(path, options) {
|
|
37
|
+
return _readdirSync(path, options);
|
|
38
|
+
},
|
|
39
|
+
execSync: function execSync(command, options) {
|
|
40
|
+
try {
|
|
41
|
+
return _execSync(command, _objectSpread(_objectSpread({}, options), {}, {
|
|
42
|
+
encoding: 'utf-8'
|
|
43
|
+
})).trim();
|
|
44
|
+
} catch (_unused) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
cache: {}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Information about cross-package re-export origin.
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Information about where an export originates.
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Context for package resolution operations.
|
|
61
|
+
*/
|