{"id":17258163,"url":"https://github.com/asapach/babel-plugin-rewire-exports","last_synced_at":"2026-03-06T04:31:33.770Z","repository":{"id":12373680,"uuid":"71659041","full_name":"asapach/babel-plugin-rewire-exports","owner":"asapach","description":"Babel plugin for stubbing [ES6, ES2015] module exports","archived":false,"fork":false,"pushed_at":"2026-01-21T23:33:59.000Z","size":689,"stargazers_count":66,"open_issues_count":4,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2026-01-22T12:49:47.542Z","etag":null,"topics":["babel","babel-plugin","es2015","es6","esm","javascript","rewire","rollup","stub","systemjs","unit-testing","webpack"],"latest_commit_sha":null,"homepage":"","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/asapach.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2016-10-22T18:49:50.000Z","updated_at":"2026-01-21T23:33:56.000Z","dependencies_parsed_at":"2024-06-18T13:59:52.751Z","dependency_job_id":"261defbf-ea55-4154-8bb9-3c415afaa033","html_url":"https://github.com/asapach/babel-plugin-rewire-exports","commit_stats":{"total_commits":149,"total_committers":6,"mean_commits":"24.833333333333332","dds":0.1476510067114094,"last_synced_commit":"9f7f069b707e012379bb4ce04f4846d56f1cf4d5"},"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"purl":"pkg:github/asapach/babel-plugin-rewire-exports","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asapach%2Fbabel-plugin-rewire-exports","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asapach%2Fbabel-plugin-rewire-exports/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asapach%2Fbabel-plugin-rewire-exports/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asapach%2Fbabel-plugin-rewire-exports/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/asapach","download_url":"https://codeload.github.com/asapach/babel-plugin-rewire-exports/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asapach%2Fbabel-plugin-rewire-exports/sbom","scorecard":{"id":210807,"data":{"date":"2025-08-11","repo":{"name":"github.com/asapach/babel-plugin-rewire-exports","commit":"150b328cde699a2ab3521fa8cab511fd3e602b43"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":1.7,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":0,"reason":"Found 0/14 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"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"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 16 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":0,"reason":"11 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c","Warn: Project is vulnerable to: GHSA-ww39-953v-wcq6","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-qrpm-p2h7-hrv2","Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-17T00:44:25.671Z","repository_id":12373680,"created_at":"2025-08-17T00:44:25.671Z","updated_at":"2025-08-17T00:44:25.671Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30161734,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-06T04:22:03.816Z","status":"ssl_error","status_checked_at":"2026-03-06T04:22:00.183Z","response_time":250,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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","babel-plugin","es2015","es6","esm","javascript","rewire","rollup","stub","systemjs","unit-testing","webpack"],"created_at":"2024-10-15T07:19:40.818Z","updated_at":"2026-03-06T04:31:33.735Z","avatar_url":"https://github.com/asapach.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# babel-plugin-rewire-exports\n\n[![NPM Version][npm-image]][npm-url]\n[![NPM Downloads][downloads-image]][downloads-url]\n[![Build Status][travis-image]][travis-url]\n\nBabel plugin for stubbing (ES6, ES2015) module exports.\nIt allows to rewire the exported values in all the importing modules.\nUnlike [babel-plugin-rewire](https://github.com/speedskater/babel-plugin-rewire) it doesn't modify the module internals\n(e.g. imports and top-level variables and functions).\nSee [How it works](#how-it-works) section for implementation details.\n\n## Exports\nPlugin transforms module exports in such a way that they can be stubbed (or \"rewired\") via the following API:\n* default export - plugin exports additional `rewire(stub)` function that allows to replace the original\n* named exports - for each export (e.g. `export var foo`) an additional function `rewire$foo(stub)` is exported\n* `restore()` function allows to restore the exports to their original values\n* if there are existing `rewire` or `restore` top-level identifiers, the generated exports will be named\n`rewire$default` and `restore$rewire` respectively\n\n### Example\n\nNamed export:\n```js\n//------ text.js ------\nexport let message = 'Hello world!'\n\n//------ logger.js ------\nimport {message} from './text.js'\n\nexport default function () {\n  console.log(message)\n}\n\n//------ main.js ------\nimport {rewire$message, restore} from './text.js'\nimport logger from './logger.js'\n\nlogger() // 'Hello world!'\nrewire$message('I am now rewired')\nlogger() // 'I am now rewired'\nrestore()\nlogger() // 'Hello world!'\n```\n\nDefault export:\n```js\n//------ fetch.js ------\nexport default function (url) {\n  // perform some expensive remote call\n}\n\n//------ adapter.js ------\nimport fetch from './fetch.js'\n\nexport function fetchItems() {\n  return fetch('/items')\n}\n\n//------ test.js ------\nimport {rewire, restore} from './fetch.js'\nimport {fetchItems} from './adapter.js'\n\n// Jasmine example\ndescribe('adapter', function () {\n  beforeEach(function () {\n    rewire(this.spy = jasmine.createSpy('fetch'))\n  })\n  afterAll(restore)\n  \n  it('should call fetch', function () {\n    fetchItems()\n    expect(this.spy).toHaveBeenCalledWith('/items')\n  })\n})\n\n// Mocha/Chai and Sinon example\ndescribe('adapter', function () {\n  var spy\n\n  beforeEach(function () {\n    rewire(spy = sinon.spy())\n  })\n  after(restore)\n  \n  it('should call fetch', function () {\n    fetchItems()\n    expect(spy.withArgs('/items').calledOnce).to.be.true\n  })\n})\n```\n\n## Compatibility\n* ❤️ Works with modern browsers:\n  * 🕕 Safari 10.1+\n  * 🍉 Chrome 61+\n  * 🦊 Firefox 60+\n  * 💎 Edge 16+\n* 🍏 Node:\n  * [`@std/esm`](https://github.com/standard-things/esm)\n  * `8.5.0+` behind [`--experimental-modules` flag](https://github.com/nodejs/node/blob/master/doc/changelogs/CHANGELOG_V8.md#8.5.0)\n* ✨ SystemJS\n* 🌟 Webpack 2+\n* 💥 Rollup\n* 📦 Works with CommonJS, including running in Node and bundling with webpack/browserify:\n  * Use [`env`](https://babeljs.io/docs/en/babel-preset-env/) preset\n  * When specifying `plugins` directly make sure that `\"rewire-exports\"` goes\n    before [`\"@babel/plugin-transform-modules-commonjs\"`](https://babeljs.io/docs/en/babel-plugin-transform-modules-commonjs)\n  * Works with [🃏 Jest](https://jestjs.io/) using [babel-jest](https://github.com/facebook/jest/tree/master/packages/babel-jest)\n\n## How it works\n[In ES6, imports are live read-only views on exported values](\nhttp://exploringjs.com/es6/ch_modules.html#_in-es6-imports-are-live-read-only-views-on-exported-values):\n\n```js\n//------ lib.js ------\nexport let counter = 3;\nexport function incCounter() {\n    counter++;\n}\n\n//------ main1.js ------\nimport { counter, incCounter } from './lib';\n\n// The imported value `counter` is live\nconsole.log(counter); // 3\nincCounter();\nconsole.log(counter); // 4\n\n// The imported value can’t be changed\ncounter++; // TypeError\n```\n\nThis allows for any exports to be overwritten from within the module -\nand imports will be automatically updated via their bindings.\n\n### Transformations\nHere's how various kinds of export declarations are transformed:\n* Literals (`export default 'foo'`) - the original value is copied to a variable to be stubbed and restored later:\n  `export {_default as default}`\n\n* Variables:\n  - named exports (`export var foo`, `export let bar` or `export {baz}`) are left intact,\n    but their initial values are similarly copied to temp variables.\n  - default export (`export default foo`) is converted to a named export to enable live binding:\n    `export {foo as default}`\n\n* Constants (`export const foo = 'bar'` or `export default foo`) are treated similar to variables,\n  but their values are **not modified** _within_ the module (since they are read-only) - only exported values are rewired:\n  - named exports: `export { _foo as foo }`\n  - default export: `export { _default as default }`\n\n  You can use `unsafeConst` [option](#options) to convert `const` to `let` in order to enable live binding.\n\n* Functions (`export default function () {…}` or `export function foo() {…}`)\n  are converted into a function expression and exported variable by the same name.\n  The variable initialization is hoisted to the top of the scope to preserve existing behavior.\n\n* Classes (`export default class foo {…}` or `export class foo {…}`) are handled similarly to functions\n  except the variables are not hoisted (again to preserve the existing behavior).\n\n* Re-exports (`export * from './foo.js'` or `export {bar} from 'baz'`) are ignored.\n  They can be rewired in the original modules.\n\n* Immutable values such as `undefined`, *globals* and *imports* are copied similar to literals. \n\n## Installation\n\n```sh\n$ npm install babel-plugin-rewire-exports\n```\n\n## Usage\n\n### Via `.babelrc` (Recommended)\n\n**.babelrc**\n\n```javascript\n// without options\n{\n  \"plugins\": [\"rewire-exports\"]\n}\n\n// with options\n{\n  \"plugins\": [\n    [\"rewire-exports\", {\n      \"unsafeConst\": true\n    }]\n  ]\n}\n```\n\n### Via CLI\n\n```sh\n$ babel --plugins rewire-exports script.js\n```\n\n### Via Node API\n\n```javascript\nrequire(\"@babel/core\").transform(\"code\", {\n  plugins: [\"rewire-exports\"]\n});\n```\n\n## Options\n\n### `unsafeConst`\n`boolean`, defaults to `false`.\n\nConstants cannot be rewired if you're targeting ES2015+,\nbecause the plugin relies on variables being assign-able in order to work.\nHowever setting `unsafeConst: true` will convert `export const foo = 'bar'` to `export let foo = 'bar'`.\nThis will allow to treat constant exports as regular variables.\nThis is *potentially unsafe* if your code relies on constants being read-only.\n\n[npm-image]: https://img.shields.io/npm/v/babel-plugin-rewire-exports.svg?style=flat\n[npm-url]: https://npmjs.org/package/babel-plugin-rewire-exports\n[travis-image]: https://img.shields.io/travis/asapach/babel-plugin-rewire-exports.svg?style=flat\n[travis-url]: https://travis-ci.org/asapach/babel-plugin-rewire-exports\n[downloads-image]: https://img.shields.io/npm/dm/babel-plugin-rewire-exports.svg?style=flat\n[downloads-url]: https://npmjs.org/package/babel-plugin-rewire-exports\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasapach%2Fbabel-plugin-rewire-exports","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fasapach%2Fbabel-plugin-rewire-exports","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasapach%2Fbabel-plugin-rewire-exports/lists"}