Gathering detailed insights and metrics for rollup-pluginutils
Approximately 800 new packages are uploaded to the npm registry every day. This number can vary, but it reflects the active and growing nature of the JavaScript development community.
Gathering detailed insights and metrics for rollup-pluginutils
Approximately 800 new packages are uploaded to the npm registry every day. This number can vary, but it reflects the active and growing nature of the JavaScript development community.
npm install rollup-pluginutils
99.2
Supply Chain
99.6
Quality
80.9
Maintenance
100
Vulnerability
100
License
45 Stars
138 Commits
17 Forks
16 Watching
4 Branches
23 Contributors
Updated on 28 Feb 2024
TypeScript (85.33%)
JavaScript (14.67%)
Cumulative downloads
Total Downloads
Last day
31.6%
759,065
Compared to previous day
Last week
11.6%
4,562,870
Compared to previous week
Last month
27.3%
15,948,900
Compared to previous month
Last year
-10.2%
150,348,848
Compared to previous year
This package has moved and is now available at @rollup/pluginutils. Please update your dependencies. This repository is no longer maintained.
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
project is not fuzzed
Details
Reason
security policy file not detected
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-11-18
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@rollup/pluginutils
A set of utility functions commonly used by Rollup plugins
@naiable/rollup-config
Use rollup like tsup, but opinionated my way.
@jamesernator/rollup-pluginutils
Functionality commonly needed by Rollup plugins
@trusktr/rollup-pluginutils
Functionality commonly needed by Rollup plugins