Skip to content

Commit

Permalink
Merge branch 'main' into usage-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
pmcelhaney committed Aug 2, 2022
2 parents 7ef4fb1 + b06aec5 commit aaeabf9
Show file tree
Hide file tree
Showing 6 changed files with 404 additions and 333 deletions.
5 changes: 5 additions & 0 deletions .changeset/eleven-spoons-rhyme.md
@@ -0,0 +1,5 @@
---
"counterfact": patch
---

replaced EventEmitter with EventTarget
5 changes: 5 additions & 0 deletions .eslintrc.cjs
Expand Up @@ -41,6 +41,11 @@ module.exports = {
sourceType: "module",
},

env: {
es2021: true,
node: true,
},

rules,

overrides: [
Expand Down
24 changes: 12 additions & 12 deletions demo-ts/yarn.lock
Expand Up @@ -39,9 +39,9 @@
integrity sha512-SQ7Kzhh9+D+ZW9MA0zkYv3VXhIDNx+LzM6EJ+/65I3QY+enU6Itte7E5XX7EWrqLW2FN4n06GWzBnPoC3th2aQ==

"@npmcli/arborist@^5.0.0", "@npmcli/arborist@^5.0.4":
version "5.3.0"
resolved "https://registry.yarnpkg.com/@npmcli/arborist/-/arborist-5.3.0.tgz#321d9424677bfc08569e98a5ac445ee781f32053"
integrity sha512-+rZ9zgL1lnbl8Xbb1NQdMjveOMwj4lIYfcDtyJHHi5x4X8jtR6m8SXooJMZy5vmFVZ8w7A2Bnd/oX9eTuU8w5A==
version "5.3.1"
resolved "https://registry.yarnpkg.com/@npmcli/arborist/-/arborist-5.3.1.tgz#6ce26ccd909dd74a5b37eb32f032ab2655a95709"
integrity sha512-qTxXudG7HI46sHpuWCos/uchJONsRnz+Pf/jkMsu7nKA3BdtgI+pFRatozuliHrIR9uOxyTQlAm6cQojKmyy1A==
dependencies:
"@isaacs/string-locale-compare" "^1.1.0"
"@npmcli/installed-package-contents" "^1.0.7"
Expand Down Expand Up @@ -136,9 +136,9 @@
npm-normalize-package-bin "^1.0.1"

"@npmcli/map-workspaces@^2.0.2", "@npmcli/map-workspaces@^2.0.3":
version "2.0.3"
resolved "https://registry.yarnpkg.com/@npmcli/map-workspaces/-/map-workspaces-2.0.3.tgz#2d3c75119ee53246e9aa75bc469a55281cd5f08f"
integrity sha512-X6suAun5QyupNM8iHkNPh0AHdRC2rb1W+MTdMvvA/2ixgmqZwlq5cGUBgmKHUHT2LgrkKJMAXbfAoTxOigpK8Q==
version "2.0.4"
resolved "https://registry.yarnpkg.com/@npmcli/map-workspaces/-/map-workspaces-2.0.4.tgz#9e5e8ab655215a262aefabf139782b894e0504fc"
integrity sha512-bMo0aAfwhVwqoVM5UzX1DJnlvVvzDCHae821jv48L1EsrYwfOZChlqWYXEtto/+BkBXetPbEWgau++/brh4oVg==
dependencies:
"@npmcli/name-from-folder" "^1.0.1"
glob "^8.0.1"
Expand Down Expand Up @@ -420,9 +420,9 @@ archy@~1.0.0:
integrity sha512-Xg+9RwCg/0p32teKdGMPTPnVXKD0w3DfHnFTficozsAgsvq2XenPJq/MYpzzQ/v8zrOyJn6Ds39VA4JIDwFfqw==

are-we-there-yet@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/are-we-there-yet/-/are-we-there-yet-3.0.0.tgz#ba20bd6b553e31d62fc8c31bd23d22b95734390d"
integrity sha512-0GWpv50YSOcLXaN6/FAKY3vfRbllXWV2xvfA/oKJF8pzFhWXPV+yjhJXDBbjscDYowv7Yw1A3uigpzn5iEGTyw==
version "3.0.1"
resolved "https://registry.yarnpkg.com/are-we-there-yet/-/are-we-there-yet-3.0.1.tgz#679df222b278c64f2cdba1175cdc00b0d96164bd"
integrity sha512-QZW4EDmGwlYur0Yyf/b2uGucHQMa8aFUP7eu9ddR73vvhFyt4V0Vl3QHPcTNJ8l6qYOBdxgXdnBXQrHilfRQBg==
dependencies:
delegates "^1.0.0"
readable-stream "^3.6.0"
Expand Down Expand Up @@ -1900,9 +1900,9 @@ npm-user-validate@^1.0.1:
integrity sha512-uQwcd/tY+h1jnEaze6cdX/LrhWhoBxfSknxentoqmIuStxUExxjWd3ULMLFPiFUrZKbOVMowH6Jq2FRWfmhcEw==

npm@^8.13.1:
version "8.15.0"
resolved "https://registry.yarnpkg.com/npm/-/npm-8.15.0.tgz#d4b53cd29b13ea164f0f5767bca274dbe7d8f78d"
integrity sha512-sFXrMiO07eDWUb/e5ni2yNvtz2hePKqSyukUxYcQv0QHjyXCe+zKP7af/bISjcvsgRBWGyivk5V3KCZ0vg8J3Q==
version "8.15.1"
resolved "https://registry.yarnpkg.com/npm/-/npm-8.15.1.tgz#0cda5f182e6ef057c15cde5b8e443b52907ba052"
integrity sha512-ZjVMjEn+PqdjpZg+VLMFz5lyzh7tW+SBt+KQzvoQC986U/clE897eg7YR0PLYw6RfjTsoPTuB95xQ8ubn9go6Q==
dependencies:
"@isaacs/string-locale-compare" "^1.1.0"
"@npmcli/arborist" "^5.0.4"
Expand Down
7 changes: 4 additions & 3 deletions package.json
Expand Up @@ -27,23 +27,24 @@
"test:mutants": "stryker run stryker.config.json",
"release": "npx changeset publish",
"prepare": "husky install",
"lint": "eslint .",
"lint": "eslint . --plugin file-progress --rule 'file-progress/activate: 1'",
"lint:quickfix": "eslint --fix . eslint --fix demo-ts --rule=\"import/namespace: 0,etc/no-deprecated:0,import/no-cycle:0,no-explicit-type-exports/no-explicit-type-exports:0,import/no-deprecated:0,import/no-self-import:0,import/default:0,import/no-named-as-default:0\"",
"generate": "./bin/counterfact.js generate",
"generate:petstore": "yarn generate ./petstore.yaml demo-ts",
"generate:example": "yarn generate ./openapi-example.yaml demo-ts",
"counterfact": "./bin/counterfact.js"
},
"devDependencies": {
"@changesets/cli": "2.23.2",
"@changesets/cli": "2.24.1",
"@stryker-mutator/core": "6.1.2",
"@stryker-mutator/jest-runner": "6.1.2",
"@types/koa": "2.13.5",
"@types/koa-static": "^4.0.2",
"eslint": "8.20.0",
"eslint-config-hardcore": "24.10.0",
"eslint-config-hardcore": "24.11.0",
"eslint-formatter-github-annotations": "0.1.0",
"eslint-import-resolver-typescript": "^3.2.5",
"eslint-plugin-file-progress": "^1.3.0",
"eslint-plugin-import": "^2.26.0",
"husky": "8.0.1",
"jest": "28.1.2",
Expand Down
18 changes: 9 additions & 9 deletions src/module-loader.js
@@ -1,12 +1,10 @@
/* eslint-disable node/no-unsupported-features/es-syntax */
/* eslint-disable import/no-dynamic-require */
import fs from "node:fs/promises";
import nodePath from "node:path";
import EventEmitter, { once } from "node:events";
import { once } from "node:events";

import chokidar from "chokidar";

export class ModuleLoader extends EventEmitter {
export class ModuleLoader extends EventTarget {
basePath;

registry;
Expand All @@ -22,8 +20,8 @@ export class ModuleLoader extends EventEmitter {
async watch() {
this.watcher = chokidar
.watch(`${this.basePath}/**/*.{js,mjs,ts,mts}`)
.on("all", (event, pathName) => {
if (!["add", "change", "unlink"].includes(event)) {
.on("all", (eventName, pathName) => {
if (!["add", "change", "unlink"].includes(eventName)) {
return;
}

Expand All @@ -34,16 +32,17 @@ export class ModuleLoader extends EventEmitter {
return;
}

if (event === "unlink") {
if (eventName === "unlink") {
this.registry.remove(url);
this.emit("remove", pathName);
this.dispatchEvent(new Event("remove"), pathName);
}

// eslint-disable-next-line node/no-unsupported-features/es-syntax, import/no-dynamic-require
import(`${pathName}?cacheBust=${Date.now()}`)
// eslint-disable-next-line promise/prefer-await-to-then
.then((endpoint) => {
this.registry.add(url, endpoint);
this.emit(event, pathName);
this.dispatchEvent(new Event(eventName), pathName);

return "ok";
})
Expand Down Expand Up @@ -80,6 +79,7 @@ export class ModuleLoader extends EventEmitter {
return;
}

// eslint-disable-next-line node/no-unsupported-features/es-syntax, import/no-dynamic-require
const endpoint = await import(
nodePath.join(this.basePath, directory, file.name)
);
Expand Down

0 comments on commit aaeabf9

Please sign in to comment.