Skip to content

Commit

Permalink
chore: introduce types package, switch to rollup build, update depend…
Browse files Browse the repository at this point in the history
…encies, fix types (#4317)

Co-authored-by: Roland Schläfli <rolandschlaefli@gmail.com>
  • Loading branch information
sjschlapbach and rschlaefli authored Oct 20, 2024
1 parent 53bf3cc commit 6f5cb21
Show file tree
Hide file tree
Showing 181 changed files with 3,309 additions and 3,418 deletions.
18 changes: 17 additions & 1 deletion .github/workflows/check-types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,29 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v4

- uses: pnpm/action-setup@v4
with:
version: 9.10.0
run_install: true

- name: Build all packages and apps
- name: Build relevant packages
run: |
cd packages/markdown
pnpm run build
cd ../grading
pnpm run build
cd ../prisma
pnpm run build
cd ../types
pnpm run build
cd ../util
pnpm run build
cd ../graphql
pnpm run build
cd ../shared-components
pnpm run build
cd ../../apps/backend-docker
pnpm run build
- name: Check prisma package typescript types
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ packages/prisma/src/seed
.turbo

out/
.rollup.cache/
8 changes: 5 additions & 3 deletions apps/backend-docker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
"devDependencies": {
"@cypress/code-coverage": "~3.13.4",
"@istanbuljs/nyc-config-typescript": "~1.0.2",
"@rollup/plugin-node-resolve": "~15.3.0",
"@rollup/plugin-typescript": "~12.1.1",
"@types/cookie-parser": "^1.4.7",
"@types/cors": "^2.8.17",
"@types/express": "^4.17.17",
Expand All @@ -65,19 +67,19 @@
"npm-run-all": "~4.1.5",
"nyc": "~17.1.0",
"prisma": "~5.21.0",
"rollup": "~4.24.0",
"source-map-support": "~0.5.21",
"tsup": "~8.3.0",
"tsx": "~4.19.1",
"typescript": "~5.6.3"
},
"scripts": {
"build": "cross-env NODE_ENV=production run-s build:ts",
"build:instrument": "nyc instrument --compact=false src instrumented",
"build:test": "run-s build:instrument build:ts",
"build:ts": "tsup",
"build:ts": "rollup -c",
"check": "tsc --noEmit",
"dev": "npm-run-all --parallel dev:build dev:run",
"dev:build": "tsup --watch",
"dev:build": "rollup -c --watch",
"dev:doppler": "doppler run --config dev -- pnpm run dev",
"dev:lti": "pnpm run dev",
"dev:offline": "pnpm run dev",
Expand Down
31 changes: 31 additions & 0 deletions apps/backend-docker/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { nodeResolve } from '@rollup/plugin-node-resolve'
import typescript from '@rollup/plugin-typescript'
import { defineConfig } from 'rollup'

const config = defineConfig([
{
// Main build configuration
input:
process.env.NODE_ENV === 'test'
? ['instrumented/index.ts']
: ['src/index.ts'],
output: {
dir: 'dist',
format: 'esm',
sourcemap: true,
// preserveModules: true,
// preserveModulesRoot: 'src',
entryFileNames: '[name].js',
},
plugins: [
nodeResolve(),
typescript({
tsconfig: './tsconfig.json',
rootDir: process.env.NODE_ENV === 'test' ? 'instrumented' : 'src',
}),
],
external: [/@klicker-uzh*/, /node_modules/], // Exclude node_modules and specific external dependencies
},
])

export default config
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default async function execute(prisma: PrismaMigrationClient) {

const elementInstances = await prisma.elementInstance.findMany({})
const filteredElementInstances = elementInstances.filter(
// @ts-ignore - elementData has been updated in the meantim
(elem) => typeof elem.elementData.questionId === 'undefined'
)
for (const elem of filteredElementInstances) {
Expand All @@ -48,10 +49,12 @@ export default async function execute(prisma: PrismaMigrationClient) {
typeof elem.elementData.id === 'number'
? `${elem.elementData.id}-v1`
: elem.elementData.id,
// @ts-ignore - elementData has been updated in the meantim
questionId:
typeof elem.elementData.id === 'number'
? elem.elementData.id
: elem.elementData.questionId,
: // @ts-ignore - elementData has been updated in the meantim
elem.elementData.questionId,
},
},
})
Expand Down
2 changes: 1 addition & 1 deletion apps/backend-docker/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function prepareApp({ prisma, redisExec, pubSub, cache, emitter }: any) {
)
},
// TODO: persist both JWT in separate ctx objects? (allow for parallel logins as user and participant)
secretOrKey: process.env.APP_SECRET,
secretOrKey: process.env.APP_SECRET as string,
// issuer: 'abcd',
// audience: 'localhost',
},
Expand Down
4 changes: 3 additions & 1 deletion apps/backend-docker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ if (
process.env.NODE_ENV === 'development' &&
process.env.PRISMA_OPTIMIZE === 'true'
) {
prisma = prisma.$extends(withOptimize()) as PrismaClient
prisma = prisma.$extends(
withOptimize({ apiKey: process.env.PRISMA_OPTIMIZE_API_KEY as string })
) as PrismaClient
}

