Skip to content

Commit

Permalink
Merge pull request #22 from rustymotors/develop
Browse files Browse the repository at this point in the history
chore: Update .gitignore and .npmrc, delete unused vitest.config.js f…
  • Loading branch information
drazisil authored Jul 26, 2024
2 parents a7474c5 + 0868475 commit 41143b1
Show file tree
Hide file tree
Showing 33 changed files with 921 additions and 794 deletions.
14 changes: 12 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ permissions:
actions: read
contents: read


jobs:
main:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -38,6 +39,15 @@ jobs:
# Prepend any command with "nx-cloud record --" to record its logs to Nx Cloud
# - run: pnpm exec nx-cloud record -- echo Hello World
# Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected
- run: pnpm exec nx affected -t lint build test
- run: make test
env:
NX_CLOUD_AUTH_TOKEN: ${{ secrets.NX_CLOUD_AUTH_TOKEN }}
- name: Upload test results to Codecov
if: ${{ !cancelled() }}
uses: codecov/test-results-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
- name: Upload coverage reports to Codecov
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,10 @@ node_modules
.nx/workspace-data
*.sqlite
coverage
*.xml

# tell Git to ignore/stop ignoring this file
#$ git update-index --assume-unchanged <file-to-ignore>
#$ git update-index --no-assume-unchanged <file-to-ignore>
# Credit: https://web.archive.org/web/20240726013834/https://practicalgit.com/blog/make-git-ignore-local-changes-to-tracked-files.html
nx.json
5 changes: 0 additions & 5 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
use-node-version=22.5.1
strict-peer-dependencies=false
ublish-branch=main
save-prefix=""
link-workspace-packages=false
save-workspace-protocol=rolling
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
test:
./scripts/inject-token.sh
pnpm exec nx affected -t lint build test

@PHONY: test
2 changes: 1 addition & 1 deletion apps/server/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ export default tseslint.config(
...tseslint.configs.disableTypeChecked,
},
{
ignores: ["**/dist/*"],
ignores: ["**/coverage/*", "**/dist/*"],
}
);
17 changes: 11 additions & 6 deletions apps/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,28 @@
"type": "module",
"scripts": {
"clean": "rm -rf dist",
"build": "tsc",
"build": "tsc --build --verbose",
"check-types": "tsc --noEmit",
"start": "node dist/index.js",
"lint": "eslint src",
"start": "node dist/src/index.js",
"test": "vitest",
"dev": "node --import 'data:text/javascript,import { register } from \"node:module\"; import { pathToFileURL } from \"node:url\"; register(\"ts-node/esm\", pathToFileURL(\"./\"));' --watch src/index.ts"
},
"keywords": [],
"author": "",
"license": "GPL-3.0-only",
"devDependencies": {
"@types/node": "^20.14.11",
"@types/node": "20.14.12",
"@types/pino": "7.0.5",
"@vitest/coverage-v8": "^2.0.3",
"eslint": "8",
"@vitest/coverage-v8": "^2.0.4",
"@vitest/ui": "^2.0.4",
"eslint": "^8.57.0",
"nx": "19.5.1",
"ts-node": "^10.9.2",
"tslib": "^2.6.3",
"typescript": "^5.5.4",
"vitest": "^1.3.1"
"vite": "2.0.4",
"vitest": "^2.0.4"
},
"dependencies": {
"@rusty/util": "workspace:*",
Expand Down
11 changes: 1 addition & 10 deletions apps/server/project.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
{
"targets": {
"test": {
"executor": "@nx/vite:test",
"options": {
"command": "vitest run",
"coverage": true,
"reporter": "verbose"
}
}
}
"projectType": "application"
}
19 changes: 2 additions & 17 deletions apps/server/src/ServerController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,7 @@ import { WrappedServer } from "./WrappedServer.js";
import { exit } from "node:process";
import { log } from "@rusty/util";
import { handleWebRequests } from "@rusty/web";

function headerstoRecords(
headers: import("node:http").IncomingHttpHeaders
): Record<string, string> {
const result: Record<string, string> = {};
for (const [key, value] of Object.entries(headers)) {
if (Array.isArray(value)) {
result[key] = value.join(", ");
} else {
if (typeof key === "string" && typeof value === "string") {
result[key] = value;
}
}
}
return result;
}
import { headersToRecords } from "./headersToRecords.js";

/**
*
Expand All @@ -32,7 +17,7 @@ async function handleIncomingRequest(
res: import("node:http").ServerResponse
) {
const response = await handleWebRequests({
headers: headerstoRecords(req.headers),
headers: headersToRecords(req.headers),
remoteAddress: req.socket.remoteAddress || "",
method: req.method || "",
url: req.url || "",
Expand Down
13 changes: 13 additions & 0 deletions apps/server/src/headersToRecords.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export function headersToRecords(
headers: import("node:http").IncomingHttpHeaders
): Record<string, string> {
const result: Record<string, string> = {};
for (const [key, value] of Object.entries(headers)) {
if (Array.isArray(value)) {
result[key] = value.join(", ");
} else if (typeof key === "string" && typeof value === "string") {
result[key] = value;
}
}
return result;
}
33 changes: 33 additions & 0 deletions apps/server/test/headersToRecords.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { describe, expect, test } from "vitest";
import { headersToRecords } from "../src/headersToRecords.js";
import type { IncomingHttpHeaders } from "node:http";

describe("headersToRecords", () => {
test("should convert headers to records", () => {
const headers: IncomingHttpHeaders = {
"content-type": "application/json",
"x-auth-token": "abc123",
accept: "application/json, text/html",
};

const expected = {
"content-type": "application/json",
"x-auth-token": "abc123",
accept: "application/json, text/html",
};

const result = headersToRecords(headers);

expect(result).toEqual(expected);
});

test("should handle empty headers", () => {
const headers = {};

const expected = {};

const result = headersToRecords(headers);

expect(result).toEqual(expected);
});
});
6 changes: 3 additions & 3 deletions apps/server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./dist",
"declarationDir": "./dist"
"declarationDir": "./dist",
"composite": true
},
"include": ["src/**/*.ts", "test/**/*.ts"],
"exclude": ["node_modules", "dist"],
"references": [{ "path": "../../libs/util" }, { "path": "../../libs/web" }]
"exclude": ["node_modules", "dist"]
}
13 changes: 12 additions & 1 deletion apps/server/vitest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@ import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
coverage: {
provider: "v8",
enabled: true,
all: true,
exclude: [
"dist/**",
"eslint.config.js",
"vitest.config.js"
],
reporter: ["lcov", "text", "cobertura"],
},
reporters: ["junit", "default", "hanging-process"],
outputFile: "mcos.junit.xml",
pool: "forks",
watch: false,
},
});
2 changes: 1 addition & 1 deletion libs/util/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ export default tseslint.config(
...tseslint.configs.disableTypeChecked,
},
{
ignores: ["**/dist/*"],
ignores: ["**/coverage/*", "**/dist/*"],
}
);
17 changes: 11 additions & 6 deletions libs/util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,26 @@
"types": "./dist/index.d.ts",
"scripts": {
"clean": "rm -rf dist",
"build": "tsc",
"check-types": "tsc --noEmit"
"build": "tsc --build --verbose",
"test": "vitest",
"check-types": "tsc --noEmit",
"lint": "eslint src"
},
"keywords": [],
"author": "",
"license": "GPL-3.0-only",
"devDependencies": {
"@types/node": "^20.14.11",
"@types/node": "20.14.12",
"@types/pino": "7.0.5",
"@vitest/coverage-v8": "^2.0.3",
"eslint": "8",
"@vitest/coverage-v8": "^2.0.4",
"@vitest/ui": "^2.0.4",
"eslint": "^8.57.0",
"nx": "19.5.1",
"ts-node": "^10.9.2",
"tslib": "^2.6.3",
"typescript": "^5.5.4",
"vitest": "^1.3.1"
"vite": "2.0.4",
"vitest": "^2.0.4"
},
"dependencies": {
"pino": "9.3.1"
Expand Down
12 changes: 0 additions & 12 deletions libs/util/project.json

This file was deleted.

7 changes: 7 additions & 0 deletions libs/util/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { describe, test, expect } from "vitest";

describe("example", () => {
test("example", () => {
expect(1).toBe(1);
});
});
15 changes: 13 additions & 2 deletions libs/util/vitest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@ import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
coverage: {
provider: "v8",
enabled: true,
all: true,
exclude: [
"dist/**",
"eslint.config.js",
"vitest.config.js"
],
reporter: ["lcov", "text", "cobertura"],
},
reporters: ["junit", "default", "hanging-process"],
outputFile: "mcos.junit.xml",
pool: "forks",
watch: false,
},
});
});
2 changes: 1 addition & 1 deletion libs/web/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ export default tseslint.config(
...tseslint.configs.disableTypeChecked,
},
{
ignores: ["**/dist/*"],
ignores: ["**/coverage/*", "**/dist/*"],
}
);
17 changes: 11 additions & 6 deletions libs/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,26 @@
"types": "./dist/index.d.ts",
"scripts": {
"clean": "rm -rf dist",
"build": "tsc",
"check-types": "tsc --noEmit"
"build": "tsc --build --verbose",
"test": "vitest",
"check-types": "tsc --noEmit",
"lint": "eslint src"
},
"keywords": [],
"author": "",
"license": "GPL-3.0-only",
"devDependencies": {
"@types/node": "^20.14.11",
"@types/node": "20.14.12",
"@types/pino": "7.0.5",
"@vitest/coverage-v8": "^2.0.3",
"eslint": "8",
"@vitest/coverage-v8": "^2.0.4",
"@vitest/ui": "^2.0.4",
"eslint": "^8.57.0",
"nx": "19.5.1",
"ts-node": "^10.9.2",
"tslib": "^2.6.3",
"typescript": "^5.5.4",
"vitest": "^1.3.1"
"vite": "2.0.4",
"vitest": "^2.0.4"
},
"dependencies": {
"@rusty/util": "workspace:*",
Expand Down
12 changes: 0 additions & 12 deletions libs/web/project.json

This file was deleted.

6 changes: 4 additions & 2 deletions libs/web/src/db.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Sequelize } from "sequelize";

const DATABASE_URL = process.env.DATABASE_URL || ":memory:";

export const db = new Sequelize({
dialect: "sqlite",
storage: "db.sqlite",
storage: DATABASE_URL,
logging: console.log, // Enable logging
});

db.authenticate()
.then(() => console.log("Database connected..."))
.then(() => db.sync())
.catch((err) => console.error("Error connecting to the database:", err));
Loading

0 comments on commit 41143b1

Please sign in to comment.