Issue with dependency_tree
Hi,
I'm the developer of Adonis AutoSwagger I've recently implemented autogeneration for adonisJS validators.
However, when node ace serve --hmr is used, it breaks the functionality of my library.
Error: Node /home/adonis/.local/tmp/adonis-test-file/server/app/validators/comment.ts does not exist
at DependencyTree.getVersion (file:///home/adonis/.local/tmp/adonis-test-file/server/node_modules/.pnpm/[email protected]/node_modules/hot-hook/build/src/dependency_tree.js:26:19)
at HotHookLoader.resolve (file:///home/adonis/.local/tmp/adonis-test-file/server/node_modules/.pnpm/[email protected]/node_modules/hot-hook/build/src/loader.js:169:46)
at async nextResolve (node:internal/modules/esm/hooks:750:22)
at async Hooks.resolve (node:internal/modules/esm/hooks:238:24)
at async handleMessage (node:internal/modules/esm/worker:199:18)
Here's a simplified example, how the integration works.
adonisJS routes.ts
router.get('/swagger', async () => {
return AutoSwagger.default.docs(router.toJSON(), swagger)
})
Adonis AutoSwagger then automatically imports all files from the adonisJS projects app/validators/**/*.ts folder
// files reads the root folder of the adonisjs project and gets all files from app/validators/*.ts
for (let file of files) {
if (/^[a-zA-Z]:/.test(file)) {
file = "file:///" + file;
}
const val = await import(file);
for (const [key, value] of Object.entries(val)) {
if (value.constructor.name.includes("VineValidator")) {
validators[key] = await this.validatorParser.validatorToObject(
value as VineValidator<any, any>
);
validators[key].description = key + " (Validator)";
}
}
}
And here's the issue... hot-hook throws an error, that the file does not exist, but it does.
Is there anything I can fix on my side here? Or is it an upstream issue?
Hi, could you provide a simplified reproduction please?
Oh sure... https://github.com/ad-on-is/adonisjs-hothook-issue
- Check out repo
- cd into server
- Run '(p)npm i'
- Run '(p)npm run dev
- Visit http://localhost:3333/swagger
Hey @Julien-R44 just wanted to ask if you found time to look into this issue or whether you need any further info from my side?
Hey, sorry I've been super busy these last few weeks. Thanks for the repro I'll try to look at it asap
Hey, sorry for the late reply!
after some investigation, I believe the problem is because adonis-autoswagger is using CommonJS modules. Can you try with an ESM build and see what happens?
You should be fine with publishing ESM only since AdonisJS6 is esm only too. None of your users should be affected by this change.
Closing since this is probably the issue. Feel free to reopen if needed :)