hot-hook icon indicating copy to clipboard operation
hot-hook copied to clipboard

Issue with dependency_tree

Open ad-on-is opened this issue 1 year ago • 4 comments

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?

ad-on-is avatar Jun 27 '24 14:06 ad-on-is

Hi, could you provide a simplified reproduction please?

Julien-R44 avatar Jun 27 '24 14:06 Julien-R44

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

ad-on-is avatar Jun 27 '24 14:06 ad-on-is

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?

ad-on-is avatar Jul 14 '24 15:07 ad-on-is

Hey, sorry I've been super busy these last few weeks. Thanks for the repro I'll try to look at it asap

Julien-R44 avatar Jul 15 '24 04:07 Julien-R44

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.

Julien-R44 avatar Sep 20 '24 16:09 Julien-R44

Closing since this is probably the issue. Feel free to reopen if needed :)

Julien-R44 avatar Sep 30 '24 17:09 Julien-R44