master 6854ac27f34e cached
217 files
88.7 KB
31.5k tokens
61 symbols
1 requests
Download .txt
Repository: rollup/rollup-plugin-commonjs
Branch: master
Commit: 6854ac27f34e
Files: 217
Total size: 88.7 KB

Directory structure:
gitextract_emltkzmn/

├── .babelrc.js
├── .eslintrc.json
├── .gitignore
├── .huskyrc
├── .lintstagedrc
├── .prettierrc
├── .travis.yml
├── CHANGELOG.md
├── LICENSE
├── README.md
├── appveyor.yml
├── index.d.ts
├── package.json
├── rollup.config.js
├── src/
│   ├── ast-utils.js
│   ├── helpers.js
│   ├── index.js
│   ├── is-cjs.js
│   ├── resolve-id.js
│   ├── transform.js
│   └── utils.js
├── test/
│   ├── form/
│   │   ├── async-function/
│   │   │   ├── input.js
│   │   │   └── output.js
│   │   ├── constant-template-literal/
│   │   │   ├── input.js
│   │   │   └── output.js
│   │   ├── dynamic-template-literal/
│   │   │   ├── input.js
│   │   │   └── output.js
│   │   ├── ignore-ids/
│   │   │   ├── _config.js
│   │   │   ├── input.js
│   │   │   └── output.js
│   │   ├── ignore-ids-function/
│   │   │   ├── _config.js
│   │   │   ├── input.js
│   │   │   └── output.js
│   │   ├── multiple-var-declarations/
│   │   │   ├── input.js
│   │   │   └── output.js
│   │   ├── multiple-var-declarations-b/
│   │   │   ├── input.js
│   │   │   └── output.js
│   │   ├── multiple-var-declarations-c/
│   │   │   ├── input.js
│   │   │   └── output.js
│   │   ├── no-exports-entry/
│   │   │   ├── _config.js
│   │   │   ├── input.js
│   │   │   └── output.js
│   │   ├── no-toplevel-return/
│   │   │   ├── input.js
│   │   │   └── output.js
│   │   ├── optimised-default-export/
│   │   │   ├── input.js
│   │   │   └── output.js
│   │   ├── optimised-default-export-function/
│   │   │   ├── input.js
│   │   │   └── output.js
│   │   ├── optimised-default-export-function-double-assign/
│   │   │   ├── input.js
│   │   │   └── output.js
│   │   ├── optimised-default-export-iife/
│   │   │   ├── input.js
│   │   │   └── output.js
│   │   ├── optimised-named-export/
│   │   │   ├── input.js
│   │   │   └── output.js
│   │   ├── optimised-named-export-conflicts/
│   │   │   ├── input.js
│   │   │   └── output.js
│   │   ├── require-collision/
│   │   │   ├── input.js
│   │   │   └── output.js
│   │   ├── typeof-module-exports/
│   │   │   ├── input.js
│   │   │   └── output.js
│   │   ├── unambiguous-with-default-export/
│   │   │   ├── input.js
│   │   │   └── output.js
│   │   ├── unambiguous-with-import/
│   │   │   ├── input.js
│   │   │   └── output.js
│   │   └── unambiguous-with-named-export/
│   │       ├── input.js
│   │       └── output.js
│   ├── function/
│   │   ├── __esModule/
│   │   │   ├── answer.js
│   │   │   └── main.js
│   │   ├── assign-properties-to-default-export/
│   │   │   ├── foo.js
│   │   │   └── main.js
│   │   ├── assumed-globals/
│   │   │   ├── _config.js
│   │   │   ├── document.js
│   │   │   └── main.js
│   │   ├── bare-import/
│   │   │   ├── _config.js
│   │   │   ├── bar.js
│   │   │   ├── foo.js
│   │   │   └── main.js
│   │   ├── bare-import-comment/
│   │   │   ├── bar.js
│   │   │   ├── foo.js
│   │   │   └── main.js
│   │   ├── basic/
│   │   │   ├── _config.js
│   │   │   ├── foo.js
│   │   │   └── main.js
│   │   ├── deconflict-export-and-local/
│   │   │   ├── index.js
│   │   │   ├── main.js
│   │   │   └── someValue.js
│   │   ├── dot/
│   │   │   ├── foo.bar.js
│   │   │   └── main.js
│   │   ├── duplicate-default-exports/
│   │   │   ├── main.js
│   │   │   └── x.js
│   │   ├── duplicate-default-exports-b/
│   │   │   ├── main.js
│   │   │   └── x.js
│   │   ├── duplicate-default-exports-c/
│   │   │   ├── exports.js
│   │   │   └── main.js
│   │   ├── export-default-from/
│   │   │   ├── _config.js
│   │   │   ├── imported.js
│   │   │   ├── main.js
│   │   │   └── reexporter.js
│   │   ├── exports/
│   │   │   ├── _config.js
│   │   │   ├── foo.js
│   │   │   └── main.js
│   │   ├── external-imports/
│   │   │   ├── _config.js
│   │   │   └── main.js
│   │   ├── fallback-no-default/
│   │   │   ├── foo.js
│   │   │   └── main.js
│   │   ├── global-not-overwritten/
│   │   │   ├── _config.js
│   │   │   ├── encode.js
│   │   │   └── main.js
│   │   ├── global-var/
│   │   │   └── main.js
│   │   ├── index/
│   │   │   ├── foo/
│   │   │   │   └── index.js
│   │   │   └── main.js
│   │   ├── inline/
│   │   │   ├── _config.js
│   │   │   ├── foo.js
│   │   │   ├── main.js
│   │   │   └── multiply.js
│   │   ├── named-exports/
│   │   │   ├── foo.js
│   │   │   └── main.js
│   │   ├── ordering/
│   │   │   ├── bar.js
│   │   │   ├── foo.js
│   │   │   ├── main.js
│   │   │   └── shared.js
│   │   ├── react-apollo/
│   │   │   ├── commonjs-bar.js
│   │   │   ├── commonjs-foo.js
│   │   │   └── main.js
│   │   ├── reassignment/
│   │   │   ├── foo.js
│   │   │   └── main.js
│   │   ├── reexports/
│   │   │   ├── _config.js
│   │   │   ├── bar.js
│   │   │   ├── foo.js
│   │   │   └── main.js
│   │   ├── resolve-is-cjs-extension/
│   │   │   ├── _config.js
│   │   │   ├── main.js
│   │   │   └── second.x
│   │   ├── resolve-is-cjs-filtered/
│   │   │   ├── _config.js
│   │   │   ├── main.js
│   │   │   └── second.js
│   │   ├── shadowing/
│   │   │   └── main.js
│   │   ├── skips-dead-branches/
│   │   │   ├── _config.js
│   │   │   ├── a.js
│   │   │   ├── b.js
│   │   │   ├── c.js
│   │   │   └── main.js
│   │   ├── this/
│   │   │   ├── foo.js
│   │   │   └── main.js
│   │   ├── toplevel-return/
│   │   │   ├── _config.js
│   │   │   ├── foo.js
│   │   │   └── main.js
│   │   ├── toplevel-return-complex/
│   │   │   ├── _config.js
│   │   │   ├── bar.js
│   │   │   ├── foo.js
│   │   │   └── main.js
│   │   ├── trailing-slash/
│   │   │   ├── foo/
│   │   │   │   └── index.js
│   │   │   └── main.js
│   │   └── typeof-require/
│   │       ├── foo.js
│   │       └── main.js
│   ├── mocha.opts
│   ├── node_modules/
│   │   ├── .gitkeep
│   │   ├── bar/
│   │   │   └── index.js
│   │   ├── baz/
│   │   │   └── index.js
│   │   ├── events/
│   │   │   └── index.js
│   │   ├── external/
│   │   │   └── index.js
│   │   └── foo/
│   │       └── index.js
│   ├── samples/
│   │   ├── array-destructuring-assignment/
│   │   │   └── main.js
│   │   ├── corejs/
│   │   │   └── literal-with-default.js
│   │   ├── custom-named-exports/
│   │   │   ├── main.js
│   │   │   └── secret-named-exporter.js
│   │   ├── custom-named-exports-browser-shims/
│   │   │   └── main.js
│   │   ├── custom-named-exports-false-positive/
│   │   │   ├── main.js
│   │   │   └── other.js
│   │   ├── custom-named-exports-warn-builtins/
│   │   │   └── main.js
│   │   ├── deconflict-helpers/
│   │   │   └── main.js
│   │   ├── define-is-undefined/
│   │   │   ├── foo.js
│   │   │   └── main.js
│   │   ├── es-modules-without-default-export/
│   │   │   ├── main.js
│   │   │   └── other.js
│   │   ├── extension/
│   │   │   ├── foo.coffee
│   │   │   └── main.coffee
│   │   ├── external/
│   │   │   └── main.js
│   │   ├── global/
│   │   │   └── main.js
│   │   ├── global-in-if-block/
│   │   │   └── main.js
│   │   ├── ignore-global/
│   │   │   ├── firstpass.js
│   │   │   ├── identifier.js
│   │   │   ├── main.js
│   │   │   └── this.js
│   │   ├── ignore-virtual-modules/
│   │   │   └── main.js
│   │   ├── invalid-syntax/
│   │   │   └── main.js
│   │   ├── multiple-entry-points/
│   │   │   ├── 2.js
│   │   │   ├── 3.js
│   │   │   ├── 4.js
│   │   │   ├── b.js
│   │   │   └── c.js
│   │   ├── named-exports-from-object-literal/
│   │   │   ├── a.js
│   │   │   ├── main.js
│   │   │   └── other.js
│   │   ├── other-transforms/
│   │   │   ├── bar.js
│   │   │   ├── foo.js
│   │   │   └── main.js
│   │   ├── paren-expression/
│   │   │   └── index.js
│   │   ├── reexport/
│   │   │   ├── export.js
│   │   │   ├── main.js
│   │   │   └── reexport.js
│   │   ├── rename-index/
│   │   │   ├── invalid-var/
│   │   │   │   └── index.js
│   │   │   ├── main.js
│   │   │   ├── other/
│   │   │   │   └── nonIndex.js
│   │   │   └── validVar/
│   │   │       └── index.js
│   │   ├── reserved-as-property/
│   │   │   └── main.js
│   │   ├── sourcemap/
│   │   │   ├── foo.js
│   │   │   └── main.js
│   │   ├── symlinked-node-modules/
│   │   │   └── index.js
│   │   ├── umd/
│   │   │   ├── correct-scoping.js
│   │   │   ├── protobuf.js
│   │   │   └── sinon.js
│   │   └── use-own-output/
│   │       ├── from-rollup.js
│   │       └── main.js
│   └── test.js
├── tsconfig.json
└── typings-test.js

================================================
FILE CONTENTS
================================================

================================================
FILE: .babelrc.js
================================================
module.exports = {
	presets: [
		[
			'@babel/preset-env',
			{
				targets: {
					node: 6
				}
			}
		]
	]
};


================================================
FILE: .eslintrc.json
================================================
{
  "root": true,
  "rules": {
    "indent": [ 2, "tab", { "SwitchCase": 1 } ],
    "semi": [ 2, "always" ],
    "keyword-spacing": [ 2, { "before": true, "after": true } ],
    "space-before-blocks": [ 2, "always" ],
    "no-mixed-spaces-and-tabs": [ 2, "smart-tabs" ],
    "no-cond-assign": 0,
    "no-unused-vars": 2,
    "object-shorthand":  [ 2, "always" ],
    "no-const-assign": 2,
    "no-class-assign": 2,
    "no-this-before-super": 2,
    "no-var": 2,
    "no-unreachable": 2,
    "valid-typeof": 2,
    "quote-props": [ 2, "as-needed" ],
    "one-var": [ 2, "never" ],
    "prefer-arrow-callback": 2,
    "prefer-const": [ 2, { "destructuring": "all" } ],
    "arrow-spacing": 2
  },
  "env": {
    "es6": true,
    "browser": true,
    "node": true
  },
  "extends": [
    "eslint:recommended",
    "plugin:import/errors",
    "plugin:import/warnings"
  ],
  "parserOptions": {
    "ecmaVersion": 8,
    "sourceType": "module"
  },
  "settings": {
    "import/ignore": [ 0, [
      "\\.path.js$"
    ] ]
  }
}


================================================
FILE: .gitignore
================================================
.DS_Store
node_modules
.gobble*
dist
!test/**/node_modules


================================================
FILE: .huskyrc
================================================
{
  "hooks": {
    "post-commit": "git reset",
    "pre-commit": "lint-staged"
  }
}


================================================
FILE: .lintstagedrc
================================================
{
  "{src/**/*,test/test,test/**/_config}.js": [
    "prettier --write",
    "eslint --fix",
    "git add"
  ]
}


================================================
FILE: .prettierrc
================================================
{
	"singleQuote": true,
	"useTabs": true,
	"printWidth": 100
}


================================================
FILE: .travis.yml
================================================
sudo: false
language: node_js
node_js:
  - "8"
  - "10"
env:
  global:
    - BUILD_TIMEOUT=10000
install: npm ci --ignore-scripts
before_install:
  - if [[ $TRAVIS_NODE_VERSION -lt 8 ]]; then npm install --global npm@5; fi


================================================
FILE: CHANGELOG.md
================================================
# rollup-plugin-commonjs changelog

