Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Declare subpath exports for bundled plugins, Eleventy-maintained data, etc. #3460

Open
noelforte opened this issue Sep 27, 2024 · 0 comments

Comments

@noelforte
Copy link

noelforte commented Sep 27, 2024

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

Upfront note: I'd be willing to submit a PR to help out with this.

Commit c505822 inadvertantly introduced some breaking changes to subpath exports when Eleventy is consumed as a dependency. By adding the exports key to package.json with only 1 conditional import (import/requre keys), any attempt to import a subpath throws an error.

Describe the solution you'd like

This is more specific to @11ty/eleventy/src/Engines/Util/ContextAugmenter.js (#3355 (comment)) but is applicable to any exports in Eleventy that could be consumed by outside packages, including (but not limited to):

  • Plugins bundled with Eleventy
  • .d.ts declaration files (#3097, #3296)
  • Eleventy-maintained global data and methods like augmentKeys

Syntax I'm thinking of could be something like:

"exports": {
  ".": {
    "import": "./src/Eleventy.js",
    "require": "./src/EleventyCommonJs.cjs",
  },
  "./user-config": {
    "types": "./types/UserConfig.d.ts"
  },
  "./plugins/*": "./src/Plugins/*",
}

The above declarations can be consumed as so:

import type UserConfig from '@11ty/eleventy/user-config';
import Eleventy from '@11ty/eleventy';
import HtmlBasePlugin from '@11ty/eleventy/plugins/HtmlBasePlugin.js';
// ...

Or via an aggregator:

"exports": {
  "./internal-plugins/*": "./src/Plugins/index.js",
}
import {
  HtmlBasePlugin,
  RenderPlugin,
  InputPathToUrlPlugin,
} from '@11ty/eleventy/internal-plugins';

Describe alternatives you've considered

no response

Additional context

Subpath exports are supported by Node 18 which is the required minimum for 3.0. Additionally, when an exports field is present the main field isn't looked at by Node.js except in the case of require() statements, but with a exports[path].require field it's redundant to have for Node 18+.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant