@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.
Files changed (85) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/index.js +19 -3
  3. package/dist/cjs/rules/ensure-use-sync-external-store-server-snapshot/index.js +41 -0
  4. package/dist/cjs/rules/feature-gating/valid-gate-name/index.js +60 -0
  5. package/dist/cjs/rules/import/no-barrel-entry-imports/index.js +1279 -0
  6. package/dist/cjs/rules/import/no-barrel-entry-jest-mock/index.js +1659 -0
  7. package/dist/cjs/rules/import/no-conversation-assistant-barrel-imports/index.js +43 -0
  8. package/dist/cjs/rules/import/no-jest-mock-barrel-files/index.js +1402 -0
  9. package/dist/cjs/rules/import/no-relative-barrel-file-imports/index.js +781 -0
  10. package/dist/cjs/rules/import/shared/barrel-parsing.js +511 -0
  11. package/dist/cjs/rules/import/shared/file-system.js +186 -0
  12. package/dist/cjs/rules/import/shared/jest-utils.js +244 -0
  13. package/dist/cjs/rules/import/shared/package-registry.js +263 -0
  14. package/dist/cjs/rules/import/shared/package-resolution.js +318 -0
  15. package/dist/cjs/rules/import/shared/perf.js +89 -0
  16. package/dist/cjs/rules/import/shared/types.js +67 -0
  17. package/dist/cjs/rules/visit-example-type-import-required/index.js +409 -0
  18. package/dist/es2019/index.js +19 -3
  19. package/dist/es2019/rules/ensure-use-sync-external-store-server-snapshot/index.js +43 -0
  20. package/dist/es2019/rules/feature-gating/valid-gate-name/index.js +52 -0
  21. package/dist/es2019/rules/import/no-barrel-entry-imports/index.js +1158 -0
  22. package/dist/es2019/rules/import/no-barrel-entry-jest-mock/index.js +1341 -0
  23. package/dist/es2019/rules/import/no-conversation-assistant-barrel-imports/index.js +37 -0
  24. package/dist/es2019/rules/import/no-jest-mock-barrel-files/index.js +1180 -0
  25. package/dist/es2019/rules/import/no-relative-barrel-file-imports/index.js +742 -0
  26. package/dist/es2019/rules/import/shared/barrel-parsing.js +433 -0
  27. package/dist/es2019/rules/import/shared/file-system.js +174 -0
  28. package/dist/es2019/rules/import/shared/jest-utils.js +203 -0
  29. package/dist/es2019/rules/import/shared/package-registry.js +240 -0
  30. package/dist/es2019/rules/import/shared/package-resolution.js +253 -0
  31. package/dist/es2019/rules/import/shared/perf.js +83 -0
  32. package/dist/es2019/rules/import/shared/types.js +57 -0
  33. package/dist/es2019/rules/visit-example-type-import-required/index.js +375 -0
  34. package/dist/esm/index.js +19 -3
  35. package/dist/esm/rules/ensure-use-sync-external-store-server-snapshot/index.js +35 -0
  36. package/dist/esm/rules/feature-gating/valid-gate-name/index.js +53 -0
  37. package/dist/esm/rules/import/no-barrel-entry-imports/index.js +1272 -0
  38. package/dist/esm/rules/import/no-barrel-entry-jest-mock/index.js +1650 -0
  39. package/dist/esm/rules/import/no-conversation-assistant-barrel-imports/index.js +37 -0
  40. package/dist/esm/rules/import/no-jest-mock-barrel-files/index.js +1392 -0
  41. package/dist/esm/rules/import/no-relative-barrel-file-imports/index.js +774 -0
  42. package/dist/esm/rules/import/shared/barrel-parsing.js +500 -0
  43. package/dist/esm/rules/import/shared/file-system.js +176 -0
  44. package/dist/esm/rules/import/shared/jest-utils.js +231 -0
  45. package/dist/esm/rules/import/shared/package-registry.js +256 -0
  46. package/dist/esm/rules/import/shared/package-resolution.js +306 -0
  47. package/dist/esm/rules/import/shared/perf.js +80 -0
  48. package/dist/esm/rules/import/shared/types.js +61 -0
  49. package/dist/esm/rules/visit-example-type-import-required/index.js +402 -0
  50. package/dist/types/index.d.ts +28 -2
  51. package/dist/types/rules/ensure-use-sync-external-store-server-snapshot/index.d.ts +3 -0
  52. package/dist/types/rules/feature-gating/valid-gate-name/index.d.ts +3 -0
  53. package/dist/types/rules/import/no-barrel-entry-imports/index.d.ts +9 -0
  54. package/dist/types/rules/import/no-barrel-entry-jest-mock/index.d.ts +9 -0
  55. package/dist/types/rules/import/no-conversation-assistant-barrel-imports/index.d.ts +3 -0
  56. package/dist/types/rules/import/no-jest-mock-barrel-files/index.d.ts +22 -0
  57. package/dist/types/rules/import/no-relative-barrel-file-imports/index.d.ts +5 -0
  58. package/dist/types/rules/import/shared/barrel-parsing.d.ts +30 -0
  59. package/dist/types/rules/import/shared/file-system.d.ts +38 -0
  60. package/dist/types/rules/import/shared/jest-utils.d.ts +55 -0
  61. package/dist/types/rules/import/shared/package-registry.d.ts +26 -0
  62. package/dist/types/rules/import/shared/package-resolution.d.ts +58 -0
  63. package/dist/types/rules/import/shared/perf.d.ts +13 -0
  64. package/dist/types/rules/import/shared/types.d.ts +131 -0
  65. package/dist/types/rules/visit-example-type-import-required/index.d.ts +4 -0
  66. package/dist/types-ts4.5/index.d.ts +28 -2
  67. package/dist/types-ts4.5/rules/import/no-barrel-entry-imports/index.d.ts +9 -0
  68. package/dist/types-ts4.5/rules/import/no-barrel-entry-jest-mock/index.d.ts +9 -0
  69. package/dist/types-ts4.5/rules/import/no-conversation-assistant-barrel-imports/index.d.ts +3 -0
  70. package/dist/types-ts4.5/rules/import/no-jest-mock-barrel-files/index.d.ts +22 -0
  71. package/dist/types-ts4.5/rules/import/no-relative-barrel-file-imports/index.d.ts +5 -0
  72. package/dist/types-ts4.5/rules/import/shared/barrel-parsing.d.ts +30 -0
  73. package/dist/types-ts4.5/rules/import/shared/file-system.d.ts +38 -0
  74. package/dist/types-ts4.5/rules/import/shared/jest-utils.d.ts +55 -0
  75. package/dist/types-ts4.5/rules/import/shared/package-registry.d.ts +26 -0
  76. package/dist/types-ts4.5/rules/import/shared/package-resolution.d.ts +58 -0
  77. package/dist/types-ts4.5/rules/import/shared/perf.d.ts +13 -0
  78. package/dist/types-ts4.5/rules/import/shared/types.d.ts +131 -0
  79. package/dist/types-ts4.5/rules/visit-example-type-import-required/index.d.ts +4 -0
  80. package/package.json +6 -2
  81. package/dist/cjs/rules/ensure-native-and-af-exports-synced/index.js +0 -158
  82. package/dist/es2019/rules/ensure-native-and-af-exports-synced/index.js +0 -146
  83. package/dist/esm/rules/ensure-native-and-af-exports-synced/index.js +0 -151
  84. /package/dist/types-ts4.5/rules/{ensure-native-and-af-exports-synced → ensure-use-sync-external-store-server-snapshot}/index.d.ts +0 -0
  85. /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,231 @@
1
+ import _typeof from "@babel/runtime/helpers/typeof";
2
+ 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; } } }; }
3
+ 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; } }
4
+ 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; }
5
+ /**
6
+ * Shared utilities for jest.mock-related lint rules.
7
+ *
8
+ * These helpers are used by both `no-barrel-entry-jest-mock` (cross-package)
9
+ * and `no-jest-mock-barrel-files` (relative imports).
10
+ */
11
+
12
+ /**
13
+ * Check if a CallExpression node is a jest.mock() call
14
+ */
15
+ export function isJestMockCall(node) {
16
+ var callee = node.callee;
17
+ if (callee.type === 'MemberExpression') {
18
+ return callee.object.type === 'Identifier' && callee.object.name === 'jest' && callee.property.type === 'Identifier' && callee.property.name === 'mock';
19
+ }
20
+ if (callee.type === 'Identifier') {
21
+ return callee.name === 'jest.mock';
22
+ }
23
+ return false;
24
+ }
25
+
26
+ /**
27
+ * Check if a node is a jest.requireActual() call
28
+ */
29
+ export function isJestRequireActual(node) {
30
+ if (node.type !== 'CallExpression') {
31
+ return false;
32
+ }
33
+ var callee = node.callee;
34
+ if (callee.type === 'MemberExpression') {
35
+ return callee.object.type === 'Identifier' && callee.object.name === 'jest' && callee.property.type === 'Identifier' && callee.property.name === 'requireActual';
36
+ }
37
+ return false;
38
+ }
39
+
40
+ /**
41
+ * Check if a node is a jest.requireMock() call
42
+ */
43
+ export function isJestRequireMock(node) {
44
+ if (node.type !== 'CallExpression') {
45
+ return false;
46
+ }
47
+ var callee = node.callee;
48
+ if (callee.type === 'MemberExpression') {
49
+ return callee.object.type === 'Identifier' && callee.object.name === 'jest' && callee.property.type === 'Identifier' && callee.property.name === 'requireMock';
50
+ }
51
+ return false;
52
+ }
53
+
54
+ /**
55
+ * Extract the import path string from a jest.mock/jest.requireMock/jest.requireActual call's arguments.
56
+ * Returns null if the path cannot be statically determined.
57
+ */
58
+ export function extractImportPath(node) {
59
+ if (node.arguments.length === 0) {
60
+ return null;
61
+ }
62
+ var firstArg = node.arguments[0];
63
+ if (firstArg.type === 'Literal') {
64
+ return String(firstArg.value);
65
+ }
66
+ if (firstArg.type === 'TemplateLiteral' && firstArg.expressions.length === 0) {
67
+ return firstArg.quasis[0].value.raw;
68
+ }
69
+ return null;
70
+ }
71
+
72
+ /**
73
+ * Find all jest.requireMock() calls in the AST whose import path matches a given target.
74
+ *
75
+ * The `matchPath` callback allows callers to provide their own path-matching strategy:
76
+ * - Cross-package rules can use simple string equality
77
+ * - Relative import rules can use normalized/resolved path comparison
78
+ */
79
+ export function findJestRequireMockCalls(_ref) {
80
+ var ast = _ref.ast,
81
+ matchPath = _ref.matchPath;
82
+ var results = [];
83
+ var visited = new WeakSet();
84
+ var skipKeys = new Set(['parent', 'loc', 'range', 'tokens', 'comments']);
85
+ function visit(node) {
86
+ if (visited.has(node)) {
87
+ return;
88
+ }
89
+ visited.add(node);
90
+ if (node.type === 'CallExpression' && isJestRequireMock(node)) {
91
+ var path = extractImportPath(node);
92
+ if (path && matchPath(path)) {
93
+ results.push(node);
94
+ }
95
+ }
96
+ for (var key in node) {
97
+ if (skipKeys.has(key)) {
98
+ continue;
99
+ }
100
+ var value = node[key];
101
+ if (value && _typeof(value) === 'object') {
102
+ if (Array.isArray(value)) {
103
+ var _iterator = _createForOfIteratorHelper(value),
104
+ _step;
105
+ try {
106
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
107
+ var child = _step.value;
108
+ if (child && _typeof(child) === 'object' && 'type' in child) {
109
+ visit(child);
110
+ }
111
+ }
112
+ } catch (err) {
113
+ _iterator.e(err);
114
+ } finally {
115
+ _iterator.f();
116
+ }
117
+ } else if ('type' in value) {
118
+ visit(value);
119
+ }
120
+ }
121
+ }
122
+ }
123
+ visit(ast);
124
+ return results;
125
+ }
126
+
127
+ /**
128
+ * Find all jest.requireActual() calls in the AST whose import path matches a given target.
129
+ * Works identically to findJestRequireMockCalls but for requireActual.
130
+ */
131
+ export function findJestRequireActualCalls(_ref2) {
132
+ var ast = _ref2.ast,
133
+ matchPath = _ref2.matchPath;
134
+ var results = [];
135
+ var visited = new WeakSet();
136
+ var skipKeys = new Set(['parent', 'loc', 'range', 'tokens', 'comments']);
137
+ function visit(node) {
138
+ if (visited.has(node)) {
139
+ return;
140
+ }
141
+ visited.add(node);
142
+ if (node.type === 'CallExpression' && isJestRequireActual(node)) {
143
+ var path = extractImportPath(node);
144
+ if (path && matchPath(path)) {
145
+ results.push(node);
146
+ }
147
+ }
148
+ for (var key in node) {
149
+ if (skipKeys.has(key)) {
150
+ continue;
151
+ }
152
+ var value = node[key];
153
+ if (value && _typeof(value) === 'object') {
154
+ if (Array.isArray(value)) {
155
+ var _iterator2 = _createForOfIteratorHelper(value),
156
+ _step2;
157
+ try {
158
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
159
+ var child = _step2.value;
160
+ if (child && _typeof(child) === 'object' && 'type' in child) {
161
+ visit(child);
162
+ }
163
+ }
164
+ } catch (err) {
165
+ _iterator2.e(err);
166
+ } finally {
167
+ _iterator2.f();
168
+ }
169
+ } else if ('type' in value) {
170
+ visit(value);
171
+ }
172
+ }
173
+ }
174
+ }
175
+ visit(ast);
176
+ return results;
177
+ }
178
+
179
+ /**
180
+ * Determine the best new import path for a jest.requireMock() call by inspecting
181
+ * the destructured symbols or property access at the call site.
182
+ *
183
+ * @param requireMockNode - The jest.requireMock() CallExpression node
184
+ * @param symbolToNewPath - Map from symbol name to the new mock path that provides it
185
+ * @returns The resolved new path, or null if it cannot be determined
186
+ */
187
+ export function resolveNewPathForRequireMock(_ref3) {
188
+ var requireMockNode = _ref3.requireMockNode,
189
+ symbolToNewPath = _ref3.symbolToNewPath;
190
+ var parent = requireMockNode.parent;
191
+ if (parent) {
192
+ var _parent;
193
+ // Check for destructuring pattern: const { foo } = jest.requireMock('...')
194
+ var declarator = parent.type === 'VariableDeclarator' ? parent : ((_parent = parent.parent) === null || _parent === void 0 ? void 0 : _parent.type) === 'VariableDeclarator' ? parent.parent : null;
195
+ if (declarator && declarator.type === 'VariableDeclarator' && declarator.id.type === 'ObjectPattern') {
196
+ var _iterator3 = _createForOfIteratorHelper(declarator.id.properties),
197
+ _step3;
198
+ try {
199
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
200
+ var prop = _step3.value;
201
+ if (prop.type === 'Property' && prop.key.type === 'Identifier') {
202
+ var matchedPath = symbolToNewPath.get(prop.key.name);
203
+ if (matchedPath) {
204
+ return matchedPath;
205
+ }
206
+ }
207
+ }
208
+ } catch (err) {
209
+ _iterator3.e(err);
210
+ } finally {
211
+ _iterator3.f();
212
+ }
213
+ }
214
+
215
+ // Check for property access pattern: jest.requireMock('...').foo
216
+ if (parent.type === 'MemberExpression' && parent.property.type === 'Identifier') {
217
+ var _matchedPath = symbolToNewPath.get(parent.property.name);
218
+ if (_matchedPath) {
219
+ return _matchedPath;
220
+ }
221
+ }
222
+ }
223
+
224
+ // Fallback: if only one new path exists, use it
225
+ var uniquePaths = new Set(symbolToNewPath.values());
226
+ if (uniquePaths.size === 1) {
227
+ var _uniquePaths$values$n;
228
+ return (_uniquePaths$values$n = uniquePaths.values().next().value) !== null && _uniquePaths$values$n !== void 0 ? _uniquePaths$values$n : null;
229
+ }
230
+ return null;
231
+ }
@@ -0,0 +1,256 @@
1
+ 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; } } }; }
2
+ 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; } }
3
+ 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; }
4
+ import { join } from 'path';
5
+ import { DEFAULT_TARGET_FOLDERS } from './file-system';
6
+ import { perfInc, perfTime } from './perf';
7
+ /**
8
+ * The folder paths used for package resolution.
9
+ * All packages under these folders can be resolved regardless of applyToImportsFrom.
10
+ * applyToImportsFrom is only used to filter which packages the lint rules apply to.
11
+ */
12
+ var PACKAGE_RESOLUTION_ROOTS = ['platform/packages'];
13
+
14
+ /**
15
+ * Get yarn.lock modification time for cache invalidation.
16
+ * Returns 0 if yarn.lock doesn't exist.
17
+ */
18
+ function getYarnLockMtime(_ref) {
19
+ var workspaceRoot = _ref.workspaceRoot,
20
+ fs = _ref.fs;
21
+ var yarnLockPath = join(workspaceRoot, 'yarn.lock');
22
+ try {
23
+ if (fs.existsSync(yarnLockPath)) {
24
+ var _stats$mtimeMs;
25
+ var stats = fs.statSync(yarnLockPath);
26
+ return (_stats$mtimeMs = stats.mtimeMs) !== null && _stats$mtimeMs !== void 0 ? _stats$mtimeMs : 0;
27
+ }
28
+ } catch (_unused) {
29
+ // Ignore errors
30
+ }
31
+ return 0;
32
+ }
33
+
34
+ /**
35
+ * Check if the cache is valid for the given workspace root.
36
+ * Cache is invalid if:
37
+ * - The cache is not fully initialized
38
+ * - The workspace root has changed
39
+ * - The yarn.lock file has been modified
40
+ */
41
+ function isCacheValid(_ref2) {
42
+ var cache = _ref2.cache,
43
+ workspaceRoot = _ref2.workspaceRoot,
44
+ fs = _ref2.fs;
45
+ // Cache is invalid if not initialized
46
+ if (!cache.packageNameToDir || !cache.scannedDirectories) {
47
+ return false;
48
+ }
49
+
50
+ // Cache is invalid if workspace root changed
51
+ if (cache.workspaceRoot !== workspaceRoot) {
52
+ return false;
53
+ }
54
+
55
+ // Cache is invalid if yarn.lock mtime changed
56
+ var currentMtime = getYarnLockMtime({
57
+ workspaceRoot: workspaceRoot,
58
+ fs: fs
59
+ });
60
+ return currentMtime === cache.yarnLockMtime;
61
+ }
62
+
63
+ /**
64
+ * Read package name from a package.json file.
65
+ * Returns null if the file doesn't exist or doesn't have a valid name.
66
+ */
67
+ function readPackageName(_ref3) {
68
+ var packageJsonPath = _ref3.packageJsonPath,
69
+ fs = _ref3.fs;
70
+ try {
71
+ if (!fs.existsSync(packageJsonPath)) {
72
+ return null;
73
+ }
74
+ var content = fs.readFileSync(packageJsonPath, 'utf-8');
75
+ var pkg = JSON.parse(content);
76
+ if (pkg.name && typeof pkg.name === 'string') {
77
+ return pkg.name;
78
+ }
79
+ } catch (_unused2) {
80
+ // Ignore errors (invalid JSON, etc.)
81
+ }
82
+ return null;
83
+ }
84
+
85
+ /**
86
+ * Recursively scan a directory for packages and update the cache.
87
+ * Directories are cached (including those without packages) to avoid re-scanning.
88
+ *
89
+ * Once a package.json is found, subdirectories are not scanned since packages
90
+ * don't contain nested packages. The exception is target folder roots (e.g., 'platform')
91
+ * which may have a package.json but still contain packages in subdirectories.
92
+ */
93
+ function scanDirectoryForPackages(_ref4) {
94
+ var dir = _ref4.dir,
95
+ cache = _ref4.cache,
96
+ fs = _ref4.fs,
97
+ _ref4$isTargetRoot = _ref4.isTargetRoot,
98
+ isTargetRoot = _ref4$isTargetRoot === void 0 ? false : _ref4$isTargetRoot,
99
+ nestedTargetRoots = _ref4.nestedTargetRoots;
100
+ // Skip if already scanned
101
+ if (cache.scannedDirectories.has(dir)) {
102
+ return;
103
+ }
104
+
105
+ // Mark as scanned (even if it doesn't contain a package)
106
+ cache.scannedDirectories.add(dir);
107
+ try {
108
+ // Check for package.json in current directory
109
+ var packageJsonPath = join(dir, 'package.json');
110
+ var packageName = readPackageName({
111
+ packageJsonPath: packageJsonPath,
112
+ fs: fs
113
+ });
114
+ if (packageName) {
115
+ cache.packageNameToDir.set(packageName, dir);
116
+ // Don't scan subdirectories - packages don't contain nested packages
117
+ // Exception: target folder roots (e.g., 'platform') may have packages in subdirectories
118
+ if (!isTargetRoot) {
119
+ return;
120
+ }
121
+ }
122
+
123
+ // Recursively scan subdirectories
124
+ var entries = fs.readdirSync(dir, {
125
+ withFileTypes: true
126
+ });
127
+ var _iterator = _createForOfIteratorHelper(entries),
128
+ _step;
129
+ try {
130
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
131
+ var entry = _step.value;
132
+ // Skip node_modules, hidden directories, and non-directories
133
+ if (!entry.isDirectory() || entry.name === 'node_modules' || entry.name.startsWith('.')) {
134
+ continue;
135
+ }
136
+ scanDirectoryForPackages({
137
+ dir: join(dir, entry.name),
138
+ cache: cache,
139
+ fs: fs,
140
+ // Only certain directory levels are treated as "target roots"
141
+ isTargetRoot: nestedTargetRoots.has(dir),
142
+ nestedTargetRoots: nestedTargetRoots
143
+ });
144
+ }
145
+ } catch (err) {
146
+ _iterator.e(err);
147
+ } finally {
148
+ _iterator.f();
149
+ }
150
+ } catch (_unused3) {
151
+ // Directory doesn't exist or not readable, skip
152
+ }
153
+ }
154
+
155
+ /**
156
+ * Ensure all packages under platform/packages have been scanned.
157
+ * Initializes or updates the cache on fs.cache as needed.
158
+ * Package resolution is not constrained by applyToImportsFrom - any package can be resolved.
159
+ */
160
+ function ensureCachePopulated(_ref5) {
161
+ var workspaceRoot = _ref5.workspaceRoot,
162
+ fs = _ref5.fs;
163
+ // Check if cache is still valid
164
+ if (isCacheValid({
165
+ cache: fs.cache,
166
+ workspaceRoot: workspaceRoot,
167
+ fs: fs
168
+ })) {
169
+ return;
170
+ }
171
+ perfInc({
172
+ fs: fs,
173
+ key: 'packageRegistry.rebuild'
174
+ });
175
+ return perfTime({
176
+ fs: fs,
177
+ key: 'packageRegistry.rebuildMs',
178
+ fn: function fn() {
179
+ // Initialize fresh cache
180
+ fs.cache.packageNameToDir = new Map();
181
+ fs.cache.scannedDirectories = new Set();
182
+ fs.cache.yarnLockMtime = getYarnLockMtime({
183
+ workspaceRoot: workspaceRoot,
184
+ fs: fs
185
+ });
186
+ fs.cache.workspaceRoot = workspaceRoot;
187
+ // When the workspace graph changes, clear derived caches as well
188
+ fs.cache.packageExportsByDir = new Map();
189
+
190
+ // Scan all packages under the resolution roots
191
+ // This is not constrained by applyToImportsFrom - any package can be resolved
192
+ // The immediate children of each root (e.g., ai-mate, search) are treated as
193
+ // "nested target roots" - they may have a package.json but still contain nested packages
194
+ var _iterator2 = _createForOfIteratorHelper(PACKAGE_RESOLUTION_ROOTS),
195
+ _step2;
196
+ try {
197
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
198
+ var resolutionRoot = _step2.value;
199
+ var targetPath = join(workspaceRoot, resolutionRoot);
200
+ scanDirectoryForPackages({
201
+ dir: targetPath,
202
+ cache: fs.cache,
203
+ fs: fs,
204
+ isTargetRoot: true,
205
+ nestedTargetRoots: new Set([targetPath])
206
+ });
207
+ }
208
+ } catch (err) {
209
+ _iterator2.e(err);
210
+ } finally {
211
+ _iterator2.f();
212
+ }
213
+ }
214
+ });
215
+ }
216
+
217
+ /**
218
+ * Find the package directory for a given package name.
219
+ * Returns the absolute path to the package directory or null if not found.
220
+ *
221
+ * This function uses lazy scanning - it will scan platform/packages on first lookup
222
+ * and cache results in fs.cache for subsequent lookups.
223
+ *
224
+ * Note: Package resolution is NOT constrained by applyToImportsFrom. Any package under
225
+ * platform/packages can be resolved. Use isPackageInApplyToImportsFrom to check if a
226
+ * package should be processed by the lint rule.
227
+ */
228
+ export function findPackageInRegistry(_ref6) {
229
+ var _fs$cache$packageName, _fs$cache$packageName2;
230
+ var packageName = _ref6.packageName,
231
+ workspaceRoot = _ref6.workspaceRoot,
232
+ fs = _ref6.fs;
233
+ // Ensure cache is populated
234
+ ensureCachePopulated({
235
+ workspaceRoot: workspaceRoot,
236
+ fs: fs
237
+ });
238
+
239
+ // Look up the package
240
+ return (_fs$cache$packageName = (_fs$cache$packageName2 = fs.cache.packageNameToDir) === null || _fs$cache$packageName2 === void 0 ? void 0 : _fs$cache$packageName2.get(packageName)) !== null && _fs$cache$packageName !== void 0 ? _fs$cache$packageName : null;
241
+ }
242
+
243
+ /**
244
+ * Check if a package is within one of the applyToImportsFrom folders.
245
+ * This can be used to quickly filter out packages that shouldn't be checked.
246
+ */
247
+ export function isPackageInApplyToImportsFrom(_ref7) {
248
+ var packageDir = _ref7.packageDir,
249
+ workspaceRoot = _ref7.workspaceRoot,
250
+ _ref7$applyToImportsF = _ref7.applyToImportsFrom,
251
+ applyToImportsFrom = _ref7$applyToImportsF === void 0 ? DEFAULT_TARGET_FOLDERS : _ref7$applyToImportsF;
252
+ return applyToImportsFrom.some(function (folder) {
253
+ var targetPath = join(workspaceRoot, folder);
254
+ return packageDir.startsWith(targetPath);
255
+ });
256
+ }