Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy clone with batch #2326

Merged
merged 63 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
3ef6238
add placeholder support to memfs implementation
janfjohannes Feb 5, 2024
df68c41
fix cors middleware path parsing
janfjohannes Feb 5, 2024
2bda501
fix getOrigin type and remove safeHash support
janfjohannes Feb 6, 2024
0181afb
ignore git folder in listProjects
janfjohannes Feb 6, 2024
a42c8a5
add reminder to add json format support
janfjohannes Feb 6, 2024
5c8329e
fix git proxy path parsing and add local dev setup configuration
janfjohannes Feb 6, 2024
28eca14
split up editor and lix dev commands and always rebuild env var package
janfjohannes Feb 7, 2024
49173dc
add git server configuration
janfjohannes Feb 7, 2024
336e9f5
add debug features to editor on non prod, add file patching to plugin…
janfjohannes Feb 7, 2024
64fae46
add isogit cache flag (still disabled)
janfjohannes Feb 7, 2024
d48e14c
fix git proxy urls for new parsing logic
janfjohannes Feb 7, 2024
bbcba41
add lazy warning and cache for clone
janfjohannes Feb 7, 2024
26a4204
dont crash app on failing to write project id
janfjohannes Feb 7, 2024
2b71399
fail unsupported lazy re-checkout
janfjohannes Feb 7, 2024
af8458d
add lixFs feature flag
janfjohannes Feb 7, 2024
455d940
add lazy checkout and placeholder checkout capabilities
janfjohannes Feb 7, 2024
0cc1534
minor reformating
janfjohannes Feb 7, 2024
5ae33f1
switch to checkout placeholders instead of full checkout
janfjohannes Feb 7, 2024
f9e4b7d
minor reformating
janfjohannes Feb 7, 2024
0ba9de6
disable lazy fs handling on nodeFS with preexisting git repo
janfjohannes Feb 7, 2024
7f821a3
add lazy readfile and readlink with batching
janfjohannes Feb 7, 2024
1949ebd
add test test cases for statusMatrix
janfjohannes Feb 8, 2024
e4b1c68
reimplement statusMatrix
janfjohannes Feb 8, 2024
03fa6f2
breaking: update lix status api, enable isogit cache, catch lix broke…
janfjohannes Feb 16, 2024
ce48d66
WIP
janfjohannes Feb 28, 2024
e14cfb9
move iso git folder, fix snapshot handling for placeholders, fix file…
janfjohannes Feb 29, 2024
503fb81
remove obsolete changeset and fix file mode matching
janfjohannes Mar 1, 2024
ac007e9
ignore node modules by default in debug launch config
janfjohannes Mar 1, 2024
ccd8c1b
reenable telemetry
janfjohannes Mar 1, 2024
48a61a7
fix iso git really needed deps and update deps to non vulnerable ones
janfjohannes Mar 1, 2024
e40aab3
fix all isogit imports/ usage, fix isPlaceholder crash on nodefs
janfjohannes Mar 1, 2024
f862f13
typo
janfjohannes Mar 1, 2024
b17ca88
add back pathnormalization for readlink
janfjohannes Mar 1, 2024
82039d2
add worth walking patch
janfjohannes Mar 1, 2024
11e7747
let isogit handle missing cache internally
janfjohannes Mar 1, 2024
0ed9987
remove done todo
janfjohannes Mar 1, 2024
60c334c
remove old debug timeout
janfjohannes Mar 1, 2024
fce28a6
remove desperate comment crying for help
janfjohannes Mar 1, 2024
10df944
remove obsolete comments
janfjohannes Mar 1, 2024
0d129ff
fix formatting
janfjohannes Mar 1, 2024
2a7789c
use internal branch name istead of argument
janfjohannes Mar 1, 2024
401e119
add first batch of pr feedback
janfjohannes Mar 5, 2024
ac7794a
add documentation to statustext type
janfjohannes Mar 5, 2024
6d76bfd
commenting, cleanup and more expliced returns
martin-lysk Mar 11, 2024
7f4cbde
adds limitation collection
martin-lysk Mar 11, 2024
2c701a0
PR review cleanup
martin-lysk Mar 12, 2024
3ec08d7
pr - review changes added
martin-lysk Mar 12, 2024
31fd935
WIP - some tests failing
martin-lysk Mar 14, 2024
1713f33
fixes status list test for untracked files
martin-lysk Mar 14, 2024
f61c946
add sparefilter filteype fixes
janfjohannes Mar 15, 2024
50e0135
fix formatting, add batching explanation, add *added2 status,
janfjohannes Mar 18, 2024
134f89e
replace implicit isogit imports, remove obsolete pending initializati…
janfjohannes Mar 18, 2024
d458804
fix error handling for unlinking placeholder
janfjohannes Mar 18, 2024
b37a6ad
fix error handling for symlinking on placeholder
janfjohannes Mar 18, 2024
752f660
fix error codes for placeholder
janfjohannes Mar 18, 2024
246c057
fix error message for rmdir placeholder
janfjohannes Mar 18, 2024
99c5daf
add missing placholder check in mkdir
janfjohannes Mar 18, 2024
a88cc30
add support for nested gitignore files
janfjohannes Mar 19, 2024
0314da1
fix race conditions, check placeholder support upfront fro lazy clone,
janfjohannes Mar 19, 2024
c532620
use whitelisted repos for lazy clone in fink, allow disabling lazy vi…
janfjohannes Mar 20, 2024
bb42559
use globalThis.crypto instead of node only import to fix esbuild setup
janfjohannes Mar 20, 2024
3aea6af
try other method to force exclusion of dynamic import as we have to s…
janfjohannes Mar 21, 2024
00c807e
update lockfile
janfjohannes Mar 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/fifty-chefs-sneeze.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@lix-js/client": major
"@lix-js/server": major
"@lix-js/fs": major
---

New lazy checkout features and breaking api improvements
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"autoAttachChildProcesses": true,
"skipFiles": ["<node_internals>/**", "**/node_modules/**"],
"program": "${workspaceRoot}/node_modules/vitest/vitest.mjs",
"args": ["run", "${relativeFile}"],
"args": ["dev", "--singleThread=true", "${relativeFile}"],
"smartStep": true,
"console": "integratedTerminal"
},
Expand Down
1 change: 0 additions & 1 deletion inlang/source-code/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
"consola": "^3.2.3",
"cross-env": "^7.0.3",
"esbuild": "^0.19.2",
"isomorphic-git": "1.24.5",
"node-fetch": "^3.3.2",
"prompts": "^2.4.2",
"typescript": "5.2.2",
Expand Down
13 changes: 9 additions & 4 deletions inlang/source-code/cli/src/commands/open/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { exec } from "node:child_process"
import { Command } from "commander"
import { log } from "../../utilities/log.js"
import fs from "node:fs/promises"
import { findRoot, listRemotes } from "isomorphic-git"
import { findRepoRoot, _listRemotes } from "@lix-js/client"
import { parseOrigin } from "@inlang/telemetry"
import type { NodeishFilesystem } from "@lix-js/fs"

Expand All @@ -21,15 +21,20 @@ export async function editorCommandAction(args: {
}) {
let repoRoot: string | undefined
try {
repoRoot = await findRoot({ fs: args.nodeishFs, filepath: args.path })
repoRoot = await findRepoRoot({ nodeishFs: args.nodeishFs, path: args.path })
if (!repoRoot) {
args.logger.error("Failed to find repository root.")
return
}
} catch (error) {
args.logger.error("Failed to find repository root.")
return
}

const remotes = await listRemotes({
// _listReomotes deprecated, open repo and use repo.listRemotes
const remotes = await _listRemotes({
fs: args.nodeishFs,
dir: repoRoot,
dir: repoRoot?.replace("file://", ""),
})

const origin = parseOrigin({ remotes })
Expand Down
2 changes: 0 additions & 2 deletions inlang/source-code/editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"node": ">=18.0.0"
},
"dependencies": {
"@isomorphic-git/cors-proxy": "^2.7.1",
"@lix-js/client": "workspace:*",
"@lix-js/fs": "workspace:*",
"@lix-js/server": "workspace:*",
Expand Down Expand Up @@ -49,7 +48,6 @@
"date-fns": "^2.29.3",
"dotenv": "^16.0.3",
"flat": "^5.0.2",
"isomorphic-git": "1.24.5",
"jose": "^4.11.1",
"octokit": "3.1.2",
"posthog-js": "^1.91.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ export function EditorStateProvider(props: { children: JSXElement }) {
async ({ routeParams: { host, owner, repository }, branch, user }) => {
if (host && owner && repository && user) {
try {
if (!import.meta.env.PROD) {
console.time("openRepository")
}

const newRepo = await openRepository(
`${publicEnv.PUBLIC_GIT_PROXY_BASE_URL}/git/${host}/${owner}/${repository}`,
{
Expand All @@ -271,15 +275,21 @@ export function EditorStateProvider(props: { children: JSXElement }) {
}
)

if (window && !import.meta.env.PROD) {
// @ts-expect-error
window.repo = newRepo
}

if (newRepo.errors().length > 0) {
setLixErrors(newRepo.errors())
return
} else {
setLixErrors([])
}

// @ts-expect-error
newRepo.nodeishFs.watch = () => undefined
// @ts-ignore -- causes reactivity bugs because the sdk uses watch and triggers updates on changes caused by itself
newRepo.nodeishFs.watch = () => {}
janfjohannes marked this conversation as resolved.
Show resolved Hide resolved

setLastPullTime(new Date())
// Invalidate the project while we switch branches
setProject(undefined)
Expand All @@ -294,7 +304,7 @@ export function EditorStateProvider(props: { children: JSXElement }) {
}
)

repo()?.errors.subscribe((errors) => {
repo()?.errors.subscribe((errors: any) => {
setLixErrors(errors)
})

Expand Down Expand Up @@ -614,8 +624,7 @@ export async function pushChanges(args: {
return { error: new PushException("User not logged in") }
}

// stage all changes
const status = await args.repo.statusMatrix({
const filesWithUncommittedChanges = await args.repo.statusList({
filter: (f: any) =>
f.endsWith("project_id") ||
f.endsWith(".json") ||
Expand All @@ -626,25 +635,15 @@ export async function pushChanges(args: {
f.endsWith(".ts"),
})

const filesWithUncommittedChanges = status.filter(
(row: any) =>
// files with unstaged and uncommitted changes
(row[2] === 2 && row[3] === 1) ||
// added files
(row[2] === 2 && row[3] === 0)
)

if (filesWithUncommittedChanges.length > 0) {
// add all changes
await args.repo.add({ filepath: filesWithUncommittedChanges.map((file) => file[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]),
martin-lysk marked this conversation as resolved.
Show resolved Hide resolved
})
}

Expand Down
1 change: 0 additions & 1 deletion inlang/source-code/ide-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@
"esbuild": "^0.19.8",
"expect-webdriverio": "^4.6.1",
"fs-extra": "^11.2.0",
"isomorphic-git": "1.25.0",
"mocha": "^10.2.0",
"node-fetch": "^3.3.2",
"ovsx": "^0.8.3",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { describe, it, expect, vi, beforeEach } from "vitest"
import { getGitOrigin } from "./getGitOrigin.js"
import * as isomorphicGit from "isomorphic-git"
import * as lixClient from "@lix-js/client"

// Mocks
vi.mock("vscode", () => ({
workspace: {
workspaceFolders: [{ uri: { fsPath: "mock/path" } }],
},
}))
vi.mock("isomorphic-git", () => ({
findRoot: vi.fn().mockResolvedValue("mock/root"),
listRemotes: vi.fn().mockResolvedValue([{ url: "[email protected]:user/repo.git" }]),
vi.mock("@lix-js/client", () => ({
findRepoRoot: vi.fn().mockResolvedValue("mock/root"),
_listRemotes: vi.fn().mockResolvedValue([{ url: "[email protected]:user/repo.git" }]),
}))
vi.mock("node:fs", () => ({}))
vi.mock("node:fs/promises", () => ({}))
vi.mock("@inlang/telemetry", () => ({
parseOrigin: vi.fn().mockReturnValue("https://github.com/user/repo"),
}))
Expand All @@ -21,9 +21,9 @@ describe("getGitOrigin", () => {
beforeEach(() => {
vi.clearAllMocks()
// @ts-expect-error
isomorphicGit.findRoot.mockResolvedValue("mock/root")
lixClient.findRepoRoot.mockResolvedValue("mock/root")
// @ts-expect-error
isomorphicGit.listRemotes.mockResolvedValue([{ url: "[email protected]:user/repo.git" }])
lixClient._listRemotes.mockResolvedValue([{ url: "[email protected]:user/repo.git" }])
})

it("should return the parsed git origin URL", async () => {
Expand All @@ -33,7 +33,7 @@ describe("getGitOrigin", () => {

it("should handle errors and return undefined", async () => {
// @ts-expect-error
isomorphicGit.findRoot.mockRejectedValueOnce(new Error("Mock error"))
lixClient.findRepoRoot.mockRejectedValueOnce(new Error("Mock error"))
const origin = await getGitOrigin()
expect(origin).toBeUndefined()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@
*/

import { parseOrigin } from "@inlang/telemetry"
import { findRoot, listRemotes } from "isomorphic-git"
import { findRepoRoot, _listRemotes } from "@lix-js/client"
import * as vscode from "vscode"
import * as fs from "node:fs"
import * as fs from "node:fs/promises"

export async function getGitOrigin() {
try {
const workspaceRoot = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath
const remotes = await listRemotes({

// FIXME _listRemotes is deprecated. openRepo and then call repo.listRemotes instead!
const remotes = await _listRemotes({
fs,
dir: await findRoot({
fs,
filepath: workspaceRoot ?? process.cwd(),
}),
dir: (
await findRepoRoot({
nodeishFs: fs,
path: workspaceRoot ?? process.cwd(),
})
)?.replace("file://", ""),
})
const gitOrigin = parseOrigin({ remotes })
return gitOrigin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@
$: if (browser) document.documentElement.dir = i18n.config.textDirection[lang] ?? "ltr"

let numberOfLanugageChanges = 0
$: if(lang)numberOfLanugageChanges += 1;
$: if(browser && lang && numberOfLanugageChanges > 1) invalidate(LANGUAGE_CHANGE_INVALIDATION_KEY)

$: if (lang) numberOfLanugageChanges += 1
$: if (browser && lang && numberOfLanugageChanges > 1)
invalidate(LANGUAGE_CHANGE_INVALIDATION_KEY)

function translateHref(href: string, hreflang: string | undefined): string {
const from = new URL(get(page).url)
Expand Down Expand Up @@ -90,12 +90,11 @@

setContext(PARAGLIDE_CONTEXT_KEY, { translateHref })


// In svelte 5 the #key block will re-render the second the key changes,
// In svelte 5 the #key block will re-render the second the key changes,
// not after the all the updates in the Component are done.
// We need to make sure that changing the key happens last.
// See https://github.com/sveltejs/svelte/issues/10597
$: langKey = lang;
$: langKey = lang
</script>

<svelte:head>
Expand All @@ -110,13 +109,11 @@
prefixDefaultLanguage: i18n.config.prefixDefaultLanguage,
})}

{@const href = $page.url.host === "sveltekit-prerender"
? path
: (new URL(path, new URL($page.url))).href
}
{@const href =
$page.url.host === "sveltekit-prerender" ? path : new URL(path, new URL($page.url)).href}

<!-- Should be a fully qualified href, including protocol -->
<link rel="alternate" hreflang={lang} href={href} />
<link rel="alternate" hreflang={lang} {href} />
{/each}
{/if}
{/if}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,14 @@ export type I18nConfig<T extends string> = {
export function createI18n<T extends string>(runtime: Paraglide<T>, options?: I18nUserConfig<T>) {
const translations = resolvePathTranslations(
options?.pathnames ?? {},
runtime.availableLanguageTags
runtime.availableLanguageTags,
)

if (dev) {
const issues = validatePathTranslations(translations, runtime.availableLanguageTags)
if (issues.length) {
console.warn(
`The following issues were found in your path translations. Make sure to fix them before deploying your app:`
`The following issues were found in your path translations. Make sure to fix them before deploying your app:`,
)
console.table(issues)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ export type PathTranslations<T extends string = string> = {

export type Message<T extends string> = (
params: Record<string, never>,
options: { languageTag: T }
options: { languageTag: T },
) => string
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { Message, PathTranslations, UserPathTranslations } from "./pathTran
*/
export function resolvePathTranslations<T extends string>(
userTranslations: UserPathTranslations<T>,
availableLanguageTags: readonly T[]
availableLanguageTags: readonly T[],
): PathTranslations<T> {
const translations: PathTranslations<T> = {}
for (const path in userTranslations) {
Expand All @@ -33,10 +33,10 @@ export function resolvePathTranslations<T extends string>(

function fromMessage<T extends string>(
message: Message<T>,
availableLanguageTags: readonly T[]
availableLanguageTags: readonly T[],
): Record<T, `/${string}`> {
const entries = availableLanguageTags.map(
(languageTag) => [languageTag, message({}, { languageTag })] as const
(languageTag) => [languageTag, message({}, { languageTag })] as const,
)
return Object.fromEntries(entries) as Record<T, `/${string}`>
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export type PathTranslationIssue = {
*/
export function validatePathTranslations<T extends string>(
pathTranslations: PathTranslations<T>,
availableLanguageTags: readonly T[]
availableLanguageTags: readonly T[],
): PathTranslationIssue[] {
const issues: PathTranslationIssue[] = []
const expectedLanguages = new Set(availableLanguageTags)
Expand Down Expand Up @@ -58,7 +58,7 @@ export function validatePathTranslations<T extends string>(
issues.push({
path,
message: `The following languages are missing translations: ${[...missingLanguages].join(
", "
", ",
)}`,
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export type HandleOptions = {

export const createHandle = <T extends string>(
i18n: I18nConfig<T>,
options: HandleOptions
options: HandleOptions,
): Handle => {
const langPlaceholder = options.langPlaceholder ?? "%paraglide.lang%"
const dirPlaceholder = options.textDirectionPlaceholder ?? "%paraglide.textDirection%"
Expand Down Expand Up @@ -83,7 +83,7 @@ export const createHandle = <T extends string>(
`Please replace the \`lang\` attribute with the correct placeholder:"\n\n` +
` - <html ${SVELTEKIT_DEFAULT_LANG_ATTRIBUTE}>\n` +
` + <html lang="${langPlaceholder}" dir="${dirPlaceholder}">` +
`\n\nThis message will not be shown in production.`
`\n\nThis message will not be shown in production.`,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { PathTranslations } from "../config/pathTranslations.js"
*/
export const handleRedirects: (
runtime: Paraglide<any>,
translations: PathTranslations<string>
translations: PathTranslations<string>,
) => Handle =
(runtime, translations) =>
async ({ event, resolve }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { PathTranslations } from "../config/pathTranslations.js"
export function getCanonicalPath(
translatedPath: string,
lang: string,
translations: PathTranslations
translations: PathTranslations,
): string {
for (const [canonicalPathDefinition, translationsForPath] of Object.entries(translations)) {
if (!(lang in translationsForPath)) continue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { PathTranslations } from "../config/pathTranslations.js"
export function getTranslatedPath(
canonicalPath: string,
lang: string,
translations: PathTranslations
translations: PathTranslations,
) {
const match = matches(canonicalPath, Object.keys(translations))
if (!match) return canonicalPath
Expand Down
Loading
Loading