Skip to content

fix(plugin): preserve package import paths - #3938

Open
yudin-s wants to merge 1 commit into
nestjs:masterfrom
yudin-s:fix/preserve-package-imports
Open

fix(plugin): preserve package import paths#3938
yudin-s wants to merge 1 commit into
nestjs:masterfrom
yudin-s:fix/preserve-package-imports

Conversation

@yudin-s

@yudin-s yudin-s commented May 29, 2026

Copy link
Copy Markdown
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

When the CLI plugin sees a DTO property typed from a workspace package import such as @repro/shared/messages, TypeScript may resolve the type to the package physical output path. The generated _OPENAPI_METADATA_FACTORY() can then emit a filesystem-relative require() into packages/shared/dist/..., which is not stable at runtime after the package is installed from node_modules.

Issue Number: Fixes #3937

What is the new behavior?

The model visitor now preserves explicit package import specifiers for imported property/enum types before normalizing paths. Package-style references keep emitting package-based require() calls, while relative and built-in/bare module behavior stays unchanged.

A regression fixture covers a monorepo-style DTO importing an enum from @repro/shared/messages and asserts the emitted metadata uses require("@repro/shared/messages").ItemStatus instead of a resolved sibling package path.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Docs were not updated because this is a CLI plugin code-generation bug fix with regression coverage.

Local validation:

npm test -- test/plugin/plugin-utils.spec.ts test/plugin/model-class-visitor.spec.ts
npm test -- test/plugin
npm run build -- --pretty false
npm exec -- prettier --check lib/plugin/utils/plugin-utils.ts lib/plugin/visitors/model-class.visitor.ts test/plugin/plugin-utils.spec.ts test/plugin/model-class-visitor.spec.ts test/plugin/fixtures/package-imports/apps/api/src/item.dto.ts test/plugin/fixtures/package-imports/packages/shared/dist/messages/item.d.ts test/plugin/fixtures/package-imports/tsconfig.json
npm run lint
git diff --check

Note: local install required restoring optional native packages for Vitest/oxlint on macOS; no package manifest or lockfile changes are included.

@yudin-s
yudin-s force-pushed the fix/preserve-package-imports branch from 0b79e65 to dba96e4 Compare May 29, 2026 08:49
@yudin-s
yudin-s marked this pull request as ready for review May 29, 2026 09:55
@SmallhillCZ

SmallhillCZ commented Jun 3, 2026

Copy link
Copy Markdown

whoah! hoped this would be simpler :) thanks for working on this!

@SmallhillCZ

Copy link
Copy Markdown

@yudin-s @kamilmysliwiec hi, is there an ETA for merging? thanks

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

Successfully merging this pull request may close these issues.

CLI plugin emits filesystem-relative require() to workspace package internals instead of the source import path

2 participants