@alloc/resolve.exports
TypeScript icon, indicating that this package has built-in type declarations

1.2.1 • Public • Published

@alloc/resolve.exports

An improved version of the acclaimed resolve.exports package.

  • written in TypeScript
  • prefer readability over code golfing
  • only 50% larger than the original package (+1.5kB, unminified)
  • tests use Vitest (100% test coverage)
  • code formatted with Prettier

 

API differences

This package exports a resolveExports function, whose type signature is incompatible with the original resolve.exports package. A few options have been removed or renamed to better fit the needs of Vite.

This package has no legacy function export.

This package only throws errors for invalid exports syntax. It returns an empty array if no modules are matched.

Fallback arrays

To support the "fallback array" feature (useful for glob patterns), the resolveExports function will always return an array of paths. If no matches are found, the array will be empty.

Renamed options

The require was renamed to isRequire to match the resolve options used by Vite internals. This allows Vite to avoid creating a new object for every call to resolveExports.

Removed options

The unsafe and browser options have been removed. There is no way to replicate the behavior of unsafe in this package. The browser option was removed because I want to leave room for future platform conditions (beyond just browser and node).

Bug fixes

The following issues from resolve.exports are fixed by this package:

 

Type definitions

type ExportMapping = null | string | PackageExports | readonly ExportMapping[]
export type PackageExports = {
  [key: string]: ExportMapping
}
export type PackageJson = {
  name?: string
  exports?: ExportMapping
}
export interface ResolveExports {
  (
    pkg: PackageJson,
    entry: string,
    options?: ResolveExports.Options,
    inlineConditions?: string[]
  ): string[]
}
export namespace ResolveExports {
  export type Options = {
    /**
     * Custom conditions to match with.
     *
     * @example ['node']
     */
    conditions?: readonly string[]
    /**
     * When true, the `production` condition is used. Otherwise, the
     * `development` condition is used.
     */
    isProduction?: boolean
    /**
     * When true, the `require` condition is used. Otherwise, the
     * `import` condition is used.
     */
    isRequire?: boolean
  }
}

Package Sidebar

Install

npm i @alloc/resolve.exports

Weekly Downloads

1

Version

1.2.1

License

MIT

Unpacked Size

15.6 kB

Total Files

6

Last publish

Collaborators

  • aleclarson