diff --git a/packages/whook-example/package.json b/packages/whook-example/package.json index fbe724f2..7b0fd574 100644 --- a/packages/whook-example/package.json +++ b/packages/whook-example/package.json @@ -42,7 +42,7 @@ } }, "scripts": { - "apitypes": "npm run --silent whook -- generateOpenAPISchema --authenticated=false | npm run --silent whook -- generateOpenAPITypes > src/openAPISchema.d.ts", + "apitypes": "npm run --silent whook -- generateOpenAPISchema --authenticated=true | npm run --silent whook -- generateOpenAPITypes > src/openAPISchema.d.ts", "build": "npm run compile && NODE_ENV=${NODE_ENV:-development} node bin/build", "cli": "env NODE_ENV=${NODE_ENV:-cli}", "compile": "rimraf -f 'dist' && npm run compile:cjs && npm run compile:mjs", diff --git a/packages/whook-example/src/watch.ts b/packages/whook-example/src/watch.ts index 6db63869..c27f71c1 100644 --- a/packages/whook-example/src/watch.ts +++ b/packages/whook-example/src/watch.ts @@ -25,10 +25,10 @@ export async function watchDevServer() { if (filePath.match(/package.*\.json/)) { for (let key in require.cache) { - delete require.cache[key]; + uncache(key); } } else { - delete require.cache[absolutePath]; + uncache(absolutePath, true); } if (delay) { @@ -116,3 +116,21 @@ export async function restartDevServer() { log('warning', '🦄 - API types generated!'); } } + +function uncache(key: string, recursively = false) { + const module = require.cache[key]; + + if (!module) { + return; + } + + if (!key.endsWith('.node')) { + delete require.cache[key]; + } + + if (!recursively) { + return; + } + + uncache(module.parent.id); +}