Skip to content

Package.json exports field: Differentiate between ./* and ./*/ #39994

@ctjlewis

Description

@ctjlewis

Is your feature request related to a problem? Please describe.

Yes. I would like to be able to statically resolve entry points to path/*/index.js and path/*.js, similar to how is done in CJS, e.g. by adding a trailing slash to the match pattern like so:

"exports": {
  "./package.json": "./package.json",
  ".": "./dist/index.js",
  "./*/": "./dist/*/index.js",
  "./*": "./dist/*.js"
},

This would allow interop with traditional indexing:

import 'my-package/path/to/dir/'
// resolves to `my-package/path/to/dir/index.js`

import 'my-package/path/to/dir/module'`
// resolves to `my-package/path/to/dir/module.js`

This is currently not feasible as I understand it, and it would be necessary to import via import '.../index.js' regardless of how the exports field is configured.

Describe the solution you'd like

Modify exports field logic to differentiate between ./* and ./*/.

Allow a single pattern to have multiple matches, either via:

"exports": {
  "./package.json": "./package.json",
  ".": "./dist/index.js",
  "./*": "./dist/*/index.js",
  "./*": "./dist/*.js"
},

Or:

"exports": {
  "./package.json": "./package.json",
  ".": "./dist/index.js",
  "./*": ["./dist/*/index.js", "./dist/*.js"]
},

Metadata

Metadata

Assignees

No one assigned

    Labels

    moduleIssues and PRs related to the module subsystem.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions