Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check dependencies when adding imports #1239

Merged
merged 9 commits into from
Apr 12, 2024
Merged

Conversation

kuhe
Copy link
Contributor

@kuhe kuhe commented Apr 11, 2024

when calling addImport, the TSWriter will either add the import or throw an error if it determines the import is a non-native package and has not been added via addDependency.

this is to prevent calls to addImport that forget to also call addDependency.

@kuhe kuhe marked this pull request as ready for review April 11, 2024 17:46
@kuhe kuhe requested review from a team as code owners April 11, 2024 17:46
@kuhe kuhe requested a review from kstich April 11, 2024 17:46
@@ -114,19 +142,54 @@ public TypeScriptWriter addIgnoredDefaultImport(String name, String from, String
*/
@Deprecated
public TypeScriptWriter addImport(String name, String as, String from) {
boolean isNodePackage = from.startsWith("node:");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should a class wrap the String input from to provide answers like boolean isNamespaced, boolean isNodeJSNativePackage, String getPackageName etc.?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That probably should go in Dependency in the long run.

Comment on lines 189 to +152
public TypeScriptWriter addImport(String name, String as, PackageContainer from) {
if (from instanceof Dependency) {
addDependency((Dependency) from);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the long run, we should move it to taking Dependency as the third parameter.

@kuhe kuhe merged commit cad7ae0 into smithy-lang:main Apr 12, 2024
7 checks passed
@kuhe kuhe deleted the fix/imports branch April 12, 2024 15:06
kuhe added a commit to kuhe/smithy-typescript that referenced this pull request May 28, 2024
* fix: check dependencies when adding imports

* avoid method overload with super type

* handle node: prefix package imports

* exempt node: prefix packages from enforced registration

* remove addImportUnchecked

* remove stray deprecation tag

* convert import logic to class

* comment grammar

* add internalapi annotation to ImportFrom
kuhe added a commit to kuhe/smithy-typescript that referenced this pull request Jun 28, 2024
* fix: check dependencies when adding imports

* avoid method overload with super type

* handle node: prefix package imports

* exempt node: prefix packages from enforced registration

* remove addImportUnchecked

* remove stray deprecation tag

* convert import logic to class

* comment grammar

* add internalapi annotation to ImportFrom
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants