@atlaskit/eslint-plugin-platform 2.7.1 → 2.8.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 (125) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/cjs/index.js +17 -9
  3. package/dist/cjs/rules/constants.js +1 -1
  4. package/dist/cjs/rules/ensure-critical-dependency-resolutions/index.js +5 -5
  5. package/dist/cjs/rules/ensure-no-private-dependencies/index.js +48 -66
  6. package/dist/cjs/rules/feature-gating/inline-usage/index.js +14 -3
  7. package/dist/cjs/rules/feature-gating/no-alias/index.js +1 -1
  8. package/dist/cjs/rules/feature-gating/no-module-level-eval/index.js +1 -1
  9. package/dist/cjs/rules/feature-gating/no-module-level-eval-nav4/index.js +1 -1
  10. package/dist/cjs/rules/feature-gating/no-preconditioning/index.js +4 -1
  11. package/dist/cjs/rules/feature-gating/prefer-fg/index.js +1 -1
  12. package/dist/cjs/rules/feature-gating/static-feature-flags/index.js +2 -2
  13. package/dist/cjs/rules/feature-gating/use-recommended-utils/index.js +1 -1
  14. package/dist/cjs/rules/feature-gating/valid-gate-name/index.js +60 -0
  15. package/dist/cjs/rules/import/no-barrel-entry-imports/index.js +871 -0
  16. package/dist/cjs/rules/import/no-barrel-entry-jest-mock/index.js +1384 -0
  17. package/dist/cjs/rules/import/no-conversation-assistant-barrel-imports/index.js +43 -0
  18. package/dist/cjs/rules/import/no-jest-mock-barrel-files/index.js +1401 -0
  19. package/dist/cjs/rules/import/no-relative-barrel-file-imports/index.js +777 -0
  20. package/dist/cjs/rules/import/shared/barrel-parsing.js +511 -0
  21. package/dist/cjs/rules/import/shared/file-system.js +186 -0
  22. package/dist/cjs/rules/import/shared/jest-utils.js +191 -0
  23. package/dist/cjs/rules/import/shared/package-registry.js +263 -0
  24. package/dist/cjs/rules/import/shared/package-resolution.js +185 -0
  25. package/dist/cjs/rules/import/shared/perf.js +89 -0
  26. package/dist/cjs/rules/import/shared/types.js +67 -0
  27. package/dist/cjs/rules/no-invalid-storybook-decorator-usage/index.js +1 -1
  28. package/dist/cjs/rules/no-sparse-checkout/index.js +1 -1
  29. package/dist/cjs/rules/prefer-crypto-random-uuid/index.js +87 -0
  30. package/dist/cjs/rules/use-entrypoints-in-examples/index.js +1 -1
  31. package/dist/es2019/index.js +17 -9
  32. package/dist/es2019/rules/constants.js +1 -1
  33. package/dist/es2019/rules/ensure-critical-dependency-resolutions/index.js +5 -5
  34. package/dist/es2019/rules/ensure-no-private-dependencies/index.js +10 -9
  35. package/dist/es2019/rules/feature-gating/inline-usage/index.js +14 -3
  36. package/dist/es2019/rules/feature-gating/no-alias/index.js +1 -1
  37. package/dist/es2019/rules/feature-gating/no-module-level-eval/index.js +1 -1
  38. package/dist/es2019/rules/feature-gating/no-module-level-eval-nav4/index.js +1 -1
  39. package/dist/es2019/rules/feature-gating/no-preconditioning/index.js +4 -1
  40. package/dist/es2019/rules/feature-gating/prefer-fg/index.js +1 -1
  41. package/dist/es2019/rules/feature-gating/static-feature-flags/index.js +2 -2
  42. package/dist/es2019/rules/feature-gating/use-recommended-utils/index.js +1 -1
  43. package/dist/es2019/rules/feature-gating/valid-gate-name/index.js +52 -0
  44. package/dist/es2019/rules/import/no-barrel-entry-imports/index.js +801 -0
  45. package/dist/es2019/rules/import/no-barrel-entry-jest-mock/index.js +1113 -0
  46. package/dist/es2019/rules/import/no-conversation-assistant-barrel-imports/index.js +37 -0
  47. package/dist/es2019/rules/import/no-jest-mock-barrel-files/index.js +1179 -0
  48. package/dist/es2019/rules/import/no-relative-barrel-file-imports/index.js +738 -0
  49. package/dist/es2019/rules/import/shared/barrel-parsing.js +433 -0
  50. package/dist/es2019/rules/import/shared/file-system.js +174 -0
  51. package/dist/es2019/rules/import/shared/jest-utils.js +159 -0
  52. package/dist/es2019/rules/import/shared/package-registry.js +240 -0
  53. package/dist/es2019/rules/import/shared/package-resolution.js +161 -0
  54. package/dist/es2019/rules/import/shared/perf.js +83 -0
  55. package/dist/es2019/rules/import/shared/types.js +57 -0
  56. package/dist/es2019/rules/no-invalid-storybook-decorator-usage/index.js +1 -1
  57. package/dist/es2019/rules/no-sparse-checkout/index.js +1 -1
  58. package/dist/es2019/rules/prefer-crypto-random-uuid/index.js +81 -0
  59. package/dist/es2019/rules/use-entrypoints-in-examples/index.js +1 -1
  60. package/dist/esm/index.js +17 -9
  61. package/dist/esm/rules/constants.js +1 -1
  62. package/dist/esm/rules/ensure-critical-dependency-resolutions/index.js +5 -5
  63. package/dist/esm/rules/ensure-no-private-dependencies/index.js +48 -65
  64. package/dist/esm/rules/feature-gating/inline-usage/index.js +14 -3
  65. package/dist/esm/rules/feature-gating/no-alias/index.js +1 -1
  66. package/dist/esm/rules/feature-gating/no-module-level-eval/index.js +1 -1
  67. package/dist/esm/rules/feature-gating/no-module-level-eval-nav4/index.js +1 -1
  68. package/dist/esm/rules/feature-gating/no-preconditioning/index.js +4 -1
  69. package/dist/esm/rules/feature-gating/prefer-fg/index.js +1 -1
  70. package/dist/esm/rules/feature-gating/static-feature-flags/index.js +2 -2
  71. package/dist/esm/rules/feature-gating/use-recommended-utils/index.js +1 -1
  72. package/dist/esm/rules/feature-gating/valid-gate-name/index.js +53 -0
  73. package/dist/esm/rules/import/no-barrel-entry-imports/index.js +864 -0
  74. package/dist/esm/rules/import/no-barrel-entry-jest-mock/index.js +1375 -0
  75. package/dist/esm/rules/import/no-conversation-assistant-barrel-imports/index.js +37 -0
  76. package/dist/esm/rules/import/no-jest-mock-barrel-files/index.js +1391 -0
  77. package/dist/esm/rules/import/no-relative-barrel-file-imports/index.js +770 -0
  78. package/dist/esm/rules/import/shared/barrel-parsing.js +500 -0
  79. package/dist/esm/rules/import/shared/file-system.js +176 -0
  80. package/dist/esm/rules/import/shared/jest-utils.js +179 -0
  81. package/dist/esm/rules/import/shared/package-registry.js +256 -0
  82. package/dist/esm/rules/import/shared/package-resolution.js +175 -0
  83. package/dist/esm/rules/import/shared/perf.js +80 -0
  84. package/dist/esm/rules/import/shared/types.js +61 -0
  85. package/dist/esm/rules/no-invalid-storybook-decorator-usage/index.js +1 -1
  86. package/dist/esm/rules/no-sparse-checkout/index.js +1 -1
  87. package/dist/esm/rules/prefer-crypto-random-uuid/index.js +81 -0
  88. package/dist/esm/rules/use-entrypoints-in-examples/index.js +1 -1
  89. package/dist/types/index.d.ts +18 -16
  90. package/dist/types/rules/import/no-barrel-entry-imports/index.d.ts +9 -0
  91. package/dist/types/rules/import/no-barrel-entry-jest-mock/index.d.ts +9 -0
  92. package/dist/types/rules/import/no-conversation-assistant-barrel-imports/index.d.ts +3 -0
  93. package/dist/types/rules/import/no-jest-mock-barrel-files/index.d.ts +22 -0
  94. package/dist/types/rules/import/no-relative-barrel-file-imports/index.d.ts +5 -0
  95. package/dist/types/rules/import/shared/barrel-parsing.d.ts +30 -0
  96. package/dist/types/rules/import/shared/file-system.d.ts +38 -0
  97. package/dist/types/rules/import/shared/jest-utils.d.ts +47 -0
  98. package/dist/types/rules/import/shared/package-registry.d.ts +26 -0
  99. package/dist/types/rules/import/shared/package-resolution.d.ts +38 -0
  100. package/dist/types/rules/import/shared/perf.d.ts +13 -0
  101. package/dist/types/rules/import/shared/types.d.ts +131 -0
  102. package/dist/types/rules/prefer-crypto-random-uuid/index.d.ts +3 -0
  103. package/dist/types-ts4.5/index.d.ts +18 -28
  104. package/dist/types-ts4.5/rules/import/no-barrel-entry-imports/index.d.ts +9 -0
  105. package/dist/types-ts4.5/rules/import/no-barrel-entry-jest-mock/index.d.ts +9 -0
  106. package/dist/types-ts4.5/rules/import/no-jest-mock-barrel-files/index.d.ts +22 -0
  107. package/dist/types-ts4.5/rules/import/no-relative-barrel-file-imports/index.d.ts +5 -0
  108. package/dist/types-ts4.5/rules/import/shared/barrel-parsing.d.ts +30 -0
  109. package/dist/types-ts4.5/rules/import/shared/file-system.d.ts +38 -0
  110. package/dist/types-ts4.5/rules/import/shared/jest-utils.d.ts +47 -0
  111. package/dist/types-ts4.5/rules/import/shared/package-registry.d.ts +26 -0
  112. package/dist/types-ts4.5/rules/import/shared/package-resolution.d.ts +38 -0
  113. package/dist/types-ts4.5/rules/import/shared/perf.d.ts +13 -0
  114. package/dist/types-ts4.5/rules/import/shared/types.d.ts +131 -0
  115. package/package.json +4 -5
  116. package/dist/cjs/rules/ensure-feature-flag-prefix/index.js +0 -75
  117. package/dist/cjs/rules/ensure-native-and-af-exports-synced/index.js +0 -158
  118. package/dist/es2019/rules/ensure-feature-flag-prefix/index.js +0 -65
  119. package/dist/es2019/rules/ensure-native-and-af-exports-synced/index.js +0 -146
  120. package/dist/esm/rules/ensure-feature-flag-prefix/index.js +0 -69
  121. package/dist/esm/rules/ensure-native-and-af-exports-synced/index.js +0 -151
  122. /package/dist/types/rules/{ensure-native-and-af-exports-synced → feature-gating/valid-gate-name}/index.d.ts +0 -0
  123. /package/dist/types-ts4.5/rules/{ensure-feature-flag-prefix → feature-gating/valid-gate-name}/index.d.ts +0 -0
  124. /package/dist/types-ts4.5/rules/{ensure-native-and-af-exports-synced → import/no-conversation-assistant-barrel-imports}/index.d.ts +0 -0
  125. /package/dist/{types/rules/ensure-feature-flag-prefix → types-ts4.5/rules/prefer-crypto-random-uuid}/index.d.ts +0 -0
