Fix path splitting issues on windows (#3565)

* Fix path splitting issues on windows

* Fix path splitting issue on routeLoaders

* Enable some e2e tests

* Swap enabled e2e tests

* Working bare-min project parse

* Make tsc happy

* Clean up & enable more tests

* Fix paths in browser

* Fix tests for windows

fmt

* Clean up wasm side

* Make build:wasm windows compatible

* More paths cleanup & some tests

* Remove sleep

* Use new config sturcture in parseroute

* Clean up debugger

* Fix: on settings close go back to the same file (#3549)

* Fix: on settings close go back to the same file

* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest)

* shit aint working yo

* Get that page a-loading

* A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest)

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Jess Frazelle <jessfraz@users.noreply.github.com>

* Fmt

* Comment out currently failing win32 tests

* Ignore tsc for electron monkey-patch

* Force line-endings to only

* Fix tsc

* Enable more tests

* A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest)

* Avoid modifying global for tests

---------

Co-authored-by: 49fl <ircsurfer33@gmail.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Jess Frazelle <jessfraz@users.noreply.github.com>
This commit is contained in:
Adam Sunderland
2024-08-22 13:38:53 -04:00
committed by GitHub
parent 0bb4586e6d
commit a2d8c5a714
14 changed files with 378 additions and 347 deletions

View File

@ -1,13 +1,13 @@
import { onboardingPaths } from 'routes/Onboarding/paths'
import { BROWSER_FILE_NAME, BROWSER_PROJECT_NAME, FILE_EXT } from './constants'
import { isDesktop } from './isDesktop'
import { ProjectRoute } from 'wasm-lib/kcl/bindings/ProjectRoute'
import { parseProjectRoute, readAppSettingsFile } from './desktop'
import { readAppSettingsFile } from './desktop'
import { readLocalStorageAppSettingsFile } from './settings/settingsUtils'
import { err } from 'lib/trap'
import { IS_PLAYWRIGHT_KEY } from '../../e2e/playwright/storageStates'
import { DeepPartial } from './types'
import { Configuration } from 'wasm-lib/kcl/bindings/Configuration'
import { PlatformPath } from 'path'
const prependRoutes =
(routesObject: Record<string, string>) => (prepend: string) => {
@ -25,6 +25,13 @@ type OnboardingPaths = {
const SETTINGS = '/settings' as const
export type ProjectRoute = {
projectName: string | null
projectPath: string
currentFileName: string | null
currentFilePath: string | null
}
export const PATHS = {
INDEX: '/',
HOME: '/home',
@ -60,9 +67,64 @@ export async function getProjectMetaByRouteId(
return Promise.reject(new Error('No configuration found'))
}
const route = parseProjectRoute(configuration, id)
const route = parseProjectRoute(configuration, id, window?.electron?.path)
if (err(route)) return Promise.reject(route)
return route
}
export async function parseProjectRoute(
configuration: DeepPartial<Configuration>,
id: string,
pathlib: PlatformPath | undefined
): Promise<ProjectRoute> {
let projectName = null
let projectPath = ''
let currentFileName = null
let currentFilePath = null
if (
pathlib &&
configuration.settings?.project?.directory &&
id.startsWith(configuration.settings.project.directory)
) {
const relativeToRoot = pathlib.relative(
configuration.settings.project.directory,
id
)
projectName = relativeToRoot.split(pathlib.sep)[0]
projectPath = pathlib.join(
configuration.settings.project.directory,
projectName
)
projectName = projectName === '' ? null : projectName
} else {
projectPath = id
if (pathlib) {
if (pathlib.extname(id) === '.kcl') {
projectPath = pathlib.dirname(id)
}
projectName = pathlib.basename(projectPath)
} else {
if (id.endsWith('.kcl')) {
projectPath = '/browser'
projectName = 'browser'
}
}
}
if (pathlib) {
if (projectPath !== id) {
currentFileName = pathlib.basename(id)
currentFilePath = id
}
} else {
currentFileName = 'main.kcl'
currentFilePath = id
}
return {
projectName: projectName,
projectPath: projectPath,
currentFileName: currentFileName,
currentFilePath: currentFilePath,
}
}