@@ -51,8 +51,11 @@ type Pkg struct {
5151}
5252
5353// NewPkg loads the package in the specified directory.
54- // It's required there is only one package in the directory.
55- func NewPkg (dir , modulePath string ) (* Pkg , error ) {
54+ //
55+ // - dir is the directory containing the package
56+ // - modulePath is the import path of the module containing the package
57+ // - moduleRoot is the root directory of the module on disk (used to compute the package's relative name e.g. "azcore/log")
58+ func NewPkg (dir , modulePath , moduleRoot string ) (* Pkg , error ) {
5659 pk := & Pkg {
5760 modulePath : modulePath ,
5861 c : newContent (),
@@ -61,12 +64,8 @@ func NewPkg(dir, modulePath string) (*Pkg, error) {
6164 }
6265 modulePathWithoutVersion := strings .TrimSuffix (versionReg .ReplaceAllString (modulePath , "/" ), "/" )
6366 moduleName := filepath .Base (modulePathWithoutVersion )
64- if _ , after , found := strings .Cut (dir , moduleName ); found {
65- pk .relName = moduleName
66- if after != "" && after [0 ] != '@' {
67- pk .relName += after
68- }
69- pk .relName = strings .ReplaceAll (pk .relName , "\\ " , "/" )
67+ if _ , after , found := strings .Cut (dir , moduleRoot ); found {
68+ pk .relName = strings .ReplaceAll (moduleName + after , "\\ " , "/" )
7069 } else {
7170 return nil , errors .New (dir + " isn't part of module " + moduleName )
7271 }
0 commit comments