Gathering detailed insights and metrics for rollup-pluginutils
Gathering detailed insights and metrics for rollup-pluginutils
Gathering detailed insights and metrics for rollup-pluginutils
Gathering detailed insights and metrics for rollup-pluginutils
@rollup/pluginutils
A set of utility functions commonly used by Rollup plugins
@jamesernator/rollup-pluginutils
Functionality commonly needed by Rollup plugins
@trusktr/rollup-pluginutils
Functionality commonly needed by Rollup plugins
@naiable/rollup-config
Use rollup like tsup, but opinionated my way.
This package has moved and is now available at @rollup/pluginutils / https://github.com/rollup/plugins
npm install rollup-pluginutils
Typescript
Module System
Node Version
NPM Version
TypeScript (85.33%)
JavaScript (14.67%)
Total Downloads
882,991,261
Last Day
576,975
Last Week
3,938,508
Last Month
21,713,332
Last Year
175,302,504
45 Stars
138 Commits
17 Forks
15 Watchers
4 Branches
23 Contributors
Updated on Feb 28, 2024
Latest Version
2.8.2
Package Id
rollup-pluginutils@2.8.2
Size
52.50 kB
NPM Version
6.11.2
Node Version
12.8.1
Published on
Sep 13, 2019
Cumulative downloads
Total Downloads
Last Day
-7.6%
576,975
Compared to previous day
Last Week
-16.5%
3,938,508
Compared to previous week
Last Month
33.8%
21,713,332
Compared to previous month
Last Year
16.3%
175,302,504
Compared to previous year
A set of functions commonly used by Rollup plugins.
1npm install --save rollup-pluginutils
1import { addExtension } from 'rollup-pluginutils'; 2 3export default function myPlugin ( options = {} ) { 4 return { 5 resolveId ( code, id ) { 6 // only adds an extension if there isn't one already 7 id = addExtension( id ); // `foo` -> `foo.js`, `foo.js -> foo.js` 8 id = addExtension( id, '.myext' ); // `foo` -> `foo.myext`, `foo.js -> `foo.js` 9 } 10 }; 11}
This function attaches Scope
objects to the relevant nodes of an AST. Each Scope
object has a scope.contains(name)
method that returns true
if a given name is defined in the current scope or a parent scope.
See rollup-plugin-inject or rollup-plugin-commonjs for an example of usage.
1import { attachScopes } from 'rollup-pluginutils'; 2import { walk } from 'estree-walker'; 3 4export default function myPlugin ( options = {} ) { 5 return { 6 transform ( code ) { 7 const ast = this.parse( code ); 8 9 let scope = attachScopes( ast, 'scope' ); 10 11 walk( ast, { 12 enter ( node ) { 13 if ( node.scope ) scope = node.scope; 14 15 if ( !scope.contains( 'foo' ) ) { 16 // `foo` is not defined, so if we encounter it, 17 // we assume it's a global 18 } 19 }, 20 leave ( node ) { 21 if ( node.scope ) scope = scope.parent; 22 } 23 }); 24 } 25 }; 26}
1import { createFilter } from 'rollup-pluginutils'; 2 3export default function myPlugin ( options = {} ) { 4 // `options.include` and `options.exclude` can each be a minimatch 5 // pattern, or an array of minimatch patterns, relative to process.cwd() 6 var filter = createFilter( options.include, options.exclude ); 7 8 return { 9 transform ( code, id ) { 10 // if `options.include` is omitted or has zero length, filter 11 // will return `true` by default. Otherwise, an ID must match 12 // one or more of the minimatch patterns, and must not match 13 // any of the `options.exclude` patterns. 14 if ( !filter( id ) ) return; 15 16 // proceed with the transformation... 17 } 18 }; 19}
If you want to resolve the patterns against a directory other than
process.cwd()
, you can additionally pass a resolve
option:
1var filter = createFilter( options.include, options.exclude, {resolve: '/my/base/dir'} )
If resolve
is a string, then this value will be used as the base directory.
Relative paths will be resolved against process.cwd()
first. If resolve
is
false
, then the patterns will not be resolved against any directory. This can
be useful if you want to create a filter for virtual module names.
1import { makeLegalIdentifier } from 'rollup-pluginutils'; 2 3makeLegalIdentifier( 'foo-bar' ); // 'foo_bar' 4makeLegalIdentifier( 'typeof' ); // '_typeof'
Helper for treeshakable data imports
1import { dataToEsm } from 'rollup-pluginutils'; 2 3const esModuleSource = dataToEsm({ 4 custom: 'data', 5 to: ['treeshake'] 6}, { 7 compact: false, 8 indent: '\t', 9 preferConst: false, 10 objectShorthand: false, 11 namedExports: true 12}); 13/* 14Outputs the string ES module source: 15 export const custom = 'data'; 16 export const to = ['treeshake']; 17 export default { custom, to }; 18*/
Extract the names of all assignment targets from patterns.
1import { extractAssignedNames } from 'rollup-pluginutils'; 2import { walk } from 'estree-walker'; 3 4export default function myPlugin ( options = {} ) { 5 return { 6 transform ( code ) { 7 const ast = this.parse( code ); 8 9 walk( ast, { 10 enter ( node ) { 11 if ( node.type === 'VariableDeclarator' ) { 12 const declaredNames = extractAssignedNames(node.id); 13 // do something with the declared names 14 // e.g. for `const {x, y: z} = ... => declaredNames = ['x', 'z'] 15 } 16 } 17 }); 18 } 19 }; 20}
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
Found 4/25 approved changesets -- score normalized to 1
Reason
project is archived
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
license file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
54 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More