Skip to content

Commit

Permalink
fix sdk + sherlock on win
Browse files Browse the repository at this point in the history
  • Loading branch information
felixhaeberle committed Feb 28, 2025
1 parent accf629 commit 8bf5b00
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 17 deletions.
34 changes: 23 additions & 11 deletions inlang/packages/sdk/src/project/loadProjectFromDirectory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -705,21 +705,33 @@ export function withAbsolutePaths(
* Joins a path from a project path.
*
* @example
* joinPathFromProject("/project.inlang", "./local-plugins/mock-plugin.js") -> "/local-plugins/mock-plugin.js"
* absolutePathFromProject("/project.inlang", "./local-plugins/mock-plugin.js") -> "/local-plugins/mock-plugin.js"
*
* joinPathFromProject("/website/project.inlang", "./mock-plugin.js") -> "/website/mock-plugin.js"
* absolutePathFromProject("/website/project.inlang", "./mock-plugin.js") -> "/website/mock-plugin.js"
*/
export function absolutePathFromProject(projectPath: string, path: string) {
// need to remove the project path from the module path for legacy reasons
// "/project.inlang/local-plugins/mock-plugin.js" -> "/local-plugins/mock-plugin.js"
const pathWithoutProject = projectPath
.split(nodePath.sep)
.slice(0, -1)
.join(nodePath.sep);
export function absolutePathFromProject(
projectPath: string,
filePath: string
): string {
// Normalize paths for consistency across platforms
const normalizedProjectPath = nodePath
.normalize(projectPath)
.replace(/\\/g, "/");
const normalizedFilePath = nodePath.normalize(filePath).replace(/\\/g, "/");

// Remove the last part of the project path (file name) to get the project root
const projectRoot = nodePath.dirname(normalizedProjectPath);

// If filePath is already absolute, return it directly
if (nodePath.isAbsolute(normalizedFilePath)) {
return normalizedFilePath;
}

const resolvedPath = nodePath.resolve(pathWithoutProject, path);
// Compute absolute resolved path
const resolvedPath = nodePath.resolve(projectRoot, normalizedFilePath);

return resolvedPath;
// Ensure final path always uses forward slashes
return resolvedPath.replace(/\\/g, "/");
}

export class ResourceFileImportError extends Error {
Expand Down
22 changes: 18 additions & 4 deletions inlang/packages/sherlock/src/utilities/project/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,25 @@ export function createProjectViewNodes(args: {
}

const projectPath = typeof project.projectPath === "string" ? project.projectPath : ""
const projectName = projectPath.split("/").slice(-1).join("/").replace(".inlang", "")
const relativePath =
"./" + path.normalize(projectPath.replace(args.workspaceFolder.uri.fsPath, "./"))

// Ensure forward slashes are used across platforms
const normalizedProjectPath = projectPath.split(path.sep).join("/")

// Extract project name safely
const projectName = normalizedProjectPath.split("/").slice(-1).join("/").replace(".inlang", "")

// Compute relative path
const relativePath = path
.relative(args.workspaceFolder.uri.fsPath, projectPath) // Get relative path
.split(path.sep) // Normalize separators
.join("/") // Ensure forward slashes for cross-platform compatibility

const finalRelativePath = `./${relativePath}`

return {
label: projectName,
path: project.projectPath,
relativePath: relativePath,
relativePath: finalRelativePath,
isSelected: project.projectPath === state().selectedProjectPath,
collapsibleState: vscode.TreeItemCollapsibleState.Collapsed,
context: args.context,
Expand Down Expand Up @@ -95,6 +106,7 @@ export async function handleTreeSelection(args: {
}))

const newSelectedProject = projectViewNodes.find((node) => node.isSelected)?.path as string
console.log(newSelectedProject)

try {
const localAccount = getLocalAccount({ fs })
Expand All @@ -106,6 +118,8 @@ export async function handleTreeSelection(args: {
appId: CONFIGURATION.STRINGS.APP_ID,
})

console.log("inlangProject", await inlangProject.plugins.get())

setState({
...state(),
project: inlangProject,
Expand Down
2 changes: 0 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8bf5b00

Please sign in to comment.