Skip to content

Bug when folder name is the same as package name #231

Description

@0x62

I discovered a weird bug today. My folder structure is as follows:

  • packages/
    • sys/
      • api/ - @internal/api
        • src/
          • api/
          • other/
          • folder/
      • core/ - @internal/core

Each of the packages in sys has an @lib alias pointing to src.

Running tsc-alias --debug in the @internal/api package returns:

tsc-alias debug: default replacer - alias:  {
  shouldPrefixMatchWildly: true,
  prefix: '@lib/',
  paths: [
    {
      path: 'src/',
      basePath: '/Users/<redact>/packages/sys/api/dist/api',
      isExtra: false
    },
    [length]: 1
  ]
}

The base path has an extra /api appended to it, resulting in an Invalid path warning and no substitution taking place. Meanwhile, the @internal/core package has exactly the same config but no problems.

I changed the structure to

  • packages/
    • sys/
      • api-models/ - @internal/api-models
        • src/
          • api/
          • other/
          • folder/
      • core/ - @internal/core

And after running again I get the correct output:

tsc-alias debug: default replacer - alias:  {
  shouldPrefixMatchWildly: true,
  prefix: '@lib/',
  paths: [
    {
      path: 'src/',
      basePath: '/Users/<redact>/packages/sys/api-models/dist',
      isExtra: false
    },
    [length]: 1
  ]
}

I can recreate the same issue in @internal/core by adding a core folder to the src directory.

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