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