Mirror: Rollup plugin to automatically check the exports of a library for cjs-module-lexer compatibility.

Initial Commit

kitten.sh 24410c93

+9
.gitignore
···
+
/.idea
+
/.vscode
+
**/node_modules
+
*.log
+
.rts2_cache*
+
.husky
+
dist/
+
package-lock.json
+
.DS_Store
+21
LICENSE
···
+
MIT License
+
+
Copyright (c) 2022 0no.co
+
+
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.
+59
README.md
···
+
# rollup-plugin-cjs-check
+
+
A Rollup plugin for checking CommonJS exports against `cjs-module-lexer`.
+
+
## Why?
+
+
As Node.js defines it, CommonJS modules consist of a `module.exports` object which can be of any type.
+
When importing a `CommonJS`, while Node.js is in ESM mode, a CommonJS module will always be reliably
+
importable via a default import.
+
+
For modern modules, it's common to use Rollup to bundle and build both CommonJS and ECMAScript Modules (ESM)
+
outputs for any given module. This means that to achieve compatibility between both modules either requires
+
the module to only have a default-export, or to rely on Node.js' compatibility mode.
+
+
For better compatibility, Node.js attempts to detect the CommonJS exports of every CommonJS module that's
+
exported. Since sometimes, especially in legacy CommonJS mode, the import of a given CommonJS module built with
+
Rollup cannot be prevented entirely, the module has to be compatible with `cjs-module-lexer`.
+
+
The [`cjs-module-lexer` library](https://github.com/nodejs/cjs-module-lexer) is what Node.js uses to detect
+
exports of a given CommonJS module and hence, when choosing how to configure Rollup, the Rollup bundle outputs
+
have to be compatible with it, or otherwise, the module's exports won't be detected.
+
+
**This plugin checks that `cjs-module-lexer` agrees with the ECMAScript modules exports that Rollup detects.**
+
+
For more information, check out [the Node.js documentation on CommonJS namespaces.](https://nodejs.org/api/esm.html#commonjs-namespaces)
+
+
## Requirements
+
+
This plugin requires an [LTS](https://github.com/nodejs/Release) Node version (v14.0.0+) and Rollup v1.20.0+.
+
+
## Install
+
+
```console
+
npm install --save-dev rollup-plugin-cjs-check
+
# or
+
yarn add -D rollup-plugin-cjs-check
+
# or
+
pnpm add --save-dev rollup-plugin-cjs-check
+
```
+
+
## Usage
+
+
Import the `rollup-plugin-cjs-check` plugin in your [Rollup configuration file](https://www.rollupjs.org/guide/en/#configuration-files),
+
and add it to your plugins:
+
+
```js
+
import cjsCheck from 'rollup-plugin-cjs-check';
+
+
export default {
+
input: 'src/index.js',
+
output: {
+
dir: 'output',
+
format: 'cjs'
+
},
+
plugins: [
+
cjsCheck(),
+
]
+
};
+
```
+49
package.json
···
+
{
+
"name": "rollup-plugin-cjs-check",
+
"version": "1.0.0",
+
"description": "Rollup plugin to automatically check the exports of a library for cjs-module-lexer compatibility.",
+
"author": "0no.co <hi@0no.co>",
+
"scripts": {
+
"build": "rollup -c rollup.config.mjs",
+
"prepublishOnly": "run-s build"
+
},
+
"source": "./src/index.ts",
+
"main": "./dist/rollup-plugin-cjs-check",
+
"module": "./dist/rollup-plugin-cjs-check.mjs",
+
"types": "./src/index.d.ts",
+
"exports": {
+
".": {
+
"import": "./dist/rollup-plugin-cjs-check.mjs",
+
"require": "./dist/rollup-plugin-cjs-check.js",
+
"types": "./src/index.d.ts",
+
"source": "./src/index.mjs"
+
},
+
"./package.json": "./package.json"
+
},
+
"sideEffects": false,
+
"files": [
+
"src",
+
"dist",
+
"README.md",
+
"LICENSE"
+
],
+
"repository": "https://github.com/0no-co/rollup-plugin-cjs-check",
+
"bugs": {
+
"url": "https://github.com/0no-co/rollup-plugin-cjs-check/issues"
+
},
+
"license": "MIT",
+
"engines": {
+
"node": ">=14.0.0"
+
},
+
"peerDependencies": {
+
"rollup": "^1.20.0 || ^2.0.0 || ^3.0.0"
+
},
+
"dependencies": {
+
"@rollup/pluginutils": "^5.0.2",
+
"cjs-module-lexer": "^1.2.2"
+
},
+
"devDependencies": {
+
"npm-run-all": "^4.1.5",
+
"rollup": "^3.5.1"
+
}
+
}
+620
pnpm-lock.yaml
···
+
lockfileVersion: 5.4
+
+
specifiers:
+
'@rollup/pluginutils': ^5.0.2
+
cjs-module-lexer: ^1.2.2
+
npm-run-all: ^4.1.5
+
rollup: ^3.5.1
+
+
dependencies:
+
'@rollup/pluginutils': 5.0.2_rollup@3.5.1
+
cjs-module-lexer: 1.2.2
+
+
devDependencies:
+
npm-run-all: 4.1.5
+
rollup: 3.5.1
+
+
packages:
+
+
/@rollup/pluginutils/5.0.2_rollup@3.5.1:
+
resolution: {integrity: sha512-pTd9rIsP92h+B6wWwFbW8RkZv4hiR/xKsqre4SIuAOaOEQRxi0lqLke9k2/7WegC85GgUs9pjmOjCUi3In4vwA==}
+
engines: {node: '>=14.0.0'}
+
peerDependencies:
+
rollup: ^1.20.0||^2.0.0||^3.0.0
+
peerDependenciesMeta:
+
rollup:
+
optional: true
+
dependencies:
+
'@types/estree': 1.0.0
+
estree-walker: 2.0.2
+
picomatch: 2.3.1
+
rollup: 3.5.1
+
dev: false
+
+
/@types/estree/1.0.0:
+
resolution: {integrity: sha512-WulqXMDUTYAXCjZnk6JtIHPigp55cVtDgDrO2gHRwhyJto21+1zbVCtOYB2L1F9w4qCQ0rOGWBnBe0FNTiEJIQ==}
+
dev: false
+
+
/ansi-styles/3.2.1:
+
resolution: {integrity: sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==}
+
engines: {node: '>=4'}
+
dependencies:
+
color-convert: 1.9.3
+
dev: true
+
+
/balanced-match/1.0.2:
+
resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==}
+
dev: true
+
+
/brace-expansion/1.1.11:
+
resolution: {integrity: sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==}
+
dependencies:
+
balanced-match: 1.0.2
+
concat-map: 0.0.1
+
dev: true
+
+
/call-bind/1.0.2:
+
resolution: {integrity: sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==}
+
dependencies:
+
function-bind: 1.1.1
+
get-intrinsic: 1.1.3
+
dev: true
+
+
/chalk/2.4.2:
+
resolution: {integrity: sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==}
+
engines: {node: '>=4'}
+
dependencies:
+
ansi-styles: 3.2.1
+
escape-string-regexp: 1.0.5
+
supports-color: 5.5.0
+
dev: true
+
+
/cjs-module-lexer/1.2.2:
+
resolution: {integrity: sha512-cOU9usZw8/dXIXKtwa8pM0OTJQuJkxMN6w30csNRUerHfeQ5R6U3kkU/FtJeIf3M202OHfY2U8ccInBG7/xogA==}
+
dev: false
+
+
/color-convert/1.9.3:
+
resolution: {integrity: sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==}
+
dependencies:
+
color-name: 1.1.3
+
dev: true
+
+
/color-name/1.1.3:
+
resolution: {integrity: sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==}
+
dev: true
+
+
/concat-map/0.0.1:
+
resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==}
+
dev: true
+
+
/cross-spawn/6.0.5:
+
resolution: {integrity: sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==}
+
engines: {node: '>=4.8'}
+
dependencies:
+
nice-try: 1.0.5
+
path-key: 2.0.1
+
semver: 5.7.1
+
shebang-command: 1.2.0
+
which: 1.3.1
+
dev: true
+
+
/define-properties/1.1.4:
+
resolution: {integrity: sha512-uckOqKcfaVvtBdsVkdPv3XjveQJsNQqmhXgRi8uhvWWuPYZCNlzT8qAyblUgNoXdHdjMTzAqeGjAoli8f+bzPA==}
+
engines: {node: '>= 0.4'}
+
dependencies:
+
has-property-descriptors: 1.0.0
+
object-keys: 1.1.1
+
dev: true
+
+
/error-ex/1.3.2:
+
resolution: {integrity: sha512-7dFHNmqeFSEt2ZBsCriorKnn3Z2pj+fd9kmI6QoWw4//DL+icEBfc0U7qJCisqrTsKTjw4fNFy2pW9OqStD84g==}
+
dependencies:
+
is-arrayish: 0.2.1
+
dev: true
+
+
/es-abstract/1.20.4:
+
resolution: {integrity: sha512-0UtvRN79eMe2L+UNEF1BwRe364sj/DXhQ/k5FmivgoSdpM90b8Jc0mDzKMGo7QS0BVbOP/bTwBKNnDc9rNzaPA==}
+
engines: {node: '>= 0.4'}
+
dependencies:
+
call-bind: 1.0.2
+
es-to-primitive: 1.2.1
+
function-bind: 1.1.1
+
function.prototype.name: 1.1.5
+
get-intrinsic: 1.1.3
+
get-symbol-description: 1.0.0
+
has: 1.0.3
+
has-property-descriptors: 1.0.0
+
has-symbols: 1.0.3
+
internal-slot: 1.0.3
+
is-callable: 1.2.7
+
is-negative-zero: 2.0.2
+
is-regex: 1.1.4
+
is-shared-array-buffer: 1.0.2
+
is-string: 1.0.7
+
is-weakref: 1.0.2
+
object-inspect: 1.12.2
+
object-keys: 1.1.1
+
object.assign: 4.1.4
+
regexp.prototype.flags: 1.4.3
+
safe-regex-test: 1.0.0
+
string.prototype.trimend: 1.0.6
+
string.prototype.trimstart: 1.0.6
+
unbox-primitive: 1.0.2
+
dev: true
+
+
/es-to-primitive/1.2.1:
+
resolution: {integrity: sha512-QCOllgZJtaUo9miYBcLChTUaHNjJF3PYs1VidD7AwiEj1kYxKeQTctLAezAOH5ZKRH0g2IgPn6KwB4IT8iRpvA==}
+
engines: {node: '>= 0.4'}
+
dependencies:
+
is-callable: 1.2.7
+
is-date-object: 1.0.5
+
is-symbol: 1.0.4
+
dev: true
+
+
/escape-string-regexp/1.0.5:
+
resolution: {integrity: sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==}
+
engines: {node: '>=0.8.0'}
+
dev: true
+
+
/estree-walker/2.0.2:
+
resolution: {integrity: sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==}
+
dev: false
+
+
/fsevents/2.3.2:
+
resolution: {integrity: sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==}
+
engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0}
+
os: [darwin]
+
requiresBuild: true
+
optional: true
+
+
/function-bind/1.1.1:
+
resolution: {integrity: sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==}
+
dev: true
+
+
/function.prototype.name/1.1.5:
+
resolution: {integrity: sha512-uN7m/BzVKQnCUF/iW8jYea67v++2u7m5UgENbHRtdDVclOUP+FMPlCNdmk0h/ysGyo2tavMJEDqJAkJdRa1vMA==}
+
engines: {node: '>= 0.4'}
+
dependencies:
+
call-bind: 1.0.2
+
define-properties: 1.1.4
+
es-abstract: 1.20.4
+
functions-have-names: 1.2.3
+
dev: true
+
+
/functions-have-names/1.2.3:
+
resolution: {integrity: sha512-xckBUXyTIqT97tq2x2AMb+g163b5JFysYk0x4qxNFwbfQkmNZoiRHb6sPzI9/QV33WeuvVYBUIiD4NzNIyqaRQ==}
+
dev: true
+
+
/get-intrinsic/1.1.3:
+
resolution: {integrity: sha512-QJVz1Tj7MS099PevUG5jvnt9tSkXN8K14dxQlikJuPt4uD9hHAHjLyLBiLR5zELelBdD9QNRAXZzsJx0WaDL9A==}
+
dependencies:
+
function-bind: 1.1.1
+
has: 1.0.3
+
has-symbols: 1.0.3
+
dev: true
+
+
/get-symbol-description/1.0.0:
+
resolution: {integrity: sha512-2EmdH1YvIQiZpltCNgkuiUnyukzxM/R6NDJX31Ke3BG1Nq5b0S2PhX59UKi9vZpPDQVdqn+1IcaAwnzTT5vCjw==}
+
engines: {node: '>= 0.4'}
+
dependencies:
+
call-bind: 1.0.2
+
get-intrinsic: 1.1.3
+
dev: true
+
+
/graceful-fs/4.2.10:
+
resolution: {integrity: sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA==}
+
dev: true
+
+
/has-bigints/1.0.2:
+
resolution: {integrity: sha512-tSvCKtBr9lkF0Ex0aQiP9N+OpV4zi2r/Nee5VkRDbaqv35RLYMzbwQfFSZZH0kR+Rd6302UJZ2p/bJCEoR3VoQ==}
+
dev: true
+
+
/has-flag/3.0.0:
+
resolution: {integrity: sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==}
+
engines: {node: '>=4'}
+
dev: true
+
+
/has-property-descriptors/1.0.0:
+
resolution: {integrity: sha512-62DVLZGoiEBDHQyqG4w9xCuZ7eJEwNmJRWw2VY84Oedb7WFcA27fiEVe8oUQx9hAUJ4ekurquucTGwsyO1XGdQ==}
+
dependencies:
+
get-intrinsic: 1.1.3
+
dev: true
+
+
/has-symbols/1.0.3:
+
resolution: {integrity: sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==}
+
engines: {node: '>= 0.4'}
+
dev: true
+
+
/has-tostringtag/1.0.0:
+
resolution: {integrity: sha512-kFjcSNhnlGV1kyoGk7OXKSawH5JOb/LzUc5w9B02hOTO0dfFRjbHQKvg1d6cf3HbeUmtU9VbbV3qzZ2Teh97WQ==}
+
engines: {node: '>= 0.4'}
+
dependencies:
+
has-symbols: 1.0.3
+
dev: true
+
+
/has/1.0.3:
+
resolution: {integrity: sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==}
+
engines: {node: '>= 0.4.0'}
+
dependencies:
+
function-bind: 1.1.1
+
dev: true
+
+
/hosted-git-info/2.8.9:
+
resolution: {integrity: sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw==}
+
dev: true
+
+
/internal-slot/1.0.3:
+
resolution: {integrity: sha512-O0DB1JC/sPyZl7cIo78n5dR7eUSwwpYPiXRhTzNxZVAMUuB8vlnRFyLxdrVToks6XPLVnFfbzaVd5WLjhgg+vA==}
+
engines: {node: '>= 0.4'}
+
dependencies:
+
get-intrinsic: 1.1.3
+
has: 1.0.3
+
side-channel: 1.0.4
+
dev: true
+
+
/is-arrayish/0.2.1:
+
resolution: {integrity: sha512-zz06S8t0ozoDXMG+ube26zeCTNXcKIPJZJi8hBrF4idCLms4CG9QtK7qBl1boi5ODzFpjswb5JPmHCbMpjaYzg==}
+
dev: true
+
+
/is-bigint/1.0.4:
+
resolution: {integrity: sha512-zB9CruMamjym81i2JZ3UMn54PKGsQzsJeo6xvN3HJJ4CAsQNB6iRutp2To77OfCNuoxspsIhzaPoO1zyCEhFOg==}
+
dependencies:
+
has-bigints: 1.0.2
+
dev: true
+
+
/is-boolean-object/1.1.2:
+
resolution: {integrity: sha512-gDYaKHJmnj4aWxyj6YHyXVpdQawtVLHU5cb+eztPGczf6cjuTdwve5ZIEfgXqH4e57An1D1AKf8CZ3kYrQRqYA==}
+
engines: {node: '>= 0.4'}
+
dependencies:
+
call-bind: 1.0.2
+
has-tostringtag: 1.0.0
+
dev: true
+
+
/is-callable/1.2.7:
+
resolution: {integrity: sha512-1BC0BVFhS/p0qtw6enp8e+8OD0UrK0oFLztSjNzhcKA3WDuJxxAPXzPuPtKkjEY9UUoEWlX/8fgKeu2S8i9JTA==}
+
engines: {node: '>= 0.4'}
+
dev: true
+
+
/is-core-module/2.11.0:
+
resolution: {integrity: sha512-RRjxlvLDkD1YJwDbroBHMb+cukurkDWNyHx7D3oNB5x9rb5ogcksMC5wHCadcXoo67gVr/+3GFySh3134zi6rw==}
+
dependencies:
+
has: 1.0.3
+
dev: true
+
+
/is-date-object/1.0.5:
+
resolution: {integrity: sha512-9YQaSxsAiSwcvS33MBk3wTCVnWK+HhF8VZR2jRxehM16QcVOdHqPn4VPHmRK4lSr38n9JriurInLcP90xsYNfQ==}
+
engines: {node: '>= 0.4'}
+
dependencies:
+
has-tostringtag: 1.0.0
+
dev: true
+
+
/is-negative-zero/2.0.2:
+
resolution: {integrity: sha512-dqJvarLawXsFbNDeJW7zAz8ItJ9cd28YufuuFzh0G8pNHjJMnY08Dv7sYX2uF5UpQOwieAeOExEYAWWfu7ZZUA==}
+
engines: {node: '>= 0.4'}
+
dev: true
+
+
/is-number-object/1.0.7:
+
resolution: {integrity: sha512-k1U0IRzLMo7ZlYIfzRu23Oh6MiIFasgpb9X76eqfFZAqwH44UI4KTBvBYIZ1dSL9ZzChTB9ShHfLkR4pdW5krQ==}
+
engines: {node: '>= 0.4'}
+
dependencies:
+
has-tostringtag: 1.0.0
+
dev: true
+
+
/is-regex/1.1.4:
+
resolution: {integrity: sha512-kvRdxDsxZjhzUX07ZnLydzS1TU/TJlTUHHY4YLL87e37oUA49DfkLqgy+VjFocowy29cKvcSiu+kIv728jTTVg==}
+
engines: {node: '>= 0.4'}
+
dependencies:
+
call-bind: 1.0.2
+
has-tostringtag: 1.0.0
+
dev: true
+
+
/is-shared-array-buffer/1.0.2:
+
resolution: {integrity: sha512-sqN2UDu1/0y6uvXyStCOzyhAjCSlHceFoMKJW8W9EU9cvic/QdsZ0kEU93HEy3IUEFZIiH/3w+AH/UQbPHNdhA==}
+
dependencies:
+
call-bind: 1.0.2
+
dev: true
+
+
/is-string/1.0.7:
+
resolution: {integrity: sha512-tE2UXzivje6ofPW7l23cjDOMa09gb7xlAqG6jG5ej6uPV32TlWP3NKPigtaGeHNu9fohccRYvIiZMfOOnOYUtg==}
+
engines: {node: '>= 0.4'}
+
dependencies:
+
has-tostringtag: 1.0.0
+
dev: true
+
+
/is-symbol/1.0.4:
+
resolution: {integrity: sha512-C/CPBqKWnvdcxqIARxyOh4v1UUEOCHpgDa0WYgpKDFMszcrPcffg5uhwSgPCLD2WWxmq6isisz87tzT01tuGhg==}
+
engines: {node: '>= 0.4'}
+
dependencies:
+
has-symbols: 1.0.3
+
dev: true
+
+
/is-weakref/1.0.2:
+
resolution: {integrity: sha512-qctsuLZmIQ0+vSSMfoVvyFe2+GSEvnmZ2ezTup1SBse9+twCCeial6EEi3Nc2KFcf6+qz2FBPnjXsk8xhKSaPQ==}
+
dependencies:
+
call-bind: 1.0.2
+
dev: true
+
+
/isexe/2.0.0:
+
resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==}
+
dev: true
+
+
/json-parse-better-errors/1.0.2:
+
resolution: {integrity: sha512-mrqyZKfX5EhL7hvqcV6WG1yYjnjeuYDzDhhcAAUrq8Po85NBQBJP+ZDUT75qZQ98IkUoBqdkExkukOU7Ts2wrw==}
+
dev: true
+
+
/load-json-file/4.0.0:
+
resolution: {integrity: sha512-Kx8hMakjX03tiGTLAIdJ+lL0htKnXjEZN6hk/tozf/WOuYGdZBJrZ+rCJRbVCugsjB3jMLn9746NsQIf5VjBMw==}
+
engines: {node: '>=4'}
+
dependencies:
+
graceful-fs: 4.2.10
+
parse-json: 4.0.0
+
pify: 3.0.0
+
strip-bom: 3.0.0
+
dev: true
+
+
/memorystream/0.3.1:
+
resolution: {integrity: sha512-S3UwM3yj5mtUSEfP41UZmt/0SCoVYUcU1rkXv+BQ5Ig8ndL4sPoJNBUJERafdPb5jjHJGuMgytgKvKIf58XNBw==}
+
engines: {node: '>= 0.10.0'}
+
dev: true
+
+
/minimatch/3.1.2:
+
resolution: {integrity: sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==}
+
dependencies:
+
brace-expansion: 1.1.11
+
dev: true
+
+
/nice-try/1.0.5:
+
resolution: {integrity: sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==}
+
dev: true
+
+
/normalize-package-data/2.5.0:
+
resolution: {integrity: sha512-/5CMN3T0R4XTj4DcGaexo+roZSdSFW/0AOOTROrjxzCG1wrWXEsGbRKevjlIL+ZDE4sZlJr5ED4YW0yqmkK+eA==}
+
dependencies:
+
hosted-git-info: 2.8.9
+
resolve: 1.22.1
+
semver: 5.7.1
+
validate-npm-package-license: 3.0.4
+
dev: true
+
+
/npm-run-all/4.1.5:
+
resolution: {integrity: sha512-Oo82gJDAVcaMdi3nuoKFavkIHBRVqQ1qvMb+9LHk/cF4P6B2m8aP04hGf7oL6wZ9BuGwX1onlLhpuoofSyoQDQ==}
+
engines: {node: '>= 4'}
+
hasBin: true
+
dependencies:
+
ansi-styles: 3.2.1
+
chalk: 2.4.2
+
cross-spawn: 6.0.5
+
memorystream: 0.3.1
+
minimatch: 3.1.2
+
pidtree: 0.3.1
+
read-pkg: 3.0.0
+
shell-quote: 1.7.4
+
string.prototype.padend: 3.1.4
+
dev: true
+
+
/object-inspect/1.12.2:
+
resolution: {integrity: sha512-z+cPxW0QGUp0mcqcsgQyLVRDoXFQbXOwBaqyF7VIgI4TWNQsDHrBpUQslRmIfAoYWdYzs6UlKJtB2XJpTaNSpQ==}
+
dev: true
+
+
/object-keys/1.1.1:
+
resolution: {integrity: sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==}
+
engines: {node: '>= 0.4'}
+
dev: true
+
+
/object.assign/4.1.4:
+
resolution: {integrity: sha512-1mxKf0e58bvyjSCtKYY4sRe9itRk3PJpquJOjeIkz885CczcI4IvJJDLPS72oowuSh+pBxUFROpX+TU++hxhZQ==}
+
engines: {node: '>= 0.4'}
+
dependencies:
+
call-bind: 1.0.2
+
define-properties: 1.1.4
+
has-symbols: 1.0.3
+
object-keys: 1.1.1
+
dev: true
+
+
/parse-json/4.0.0:
+
resolution: {integrity: sha512-aOIos8bujGN93/8Ox/jPLh7RwVnPEysynVFE+fQZyg6jKELEHwzgKdLRFHUgXJL6kylijVSBC4BvN9OmsB48Rw==}
+
engines: {node: '>=4'}
+
dependencies:
+
error-ex: 1.3.2
+
json-parse-better-errors: 1.0.2
+
dev: true
+
+
/path-key/2.0.1:
+
resolution: {integrity: sha512-fEHGKCSmUSDPv4uoj8AlD+joPlq3peND+HRYyxFz4KPw4z926S/b8rIuFs2FYJg3BwsxJf6A9/3eIdLaYC+9Dw==}
+
engines: {node: '>=4'}
+
dev: true
+
+
/path-parse/1.0.7:
+
resolution: {integrity: sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==}
+
dev: true
+
+
/path-type/3.0.0:
+
resolution: {integrity: sha512-T2ZUsdZFHgA3u4e5PfPbjd7HDDpxPnQb5jN0SrDsjNSuVXHJqtwTnWqG0B1jZrgmJ/7lj1EmVIByWt1gxGkWvg==}
+
engines: {node: '>=4'}
+
dependencies:
+
pify: 3.0.0
+
dev: true
+
+
/picomatch/2.3.1:
+
resolution: {integrity: sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==}
+
engines: {node: '>=8.6'}
+
dev: false
+
+
/pidtree/0.3.1:
+
resolution: {integrity: sha512-qQbW94hLHEqCg7nhby4yRC7G2+jYHY4Rguc2bjw7Uug4GIJuu1tvf2uHaZv5Q8zdt+WKJ6qK1FOI6amaWUo5FA==}
+
engines: {node: '>=0.10'}
+
hasBin: true
+
dev: true
+
+
/pify/3.0.0:
+
resolution: {integrity: sha512-C3FsVNH1udSEX48gGX1xfvwTWfsYWj5U+8/uK15BGzIGrKoUpghX8hWZwa/OFnakBiiVNmBvemTJR5mcy7iPcg==}
+
engines: {node: '>=4'}
+
dev: true
+
+
/read-pkg/3.0.0:
+
resolution: {integrity: sha512-BLq/cCO9two+lBgiTYNqD6GdtK8s4NpaWrl6/rCO9w0TUS8oJl7cmToOZfRYllKTISY6nt1U7jQ53brmKqY6BA==}
+
engines: {node: '>=4'}
+
dependencies:
+
load-json-file: 4.0.0
+
normalize-package-data: 2.5.0
+
path-type: 3.0.0
+
dev: true
+
+
/regexp.prototype.flags/1.4.3:
+
resolution: {integrity: sha512-fjggEOO3slI6Wvgjwflkc4NFRCTZAu5CnNfBd5qOMYhWdn67nJBBu34/TkD++eeFmd8C9r9jfXJ27+nSiRkSUA==}
+
engines: {node: '>= 0.4'}
+
dependencies:
+
call-bind: 1.0.2
+
define-properties: 1.1.4
+
functions-have-names: 1.2.3
+
dev: true
+
+
/resolve/1.22.1:
+
resolution: {integrity: sha512-nBpuuYuY5jFsli/JIs1oldw6fOQCBioohqWZg/2hiaOybXOft4lonv85uDOKXdf8rhyK159cxU5cDcK/NKk8zw==}
+
hasBin: true
+
dependencies:
+
is-core-module: 2.11.0
+
path-parse: 1.0.7
+
supports-preserve-symlinks-flag: 1.0.0
+
dev: true
+
+
/rollup/3.5.1:
+
resolution: {integrity: sha512-hdQWTvPeiAbM6SUkxV70HdGUVxsgsc+CLy5fuh4KdgUBJ0SowXiix8gANgXoG3wEuLwfoJhCT2V+WwxfWq9Ikw==}
+
engines: {node: '>=14.18.0', npm: '>=8.0.0'}
+
hasBin: true
+
optionalDependencies:
+
fsevents: 2.3.2
+
+
/safe-regex-test/1.0.0:
+
resolution: {integrity: sha512-JBUUzyOgEwXQY1NuPtvcj/qcBDbDmEvWufhlnXZIm75DEHp+afM1r1ujJpJsV/gSM4t59tpDyPi1sd6ZaPFfsA==}
+
dependencies:
+
call-bind: 1.0.2
+
get-intrinsic: 1.1.3
+
is-regex: 1.1.4
+
dev: true
+
+
/semver/5.7.1:
+
resolution: {integrity: sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==}
+
hasBin: true
+
dev: true
+
+
/shebang-command/1.2.0:
+
resolution: {integrity: sha512-EV3L1+UQWGor21OmnvojK36mhg+TyIKDh3iFBKBohr5xeXIhNBcx8oWdgkTEEQ+BEFFYdLRuqMfd5L84N1V5Vg==}
+
engines: {node: '>=0.10.0'}
+
dependencies:
+
shebang-regex: 1.0.0
+
dev: true
+
+
/shebang-regex/1.0.0:
+
resolution: {integrity: sha512-wpoSFAxys6b2a2wHZ1XpDSgD7N9iVjg29Ph9uV/uaP9Ex/KXlkTZTeddxDPSYQpgvzKLGJke2UU0AzoGCjNIvQ==}
+
engines: {node: '>=0.10.0'}
+
dev: true
+
+
/shell-quote/1.7.4:
+
resolution: {integrity: sha512-8o/QEhSSRb1a5i7TFR0iM4G16Z0vYB2OQVs4G3aAFXjn3T6yEx8AZxy1PgDF7I00LZHYA3WxaSYIf5e5sAX8Rw==}
+
dev: true
+
+
/side-channel/1.0.4:
+
resolution: {integrity: sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==}
+
dependencies:
+
call-bind: 1.0.2
+
get-intrinsic: 1.1.3
+
object-inspect: 1.12.2
+
dev: true
+
+
/spdx-correct/3.1.1:
+
resolution: {integrity: sha512-cOYcUWwhCuHCXi49RhFRCyJEK3iPj1Ziz9DpViV3tbZOwXD49QzIN3MpOLJNxh2qwq2lJJZaKMVw9qNi4jTC0w==}
+
dependencies:
+
spdx-expression-parse: 3.0.1
+
spdx-license-ids: 3.0.12
+
dev: true
+
+
/spdx-exceptions/2.3.0:
+
resolution: {integrity: sha512-/tTrYOC7PPI1nUAgx34hUpqXuyJG+DTHJTnIULG4rDygi4xu/tfgmq1e1cIRwRzwZgo4NLySi+ricLkZkw4i5A==}
+
dev: true
+
+
/spdx-expression-parse/3.0.1:
+
resolution: {integrity: sha512-cbqHunsQWnJNE6KhVSMsMeH5H/L9EpymbzqTQ3uLwNCLZ1Q481oWaofqH7nO6V07xlXwY6PhQdQ2IedWx/ZK4Q==}
+
dependencies:
+
spdx-exceptions: 2.3.0
+
spdx-license-ids: 3.0.12
+
dev: true
+
+
/spdx-license-ids/3.0.12:
+
resolution: {integrity: sha512-rr+VVSXtRhO4OHbXUiAF7xW3Bo9DuuF6C5jH+q/x15j2jniycgKbxU09Hr0WqlSLUs4i4ltHGXqTe7VHclYWyA==}
+
dev: true
+
+
/string.prototype.padend/3.1.4:
+
resolution: {integrity: sha512-67otBXoksdjsnXXRUq+KMVTdlVRZ2af422Y0aTyTjVaoQkGr3mxl2Bc5emi7dOQ3OGVVQQskmLEWwFXwommpNw==}
+
engines: {node: '>= 0.4'}
+
dependencies:
+
call-bind: 1.0.2
+
define-properties: 1.1.4
+
es-abstract: 1.20.4
+
dev: true
+
+
/string.prototype.trimend/1.0.6:
+
resolution: {integrity: sha512-JySq+4mrPf9EsDBEDYMOb/lM7XQLulwg5R/m1r0PXEFqrV0qHvl58sdTilSXtKOflCsK2E8jxf+GKC0T07RWwQ==}
+
dependencies:
+
call-bind: 1.0.2
+
define-properties: 1.1.4
+
es-abstract: 1.20.4
+
dev: true
+
+
/string.prototype.trimstart/1.0.6:
+
resolution: {integrity: sha512-omqjMDaY92pbn5HOX7f9IccLA+U1tA9GvtU4JrodiXFfYB7jPzzHpRzpglLAjtUV6bB557zwClJezTqnAiYnQA==}
+
dependencies:
+
call-bind: 1.0.2
+
define-properties: 1.1.4
+
es-abstract: 1.20.4
+
dev: true
+
+
/strip-bom/3.0.0:
+
resolution: {integrity: sha512-vavAMRXOgBVNF6nyEEmL3DBK19iRpDcoIwW+swQ+CbGiu7lju6t+JklA1MHweoWtadgt4ISVUsXLyDq34ddcwA==}
+
engines: {node: '>=4'}
+
dev: true
+
+
/supports-color/5.5.0:
+
resolution: {integrity: sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==}
+
engines: {node: '>=4'}
+
dependencies:
+
has-flag: 3.0.0
+
dev: true
+
+
/supports-preserve-symlinks-flag/1.0.0:
+
resolution: {integrity: sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==}
+
engines: {node: '>= 0.4'}
+
dev: true
+
+
/unbox-primitive/1.0.2:
+
resolution: {integrity: sha512-61pPlCD9h51VoreyJ0BReideM3MDKMKnh6+V9L08331ipq6Q8OFXZYiqP6n/tbHx4s5I9uRhcye6BrbkizkBDw==}
+
dependencies:
+
call-bind: 1.0.2
+
has-bigints: 1.0.2
+
has-symbols: 1.0.3
+
which-boxed-primitive: 1.0.2
+
dev: true
+
+
/validate-npm-package-license/3.0.4:
+
resolution: {integrity: sha512-DpKm2Ui/xN7/HQKCtpZxoRWBhZ9Z0kqtygG8XCgNQ8ZlDnxuQmWhj566j8fN4Cu3/JmbhsDo7fcAJq4s9h27Ew==}
+
dependencies:
+
spdx-correct: 3.1.1
+
spdx-expression-parse: 3.0.1
+
dev: true
+
+
/which-boxed-primitive/1.0.2:
+
resolution: {integrity: sha512-bwZdv0AKLpplFY2KZRX6TvyuN7ojjr7lwkg6ml0roIy9YeuSr7JS372qlNW18UQYzgYK9ziGcerWqZOmEn9VNg==}
+
dependencies:
+
is-bigint: 1.0.4
+
is-boolean-object: 1.1.2
+
is-number-object: 1.0.7
+
is-string: 1.0.7
+
is-symbol: 1.0.4
+
dev: true
+
+
/which/1.3.1:
+
resolution: {integrity: sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==}
+
hasBin: true
+
dependencies:
+
isexe: 2.0.0
+
dev: true
+53
rollup.config.mjs
···
+
import { builtinModules } from 'module';
+
import { readFileSync } from 'fs';
+
+
import cjsCheck from './src/index.mjs';
+
+
const pkg = JSON.parse(readFileSync('./package.json', 'utf-8'));
+
+
const output = format => {
+
const extension = format === 'esm' ? '.mjs' : '.js';
+
return {
+
chunkFileNames: '[hash]' + extension,
+
entryFileNames: '[name]' + extension,
+
dir: './dist',
+
exports: 'named',
+
sourcemap: true,
+
indent: false,
+
freeze: false,
+
strict: false,
+
format,
+
esModule: format !== 'esm',
+
externalLiveBindings: format !== 'esm',
+
generatedCode: {
+
preset: 'es5',
+
reservedNamesAsProps: false,
+
objectShorthand: false,
+
constBindings: false,
+
},
+
};
+
};
+
+
export default {
+
input: {
+
'rollup-plugin-cjs-check': './src/index.mjs',
+
},
+
external: [
+
...builtinModules,
+
...Object.keys(pkg.dependencies || {}),
+
...Object.keys(pkg.peerDependencies || {}),
+
],
+
onwarn() {},
+
plugins: [
+
cjsCheck(),
+
],
+
treeshake: {
+
unknownGlobalSideEffects: false,
+
tryCatchDeoptimization: false,
+
moduleSideEffects: false,
+
},
+
output: [
+
output('esm'),
+
output('cjs')
+
],
+
};
+26
src/index.d.ts
···
+
import { Plugin } from 'rollup';
+
import { FilterPattern } from '@rollup/pluginutils';
+
+
export interface CJSCheckOptions {
+
/**
+
* A picomatch pattern, or array of patterns, which specifies the files in
+
* the build the plugin should operate on. By default, all files with
+
* extension `".cjs"` or those in `extensions` are included, but you can
+
* narrow this list by only including specific files. These files will be
+
* analyzed and transpiled if either the analysis does not find ES module
+
* specific statements or `transformMixedEsModules` is `true`.
+
* @default undefined
+
*/
+
include?: FilterPattern;
+
/**
+
* A picomatch pattern, or array of patterns, which specifies the files in
+
* the build the plugin should _ignore_. By default, all files with
+
* extensions other than those in `extensions` or `".cjs"` are ignored, but you
+
* can exclude additional files. See also the `include` option.
+
* @default undefined
+
*/
+
exclude?: FilterPattern;
+
}
+
+
/** A Rollup plugin for checking CommonJS exports against `cjs-module-lexer`. */
+
export default function cjsCheck(options?: CJSCheckOptions): Plugin;
+61
src/index.mjs
···
+
import { parse, init } from 'cjs-module-lexer';
+
import { createFilter } from '@rollup/pluginutils';
+
+
function cjsCheck(opts = {}) {
+
const filter = createFilter(opts.include, opts.exclude, {
+
resolve: false
+
});
+
+
return {
+
name: "cjs-check",
+
+
async renderChunk(code, chunk) {
+
if (opts.extension !== '.js') {
+
return null;
+
} else if (!filter(chunk.fileName)) {
+
return null;
+
}
+
+
await init()
+
const output = parse(code);
+
const missingReexports = [];
+
const missingExports = [];
+
+
let hasMissing = false;
+
for (const mod of chunk.exports) {
+
if (mod[0] == '*' && !output.reexports.includes(mod.slice(1))) {
+
hasMissing = true;
+
missingReexports.push(mod.slice(1));
+
} else if (mod[0] != '*' && !output.exports.includes(mod)) {
+
hasMissing = true;
+
missingExports.push(mod);
+
}
+
}
+
+
if (hasMissing) {
+
let message = '';
+
if (missingReexports.length) {
+
message += 'The following re-exports are undetected:\n';
+
message += missingReexports.map(x => `- ${x}\n`).join('');
+
}
+
+
if (missingExports.length) {
+
message += 'The following exports are undetected:\n';
+
message += missingExports.map(x => `- ${x}\n`).join('');
+
}
+
+
if (missingExports.length + missingReexports.length >= chunk.exports.length) {
+
message = 'All chunk exports have not been detected. Is the chunk a CommonJS module?'
+
}
+
+
throw new Error(
+
`cjs-module-lexer did not agree with Rollup\'s exports for ${chunk.fileName}.\n${message}`
+
);
+
}
+
+
return null;
+
}
+
};
+
}
+
+
export default cjsCheck;