rollup-pluginutils

raw JSON →
2.8.2 verified Mon Apr 27 auth: no javascript maintenance

Utility functions commonly needed by Rollup plugins, including file filtering (createFilter), scope analysis (attachScopes), identifier sanitization (makeLegalIdentifier), data-to-ESM conversion (dataToEsm), and extension handling (addExtension). This package is at version 2.8.2 and is stable but in maintenance mode; it has been superseded by `@rollup/pluginutils` for Rollup >= 1.0. TypeScript type definitions are included. Unlike ad-hoc implementations, these utilities are optimized for Rollup's plugin lifecycle and AST walking.

error Cannot find module 'rollup-pluginutils'
cause Package not installed or incorrect import path
fix
Run npm install rollup-pluginutils@2.8.2 or if using newer Rollup, install @rollup/pluginutils.
error TypeError: createFilter is not a function
cause Default import used instead of named import
fix
Change import createFilter from 'rollup-pluginutils' to import { createFilter } from 'rollup-pluginutils'.
error Error: Could not resolve 'estree-walker'
cause Missing peer dependency estree-walker
fix
Run npm install estree-walker or ensure it is in dependencies.
error Error: AttachScopes requires an AST and identifier (like 'scope')
cause attachScopes called with missing or incorrect arguments
fix
Ensure the second argument is a string property name to attach, e.g., attachScopes(ast, 'scope').
deprecated rollup-pluginutils is deprecated in favor of @rollup/pluginutils
fix Replace rollup-pluginutils with @rollup/pluginutils and update imports (e.g., import { createFilter } from '@rollup/pluginutils').
breaking createFilter signature changed with the addition of options object (resolve option) in v2.0.0
fix If migrating from v1, pass {resolve: string} as third argument instead of a string directly. Updated docs: createFilter(include, exclude, {resolve: '/path'}).
gotcha attachScopes modifies the AST in place and expects estree-walker compatibility; it does not work with ASTs from other parsers.
fix Ensure the AST is produced by acorn (Rollup's default parser) or a compatible parser that uses the same node types.
deprecated attachScopes may be removed in future major versions; consider using @rollup/pluginutils which provides similar functionality
fix Migrate to @rollup/pluginutils and use its attachScopes function.
breaking dataToEsm namedExports option changed behavior in v2.0.0, defaulting to true instead of false
fix If you relied on namedExports being false by default, explicitly set it to false in options.
gotcha makeLegalIdentifier does not guarantee uniqueness for all patterns; collisions can occur.
fix Do not rely on makeLegalIdentifier for generating unique identifiers; it only converts non-legal characters to underscores.
deprecated Version 2.8.2 is the last release; no further updates will be published to this package.
fix Switch to @rollup/pluginutils for continued maintenance.
npm install rollup-pluginutils
yarn add rollup-pluginutils
pnpm add rollup-pluginutils

Demonstrates using createFilter to include only files under src/ and exclude node_modules, then applying a simple transform.

import { createFilter } from 'rollup-pluginutils';
import { rollup } from 'rollup';

const filter = createFilter(['src/**'], ['node_modules/**']);

async function build() {
  const bundle = await rollup({
    input: 'src/index.js',
    plugins: [{
      name: 'example',
      transform(code, id) {
        if (!filter(id)) return null;
        // transform code
        return code.replace(/__VERSION__/g, '1.0.0');
      }
    }]
  });
  await bundle.write({ file: 'dist/bundle.js', format: 'es' });
}

build().catch(err => console.error(err));