Repository: pmcelhaney/counterfact
Pull request #369 (2023-01-19 20:26:40)

don't import HTTPStatusCode if not needed

changeset-bot[bot]: ###  🦋  Changeset detected

Latest commit: e7e6eb7af08ee238f46f8bedf888815961d7e5aa

**The changes in this PR will be included in the next version bump.**

<details><summary>This PR includes changesets to release 1 package</summary>

  | Name        | Type  |
| ----------- | ----- |
| counterfact | Minor |

</details>

Not sure what this means? [Click here  to learn what changesets are](https://github.com/changesets/changesets/blob/master/docs/adding-a-changeset.md).

[Click here if you're a maintainer who wants to add another changeset to this PR](https://github.com/pmcelhaney/counterfact/new/fix-extrarneous-import?filename=.changeset/fluffy-tools-switch.md&value=---%0A%22counterfact%22%3A%20patch%0A---%0A%0Adon't%20import%20HTTPStatusCode%20if%20not%20needed%0A)



Patch:
diff --git a/.changeset/late-pianos-jam.md b/.changeset/late-pianos-jam.md
new file mode 100644
index 0000000..1ca18b3
--- /dev/null
+++ b/.changeset/late-pianos-jam.md
@@ -0,0 +1,5 @@
+---
+"counterfact": patch
+---
+
+don't import HTTPStatusCode if not needed
diff --git a/src/typescript-generator/response-type-coder.js b/src/typescript-generator/response-type-coder.js
index 6382adb..3aa7364 100644
--- a/src/typescript-generator/response-type-coder.js
+++ b/src/typescript-generator/response-type-coder.js
@@ -12,6 +12,8 @@ export class ResponseTypeCoder extends Coder {
   }
 
   typeForDefaultStatusCode(listedStatusCodes) {
+    this.needsHttpStatusCodeImport = true;
+
     const definedStatusCodes = listedStatusCodes.filter(
       (key) => key !== "default"
     );
@@ -101,10 +103,13 @@ export class ResponseTypeCoder extends Coder {
       "ResponseBuilderFactory",
       nodePath.join(basePath, "response-builder-factory.js")
     );
-    script.importExternalType(
-      "HttpStatusCode",
-      nodePath.join(basePath, "response-builder-factory.js")
-    );
+
+    if (this.needsHttpStatusCodeImport) {
+      script.importExternalType(
+        "HttpStatusCode",
+        nodePath.join(basePath, "response-builder-factory.js")
+      );
+    }
 
     return `ResponseBuilderFactory<${this.buildResponseObjectType(script)}>`;
   }


Test patch:
diff --git a/test/typescript-generator/__snapshots__/end-to-end.test.js.snap b/test/typescript-generator/__snapshots__/end-to-end.test.js.snap
index de8856f..58b6669 100644
--- a/test/typescript-generator/__snapshots__/end-to-end.test.js.snap
+++ b/test/typescript-generator/__snapshots__/end-to-end.test.js.snap
@@ -144,10 +144,6 @@ Map {
               "isType": true,
               "modulePath": "../response-builder-factory.js",
             },
-            "HttpStatusCode" => Object {
-              "isType": true,
-              "modulePath": "../response-builder-factory.js",
-            },
           },
           "imports": Map {
             "Context" => Object {
@@ -448,10 +444,6 @@ class Context {
               "isType": true,
               "modulePath": "../response-builder-factory.js",
             },
-            "HttpStatusCode" => Object {
-              "isType": true,
-              "modulePath": "../response-builder-factory.js",
-            },
           },
           "imports": Map {
             "Context" => Object {
@@ -756,10 +748,6 @@ class Context {
         "isType": true,
         "modulePath": "../response-builder-factory.js",
       },
-      "HttpStatusCode" => Object {
-        "isType": true,
-        "modulePath": "../response-builder-factory.js",
-      },
     },
     "imports": Map {
       "Context" => Object {
@@ -1030,10 +1018,6 @@ class Context {
               "isType": true,
               "modulePath": "../../response-builder-factory.js",
             },
-            "HttpStatusCode" => Object {
-              "isType": true,
-              "modulePath": "../../response-builder-factory.js",
-            },
           },
           "imports": Map {
             "Context" => Object {
@@ -1245,10 +1229,6 @@ class Context {
         "isType": true,
         "modulePath": "../../response-builder-factory.js",
       },
-      "HttpStatusCode" => Object {
-        "isType": true,
-        "modulePath": "../../response-builder-factory.js",
-      },
     },
     "imports": Map {
       "Context" => Object {
@@ -1477,10 +1457,6 @@ class Context {
               "isType": true,
               "modulePath": "../../response-builder-factory.js",
             },
-            "HttpStatusCode" => Object {
-              "isType": true,
-              "modulePath": "../../response-builder-factory.js",
-            },
           },
           "imports": Map {
             "Context" => Object {
@@ -1692,10 +1668,6 @@ class Context {
         "isType": true,
         "modulePath": "../../response-builder-factory.js",
       },
-      "HttpStatusCode" => Object {
-        "isType": true,
-        "modulePath": "../../response-builder-factory.js",
-      },
     },
     "imports": Map {
       "Context" => Object {
@@ -1996,10 +1968,6 @@ class Context {
               "isType": true,
               "modulePath": "../../response-builder-factory.js",
             },
-            "HttpStatusCode" => Object {
-              "isType": true,
-              "modulePath": "../../response-builder-factory.js",
-            },
           },
           "imports": Map {
             "Context" => Object {
@@ -2345,10 +2313,6 @@ class Context {
               "isType": true,
               "modulePath": "../../response-builder-factory.js",
             },
-            "HttpStatusCode" => Object {
-              "isType": true,
-              "modulePath": "../../response-builder-factory.js",
-            },
           },
           "imports": Map {
             "Context" => Object {
@@ -2694,10 +2658,6 @@ class Context {
               "isType": true,
               "modulePath": "../../response-builder-factory.js",
             },
-            "HttpStatusCode" => Object {
-              "isType": true,
-              "modulePath": "../../response-builder-factory.js",
-            },
           },
           "imports": Map {
             "Context" => Object {
@@ -3047,10 +3007,6 @@ class Context {
         "isType": true,
         "modulePath": "../../response-builder-factory.js",
       },
-      "HttpStatusCode" => Object {
-        "isType": true,
-        "modulePath": "../../response-builder-factory.js",
-      },
     },
     "imports": Map {
       "Context" => Object {
@@ -3358,10 +3314,6 @@ class Context {
               "isType": true,
               "modulePath": "../../../response-builder-factory.js",
             },
-            "HttpStatusCode" => Object {
-              "isType": true,
-              "modulePath": "../../../response-builder-factory.js",
-            },
           },
           "imports": Map {
             "Context" => Object {
@@ -3495,10 +3447,6 @@ class Context {
         "isType": true,
         "modulePath": "../../../response-builder-factory.js",
       },
-      "HttpStatusCode" => Object {
-        "isType": true,
-        "modulePath": "../../../response-builder-factory.js",
-      },
     },
     "imports": Map {
       "Context" => Object {
@@ -3648,10 +3596,6 @@ class Context {
               "isType": true,
               "modulePath": "../../response-builder-factory.js",
             },
-            "HttpStatusCode" => Object {
-              "isType": true,
-              "modulePath": "../../response-builder-factory.js",
-            },
           },
           "imports": Map {
             "Context" => Object {
@@ -3753,10 +3697,6 @@ class Context {
         "isType": true,
         "modulePath": "../../response-builder-factory.js",
       },
-      "HttpStatusCode" => Object {
-        "isType": true,
-        "modulePath": "../../response-builder-factory.js",
-      },
     },
     "imports": Map {
       "Context" => Object {
@@ -3882,10 +3822,6 @@ class Context {
               "isType": true,
               "modulePath": "../../response-builder-factory.js",
             },
-            "HttpStatusCode" => Object {
-              "isType": true,
-              "modulePath": "../../response-builder-factory.js",
-            },
           },
           "imports": Map {
             "Context" => Object {
@@ -4025,10 +3961,6 @@ class Context {
         "isType": true,
         "modulePath": "../../response-builder-factory.js",
       },
-      "HttpStatusCode" => Object {
-        "isType": true,
-        "modulePath": "../../response-builder-factory.js",
-      },
     },
     "imports": Map {
       "Context" => Object {
@@ -4237,10 +4169,6 @@ class Context {
               "isType": true,
               "modulePath": "../../../response-builder-factory.js",
             },
-            "HttpStatusCode" => Object {
-              "isType": true,
-              "modulePath": "../../../response-builder-factory.js",
-            },
           },
           "imports": Map {
             "Context" => Object {
@@ -4461,10 +4389,6 @@ class Context {
               "isType": true,
               "modulePath": "../../../response-builder-factory.js",
             },
-            "HttpStatusCode" => Object {
-              "isType": true,
-              "modulePath": "../../../response-builder-factory.js",
-            },
           },
           "imports": Map {
             "Context" => Object {
@@ -4689,10 +4613,6 @@ class Context {
         "isType": true,
         "modulePath": "../../../response-builder-factory.js",
       },
-      "HttpStatusCode" => Object {
-        "isType": true,
-        "modulePath": "../../../response-builder-factory.js",
-      },
     },
     "imports": Map {
       "Context" => Object {
@@ -4896,10 +4816,6 @@ class Context {
               "isType": true,
               "modulePath": "../response-builder-factory.js",
             },
-            "HttpStatusCode" => Object {
-              "isType": true,
-              "modulePath": "../response-builder-factory.js",
-            },
           },
           "imports": Map {
             "Context" => Object {
@@ -5038,10 +4954,6 @@ class Context {
         "isType": true,
         "modulePath": "../response-builder-factory.js",
       },
-      "HttpStatusCode" => Object {
-        "isType": true,
-        "modulePath": "../response-builder-factory.js",
-      },
     },
     "imports": Map {
       "Context" => Object {
@@ -5203,10 +5115,6 @@ class Context {
               "isType": true,
               "modulePath": "../../response-builder-factory.js",
             },
-            "HttpStatusCode" => Object {
-              "isType": true,
-              "modulePath": "../../response-builder-factory.js",
-            },
           },
           "imports": Map {
             "Context" => Object {
@@ -5353,10 +5261,6 @@ class Context {
         "isType": true,
         "modulePath": "../../response-builder-factory.js",
       },
-      "HttpStatusCode" => Object {
-        "isType": true,
-        "modulePath": "../../response-builder-factory.js",
-      },
     },
     "imports": Map {
       "Context" => Object {
@@ -5522,10 +5426,6 @@ class Context {
               "isType": true,
               "modulePath": "../../response-builder-factory.js",
             },
-            "HttpStatusCode" => Object {
-              "isType": true,
-              "modulePath": "../../response-builder-factory.js",
-            },
           },
           "imports": Map {
             "Context" => Object {
@@ -5643,10 +5543,6 @@ class Context {
         "isType": true,
         "modulePath": "../../response-builder-factory.js",
       },
-      "HttpStatusCode" => Object {
-        "isType": true,
-        "modulePath": "../../response-builder-factory.js",
-      },
     },
     "imports": Map {
       "Context" => Object {
@@ -5757,10 +5653,6 @@ class Context {
               "isType": true,
               "modulePath": "../../response-builder-factory.js",
             },
-            "HttpStatusCode" => Object {
-              "isType": true,
-              "modulePath": "../../response-builder-factory.js",
-            },
           },
           "imports": Map {
             "Context" => Object {
@@ -5856,10 +5748,6 @@ class Context {
         "isType": true,
         "modulePath": "../../response-builder-factory.js",
       },
-      "HttpStatusCode" => Object {
-        "isType": true,
-        "modulePath": "../../response-builder-factory.js",
-      },
     },
     "imports": Map {
       "Context" => Object {
@@ -6070,10 +5958,6 @@ class Context {
               "isType": true,
               "modulePath": "../../response-builder-factory.js",
             },
-            "HttpStatusCode" => Object {
-              "isType": true,
-              "modulePath": "../../response-builder-factory.js",
-            },
           },
           "imports": Map {
             "Context" => Object {
@@ -6360,10 +6244,6 @@ class Context {
               "isType": true,
               "modulePath": "../../response-builder-factory.js",
             },
-            "HttpStatusCode" => Object {
-              "isType": true,
-              "modulePath": "../../response-builder-factory.js",
-            },
           },
           "imports": Map {
             "Context" => Object {
@@ -6650,10 +6530,6 @@ class Context {
               "isType": true,
               "modulePath": "../../response-builder-factory.js",
             },
-            "HttpStatusCode" => Object {
-              "isType": true,
-              "modulePath": "../../response-builder-factory.js",
-            },
           },
           "imports": Map {
             "Context" => Object {
@@ -6944,10 +6820,6 @@ class Context {
         "isType": true,
         "modulePath": "../../response-builder-factory.js",
       },
-      "HttpStatusCode" => Object {
-        "isType": true,
-        "modulePath": "../../response-builder-factory.js",
-      },
     },
     "imports": Map {
       "Context" => Object {