Skip to content

Commit cacb4fb

Browse files
authored
New technique for resolving module name conflicts to module alias docs (#8983)
Conflicts can arise due to duplicate module names within a package graph. Module aliases themselves if they are not globally unique can introduce further conflicts. The documentation for the module aliases feature can describe a technique for the naming that can help to reduce the likelihood of further collisions by recommending the use of the package identifier as a qualifier to the alias. As other packages in the graph encounter the collision, this system can help for there to be a broader agreement on the new name, which should lessen the cases where module alias chaining is needed. Update the correct ModuleAliases.md file so that the changes will be shown in the new documentation system.
1 parent 6d0dd36 commit cacb4fb

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

Sources/PackageManagerDocs/Documentation.docc/ModuleAliasing.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ Module aliases are defined as a dictionary parameter in a target's dependencies
3333
.product(
3434
name: "Utils",
3535
package: "MyPackage",
36-
moduleAliases: ["Utils": "MyUtils"]
36+
moduleAliases: ["Utils": "MyPackageUtils"]
3737
)
3838
]
3939
)
4040
]
4141
```
4242

43-
This will rename the `Utils` module in the `MyPackage` package to the new user-defined unique name, in this case `MyUtils`; the name of the binary will be `MyUtils.swiftmodule`. No source or manifest changes are required by the dependency package.
43+
This will rename the `Utils` module in the `MyPackage` package to the new user-defined unique name, in this case `MyPackageUtils`; the name of the binary will be `MyPackageUtils.swiftmodule`. No source or manifest changes are required by the dependency package.
4444

45-
To use the aliased module, your root package needs to reference the the new name, i.e. `import MyUtils`.
45+
To use the aliased module your root package can use the new unique name, i.e. `import MyPackageUtils`, and make it clear that it is importing the utilities module from `MyPackage`.
4646

4747
Consider the following example to go over how module aliasing can be used in more detail.
4848

@@ -107,17 +107,17 @@ Package manifest `App`
107107
package: "swift-draw"),
108108
.product(name: "Utils",
109109
package: "swift-game",
110-
moduleAliases: ["Utils": "GameUtils"]),
110+
moduleAliases: ["Utils": "SwiftGameUtils"]),
111111
])
112112
]
113113
```
114114

115-
This will rename the `Utils` module in package `swift-game` as `GameUtils`; the name of the binary will be `GameUtils.swiftmodule`.
115+
This will rename the `Utils` module in package `swift-game` as `SwiftGameUtils`; the name of the binary will be `SwiftGameUtils.swiftmodule`.
116116

117-
To use the aliased module, `App` needs to reference the the new name, i.e. `import GameUtils`. Its existing `import Utils` statement will continue to reference the `Utils` module from package `swift-draw`, as expected.
117+
To use the aliased module, `App` can reference the new package-qualified name, i.e. `import SwiftGameUtils`. Its existing `import Utils` statement will continue to reference the `Utils` module from package `swift-draw`, as expected.
118118

119119
Note that the dependency product names are duplicate, i.e. both have the same name `Utils`, which is by default not allowed.
120-
However, this is allowed when module aliasing is used as long as no multiple files with the same product name are created.
120+
However, this is allowed when module aliasing is used as long as no files with the same product name are created.
121121
This means they must all be automatic library types, or at most one of them can be a static library, dylib, an executable, or any other type that creates a file or a directory with the product name.
122122

123123
###### Transitive Logging modules
@@ -138,25 +138,25 @@ Package manifest `App`
138138
package: "swift-draw"),
139139
.product(name: "Utils",
140140
package: "swift-game",
141-
moduleAliases: ["Utils": "GameUtils"]),
141+
moduleAliases: ["Utils": "SwiftGameUtils"]),
142142
// Logging module aliasing:
143143
.product(name: "Logging",
144144
package: "swift-draw"),
145145
.product(name: "Game",
146146
package: "swift-game",
147-
moduleAliases: ["Logging": "GameLogging"]),
147+
moduleAliases: ["Logging": "SwiftGameLogging"]),
148148
])
149149
]
150150
```
151151

152-
The `Logging` module from `swift-game` is renamed as `GameLogging`, and all the references to `Logging` in source files of `Game` are compiled as `GameLogging`. Similar to before, no source or manifest changes are required by the `swift-game` package.
152+
The `Logging` module from `swift-game` is renamed as `SwiftGameLogging`, and all the references to `Logging` in source files of `Game` are compiled as `SwiftGameLogging`. Similar to before, no source or manifest changes are required by the `swift-game` package.
153153

154154
If more aliases need to be defined, they can be added with a comma delimiter, per below.
155155

156156
```
157-
moduleAliases: ["Utils": "GameUtils", "Logging": "GameLogging"]),
157+
moduleAliases: ["Utils": "SwiftGameUtils", "Logging": "SwiftGameLogging"]),
158158
```
159159

160160
### Override Module Aliases
161161

162-
If module alias values defined upstream are conflicting downstream, they can be overridden by chaining; add an entry to the `moduleAliases` parameter downstream using the conflicting alias value as a key and provide a unique value.
162+
If module alias values defined upstream are conflicting downstream, they can be overridden by chaining; add an entry to the `moduleAliases` parameter downstream using the conflicting alias value as a key and provide a unique value. Since the package identifier is unique to the package, using it as the prefix for the new module alias as a convention should help to prevent more collisions since it can be a generally agreed unique name for the module.

0 commit comments

Comments
 (0)