## 10.1.0
*2019-08-27*
* Normalize ids before looking up in named export map ([#406](https://github.com/rollup/rollup-plugin-commonjs/issues/406))
* Update README.md with note on symlinks ([#405](https://github.com/rollup/rollup-plugin-commonjs/issues/405))

## 10.0.2
*2019-08-03*
* Support preserveSymlinks: false ([#401](https://github.com/rollup/rollup-plugin-commonjs/issues/401))

## 10.0.1
*2019-06-27*
* Make tests run with Node 6 again and update dependencies ([#389](https://github.com/rollup/rollup-plugin-commonjs/issues/389))
* Handle builtins appropriately for resolve 1.11.0 ([#395](https://github.com/rollup/rollup-plugin-commonjs/issues/395))

## 10.0.0
*2019-05-15*
* Use new Rollup@1.12 context functions, fix issue when resolveId returns an object ([#387](https://github.com/rollup/rollup-plugin-commonjs/issues/387))

## 9.3.4
*2019-04-04*
* Make "extensions" optional ([#384](https://github.com/rollup/rollup-plugin-commonjs/issues/384))
* Use same typing for include and exclude properties ([#385](https://github.com/rollup/rollup-plugin-commonjs/issues/385))

## 9.3.3
*2019-04-04*
* Remove colon from module prefixes ([#371](https://github.com/rollup/rollup-plugin-commonjs/issues/371))

## 9.3.2
*2019-04-04*
* Use shared extractAssignedNames, fix destructuring issue ([#303](https://github.com/rollup/rollup-plugin-commonjs/issues/303))

## 9.3.1
*2019-04-04*
* Include typings in release ([#382](https://github.com/rollup/rollup-plugin-commonjs/issues/382))

## 9.3.0
*2019-04-03*
* Add TypeScript types ([#363](https://github.com/rollup/rollup-plugin-commonjs/issues/363))

## 9.2.3
*2019-04-02*
* Improve support for ES3 browsers ([#364](https://github.com/rollup/rollup-plugin-commonjs/issues/364))
* Add note about monorepo usage to readme ([#372](https://github.com/rollup/rollup-plugin-commonjs/issues/372))
* Add .js extension to generated helper file ([#373](https://github.com/rollup/rollup-plugin-commonjs/issues/373))

## 9.2.2
*2019-03-25*
* Handle array destructuring assignment ([#379](https://github.com/rollup/rollup-plugin-commonjs/issues/379))

## 9.2.1
*2019-02-23*
* Use correct context when manually resolving ids ([#370](https://github.com/rollup/rollup-plugin-commonjs/issues/370))

## 9.2.0
*2018-10-10*
* Fix missing default warning, produce better code when importing known ESM default exports ([#349](https://github.com/rollup/rollup-plugin-commonjs/issues/349))
* Refactor code and add prettier ([#346](https://github.com/rollup/rollup-plugin-commonjs/issues/346))

## 9.1.8
*2018-09-18*
* Ignore virtual modules created by other plugins ([#327](https://github.com/rollup/rollup-plugin-commonjs/issues/327))
* Add "location" and "process" to reserved words ([#330](https://github.com/rollup/rollup-plugin-commonjs/issues/330))

## 9.1.6
*2018-08-24*
* Keep commonJS detection between instantiations ([#338](https://github.com/rollup/rollup-plugin-commonjs/issues/338))

## 9.1.5
*2018-08-09*
* Handle object form of input ([#329](https://github.com/rollup/rollup-plugin-commonjs/issues/329))

## 9.1.4
*2018-07-27*
* Make "from" a reserved word ([#320](https://github.com/rollup/rollup-plugin-commonjs/issues/320))

## 9.1.3
*2018-04-30*
* Fix a caching issue ([#316](https://github.com/rollup/rollup-plugin-commonjs/issues/316))

## 9.1.2
*2018-04-30*
* Re-publication of 9.1.0

## 9.1.1
*2018-04-30*
* Fix ordering of modules when using rollup 0.58 ([#302](https://github.com/rollup/rollup-plugin-commonjs/issues/302))

## 9.1.0

* Do not automatically wrap modules with return statements in top level arrow functions ([#302](https://github.com/rollup/rollup-plugin-commonjs/issues/302))

## 9.0.0

* Make rollup a peer dependency with a version range ([#300](https://github.com/rollup/rollup-plugin-commonjs/issues/300))

## 8.4.1

* Re-release of 8.3.0 as #287 was actually a breaking change

## 8.4.0

* Better handle non-CJS files that contain CJS keywords ([#285](https://github.com/rollup/rollup-plugin-commonjs/issues/285))
* Use rollup's plugin context`parse` function ([#287](https://github.com/rollup/rollup-plugin-commonjs/issues/287))
* Improve error handling ([#288](https://github.com/rollup/rollup-plugin-commonjs/issues/288))

## 8.3.0

* Handle multiple entry points ([#283](https://github.com/rollup/rollup-plugin-commonjs/issues/283))
* Extract named exports from exported object literals ([#272](https://github.com/rollup/rollup-plugin-commonjs/issues/272))
* Fix when `options.external` is modified by other plugins ([#264](https://github.com/rollup/rollup-plugin-commonjs/issues/264))
* Recognize static template strings in require statements ([#271](https://github.com/rollup/rollup-plugin-commonjs/issues/271))

## 8.2.4

* Don't import default from ES modules that don't export default ([#206](https://github.com/rollup/rollup-plugin-commonjs/issues/206))

## 8.2.3

* Prevent duplicate default exports ([#230](https://github.com/rollup/rollup-plugin-commonjs/pull/230))
* Only include default export when it exists ([#226](https://github.com/rollup/rollup-plugin-commonjs/pull/226))
* Deconflict `require` aliases ([#232](https://github.com/rollup/rollup-plugin-commonjs/issues/232))

## 8.2.1

* Fix magic-string deprecation warning

## 8.2.0

* Avoid using `index` as a variable name ([#208](https://github.com/rollup/rollup-plugin-commonjs/pull/208))

## 8.1.1

* Compatibility with 0.48 ([#220](https://github.com/rollup/rollup-plugin-commonjs/issues/220))

## 8.1.0

* Handle `options.external` correctly ([#212](https://github.com/rollup/rollup-plugin-commonjs/pull/212))
* Support top-level return ([#195](https://github.com/rollup/rollup-plugin-commonjs/pull/195))

## 8.0.2

* Fix another `var` rewrite bug ([#181](https://github.com/rollup/rollup-plugin-commonjs/issues/181))

## 8.0.1

* Remove declarators within a var declaration correctly ([#179](https://github.com/rollup/rollup-plugin-commonjs/issues/179))

## 8.0.0

* Prefer the names dependencies are imported by for the common `var foo = require('foo')` pattern ([#176](https://github.com/rollup/rollup-plugin-commonjs/issues/176))

## 7.1.0

* Allow certain `require` statements to pass through unmolested ([#174](https://github.com/rollup/rollup-plugin-commonjs/issues/174))

## 7.0.2

* Handle duplicate default exports ([#158](https://github.com/rollup/rollup-plugin-commonjs/issues/158))

## 7.0.1

* Fix exports with parentheses ([#168](https://github.com/rollup/rollup-plugin-commonjs/issues/168))

## 7.0.0

* Rewrite `typeof module`, `typeof module.exports` and `typeof exports` as `'object'` ([#151](https://github.com/rollup/rollup-plugin-commonjs/issues/151))

## 6.0.1

* Don't overwrite globals ([#127](https://github.com/rollup/rollup-plugin-commonjs/issues/127))

## 6.0.0

* Rewrite top-level `define` as `undefined`, so AMD-first UMD blocks do not cause breakage ([#144](https://github.com/rollup/rollup-plugin-commonjs/issues/144))
* Support ES2017 syntax ([#132](https://github.com/rollup/rollup-plugin-commonjs/issues/132))
* Deconflict exported reserved keywords ([#116](https://github.com/rollup/rollup-plugin-commonjs/issues/116))

## 5.0.5
* Fix parenthesis wrapped exports ([#120](https://github.com/rollup/rollup-plugin-commonjs/issues/120))

## 5.0.4

* Ensure named exports are added to default export in optimised modules ([#112](https://github.com/rollup/rollup-plugin-commonjs/issues/112))

## 5.0.3

* Respect custom `namedExports` in optimised modules ([#35](https://github.com/rollup/rollup-plugin-commonjs/issues/35))

## 5.0.2

* Replace `require` (outside call expressions) with `commonjsRequire` helper ([#77](https://github.com/rollup/rollup-plugin-commonjs/issues/77), [#83](https://github.com/rollup/rollup-plugin-commonjs/issues/83))

## 5.0.1

* Deconflict against globals ([#84](https://github.com/rollup/rollup-plugin-commonjs/issues/84))

## 5.0.0

* Optimise modules that don't need to be wrapped in a function ([#106](https://github.com/rollup/rollup-plugin-commonjs/pull/106))
* Ignore modules containing `import` and `export` statements ([#96](https://github.com/rollup/rollup-plugin-commonjs/pull/96))

## 4.1.0

* Ignore dead branches ([#93](https://github.com/rollup/rollup-plugin-commonjs/issues/93))

## 4.0.1

* Fix `ignoreGlobal` option ([#86](https://github.com/rollup/rollup-plugin-commonjs/pull/86))

## 4.0.0

* Better interop and smaller output ([#92](https://github.com/rollup/rollup-plugin-commonjs/pull/92))

## 3.3.1

* Deconflict export and local module ([rollup/rollup#554](https://github.com/rollup/rollup/issues/554))

## 3.3.0

* Keep the order of execution for require calls ([#43](https://github.com/rollup/rollup-plugin-commonjs/pull/43))
* Use interopDefault as helper ([#42](https://github.com/rollup/rollup-plugin-commonjs/issues/42))

## 3.2.0

* Use named exports as a function when no default export is defined ([#524](https://github.com/rollup/rollup/issues/524))

## 3.1.0

* Replace `typeof require` with `'function'` ([#38](https://github.com/rollup/rollup-plugin-commonjs/issues/38))
* Don't attempt to resolve entry file relative to importer ([#63](https://github.com/rollup/rollup-plugin-commonjs/issues/63))

## 3.0.2

* Handle multiple references to `global`

## 3.0.1

* Return a `name`

## 3.0.0

* Make `transform` stateless ([#71](https://github.com/rollup/rollup-plugin-commonjs/pull/71))
* Support web worker `global` ([#50](https://github.com/rollup/rollup-plugin-commonjs/issues/50))
* Ignore global with `options.ignoreGlobal` ([#48](https://github.com/rollup/rollup-plugin-commonjs/issues/48))

## 2.2.1

* Prevent false positives with `namedExports` ([#36](https://github.com/rollup/rollup-plugin-commonjs/issues/36))

## 2.2.0

* Rewrite top-level `this` expressions to mean the same as `global`  ([#31](https://github.com/rollup/rollup-plugin-commonjs/issues/31))

## 2.1.0

* Optimised module wrappers ([#20](https://github.com/rollup/rollup-plugin-commonjs/pull/20))
* Allow control over named exports via `options.namedExports` ([#18](https://github.com/rollup/rollup-plugin-commonjs/issues/18))
* Handle bare imports correctly ([#23](https://github.com/rollup/rollup-plugin-commonjs/issues/23))
* Blacklist all reserved words as export names ([#21](https://github.com/rollup/rollup-plugin-commonjs/issues/21))
* Configure allowed file extensions via `options.extensions` ([#27](https://github.com/rollup/rollup-plugin-commonjs/pull/27))

## 2.0.0

* Support for transpiled modules – `exports.default` is used as the default export in place of `module.exports`, if applicable, and `__esModule` is not exported ([#16](https://github.com/rollup/rollup-plugin-commonjs/pull/16))

## 1.4.0

* Generate sourcemaps by default

## 1.3.0

* Handle references to `global` ([#6](https://github.com/rollup/rollup-plugin-commonjs/issues/6))

## 1.2.0

* Generate named exports where possible ([#5](https://github.com/rollup/rollup-plugin-commonjs/issues/5))
* Handle shadowed `require`/`module`/`exports`

## 1.1.0

* Handle dots in filenames ([#3](https://github.com/rollup/rollup-plugin-commonjs/issues/3))
* Wrap modules in IIFE for more readable output

## 1.0.0

* Stable release, now that Rollup supports plugins

## 0.2.1

* Allow mixed CommonJS/ES6 imports/exports
* Use `var` instead of `let`

## 0.2.0

* Sourcemap support
* Support `options.include` and `options.exclude`
* Bail early if module is obviously not a CommonJS module

## 0.1.1

Add dist files to package (whoops!)

## 0.1.0

* First release


================================================
FILE: LICENSE
================================================
The MIT License (MIT)

Copyright (c) 2017 [these people](https://github.com/rollup/rollup-plugin-commonjs/graphs/contributors)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.


================================================
FILE: README.md
================================================
# Moved

This module has moved and is now available at [@rollup/plugin-commonjs](https://github.com/rollup/plugins). Please update your dependencies. This repository is no longer maintained.


# rollup-plugin-commonjs [![Build Status][travis-img]][travis]

[travis-img]: https://travis-ci.org/rollup/rollup-plugin-commonjs.svg
[travis]: https://travis-ci.org/rollup/rollup-plugin-commonjs

Convert CommonJS modules to ES6, so they can be included in a Rollup bundle


## Installation

```bash
npm install --save-dev rollup-plugin-commonjs
```


## Usage

Typically, you would use this plugin alongside [rollup-plugin-node-resolve](https://github.com/rollup/rollup-plugin-node-resolve), so that you could bundle your CommonJS dependencies in `node_modules`.

```js
// rollup.config.js
import commonjs from 'rollup-plugin-commonjs';
import nodeResolve from 'rollup-plugin-node-resolve';

export default {
  input: 'main.js',
  output: {
    file: 'bundle.js',
    format: 'iife'
  },
  plugins: [
    nodeResolve({
      jsnext: true,
      main: true
    }),

    commonjs({
      // non-CommonJS modules will be ignored, but you can also
      // specifically include/exclude files
      include: 'node_modules/**',  // Default: undefined
      exclude: [ 'node_modules/foo/**', 'node_modules/bar/**' ],  // Default: undefined
      // these values can also be regular expressions
      // include: /node_modules/

      // search for files other than .js files (must already
      // be transpiled by a previous plugin!)
      extensions: [ '.js', '.coffee' ],  // Default: [ '.js' ]

      // if true then uses of `global` won't be dealt with by this plugin
      ignoreGlobal: false,  // Default: false

      // if false then skip sourceMap generation for CommonJS modules
      sourceMap: false,  // Default: true

      // explicitly specify unresolvable named exports
      // (see below for more details)
      namedExports: { 'react': ['createElement', 'Component' ] },  // Default: undefined

      // sometimes you have to leave require statements
      // unconverted. Pass an array containing the IDs
      // or a `id => boolean` function. Only use this
      // option if you know what you're doing!
      ignore: [ 'conditional-runtime-dependency' ]
    })
  ]
};
```

### Usage with symlinks

Symlinks are common in monorepos and are also created by the `npm link` command. Rollup with `rollup-plugin-node-resolve` resolves modules to their real paths by default. So `include` and `exclude` paths should handle real paths rather than symlinked paths (e.g. `../common/node_modules/**` instead of `node_modules/**`). You may also use a regular expression for `include` that works regardless of base path. Try this:

```js
commonjs({
  include: /node_modules/
})
```

Whether symlinked module paths are [realpathed](http://man7.org/linux/man-pages/man3/realpath.3.html) or preserved depends on Rollup's `preserveSymlinks` setting, which is false by default, matching Node.js' default behavior. Setting `preserveSymlinks` to true in your Rollup config will cause `import` and `export` to match based on symlinked paths instead.

### Custom named exports

This plugin will attempt to create named exports, where appropriate, so you can do this...

```js
// importer.js
import { named } from './exporter.js';

// exporter.js
module.exports = { named: 42 }; // or `exports.named = 42;`
```

...but that's not always possible:

```js
// importer.js
import { named } from 'my-lib';

// my-lib.js
var myLib = exports;
myLib.named = 'you can\'t see me';
```

In those cases, you can specify custom named exports:

```js
commonjs({
  namedExports: {
    // left-hand side can be an absolute path, a path
    // relative to the current directory, or the name
    // of a module in node_modules
    'my-lib': [ 'named' ]
  }
})
```


## Strict mode

ES modules are *always* parsed in strict mode. That means that certain non-strict constructs (like octal literals) will be treated as syntax errors when Rollup parses modules that use them. Some older CommonJS modules depend on those constructs, and if you depend on them your bundle will blow up. There's basically nothing we can do about that.

Luckily, there is absolutely no good reason *not* to use strict mode for everything — so the solution to this problem is to lobby the authors of those modules to update them.


## License

MIT


================================================
FILE: appveyor.yml
================================================
# http://www.appveyor.com/docs/appveyor-yml

version: "{build}"

clone_depth: 10

init:
  - git config --global core.autocrlf false
  - git config --global core.symlinks true

environment:
  matrix:
    # node.js
    - nodejs_version: 8

install:
  - ps: Install-Product node $env:nodejs_version
  - IF %nodejs_version% LSS 7 npm -g install npm@4
  - npm install

build: off

test_script:
  - node --version && npm --version
  - npm test

matrix:
  fast_finish: false

# cache:
#   - C:\Users\appveyor\AppData\Roaming\npm-cache -> package.json     # npm cache
#   - node_modules -> package.json                                    # local npm modules


================================================
FILE: index.d.ts
================================================
import { Plugin } from 'rollup';

interface RollupCommonJSOptions {
	/**
	 * non-CommonJS modules will be ignored, but you can also
	 * specifically include/exclude files
	 * @default undefined
	 */
	include?: string | RegExp | ReadonlyArray<string | RegExp>,
	/**
	 * non-CommonJS modules will be ignored, but you can also
	 * specifically include/exclude files
	 * @default undefined
	 */
	exclude?: string | RegExp | ReadonlyArray<string | RegExp>,
	/**
	 * search for files other than .js files (must already
	 * be transpiled by a previous plugin!)
	 * @default [ '.js' ]
	 */
	extensions?: ReadonlyArray<string | RegExp>,
	/**
	 * if true then uses of `global` won't be dealt with by this plugin
	 * @default false
	 */
	ignoreGlobal?: boolean,
	/**
	 * if false then skip sourceMap generation for CommonJS modules
	 * @default true
	 */
	sourceMap?: boolean,
	/**
	 * explicitly specify unresolvable named exports
	 * ([see below for more details](https://github.com/rollup/rollup-plugin-commonjs#custom-named-exports))
	 * @default undefined
	 */
	namedExports?: { [package: string]: ReadonlyArray<string> },
	/**
	 * sometimes you have to leave require statements
	 * unconverted. Pass an array containing the IDs
	 * or a `id => boolean` function. Only use this
	 * option if you know what you're doing!
	 */
	ignore?: ReadonlyArray<string | ((id: string) => boolean)>,
}

/**
 * Convert CommonJS modules to ES6, so they can be included in a Rollup bundle
 */
export default function commonjs(options?: RollupCommonJSOptions): Plugin;


================================================
FILE: package.json
================================================
{
  "name": "rollup-plugin-commonjs",
  "version": "10.1.0",
  "description": "Convert CommonJS modules to ES2015",
  "main": "dist/rollup-plugin-commonjs.cjs.js",
  "module": "dist/rollup-plugin-commonjs.es.js",
  "jsnext:main": "dist/rollup-plugin-commonjs.es.js",
  "scripts": {
    "test": "npm run test:only",
    "test:only": "mocha && tsc",
    "pretest": "npm run build",
    "build": "shx rm -rf dist/* && rollup -c",
    "dev": "rollup -c -w",
    "lint": "prettier --write src/**/*.js test/test.js test/**/_config.js && eslint --fix src/**/*.js test/test.js test/**/_config.js",
    "prepublishOnly": "npm run lint && npm run test:only",
    "prepare": "npm run build"
  },
  "files": [
    "src",
    "dist",
    "index.d.ts",
    "README.md"
  ],
  "peerDependencies": {
    "rollup": ">=1.12.0"
  },
  "dependencies": {
    "estree-walker": "^0.6.1",
    "is-reference": "^1.1.2",
    "magic-string": "^0.25.2",
    "resolve": "^1.11.0",
    "rollup-pluginutils": "^2.8.1"
  },
  "devDependencies": {
    "@babel/core": "^7.4.5",
    "@babel/preset-env": "^7.4.5",
    "@babel/register": "^7.4.4",
    "acorn": "^6.1.1",
    "eslint": "^6.0.1",
    "eslint-plugin-import": "^2.18.0",
    "husky": "^2.4.1",
    "lint-staged": "^8.2.1",
    "locate-character": "^2.0.5",
    "mocha": "^6.1.4",
    "prettier": "^1.18.2",
    "require-relative": "^0.8.7",
    "rollup": "^1.16.2",
    "rollup-plugin-babel": "^4.3.3",
    "rollup-plugin-json": "^4.0.0",
    "rollup-plugin-node-resolve": "^5.1.0",
    "shx": "^0.3.2",
    "source-map": "^0.6.1",
    "source-map-support": "^0.5.12",
    "typescript": "^3.5.2"
  },
  "repository": "rollup/rollup-plugin-commonjs",
  "author": "Rich Harris",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/rollup/rollup-plugin-commonjs/issues"
  },
  "homepage": "https://github.com/rollup/rollup-plugin-commonjs"
}


================================================
FILE: rollup.config.js
================================================
import babel from 'rollup-plugin-babel';
import json from 'rollup-plugin-json';
import pkg from './package.json';

export default {
	input: 'src/index.js',
	plugins: [
		json(),
		babel()
	],
	external: Object.keys(pkg.dependencies).concat(['fs', 'path']),
	output: [
		{
			format: 'es',
			file: pkg.module,
			sourcemap: true
		},
		{
			format: 'cjs',
			file: pkg.main,
			sourcemap: true
		}
	]
};


================================================
FILE: src/ast-utils.js
================================================
export { default as isReference } from 'is-reference';

export function flatten(node) {
	const parts = [];

	while (node.type === 'MemberExpression') {
		if (node.computed) return null;

		parts.unshift(node.property.name);
		node = node.object;
	}

	if (node.type !== 'Identifier') return null;

	const name = node.name;
	parts.unshift(name);

	return { name, keypath: parts.join('.') };
}

export function extractNames(node) {
	const names = [];
	extractors[node.type](names, node);
	return names;
}

function getExtractor (type) {
	const extractor = extractors[type];
	if (!extractor)
		throw new SyntaxError(`${type} pattern not supported.`);
	return extractor;
}

const extractors = {
	Identifier(names, node) {
		names.push(node.name);
	},

	ObjectPattern(names, node) {
		node.properties.forEach(prop => {
			getExtractor(prop.value.type)(names, prop.value);
		});
	},

	ArrayPattern(names, node) {
		node.elements.forEach(element => {
			if (!element) return;
			getExtractor(element.type)(names, element);
		});
	},

	RestElement(names, node) {
		getExtractor(node.argument.type)(names, node.argument);
	},

	AssignmentPattern(names, node) {
		getExtractor(node.left.type)(names, node.left);
	}
};

export function isTruthy(node) {
	if (node.type === 'Literal') return !!node.value;
	if (node.type === 'ParenthesizedExpression') return isTruthy(node.expression);
	if (node.operator in operators) return operators[node.operator](node);
}

export function isFalsy(node) {
	return not(isTruthy(node));
}

function not(value) {
	return value === undefined ? value : !value;
}

function equals(a, b, strict) {
	if (a.type !== b.type) return undefined;
	if (a.type === 'Literal') return strict ? a.value === b.value : a.value == b.value;
}

const operators = {
	'==': x => {
		return equals(x.left, x.right, false);
	},

	'!=': x => not(operators['=='](x)),

	'===': x => {
		return equals(x.left, x.right, true);
	},

	'!==': x => not(operators['==='](x)),

	'!': x => isFalsy(x.argument),

	'&&': x => isTruthy(x.left) && isTruthy(x.right),

	'||': x => isTruthy(x.left) || isTruthy(x.right)
};


================================================
FILE: src/helpers.js
================================================
export const PROXY_SUFFIX = '?commonjs-proxy';
export const getProxyId = id => `\0${id}${PROXY_SUFFIX}`;
export const getIdFromProxyId = proxyId => proxyId.slice(1, -PROXY_SUFFIX.length);

export const EXTERNAL_SUFFIX = '?commonjs-external';
export const getExternalProxyId = id => `\0${id}${EXTERNAL_SUFFIX}`;
export const getIdFromExternalProxyId = proxyId => proxyId.slice(1, -EXTERNAL_SUFFIX.length);

export const HELPERS_ID = '\0commonjsHelpers.js';

// `x['default']` is used instead of `x.default` for backward compatibility with ES3 browsers.
// Minifiers like uglify will usually transpile it back if compatibility with ES3 is not enabled.
export const HELPERS = `
export var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};

export function commonjsRequire () {
	throw new Error('Dynamic requires are not currently supported by rollup-plugin-commonjs');
}

export function unwrapExports (x) {
	return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
}

export function createCommonjsModule(fn, module) {
	return module = { exports: {} }, fn(module, module.exports), module.exports;
}

export function getCjsExportFromNamespace (n) {
	return n && n['default'] || n;
}`;


================================================
FILE: src/index.js
================================================
import { realpathSync, existsSync } from 'fs';
import { extname, resolve, normalize } from 'path';
import { sync as nodeResolveSync, isCore } from 'resolve';
import { createFilter } from 'rollup-pluginutils';
import { peerDependencies } from '../package.json';
import {
	EXTERNAL_SUFFIX,
	getIdFromExternalProxyId,
	getIdFromProxyId,
	HELPERS,
	HELPERS_ID,
	PROXY_SUFFIX
} from './helpers';
import { getIsCjsPromise, setIsCjsPromise } from './is-cjs';
import { getResolveId } from './resolve-id';
import { checkEsModule, hasCjsKeywords, transformCommonjs } from './transform.js';
import { getName } from './utils.js';

export default function commonjs(options = {}) {
	const extensions = options.extensions || ['.js'];
	const filter = createFilter(options.include, options.exclude);
	const ignoreGlobal = options.ignoreGlobal;

	const customNamedExports = {};
	if (options.namedExports) {
		Object.keys(options.namedExports).forEach(id => {
			let resolveId = id;
			let resolvedId;

			if (isCore(id)) {
				// resolve will not find npm modules with the same name as
				// core modules without a trailing slash. Since core modules
				// must be external, we can assume any core modules defined
				// here are npm modules by that name.
				resolveId += '/';
			}

			try {
				resolvedId = nodeResolveSync(resolveId, { basedir: process.cwd() });
			} catch (err) {
				resolvedId = resolve(id);
			}

			// Note: customNamedExport's keys must be normalized file paths.
			// resolve and nodeResolveSync both return normalized file paths
			// so no additional normalization is necessary.
			customNamedExports[resolvedId] = options.namedExports[id];

			if (existsSync(resolvedId)) {
				const realpath = realpathSync(resolvedId);
				if (realpath !== resolvedId) {
					customNamedExports[realpath] = options.namedExports[id];
				}
			}
		});
	}

	const esModulesWithoutDefaultExport = new Set();
	const esModulesWithDefaultExport = new Set();
	const allowDynamicRequire = !!options.ignore; // TODO maybe this should be configurable?

	const ignoreRequire =
		typeof options.ignore === 'function'
			? options.ignore
			: Array.isArray(options.ignore)
				? id => options.ignore.includes(id)
				: () => false;

	const resolveId = getResolveId(extensions);

	const sourceMap = options.sourceMap !== false;

	function transformAndCheckExports(code, id) {
		{
			const { isEsModule, hasDefaultExport, ast } = checkEsModule(this.parse, code, id);
			if (isEsModule) {
				(hasDefaultExport ? esModulesWithDefaultExport : esModulesWithoutDefaultExport).add(id);
				return null;
			}

			// it is not an ES module but it does not have CJS-specific elements.
			if (!hasCjsKeywords(code, ignoreGlobal)) {
				esModulesWithoutDefaultExport.add(id);
				return null;
			}

			const normalizedId = normalize(id);

			const transformed = transformCommonjs(
				this.parse,
				code,
				id,
				this.getModuleInfo(id).isEntry,
				ignoreGlobal,
				ignoreRequire,
				customNamedExports[normalizedId],
				sourceMap,
				allowDynamicRequire,
				ast
			);
			if (!transformed) {
				esModulesWithoutDefaultExport.add(id);
				return null;
			}

			return transformed;
		}
	}

	return {
		name: 'commonjs',

		buildStart() {
			const [major, minor] = this.meta.rollupVersion.split('.').map(Number);
			const minVersion = peerDependencies.rollup.slice(2);
			const [minMajor, minMinor] = minVersion.split('.').map(Number);
			if (major < minMajor || (major === minMajor && minor < minMinor)) {
				this.error(
					`Insufficient Rollup version: "rollup-plugin-commonjs" requires at least rollup@${minVersion} but found rollup@${this.meta.rollupVersion}.`
				);
			}
		},

		resolveId,

		load(id) {
			if (id === HELPERS_ID) return HELPERS;

			// generate proxy modules
			if (id.endsWith(EXTERNAL_SUFFIX)) {
				const actualId = getIdFromExternalProxyId(id);
				const name = getName(actualId);

				return `import ${name} from ${JSON.stringify(actualId)}; export default ${name};`;
			}

			if (id.endsWith(PROXY_SUFFIX)) {
				const actualId = getIdFromProxyId(id);
				const name = getName(actualId);

				return getIsCjsPromise(actualId).then(isCjs => {
					if (isCjs)
						return `import { __moduleExports } from ${JSON.stringify(
							actualId
						)}; export default __moduleExports;`;
					else if (esModulesWithoutDefaultExport.has(actualId))
						return `import * as ${name} from ${JSON.stringify(actualId)}; export default ${name};`;
					else if (esModulesWithDefaultExport.has(actualId)) {
						return `export {default} from ${JSON.stringify(actualId)};`;
					} else
						return `import * as ${name} from ${JSON.stringify(
							actualId
						)}; import {getCjsExportFromNamespace} from "${HELPERS_ID}"; export default getCjsExportFromNamespace(${name})`;
				});
			}
		},

		transform(code, id) {
			if (!filter(id) || extensions.indexOf(extname(id)) === -1) {
				setIsCjsPromise(id, null);
				return null;
			}

			let transformed;
			try {
				transformed = transformAndCheckExports.call(this, code, id);
			} catch (err) {
				transformed = null;
				this.error(err, err.loc);
			}

			setIsCjsPromise(id, Boolean(transformed));
			return transformed;
		}
	};
}


================================================
FILE: src/is-cjs.js
================================================
const isCjsPromises = new Map();

export function getIsCjsPromise(id) {
	let isCjsPromise = isCjsPromises.get(id);
	if (isCjsPromise) return isCjsPromise.promise;

	const promise = new Promise(resolve => {
		isCjsPromise = {
			resolve,
			promise: undefined
		};
		isCjsPromises.set(id, isCjsPromise);
	});
	isCjsPromise.promise = promise;

	return promise;
}

export function setIsCjsPromise(id, resolution) {
	const isCjsPromise = isCjsPromises.get(id);
	if (isCjsPromise) {
		if (isCjsPromise.resolve) {
			isCjsPromise.resolve(resolution);
			isCjsPromise.resolve = undefined;
		}
	} else {
		isCjsPromises.set(id, { promise: Promise.resolve(resolution), resolve: undefined });
	}
}


================================================
FILE: src/resolve-id.js
================================================
import { statSync } from 'fs';
import { dirname, resolve, sep } from 'path';
import {
	getExternalProxyId,
	getIdFromProxyId,
	getProxyId,
	HELPERS_ID,
	PROXY_SUFFIX
} from './helpers';

function getCandidatesForExtension(resolved, extension) {
	return [resolved + extension, resolved + `${sep}index${extension}`];
}

function getCandidates(resolved, extensions) {
	return extensions.reduce(
		(paths, extension) => paths.concat(getCandidatesForExtension(resolved, extension)),
		[resolved]
	);
}

export function getResolveId(extensions) {
	function resolveExtensions(importee, importer) {
		if (importee[0] !== '.' || !importer) return; // not our problem

		const resolved = resolve(dirname(importer), importee);
		const candidates = getCandidates(resolved, extensions);

		for (let i = 0; i < candidates.length; i += 1) {
			try {
				const stats = statSync(candidates[i]);
				if (stats.isFile()) return { id: candidates[i] };
			} catch (err) {
				/* noop */
			}
		}
	}

	function resolveId(importee, importer) {
		const isProxyModule = importee.endsWith(PROXY_SUFFIX);
		if (isProxyModule) {
			importee = getIdFromProxyId(importee);
		} else if (importee.startsWith('\0')) {
			if (importee === HELPERS_ID) {
				return importee;
			}
			return null;
		}

		if (importer && importer.endsWith(PROXY_SUFFIX)) {
			importer = getIdFromProxyId(importer);
		}

		return this.resolve(importee, importer, { skipSelf: true }).then(resolved => {
			if (!resolved) {
				resolved = resolveExtensions(importee, importer);
			}
			if (isProxyModule) {
				if (!resolved) {
					return { id: getExternalProxyId(importee), external: false };
				}
				resolved.id = (resolved.external ? getExternalProxyId : getProxyId)(resolved.id);
				resolved.external = false;
				return resolved;
			}
			return resolved;
		});
	}

	return resolveId;
}


================================================
FILE: src/transform.js
================================================
import { walk } from 'estree-walker';
import MagicString from 'magic-string';
import { attachScopes, extractAssignedNames, makeLegalIdentifier } from 'rollup-pluginutils';
import { flatten, isFalsy, isReference, isTruthy } from './ast-utils.js';
import { getProxyId, HELPERS_ID } from './helpers';
import { getName } from './utils.js';

const reserved = 'process location abstract arguments boolean break byte case catch char class const continue debugger default delete do double else enum eval export extends false final finally float for from function goto if implements import in instanceof int interface let long native new null package private protected public return short static super switch synchronized this throw throws transient true try typeof var void volatile while with yield'.split(
	' '
);
const blacklist = { __esModule: true };
reserved.forEach(word => (blacklist[word] = true));

const exportsPattern = /^(?:module\.)?exports(?:\.([a-zA-Z_$][a-zA-Z_$0-9]*))?$/;

const firstpassGlobal = /\b(?:require|module|exports|global)\b/;
const firstpassNoGlobal = /\b(?:require|module|exports)\b/;
const importExportDeclaration = /^(?:Import|Export(?:Named|Default))Declaration/;
const functionType = /^(?:FunctionDeclaration|FunctionExpression|ArrowFunctionExpression)$/;

function deconflict(scope, globals, identifier) {
	let i = 1;
	let deconflicted = identifier;

	while (scope.contains(deconflicted) || globals.has(deconflicted) || deconflicted in blacklist)
		deconflicted = `${identifier}_${i++}`;
	scope.declarations[deconflicted] = true;

	return deconflicted;
}

function tryParse(parse, code, id) {
	try {
		return parse(code, { allowReturnOutsideFunction: true });
	} catch (err) {
		err.message += ` in ${id}`;
		throw err;
	}
}

export function hasCjsKeywords(code, ignoreGlobal) {
	const firstpass = ignoreGlobal ? firstpassNoGlobal : firstpassGlobal;
	return firstpass.test(code);
}

export function checkEsModule(parse, code, id) {
	const ast = tryParse(parse, code, id);

	let isEsModule = false;
	for (const node of ast.body) {
		if (node.type === 'ExportDefaultDeclaration')
			return { isEsModule: true, hasDefaultExport: true, ast };
		if (node.type === 'ExportNamedDeclaration') {
			isEsModule = true;
			for (const specifier of node.specifiers) {
				if (specifier.exported.name === 'default') {
					return { isEsModule: true, hasDefaultExport: true, ast };
				}
			}
		} else if (importExportDeclaration.test(node.type)) isEsModule = true;
	}

	return { isEsModule, hasDefaultExport: false, ast };
}

export function transformCommonjs(
	parse,
	code,
	id,
	isEntry,
	ignoreGlobal,
	ignoreRequire,
	customNamedExports,
	sourceMap,
	allowDynamicRequire,
	astCache
) {
	const ast = astCache || tryParse(parse, code, id);

	const magicString = new MagicString(code);

	const required = {};
	// Because objects have no guaranteed ordering, yet we need it,
	// we need to keep track of the order in a array
	const sources = [];

	let uid = 0;

	let scope = attachScopes(ast, 'scope');
	const uses = { module: false, exports: false, global: false, require: false };

	let lexicalDepth = 0;
	let programDepth = 0;

	const globals = new Set();

	const HELPERS_NAME = deconflict(scope, globals, 'commonjsHelpers'); // TODO technically wrong since globals isn't populated yet, but ¯\_(ツ)_/¯

	const namedExports = {};

	// TODO handle transpiled modules
	let shouldWrap = /__esModule/.test(code);

	function isRequireStatement(node) {
		if (!node) return;
		if (node.type !== 'CallExpression') return;
		if (node.callee.name !== 'require' || scope.contains('require')) return;
		if (node.arguments.length === 0) return; // Weird case of require() without arguments
		return true;
	}

	function hasDynamicArguments(node) {
		return (
			node.arguments.length > 1 ||
			(node.arguments[0].type !== 'Literal' &&
				(node.arguments[0].type !== 'TemplateLiteral' || node.arguments[0].expressions.length > 0))
		);
	}

	function isStaticRequireStatement(node) {
		if (!isRequireStatement(node)) return;
		if (hasDynamicArguments(node)) return;
		if (ignoreRequire(node.arguments[0].value)) return;
		return true;
	}

	function getRequireStringArg(node) {
		return node.arguments[0].type === 'Literal'
			? node.arguments[0].value
			: node.arguments[0].quasis[0].value.cooked;
	}

	function getRequired(node, name) {
		const sourceId = getRequireStringArg(node);
		const existing = required[sourceId];
		if (existing === undefined) {
			if (!name) {
				do name = `require$$${uid++}`;
				while (scope.contains(name));
			}

			sources.push(sourceId);
			required[sourceId] = { source: sourceId, name, importsDefault: false };
		}

		return required[sourceId];
	}

	// do a first pass, see which names are assigned to. This is necessary to prevent
	// illegally replacing `var foo = require('foo')` with `import foo from 'foo'`,
	// where `foo` is later reassigned. (This happens in the wild. CommonJS, sigh)
	const assignedTo = new Set();
	walk(ast, {
		enter(node) {
			if (node.type !== 'AssignmentExpression') return;
			if (node.left.type === 'MemberExpression') return;

			extractAssignedNames(node.left).forEach(name => {
				assignedTo.add(name);
			});
		}
	});

	walk(ast, {
		enter(node, parent) {
			if (sourceMap) {
				magicString.addSourcemapLocation(node.start);
				magicString.addSourcemapLocation(node.end);
			}

			// skip dead branches
			if (parent && (parent.type === 'IfStatement' || parent.type === 'ConditionalExpression')) {
				if (node === parent.consequent && isFalsy(parent.test)) return this.skip();
				if (node === parent.alternate && isTruthy(parent.test)) return this.skip();
			}

			if (node._skip) return this.skip();

			programDepth += 1;

			if (node.scope) scope = node.scope;
			if (functionType.test(node.type)) lexicalDepth += 1;

			// if toplevel return, we need to wrap it
			if (node.type === 'ReturnStatement' && lexicalDepth === 0) {
				shouldWrap = true;
			}

			// rewrite `this` as `commonjsHelpers.commonjsGlobal`
			if (node.type === 'ThisExpression' && lexicalDepth === 0) {
				uses.global = true;
				if (!ignoreGlobal)
					magicString.overwrite(node.start, node.end, `${HELPERS_NAME}.commonjsGlobal`, {
						storeName: true
					});
				return;
			}

			// rewrite `typeof module`, `typeof module.exports` and `typeof exports` (https://github.com/rollup/rollup-plugin-commonjs/issues/151)
			if (node.type === 'UnaryExpression' && node.operator === 'typeof') {
				const flattened = flatten(node.argument);
				if (!flattened) return;

				if (scope.contains(flattened.name)) return;

				if (
					flattened.keypath === 'module.exports' ||
					flattened.keypath === 'module' ||
					flattened.keypath === 'exports'
				) {
					magicString.overwrite(node.start, node.end, `'object'`, { storeName: false });
				}
			}

			// rewrite `require` (if not already handled) `global` and `define`, and handle free references to
			// `module` and `exports` as these mean we need to wrap the module in commonjsHelpers.createCommonjsModule
			if (node.type === 'Identifier') {
				if (isReference(node, parent) && !scope.contains(node.name)) {
					if (node.name in uses) {
						if (node.name === 'require') {
							if (allowDynamicRequire) return;
							magicString.overwrite(node.start, node.end, `${HELPERS_NAME}.commonjsRequire`, {
								storeName: true
							});
						}

						uses[node.name] = true;
						if (node.name === 'global' && !ignoreGlobal) {
							magicString.overwrite(node.start, node.end, `${HELPERS_NAME}.commonjsGlobal`, {
								storeName: true
							});
						}

						// if module or exports are used outside the context of an assignment
						// expression, we need to wrap the module
						if (node.name === 'module' || node.name === 'exports') {
							shouldWrap = true;
						}
					}

					if (node.name === 'define') {
						magicString.overwrite(node.start, node.end, 'undefined', { storeName: true });
					}

					globals.add(node.name);
				}

				return;
			}

			// Is this an assignment to exports or module.exports?
			if (node.type === 'AssignmentExpression') {
				if (node.left.type !== 'MemberExpression') return;

				const flattened = flatten(node.left);
				if (!flattened) return;

				if (scope.contains(flattened.name)) return;

				const match = exportsPattern.exec(flattened.keypath);
				if (!match || flattened.keypath === 'exports') return;

				uses[flattened.name] = true;

				// we're dealing with `module.exports = ...` or `[module.]exports.foo = ...` –
				// if this isn't top-level, we'll need to wrap the module
				if (programDepth > 3) shouldWrap = true;

				node.left._skip = true;

				if (flattened.keypath === 'module.exports' && node.right.type === 'ObjectExpression') {
					return node.right.properties.forEach(prop => {
						if (prop.computed || prop.key.type !== 'Identifier') return;
						const name = prop.key.name;
						if (name === makeLegalIdentifier(name)) namedExports[name] = true;
					});
				}

				if (match[1]) namedExports[match[1]] = true;
				return;
			}

			// if this is `var x = require('x')`, we can do `import x from 'x'`
			if (
				node.type === 'VariableDeclarator' &&
				node.id.type === 'Identifier' &&
				isStaticRequireStatement(node.init)
			) {
				// for now, only do this for top-level requires. maybe fix this in future
				if (scope.parent) return;

				// edge case — CJS allows you to assign to imports. ES doesn't
				if (assignedTo.has(node.id.name)) return;

				const required = getRequired(node.init, node.id.name);
				required.importsDefault = true;

				if (required.name === node.id.name) {
					node._shouldRemove = true;
				}
			}

			if (!isStaticRequireStatement(node)) return;

			const required = getRequired(node);

			if (parent.type === 'ExpressionStatement') {
				// is a bare import, e.g. `require('foo');`
				magicString.remove(parent.start, parent.end);
			} else {
				required.importsDefault = true;
				magicString.overwrite(node.start, node.end, required.name);
			}

			node.callee._skip = true;
		},

		leave(node) {
			programDepth -= 1;
			if (node.scope) scope = scope.parent;
			if (functionType.test(node.type)) lexicalDepth -= 1;

			if (node.type === 'VariableDeclaration') {
				let keepDeclaration = false;
				let c = node.declarations[0].start;

				for (let i = 0; i < node.declarations.length; i += 1) {
					const declarator = node.declarations[i];

					if (declarator._shouldRemove) {
						magicString.remove(c, declarator.end);
					} else {
						if (!keepDeclaration) {
							magicString.remove(c, declarator.start);
							keepDeclaration = true;
						}

						c = declarator.end;
					}
				}

				if (!keepDeclaration) {
					magicString.remove(node.start, node.end);
				}
			}
		}
	});

	if (
		!sources.length &&
		!uses.module &&
		!uses.exports &&
		!uses.require &&
		(ignoreGlobal || !uses.global)
	) {
		if (Object.keys(namedExports).length) {
			throw new Error(
				`Custom named exports were specified for ${id} but it does not appear to be a CommonJS module`
			);
		}
		return null; // not a CommonJS module
	}

	const includeHelpers = shouldWrap || uses.global || uses.require;
	const importBlock =
		(includeHelpers ? [`import * as ${HELPERS_NAME} from '${HELPERS_ID}';`] : [])
			.concat(
				sources.map(source => {
					// import the actual module before the proxy, so that we know
					// what kind of proxy to build
					return `import '${source}';`;
				}),
				sources.map(source => {
					const { name, importsDefault } = required[source];
					return `import ${importsDefault ? `${name} from ` : ``}'${getProxyId(source)}';`;
				})
			)
			.join('\n') + '\n\n';

	const namedExportDeclarations = [];
	let wrapperStart = '';
	let wrapperEnd = '';

	const moduleName = deconflict(scope, globals, getName(id));
	if (!isEntry) {
		const exportModuleExports = {
			str: `export { ${moduleName} as __moduleExports };`,
			name: '__moduleExports'
		};

		namedExportDeclarations.push(exportModuleExports);
	}

	const name = getName(id);

	function addExport(x) {
		const deconflicted = deconflict(scope, globals, name);

		const declaration =
			deconflicted === name
				? `export var ${x} = ${moduleName}.${x};`
				: `var ${deconflicted} = ${moduleName}.${x};\nexport { ${deconflicted} as ${x} };`;

		namedExportDeclarations.push({
			str: declaration,
			name: x
		});
	}

	if (customNamedExports) customNamedExports.forEach(addExport);

	const defaultExportPropertyAssignments = [];
	let hasDefaultExport = false;

	if (shouldWrap) {
		const args = `module${uses.exports ? ', exports' : ''}`;

		wrapperStart = `var ${moduleName} = ${HELPERS_NAME}.createCommonjsModule(function (${args}) {\n`;
		wrapperEnd = `\n});`;
	} else {
		const names = [];

		ast.body.forEach(node => {
			if (node.type === 'ExpressionStatement' && node.expression.type === 'AssignmentExpression') {
				const left = node.expression.left;
				const flattened = flatten(left);

				if (!flattened) return;

				const match = exportsPattern.exec(flattened.keypath);
				if (!match) return;

				if (flattened.keypath === 'module.exports') {
					hasDefaultExport = true;
					magicString.overwrite(left.start, left.end, `var ${moduleName}`);
				} else {
					const name = match[1];
					const deconflicted = deconflict(scope, globals, name);

					names.push({ name, deconflicted });

					magicString.overwrite(node.start, left.end, `var ${deconflicted}`);

					const declaration =
						name === deconflicted
							? `export { ${name} };`
							: `export { ${deconflicted} as ${name} };`;

					if (name !== 'default') {
						namedExportDeclarations.push({
							str: declaration,
							name
						});
						delete namedExports[name];
					}

					defaultExportPropertyAssignments.push(`${moduleName}.${name} = ${deconflicted};`);
				}
			}
		});

		if (!hasDefaultExport && (names.length || !isEntry)) {
			wrapperEnd = `\n\nvar ${moduleName} = {\n${names
				.map(({ name, deconflicted }) => `\t${name}: ${deconflicted}`)
				.join(',\n')}\n};`;
		}
	}
	Object.keys(namedExports)
		.filter(key => !blacklist[key])
		.forEach(addExport);

	const defaultExport = /__esModule/.test(code)
		? `export default ${HELPERS_NAME}.unwrapExports(${moduleName});`
		: `export default ${moduleName};`;

	const named = namedExportDeclarations
		.filter(x => x.name !== 'default' || !hasDefaultExport)
		.map(x => x.str);

	const exportBlock =
		'\n\n' +
		[defaultExport]
			.concat(named)
			.concat(hasDefaultExport ? defaultExportPropertyAssignments : [])
			.join('\n');

	magicString
		.trim()
		.prepend(importBlock + wrapperStart)
		.trim()
		.append(wrapperEnd);

	if (hasDefaultExport || named.length > 0 || shouldWrap || !isEntry) {
		magicString.append(exportBlock);
	}

	code = magicString.toString();
	const map = sourceMap ? magicString.generateMap() : null;

	return { code, map };
}


================================================
FILE: src/utils.js
================================================
import { basename, dirname, extname, sep } from 'path';
import { makeLegalIdentifier } from 'rollup-pluginutils';

export function getName(id) {
	const name = makeLegalIdentifier(basename(id, extname(id)));
	if (name !== 'index') {
		return name;
	} else {
		const segments = dirname(id).split(sep);
		return makeLegalIdentifier(segments[segments.length - 1]);
	}
}

// Return the first non-falsy result from an array of
// maybe-sync, maybe-promise-returning functions
export function first(candidates) {
	return function(...args) {
		return candidates.reduce((promise, candidate) => {
			return promise.then(result =>
				result != null ? result : Promise.resolve(candidate.call(this, ...args))
			);
		}, Promise.resolve());
	};
}


================================================
FILE: test/form/async-function/input.js
================================================
module.exports = async function () {
	// TODO
};


================================================
FILE: test/form/async-function/output.js
================================================
var input = async function () {
	// TODO
};

export default input;
export { input as __moduleExports };


================================================
FILE: test/form/constant-template-literal/input.js
================================================
var foo = require(`tape`);
console.log(foo);


================================================
FILE: test/form/constant-template-literal/output.js
================================================
import 'tape';
import foo from '_tape?commonjs-proxy';

console.log(foo);

var input = {

};

export default input;
export { input as __moduleExports };


================================================
FILE: test/form/dynamic-template-literal/input.js
================================================
var pe = 'pe';
var foo = require(`ta${pe}`);
console.log(foo);


================================================
FILE: test/form/dynamic-template-literal/output.js
================================================
import * as commonjsHelpers from '_commonjsHelpers.js';

var pe = 'pe';
var foo = commonjsHelpers.commonjsRequire(`ta${pe}`);
console.log(foo);

var input = {

};

export default input;
export { input as __moduleExports };


================================================
FILE: test/form/ignore-ids/_config.js
================================================
module.exports = {
	options: {
		ignore: ['foo']
	}
};


================================================
FILE: test/form/ignore-ids/input.js
================================================
var foo = require( 'foo' );
var bar = require( 'bar' );

================================================
FILE: test/form/ignore-ids/output.js
================================================
import 'bar';
import bar from '_bar?commonjs-proxy';

var foo = require( 'foo' );

var input = {

};

export default input;
export { input as __moduleExports };


================================================
FILE: test/form/ignore-ids-function/_config.js
================================================
module.exports = {
	options: {
		ignore: id => id === 'foo'
	}
};


================================================
FILE: test/form/ignore-ids-function/input.js
================================================
var foo = require( 'foo' );
var bar = require( 'bar' );

================================================
FILE: test/form/ignore-ids-function/output.js
================================================
import 'bar';
import bar from '_bar?commonjs-proxy';

var foo = require( 'foo' );

var input = {

};

export default input;
export { input as __moduleExports };


================================================
FILE: test/form/multiple-var-declarations/input.js
================================================
var a = require('./a')()
  , b = require('./b');

console.log( a, b );

================================================
FILE: test/form/multiple-var-declarations/output.js
================================================
import './a';
import './b';
import require$$0 from '_./a?commonjs-proxy';
import b from '_./b?commonjs-proxy';

var a = require$$0();

console.log( a, b );

var input = {

};

export default input;
export { input as __moduleExports };


================================================
FILE: test/form/multiple-var-declarations-b/input.js
================================================
var a = require('./a')
  , b = 42;

console.log( a, b );

================================================
FILE: test/form/multiple-var-declarations-b/output.js
================================================
import './a';
import a from '_./a?commonjs-proxy';

var b = 42;

console.log( a, b );

var input = {

};

export default input;
export { input as __moduleExports };


================================================
FILE: test/form/multiple-var-declarations-c/input.js
================================================
var a = 'a'
  , b = require( './b' )
  , c = 'c';

console.log( a, b, c );

================================================
FILE: test/form/multiple-var-declarations-c/output.js
================================================
import './b';
import b from '_./b?commonjs-proxy';

var a = 'a'
  , c = 'c';

console.log( a, b, c );

var input = {

};

export default input;
export { input as __moduleExports };


================================================
FILE: test/form/no-exports-entry/_config.js
================================================
module.exports = {
	options: {
		ignore: [ 'foo' ]
	},
	entry: './input.js'
};


================================================
FILE: test/form/no-exports-entry/input.js
================================================
var dummy = require('./dummy');

var foo = function () {
	return;
};

var input = 42;


================================================
FILE: test/form/no-exports-entry/output.js
================================================
import './dummy';
import dummy from '_./dummy?commonjs-proxy';

var foo = function () {
	return;
};

var input = 42;


================================================
FILE: test/form/no-toplevel-return/input.js
================================================
var foo = function () {
	return;
};

var bar = () => {
	return;
};

function baz () {
	return;
}

module.exports = 42;


================================================
FILE: test/form/no-toplevel-return/output.js
================================================
var foo = function () {
	return;
};

var bar = () => {
	return;
};

function baz () {
	return;
}

var input = 42;

export default input;
export { input as __moduleExports };


================================================
FILE: test/form/optimised-default-export/input.js
================================================
module.exports = 42;


================================================
FILE: test/form/optimised-default-export/output.js
================================================
var input = 42;

export default input;
export { input as __moduleExports };


================================================
FILE: test/form/optimised-default-export-function/input.js
================================================
module.exports = function foo () {};


================================================
FILE: test/form/optimised-default-export-function/output.js
================================================
var input = function foo () {};

export default input;
export { input as __moduleExports };


================================================
FILE: test/form/optimised-default-export-function-double-assign/input.js
================================================
var bar;
module.exports = bar = function foo () {};


================================================
FILE: test/form/optimised-default-export-function-double-assign/output.js
================================================
var bar;
var input = bar = function foo () {};

export default input;
export { input as __moduleExports };


================================================
FILE: test/form/optimised-default-export-iife/input.js
================================================
module.exports = (function foo () {
  return function fooChild() {};
}());


================================================
FILE: test/form/optimised-default-export-iife/output.js
================================================
var input = (function foo () {
  return function fooChild() {};
}());

export default input;
export { input as __moduleExports };


================================================
FILE: test/form/optimised-named-export/input.js
================================================
exports.foo = 'a';
module.exports.bar = 'b';


================================================
FILE: test/form/optimised-named-export/output.js
================================================
var foo = 'a';
var bar = 'b';

var input = {
	foo: foo,
	bar: bar
};

export default input;
export { input as __moduleExports };
export { foo };
export { bar };


================================================
FILE: test/form/optimised-named-export-conflicts/input.js
================================================
var foo = 1;
var bar = 2;

exports.foo = 'a';
module.exports.bar = 'b';


================================================
FILE: test/form/optimised-named-export-conflicts/output.js
================================================
var foo = 1;
var bar = 2;

var foo_1 = 'a';
var bar_1 = 'b';

var input = {
	foo: foo_1,
	bar: bar_1
};

export default input;
export { input as __moduleExports };
export { foo_1 as foo };
export { bar_1 as bar };


================================================
FILE: test/form/require-collision/input.js
================================================
(function() {
  var foo = require("foo");
  var require$$0 = "FAIL";
  console.log(foo);
})();


================================================
FILE: test/form/require-collision/output.js
================================================
import 'foo';
import require$$1 from '_foo?commonjs-proxy';

(function() {
  var foo = require$$1;
  var require$$0 = "FAIL";
  console.log(foo);
})();

var input = {

};

export default input;
export { input as __moduleExports };


================================================
FILE: test/form/typeof-module-exports/input.js
================================================
var foo = 42;

if ( typeof exports === 'object' && typeof module === 'object' ) {
	module.exports = foo;
} else if ( typeof define === 'function' && define.amd ) {
	define([], function () { return foo; });
} else {
	window.foo = foo;
}


================================================
FILE: test/form/typeof-module-exports/output.js
================================================
import * as commonjsHelpers from '_commonjsHelpers.js';

var input = commonjsHelpers.createCommonjsModule(function (module, exports) {
var foo = 42;

if ( 'object' === 'object' && 'object' === 'object' ) {
	module.exports = foo;
} else if ( typeof undefined === 'function' && undefined.amd ) {
	undefined([], function () { return foo; });
} else {
	window.foo = foo;
}
});

export default input;
export { input as __moduleExports };


================================================
FILE: test/form/unambiguous-with-default-export/input.js
================================================
require( './foo.js' );

export default {};


================================================
FILE: test/form/unambiguous-with-default-export/output.js
================================================
require( './foo.js' );

export default {};


================================================
FILE: test/form/unambiguous-with-import/input.js
================================================
require( './foo.js' );

import './bar.js';


================================================
FILE: test/form/unambiguous-with-import/output.js
================================================
require( './foo.js' );

import './bar.js';


================================================
FILE: test/form/unambiguous-with-named-export/input.js
================================================
require( './foo.js' );

export {};


================================================
FILE: test/form/unambiguous-with-named-export/output.js
================================================
require( './foo.js' );

export {};


================================================
FILE: test/function/__esModule/answer.js
================================================
exports.__esModule = true;
exports.answer = 42;


================================================
FILE: test/function/__esModule/main.js
================================================
import * as x from './answer';

assert.ok( 'answer' in x );
assert.ok( 'default' in x );
assert.ok( !( '__esModule' in x ) );


================================================
FILE: test/function/assign-properties-to-default-export/foo.js
================================================
var foo = {};

module.exports = foo;
module.exports.bar = 1;
exports.baz = 2;


================================================
FILE: test/function/assign-properties-to-default-export/main.js
================================================
import foo from './foo.js';

assert.equal( foo.bar, 1 );
assert.equal( foo.baz, 2 );


================================================
FILE: test/function/assumed-globals/_config.js
================================================
module.exports = {
	context: {
		document: { real: true }
	}
};


================================================
FILE: test/function/assumed-globals/document.js
================================================
if ( typeof document !== 'undefined' ) {
	module.exports = document;
} else {
	module.exports = { fake: true };
}


================================================
FILE: test/function/assumed-globals/main.js
================================================
import document from './document.js';

assert.deepEqual( document, { real: true });


================================================
FILE: test/function/bare-import/_config.js
================================================
module.exports = {};


================================================
FILE: test/function/bare-import/bar.js
================================================
Math.bar = 42;


================================================
FILE: test/function/bare-import/foo.js
================================================
require( './bar.js' );


================================================
FILE: test/function/bare-import/main.js
================================================
import './foo.js';

assert.equal( Math.bar, 42 );


================================================
FILE: test/function/bare-import-comment/bar.js
================================================
// Great module
Math.bar = 42;


================================================
FILE: test/function/bare-import-comment/foo.js
================================================
require( './bar.js' );


================================================
FILE: test/function/bare-import-comment/main.js
================================================
import './foo.js';

assert.equal( Math.bar, 42 );


================================================
FILE: test/function/basic/_config.js
================================================
const assert = require('assert');

module.exports = {
	exports: exports => {
		assert.equal(exports, 42);
	}
};


================================================
FILE: test/function/basic/foo.js
================================================
module.exports = 21;


================================================
FILE: test/function/basic/main.js
================================================
var foo = require( './foo' );
module.exports = foo * 2;


================================================
FILE: test/function/deconflict-export-and-local/index.js
================================================
var someValueModule = require('./someValue');

exports.someValue = someValueModule.someValue;


================================================
FILE: test/function/deconflict-export-and-local/main.js
================================================
import { someValue } from './index.js';

assert.equal( someValue, 10 );


================================================
FILE: test/function/deconflict-export-and-local/someValue.js
================================================
exports.someValue = 10;


================================================
FILE: test/function/dot/foo.bar.js
================================================
module.exports = 'fubar';


================================================
FILE: test/function/dot/main.js
================================================
var status = require( './foo.bar' );

assert.equal( status, 'fubar' );


================================================
FILE: test/function/duplicate-default-exports/main.js
================================================
import x from './x';

assert.strictEqual( x.default, x );

================================================
FILE: test/function/duplicate-default-exports/x.js
================================================
var x = {};

module.exports = x;
module.exports.default = x;

================================================
FILE: test/function/duplicate-default-exports-b/main.js
================================================
import x from './x';

assert.deepEqual( x, { default: 42 });

================================================
FILE: test/function/duplicate-default-exports-b/x.js
================================================
var x = {};

module.exports = x;
module.exports.default = 42;

================================================
FILE: test/function/duplicate-default-exports-c/exports.js
================================================
exports.Foo = 1;
exports.var = 'VAR';
exports.default = {
	Foo: 2,
	default: 3
};


================================================
FILE: test/function/duplicate-default-exports-c/main.js
================================================
import E from './exports.js';
import { Foo } from './exports.js';
import { var as Var } from './exports.js';

assert.strictEqual( E.Foo, 1 );
assert.strictEqual( E.var, 'VAR' );
assert.deepEqual( E.default, { Foo: 2, default:  3 });
assert.strictEqual( E.default.Foo, 2 );
assert.strictEqual( E.default.default, 3 );
assert.strictEqual( Foo, 1 );
assert.strictEqual( Var, 'VAR' );


================================================
FILE: test/function/export-default-from/_config.js
================================================
module.exports = {};


================================================
FILE: test/function/export-default-from/imported.js
================================================
export default 'default export';


================================================
FILE: test/function/export-default-from/main.js
================================================
assert.equal(require('./reexporter'), 'default export');


================================================
FILE: test/function/export-default-from/reexporter.js
================================================
export {default} from './imported';


================================================
FILE: test/function/exports/_config.js
================================================
const assert = require('assert');

module.exports = {
	exports: exports => {
		assert.equal(exports, 'BARBAZ');
	}
};


================================================
FILE: test/function/exports/foo.js
================================================
exports.bar = 'BAR';
exports.baz = 'BAZ';


================================================
FILE: test/function/exports/main.js
================================================
var bar = require( './foo' ).bar;
var baz = require( './foo' ).baz;

module.exports = bar + baz;


================================================
FILE: test/function/external-imports/_config.js
================================================
const assert = require('assert');

module.exports = {
	options: {
		external: ['foo']
	},
	exports: exports => {
		assert.equal(exports, 'foo');
	}
};


================================================
FILE: test/function/external-imports/main.js
================================================
var foo = require( 'foo' );

module.exports = foo;


================================================
FILE: test/function/fallback-no-default/foo.js
================================================
export var one = 1;

export var two = 2;


================================================
FILE: test/function/fallback-no-default/main.js
================================================
var foo = require('./foo.js');

assert.equal( foo.one, 1 );
assert.equal( foo.two, 2 );


================================================
FILE: test/function/global-not-overwritten/_config.js
================================================
const assert = require('assert');

module.exports = {
	exports(exports) {
		assert.equal(exports.encoded, encodeURIComponent('test string'));
	}
};


================================================
FILE: test/function/global-not-overwritten/encode.js
================================================
exports.encodeURIComponent = function () {
	return encodeURIComponent( this.str );
};

global.foo = exports; // to ensure module is wrapped


================================================
FILE: test/function/global-not-overwritten/main.js
================================================
import { encodeURIComponent } from './encode.js';

var foo = {
	str: 'test string',
	encodeURIComponent
};

export var encoded = foo.encodeURIComponent();


================================================
FILE: test/function/global-var/main.js
================================================
function foo () {
	var a = 1, global = {};
	global.modified = true;
	return global;
}

var notGlobal = foo();
assert.ok( notGlobal.modified );
assert.ok( !global.modified );

module.exports = {};


================================================
FILE: test/function/index/foo/index.js
================================================
module.exports = 42;


================================================
FILE: test/function/index/main.js
================================================
var foo = require( './foo' );

assert.equal( foo, 42 );


================================================
FILE: test/function/inline/_config.js
================================================
const assert = require('assert');

module.exports = {
	exports: exports => {
		assert.equal(exports(), 2);
	}
};


================================================
FILE: test/function/inline/foo.js
================================================
module.exports = 1;


================================================
FILE: test/function/inline/main.js
================================================
module.exports = function () {
	return require( './multiply' )( 2, require( './foo' ) );
};


================================================
FILE: test/function/inline/multiply.js
================================================
module.exports = function ( a, b ) {
	return a * b;
};


================================================
FILE: test/function/named-exports/foo.js
================================================
exports.a = 1;
module.exports.b = 2;


================================================
FILE: test/function/named-exports/main.js
================================================
import { a, b } from './foo.js';

assert.equal( a, 1 );
assert.equal( b, 2 );


================================================
FILE: test/function/ordering/bar.js
================================================
var shared = require('./shared');

module.exports = shared.fooLoaded


================================================
FILE: test/function/ordering/foo.js
================================================
var shared = require('./shared');

// Mutate the shared module
shared.fooLoaded = true;


================================================
FILE: test/function/ordering/main.js
================================================
require('./foo');

var fooLoaded = require('./bar');

assert.ok( fooLoaded );


================================================
FILE: test/function/ordering/shared.js
================================================
module.exports = {
	fooLoaded: false
};


================================================
FILE: test/function/react-apollo/commonjs-bar.js
================================================
function Bar () {
	this.x = 42;
}

exports.__esModule = true;
exports.default = Bar;


================================================
FILE: test/function/react-apollo/commonjs-foo.js
================================================
var Bar = require( './commonjs-bar' );

exports.__esModule = true;
exports.Bar = Bar.default;


================================================
FILE: test/function/react-apollo/main.js
================================================
import { Bar } from './commonjs-foo.js';

assert.equal( new Bar().x, 42 );


================================================
FILE: test/function/reassignment/foo.js
================================================
function foo () {}
foo.something = false;

module.exports = foo;


================================================
FILE: test/function/reassignment/main.js
================================================
var foo = require( './foo.js' );

if ( !foo.something ) {
	foo = function somethingElse () {}
	foo.something = true;
}

assert.ok( foo.something );


================================================
FILE: test/function/reexports/_config.js
================================================
const path = require('path');

module.exports = {
	pluginOptions: {
		namedExports: {
			[path.resolve(__dirname, 'foo.js')]: ['named']
		}
	}
};


================================================
FILE: test/function/reexports/bar.js
================================================
exports.named = 42;


================================================
FILE: test/function/reexports/foo.js
================================================
module.exports = require( './bar.js' );


================================================
FILE: test/function/reexports/main.js
================================================
import { named } from './foo.js';

assert.equal( named, 42 );


================================================
FILE: test/function/resolve-is-cjs-extension/_config.js
================================================
module.exports = {
	description: 'always resolve cjs detection even if an imported file has an unknown extension',
	options: {
		plugins: [
			{
				resolveId(importee) {
					if (importee === 'second') {
						return `${__dirname}/second.x`;
					}
				}
			}
		]
	},
	pluginOptions: {}
};


================================================
FILE: test/function/resolve-is-cjs-extension/main.js
================================================
assert.equal(require('second').result, 'second' );


================================================
FILE: test/function/resolve-is-cjs-extension/second.x
================================================
export const result = 'second';


================================================
FILE: test/function/resolve-is-cjs-filtered/_config.js
================================================
module.exports = {
	description: 'always resolve cjs detection even if an imported file is filtered',
	options: {
		plugins: [
			{
				resolveId(importee) {
					if (importee === 'second') {
						return `${__dirname}/second.js`;
					}
				}
			}
		]
	},
	pluginOptions: {
		include: ['function/resolve-is-cjs-filtered/main.js']
	}
};


================================================
FILE: test/function/resolve-is-cjs-filtered/main.js
================================================
assert.equal(require('second').result, 'second' );


================================================
FILE: test/function/resolve-is-cjs-filtered/second.js
================================================
export const result = 'second';


================================================
FILE: test/function/shadowing/main.js
================================================
function foo ( require ) {
	require( 'not-an-actual-require-statement' );
}

var result;

foo( function ( msg ) {
	result = msg;
});

assert.equal( result, 'not-an-actual-require-statement' );


================================================
FILE: test/function/skips-dead-branches/_config.js
================================================
const assert = require('assert');

module.exports = {
	global: global => {
		assert.equal(global.a, undefined);
		assert.equal(global.b, 2);
		assert.equal(global.c, undefined);
	}
};


================================================
FILE: test/function/skips-dead-branches/a.js
================================================
global.a = 1;


================================================
FILE: test/function/skips-dead-branches/b.js
================================================
global.b = 2;
module.exports = 'b';


================================================
FILE: test/function/skips-dead-branches/c.js
================================================
global.c = 3;
module.exports = 'c';


================================================
FILE: test/function/skips-dead-branches/main.js
================================================
if ( 'development' === 'production' ) {
	require( './a.js' );
}

module.exports = true ?
	require( './b.js' ) :
	require( './c.js' );


================================================
FILE: test/function/this/foo.js
================================================
module.exports = function augmentThis () {
	this.x = 'x';
};

this.y = 'y';


================================================
FILE: test/function/this/main.js
================================================
var foo = require( './foo' );

var obj = {};
foo.call( obj );

assert.equal( obj.x, 'x' );
assert.equal( this.y, 'y' );


================================================
FILE: test/function/toplevel-return/_config.js
================================================
const assert = require('assert');

module.exports = {
	exports: exports => {
		assert.equal(exports, 'foo');
	}
};


================================================
FILE: test/function/toplevel-return/foo.js
================================================
module.exports = 'foo';
return;


================================================
FILE: test/function/toplevel-return/main.js
================================================
var foo = require('./foo');

module.exports = 'foo';


================================================
FILE: test/function/toplevel-return-complex/_config.js
================================================
const assert = require('assert');

module.exports = {
	exports: exports => {
		assert.equal(exports, 'bar');
	}
};


================================================
FILE: test/function/toplevel-return-complex/bar.js
================================================
module.exports = function () {
  return true;
};


================================================
FILE: test/function/toplevel-return-complex/foo.js
================================================
var bar = require('./bar');
module.exports = 'bar';
if (bar()) {
  return;
}
module.exports = 'foo';


================================================
FILE: test/function/toplevel-return-complex/main.js
================================================
var foo = require('./foo');

module.exports = foo;


================================================
FILE: test/function/trailing-slash/foo/index.js
================================================
module.exports = 42;


================================================
FILE: test/function/trailing-slash/main.js
================================================
var foo = require( './foo/' );

assert.equal( foo, 42 );


================================================
FILE: test/function/typeof-require/foo.js
================================================
if ( typeof require === 'function' && require ) {
	module.exports = 1;
} else {
	module.exports = 2;
}


================================================
FILE: test/function/typeof-require/main.js
================================================
import foo from './foo.js';

assert.equal( foo, 1 );


================================================
FILE: test/mocha.opts
================================================
--require @babel/register


================================================
FILE: test/node_modules/.gitkeep
================================================


================================================
FILE: test/node_modules/bar/index.js
================================================
const baz = require('baz');
module.exports = function () {
	return baz;
};

================================================
FILE: test/node_modules/baz/index.js
================================================
module.exports = 'hello';

================================================
FILE: test/node_modules/events/index.js
================================================
exports.message = 'this is not builtin';

const myLib = exports;
myLib.foo = 'this is a hidden export';

================================================
FILE: test/node_modules/external/index.js
================================================
var externalLib = exports;
externalLib.message = 'it works';


================================================
FILE: test/node_modules/foo/index.js
================================================
module.exports = 'foo';

================================================
FILE: test/samples/array-destructuring-assignment/main.js
================================================

function shuffleArray(array) {
  for (let i = array.length - 1; i > 0; i--) {
    const j = Math.floor(Math.random() * (i + 1));
    [array[i], array[j]] = [array[j], array[i]];
  }
}

exports.shuffleArray = shuffleArray;


================================================
FILE: test/samples/corejs/literal-with-default.js
================================================
module.exports = { default: 'foobar', __esModule: true };


================================================
FILE: test/samples/custom-named-exports/main.js
================================================
import { named } from './secret-named-exporter.js';
import { message } from 'external';

assert.equal( named, 42 );
assert.equal( message, 'it works' );


================================================
FILE: test/samples/custom-named-exports/secret-named-exporter.js
================================================
var myLib = exports;
myLib.named = 42;


================================================
FILE: test/samples/custom-named-exports-browser-shims/main.js
================================================
import { message, foo } from 'events';

assert.equal( message, 'this is not builtin' );
assert.equal( foo, 'this is a hidden export' );


================================================
FILE: test/samples/custom-named-exports-false-positive/main.js
================================================
import { thing } from './other.js';
assert.equal( thing, 'yes' );


================================================
FILE: test/samples/custom-named-exports-false-positive/other.js
================================================
/* require (https://github.com/rollup/rollup-plugin-commonjs/issues/36) */
export var thing = 'yes';


================================================
FILE: test/samples/custom-named-exports-warn-builtins/main.js
================================================
import { message } from 'events';

assert.equal( message, 'this is not builtin' );


================================================
FILE: test/samples/deconflict-helpers/main.js
================================================
var commonjsHelpers = { commonjsGlobal: 'nope' };
module.exports = global;


================================================
FILE: test/samples/define-is-undefined/foo.js
================================================
(function (global, factory) {
	typeof define === 'function' && define.amd ? define(factory) :
	typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
	(global.foo = factory());
}(this, (function () { 'use strict';

	return 42;

})));


================================================
FILE: test/samples/define-is-undefined/main.js
================================================
import foo from './foo.js';

export default 42;


================================================
FILE: test/samples/es-modules-without-default-export/main.js
================================================
const { a } = require('./other.js');

assert.equal( a, 1 );


================================================
FILE: test/samples/es-modules-without-default-export/other.js
================================================
export const a = 1;


================================================
FILE: test/samples/extension/foo.coffee
================================================
module.exports = 21;


================================================
FILE: test/samples/extension/main.coffee
================================================
var foo = require( './foo' );
module.exports = foo * 2;


================================================
FILE: test/samples/external/main.js
================================================
import bar from 'bar';

export default bar().toUpperCase();

================================================
FILE: test/samples/global/main.js
================================================
global.foo = 'bar';


================================================
FILE: test/samples/global-in-if-block/main.js
================================================
if (!global.count) {
	global.count = 0;
}

global.count += 1;


================================================
FILE: test/samples/ignore-global/firstpass.js
================================================
export var immediate = typeof global.setImmediate === 'function' ?
   global.setImmediate : global.setTimeout;


================================================
FILE: test/samples/ignore-global/identifier.js
================================================
// require (firstpass)

export var immediate = typeof global.setImmediate === 'function' ?
   global.setImmediate : global.setTimeout;


================================================
FILE: test/samples/ignore-global/main.js
================================================
export { immediate as immediate1 } from './firstpass';
export { immediate as immediate2 } from './identifier';
export { immediate as immediate3 } from './this';


================================================
FILE: test/samples/ignore-global/this.js
================================================
// require (firstpass)

// "this" will be rewritten with "undefined" by rollup
export var immediate = typeof this === 'undefined' ? 
   null : typeof this.setImmediate === 'function' ?
   this.setImmediate : this.setTimeout;


================================================
FILE: test/samples/ignore-virtual-modules/main.js
================================================
module.exports = require('\0virtual');


================================================
FILE: test/samples/invalid-syntax/main.js
================================================
export const foo = 2,

================================================
FILE: test/samples/multiple-entry-points/2.js
================================================
function second () {
	console.log('second');
}
exports.second = second;

================================================
FILE: test/samples/multiple-entry-points/3.js
================================================
function third () {
	console.log('third');
}

exports.third = third;


================================================
FILE: test/samples/multiple-entry-points/4.js
================================================
export function fourth () {
	console.log('fourth');
}


================================================
FILE: test/samples/multiple-entry-points/b.js
================================================
import { second } from './2';
import { third } from './3';

second();
third();


================================================
FILE: test/samples/multiple-entry-points/c.js
================================================
import { second } from './2';
import { third } from './3';
import { fourth } from './4';

second();
third();
fourth();


================================================
FILE: test/samples/named-exports-from-object-literal/a.js
================================================
module.exports = 1;


================================================
FILE: test/samples/named-exports-from-object-literal/main.js
================================================
import { a, b, c } from './other.js';

assert.equal( a, 1 );
assert.equal( b, 2 );
assert.equal( c, 3 );


================================================
FILE: test/samples/named-exports-from-object-literal/other.js
================================================
var a = require( './a.js' );
var b = 2;

module.exports = {
  a: a,
  b: b,
  c: a + b,
  2: 1 + 1
};


================================================
FILE: test/samples/other-transforms/bar.js
================================================
module.exports = 40;


================================================
FILE: test/samples/other-transforms/foo.js
================================================
var bar = require( './bar.js' );

module.exports = bar + 1;


================================================
FILE: test/samples/other-transforms/main.js
================================================
import foo from './foo.js';

assert.equal( foo, 42 );


================================================
FILE: test/samples/paren-expression/index.js
================================================
module.exports = (42);


================================================
FILE: test/samples/reexport/export.js
================================================
exports.named = 2;


================================================
FILE: test/samples/reexport/main.js
================================================
import { named } from './reexport.js';

assert.equal(named, 2);


================================================
FILE: test/samples/reexport/reexport.js
================================================
module.exports = require('./export.js');


================================================
FILE: test/samples/rename-index/invalid-var/index.js
================================================
module.exports = 'invalid';


================================================
FILE: test/samples/rename-index/main.js
================================================
import invalid from './invalid-var';
import valid from './validVar';
import other from './other/nonIndex';

console.log(invalid, valid, other);


================================================
FILE: test/samples/rename-index/other/nonIndex.js
================================================
module.exports = 'not an index file';


================================================
FILE: test/samples/rename-index/validVar/index.js
================================================
module.exports = 'valid';


================================================
FILE: test/samples/reserved-as-property/main.js
================================================
module.exports.delete = 'foo';


================================================
FILE: test/samples/sourcemap/foo.js
================================================
export default 42;


================================================
FILE: test/samples/sourcemap/main.js
================================================
var foo = require( './foo' );
console.log( foo );


================================================
FILE: test/samples/symlinked-node-modules/index.js
================================================
import { foo } from 'events';

================================================
FILE: test/samples/umd/correct-scoping.js
================================================
if ( typeof require === 'function' ) {
	module.exports = function ( require ) {
		return typeof require;
	}( {} );
}


================================================
FILE: test/samples/umd/protobuf.js
================================================
// From https://github.com/rollup/rollup-plugin-commonjs/issues/38
(function(global, factory) {
    /* AMD */ if (typeof define === 'function' && define["amd"])
        define(["foo"], factory);
    /* CommonJS */ else if (typeof require === "function" && typeof module === "object" && module && module["exports"])
        module["exports"] = factory(require("foo"), true);
    /* Global */ else
        (global["dcodeIO"] = global["dcodeIO"] || {})["ProtoBuf"] = factory(global["dcodeIO"]["ByteBuffer"]);
})(this, function(ByteBuffer, isCommonJS) {
  return isCommonJS;
})


================================================
FILE: test/samples/umd/sinon.js
================================================
// From https://github.com/rollup/rollup-plugin-commonjs/issues/38
var sinon = (function () { // eslint-disable-line no-unused-vars
    "use strict";

    var sinonModule;
    var isNode = typeof module !== "undefined" && module.exports && typeof require === "function";
    var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;

    function loadDependencies(require, exports, module) {
        sinonModule = module.exports = require("./sinon/util/core");
        require("./sinon/extend");
        require("./sinon/walk");
        require("./sinon/typeOf");
        require("./sinon/times_in_words");
        require("./sinon/spy");
        require("./sinon/call");
        require("./sinon/behavior");
        require("./sinon/stub");
        require("./sinon/mock");
        require("./sinon/collection");
        require("./sinon/assert");
        require("./sinon/sandbox");
        require("./sinon/test");
        require("./sinon/test_case");
        require("./sinon/match");
        require("./sinon/format");
        require("./sinon/log_error");
    }

    if (isAMD) {
        define(loadDependencies);
    } else if (isNode) {
        loadDependencies(require, module.exports, module);
        sinonModule = module.exports;
    } else {
        sinonModule = {};
    }

    return sinonModule;
}());


================================================
FILE: test/samples/use-own-output/from-rollup.js
================================================
Object.defineProperty(exports, '__esModule', { value: true });
exports.x = 10


================================================
FILE: test/samples/use-own-output/main.js
================================================
import * as b from "./from-rollup";
window.b = b;


================================================
FILE: test/test.js
================================================
/* eslint-env mocha */
/* eslint-disable no-console */

const acorn = require('acorn');
const path = require('path');
const fs = require('fs');
const assert = require('assert');
const relative = require('require-relative');
const { SourceMapConsumer } = require('source-map');
const { getLocator } = require('locate-character');
const { rollup } = require('rollup');
const resolve = require('rollup-plugin-node-resolve');

function commonjs(options) {
	delete require.cache[require.resolve('..')];
	return require('..')(options);
}

require('source-map-support').install();

process.chdir(__dirname);

function execute(code, context = {}) {
	let fn;
	const contextKeys = Object.keys(context);
	const argNames = contextKeys.concat(
		'module',
		'exports',
		'require',
		'global',
		'assert',
		'globalThis',
		code
	);

	try {
		fn = new Function(...argNames);
	} catch (err) {
		// syntax error
		console.log(code);
		throw err;
	}

	const module = { exports: {} };
	const global = {};

	const argValues = contextKeys
		.map(key => context[key])
		.concat(module, module.exports, name => relative(name, 'test/x.js'), global, assert, global);

	fn(...argValues);

	return {
		code,
		exports: module.exports,
		global
	};
}

const getOutputFromGenerated = generated => (generated.output ? generated.output[0] : generated);

async function getCodeFromBundle(bundle, customOptions = {}) {
	const options = Object.assign({ format: 'cjs' }, customOptions);
	return getOutputFromGenerated(await bundle.generate(options)).code;
}

async function executeBundle(bundle, { context, exports } = {}) {
	const code = await getCodeFromBundle(bundle, exports ? { exports } : {});
	return execute(code, context);
}

describe('rollup-plugin-commonjs', () => {
	describe('form', () => {
		const transformContext = {
			parse: (input, options) =>
				acorn.parse(
					input,
					Object.assign(
						{
							ecmaVersion: 9,
							sourceType: 'module'
						},
						options
					)
				)
		};

		fs.readdirSync('form').forEach(dir => {
			let config;

			try {
				config = require(`./form/${dir}/_config.js`);
			} catch (err) {
				config = {};
			}

			(config.solo ? it.only : it)(dir, () => {
				const { transform } = commonjs(config.options);
				const id = `./form/${dir}/input.js`;

				transformContext.getModuleInfo = moduleId => ({
					isEntry: config.entry && moduleId === id
				});

				const input = fs.readFileSync(id, 'utf-8');

				let outputFile = `form/${dir}/output`;
				if (fs.existsSync(`${outputFile}.${process.platform}.js`)) {
					outputFile += `.${process.platform}.js`;
				} else {
					outputFile += '.js';
				}

				const expected = fs.readFileSync(outputFile, 'utf-8').trim();

				const transformed = transform.call(transformContext, input, id);
				const actual = (transformed ? transformed.code : input).trim().replace(/\0/g, '_');
				assert.equal(actual, expected);
			});
		});
	});

	describe('function', () => {
		fs.readdirSync('function').forEach(dir => {
			let config;

			try {
				config = require(`./function/${dir}/_config.js`);
			} catch (err) {
				config = {};
			}

			(config.solo ? it.only : it)(dir, async () => {
				const options = Object.assign(
					{
						input: `function/${dir}/main.js`
					},
					config.options || {},
					{
						plugins: [
							...((config.options && config.options.plugins) || []),
							commonjs(config.pluginOptions)
						]
					}
				);

				const bundle = await rollup(options);
				const code = await getCodeFromBundle(bundle);
				if (config.show || config.solo) {
					console.error(code);
				}

				const { exports, global } = execute(code, config.context);

				if (config.exports) config.exports(exports);
				if (config.global) config.global(global);
			});
		});
	});

	describe('misc tests', () => {
		// most of these should be moved over to function...
		it('generates a sourcemap', async () => {
			const bundle = await rollup({
				input: 'samples/sourcemap/main.js',
				plugins: [commonjs({ sourceMap: true })]
			});

			const { code, map } = getOutputFromGenerated(
				await bundle.generate({
					format: 'cjs',
					sourcemap: true,
					sourcemapFile: path.resolve('bundle.js')
				})
			);

			const smc = new SourceMapConsumer(map);
			const locator = getLocator(code, { offsetLine: 1 });

			let generatedLoc = locator('42');
			let loc = smc.originalPositionFor(generatedLoc); // 42
			assert.equal(loc.source, 'samples/sourcemap/foo.js');
			assert.equal(loc.line, 1);
			assert.equal(loc.column, 15);

			generatedLoc = locator('log');
			loc = smc.originalPositionFor(generatedLoc); // log
			assert.equal(loc.source, 'samples/sourcemap/main.js');
			assert.equal(loc.line, 2);
			assert.equal(loc.column, 8);
		});

		it('supports an array of multiple entry points', async () => {
			const bundle = await rollup({
				input: ['samples/multiple-entry-points/b.js', 'samples/multiple-entry-points/c.js'],
				plugins: [commonjs()]
			});

			const { output } = await bundle.generate({
				format: 'cjs',
				chunkFileNames: '[name].js'
			});
			if (Array.isArray(output)) {
				assert.equal(output.length, 3);
				assert.ok(output.find(({ fileName }) => fileName === 'b.js'));
				assert.ok(output.find(({ fileName }) => fileName === 'c.js'));
			} else {
				assert.equal(Object.keys(output).length, 3);
				assert.equal('b.js' in output, true);
				assert.equal('c.js' in output, true);
			}
		});

		it('supports an object of multiple entry points', async () => {
			const bundle = await rollup({
				input: {
					b: require.resolve('./samples/multiple-entry-points/b.js'),
					c: require.resolve('./samples/multiple-entry-points/c.js')
				},
				plugins: [resolve(), commonjs()]
			});

			const { output } = await bundle.generate({
				format: 'cjs',
				chunkFileNames: '[name].js'
			});

			if (Array.isArray(output)) {
				assert.equal(output.length, 3);
				assert.ok(output.find(({ fileName }) => fileName === 'b.js'));
				assert.ok(output.find(({ fileName }) => fileName === 'c.js'));
			} else {
				assert.equal(Object.keys(output).length, 3);
				assert.equal('b.js' in output, true);
				assert.equal('c.js' in output, true);
			}
		});

		it('handles references to `global`', async () => {
			const bundle = await rollup({
				input: 'samples/global/main.js',
				plugins: [commonjs()]
			});

			const code = await getCodeFromBundle(bundle);

			const mockWindow = {};
			const mockGlobal = {};
			const mockSelf = {};

			const fn = new Function('module', 'globalThis', 'window', 'global', 'self', code);

			fn({}, undefined, mockWindow, mockGlobal, mockSelf);
			assert.equal(mockWindow.foo, 'bar', code);
			assert.equal(mockGlobal.foo, undefined, code);
			assert.equal(mockSelf.foo, undefined, code);

			fn({}, undefined, undefined, mockGlobal, mockSelf);
			assert.equal(mockGlobal.foo, 'bar', code);
			assert.equal(mockSelf.foo, undefined, code);

			fn({}, undefined, undefined, undefined, mockSelf);
			assert.equal(mockSelf.foo, 'bar', code);
		});

		it('handles multiple references to `global`', async () => {
			const bundle = await rollup({
				input: 'samples/global-in-if-block/main.js',
				plugins: [commonjs()]
			});

			const code = await getCodeFromBundle(bundle);
			const fn = new Function('module', 'exports', 'globalThis', code);
			const module = { exports: {} };
			const globalThis = {};

			fn(module, module.exports, globalThis);
			assert.equal(globalThis.count, 1);

			fn(module, module.exports, globalThis);
			assert.equal(globalThis.count, 2);
		});

		it('handles transpiled CommonJS modules', async () => {
			const bundle = await rollup({
				input: 'samples/corejs/literal-with-default.js',
				plugins: [commonjs()]
			});

			const code = await getCodeFromBundle(bundle);
			const module = { exports: {} };

			const fn = new Function('module', 'exports', code);
			fn(module, module.exports);

			assert.equal(module.exports, 'foobar', code);
		});

		it('handles successive builds', async () => {
			const plugin = commonjs();
			let bundle = await rollup({
				input: 'samples/corejs/literal-with-default.js',
				plugins: [plugin]
			});
			await bundle.generate({
				format: 'cjs'
			});

			bundle = await rollup({
				input: 'samples/corejs/literal-with-default.js',
				plugins: [plugin]
			});
			const code = await getCodeFromBundle(bundle);

			const module = { exports: {} };

			const fn = new Function('module', 'exports', code);
			fn(module, module.exports);

			assert.equal(module.exports, 'foobar', code);
		});

		it('allows named exports to be added explicitly via config', async () => {
			const bundle = await rollup({
				input: 'samples/custom-named-exports/main.js',
				plugins: [
					resolve(),
					commonjs({
						namedExports: {
							'samples/custom-named-exports/secret-named-exporter.js': ['named'],
							external: ['message']
						}
					})
				]
			});

			await executeBundle(bundle);
		});

		it('handles warnings without error when resolving named exports', () => {
			return rollup({
				input: 'samples/custom-named-exports-warn-builtins/main.js',
				plugins: [
					resolve(),
					commonjs({
						namedExports: {
							events: ['message']
						}
					})
				]
			});
		});

		it('handles symlinked node_modules with preserveSymlinks: false', () => {
			const cwd = process.cwd();

			// ensure we resolve starting from a directory with
			// symlinks in node_modules.

			process.chdir('samples/symlinked-node-modules');

			return rollup({
				input: './index.js',
				onwarn(warning) {
					// should not get a warning about unknown export 'foo'
					throw new Error(`Unexpected warning: ${warning.message}`);
				},
				plugins: [
					resolve({
						preserveSymlinks: false,
						preferBuiltins: false
					}),
					commonjs({
						namedExports: {
							events: ['foo']
						}
					})
				]
			})
				.then(v => {
					process.chdir(cwd);
					return v;
				})
				.catch(err => {
					process.chdir(cwd);
					throw err;
				});
		});

		it('handles named exports for built-in shims', async () => {
			const bundle = await rollup({
				input: 'samples/custom-named-exports-browser-shims/main.js',
				plugins: [
					resolve({
						preferBuiltins: false
					}),
					commonjs({
						namedExports: {
							events: ['foo']
						}
					})
				]
			});

			await executeBundle(bundle);
		});

		it('ignores false positives with namedExports (#36)', async () => {
			const bundle = await rollup({
				input: 'samples/custom-named-exports-false-positive/main.js',
				plugins: [
					resolve(),
					commonjs({
						namedExports: {
							irrelevant: ['lol']
						}
					})
				]
			});

			await executeBundle(bundle);
		});

		it('converts a CommonJS module with custom file extension', async () => {
			const bundle = await rollup({
				input: 'samples/extension/main.coffee',
				plugins: [commonjs({ extensions: ['.coffee'] })]
			});

			assert.equal((await executeBundle(bundle)).exports, 42);
		});

		it('identifies named exports from object literals', async () => {
			const bundle = await rollup({
				input: 'samples/named-exports-from-object-literal/main.js',
				plugins: [commonjs()]
			});

			const { code } = await bundle.generate({
				format: 'cjs'
			});

			const fn = new Function('module', 'assert', code);
			fn({}, assert);
		});

		it('can ignore references to `global`', async () => {
			const bundle = await rollup({
				input: 'samples/ignore-global/main.js',
				plugins: [commonjs({ ignoreGlobal: true })],
				onwarn: warning => {
					if (warning.code === 'THIS_IS_UNDEFINED') return;
					console.warn(warning.message);
				}
			});

			const code = await getCodeFromBundle(bundle);
			const { exports, global } = await executeBundle(bundle);

			assert.equal(exports.immediate1, global.setImmediate, code);
			assert.equal(exports.immediate2, global.setImmediate, code);
			assert.equal(exports.immediate3, null, code);
		});

		it('can handle parens around right have node while producing default export', async () => {
			const bundle = await rollup({
				input: 'samples/paren-expression/index.js',
				plugins: [commonjs()]
			});

			assert.equal((await executeBundle(bundle)).exports, 42);
		});

		describe('typeof transforms', () => {
			it('correct-scoping', async () => {
				const bundle = await rollup({
					input: 'samples/umd/correct-scoping.js',
					plugins: [commonjs()]
				});

				assert.equal((await executeBundle(bundle)).exports, 'object');
			});

			it('protobuf', async () => {
				const bundle = await rollup({
					input: 'samples/umd/protobuf.js',
					external: ['bytebuffer'],
					plugins: [commonjs()]
				});

				assert.equal((await executeBundle(bundle)).exports, true);
			});

			it('sinon', async () => {
				const bundle = await rollup({
					input: 'samples/umd/sinon.js',
					plugins: [commonjs()]
				});

				const { code } = getOutputFromGenerated(await bundle.generate({ format: 'es' }));

				assert.equal(code.indexOf('typeof require'), -1, code);
				// assert.notEqual( code.indexOf( 'typeof module' ), -1, code ); // #151 breaks this test
				// assert.notEqual( code.indexOf( 'typeof define' ), -1, code ); // #144 breaks this test
			});
		});

		it('deconflicts helper name', async () => {
			const bundle = await rollup({
				input: 'samples/deconflict-helpers/main.js',
				plugins: [commonjs()]
			});

			const { exports } = await executeBundle(bundle);
			assert.notEqual(exports, 'nope');
		});

		it('deconflicts reserved keywords', async () => {
			const bundle = await rollup({
				input: 'samples/reserved-as-property/main.js',
				plugins: [commonjs()]
			});

			const reservedProp = (await executeBundle(bundle, { exports: 'named' })).exports.delete;
			assert.equal(reservedProp, 'foo');
		});

		it('does not process the entry file when it has a leading "." (issue #63)', async () => {
			const bundle = await rollup({
				input: './function/basic/main.js',
				plugins: [commonjs()]
			});

			await executeBundle(bundle);
		});

		it('does not reexport named contents', async () => {
			try {
				await rollup({
					input: 'samples/reexport/main.js',
					plugins: [commonjs()]
				});
			} catch (error) {
				assert.equal(
					error.message,
					`'named' is not exported by samples${path.sep}reexport${path.sep}reexport.js`
				);
			}
		});

		it('respects other plugins', async () => {
			const bundle = await rollup({
				input: 'samples/other-transforms/main.js',
				plugins: [
					{
						transform(code, id) {
							if (id[0] === '\0') return null;
							return code.replace('40', '41');
						}
					},
					commonjs()
				]
			});

			await executeBundle(bundle);
		});

		it('rewrites top-level defines', async () => {
			const bundle = await rollup({
				input: 'samples/define-is-undefined/main.js',
				plugins: [commonjs()]
			});

			function define() {
				throw new Error('nope');
			}

			define.amd = true;

			const { exports } = await executeBundle(bundle, { context: { define } });
			assert.equal(exports, 42);
		});

		it('respects options.external', async () => {
			const bundle = await rollup({
				input: 'samples/external/main.js',
				plugins: [resolve(), commonjs()],
				external: ['baz']
			});

			const code = await getCodeFromBundle(bundle);
			assert.equal(code.indexOf('hello'), -1);

			const { exports } = await executeBundle(bundle);
			assert.equal(exports, 'HELLO');
		});

		it('prefers to set name using directory for index files', async () => {
			const bundle = await rollup({
				input: 'samples/rename-index/main.js',
				plugins: [commonjs()]
			});

			const code = await getCodeFromBundle(bundle);
			assert.equal(code.indexOf('var index'), -1);
			assert.notEqual(code.indexOf('var invalidVar'), -1);
			assert.notEqual(code.indexOf('var validVar'), -1);
			assert.notEqual(code.indexOf('var nonIndex'), -1);
		});

		it('does not misassign default when consuming rollup output', async () => {
			// Issue #224
			const bundle = await rollup({
				input: 'samples/use-own-output/main.js',
				plugins: [commonjs()]
			});

			const window = {};
			await executeBundle(bundle, { context: { window } });
			assert.notEqual(window.b.default, undefined);
		});

		it('does not warn even if the ES module not export "default"', async () => {
			const warns = [];
			await rollup({
				input: 'samples/es-modules-without-default-export/main.js',
				plugins: [commonjs()],
				onwarn: warn => warns.push(warn)
			});
			assert.equal(warns.length, 0);

			await rollup({
				input: 'function/bare-import/bar.js',
				plugins: [commonjs()],
				onwarn: warn => warns.push(warn)
			});
			assert.equal(warns.length, 0);

			await rollup({
				input: 'function/bare-import-comment/main.js',
				plugins: [commonjs()],
				onwarn: warn => warns.push(warn)
			});
			assert.equal(warns.length, 0);
		});

		it('compiles with cache', async () => {
			// specific commonjs require() to ensure same instance is used
			const commonjs = require('..');

			const bundle = await rollup({
				input: 'function/index/main.js',
				plugins: [commonjs()]
			});

			await rollup({
				input: 'function/index/main.js',
				plugins: [commonjs()],
				cache: bundle
			});
		});

		it('creates an error with a code frame when parsing fails', async () => {
			try {
				await rollup({
					input: 'samples/invalid-syntax/main.js',
					plugins: [commonjs()]
				});
			} catch (error) {
				assert.equal(error.frame, '1: export const foo = 2,\n                        ^');
			}
		});

		it('ignores virtual modules', async () => {
			const bundle = await rollup({
				input: 'samples/ignore-virtual-modules/main.js',
				plugins: [
					commonjs(),
					{
						resolveId(id) {
							if (id === '\0virtual' || id === '\0resolved-virtual') {
								return '\0resolved-virtual';
							}
						},
						load(id) {
							if (id === '\0resolved-virtual') {
								return 'export default "Virtual export"';
							}
						}
					}
				]
			});
			assert.equal((await executeBundle(bundle)).exports, 'Virtual export');
		});

		it('does not produce warnings when importing .mjs without default export', async () => {
			const bundle = await rollup({
				input: 'main.mjs',
				onwarn(warning) {
					// The interop should not trigger a "default is not exported" warning
					throw new Error(`Unexpected warning: ${warning.message}`);
				},
				plugins: [
					commonjs(),
					{
						load(id) {
							if (id === 'main.mjs') {
								return 'import cjs from "cjs.js"; export default cjs;';
							}
							if (id === 'cjs.js') {
								// CJS libraries expect to receive a CJS file here
								return 'module.exports = require("fromNodeModules");';
							}
							if (id === 'fromNodeModules.mjs') {
								return 'export const result = "from esm";';
							}
						},
						resolveId(id) {
							// rollup-plugin-node-resolve usually prefers ESM versions
							if (id === 'fromNodeModules') {
								return 'fromNodeModules.mjs';
							}
							return id;
						}
					}
				]
			});
			assert.deepEqual((await executeBundle(bundle)).exports, { result: 'from esm' });
		});

		it('produces optimized code when importing esm with a known default export', async () => {
			const bundle = await rollup({
				input: 'main.js',
				plugins: [
					commonjs(),
					{
						load(id) {
							if (id === 'main.js') {
								return 'module.exports = require("esm.js")';
							}
							if (id === 'esm.js') {
								return 'export const ignored = "ignored"; export default "default"';
							}
						},
						resolveId(id) {
							return id;
						}
					}
				]
			});
			const code = await getCodeFromBundle(bundle);
			assert.equal(
				code,
				`'use strict';

var require$$0 = "default";

var main = require$$0;

module.exports = main;
`
			);
		});

		it('produces optimized code when importing esm without a default export', async () => {
			const bundle = await rollup({
				input: 'main.js',
				plugins: [
					commonjs(),
					{
						load(id) {
							if (id === 'main.js') {
								return 'module.exports = require("esm.js")';
							}
							if (id === 'esm.js') {
								return 'export const value = "value";';
							}
						},
						resolveId(id) {
							return id;
						}
					}
				]
			});
			const code = await getCodeFromBundle(bundle);
			assert.equal(
				code,
				`'use strict';

const value = "value";

var esm = /*#__PURE__*/Object.freeze({
	value: value
});

var main = esm;

module.exports = main;
`
			);
		});

		it('handles array destructuring assignment', async () => {
			const bundle = await rollup({
				input: 'samples/array-destructuring-assignment/main.js',
				plugins: [commonjs({ sourceMap: true })]
			});

			const code = await getCodeFromBundle(bundle);
			assert.equal(
				code,
				`'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

function shuffleArray(array) {
  for (let i = array.length - 1; i > 0; i--) {
    const j = Math.floor(Math.random() * (i + 1));
    [array[i], array[j]] = [array[j], array[i]];
  }
}

var shuffleArray_1 = shuffleArray;

var main = {
	shuffleArray: shuffleArray_1
};

exports.default = main;
exports.shuffleArray = shuffleArray_1;
`
			);
		});

		it('normalizes paths used in the named export map', async () => {
			// Deliberately denormalizes file paths and ensures named exports
			// continue to work.
			function hookedResolve() {
				const resolvePlugin = resolve();
				const oldResolve = resolvePlugin.resolveId;
				resolvePlugin.resolveId = async function() {
					const result = await oldResolve.apply(resolvePlugin, arguments);
					if (result) {
						result.id = result.id.replace(/\/|\\/, path.sep);
					}

					return result;
				};

				return resolvePlugin;
			}

			const bundle = await rollup({
				input: 'samples/custom-named-exports/main.js',
				plugins: [
					hookedResolve(),
					commonjs({
						namedExports: {
							'samples/custom-named-exports/secret-named-exporter.js': ['named'],
							external: ['message']
						}
					})
				]
			});

			await executeBundle(bundle);
		});
	});
});


================================================
FILE: tsconfig.json
================================================
{
    "compilerOptions": {
        "lib": [
            "es6"
        ],
        "noImplicitAny": true,
        "noImplicitThis": true,
        "strict": true,
        "noEmit": true,
        "allowJs": true
    },
    "files": [
        "index.d.ts",
        "typings-test.js"
    ]
}


================================================
FILE: typings-test.js
================================================
// @ts-check
import commonjs from '.';

/** @type {import("rollup").RollupOptions} */
const config = {
	input: 'main.js',
	output: {
		file: 'bundle.js',
		format: 'iife'
	},
	plugins: [
		commonjs({
			include: 'node_modules/**',
			exclude: [ 'node_modules/foo/**', 'node_modules/bar/**', /node_modules/ ],
			extensions: [ '.js', '.coffee' ],
			ignoreGlobal: false,
			sourceMap: false,
			namedExports: { './module.js': ['foo', 'bar' ] },
			ignore: [ 'conditional-runtime-dependency' ]
		})
	]
};

export default config;
Download .txt
gitextract_emltkzmn/

├── .babelrc.js
├── .eslintrc.json
├── .gitignore
├── .huskyrc
├── .lintstagedrc
├── .prettierrc
├── .travis.yml
├── CHANGELOG.md
├── LICENSE
├── README.md
├── appveyor.yml
├── index.d.ts
├── package.json
├── rollup.config.js
├── src/
│   ├── ast-utils.js
│   ├── helpers.js
│   ├── index.js
│   ├── is-cjs.js
│   ├── resolve-id.js
│   ├── transform.js
│   └── utils.js
├── test/
│   ├── form/
│   │   ├── async-function/
│   │   │   ├── input.js
│   │   │   └── output.js
│   │   ├── constant-template-literal/
│   │   │   ├── input.js
│   │   │   └── output.js
│   │   ├── dynamic-template-literal/
│   │   │   ├── input.js
│   │   │   └── output.js
│   │   ├── ignore-ids/
│   │   │   ├── _config.js
│   │   │   ├── input.js
│   │   │   └── output.js
│   │   ├── ignore-ids-function/
│   │   │   ├── _config.js
│   │   │   ├── input.js
│   │   │   └── output.js
│   │   ├── multiple-var-declarations/
│   │   │   ├── input.js
│   │   │   └── output.js
│   │   ├── multiple-var-declarations-b/
│   │   │   ├── input.js
│   │   │   └── output.js
│   │   ├── multiple-var-declarations-c/
│   │   │   ├── input.js
│   │   │   └── output.js
│   │   ├── no-exports-entry/
│   │   │   ├── _config.js
│   │   │   ├── input.js
│   │   │   └── output.js
│   │   ├── no-toplevel-return/
│   │   │   ├── input.js
│   │   │   └── output.js
│   │   ├── optimised-default-export/
│   │   │   ├── input.js
│   │   │   └── output.js
│   │   ├── optimised-default-export-function/
│   │   │   ├── input.js
│   │   │   └── output.js
│   │   ├── optimised-default-export-function-double-assign/
│   │   │   ├── input.js
│   │   │   └── output.js
│   │   ├── optimised-default-export-iife/
│   │   │   ├── input.js
│   │   │   └── output.js
│   │   ├── optimised-named-export/
│   │   │   ├── input.js
│   │   │   └── output.js
│   │   ├── optimised-named-export-conflicts/
│   │   │   ├── input.js
│   │   │   └── output.js
│   │   ├── require-collision/
│   │   │   ├── input.js
│   │   │   └── output.js
│   │   ├── typeof-module-exports/
│   │   │   ├── input.js
│   │   │   └── output.js
│   │   ├── unambiguous-with-default-export/
│   │   │   ├── input.js
│   │   │   └── output.js
│   │   ├── unambiguous-with-import/
│   │   │   ├── input.js
│   │   │   └── output.js
│   │   └── unambiguous-with-named-export/
│   │       ├── input.js
│   │       └── output.js
│   ├── function/
│   │   ├── __esModule/
│   │   │   ├── answer.js
│   │   │   └── main.js
│   │   ├── assign-properties-to-default-export/
│   │   │   ├── foo.js
│   │   │   └── main.js
│   │   ├── assumed-globals/
│   │   │   ├── _config.js
│   │   │   ├── document.js
│   │   │   └── main.js
│   │   ├── bare-import/
│   │   │   ├── _config.js
│   │   │   ├── bar.js
│   │   │   ├── foo.js
│   │   │   └── main.js
│   │   ├── bare-import-comment/
│   │   │   ├── bar.js
│   │   │   ├── foo.js
│   │   │   └── main.js
│   │   ├── basic/
│   │   │   ├── _config.js
│   │   │   ├── foo.js
│   │   │   └── main.js
│   │   ├── deconflict-export-and-local/
│   │   │   ├── index.js
│   │   │   ├── main.js
│   │   │   └── someValue.js
│   │   ├── dot/
│   │   │   ├── foo.bar.js
│   │   │   └── main.js
│   │   ├── duplicate-default-exports/
│   │   │   ├── main.js
│   │   │   └── x.js
│   │   ├── duplicate-default-exports-b/
│   │   │   ├── main.js
│   │   │   └── x.js
│   │   ├── duplicate-default-exports-c/
│   │   │   ├── exports.js
│   │   │   └── main.js
│   │   ├── export-default-from/
│   │   │   ├── _config.js
│   │   │   ├── imported.js
│   │   │   ├── main.js
│   │   │   └── reexporter.js
│   │   ├── exports/
│   │   │   ├── _config.js
│   │   │   ├── foo.js
│   │   │   └── main.js
│   │   ├── external-imports/
│   │   │   ├── _config.js
│   │   │   └── main.js
│   │   ├── fallback-no-default/
│   │   │   ├── foo.js
│   │   │   └── main.js
│   │   ├── global-not-overwritten/
│   │   │   ├── _config.js
│   │   │   ├── encode.js
│   │   │   └── main.js
│   │   ├── global-var/
│   │   │   └── main.js
│   │   ├── index/
│   │   │   ├── foo/
│   │   │   │   └── index.js
│   │   │   └── main.js
│   │   ├── inline/
│   │   │   ├── _config.js
│   │   │   ├── foo.js
│   │   │   ├── main.js
│   │   │   └── multiply.js
│   │   ├── named-exports/
│   │   │   ├── foo.js
│   │   │   └── main.js
│   │   ├── ordering/
│   │   │   ├── bar.js
│   │   │   ├── foo.js
│   │   │   ├── main.js
│   │   │   └── shared.js
│   │   ├── react-apollo/
│   │   │   ├── commonjs-bar.js
│   │   │   ├── commonjs-foo.js
│   │   │   └── main.js
│   │   ├── reassignment/
│   │   │   ├── foo.js
│   │   │   └── main.js
│   │   ├── reexports/
│   │   │   ├── _config.js
│   │   │   ├── bar.js
│   │   │   ├── foo.js
│   │   │   └── main.js
│   │   ├── resolve-is-cjs-extension/
│   │   │   ├── _config.js
│   │   │   ├── main.js
│   │   │   └── second.x
│   │   ├── resolve-is-cjs-filtered/
│   │   │   ├── _config.js
│   │   │   ├── main.js
│   │   │   └── second.js
│   │   ├── shadowing/
│   │   │   └── main.js
│   │   ├── skips-dead-branches/
│   │   │   ├── _config.js
│   │   │   ├── a.js
│   │   │   ├── b.js
│   │   │   ├── c.js
│   │   │   └── main.js
│   │   ├── this/
│   │   │   ├── foo.js
│   │   │   └── main.js
│   │   ├── toplevel-return/
│   │   │   ├── _config.js
│   │   │   ├── foo.js
│   │   │   └── main.js
│   │   ├── toplevel-return-complex/
│   │   │   ├── _config.js
│   │   │   ├── bar.js
│   │   │   ├── foo.js
│   │   │   └── main.js
│   │   ├── trailing-slash/
│   │   │   ├── foo/
│   │   │   │   └── index.js
│   │   │   └── main.js
│   │   └── typeof-require/
│   │       ├── foo.js
│   │       └── main.js
│   ├── mocha.opts
│   ├── node_modules/
│   │   ├── .gitkeep
│   │   ├── bar/
│   │   │   └── index.js
│   │   ├── baz/
│   │   │   └── index.js
│   │   ├── events/
│   │   │   └── index.js
│   │   ├── external/
│   │   │   └── index.js
│   │   └── foo/
│   │       └── index.js
│   ├── samples/
│   │   ├── array-destructuring-assignment/
│   │   │   └── main.js
│   │   ├── corejs/
│   │   │   └── literal-with-default.js
│   │   ├── custom-named-exports/
│   │   │   ├── main.js
│   │   │   └── secret-named-exporter.js
│   │   ├── custom-named-exports-browser-shims/
│   │   │   └── main.js
│   │   ├── custom-named-exports-false-positive/
│   │   │   ├── main.js
│   │   │   └── other.js
│   │   ├── custom-named-exports-warn-builtins/
│   │   │   └── main.js
│   │   ├── deconflict-helpers/
│   │   │   └── main.js
│   │   ├── define-is-undefined/
│   │   │   ├── foo.js
│   │   │   └── main.js
│   │   ├── es-modules-without-default-export/
│   │   │   ├── main.js
│   │   │   └── other.js
│   │   ├── extension/
│   │   │   ├── foo.coffee
│   │   │   └── main.coffee
│   │   ├── external/
│   │   │   └── main.js
│   │   ├── global/
│   │   │   └── main.js
│   │   ├── global-in-if-block/
│   │   │   └── main.js
│   │   ├── ignore-global/
│   │   │   ├── firstpass.js
│   │   │   ├── identifier.js
│   │   │   ├── main.js
│   │   │   └── this.js
│   │   ├── ignore-virtual-modules/
│   │   │   └── main.js
│   │   ├── invalid-syntax/
│   │   │   └── main.js
│   │   ├── multiple-entry-points/
│   │   │   ├── 2.js
│   │   │   ├── 3.js
│   │   │   ├── 4.js
│   │   │   ├── b.js
│   │   │   └── c.js
│   │   ├── named-exports-from-object-literal/
│   │   │   ├── a.js
│   │   │   ├── main.js
│   │   │   └── other.js
│   │   ├── other-transforms/
│   │   │   ├── bar.js
│   │   │   ├── foo.js
│   │   │   └── main.js
│   │   ├── paren-expression/
│   │   │   └── index.js
│   │   ├── reexport/
│   │   │   ├── export.js
│   │   │   ├── main.js
│   │   │   └── reexport.js
│   │   ├── rename-index/
│   │   │   ├── invalid-var/
│   │   │   │   └── index.js
│   │   │   ├── main.js
│   │   │   ├── other/
│   │   │   │   └── nonIndex.js
│   │   │   └── validVar/
│   │   │       └── index.js
│   │   ├── reserved-as-property/
│   │   │   └── main.js
│   │   ├── sourcemap/
│   │   │   ├── foo.js
│   │   │   └── main.js
│   │   ├── symlinked-node-modules/
│   │   │   └── index.js
│   │   ├── umd/
│   │   │   ├── correct-scoping.js
│   │   │   ├── protobuf.js
│   │   │   └── sinon.js
│   │   └── use-own-output/
│   │       ├── from-rollup.js
│   │       └── main.js
│   └── test.js
├── tsconfig.json
└── typings-test.js
Download .txt
SYMBOL INDEX (61 symbols across 23 files)

FILE: index.d.ts
  type RollupCommonJSOptions (line 3) | interface RollupCommonJSOptions {

FILE: src/ast-utils.js
  function flatten (line 3) | function flatten(node) {
  function extractNames (line 21) | function extractNames(node) {
  function getExtractor (line 27) | function getExtractor (type) {
  method Identifier (line 35) | Identifier(names, node) {
  method ObjectPattern (line 39) | ObjectPattern(names, node) {
  method ArrayPattern (line 45) | ArrayPattern(names, node) {
  method RestElement (line 52) | RestElement(names, node) {
  method AssignmentPattern (line 56) | AssignmentPattern(names, node) {
  function isTruthy (line 61) | function isTruthy(node) {
  function isFalsy (line 67) | function isFalsy(node) {
  function not (line 71) | function not(value) {
  function equals (line 75) | function equals(a, b, strict) {

FILE: src/helpers.js
  constant PROXY_SUFFIX (line 1) | const PROXY_SUFFIX = '?commonjs-proxy';
  constant EXTERNAL_SUFFIX (line 5) | const EXTERNAL_SUFFIX = '?commonjs-external';
  constant HELPERS_ID (line 9) | const HELPERS_ID = '\0commonjsHelpers.js';
  constant HELPERS (line 13) | const HELPERS = `

FILE: src/index.js
  function commonjs (line 19) | function commonjs(options = {}) {

FILE: src/is-cjs.js
  function getIsCjsPromise (line 3) | function getIsCjsPromise(id) {
  function setIsCjsPromise (line 19) | function setIsCjsPromise(id, resolution) {

FILE: src/resolve-id.js
  function getCandidatesForExtension (line 11) | function getCandidatesForExtension(resolved, extension) {
  function getCandidates (line 15) | function getCandidates(resolved, extensions) {
  function getResolveId (line 22) | function getResolveId(extensions) {

FILE: src/transform.js
  function deconflict (line 21) | function deconflict(scope, globals, identifier) {
  function tryParse (line 32) | function tryParse(parse, code, id) {
  function hasCjsKeywords (line 41) | function hasCjsKeywords(code, ignoreGlobal) {
  function checkEsModule (line 46) | function checkEsModule(parse, code, id) {
  function transformCommonjs (line 66) | function transformCommonjs(

FILE: src/utils.js
  function getName (line 4) | function getName(id) {
  function first (line 16) | function first(candidates) {

FILE: test/form/no-toplevel-return/input.js
  function baz (line 9) | function baz () {

FILE: test/form/no-toplevel-return/output.js
  function baz (line 9) | function baz () {

FILE: test/function/global-not-overwritten/_config.js
  method exports (line 4) | exports(exports) {

FILE: test/function/global-var/main.js
  function foo (line 1) | function foo () {

FILE: test/function/react-apollo/commonjs-bar.js
  function Bar (line 1) | function Bar () {

FILE: test/function/reassignment/foo.js
  function foo (line 1) | function foo () {}

FILE: test/function/resolve-is-cjs-extension/_config.js
  method resolveId (line 6) | resolveId(importee) {

FILE: test/function/resolve-is-cjs-filtered/_config.js
  method resolveId (line 6) | resolveId(importee) {

FILE: test/function/shadowing/main.js
  function foo (line 1) | function foo ( require ) {

FILE: test/samples/array-destructuring-assignment/main.js
  function shuffleArray (line 2) | function shuffleArray(array) {

FILE: test/samples/multiple-entry-points/2.js
  function second (line 1) | function second () {

FILE: test/samples/multiple-entry-points/3.js
  function third (line 1) | function third () {

FILE: test/samples/multiple-entry-points/4.js
  function fourth (line 1) | function fourth () {

FILE: test/samples/umd/sinon.js
  function loadDependencies (line 9) | function loadDependencies(require, exports, module) {

FILE: test/test.js
  function commonjs (line 14) | function commonjs(options) {
  function execute (line 23) | function execute(code, context = {}) {
  function getCodeFromBundle (line 62) | async function getCodeFromBundle(bundle, customOptions = {}) {
  function executeBundle (line 67) | async function executeBundle(bundle, { context, exports } = {}) {
  method onwarn (line 364) | onwarn(warning) {
  method transform (line 556) | transform(code, id) {
  function define (line 574) | function define() {
  method resolveId (line 680) | resolveId(id) {
  method load (line 685) | load(id) {
  method onwarn (line 699) | onwarn(warning) {
  method load (line 706) | load(id) {
  method resolveId (line 718) | resolveId(id) {
  method load (line 737) | load(id) {
  method resolveId (line 745) | resolveId(id) {
  method load (line 771) | load(id) {
  method resolveId (line 779) | resolveId(id) {
  function hookedResolve (line 838) | function hookedResolve() {
Condensed preview — 217 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (114K chars).
[
  {
    "path": ".babelrc.js",
    "chars": 113,
    "preview": "module.exports = {\n\tpresets: [\n\t\t[\n\t\t\t'@babel/preset-env',\n\t\t\t{\n\t\t\t\ttargets: {\n\t\t\t\t\tnode: 6\n\t\t\t\t}\n\t\t\t}\n\t\t]\n\t]\n};\n"
  },
  {
    "path": ".eslintrc.json",
    "chars": 1023,
    "preview": "{\n  \"root\": true,\n  \"rules\": {\n    \"indent\": [ 2, \"tab\", { \"SwitchCase\": 1 } ],\n    \"semi\": [ 2, \"always\" ],\n    \"keywor"
  },
  {
    "path": ".gitignore",
    "chars": 59,
    "preview": ".DS_Store\nnode_modules\n.gobble*\ndist\n!test/**/node_modules\n"
  },
  {
    "path": ".huskyrc",
    "chars": 85,
    "preview": "{\n  \"hooks\": {\n    \"post-commit\": \"git reset\",\n    \"pre-commit\": \"lint-staged\"\n  }\n}\n"
  },
  {
    "path": ".lintstagedrc",
    "chars": 113,
    "preview": "{\n  \"{src/**/*,test/test,test/**/_config}.js\": [\n    \"prettier --write\",\n    \"eslint --fix\",\n    \"git add\"\n  ]\n}\n"
  },
  {
    "path": ".prettierrc",
    "chars": 63,
    "preview": "{\n\t\"singleQuote\": true,\n\t\"useTabs\": true,\n\t\"printWidth\": 100\n}\n"
  },
  {
    "path": ".travis.yml",
    "chars": 223,
    "preview": "sudo: false\nlanguage: node_js\nnode_js:\n  - \"8\"\n  - \"10\"\nenv:\n  global:\n    - BUILD_TIMEOUT=10000\ninstall: npm ci --ignor"
  },
  {
    "path": "CHANGELOG.md",
    "chars": 11499,
    "preview": "# rollup-plugin-commonjs changelog\n\n## 10.1.0\n*2019-08-27*\n* Normalize ids before looking up in named export map ([#406]"
  },
  {
    "path": "LICENSE",
    "chars": 1151,
    "preview": "The MIT License (MIT)\n\nCopyright (c) 2017 [these people](https://github.com/rollup/rollup-plugin-commonjs/graphs/contrib"
  },
  {
    "path": "README.md",
    "chars": 4393,
    "preview": "# Moved\n\nThis module has moved and is now available at [@rollup/plugin-commonjs](https://github.com/rollup/plugins). Ple"
  },
  {
    "path": "appveyor.yml",
    "chars": 650,
    "preview": "# http://www.appveyor.com/docs/appveyor-yml\n\nversion: \"{build}\"\n\nclone_depth: 10\n\ninit:\n  - git config --global core.aut"
  },
  {
    "path": "index.d.ts",
    "chars": 1545,
    "preview": "import { Plugin } from 'rollup';\n\ninterface RollupCommonJSOptions {\n\t/**\n\t * non-CommonJS modules will be ignored, but y"
  },
  {
    "path": "package.json",
    "chars": 1877,
    "preview": "{\n  \"name\": \"rollup-plugin-commonjs\",\n  \"version\": \"10.1.0\",\n  \"description\": \"Convert CommonJS modules to ES2015\",\n  \"m"
  },
  {
    "path": "rollup.config.js",
    "chars": 404,
    "preview": "import babel from 'rollup-plugin-babel';\nimport json from 'rollup-plugin-json';\nimport pkg from './package.json';\n\nexpor"
  },
  {
    "path": "src/ast-utils.js",
    "chars": 2100,
    "preview": "export { default as isReference } from 'is-reference';\n\nexport function flatten(node) {\n\tconst parts = [];\n\n\twhile (node"
  },
  {
    "path": "src/helpers.js",
    "chars": 1363,
    "preview": "export const PROXY_SUFFIX = '?commonjs-proxy';\nexport const getProxyId = id => `\\0${id}${PROXY_SUFFIX}`;\nexport const ge"
  },
  {
    "path": "src/index.js",
    "chars": 5190,
    "preview": "import { realpathSync, existsSync } from 'fs';\nimport { extname, resolve, normalize } from 'path';\nimport { sync as node"
  },
  {
    "path": "src/is-cjs.js",
    "chars": 688,
    "preview": "const isCjsPromises = new Map();\n\nexport function getIsCjsPromise(id) {\n\tlet isCjsPromise = isCjsPromises.get(id);\n\tif ("
  },
  {
    "path": "src/resolve-id.js",
    "chars": 1838,
    "preview": "import { statSync } from 'fs';\nimport { dirname, resolve, sep } from 'path';\nimport {\n\tgetExternalProxyId,\n\tgetIdFromPro"
  },
  {
    "path": "src/transform.js",
    "chars": 14862,
    "preview": "import { walk } from 'estree-walker';\nimport MagicString from 'magic-string';\nimport { attachScopes, extractAssignedName"
  },
  {
    "path": "src/utils.js",
    "chars": 734,
    "preview": "import { basename, dirname, extname, sep } from 'path';\nimport { makeLegalIdentifier } from 'rollup-pluginutils';\n\nexpor"
  },
  {
    "path": "test/form/async-function/input.js",
    "chars": 49,
    "preview": "module.exports = async function () {\n\t// TODO\n};\n"
  },
  {
    "path": "test/form/async-function/output.js",
    "chars": 104,
    "preview": "var input = async function () {\n\t// TODO\n};\n\nexport default input;\nexport { input as __moduleExports };\n"
  },
  {
    "path": "test/form/constant-template-literal/input.js",
    "chars": 45,
    "preview": "var foo = require(`tape`);\nconsole.log(foo);\n"
  },
  {
    "path": "test/form/constant-template-literal/output.js",
    "chars": 153,
    "preview": "import 'tape';\nimport foo from '_tape?commonjs-proxy';\n\nconsole.log(foo);\n\nvar input = {\n\n};\n\nexport default input;\nexpo"
  },
  {
    "path": "test/form/dynamic-template-literal/input.js",
    "chars": 63,
    "preview": "var pe = 'pe';\nvar foo = require(`ta${pe}`);\nconsole.log(foo);\n"
  },
  {
    "path": "test/form/dynamic-template-literal/output.js",
    "chars": 223,
    "preview": "import * as commonjsHelpers from '_commonjsHelpers.js';\n\nvar pe = 'pe';\nvar foo = commonjsHelpers.commonjsRequire(`ta${p"
  },
  {
    "path": "test/form/ignore-ids/_config.js",
    "chars": 55,
    "preview": "module.exports = {\n\toptions: {\n\t\tignore: ['foo']\n\t}\n};\n"
  },
  {
    "path": "test/form/ignore-ids/input.js",
    "chars": 55,
    "preview": "var foo = require( 'foo' );\nvar bar = require( 'bar' );"
  },
  {
    "path": "test/form/ignore-ids/output.js",
    "chars": 161,
    "preview": "import 'bar';\nimport bar from '_bar?commonjs-proxy';\n\nvar foo = require( 'foo' );\n\nvar input = {\n\n};\n\nexport default inp"
  },
  {
    "path": "test/form/ignore-ids-function/_config.js",
    "chars": 66,
    "preview": "module.exports = {\n\toptions: {\n\t\tignore: id => id === 'foo'\n\t}\n};\n"
  },
  {
    "path": "test/form/ignore-ids-function/input.js",
    "chars": 55,
    "preview": "var foo = require( 'foo' );\nvar bar = require( 'bar' );"
  },
  {
    "path": "test/form/ignore-ids-function/output.js",
    "chars": 161,
    "preview": "import 'bar';\nimport bar from '_bar?commonjs-proxy';\n\nvar foo = require( 'foo' );\n\nvar input = {\n\n};\n\nexport default inp"
  },
  {
    "path": "test/form/multiple-var-declarations/input.js",
    "chars": 70,
    "preview": "var a = require('./a')()\n  , b = require('./b');\n\nconsole.log( a, b );"
  },
  {
    "path": "test/form/multiple-var-declarations/output.js",
    "chars": 235,
    "preview": "import './a';\nimport './b';\nimport require$$0 from '_./a?commonjs-proxy';\nimport b from '_./b?commonjs-proxy';\n\nvar a = "
  },
  {
    "path": "test/form/multiple-var-declarations-b/input.js",
    "chars": 56,
    "preview": "var a = require('./a')\n  , b = 42;\n\nconsole.log( a, b );"
  },
  {
    "path": "test/form/multiple-var-declarations-b/output.js",
    "chars": 165,
    "preview": "import './a';\nimport a from '_./a?commonjs-proxy';\n\nvar b = 42;\n\nconsole.log( a, b );\n\nvar input = {\n\n};\n\nexport default"
  },
  {
    "path": "test/form/multiple-var-declarations-c/input.js",
    "chars": 74,
    "preview": "var a = 'a'\n  , b = require( './b' )\n  , c = 'c';\n\nconsole.log( a, b, c );"
  },
  {
    "path": "test/form/multiple-var-declarations-c/output.js",
    "chars": 181,
    "preview": "import './b';\nimport b from '_./b?commonjs-proxy';\n\nvar a = 'a'\n  , c = 'c';\n\nconsole.log( a, b, c );\n\nvar input = {\n\n};"
  },
  {
    "path": "test/form/no-exports-entry/_config.js",
    "chars": 79,
    "preview": "module.exports = {\n\toptions: {\n\t\tignore: [ 'foo' ]\n\t},\n\tentry: './input.js'\n};\n"
  },
  {
    "path": "test/form/no-exports-entry/input.js",
    "chars": 86,
    "preview": "var dummy = require('./dummy');\n\nvar foo = function () {\n\treturn;\n};\n\nvar input = 42;\n"
  },
  {
    "path": "test/form/no-exports-entry/output.js",
    "chars": 117,
    "preview": "import './dummy';\nimport dummy from '_./dummy?commonjs-proxy';\n\nvar foo = function () {\n\treturn;\n};\n\nvar input = 42;\n"
  },
  {
    "path": "test/form/no-toplevel-return/input.js",
    "chars": 119,
    "preview": "var foo = function () {\n\treturn;\n};\n\nvar bar = () => {\n\treturn;\n};\n\nfunction baz () {\n\treturn;\n}\n\nmodule.exports = 42;\n"
  },
  {
    "path": "test/form/no-toplevel-return/output.js",
    "chars": 174,
    "preview": "var foo = function () {\n\treturn;\n};\n\nvar bar = () => {\n\treturn;\n};\n\nfunction baz () {\n\treturn;\n}\n\nvar input = 42;\n\nexpor"
  },
  {
    "path": "test/form/optimised-default-export/input.js",
    "chars": 21,
    "preview": "module.exports = 42;\n"
  },
  {
    "path": "test/form/optimised-default-export/output.js",
    "chars": 76,
    "preview": "var input = 42;\n\nexport default input;\nexport { input as __moduleExports };\n"
  },
  {
    "path": "test/form/optimised-default-export-function/input.js",
    "chars": 37,
    "preview": "module.exports = function foo () {};\n"
  },
  {
    "path": "test/form/optimised-default-export-function/output.js",
    "chars": 92,
    "preview": "var input = function foo () {};\n\nexport default input;\nexport { input as __moduleExports };\n"
  },
  {
    "path": "test/form/optimised-default-export-function-double-assign/input.js",
    "chars": 52,
    "preview": "var bar;\nmodule.exports = bar = function foo () {};\n"
  },
  {
    "path": "test/form/optimised-default-export-function-double-assign/output.js",
    "chars": 107,
    "preview": "var bar;\nvar input = bar = function foo () {};\n\nexport default input;\nexport { input as __moduleExports };\n"
  },
  {
    "path": "test/form/optimised-default-export-iife/input.js",
    "chars": 75,
    "preview": "module.exports = (function foo () {\n  return function fooChild() {};\n}());\n"
  },
  {
    "path": "test/form/optimised-default-export-iife/output.js",
    "chars": 130,
    "preview": "var input = (function foo () {\n  return function fooChild() {};\n}());\n\nexport default input;\nexport { input as __moduleE"
  },
  {
    "path": "test/form/optimised-named-export/input.js",
    "chars": 45,
    "preview": "exports.foo = 'a';\nmodule.exports.bar = 'b';\n"
  },
  {
    "path": "test/form/optimised-named-export/output.js",
    "chars": 161,
    "preview": "var foo = 'a';\nvar bar = 'b';\n\nvar input = {\n\tfoo: foo,\n\tbar: bar\n};\n\nexport default input;\nexport { input as __moduleEx"
  },
  {
    "path": "test/form/optimised-named-export-conflicts/input.js",
    "chars": 72,
    "preview": "var foo = 1;\nvar bar = 2;\n\nexports.foo = 'a';\nmodule.exports.bar = 'b';\n"
  },
  {
    "path": "test/form/optimised-named-export-conflicts/output.js",
    "chars": 214,
    "preview": "var foo = 1;\nvar bar = 2;\n\nvar foo_1 = 'a';\nvar bar_1 = 'b';\n\nvar input = {\n\tfoo: foo_1,\n\tbar: bar_1\n};\n\nexport default "
  },
  {
    "path": "test/form/require-collision/input.js",
    "chars": 95,
    "preview": "(function() {\n  var foo = require(\"foo\");\n  var require$$0 = \"FAIL\";\n  console.log(foo);\n})();\n"
  },
  {
    "path": "test/form/require-collision/output.js",
    "chars": 231,
    "preview": "import 'foo';\nimport require$$1 from '_foo?commonjs-proxy';\n\n(function() {\n  var foo = require$$1;\n  var require$$0 = \"F"
  },
  {
    "path": "test/form/typeof-module-exports/input.js",
    "chars": 236,
    "preview": "var foo = 42;\n\nif ( typeof exports === 'object' && typeof module === 'object' ) {\n\tmodule.exports = foo;\n} else if ( typ"
  },
  {
    "path": "test/form/typeof-module-exports/output.js",
    "chars": 433,
    "preview": "import * as commonjsHelpers from '_commonjsHelpers.js';\n\nvar input = commonjsHelpers.createCommonjsModule(function (modu"
  },
  {
    "path": "test/form/unambiguous-with-default-export/input.js",
    "chars": 43,
    "preview": "require( './foo.js' );\n\nexport default {};\n"
  },
  {
    "path": "test/form/unambiguous-with-default-export/output.js",
    "chars": 43,
    "preview": "require( './foo.js' );\n\nexport default {};\n"
  },
  {
    "path": "test/form/unambiguous-with-import/input.js",
    "chars": 43,
    "preview": "require( './foo.js' );\n\nimport './bar.js';\n"
  },
  {
    "path": "test/form/unambiguous-with-import/output.js",
    "chars": 43,
    "preview": "require( './foo.js' );\n\nimport './bar.js';\n"
  },
  {
    "path": "test/form/unambiguous-with-named-export/input.js",
    "chars": 35,
    "preview": "require( './foo.js' );\n\nexport {};\n"
  },
  {
    "path": "test/form/unambiguous-with-named-export/output.js",
    "chars": 35,
    "preview": "require( './foo.js' );\n\nexport {};\n"
  },
  {
    "path": "test/function/__esModule/answer.js",
    "chars": 48,
    "preview": "exports.__esModule = true;\nexports.answer = 42;\n"
  },
  {
    "path": "test/function/__esModule/main.js",
    "chars": 126,
    "preview": "import * as x from './answer';\n\nassert.ok( 'answer' in x );\nassert.ok( 'default' in x );\nassert.ok( !( '__esModule' in x"
  },
  {
    "path": "test/function/assign-properties-to-default-export/foo.js",
    "chars": 78,
    "preview": "var foo = {};\n\nmodule.exports = foo;\nmodule.exports.bar = 1;\nexports.baz = 2;\n"
  },
  {
    "path": "test/function/assign-properties-to-default-export/main.js",
    "chars": 85,
    "preview": "import foo from './foo.js';\n\nassert.equal( foo.bar, 1 );\nassert.equal( foo.baz, 2 );\n"
  },
  {
    "path": "test/function/assumed-globals/_config.js",
    "chars": 64,
    "preview": "module.exports = {\n\tcontext: {\n\t\tdocument: { real: true }\n\t}\n};\n"
  },
  {
    "path": "test/function/assumed-globals/document.js",
    "chars": 114,
    "preview": "if ( typeof document !== 'undefined' ) {\n\tmodule.exports = document;\n} else {\n\tmodule.exports = { fake: true };\n}\n"
  },
  {
    "path": "test/function/assumed-globals/main.js",
    "chars": 84,
    "preview": "import document from './document.js';\n\nassert.deepEqual( document, { real: true });\n"
  },
  {
    "path": "test/function/bare-import/_config.js",
    "chars": 21,
    "preview": "module.exports = {};\n"
  },
  {
    "path": "test/function/bare-import/bar.js",
    "chars": 15,
    "preview": "Math.bar = 42;\n"
  },
  {
    "path": "test/function/bare-import/foo.js",
    "chars": 23,
    "preview": "require( './bar.js' );\n"
  },
  {
    "path": "test/function/bare-import/main.js",
    "chars": 50,
    "preview": "import './foo.js';\n\nassert.equal( Math.bar, 42 );\n"
  },
  {
    "path": "test/function/bare-import-comment/bar.js",
    "chars": 31,
    "preview": "// Great module\nMath.bar = 42;\n"
  },
  {
    "path": "test/function/bare-import-comment/foo.js",
    "chars": 23,
    "preview": "require( './bar.js' );\n"
  },
  {
    "path": "test/function/bare-import-comment/main.js",
    "chars": 50,
    "preview": "import './foo.js';\n\nassert.equal( Math.bar, 42 );\n"
  },
  {
    "path": "test/function/basic/_config.js",
    "chars": 112,
    "preview": "const assert = require('assert');\n\nmodule.exports = {\n\texports: exports => {\n\t\tassert.equal(exports, 42);\n\t}\n};\n"
  },
  {
    "path": "test/function/basic/foo.js",
    "chars": 21,
    "preview": "module.exports = 21;\n"
  },
  {
    "path": "test/function/basic/main.js",
    "chars": 56,
    "preview": "var foo = require( './foo' );\nmodule.exports = foo * 2;\n"
  },
  {
    "path": "test/function/deconflict-export-and-local/index.js",
    "chars": 94,
    "preview": "var someValueModule = require('./someValue');\n\nexports.someValue = someValueModule.someValue;\n"
  },
  {
    "path": "test/function/deconflict-export-and-local/main.js",
    "chars": 72,
    "preview": "import { someValue } from './index.js';\n\nassert.equal( someValue, 10 );\n"
  },
  {
    "path": "test/function/deconflict-export-and-local/someValue.js",
    "chars": 24,
    "preview": "exports.someValue = 10;\n"
  },
  {
    "path": "test/function/dot/foo.bar.js",
    "chars": 26,
    "preview": "module.exports = 'fubar';\n"
  },
  {
    "path": "test/function/dot/main.js",
    "chars": 71,
    "preview": "var status = require( './foo.bar' );\n\nassert.equal( status, 'fubar' );\n"
  },
  {
    "path": "test/function/duplicate-default-exports/main.js",
    "chars": 57,
    "preview": "import x from './x';\n\nassert.strictEqual( x.default, x );"
  },
  {
    "path": "test/function/duplicate-default-exports/x.js",
    "chars": 60,
    "preview": "var x = {};\n\nmodule.exports = x;\nmodule.exports.default = x;"
  },
  {
    "path": "test/function/duplicate-default-exports-b/main.js",
    "chars": 60,
    "preview": "import x from './x';\n\nassert.deepEqual( x, { default: 42 });"
  },
  {
    "path": "test/function/duplicate-default-exports-b/x.js",
    "chars": 61,
    "preview": "var x = {};\n\nmodule.exports = x;\nmodule.exports.default = 42;"
  },
  {
    "path": "test/function/duplicate-default-exports-c/exports.js",
    "chars": 82,
    "preview": "exports.Foo = 1;\nexports.var = 'VAR';\nexports.default = {\n\tFoo: 2,\n\tdefault: 3\n};\n"
  },
  {
    "path": "test/function/duplicate-default-exports-c/main.js",
    "chars": 381,
    "preview": "import E from './exports.js';\nimport { Foo } from './exports.js';\nimport { var as Var } from './exports.js';\n\nassert.str"
  },
  {
    "path": "test/function/export-default-from/_config.js",
    "chars": 21,
    "preview": "module.exports = {};\n"
  },
  {
    "path": "test/function/export-default-from/imported.js",
    "chars": 33,
    "preview": "export default 'default export';\n"
  },
  {
    "path": "test/function/export-default-from/main.js",
    "chars": 57,
    "preview": "assert.equal(require('./reexporter'), 'default export');\n"
  },
  {
    "path": "test/function/export-default-from/reexporter.js",
    "chars": 36,
    "preview": "export {default} from './imported';\n"
  },
  {
    "path": "test/function/exports/_config.js",
    "chars": 118,
    "preview": "const assert = require('assert');\n\nmodule.exports = {\n\texports: exports => {\n\t\tassert.equal(exports, 'BARBAZ');\n\t}\n};\n"
  },
  {
    "path": "test/function/exports/foo.js",
    "chars": 42,
    "preview": "exports.bar = 'BAR';\nexports.baz = 'BAZ';\n"
  },
  {
    "path": "test/function/exports/main.js",
    "chars": 97,
    "preview": "var bar = require( './foo' ).bar;\nvar baz = require( './foo' ).baz;\n\nmodule.exports = bar + baz;\n"
  },
  {
    "path": "test/function/external-imports/_config.js",
    "chars": 151,
    "preview": "const assert = require('assert');\n\nmodule.exports = {\n\toptions: {\n\t\texternal: ['foo']\n\t},\n\texports: exports => {\n\t\tasser"
  },
  {
    "path": "test/function/external-imports/main.js",
    "chars": 51,
    "preview": "var foo = require( 'foo' );\n\nmodule.exports = foo;\n"
  },
  {
    "path": "test/function/fallback-no-default/foo.js",
    "chars": 41,
    "preview": "export var one = 1;\n\nexport var two = 2;\n"
  },
  {
    "path": "test/function/fallback-no-default/main.js",
    "chars": 88,
    "preview": "var foo = require('./foo.js');\n\nassert.equal( foo.one, 1 );\nassert.equal( foo.two, 2 );\n"
  },
  {
    "path": "test/function/global-not-overwritten/_config.js",
    "chars": 148,
    "preview": "const assert = require('assert');\n\nmodule.exports = {\n\texports(exports) {\n\t\tassert.equal(exports.encoded, encodeURICompo"
  },
  {
    "path": "test/function/global-not-overwritten/encode.js",
    "chars": 140,
    "preview": "exports.encodeURIComponent = function () {\n\treturn encodeURIComponent( this.str );\n};\n\nglobal.foo = exports; // to ensur"
  },
  {
    "path": "test/function/global-not-overwritten/main.js",
    "chars": 155,
    "preview": "import { encodeURIComponent } from './encode.js';\n\nvar foo = {\n\tstr: 'test string',\n\tencodeURIComponent\n};\n\nexport var e"
  },
  {
    "path": "test/function/global-var/main.js",
    "chars": 196,
    "preview": "function foo () {\n\tvar a = 1, global = {};\n\tglobal.modified = true;\n\treturn global;\n}\n\nvar notGlobal = foo();\nassert.ok("
  },
  {
    "path": "test/function/index/foo/index.js",
    "chars": 21,
    "preview": "module.exports = 42;\n"
  },
  {
    "path": "test/function/index/main.js",
    "chars": 56,
    "preview": "var foo = require( './foo' );\n\nassert.equal( foo, 42 );\n"
  },
  {
    "path": "test/function/inline/_config.js",
    "chars": 113,
    "preview": "const assert = require('assert');\n\nmodule.exports = {\n\texports: exports => {\n\t\tassert.equal(exports(), 2);\n\t}\n};\n"
  },
  {
    "path": "test/function/inline/foo.js",
    "chars": 20,
    "preview": "module.exports = 1;\n"
  },
  {
    "path": "test/function/inline/main.js",
    "chars": 92,
    "preview": "module.exports = function () {\n\treturn require( './multiply' )( 2, require( './foo' ) );\n};\n"
  },
  {
    "path": "test/function/inline/multiply.js",
    "chars": 55,
    "preview": "module.exports = function ( a, b ) {\n\treturn a * b;\n};\n"
  },
  {
    "path": "test/function/named-exports/foo.js",
    "chars": 37,
    "preview": "exports.a = 1;\nmodule.exports.b = 2;\n"
  },
  {
    "path": "test/function/named-exports/main.js",
    "chars": 78,
    "preview": "import { a, b } from './foo.js';\n\nassert.equal( a, 1 );\nassert.equal( b, 2 );\n"
  },
  {
    "path": "test/function/ordering/bar.js",
    "chars": 69,
    "preview": "var shared = require('./shared');\n\nmodule.exports = shared.fooLoaded\n"
  },
  {
    "path": "test/function/ordering/foo.js",
    "chars": 88,
    "preview": "var shared = require('./shared');\n\n// Mutate the shared module\nshared.fooLoaded = true;\n"
  },
  {
    "path": "test/function/ordering/main.js",
    "chars": 78,
    "preview": "require('./foo');\n\nvar fooLoaded = require('./bar');\n\nassert.ok( fooLoaded );\n"
  },
  {
    "path": "test/function/ordering/shared.js",
    "chars": 40,
    "preview": "module.exports = {\n\tfooLoaded: false\n};\n"
  },
  {
    "path": "test/function/react-apollo/commonjs-bar.js",
    "chars": 85,
    "preview": "function Bar () {\n\tthis.x = 42;\n}\n\nexports.__esModule = true;\nexports.default = Bar;\n"
  },
  {
    "path": "test/function/react-apollo/commonjs-foo.js",
    "chars": 94,
    "preview": "var Bar = require( './commonjs-bar' );\n\nexports.__esModule = true;\nexports.Bar = Bar.default;\n"
  },
  {
    "path": "test/function/react-apollo/main.js",
    "chars": 75,
    "preview": "import { Bar } from './commonjs-foo.js';\n\nassert.equal( new Bar().x, 42 );\n"
  },
  {
    "path": "test/function/reassignment/foo.js",
    "chars": 65,
    "preview": "function foo () {}\nfoo.something = false;\n\nmodule.exports = foo;\n"
  },
  {
    "path": "test/function/reassignment/main.js",
    "chars": 148,
    "preview": "var foo = require( './foo.js' );\n\nif ( !foo.something ) {\n\tfoo = function somethingElse () {}\n\tfoo.something = true;\n}\n\n"
  },
  {
    "path": "test/function/reexports/_config.js",
    "chars": 146,
    "preview": "const path = require('path');\n\nmodule.exports = {\n\tpluginOptions: {\n\t\tnamedExports: {\n\t\t\t[path.resolve(__dirname, 'foo.j"
  },
  {
    "path": "test/function/reexports/bar.js",
    "chars": 20,
    "preview": "exports.named = 42;\n"
  },
  {
    "path": "test/function/reexports/foo.js",
    "chars": 40,
    "preview": "module.exports = require( './bar.js' );\n"
  },
  {
    "path": "test/function/reexports/main.js",
    "chars": 62,
    "preview": "import { named } from './foo.js';\n\nassert.equal( named, 42 );\n"
  },
  {
    "path": "test/function/resolve-is-cjs-extension/_config.js",
    "chars": 291,
    "preview": "module.exports = {\n\tdescription: 'always resolve cjs detection even if an imported file has an unknown extension',\n\topti"
  },
  {
    "path": "test/function/resolve-is-cjs-extension/main.js",
    "chars": 51,
    "preview": "assert.equal(require('second').result, 'second' );\n"
  },
  {
    "path": "test/function/resolve-is-cjs-extension/second.x",
    "chars": 32,
    "preview": "export const result = 'second';\n"
  },
  {
    "path": "test/function/resolve-is-cjs-filtered/_config.js",
    "chars": 337,
    "preview": "module.exports = {\n\tdescription: 'always resolve cjs detection even if an imported file is filtered',\n\toptions: {\n\t\tplug"
  },
  {
    "path": "test/function/resolve-is-cjs-filtered/main.js",
    "chars": 51,
    "preview": "assert.equal(require('second').result, 'second' );\n"
  },
  {
    "path": "test/function/resolve-is-cjs-filtered/second.js",
    "chars": 32,
    "preview": "export const result = 'second';\n"
  },
  {
    "path": "test/function/shadowing/main.js",
    "chars": 193,
    "preview": "function foo ( require ) {\n\trequire( 'not-an-actual-require-statement' );\n}\n\nvar result;\n\nfoo( function ( msg ) {\n\tresul"
  },
  {
    "path": "test/function/skips-dead-branches/_config.js",
    "chars": 184,
    "preview": "const assert = require('assert');\n\nmodule.exports = {\n\tglobal: global => {\n\t\tassert.equal(global.a, undefined);\n\t\tassert"
  },
  {
    "path": "test/function/skips-dead-branches/a.js",
    "chars": 14,
    "preview": "global.a = 1;\n"
  },
  {
    "path": "test/function/skips-dead-branches/b.js",
    "chars": 36,
    "preview": "global.b = 2;\nmodule.exports = 'b';\n"
  },
  {
    "path": "test/function/skips-dead-branches/c.js",
    "chars": 36,
    "preview": "global.c = 3;\nmodule.exports = 'c';\n"
  },
  {
    "path": "test/function/skips-dead-branches/main.js",
    "chars": 134,
    "preview": "if ( 'development' === 'production' ) {\n\trequire( './a.js' );\n}\n\nmodule.exports = true ?\n\trequire( './b.js' ) :\n\trequire"
  },
  {
    "path": "test/function/this/foo.js",
    "chars": 76,
    "preview": "module.exports = function augmentThis () {\n\tthis.x = 'x';\n};\n\nthis.y = 'y';\n"
  },
  {
    "path": "test/function/this/main.js",
    "chars": 120,
    "preview": "var foo = require( './foo' );\n\nvar obj = {};\nfoo.call( obj );\n\nassert.equal( obj.x, 'x' );\nassert.equal( this.y, 'y' );\n"
  },
  {
    "path": "test/function/toplevel-return/_config.js",
    "chars": 115,
    "preview": "const assert = require('assert');\n\nmodule.exports = {\n\texports: exports => {\n\t\tassert.equal(exports, 'foo');\n\t}\n};\n"
  },
  {
    "path": "test/function/toplevel-return/foo.js",
    "chars": 32,
    "preview": "module.exports = 'foo';\nreturn;\n"
  },
  {
    "path": "test/function/toplevel-return/main.js",
    "chars": 53,
    "preview": "var foo = require('./foo');\n\nmodule.exports = 'foo';\n"
  },
  {
    "path": "test/function/toplevel-return-complex/_config.js",
    "chars": 115,
    "preview": "const assert = require('assert');\n\nmodule.exports = {\n\texports: exports => {\n\t\tassert.equal(exports, 'bar');\n\t}\n};\n"
  },
  {
    "path": "test/function/toplevel-return-complex/bar.js",
    "chars": 49,
    "preview": "module.exports = function () {\n  return true;\n};\n"
  },
  {
    "path": "test/function/toplevel-return-complex/foo.js",
    "chars": 101,
    "preview": "var bar = require('./bar');\nmodule.exports = 'bar';\nif (bar()) {\n  return;\n}\nmodule.exports = 'foo';\n"
  },
  {
    "path": "test/function/toplevel-return-complex/main.js",
    "chars": 51,
    "preview": "var foo = require('./foo');\n\nmodule.exports = foo;\n"
  },
  {
    "path": "test/function/trailing-slash/foo/index.js",
    "chars": 21,
    "preview": "module.exports = 42;\n"
  },
  {
    "path": "test/function/trailing-slash/main.js",
    "chars": 57,
    "preview": "var foo = require( './foo/' );\n\nassert.equal( foo, 42 );\n"
  },
  {
    "path": "test/function/typeof-require/foo.js",
    "chars": 103,
    "preview": "if ( typeof require === 'function' && require ) {\n\tmodule.exports = 1;\n} else {\n\tmodule.exports = 2;\n}\n"
  },
  {
    "path": "test/function/typeof-require/main.js",
    "chars": 53,
    "preview": "import foo from './foo.js';\n\nassert.equal( foo, 1 );\n"
  },
  {
    "path": "test/mocha.opts",
    "chars": 26,
    "preview": "--require @babel/register\n"
  },
  {
    "path": "test/node_modules/.gitkeep",
    "chars": 0,
    "preview": ""
  },
  {
    "path": "test/node_modules/bar/index.js",
    "chars": 74,
    "preview": "const baz = require('baz');\nmodule.exports = function () {\n\treturn baz;\n};"
  },
  {
    "path": "test/node_modules/baz/index.js",
    "chars": 25,
    "preview": "module.exports = 'hello';"
  },
  {
    "path": "test/node_modules/events/index.js",
    "chars": 103,
    "preview": "exports.message = 'this is not builtin';\n\nconst myLib = exports;\nmyLib.foo = 'this is a hidden export';"
  },
  {
    "path": "test/node_modules/external/index.js",
    "chars": 61,
    "preview": "var externalLib = exports;\nexternalLib.message = 'it works';\n"
  },
  {
    "path": "test/node_modules/foo/index.js",
    "chars": 23,
    "preview": "module.exports = 'foo';"
  },
  {
    "path": "test/samples/array-destructuring-assignment/main.js",
    "chars": 223,
    "preview": "\nfunction shuffleArray(array) {\n  for (let i = array.length - 1; i > 0; i--) {\n    const j = Math.floor(Math.random() * "
  },
  {
    "path": "test/samples/corejs/literal-with-default.js",
    "chars": 58,
    "preview": "module.exports = { default: 'foobar', __esModule: true };\n"
  },
  {
    "path": "test/samples/custom-named-exports/main.js",
    "chars": 153,
    "preview": "import { named } from './secret-named-exporter.js';\nimport { message } from 'external';\n\nassert.equal( named, 42 );\nasse"
  },
  {
    "path": "test/samples/custom-named-exports/secret-named-exporter.js",
    "chars": 39,
    "preview": "var myLib = exports;\nmyLib.named = 42;\n"
  },
  {
    "path": "test/samples/custom-named-exports-browser-shims/main.js",
    "chars": 136,
    "preview": "import { message, foo } from 'events';\n\nassert.equal( message, 'this is not builtin' );\nassert.equal( foo, 'this is a hi"
  },
  {
    "path": "test/samples/custom-named-exports-false-positive/main.js",
    "chars": 66,
    "preview": "import { thing } from './other.js';\nassert.equal( thing, 'yes' );\n"
  },
  {
    "path": "test/samples/custom-named-exports-false-positive/other.js",
    "chars": 101,
    "preview": "/* require (https://github.com/rollup/rollup-plugin-commonjs/issues/36) */\nexport var thing = 'yes';\n"
  },
  {
    "path": "test/samples/custom-named-exports-warn-builtins/main.js",
    "chars": 83,
    "preview": "import { message } from 'events';\n\nassert.equal( message, 'this is not builtin' );\n"
  },
  {
    "path": "test/samples/deconflict-helpers/main.js",
    "chars": 75,
    "preview": "var commonjsHelpers = { commonjsGlobal: 'nope' };\nmodule.exports = global;\n"
  },
  {
    "path": "test/samples/define-is-undefined/foo.js",
    "chars": 271,
    "preview": "(function (global, factory) {\n\ttypeof define === 'function' && define.amd ? define(factory) :\n\ttypeof exports === 'objec"
  },
  {
    "path": "test/samples/define-is-undefined/main.js",
    "chars": 48,
    "preview": "import foo from './foo.js';\n\nexport default 42;\n"
  },
  {
    "path": "test/samples/es-modules-without-default-export/main.js",
    "chars": 60,
    "preview": "const { a } = require('./other.js');\n\nassert.equal( a, 1 );\n"
  },
  {
    "path": "test/samples/es-modules-without-default-export/other.js",
    "chars": 20,
    "preview": "export const a = 1;\n"
  },
  {
    "path": "test/samples/extension/foo.coffee",
    "chars": 21,
    "preview": "module.exports = 21;\n"
  },
  {
    "path": "test/samples/extension/main.coffee",
    "chars": 56,
    "preview": "var foo = require( './foo' );\nmodule.exports = foo * 2;\n"
  },
  {
    "path": "test/samples/external/main.js",
    "chars": 59,
    "preview": "import bar from 'bar';\n\nexport default bar().toUpperCase();"
  },
  {
    "path": "test/samples/global/main.js",
    "chars": 20,
    "preview": "global.foo = 'bar';\n"
  },
  {
    "path": "test/samples/global-in-if-block/main.js",
    "chars": 62,
    "preview": "if (!global.count) {\n\tglobal.count = 0;\n}\n\nglobal.count += 1;\n"
  },
  {
    "path": "test/samples/ignore-global/firstpass.js",
    "chars": 111,
    "preview": "export var immediate = typeof global.setImmediate === 'function' ?\n   global.setImmediate : global.setTimeout;\n"
  },
  {
    "path": "test/samples/ignore-global/identifier.js",
    "chars": 135,
    "preview": "// require (firstpass)\n\nexport var immediate = typeof global.setImmediate === 'function' ?\n   global.setImmediate : glob"
  },
  {
    "path": "test/samples/ignore-global/main.js",
    "chars": 161,
    "preview": "export { immediate as immediate1 } from './firstpass';\nexport { immediate as immediate2 } from './identifier';\nexport { "
  },
  {
    "path": "test/samples/ignore-global/this.js",
    "chars": 225,
    "preview": "// require (firstpass)\n\n// \"this\" will be rewritten with \"undefined\" by rollup\nexport var immediate = typeof this === 'u"
  },
  {
    "path": "test/samples/ignore-virtual-modules/main.js",
    "chars": 39,
    "preview": "module.exports = require('\\0virtual');\n"
  },
  {
    "path": "test/samples/invalid-syntax/main.js",
    "chars": 21,
    "preview": "export const foo = 2,"
  },
  {
    "path": "test/samples/multiple-entry-points/2.js",
    "chars": 71,
    "preview": "function second () {\n\tconsole.log('second');\n}\nexports.second = second;"
  },
  {
    "path": "test/samples/multiple-entry-points/3.js",
    "chars": 69,
    "preview": "function third () {\n\tconsole.log('third');\n}\n\nexports.third = third;\n"
  },
  {
    "path": "test/samples/multiple-entry-points/4.js",
    "chars": 54,
    "preview": "export function fourth () {\n\tconsole.log('fourth');\n}\n"
  },
  {
    "path": "test/samples/multiple-entry-points/b.js",
    "chars": 79,
    "preview": "import { second } from './2';\nimport { third } from './3';\n\nsecond();\nthird();\n"
  },
  {
    "path": "test/samples/multiple-entry-points/c.js",
    "chars": 119,
    "preview": "import { second } from './2';\nimport { third } from './3';\nimport { fourth } from './4';\n\nsecond();\nthird();\nfourth();\n"
  },
  {
    "path": "test/samples/named-exports-from-object-literal/a.js",
    "chars": 20,
    "preview": "module.exports = 1;\n"
  },
  {
    "path": "test/samples/named-exports-from-object-literal/main.js",
    "chars": 105,
    "preview": "import { a, b, c } from './other.js';\n\nassert.equal( a, 1 );\nassert.equal( b, 2 );\nassert.equal( c, 3 );\n"
  },
  {
    "path": "test/samples/named-exports-from-object-literal/other.js",
    "chars": 102,
    "preview": "var a = require( './a.js' );\nvar b = 2;\n\nmodule.exports = {\n  a: a,\n  b: b,\n  c: a + b,\n  2: 1 + 1\n};\n"
  },
  {
    "path": "test/samples/other-transforms/bar.js",
    "chars": 21,
    "preview": "module.exports = 40;\n"
  },
  {
    "path": "test/samples/other-transforms/foo.js",
    "chars": 60,
    "preview": "var bar = require( './bar.js' );\n\nmodule.exports = bar + 1;\n"
  },
  {
    "path": "test/samples/other-transforms/main.js",
    "chars": 54,
    "preview": "import foo from './foo.js';\n\nassert.equal( foo, 42 );\n"
  },
  {
    "path": "test/samples/paren-expression/index.js",
    "chars": 23,
    "preview": "module.exports = (42);\n"
  },
  {
    "path": "test/samples/reexport/export.js",
    "chars": 19,
    "preview": "exports.named = 2;\n"
  },
  {
    "path": "test/samples/reexport/main.js",
    "chars": 64,
    "preview": "import { named } from './reexport.js';\n\nassert.equal(named, 2);\n"
  }
]

// ... and 17 more files (download for full content)

About this extraction

This page contains the full source code of the rollup/rollup-plugin-commonjs GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 217 files (88.7 KB), approximately 31.5k tokens, and a symbol index with 61 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!