Skip to content

Commit 727cec6

Browse files
committed
Imports from frontend to backend and vice versa are now restricted.
1 parent 34138a1 commit 727cec6

File tree

6 files changed

+372
-14
lines changed

6 files changed

+372
-14
lines changed

.eslintrc.cjs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,47 @@
22
module.exports = {
33
root: true,
44
parser: "@typescript-eslint/parser",
5-
plugins: ["@typescript-eslint", "prettier"],
5+
plugins: ["import", "@typescript-eslint", "prettier"],
66
extends: [
77
"eslint:recommended",
8+
"plugin:import/recommended",
9+
"plugin:import/typescript",
810
"plugin:@typescript-eslint/eslint-recommended",
911
"plugin:@typescript-eslint/recommended",
1012
"prettier",
1113
],
1214
parserOptions: {
1315
ecmaVersion: "latest",
1416
},
15-
ignorePatterns: ["dist", "node_modules"],
17+
settings: {
18+
"import/resolver": {
19+
typescript: true,
20+
node: true,
21+
},
22+
},
23+
ignorePatterns: ["**/dist/*", "**/node_modules/*"],
1624
rules: {
1725
"prettier/prettier": ["error"],
1826
// Fix annoying CRLF vs LF error.
1927
"linebreak-style": ["error", process.platform === "win32" ? "windows" : "unix"],
28+
29+
"import/no-restricted-paths": [
30+
"error",
31+
{
32+
zones: [
33+
{
34+
target: "apps/backend/",
35+
from: "apps/frontend/",
36+
message: "Backend should not import from frontend. Use hotel-management-shared instead.",
37+
},
38+
{
39+
target: "apps/frontend/",
40+
from: "apps/backend/",
41+
message: "Frontend should not import from backend. Use hotel-management-shared instead.",
42+
},
43+
],
44+
},
45+
],
2046
},
2147
overrides: [
2248
{

apps/backend/src/main.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ const PORT = 3000;
1111
const app = express();
1212
app.use(cors());
1313

14-
const hotels: Hotel[] = [
15-
{ id: 1, name: "City Centre" },
16-
{ id: 2, name: "Messe" },
17-
{ id: 3, name: "Westend" },
14+
export type BackendHotel = Hotel & {
15+
updateCount: number;
16+
};
17+
18+
const hotels: BackendHotel[] = [
19+
{ id: 1, name: "City Centre", updateCount: 0 },
20+
{ id: 2, name: "Messe", updateCount: 0 },
21+
{ id: 3, name: "Westend", updateCount: 0 },
1822
];
1923

2024
app.get("/hotels", (request, response) => {

apps/frontend/src/components/HotelList.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<script setup lang="ts">
2-
import type { Hotel } from "hotel-management-shared";
2+
// import type { Hotel } from "hotel-management-shared";
3+
4+
import type { BackendHotel } from "../../../backend/dist/main.js";
35
46
const props = defineProps<{
5-
hotels: Hotel[];
7+
hotels: BackendHotel[];
68
}>();
79
</script>
810

apps/frontend/src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { createApp } from "vue";
22
import { createPinia } from "pinia";
33

44
import App from "./App.vue";
5-
import router from "./router";
5+
import router from "./router/index.js";
66

77
import "./assets/main.scss";
88

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
"@typescript-eslint/parser": "5.49.0",
2626
"eslint": "8.22.0",
2727
"eslint-config-prettier": "8.6.0",
28+
"eslint-import-resolver-typescript": "3.5.3",
29+
"eslint-plugin-import": "2.27.5",
2830
"eslint-plugin-prettier": "4.2.1",
2931
"npm-run-all": "4.1.5",
3032
"prettier": "2.7.1",

0 commit comments

Comments
 (0)