@backstage/eslint-plugin 0.1.11 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/docs/rules/no-mixed-plugin-imports.md +20 -1
- package/docs/rules/no-relative-monorepo-imports.md +1 -1
- package/docs/rules/no-undeclared-imports.md +1 -1
- package/lib/getPackages.js +1 -1
- package/package.json +2 -2
- package/rules/no-mixed-plugin-imports.js +27 -0
- package/src/__fixtures__/monorepo/packages/bar/package.json +2 -1
- package/src/__fixtures__/monorepo/packages/bar-override/package.json +19 -0
- package/src/__fixtures__/monorepo/packages/foo/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @backstage/eslint-plugin
|
|
2
2
|
|
|
3
|
+
## 0.1.12
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 5e98e61: Minor doc updates
|
|
8
|
+
- a1dae71: Allow frontend plugin to import from another frontend plugin with same plugin id.
|
|
9
|
+
|
|
10
|
+
This prevents the ESLint rule from incorrectly flagging these imports in the new frontend system
|
|
11
|
+
where plugin override requires cross-plugin imports.
|
|
12
|
+
|
|
3
13
|
## 0.1.11
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
# @backstage/no-mixed-plugin-imports
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This rule ensures that imports between Backstage plugins are consistent with their intended usage.
|
|
4
|
+
|
|
5
|
+
The rule checks the `backstage.role` field in the `package.json` of both the importing and target packages to determine if they are compatible.
|
|
6
|
+
|
|
7
|
+
Plugin roles include:
|
|
8
|
+
|
|
9
|
+
- `frontend-plugin` (or `frontend` for short)
|
|
10
|
+
- `backend-plugin` (or `backend` for short)
|
|
11
|
+
- `web-library` (or `react` for short)
|
|
12
|
+
- `node-library` (or `node` for short)
|
|
13
|
+
- `common-library` (or `common` for short)
|
|
14
|
+
|
|
15
|
+
Prohibited imports include:
|
|
16
|
+
|
|
17
|
+
- A `frontend` plugin importing directly from another `frontend`, `backend`, or `node` package. Instead, it should import from the corresponding `react` or `common` package.
|
|
18
|
+
- With an exception with the new frontend system where frontend plugins with the same plugin id are allowed to import from each other.
|
|
19
|
+
- A `backend` plugin importing directly from another `backend`, `frontend`, or `react` package. Instead, it should import from the corresponding `node` or `common` package.
|
|
20
|
+
- A `react` package importing from `frontend`, `backend`, or `node` packages.
|
|
21
|
+
- A `node` package importing from `frontend`, `backend`, or `react` packages
|
|
22
|
+
- A `common` package importing directly from any other plugin package.
|
|
4
23
|
|
|
5
24
|
## Usage
|
|
6
25
|
|
|
@@ -10,7 +10,7 @@ Add the rules as follows, it has no options:
|
|
|
10
10
|
"@backstage/no-relative-monorepo-imports": ["error"]
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
The following patterns are considered files used during development, and only need dependencies to be declared in devDependencies
|
|
13
|
+
The following patterns are considered files used during development, and only need dependencies to be declared in `devDependencies`:
|
|
14
14
|
|
|
15
15
|
```python
|
|
16
16
|
!src/** # Any files outside of src are considered dev files
|
|
@@ -10,7 +10,7 @@ Add the rules as follows, it has no options:
|
|
|
10
10
|
"@backstage/no-undeclared-imports": ["error"]
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
The following patterns are considered files used during development, and only need dependencies to be declared in devDependencies
|
|
13
|
+
The following patterns are considered files used during development, and only need dependencies to be declared in `devDependencies`:
|
|
14
14
|
|
|
15
15
|
```python
|
|
16
16
|
!src/** # Any files outside of src are considered dev files
|
package/lib/getPackages.js
CHANGED
|
@@ -21,7 +21,7 @@ const manypkg = require('@manypkg/get-packages');
|
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* @typedef ExtendedPackage
|
|
24
|
-
* @type {import('@manypkg/get-packages').Package & { packageJson: { exports?: Record<string, string>, files?: Array<string>, backstage?: { inline?: boolean, role?: string } }}} packageJson
|
|
24
|
+
* @type {import('@manypkg/get-packages').Package & { packageJson: { exports?: Record<string, string>, files?: Array<string>, backstage?: { inline?: boolean, role?: string, pluginId?: string } }}} packageJson
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
27
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/eslint-plugin",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.12",
|
|
4
4
|
"description": "Backstage ESLint plugin",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"minimatch": "^9.0.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@backstage/cli": "^0.
|
|
25
|
+
"@backstage/cli": "^0.34.4",
|
|
26
26
|
"@types/estree": "^1.0.5",
|
|
27
27
|
"eslint": "^8.33.0"
|
|
28
28
|
}
|
|
@@ -64,6 +64,7 @@ module.exports = {
|
|
|
64
64
|
messages: {
|
|
65
65
|
forbidden:
|
|
66
66
|
'{{sourcePackage}} ({{sourceRole}}) uses forbidden import from {{targetPackage}} ({{targetRole}}).',
|
|
67
|
+
useSamePluginId: `Import of {{targetPackage}} ({{targetRole}}) from {{sourceRole}} is forbidden unless you are overriding the plugin, in which case the \`backstage.pluginId\` in {{sourcePackage}}/package.json must be the same as in {{targetPackage}}`,
|
|
67
68
|
useReactPlugin:
|
|
68
69
|
'Use web library {{targetPackage}}-react or common library instead.',
|
|
69
70
|
useNodePlugin:
|
|
@@ -146,11 +147,24 @@ module.exports = {
|
|
|
146
147
|
}
|
|
147
148
|
|
|
148
149
|
const sourceRole = pkg.packageJson.backstage?.role;
|
|
150
|
+
const sourcePluginId = pkg.packageJson.backstage?.pluginId;
|
|
149
151
|
const targetRole = targetPackage.packageJson.backstage?.role;
|
|
152
|
+
const targetPluginId = targetPackage.packageJson.backstage?.pluginId;
|
|
150
153
|
if (!sourceRole || !targetRole) {
|
|
151
154
|
return;
|
|
152
155
|
}
|
|
153
156
|
|
|
157
|
+
// Allow frontend plugins to import from other frontend plugins with the same pluginId for NFS
|
|
158
|
+
if (
|
|
159
|
+
sourceRole === 'frontend-plugin' &&
|
|
160
|
+
targetRole === 'frontend-plugin' &&
|
|
161
|
+
sourcePluginId &&
|
|
162
|
+
targetPluginId &&
|
|
163
|
+
sourcePluginId === targetPluginId
|
|
164
|
+
) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
|
|
154
168
|
if (
|
|
155
169
|
roleRules.some(
|
|
156
170
|
rule =>
|
|
@@ -165,6 +179,19 @@ module.exports = {
|
|
|
165
179
|
(sourceRole === 'frontend-plugin' || sourceRole === 'web-library') &&
|
|
166
180
|
targetRole === 'frontend-plugin'
|
|
167
181
|
) {
|
|
182
|
+
suggest.push({
|
|
183
|
+
messageId: 'useSamePluginId',
|
|
184
|
+
data: {
|
|
185
|
+
targetPackage: targetName,
|
|
186
|
+
targetRole: targetRole,
|
|
187
|
+
sourcePackage: sourceName,
|
|
188
|
+
sourceRole: sourceRole,
|
|
189
|
+
},
|
|
190
|
+
/** @param {import('eslint').Rule.RuleFixer} _fixer */
|
|
191
|
+
fix(_fixer) {
|
|
192
|
+
// Not a fixable case, just give a suggestion to change plugin id
|
|
193
|
+
},
|
|
194
|
+
});
|
|
168
195
|
suggest.push({
|
|
169
196
|
messageId: 'useReactPlugin',
|
|
170
197
|
data: {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@internal/bar-override",
|
|
3
|
+
"backstage": {
|
|
4
|
+
"role": "frontend-plugin",
|
|
5
|
+
"pluginId": "bar"
|
|
6
|
+
},
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./src/index.ts",
|
|
9
|
+
"./BarPage": "./src/components/Bar.tsx",
|
|
10
|
+
"./package.json": "./package.json"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"inline-dep": "*",
|
|
14
|
+
"react-router": "*"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"react-router-dom": "*"
|
|
18
|
+
}
|
|
19
|
+
}
|