{"id":13448622,"url":"https://github.com/rollup/rollup-pluginutils","last_synced_at":"2025-03-22T09:31:29.953Z","repository":{"id":57120132,"uuid":"44849666","full_name":"rollup/rollup-pluginutils","owner":"rollup","description":"This package has moved and is now available at @rollup/pluginutils / https://github.com/rollup/plugins","archived":true,"fork":false,"pushed_at":"2019-12-31T00:00:43.000Z","size":592,"stargazers_count":45,"open_issues_count":0,"forks_count":17,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-03-16T16:42:16.591Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rollup.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-10-24T02:56:00.000Z","updated_at":"2024-02-28T14:57:34.000Z","dependencies_parsed_at":"2022-08-24T05:40:28.026Z","dependency_job_id":null,"html_url":"https://github.com/rollup/rollup-pluginutils","commit_stats":null,"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rollup%2Frollup-pluginutils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rollup%2Frollup-pluginutils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rollup%2Frollup-pluginutils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rollup%2Frollup-pluginutils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rollup","download_url":"https://codeload.github.com/rollup/rollup-pluginutils/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244937751,"owners_count":20535124,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T05:01:50.834Z","updated_at":"2025-03-22T09:31:29.626Z","avatar_url":"https://github.com/rollup.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# Moved\n\nThis package has moved and is now available at [@rollup/pluginutils](https://github.com/rollup/plugins). Please update your dependencies. This repository is no longer maintained.\n\n# rollup-pluginutils\n\nA set of functions commonly used by Rollup plugins.\n\n\n## Installation\n\n```bash\nnpm install --save rollup-pluginutils\n```\n\n\n## Usage\n\n### addExtension\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` -\u003e `foo.js`, `foo.js -\u003e foo.js`\n      id = addExtension( id, '.myext' ); // `foo` -\u003e `foo.myext`, `foo.js -\u003e `foo.js`\n    }\n  };\n}\n```\n\n\n### attachScopes\n\nThis 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.\n\nSee [rollup-plugin-inject](https://github.com/rollup/rollup-plugin-inject) or [rollup-plugin-commonjs](https://github.com/rollup/rollup-plugin-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\n### createFilter\n\n```js\nimport { createFilter } from 'rollup-pluginutils';\n\nexport default function myPlugin ( options = {} ) {\n  // `options.include` and `options.exclude` can each be a minimatch\n  // pattern, or an array of minimatch patterns, relative to process.cwd()\n  var filter = createFilter( options.include, options.exclude );\n\n  return {\n    transform ( code, id ) {\n      // if `options.include` is omitted or has zero length, filter\n      // will return `true` by default. Otherwise, an ID must match\n      // one or more of the minimatch patterns, and must not match\n      // any of the `options.exclude` patterns.\n      if ( !filter( id ) ) return;\n\n      // proceed with the transformation...\n    }\n  };\n}\n```\n\nIf you want to resolve the patterns against a directory other than\n`process.cwd()`, you can additionally pass a `resolve` option:\n\n```js\nvar filter = createFilter( options.include, options.exclude, {resolve: '/my/base/dir'} )\n```\n\nIf `resolve` is a string, then this value will be used as the base directory.\nRelative paths will be resolved against `process.cwd()` first. If `resolve` is\n`false`, then the patterns will not be resolved against any directory. This can\nbe useful if you want to create a filter for virtual module names.\n\n\n### makeLegalIdentifier\n\n```js\nimport { makeLegalIdentifier } from 'rollup-pluginutils';\n\nmakeLegalIdentifier( 'foo-bar' ); // 'foo_bar'\nmakeLegalIdentifier( 'typeof' ); // '_typeof'\n```\n\n### dataToEsm\n\nHelper for treeshakable data imports\n\n```js\nimport { dataToEsm } from 'rollup-pluginutils';\n\nconst esModuleSource = dataToEsm({\n  custom: 'data',\n  to: ['treeshake']\n}, {\n  compact: false,\n  indent: '\\t',\n  preferConst: false,\n  objectShorthand: false,\n  namedExports: true\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\nExtract the names of all assignment targets from patterns.\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          \tconst declaredNames = extractAssignedNames(node.id);\n          \t// do something with the declared names\n          \t// e.g. for `const {x, y: z} = ... =\u003e declaredNames = ['x', 'z']\n          }\n        }\n      });\n    }\n  };\n}\n```\n\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frollup%2Frollup-pluginutils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frollup%2Frollup-pluginutils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frollup%2Frollup-pluginutils/lists"}