Open Closed

Abp Angular Module proxy nightmare #3414


User avatar
0
andmattia created
  • ABP Framework version: v5.3.1
  • UI type: Angular

We have a module created via suite and now we have crate our nuget pack and NPM to reuse it in another module.

I try to find a way to solve a nightmare related to export module/proxy. All works fine until I need to call a proxy from module B that it came from module A.

I look into a SAAS module and I see that proxy folder is not inside SRC for angular but it was at root level

saas |--proxy |--src

I try to reproduce the same structure but via abp generate-proxy is not possibile... or don't find a way to do that. Looking inside the source I see that ad a ng-package.json to export proxy from module. I do the same but I still get the error module not exported.

My folder structure is ModuleA |--src |-----lib |--------proxy -> In this folder I put ng-package.json

So now I have my build module with proxy epoxrted... but it still no working.

Looking into the generated code I see that SAAS has @volo/abp.ng.saas/proxy into proxy folder but in my module I have @moduleA/src/lib/proxy. I search the documentation where find a way to create a module and NPM package but I don't find anything.

In all module angualr exists only the project foleder and not the entire project (I see that it is refere to a file tsconfig.base.json but where is this file?)


3 Answer(s)
  • User Avatar
    0
    muhammedaltug created

    Hello,

    Currently, abp proxy generation does not support direct generation in secondary entrypoints. But there is a way to generate in a secondary entrypoint. You can follow the steps below;

    1. Create a secondary entrypoint named 'proxy' (you can look ng-packager doc)
    2. Before running the proxy generation command open the angular.json folder and edit the sourceRoot property of your project's from 'projects/your-lib/src' to 'projects/your-lib/proxy/src'
    3. Run proxy generation command
    4. Revert sourceRoot change in angular.json
    5. Create an index.ts near proxy/src/lib/proxy and export dirs directly. Do not export index.ts in the proxy folder (eg export * from proxy/identity ). Export index.ts where in proxy/src/lib/ in public-api.ts
    6. Define paths in tsconfig.json near your modules path
    //tsconfig.json
    "paths": {
          "your-project": ["src/projects/your-project/src/public-api.ts"],
          "your-project/proxy": ["src/projects/your-project/proxy/src/public-api.ts*"] // this line added
        }
    

    After these steps, you are available to import generated code from "your-project/proxy" entry point.

    Also, I opened an issue for support generating in secondary entrypoints. You can follow the status of the issue.

  • User Avatar
    0
    andmattia created

    Hi @muhammedaltug

    thanks for your quickly reply.

    I add some note to integrate your suggestion:

    1. Remove src prefix and * at file name end
    //tsconfig.json 
    "paths": {
          "your-project": ["projects/your-project/src/public-api.ts"],
          "your-project/proxy": ["projects/your-project/proxy/src/public-api.ts"] // this line added without *
        }
    
    1. public-api.ts: in projects/your-project/proxy/src/public-api.ts add lib export created before on /proxy/src/lib (not index.ts into /proxy/src/lib/proxy
    2. create a ng-packge.json like this. On github like the suggestion is to create it empty but you must export ts on dist folder
    {
      "$schema": "../../../node_modules/ng-packagr/ng-package.schema.json",
      "dest": "../../../dist/your-project/proxy",
      "lib": {
        "entryFile": "src/public-api.ts"
      }
    }
    
    
  • User Avatar
    0
    muhammedaltug created

    Hello,

    Yes, your notes are correct. What is the last status of the process of the generation proxies ? Can we close the question?

Made with ❤️ on ABP v9.1.0-preview. Updated on December 10, 2024, 06:38