|
16 | 16 | package software.amazon.smithy.typescript.codegen;
|
17 | 17 |
|
18 | 18 | import java.nio.file.Path;
|
19 |
| -import java.util.List; |
20 | 19 | import java.util.Set;
|
21 | 20 | import java.util.function.BiFunction;
|
22 | 21 | import java.util.function.UnaryOperator;
|
23 | 22 | import software.amazon.smithy.codegen.core.CodegenException;
|
24 | 23 | import software.amazon.smithy.codegen.core.Symbol;
|
25 |
| -import software.amazon.smithy.codegen.core.SymbolDependency; |
26 | 24 | import software.amazon.smithy.codegen.core.SymbolReference;
|
27 | 25 | import software.amazon.smithy.codegen.core.SymbolWriter;
|
28 | 26 | import software.amazon.smithy.model.Model;
|
@@ -144,19 +142,27 @@ public TypeScriptWriter addIgnoredDefaultImport(String name, String from, String
|
144 | 142 | */
|
145 | 143 | @Deprecated
|
146 | 144 | public TypeScriptWriter addImport(String name, String as, String from) {
|
| 145 | + boolean isNodePackage = from.startsWith("node:"); |
| 146 | + boolean isNamespacePackage = from.startsWith("@"); |
| 147 | + boolean isRelativeImport = from.startsWith("/") || from.startsWith("."); |
| 148 | + |
147 | 149 | final boolean isPackageImport =
|
148 |
| - from.startsWith("@") |
149 |
| - || (!from.startsWith("/") && !from.startsWith(".")); |
| 150 | + isNodePackage |
| 151 | + || isNamespacePackage |
| 152 | + || !isRelativeImport; |
150 | 153 |
|
151 | 154 | if (isPackageImport) {
|
152 | 155 | String[] packageNameSegments = from.split("/");
|
153 |
| - String packageName = |
154 |
| - from.startsWith("@") |
155 |
| - ? packageNameSegments[0] + "/" + packageNameSegments[1] |
156 |
| - : packageNameSegments[0]; |
157 |
| - List<SymbolDependency> dependencies = getDependencies(); |
| 156 | + String packageName; |
| 157 | + if (isNodePackage) { |
| 158 | + packageName = from.substring("node:".length(), from.indexOf('/')); |
| 159 | + } else if (isNamespacePackage) { |
| 160 | + packageName = packageNameSegments[0] + "/" + packageNameSegments[1]; |
| 161 | + } else { |
| 162 | + packageName = packageNameSegments[0]; |
| 163 | + } |
158 | 164 | if (!EXEMPT_DEPENDENCIES.contains(packageName)
|
159 |
| - && dependencies.stream().noneMatch(dep -> dep.getPackageName().equals(packageName))) { |
| 165 | + && getDependencies().stream().noneMatch(dep -> dep.getPackageName().equals(packageName))) { |
160 | 166 | throw new CodegenException(
|
161 | 167 | """
|
162 | 168 | The import %s does not correspond to a registered dependency.
|
|
0 commit comments