Skip to content

all, one, etc should be re-exported in main index.js? #53

@ignatiusreza

Description

@ignatiusreza

Initial checklist

  • I read the support docs
  • I read the contributing guide
  • I agree to follow the code of conduct
  • I searched issues and couldn’t find anything (or linked relevant results below)

Subject

The exported toHast support passing options.handlers to provide customized logic to process certain node. The documentation for this options suggest to "Take a look at lib/handlers/ for examples.".

Most of the handlers under lib/handlers/ are written using the helper function all, one, etc. So it seems quite reasonable for custom handlers to also want to use those helper functions.

Problem

Pre-ESM migration, we can import/require directly from mdast-util-to-hast/lib/all and it will worked.

Post-ESM migration, .mjs file can't import from mdast-util-to-hast/lib/all.js since it is written using esm syntax, but does not have .mjs extension (seems like for direct file import, the type: module config in package.json is ignored?)

Solution

in index.js, we should reexport the helper functions

export {all} from './lib/all.js'
export {one} from './lib/one.js'
export {toHast} from './lib/index.js'

so that we can import it like import { all, toHash } from 'mdast-util-to-hast';..

Alternatives

Copy+paste the helper functions?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions