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

Unexpected behavior in import a local package. #182

Open
zongc1001 opened this issue Nov 21, 2023 · 1 comment
Open

Unexpected behavior in import a local package. #182

zongc1001 opened this issue Nov 21, 2023 · 1 comment
Labels
Bug Something isn't working

Comments

@zongc1001
Copy link

Reproduce repo

https://github.com/zongc1001/exposes-dts-poc.git

  • tsconfig.json:
{
  ...,
  "compilerOptions": {
     ...,
    "baseUrl": ".",
    "paths": {
      "@monospace/openapp": ["packages/openapp"],
      "@monospace/openapp/*": ["packages/openapp/*"],
      "@monospace/*": ["packages/*"],
    },
    "plugins": [
      {
        "transform": "typescript-transform-paths",
        "afterDeclarations": true,
      },
    ]
  },
  "include": [
    "expose/expose.ts",
  ],
}

Reproduce step

  1. pnpm install
  2. pnpm build:alias
  3. Check the output file types/packages/openapp/src/deep/import-other-mono.d.ts:
import { ModalProps } from "../../../../../packages/components";  // Wrong. Point to the source ts file.
import { PopoverProps } from "../../../components/src/Popover"; // Correct. Point to the output d.ts file.
export type SomeComp = {
    modalProps: ModalProps;
    popoverProps: PopoverProps;
};
  1. And the source file:
import { Modal, ModalProps } from "@monospace/components";
import { Popover, PopoverProps } from "@monospace/components/src/Popover";

console.log(Modal, Popover);

export type SomeComp = {
  modalProps: ModalProps,
  popoverProps: PopoverProps,
}
@zongc1001
Copy link
Author

And I checked the source code. Seems this issue is caused by the function resolveModuleName.
In this line:

function resolveModuleName(context: VisitorContext, moduleName: string) {
  ...;
  let moduleFileOutputDir = implicitPackageIndex ? resolvedDir : resolvedSourceFileOutputDir; 
  // When `moduleName` equals `@monospace/components`, `implicitPackageIndex` is not undefined and
  // the `resolvedDir` is a path point to the source ts file but not the output declaration file.
  ...;
}

@danielpza danielpza added the Bug Something isn't working label Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants