Skip to content

extract-ts-types.mjs writes types.ts for NuGet-installed modules into the consumer's source tree #283

Description

@antosubash

Summary

scripts/extract-ts-types.mjs iterates over every DtoTypeScript_*.g.cs the source generator emits and writes a types.ts for each. That set includes modules that arrived as NuGet packages, not as source in the consumer's repo — so the script creates source directories for modules the consumer does not own.

Reproduction

Scaffold a project, then install any packaged module:

sm new project MyApp && cd MyApp
sm install SimpleModule.Users        # pulls SimpleModule.Settings too
npm run generate:types

Result

src/modules/Users/src/SimpleModule.Users/types.ts        # module lives in a NuGet package
src/modules/Settings/src/SimpleModule.Settings/types.ts  # ditto

Neither Users nor Settings has any source in the repo. Before generate:types ran, src/modules/ contained only the locally-created modules.

Why it matters

  1. Repo pollution. The consumer gets tracked source directories for code they do not own and cannot edit. Regenerating the types is the only thing that ever writes there.
  2. Collides with the npm workspaces glob. The root package.json uses "workspaces": ["src/modules/*/src/*", ...]. These phantom directories match that glob. They contain no package.json so npm currently skips them, but the layout is one step away from breaking npm install.
  3. They get committed. Nothing in the generated .gitignore excludes them, so they land in the consumer's history and show up in diffs whenever a packaged module's DTOs change.
  4. Stale entries are never removed. Deleting a module leaves its directory behind — see the companion issue.

Suggested fix

Only emit types for modules that have a corresponding project directory in <modulesDir>. Something like: skip the file when <modulesDir>/<moduleName> does not already exist, rather than mkdirSync(..., { recursive: true }) unconditionally.

Packaged modules could ship their types.ts inside the NuGet package (or under node_modules/obj) instead of being reconstructed in the consumer's source tree.

Environment

  • SimpleModule.Cli 0.0.39, packages 0.0.39
  • .NET SDK 10.0.201, Node 23.5.0, macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions