Repository: pmcelhaney/counterfact
Pull request #342 (2022-12-13 00:10:54)

ts node fix
- use esbuild loader instead of adding .mjs files to the drive
- ts-node via loader
- fix hashbang
- okay, I give up, you have to have ts-node installed globally


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

Latest commit: 45f32c7e6f139f09c63593921f7b8f70678ca828

**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/ts-node-fix?filename=.changeset/purple-socks-tie.md&value=---%0A%22counterfact%22%3A%20patch%0A---%0A%0Ats%20node%20fix%0A)



Patch:
diff --git a/.changeset/empty-jars-change.md b/.changeset/empty-jars-change.md
new file mode 100644
index 0000000..cfd8b4d
--- /dev/null
+++ b/.changeset/empty-jars-change.md
@@ -0,0 +1,5 @@
+---
+"counterfact": minor
+---
+
+requires ts-node to be installed globally (for now)
diff --git a/bin/counterfact.js b/bin/counterfact.js
index 5751b89..9881f8f 100755
--- a/bin/counterfact.js
+++ b/bin/counterfact.js
@@ -1,5 +1,6 @@
-#!/usr/bin/env node --experimental-loader ts-node/esm
+#!/usr/bin/env ts-node --esm --transpileOnly
 
+// eslint-disable-next-line node/shebang
 import nodePath from "node:path";
 import repl from "node:repl";
 
diff --git a/docs/quick-start.md b/docs/quick-start.md
index 47d6200..70dc336 100644
--- a/docs/quick-start.md
+++ b/docs/quick-start.md
@@ -3,6 +3,7 @@
 Copy the following command into your terminal. The only prerequisite is Node 16+.
 
 ```sh copy
+npm i -g ts-node
 npx counterfact@latest https://petstore3.swagger.io/api/v3/openapi.json api --open
 ```
 
diff --git a/docs/usage.md b/docs/usage.md
index 39c201e..7522a59 100644
--- a/docs/usage.md
+++ b/docs/usage.md
@@ -16,6 +16,7 @@ Counterfact is two complimentary tools in one:
 The easiest way to start is to copy and paste this command into your terminal.
 
 ```sh copy
+npm i -g ts-node
 npx counterfact@latest https://petstore3.swagger.io/api/v3/openapi.json api --open
 ```
 
diff --git a/package.json b/package.json
index e6813ac..4406156 100644
--- a/package.json
+++ b/package.json
@@ -33,7 +33,7 @@
     "go:petstore": "yarn counterfact https://petstore3.swagger.io/api/v3/openapi.json out",
     "go:petstore2": "yarn counterfact  https://petstore.swagger.io/v2/swagger.json out",
     "go:example": "yarn counterfact ./openapi-example.yaml out --open",
-    "counterfact": "node --experimental-loader ts-node/esm ./bin/counterfact.js"
+    "counterfact": "ts-node --esm --transpileOnly ./bin/counterfact.js"
   },
   "devDependencies": {
     "@changesets/cli": "2.25.2",
diff --git a/src/typescript-generator/context-coder.js b/src/typescript-generator/context-coder.js
index 5726d76..65bfcbd 100644
--- a/src/typescript-generator/context-coder.js
+++ b/src/typescript-generator/context-coder.js
@@ -43,7 +43,7 @@ class Context {
 
     script.repository.get(parentPath).exportDefault(this);
 
-    return { raw: 'export { default } from "../$.context.mjs"' };
+    return { raw: 'export { default } from "../$.context.js"' };
   }
 
   modulePath() {
diff --git a/tsconfig.json b/tsconfig.json
index c050da3..370eb85 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -6,8 +6,5 @@
     "strictNullChecks": true,
     "allowSyntheticDefaultImports": true
   },
-  "include": ["src", "demo-ts", "templates"],
-  "ts-node": {
-    "esm": true
-  }
+  "include": ["src", "demo-ts", "templates"]
 }


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 8f70119..52521c6 100644
--- a/test/typescript-generator/__snapshots__/end-to-end.test.js.snap
+++ b/test/typescript-generator/__snapshots__/end-to-end.test.js.snap
@@ -1061,7 +1061,7 @@ class Context {
 }
 ",
                     "code": Object {
-                      "raw": "export { default } from \\"../$.context.mjs\\"",
+                      "raw": "export { default } from \\"../$.context.js\\"",
                     },
                     "done": true,
                     "id": "ContextCoder@petstore.yaml#/paths/~1pet~1findByStatus/get",
@@ -1276,7 +1276,7 @@ class Context {
 }
 ",
               "code": Object {
-                "raw": "export { default } from \\"../$.context.mjs\\"",
+                "raw": "export { default } from \\"../$.context.js\\"",
               },
               "done": true,
               "id": "ContextCoder@petstore.yaml#/paths/~1pet~1findByStatus/get",
@@ -1508,7 +1508,7 @@ class Context {
 }
 ",
                     "code": Object {
-                      "raw": "export { default } from \\"../$.context.mjs\\"",
+                      "raw": "export { default } from \\"../$.context.js\\"",
                     },
                     "done": true,
                     "id": "ContextCoder@petstore.yaml#/paths/~1pet~1findByStatus/get",
@@ -1723,7 +1723,7 @@ class Context {
 }
 ",
               "code": Object {
-                "raw": "export { default } from \\"../$.context.mjs\\"",
+                "raw": "export { default } from \\"../$.context.js\\"",
               },
               "done": true,
               "id": "ContextCoder@petstore.yaml#/paths/~1pet~1findByStatus/get",
@@ -2027,7 +2027,7 @@ class Context {
 }
 ",
                     "code": Object {
-                      "raw": "export { default } from \\"../$.context.mjs\\"",
+                      "raw": "export { default } from \\"../$.context.js\\"",
                     },
                     "done": true,
                     "id": "ContextCoder@petstore.yaml#/paths/~1pet~1findByStatus/get",
@@ -2169,7 +2169,7 @@ class Context {
 }
 ",
                     "code": Object {
-                      "raw": "export { default } from \\"../$.context.mjs\\"",
+                      "raw": "export { default } from \\"../$.context.js\\"",
                     },
                     "done": true,
                     "id": "ContextCoder@petstore.yaml#/paths/~1pet~1findByStatus/get",
@@ -2215,7 +2215,7 @@ class Context {
 }
 ",
                     "code": Object {
-                      "raw": "export { default } from \\"../$.context.mjs\\"",
+                      "raw": "export { default } from \\"../$.context.js\\"",
                     },
                     "done": true,
                     "id": "ContextCoder@petstore.yaml#/paths/~1pet~1findByStatus/get",
@@ -2376,7 +2376,7 @@ class Context {
 }
 ",
                     "code": Object {
-                      "raw": "export { default } from \\"../$.context.mjs\\"",
+                      "raw": "export { default } from \\"../$.context.js\\"",
                     },
                     "done": true,
                     "id": "ContextCoder@petstore.yaml#/paths/~1pet~1findByStatus/get",
@@ -2518,7 +2518,7 @@ class Context {
 }
 ",
                     "code": Object {
-                      "raw": "export { default } from \\"../$.context.mjs\\"",
+                      "raw": "export { default } from \\"../$.context.js\\"",
                     },
                     "done": true,
                     "id": "ContextCoder@petstore.yaml#/paths/~1pet~1findByStatus/get",
@@ -2564,7 +2564,7 @@ class Context {
 }
 ",
                     "code": Object {
-                      "raw": "export { default } from \\"../$.context.mjs\\"",
+                      "raw": "export { default } from \\"../$.context.js\\"",
                     },
                     "done": true,
                     "id": "ContextCoder@petstore.yaml#/paths/~1pet~1findByStatus/get",
@@ -2725,7 +2725,7 @@ class Context {
 }
 ",
                     "code": Object {
-                      "raw": "export { default } from \\"../$.context.mjs\\"",
+                      "raw": "export { default } from \\"../$.context.js\\"",
                     },
                     "done": true,
                     "id": "ContextCoder@petstore.yaml#/paths/~1pet~1findByStatus/get",
@@ -2867,7 +2867,7 @@ class Context {
 }
 ",
                     "code": Object {
-                      "raw": "export { default } from \\"../$.context.mjs\\"",
+                      "raw": "export { default } from \\"../$.context.js\\"",
                     },
                     "done": true,
                     "id": "ContextCoder@petstore.yaml#/paths/~1pet~1findByStatus/get",
@@ -2913,7 +2913,7 @@ class Context {
 }
 ",
                     "code": Object {
-                      "raw": "export { default } from \\"../$.context.mjs\\"",
+                      "raw": "export { default } from \\"../$.context.js\\"",
                     },
                     "done": true,
                     "id": "ContextCoder@petstore.yaml#/paths/~1pet~1findByStatus/get",
@@ -3078,7 +3078,7 @@ class Context {
 }
 ",
               "code": Object {
-                "raw": "export { default } from \\"../$.context.mjs\\"",
+                "raw": "export { default } from \\"../$.context.js\\"",
               },
               "done": true,
               "id": "ContextCoder@petstore.yaml#/paths/~1pet~1findByStatus/get",
@@ -3220,7 +3220,7 @@ class Context {
 }
 ",
               "code": Object {
-                "raw": "export { default } from \\"../$.context.mjs\\"",
+                "raw": "export { default } from \\"../$.context.js\\"",
               },
               "done": true,
               "id": "ContextCoder@petstore.yaml#/paths/~1pet~1findByStatus/get",
@@ -3266,7 +3266,7 @@ class Context {
 }
 ",
               "code": Object {
-                "raw": "export { default } from \\"../$.context.mjs\\"",
+                "raw": "export { default } from \\"../$.context.js\\"",
               },
               "done": true,
               "id": "ContextCoder@petstore.yaml#/paths/~1pet~1findByStatus/get",
@@ -3389,7 +3389,7 @@ class Context {
 }
 ",
                     "code": Object {
-                      "raw": "export { default } from \\"../$.context.mjs\\"",
+                      "raw": "export { default } from \\"../$.context.js\\"",
                     },
                     "done": true,
                     "id": "ContextCoder@petstore.yaml#/paths/~1pet~1{petId}~1uploadImage/post",
@@ -3526,7 +3526,7 @@ class Context {
 }
 ",
               "code": Object {
-                "raw": "export { default } from \\"../$.context.mjs\\"",
+                "raw": "export { default } from \\"../$.context.js\\"",
               },
               "done": true,
               "id": "ContextCoder@petstore.yaml#/paths/~1pet~1{petId}~1uploadImage/post",
@@ -3679,7 +3679,7 @@ class Context {
 }
 ",
                     "code": Object {
-                      "raw": "export { default } from \\"../$.context.mjs\\"",
+                      "raw": "export { default } from \\"../$.context.js\\"",
                     },
                     "done": true,
                     "id": "ContextCoder@petstore.yaml#/paths/~1store~1inventory/get",
@@ -3784,7 +3784,7 @@ class Context {
 }
 ",
               "code": Object {
-                "raw": "export { default } from \\"../$.context.mjs\\"",
+                "raw": "export { default } from \\"../$.context.js\\"",
               },
               "done": true,
               "id": "ContextCoder@petstore.yaml#/paths/~1store~1inventory/get",
@@ -3913,7 +3913,7 @@ class Context {
 }
 ",
                     "code": Object {
-                      "raw": "export { default } from \\"../$.context.mjs\\"",
+                      "raw": "export { default } from \\"../$.context.js\\"",
                     },
                     "done": true,
                     "id": "ContextCoder@petstore.yaml#/paths/~1store~1inventory/get",
@@ -4056,7 +4056,7 @@ class Context {
 }
 ",
               "code": Object {
-                "raw": "export { default } from \\"../$.context.mjs\\"",
+                "raw": "export { default } from \\"../$.context.js\\"",
               },
               "done": true,
               "id": "ContextCoder@petstore.yaml#/paths/~1store~1inventory/get",
@@ -4268,7 +4268,7 @@ class Context {
 }
 ",
                     "code": Object {
-                      "raw": "export { default } from \\"../$.context.mjs\\"",
+                      "raw": "export { default } from \\"../$.context.js\\"",
                     },
                     "done": true,
                     "id": "ContextCoder@petstore.yaml#/paths/~1store~1order~1{orderId}/get",
@@ -4345,7 +4345,7 @@ class Context {
 }
 ",
                     "code": Object {
-                      "raw": "export { default } from \\"../$.context.mjs\\"",
+                      "raw": "export { default } from \\"../$.context.js\\"",
                     },
                     "done": true,
                     "id": "ContextCoder@petstore.yaml#/paths/~1store~1order~1{orderId}/get",
@@ -4492,7 +4492,7 @@ class Context {
 }
 ",
                     "code": Object {
-                      "raw": "export { default } from \\"../$.context.mjs\\"",
+                      "raw": "export { default } from \\"../$.context.js\\"",
                     },
                     "done": true,
                     "id": "ContextCoder@petstore.yaml#/paths/~1store~1order~1{orderId}/get",
@@ -4569,7 +4569,7 @@ class Context {
 }
 ",
                     "code": Object {
-                      "raw": "export { default } from \\"../$.context.mjs\\"",
+                      "raw": "export { default } from \\"../$.context.js\\"",
                     },
                     "done": true,
                     "id": "ContextCoder@petstore.yaml#/paths/~1store~1order~1{orderId}/get",
