Repository navigation
Tags
Tags
fix(cmd/gf): avoid duplicate imports when ensuring an existing path (#… …4945) Follow-up to #4929. ## What `EnsureImports` now matches imports by their path before calling `astutil.AddNamedImport`. `astutil.AddNamedImport` matches on `(name, path)`, and an unnamed import has an empty name. A controller generated by an older gf version imports the api package without an alias: ```go import "project/api/hello/v1" ``` When `gf gen pb` regenerates it with a new RPC method, `EnsureImports` passes `{Name: "v1", Path: ...}`, does not recognize the existing unnamed import, and adds a second import of the same path: ```go import ( "project/api/hello/v1" v1 "project/api/hello/v1" ) ``` The generated controller no longer compiles. ## How - Check the existing paths first; an already imported path is never imported again. - An existing unnamed import satisfies the spec, which covers controllers generated by older versions. - Blank/dot imports and explicit aliases that differ from the required one return an error instead of writing duplicate imports. ## Compatibility Freshly generated files are unchanged. Existing controllers no longer get a duplicate import. Conflicting existing imports now fail with a clear error instead of producing code that does not compile. This is an internal utility only; no public API change. ## Tests - `Test_EnsureImports_ExistingPath`: unnamed existing import + requested alias, same alias, alias conflict, blank conflict, redundant alias. - `TestGenPb_ControllerImports`: generate a controller in the standard `hello/v1` layout, strip the api alias to simulate an older controller, regenerate, and assert the api path appears once. - `go test ./internal/utility/utils/ ./internal/cmd/gendao/` and `TestGenPb_ControllerImports` pass.
fix(cmd/gf): avoid duplicate imports when ensuring an existing path (#… …4945) Follow-up to #4929. ## What `EnsureImports` now matches imports by their path before calling `astutil.AddNamedImport`. `astutil.AddNamedImport` matches on `(name, path)`, and an unnamed import has an empty name. A controller generated by an older gf version imports the api package without an alias: ```go import "project/api/hello/v1" ``` When `gf gen pb` regenerates it with a new RPC method, `EnsureImports` passes `{Name: "v1", Path: ...}`, does not recognize the existing unnamed import, and adds a second import of the same path: ```go import ( "project/api/hello/v1" v1 "project/api/hello/v1" ) ``` The generated controller no longer compiles. ## How - Check the existing paths first; an already imported path is never imported again. - An existing unnamed import satisfies the spec, which covers controllers generated by older versions. - Blank/dot imports and explicit aliases that differ from the required one return an error instead of writing duplicate imports. ## Compatibility Freshly generated files are unchanged. Existing controllers no longer get a duplicate import. Conflicting existing imports now fail with a clear error instead of producing code that does not compile. This is an internal utility only; no public API change. ## Tests - `Test_EnsureImports_ExistingPath`: unnamed existing import + requested alias, same alias, alias conflict, blank conflict, redundant alias. - `TestGenPb_ControllerImports`: generate a controller in the standard `hello/v1` layout, strip the api alias to simulate an older controller, regenerate, and assert the api path appears once. - `go test ./internal/utility/utils/ ./internal/cmd/gendao/` and `TestGenPb_ControllerImports` pass.
fix(cmd/gf): avoid duplicate imports when ensuring an existing path (#… …4945) Follow-up to #4929. ## What `EnsureImports` now matches imports by their path before calling `astutil.AddNamedImport`. `astutil.AddNamedImport` matches on `(name, path)`, and an unnamed import has an empty name. A controller generated by an older gf version imports the api package without an alias: ```go import "project/api/hello/v1" ``` When `gf gen pb` regenerates it with a new RPC method, `EnsureImports` passes `{Name: "v1", Path: ...}`, does not recognize the existing unnamed import, and adds a second import of the same path: ```go import ( "project/api/hello/v1" v1 "project/api/hello/v1" ) ``` The generated controller no longer compiles. ## How - Check the existing paths first; an already imported path is never imported again. - An existing unnamed import satisfies the spec, which covers controllers generated by older versions. - Blank/dot imports and explicit aliases that differ from the required one return an error instead of writing duplicate imports. ## Compatibility Freshly generated files are unchanged. Existing controllers no longer get a duplicate import. Conflicting existing imports now fail with a clear error instead of producing code that does not compile. This is an internal utility only; no public API change. ## Tests - `Test_EnsureImports_ExistingPath`: unnamed existing import + requested alias, same alias, alias conflict, blank conflict, redundant alias. - `TestGenPb_ControllerImports`: generate a controller in the standard `hello/v1` layout, strip the api alias to simulate an older controller, regenerate, and assert the api path appears once. - `go test ./internal/utility/utils/ ./internal/cmd/gendao/` and `TestGenPb_ControllerImports` pass.
fix(cmd/gf): avoid duplicate imports when ensuring an existing path (#… …4945) Follow-up to #4929. ## What `EnsureImports` now matches imports by their path before calling `astutil.AddNamedImport`. `astutil.AddNamedImport` matches on `(name, path)`, and an unnamed import has an empty name. A controller generated by an older gf version imports the api package without an alias: ```go import "project/api/hello/v1" ``` When `gf gen pb` regenerates it with a new RPC method, `EnsureImports` passes `{Name: "v1", Path: ...}`, does not recognize the existing unnamed import, and adds a second import of the same path: ```go import ( "project/api/hello/v1" v1 "project/api/hello/v1" ) ``` The generated controller no longer compiles. ## How - Check the existing paths first; an already imported path is never imported again. - An existing unnamed import satisfies the spec, which covers controllers generated by older versions. - Blank/dot imports and explicit aliases that differ from the required one return an error instead of writing duplicate imports. ## Compatibility Freshly generated files are unchanged. Existing controllers no longer get a duplicate import. Conflicting existing imports now fail with a clear error instead of producing code that does not compile. This is an internal utility only; no public API change. ## Tests - `Test_EnsureImports_ExistingPath`: unnamed existing import + requested alias, same alias, alias conflict, blank conflict, redundant alias. - `TestGenPb_ControllerImports`: generate a controller in the standard `hello/v1` layout, strip the api alias to simulate an older controller, regenerate, and assert the api path appears once. - `go test ./internal/utility/utils/ ./internal/cmd/gendao/` and `TestGenPb_ControllerImports` pass.
fix(cmd/gf): avoid duplicate imports when ensuring an existing path (#… …4945) Follow-up to #4929. ## What `EnsureImports` now matches imports by their path before calling `astutil.AddNamedImport`. `astutil.AddNamedImport` matches on `(name, path)`, and an unnamed import has an empty name. A controller generated by an older gf version imports the api package without an alias: ```go import "project/api/hello/v1" ``` When `gf gen pb` regenerates it with a new RPC method, `EnsureImports` passes `{Name: "v1", Path: ...}`, does not recognize the existing unnamed import, and adds a second import of the same path: ```go import ( "project/api/hello/v1" v1 "project/api/hello/v1" ) ``` The generated controller no longer compiles. ## How - Check the existing paths first; an already imported path is never imported again. - An existing unnamed import satisfies the spec, which covers controllers generated by older versions. - Blank/dot imports and explicit aliases that differ from the required one return an error instead of writing duplicate imports. ## Compatibility Freshly generated files are unchanged. Existing controllers no longer get a duplicate import. Conflicting existing imports now fail with a clear error instead of producing code that does not compile. This is an internal utility only; no public API change. ## Tests - `Test_EnsureImports_ExistingPath`: unnamed existing import + requested alias, same alias, alias conflict, blank conflict, redundant alias. - `TestGenPb_ControllerImports`: generate a controller in the standard `hello/v1` layout, strip the api alias to simulate an older controller, regenerate, and assert the api path appears once. - `go test ./internal/utility/utils/ ./internal/cmd/gendao/` and `TestGenPb_ControllerImports` pass.
fix(cmd/gf): avoid duplicate imports when ensuring an existing path (#… …4945) Follow-up to #4929. ## What `EnsureImports` now matches imports by their path before calling `astutil.AddNamedImport`. `astutil.AddNamedImport` matches on `(name, path)`, and an unnamed import has an empty name. A controller generated by an older gf version imports the api package without an alias: ```go import "project/api/hello/v1" ``` When `gf gen pb` regenerates it with a new RPC method, `EnsureImports` passes `{Name: "v1", Path: ...}`, does not recognize the existing unnamed import, and adds a second import of the same path: ```go import ( "project/api/hello/v1" v1 "project/api/hello/v1" ) ``` The generated controller no longer compiles. ## How - Check the existing paths first; an already imported path is never imported again. - An existing unnamed import satisfies the spec, which covers controllers generated by older versions. - Blank/dot imports and explicit aliases that differ from the required one return an error instead of writing duplicate imports. ## Compatibility Freshly generated files are unchanged. Existing controllers no longer get a duplicate import. Conflicting existing imports now fail with a clear error instead of producing code that does not compile. This is an internal utility only; no public API change. ## Tests - `Test_EnsureImports_ExistingPath`: unnamed existing import + requested alias, same alias, alias conflict, blank conflict, redundant alias. - `TestGenPb_ControllerImports`: generate a controller in the standard `hello/v1` layout, strip the api alias to simulate an older controller, regenerate, and assert the api path appears once. - `go test ./internal/utility/utils/ ./internal/cmd/gendao/` and `TestGenPb_ControllerImports` pass.
fix(cmd/gf): avoid duplicate imports when ensuring an existing path (#… …4945) Follow-up to #4929. ## What `EnsureImports` now matches imports by their path before calling `astutil.AddNamedImport`. `astutil.AddNamedImport` matches on `(name, path)`, and an unnamed import has an empty name. A controller generated by an older gf version imports the api package without an alias: ```go import "project/api/hello/v1" ``` When `gf gen pb` regenerates it with a new RPC method, `EnsureImports` passes `{Name: "v1", Path: ...}`, does not recognize the existing unnamed import, and adds a second import of the same path: ```go import ( "project/api/hello/v1" v1 "project/api/hello/v1" ) ``` The generated controller no longer compiles. ## How - Check the existing paths first; an already imported path is never imported again. - An existing unnamed import satisfies the spec, which covers controllers generated by older versions. - Blank/dot imports and explicit aliases that differ from the required one return an error instead of writing duplicate imports. ## Compatibility Freshly generated files are unchanged. Existing controllers no longer get a duplicate import. Conflicting existing imports now fail with a clear error instead of producing code that does not compile. This is an internal utility only; no public API change. ## Tests - `Test_EnsureImports_ExistingPath`: unnamed existing import + requested alias, same alias, alias conflict, blank conflict, redundant alias. - `TestGenPb_ControllerImports`: generate a controller in the standard `hello/v1` layout, strip the api alias to simulate an older controller, regenerate, and assert the api path appears once. - `go test ./internal/utility/utils/ ./internal/cmd/gendao/` and `TestGenPb_ControllerImports` pass.
fix(cmd/gf): avoid duplicate imports when ensuring an existing path (#… …4945) Follow-up to #4929. ## What `EnsureImports` now matches imports by their path before calling `astutil.AddNamedImport`. `astutil.AddNamedImport` matches on `(name, path)`, and an unnamed import has an empty name. A controller generated by an older gf version imports the api package without an alias: ```go import "project/api/hello/v1" ``` When `gf gen pb` regenerates it with a new RPC method, `EnsureImports` passes `{Name: "v1", Path: ...}`, does not recognize the existing unnamed import, and adds a second import of the same path: ```go import ( "project/api/hello/v1" v1 "project/api/hello/v1" ) ``` The generated controller no longer compiles. ## How - Check the existing paths first; an already imported path is never imported again. - An existing unnamed import satisfies the spec, which covers controllers generated by older versions. - Blank/dot imports and explicit aliases that differ from the required one return an error instead of writing duplicate imports. ## Compatibility Freshly generated files are unchanged. Existing controllers no longer get a duplicate import. Conflicting existing imports now fail with a clear error instead of producing code that does not compile. This is an internal utility only; no public API change. ## Tests - `Test_EnsureImports_ExistingPath`: unnamed existing import + requested alias, same alias, alias conflict, blank conflict, redundant alias. - `TestGenPb_ControllerImports`: generate a controller in the standard `hello/v1` layout, strip the api alias to simulate an older controller, regenerate, and assert the api path appears once. - `go test ./internal/utility/utils/ ./internal/cmd/gendao/` and `TestGenPb_ControllerImports` pass.
fix(cmd/gf): avoid duplicate imports when ensuring an existing path (#… …4945) Follow-up to #4929. ## What `EnsureImports` now matches imports by their path before calling `astutil.AddNamedImport`. `astutil.AddNamedImport` matches on `(name, path)`, and an unnamed import has an empty name. A controller generated by an older gf version imports the api package without an alias: ```go import "project/api/hello/v1" ``` When `gf gen pb` regenerates it with a new RPC method, `EnsureImports` passes `{Name: "v1", Path: ...}`, does not recognize the existing unnamed import, and adds a second import of the same path: ```go import ( "project/api/hello/v1" v1 "project/api/hello/v1" ) ``` The generated controller no longer compiles. ## How - Check the existing paths first; an already imported path is never imported again. - An existing unnamed import satisfies the spec, which covers controllers generated by older versions. - Blank/dot imports and explicit aliases that differ from the required one return an error instead of writing duplicate imports. ## Compatibility Freshly generated files are unchanged. Existing controllers no longer get a duplicate import. Conflicting existing imports now fail with a clear error instead of producing code that does not compile. This is an internal utility only; no public API change. ## Tests - `Test_EnsureImports_ExistingPath`: unnamed existing import + requested alias, same alias, alias conflict, blank conflict, redundant alias. - `TestGenPb_ControllerImports`: generate a controller in the standard `hello/v1` layout, strip the api alias to simulate an older controller, regenerate, and assert the api path appears once. - `go test ./internal/utility/utils/ ./internal/cmd/gendao/` and `TestGenPb_ControllerImports` pass.
PreviousNext