eslint-plugin: add support for inline packages
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
{
|
||||
"name": "@internal/bar",
|
||||
"backstage": {
|
||||
"role": "frontend-plugin"
|
||||
},
|
||||
"exports": {
|
||||
".": "./src/index.ts",
|
||||
"./BarPage": "./src/components/Bar.tsx",
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"backstage": {
|
||||
"role": "frontend-plugin"
|
||||
},
|
||||
"dependencies": {
|
||||
"inline-dep": "*",
|
||||
"react-router": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "@internal/inline-dep-direct",
|
||||
"files": [
|
||||
"dist",
|
||||
"type-utils"
|
||||
],
|
||||
"dependencies": {
|
||||
"@internal/inline": "workspace:^",
|
||||
"@internal/inline-dep-valid": "workspace:^",
|
||||
"react": "*"
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"name": "@internal/inline-dep-missing",
|
||||
"files": [
|
||||
"dist",
|
||||
"type-utils"
|
||||
]
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "@internal/inline-dep-valid",
|
||||
"files": [
|
||||
"dist",
|
||||
"type-utils"
|
||||
],
|
||||
"peerDependencies": {
|
||||
"react": "*"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "@internal/inline",
|
||||
"backstage": {
|
||||
"inline": true
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
"type-utils"
|
||||
],
|
||||
"dependencies": {
|
||||
"@internal/inline-dep-valid": "workspace:^"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "*"
|
||||
}
|
||||
}
|
||||
@@ -52,6 +52,12 @@ const ERR_SWITCHED = (
|
||||
const ERR_SWITCH_BACK = () => ({
|
||||
message: 'Switch back to import declaration',
|
||||
});
|
||||
const ERR_INLINE_DIRECT = (name: string) => ({
|
||||
message: `The dependency on the inline package ${name} must not be declared in package dependencies.`,
|
||||
});
|
||||
const ERR_INLINE_MISSING = (name: string, missing: string) => ({
|
||||
message: `Each production dependency from the inline package ${name} must be re-declared by this package, the following dependencies are missing: ${missing}`,
|
||||
});
|
||||
|
||||
// cwd must be restored
|
||||
const origDir = process.cwd();
|
||||
@@ -102,6 +108,17 @@ ruleTester.run(RULE, rule, {
|
||||
code: `require('lod' + 'ash')`,
|
||||
filename: joinPath(FIXTURE, 'packages/bar/src/index.ts'),
|
||||
},
|
||||
{
|
||||
code: `import '@internal/inline'`,
|
||||
filename: joinPath(FIXTURE, 'packages/inline-dep-valid/src/index.ts'),
|
||||
},
|
||||
{
|
||||
code: `import '@internal/inline'`,
|
||||
filename: joinPath(
|
||||
FIXTURE,
|
||||
'packages/inline-dep-valid/src/index.test.ts',
|
||||
),
|
||||
},
|
||||
],
|
||||
invalid: [
|
||||
{
|
||||
@@ -264,6 +281,29 @@ ruleTester.run(RULE, rule, {
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
code: `import '@internal/inline'`,
|
||||
output: `import 'directive:inline-imports:@internal/inline'`,
|
||||
filename: joinPath(
|
||||
FIXTURE,
|
||||
'packages/inline-dep-invalid-direct/src/index.ts',
|
||||
),
|
||||
errors: [ERR_INLINE_DIRECT('@internal/inline')],
|
||||
},
|
||||
{
|
||||
code: `import '@internal/inline'`,
|
||||
output: `import 'directive:inline-imports:@internal/inline'`,
|
||||
filename: joinPath(
|
||||
FIXTURE,
|
||||
'packages/inline-dep-invalid-missing/src/index.ts',
|
||||
),
|
||||
errors: [
|
||||
ERR_INLINE_MISSING(
|
||||
'@internal/inline',
|
||||
'@internal/inline-dep-valid, react',
|
||||
),
|
||||
],
|
||||
},
|
||||
|
||||
// Switching back to original import declarations
|
||||
{
|
||||
@@ -302,5 +342,14 @@ ruleTester.run(RULE, rule, {
|
||||
filename: joinPath(FIXTURE, 'packages/bar/src/index.ts'),
|
||||
errors: [ERR_SWITCH_BACK()],
|
||||
},
|
||||
{
|
||||
code: `import 'directive:inline-imports:@internal/inline'`,
|
||||
output: `import '@internal/inline'`,
|
||||
filename: joinPath(
|
||||
FIXTURE,
|
||||
'packages/inline-dep-invalid-direct/src/index.ts',
|
||||
),
|
||||
errors: [ERR_SWITCH_BACK()],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user