diff --git a/src/Router.tsx b/src/Router.tsx index d013555b9..9c34ec7e5 100644 --- a/src/Router.tsx +++ b/src/Router.tsx @@ -101,7 +101,10 @@ const router = createBrowserRouter([ - {!isDesktop() && import.meta.env.PROD && } + { + // @ts-ignore + !isDesktop() && import.meta.env.PROD && + } diff --git a/src/components/FileMachineProvider.tsx b/src/components/FileMachineProvider.tsx index ef5cfb834..039c7ec31 100644 --- a/src/components/FileMachineProvider.tsx +++ b/src/components/FileMachineProvider.tsx @@ -137,7 +137,9 @@ export const FileMachineProvider = ({ await window.electron.rename(oldPath, newPath) - if (!file) { return Promise.reject(new Error('file is not defined')) } + if (!file) { + return Promise.reject(new Error('file is not defined')) + } const currentFilePath = window.electron.path.join(file.path, file.name) if (oldPath === currentFilePath && project?.path) { diff --git a/src/components/HelpMenu.tsx b/src/components/HelpMenu.tsx index 777f9a1ac..f0adc880d 100644 --- a/src/components/HelpMenu.tsx +++ b/src/components/HelpMenu.tsx @@ -142,7 +142,9 @@ function HelpMenuItem({ {as === 'a' ? ( )} - onClick={openExternalBrowserIfDesktop((props as React.ComponentProps<'a'>).href)} + onClick={openExternalBrowserIfDesktop( + (props as React.ComponentProps<'a'>).href + )} className={`no-underline text-inherit ${baseClassName} ${className}`} > {children} diff --git a/src/components/LowerRightControls.tsx b/src/components/LowerRightControls.tsx index 2c4958bcd..5d7bfd49f 100644 --- a/src/components/LowerRightControls.tsx +++ b/src/components/LowerRightControls.tsx @@ -26,7 +26,10 @@ export function LowerRightControls({ const isPlayWright = window?.localStorage.getItem('playwright') === 'true' - async function reportbug(event: { preventDefault: () => void, stopPropagation: () => void }) { + async function reportbug(event: { + preventDefault: () => void + stopPropagation: () => void + }) { event?.preventDefault() event?.stopPropagation() diff --git a/src/components/ProjectCard/ProjectCard.tsx b/src/components/ProjectCard/ProjectCard.tsx index 20ebfee92..4d64877cf 100644 --- a/src/components/ProjectCard/ProjectCard.tsx +++ b/src/components/ProjectCard/ProjectCard.tsx @@ -114,7 +114,7 @@ function ProjectCard({ Edited{' '} {project.metadata && project.metadata.modified - ? getDisplayedTime(project.metadata.modified.toString()) + ? getDisplayedTime(parseInt(project.metadata.modified)) : 'never'} diff --git a/src/components/Settings/AllSettingsFields.tsx b/src/components/Settings/AllSettingsFields.tsx index a82214bf0..cbb9a954d 100644 --- a/src/components/Settings/AllSettingsFields.tsx +++ b/src/components/Settings/AllSettingsFields.tsx @@ -196,7 +196,9 @@ export const AllSettingsFields = forwardRef( projectPath ? decodeURIComponent(projectPath) : undefined ) const finalPath = paths[searchParamTab] - if (!finalPath) { return new Error('finalPath undefined') } + if (!finalPath) { + return new Error('finalPath undefined') + } window.electron.showInFolder(finalPath) }} iconStart={{ diff --git a/src/env.ts b/src/env.ts index f133e2a7b..212ba9683 100644 --- a/src/env.ts +++ b/src/env.ts @@ -1,15 +1,28 @@ // env vars were centralised so they could be mocked in jest // but isn't needed anymore with vite, so is now just a convention +// Even though we transpile to a module system that supports import, the +// typescript checker doesn't know that, so it's causing problems +// to properly type check anything with "import.meta". I've tried for a good +// hour to fix this but nothing has worked. This is the pain the JS ecosystem +// gets for like 6 different module systems. + +// @ts-ignore export const VITE_KC_API_WS_MODELING_URL = import.meta.env .VITE_KC_API_WS_MODELING_URL +// @ts-ignore export const VITE_KC_API_BASE_URL = import.meta.env.VITE_KC_API_BASE_URL +// @ts-ignore export const VITE_KC_SITE_BASE_URL = import.meta.env.VITE_KC_SITE_BASE_URL +// @ts-ignore export const VITE_KC_CONNECTION_TIMEOUT_MS = import.meta.env .VITE_KC_CONNECTION_TIMEOUT_MS +// @ts-ignore export const VITE_KC_DEV_TOKEN = import.meta.env.VITE_KC_DEV_TOKEN as | string | undefined +// @ts-ignore export const TEST = import.meta.env.TEST +// @ts-ignore export const DEV = import.meta.env.DEV export const CI = import.meta.env.CI diff --git a/src/hooks/usePlatform.ts b/src/hooks/usePlatform.ts index 516712b22..8ef85a892 100644 --- a/src/hooks/usePlatform.ts +++ b/src/hooks/usePlatform.ts @@ -1,14 +1,14 @@ import { isDesktop } from 'lib/isDesktop' import { useEffect, useState } from 'react' -export type Platform = 'macos' | 'windows' | 'linux' +export type Platform = 'macos' | 'windows' | 'linux' | '' export default function usePlatform() { - const [platformName, setPlatformName] = useState('') + const [platformName, setPlatformName] = useState('') useEffect(() => { async function getPlatform() { - setPlatformName(window.electron.platform) + setPlatformName((window.electron.platform ?? '') as Platform) } if (isDesktop()) { diff --git a/src/lang/codeManager.ts b/src/lang/codeManager.ts index a33fe43ed..b55a472bc 100644 --- a/src/lang/codeManager.ts +++ b/src/lang/codeManager.ts @@ -121,7 +121,7 @@ export default class CodeManager { this._currentFilePath && window.electron .writeFile(this._currentFilePath, this.code ?? '') - .catch((err) => { + .catch((err: Error) => { // TODO: add tracing per GH issue #254 (https://github.com/KittyCAD/modeling-app/issues/254) console.error('error saving file', err) toast.error('Error saving file, please check file permissions') diff --git a/src/lang/wasm.ts b/src/lang/wasm.ts index c8a7f54c8..fec58834f 100644 --- a/src/lang/wasm.ts +++ b/src/lang/wasm.ts @@ -23,9 +23,7 @@ import { configurationToSettingsPayload, projectConfigurationToSettingsPayload, } from 'lib/settings/settingsUtils' -import { - SaveSettingsPayload, -} from 'lib/settings/settingsTypes' +import { SaveSettingsPayload } from 'lib/settings/settingsTypes' import { KCLError } from './errors' import { KclError as RustKclError } from '../wasm-lib/kcl/bindings/KclError' import { EngineCommandManager } from './std/engineConnection' @@ -589,7 +587,7 @@ export function parseProjectSettings( } export function parseProjectRoute( - configuration: Configuration, + configuration: Partial, route_str: string ): ProjectRoute | Error { return parse_project_route(JSON.stringify(configuration), route_str) diff --git a/src/lib/desktop.ts b/src/lib/desktop.ts index 997570830..6e90fa269 100644 --- a/src/lib/desktop.ts +++ b/src/lib/desktop.ts @@ -6,6 +6,7 @@ import { ProjectState } from 'wasm-lib/kcl/bindings/ProjectState' import { ProjectRoute } from 'wasm-lib/kcl/bindings/ProjectRoute' import { components } from './machine-api' import { isDesktop } from './isDesktop' +import { FileEntry } from 'wasm-lib/kcl/bindings/FileEntry' import { SaveSettingsPayload } from 'lib/settings/settingsUtils' import { @@ -79,7 +80,9 @@ export async function ensureProjectDirectoryExists( config: Partial ): Promise { const projectDir = config.app?.projectDirectory - if (!projectDir) { return Promise.reject(new Error('projectDir is falsey')) } + if (!projectDir) { + return Promise.reject(new Error('projectDir is falsey')) + } try { await window.electron.stat(projectDir) } catch (e) { @@ -106,7 +109,9 @@ export async function createNewProjectDirectory( return Promise.reject('Project name cannot be empty.') } - if (!mainDir) { return Promise.reject(new Error('mainDir is falsey')) } + if (!mainDir) { + return Promise.reject(new Error('mainDir is falsey')) + } const projectDir = window.electron.path.join(mainDir, projectName) try { @@ -129,7 +134,7 @@ export async function createNewProjectDirectory( name: projectName, // We don't need to recursively get all files in the project directory. // Because we just created it and it's empty. - children: undefined, + children: null, default_file: projectFile, metadata, kcl_file_count: 1, @@ -194,7 +199,7 @@ const collectAllFilesRecursiveFrom = async (path: string) => { } const pathParts = path.split('/') - let entry = /* FileEntry */ { + let entry: FileEntry = { name: pathParts.slice(-1)[0], path, children: [], @@ -256,7 +261,7 @@ const getDefaultKclFileForDir = async (projectDir: string, file: FileEntry) => { for (let entry of file.children) { if (entry.name.endsWith('.kcl')) { return window.electron.path.join(projectDir, entry.name) - } else if (entry.children.length > 0) { + } else if (entry.children?.length > 0) { // Recursively find a kcl file in the directory. return getDefaultKclFileForDir(entry.path, entry) } @@ -275,7 +280,7 @@ const getDefaultKclFileForDir = async (projectDir: string, file: FileEntry) => { return defaultFilePath } -const kclFileCount = (file /* fileEntry */) => { +const kclFileCount = (file: FileEntry) => { let count = 0 if (file.children) { for (let entry of file.children) { @@ -291,7 +296,7 @@ const kclFileCount = (file /* fileEntry */) => { } /// Populate the number of directories in the project. -const directoryCount = (file /* FileEntry */) => { +const directoryCount = (file: FileEntry) => { let count = 0 if (file.children) { for (let entry of file.children) { @@ -330,7 +335,9 @@ export async function getProjectInfo(projectPath: string): Promise { let project = { ...walked, // We need to map from node fs.Stats to FileMetadata - metadata: metadata.map((data: { mtimeMs: number }) => ({ modified: data.mtimeMs })), + metadata: metadata.map((data: { mtimeMs: number }) => ({ + modified: data.mtimeMs, + })), kcl_file_count: 0, directory_count: 0, default_file, @@ -346,15 +353,12 @@ export async function getProjectInfo(projectPath: string): Promise { } // Write project settings file. -export async function writeProjectSettingsFile({ - projectPath, - configuration, -}: { - projectPath: string - configuration: Partial -}): Promise { +export async function writeProjectSettingsFile( + projectPath: string, + configuration: Partial, +): Promise { const projectSettingsFilePath = await getProjectSettingsFilePath(projectPath) - const tomlStr = tomlStringify(configuration) + const tomlStr = tomlStringify({ settings: configuration }) if (err(tomlStr)) return Promise.reject(tomlStr) return window.electron.writeFile(projectSettingsFilePath, tomlStr) } @@ -419,6 +423,7 @@ export const readAppSettingsFile = async () => { } catch (e) { if (e === 'ENOENT') { const config = defaultAppSettings() + if (!config.app) { return Promise.reject(new Error('config.app is falsey')) } config.app.projectDirectory = await getInitialDefaultDir() return config } @@ -432,7 +437,7 @@ export const writeAppSettingsFile = async ( config: Partial ) => { const appSettingsFilePath = await getAppSettingsFilePath() - const tomlStr = tomlStringify(config) + const tomlStr = tomlStringify({ settings: config }) if (err(tomlStr)) return Promise.reject(tomlStr) return window.electron.writeFile(appSettingsFilePath, tomlStr) } diff --git a/src/lib/paths.ts b/src/lib/paths.ts index 7a47137d1..c89848e90 100644 --- a/src/lib/paths.ts +++ b/src/lib/paths.ts @@ -5,6 +5,7 @@ import { Configuration } from 'wasm-lib/kcl/bindings/Configuration' import { ProjectRoute } from 'wasm-lib/kcl/bindings/ProjectRoute' import { parseProjectRoute, readAppSettingsFile } from './desktop' import { readLocalStorageAppSettingsFile } from './settings/settingsUtils' +import { SaveSettingsPayload } from './settings/settingsTypes' import { err } from 'lib/trap' const prependRoutes = @@ -33,7 +34,7 @@ export const BROWSER_PATH = `%2F${BROWSER_PROJECT_NAME}%2F${BROWSER_FILE_NAME}${ export async function getProjectMetaByRouteId( id?: string, - configuration?: Configuration | Error + configuration?: Partial | Error ): Promise { if (!id) return undefined diff --git a/src/lib/routeLoaders.ts b/src/lib/routeLoaders.ts index c19725eed..be955b8d2 100644 --- a/src/lib/routeLoaders.ts +++ b/src/lib/routeLoaders.ts @@ -118,14 +118,14 @@ export const fileLoader: LoaderFunction = async ( fileSystemManager.dir = project_path const defaultProjectData = { - name: project_name || 'unnamed', - path: project_path, - children: [], - kcl_file_count: 0, - directory_count: 0, - metadata: null, - default_file: project_path, - } + name: project_name || 'unnamed', + path: project_path, + children: [], + kcl_file_count: 0, + directory_count: 0, + metadata: null, + default_file: project_path, + } const projectData: IndexLoaderData = { code, diff --git a/src/lib/settings/initialSettings.tsx b/src/lib/settings/initialSettings.tsx index 6bf192166..aa08af8f0 100644 --- a/src/lib/settings/initialSettings.tsx +++ b/src/lib/settings/initialSettings.tsx @@ -63,9 +63,7 @@ export class Setting { return this._user } set user(v: T | undefined) { - this._user = v !== undefined - ? this.validate(v) ? v : this._user - : v + this._user = v !== undefined ? (this.validate(v) ? v : this._user) : v this.current = this.resolve() } /** @@ -75,9 +73,7 @@ export class Setting { return this._project } set project(v: T | undefined) { - this._project = v !== undefined - ? this.validate(v) ? v : this._project - : v + this._project = v !== undefined ? (this.validate(v) ? v : this._project) : v this.current = this.resolve() } /** diff --git a/src/lib/settings/settingsUtils.ts b/src/lib/settings/settingsUtils.ts index d05c126fd..89b088b6d 100644 --- a/src/lib/settings/settingsUtils.ts +++ b/src/lib/settings/settingsUtils.ts @@ -105,7 +105,7 @@ function localStorageProjectSettingsPath() { return '/' + BROWSER_PROJECT_NAME + '/project.toml' } -export function readLocalStorageAppSettingsFile(): Configuration | Error { +export function readLocalStorageAppSettingsFile(): Partial | Error { // TODO: Remove backwards compatibility after a few releases. let stored = localStorage.getItem(localStorageAppSettingsPath()) ?? @@ -129,7 +129,9 @@ export function readLocalStorageAppSettingsFile(): Configuration | Error { } } -function readLocalStorageProjectSettingsFile(): Partial | Error { +function readLocalStorageProjectSettingsFile(): + | Partial + | Error { // TODO: Remove backwards compatibility after a few releases. let stored = localStorage.getItem(localStorageProjectSettingsPath()) ?? '' @@ -151,8 +153,8 @@ function readLocalStorageProjectSettingsFile(): Partial | E } export interface AppSettings { - settings: ReturnType - configuration: Configuration + settings: ReturnType, + configuration: Partial } export async function loadAndValidateSettings( @@ -204,10 +206,10 @@ export async function saveSettings( if (err(tomlString)) return // Parse this as a Configuration. - const appSettings = { settings: parseAppSettings(tomlString) } + const appSettings = parseAppSettings(tomlString) if (err(appSettings)) return - const tomlString2 = tomlStringify(appSettings) + const tomlString2 = tomlStringify({ settings: appSettings }) if (err(tomlString2)) return // Write the app settings. @@ -237,10 +239,10 @@ export async function saveSettings( // Write the project settings. if (onDesktop) { - await writeProjectSettingsFile({ + await writeProjectSettingsFile( projectPath, - configuration: { settings: projectSettings }, - }) + projectSettings, + ) } else { localStorage.setItem(localStorageProjectSettingsPath(), tomlStr) } diff --git a/src/machines/authMachine.ts b/src/machines/authMachine.ts index 9f38df1f6..9ef7f9ef4 100644 --- a/src/machines/authMachine.ts +++ b/src/machines/authMachine.ts @@ -6,6 +6,7 @@ import { VITE_KC_API_BASE_URL, VITE_KC_DEV_TOKEN } from 'env' import { getUser as getUserDesktop } from 'lib/desktop' const SKIP_AUTH = + // @ts-ignore import.meta.env.VITE_KC_SKIP_AUTH === 'true' && import.meta.env.DEV const LOCAL_USER: Models['User_type'] = { diff --git a/src/routes/Settings.tsx b/src/routes/Settings.tsx index 07a77a134..b113e3723 100644 --- a/src/routes/Settings.tsx +++ b/src/routes/Settings.tsx @@ -15,7 +15,8 @@ import { KeybindingsSectionsList } from 'components/Settings/KeybindingsSections import { isDesktop } from 'lib/isDesktop' export const APP_VERSION = isDesktop() - ? import.meta.env.PACKAGE_VERSION || 'unknown' + ? // @ts-ignore + import.meta.env.PACKAGE_VERSION || 'unknown' : 'main' export const Settings = () => { diff --git a/tsconfig.desktop.json b/tsconfig.desktop.json deleted file mode 100644 index 61d9a1c8e..000000000 --- a/tsconfig.desktop.json +++ /dev/null @@ -1,39 +0,0 @@ -{ - "compilerOptions": { - "baseUrl": "src", - "paths": { - "@kittycad/codemirror-lsp-client": [ - "../packages/codemirror-lsp-client/src/index.ts" - ], - "/*": ["src/*"] - }, - "types": [ - "vite/client", - "@types/wicg-file-system-access", - "node", - "@wdio/globals/types", - "mocha", - "@lezer/generator" - ], - "target": "esnext", - "lib": ["dom", "dom.iterable", "esnext"], - "allowJs": true, - "skipLibCheck": true, - "esModuleInterop": true, - "sourceMap": true, - "allowSyntheticDefaultImports": true, - "strict": true, - "forceConsistentCasingInFileNames": true, - "noFallthroughCasesInSwitch": true, - "module": "commonjs", - "moduleResolution": "node", - "resolveJsonModule": true, - "composite": true, - "isolatedModules": true, - "noEmit": true, - "jsx": "react-jsx" - }, - "include": ["src", "e2e", "packages", "./*.ts", "package.json"], - "exclude": ["node_modules", "./*.grammar"], - "references": [{ "path": "./tsconfig.node.json" }] -}