@atlaskit/eslint-plugin-platform 2.9.0 → 2.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/cjs/index.js +8 -2
  3. package/dist/cjs/rules/compiled/no-css-prop-in-object-spread/index.js +162 -0
  4. package/dist/cjs/rules/ensure-critical-dependency-resolutions/index.js +0 -1
  5. package/dist/cjs/rules/import/no-barrel-entry-imports/index.js +68 -16
  6. package/dist/cjs/rules/import/no-barrel-entry-jest-mock/index.js +42 -8
  7. package/dist/cjs/rules/import/shared/package-resolution.js +153 -8
  8. package/dist/cjs/rules/no-restricted-fedramp-imports/index.js +65 -0
  9. package/dist/cjs/rules/no-xcss-in-cx/index.js +221 -0
  10. package/dist/cjs/rules/visit-example-type-import-required/index.js +24 -14
  11. package/dist/es2019/index.js +8 -2
  12. package/dist/es2019/rules/compiled/no-css-prop-in-object-spread/index.js +136 -0
  13. package/dist/es2019/rules/ensure-critical-dependency-resolutions/index.js +0 -1
  14. package/dist/es2019/rules/import/no-barrel-entry-imports/index.js +66 -17
  15. package/dist/es2019/rules/import/no-barrel-entry-jest-mock/index.js +43 -9
  16. package/dist/es2019/rules/import/shared/package-resolution.js +119 -4
  17. package/dist/es2019/rules/no-restricted-fedramp-imports/index.js +47 -0
  18. package/dist/es2019/rules/no-xcss-in-cx/index.js +187 -0
  19. package/dist/es2019/rules/visit-example-type-import-required/index.js +24 -15
  20. package/dist/esm/index.js +8 -2
  21. package/dist/esm/rules/compiled/no-css-prop-in-object-spread/index.js +156 -0
  22. package/dist/esm/rules/ensure-critical-dependency-resolutions/index.js +0 -1
  23. package/dist/esm/rules/import/no-barrel-entry-imports/index.js +69 -17
  24. package/dist/esm/rules/import/no-barrel-entry-jest-mock/index.js +43 -9
  25. package/dist/esm/rules/import/shared/package-resolution.js +151 -8
  26. package/dist/esm/rules/no-restricted-fedramp-imports/index.js +59 -0
  27. package/dist/esm/rules/no-xcss-in-cx/index.js +216 -0
  28. package/dist/esm/rules/visit-example-type-import-required/index.js +24 -14
  29. package/dist/types/index.d.ts +278 -241
  30. package/dist/types/rules/compiled/no-css-prop-in-object-spread/index.d.ts +3 -0
  31. package/dist/types/rules/import/shared/package-resolution.d.ts +25 -0
  32. package/dist/types/rules/no-restricted-fedramp-imports/index.d.ts +3 -0
  33. package/dist/types/rules/no-xcss-in-cx/index.d.ts +31 -0
  34. package/dist/types-ts4.5/index.d.ts +222 -209
  35. package/dist/types-ts4.5/rules/compiled/no-css-prop-in-object-spread/index.d.ts +3 -0
  36. package/dist/types-ts4.5/rules/import/shared/package-resolution.d.ts +25 -0
  37. package/dist/types-ts4.5/rules/no-restricted-fedramp-imports/index.d.ts +3 -0
  38. package/dist/types-ts4.5/rules/no-xcss-in-cx/index.d.ts +31 -0
  39. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @atlaskit/eslint-plugin-platform
2
2
 
3
+ ## 2.9.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [`48fa19b8ba41a`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/48fa19b8ba41a) -
8
+ Add `no-xcss-in-cx` ESLint rule to prevent `xcss()` from `@atlaskit/primitives` being called
9
+ inline inside `cx()` in an `xcss` prop. Calling `xcss()` inline produces a StyleRule opaque object
10
+ rather than a Compiled atomic class string, which causes runtime errors. The rule is import-aware
11
+ and recurses into logical (`&&`) and conditional (`?:`) expressions.
12
+
13
+ ## 2.9.1
14
+
15
+ ### Patch Changes
16
+
17
+ - [`5fed54075f1b8`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/5fed54075f1b8) -
18
+ add eslint rule for restricting isFedramp and isIsolatedCloud imports
19
+
3
20
  ## 2.9.0
4
21
 
5
22
  ### Minor Changes
