Skip to content
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

hard coded tsconfig #750

Open
1 of 2 tasks
asollberger opened this issue Jan 31, 2025 · 3 comments
Open
1 of 2 tasks

hard coded tsconfig #750

asollberger opened this issue Jan 31, 2025 · 3 comments

Comments

@asollberger
Copy link

With what library do you have an issue?

native-federation

Reproduction of the bug/regression with instructions

Dear Angular Architects

I tried to specify the tsconfig to be used for a native federation run through the angular.json configuration only to find out that it was entirely ignored.

... so I looked into the code and found this hard coding:

export function findRootTsConfigJson(): string {
  const packageJson = findPackageJson(cwd());
  const projectRoot = path.dirname(packageJson);
  const tsConfigBaseJson = path.join(projectRoot, 'tsconfig.base.json');
  const tsConfigJson = path.join(projectRoot, 'tsconfig.json');

  if (fs.existsSync(tsConfigBaseJson)) {
    return tsConfigBaseJson;
  } else if (fs.existsSync(tsConfigJson)) {
    return tsConfigJson;
  }

  throw new Error('Neither a tsconfig.json nor a tsconfig.base.json was found');
}

Would it be possible to read the configured tsConfig file from angular.json instead (when present, I understand that you're supporting nx as well)?
f.ex.

                "esbuild": {
                    "builder": "@angular-devkit/build-angular:application",
                    "options": {
                        "index": "src/index.html",
                        "tsConfig": "tsconfig.dev.json",

Expected behavior

I'd be fine to create a PR if you can tell me how to properly read the information (I'm guessing it's not just simply reading angular.json, there's probably some angular way to access the parsed configuration).

Versions of Native/Module Federation, Angular, Node, Browser, and operating system

Using native federation v17 in prod, v18 in dev, moving to v19 soon

Other information

No response

I would be willing to submit a PR to fix this issue

  • Yes
  • No
@manfredsteyer
Copy link
Contributor

Hi,

you are right. Yes, feel free to provide an PR.

@asollberger
Copy link
Author

Hi @manfredsteyer

I noticed you're making a copy of the currently used tsconfig (coming from the dev server configuration):

function createTsConfigForFederation(
  workspaceRoot: string,
  tsConfigPath: string,
  entryPoints: EntryPoint[]
) {
  const fullTsConfigPath = path.join(workspaceRoot, tsConfigPath);
  const tsconfigDir = path.dirname(fullTsConfigPath);
  ...
  const tsconfigAsString = fs.readFileSync(fullTsConfigPath, 'utf-8');
  const tsconfig = JSON5.parse(tsconfigAsString);
  ...
  const content = JSON5.stringify(tsconfig, null, 2);

  const tsconfigFedPath = path.join(tsconfigDir, 'tsconfig.federation.json');

  if (!doesFileExist(tsconfigFedPath, content)) {
    fs.writeFileSync(tsconfigFedPath, JSON.stringify(tsconfig, null, 2));
  }

The simplest solution for this issue would be to reuse tsconfig.federation.json.
Do you see any issues with that?

Changing the find function to this:

export function findRootTsConfigJson(): string {
  const packageJson = findPackageJson(cwd());
  const projectRoot = path.dirname(packageJson);
  const tsConfigJson = path.join(projectRoot, 'tsconfig.federation.json');

  if (fs.existsSync(tsConfigJson)) {
    return tsConfigJson;
  }

  throw new Error('tsconfig.federation.json could not be found');
}

@manfredsteyer
Copy link
Contributor

manfredsteyer commented Feb 9, 2025

The thing is that this file can be overwritten by the builder and as soon as the Angular compiler permits, we won't use it anymore. Hence, in future versions there might not be such a file anymore.

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

2 participants