From fb04557de327cf05a0c339b3fcd14f9e8e2fda11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Fern=C3=A1ndez?= Date: Thu, 9 Jan 2025 23:38:29 +0100 Subject: [PATCH] feat: create tauri-runtime package MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fernando Fernández --- frontend/package.json | 4 ++++ frontend/scripts/paths.ts | 2 +- frontend/vite.config.ts | 20 ++++++++++++------- package-lock.json | 14 +++++++++++++ packages/configs/src/lint/rules/base.ts | 4 ++-- packages/tauri-runtime/entrypoint.ts | 9 +++++++++ packages/tauri-runtime/eslint.config.ts | 9 +++++++++ packages/tauri-runtime/package.json | 26 +++++++++++++++++++++++++ packages/tauri-runtime/src/main.ts | 0 packages/tauri-runtime/tsconfig.json | 14 +++++++++++++ packages/tauri-runtime/vite.config.ts | 18 +++++++++++++++++ packages/vite-plugins/src/index.ts | 8 ++++---- 12 files changed, 114 insertions(+), 14 deletions(-) create mode 100644 packages/tauri-runtime/entrypoint.ts create mode 100644 packages/tauri-runtime/eslint.config.ts create mode 100644 packages/tauri-runtime/package.json create mode 100644 packages/tauri-runtime/src/main.ts create mode 100644 packages/tauri-runtime/tsconfig.json create mode 100644 packages/tauri-runtime/vite.config.ts diff --git a/frontend/package.json b/frontend/package.json index bcd4c5484de..73a469696f1 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -8,6 +8,10 @@ "imports": { "#/*": "./src/*" }, + "exports": { + ".": "./src/main.ts", + "./vite-config": "./vite.config.ts" + }, "scripts": { "analyze:bundle": "vite build --mode analyze:bundle", "analyze:cycles": "vite build --mode analyze:cycles", diff --git a/frontend/scripts/paths.ts b/frontend/scripts/paths.ts index f79dbc21379..d85629d9452 100644 --- a/frontend/scripts/paths.ts +++ b/frontend/scripts/paths.ts @@ -1,3 +1,3 @@ import { resolve } from 'node:path'; -export const localeFilesFolder = resolve('locales/**'); +export const localeFilesFolder = resolve(import.meta.dirname, '../locales/**'); diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index 52becb91e56..9e511d40f10 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -1,4 +1,4 @@ -import { join } from 'node:path'; +import { resolve } from 'node:path'; import VueI18nPlugin from '@intlify/unplugin-vue-i18n/vite'; import Virtual from '@rollup/plugin-virtual'; import VueDevTools from 'vite-plugin-vue-devtools'; @@ -31,9 +31,14 @@ export default defineConfig({ BundleSizeReport(), Virtual(virtualModules), VueRouter({ - dts: './types/global/routes.d.ts', + dts: resolve(import.meta.dirname, 'types/global/routes.d.ts'), importMode: 'sync', - routeBlockLang: 'yaml' + routeBlockLang: 'yaml', + routesFolder: [ + { + src: resolve(import.meta.dirname, 'src/pages') + } + ] }), Vue({ template: { @@ -44,7 +49,8 @@ export default defineConfig({ }), // This plugin allows to autoimport Vue components Components({ - dts: './types/global/components.d.ts', + dirs: [resolve(import.meta.dirname, 'src/components')], + dts: resolve(import.meta.dirname, 'types/global/components.d.ts'), /** * The icons resolver finds icons components from 'unplugin-icons' using this convenction: * {prefix}-{collection}-{icon} e.g. @@ -87,9 +93,9 @@ export default defineConfig({ reportCompressedSize: false, rollupOptions: { input: { - splashscreen: join(import.meta.dirname, 'src/splashscreen.ts'), - main: join(import.meta.dirname, 'src/main.ts'), - index: join(import.meta.dirname, 'index.html') + splashscreen: resolve(import.meta.dirname, 'src/splashscreen.ts'), + main: resolve(import.meta.dirname, 'src/main.ts'), + index: resolve(import.meta.dirname, 'index.html') }, output: { validate: true diff --git a/package-lock.json b/package-lock.json index e64f373344d..fd5b987b45f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2984,6 +2984,10 @@ "resolved": "packaging/tauri", "link": true }, + "node_modules/@jellyfin-vue/tauri-runtime": { + "resolved": "packages/tauri-runtime", + "link": true + }, "node_modules/@jellyfin-vue/ui-toolkit": { "resolved": "packages/ui-toolkit", "link": true @@ -13105,6 +13109,16 @@ "@jellyfin-vue/configs": "*" } }, + "packages/tauri-runtime": { + "name": "@jellyfin-vue/tauri-runtime", + "dependencies": { + "@jellyfin-vue/frontend": "*" + }, + "devDependencies": { + "@jellyfin-vue/configs": "*", + "vite": "6.0.7" + } + }, "packages/ui-toolkit": { "name": "@jellyfin-vue/ui-toolkit", "dependencies": { diff --git a/packages/configs/src/lint/rules/base.ts b/packages/configs/src/lint/rules/base.ts index 7ffd4ce2469..3cd7acea0a8 100644 --- a/packages/configs/src/lint/rules/base.ts +++ b/packages/configs/src/lint/rules/base.ts @@ -1,4 +1,4 @@ -import { join, basename } from 'node:path'; +import { basename, resolve } from 'node:path'; import { spawnSync } from 'node:child_process'; import type { Linter } from 'eslint'; import { findUpSync } from 'find-up-simple'; @@ -35,7 +35,7 @@ export function getBaseConfig(packageName: string, forceCache = !CI_environment, const newArgs = process.argv.slice(1); if (forceCache && !(newArgs.includes('--cache') && newArgs.includes('--cache-location'))) { - const cacheLocation = join(findUpSync('node_modules', { type: 'directory' }) ?? '', '.cache/eslint', packageName.replace('/', '_')); + const cacheLocation = resolve(findUpSync('node_modules', { type: 'directory' }) ?? '', '.cache/eslint', packageName.replace('/', '_')); newArgs.push('--cache', '--cache-location', cacheLocation); console.log(`[@jellyfin-vue/configs/lint] (${packageName}) Force enabling caching for this run`); diff --git a/packages/tauri-runtime/entrypoint.ts b/packages/tauri-runtime/entrypoint.ts new file mode 100644 index 00000000000..d5fb95427a4 --- /dev/null +++ b/packages/tauri-runtime/entrypoint.ts @@ -0,0 +1,9 @@ +import './src/main.ts'; +/** + * The Tauri-specific code must be loaded before the frontend code to ensure that + * all the polyfills for the runtime have been loaded + * before the frontend code is executed. + * + * THIS IMPORT ALWAYS NEEDS TO BE THE LAST IMPORT IN THIS FILE + */ +import '@jellyfin-vue/frontend'; diff --git a/packages/tauri-runtime/eslint.config.ts b/packages/tauri-runtime/eslint.config.ts new file mode 100644 index 00000000000..96866c6f329 --- /dev/null +++ b/packages/tauri-runtime/eslint.config.ts @@ -0,0 +1,9 @@ +import type { Linter } from 'eslint'; +import { getBaseConfig, getNodeFiles, getTSVueConfig, tsFiles } from '@jellyfin-vue/configs/lint'; +import pkg from './package.json' with { type: 'json' }; + +export default [ + ...getBaseConfig(pkg.name), + ...getTSVueConfig(false, import.meta.dirname), + ...getNodeFiles(tsFiles) +] satisfies Linter.Config[]; diff --git a/packages/tauri-runtime/package.json b/packages/tauri-runtime/package.json new file mode 100644 index 00000000000..58f7efafc11 --- /dev/null +++ b/packages/tauri-runtime/package.json @@ -0,0 +1,26 @@ +{ + "name": "@jellyfin-vue/tauri-runtime", + "type": "module", + "description": "The frontend including tauri-specific runtime code", + "scripts": { + "analyze:bundle": "vite build --mode analyze:bundle", + "analyze:cycles": "vite build --mode analyze:cycles", + "lint": "eslint . --flag unstable_ts_config", + "lint:fix": "eslint . --fix --flag unstable_ts_config", + "lint:inspect": "eslint-config-inspector", + "build": "vite build", + "check": "npm run lint && npm run check:types", + "check:types": "vue-tsc", + "start": "vite", + "serve": "vite preview", + "prod": "npm run build && npm run serve", + "clean": "git clean -fxd" + }, + "devDependencies": { + "@jellyfin-vue/configs": "*", + "vite": "6.0.7" + }, + "dependencies": { + "@jellyfin-vue/frontend": "*" + } +} diff --git a/packages/tauri-runtime/src/main.ts b/packages/tauri-runtime/src/main.ts new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/tauri-runtime/tsconfig.json b/packages/tauri-runtime/tsconfig.json new file mode 100644 index 00000000000..0692e8899d2 --- /dev/null +++ b/packages/tauri-runtime/tsconfig.json @@ -0,0 +1,14 @@ +{ + "extends": "@jellyfin-vue/configs/typescript", + "compilerOptions": { + "baseUrl": "." + }, + "exclude": [ + "dist", + "node_modules", + "coverage" + ], + "include": [ + "**/*.ts" + ] +} diff --git a/packages/tauri-runtime/vite.config.ts b/packages/tauri-runtime/vite.config.ts new file mode 100644 index 00000000000..c692c0ee099 --- /dev/null +++ b/packages/tauri-runtime/vite.config.ts @@ -0,0 +1,18 @@ +import { resolve } from 'node:path'; +import { defineConfig } from 'vite'; +// @ts-expect-error - This error will be fixed once the Vite team adds monorepo support for config files +import OriginalViteConfig from '../../frontend/vite.config.ts'; + +export default defineConfig({ + ...OriginalViteConfig, + build: { + ...OriginalViteConfig.build, + rollupOptions: { + ...OriginalViteConfig.build?.rollupOptions, + input: { + ...OriginalViteConfig.build?.rollupOptions?.input, + main: resolve(import.meta.dirname, 'entrypoint.ts') + } + } + } +}); diff --git a/packages/vite-plugins/src/index.ts b/packages/vite-plugins/src/index.ts index 0f4499f90a0..70ccf8abac1 100644 --- a/packages/vite-plugins/src/index.ts +++ b/packages/vite-plugins/src/index.ts @@ -1,4 +1,4 @@ -import { basename, join } from 'node:path'; +import { basename, resolve } from 'node:path'; import { globSync } from 'node:fs'; import { lstat, rename, rm } from 'node:fs/promises'; import type { LiteralUnion } from 'type-fest'; @@ -18,7 +18,7 @@ const defaultConfig = { build: { outDir: 'dist' } }; */ export function BundleAnalysis(): Plugin { let mode: LiteralUnion<'analyze:bundle' | 'analyze:cycles', string>; - const report_filename = () => join(defaultConfig.build.outDir, 'bundle-report.html'); + const report_filename = () => resolve(defaultConfig.build.outDir, 'bundle-report.html'); const warnings: RollupLog[] = []; return { @@ -69,9 +69,9 @@ export function BundleAnalysis(): Plugin { throw new Error('There are circular dependencies'); } } else if (mode === 'analyze:bundle') { - await rename(report_filename(), join(defaultConfig.build.outDir, 'index.html')); + await rename(report_filename(), resolve(defaultConfig.build.outDir, 'index.html')); - for (const file of globSync(join(defaultConfig.build.outDir, '**/*'))) { + for (const file of globSync(resolve(defaultConfig.build.outDir, '**/*'))) { if (!file.endsWith('index.html')) { await rm(file, { force: true, recursive: true }); }