package/dist/cjs/index.js CHANGED
@@ -32,10 +32,12 @@ var _useRecommendedUtils = _interopRequireDefault(require("./rules/feature-gatin
32
32
  var _validGateName = _interopRequireDefault(require("./rules/feature-gating/valid-gate-name"));
33
33
  var _expandBackgroundShorthand = _interopRequireDefault(require("./rules/compiled/expand-background-shorthand"));
34
34
  var _expandSpacingShorthand = _interopRequireDefault(require("./rules/compiled/expand-spacing-shorthand"));
35
+ var _noCssPropInObjectSpread = _interopRequireDefault(require("./rules/compiled/no-css-prop-in-object-spread"));
35
36
  var _noSparseCheckout = _interopRequireDefault(require("./rules/no-sparse-checkout"));
36
37
  var _noDirectDocumentUsage = _interopRequireDefault(require("./rules/no-direct-document-usage"));
37
38
  var _noSetImmediate = _interopRequireDefault(require("./rules/no-set-immediate"));
38
39
  var _preferCryptoRandomUuid = _interopRequireDefault(require("./rules/prefer-crypto-random-uuid"));
40
+ var _noRestrictedFedrampImports = _interopRequireDefault(require("./rules/no-restricted-fedramp-imports"));
39
41
  var _noBarrelEntryImports = _interopRequireDefault(require("./rules/import/no-barrel-entry-imports"));
40
42
  var _noBarrelEntryJestMock = _interopRequireDefault(require("./rules/import/no-barrel-entry-jest-mock"));
41
43
  var _noJestMockBarrelFiles = _interopRequireDefault(require("./rules/import/no-jest-mock-barrel-files"));
@@ -43,6 +45,7 @@ var _noRelativeBarrelFileImports = _interopRequireDefault(require("./rules/impor
43
45
  var _noConversationAssistantBarrelImports = _interopRequireDefault(require("./rules/import/no-conversation-assistant-barrel-imports"));
44
46
  var _visitExampleTypeImportRequired = _interopRequireDefault(require("./rules/visit-example-type-import-required"));
45
47
  var _ensureUseSyncExternalStoreServerSnapshot = _interopRequireDefault(require("./rules/ensure-use-sync-external-store-server-snapshot"));
48
+ var _noXcssInCx = _interopRequireDefault(require("./rules/no-xcss-in-cx"));
46
49
  var _nodePath = require("node:path");
47
50
  var _nodeFs = require("node:fs");
48
51
  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; }
@@ -75,6 +78,7 @@ var rules = exports.rules = {
75
78
  'expand-border-shorthand': _expandBorderShorthand.default,
76
79
  'expand-background-shorthand': _expandBackgroundShorthand.default,
77
80
  'expand-spacing-shorthand': _expandSpacingShorthand.default,
81
+ 'no-css-prop-in-object-spread': _noCssPropInObjectSpread.default,
78
82
  'no-duplicate-dependencies': _noDuplicateDependencies.default,
79
83
  'no-invalid-feature-flag-usage': _noInvalidFeatureFlagUsage.default,
80
84
  'no-pre-post-install-scripts': _noPrePostInstalls.default,
@@ -94,12 +98,14 @@ var rules = exports.rules = {
94
98
  'no-direct-document-usage': _noDirectDocumentUsage.default,
95
99
  'no-set-immediate': _noSetImmediate.default,
96
100
  'prefer-crypto-random-uuid': _preferCryptoRandomUuid.default,
101
+ 'no-restricted-fedramp-imports': _noRestrictedFedrampImports.default,
97
102
  'no-barrel-entry-imports': _noBarrelEntryImports.default,
98
103
  'no-barrel-entry-jest-mock': _noBarrelEntryJestMock.default,
99
104
  'no-jest-mock-barrel-files': _noJestMockBarrelFiles.default,
100
105
  'no-relative-barrel-file-imports': _noRelativeBarrelFileImports.default,
101
106
  'no-conversation-assistant-barrel-imports': _noConversationAssistantBarrelImports.default,
102
107
  'visit-example-type-import-required': _visitExampleTypeImportRequired.default,
108
+ 'no-xcss-in-cx': _noXcssInCx.default,
103
109
  'ensure-use-sync-external-store-server-snapshot': _ensureUseSyncExternalStoreServerSnapshot.default
104
110
  };
105
111
  var commonConfig = {
@@ -112,10 +118,12 @@ var commonConfig = {
112
118
  '@atlaskit/platform/no-module-level-eval-nav4': 'error',
113
119
  '@atlaskit/platform/no-direct-document-usage': 'warn',
114
120
  '@atlaskit/platform/no-set-immediate': 'error',
121
+ '@atlaskit/platform/no-xcss-in-cx': 'error',
115
122
  // Compiled: rules that are not included via `@compiled/recommended
116
123
  '@atlaskit/platform/expand-border-shorthand': 'error',
117
124
  '@atlaskit/platform/expand-background-shorthand': 'error',
118
125
  '@atlaskit/platform/expand-spacing-shorthand': 'error',
126
+ '@atlaskit/platform/no-css-prop-in-object-spread': 'error',
119
127
  '@compiled/jsx-pragma': ['error', {
120
128
  importSources: ['@atlaskit/css'],
121
129
  onlyRunIfImportingCompiled: true,
@@ -157,7 +165,6 @@ var plugin = exports.plugin = {
157
165
  get '@atlaskit/platform'() {
158
166
  return plugin;
159
167
  },
160
- // @ts-expect-error there's an issue with the types for @compiled/eslint-plugin ('no-css-prop-without-css-function' specifically)
161
168
  '@compiled': {
162
169
  meta: _eslintPlugin.default.meta,
163
170
  rules: _eslintPlugin.default.rules
@@ -174,7 +181,6 @@ var plugin = exports.plugin = {
174
181
  get '@atlaskit/platform'() {
175
182
  return plugin;
176
183
  },
177
- // @ts-expect-error there's an issue with the types for @compiled/eslint-plugin ('no-css-prop-without-css-function' specifically)
178
184
  '@compiled': {
179
185
  meta: _eslintPlugin.default.meta,
180
186
  rules: _eslintPlugin.default.rules
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.noCssPropInObjectSpread = exports.default = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _contextCompat = require("../../util/context-compat");
10
+ 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; }
11
+ 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) { (0, _defineProperty2.default)(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; }
12
+ 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; } } }; }
13
+ 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; } }
14
+ 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; }
15
+ /**
16
+ * Returns the `css` Property node from an ObjectExpression, or null if not found.
17
+ */
18
+ function getCssProperty(objectExpression) {
19
+ var _iterator = _createForOfIteratorHelper(objectExpression.properties),
20
+ _step;
21
+ try {
22
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
23
+ var prop = _step.value;
24
+ if (prop.type !== 'Property') {
25
+ continue;
26
+ }
27
+ var key = prop.key;
28
+ if (key.type === 'Identifier' && key.name === 'css' || key.type === 'Literal' && key.value === 'css') {
29
+ return prop;
30
+ }
31
+ }
32
+ } catch (err) {
33
+ _iterator.e(err);
34
+ } finally {
35
+ _iterator.f();
36
+ }
37
+ return null;
38
+ }
39
+ var noCssPropInObjectSpread = exports.noCssPropInObjectSpread = {
40
+ meta: {
41
+ docs: {
42
+ url: 'https://bitbucket.org/atlassian/atlassian-frontend-monorepo/src/master/platform/packages/platform/eslint-plugin/src/rules/compiled/no-css-prop-in-object-spread/',
43
+ description: 'Disallows `css` property inside objects spread into JSX — the Compiled JSX pragma ignores it'
44
+ },
45
+ fixable: 'code',
46
+ messages: {
47
+ noCssPropInObjectSpread: 'The `css` property inside an object spread into JSX is a no-op. The Compiled JSX pragma only processes `css` as a direct JSX attribute. Move `css` out of the spread: <El css={...} />'
48
+ },
49
+ type: 'problem'
50
+ },
51
+ create: function create(context) {
52
+ return {
53
+ JSXSpreadAttribute: function JSXSpreadAttribute(node) {
54
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
55
+ var spreadNode = node;
56
+ var arg = spreadNode.argument;
57
+
58
+ // Case 1: inline object literal — <div {...{ css: styles, id: 'foo' }} />
59
+ if (arg.type === 'ObjectExpression') {
60
+ var objectArg = arg;
61
+ var cssProp = getCssProperty(objectArg);
62
+ if (!cssProp) {
63
+ return;
64
+ }
65
+ context.report({
66
+ node: node,
67
+ messageId: 'noCssPropInObjectSpread',
68
+ fix: function fix(fixer) {
69
+ var sourceCode = (0, _contextCompat.getSourceCode)(context);
70
+ var cssValueText = sourceCode.getText(cssProp.value);
71
+ var remainingProps = objectArg.properties.filter(function (p) {
72
+ return p !== cssProp;
73
+ });
74
+ var directCssProp = "css={".concat(cssValueText, "}");
75
+ if (remainingProps.length === 0) {
76
+ return fixer.replaceText(node, directCssProp);
77
+ }
78
+ var remainingText = remainingProps.map(function (p) {
79
+ return sourceCode.getText(p);
80
+ }).join(', ');
81
+ return fixer.replaceText(node, "".concat(directCssProp, " {...{ ").concat(remainingText, " }}"));
82
+ }
83
+ });
84
+ return;
85
+ }
86
+
87
+ // Case 2: variable reference — <div {...props} />
88
+ if (arg.type === 'Identifier') {
89
+ var scope = (0, _contextCompat.getScope)(context, arg);
90
+ var currentScope = scope;
91
+ var variable = null;
92
+ while (currentScope) {
93
+ var found = currentScope.variables.find(function (v) {
94
+ return v.name === arg.name;
95
+ });
96
+ if (found) {
97
+ variable = found;
98
+ break;
99
+ }
100
+ currentScope = currentScope.upper;
101
+ }
102
+ if (!variable || variable.defs.length === 0) {
103
+ return;
104
+ }
105
+ var def = variable.defs[0];
106
+ if (def.type !== 'Variable' || !def.node.init || def.node.init.type !== 'ObjectExpression') {
107
+ return;
108
+ }
109
+ var initObject = def.node.init;
110
+ var _cssProp = getCssProperty(initObject);
111
+ if (!_cssProp) {
112
+ return;
113
+ }
114
+
115
+ // Only auto-fix when there is exactly one JSX spread site for this variable
116
+ var spreadCount = variable.references.filter(function (ref) {
117
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
118
+ var refParent = ref.identifier.parent;
119
+ return (refParent === null || refParent === void 0 ? void 0 : refParent.type) === 'JSXSpreadAttribute';
120
+ }).length;
121
+ context.report(_objectSpread({
122
+ node: node,
123
+ messageId: 'noCssPropInObjectSpread'
124
+ }, spreadCount === 1 ? {
125
+ fix: function fix(fixer) {
126
+ var sourceCode = (0, _contextCompat.getSourceCode)(context);
127
+ var cssValueText = sourceCode.getText(_cssProp.value);
128
+ var fixes = [];
129
+ var remainingProps = initObject.properties.filter(function (p) {
130
+ return p !== _cssProp;
131
+ });
132
+ if (remainingProps.length === 0) {
133
+ fixes.push(fixer.replaceText(initObject, '{}'));
134
+ } else {
135
+ var propIndex = initObject.properties.indexOf(_cssProp);
136
+ var isLast = propIndex === initObject.properties.length - 1;
137
+ var tokenBefore = sourceCode.getTokenBefore(_cssProp);
138
+ var tokenAfter = sourceCode.getTokenAfter(_cssProp);
139
+ if (!isLast && tokenAfter && tokenAfter.value === ',') {
140
+ var src = sourceCode.getText();
141
+ var afterEnd = tokenAfter.range[1];
142
+ var end = afterEnd;
143
+ while (end < src.length && src[end] === ' ') {
144
+ end++;
145
+ }
146
+ fixes.push(fixer.removeRange([_cssProp.range[0], end]));
147
+ } else if (tokenBefore && tokenBefore.value === ',') {
148
+ fixes.push(fixer.removeRange([tokenBefore.range[0], _cssProp.range[1]]));
149
+ } else {
150
+ fixes.push(fixer.remove(_cssProp));
151
+ }
152
+ }
153
+ fixes.push(fixer.insertTextBefore(node, "css={".concat(cssValueText, "} ")));
154
+ return fixes;
155
+ }
156
+ } : {}));
157
+ }
158
+ }
159
+ };
160
+ }
161
+ };
162
+ var _default = exports.default = noCssPropInObjectSpread;
@@ -18,7 +18,6 @@ var DESIRED_PKG_VERSIONS = {
18
18
  tslib: ['2.6', '2.8'],
19
19
  '@types/react': ['16.14', '18.2', '18.3'],
20
20
  'react-relay': ['npm:atl-react-relay@0.0.0-main-39e79f66'],
21
- 'relay-compiler': ['npm:atl-relay-compiler@0.0.0-main-39e79f66'],
22
21
  'relay-runtime': ['npm:atl-relay-runtime@0.0.0-main-39e79f66'],
23
22
  'relay-test-utils': ['npm:atl-relay-test-utils@0.0.0-main-39e79f66']
24
23
  };
@@ -48,6 +48,10 @@ var ruleMeta = {
48
48
  type: 'string'
49
49
  },
50
50
  description: 'The folder paths (relative to workspace root) containing packages whose imports will be checked and autofixed.'
51
+ },
52
+ preferImportedPackageSubpath: {
53
+ type: 'boolean',
54
+ description: 'Prefer subpaths on the imported barrel package when they bridge to the dependency (e.g. @scope/pkg/subpath instead of @scope/dependency).'
51
55
  }
52
56
  },
53
57
  additionalProperties: false
@@ -247,10 +251,12 @@ function classifySpecifiers(_ref4) {
247
251
  var node = _ref4.node,
248
252
  importContext = _ref4.importContext,
249
253
  workspaceRoot = _ref4.workspaceRoot,
250
- fs = _ref4.fs;
254
+ fs = _ref4.fs,
255
+ preferImportedPackageSubpath = _ref4.preferImportedPackageSubpath;
251
256
  var currentExportPath = importContext.currentExportPath,
252
257
  exportsMap = importContext.exportsMap,
253
- exportMap = importContext.exportMap;
258
+ exportMap = importContext.exportMap,
259
+ importedPackageName = importContext.packageName;
254
260
  var specifiers = node.specifiers;
255
261
  var specifiersByTarget = new Map();
256
262
  var unmappedSpecifiers = [];
@@ -271,6 +277,7 @@ function classifySpecifiers(_ref4) {
271
277
  var kind = 'value';
272
278
  if (spec.type === 'ImportDefaultSpecifier') {
273
279
  nameInSource = 'default';
280
+ kind = node.importKind === 'type' ? 'type' : 'value';
274
281
  } else if (spec.type === 'ImportSpecifier') {
275
282
  nameInSource = getImportedName(spec);
276
283
  var parentImportKind = node.importKind;
@@ -286,6 +293,36 @@ function classifySpecifiers(_ref4) {
286
293
  // Check if this is a cross-package re-export
287
294
  var sourcePackageName = (_exportInfo$crossPack = exportInfo.crossPackageSource) === null || _exportInfo$crossPack === void 0 ? void 0 : _exportInfo$crossPack.packageName;
288
295
  if (sourcePackageName) {
296
+ var targetKey = void 0;
297
+ var resolvedOriginalName = exportInfo.originalName;
298
+ if (preferImportedPackageSubpath) {
299
+ var bridge = (0, _packageResolution.findCrossPackageBridgeExportPath)({
300
+ exportsMap: exportsMap,
301
+ crossPackageName: sourcePackageName,
302
+ exportedName: nameInSource,
303
+ fs: fs
304
+ });
305
+ if (bridge) {
306
+ targetKey = importedPackageName + bridge.exportPath.slice(1);
307
+ if (bridge.entryPointExportName !== undefined) {
308
+ resolvedOriginalName = bridge.entryPointExportName === nameInSource ? undefined : bridge.entryPointExportName;
309
+ }
310
+ if (!specifiersByTarget.has(targetKey)) {
311
+ specifiersByTarget.set(targetKey, []);
312
+ }
313
+ specifiersByTarget.get(targetKey).push({
314
+ spec: _objectSpread(_objectSpread({}, spec), {}, {
315
+ importKind: effectiveKind
316
+ }),
317
+ originalName: resolvedOriginalName,
318
+ targetExportPath: targetKey,
319
+ kind: effectiveKind,
320
+ sourcePackageName: sourcePackageName
321
+ });
322
+ continue;
323
+ }
324
+ }
325
+
289
326
  // For cross-package re-exports, find the most specific subpath in the source package
290
327
  // Note: Package resolution is not constrained by applyToImportsFrom - any package can be resolved
291
328
  var sourcePackageExportsMap = sourcePackageExportsMaps.get(sourcePackageName);
@@ -306,7 +343,6 @@ function classifySpecifiers(_ref4) {
306
343
 
307
344
  // Find the best export path in the source package
308
345
  var _targetExportPath = null;
309
- var resolvedOriginalName = exportInfo.originalName;
310
346
  if (sourcePackageExportsMap) {
311
347
  var _exportInfo$originalN, _matchResult$exportPa;
312
348
  var _sourceExportName = (_exportInfo$originalN = exportInfo.originalName) !== null && _exportInfo$originalN !== void 0 ? _exportInfo$originalN : nameInSource;
@@ -323,7 +359,7 @@ function classifySpecifiers(_ref4) {
323
359
  }
324
360
 
325
361
  // Build the full import path: @package/subpath or just @package if no subpath found
326
- var targetKey = _targetExportPath ? sourcePackageName + _targetExportPath.slice(1) // Remove leading '.' from subpath
362
+ targetKey = _targetExportPath ? sourcePackageName + _targetExportPath.slice(1) // Remove leading '.' from subpath
327
363
  : sourcePackageName;
328
364
  if (!specifiersByTarget.has(targetKey)) {
329
365
  specifiersByTarget.set(targetKey, []);
@@ -698,7 +734,10 @@ function createBarrelImportFix(_ref0) {
698
734
  }
699
735
  } else {
700
736
  // Create new import
701
- var _isTypeImport = node.importKind === 'type';
737
+ var allSpecsAreType = specsWithTarget.every(function (s) {
738
+ return s.kind === 'type';
739
+ });
740
+ var _isTypeImport = node.importKind === 'type' || allSpecsAreType;
702
741
  var importStatement = buildImportStatement({
703
742
  specs: specs,
704
743
  path: newImportPath,
@@ -724,7 +763,10 @@ function createBarrelImportFix(_ref0) {
724
763
  var unmappedSpecs = unmappedSpecifiers.map(function (u) {
725
764
  return u.spec;
726
765
  });
727
- var isTypeImport = node.importKind === 'type';
766
+ var allUnmappedAreType = unmappedSpecifiers.every(function (u) {
767
+ return u.kind === 'type';
768
+ });
769
+ var isTypeImport = node.importKind === 'type' || allUnmappedAreType;
728
770
  var remainingImport = buildImportStatement({
729
771
  specs: unmappedSpecs,
730
772
  path: importPath,
@@ -900,7 +942,8 @@ function handleRequireMemberExpression(_ref13) {
900
942
  context = _ref13.context,
901
943
  workspaceRoot = _ref13.workspaceRoot,
902
944
  fs = _ref13.fs,
903
- applyToImportsFrom = _ref13.applyToImportsFrom;
945
+ applyToImportsFrom = _ref13.applyToImportsFrom,
946
+ preferImportedPackageSubpath = _ref13.preferImportedPackageSubpath;
904
947
  if (node.computed || node.property.type !== 'Identifier') {
905
948
  return;
906
949
  }
@@ -924,7 +967,8 @@ function handleRequireMemberExpression(_ref13) {
924
967
  node: synthetic,
925
968
  importContext: importContext,
926
969
  workspaceRoot: workspaceRoot,
927
- fs: fs
970
+ fs: fs,
971
+ preferImportedPackageSubpath: preferImportedPackageSubpath
928
972
  }),
929
973
  specifiersByTarget = _classifySpecifiers.specifiersByTarget,
930
974
  hasNamespaceImport = _classifySpecifiers.hasNamespaceImport;
@@ -982,7 +1026,8 @@ function handleRequireDestructuringDeclarator(_ref16) {
982
1026
  context = _ref16.context,
983
1027
  workspaceRoot = _ref16.workspaceRoot,
984
1028
  fs = _ref16.fs,
985
- applyToImportsFrom = _ref16.applyToImportsFrom;
1029
+ applyToImportsFrom = _ref16.applyToImportsFrom,
1030
+ preferImportedPackageSubpath = _ref16.preferImportedPackageSubpath;
986
1031
  if (node.id.type !== 'ObjectPattern' || !node.init || node.init.type !== 'CallExpression') {
987
1032
  return;
988
1033
  }
@@ -1048,7 +1093,8 @@ function handleRequireDestructuringDeclarator(_ref16) {
1048
1093
  node: synthetic,
1049
1094
  importContext: importContext,
1050
1095
  workspaceRoot: workspaceRoot,
1051
- fs: fs
1096
+ fs: fs,
1097
+ preferImportedPackageSubpath: preferImportedPackageSubpath
1052
1098
  }),
1053
1099
  specifiersByTarget = _classifySpecifiers2.specifiersByTarget,
1054
1100
  unmappedSpecifiers = _classifySpecifiers2.unmappedSpecifiers,
@@ -1158,7 +1204,8 @@ function handleImportDeclaration(_ref19) {
1158
1204
  context = _ref19.context,
1159
1205
  workspaceRoot = _ref19.workspaceRoot,
1160
1206
  fs = _ref19.fs,
1161
- applyToImportsFrom = _ref19.applyToImportsFrom;
1207
+ applyToImportsFrom = _ref19.applyToImportsFrom,
1208
+ preferImportedPackageSubpath = _ref19.preferImportedPackageSubpath;
1162
1209
  // Resolve import context (validates and extracts package/export info)
1163
1210
  // applyToImportsFrom is used here to filter which packages the rule applies to
1164
1211
  var importContext = resolveImportContext({
@@ -1181,7 +1228,8 @@ function handleImportDeclaration(_ref19) {
1181
1228
  node: node,
1182
1229
  importContext: importContext,
1183
1230
  workspaceRoot: workspaceRoot,
1184
- fs: fs
1231
+ fs: fs,
1232
+ preferImportedPackageSubpath: preferImportedPackageSubpath
1185
1233
  }),
1186
1234
  specifiersByTarget = _classifySpecifiers3.specifiersByTarget,
1187
1235
  unmappedSpecifiers = _classifySpecifiers3.unmappedSpecifiers,
@@ -1234,9 +1282,10 @@ function createRule(fs) {
1234
1282
  return {
1235
1283
  meta: ruleMeta,
1236
1284
  create: function create(context) {
1237
- var _options$applyToImpor;
1285
+ var _options$applyToImpor, _options$preferImport;
1238
1286
  var options = context.options[0] || {};
1239
1287
  var applyToImportsFrom = (_options$applyToImpor = options.applyToImportsFrom) !== null && _options$applyToImpor !== void 0 ? _options$applyToImpor : _fileSystem.DEFAULT_TARGET_FOLDERS;
1288
+ var preferImportedPackageSubpath = (_options$preferImport = options.preferImportedPackageSubpath) !== null && _options$preferImport !== void 0 ? _options$preferImport : false;
1240
1289
  var workspaceRoot = (0, _fileSystem.findWorkspaceRoot)({
1241
1290
  startPath: (0, _path.dirname)(context.filename),
1242
1291
  fs: fs,
@@ -1250,7 +1299,8 @@ function createRule(fs) {
1250
1299
  context: context,
1251
1300
  workspaceRoot: workspaceRoot,
1252
1301
  fs: fs,
1253
- applyToImportsFrom: applyToImportsFrom
1302
+ applyToImportsFrom: applyToImportsFrom,
1303
+ preferImportedPackageSubpath: preferImportedPackageSubpath
1254
1304
  });
1255
1305
  },
1256
1306
  MemberExpression: function MemberExpression(rawNode) {
@@ -1259,7 +1309,8 @@ function createRule(fs) {
1259
1309
  context: context,
1260
1310
  workspaceRoot: workspaceRoot,
1261
1311
  fs: fs,
1262
- applyToImportsFrom: applyToImportsFrom
1312
+ applyToImportsFrom: applyToImportsFrom,
1313
+ preferImportedPackageSubpath: preferImportedPackageSubpath
1263
1314
  });
1264
1315
  },
1265
1316
  VariableDeclarator: function VariableDeclarator(rawNode) {
@@ -1268,7 +1319,8 @@ function createRule(fs) {
1268
1319
  context: context,
1269
1320
  workspaceRoot: workspaceRoot,
1270
1321
  fs: fs,
1271
- applyToImportsFrom: applyToImportsFrom
1322
+ applyToImportsFrom: applyToImportsFrom,
1323
+ preferImportedPackageSubpath: preferImportedPackageSubpath
1272
1324
  });
1273
1325
  }
1274
1326
  };
@@ -671,7 +671,9 @@ function traceSymbolsToExports(_ref10) {
671
671
  exportMap = _ref10.exportMap,
672
672
  exportsMap = _ref10.exportsMap,
673
673
  currentExportPath = _ref10.currentExportPath,
674
- fs = _ref10.fs;
674
+ fs = _ref10.fs,
675
+ barrelPackageName = _ref10.barrelPackageName,
676
+ preferImportedPackageSubpath = _ref10.preferImportedPackageSubpath;
675
677
  var groupedByExport = new Map();
676
678
  var crossPackageGroups = new Map();
677
679
  var unmappedSymbols = [];
@@ -689,16 +691,38 @@ function traceSymbolsToExports(_ref10) {
689
691
 
690
692
  // Check for cross-package source first
691
693
  if (exportInfo.crossPackageSource) {
692
- var key = "".concat(exportInfo.crossPackageSource.packageName).concat(exportInfo.crossPackageSource.exportPath === '.' ? '' : exportInfo.crossPackageSource.exportPath.slice(1));
694
+ var key = void 0;
695
+ var tracedOriginalName = exportInfo.originalName;
696
+ var barrelBridgeExportPath = void 0;
697
+ if (preferImportedPackageSubpath) {
698
+ var bridge = (0, _packageResolution.findCrossPackageBridgeExportPath)({
699
+ exportsMap: exportsMap,
700
+ crossPackageName: exportInfo.crossPackageSource.packageName,
701
+ exportedName: symbolName,
702
+ fs: fs
703
+ });
704
+ if (bridge) {
705
+ key = "".concat(barrelPackageName).concat(bridge.exportPath.slice(1));
706
+ barrelBridgeExportPath = bridge.exportPath;
707
+ if (bridge.entryPointExportName !== undefined) {
708
+ tracedOriginalName = bridge.entryPointExportName === symbolName ? undefined : bridge.entryPointExportName;
709
+ }
710
+ } else {
711
+ key = "".concat(exportInfo.crossPackageSource.packageName).concat(exportInfo.crossPackageSource.exportPath === '.' ? '' : exportInfo.crossPackageSource.exportPath.slice(1));
712
+ }
713
+ } else {
714
+ key = "".concat(exportInfo.crossPackageSource.packageName).concat(exportInfo.crossPackageSource.exportPath === '.' ? '' : exportInfo.crossPackageSource.exportPath.slice(1));
715
+ }
693
716
  if (!crossPackageGroups.has(key)) {
694
717
  crossPackageGroups.set(key, []);
695
718
  }
696
719
  crossPackageGroups.get(key).push({
697
720
  symbolName: symbolName,
698
- originalName: exportInfo.originalName,
721
+ originalName: tracedOriginalName,
699
722
  sourceFilePath: exportInfo.path,
700
723
  isTypeOnly: exportInfo.isTypeOnly,
701
- crossPackageSource: exportInfo.crossPackageSource
724
+ crossPackageSource: exportInfo.crossPackageSource,
725
+ barrelBridgeExportPath: barrelBridgeExportPath
702
726
  });
703
727
  continue;
704
728
  }
@@ -1069,6 +1093,10 @@ var ruleMeta = {
1069
1093
  type: 'string'
1070
1094
  },
1071
1095
  description: 'The folder paths (relative to workspace root) containing packages whose imports will be checked and autofixed.'
1096
+ },
1097
+ preferImportedPackageSubpath: {
1098
+ type: 'boolean',
1099
+ description: 'Prefer subpaths on the mocked barrel package when they bridge to the dependency.'
1072
1100
  }
1073
1101
  },
1074
1102
  additionalProperties: false
@@ -1087,9 +1115,10 @@ function createRule(fs) {
1087
1115
  return {
1088
1116
  meta: ruleMeta,
1089
1117
  create: function create(context) {
1090
- var _options$applyToImpor;
1118
+ var _options$applyToImpor, _options$preferImport;
1091
1119
  var options = context.options[0] || {};
1092
1120
  var applyToImportsFrom = (_options$applyToImpor = options.applyToImportsFrom) !== null && _options$applyToImpor !== void 0 ? _options$applyToImpor : _fileSystem.DEFAULT_TARGET_FOLDERS;
1121
+ var preferImportedPackageSubpath = (_options$preferImport = options.preferImportedPackageSubpath) !== null && _options$preferImport !== void 0 ? _options$preferImport : false;
1093
1122
  var workspaceRoot = (0, _fileSystem.findWorkspaceRoot)({
1094
1123
  startPath: (0, _path.dirname)(context.filename),
1095
1124
  fs: fs,
@@ -1184,7 +1213,9 @@ function createRule(fs) {
1184
1213
  exportMap: raContext.exportMap,
1185
1214
  exportsMap: raContext.exportsMap,
1186
1215
  currentExportPath: raContext.currentExportPath,
1187
- fs: fs
1216
+ fs: fs,
1217
+ barrelPackageName: raContext.packageName,
1218
+ preferImportedPackageSubpath: preferImportedPackageSubpath
1188
1219
  }),
1189
1220
  _groupedByExport = _traceSymbolsToExport.groupedByExport,
1190
1221
  _crossPackageGroups = _traceSymbolsToExport.crossPackageGroups;
@@ -1281,7 +1312,9 @@ function createRule(fs) {
1281
1312
  exportMap: mockContext.exportMap,
1282
1313
  exportsMap: mockContext.exportsMap,
1283
1314
  currentExportPath: mockContext.currentExportPath,
1284
- fs: fs
1315
+ fs: fs,
1316
+ barrelPackageName: mockContext.packageName,
1317
+ preferImportedPackageSubpath: preferImportedPackageSubpath
1285
1318
  }),
1286
1319
  groupedByExport = _traceSymbolsToExport2.groupedByExport,
1287
1320
  crossPackageGroups = _traceSymbolsToExport2.crossPackageGroups,
@@ -1373,8 +1406,9 @@ function createRule(fs) {
1373
1406
 
1374
1407
  // Get cross-package source info from the first symbol (all symbols in same group have same source)
1375
1408
  var crossPackageSource = _symbols[0].crossPackageSource;
1409
+ var bridgeExportPath = _symbols[0].barrelBridgeExportPath;
1376
1410
  crossPackageMockGroups.push({
1377
- exportPath: crossPackageSource.exportPath,
1411
+ exportPath: bridgeExportPath !== null && bridgeExportPath !== void 0 ? bridgeExportPath : crossPackageSource.exportPath,
1378
1412
  importPath: _importPath,
1379
1413
  propertyNames: _symbols.map(function (s) {
1380
1414
  return s.symbolName;