Skip to content

Unbuilt self-package-name-imports #126

@ef4

Description

@ef4

It's nice to allow addons to import themselves by name, especially so that their tests and demos are importing things the same way a consuming app would, which aids learning.

The main reason it doesn't already work nicely is that package.json exports points at dist, not src.

One option is to create a dedicated export condition:

"exports": {
    ".": {
      "addon-development": "./src/index.ts",
      "default": "./dist/index.js"
    },

which can be enabled in vite.config.js like:

resolve: {
  conditions: ['addon-development']
}

However, I realized this creates a hazard. When your addon is consumed by another addon, that addon may also opt into the "addon-development" condition and then it will try to consume your unbuilt sources, which is definitely not desirable.

So it seems that if we want to use this pattern, we'd have to either put the package name into the condition name:

"exports": {
    ".": {
      "developing-@ef4/example-package": "./src/index.ts",
      "default": "./dist/index.js"
    },

Or have a prepublish step that deletes these extra conditions so that people installing your package never see them.

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