From a10f1b877a670b4c84ab75a39072db2b31ab5795 Mon Sep 17 00:00:00 2001 From: Felix Haeberle Date: Tue, 10 Sep 2024 12:51:16 +0200 Subject: [PATCH 01/12] remove git specifics --- .../utilities/settings/_getCurrentBranch.ts | 30 ------------------- .../src/utilities/settings/_getGitOrigin.ts | 30 ------------------- .../settings/getCurrentBranch.test.ts | 29 ------------------ .../utilities/settings/getCurrentBranch.ts | 13 -------- .../utilities/settings/getGitOrigin.test.ts | 28 ----------------- .../src/utilities/settings/getGitOrigin.ts | 13 -------- 6 files changed, 143 deletions(-) delete mode 100644 inlang/source-code/ide-extension/src/utilities/settings/_getCurrentBranch.ts delete mode 100644 inlang/source-code/ide-extension/src/utilities/settings/_getGitOrigin.ts delete mode 100644 inlang/source-code/ide-extension/src/utilities/settings/getCurrentBranch.test.ts delete mode 100644 inlang/source-code/ide-extension/src/utilities/settings/getCurrentBranch.ts delete mode 100644 inlang/source-code/ide-extension/src/utilities/settings/getGitOrigin.test.ts delete mode 100644 inlang/source-code/ide-extension/src/utilities/settings/getGitOrigin.ts diff --git a/inlang/source-code/ide-extension/src/utilities/settings/_getCurrentBranch.ts b/inlang/source-code/ide-extension/src/utilities/settings/_getCurrentBranch.ts deleted file mode 100644 index dec63f15ea..0000000000 --- a/inlang/source-code/ide-extension/src/utilities/settings/_getCurrentBranch.ts +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Gets current git branch of the currently opened repository. - */ - -import { findRepoRoot, openRepository } from "@lix-js/client" -import type { NodeishFilesystem } from "@lix-js/fs" - -export async function _getCurrentBranch({ - fs, - workspaceRoot, -}: { - fs: NodeishFilesystem - workspaceRoot: string | undefined -}): Promise { - try { - const repoRoot = await findRepoRoot({ - nodeishFs: fs, - path: workspaceRoot || "", - }) - - if (!repoRoot) { - console.error("Failed to find repository root.") - return - } - const repo = await openRepository(repoRoot, { nodeishFs: fs }) - return repo.getCurrentBranch() - } catch (e) { - return undefined - } -} diff --git a/inlang/source-code/ide-extension/src/utilities/settings/_getGitOrigin.ts b/inlang/source-code/ide-extension/src/utilities/settings/_getGitOrigin.ts deleted file mode 100644 index 90ce746b56..0000000000 --- a/inlang/source-code/ide-extension/src/utilities/settings/_getGitOrigin.ts +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Gets the git origin url of the currently opened repository. - */ - -import { findRepoRoot, openRepository } from "@lix-js/client" -import type { NodeishFilesystem } from "@lix-js/fs" - -export async function _getGitOrigin({ - fs, - workspaceRoot, -}: { - fs: NodeishFilesystem - workspaceRoot: string | undefined -}) { - try { - const repoRoot = await findRepoRoot({ - nodeishFs: fs, - path: workspaceRoot || "", - }) - - if (!repoRoot) { - console.error("Failed to find repository root.") - return - } - const repo = await openRepository(repoRoot, { nodeishFs: fs }) - return repo.getOrigin() - } catch (e) { - return undefined - } -} diff --git a/inlang/source-code/ide-extension/src/utilities/settings/getCurrentBranch.test.ts b/inlang/source-code/ide-extension/src/utilities/settings/getCurrentBranch.test.ts deleted file mode 100644 index 3816b61221..0000000000 --- a/inlang/source-code/ide-extension/src/utilities/settings/getCurrentBranch.test.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { describe, it, expect } from "vitest" -import { createNodeishMemoryFs, fromSnapshot as loadSnapshot, type Snapshot } from "@lix-js/fs" -import { readFileSync } from "node:fs" -import { resolve } from "node:path" -import { _getCurrentBranch } from "./_getCurrentBranch.js" - -const nodeishFs = createNodeishMemoryFs() - -const ciTestRepo: Snapshot = JSON.parse( - readFileSync(resolve(__dirname, "../../../test/mocks/ci-test-repo.json"), { - encoding: "utf-8", - }) -) - -loadSnapshot(nodeishFs, ciTestRepo) - -describe("getCurrentBranch", () => { - it("should return the current git branch when the repository root is found", async () => { - const branch = await _getCurrentBranch({ fs: nodeishFs, workspaceRoot: "src" }) - expect(branch).toEqual("test-symlink") - }) - - it("should return undefined when no repository root is found", async () => { - // Correctly handle the case where the repository root is not found - await nodeishFs.rm(".git", { recursive: true }) - const branch = await _getCurrentBranch({ fs: nodeishFs, workspaceRoot: "src" }) - expect(branch).toBeUndefined() - }) -}) diff --git a/inlang/source-code/ide-extension/src/utilities/settings/getCurrentBranch.ts b/inlang/source-code/ide-extension/src/utilities/settings/getCurrentBranch.ts deleted file mode 100644 index 7b947ce752..0000000000 --- a/inlang/source-code/ide-extension/src/utilities/settings/getCurrentBranch.ts +++ /dev/null @@ -1,13 +0,0 @@ -/** - * Get the current branch of the git repository. Wrapper around _getGitBranch.ts to allow testing with functional code - */ - -import { _getCurrentBranch } from "./_getCurrentBranch.js" - -import * as vscode from "vscode" -import * as fs from "node:fs/promises" - -export async function getCurrentBranch() { - const workspaceRoot = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath ?? process.cwd() - return _getCurrentBranch({ fs, workspaceRoot }) -} diff --git a/inlang/source-code/ide-extension/src/utilities/settings/getGitOrigin.test.ts b/inlang/source-code/ide-extension/src/utilities/settings/getGitOrigin.test.ts deleted file mode 100644 index bb5c1a513d..0000000000 --- a/inlang/source-code/ide-extension/src/utilities/settings/getGitOrigin.test.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { describe, it, expect } from "vitest" -import { createNodeishMemoryFs, fromSnapshot as loadSnapshot, type Snapshot } from "@lix-js/fs" -import { readFileSync } from "node:fs" -import { resolve } from "node:path" -import { _getGitOrigin } from "./_getGitOrigin.js" - -const nodeishFs = createNodeishMemoryFs() - -const ciTestRepo: Snapshot = JSON.parse( - readFileSync(resolve(__dirname, "../../../test/mocks/ci-test-repo.json"), { - encoding: "utf-8", - }) -) - -loadSnapshot(nodeishFs, ciTestRepo) - -describe("getGitOrigin", () => { - it("should return the parsed git origin URL when workspace is present", async () => { - const origin = await _getGitOrigin({ fs: nodeishFs, workspaceRoot: "src" }) - expect(origin).toEqual("github.com/inlang/ci-test-repo.git") - }) - - it("should handle errors and return undefined when no workspace folder is found", async () => { - await nodeishFs.rm(".git", { recursive: true }) - const origin = await _getGitOrigin({ fs: nodeishFs, workspaceRoot: "src" }) - expect(origin).toBeUndefined() - }) -}) diff --git a/inlang/source-code/ide-extension/src/utilities/settings/getGitOrigin.ts b/inlang/source-code/ide-extension/src/utilities/settings/getGitOrigin.ts deleted file mode 100644 index 94bc7a8958..0000000000 --- a/inlang/source-code/ide-extension/src/utilities/settings/getGitOrigin.ts +++ /dev/null @@ -1,13 +0,0 @@ -/** - * Gets the git origin url of the currently opened repository. Wrapper around _getGitOrigin.ts to allow testing with functional code - */ - -import { _getGitOrigin } from "./_getGitOrigin.js" - -import * as vscode from "vscode" -import * as fs from "node:fs/promises" - -export async function getGitOrigin() { - const workspaceRoot = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath ?? process.cwd() - return _getGitOrigin({ fs, workspaceRoot }) -} From f1c486be36d88265f523c1cb65feb4eb5fea8adb Mon Sep 17 00:00:00 2001 From: Felix Haeberle Date: Tue, 10 Sep 2024 12:51:25 +0200 Subject: [PATCH 02/12] update deps --- inlang/source-code/ide-extension/package.json | 9 ++---- pnpm-lock.yaml | 31 +++++-------------- 2 files changed, 10 insertions(+), 30 deletions(-) diff --git a/inlang/source-code/ide-extension/package.json b/inlang/source-code/ide-extension/package.json index 17ee1122d8..5d970c4aa3 100644 --- a/inlang/source-code/ide-extension/package.json +++ b/inlang/source-code/ide-extension/package.json @@ -238,16 +238,11 @@ "clean": "rm -rf ./dist ./node_modules" }, "dependencies": { - "@inlang/recommend-ninja": "workspace:*", - "@inlang/recommend-sherlock": "workspace:*", - "@inlang/result": "workspace:*", - "@inlang/rpc": "workspace:*", - "@inlang/sdk": "workspace:*", "@inlang/sdk2": "workspace:*", "@inlang/settings-component": "workspace:*", + "@inlang/recommend-sherlock": "workspace:*", "@inlang/telemetry": "workspace:*", - "@lix-js/client": "workspace:*", - "@lix-js/fs": "workspace:*", + "@inlang/rpc": "workspace:*", "@vitest/coverage-v8": "0.34.6", "comlink": "^4.4.1", "fast-glob": "^3.2.12", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b73c3c9532..05e88e2114 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -937,21 +937,12 @@ importers: inlang/source-code/ide-extension: dependencies: - '@inlang/recommend-ninja': - specifier: workspace:* - version: link:../recommendations/recommend-ninja '@inlang/recommend-sherlock': specifier: workspace:* version: link:../recommendations/recommend-sherlock - '@inlang/result': - specifier: workspace:* - version: link:../result '@inlang/rpc': specifier: workspace:* version: link:../rpc - '@inlang/sdk': - specifier: workspace:* - version: link:../sdk '@inlang/sdk2': specifier: workspace:* version: link:../sdk2 @@ -961,12 +952,6 @@ importers: '@inlang/telemetry': specifier: workspace:* version: link:../telemetry - '@lix-js/client': - specifier: workspace:* - version: link:../../../lix/packages/client - '@lix-js/fs': - specifier: workspace:* - version: link:../../../lix/packages/fs '@vitest/coverage-v8': specifier: 0.34.6 version: 0.34.6(vitest@2.0.5(@types/node@20.14.14)(jsdom@22.1.0)(lightningcss@1.26.0)(terser@5.31.6)) @@ -28013,9 +27998,9 @@ snapshots: eslint-config-prettier: 8.8.0(eslint@8.57.0) eslint-import-resolver-jsconfig: 1.1.0 eslint-import-resolver-node: 0.3.7 - eslint-import-resolver-typescript: 3.5.4(eslint-plugin-import@2.27.5(@typescript-eslint/parser@5.56.0(eslint@8.57.0)(typescript@5.3.2))(eslint@8.57.0))(eslint@8.57.0) + eslint-import-resolver-typescript: 3.5.4(eslint-plugin-import@2.27.5)(eslint@8.57.0) eslint-plugin-etc: 2.0.2(eslint@8.57.0)(typescript@5.0.3) - eslint-plugin-import: 2.27.5(@typescript-eslint/parser@5.56.0(eslint@8.57.0)(typescript@5.3.2))(eslint-import-resolver-typescript@3.5.4(eslint-plugin-import@2.27.5(@typescript-eslint/parser@5.56.0(eslint@8.57.0)(typescript@5.3.2))(eslint@8.57.0))(eslint@8.57.0))(eslint@8.57.0) + eslint-plugin-import: 2.27.5(@typescript-eslint/parser@5.56.0(eslint@8.57.0)(typescript@5.3.2))(eslint-import-resolver-typescript@3.5.4)(eslint@8.57.0) eslint-plugin-jest: 27.2.1(@typescript-eslint/eslint-plugin@5.56.0(@typescript-eslint/parser@5.56.0(eslint@8.57.0)(typescript@5.3.2))(eslint@8.57.0)(typescript@5.3.2))(eslint@8.57.0)(typescript@5.0.3) eslint-plugin-jest-dom: 4.0.3(eslint@8.57.0) eslint-plugin-jest-formatting: 3.1.0(eslint@8.57.0) @@ -28111,12 +28096,12 @@ snapshots: transitivePeerDependencies: - supports-color - eslint-import-resolver-typescript@3.5.4(eslint-plugin-import@2.27.5(@typescript-eslint/parser@5.56.0(eslint@8.57.0)(typescript@5.3.2))(eslint@8.57.0))(eslint@8.57.0): + eslint-import-resolver-typescript@3.5.4(eslint-plugin-import@2.27.5)(eslint@8.57.0): dependencies: debug: 4.3.6(supports-color@8.1.1) enhanced-resolve: 5.17.1 eslint: 8.57.0 - eslint-plugin-import: 2.27.5(@typescript-eslint/parser@5.56.0(eslint@8.57.0)(typescript@5.3.2))(eslint-import-resolver-typescript@3.5.4(eslint-plugin-import@2.27.5(@typescript-eslint/parser@5.56.0(eslint@8.57.0)(typescript@5.3.2))(eslint@8.57.0))(eslint@8.57.0))(eslint@8.57.0) + eslint-plugin-import: 2.27.5(@typescript-eslint/parser@5.56.0(eslint@8.57.0)(typescript@5.3.2))(eslint-import-resolver-typescript@3.5.4)(eslint@8.57.0) get-tsconfig: 4.7.6 globby: 13.2.2 is-core-module: 2.15.0 @@ -28142,14 +28127,14 @@ snapshots: - eslint-import-resolver-webpack - supports-color - eslint-module-utils@2.8.1(@typescript-eslint/parser@5.56.0(eslint@8.57.0)(typescript@5.3.2))(eslint-import-resolver-node@0.3.7)(eslint-import-resolver-typescript@3.5.4(eslint-plugin-import@2.27.5(@typescript-eslint/parser@5.56.0(eslint@8.57.0)(typescript@5.3.2))(eslint@8.57.0))(eslint@8.57.0))(eslint@8.57.0): + eslint-module-utils@2.8.1(@typescript-eslint/parser@5.56.0(eslint@8.57.0)(typescript@5.3.2))(eslint-import-resolver-node@0.3.7)(eslint-import-resolver-typescript@3.5.4(eslint-plugin-import@2.27.5)(eslint@8.57.0))(eslint@8.57.0): dependencies: debug: 3.2.7 optionalDependencies: '@typescript-eslint/parser': 5.56.0(eslint@8.57.0)(typescript@5.0.3) eslint: 8.57.0 eslint-import-resolver-node: 0.3.7 - eslint-import-resolver-typescript: 3.5.4(eslint-plugin-import@2.27.5(@typescript-eslint/parser@5.56.0(eslint@8.57.0)(typescript@5.3.2))(eslint@8.57.0))(eslint@8.57.0) + eslint-import-resolver-typescript: 3.5.4(eslint-plugin-import@2.27.5)(eslint@8.57.0) transitivePeerDependencies: - supports-color @@ -28177,7 +28162,7 @@ snapshots: transitivePeerDependencies: - supports-color - eslint-plugin-import@2.27.5(@typescript-eslint/parser@5.56.0(eslint@8.57.0)(typescript@5.3.2))(eslint-import-resolver-typescript@3.5.4(eslint-plugin-import@2.27.5(@typescript-eslint/parser@5.56.0(eslint@8.57.0)(typescript@5.3.2))(eslint@8.57.0))(eslint@8.57.0))(eslint@8.57.0): + eslint-plugin-import@2.27.5(@typescript-eslint/parser@5.56.0(eslint@8.57.0)(typescript@5.3.2))(eslint-import-resolver-typescript@3.5.4)(eslint@8.57.0): dependencies: array-includes: 3.1.8 array.prototype.flat: 1.3.2 @@ -28186,7 +28171,7 @@ snapshots: doctrine: 2.1.0 eslint: 8.57.0 eslint-import-resolver-node: 0.3.7 - eslint-module-utils: 2.8.1(@typescript-eslint/parser@5.56.0(eslint@8.57.0)(typescript@5.3.2))(eslint-import-resolver-node@0.3.7)(eslint-import-resolver-typescript@3.5.4(eslint-plugin-import@2.27.5(@typescript-eslint/parser@5.56.0(eslint@8.57.0)(typescript@5.3.2))(eslint@8.57.0))(eslint@8.57.0))(eslint@8.57.0) + eslint-module-utils: 2.8.1(@typescript-eslint/parser@5.56.0(eslint@8.57.0)(typescript@5.3.2))(eslint-import-resolver-node@0.3.7)(eslint-import-resolver-typescript@3.5.4(eslint-plugin-import@2.27.5)(eslint@8.57.0))(eslint@8.57.0) has: 1.0.4 is-core-module: 2.15.0 is-glob: 4.0.3 From 6e3dda280bcac1d17c96d1529f8c7e8a2b392222 Mon Sep 17 00:00:00 2001 From: Felix Haeberle Date: Tue, 10 Sep 2024 12:51:46 +0200 Subject: [PATCH 03/12] update main --- inlang/source-code/ide-extension/src/main.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/inlang/source-code/ide-extension/src/main.ts b/inlang/source-code/ide-extension/src/main.ts index 299c59ca1b..f8c5c9c095 100644 --- a/inlang/source-code/ide-extension/src/main.ts +++ b/inlang/source-code/ide-extension/src/main.ts @@ -11,7 +11,6 @@ import { errorView } from "./utilities/errors/errors.js" import { messageView } from "./utilities/messages/messages.js" import { createFileSystemMapper, type FileSystem } from "./utilities/fs/createFileSystemMapper.js" import fs from "node:fs/promises" -import { normalizePath } from "@lix-js/fs" import { gettingStartedView } from "./utilities/getting-started/gettingStarted.js" import { closestInlangProject } from "./utilities/project/closestInlangProject.js" import { recommendationBannerView } from "./utilities/recommendation/recommendation.js" @@ -20,6 +19,7 @@ import { version } from "../package.json" import { statusBar } from "./utilities/settings/statusBar.js" import fg from "fast-glob" import type { IdeExtensionConfig } from "@inlang/sdk2" +import path from "node:path" //import { initErrorMonitoring } from "./services/error-monitoring/implementation.js" // Entry Point @@ -46,7 +46,7 @@ export async function activate(context: vscode.ExtensionContext): Promise }, }) - const mappedFs = createFileSystemMapper(normalizePath(workspaceFolder.uri.fsPath), fs) + const mappedFs = createFileSystemMapper(path.normalize(workspaceFolder.uri.fsPath), fs) await setProjects({ workspaceFolder }) await main({ context, workspaceFolder, fs: mappedFs }) @@ -66,7 +66,7 @@ async function main(args: { if (state().projectsInWorkspace.length > 0) { // find the closest project to the workspace const closestProjectToWorkspace = await closestInlangProject({ - workingDirectory: normalizePath(args.workspaceFolder.uri.fsPath), + workingDirectory: path.normalize(args.workspaceFolder.uri.fsPath), projects: state().projectsInWorkspace, }) From 48dbe2d41b02b6183b7f67405ef4b9739bb7ae36 Mon Sep 17 00:00:00 2001 From: Felix Haeberle Date: Tue, 10 Sep 2024 12:51:56 +0200 Subject: [PATCH 04/12] update machineTranslate --- .../source-code/ide-extension/src/commands/machineTranslate.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inlang/source-code/ide-extension/src/commands/machineTranslate.ts b/inlang/source-code/ide-extension/src/commands/machineTranslate.ts index d05ba6ba03..06dd3b68cc 100644 --- a/inlang/source-code/ide-extension/src/commands/machineTranslate.ts +++ b/inlang/source-code/ide-extension/src/commands/machineTranslate.ts @@ -32,7 +32,7 @@ export const machineTranslateMessageCommand = { const result = await rpc.machineTranslateMessage({ bundle, // TODO: refactor machine translation to use baseLocale and targetLocales - baseLocale, + sourceLocale: baseLocale, targetLocales, }) From b746bf01719f971fd52aba47a64b4556ddcb548d Mon Sep 17 00:00:00 2001 From: Felix Haeberle Date: Tue, 10 Sep 2024 12:52:23 +0200 Subject: [PATCH 05/12] hide open in fink for now until we have lix host --- .../src/commands/openInFink.test.ts | 6 +++--- .../ide-extension/src/commands/openInFink.ts | 17 +++++------------ 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/inlang/source-code/ide-extension/src/commands/openInFink.test.ts b/inlang/source-code/ide-extension/src/commands/openInFink.test.ts index 4d6cea1411..4e66d6df63 100644 --- a/inlang/source-code/ide-extension/src/commands/openInFink.test.ts +++ b/inlang/source-code/ide-extension/src/commands/openInFink.test.ts @@ -1,8 +1,8 @@ +// @ts-nocheck import { beforeEach, describe, expect, it, vi } from "vitest" import { Uri, env } from "vscode" import { openInFinkCommand } from "./openInFink.js" import { CONFIGURATION } from "../configuration.js" -import { getGitOrigin } from "../utilities/settings/getGitOrigin.js" vi.mock("vscode", () => ({ workspace: { @@ -34,7 +34,7 @@ describe("openInFinkCommand", () => { vi.mocked(getGitOrigin).mockResolvedValue("https://github.com/user/repo") }) - it("should open the editor with message id in URL", async () => { + it.skip("should open the editor with message id in URL", async () => { const mockArgs = { messageId: "testMessageId", selectedProjectPath: "/test/path" } await openInFinkCommand.callback(mockArgs) @@ -50,7 +50,7 @@ describe("openInFinkCommand", () => { ) }) - it("should handle failure to get Git origin", async () => { + it.skip("should handle failure to get Git origin", async () => { const mockArgs = { messageId: "testMessageId", selectedProjectPath: "/test/path" } vi.mocked(getGitOrigin).mockResolvedValue(undefined) // Simulate failure diff --git a/inlang/source-code/ide-extension/src/commands/openInFink.ts b/inlang/source-code/ide-extension/src/commands/openInFink.ts index 8763457d9e..54c10d5826 100644 --- a/inlang/source-code/ide-extension/src/commands/openInFink.ts +++ b/inlang/source-code/ide-extension/src/commands/openInFink.ts @@ -1,23 +1,16 @@ import { Uri, commands, env } from "vscode" import { telemetry } from "../services/telemetry/implementation.js" -import type { Message } from "@inlang/sdk" -import { CONFIGURATION } from "../configuration.js" -import { getGitOrigin } from "../utilities/settings/getGitOrigin.js" -import { getCurrentBranch } from "../utilities/settings/getCurrentBranch.js" +import type { Bundle } from "@inlang/sdk2" +// import { CONFIGURATION } from "../configuration.js" export const openInFinkCommand = { command: "sherlock.openInFink", title: "Sherlock: Open in Fink", register: commands.registerCommand, - callback: async function (args: { messageId: Message["id"]; selectedProjectPath: string }) { - const origin = (await getGitOrigin())?.replaceAll(".git", "") - const branch = (await getCurrentBranch()) || "main" - const uri = args.messageId - ? `${CONFIGURATION.STRINGS.FINK_BASE_URL}${origin}?project=${encodeURIComponent( - args.selectedProjectPath - )}&branch=${encodeURIComponent(branch)}&id=${encodeURIComponent(args.messageId)}` - : `${CONFIGURATION.STRINGS.FINK_BASE_URL}${origin}?branch=${encodeURIComponent(branch)}` + callback: async function (args: { bundleId: Bundle["id"]; selectedProjectPath: string }) { + console.error("Not implemented", args) + const uri = "not implemented" env.openExternal(Uri.parse(uri)) telemetry.capture({ From 17b45050f61ce8de225e9ef68504ba2468cd4511 Mon Sep 17 00:00:00 2001 From: Felix Haeberle Date: Tue, 10 Sep 2024 12:52:36 +0200 Subject: [PATCH 06/12] rework file system mapper --- .../fs/createFileSystemMapper.test.ts | 25 ++++++------- .../utilities/fs/createFileSystemMapper.ts | 35 +++++++++---------- 2 files changed, 27 insertions(+), 33 deletions(-) diff --git a/inlang/source-code/ide-extension/src/utilities/fs/createFileSystemMapper.test.ts b/inlang/source-code/ide-extension/src/utilities/fs/createFileSystemMapper.test.ts index c6b7a1c27c..b57f82465e 100644 --- a/inlang/source-code/ide-extension/src/utilities/fs/createFileSystemMapper.test.ts +++ b/inlang/source-code/ide-extension/src/utilities/fs/createFileSystemMapper.test.ts @@ -1,34 +1,29 @@ import { describe, it, expect, vi, beforeEach } from "vitest" import * as _path from "node:path" -import { createFileSystemMapper } from "./createFileSystemMapper.js" +import { createFileSystemMapper, type FileSystem } from "./createFileSystemMapper.js" describe("createFileSystemMapper", () => { const normalizedBase = "/base/path" let mockFs: FileSystem beforeEach(() => { + // Mock the fs functions mockFs = { - // TODO: Fix the type of the mockFs object – fix overloads - writeFile: vi.fn(), - // @ts-expect-error readFile: vi.fn(), - // @ts-expect-error - readdir: vi.fn(), - rm: vi.fn(), + writeFile: vi.fn(), + mkdir: vi.fn(), rmdir: vi.fn(), + rm: vi.fn(), unlink: vi.fn(), - // @ts-expect-error + readdir: vi.fn(), readlink: vi.fn(), symlink: vi.fn(), - // @ts-expect-error - mkdir: vi.fn(), - // @ts-expect-error stat: vi.fn(), - // @ts-expect-error - watch: vi.fn(), - // @ts-expect-error lstat: vi.fn(), - } + watch: vi.fn(), + access: vi.fn(), + copyFile: vi.fn(), + } as unknown as FileSystem }) it("should map writeFile correctly", async () => { diff --git a/inlang/source-code/ide-extension/src/utilities/fs/createFileSystemMapper.ts b/inlang/source-code/ide-extension/src/utilities/fs/createFileSystemMapper.ts index 79715394dc..4150f893d5 100644 --- a/inlang/source-code/ide-extension/src/utilities/fs/createFileSystemMapper.ts +++ b/inlang/source-code/ide-extension/src/utilities/fs/createFileSystemMapper.ts @@ -1,4 +1,3 @@ -import { normalizePath } from "@lix-js/fs" import { default as _path } from "node:path" import type * as fs from "node:fs/promises" @@ -13,7 +12,7 @@ export type FileSystem = typeof fs */ export function createFileSystemMapper(base: string, fs: FileSystem): FileSystem { // Prevent path issue on non Unix based system normalizing the before using it - const normalizedBase = normalizePath(base) + const normalizedBase = _path.normalize(base) return { // TODO: Those expected typescript errors are because of overloads in node:fs/promises @@ -23,7 +22,7 @@ export function createFileSystemMapper(base: string, fs: FileSystem): FileSystem options: Parameters[1] ): Promise => { return fs.readFile( - normalizePath( + _path.normalize( String(path).startsWith(normalizedBase) ? String(path) : _path.resolve(normalizedBase, String(path)) @@ -37,7 +36,7 @@ export function createFileSystemMapper(base: string, fs: FileSystem): FileSystem options: Parameters[2] ) => { return fs.writeFile( - normalizePath( + _path.normalize( String(path).startsWith(normalizedBase) ? String(path) : _path.resolve(normalizedBase, String(path)) @@ -52,7 +51,7 @@ export function createFileSystemMapper(base: string, fs: FileSystem): FileSystem options?: Parameters[1] ) => { return fs.mkdir( - normalizePath( + _path.normalize( String(path).startsWith(normalizedBase) ? String(path) : _path.resolve(normalizedBase, String(path)) @@ -62,7 +61,7 @@ export function createFileSystemMapper(base: string, fs: FileSystem): FileSystem }, rmdir: async (path: Parameters[0]) => { return fs.rmdir( - normalizePath( + _path.normalize( String(path).startsWith(normalizedBase) ? String(path) : _path.resolve(normalizedBase, String(path)) @@ -71,7 +70,7 @@ export function createFileSystemMapper(base: string, fs: FileSystem): FileSystem }, rm: async (path: Parameters[0], options: Parameters[1]) => { return fs.rm( - normalizePath( + _path.normalize( String(path).startsWith(normalizedBase) ? String(path) : _path.resolve(normalizedBase, String(path)) @@ -81,7 +80,7 @@ export function createFileSystemMapper(base: string, fs: FileSystem): FileSystem }, unlink: async (path: Parameters[0]) => { return fs.unlink( - normalizePath( + _path.normalize( String(path).startsWith(normalizedBase) ? String(path) : _path.resolve(normalizedBase, String(path)) @@ -91,7 +90,7 @@ export function createFileSystemMapper(base: string, fs: FileSystem): FileSystem // @ts-expect-error readdir: async (path: Parameters[0]) => { return fs.readdir( - normalizePath( + _path.normalize( String(path).startsWith(normalizedBase) ? String(path) : _path.resolve(normalizedBase, String(path)) @@ -101,7 +100,7 @@ export function createFileSystemMapper(base: string, fs: FileSystem): FileSystem // @ts-expect-error readlink: async (path: Parameters[0]) => { return fs.readlink( - normalizePath( + _path.normalize( String(path).startsWith(normalizedBase) ? String(path) : _path.resolve(normalizedBase, String(path)) @@ -113,12 +112,12 @@ export function createFileSystemMapper(base: string, fs: FileSystem): FileSystem target: Parameters[1] ) => { return fs.symlink( - normalizePath( + _path.normalize( String(path).startsWith(normalizedBase) ? String(path) : _path.resolve(normalizedBase, String(path)) ), - normalizePath( + _path.normalize( String(target).startsWith(normalizedBase) ? String(target) : _path.resolve(normalizedBase, String(target)) @@ -128,7 +127,7 @@ export function createFileSystemMapper(base: string, fs: FileSystem): FileSystem // @ts-expect-error stat: async (path: Parameters[0]) => { return fs.stat( - normalizePath( + _path.normalize( String(path).startsWith(normalizedBase) ? String(path) : _path.resolve(normalizedBase, String(path)) @@ -138,7 +137,7 @@ export function createFileSystemMapper(base: string, fs: FileSystem): FileSystem // @ts-expect-error lstat: async (path: Parameters[0]) => { return fs.lstat( - normalizePath( + _path.normalize( String(path).startsWith(normalizedBase) ? String(path) : _path.resolve(normalizedBase, String(path)) @@ -151,7 +150,7 @@ export function createFileSystemMapper(base: string, fs: FileSystem): FileSystem options: Parameters[1] ) => { return fs.watch( - normalizePath( + _path.normalize( String(path).startsWith(normalizedBase) ? String(path) : _path.resolve(normalizedBase, String(path)) @@ -164,7 +163,7 @@ export function createFileSystemMapper(base: string, fs: FileSystem): FileSystem mode: Parameters[1] ) => { return fs.access( - normalizePath( + _path.normalize( String(path).startsWith(normalizedBase) ? String(path) : _path.resolve(normalizedBase, String(path)) @@ -178,12 +177,12 @@ export function createFileSystemMapper(base: string, fs: FileSystem): FileSystem flags: Parameters[2] ) => { return fs.copyFile( - normalizePath( + _path.normalize( String(src).startsWith(normalizedBase) ? String(src) : _path.resolve(normalizedBase, String(src)) ), - normalizePath( + _path.normalize( String(dest).startsWith(normalizedBase) ? String(dest) : _path.resolve(normalizedBase, String(dest)) From 225cd05a2446f86dfd7937bb90a996bd8615f752 Mon Sep 17 00:00:00 2001 From: Felix Haeberle Date: Tue, 10 Sep 2024 12:52:52 +0200 Subject: [PATCH 07/12] rework new project handler with path --- .../utilities/getting-started/createNewProjectHandler.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/inlang/source-code/ide-extension/src/utilities/getting-started/createNewProjectHandler.ts b/inlang/source-code/ide-extension/src/utilities/getting-started/createNewProjectHandler.ts index cfce316a0b..465602d629 100644 --- a/inlang/source-code/ide-extension/src/utilities/getting-started/createNewProjectHandler.ts +++ b/inlang/source-code/ide-extension/src/utilities/getting-started/createNewProjectHandler.ts @@ -1,8 +1,8 @@ import * as vscode from "vscode" import { loadProjectInMemory, newProject, saveProjectToDirectory } from "@inlang/sdk2" -import { normalizePath } from "@lix-js/fs" import fs from "node:fs/promises" import { createFileSystemMapper } from "../fs/createFileSystemMapper.js" +import path from "node:path" /** * Creates a new project in the workspace folder. @@ -12,10 +12,10 @@ import { createFileSystemMapper } from "../fs/createFileSystemMapper.js" export async function createNewProjectHandler(args: { workspaceFolderPath: string }) { try { const workspaceFolderPath = args.workspaceFolderPath - const nodeishFs = createFileSystemMapper(normalizePath(workspaceFolderPath), fs) + const nodeishFs = createFileSystemMapper(path.normalize(workspaceFolderPath), fs) // The path to the project directory - const projectPath = normalizePath(`${workspaceFolderPath}/project.inlang`) + const projectPath = path.normalize(`${workspaceFolderPath}/project.inlang`) // Create a new project in memory const project = await loadProjectInMemory({ @@ -33,6 +33,5 @@ export async function createNewProjectHandler(args: { workspaceFolderPath: strin vscode.commands.executeCommand("workbench.action.reloadWindow") } catch (error: any) { vscode.window.showErrorMessage(`Failed to create new project: ${error.message}`) - console.log(error) } } From 93575662ae809ec6d47213d7704c991795d70bc8 Mon Sep 17 00:00:00 2001 From: Felix Haeberle Date: Tue, 10 Sep 2024 12:53:17 +0200 Subject: [PATCH 08/12] hide open in fink for now until we have lix host --- .../ide-extension/src/utilities/messages/messages.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/inlang/source-code/ide-extension/src/utilities/messages/messages.ts b/inlang/source-code/ide-extension/src/utilities/messages/messages.ts index f321094bd4..74126762a7 100644 --- a/inlang/source-code/ide-extension/src/utilities/messages/messages.ts +++ b/inlang/source-code/ide-extension/src/utilities/messages/messages.ts @@ -282,7 +282,8 @@ export async function createMessageHtml(args: { ? `` : "" } - + +