diff --git a/packages/builder/.gitignore b/packages/builder/.gitignore index e5c961d509..41411ea16c 100644 --- a/packages/builder/.gitignore +++ b/packages/builder/.gitignore @@ -5,4 +5,5 @@ package-lock.json release/ dist/ routify -.routify/ \ No newline at end of file +.routify/ +.rollup.cache \ No newline at end of file diff --git a/packages/builder/package.json b/packages/builder/package.json index fd819b8a9c..c98e817486 100644 --- a/packages/builder/package.json +++ b/packages/builder/package.json @@ -4,14 +4,14 @@ "license": "GPL-3.0", "private": true, "scripts": { - "svelte-check": "svelte-check --no-tsconfig", - "build": "yarn svelte-check && routify -b && vite build --emptyOutDir", + "build": "routify -b && NODE_OPTIONS=\"--max_old_space_size=4096\" vite build --emptyOutDir", "start": "routify -c rollup", "dev": "routify -c dev:vite", "dev:vite": "vite --host 0.0.0.0", "rollup": "rollup -c -w", "test": "vitest run", - "test:watch": "vitest" + "test:watch": "vitest", + "check:types": "yarn svelte-check" }, "jest": { "globals": { @@ -89,6 +89,7 @@ "@babel/plugin-transform-runtime": "^7.13.10", "@babel/preset-env": "^7.13.12", "@rollup/plugin-replace": "^5.0.3", + "@rollup/plugin-typescript": "8.3.0", "@roxi/routify": "2.18.12", "@sveltejs/vite-plugin-svelte": "1.4.0", "@testing-library/jest-dom": "6.4.2", diff --git a/packages/builder/src/api.js b/packages/builder/src/api.ts similarity index 87% rename from packages/builder/src/api.js rename to packages/builder/src/api.ts index 6441b4ff48..5d1a0beaeb 100644 --- a/packages/builder/src/api.js +++ b/packages/builder/src/api.ts @@ -8,7 +8,7 @@ import { get } from "svelte/store" import { auth, navigation } from "./stores/portal" export const API = createAPIClient({ - attachHeaders: headers => { + attachHeaders: (headers: Record) => { // Attach app ID header from store let appId = get(appStore).appId if (appId) { @@ -16,13 +16,13 @@ export const API = createAPIClient({ } // Add csrf token if authenticated - const user = get(auth).user + const user: any = get(auth).user if (user?.csrfToken) { headers["x-csrf-token"] = user.csrfToken } }, - onError: error => { + onError: (error: any) => { const { url, message, status, method, handled } = error || {} // Log any errors that we haven't manually handled @@ -45,14 +45,14 @@ export const API = createAPIClient({ } } }, - onMigrationDetected: appId => { + onMigrationDetected: (appId: string) => { const updatingUrl = `/builder/app/updating/${appId}` if (window.location.pathname === updatingUrl) { return } - get(navigation).goto( + get(navigation)?.goto( `${updatingUrl}?returnUrl=${encodeURIComponent(window.location.pathname)}` ) }, diff --git a/packages/builder/src/index.d.ts b/packages/builder/src/index.d.ts new file mode 100644 index 0000000000..1cbad4f12c --- /dev/null +++ b/packages/builder/src/index.d.ts @@ -0,0 +1,8 @@ +declare module "api" { + const API: { + getPlugins: () => Promise + createPlugin: (plugin: object) => Promise + uploadPlugin: (plugin: FormData) => Promise + deletePlugin: (id: string) => Promise + } +} diff --git a/packages/builder/src/stores/portal/navigation.js b/packages/builder/src/stores/portal/navigation.ts similarity index 69% rename from packages/builder/src/stores/portal/navigation.js rename to packages/builder/src/stores/portal/navigation.ts index 67a06eff53..2b230622f6 100644 --- a/packages/builder/src/stores/portal/navigation.js +++ b/packages/builder/src/stores/portal/navigation.ts @@ -1,13 +1,20 @@ import { writable } from "svelte/store" +type GotoFuncType = (path: string) => void + +interface Store { + initialisated: boolean + goto: GotoFuncType +} + export function createNavigationStore() { - const store = writable({ + const store = writable({ initialisated: false, - goto: undefined, + goto: undefined as any, }) const { set, subscribe } = store - const init = gotoFunc => { + const init = (gotoFunc: GotoFuncType) => { if (typeof gotoFunc !== "function") { throw new Error( `gotoFunc must be a function, found a "${typeof gotoFunc}" instead` diff --git a/packages/builder/src/stores/portal/plugins.js b/packages/builder/src/stores/portal/plugins.ts similarity index 81% rename from packages/builder/src/stores/portal/plugins.js rename to packages/builder/src/stores/portal/plugins.ts index e259f9aa6d..15110a852b 100644 --- a/packages/builder/src/stores/portal/plugins.js +++ b/packages/builder/src/stores/portal/plugins.ts @@ -1,16 +1,21 @@ import { writable } from "svelte/store" +import { PluginSource } from "constants/index" + import { API } from "api" -import { PluginSource } from "constants" + +interface Plugin { + _id: string +} export function createPluginsStore() { - const { subscribe, set, update } = writable([]) + const { subscribe, set, update } = writable([]) async function load() { const plugins = await API.getPlugins() set(plugins) } - async function deletePlugin(pluginId) { + async function deletePlugin(pluginId: string) { await API.deletePlugin(pluginId) update(state => { state = state.filter(existing => existing._id !== pluginId) @@ -18,8 +23,8 @@ export function createPluginsStore() { }) } - async function createPlugin(source, url, auth = null) { - let pluginData = { + async function createPlugin(source: string, url: string, auth = null) { + let pluginData: any = { source, url, } @@ -46,7 +51,7 @@ export function createPluginsStore() { }) } - async function uploadPlugin(file) { + async function uploadPlugin(file: File) { if (!file) { return } diff --git a/packages/builder/tsconfig.build.json b/packages/builder/tsconfig.build.json index 6a5ba315a1..ca1316f83c 100644 --- a/packages/builder/tsconfig.build.json +++ b/packages/builder/tsconfig.build.json @@ -9,15 +9,9 @@ "noImplicitAny": true, "esModuleInterop": true, "resolveJsonModule": true, - "incremental": true + "incremental": true, + "skipLibCheck": true }, - "include": [ - "./src/**/*" - ], - "exclude": [ - "node_modules", - "**/*.json", - "**/*.spec.ts", - "**/*.spec.js" - ] + "include": ["./src/**/*"], + "exclude": ["node_modules", "**/*.json", "**/*.spec.ts", "**/*.spec.js"] } diff --git a/packages/builder/vite.config.mjs b/packages/builder/vite.config.mjs index f5ff388952..ccc5729d28 100644 --- a/packages/builder/vite.config.mjs +++ b/packages/builder/vite.config.mjs @@ -3,6 +3,7 @@ import replace from "@rollup/plugin-replace" import { defineConfig, loadEnv } from "vite" import { viteStaticCopy } from "vite-plugin-static-copy" import path from "path" +import typescript from "@rollup/plugin-typescript" const ignoredWarnings = [ "unused-export-let", @@ -35,7 +36,7 @@ export default defineConfig(({ mode }) => { // Copy fonts to an additional path so that svelte's automatic // prefixing of the base URL path can still resolve assets copyFonts("builder/fonts"), -] + ] return { test: { @@ -61,6 +62,7 @@ export default defineConfig(({ mode }) => { sourcemap: !isProduction, }, plugins: [ + typescript({ outDir: "../server/builder/dist" }), svelte({ hot: !isProduction, emitCss: true,