Skip to content

Content mappers: a relative package path loads the package.json of the nearest folder with node_modulesΒ #65097

Closed

Description

@onmax

πŸ”Ž Search Terms

content mapper, contentMappers, package, relative path, TS18077, TS18075

πŸ•— Version & Regression Information

  • 7.1.0-beta and 7.1.0-dev.20261101.1
  • Content mappers are new in 7.1, so this isn't a regression.

⏯ Playground Link

Repro: https://github.com/onmax/repros/tree/repro/typescript-content-mapper-relative-package/typescript-content-mapper-relative-package

git clone --branch repro/typescript-content-mapper-relative-package https://github.com/onmax/repros
cd repros/typescript-content-mapper-relative-package
pnpm install && pnpm verify

πŸ’» Code

// project/tsconfig.json, beside mapper/, which has a package.json named "txt-mapper"
{
  "contentMappers": [{ "package": "../mapper", "extensions": [".txt"] }]
}

πŸ™ Actual behavior

project/tsconfig.json(3,35): error TS18077: The 'package.json' of the content mapper package '../mapper' does not specify a 'name'.

The package.json it read is the fixture root's, which has no name. "../does-not-exist" gives the same error. When that folder's package.json declares a content mapper, as in a package's own tests, that mapper runs without any error.

πŸ™‚ Expected behavior

Either ../mapper resolves against the tsconfig's folder and loads mapper/, or it fails with TS18075 because only package names are supported.

Additional information about the issue

resolveContentMapperManifest passes the field to ResolvePackageDirectory. ParsePackageName returns .. as the package name, so the check that the package folder exists becomes DirectoryExists("<dir>/node_modules/.."), which passes in the first ancestor with a node_modules. The rest of the path is never read.

The same mapper referenced as "package": "txt-mapper" works; the repro checks both.

Metadata

Metadata

Labels

Needs InvestigationThis issue needs a team member to investigate its status.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions