{"name":"@rollup/pluginutils","version":"5.1.4","keywords":["rollup","plugin","utils"],"author":{"name":"Rich Harris","email":"richard.a.harris@gmail.com"},"license":"MIT","_id":"@rollup/pluginutils@5.1.4","maintainers":[{"name":"shellscape","email":"andrew@shellscape.org"},{"name":"rich_harris","email":"richard.a.harris@gmail.com"},{"name":"guybedford","email":"guybedford@gmail.com"},{"name":"lukastaegert","email":"lukas.taegert@tngtech.com"}],"homepage":"https://github.com/rollup/plugins/tree/master/packages/pluginutils#readme","bugs":{"url":"https://github.com/rollup/plugins/issues"},"ava":{"files":["!**/fixtures/**","!**/helpers/**","!**/recipes/**","!**/types.ts"],"require":["ts-node/register"],"extensions":["ts"],"workerThreads":false},"nyc":{"extension":[".js",".ts"]},"dist":{"shasum":"bb94f1f9eaaac944da237767cdfee6c5b2262d4a","tarball":"http://registry-npm.ywwl.com/@rollup/pluginutils/download/@rollup/pluginutils-5.1.4.tgz","fileCount":8,"integrity":"sha512-USm05zrsFxYLPdWWq+K3STlWiT/3ELn3RcV5hJMghpeAIhxfsUIg6mt12CBJBInWMV4VneoV7SfGv8xIwo2qNQ==","signatures":[{"sig":"MEYCIQDY3Vs+lXLalMi2D5+FcXJFTWfnSvHjXE3OTHE8nDXAiAIhAJ9K+oz/+Y1N2/srlZoYyaKRmUe7AumCKhjRza5l98g6","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":58354,"size":9622,"noattachment":false,"key":"/@rollup/pluginutils/-/@rollup/pluginutils-5.1.4.tgz"},"main":"./dist/cjs/index.js","type":"commonjs","_from":"file:rollup-pluginutils-5.1.4.tgz","types":"./types/index.d.ts","module":"./dist/es/index.js","engines":{"node":">=14.0.0"},"exports":{"types":"./types/index.d.ts","import":"./dist/es/index.js","default":"./dist/cjs/index.js"},"scripts":{"test":"ava","build":"rollup -c","ci:lint":"pnpm build && pnpm lint","ci:test":"pnpm test -- --verbose","pretest":"pnpm build --sourcemap","release":"pnpm --workspace-root package:release $(pwd)","test:ts":"tsc --noEmit","prebuild":"del-cli dist","prerelease":"pnpm build","ci:coverage":"nyc pnpm test && nyc report --reporter=text-lcov > coverage.lcov","ci:lint:commits":"commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}"},"_npmUser":{"name":"shellscape","email":"andrew@shellscape.org"},"_resolved":"/tmp/db2e948905eb7be7d08df60e0279fbed/rollup-pluginutils-5.1.4.tgz","_integrity":"sha512-USm05zrsFxYLPdWWq+K3STlWiT/3ELn3RcV5hJMghpeAIhxfsUIg6mt12CBJBInWMV4VneoV7SfGv8xIwo2qNQ==","repository":{"url":"git+https://github.com/rollup/plugins.git","directory":"packages/pluginutils"},"_npmVersion":"10.8.2","description":"A set of utility functions commonly used by Rollup plugins","directories":{},"_nodeVersion":"20.18.1","dependencies":{"picomatch":"^4.0.2","@types/estree":"^1.0.0","estree-walker":"^2.0.2"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"acorn":"^8.8.0","rollup":"^4.0.0-24","typescript":"^4.8.3","@types/node":"^14.18.30","@types/picomatch":"^2.3.0","@rollup/plugin-commonjs":"^23.0.0","@rollup/plugin-typescript":"^9.0.1","@rollup/plugin-node-resolve":"^15.0.0"},"peerDependencies":{"rollup":"^1.20.0||^2.0.0||^3.0.0||^4.0.0"},"peerDependenciesMeta":{"rollup":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/pluginutils_5.1.4_1734279408306_0.9109670353872381","host":"s3://npm-registry-packages-npm-production"},"readme":"[npm]: https://img.shields.io/npm/v/@rollup/pluginutils\n[npm-url]: https://www.npmjs.com/package/@rollup/pluginutils\n[size]: https://packagephobia.now.sh/badge?p=@rollup/pluginutils\n[size-url]: https://packagephobia.now.sh/result?p=@rollup/pluginutils\n\n[![npm][npm]][npm-url]\n[![size][size]][size-url]\n[![libera manifesto](https://img.shields.io/badge/libera-manifesto-lightgrey.svg)](https://liberamanifesto.com)\n\n# @rollup/pluginutils\n\nA set of utility functions commonly used by 🍣 Rollup plugins.\n\n## Requirements\n\nThe plugin utils require an [LTS](https://github.com/nodejs/Release) Node version (v14.0.0+) and Rollup v1.20.0+.\n\n## Install\n\nUsing npm:\n\n```console\nnpm install @rollup/pluginutils --save-dev\n```\n\n## Usage\n\n```js\nimport utils from '@rollup/pluginutils';\n//...\n```\n\n## API\n\nAvailable utility functions are listed below:\n\n_Note: Parameter names immediately followed by a `?` indicate that the parameter is optional._\n\n### addExtension\n\nAdds an extension to a module ID if one does not exist.\n\nParameters: `(filename: String, ext?: String)`<br>\nReturns: `String`\n\n```js\nimport { addExtension } from '@rollup/pluginutils';\n\nexport default function myPlugin(options = {}) {\n  return {\n    resolveId(code, id) {\n      // only adds an extension if there isn't one already\n      id = addExtension(id); // `foo` -> `foo.js`, `foo.js` -> `foo.js`\n      id = addExtension(id, '.myext'); // `foo` -> `foo.myext`, `foo.js` -> `foo.js`\n    }\n  };\n}\n```\n\n### attachScopes\n\nAttaches `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.\n\nParameters: `(ast: Node, propertyName?: String)`<br>\nReturns: `Object`\n\nSee [@rollup/plugin-inject](https://github.com/rollup/plugins/tree/master/packages/inject) or [@rollup/plugin-commonjs](https://github.com/rollup/plugins/tree/master/packages/commonjs) for an example of usage.\n\n```js\nimport { attachScopes } from '@rollup/pluginutils';\nimport { walk } from 'estree-walker';\n\nexport default function myPlugin(options = {}) {\n  return {\n    transform(code) {\n      const ast = this.parse(code);\n\n      let scope = attachScopes(ast, 'scope');\n\n      walk(ast, {\n        enter(node) {\n          if (node.scope) scope = node.scope;\n\n          if (!scope.contains('foo')) {\n            // `foo` is not defined, so if we encounter it,\n            // we assume it's a global\n          }\n        },\n        leave(node) {\n          if (node.scope) scope = scope.parent;\n        }\n      });\n    }\n  };\n}\n```\n\n### createFilter\n\nConstructs a filter function which can be used to determine whether or not certain modules should be operated upon.\n\nParameters: `(include?: <picomatch>, exclude?: <picomatch>, options?: Object)`<br>\nReturns: `(id: string | unknown) => boolean`\n\n#### `include` and `exclude`\n\nType: `String | RegExp | Array[...String|RegExp]`<br>\n\nA valid [`picomatch`](https://github.com/micromatch/picomatch#globbing-features) 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.\n\nNote that `picomatch` patterns are very similar to [`minimatch`](https://github.com/isaacs/minimatch#readme) patterns, and in most use cases, they are interchangeable. If you have more specific pattern matching needs, you can view [this comparison table](https://github.com/micromatch/picomatch#library-comparisons) to learn more about where the libraries differ.\n\n#### `options`\n\n##### `resolve`\n\nType: `String | Boolean | null`\n\nOptionally 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.\n\n#### Usage\n\n```js\nimport { createFilter } from '@rollup/pluginutils';\n\nexport default function myPlugin(options = {}) {\n  // assume that the myPlugin accepts options of `options.include` and `options.exclude`\n  var filter = createFilter(options.include, options.exclude, {\n    resolve: '/my/base/dir'\n  });\n\n  return {\n    transform(code, id) {\n      if (!filter(id)) return;\n\n      // proceed with the transformation...\n    }\n  };\n}\n```\n\n### dataToEsm\n\nTransforms objects into tree-shakable ES Module imports.\n\nParameters: `(data: Object, options: DataToEsmOptions)`<br>\nReturns: `String`\n\n#### `data`\n\nType: `Object`\n\nAn object to transform into an ES module.\n\n#### `options`\n\nType: `DataToEsmOptions`\n\n_Note: Please see the TypeScript definition for complete documentation of these options_\n\n#### Usage\n\n```js\nimport { dataToEsm } from '@rollup/pluginutils';\n\nconst esModuleSource = dataToEsm(\n  {\n    custom: 'data',\n    to: ['treeshake']\n  },\n  {\n    compact: false,\n    indent: '\\t',\n    preferConst: true,\n    objectShorthand: true,\n    namedExports: true,\n    includeArbitraryNames: false\n  }\n);\n/*\nOutputs the string ES module source:\n  export const custom = 'data';\n  export const to = ['treeshake'];\n  export default { custom, to };\n*/\n```\n\n### extractAssignedNames\n\nExtracts the names of all assignment targets based upon specified patterns.\n\nParameters: `(param: Node)`<br>\nReturns: `Array[...String]`\n\n#### `param`\n\nType: `Node`\n\nAn `acorn` AST Node.\n\n#### Usage\n\n```js\nimport { extractAssignedNames } from '@rollup/pluginutils';\nimport { walk } from 'estree-walker';\n\nexport default function myPlugin(options = {}) {\n  return {\n    transform(code) {\n      const ast = this.parse(code);\n\n      walk(ast, {\n        enter(node) {\n          if (node.type === 'VariableDeclarator') {\n            const declaredNames = extractAssignedNames(node.id);\n            // do something with the declared names\n            // e.g. for `const {x, y: z} = ...` => declaredNames = ['x', 'z']\n          }\n        }\n      });\n    }\n  };\n}\n```\n\n### exactRegex\n\nConstructs a RegExp that matches the exact string specified. This is useful for plugin hook filters.\n\nParameters: `(str: String | Array[...String], flags?: String)`<br>\nReturns: `RegExp`\n\n#### Usage\n\n```js\nimport { exactRegex } from '@rollup/pluginutils';\n\nexactRegex('foobar'); // /^foobar$/\nexactRegex(['foo', 'bar']); // /^(?:foo|bar)$/\nexactRegex('foo(bar)', 'i'); // /^foo\\(bar\\)$/i\n```\n\n### makeLegalIdentifier\n\nConstructs a bundle-safe identifier from a `String`.\n\nParameters: `(str: String)`<br>\nReturns: `String`\n\n#### Usage\n\n```js\nimport { makeLegalIdentifier } from '@rollup/pluginutils';\n\nmakeLegalIdentifier('foo-bar'); // 'foo_bar'\nmakeLegalIdentifier('typeof'); // '_typeof'\n```\n\n### normalizePath\n\nConverts path separators to forward slash.\n\nParameters: `(filename: String)`<br>\nReturns: `String`\n\n#### Usage\n\n```js\nimport { normalizePath } from '@rollup/pluginutils';\n\nnormalizePath('foo\\\\bar'); // 'foo/bar'\nnormalizePath('foo/bar'); // 'foo/bar'\n```\n\n### prefixRegex\n\nConstructs a RegExp that matches a value that has the specified prefix. This is useful for plugin hook filters.\n\nParameters: `(str: String | Array[...String], flags?: String)`<br>\nReturns: `RegExp`\n\n#### Usage\n\n```js\nimport { prefixRegex } from '@rollup/pluginutils';\n\nprefixRegex('foobar'); // /^foobar/\nprefixRegex(['foo', 'bar']); // /^(?:foo|bar)/\nprefixRegex('foo(bar)', 'i'); // /^foo\\(bar\\)/i\n```\n\n### suffixRegex\n\nConstructs a RegExp that matches a value that has the specified suffix. This is useful for plugin hook filters.\n\nParameters: `(str: String | Array[...String], flags?: String)`<br>\nReturns: `RegExp`\n\n#### Usage\n\n```js\nimport { suffixRegex } from '@rollup/pluginutils';\n\nsuffixRegex('foobar'); // /foobar$/\nsuffixRegex(['foo', 'bar']); // /(?:foo|bar)$/\nsuffixRegex('foo(bar)', 'i'); // /foo\\(bar\\)$/i\n```\n\n## Meta\n\n[CONTRIBUTING](/.github/CONTRIBUTING.md)\n\n[LICENSE (MIT)](/LICENSE)\n","publish_time":1734279408510,"_cnpm_publish_time":1734279408510,"dist-tags":{"latest":"5.5.1"}}