🍣 The one-stop shop for official Rollup plugins
Installations
npm install @rollup/pluginutils
Developer Guide
Typescript
Yes
Module System
CommonJS, ESM
Min. Node Version
>=14.0.0
Node Version
20.18.1
NPM Version
10.8.2
Score
56.3
Supply Chain
100
Quality
88
Maintenance
100
Vulnerability
99.6
License
Releases
Unable to fetch releases
Contributors
Languages
JavaScript (75.11%)
TypeScript (24.88%)
Shell (0.01%)
Developer
rollup
Download Statistics
Total Downloads
1,848,327,488
Last Day
2,078,503
Last Week
15,539,083
Last Month
70,651,446
Last Year
766,361,826
GitHub Statistics
3,659 Stars
1,207 Commits
593 Forks
36 Watching
4 Branches
266 Contributors
Bundle Size
27.95 kB
Minified
10.08 kB
Minified + Gzipped
Package Meta Information
Latest Version
5.1.4
Package Id
@rollup/pluginutils@5.1.4
Unpacked Size
56.99 kB
Size
9.40 kB
File Count
8
NPM Version
10.8.2
Node Version
20.18.1
Publised On
15 Dec 2024
Total Downloads
Cumulative downloads
Total Downloads
1,848,327,488
Last day
-33.9%
2,078,503
Compared to previous day
Last week
-8.5%
15,539,083
Compared to previous week
Last month
-3.4%
70,651,446
Compared to previous month
Last year
37.4%
766,361,826
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
3
Peer Dependencies
1
@rollup/pluginutils
A set of utility functions commonly used by 🍣 Rollup plugins.
Requirements
The plugin utils require an LTS Node version (v14.0.0+) and Rollup v1.20.0+.
Install
Using npm:
1npm install @rollup/pluginutils --save-dev
Usage
1import utils from '@rollup/pluginutils'; 2//...
API
Available utility functions are listed below:
Note: Parameter names immediately followed by a ?
indicate that the parameter is optional.
addExtension
Adds an extension to a module ID if one does not exist.
Parameters: (filename: String, ext?: String)
Returns: String
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}
attachScopes
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.
Parameters: (ast: Node, propertyName?: String)
Returns: Object
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}
createFilter
Constructs a filter function which can be used to determine whether or not certain modules should be operated upon.
Parameters: (include?: <picomatch>, exclude?: <picomatch>, options?: Object)
Returns: (id: string | unknown) => boolean
include
and exclude
Type: String | RegExp | Array[...String|RegExp]
A valid picomatch
pattern, or array of patterns. If options.include
is omitted or has zero length, filter will return true
by default. Otherwise, an ID must match one or more of the picomatch
patterns, and must not match any of the options.exclude
patterns.
Note that picomatch
patterns are very similar to minimatch
patterns, and in most use cases, they are interchangeable. If you have more specific pattern matching needs, you can view this comparison table to learn more about where the libraries differ.
options
resolve
Type: String | Boolean | null
Optionally resolves the patterns against a directory other than process.cwd()
. If a String
is specified, then the value will be used as the base directory. Relative paths will be resolved against process.cwd()
first. If 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.
Usage
1import { createFilter } from '@rollup/pluginutils'; 2 3export default function myPlugin(options = {}) { 4 // assume that the myPlugin accepts options of `options.include` and `options.exclude` 5 var filter = createFilter(options.include, options.exclude, { 6 resolve: '/my/base/dir' 7 }); 8 9 return { 10 transform(code, id) { 11 if (!filter(id)) return; 12 13 // proceed with the transformation... 14 } 15 }; 16}
dataToEsm
Transforms objects into tree-shakable ES Module imports.
Parameters: (data: Object, options: DataToEsmOptions)
Returns: String
data
Type: Object
An object to transform into an ES module.
options
Type: DataToEsmOptions
Note: Please see the TypeScript definition for complete documentation of these options
Usage
1import { dataToEsm } from '@rollup/pluginutils'; 2 3const esModuleSource = dataToEsm( 4 { 5 custom: 'data', 6 to: ['treeshake'] 7 }, 8 { 9 compact: false, 10 indent: '\t', 11 preferConst: true, 12 objectShorthand: true, 13 namedExports: true, 14 includeArbitraryNames: false 15 } 16); 17/* 18Outputs the string ES module source: 19 export const custom = 'data'; 20 export const to = ['treeshake']; 21 export default { custom, to }; 22*/
extractAssignedNames
Extracts the names of all assignment targets based upon specified patterns.
Parameters: (param: Node)
Returns: Array[...String]
param
Type: Node
An acorn
AST Node.
Usage
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}
makeLegalIdentifier
Constructs a bundle-safe identifier from a String
.
Parameters: (str: String)
Returns: String
Usage
1import { makeLegalIdentifier } from '@rollup/pluginutils'; 2 3makeLegalIdentifier('foo-bar'); // 'foo_bar' 4makeLegalIdentifier('typeof'); // '_typeof'
normalizePath
Converts path separators to forward slash.
Parameters: (filename: String)
Returns: String
Usage
1import { normalizePath } from '@rollup/pluginutils'; 2 3normalizePath('foo\\bar'); // 'foo/bar' 4normalizePath('foo/bar'); // 'foo/bar'
Meta
No vulnerabilities found.
Reason
30 commit(s) and 5 issue activity found in the last 90 days -- score normalized to 10
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
binaries present in source code
Details
- Warn: binary detected: packages/wasm/test/fixtures/complex.wasm:1
- Warn: binary detected: packages/wasm/test/fixtures/imports.wasm:1
- Warn: binary detected: packages/wasm/test/fixtures/sample.wasm:1
Reason
Found 13/30 approved changesets -- score normalized to 4
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/node-windows.yml:1
- Warn: no topLevel permission defined: .github/workflows/pr-title.yml:1
- Warn: no topLevel permission defined: .github/workflows/release.yml:1
- Warn: no topLevel permission defined: .github/workflows/validate.yml:1
- Info: no jobLevel write permissions found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node-windows.yml:28: update your workflow using https://app.stepsecurity.io/secureworkflow/rollup/plugins/node-windows.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node-windows.yml:36: update your workflow using https://app.stepsecurity.io/secureworkflow/rollup/plugins/node-windows.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/pr-title.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/rollup/plugins/pr-title.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/rollup/plugins/release.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:33: update your workflow using https://app.stepsecurity.io/secureworkflow/rollup/plugins/release.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:47: update your workflow using https://app.stepsecurity.io/secureworkflow/rollup/plugins/release.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:55: update your workflow using https://app.stepsecurity.io/secureworkflow/rollup/plugins/release.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/validate.yml:26: update your workflow using https://app.stepsecurity.io/secureworkflow/rollup/plugins/validate.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/validate.yml:34: update your workflow using https://app.stepsecurity.io/secureworkflow/rollup/plugins/validate.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/validate.yml:47: update your workflow using https://app.stepsecurity.io/secureworkflow/rollup/plugins/validate.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/validate.yml:55: update your workflow using https://app.stepsecurity.io/secureworkflow/rollup/plugins/validate.yml/master?enable=pin
- Info: 0 out of 10 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 third-party GitHubAction dependencies pinned
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 14 are checked with a SAST tool
Reason
16 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-4gmj-3p3h-gm8h
- Warn: Project is vulnerable to: GHSA-9pv7-vfvm-6vr7
- Warn: Project is vulnerable to: GHSA-rc47-6667-2j5j
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-3rfm-jhwj-7488
- Warn: Project is vulnerable to: GHSA-hhq3-ff78-jv3g
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55
- Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j
- Warn: Project is vulnerable to: GHSA-vm32-9rqf-rh3r
- Warn: Project is vulnerable to: GHSA-7fh5-64p2-3v2j
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
Score
3.9
/10
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 MoreOther packages similar to @rollup/pluginutils
rollup-pluginutils
Functionality commonly needed 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.