{"id":15365485,"url":"https://github.com/tunnckocore/resolve-plugins-sync","last_synced_at":"2025-04-15T09:39:09.286Z","repository":{"id":48000666,"uuid":"77921683","full_name":"tunnckoCore/resolve-plugins-sync","owner":"tunnckoCore","description":"Synchronously resolve plugins / transforms / presets just like Babel and Browserify does it, using CommonJS `require` builtin. For example, useful for loading complex configs from `package.json` file.","archived":false,"fork":false,"pushed_at":"2023-01-24T22:47:59.000Z","size":504,"stargazers_count":3,"open_issues_count":15,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-11T12:43:45.610Z","etag":null,"topics":["babel","browserify","config-management","plugins","resolve","rolldown","rollup","sync"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tunnckoCore.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-03T13:57:10.000Z","updated_at":"2023-03-04T04:44:45.000Z","dependencies_parsed_at":"2023-02-14T02:16:11.200Z","dependency_job_id":null,"html_url":"https://github.com/tunnckoCore/resolve-plugins-sync","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tunnckoCore%2Fresolve-plugins-sync","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tunnckoCore%2Fresolve-plugins-sync/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tunnckoCore%2Fresolve-plugins-sync/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tunnckoCore%2Fresolve-plugins-sync/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tunnckoCore","download_url":"https://codeload.github.com/tunnckoCore/resolve-plugins-sync/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249044614,"owners_count":21203705,"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":["babel","browserify","config-management","plugins","resolve","rolldown","rollup","sync"],"created_at":"2024-10-01T13:14:52.644Z","updated_at":"2025-04-15T09:39:09.255Z","avatar_url":"https://github.com/tunnckoCore.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# resolve-plugins-sync [![NPM version](https://img.shields.io/npm/v/resolve-plugins-sync.svg?style=flat)](https://www.npmjs.com/package/resolve-plugins-sync) [![NPM monthly downloads](https://img.shields.io/npm/dm/resolve-plugins-sync.svg?style=flat)](https://npmjs.org/package/resolve-plugins-sync) [![npm total downloads][downloads-img]][downloads-url]\n\n\u003e Synchronously resolve plugins / transforms / presets just like Babel and Browserify does it, using CommonJS `require` builtin. For example, useful for loading complex configs from `package.json` file.\n\n[![code climate][codeclimate-img]][codeclimate-url]\n[![standard code style][standard-img]][standard-url]\n[![linux build status][travis-img]][travis-url]\n[![windows build status][appveyor-img]][appveyor-url]\n[![coverage status][coveralls-img]][coveralls-url]\n[![dependency status][david-img]][david-url]\n\nYou might also be interested in [always-done](https://github.com/hybridables/always-done#readme).\n\n## Table of Contents\n- [Install](#install)\n- [Usage](#usage)\n- [Background](#background)\n  * [What and Why?](#what-and-why)\n  * [Resolution](#resolution)\n- [API](#api)\n  * [resolvePluginsSync](#resolvepluginssync)\n- [Related](#related)\n- [Contributing](#contributing)\n- [Building docs](#building-docs)\n- [Running tests](#running-tests)\n- [Author](#author)\n- [License](#license)\n\n## Install\nInstall with [npm](https://www.npmjs.com/)\n\n```\n$ npm install resolve-plugins-sync --save\n```\n\nor install using [yarn](https://yarnpkg.com)\n\n```\n$ yarn add resolve-plugins-sync\n```\n\n## Usage\n\u003e For more use-cases see the [tests](test.js)\n\n```js\nconst resolvePluginsSync = require('resolve-plugins-sync')\n\n// fake\nconst baz = require('tool-plugin-baz')\nconst qux = require('tool-plugin-qux')\n\nconst result = resolvePluginsSync([\n  'foo',\n  ['bar', { some: 'options here' }],\n  [baz, { a: 'b' }],\n  qux\n], {\n  prefix: 'tool-plugin-'\n})\n```\n\n## Background\n\n### What and Why?\nBecause we need. Because many famous tools do exact same thing. They use same kind\nof resolution of their presets, plugins, transforms and whatever you wanna call it.\nThis one is pretty configurable and small. Most of this resolution can be seen in the\nusers `package.json`s configs.\n\nFor example `browserify.transform` field in package.json\n\n```json\n{\n  \"browserify\": {\n    \"transform\": [\n      \"babel\",\n      [\"uglifyify\", {\n        \"compress\": true\n      }]\n    ]\n  }\n}\n```\n\nAnd because both [babel][] and [browserify][] uses same resolution things may gone more wild.\n\nLet's take this example\n\n```json\n{\n  \"browserify\": {\n    \"transform\": [\n      [\"babel\", {\n        \"presets\": [\n          [\"es2015\", {\n            \"modules\": false\n          }]\n        ],\n        \"plugins\": [\n          [\"react\", { \"some\": \"more options\" }]\n          \"add-module-exports\"\n        ]\n      }],\n      [\"uglifyify\", {\n        \"compress\": true\n      }]\n    ]\n  }\n}\n```\n\nAnd so on, and so on... infinite nesting. That's just freaking crazy, right?\n\nThat's all about what this package does - you give it an array and it does such thing - in case with Browserify if they use this package they should pass `browserify.transform` as first argument.\n\nIt's so customizable that it match to all their needs - both for Babel plugins/presets/transforms and Browserify transforms. The [browserify][] transforms are a bit different by all others. They accept `filename, options` signature. And so, because they don't accept `options` as first argument, like Babel's transforms or like Rollup's plugins, we need a bit configuration to make things work for Browserify.\n\nThat's why this package has `opts` object through which you can pass `opts.first` to set first argument for the plugin/transform function. Another thing that you can do is to pass `opts.args` if you want more control over the passed arguments to the plugin/transform function.\n\n### Resolution\n\nHow we resolve plugins? Resolving algorithm has 4 steps. You should know that in the following paragraphs `item` means each element in the passed array to `resolvePluginsSync()`.\n\n**1)** If item is `string`, it tries to require it from\nlocally installed dependencies, calls it and you can pass\na `opts.prefix` which will be prepended to the item string.\nThink for it like `rollup-plugin-`, `babel-plugin-`, `gulp-`\nand etc. You may want to see the comments for `resolveFromString` inside the source code.\n\n**2)** If item is `function`, it will call it and if you\nwant to pass arguments to it you can pass `opts.args` array\nor `opts.first`. If `opts.args` is passed it calls that\nitem function with `.apply`. If `opts.first` is passed\nit will pass it as first argument to that function.\n\n**3)** If item is `object`, nothing happens, it just returns it\nin the `result` array.\n\n**4)** If item is `array`, then there are few possible\nscenarios (see comments for `resolveFromArray` inside the source code):\n  - if 1st argument is string - see 1\n  - if 1st argument is function - see 2\n  - if 2nd argument is object it will be passed to\n  that resolve function from 1st argument\n\n## API\n\n### [resolvePluginsSync](index.js#L58)\n\n\u003e Babel/Browserify-style resolve of a `plugins` array\nand optional `opts` options object, where\neach \"plugin\" (item in the array) can be\n1) string, 2) function, 3) object or 4) array.\nUseful for loading complex and meaningful configs like\nexactly all of them - Babel, ESLint, Browserify. It would\nbe great if they use that package one day :)\nThe [rolldown][] bundler already using it as default\nresolution for resolving [rollup][] plugins. :)\n\n**Params**\n\n* `array` **{Array|String}**: of \"plugins/transforms/presets\" or single string, which is arrayified so returned `result` is always an array    \n* `opts` **{Object}**: optional custom configuration    \n* ``opts.prefix`` **{String}**: useful like `babel-plugin-` or `rollup-plugin-`    \n* ``opts.context`` **{Any}**: custom context to be passed to plugin function, using the `.apply` method    \n* ``opts.first`` **{Any}**: pass first argument for plugin function, if it is given, then it will pass plugin options as 2nd argument, that's useful for browserify-like transforms where first argument is `filename`, second is transform `options`    \n* ``opts.args`` **{Array}**: pass custom arguments to the resolved plugin function, if given - respected more than `opts.first`    \n* `returns` **{Array}**: `result` resolved plugins, always an array  \n\n**Example**\n\n```jsx\nconst resolve = require('resolve-plugins-sync')\n\n// fake\nconst baz = require('tool-plugin-baz')\nconst qux = require('tool-plugin-qux')\n\nresolve([\n  'foo',\n  ['bar', { some: 'options here' }],\n  [baz, { a: 'b' }],\n  qux\n], {\n  prefix: 'tool-plugin-'\n})\n```\n\n## Related\n- [always-done](https://www.npmjs.com/package/always-done): Handle completion and errors with elegance! Support for streams, callbacks, promises, child processes, async/await and sync functions. A drop-in replacement… [more](https://github.com/hybridables/always-done#readme) | [homepage](https://github.com/hybridables/always-done#readme \"Handle completion and errors with elegance! Support for streams, callbacks, promises, child processes, async/await and sync functions. A drop-in replacement for [async-done][] - pass 100% of its tests plus more\")\n- [minibase](https://www.npmjs.com/package/minibase): Minimalist alternative for Base. Build complex APIs with small units called plugins. Works well with most of the already existing… [more](https://github.com/node-minibase/minibase#readme) | [homepage](https://github.com/node-minibase/minibase#readme \"Minimalist alternative for Base. Build complex APIs with small units called plugins. Works well with most of the already existing [base][] plugins.\")\n- [try-catch-core](https://www.npmjs.com/package/try-catch-core): Low-level package to handle completion and errors of sync or asynchronous functions, using [once][] and [dezalgo][] libs. Useful for and… [more](https://github.com/hybridables/try-catch-core#readme) | [homepage](https://github.com/hybridables/try-catch-core#readme \"Low-level package to handle completion and errors of sync or asynchronous functions, using [once][] and [dezalgo][] libs. Useful for and used in higher-level libs such as [always-done][] to handle completion of anything.\")\n\n## Contributing\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/tunnckoCore/resolve-plugins-sync/issues/new).  \nPlease read the [contributing guidelines](CONTRIBUTING.md) for advice on opening issues, pull requests, and coding standards.  \nIf you need some help and can spent some cash, feel free to [contact me at CodeMentor.io](https://www.codementor.io/tunnckocore?utm_source=github\u0026utm_medium=button\u0026utm_term=tunnckocore\u0026utm_campaign=github) too.\n\n**In short:** If you want to contribute to that project, please follow these things\n\n1. Please DO NOT edit [README.md](README.md), [CHANGELOG.md](CHANGELOG.md) and [.verb.md](.verb.md) files. See [\"Building docs\"](#building-docs) section.\n2. Ensure anything is okey by installing the dependencies and run the tests. See [\"Running tests\"](#running-tests) section.\n3. Always use `npm run commit` to commit changes instead of `git commit`, because it is interactive and user-friendly. It uses [commitizen][] behind the scenes, which follows Conventional Changelog idealogy.\n4. Do NOT bump the version in package.json. For that we use `npm run release`, which is [standard-version][] and follows Conventional Changelog idealogy.\n\nThanks a lot! :)\n\n## Building docs\nDocumentation and that readme is generated using [verb-generate-readme][], which is a [verb][] generator, so you need to install both of them and then run `verb` command like that\n\n```\n$ npm install verbose/verb#dev verb-generate-readme --global \u0026\u0026 verb\n```\n\n_Please don't edit the README directly. Any changes to the readme must be made in [.verb.md](.verb.md)._\n\n## Running tests\nClone repository and run the following in that cloned directory\n\n```\n$ npm install \u0026\u0026 npm test\n```\n\n## Author\n**Charlike Mike Reagent**\n\n+ [github/tunnckoCore](https://github.com/tunnckoCore)\n+ [twitter/tunnckoCore](https://twitter.com/tunnckoCore)\n+ [codementor/tunnckoCore](https://codementor.io/tunnckoCore)\n\n## License\nCopyright © 2016-2017, [Charlike Mike Reagent](https://i.am.charlike.online). MIT\n\n***\n\n_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on October 10, 2017._  \n_Project scaffolded using [charlike][] cli._\n\n[always-done]: https://github.com/hybridables/always-done\n[async-done]: https://github.com/gulpjs/async-done\n[babel]: https://babeljs.io/\n[base]: https://github.com/node-base/base\n[browserify]: https://github.com/substack/node-browserify\n[charlike]: https://github.com/tunnckoCore/charlike\n[commitizen]: https://github.com/commitizen/cz-cli\n[dezalgo]: https://github.com/npm/dezalgo\n[once]: https://github.com/isaacs/once\n[rolldown]: https://github.com/rolldown/rolldown\n[rollup]: https://github.com/rollup/rollup\n[standard-version]: https://github.com/conventional-changelog/standard-version\n[verb-generate-readme]: https://github.com/verbose/verb-generate-readme\n[verb]: https://github.com/verbose/verb\n\n[downloads-url]: https://www.npmjs.com/package/resolve-plugins-sync\n[downloads-img]: https://img.shields.io/npm/dt/resolve-plugins-sync.svg\n\n[codeclimate-url]: https://codeclimate.com/github/tunnckoCore/resolve-plugins-sync\n[codeclimate-img]: https://img.shields.io/codeclimate/github/tunnckoCore/resolve-plugins-sync.svg\n\n[travis-url]: https://travis-ci.org/tunnckoCore/resolve-plugins-sync\n[travis-img]: https://img.shields.io/travis/tunnckoCore/resolve-plugins-sync/master.svg?label=linux\n\n[appveyor-url]: https://ci.appveyor.com/project/tunnckoCore/resolve-plugins-sync\n[appveyor-img]: https://img.shields.io/appveyor/ci/tunnckoCore/resolve-plugins-sync/master.svg?label=windows\n\n[coveralls-url]: https://coveralls.io/r/tunnckoCore/resolve-plugins-sync\n[coveralls-img]: https://img.shields.io/coveralls/tunnckoCore/resolve-plugins-sync.svg\n\n[david-url]: https://david-dm.org/tunnckoCore/resolve-plugins-sync\n[david-img]: https://img.shields.io/david/tunnckoCore/resolve-plugins-sync.svg\n\n[standard-url]: https://github.com/feross/standard\n[standard-img]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftunnckocore%2Fresolve-plugins-sync","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftunnckocore%2Fresolve-plugins-sync","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftunnckocore%2Fresolve-plugins-sync/lists"}