diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 962cd391..3dc66a09 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,6 +1,7 @@ { "recommendations": [ "esbenp.prettier-vscode", - "typescriptteam.native-preview" + "typescriptteam.native-preview", + "oxc.oxc-vscode" ] } \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index bf804191..7fce74cb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,7 +4,8 @@ }, "editor.codeActionsOnSave": { "source.organizeImports": "explicit", - "source.fixAll.eslint": "explicit" + // oxlint (requires the `oxc.oxc-vscode` extension) + "source.fixAll.oxc": "explicit" }, "[html]": { "editor.defaultFormatter": "esbenp.prettier-vscode", @@ -12,5 +13,10 @@ }, "editor.defaultFormatter": "esbenp.prettier-vscode", "editor.formatOnSave": true, - "typescript.tsdk": "node_modules/typescript/lib" + // UI Setting: + // TypeScript 7 > Experimental: Use Tsgo + // (still experimental in VS Code 1.131; disables the built-in TS/JS + // language features so the native TypeScript 7 server takes over. + // The tsdk is resolved from `node_modules/typescript` automatically.) + "js/ts.experimental.useTsgo": true } diff --git a/.yarnrc.yml b/.yarnrc.yml index 063ed601..dc612810 100644 --- a/.yarnrc.yml +++ b/.yarnrc.yml @@ -4,5 +4,3 @@ approvedGitRepositories: enableScripts: true nodeLinker: node-modules - -npmMinimalAgeGate: 0 diff --git a/src/bin/export-ratings.ts b/src/bin/export-ratings.ts index 802adcbe..714790ff 100644 --- a/src/bin/export-ratings.ts +++ b/src/bin/export-ratings.ts @@ -4,7 +4,7 @@ import { writeFile } from 'node:fs/promises'; import { csfd } from '..'; -import { CSFDUserRatingConfig } from '../dto/user-ratings'; +import type { CSFDUserRatingConfig } from '../dto/user-ratings'; import { escapeCsvField, renderProgress } from './utils'; export interface ExportRatingsOptions { diff --git a/src/bin/export-reviews.ts b/src/bin/export-reviews.ts index e860a4c6..5e3d8bbb 100644 --- a/src/bin/export-reviews.ts +++ b/src/bin/export-reviews.ts @@ -4,7 +4,7 @@ import { writeFile } from 'node:fs/promises'; import { csfd } from '..'; -import { CSFDUserReviewsConfig } from '../dto/user-reviews'; +import type { CSFDUserReviewsConfig } from '../dto/user-reviews'; import { escapeCsvField, renderProgress } from './utils'; export interface ExportReviewsOptions { diff --git a/src/bin/server.ts b/src/bin/server.ts index 8b33843a..9462b43e 100644 --- a/src/bin/server.ts +++ b/src/bin/server.ts @@ -1,9 +1,10 @@ import 'dotenv/config'; -import express, { NextFunction, Request, Response } from 'express'; +import type { NextFunction, Request, Response } from 'express'; +import express from 'express'; import { csfd } from '..'; import packageJson from '../../package.json' with { type: 'json' }; -import { CSFDFilmTypes } from '../dto/global'; -import { CSFDLanguage } from '../types'; +import type { CSFDFilmTypes } from '../dto/global'; +import type { CSFDLanguage } from '../types'; const LOG_COLORS = { info: '\x1b[36m', // cyan diff --git a/src/dto/cinema.ts b/src/dto/cinema.ts index b85e4552..e7783a3a 100644 --- a/src/dto/cinema.ts +++ b/src/dto/cinema.ts @@ -1,4 +1,4 @@ -import { CSFDMovieListItem } from './movie'; +import type { CSFDMovieListItem } from './movie'; export interface CSFDCinema { id: number; diff --git a/src/dto/creator.ts b/src/dto/creator.ts index d77e3814..820ebbef 100644 --- a/src/dto/creator.ts +++ b/src/dto/creator.ts @@ -1,4 +1,4 @@ -import { CSFDScreening } from './global'; +import type { CSFDScreening } from './global'; export interface CSFDCreator { id: number; diff --git a/src/dto/movie.ts b/src/dto/movie.ts index 175cebe5..3c0f77a5 100644 --- a/src/dto/movie.ts +++ b/src/dto/movie.ts @@ -1,4 +1,4 @@ -import { CSFDScreening } from './global'; +import type { CSFDScreening } from './global'; export interface CSFDMovie extends CSFDScreening { rating: number | null; diff --git a/src/dto/search.ts b/src/dto/search.ts index 3e1d1079..068b3d72 100644 --- a/src/dto/search.ts +++ b/src/dto/search.ts @@ -1,5 +1,5 @@ -import { CSFDScreening } from './global'; -import { CSFDMovieCreator } from './movie'; +import type { CSFDScreening } from './global'; +import type { CSFDMovieCreator } from './movie'; export interface CSFDSearch { movies: CSFDSearchMovie[]; diff --git a/src/dto/user-ratings.ts b/src/dto/user-ratings.ts index 483ad245..de13825d 100644 --- a/src/dto/user-ratings.ts +++ b/src/dto/user-ratings.ts @@ -1,4 +1,4 @@ -import { CSFDFilmTypes, CSFDScreening, CSFDStars } from './global'; +import type { CSFDFilmTypes, CSFDScreening, CSFDStars } from './global'; export interface CSFDUserRatings extends CSFDScreening { userRating: CSFDStars; diff --git a/src/dto/user-reviews.ts b/src/dto/user-reviews.ts index 4bb5356d..9e653105 100644 --- a/src/dto/user-reviews.ts +++ b/src/dto/user-reviews.ts @@ -1,4 +1,4 @@ -import { CSFDFilmTypes, CSFDScreening, CSFDStars } from './global'; +import type { CSFDFilmTypes, CSFDScreening, CSFDStars } from './global'; export interface CSFDUserReviews extends CSFDScreening { userRating: CSFDStars; diff --git a/src/fetchers/fetch.polyfill.ts b/src/fetchers/fetch.polyfill.ts index 377b2c7a..cc63d26a 100644 --- a/src/fetchers/fetch.polyfill.ts +++ b/src/fetchers/fetch.polyfill.ts @@ -1,5 +1,8 @@ +declare const window: { fetch?: typeof fetch }; + // Check if `fetch` is available in global scope (nodejs 18+) or in window (browser). export const fetchSafe = (typeof fetch === 'function' && fetch) || // ServiceWorker fetch (Cloud Functions + Chrome extension) (typeof global === 'object' && global.fetch) || // Node.js 18+ fetch (typeof window !== 'undefined' && window.fetch); // Browser fetch + diff --git a/src/helpers/cinema.helper.ts b/src/helpers/cinema.helper.ts index 031d53a6..3bfb1936 100644 --- a/src/helpers/cinema.helper.ts +++ b/src/helpers/cinema.helper.ts @@ -1,7 +1,7 @@ import { HTMLElement } from 'node-html-parser'; -import { CSFDCinemaGroupedFilmsByDate, CSFDCinemaMeta, CSFDCinemaMovie } from '../dto/cinema'; -import { CSFDColorRating } from '../dto/global'; -import { CSFDColors } from '../dto/user-ratings'; +import type { CSFDCinemaGroupedFilmsByDate, CSFDCinemaMeta, CSFDCinemaMovie } from '../dto/cinema'; +import type { CSFDColorRating } from '../dto/global'; +import type { CSFDColors } from '../dto/user-ratings'; import { parseColor, parseIdFromUrl } from './global.helper'; export const getCinemaColorRating = (el: HTMLElement | null): CSFDColorRating => { diff --git a/src/helpers/creator.helper.ts b/src/helpers/creator.helper.ts index e9ddafa1..78758a29 100644 --- a/src/helpers/creator.helper.ts +++ b/src/helpers/creator.helper.ts @@ -1,7 +1,7 @@ import { HTMLElement } from 'node-html-parser'; -import { CSFDCreatorScreening } from '../dto/creator'; -import { CSFDColorRating } from '../dto/global'; -import { CSFDColors } from '../dto/user-ratings'; +import type { CSFDCreatorScreening } from '../dto/creator'; +import type { CSFDColorRating } from '../dto/global'; +import type { CSFDColors } from '../dto/user-ratings'; import { addProtocol, parseColor, parseDate, parseIdFromUrl } from './global.helper'; const getCreatorColorRating = (el: HTMLElement | null): CSFDColorRating => { diff --git a/src/helpers/global.helper.ts b/src/helpers/global.helper.ts index 6f2acb78..dbff5d1f 100644 --- a/src/helpers/global.helper.ts +++ b/src/helpers/global.helper.ts @@ -1,5 +1,5 @@ -import { CSFDColorRating, CSFDFilmTypes } from '../dto/global'; -import { CSFDColors } from '../dto/user-ratings'; +import type { CSFDColorRating, CSFDFilmTypes } from '../dto/global'; +import type { CSFDColors } from '../dto/user-ratings'; const LANG_PREFIX_REGEX = /^[a-z]{2,3}$/; const ISO8601_DURATION_REGEX = diff --git a/src/helpers/search.helper.ts b/src/helpers/search.helper.ts index 32f8f4e6..619715d6 100644 --- a/src/helpers/search.helper.ts +++ b/src/helpers/search.helper.ts @@ -1,7 +1,7 @@ import { HTMLElement } from 'node-html-parser'; -import { CSFDColorRating, CSFDFilmTypes } from '../dto/global'; -import { CSFDMovieCreator } from '../dto/movie'; -import { CSFDColors } from '../dto/user-ratings'; +import type { CSFDColorRating, CSFDFilmTypes } from '../dto/global'; +import type { CSFDMovieCreator } from '../dto/movie'; +import type { CSFDColors } from '../dto/user-ratings'; import { addProtocol, parseColor, parseFilmType, parseIdFromUrl } from './global.helper'; type Creator = 'Režie:' | 'Hrají:'; diff --git a/src/helpers/user-ratings.helper.ts b/src/helpers/user-ratings.helper.ts index ac177ca1..562adb53 100644 --- a/src/helpers/user-ratings.helper.ts +++ b/src/helpers/user-ratings.helper.ts @@ -1,6 +1,6 @@ import { HTMLElement } from 'node-html-parser'; -import { CSFDColorRating, CSFDFilmTypes, CSFDStars } from '../dto/global'; -import { CSFDColors } from '../dto/user-ratings'; +import type { CSFDColorRating, CSFDFilmTypes, CSFDStars } from '../dto/global'; +import type { CSFDColors } from '../dto/user-ratings'; import { parseColor, parseDate, parseFilmType, parseIdFromUrl } from './global.helper'; export const getUserRatingId = (el: HTMLElement): number => { diff --git a/src/helpers/user-reviews.helper.ts b/src/helpers/user-reviews.helper.ts index c7116ed1..64e6784c 100644 --- a/src/helpers/user-reviews.helper.ts +++ b/src/helpers/user-reviews.helper.ts @@ -1,6 +1,6 @@ import { HTMLElement } from 'node-html-parser'; -import { CSFDColorRating, CSFDFilmTypes, CSFDStars } from '../dto/global'; -import { CSFDColors } from '../dto/user-ratings'; +import type { CSFDColorRating, CSFDFilmTypes, CSFDStars } from '../dto/global'; +import type { CSFDColors } from '../dto/user-ratings'; import { parseColor, parseDate, parseFilmType, parseIdFromUrl } from './global.helper'; export const getUserReviewId = (el: HTMLElement): number => { diff --git a/src/index.ts b/src/index.ts index 1fe40ea6..5a9803f7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,16 +1,16 @@ -import { CSFDCinema, CSFDCinemaPeriod } from './dto/cinema'; -import { CSFDCreator } from './dto/creator'; -import { CSFDMovie } from './dto/movie'; -import { CSFDSearch } from './dto/search'; -import { CSFDUserRatingConfig, CSFDUserRatings } from './dto/user-ratings'; -import { CSFDUserReviews, CSFDUserReviewsConfig } from './dto/user-reviews'; +import type { CSFDCinema, CSFDCinemaPeriod } from './dto/cinema'; +import type { CSFDCreator } from './dto/creator'; +import type { CSFDMovie } from './dto/movie'; +import type { CSFDSearch } from './dto/search'; +import type { CSFDUserRatingConfig, CSFDUserRatings } from './dto/user-ratings'; +import type { CSFDUserReviews, CSFDUserReviewsConfig } from './dto/user-reviews'; import { CinemaScraper } from './services/cinema.service'; import { CreatorScraper } from './services/creator.service'; import { MovieScraper } from './services/movie.service'; import { SearchScraper } from './services/search.service'; import { UserRatingsScraper } from './services/user-ratings.service'; import { UserReviewsScraper } from './services/user-reviews.service'; -import { CSFDOptions } from './types'; +import type { CSFDOptions } from './types'; export class Csfd { private defaultOptions?: CSFDOptions; diff --git a/src/services/cinema.service.ts b/src/services/cinema.service.ts index de319a54..4bb76d41 100644 --- a/src/services/cinema.service.ts +++ b/src/services/cinema.service.ts @@ -1,7 +1,7 @@ import { HTMLElement, parse } from 'node-html-parser'; -import { CSFDCinema, CSFDCinemaPeriod } from '../dto/cinema'; +import type { CSFDCinema, CSFDCinemaPeriod } from '../dto/cinema'; import { fetchPage } from '../fetchers'; -import { CSFDOptions } from '../types'; +import type { CSFDOptions } from '../types'; import { cinemasUrl } from '../vars'; import { getCinemaCoords, diff --git a/src/services/creator.service.ts b/src/services/creator.service.ts index 2f878a85..6fed67bc 100644 --- a/src/services/creator.service.ts +++ b/src/services/creator.service.ts @@ -1,7 +1,6 @@ import { HTMLElement, parse } from 'node-html-parser'; -import { CSFDCreator } from '../dto/creator'; +import type { CSFDCreator } from '../dto/creator'; import { fetchPage } from '../fetchers'; -import { extractId } from '../helpers/global.helper'; import { getCreatorBio, getCreatorBirthdayInfo, @@ -9,7 +8,8 @@ import { getCreatorName, getCreatorPhoto } from '../helpers/creator.helper'; -import { CSFDOptions } from '../types'; +import { extractId } from '../helpers/global.helper'; +import type { CSFDOptions } from '../types'; import { creatorUrl } from '../vars'; export class CreatorScraper { diff --git a/src/services/movie.service.ts b/src/services/movie.service.ts index 1f437ad1..885386b0 100644 --- a/src/services/movie.service.ts +++ b/src/services/movie.service.ts @@ -1,6 +1,6 @@ import { HTMLElement, parse } from 'node-html-parser'; -import { CSFDFilmTypes } from '../dto/global'; -import { CSFDMovie, MovieJsonLd } from '../dto/movie'; +import type { CSFDFilmTypes } from '../dto/global'; +import type { CSFDMovie, MovieJsonLd } from '../dto/movie'; import { fetchPage } from '../fetchers'; import { extractId } from '../helpers/global.helper'; import { @@ -29,7 +29,7 @@ import { getSeasonsOrEpisodes, getSeriesAndSeasonTitle } from '../helpers/movie.helper'; -import { CSFDOptions } from '../types'; +import type { CSFDOptions } from '../types'; import { LIB_PREFIX, movieUrl } from '../vars'; export class MovieScraper { diff --git a/src/services/search.service.ts b/src/services/search.service.ts index 9e61d523..fddc9d95 100644 --- a/src/services/search.service.ts +++ b/src/services/search.service.ts @@ -1,5 +1,5 @@ import { HTMLElement, parse } from 'node-html-parser'; -import { CSFDSearch, CSFDSearchCreator, CSFDSearchMovie, CSFDSearchUser } from '../dto/search'; +import type { CSFDSearch, CSFDSearchCreator, CSFDSearchMovie, CSFDSearchUser } from '../dto/search'; import { fetchPage } from '../fetchers'; import { parseIdFromUrl } from '../helpers/global.helper'; import { getCreatorImage, getCreatorName, getCreatorUrl } from '../helpers/search-creator.helper'; @@ -14,7 +14,7 @@ import { getSearchYear, parseSearchPeople } from '../helpers/search.helper'; -import { CSFDLanguage, CSFDOptions } from '../types'; +import type { CSFDLanguage, CSFDOptions } from '../types'; import { getUrlByLanguage, searchUrl } from '../vars'; export class SearchScraper { diff --git a/src/services/user-ratings.service.ts b/src/services/user-ratings.service.ts index c100ca5c..ac6771c3 100644 --- a/src/services/user-ratings.service.ts +++ b/src/services/user-ratings.service.ts @@ -1,6 +1,6 @@ import { HTMLElement, parse } from 'node-html-parser'; -import { CSFDColorRating, CSFDFilmTypes, CSFDStars } from '../dto/global'; -import { CSFDUserRatingConfig, CSFDUserRatings } from '../dto/user-ratings'; +import type { CSFDColorRating, CSFDFilmTypes, CSFDStars } from '../dto/global'; +import type { CSFDUserRatingConfig, CSFDUserRatings } from '../dto/user-ratings'; import { fetchPage } from '../fetchers'; import { sleep } from '../helpers/global.helper'; import { @@ -13,7 +13,7 @@ import { getUserRatingUrl, getUserRatingYear } from '../helpers/user-ratings.helper'; -import { CSFDOptions } from '../types'; +import type { CSFDOptions } from '../types'; import { LIB_PREFIX, userRatingsUrl } from '../vars'; export class UserRatingsScraper { diff --git a/src/services/user-reviews.service.ts b/src/services/user-reviews.service.ts index 95e28a43..c9b25adc 100644 --- a/src/services/user-reviews.service.ts +++ b/src/services/user-reviews.service.ts @@ -1,6 +1,6 @@ import { HTMLElement, parse } from 'node-html-parser'; -import { CSFDColorRating, CSFDFilmTypes, CSFDStars } from '../dto/global'; -import { CSFDUserReviews, CSFDUserReviewsConfig } from '../dto/user-reviews'; +import type { CSFDColorRating, CSFDFilmTypes, CSFDStars } from '../dto/global'; +import type { CSFDUserReviews, CSFDUserReviewsConfig } from '../dto/user-reviews'; import { fetchPage } from '../fetchers'; import { sleep } from '../helpers/global.helper'; import { @@ -15,7 +15,7 @@ import { getUserReviewUrl, getUserReviewYear } from '../helpers/user-reviews.helper'; -import { CSFDOptions } from '../types'; +import type { CSFDOptions } from '../types'; import { LIB_PREFIX, userReviewsUrl } from '../vars'; export class UserReviewsScraper { diff --git a/src/vars.ts b/src/vars.ts index f1db3109..3ced1abe 100644 --- a/src/vars.ts +++ b/src/vars.ts @@ -1,5 +1,5 @@ -import { CSFDCinemaPeriod } from './dto/cinema'; -import { CSFDLanguage } from './types'; +import type { CSFDCinemaPeriod } from './dto/cinema'; +import type { CSFDLanguage } from './types'; export const LIB_PREFIX = '[node-csfd-api]'; diff --git a/tsconfig.json b/tsconfig.json index 6a99e467..503ccc21 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,25 +1,23 @@ { "compilerOptions": { - "target": "ES2022", - "lib": ["ES2022", "DOM"], + "target": "ES2023", + "lib": ["ES2023"], "types": ["node"], - "esModuleInterop": true, + "module": "Preserve", "moduleResolution": "Bundler", "resolveJsonModule": true, + "isolatedModules": true, + + "strict": true, "strictNullChecks": false, // will be more strict in future releases - "allowSyntheticDefaultImports": true, + "noImplicitReturns": true, + "forceConsistentCasingInFileNames": true, - "sourceMap": false, - "outDir": "./dist", - "strict": true, - "declaration": true, - "pretty": true, "skipLibCheck": true, - "alwaysStrict": true, - "noImplicitAny": true, - "noImplicitReturns": true + + "noEmit": true }, "include": ["src"], - "exclude": ["dist/**/*", "*/tests/**/*"] -} + "exclude": ["dist", "**/tests/**"] +} \ No newline at end of file