counterfact 1.4.7 → 1.4.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ export {};
@@ -1,28 +1,7 @@
1
- import { namedTypes, visit } from "ast-types";
2
- import { parse, print } from "recast";
3
1
  export function convertFileExtensionsToCjs(code) {
4
- const ast = parse(code);
5
- // Visit the nodes in the AST looking for `require` calls
6
- visit(ast, {
7
- // Identify the CallExpression nodes
8
- visitCallExpression(path) {
9
- const { node } = path;
10
- // Check if it's a require call
11
- if (namedTypes.CallExpression.check(node) &&
12
- node.callee.type === "Identifier" &&
13
- node.callee.name === "require" &&
14
- node.arguments[0] !== undefined &&
15
- node.arguments[0].type === "Literal" &&
16
- typeof node.arguments[0].value === "string" &&
17
- node.arguments[0].value.startsWith(".")) {
18
- // Change the module string from "foo.js" to "foo.cjs"
19
- node.arguments[0].value = node.arguments[0].value.replace(
20
- // eslint-disable-next-line regexp/prefer-named-capture-group
21
- /(\.js|\.ts)?$/u, ".cjs");
22
- }
23
- // Continue traversing the AST
24
- this.traverse(path);
25
- },
26
- });
27
- return print(ast).code;
2
+ // Match require('...') or require("...") where the path starts with .
3
+ // Replace .js or .ts extensions (or no extension) with .cjs
4
+ return code.replace(
5
+ // eslint-disable-next-line regexp/prefer-named-capture-group
6
+ /require\((['"])(\.[^'"]*?)(\.(?:js|ts))?\1\)/g, (match, quote, path) => `require(${quote}${path}.cjs${quote})`);
28
7
  }
@@ -0,0 +1,3 @@
1
+ export interface OpenApiHeader {
2
+ schema: unknown;
3
+ }
@@ -1,6 +1,4 @@
1
- interface OpenApiHeader {
2
- schema: unknown;
3
- }
1
+ import { OpenApiHeader } from "./OpenApiHeader";
4
2
 
5
3
  interface OpenApiContent {
6
4
  schema: unknown;
@@ -54,7 +52,7 @@ type IfHasKey<
54
52
  infer FirstKey extends string,
55
53
  ...infer RestKeys extends string[],
56
54
  ]
57
- ? keyof SomeObject extends `${string}${FirstKey}${string}`
55
+ ? keyof SomeObject extends FirstKey
58
56
  ? Yes
59
57
  : IfHasKey<SomeObject, RestKeys, Yes, No>
60
58
  : No;
@@ -120,7 +118,7 @@ interface ResponseBuilder {
120
118
  xml: (body: unknown) => ResponseBuilder;
121
119
  }
122
120
 
123
- type GenericResponseBuilderInner<
121
+ export type GenericResponseBuilderInner<
124
122
  Response extends OpenApiResponse = OpenApiResponse,
125
123
  > = OmitValueWhenNever<{
126
124
  header: [keyof Response["headers"]] extends [never]
@@ -33,13 +33,12 @@ export class Repository {
33
33
  }
34
34
  }
35
35
  async copyCoreFiles(destination) {
36
- const sourcePath = nodePath.join(__dirname, "../../dist/server/types.ts");
37
- const destinationPath = nodePath.join(destination, "types.ts");
36
+ const sourcePath = nodePath.join(__dirname, "../../dist/server/counterfact-types");
37
+ const destinationPath = nodePath.join(destination, "counterfact-types");
38
38
  if (!existsSync(sourcePath)) {
39
39
  return false;
40
40
  }
41
- await ensureDirectoryExists(destination);
42
- return fs.copyFile(sourcePath, destinationPath);
41
+ return fs.cp(sourcePath, destinationPath, { recursive: true });
43
42
  }
44
43
  async writeFiles(destination, { routes, types }) {
45
44
  debug("waiting for %i or more scripts to finish before writing files", this.scripts.size);
@@ -99,7 +99,9 @@ export class Script {
99
99
  return this.importExternal(name, modulePath, true);
100
100
  }
101
101
  importSharedType(name) {
102
- return this.importExternal(name, nodePath.join(this.relativePathToBase, "types.ts").replaceAll("\\", "/"), true);
102
+ return this.importExternal(name, nodePath
103
+ .join(this.relativePathToBase, "counterfact-types/index.ts")
104
+ .replaceAll("\\", "/"), true);
103
105
  }
104
106
  exportType(coder) {
105
107
  return this.export(coder, true);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "counterfact",
3
- "version": "1.4.7",
3
+ "version": "1.4.9",
4
4
  "description": "Generate a TypeScript-based mock server from an OpenAPI spec in seconds — with stateful routes, hot reload, and REPL support.",
5
5
  "type": "module",
6
6
  "main": "./dist/app.js",
@@ -63,8 +63,8 @@
63
63
  "test": "yarn node --experimental-vm-modules ./node_modules/jest-cli/bin/jest --testPathIgnorePatterns=black-box",
64
64
  "test:black-box": "rimraf dist && rimraf out && yarn build && yarn node --experimental-vm-modules ./node_modules/jest-cli/bin/jest black-box --forceExit --coverage=false",
65
65
  "test:mutants": "stryker run stryker.config.json",
66
- "test:tsd": "tsd --typings ./dist/server/types.ts --files ./test/**/*.test-d.ts",
67
- "build": "tsc && copyfiles -f \"src/client/**\" dist/client && copyfiles -f \"src/server/types.ts\" dist/server && copyfiles -f \"src/server/*.cjs\" dist/server",
66
+ "test:tsd": "tsd --typings ./dist/server/counterfact-types/index.ts --files ./test/**/*.test-d.ts",
67
+ "build": "rm -rf dist && tsc && copyfiles -f \"src/client/**\" dist/client && copyfiles -f \"src/counterfact-types/*.ts\" dist/server/counterfact-types && copyfiles -f \"src/server/*.cjs\" dist/server",
68
68
  "prepack": "yarn build",
69
69
  "release": "npx changeset publish",
70
70
  "prepare": "husky install",
@@ -81,28 +81,34 @@
81
81
  "@stryker-mutator/core": "9.4.0",
82
82
  "@stryker-mutator/jest-runner": "9.4.0",
83
83
  "@stryker-mutator/typescript-checker": "9.4.0",
84
- "@swc/core": "1.15.3",
84
+ "@swc/core": "1.15.8",
85
85
  "@swc/jest": "0.2.39",
86
86
  "@testing-library/dom": "10.4.1",
87
+ "@types/debug": "^4.1.12",
87
88
  "@types/jest": "30.0.0",
88
89
  "@types/js-yaml": "4.0.9",
89
- "@types/koa": "2.15.0",
90
+ "@types/koa": "3.0.1",
90
91
  "@types/koa-bodyparser": "4.3.13",
91
92
  "@types/koa-proxy": "1.0.8",
92
93
  "@types/koa-static": "4.0.4",
93
- "@types/lodash": "4.17.21",
94
+ "@types/lodash": "4.17.23",
95
+ "@typescript-eslint/eslint-plugin": "^8.53.0",
96
+ "@typescript-eslint/parser": "^8.53.0",
94
97
  "copyfiles": "2.4.1",
95
- "eslint": "9.28.0",
96
- "eslint-config-hardcore": "49.0.0",
98
+ "eslint": "9.39.2",
97
99
  "eslint-formatter-github-annotations": "0.1.0",
98
100
  "eslint-import-resolver-typescript": "4.4.4",
99
101
  "eslint-plugin-etc": "2.0.3",
100
102
  "eslint-plugin-file-progress": "3.0.2",
101
103
  "eslint-plugin-import": "2.32.0",
102
- "eslint-plugin-jest": "29.2.1",
104
+ "eslint-plugin-jest": "29.12.1",
103
105
  "eslint-plugin-jest-dom": "5.5.0",
106
+ "eslint-plugin-n": "^17.23.2",
104
107
  "eslint-plugin-no-explicit-type-exports": "0.12.1",
105
108
  "eslint-plugin-prettier": "5.5.4",
109
+ "eslint-plugin-promise": "^7.2.1",
110
+ "eslint-plugin-regexp": "^2.10.0",
111
+ "eslint-plugin-security": "^3.0.1",
106
112
  "eslint-plugin-unused-imports": "4.3.0",
107
113
  "husky": "9.1.7",
108
114
  "jest": "30.2.0",
@@ -110,7 +116,7 @@
110
116
  "node-mocks-http": "1.17.2",
111
117
  "rimraf": "6.1.2",
112
118
  "stryker-cli": "1.1.0",
113
- "supertest": "7.1.4",
119
+ "supertest": "7.2.2",
114
120
  "tsd": "0.33.0",
115
121
  "using-temporary-files": "2.2.1"
116
122
  },
@@ -118,18 +124,17 @@
118
124
  "@apidevtools/json-schema-ref-parser": "13.0.5",
119
125
  "@hapi/accept": "6.0.3",
120
126
  "@types/json-schema": "7.0.15",
121
- "ast-types": "0.14.2",
122
127
  "chokidar": "5.0.0",
123
128
  "commander": "14.0.2",
124
129
  "debug": "4.4.3",
125
130
  "fetch": "1.1.0",
126
- "fs-extra": "11.3.2",
131
+ "fs-extra": "11.3.3",
127
132
  "handlebars": "4.7.8",
128
133
  "http-terminator": "3.2.0",
129
134
  "js-yaml": "4.1.1",
130
135
  "json-schema-faker": "0.5.9",
131
- "jsonwebtoken": "9.0.2",
132
- "koa": "3.0.3",
136
+ "jsonwebtoken": "9.0.3",
137
+ "koa": "3.1.1",
133
138
  "koa-bodyparser": "4.4.1",
134
139
  "koa-proxies": "0.12.4",
135
140
  "koa2-swagger-ui": "5.12.0",
@@ -138,9 +143,11 @@
138
143
  "open": "11.0.0",
139
144
  "patch-package": "8.0.1",
140
145
  "precinct": "12.2.0",
141
- "prettier": "3.7.3",
142
- "recast": "0.23.11",
146
+ "prettier": "3.7.4",
143
147
  "typescript": "5.9.3"
144
148
  },
145
- "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
149
+ "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e",
150
+ "resolutions": {
151
+ "js-yaml": "4.1.1"
152
+ }
146
153
  }