@@ -0,0 +1,179 @@
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
+ * Determine the best new import path for a jest.requireMock() call by inspecting
129
+ * the destructured symbols or property access at the call site.
130
+ *
131
+ * @param requireMockNode - The jest.requireMock() CallExpression node
132
+ * @param symbolToNewPath - Map from symbol name to the new mock path that provides it
133
+ * @returns The resolved new path, or null if it cannot be determined
134
+ */
135
+ export function resolveNewPathForRequireMock(_ref2) {
136
+ var requireMockNode = _ref2.requireMockNode,
137
+ symbolToNewPath = _ref2.symbolToNewPath;
138
+ var parent = requireMockNode.parent;
139
+ if (parent) {
140
+ var _parent;
141
+ // Check for destructuring pattern: const { foo } = jest.requireMock('...')
142
+ var declarator = parent.type === 'VariableDeclarator' ? parent : ((_parent = parent.parent) === null || _parent === void 0 ? void 0 : _parent.type) === 'VariableDeclarator' ? parent.parent : null;
143
+ if (declarator && declarator.type === 'VariableDeclarator' && declarator.id.type === 'ObjectPattern') {
144
+ var _iterator2 = _createForOfIteratorHelper(declarator.id.properties),
145
+ _step2;
146
+ try {
147
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
148
+ var prop = _step2.value;
149
+ if (prop.type === 'Property' && prop.key.type === 'Identifier') {
150
+ var matchedPath = symbolToNewPath.get(prop.key.name);
151
+ if (matchedPath) {
152
+ return matchedPath;
153
+ }
154
+ }
155
+ }
156
+ } catch (err) {
157
+ _iterator2.e(err);
158
+ } finally {
159
+ _iterator2.f();
160
+ }
161
+ }
162
+
163
+ // Check for property access pattern: jest.requireMock('...').foo
164
+ if (parent.type === 'MemberExpression' && parent.property.type === 'Identifier') {
165
+ var _matchedPath = symbolToNewPath.get(parent.property.name);
166
+ if (_matchedPath) {
167
+ return _matchedPath;
168
+ }
169
+ }
170
+ }
171
+
172
+ // Fallback: if only one new path exists, use it
173
+ var uniquePaths = new Set(symbolToNewPath.values());
174
+ if (uniquePaths.size === 1) {
175
+ var _uniquePaths$values$n;
176
+ return (_uniquePaths$values$n = uniquePaths.values().next().value) !== null && _uniquePaths$values$n !== void 0 ? _uniquePaths$values$n : null;
177
+ }
178
+ return null;
179
+ }
@@ -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
+ }
@@ -0,0 +1,175 @@
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 { join } from 'path';
7
+ import { readFileContent, resolveImportPath } from './file-system';
8
+ import { findPackageInRegistry } from './package-registry';
9
+ /**
10
+ * Parse the package.json exports field and return a map of export paths to resolved file paths.
11
+ */
12
+ export function parsePackageExports(_ref) {
13
+ var packageDir = _ref.packageDir,
14
+ fs = _ref.fs;
15
+ // Memoize per-package to avoid repeated reads/parses during IDE lint runs.
16
+ // Additionally, invalidate per-package if the package.json mtime changes
17
+ // (covers unstaged local edits in IDE).
18
+ if (!fs.cache.packageExportsByDir) {
19
+ fs.cache.packageExportsByDir = new Map();
20
+ }
21
+ var packageJsonPath = join(packageDir, 'package.json');
22
+ var currentMtimeMs = null;
23
+ try {
24
+ var _fs$statSync$mtimeMs;
25
+ currentMtimeMs = (_fs$statSync$mtimeMs = fs.statSync(packageJsonPath).mtimeMs) !== null && _fs$statSync$mtimeMs !== void 0 ? _fs$statSync$mtimeMs : null;
26
+ } catch (_unused) {
27
+ // If package.json can't be stat'ed (missing/inaccessible), use null to force re-read
28
+ currentMtimeMs = null;
29
+ }
30
+ var cached = fs.cache.packageExportsByDir.get(packageDir);
31
+ // Only use cache if we have a valid mtime and it matches
32
+ if (cached && currentMtimeMs !== null && cached.packageJsonMtimeMs === currentMtimeMs) {
33
+ return cached.exportsMap;
34
+ }
35
+ var exportsMap = new Map();
36
+ try {
37
+ var content = readFileContent({
38
+ filePath: packageJsonPath,
39
+ fs: fs
40
+ });
41
+ if (!content) {
42
+ return exportsMap;
43
+ }
44
+ var packageJson = JSON.parse(content);
45
+ var exports = packageJson.exports;
46
+ if (!exports || _typeof(exports) !== 'object') {
47
+ return exportsMap;
48
+ }
49
+ for (var _i = 0, _Object$entries = Object.entries(exports); _i < _Object$entries.length; _i++) {
50
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
51
+ exportPath = _Object$entries$_i[0],
52
+ exportValue = _Object$entries$_i[1];
53
+ // Handle both simple string values and conditional exports objects
54
+ var resolvedPath = null;
55
+ if (typeof exportValue === 'string') {
56
+ resolvedPath = exportValue;
57
+ } else if (_typeof(exportValue) === 'object' && exportValue !== null) {
58
+ // Handle conditional exports like { "import": "./...", "require": "./..." }
59
+ // Prefer "import" or "default" or first available
60
+ var condExports = exportValue;
61
+ resolvedPath = condExports['import'] || condExports['default'] || Object.values(condExports)[0];
62
+ }
63
+ if (resolvedPath && typeof resolvedPath === 'string') {
64
+ // Resolve the path relative to the package directory
65
+ var absolutePath = resolveImportPath({
66
+ basedir: packageDir,
67
+ importPath: resolvedPath,
68
+ fs: fs
69
+ });
70
+ if (absolutePath) {
71
+ exportsMap.set(exportPath, absolutePath);
72
+ }
73
+ }
74
+ }
75
+ } catch (_unused2) {
76
+ // Ignore parsing errors
77
+ }
78
+
79
+ // Cache even empty maps to avoid re-reading invalid/missing exports repeatedly.
80
+ fs.cache.packageExportsByDir.set(packageDir, {
81
+ packageJsonMtimeMs: currentMtimeMs,
82
+ exportsMap: exportsMap
83
+ });
84
+ return exportsMap;
85
+ }
86
+
87
+ /**
88
+ * Find a matching export entry for a given source file path.
89
+ * Returns the export path (e.g., "./controllers/analytics") or null if not found.
90
+ */
91
+ export function findExportForSourceFile(_ref2) {
92
+ var sourceFilePath = _ref2.sourceFilePath,
93
+ exportsMap = _ref2.exportsMap;
94
+ var _iterator = _createForOfIteratorHelper(exportsMap),
95
+ _step;
96
+ try {
97
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
98
+ var _step$value = _slicedToArray(_step.value, 2),
99
+ exportPath = _step$value[0],
100
+ resolvedPath = _step$value[1];
101
+ if (resolvedPath === sourceFilePath) {
102
+ return exportPath;
103
+ }
104
+ }
105
+ } catch (err) {
106
+ _iterator.e(err);
107
+ } finally {
108
+ _iterator.f();
109
+ }
110
+ return null;
111
+ }
112
+
113
+ /**
114
+ * Extract the package name and subpath from an import specifier.
115
+ * Returns null if the import is not a scoped package import.
116
+ */
117
+ export function extractPackageNameFromImport(moduleSpecifier) {
118
+ var match = moduleSpecifier.match(/^(@[^/]+\/[^/]+)(\/.*)?$/);
119
+ if (!match) {
120
+ return null;
121
+ }
122
+ return {
123
+ packageName: match[1],
124
+ subPath: match[2] || ''
125
+ };
126
+ }
127
+
128
+ /**
129
+ * Resolve a cross-package import to its package directory and export info.
130
+ * Returns null if the package is not in the target folder or cannot be resolved.
131
+ */
132
+ export function resolveCrossPackageImport(_ref3) {
133
+ var moduleSpecifier = _ref3.moduleSpecifier,
134
+ workspaceRoot = _ref3.workspaceRoot,
135
+ fs = _ref3.fs;
136
+ // Only handle @atlassian/* scoped packages
137
+ var parsed = extractPackageNameFromImport(moduleSpecifier);
138
+ if (!parsed) {
139
+ return null;
140
+ }
141
+ var packageName = parsed.packageName,
142
+ subPath = parsed.subPath;
143
+
144
+ // Check if package is in target folder
145
+ var packageDir = findPackageInRegistry({
146
+ packageName: packageName,
147
+ workspaceRoot: workspaceRoot,
148
+ fs: fs
149
+ });
150
+ if (!packageDir) {
151
+ return null;
152
+ }
153
+
154
+ // Parse package.json exports
155
+ var exportsMap = parsePackageExports({
156
+ packageDir: packageDir,
157
+ fs: fs
158
+ });
159
+ if (exportsMap.size === 0) {
160
+ return null;
161
+ }
162
+
163
+ // Determine the export path (e.g., '.' or './utils')
164
+ var exportPath = subPath ? '.' + subPath : '.';
165
+ var entryFilePath = exportsMap.get(exportPath);
166
+ if (!entryFilePath) {
167
+ return null;
168
+ }
169
+ return {
170
+ packageName: packageName,
171
+ packageDir: packageDir,
172
+ exportPath: exportPath,
173
+ entryFilePath: entryFilePath
174
+ };
175
+ }
@@ -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
+ }