Skip to content

Commit

Permalink
Merge branch 'main' into fix-duplicate-context-imports
Browse files Browse the repository at this point in the history
  • Loading branch information
pmcelhaney committed Jan 19, 2023
2 parents b2bf1db + 63b095b commit 91645db
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 132 deletions.
5 changes: 5 additions & 0 deletions .changeset/late-pianos-jam.md
@@ -0,0 +1,5 @@
---
"counterfact": patch
---

don't import HTTPStatusCode if not needed
13 changes: 9 additions & 4 deletions src/typescript-generator/response-type-coder.js
Expand Up @@ -12,6 +12,8 @@ export class ResponseTypeCoder extends Coder {
}

typeForDefaultStatusCode(listedStatusCodes) {
this.needsHttpStatusCodeImport = true;

const definedStatusCodes = listedStatusCodes.filter(
(key) => key !== "default"
);
Expand Down Expand Up @@ -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)}>`;
}
Expand Down
128 changes: 0 additions & 128 deletions test/typescript-generator/__snapshots__/end-to-end.test.js.snap
Expand Up @@ -143,10 +143,6 @@ Map {
"isType": true,
"modulePath": "../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -402,10 +398,6 @@ class Context {
"isType": true,
"modulePath": "../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -665,10 +657,6 @@ class Context {
"isType": true,
"modulePath": "../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -895,10 +883,6 @@ class Context {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -1110,10 +1094,6 @@ class Context {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -1342,10 +1322,6 @@ class Context {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -1557,10 +1533,6 @@ class Context {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -1859,10 +1831,6 @@ class Context {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -2114,10 +2082,6 @@ class Context {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -2369,10 +2333,6 @@ class Context {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -2628,10 +2588,6 @@ class Context {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -2847,10 +2803,6 @@ class Context {
"isType": true,
"modulePath": "../../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -2984,10 +2936,6 @@ class Context {
"isType": true,
"modulePath": "../../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -3137,10 +3085,6 @@ class Context {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -3242,10 +3186,6 @@ class Context {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -3371,10 +3311,6 @@ class Context {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -3514,10 +3450,6 @@ class Context {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -3725,10 +3657,6 @@ class Context {
"isType": true,
"modulePath": "../../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -3902,10 +3830,6 @@ class Context {
"isType": true,
"modulePath": "../../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -4083,10 +4007,6 @@ class Context {
"isType": true,
"modulePath": "../../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -4244,10 +4164,6 @@ class Context {
"isType": true,
"modulePath": "../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -4386,10 +4302,6 @@ class Context {
"isType": true,
"modulePath": "../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -4551,10 +4463,6 @@ class Context {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -4701,10 +4609,6 @@ class Context {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -4870,10 +4774,6 @@ class Context {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -4991,10 +4891,6 @@ class Context {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -5105,10 +5001,6 @@ class Context {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -5204,10 +5096,6 @@ class Context {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -5416,10 +5304,6 @@ class Context {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -5612,10 +5496,6 @@ class Context {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -5808,10 +5688,6 @@ class Context {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -6008,10 +5884,6 @@ class Context {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down

0 comments on commit 91645db

Please sign in to comment.