Skip to content

Nestia SDK not working with Monorepo or Thirdparty #923

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DaiLoc5698 opened this issue Jun 19, 2024 · 3 comments
Closed

Nestia SDK not working with Monorepo or Thirdparty #923

DaiLoc5698 opened this issue Jun 19, 2024 · 3 comments

Comments

@DaiLoc5698
Copy link

Question

Hello!

I am encountering an issue with the Nestia SDK in my project setup. Here are the details:

Problem Description
I am working on a Monorepo with multiple packages. I am facing an issue when reusing packages within my repo or when integrating external library packages. Specifically, the SDK fails to generate code for certain modules.

Code Snippets
Here is a snippet of my AppModule:

import { Module } from '@nestjs/common';

// this in my repo
import { AuthModule } from '@fzap/auth-module';

import { CategoryModule } from './fandom/category.module';
import { FandomModule } from './fandom/fandom.module';
import { AccountModule } from './account/account.module';

// this from another library
import { NotificationModule } from '@dailoc.lq/notification-module';

@Module({
  imports: [
    AccountModule.forRoot({ dataSourceName: 'default' }),
    CategoryModule,
    FandomModule,
    NotificationModule.forRoot(),
    AuthModule
  ],
})
export class AppModule { }

Here is my configuration:

import type sdk from "@nestia/sdk";
import { NestFactory } from "@nestjs/core";
import { AppModule } from "./src/app.module";

const NESTIA_CONFIG: sdk.INestiaConfig = {
  input: () => NestFactory.create(AppModule),
  output: "src/api",
  distribute: "packages/api",
  primitive: false,
  simulate: true,
  assert: true
};
export default NESTIA_CONFIG;

Issue Details
In this setup, the SDK fails to generate code for two specific modules: AuthModule (an internal package in the repo) and NotificationModule (an external library).

Upon investigation, I found the issue arises from the following code snippet in the NestiaSdkApplication.ts file:

const file: ts.SourceFile | undefined = program.getSourceFile(c.file);

// c.file => /user_path/.../fzap/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@nestjs+typeor_7ldrefmg7aejqjdg6hdcg25qvq/node_modules/@dailoc.lq/notification-module/dist/module/email/email-template/email-template.controller.js

It appears that the getSourceFile function is unable to retrieve the specified file, which prevents the SDK from generating the necessary code for these modules.

Could you please investigate this issue and provide guidance on how to resolve it? Any insights or potential fixes would be greatly appreciated.

Thank you!

@samchon
Copy link
Owner

samchon commented Jun 20, 2024

Currently, to make monorepo SDK generation working, you should generate SDK library per each package.

If you want to make it advance, can you give me a reproducible repo?

@DavidVaness
Copy link
Contributor

Currently, to make monorepo SDK generation working, you should generate SDK library per each package.

If you want to make it advance, can you give me a reproducible repo?

We use Nestia in a PNPM monorepo and generate the sdk as a package. Works without issues

@samchon
Copy link
Owner

samchon commented Dec 2, 2024

Currently, to make monorepo SDK generation working, you should generate SDK library per each package.
If you want to make it advance, can you give me a reproducible repo?

We use Nestia in a PNPM monorepo and generate the sdk as a package. Works without issues

I think it is the monorepo composed with multiple NestJS sub repositories.

No way to build integrated SDK in such circumstance.

Just build multiple SDK libraries and merge them into one by yourself please.

@samchon samchon closed this as not planned Won't fix, can't repro, duplicate, stale Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants