From 0974a3ad18a3bdf8c31562b99f9b2f141493c58d Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Thu, 28 Dec 2023 19:33:37 +1100 Subject: [PATCH] Use relative paths in go.mod for replace line. --- mkdocs-website/docs/en/changelog.md | 1 + v3/internal/templates/templates.go | 25 +++++++++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/mkdocs-website/docs/en/changelog.md b/mkdocs-website/docs/en/changelog.md index 8f83d457..1d9b4fc7 100644 --- a/mkdocs-website/docs/en/changelog.md +++ b/mkdocs-website/docs/en/changelog.md @@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Set drag-n-drop for windows to working. Added by [@pylotlight](https://github.com/pylotlight) in [PR](https://github.com/wailsapp/wails/pull/3039) - Fixed bug for linux in doctor in the event user doesn't have proper drivers installed. Added by [@pylotlight](https://github.com/pylotlight) in [PR](https://github.com/wailsapp/wails/pull/3032) - Fix dpi scaling on start up (windows). Changed by @almas1992 in [PR](https://github.com/wailsapp/wails/pull/3145) +- Fix replace line in `go.mod` to use relative paths. Fixes Windows paths with spaces - @leaanthony. ### Changed diff --git a/v3/internal/templates/templates.go b/v3/internal/templates/templates.go index a44b0254..230b311c 100644 --- a/v3/internal/templates/templates.go +++ b/v3/internal/templates/templates.go @@ -201,9 +201,26 @@ func getRemoteTemplate(uri string) (template *Template, err error) { func Install(options *flags.Init) error { + var projectDir string + if options.ProjectDir == "." || options.ProjectDir == "" { + projectDir = lo.Must(os.Getwd()) + } + var err error + projectDir, err = filepath.Abs(filepath.Join(options.ProjectDir, options.ProjectName)) + if err != nil { + return err + } + + // Calculate relative path from project directory to LocalModulePath + var relativePath string + relativePath, err = filepath.Rel(projectDir, debug.LocalModulePath) + if err != nil { + return err + } + templateData := TemplateOptions{ options, - filepath.FromSlash(debug.LocalModulePath + "/"), + filepath.ToSlash(relativePath + "/"), } defer func() { @@ -211,7 +228,6 @@ func Install(options *flags.Init) error { _ = os.Remove(filepath.Join(templateData.ProjectDir, "template.json")) }() - var err error var template *Template template, err = getInternalTemplate(options.TemplateName) if err != nil { @@ -234,10 +250,7 @@ func Install(options *flags.Init) error { return fmt.Errorf("invalid template name: %s. Use -l flag to view available templates or use a valid filepath / url to a template", options.TemplateName) } - if options.ProjectDir == "." || options.ProjectDir == "" { - templateData.ProjectDir = lo.Must(os.Getwd()) - } - templateData.ProjectDir = filepath.Join(options.ProjectDir, options.ProjectName) + templateData.ProjectDir = projectDir // If project directory already exists and is not empty, error if _, err := os.Stat(templateData.ProjectDir); !os.IsNotExist(err) {