Skip to content

kratos cli gives wrong import path when creating app with --nomod parameter #2937

@qzwxsaedc

Description

@qzwxsaedc

What happened:

  1. create a go.mod with go mod init proj
  2. create an app named "demo" with command kratos new demo --nomod
  3. open a file whose import path needs to be replaced with a local file, such as internal/server/http.go
  4. you can see that the import path does not conform to import path rules of golang. like this:

b4d9e836c24bfc508b94fe5e6a0d91bd

What you expected to happen:

import path should be github.com/CyanPigeon/toktik/demo/api/demo/v1 and github.com/CyanPigeon/toktik/demo/internal/biz in the example previous.

How to reproduce it (as minimally and precisely as possible):

  1. create a go.mod by go mod init proj
  2. create an app named "demo" with command kratos new demo --nomod
  3. open a file whose import path needs to be replaced with a local file, such as internal/server/http.go

Anything else we need to know?:

p.Path = filepath.Join(strings.TrimPrefix(workingDir, projectRoot+"/"), p.Name)
done <- p.Add(ctx, workingDir, repoURL, branch, mod)

Project.Path was set to an absolute path before Project.Add() is called.
if err := repo.CopyToV2(ctx, to, filepath.Join(mod, p.Path), repoAddIgnores, []string{filepath.Join(p.Path, "api"), "api"}); err != nil {

Here the absolute path is incorrectly concatenated with the module name via filepath.Join(), resulting in this error.

Environment:

  • Kratos version (use kratos -v): kratos version v2.6.3
  • Go version (use go version): go version go1.20.6 windows/amd64
  • OS (e.g: cat /etc/os-release): Windows 11 22621.1992
  • Others:

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions