Skip to content

node-resolve: allow more granular config of preferBuiltins #1655

@davidje13

Description

@davidje13
  • Rollup Plugin Name: @rollup/node-resolve
  • Rollup Plugin Version: 15.2.3

Feature Use Case

Some NodeJS builtins (e.g. punycode) are deprecated, and replacement packages with the same name exist in NPM. It is desirable to have preferBuiltins set to false for these specific cases, while keeping it true for all other builtins (e.g. string_decoder is also available as both a builtin and a package, but in this case the builtin is stable and should be preferred).

Feature Proposal

Allow preferBuiltins to accept a regex, array, or function, matching the behaviour of e.g. external. The relevant code is already considering these on an import-by-import basis, so it should be possible without any restructuring needed.

For example, the config for the punycode example above could be:

nodeResolve({
  preferBuiltins: (module) => module !== 'punycode',
})

(perhaps an even better API would be to reverse the config, preferring builtins by default and offering a preferModules config, since that would allow preferModules: ['punycode'], but that is not backwards-compatible, or at least introduces ambiguity if both options are used)

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