generator icon indicating copy to clipboard operation
generator copied to clipboard

Generator not searching the template in private registry

Open raaj-repos opened this issue 2 years ago • 4 comments

Describe the bug

A custom template package is published to private registry (jfrog artifactory) and referred the package, generator looks in https://registry.npmjs.org/ and not in private registry. However using generator source code from master repo and running npm run test:cli works where template is from private registry . As the latest version is 1.9.5, tried installing the 1.9.4 version which is master repo version and is not working as well.

How to Reproduce

  1. Create a sample template package and publish it to private registry in my case it is @mycompany/asyncapi-csharp
  2. Point your npm to your private registry npm config set registry https://artifactory.mycompany.com/api/npm/npm
  3. Verify if the package can be identified by npm, npm search @mycompany/asyncapi-csharp
  4. Run the generate command ag DomainServiceA.yml @mycompany/asyncapi-csharp -o ouput --debug --install
  • Screenshots
root@mylaptop:/mnt/c/Workspace/mycompany/sampleproject/DomainServiceA# ag DomainServiceA.yml @mycompany/asyncapi-csharp -o output --install --debug
Template installation started because you passed --install flag.
Something went wrong:
HttpErrorGeneral: 404 Not Found - GET https://registry.npmjs.org/@mycompany%2fasyncapi-csharp - Not found
    at /usr/local/lib/node_modules/@asyncapi/generator/node_modules/npm-registry-fetch/check-response.js:95:15
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at Arborist.[nodeFromEdge] (/usr/local/lib/node_modules/@asyncapi/generator/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:1048:19)
    at Arborist.[buildDepStep] (/usr/local/lib/node_modules/@asyncapi/generator/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:917:11)
    at Arborist.buildIdealTree (/usr/local/lib/node_modules/@asyncapi/generator/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:215:7)
    at async Promise.all (index 1)
    at Arborist.reify (/usr/local/lib/node_modules/@asyncapi/generator/node_modules/@npmcli/arborist/lib/arborist/reify.js:148:5)
    at /usr/local/lib/node_modules/@asyncapi/generator/lib/generator.js:393:31

Expected behavior

Should refer the template's npm package in private registry and generate the code.

raaj-repos avatar Jun 22 '22 22:06 raaj-repos

Welcome to AsyncAPI. Thanks a lot for reporting your first issue. Please check out our contributors guide and the instructions about a basic recommended setup useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

github-actions[bot] avatar Jun 22 '22 22:06 github-actions[bot]

@raaj-repos thanks a lot for taking time to create an issue.

Generator, after many issues related to reuse of npm binary switched approach to use https://www.npmjs.com/package/@npmcli/arborist package that is a core for npm binary itself.

This means npm config set registry https://artifactory.mycompany.com/api/npm/npm has no effect on the Generator. Arborist supports a configuration that a custom registry URL could be passed to it, but it is not yet enabled inside Generator.

One community member started working on it https://github.com/asyncapi/generator/pull/673/files but instead of enabling it on a library level, he chose to pick configuration from the npm binary. PR is discontinued.

I'm here to help if you want to take time and contribute it.

Workaround could be that you install @mycompany/asyncapi-csharp first globally and then do ag DomainServiceA.yml @mycompany/asyncapi-csharp because generator, if cannot find a package in registry, falls back to local, but do not use --install flag.

I hope that helps 🙏🏼

derberg avatar Jun 23 '22 12:06 derberg

Tried and it didnt work either. Got windows machine and installed the @mycompany/asyncapi-csharp globally and verified manually by navigating to the folder C:\Users\me\AppData\Roaming\npm\node_modules. Still getting the same error,

root@mylaptop:/mnt/c/Workspace/mycompany/sampleproject/DomainServiceA#ag DomainServiceA.yml @mycompany/asyncapi-csharp -o out --debug


Unable to resolve template location at undefined. Package is not available locally. Error: Cannot find module '@mycompany\asyncapi-csharp\package.json'
Require stack:
- C:\Program Files\nodejs\node_modules\noop.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at resolveFileName (C:\Users\me\AppData\Roaming\npm\node_modules\@asyncapi\generator\node_modules\resolve-from\index.js:29:39)
    at resolveFrom (C:\Users\me\AppData\Roaming\npm\node_modules\@asyncapi\generator\node_modules\resolve-from\index.js:43:9)
    at module.exports (C:\Users\me\AppData\Roaming\npm\node_modules\@asyncapi\generator\node_modules\resolve-from\index.js:46:47)
    at utils.getTemplateDetails (C:\Users\me\AppData\Roaming\npm\node_modules\@asyncapi\generator\lib\utils.js:195:30)
    at C:\Users\me\AppData\Roaming\npm\node_modules\@asyncapi\generator\lib\generator.js:367:26
    at new Promise (<anonymous>)
    at Generator.installTemplate (C:\Users\me\AppData\Roaming\npm\node_modules\@asyncapi\generator\lib\generator.js:360:12)
    at Generator.generate (C:\Users\me\AppData\Roaming\npm\node_modules\@asyncapi\generator\lib\generator.js:180:73)
    at C:\Users\me\AppData\Roaming\npm\node_modules\@asyncapi\generator\cli.js:154:9 {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ 'C:\\Program Files\\nodejs\\node_modules\\noop.js' ]
}
Template installation started because the template cannot be found on disk.
Something went wrong:
HttpErrorGeneral: 404 Not Found - GET https://registry.npmjs.org/@mycompany%2fasyncapi-csharp - Not found
    at C:\Users\me\AppData\Roaming\npm\node_modules\@asyncapi\generator\node_modules\npm-registry-fetch\check-response.js:95:15
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at Arborist.[nodeFromEdge] (C:\Users\me\AppData\Roaming\npm\node_modules\@asyncapi\generator\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:1048:19)
    at Arborist.[buildDepStep] (C:\Users\me\AppData\Roaming\npm\node_modules\@asyncapi\generator\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:917:11)
    at Arborist.buildIdealTree (C:\Users\me\AppData\Roaming\npm\node_modules\@asyncapi\generator\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:215:7)
    at async Promise.all (index 1)
    at Arborist.reify (C:\Users\me\AppData\Roaming\npm\node_modules\@asyncapi\generator\node_modules\@npmcli\arborist\lib\arborist\reify.js:148:5)
    at C:\Users\me\AppData\Roaming\npm\node_modules\@asyncapi\generator\lib\generator.js:393:31

raaj-repos avatar Jun 23 '22 20:06 raaj-repos

It's been a while since I wrote that code. My comments say that the undefined that you see is there because package cannot be found -> https://github.com/asyncapi/generator/blob/master/lib/utils.js#L184-L204

are you sure C:\Users\me\AppData\Roaming\npm\node_modules is a global location? When I check the code of the package that we use, to determine global location, it specifies -> https://github.com/sindresorhus/global-dirs/blob/main/index.js

Have a look at https://stackoverflow.com/questions/19874582/change-default-global-installation-directory-for-node-js-modules-in-windows Also as a workaround maybe try with yarn?

derberg avatar Jun 28 '22 14:06 derberg

No followup, closing. Feel free to drop a comment if you want to reopen it

derberg avatar Oct 11 '22 12:10 derberg