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

Configure Feed

Select the types of activity you want to include in your feed.

Initial Commit

kitten.sh 24410c93

+898
+9
.gitignore
··· 1 + /.idea 2 + /.vscode 3 + **/node_modules 4 + *.log 5 + .rts2_cache* 6 + .husky 7 + dist/ 8 + package-lock.json 9 + .DS_Store
+21
LICENSE
··· 1 + MIT License 2 + 3 + Copyright (c) 2022 0no.co 4 + 5 + Permission is hereby granted, free of charge, to any person obtaining a copy 6 + of this software and associated documentation files (the "Software"), to deal 7 + in the Software without restriction, including without limitation the rights 8 + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 + copies of the Software, and to permit persons to whom the Software is 10 + furnished to do so, subject to the following conditions: 11 + 12 + The above copyright notice and this permission notice shall be included in all 13 + copies or substantial portions of the Software. 14 + 15 + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 + SOFTWARE.
+59
README.md
··· 1 + # rollup-plugin-cjs-check 2 + 3 + A Rollup plugin for checking CommonJS exports against `cjs-module-lexer`. 4 + 5 + ## Why? 6 + 7 + As Node.js defines it, CommonJS modules consist of a `module.exports` object which can be of any type. 8 + When importing a `CommonJS`, while Node.js is in ESM mode, a CommonJS module will always be reliably 9 + importable via a default import. 10 + 11 + For modern modules, it's common to use Rollup to bundle and build both CommonJS and ECMAScript Modules (ESM) 12 + outputs for any given module. This means that to achieve compatibility between both modules either requires 13 + the module to only have a default-export, or to rely on Node.js' compatibility mode. 14 + 15 + For better compatibility, Node.js attempts to detect the CommonJS exports of every CommonJS module that's 16 + exported. Since sometimes, especially in legacy CommonJS mode, the import of a given CommonJS module built with 17 + Rollup cannot be prevented entirely, the module has to be compatible with `cjs-module-lexer`. 18 + 19 + The [`cjs-module-lexer` library](https://github.com/nodejs/cjs-module-lexer) is what Node.js uses to detect 20 + exports of a given CommonJS module and hence, when choosing how to configure Rollup, the Rollup bundle outputs 21 + have to be compatible with it, or otherwise, the module's exports won't be detected. 22 + 23 + **This plugin checks that `cjs-module-lexer` agrees with the ECMAScript modules exports that Rollup detects.** 24 + 25 + For more information, check out [the Node.js documentation on CommonJS namespaces.](https://nodejs.org/api/esm.html#commonjs-namespaces) 26 + 27 + ## Requirements 28 + 29 + This plugin requires an [LTS](https://github.com/nodejs/Release) Node version (v14.0.0+) and Rollup v1.20.0+. 30 + 31 + ## Install 32 + 33 + ```console 34 + npm install --save-dev rollup-plugin-cjs-check 35 + # or 36 + yarn add -D rollup-plugin-cjs-check 37 + # or 38 + pnpm add --save-dev rollup-plugin-cjs-check 39 + ``` 40 + 41 + ## Usage 42 + 43 + Import the `rollup-plugin-cjs-check` plugin in your [Rollup configuration file](https://www.rollupjs.org/guide/en/#configuration-files), 44 + and add it to your plugins: 45 + 46 + ```js 47 + import cjsCheck from 'rollup-plugin-cjs-check'; 48 + 49 + export default { 50 + input: 'src/index.js', 51 + output: { 52 + dir: 'output', 53 + format: 'cjs' 54 + }, 55 + plugins: [ 56 + cjsCheck(), 57 + ] 58 + }; 59 + ```
+49
package.json
··· 1 + { 2 + "name": "rollup-plugin-cjs-check", 3 + "version": "1.0.0", 4 + "description": "Rollup plugin to automatically check the exports of a library for cjs-module-lexer compatibility.", 5 + "author": "0no.co <hi@0no.co>", 6 + "scripts": { 7 + "build": "rollup -c rollup.config.mjs", 8 + "prepublishOnly": "run-s build" 9 + }, 10 + "source": "./src/index.ts", 11 + "main": "./dist/rollup-plugin-cjs-check", 12 + "module": "./dist/rollup-plugin-cjs-check.mjs", 13 + "types": "./src/index.d.ts", 14 + "exports": { 15 + ".": { 16 + "import": "./dist/rollup-plugin-cjs-check.mjs", 17 + "require": "./dist/rollup-plugin-cjs-check.js", 18 + "types": "./src/index.d.ts", 19 + "source": "./src/index.mjs" 20 + }, 21 + "./package.json": "./package.json" 22 + }, 23 + "sideEffects": false, 24 + "files": [ 25 + "src", 26 + "dist", 27 + "README.md", 28 + "LICENSE" 29 + ], 30 + "repository": "https://github.com/0no-co/rollup-plugin-cjs-check", 31 + "bugs": { 32 + "url": "https://github.com/0no-co/rollup-plugin-cjs-check/issues" 33 + }, 34 + "license": "MIT", 35 + "engines": { 36 + "node": ">=14.0.0" 37 + }, 38 + "peerDependencies": { 39 + "rollup": "^1.20.0 || ^2.0.0 || ^3.0.0" 40 + }, 41 + "dependencies": { 42 + "@rollup/pluginutils": "^5.0.2", 43 + "cjs-module-lexer": "^1.2.2" 44 + }, 45 + "devDependencies": { 46 + "npm-run-all": "^4.1.5", 47 + "rollup": "^3.5.1" 48 + } 49 + }
+620
pnpm-lock.yaml
··· 1 + lockfileVersion: 5.4 2 + 3 + specifiers: 4 + '@rollup/pluginutils': ^5.0.2 5 + cjs-module-lexer: ^1.2.2 6 + npm-run-all: ^4.1.5 7 + rollup: ^3.5.1 8 + 9 + dependencies: 10 + '@rollup/pluginutils': 5.0.2_rollup@3.5.1 11 + cjs-module-lexer: 1.2.2 12 + 13 + devDependencies: 14 + npm-run-all: 4.1.5 15 + rollup: 3.5.1 16 + 17 + packages: 18 + 19 + /@rollup/pluginutils/5.0.2_rollup@3.5.1: 20 + resolution: {integrity: sha512-pTd9rIsP92h+B6wWwFbW8RkZv4hiR/xKsqre4SIuAOaOEQRxi0lqLke9k2/7WegC85GgUs9pjmOjCUi3In4vwA==} 21 + engines: {node: '>=14.0.0'} 22 + peerDependencies: 23 + rollup: ^1.20.0||^2.0.0||^3.0.0 24 + peerDependenciesMeta: 25 + rollup: 26 + optional: true 27 + dependencies: 28 + '@types/estree': 1.0.0 29 + estree-walker: 2.0.2 30 + picomatch: 2.3.1 31 + rollup: 3.5.1 32 + dev: false 33 + 34 + /@types/estree/1.0.0: 35 + resolution: {integrity: sha512-WulqXMDUTYAXCjZnk6JtIHPigp55cVtDgDrO2gHRwhyJto21+1zbVCtOYB2L1F9w4qCQ0rOGWBnBe0FNTiEJIQ==} 36 + dev: false 37 + 38 + /ansi-styles/3.2.1: 39 + resolution: {integrity: sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==} 40 + engines: {node: '>=4'} 41 + dependencies: 42 + color-convert: 1.9.3 43 + dev: true 44 + 45 + /balanced-match/1.0.2: 46 + resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==} 47 + dev: true 48 + 49 + /brace-expansion/1.1.11: 50 + resolution: {integrity: sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==} 51 + dependencies: 52 + balanced-match: 1.0.2 53 + concat-map: 0.0.1 54 + dev: true 55 + 56 + /call-bind/1.0.2: 57 + resolution: {integrity: sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==} 58 + dependencies: 59 + function-bind: 1.1.1 60 + get-intrinsic: 1.1.3 61 + dev: true 62 + 63 + /chalk/2.4.2: 64 + resolution: {integrity: sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==} 65 + engines: {node: '>=4'} 66 + dependencies: 67 + ansi-styles: 3.2.1 68 + escape-string-regexp: 1.0.5 69 + supports-color: 5.5.0 70 + dev: true 71 + 72 + /cjs-module-lexer/1.2.2: 73 + resolution: {integrity: sha512-cOU9usZw8/dXIXKtwa8pM0OTJQuJkxMN6w30csNRUerHfeQ5R6U3kkU/FtJeIf3M202OHfY2U8ccInBG7/xogA==} 74 + dev: false 75 + 76 + /color-convert/1.9.3: 77 + resolution: {integrity: sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==} 78 + dependencies: 79 + color-name: 1.1.3 80 + dev: true 81 + 82 + /color-name/1.1.3: 83 + resolution: {integrity: sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==} 84 + dev: true 85 + 86 + /concat-map/0.0.1: 87 + resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==} 88 + dev: true 89 + 90 + /cross-spawn/6.0.5: 91 + resolution: {integrity: sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==} 92 + engines: {node: '>=4.8'} 93 + dependencies: 94 + nice-try: 1.0.5 95 + path-key: 2.0.1 96 + semver: 5.7.1 97 + shebang-command: 1.2.0 98 + which: 1.3.1 99 + dev: true 100 + 101 + /define-properties/1.1.4: 102 + resolution: {integrity: sha512-uckOqKcfaVvtBdsVkdPv3XjveQJsNQqmhXgRi8uhvWWuPYZCNlzT8qAyblUgNoXdHdjMTzAqeGjAoli8f+bzPA==} 103 + engines: {node: '>= 0.4'} 104 + dependencies: 105 + has-property-descriptors: 1.0.0 106 + object-keys: 1.1.1 107 + dev: true 108 + 109 + /error-ex/1.3.2: 110 + resolution: {integrity: sha512-7dFHNmqeFSEt2ZBsCriorKnn3Z2pj+fd9kmI6QoWw4//DL+icEBfc0U7qJCisqrTsKTjw4fNFy2pW9OqStD84g==} 111 + dependencies: 112 + is-arrayish: 0.2.1 113 + dev: true 114 + 115 + /es-abstract/1.20.4: 116 + resolution: {integrity: sha512-0UtvRN79eMe2L+UNEF1BwRe364sj/DXhQ/k5FmivgoSdpM90b8Jc0mDzKMGo7QS0BVbOP/bTwBKNnDc9rNzaPA==} 117 + engines: {node: '>= 0.4'} 118 + dependencies: 119 + call-bind: 1.0.2 120 + es-to-primitive: 1.2.1 121 + function-bind: 1.1.1 122 + function.prototype.name: 1.1.5 123 + get-intrinsic: 1.1.3 124 + get-symbol-description: 1.0.0 125 + has: 1.0.3 126 + has-property-descriptors: 1.0.0 127 + has-symbols: 1.0.3 128 + internal-slot: 1.0.3 129 + is-callable: 1.2.7 130 + is-negative-zero: 2.0.2 131 + is-regex: 1.1.4 132 + is-shared-array-buffer: 1.0.2 133 + is-string: 1.0.7 134 + is-weakref: 1.0.2 135 + object-inspect: 1.12.2 136 + object-keys: 1.1.1 137 + object.assign: 4.1.4 138 + regexp.prototype.flags: 1.4.3 139 + safe-regex-test: 1.0.0 140 + string.prototype.trimend: 1.0.6 141 + string.prototype.trimstart: 1.0.6 142 + unbox-primitive: 1.0.2 143 + dev: true 144 + 145 + /es-to-primitive/1.2.1: 146 + resolution: {integrity: sha512-QCOllgZJtaUo9miYBcLChTUaHNjJF3PYs1VidD7AwiEj1kYxKeQTctLAezAOH5ZKRH0g2IgPn6KwB4IT8iRpvA==} 147 + engines: {node: '>= 0.4'} 148 + dependencies: 149 + is-callable: 1.2.7 150 + is-date-object: 1.0.5 151 + is-symbol: 1.0.4 152 + dev: true 153 + 154 + /escape-string-regexp/1.0.5: 155 + resolution: {integrity: sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==} 156 + engines: {node: '>=0.8.0'} 157 + dev: true 158 + 159 + /estree-walker/2.0.2: 160 + resolution: {integrity: sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==} 161 + dev: false 162 + 163 + /fsevents/2.3.2: 164 + resolution: {integrity: sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==} 165 + engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0} 166 + os: [darwin] 167 + requiresBuild: true 168 + optional: true 169 + 170 + /function-bind/1.1.1: 171 + resolution: {integrity: sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==} 172 + dev: true 173 + 174 + /function.prototype.name/1.1.5: 175 + resolution: {integrity: sha512-uN7m/BzVKQnCUF/iW8jYea67v++2u7m5UgENbHRtdDVclOUP+FMPlCNdmk0h/ysGyo2tavMJEDqJAkJdRa1vMA==} 176 + engines: {node: '>= 0.4'} 177 + dependencies: 178 + call-bind: 1.0.2 179 + define-properties: 1.1.4 180 + es-abstract: 1.20.4 181 + functions-have-names: 1.2.3 182 + dev: true 183 + 184 + /functions-have-names/1.2.3: 185 + resolution: {integrity: sha512-xckBUXyTIqT97tq2x2AMb+g163b5JFysYk0x4qxNFwbfQkmNZoiRHb6sPzI9/QV33WeuvVYBUIiD4NzNIyqaRQ==} 186 + dev: true 187 + 188 + /get-intrinsic/1.1.3: 189 + resolution: {integrity: sha512-QJVz1Tj7MS099PevUG5jvnt9tSkXN8K14dxQlikJuPt4uD9hHAHjLyLBiLR5zELelBdD9QNRAXZzsJx0WaDL9A==} 190 + dependencies: 191 + function-bind: 1.1.1 192 + has: 1.0.3 193 + has-symbols: 1.0.3 194 + dev: true 195 + 196 + /get-symbol-description/1.0.0: 197 + resolution: {integrity: sha512-2EmdH1YvIQiZpltCNgkuiUnyukzxM/R6NDJX31Ke3BG1Nq5b0S2PhX59UKi9vZpPDQVdqn+1IcaAwnzTT5vCjw==} 198 + engines: {node: '>= 0.4'} 199 + dependencies: 200 + call-bind: 1.0.2 201 + get-intrinsic: 1.1.3 202 + dev: true 203 + 204 + /graceful-fs/4.2.10: 205 + resolution: {integrity: sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA==} 206 + dev: true 207 + 208 + /has-bigints/1.0.2: 209 + resolution: {integrity: sha512-tSvCKtBr9lkF0Ex0aQiP9N+OpV4zi2r/Nee5VkRDbaqv35RLYMzbwQfFSZZH0kR+Rd6302UJZ2p/bJCEoR3VoQ==} 210 + dev: true 211 + 212 + /has-flag/3.0.0: 213 + resolution: {integrity: sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==} 214 + engines: {node: '>=4'} 215 + dev: true 216 + 217 + /has-property-descriptors/1.0.0: 218 + resolution: {integrity: sha512-62DVLZGoiEBDHQyqG4w9xCuZ7eJEwNmJRWw2VY84Oedb7WFcA27fiEVe8oUQx9hAUJ4ekurquucTGwsyO1XGdQ==} 219 + dependencies: 220 + get-intrinsic: 1.1.3 221 + dev: true 222 + 223 + /has-symbols/1.0.3: 224 + resolution: {integrity: sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==} 225 + engines: {node: '>= 0.4'} 226 + dev: true 227 + 228 + /has-tostringtag/1.0.0: 229 + resolution: {integrity: sha512-kFjcSNhnlGV1kyoGk7OXKSawH5JOb/LzUc5w9B02hOTO0dfFRjbHQKvg1d6cf3HbeUmtU9VbbV3qzZ2Teh97WQ==} 230 + engines: {node: '>= 0.4'} 231 + dependencies: 232 + has-symbols: 1.0.3 233 + dev: true 234 + 235 + /has/1.0.3: 236 + resolution: {integrity: sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==} 237 + engines: {node: '>= 0.4.0'} 238 + dependencies: 239 + function-bind: 1.1.1 240 + dev: true 241 + 242 + /hosted-git-info/2.8.9: 243 + resolution: {integrity: sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw==} 244 + dev: true 245 + 246 + /internal-slot/1.0.3: 247 + resolution: {integrity: sha512-O0DB1JC/sPyZl7cIo78n5dR7eUSwwpYPiXRhTzNxZVAMUuB8vlnRFyLxdrVToks6XPLVnFfbzaVd5WLjhgg+vA==} 248 + engines: {node: '>= 0.4'} 249 + dependencies: 250 + get-intrinsic: 1.1.3 251 + has: 1.0.3 252 + side-channel: 1.0.4 253 + dev: true 254 + 255 + /is-arrayish/0.2.1: 256 + resolution: {integrity: sha512-zz06S8t0ozoDXMG+ube26zeCTNXcKIPJZJi8hBrF4idCLms4CG9QtK7qBl1boi5ODzFpjswb5JPmHCbMpjaYzg==} 257 + dev: true 258 + 259 + /is-bigint/1.0.4: 260 + resolution: {integrity: sha512-zB9CruMamjym81i2JZ3UMn54PKGsQzsJeo6xvN3HJJ4CAsQNB6iRutp2To77OfCNuoxspsIhzaPoO1zyCEhFOg==} 261 + dependencies: 262 + has-bigints: 1.0.2 263 + dev: true 264 + 265 + /is-boolean-object/1.1.2: 266 + resolution: {integrity: sha512-gDYaKHJmnj4aWxyj6YHyXVpdQawtVLHU5cb+eztPGczf6cjuTdwve5ZIEfgXqH4e57An1D1AKf8CZ3kYrQRqYA==} 267 + engines: {node: '>= 0.4'} 268 + dependencies: 269 + call-bind: 1.0.2 270 + has-tostringtag: 1.0.0 271 + dev: true 272 + 273 + /is-callable/1.2.7: 274 + resolution: {integrity: sha512-1BC0BVFhS/p0qtw6enp8e+8OD0UrK0oFLztSjNzhcKA3WDuJxxAPXzPuPtKkjEY9UUoEWlX/8fgKeu2S8i9JTA==} 275 + engines: {node: '>= 0.4'} 276 + dev: true 277 + 278 + /is-core-module/2.11.0: 279 + resolution: {integrity: sha512-RRjxlvLDkD1YJwDbroBHMb+cukurkDWNyHx7D3oNB5x9rb5ogcksMC5wHCadcXoo67gVr/+3GFySh3134zi6rw==} 280 + dependencies: 281 + has: 1.0.3 282 + dev: true 283 + 284 + /is-date-object/1.0.5: 285 + resolution: {integrity: sha512-9YQaSxsAiSwcvS33MBk3wTCVnWK+HhF8VZR2jRxehM16QcVOdHqPn4VPHmRK4lSr38n9JriurInLcP90xsYNfQ==} 286 + engines: {node: '>= 0.4'} 287 + dependencies: 288 + has-tostringtag: 1.0.0 289 + dev: true 290 + 291 + /is-negative-zero/2.0.2: 292 + resolution: {integrity: sha512-dqJvarLawXsFbNDeJW7zAz8ItJ9cd28YufuuFzh0G8pNHjJMnY08Dv7sYX2uF5UpQOwieAeOExEYAWWfu7ZZUA==} 293 + engines: {node: '>= 0.4'} 294 + dev: true 295 + 296 + /is-number-object/1.0.7: 297 + resolution: {integrity: sha512-k1U0IRzLMo7ZlYIfzRu23Oh6MiIFasgpb9X76eqfFZAqwH44UI4KTBvBYIZ1dSL9ZzChTB9ShHfLkR4pdW5krQ==} 298 + engines: {node: '>= 0.4'} 299 + dependencies: 300 + has-tostringtag: 1.0.0 301 + dev: true 302 + 303 + /is-regex/1.1.4: 304 + resolution: {integrity: sha512-kvRdxDsxZjhzUX07ZnLydzS1TU/TJlTUHHY4YLL87e37oUA49DfkLqgy+VjFocowy29cKvcSiu+kIv728jTTVg==} 305 + engines: {node: '>= 0.4'} 306 + dependencies: 307 + call-bind: 1.0.2 308 + has-tostringtag: 1.0.0 309 + dev: true 310 + 311 + /is-shared-array-buffer/1.0.2: 312 + resolution: {integrity: sha512-sqN2UDu1/0y6uvXyStCOzyhAjCSlHceFoMKJW8W9EU9cvic/QdsZ0kEU93HEy3IUEFZIiH/3w+AH/UQbPHNdhA==} 313 + dependencies: 314 + call-bind: 1.0.2 315 + dev: true 316 + 317 + /is-string/1.0.7: 318 + resolution: {integrity: sha512-tE2UXzivje6ofPW7l23cjDOMa09gb7xlAqG6jG5ej6uPV32TlWP3NKPigtaGeHNu9fohccRYvIiZMfOOnOYUtg==} 319 + engines: {node: '>= 0.4'} 320 + dependencies: 321 + has-tostringtag: 1.0.0 322 + dev: true 323 + 324 + /is-symbol/1.0.4: 325 + resolution: {integrity: sha512-C/CPBqKWnvdcxqIARxyOh4v1UUEOCHpgDa0WYgpKDFMszcrPcffg5uhwSgPCLD2WWxmq6isisz87tzT01tuGhg==} 326 + engines: {node: '>= 0.4'} 327 + dependencies: 328 + has-symbols: 1.0.3 329 + dev: true 330 + 331 + /is-weakref/1.0.2: 332 + resolution: {integrity: sha512-qctsuLZmIQ0+vSSMfoVvyFe2+GSEvnmZ2ezTup1SBse9+twCCeial6EEi3Nc2KFcf6+qz2FBPnjXsk8xhKSaPQ==} 333 + dependencies: 334 + call-bind: 1.0.2 335 + dev: true 336 + 337 + /isexe/2.0.0: 338 + resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==} 339 + dev: true 340 + 341 + /json-parse-better-errors/1.0.2: 342 + resolution: {integrity: sha512-mrqyZKfX5EhL7hvqcV6WG1yYjnjeuYDzDhhcAAUrq8Po85NBQBJP+ZDUT75qZQ98IkUoBqdkExkukOU7Ts2wrw==} 343 + dev: true 344 + 345 + /load-json-file/4.0.0: 346 + resolution: {integrity: sha512-Kx8hMakjX03tiGTLAIdJ+lL0htKnXjEZN6hk/tozf/WOuYGdZBJrZ+rCJRbVCugsjB3jMLn9746NsQIf5VjBMw==} 347 + engines: {node: '>=4'} 348 + dependencies: 349 + graceful-fs: 4.2.10 350 + parse-json: 4.0.0 351 + pify: 3.0.0 352 + strip-bom: 3.0.0 353 + dev: true 354 + 355 + /memorystream/0.3.1: 356 + resolution: {integrity: sha512-S3UwM3yj5mtUSEfP41UZmt/0SCoVYUcU1rkXv+BQ5Ig8ndL4sPoJNBUJERafdPb5jjHJGuMgytgKvKIf58XNBw==} 357 + engines: {node: '>= 0.10.0'} 358 + dev: true 359 + 360 + /minimatch/3.1.2: 361 + resolution: {integrity: sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==} 362 + dependencies: 363 + brace-expansion: 1.1.11 364 + dev: true 365 + 366 + /nice-try/1.0.5: 367 + resolution: {integrity: sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==} 368 + dev: true 369 + 370 + /normalize-package-data/2.5.0: 371 + resolution: {integrity: sha512-/5CMN3T0R4XTj4DcGaexo+roZSdSFW/0AOOTROrjxzCG1wrWXEsGbRKevjlIL+ZDE4sZlJr5ED4YW0yqmkK+eA==} 372 + dependencies: 373 + hosted-git-info: 2.8.9 374 + resolve: 1.22.1 375 + semver: 5.7.1 376 + validate-npm-package-license: 3.0.4 377 + dev: true 378 + 379 + /npm-run-all/4.1.5: 380 + resolution: {integrity: sha512-Oo82gJDAVcaMdi3nuoKFavkIHBRVqQ1qvMb+9LHk/cF4P6B2m8aP04hGf7oL6wZ9BuGwX1onlLhpuoofSyoQDQ==} 381 + engines: {node: '>= 4'} 382 + hasBin: true 383 + dependencies: 384 + ansi-styles: 3.2.1 385 + chalk: 2.4.2 386 + cross-spawn: 6.0.5 387 + memorystream: 0.3.1 388 + minimatch: 3.1.2 389 + pidtree: 0.3.1 390 + read-pkg: 3.0.0 391 + shell-quote: 1.7.4 392 + string.prototype.padend: 3.1.4 393 + dev: true 394 + 395 + /object-inspect/1.12.2: 396 + resolution: {integrity: sha512-z+cPxW0QGUp0mcqcsgQyLVRDoXFQbXOwBaqyF7VIgI4TWNQsDHrBpUQslRmIfAoYWdYzs6UlKJtB2XJpTaNSpQ==} 397 + dev: true 398 + 399 + /object-keys/1.1.1: 400 + resolution: {integrity: sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==} 401 + engines: {node: '>= 0.4'} 402 + dev: true 403 + 404 + /object.assign/4.1.4: 405 + resolution: {integrity: sha512-1mxKf0e58bvyjSCtKYY4sRe9itRk3PJpquJOjeIkz885CczcI4IvJJDLPS72oowuSh+pBxUFROpX+TU++hxhZQ==} 406 + engines: {node: '>= 0.4'} 407 + dependencies: 408 + call-bind: 1.0.2 409 + define-properties: 1.1.4 410 + has-symbols: 1.0.3 411 + object-keys: 1.1.1 412 + dev: true 413 + 414 + /parse-json/4.0.0: 415 + resolution: {integrity: sha512-aOIos8bujGN93/8Ox/jPLh7RwVnPEysynVFE+fQZyg6jKELEHwzgKdLRFHUgXJL6kylijVSBC4BvN9OmsB48Rw==} 416 + engines: {node: '>=4'} 417 + dependencies: 418 + error-ex: 1.3.2 419 + json-parse-better-errors: 1.0.2 420 + dev: true 421 + 422 + /path-key/2.0.1: 423 + resolution: {integrity: sha512-fEHGKCSmUSDPv4uoj8AlD+joPlq3peND+HRYyxFz4KPw4z926S/b8rIuFs2FYJg3BwsxJf6A9/3eIdLaYC+9Dw==} 424 + engines: {node: '>=4'} 425 + dev: true 426 + 427 + /path-parse/1.0.7: 428 + resolution: {integrity: sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==} 429 + dev: true 430 + 431 + /path-type/3.0.0: 432 + resolution: {integrity: sha512-T2ZUsdZFHgA3u4e5PfPbjd7HDDpxPnQb5jN0SrDsjNSuVXHJqtwTnWqG0B1jZrgmJ/7lj1EmVIByWt1gxGkWvg==} 433 + engines: {node: '>=4'} 434 + dependencies: 435 + pify: 3.0.0 436 + dev: true 437 + 438 + /picomatch/2.3.1: 439 + resolution: {integrity: sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==} 440 + engines: {node: '>=8.6'} 441 + dev: false 442 + 443 + /pidtree/0.3.1: 444 + resolution: {integrity: sha512-qQbW94hLHEqCg7nhby4yRC7G2+jYHY4Rguc2bjw7Uug4GIJuu1tvf2uHaZv5Q8zdt+WKJ6qK1FOI6amaWUo5FA==} 445 + engines: {node: '>=0.10'} 446 + hasBin: true 447 + dev: true 448 + 449 + /pify/3.0.0: 450 + resolution: {integrity: sha512-C3FsVNH1udSEX48gGX1xfvwTWfsYWj5U+8/uK15BGzIGrKoUpghX8hWZwa/OFnakBiiVNmBvemTJR5mcy7iPcg==} 451 + engines: {node: '>=4'} 452 + dev: true 453 + 454 + /read-pkg/3.0.0: 455 + resolution: {integrity: sha512-BLq/cCO9two+lBgiTYNqD6GdtK8s4NpaWrl6/rCO9w0TUS8oJl7cmToOZfRYllKTISY6nt1U7jQ53brmKqY6BA==} 456 + engines: {node: '>=4'} 457 + dependencies: 458 + load-json-file: 4.0.0 459 + normalize-package-data: 2.5.0 460 + path-type: 3.0.0 461 + dev: true 462 + 463 + /regexp.prototype.flags/1.4.3: 464 + resolution: {integrity: sha512-fjggEOO3slI6Wvgjwflkc4NFRCTZAu5CnNfBd5qOMYhWdn67nJBBu34/TkD++eeFmd8C9r9jfXJ27+nSiRkSUA==} 465 + engines: {node: '>= 0.4'} 466 + dependencies: 467 + call-bind: 1.0.2 468 + define-properties: 1.1.4 469 + functions-have-names: 1.2.3 470 + dev: true 471 + 472 + /resolve/1.22.1: 473 + resolution: {integrity: sha512-nBpuuYuY5jFsli/JIs1oldw6fOQCBioohqWZg/2hiaOybXOft4lonv85uDOKXdf8rhyK159cxU5cDcK/NKk8zw==} 474 + hasBin: true 475 + dependencies: 476 + is-core-module: 2.11.0 477 + path-parse: 1.0.7 478 + supports-preserve-symlinks-flag: 1.0.0 479 + dev: true 480 + 481 + /rollup/3.5.1: 482 + resolution: {integrity: sha512-hdQWTvPeiAbM6SUkxV70HdGUVxsgsc+CLy5fuh4KdgUBJ0SowXiix8gANgXoG3wEuLwfoJhCT2V+WwxfWq9Ikw==} 483 + engines: {node: '>=14.18.0', npm: '>=8.0.0'} 484 + hasBin: true 485 + optionalDependencies: 486 + fsevents: 2.3.2 487 + 488 + /safe-regex-test/1.0.0: 489 + resolution: {integrity: sha512-JBUUzyOgEwXQY1NuPtvcj/qcBDbDmEvWufhlnXZIm75DEHp+afM1r1ujJpJsV/gSM4t59tpDyPi1sd6ZaPFfsA==} 490 + dependencies: 491 + call-bind: 1.0.2 492 + get-intrinsic: 1.1.3 493 + is-regex: 1.1.4 494 + dev: true 495 + 496 + /semver/5.7.1: 497 + resolution: {integrity: sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==} 498 + hasBin: true 499 + dev: true 500 + 501 + /shebang-command/1.2.0: 502 + resolution: {integrity: sha512-EV3L1+UQWGor21OmnvojK36mhg+TyIKDh3iFBKBohr5xeXIhNBcx8oWdgkTEEQ+BEFFYdLRuqMfd5L84N1V5Vg==} 503 + engines: {node: '>=0.10.0'} 504 + dependencies: 505 + shebang-regex: 1.0.0 506 + dev: true 507 + 508 + /shebang-regex/1.0.0: 509 + resolution: {integrity: sha512-wpoSFAxys6b2a2wHZ1XpDSgD7N9iVjg29Ph9uV/uaP9Ex/KXlkTZTeddxDPSYQpgvzKLGJke2UU0AzoGCjNIvQ==} 510 + engines: {node: '>=0.10.0'} 511 + dev: true 512 + 513 + /shell-quote/1.7.4: 514 + resolution: {integrity: sha512-8o/QEhSSRb1a5i7TFR0iM4G16Z0vYB2OQVs4G3aAFXjn3T6yEx8AZxy1PgDF7I00LZHYA3WxaSYIf5e5sAX8Rw==} 515 + dev: true 516 + 517 + /side-channel/1.0.4: 518 + resolution: {integrity: sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==} 519 + dependencies: 520 + call-bind: 1.0.2 521 + get-intrinsic: 1.1.3 522 + object-inspect: 1.12.2 523 + dev: true 524 + 525 + /spdx-correct/3.1.1: 526 + resolution: {integrity: sha512-cOYcUWwhCuHCXi49RhFRCyJEK3iPj1Ziz9DpViV3tbZOwXD49QzIN3MpOLJNxh2qwq2lJJZaKMVw9qNi4jTC0w==} 527 + dependencies: 528 + spdx-expression-parse: 3.0.1 529 + spdx-license-ids: 3.0.12 530 + dev: true 531 + 532 + /spdx-exceptions/2.3.0: 533 + resolution: {integrity: sha512-/tTrYOC7PPI1nUAgx34hUpqXuyJG+DTHJTnIULG4rDygi4xu/tfgmq1e1cIRwRzwZgo4NLySi+ricLkZkw4i5A==} 534 + dev: true 535 + 536 + /spdx-expression-parse/3.0.1: 537 + resolution: {integrity: sha512-cbqHunsQWnJNE6KhVSMsMeH5H/L9EpymbzqTQ3uLwNCLZ1Q481oWaofqH7nO6V07xlXwY6PhQdQ2IedWx/ZK4Q==} 538 + dependencies: 539 + spdx-exceptions: 2.3.0 540 + spdx-license-ids: 3.0.12 541 + dev: true 542 + 543 + /spdx-license-ids/3.0.12: 544 + resolution: {integrity: sha512-rr+VVSXtRhO4OHbXUiAF7xW3Bo9DuuF6C5jH+q/x15j2jniycgKbxU09Hr0WqlSLUs4i4ltHGXqTe7VHclYWyA==} 545 + dev: true 546 + 547 + /string.prototype.padend/3.1.4: 548 + resolution: {integrity: sha512-67otBXoksdjsnXXRUq+KMVTdlVRZ2af422Y0aTyTjVaoQkGr3mxl2Bc5emi7dOQ3OGVVQQskmLEWwFXwommpNw==} 549 + engines: {node: '>= 0.4'} 550 + dependencies: 551 + call-bind: 1.0.2 552 + define-properties: 1.1.4 553 + es-abstract: 1.20.4 554 + dev: true 555 + 556 + /string.prototype.trimend/1.0.6: 557 + resolution: {integrity: sha512-JySq+4mrPf9EsDBEDYMOb/lM7XQLulwg5R/m1r0PXEFqrV0qHvl58sdTilSXtKOflCsK2E8jxf+GKC0T07RWwQ==} 558 + dependencies: 559 + call-bind: 1.0.2 560 + define-properties: 1.1.4 561 + es-abstract: 1.20.4 562 + dev: true 563 + 564 + /string.prototype.trimstart/1.0.6: 565 + resolution: {integrity: sha512-omqjMDaY92pbn5HOX7f9IccLA+U1tA9GvtU4JrodiXFfYB7jPzzHpRzpglLAjtUV6bB557zwClJezTqnAiYnQA==} 566 + dependencies: 567 + call-bind: 1.0.2 568 + define-properties: 1.1.4 569 + es-abstract: 1.20.4 570 + dev: true 571 + 572 + /strip-bom/3.0.0: 573 + resolution: {integrity: sha512-vavAMRXOgBVNF6nyEEmL3DBK19iRpDcoIwW+swQ+CbGiu7lju6t+JklA1MHweoWtadgt4ISVUsXLyDq34ddcwA==} 574 + engines: {node: '>=4'} 575 + dev: true 576 + 577 + /supports-color/5.5.0: 578 + resolution: {integrity: sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==} 579 + engines: {node: '>=4'} 580 + dependencies: 581 + has-flag: 3.0.0 582 + dev: true 583 + 584 + /supports-preserve-symlinks-flag/1.0.0: 585 + resolution: {integrity: sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==} 586 + engines: {node: '>= 0.4'} 587 + dev: true 588 + 589 + /unbox-primitive/1.0.2: 590 + resolution: {integrity: sha512-61pPlCD9h51VoreyJ0BReideM3MDKMKnh6+V9L08331ipq6Q8OFXZYiqP6n/tbHx4s5I9uRhcye6BrbkizkBDw==} 591 + dependencies: 592 + call-bind: 1.0.2 593 + has-bigints: 1.0.2 594 + has-symbols: 1.0.3 595 + which-boxed-primitive: 1.0.2 596 + dev: true 597 + 598 + /validate-npm-package-license/3.0.4: 599 + resolution: {integrity: sha512-DpKm2Ui/xN7/HQKCtpZxoRWBhZ9Z0kqtygG8XCgNQ8ZlDnxuQmWhj566j8fN4Cu3/JmbhsDo7fcAJq4s9h27Ew==} 600 + dependencies: 601 + spdx-correct: 3.1.1 602 + spdx-expression-parse: 3.0.1 603 + dev: true 604 + 605 + /which-boxed-primitive/1.0.2: 606 + resolution: {integrity: sha512-bwZdv0AKLpplFY2KZRX6TvyuN7ojjr7lwkg6ml0roIy9YeuSr7JS372qlNW18UQYzgYK9ziGcerWqZOmEn9VNg==} 607 + dependencies: 608 + is-bigint: 1.0.4 609 + is-boolean-object: 1.1.2 610 + is-number-object: 1.0.7 611 + is-string: 1.0.7 612 + is-symbol: 1.0.4 613 + dev: true 614 + 615 + /which/1.3.1: 616 + resolution: {integrity: sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==} 617 + hasBin: true 618 + dependencies: 619 + isexe: 2.0.0 620 + dev: true
+53
rollup.config.mjs
··· 1 + import { builtinModules } from 'module'; 2 + import { readFileSync } from 'fs'; 3 + 4 + import cjsCheck from './src/index.mjs'; 5 + 6 + const pkg = JSON.parse(readFileSync('./package.json', 'utf-8')); 7 + 8 + const output = format => { 9 + const extension = format === 'esm' ? '.mjs' : '.js'; 10 + return { 11 + chunkFileNames: '[hash]' + extension, 12 + entryFileNames: '[name]' + extension, 13 + dir: './dist', 14 + exports: 'named', 15 + sourcemap: true, 16 + indent: false, 17 + freeze: false, 18 + strict: false, 19 + format, 20 + esModule: format !== 'esm', 21 + externalLiveBindings: format !== 'esm', 22 + generatedCode: { 23 + preset: 'es5', 24 + reservedNamesAsProps: false, 25 + objectShorthand: false, 26 + constBindings: false, 27 + }, 28 + }; 29 + }; 30 + 31 + export default { 32 + input: { 33 + 'rollup-plugin-cjs-check': './src/index.mjs', 34 + }, 35 + external: [ 36 + ...builtinModules, 37 + ...Object.keys(pkg.dependencies || {}), 38 + ...Object.keys(pkg.peerDependencies || {}), 39 + ], 40 + onwarn() {}, 41 + plugins: [ 42 + cjsCheck(), 43 + ], 44 + treeshake: { 45 + unknownGlobalSideEffects: false, 46 + tryCatchDeoptimization: false, 47 + moduleSideEffects: false, 48 + }, 49 + output: [ 50 + output('esm'), 51 + output('cjs') 52 + ], 53 + };
+26
src/index.d.ts
··· 1 + import { Plugin } from 'rollup'; 2 + import { FilterPattern } from '@rollup/pluginutils'; 3 + 4 + export interface CJSCheckOptions { 5 + /** 6 + * A picomatch pattern, or array of patterns, which specifies the files in 7 + * the build the plugin should operate on. By default, all files with 8 + * extension `".cjs"` or those in `extensions` are included, but you can 9 + * narrow this list by only including specific files. These files will be 10 + * analyzed and transpiled if either the analysis does not find ES module 11 + * specific statements or `transformMixedEsModules` is `true`. 12 + * @default undefined 13 + */ 14 + include?: FilterPattern; 15 + /** 16 + * A picomatch pattern, or array of patterns, which specifies the files in 17 + * the build the plugin should _ignore_. By default, all files with 18 + * extensions other than those in `extensions` or `".cjs"` are ignored, but you 19 + * can exclude additional files. See also the `include` option. 20 + * @default undefined 21 + */ 22 + exclude?: FilterPattern; 23 + } 24 + 25 + /** A Rollup plugin for checking CommonJS exports against `cjs-module-lexer`. */ 26 + export default function cjsCheck(options?: CJSCheckOptions): Plugin;
+61
src/index.mjs
··· 1 + import { parse, init } from 'cjs-module-lexer'; 2 + import { createFilter } from '@rollup/pluginutils'; 3 + 4 + function cjsCheck(opts = {}) { 5 + const filter = createFilter(opts.include, opts.exclude, { 6 + resolve: false 7 + }); 8 + 9 + return { 10 + name: "cjs-check", 11 + 12 + async renderChunk(code, chunk) { 13 + if (opts.extension !== '.js') { 14 + return null; 15 + } else if (!filter(chunk.fileName)) { 16 + return null; 17 + } 18 + 19 + await init() 20 + const output = parse(code); 21 + const missingReexports = []; 22 + const missingExports = []; 23 + 24 + let hasMissing = false; 25 + for (const mod of chunk.exports) { 26 + if (mod[0] == '*' && !output.reexports.includes(mod.slice(1))) { 27 + hasMissing = true; 28 + missingReexports.push(mod.slice(1)); 29 + } else if (mod[0] != '*' && !output.exports.includes(mod)) { 30 + hasMissing = true; 31 + missingExports.push(mod); 32 + } 33 + } 34 + 35 + if (hasMissing) { 36 + let message = ''; 37 + if (missingReexports.length) { 38 + message += 'The following re-exports are undetected:\n'; 39 + message += missingReexports.map(x => `- ${x}\n`).join(''); 40 + } 41 + 42 + if (missingExports.length) { 43 + message += 'The following exports are undetected:\n'; 44 + message += missingExports.map(x => `- ${x}\n`).join(''); 45 + } 46 + 47 + if (missingExports.length + missingReexports.length >= chunk.exports.length) { 48 + message = 'All chunk exports have not been detected. Is the chunk a CommonJS module?' 49 + } 50 + 51 + throw new Error( 52 + `cjs-module-lexer did not agree with Rollup\'s exports for ${chunk.fileName}.\n${message}` 53 + ); 54 + } 55 + 56 + return null; 57 + } 58 + }; 59 + } 60 + 61 + export default cjsCheck;