// if (process.env.SENTRY_DSN) {
Expand Down
4 changes: 2 additions & 2 deletions apps/backend-docker/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"include": ["./src/**/*", "./scripts/**/*"],
"exclude": ["instrumented/"],
"include": ["./src/**/*", "./scripts/**/*", "./instrumented/**/*"],
"compilerOptions": {
"baseUrl": ".",
/* Base Options: */
Expand All @@ -20,6 +19,7 @@
"module": "NodeNext",
"outDir": "dist",
"sourceMap": true,
"tsBuildInfoFile": "dist/tsconfig.tsbuildinfo",
/* If your code doesn't run in the DOM: */
"lib": ["es2022"]
}
Expand Down
11 changes: 0 additions & 11 deletions apps/backend-docker/tsup.config.ts

This file was deleted.

2 changes: 1 addition & 1 deletion apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"react-text-transition": "~3.1.0",
"recharts": "~2.13.0",
"rehype-katex": "~7.0.1",
"remark-math": "~5.1.1",
"remark-math": "~6.0.0",
"tailwind-merge": "~2.5.4",
"tailwindcss": "~3.4.14",
"typescript": "~5.6.3"
Expand Down
50 changes: 24 additions & 26 deletions apps/frontend-control/src/lib/apollo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,34 +46,32 @@ function createIsomorphLink() {

const errorLink = onError(({ graphQLErrors, networkError }) => {
if (graphQLErrors)
graphQLErrors.forEach(
({ message, locations, path, extensions, originalError }) => {
console.log(
`[GraphQL error]: Message: ${message}, Locations: ${util.inspect(
locations,
false,
null,
true
)}, Path: ${path}, Extensions: ${util.inspect(
extensions,
false,
null,
true
)}, Original: ${originalError}`
)
graphQLErrors.forEach(({ message, locations, path, extensions }) => {
console.log(
`[GraphQL error]: Message: ${message}, Locations: ${util.inspect(
locations,
false,
null,
true
)}, Path: ${path}, Extensions: ${util.inspect(
extensions,
false,
null,
true
)}`
)

// redirect the user to the login page on errors
if (isBrowser && message === 'Unauthorized') {
Router.push(
`/login?expired=true&redirect_to=${
encodeURIComponent(
window?.location?.pathname + (window?.location?.search ?? '')
) ?? '/'
}`
)
}
// redirect the user to the login page on errors
if (isBrowser && message === 'Unauthorized') {
Router.push(
`/login?expired=true&redirect_to=${
encodeURIComponent(
window?.location?.pathname + (window?.location?.search ?? '')
) ?? '/'
}`
)
}
)
})
if (networkError) console.log(`[Network error]`, networkError)
})

Expand Down
2 changes: 1 addition & 1 deletion apps/frontend-manage/src/components/common/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function DataTable<TData, TValue>({
suffix={dayjs().format('YYYY-MM-DD')}
filename={csvFilename}
columns={csvColumns}
datas={data}
datas={data as Record<string, string | undefined | null>[]}
separator=";"
>
<Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ import { useTranslations } from 'next-intl'
import { twMerge } from 'tailwind-merge'
import GroupsLeaderboard from './GroupsLeaderboard'
import GroupsList from './GroupsList'
import IndividualLeaderboard from './IndividualLeaderboard'
import IndividualLeaderboard, {
type InvididualLeaderboardEntry,
} from './IndividualLeaderboard'

interface CourseGamificationInfosProps {
course: Course
course: Omit<Course, 'leaderboard' | 'sessions'> & {
leaderboard?: InvididualLeaderboardEntry[] | null
}
tabValue: string
setTabValue: (newValue: string) => void
}
Expand Down Expand Up @@ -67,8 +71,14 @@ function CourseGamificationInfos({
data={{ cy: 'tab-groups' }}
/>
</Tabs.TabList>
<IndividualLeaderboard course={course} />
<GroupsLeaderboard course={course} />
<IndividualLeaderboard
leaderboard={course.leaderboard}
courseName={course.name}
numOfParticipants={course.numOfParticipants}
numOfActiveParticipants={course.numOfActiveParticipants}
averageActiveScore={course.averageActiveScore}
/>
<GroupsLeaderboard />
<GroupsList
courseId={course.id}
groupCreationFinalized={course.randomAssignmentFinalized}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Course } from '@klicker-uzh/graphql/dist/ops'
import { Tabs, UserNotification } from '@uzh-bf/design-system'
import { useTranslations } from 'next-intl'

function GroupsLeaderboard({ course }: { course: Course }) {
function GroupsLeaderboard() {
const t = useTranslations()

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
import DataTable from '@components/common/DataTable'
import { Course } from '@klicker-uzh/graphql/dist/ops'
import { LeaderboardEntry } from '@klicker-uzh/graphql/dist/ops'
import { Tabs } from '@uzh-bf/design-system'
import { TableCell } from '@uzh-bf/design-system/dist/future'
import { useTranslations } from 'next-intl'

function IndividualLeaderboard({ course }: { course: Course }) {
export type InvididualLeaderboardEntry = Omit<
LeaderboardEntry,
'level' | 'participantId' | 'participation'
>

interface IndividualLeaderboardProps {
leaderboard?: InvididualLeaderboardEntry[] | null
courseName: string
numOfParticipants?: number | null
numOfActiveParticipants?: number | null
averageActiveScore?: number | null
}

function IndividualLeaderboard({
leaderboard,
courseName,
numOfParticipants,
numOfActiveParticipants,
averageActiveScore,
}: IndividualLeaderboardProps) {
const t = useTranslations()

return (
Expand All @@ -30,8 +49,8 @@ function IndividualLeaderboard({ course }: { course: Course }) {
header: t('shared.leaderboard.points'),
},
]}
data={course.leaderboard ?? []}
csvFilename={`${course.name.replace(' ', '-')}_leaderboard`}
data={leaderboard ?? []}
csvFilename={`${courseName.replace(' ', '-')}_leaderboard`}
className={{
tableHeader: 'h-7 p-2',
tableCell: 'h-7 p-2',
Expand All @@ -43,13 +62,13 @@ function IndividualLeaderboard({ course }: { course: Course }) {
>
<div>
{t('manage.course.participantsLeaderboard', {
number: course.numOfActiveParticipants,
number: numOfActiveParticipants,
})}
/{course.numOfParticipants}
/{numOfParticipants}
</div>
<div>
{t('manage.course.avgPoints', {
points: course.averageActiveScore?.toFixed(2),
points: averageActiveScore?.toFixed(2),
})}
</div>
</TableCell>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export function getAccessLink({
<div className="text-primary-100 flex cursor-pointer flex-row items-center gap-1">
<FontAwesomeIcon icon={faCopy} size="sm" className="w-4" />
<div>
{/* @ts-expect-error next-intl dictionary is not correctly typed */}
{t('manage.course.copyAccessLink')}
{typeof label == 'string' && ` (${label})`}
</div>
Expand Down Expand Up @@ -81,6 +82,7 @@ export function getLTIAccessLink({
<div className="text-primary-100 flex cursor-pointer flex-row items-center gap-1">
<FontAwesomeIcon icon={faLink} size="sm" className="w-4" />
<div>
{/* @ts-expect-error next-intl dictionary is not correctly typed */}
{t('manage.course.copyLTIAccessLink')}
{typeof label == 'string' && ` (${label})`}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ interface GroupActivityStartingModalProps {
open: boolean
setOpen: (open: boolean) => void
activityId: string
activityEndDate: Date
activityEndDate: string
courseId: string
groupDeadlineDate: Date
groupDeadlineDate: string
numOfParticipantGroups: number
}

Expand Down Expand Up @@ -78,7 +78,8 @@ function GroupActivityStartingModal({
confirmationsInitializing={false}
confirmationType="confirm"
>
{numOfParticipantGroups === 0 || groupDeadlineDate > new Date() ? (
{numOfParticipantGroups === 0 ||
dayjs(groupDeadlineDate).isAfter(dayjs()) ? (
<UserNotification
type="warning"
message={
Expand Down
Loading

0 comments on commit 6f5cb21

Please sign in to comment.