@@ -4720,7 +4720,7 @@ class Context {
 }
 ",
               "code": Object {
-                "raw": "export { default } from \\"../$.context.mjs\\"",
+                "raw": "export { default } from \\"../$.context.js\\"",
               },
               "done": true,
               "id": "ContextCoder@petstore.yaml#/paths/~1store~1order~1{orderId}/get",
@@ -4797,7 +4797,7 @@ class Context {
 }
 ",
               "code": Object {
-                "raw": "export { default } from \\"../$.context.mjs\\"",
+                "raw": "export { default } from \\"../$.context.js\\"",
               },
               "done": true,
               "id": "ContextCoder@petstore.yaml#/paths/~1store~1order~1{orderId}/get",
@@ -5234,7 +5234,7 @@ class Context {
 }
 ",
                     "code": Object {
-                      "raw": "export { default } from \\"../$.context.mjs\\"",
+                      "raw": "export { default } from \\"../$.context.js\\"",
                     },
                     "done": true,
                     "id": "ContextCoder@petstore.yaml#/paths/~1user~1createWithList/post",
@@ -5384,7 +5384,7 @@ class Context {
 }
 ",
               "code": Object {
-                "raw": "export { default } from \\"../$.context.mjs\\"",
+                "raw": "export { default } from \\"../$.context.js\\"",
               },
               "done": true,
               "id": "ContextCoder@petstore.yaml#/paths/~1user~1createWithList/post",
@@ -5553,7 +5553,7 @@ class Context {
 }
 ",
                     "code": Object {
-                      "raw": "export { default } from \\"../$.context.mjs\\"",
+                      "raw": "export { default } from \\"../$.context.js\\"",
                     },
                     "done": true,
                     "id": "ContextCoder@petstore.yaml#/paths/~1user~1createWithList/post",
@@ -5674,7 +5674,7 @@ class Context {
 }
 ",
               "code": Object {
-                "raw": "export { default } from \\"../$.context.mjs\\"",
+                "raw": "export { default } from \\"../$.context.js\\"",
               },
               "done": true,
               "id": "ContextCoder@petstore.yaml#/paths/~1user~1createWithList/post",
@@ -5788,7 +5788,7 @@ class Context {
 }
 ",
                     "code": Object {
-                      "raw": "export { default } from \\"../$.context.mjs\\"",
+                      "raw": "export { default } from \\"../$.context.js\\"",
                     },
                     "done": true,
                     "id": "ContextCoder@petstore.yaml#/paths/~1user~1createWithList/post",
@@ -5887,7 +5887,7 @@ class Context {
 }
 ",
               "code": Object {
-                "raw": "export { default } from \\"../$.context.mjs\\"",
+                "raw": "export { default } from \\"../$.context.js\\"",
               },
               "done": true,
               "id": "ContextCoder@petstore.yaml#/paths/~1user~1createWithList/post",
@@ -6101,7 +6101,7 @@ class Context {
 }
 ",
                     "code": Object {
-                      "raw": "export { default } from \\"../$.context.mjs\\"",
+                      "raw": "export { default } from \\"../$.context.js\\"",
                     },
                     "done": true,
                     "id": "ContextCoder@petstore.yaml#/paths/~1user~1createWithList/post",
@@ -6178,7 +6178,7 @@ class Context {
 }
 ",
                     "code": Object {
-                      "raw": "export { default } from \\"../$.context.mjs\\"",
+                      "raw": "export { default } from \\"../$.context.js\\"",
                     },
                     "done": true,
                     "id": "ContextCoder@petstore.yaml#/paths/~1user~1createWithList/post",
@@ -6224,7 +6224,7 @@ class Context {
 }
 ",
                     "code": Object {
-                      "raw": "export { default } from \\"../$.context.mjs\\"",
+                      "raw": "export { default } from \\"../$.context.js\\"",
                     },
                     "done": true,
                     "id": "ContextCoder@petstore.yaml#/paths/~1user~1createWithList/post",
@@ -6391,7 +6391,7 @@ class Context {
 }
 ",
                     "code": Object {
-                      "raw": "export { default } from \\"../$.context.mjs\\"",
+                      "raw": "export { default } from \\"../$.context.js\\"",
                     },
                     "done": true,
                     "id": "ContextCoder@petstore.yaml#/paths/~1user~1createWithList/post",
