Skip to content

Commit

Permalink
Merge pull request #2663 from opral/paraglide-next-init-windows-paths
Browse files Browse the repository at this point in the history
Paraglide next init windows paths
  • Loading branch information
LorisSigrist authored Apr 26, 2024
2 parents 05ced20 + 3d87380 commit f5524a7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/hot-tigers-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@inlang/paraglide-next": patch
---

The `init` command now always produces posix paths for the outdir and project path, even on windows
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import path from "node:path"
import { Logger } from "@inlang/paraglide-js/internal"
import { CliStep } from "../utils"
import { CliStep, normalizePath } from "../utils"
import { Repository } from "@lix-js/client"
import { NextJSProject } from "./scan-next-project"
import path from "node:path"
import { Outdir } from "./getOutDir"

export const addParaglideNextPluginToNextConfig: CliStep<
Expand Down Expand Up @@ -63,8 +63,10 @@ https://inlang.com/m/osslbuzt/paraglide-next-i18n
const configIdentifier = match.groups?.configIdentifier as string
const identifierStartIndex = endIndex - configIdentifier.length

const relativeOutdir = "./" + path.relative(process.cwd(), ctx.outdir.path)
const relativeProjectPath = "./" + path.relative(process.cwd(), ctx.projectPath)
const posixCWD = normalizePath(process.cwd())

const relativeOutdir = "./" + path.posix.relative(posixCWD, normalizePath(ctx.outdir.path))
const relativeProjectPath = "./" + path.posix.relative(posixCWD, normalizePath(ctx.projectPath))

const wrappedIdentifier = `paraglide({
paraglide: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { CliStep } from "../utils"
export type Outdir = {
/**
* The absolute path to the outdir
*
* @example
* "/Users/---/dev/next-project/src/paraglide"
*/
Expand Down
13 changes: 13 additions & 0 deletions inlang/source-code/paraglide/paraglide-next/src/cli/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import path from "node:path"

/**
* One step in a CLI chain.
* Defines which types the context needs to extend and how it extends the context
Expand Down Expand Up @@ -49,3 +51,14 @@ export async function succeedOrElse<T extends Promise<unknown>, U>(
return orElse
}
}

const WINDOWS_SLASH_REGEX = /\\/g
function slash(p: string): string {
return p.replace(WINDOWS_SLASH_REGEX, "/")
}

const isWindows = typeof process !== "undefined" && process.platform === "win32"

export function normalizePath(id: string) {
return path.posix.normalize(isWindows ? slash(id) : id)
}

0 comments on commit f5524a7

Please sign in to comment.