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
99.2
Supply Chain
99.6
Quality
80.9
Maintenance
100
Vulnerability
100
License
TypeScript (85.33%)
JavaScript (14.67%)
Total Downloads
780,236,327
Last Day
353,468
Last Week
2,853,648
Last Month
13,576,641
Last Year
151,961,576
45 Stars
138 Commits
17 Forks
16 Watching
4 Branches
23 Contributors
Minified
Minified + Gzipped
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
Publised On
13 Sept 2019
Cumulative downloads
Total Downloads
Last day
-31.7%
353,468
Compared to previous day
Last week
-2.2%
2,853,648
Compared to previous week
Last month
-14%
13,576,641
Compared to previous month
Last year
-7.9%
151,961,576
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
project is not fuzzed
Details
Reason
license file not detected
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
51 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-12-16
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