@@ -6468,7 +6468,7 @@ class Context {
 }
 ",
                     "code": Object {
-                      "raw": "export { default } from \\"../$.context.mjs\\"",
+                      "raw": "export { default } from \\"../$.context.js\\"",
                     },
                     "done": true,
                     "id": "ContextCoder@petstore.yaml#/paths/~1user~1createWithList/post",
@@ -6514,7 +6514,7 @@ class Context {
 }
 ",
                     "code": Object {
-                      "raw": "export { default } from \\"../$.context.mjs\\"",
+                      "raw": "export { default } from \\"../$.context.js\\"",
                     },
                     "done": true,
                     "id": "ContextCoder@petstore.yaml#/paths/~1user~1createWithList/post",
@@ -6681,7 +6681,7 @@ class Context {
 }
 ",
                     "code": Object {
-                      "raw": "export { default } from \\"../$.context.mjs\\"",
+                      "raw": "export { default } from \\"../$.context.js\\"",
                     },
                     "done": true,
                     "id": "ContextCoder@petstore.yaml#/paths/~1user~1createWithList/post",
@@ -6758,7 +6758,7 @@ class Context {
 }
 ",
                     "code": Object {
-                      "raw": "export { default } from \\"../$.context.mjs\\"",
+                      "raw": "export { default } from \\"../$.context.js\\"",
                     },
                     "done": true,
                     "id": "ContextCoder@petstore.yaml#/paths/~1user~1createWithList/post",
@@ -6804,7 +6804,7 @@ class Context {
 }
 ",
                     "code": Object {
-                      "raw": "export { default } from \\"../$.context.mjs\\"",
+                      "raw": "export { default } from \\"../$.context.js\\"",
                     },
                     "done": true,
                     "id": "ContextCoder@petstore.yaml#/paths/~1user~1createWithList/post",
@@ -6975,7 +6975,7 @@ class Context {
 }
 ",
               "code": Object {
-                "raw": "export { default } from \\"../$.context.mjs\\"",
+                "raw": "export { default } from \\"../$.context.js\\"",
               },
               "done": true,
               "id": "ContextCoder@petstore.yaml#/paths/~1user~1createWithList/post",
@@ -7052,7 +7052,7 @@ class Context {
 }
 ",
               "code": Object {
-                "raw": "export { default } from \\"../$.context.mjs\\"",
+                "raw": "export { default } from \\"../$.context.js\\"",
               },
               "done": true,
               "id": "ContextCoder@petstore.yaml#/paths/~1user~1createWithList/post",
@@ -7098,7 +7098,7 @@ class Context {
 }
 ",
               "code": Object {
-                "raw": "export { default } from \\"../$.context.mjs\\"",
+                "raw": "export { default } from \\"../$.context.js\\"",
               },
               "done": true,
               "id": "ContextCoder@petstore.yaml#/paths/~1user~1createWithList/post",
@@ -7278,7 +7278,7 @@ class Context {
 }
 ",
         "code": Object {
-          "raw": "export { default } from \\"../$.context.mjs\\"",
+          "raw": "export { default } from \\"../$.context.js\\"",
         },
         "done": true,
         "id": "ContextCoder@petstore.yaml#/paths/~1pet~1findByStatus/get",
@@ -7319,7 +7319,7 @@ class Context {
 }
 ",
         "code": Object {
-          "raw": "export { default } from \\"../$.context.mjs\\"",
+          "raw": "export { default } from \\"../$.context.js\\"",
         },
         "done": true,
         "id": "ContextCoder@petstore.yaml#/paths/~1pet~1{petId}~1uploadImage/post",
@@ -7386,7 +7386,7 @@ class Context {
 }
 ",
         "code": Object {
-          "raw": "export { default } from \\"../$.context.mjs\\"",
+          "raw": "export { default } from \\"../$.context.js\\"",
         },
         "done": true,
         "id": "ContextCoder@petstore.yaml#/paths/~1store~1inventory/get",
@@ -7453,7 +7453,7 @@ class Context {
 }
 ",
         "code": Object {
-          "raw": "export { default } from \\"../$.context.mjs\\"",
+          "raw": "export { default } from \\"../$.context.js\\"",
         },
         "done": true,
         "id": "ContextCoder@petstore.yaml#/paths/~1store~1order~1{orderId}/get",
@@ -7520,7 +7520,7 @@ class Context {
 }
 ",
         "code": Object {
-          "raw": "export { default } from \\"../$.context.mjs\\"",
+          "raw": "export { default } from \\"../$.context.js\\"",
         },
         "done": true,
         "id": "ContextCoder@petstore.yaml#/paths/~1user~1createWithList/post",