Skip to content
This repository was archived by the owner on Sep 2, 2023. It is now read-only.
This repository was archived by the owner on Sep 2, 2023. It is now read-only.

Subpath extension patterns and wildcard expansions #535

Closed
@guybedford

Description

@guybedford

With package exports, it is ambiguous whether users should use extensions, as the author can define whatever they like:

{
  "exports": {
    "./feature.js": "./dist/feature.js",
    "./feature": "./dist/feature.js"
  }
}

as a result it seems likely that packages will have their own preferences here and we might see mixed patterns, unless we want to try and create some wider guidance.

Question: Should we encourage package authors to use extensions or not in subpaths for exports?

Furthermore, when using path exports it means that packages absolutely have to use extensions since:

{
  "exports": {
    "./features/": "./dist/features/"
  }
}

requires each pkg/features/x.js subpath to have an explicit extension.

One might argue that explicitly listing the exports could be an alternative here, but for example I recently provided an exports PR to a package with hundreds of individual components here - carbon-design-system/carbon-web-components#443.

In this case, the package absolutely must require its users to use extensions, and that is the only option practically.

Question: Are we ok with packages therefore having reason to sometimes have users use extensions in subpaths and sometimes not?

One thought here is that if a package wanted to maintain an extensionless interface, we could support this via a wildcard expansion of exports:

{
  "exports": {
    "./features/": "./dist/features/*.js"
  }
}

This would effectively be a sugar for globbing the RHS and treating it as if each entry were a separate entry in exports, but helps when there are hundreds that would be impractical to manually maintain.

When it comes to interop with import maps, the pattern would be that the import map only needs to include those mappings actually in use by the app - just because a component lib has 100s of components, doesn't mean you necessarily need every single one.

The risk is the complexity of users not necessarily knowing the difference beteween path exports and wildcard expansions when it comes to the import map implications.

Question: Would wildcard expansions be a useful feature for encouraging extensionless subpath patterns?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions