From d43b660c2ca438a85633f23b6170ff4effad4515 Mon Sep 17 00:00:00 2001 From: Martin Lysk Date: Tue, 9 Apr 2024 21:33:07 +0200 Subject: [PATCH 01/11] moves all repo function calls from GitFloat to function provided by state, prepares removal of reactive errors property --- .../pages/@host/@owner/@repository/State.tsx | 201 ++++++++++-------- .../@repository/components/Gitfloat.tsx | 14 +- .../manage/src/components/InlangManage.ts | 22 +- lix/packages/client/src/api.test.ts | 20 +- 4 files changed, 140 insertions(+), 117 deletions(-) diff --git a/inlang/source-code/editor/src/pages/@host/@owner/@repository/State.tsx b/inlang/source-code/editor/src/pages/@host/@owner/@repository/State.tsx index 9ca817b1fa..bd8700f1b9 100644 --- a/inlang/source-code/editor/src/pages/@host/@owner/@repository/State.tsx +++ b/inlang/source-code/editor/src/pages/@host/@owner/@repository/State.tsx @@ -56,6 +56,16 @@ type EditorStateSchema = { */ mutateForkStatus: (args: { ahead: number; behind: number; conflicts: boolean }) => void + pushChanges: (args: { + user: LocalStorageSchema["user"] + setFsChange: (date: Date) => void + setLastPullTime: (date: Date) => void + }) => Promise> + + mergeUpstream: () => Promise>> + + createFork: () => Promise>> + currentBranch: Resource /** * The branch names of current repo. @@ -149,7 +159,7 @@ type EditorStateSchema = { /** * Expose lix errors that happen wihle opening the repository */ - lixErrors: () => ReturnType + lixErrors: () => LixError[] /** * Unpushed changes in the repository. @@ -244,7 +254,7 @@ export function EditorStateProvider(props: { children: JSXElement }) { const [localStorage] = useLocalStorage() ?? [] // get lix errors - const [lixErrors, setLixErrors] = createSignal>([]) + const [lixErrors, setLixErrors] = createSignal([]) const [activeBranch, setActiveBranch] = createSignal( params.get("branch") || undefined @@ -281,24 +291,19 @@ export function EditorStateProvider(props: { children: JSXElement }) { // @ts-expect-error window.repo = newRepo } - - if (newRepo.errors().length > 0) { - setLixErrors(newRepo.errors()) - return - } else { - setLixErrors([]) - } + // TODO replace this with `setLixErrors([])` as soon as repo throws + setLixErrors(newRepo.errors) // @ts-ignore -- causes reactivity bugs because the sdk uses watch and triggers updates on changes caused by itself newRepo.nodeishFs.watch = () => {} setLastPullTime(new Date()) + // Invalidate the project while we switch branches setProject(undefined) return newRepo - } catch (err) { - console.error(err) - return + } catch (e) { + setLixErrors([e as Error]) } } else { return @@ -306,10 +311,6 @@ export function EditorStateProvider(props: { children: JSXElement }) { } ) - repo()?.errors.subscribe((errors: any) => { - setLixErrors(errors) - }) - const isForkSyncDisabled = () => localStorage.disableForkSyncWarning?.some( (repo) => repo.owner === routeParams().owner && repo.repository === routeParams().repository @@ -318,14 +319,15 @@ export function EditorStateProvider(props: { children: JSXElement }) { const [forkStatus, { refetch: refetchForkStatus, mutate: mutateForkStatus }] = createResource( () => { if (repo() && !isForkSyncDisabled()) { - return repo() + return { repo: repo() } } else { return false } }, async (args) => { - const value = await args.forkStatus() + const value = await args.repo!.forkStatus() if ("error" in value) { + setLixErrors([new Error(value.error), ...lixErrors()]) return { ahead: 0, behind: 0, conflicts: false } } else { return value @@ -334,6 +336,87 @@ export function EditorStateProvider(props: { children: JSXElement }) { { initialValue: { ahead: 0, behind: 0, conflicts: false } } ) + async function pushChanges(args: { + user: LocalStorageSchema["user"] + setFsChange: (date: Date) => void + setLastPullTime: (date: Date) => void + }): Promise> { + const loadedRepo = repo() + if (!loadedRepo) { + return { error: new PushException("Repo not loaded") } + } + + if (typeof args.user === "undefined" || args.user?.isLoggedIn === false) { + return { error: new PushException("User not logged in") } + } + + const filesWithUncommittedChanges = await loadedRepo.statusList({ + filter: (f: any) => + f.endsWith("project_id") || + f.endsWith(".json") || + f.endsWith(".po") || + f.endsWith(".yaml") || + f.endsWith(".yml") || + f.endsWith(".js") || + f.endsWith(".ts"), + }) + + if (filesWithUncommittedChanges.length > 0) { + // commit changes + await loadedRepo.commit({ + author: { + name: args.user.username, + email: args.user.email, + }, + message: "Fink 🐦: update translations", + include: filesWithUncommittedChanges.map((f) => f[0]), + }) + } + + // triggering a side effect here to trigger a re-render + // of components that depends on fs + args.setFsChange(new Date()) + // push changes + try { + const push = await loadedRepo.push() + if (push?.ok === false) { + return { error: new PushException("Failed to push", { cause: push.error }) } + } + await loadedRepo.pull({ + author: { + name: args.user.username, + email: args.user.email, + }, + fastForward: true, + singleBranch: true, + }) + const time = new Date() + // triggering a rebuild of everything fs related + args.setFsChange(time) + args.setLastPullTime(time) + return { data: true } + } catch (error) { + return { error: (error as PushException) ?? "Unknown error" } + } + } + + async function mergeUpstream(): Promise>> { + const loadedRepo = repo() + if (!loadedRepo) { + throw new Error("Repo not loaded") + } + + return loadedRepo.mergeUpstream() + } + + async function createFork() { + const loadedRepo = repo() + if (!loadedRepo) { + throw new Error("Repo not loaded yet") + } + return await loadedRepo.createFork() + } + const [projectList] = createResource( () => { return { repo: repo() } @@ -375,13 +458,13 @@ export function EditorStateProvider(props: { children: JSXElement }) { // open the inlang project and store it in a resource const [project, { mutate: setProject }] = createResource( () => { - if (repo() === undefined || lixErrors().length > 0 || activeProject() === undefined) { + if (repo() === undefined || activeProject() === undefined) { return false } - return { newRepo: repo(), lixErrors: lixErrors(), activeProject: activeProject() } + return { newRepo: repo(), activeProject: activeProject() } }, - async ({ newRepo, lixErrors, activeProject }) => { - if (lixErrors.length === 0 && newRepo) { + async ({ newRepo, activeProject }) => { + if (newRepo) { const project = solidAdapter( await loadProject({ repo: newRepo, @@ -459,7 +542,10 @@ export function EditorStateProvider(props: { children: JSXElement }) { } }, async () => { - const repoMeta = await repo()?.getMeta() + const repoMeta = await repo()!.getMeta() + if ("error" in repoMeta) { + setLixErrors([repoMeta.error, ...lixErrors()]) + } return repoMeta } ) @@ -486,7 +572,7 @@ export function EditorStateProvider(props: { children: JSXElement }) { const [currentBranch] = createResource( () => { - if (lixErrors().length > 0 || repo() === undefined) { + if (repo() === undefined) { return {} } else { return { repo: repo() } @@ -524,7 +610,6 @@ export function EditorStateProvider(props: { children: JSXElement }) { return { user: localStorage?.user?.isLoggedIn ?? "not logged in", routeParams: currentPageContext.routeParams as EditorRouteParams, - currentRepo: repo(), repoMeta: githubRepositoryInformation(), } }, @@ -550,6 +635,9 @@ export function EditorStateProvider(props: { children: JSXElement }) { forkStatus, mutateForkStatus, refetchForkStatus, + pushChanges, + mergeUpstream, + createFork, currentBranch, branchNames, githubRepositoryInformation, @@ -612,66 +700,3 @@ export class UnknownException extends Error { super(id) } } - -/** - * Pushed changes and pulls right afterwards. - */ -export async function pushChanges(args: { - repo: Repository - user: LocalStorageSchema["user"] - setFsChange: (date: Date) => void - setLastPullTime: (date: Date) => void -}): Promise> { - if (typeof args.user === "undefined" || args.user?.isLoggedIn === false) { - return { error: new PushException("User not logged in") } - } - - const filesWithUncommittedChanges = await args.repo.statusList({ - filter: (f: any) => - f.endsWith("project_id") || - f.endsWith(".json") || - f.endsWith(".po") || - f.endsWith(".yaml") || - f.endsWith(".yml") || - f.endsWith(".js") || - f.endsWith(".ts"), - }) - - if (filesWithUncommittedChanges.length > 0) { - // commit changes - await args.repo.commit({ - author: { - name: args.user.username, - email: args.user.email, - }, - message: "Fink 🐦: update translations", - include: filesWithUncommittedChanges.map((f) => f[0]), - }) - } - - // triggering a side effect here to trigger a re-render - // of components that depends on fs - args.setFsChange(new Date()) - // push changes - try { - const push = await args.repo.push() - if (push?.ok === false) { - return { error: new PushException("Failed to push", { cause: push.error }) } - } - await args.repo.pull({ - author: { - name: args.user.username, - email: args.user.email, - }, - fastForward: true, - singleBranch: true, - }) - const time = new Date() - // triggering a rebuild of everything fs related - args.setFsChange(time) - args.setLastPullTime(time) - return { data: true } - } catch (error) { - return { error: (error as PushException) ?? "Unknown error" } - } -} diff --git a/inlang/source-code/editor/src/pages/@host/@owner/@repository/components/Gitfloat.tsx b/inlang/source-code/editor/src/pages/@host/@owner/@repository/components/Gitfloat.tsx index 83067494d4..22b79ca6b3 100644 --- a/inlang/source-code/editor/src/pages/@host/@owner/@repository/components/Gitfloat.tsx +++ b/inlang/source-code/editor/src/pages/@host/@owner/@repository/components/Gitfloat.tsx @@ -1,7 +1,7 @@ import { useLocalStorage } from "#src/services/local-storage/index.js" import { createEffect, createSignal, type JSXElement, onMount, Show, on } from "solid-js" import IconGithub from "~icons/cib/github" -import { pushChanges, useEditorState } from "../State.jsx" +import { useEditorState } from "../State.jsx" import type { SlDialog } from "@shoelace-style/shoelace" import { showToast } from "#src/interface/components/Toast.jsx" import { navigate } from "vike/client/router" @@ -30,9 +30,12 @@ export const Gitfloat = () => { forkStatus, mutateForkStatus, refetchForkStatus, + createFork, userIsCollaborator, githubRepositoryInformation, currentBranch, + pushChanges, + mergeUpstream, localChanges, setLocalChanges, setFsChange, @@ -65,7 +68,7 @@ export const Gitfloat = () => { } else if (localStorage?.user?.isLoggedIn === false) { return "login" } else if ( - typeof githubRepositoryInformation() === "undefined" || + typeof repoInfo === "undefined" || userIsCollaborator.loading || !projectList() || isForking() @@ -116,9 +119,7 @@ export const Gitfloat = () => { return } setIsForking(true) - const response = await repo() - ?.createFork() - .catch((err) => err) + const response = await createFork().catch((err) => err) telemetryBrowser.capture("EDITOR created fork", { owner: routeParams().owner, @@ -172,7 +173,6 @@ export const Gitfloat = () => { } const pushResult = await pushChanges({ - repo: repo()!, user: localStorage.user, setFsChange, setLastPullTime, @@ -406,7 +406,7 @@ export const Gitfloat = () => { prop:size="small" onClick={async () => { setIsMerging(true) - await repo()?.mergeUpstream() + await mergeUpstream() refetchRepo() setIsMerging(false) setTimeout(() => { diff --git a/inlang/source-code/manage/src/components/InlangManage.ts b/inlang/source-code/manage/src/components/InlangManage.ts index dee783dd54..28af0959c2 100644 --- a/inlang/source-code/manage/src/components/InlangManage.ts +++ b/inlang/source-code/manage/src/components/InlangManage.ts @@ -5,7 +5,7 @@ import { TwLitElement } from "../common/TwLitElement.js" import { z } from "zod" import "./InlangUninstall" import "./InlangInstall" -import { createNodeishMemoryFs, openRepository } from "@lix-js/client" +import { createNodeishMemoryFs, openRepository, type Repository } from "@lix-js/client" import { listProjects, isValidLanguageTag } from "@inlang/sdk" import { publicEnv } from "@inlang/env-variables" import { browserAuth, getUser } from "@lix-js/server" @@ -73,15 +73,17 @@ export class InlangManage extends TwLitElement { projectDropdown: NodeListOf | undefined async projectHandler() { - const repo = await openRepository( - `${publicEnv.PUBLIC_GIT_PROXY_BASE_URL}/git/${this.url.repo}`, - { - nodeishFs: createNodeishMemoryFs(), - branch: this.url.branch ? this.url.branch : undefined, - } - ) - - if (repo.errors().length > 0) { + let repo: Repository; + try { + + repo = await openRepository( + `${publicEnv.PUBLIC_GIT_PROXY_BASE_URL}/git/${this.url.repo}`, + { + nodeishFs: createNodeishMemoryFs(), + branch: this.url.branch ? this.url.branch : undefined, + } + ) + } catch (e) { this.projects = "no-access" return } diff --git a/lix/packages/client/src/api.test.ts b/lix/packages/client/src/api.test.ts index a5e5dbe41f..a164e1af78 100644 --- a/lix/packages/client/src/api.test.ts +++ b/lix/packages/client/src/api.test.ts @@ -14,18 +14,14 @@ import { resolve } from "node:path" describe("main workflow", () => { let repository: Awaited> - it("allows to subscribe to errors", async () => { - const errorHandler = vi.fn() - repository = await openRepository("https://github.com/inlang/does-not-exist", { - nodeishFs: createNodeishMemoryFs(), - }) - - repository.errors.subscribe(errorHandler) - - await new Promise((resolve) => setTimeout(resolve, 1000)) - - expect(errorHandler.mock.calls.length).toBe(1) - expect(errorHandler.mock.calls[0][0][0].code).toBe("HttpError") + it("should throw errors directly", async () => { + try { + repository = await openRepository("https://github.com/inlang/does-not-exist", { + nodeishFs: createNodeishMemoryFs(), + }) + } catch (e) { + expect(e.code).toBe("HttpError") + } }) it("opens a repo url without error", async () => { From a304f158d13aba72403fefa6cc7425cd3bd30438 Mon Sep 17 00:00:00 2001 From: Martin Lysk Date: Tue, 9 Apr 2024 22:06:26 +0200 Subject: [PATCH 02/11] fixes linting issues --- lix/packages/client/src/api.test.ts | 2 +- lix/packages/client/src/git/_checkout.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lix/packages/client/src/api.test.ts b/lix/packages/client/src/api.test.ts index a164e1af78..6ca199fe83 100644 --- a/lix/packages/client/src/api.test.ts +++ b/lix/packages/client/src/api.test.ts @@ -1,4 +1,4 @@ -import { describe, it, expect, vi } from "vitest" +import { describe, it, expect } from "vitest" import { openRepository, findRepoRoot } from "./index.ts" // @ts-ignore -- ts import not working correctly, TODO: find out why import { createNodeishMemoryFs, fromSnapshot } from "@lix-js/fs" diff --git a/lix/packages/client/src/git/_checkout.js b/lix/packages/client/src/git/_checkout.js index 2e7524bd39..39257e29f1 100644 --- a/lix/packages/client/src/git/_checkout.js +++ b/lix/packages/client/src/git/_checkout.js @@ -321,6 +321,7 @@ async function analyze({ fs, cache, onProgress, dir, gitdir, ref, force, filepat // match against base paths // @ts-ignore if (filepaths && !filepaths.some((base) => _worthWalking(fullpath, base))) { + // eslint-disable-next-line unicorn/no-null -- return null to skip walking of ignored trees (folders) return null } // Emit progress event From 8b077cac2ccc43e1fcb8ac7f8c15644b2ed2491c Mon Sep 17 00:00:00 2001 From: Martin Lysk Date: Wed, 10 Apr 2024 11:13:11 +0200 Subject: [PATCH 03/11] fixes missing LixError type --- .../src/interface/editor/EditorHeader.tsx | 22 ++++++++++++------- .../editor/src/interface/editor/Footer.tsx | 6 ++--- .../pages/@host/@owner/@repository/State.tsx | 7 +++--- .../manage/src/components/InlangManage.ts | 14 +++++------- lix/packages/client/src/index.ts | 2 +- 5 files changed, 26 insertions(+), 25 deletions(-) diff --git a/inlang/source-code/editor/src/interface/editor/EditorHeader.tsx b/inlang/source-code/editor/src/interface/editor/EditorHeader.tsx index c730634576..42073066e7 100644 --- a/inlang/source-code/editor/src/interface/editor/EditorHeader.tsx +++ b/inlang/source-code/editor/src/interface/editor/EditorHeader.tsx @@ -54,14 +54,22 @@ function EditorHeader() { (user()?.isLoggedIn && "mr-14") } > - - @@ -73,9 +81,7 @@ function EditorHeader() { {link.name} - +
diff --git a/inlang/source-code/editor/src/interface/editor/Footer.tsx b/inlang/source-code/editor/src/interface/editor/Footer.tsx index 0c66083143..990608cbc4 100644 --- a/inlang/source-code/editor/src/interface/editor/Footer.tsx +++ b/inlang/source-code/editor/src/interface/editor/Footer.tsx @@ -39,7 +39,7 @@ export const getFinkResourcesLinks = () => { { name: "Submit Feedback", href: "https://github.com/orgs/opral/discussions/categories/-fink-general", - } + }, ] } @@ -99,9 +99,7 @@ const Footer = () => { {link.name} - +
diff --git a/inlang/source-code/editor/src/pages/@host/@owner/@repository/State.tsx b/inlang/source-code/editor/src/pages/@host/@owner/@repository/State.tsx index bd8700f1b9..004b8f6ba0 100644 --- a/inlang/source-code/editor/src/pages/@host/@owner/@repository/State.tsx +++ b/inlang/source-code/editor/src/pages/@host/@owner/@repository/State.tsx @@ -18,7 +18,7 @@ import type { LocalStorageSchema } from "#src/services/local-storage/index.js" import { useLocalStorage } from "#src/services/local-storage/index.js" import type { TourStepId } from "./components/Notification/TourHintWrapper.jsx" import { setSearchParams } from "./helper/setSearchParams.js" -import { openRepository, createNodeishMemoryFs, type Repository } from "@lix-js/client" +import { openRepository, createNodeishMemoryFs, type Repository, LixError } from "@lix-js/client" import { browserAuth } from "@lix-js/server" import { publicEnv } from "@inlang/env-variables" import { @@ -62,7 +62,7 @@ type EditorStateSchema = { setLastPullTime: (date: Date) => void }) => Promise> - mergeUpstream: () => Promise>> + mergeUpstream: () => Promise>> createFork: () => Promise>> @@ -291,7 +291,7 @@ export function EditorStateProvider(props: { children: JSXElement }) { // @ts-expect-error window.repo = newRepo } - // TODO replace this with `setLixErrors([])` as soon as repo throws + // TODO replace this with `setLixErrors([])` as soon as repo throws setLixErrors(newRepo.errors) // @ts-ignore -- causes reactivity bugs because the sdk uses watch and triggers updates on changes caused by itself @@ -304,6 +304,7 @@ export function EditorStateProvider(props: { children: JSXElement }) { return newRepo } catch (e) { setLixErrors([e as Error]) + return } } else { return diff --git a/inlang/source-code/manage/src/components/InlangManage.ts b/inlang/source-code/manage/src/components/InlangManage.ts index 28af0959c2..f130cc5bc6 100644 --- a/inlang/source-code/manage/src/components/InlangManage.ts +++ b/inlang/source-code/manage/src/components/InlangManage.ts @@ -73,16 +73,12 @@ export class InlangManage extends TwLitElement { projectDropdown: NodeListOf | undefined async projectHandler() { - let repo: Repository; + let repo: Repository try { - - repo = await openRepository( - `${publicEnv.PUBLIC_GIT_PROXY_BASE_URL}/git/${this.url.repo}`, - { - nodeishFs: createNodeishMemoryFs(), - branch: this.url.branch ? this.url.branch : undefined, - } - ) + repo = await openRepository(`${publicEnv.PUBLIC_GIT_PROXY_BASE_URL}/git/${this.url.repo}`, { + nodeishFs: createNodeishMemoryFs(), + branch: this.url.branch ? this.url.branch : undefined, + }) } catch (e) { this.projects = "no-access" return diff --git a/lix/packages/client/src/index.ts b/lix/packages/client/src/index.ts index 48ac08ea18..5ca6d9e378 100644 --- a/lix/packages/client/src/index.ts +++ b/lix/packages/client/src/index.ts @@ -1,4 +1,4 @@ -export { type Repository } from "./api.js" +export { type Repository, LixError } from "./api.js" export { openRepository, findRepoRoot } from "./openRepository.js" export { createNodeishMemoryFs } from "@lix-js/fs" export { hash } from "./hash.js" From bcfbe26d5f31719c58605a715231e476f8491f89 Mon Sep 17 00:00:00 2001 From: NiklasBuchfink Date: Wed, 10 Apr 2024 13:46:50 +0200 Subject: [PATCH 04/11] fix: forkStatus should not run if repo is not a fork --- .../pages/@host/@owner/@repository/State.tsx | 51 ++++++++++--------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/inlang/source-code/editor/src/pages/@host/@owner/@repository/State.tsx b/inlang/source-code/editor/src/pages/@host/@owner/@repository/State.tsx index 004b8f6ba0..3521d2e04f 100644 --- a/inlang/source-code/editor/src/pages/@host/@owner/@repository/State.tsx +++ b/inlang/source-code/editor/src/pages/@host/@owner/@repository/State.tsx @@ -312,31 +312,6 @@ export function EditorStateProvider(props: { children: JSXElement }) { } ) - const isForkSyncDisabled = () => - localStorage.disableForkSyncWarning?.some( - (repo) => repo.owner === routeParams().owner && repo.repository === routeParams().repository - ) - - const [forkStatus, { refetch: refetchForkStatus, mutate: mutateForkStatus }] = createResource( - () => { - if (repo() && !isForkSyncDisabled()) { - return { repo: repo() } - } else { - return false - } - }, - async (args) => { - const value = await args.repo!.forkStatus() - if ("error" in value) { - setLixErrors([new Error(value.error), ...lixErrors()]) - return { ahead: 0, behind: 0, conflicts: false } - } else { - return value - } - }, - { initialValue: { ahead: 0, behind: 0, conflicts: false } } - ) - async function pushChanges(args: { user: LocalStorageSchema["user"] setFsChange: (date: Date) => void @@ -551,6 +526,32 @@ export function EditorStateProvider(props: { children: JSXElement }) { } ) + const isForkSyncDisabled = () => + localStorage.disableForkSyncWarning?.some( + (repo) => repo.owner === routeParams().owner && repo.repository === routeParams().repository + ) + + const [forkStatus, { refetch: refetchForkStatus, mutate: mutateForkStatus }] = createResource( + () => { + const repoMeta = githubRepositoryInformation() + if (repo() && !isForkSyncDisabled() && repoMeta && !("error" in repoMeta) && repoMeta.isFork) { + return { repo: repo() } + } else { + return false + } + }, + async (args) => { + const value = await args.repo!.forkStatus() + if ("error" in value) { + setLixErrors([new Error(value.error), ...lixErrors()]) + return { ahead: 0, behind: 0, conflicts: false } + } else { + return value + } + }, + { initialValue: { ahead: 0, behind: 0, conflicts: false } } + ) + const [previousLoginStatus, setPreviousLoginStatus] = createSignal(localStorage?.user?.isLoggedIn) createEffect( on( From b66f40f5f05afc0969dcd5842920bf4dc43abd7e Mon Sep 17 00:00:00 2001 From: Martin Lysk Date: Wed, 10 Apr 2024 20:34:41 +0200 Subject: [PATCH 05/11] fixes open repo - and removes test that is no longer required since openRepository doesn't fill errors anymore --- .../migrations/maybeCreateFirstProjectId.test.ts | 15 +-------------- lix/packages/client/src/openRepository.ts | 3 --- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/inlang/source-code/sdk/src/migrations/maybeCreateFirstProjectId.test.ts b/inlang/source-code/sdk/src/migrations/maybeCreateFirstProjectId.test.ts index 3aad6dd0d4..db90122636 100644 --- a/inlang/source-code/sdk/src/migrations/maybeCreateFirstProjectId.test.ts +++ b/inlang/source-code/sdk/src/migrations/maybeCreateFirstProjectId.test.ts @@ -1,7 +1,6 @@ import { generateProjectId } from "./maybeCreateFirstProjectId.js" import { it, expect } from "vitest" -import { openRepository } from "@lix-js/client/src/openRepository.ts" -import { mockRepo, createNodeishMemoryFs } from "@lix-js/client" +import { mockRepo } from "@lix-js/client" import { type Snapshot } from "@lix-js/fs" // eslint-disable-next-line no-restricted-imports -- test import { readFileSync } from "node:fs" @@ -20,15 +19,3 @@ it("should generate a project id", async () => { const projectId = await generateProjectId({ repo, projectPath: "mocked_project_path" }) expect(projectId).toBe("432d7ef29c510e99d95e2d14ef57a0797a1603859b5a851b7dff7e77161b8c08") }) - -it("should return undefined if repoMeta contains error", async () => { - const repoWithError = await openRepository("https://github.com/inlang/no-exist", { - nodeishFs: createNodeishMemoryFs(), - }) - - const projectId = await generateProjectId({ - repo: repoWithError, - projectPath: "mocked_project_path", - }) - expect(projectId).toBeUndefined() -}) diff --git a/lix/packages/client/src/openRepository.ts b/lix/packages/client/src/openRepository.ts index c361b45f5f..9e901f5e3f 100644 --- a/lix/packages/client/src/openRepository.ts +++ b/lix/packages/client/src/openRepository.ts @@ -381,9 +381,6 @@ export async function openRepository( noTags: true, }) .then(() => checkOutPlaceholders()) - .catch((newError: Error) => { - setErrors((previous: any) => [...(previous || []), newError]) - }) } else { console.info("Using existing cloned repo") } From 215af490368ed25be0ad31d8cd16d353db6c855e Mon Sep 17 00:00:00 2001 From: Martin Lysk Date: Wed, 10 Apr 2024 21:36:03 +0200 Subject: [PATCH 06/11] removes the errors dependency on state initialization --- .../editor/src/pages/@host/@owner/@repository/State.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/inlang/source-code/editor/src/pages/@host/@owner/@repository/State.tsx b/inlang/source-code/editor/src/pages/@host/@owner/@repository/State.tsx index 3521d2e04f..8a309601f1 100644 --- a/inlang/source-code/editor/src/pages/@host/@owner/@repository/State.tsx +++ b/inlang/source-code/editor/src/pages/@host/@owner/@repository/State.tsx @@ -291,8 +291,7 @@ export function EditorStateProvider(props: { children: JSXElement }) { // @ts-expect-error window.repo = newRepo } - // TODO replace this with `setLixErrors([])` as soon as repo throws - setLixErrors(newRepo.errors) + setLixErrors([]) // @ts-ignore -- causes reactivity bugs because the sdk uses watch and triggers updates on changes caused by itself newRepo.nodeishFs.watch = () => {} From 7886fe3a4acb5ca7a78f595edbaabf13a5141b26 Mon Sep 17 00:00:00 2001 From: Martin Lysk Date: Thu, 11 Apr 2024 10:05:45 +0200 Subject: [PATCH 07/11] passing repo as an argument instead of using bang --- .../src/pages/@host/@owner/@repository/State.tsx | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/inlang/source-code/editor/src/pages/@host/@owner/@repository/State.tsx b/inlang/source-code/editor/src/pages/@host/@owner/@repository/State.tsx index 8a309601f1..fb48d605f3 100644 --- a/inlang/source-code/editor/src/pages/@host/@owner/@repository/State.tsx +++ b/inlang/source-code/editor/src/pages/@host/@owner/@repository/State.tsx @@ -503,21 +503,23 @@ export function EditorStateProvider(props: { children: JSXElement }) { const [githubRepositoryInformation, { refetch: refetchRepoInfo }] = createResource( () => { + const loadedRepo = repo(); if ( localStorage?.user === undefined || routeParams().owner === undefined || routeParams().repository === undefined || - repo() === undefined + loadedRepo === undefined ) { return false } return { + repo: loadedRepo, user: localStorage.user, routeParams: routeParams(), } }, - async () => { - const repoMeta = await repo()!.getMeta() + async ({repo: loadedRepo}) => { + const repoMeta = await loadedRepo.getMeta() if ("error" in repoMeta) { setLixErrors([repoMeta.error, ...lixErrors()]) } @@ -533,7 +535,13 @@ export function EditorStateProvider(props: { children: JSXElement }) { const [forkStatus, { refetch: refetchForkStatus, mutate: mutateForkStatus }] = createResource( () => { const repoMeta = githubRepositoryInformation() - if (repo() && !isForkSyncDisabled() && repoMeta && !("error" in repoMeta) && repoMeta.isFork) { + if ( + repo() && + !isForkSyncDisabled() && + repoMeta && + !("error" in repoMeta) && + repoMeta.isFork + ) { return { repo: repo() } } else { return false From 8aca5925bb03651d41aea0d3b5f2c0f52c28cc77 Mon Sep 17 00:00:00 2001 From: Martin Lysk Date: Thu, 11 Apr 2024 15:06:49 +0200 Subject: [PATCH 08/11] cleanup --- .../editor/src/pages/@host/@owner/@repository/State.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inlang/source-code/editor/src/pages/@host/@owner/@repository/State.tsx b/inlang/source-code/editor/src/pages/@host/@owner/@repository/State.tsx index fb48d605f3..1775bdd395 100644 --- a/inlang/source-code/editor/src/pages/@host/@owner/@repository/State.tsx +++ b/inlang/source-code/editor/src/pages/@host/@owner/@repository/State.tsx @@ -503,7 +503,7 @@ export function EditorStateProvider(props: { children: JSXElement }) { const [githubRepositoryInformation, { refetch: refetchRepoInfo }] = createResource( () => { - const loadedRepo = repo(); + const loadedRepo = repo() if ( localStorage?.user === undefined || routeParams().owner === undefined || @@ -518,7 +518,7 @@ export function EditorStateProvider(props: { children: JSXElement }) { routeParams: routeParams(), } }, - async ({repo: loadedRepo}) => { + async ({ repo: loadedRepo }) => { const repoMeta = await loadedRepo.getMeta() if ("error" in repoMeta) { setLixErrors([repoMeta.error, ...lixErrors()]) From f6d10dd85b7c400286825c4d638c085b4b8980c5 Mon Sep 17 00:00:00 2001 From: Martin Lysk Date: Tue, 16 Apr 2024 15:34:33 +0200 Subject: [PATCH 09/11] WIP test added --- .../src/migrations/maybeCreateFirstProjectId.test.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/inlang/source-code/sdk/src/migrations/maybeCreateFirstProjectId.test.ts b/inlang/source-code/sdk/src/migrations/maybeCreateFirstProjectId.test.ts index db90122636..c931548e53 100644 --- a/inlang/source-code/sdk/src/migrations/maybeCreateFirstProjectId.test.ts +++ b/inlang/source-code/sdk/src/migrations/maybeCreateFirstProjectId.test.ts @@ -19,3 +19,13 @@ it("should generate a project id", async () => { const projectId = await generateProjectId({ repo, projectPath: "mocked_project_path" }) expect(projectId).toBe("432d7ef29c510e99d95e2d14ef57a0797a1603859b5a851b7dff7e77161b8c08") }) + +it("should return undefined if repoMeta contains error", async () => { + await repo.nodeishFs.rm("/.git", { recursive: true }) + + const projectId = await generateProjectId({ + repo: repo, + projectPath: "mocked_project_path", + }) + expect(projectId).toBeUndefined() +}) \ No newline at end of file From 1b7e32e8cf3b40f6fde874f35ed468e7a086dd18 Mon Sep 17 00:00:00 2001 From: Jan <110794494+janfjohannes@users.noreply.github.com> Date: Tue, 16 Apr 2024 13:45:13 +0000 Subject: [PATCH 10/11] update lock file --- pnpm-lock.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 669ebb2a99..7cacdf7914 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2240,7 +2240,7 @@ importers: devDependencies: '@types/node': specifier: ^20.12.6 - version: 20.12.7 + version: 20.12.6 vitest: specifier: 0.34.6 version: 0.34.6(jsdom@22.1.0) From ebb3b7620a150ef0f56dd6f70ca2929c38d63033 Mon Sep 17 00:00:00 2001 From: Jan <110794494+janfjohannes@users.noreply.github.com> Date: Tue, 16 Apr 2024 14:19:17 +0000 Subject: [PATCH 11/11] fix mising type imporrt --- .../editor/src/pages/@host/@owner/@repository/State.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/inlang/source-code/editor/src/pages/@host/@owner/@repository/State.tsx b/inlang/source-code/editor/src/pages/@host/@owner/@repository/State.tsx index e07b063c7c..d672f7c171 100644 --- a/inlang/source-code/editor/src/pages/@host/@owner/@repository/State.tsx +++ b/inlang/source-code/editor/src/pages/@host/@owner/@repository/State.tsx @@ -23,6 +23,7 @@ import { openRepository, createNodeishMemoryFs, type Repository, + type LixError } from "@lix-js/client" import { publicEnv } from "@inlang/env-variables"