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

[Bug]: TS issues in generated file libs/library/schematics/ng-add/index.ts #2714

Open
malek-benazzouz opened this issue Jan 21, 2025 · 1 comment · May be fixed by #2727
Open

[Bug]: TS issues in generated file libs/library/schematics/ng-add/index.ts #2714

malek-benazzouz opened this issue Jan 21, 2025 · 1 comment · May be fixed by #2727
Assignees
Labels
bug Something isn't working priority:high

Comments

@malek-benazzouz
Copy link

malek-benazzouz commented Jan 21, 2025

Package name

core

Package version

11.5.3

Reproduction steps

Create a project with o3r generator, then generate a library:

npm create @o3r project
cd project
ng g library lib

Current result

There are TS issues in the generated libs/library/schematics/ng-add/index.ts file:

  1. fs.readFileSync is used, but fs is not imported. We should add import * as fs from 'node:fs'; in the imports section.

  2. Replace const dependenciesToInstall = [] by const dependenciesToInstall: string[] = [] to avoid lint issues. Same for dependenciesToNgAdd.

  3. In ngAddFn function, the line return async (tree, context) => { raises a lint issue because context is not used. We could replace it by _context.

  4. Lines 36 to 38 have compilation issues.
    To fix them, replace:

    const { getProjectNewDependenciesTypes, getPackageInstallConfig, applyEsLintFix, install } = await import('@o3r/schematics');
    // current package version
    const version = JSON.stringify(fs.readFileSync(packageJsonPath)).version;
    const dependencies = [...dependenciesToInstall, ...dependenciesToNgAdd].reduce((acc, dep) => {

By:

    const { getProjectNewDependenciesTypes, getPackageInstallConfig, applyEsLintFix, setupDependencies, getWorkspaceConfig } = await import('@o3r/schematics');
    const version = (JSON.parse(fs.readFileSync(packageJsonPath, { encoding: 'utf8' })) as PackageJson).version;
    const workspaceProject = options.projectName ? getWorkspaceConfig(tree)?.projects[options.projectName] : undefined;
    const dependencies = [...dependenciesToInstall, ...dependenciesToNgAdd].reduce((acc, dep) => {

Expected result

All the above issues should be fixed in the template file that is used to generate the ng-add/index.ts file.

Additional comments

No response

@malek-benazzouz malek-benazzouz added bug Something isn't working triage labels Jan 21, 2025
@malek-benazzouz malek-benazzouz changed the title [Bug]: [Bug]: TS issues in generated file libs/library/schematics/ng-add/index.ts Jan 21, 2025
@vscaiceanu-1a
Copy link
Member

After fixing #2481 we should be able to reactivate the lint command in the integration test in packages/@o3r/eslint-config/schematics/index.it.spec.ts to validate this fix.

@vscaiceanu-1a vscaiceanu-1a self-assigned this Jan 23, 2025
@vscaiceanu-1a vscaiceanu-1a linked a pull request Jan 23, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority:high
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants