From 6a626e494427a49092b8012d65e4e4d10a5429af Mon Sep 17 00:00:00 2001 From: Stephan Schreiber <Septh@users.noreply.github.com> Date: Mon, 8 May 2023 03:38:09 +0200 Subject: [PATCH] Switch package to ESM only and Rollup 3 compatibility only --- README.md | 11 +- package-lock.json | 762 +++++++++------------------------------ package.json | 50 ++- {src => source}/index.ts | 520 +++++++++++++------------- test/_common.ts | 5 +- test/builtins.test.ts | 2 +- test/monorepo.test.ts | 2 +- test/options.test.ts | 6 +- test/specifier.test.ts | 2 +- test/workspaces.test.ts | 2 +- tsconfig.json | 17 +- 11 files changed, 481 insertions(+), 898 deletions(-) rename {src => source}/index.ts (97%) diff --git a/README.md b/README.md index 9c2be06..33efa3c 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # rollup-plugin-node-externals A Rollup plugin that automatically declares NodeJS built-in modules as `external`. Also handles npm dependencies, devDependencies, peerDependencies and optionalDependencies. -Works in monorepos too! +Works in npm/yarn/pnpm/lerna monorepos too! ## Why you need this <details><summary>(click to expand)</summary> @@ -24,7 +24,7 @@ npm install --save-dev rollup-plugin-node-externals ``` ## Usage -When bundling an application or library, you want to have your **runtime dependencies** listed under `dependencies` in `package.json`, and **development dependencies** listed under `devDependencies`. +You generally want to have your **runtime dependencies** listed under `dependencies` in `package.json`, and your **development dependencies** listed under `devDependencies`. If you follow this simple rule, then the defaults are just what you need: ```js @@ -162,7 +162,12 @@ Rollup's own `external` configuration option always takes precedence over this p ## Breaking changes -<details><summary>(click to expand)</summary> + +### Breaking changes in version 6 +- This package is now esm-only and requires NodeJS v16+.<br />*If you need CommonJS or older NodeJS support, please stick to v5.* +- This plugin now has a **peer-dependency** on Rollup ^3.0.0.<br />*If you need Rollup 2 support, please stick to v5.* + +<details><summary>Previous versions -- click to expand</summary> ### Breaking changes in version 5 - In previous versions, the `devDeps` option defaulted to `true`.<br>This was practical, but often wrong: devDependencies are meant just for that: being used when developping. Therefore, the `devDeps` option now defaults to `false`, meaning Rollup will include them in your bundle. diff --git a/package-lock.json b/package-lock.json index ce79f15..42dc7aa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,26 +9,53 @@ "version": "5.1.3", "license": "MIT", "devDependencies": { - "@fast-check/ava": "^1.1.0", - "@rollup/plugin-commonjs": "^23.0.0", - "@rollup/plugin-node-resolve": "^15.0.0", - "@typescript-eslint/eslint-plugin": "^5.40.0", - "@typescript-eslint/parser": "^5.40.0", - "ava": "^5.0.1", - "eslint": "^8.25.0", - "fast-check": "^3.2.0", + "@fast-check/ava": "^1.1.4", + "@types/node": "^16.18.26", + "@typescript-eslint/eslint-plugin": "^5.59.2", + "@typescript-eslint/parser": "^5.59.2", + "ava": "^5.2.0", + "eslint": "^8.40.0", + "fast-check": "^3.8.1", "rimraf": "^3.0.2", - "rollup": "^3.0.0", - "rollup-plugin-ts": "^3.0.2", + "rollup": "^3.21.5", "ts-node": "^10.9.1", - "tslib": "^2.4.0", - "typescript": "^4.8.4" + "tslib": "^2.5.0", + "typescript": "^5.0.4" }, "engines": { - "node": ">=14.0.0" + "node": ">=16.20.0" }, "peerDependencies": { - "rollup": "^2.60.0 || ^3.0.0" + "rollup": "^3.0.0" + } + }, + "node_modules/@ava/typescript": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/@ava/typescript/-/typescript-4.0.0.tgz", + "integrity": "sha512-QFIPeqkEbdvn7Pob0wVeYpeZD0eXd8nDYdCl+knJVaIJrHdF2fXa58vFaig26cmYwnsEN0KRNTYJKbqW1B0lfg==", + "dev": true, + "optional": true, + "peer": true, + "dependencies": { + "escape-string-regexp": "^5.0.0", + "execa": "^7.1.0" + }, + "engines": { + "node": ">=14.19 <15 || >=16.15 <17 || >=18" + } + }, + "node_modules/@ava/typescript/node_modules/escape-string-regexp": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-5.0.0.tgz", + "integrity": "sha512-/veY75JbMK4j1yjvuUxuVsiS/hr/4iHs9FTT6cgTexxdE0Ly/glccBAkloH/DofkjRbZU3bnoj38mOmhkZ0lHw==", + "dev": true, + "optional": true, + "peer": true, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/@cspotcode/source-map-support": { @@ -179,12 +206,6 @@ "@jridgewell/sourcemap-codec": "^1.4.10" } }, - "node_modules/@mdn/browser-compat-data": { - "version": "5.2.56", - "resolved": "https://registry.npmjs.org/@mdn/browser-compat-data/-/browser-compat-data-5.2.56.tgz", - "integrity": "sha512-1Pu6qcdJ1tQApjhWONtf8XtXH4bG9qnRyry+mYzNgZhfawoO2ODJWasvDf4pgEPlaHbxxFuZFL5l3UeKCdS3Xg==", - "dev": true - }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -220,78 +241,6 @@ "node": ">= 8" } }, - "node_modules/@rollup/plugin-commonjs": { - "version": "23.0.7", - "resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-23.0.7.tgz", - "integrity": "sha512-hsSD5Qzyuat/swzrExGG5l7EuIlPhwTsT7KwKbSCQzIcJWjRxiimi/0tyMYY2bByitNb3i1p+6JWEDGa0NvT0Q==", - "dev": true, - "dependencies": { - "@rollup/pluginutils": "^5.0.1", - "commondir": "^1.0.1", - "estree-walker": "^2.0.2", - "glob": "^8.0.3", - "is-reference": "1.2.1", - "magic-string": "^0.27.0" - }, - "engines": { - "node": ">=14.0.0" - }, - "peerDependencies": { - "rollup": "^2.68.0||^3.0.0" - }, - "peerDependenciesMeta": { - "rollup": { - "optional": true - } - } - }, - "node_modules/@rollup/plugin-node-resolve": { - "version": "15.0.2", - "resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-15.0.2.tgz", - "integrity": "sha512-Y35fRGUjC3FaurG722uhUuG8YHOJRJQbI6/CkbRkdPotSpDj9NtIN85z1zrcyDcCQIW4qp5mgG72U+gJ0TAFEg==", - "dev": true, - "dependencies": { - "@rollup/pluginutils": "^5.0.1", - "@types/resolve": "1.20.2", - "deepmerge": "^4.2.2", - "is-builtin-module": "^3.2.1", - "is-module": "^1.0.0", - "resolve": "^1.22.1" - }, - "engines": { - "node": ">=14.0.0" - }, - "peerDependencies": { - "rollup": "^2.78.0||^3.0.0" - }, - "peerDependenciesMeta": { - "rollup": { - "optional": true - } - } - }, - "node_modules/@rollup/pluginutils": { - "version": "5.0.2", - "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.0.2.tgz", - "integrity": "sha512-pTd9rIsP92h+B6wWwFbW8RkZv4hiR/xKsqre4SIuAOaOEQRxi0lqLke9k2/7WegC85GgUs9pjmOjCUi3In4vwA==", - "dev": true, - "dependencies": { - "@types/estree": "^1.0.0", - "estree-walker": "^2.0.2", - "picomatch": "^2.3.1" - }, - "engines": { - "node": ">=14.0.0" - }, - "peerDependencies": { - "rollup": "^1.20.0||^2.0.0||^3.0.0" - }, - "peerDependenciesMeta": { - "rollup": { - "optional": true - } - } - }, "node_modules/@tsconfig/node10": { "version": "1.0.9", "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.9.tgz", @@ -316,12 +265,6 @@ "integrity": "sha512-yOlFc+7UtL/89t2ZhjPvvB/DeAr3r+Dq58IgzsFkOAvVC6NMJXmCGjbptdXdR9qsX7pKcTL+s87FtYREi2dEEQ==", "dev": true }, - "node_modules/@types/estree": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.1.tgz", - "integrity": "sha512-LG4opVs2ANWZ1TJoKc937iMmNstM/d0ae1vNbnBvBhqCSezgVUOzcLCqbI5elV8Vy6WKwKjaqR+zO9VKirBBCA==", - "dev": true - }, "node_modules/@types/json-schema": { "version": "7.0.11", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.11.tgz", @@ -329,22 +272,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "20.1.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.1.0.tgz", - "integrity": "sha512-O+z53uwx64xY7D6roOi4+jApDGFg0qn6WHcxe5QeqjMaTezBO/mxdfFXIVAVVyNWKx84OmPB3L8kbVYOTeN34A==", - "dev": true, - "peer": true - }, - "node_modules/@types/object-path": { - "version": "0.11.1", - "resolved": "https://registry.npmjs.org/@types/object-path/-/object-path-0.11.1.tgz", - "integrity": "sha512-219LSCO9HPcoXcRTC6DbCs0FRhZgBnEMzf16RRqkT40WbkKx3mOeQuz3e2XqbfhOz/AHfbru0kzB1n1RCAsIIg==", - "dev": true - }, - "node_modules/@types/resolve": { - "version": "1.20.2", - "resolved": "https://registry.npmjs.org/@types/resolve/-/resolve-1.20.2.tgz", - "integrity": "sha512-60BCwRFOZCQhDncwQdxxeOEEkbc5dIMccYLwbxsS4TUNeVECQ/pBJ0j09mrHOl/JJvpRPGwO9SvE4nR2Nb/a4Q==", + "version": "16.18.26", + "resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.26.tgz", + "integrity": "sha512-pCNBzNQqCXE4A6FWDmrn/o1Qu+qBf8tnorBlNoPNSBQJF+jXzvTKNI/aMiE+hGJbK5sDAD65g7OS/YwSHIEJdw==", "dev": true }, "node_modules/@types/semver": { @@ -353,12 +283,6 @@ "integrity": "sha512-21cFJr9z3g5dW8B0CVI9g2O9beqaThGQ6ZFBqHfwhzLDKUxaqTIy3vnfah/UPkfOiF2pLq+tGz+W8RyCskuslw==", "dev": true }, - "node_modules/@types/ua-parser-js": { - "version": "0.7.36", - "resolved": "https://registry.npmjs.org/@types/ua-parser-js/-/ua-parser-js-0.7.36.tgz", - "integrity": "sha512-N1rW+njavs70y2cApeIw1vLMYXRwfBy+7trgavGuuTfOd7j1Yh7QTRc/yqsPl6ncokt72ZXuxEU0PiCp9bSwNQ==", - "dev": true - }, "node_modules/@typescript-eslint/eslint-plugin": { "version": "5.59.2", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.59.2.tgz", @@ -547,15 +471,6 @@ "url": "https://opencollective.com/typescript-eslint" } }, - "node_modules/@wessberg/stringutil": { - "version": "1.0.19", - "resolved": "https://registry.npmjs.org/@wessberg/stringutil/-/stringutil-1.0.19.tgz", - "integrity": "sha512-9AZHVXWlpN8Cn9k5BC/O0Dzb9E9xfEMXzYrNunwvkUTvuK7xgQPVRZpLo+jWCOZ5r8oBa8NIrHuPEu1hzbb6bg==", - "dev": true, - "engines": { - "node": ">=8.0.0" - } - }, "node_modules/acorn": { "version": "8.8.2", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.2.tgz", @@ -618,15 +533,6 @@ "url": "https://github.com/sponsors/epoberezkin" } }, - "node_modules/ansi-colors": { - "version": "4.1.3", - "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.3.tgz", - "integrity": "sha512-/6w/C21Pm1A7aZitlI5Ni/2J6FFQN8i1Cvz3kHABAAbw93v/NlvKdVOqz7CCWz/3iv/JplRSEEZ83XION15ovw==", - "dev": true, - "engines": { - "node": ">=6" - } - }, "node_modules/ansi-regex": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz", @@ -856,74 +762,6 @@ "node": ">=8" } }, - "node_modules/browserslist": { - "version": "4.21.5", - "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.21.5.tgz", - "integrity": "sha512-tUkiguQGW7S3IhB7N+c2MV/HZPSCPAAiYBZXLsBhFB/PCy6ZKKsZrmBayHV9fdGV/ARIfJ14NkxKzRDjvp7L6w==", - "dev": true, - "funding": [ - { - "type": "opencollective", - "url": "https://opencollective.com/browserslist" - }, - { - "type": "tidelift", - "url": "https://tidelift.com/funding/github/npm/browserslist" - } - ], - "dependencies": { - "caniuse-lite": "^1.0.30001449", - "electron-to-chromium": "^1.4.284", - "node-releases": "^2.0.8", - "update-browserslist-db": "^1.0.10" - }, - "bin": { - "browserslist": "cli.js" - }, - "engines": { - "node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7" - } - }, - "node_modules/browserslist-generator": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/browserslist-generator/-/browserslist-generator-2.0.3.tgz", - "integrity": "sha512-3j8ogwvlBpOEDR3f5n1H2n5BWXqHPWi/Xm8EC1DPJy5BWl4WkSFisatBygH/L9AEmg0MtOfcR1QnMuM9XL28jA==", - "dev": true, - "dependencies": { - "@mdn/browser-compat-data": "^5.2.33", - "@types/object-path": "^0.11.1", - "@types/semver": "^7.3.13", - "@types/ua-parser-js": "^0.7.36", - "browserslist": "^4.21.5", - "caniuse-lite": "^1.0.30001450", - "isbot": "^3.6.5", - "object-path": "^0.11.8", - "semver": "^7.3.8", - "ua-parser-js": "^1.0.33" - }, - "engines": { - "node": ">=16.15.1", - "npm": ">=7.0.0", - "pnpm": ">=3.2.0", - "yarn": ">=1.13" - }, - "funding": { - "type": "github", - "url": "https://github.com/wessberg/browserslist-generator?sponsor=1" - } - }, - "node_modules/builtin-modules": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-3.3.0.tgz", - "integrity": "sha512-zhaCDicdLuWN5UbN5IMnFqNMhNfo919sH85y2/ea+5Yg9TsTkeZxpL+JLbp6cgYFS4sRLp3YV4S6yDuqVWHYOw==", - "dev": true, - "engines": { - "node": ">=6" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/callsites": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-4.0.0.tgz", @@ -936,26 +774,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/caniuse-lite": { - "version": "1.0.30001486", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001486.tgz", - "integrity": "sha512-uv7/gXuHi10Whlj0pp5q/tsK/32J2QSqVRKQhs2j8VsDCjgyruAh/eEXHF822VqO9yT6iZKw3nRwZRSPBE9OQg==", - "dev": true, - "funding": [ - { - "type": "opencollective", - "url": "https://opencollective.com/browserslist" - }, - { - "type": "tidelift", - "url": "https://tidelift.com/funding/github/npm/caniuse-lite" - }, - { - "type": "github", - "url": "https://github.com/sponsors/ai" - } - ] - }, "node_modules/cbor": { "version": "8.1.0", "resolved": "https://registry.npmjs.org/cbor/-/cbor-8.1.0.tgz", @@ -1186,27 +1004,6 @@ "integrity": "sha512-QE33hToZseCH3jS0qN96O/bSh3kaw/h+Tq7ngyY9eWDUnTlTNUyqfqvCXioLe5Na5jFsL78ra/wuBU4iuEgd4w==", "dev": true }, - "node_modules/commondir": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz", - "integrity": "sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg==", - "dev": true - }, - "node_modules/compatfactory": { - "version": "2.0.9", - "resolved": "https://registry.npmjs.org/compatfactory/-/compatfactory-2.0.9.tgz", - "integrity": "sha512-fvO+AWcmbO7P1S+A3mwm3IGr74eHMeq5ZLhNhyNQc9mVDNHT4oe0Gg0ksdIFFNXLK7k7Z/TYcLAUSQdRgh1bsA==", - "dev": true, - "dependencies": { - "helpertypes": "^0.0.19" - }, - "engines": { - "node": ">=14.9.0" - }, - "peerDependencies": { - "typescript": ">=3.x || >= 4.x" - } - }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -1261,24 +1058,6 @@ "node": ">= 8" } }, - "node_modules/crosspath": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/crosspath/-/crosspath-2.0.0.tgz", - "integrity": "sha512-ju88BYCQ2uvjO2bR+SsgLSTwTSctU+6Vp2ePbKPgSCZyy4MWZxYsT738DlKVRE5utUjobjPRm1MkTYKJxCmpTA==", - "dev": true, - "dependencies": { - "@types/node": "^17.0.36" - }, - "engines": { - "node": ">=14.9.0" - } - }, - "node_modules/crosspath/node_modules/@types/node": { - "version": "17.0.45", - "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.45.tgz", - "integrity": "sha512-w+tIMs3rq2afQdsPJlODhoUEKzFP1ayaoyl1CcnwtIlsVe7K7bA1NGm4s3PraqTLlXnbIN84zuBlxBWo1u9BLw==", - "dev": true - }, "node_modules/currently-unhandled": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/currently-unhandled/-/currently-unhandled-0.4.1.tgz", @@ -1332,15 +1111,6 @@ "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==", "dev": true }, - "node_modules/deepmerge": { - "version": "4.3.1", - "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-4.3.1.tgz", - "integrity": "sha512-3sUqbMEc77XqpdNO7FRyRog+eW3ph+GYCbj+rK+uYyRMuwsVy0rMiVtPn+QJlKFvWP/1PYpapqYn0Me2knFn+A==", - "dev": true, - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/del": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/del/-/del-7.0.0.tgz", @@ -1433,12 +1203,6 @@ "integrity": "sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==", "dev": true }, - "node_modules/electron-to-chromium": { - "version": "1.4.385", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.385.tgz", - "integrity": "sha512-L9zlje9bIw0h+CwPQumiuVlfMcV4boxRjFIWDcLfFqTZNbkwOExBzfmswytHawObQX4OUhtNv8gIiB21kOurIg==", - "dev": true - }, "node_modules/emittery": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/emittery/-/emittery-1.0.1.tgz", @@ -1739,12 +1503,6 @@ "node": ">=4.0" } }, - "node_modules/estree-walker": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz", - "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==", - "dev": true - }, "node_modules/esutils": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", @@ -1754,6 +1512,39 @@ "node": ">=0.10.0" } }, + "node_modules/execa": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/execa/-/execa-7.1.1.tgz", + "integrity": "sha512-wH0eMf/UXckdUYnO21+HDztteVv05rq2GXksxT4fCGeHkBhw1DROXh40wcjMcRqDOWE7iPJ4n3M7e2+YFP+76Q==", + "dev": true, + "optional": true, + "peer": true, + "dependencies": { + "cross-spawn": "^7.0.3", + "get-stream": "^6.0.1", + "human-signals": "^4.3.0", + "is-stream": "^3.0.0", + "merge-stream": "^2.0.0", + "npm-run-path": "^5.1.0", + "onetime": "^6.0.0", + "signal-exit": "^3.0.7", + "strip-final-newline": "^3.0.0" + }, + "engines": { + "node": "^14.18.0 || ^16.14.0 || >=18.0.0" + }, + "funding": { + "url": "https://github.com/sindresorhus/execa?sponsor=1" + } + }, + "node_modules/execa/node_modules/signal-exit": { + "version": "3.0.7", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", + "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==", + "dev": true, + "optional": true, + "peer": true + }, "node_modules/fast-check": { "version": "3.8.1", "resolved": "https://registry.npmjs.org/fast-check/-/fast-check-3.8.1.tgz", @@ -1932,12 +1723,6 @@ "node": "^8.16.0 || ^10.6.0 || >=11.0.0" } }, - "node_modules/function-bind": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", - "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", - "dev": true - }, "node_modules/get-caller-file": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", @@ -1947,23 +1732,18 @@ "node": "6.* || 8.* || >= 10.*" } }, - "node_modules/glob": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz", - "integrity": "sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==", + "node_modules/get-stream": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-6.0.1.tgz", + "integrity": "sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==", "dev": true, - "dependencies": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^5.0.1", - "once": "^1.3.0" - }, + "optional": true, + "peer": true, "engines": { - "node": ">=12" + "node": ">=10" }, "funding": { - "url": "https://github.com/sponsors/isaacs" + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/glob-parent": { @@ -1978,27 +1758,6 @@ "node": ">= 6" } }, - "node_modules/glob/node_modules/brace-expansion": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", - "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", - "dev": true, - "dependencies": { - "balanced-match": "^1.0.0" - } - }, - "node_modules/glob/node_modules/minimatch": { - "version": "5.1.6", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz", - "integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==", - "dev": true, - "dependencies": { - "brace-expansion": "^2.0.1" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/globals": { "version": "13.20.0", "resolved": "https://registry.npmjs.org/globals/-/globals-13.20.0.tgz", @@ -2046,18 +1805,6 @@ "integrity": "sha512-bzh50DW9kTPM00T8y4o8vQg89Di9oLJVLW/KaOGIXJWP/iqCN6WKYkbNOF04vFLJhwcpYUh9ydh/+5vpOqV4YQ==", "dev": true }, - "node_modules/has": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", - "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", - "dev": true, - "dependencies": { - "function-bind": "^1.1.1" - }, - "engines": { - "node": ">= 0.4.0" - } - }, "node_modules/has-flag": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", @@ -2067,13 +1814,15 @@ "node": ">=8" } }, - "node_modules/helpertypes": { - "version": "0.0.19", - "resolved": "https://registry.npmjs.org/helpertypes/-/helpertypes-0.0.19.tgz", - "integrity": "sha512-J00e55zffgi3yVnUp0UdbMztNkr2PnizEkOe9URNohnrNhW5X0QpegkuLpOmFQInpi93Nb8MCjQRHAiCDF42NQ==", + "node_modules/human-signals": { + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-4.3.1.tgz", + "integrity": "sha512-nZXjEF2nbo7lIw3mgYjItAfgQXog3OjJogSbKa2CQIIvSGWcKgeJnQlNXip6NglNzYH45nSRiEVimMvYL8DDqQ==", "dev": true, + "optional": true, + "peer": true, "engines": { - "node": ">=10.0.0" + "node": ">=14.18.0" } }, "node_modules/ignore": { @@ -2168,33 +1917,6 @@ "node": ">=8" } }, - "node_modules/is-builtin-module": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/is-builtin-module/-/is-builtin-module-3.2.1.tgz", - "integrity": "sha512-BSLE3HnV2syZ0FK0iMA/yUGplUeMmNz4AW5fnTunbCIqZi4vG3WjJT9FHMy5D69xmAYBHXQhJdALdpwVxV501A==", - "dev": true, - "dependencies": { - "builtin-modules": "^3.3.0" - }, - "engines": { - "node": ">=6" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/is-core-module": { - "version": "2.12.0", - "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.12.0.tgz", - "integrity": "sha512-RECHCBCd/viahWmwj6enj19sKbHfJrddi/6cBDsNTKbNq0f7VeaUkBo60BqzvPqo/W54ChS62Z5qyun7cfOMqQ==", - "dev": true, - "dependencies": { - "has": "^1.0.3" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/is-error": { "version": "2.2.2", "resolved": "https://registry.npmjs.org/is-error/-/is-error-2.2.2.tgz", @@ -2234,12 +1956,6 @@ "node": ">=0.10.0" } }, - "node_modules/is-module": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-module/-/is-module-1.0.0.tgz", - "integrity": "sha512-51ypPSPCoTEIN9dy5Oy+h4pShgJmPCygKfyRCISBI+JoWT/2oJvK8QPxmwv7b/p239jXrm9M1mlQbyKJ5A152g==", - "dev": true - }, "node_modules/is-number": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", @@ -2288,13 +2004,18 @@ "integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==", "dev": true }, - "node_modules/is-reference": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/is-reference/-/is-reference-1.2.1.tgz", - "integrity": "sha512-U82MsXXiFIrjCK4otLT+o2NA2Cd2g5MLoOVXUZjIOhLurrRxpEXzI8O0KZHr3IjLvlAH1kTPYSuqer5T9ZVBKQ==", + "node_modules/is-stream": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-3.0.0.tgz", + "integrity": "sha512-LnQR4bZ9IADDRSkvpqMGvt/tEJWclzklNgSw48V5EAaAeDd6qGvN8ei6k5p0tvxSR171VmGyHuTiAOfxAbr8kA==", "dev": true, - "dependencies": { - "@types/estree": "*" + "optional": true, + "peer": true, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/is-unicode-supported": { @@ -2309,15 +2030,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/isbot": { - "version": "3.6.10", - "resolved": "https://registry.npmjs.org/isbot/-/isbot-3.6.10.tgz", - "integrity": "sha512-+I+2998oyP4oW9+OTQD8TS1r9P6wv10yejukj+Ksj3+UR5pUhsZN3f8W7ysq0p1qxpOVNbl5mCuv0bCaF8y5iQ==", - "dev": true, - "engines": { - "node": ">=12" - } - }, "node_modules/isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", @@ -2431,18 +2143,6 @@ "node": ">=10" } }, - "node_modules/magic-string": { - "version": "0.27.0", - "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.27.0.tgz", - "integrity": "sha512-8UnnX2PeRAPZuN12svgR9j7M1uWMovg/CEnIwIG0LFkXSJJe4PdfUGiTGl8V9bsBHFUtfVINcSyYxd7q+kx9fA==", - "dev": true, - "dependencies": { - "@jridgewell/sourcemap-codec": "^1.4.13" - }, - "engines": { - "node": ">=12" - } - }, "node_modules/make-error": { "version": "1.3.6", "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", @@ -2516,6 +2216,14 @@ "url": "https://github.com/sindresorhus/mem?sponsor=1" } }, + "node_modules/merge-stream": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", + "integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==", + "dev": true, + "optional": true, + "peer": true + }, "node_modules/merge2": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", @@ -2580,12 +2288,6 @@ "integrity": "sha512-Tj+HTDSJJKaZnfiuw+iaF9skdPpTo2GtEly5JHnWV/hfv2Qj/9RKsGISQtLh2ox3l5EAGw487hnBee0sIJ6v2g==", "dev": true }, - "node_modules/node-releases": { - "version": "2.0.10", - "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.10.tgz", - "integrity": "sha512-5GFldHPXVG/YZmFzJvKK2zDSzPKhEp0+ZR5SVaoSag9fsL5YgHbUHDfnG5494ISANDcK4KwPXAx2xqVEydmd7w==", - "dev": true - }, "node_modules/nofilter": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/nofilter/-/nofilter-3.1.0.tgz", @@ -2604,13 +2306,35 @@ "node": ">=0.10.0" } }, - "node_modules/object-path": { - "version": "0.11.8", - "resolved": "https://registry.npmjs.org/object-path/-/object-path-0.11.8.tgz", - "integrity": "sha512-YJjNZrlXJFM42wTBn6zgOJVar9KFJvzx6sTWDte8sWZF//cnjl0BxHNpfZx+ZffXX63A9q0b1zsFiBX4g4X5KA==", + "node_modules/npm-run-path": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-5.1.0.tgz", + "integrity": "sha512-sJOdmRGrY2sjNTRMbSvluQqg+8X7ZK61yvzBEIDhz4f8z1TZFYABsqjjCBd/0PUNE9M6QDgHJXQkGUEm7Q+l9Q==", "dev": true, + "optional": true, + "peer": true, + "dependencies": { + "path-key": "^4.0.0" + }, "engines": { - "node": ">= 10.12.0" + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/npm-run-path/node_modules/path-key": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-4.0.0.tgz", + "integrity": "sha512-haREypq7xkM7ErfgIyA0z+Bj4AGKlMSdlQE2jvJo6huWD1EdkKYV+G/T4nq0YEF2vgTT8kqMFKo1uHn950r4SQ==", + "dev": true, + "optional": true, + "peer": true, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/once": { @@ -2622,6 +2346,23 @@ "wrappy": "1" } }, + "node_modules/onetime": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/onetime/-/onetime-6.0.0.tgz", + "integrity": "sha512-1FlR+gjXK7X+AsAHso35MnyN5KqGwJRi/31ft6x0M194ht7S+rWAvd7PHss9xSKMzE0asv1pyIHaJYq+BbacAQ==", + "dev": true, + "optional": true, + "peer": true, + "dependencies": { + "mimic-fn": "^4.0.0" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/optionator": { "version": "0.9.1", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.1.tgz", @@ -2780,12 +2521,6 @@ "node": ">=8" } }, - "node_modules/path-parse": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", - "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", - "dev": true - }, "node_modules/path-type": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", @@ -2795,12 +2530,6 @@ "node": ">=8" } }, - "node_modules/picocolors": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz", - "integrity": "sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==", - "dev": true - }, "node_modules/picomatch": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", @@ -3016,23 +2745,6 @@ "node": ">=0.10.0" } }, - "node_modules/resolve": { - "version": "1.22.2", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.2.tgz", - "integrity": "sha512-Sb+mjNHOULsBv818T40qSPeRiuWLyaGMa5ewydRLFimneixmVy2zdivRl+AF6jaYPC8ERxGDmFSiqui6SfPd+g==", - "dev": true, - "dependencies": { - "is-core-module": "^2.11.0", - "path-parse": "^1.0.7", - "supports-preserve-symlinks-flag": "^1.0.0" - }, - "bin": { - "resolve": "bin/resolve" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/resolve-cwd": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/resolve-cwd/-/resolve-cwd-3.0.0.tgz", @@ -3124,68 +2836,6 @@ "fsevents": "~2.3.2" } }, - "node_modules/rollup-plugin-ts": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/rollup-plugin-ts/-/rollup-plugin-ts-3.2.0.tgz", - "integrity": "sha512-KkTLVifkUexEiAXS9VtSjDrjKr0TyusmNJpb2ZTAzI9VuPumSu4AktIaVNnwv70iUEitHwZtET7OAM+5n1u1tg==", - "dev": true, - "dependencies": { - "@rollup/pluginutils": "^5.0.2", - "@wessberg/stringutil": "^1.0.19", - "ansi-colors": "^4.1.3", - "browserslist": "^4.21.4", - "browserslist-generator": "^2.0.1", - "compatfactory": "^2.0.9", - "crosspath": "^2.0.0", - "magic-string": "^0.27.0", - "ts-clone-node": "^2.0.4", - "tslib": "^2.4.1" - }, - "engines": { - "node": ">=14.9.0", - "npm": ">=7.0.0", - "pnpm": ">=3.2.0", - "yarn": ">=1.13" - }, - "funding": { - "type": "github", - "url": "https://github.com/wessberg/rollup-plugin-ts?sponsor=1" - }, - "peerDependencies": { - "@babel/core": ">=6.x || >=7.x", - "@babel/plugin-transform-runtime": ">=6.x || >=7.x", - "@babel/preset-env": ">=6.x || >=7.x", - "@babel/preset-typescript": ">=6.x || >=7.x", - "@babel/runtime": ">=6.x || >=7.x", - "@swc/core": ">=1.x", - "@swc/helpers": ">=0.2", - "rollup": ">=1.x || >=2.x", - "typescript": ">=3.2.x || >= 4.x" - }, - "peerDependenciesMeta": { - "@babel/core": { - "optional": true - }, - "@babel/plugin-transform-runtime": { - "optional": true - }, - "@babel/preset-env": { - "optional": true - }, - "@babel/preset-typescript": { - "optional": true - }, - "@babel/runtime": { - "optional": true - }, - "@swc/core": { - "optional": true - }, - "@swc/helpers": { - "optional": true - } - } - }, "node_modules/run-parallel": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", @@ -3368,6 +3018,20 @@ "url": "https://github.com/chalk/strip-ansi?sponsor=1" } }, + "node_modules/strip-final-newline": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-3.0.0.tgz", + "integrity": "sha512-dOESqjYr96iWYylGObzd39EuNTa5VJxyvVAEm5Jnh7KGo75V43Hk1odPQkNDyXNmUR6k+gEiDVXnjB8HJ3crXw==", + "dev": true, + "optional": true, + "peer": true, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/strip-json-comments": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", @@ -3429,18 +3093,6 @@ "node": ">=8" } }, - "node_modules/supports-preserve-symlinks-flag": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", - "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==", - "dev": true, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/temp-dir": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/temp-dir/-/temp-dir-3.0.0.tgz", @@ -3477,25 +3129,6 @@ "node": ">=8.0" } }, - "node_modules/ts-clone-node": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/ts-clone-node/-/ts-clone-node-2.0.4.tgz", - "integrity": "sha512-eG6FAgmQsenhIJOIFhUcO6yyYejBKZIKcI3y21jiQmIOrth5pD6GElyPAyeihbPSyBs3u/9PVNXy+5I7jGy8jA==", - "dev": true, - "dependencies": { - "compatfactory": "^2.0.9" - }, - "engines": { - "node": ">=14.9.0" - }, - "funding": { - "type": "github", - "url": "https://github.com/wessberg/ts-clone-node?sponsor=1" - }, - "peerDependencies": { - "typescript": "^3.x || ^4.x" - } - }, "node_modules/ts-node": { "version": "10.9.1", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.1.tgz", @@ -3591,65 +3224,16 @@ } }, "node_modules/typescript": { - "version": "4.9.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", - "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==", + "version": "5.0.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.4.tgz", + "integrity": "sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==", "dev": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" }, "engines": { - "node": ">=4.2.0" - } - }, - "node_modules/ua-parser-js": { - "version": "1.0.35", - "resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-1.0.35.tgz", - "integrity": "sha512-fKnGuqmTBnIE+/KXSzCn4db8RTigUzw1AN0DmdU6hJovUTbYJKyqj+8Mt1c4VfRDnOVJnENmfYkIPZ946UrSAA==", - "dev": true, - "funding": [ - { - "type": "opencollective", - "url": "https://opencollective.com/ua-parser-js" - }, - { - "type": "paypal", - "url": "https://paypal.me/faisalman" - } - ], - "engines": { - "node": "*" - } - }, - "node_modules/update-browserslist-db": { - "version": "1.0.11", - "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.0.11.tgz", - "integrity": "sha512-dCwEFf0/oT85M1fHBg4F0jtLwJrutGoHSQXCh7u4o2t1drG+c0a9Flnqww6XUKSfQMPpJBRjU8d4RXB09qtvaA==", - "dev": true, - "funding": [ - { - "type": "opencollective", - "url": "https://opencollective.com/browserslist" - }, - { - "type": "tidelift", - "url": "https://tidelift.com/funding/github/npm/browserslist" - }, - { - "type": "github", - "url": "https://github.com/sponsors/ai" - } - ], - "dependencies": { - "escalade": "^3.1.1", - "picocolors": "^1.0.0" - }, - "bin": { - "update-browserslist-db": "cli.js" - }, - "peerDependencies": { - "browserslist": ">= 4.21.0" + "node": ">=12.20" } }, "node_modules/uri-js": { diff --git a/package.json b/package.json index 2d8d424..227256a 100644 --- a/package.json +++ b/package.json @@ -29,55 +29,49 @@ }, "license": "MIT", "engines": { - "node": ">=14.0.0" + "node": ">=16.0.0" }, - "type": "commonjs", - "main": "./dist/cjs/index.js", - "module": "./dist/esm/index.js", - "types": "./dist/index.d.ts", + "type": "module", "exports": { "types": "./dist/index.d.ts", - "require": "./dist/cjs/index.js", - "import": "./dist/esm/index.js" + "import": "./dist/index.js" }, "files": [ "dist", "!dist/**/*.map" ], "scripts": { - "build": "rollup -c", - "watch": "rollup -cw", + "build": "tsc", + "watch": "tsc -w", "test": "ava", - "lint": "eslint src/index.ts", + "lint": "eslint source/index.ts", "clean": "rimraf dist", "prepublishOnly": "npm run lint && npm run clean && npm run build" }, "devDependencies": { - "@fast-check/ava": "^1.1.0", - "@rollup/plugin-commonjs": "^23.0.0", - "@rollup/plugin-node-resolve": "^15.0.0", - "@typescript-eslint/eslint-plugin": "^5.40.0", - "@typescript-eslint/parser": "^5.40.0", - "ava": "^5.0.1", - "eslint": "^8.25.0", - "fast-check": "^3.2.0", + "@fast-check/ava": "^1.1.4", + "@types/node": "^16.18.26", + "@typescript-eslint/eslint-plugin": "^5.59.2", + "@typescript-eslint/parser": "^5.59.2", + "ava": "^5.2.0", + "eslint": "^8.40.0", + "fast-check": "^3.8.1", "rimraf": "^3.0.2", - "rollup": "^3.0.0", - "rollup-plugin-ts": "^3.0.2", + "rollup": "^3.21.5", "ts-node": "^10.9.1", - "tslib": "^2.4.0", - "typescript": "^4.8.4" + "tslib": "^2.5.0", + "typescript": "^5.0.4" }, "peerDependencies": { - "rollup": "^2.60.0 || ^3.0.0" + "rollup": "^3.0.0" }, "ava": { "workerThreads": false, - "extensions": [ - "ts" - ], - "require": [ - "ts-node/register" + "extensions": { + "ts": "module" + }, + "nodeArguments": [ + "--loader=ts-node/esm" ] }, "np": { diff --git a/src/index.ts b/source/index.ts similarity index 97% rename from src/index.ts rename to source/index.ts index cbf81ef..5174a73 100644 --- a/src/index.ts +++ b/source/index.ts @@ -1,260 +1,260 @@ -import path from 'node:path' -import fs from 'node:fs/promises' -import { builtinModules } from 'node:module' -import type { Plugin } from 'rollup' - -type MaybeFalsy<T> = T | undefined | null | false -type MaybeArray<T> = T | T[] - -export interface ExternalsOptions { - - /** - * Mark node built-in modules like `path`, `fs`... as external. - * - * Defaults to `true`. - */ - builtins?: boolean - - /** - * node: prefix handing for importing Node builtins: - * - `'add'` turns `'path'` to `'node:path'` - * - `'strip'` turns `'node:path'` to `'path'` - * - `'ignore'` leave Node builtin names as-is - * - * Defaults to `add`. - */ - builtinsPrefix?: 'add' | 'strip' | 'ignore' - - /** - * Path/to/your/package.json file (or array of paths). - * - * Defaults to all package.json files found in parent directories recursively. - * Won't go outside of a git repository. - */ - packagePath?: string | string[] - - /** - * Mark dependencies as external. - * - * Defaults to `true`. - */ - deps?: boolean - - /** - * Mark devDependencies as external. - * - * Defaults to `false`. - */ - devDeps?: boolean - - /** - * Mark peerDependencies as external. - * - * Defaults to `true`. - */ - peerDeps?: boolean - - /** - * Mark optionalDependencies as external. - * - * Defaults to `true`. - */ - optDeps?: boolean - - /** - * Force include these deps in the list of externals, regardless of other settings. - * - * Defaults to `[]` (force include nothing) - */ - include?: MaybeArray<MaybeFalsy<string | RegExp>> - - /** - * Force exclude these deps from the list of externals, regardless of other settings. - * - * Defaults to `[]` (force exclude nothing) - */ - exclude?: MaybeArray<MaybeFalsy<string | RegExp>> -} - -// Listing only fields of interest in package.json -interface PackageJson { - dependencies?: Record<string, string> - devDependencies?: Record<string, string> - peerDependencies?: Record<string, string> - optionalDependencies?: Record<string, string> - workspaces?: string[] - packages?: string[] -} - -// Prepare node built-in modules lists. -const nodePrefix = 'node:' -const nodePrefixRx = /^node:/ -const builtins = { - all: new Set(builtinModules), - alwaysPrefixed: new Set( - builtinModules.filter(mod => nodePrefixRx.test(mod)) - ) -} - -const workspaceRootFiles = new Set([ - 'pnpm-workspace.yaml', // pnpm - 'lerna.json', // Lerna - // Note: is there any interest in the following? - // 'workspace.jsonc', // Bit - // 'nx.json', // Nx - // 'rush.json', // Rush -]) - -// Our defaults -type Config = Required<ExternalsOptions> - -const defaults: Config = { - builtins: true, - builtinsPrefix: 'add', - packagePath: [], - deps: true, - devDeps: false, - peerDeps: true, - optDeps: true, - include: [], - exclude: [] -} - -const isString = (str: unknown): str is string => - typeof str === 'string' && str.length > 0 - -/** - * A Rollup plugin that automatically declares NodeJS built-in modules, - * and optionally npm dependencies, as 'external'. - */ -function externals(options: ExternalsOptions = {}): Plugin { - - const config: Config = Object.assign(Object.create(null), defaults, options) - let include: RegExp[], - exclude: RegExp[] - const isIncluded = (id: string) => include.some(rx => rx.test(id)) - const isExcluded = (id: string) => exclude.some(rx => rx.test(id)) - - return { - name: 'node-externals', - - async buildStart() { - // Map the include and exclude options to arrays of regexes. - [ include, exclude ] = ([ 'include', 'exclude' ] as const).map(option => - ([] as Array<string | RegExp | null | undefined | false>) - .concat(config[option]) - .reduce((result, entry, index) => { - if (entry) { - if (entry instanceof RegExp) - result.push(entry) - else if (typeof entry === 'string') - result.push(new RegExp('^' + entry.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + '$')) - else { - this.warn(`Ignoring wrong entry type #${index} in '${option}' option: ${JSON.stringify(entry)}`) - } - } - return result - }, [] as RegExp[]) - ) - - // Prepare npm dependencies list. - const packageFiles: string[] = Array.isArray(config.packagePath) - ? config.packagePath.filter(isString) - : isString(config.packagePath) - ? [ config.packagePath ] - : [] - - // Populate packagePaths if not given by getting all package.json files - // from cwd up to the root of the git repo, the root of the monorepo, - // or the root of the volume, whichever comes first. - if (packageFiles.length === 0) { - for ( - let current = process.cwd(), previous: string | undefined; - previous !== current; - previous = current, current = path.dirname(current) - ) { - const entries = await fs.readdir(current, { withFileTypes: true }) - if (entries.some(entry => entry.name === 'package.json' && entry.isFile())) - packageFiles.push(path.join(current, 'package.json')) - - // Break early if this is a git repo root or a pnpm/lerna workspace root. - if (entries.some(entry => - (entry.name === '.git' && entry.isDirectory()) || - (workspaceRootFiles.has(entry.name) && entry.isFile()) - )) { - break - } - } - } - - // Gather dependencies names. - const dependencies: Record<string, string> = {} - for (const packageFile of packageFiles) { - try { - const json = (await fs.readFile(packageFile)).toString() - try { - const pkg: PackageJson = JSON.parse(json) - Object.assign(dependencies, - config.deps ? pkg.dependencies : undefined, - config.devDeps ? pkg.devDependencies : undefined, - config.peerDeps ? pkg.peerDependencies : undefined, - config.optDeps ? pkg.optionalDependencies : undefined - ) - - // Watch the file. - if (this.meta.watchMode) - this.addWatchFile(packageFile) - - // Break early if this is a npm/yarn workspace root. - if ('workspaces' in pkg || 'packages' in pkg) - break - } - catch { - this.error({ - message: `File ${JSON.stringify(packageFile)} does not look like a valid package.json file.`, - stack: undefined - }) - } - } - catch { - this.error({ - message: `Cannot read file ${JSON.stringify(packageFile)}`, - stack: undefined - }) - } - } - - const names = Object.keys(dependencies) - if (names.length > 0) - include.push(new RegExp('^(?:' + names.join('|') + ')(?:/.+)?$')) - }, - - async resolveId(id) { - // Let Rollup handle already resolved ids, relative imports and virtual modules. - if (path.isAbsolute(id) || /^(?:\0|\.{1,2}[\\/])/.test(id)) - return null - - // Handle node builtins. - if (id.startsWith(nodePrefix) || builtins.all.has(id)) { - const stripped = id.replace(nodePrefixRx, '') - return { - id: config.builtinsPrefix === 'ignore' - ? id - : config.builtinsPrefix === 'add' || builtins.alwaysPrefixed.has(id) - ? nodePrefix + stripped - : stripped, - external: config.builtins && !isExcluded(id), - moduleSideEffects: false - } - } - - // Handle npm dependencies. - return isIncluded(id) && !isExcluded(id) - ? false // external - : null // normal handling - } - } -} - -export default externals -export { externals } +import path from 'node:path' +import fs from 'node:fs/promises' +import { builtinModules } from 'node:module' +import type { Plugin } from 'rollup' + +type MaybeFalsy<T> = T | undefined | null | false +type MaybeArray<T> = T | T[] + +export interface ExternalsOptions { + + /** + * Mark node built-in modules like `path`, `fs`... as external. + * + * Defaults to `true`. + */ + builtins?: boolean + + /** + * node: prefix handing for importing Node builtins: + * - `'add'` turns `'path'` to `'node:path'` + * - `'strip'` turns `'node:path'` to `'path'` + * - `'ignore'` leave Node builtin names as-is + * + * Defaults to `add`. + */ + builtinsPrefix?: 'add' | 'strip' | 'ignore' + + /** + * Path/to/your/package.json file (or array of paths). + * + * Defaults to all package.json files found in parent directories recursively. + * Won't go outside of a git repository. + */ + packagePath?: string | string[] + + /** + * Mark dependencies as external. + * + * Defaults to `true`. + */ + deps?: boolean + + /** + * Mark devDependencies as external. + * + * Defaults to `false`. + */ + devDeps?: boolean + + /** + * Mark peerDependencies as external. + * + * Defaults to `true`. + */ + peerDeps?: boolean + + /** + * Mark optionalDependencies as external. + * + * Defaults to `true`. + */ + optDeps?: boolean + + /** + * Force include these deps in the list of externals, regardless of other settings. + * + * Defaults to `[]` (force include nothing) + */ + include?: MaybeArray<MaybeFalsy<string | RegExp>> + + /** + * Force exclude these deps from the list of externals, regardless of other settings. + * + * Defaults to `[]` (force exclude nothing) + */ + exclude?: MaybeArray<MaybeFalsy<string | RegExp>> +} + +// Listing only fields of interest in package.json +interface PackageJson { + dependencies?: Record<string, string> + devDependencies?: Record<string, string> + peerDependencies?: Record<string, string> + optionalDependencies?: Record<string, string> + workspaces?: string[] + packages?: string[] +} + +// Prepare node built-in modules lists. +const nodePrefix = 'node:' +const nodePrefixRx = /^node:/ +const builtins = { + all: new Set(builtinModules), + alwaysPrefixed: new Set( + builtinModules.filter(mod => nodePrefixRx.test(mod)) + ) +} + +const workspaceRootFiles = new Set([ + 'pnpm-workspace.yaml', // pnpm + 'lerna.json', // Lerna + // Note: is there any interest in the following? + // 'workspace.jsonc', // Bit + // 'nx.json', // Nx + // 'rush.json', // Rush +]) + +// Our defaults +type Config = Required<ExternalsOptions> + +const defaults: Config = { + builtins: true, + builtinsPrefix: 'add', + packagePath: [], + deps: true, + devDeps: false, + peerDeps: true, + optDeps: true, + include: [], + exclude: [] +} + +const isString = (str: unknown): str is string => + typeof str === 'string' && str.length > 0 + +/** + * A Rollup plugin that automatically declares NodeJS built-in modules, + * and optionally npm dependencies, as 'external'. + */ +function externals(options: ExternalsOptions = {}): Plugin { + + const config: Config = Object.assign(Object.create(null), defaults, options) + let include: RegExp[], + exclude: RegExp[] + const isIncluded = (id: string) => include.some(rx => rx.test(id)) + const isExcluded = (id: string) => exclude.some(rx => rx.test(id)) + + return { + name: 'node-externals', + + async buildStart() { + // Map the include and exclude options to arrays of regexes. + [ include, exclude ] = ([ 'include', 'exclude' ] as const).map(option => + ([] as Array<string | RegExp | null | undefined | false>) + .concat(config[option]) + .reduce((result, entry, index) => { + if (entry) { + if (entry instanceof RegExp) + result.push(entry) + else if (typeof entry === 'string') + result.push(new RegExp('^' + entry.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + '$')) + else { + this.warn(`Ignoring wrong entry type #${index} in '${option}' option: ${JSON.stringify(entry)}`) + } + } + return result + }, [] as RegExp[]) + ) + + // Prepare npm dependencies list. + const packageFiles: string[] = Array.isArray(config.packagePath) + ? config.packagePath.filter(isString) + : isString(config.packagePath) + ? [ config.packagePath ] + : [] + + // Populate packagePaths if not given by getting all package.json files + // from cwd up to the root of the git repo, the root of the monorepo, + // or the root of the volume, whichever comes first. + if (packageFiles.length === 0) { + for ( + let current = process.cwd(), previous: string | undefined; + previous !== current; + previous = current, current = path.dirname(current) + ) { + const entries = await fs.readdir(current, { withFileTypes: true }) + if (entries.some(entry => entry.name === 'package.json' && entry.isFile())) + packageFiles.push(path.join(current, 'package.json')) + + // Break early if this is a git repo root or a pnpm/lerna workspace root. + if (entries.some(entry => + (entry.name === '.git' && entry.isDirectory()) || + (workspaceRootFiles.has(entry.name) && entry.isFile()) + )) { + break + } + } + } + + // Gather dependencies names. + const dependencies: Record<string, string> = {} + for (const packageFile of packageFiles) { + try { + const json = (await fs.readFile(packageFile)).toString() + try { + const pkg: PackageJson = JSON.parse(json) + Object.assign(dependencies, + config.deps ? pkg.dependencies : undefined, + config.devDeps ? pkg.devDependencies : undefined, + config.peerDeps ? pkg.peerDependencies : undefined, + config.optDeps ? pkg.optionalDependencies : undefined + ) + + // Watch the file. + if (this.meta.watchMode) + this.addWatchFile(packageFile) + + // Break early if this is a npm/yarn workspace root. + if ('workspaces' in pkg || 'packages' in pkg) + break + } + catch { + this.error({ + message: `File ${JSON.stringify(packageFile)} does not look like a valid package.json file.`, + stack: undefined + }) + } + } + catch { + this.error({ + message: `Cannot read file ${JSON.stringify(packageFile)}`, + stack: undefined + }) + } + } + + const names = Object.keys(dependencies) + if (names.length > 0) + include.push(new RegExp('^(?:' + names.join('|') + ')(?:/.+)?$')) + }, + + async resolveId(id) { + // Let Rollup handle already resolved ids, relative imports and virtual modules. + if (path.isAbsolute(id) || /^(?:\0|\.{1,2}[\\/])/.test(id)) + return null + + // Handle node builtins. + if (id.startsWith(nodePrefix) || builtins.all.has(id)) { + const stripped = id.replace(nodePrefixRx, '') + return { + id: config.builtinsPrefix === 'ignore' + ? id + : config.builtinsPrefix === 'add' || builtins.alwaysPrefixed.has(id) + ? nodePrefix + stripped + : stripped, + external: config.builtins && !isExcluded(id), + moduleSideEffects: false + } + } + + // Handle npm dependencies. + return isIncluded(id) && !isExcluded(id) + ? false // external + : null // normal handling + } + } +} + +export default externals +export { externals } diff --git a/test/_common.ts b/test/_common.ts index bb44429..78ae72f 100644 --- a/test/_common.ts +++ b/test/_common.ts @@ -1,6 +1,9 @@ import path from 'node:path' +import { fileURLToPath } from 'node:url' import type { Plugin, RollupError, ObjectHook } from 'rollup' -import { externals, type ExternalsOptions } from '../src/index' +import { externals, type ExternalsOptions } from '../source/index.js' + +const __dirname = path.dirname(fileURLToPath(import.meta.url)) const warnings: string[] = [] const fakePluginContext = { diff --git a/test/builtins.test.ts b/test/builtins.test.ts index 783be75..6db5ae2 100644 --- a/test/builtins.test.ts +++ b/test/builtins.test.ts @@ -1,5 +1,5 @@ import test from 'ava' -import { initPlugin, callHook } from './_common' +import { initPlugin, callHook } from './_common.js' test("Adds 'node:' prefix to builtins by default", async t => { const { plugin } = await initPlugin() diff --git a/test/monorepo.test.ts b/test/monorepo.test.ts index 7a8431c..2d3f0a3 100644 --- a/test/monorepo.test.ts +++ b/test/monorepo.test.ts @@ -1,6 +1,6 @@ import fs from 'node:fs/promises' import test from 'ava' -import { initPlugin, callHook, fixture } from './_common' +import { initPlugin, callHook, fixture } from './_common.js' // These two tests need to be run in sequence test.serial('git monorepo usage', async t => { diff --git a/test/options.test.ts b/test/options.test.ts index 02ddf1a..0d400ce 100644 --- a/test/options.test.ts +++ b/test/options.test.ts @@ -1,8 +1,8 @@ import test from 'ava' import { testProp, fc } from '@fast-check/ava' import type { Arbitrary } from 'fast-check' -import { initPlugin, callHook, fixture } from './_common' -import { type ExternalsOptions } from '../src/index' +import { initPlugin, callHook, fixture } from './_common.js' +import { type ExternalsOptions } from '../source/index.js' // Ensures tests use local package.json process.chdir(fixture()) @@ -11,7 +11,7 @@ process.chdir(fixture()) const externalsOptionsArbitrary = (): Arbitrary<ExternalsOptions> => fc.record({ packagePath: fc.string(), builtins: fc.boolean(), - builtinsPrefix: fc.oneof(fc.constant<'strip'>('strip'), fc.constant<'add'>('add')), + builtinsPrefix: fc.oneof(fc.constant<'strip'>('strip'), fc.constant<'add'>('add'), fc.constant<'ignore'>('ignore')), deps: fc.boolean(), devDeps: fc.boolean(), peerDeps: fc.boolean(), diff --git a/test/specifier.test.ts b/test/specifier.test.ts index 2d78926..acae1f4 100644 --- a/test/specifier.test.ts +++ b/test/specifier.test.ts @@ -1,5 +1,5 @@ import test from 'ava' -import { initPlugin, callHook, noDepsAtAllOptions } from './_common' +import { initPlugin, callHook, noDepsAtAllOptions } from './_common.js' test("Does NOT filter out relative specifiers by default", async t => { const relativeSpecifiers = [ './sibling.js', '../parent.js' ] diff --git a/test/workspaces.test.ts b/test/workspaces.test.ts index cd746dd..ecc70b3 100644 --- a/test/workspaces.test.ts +++ b/test/workspaces.test.ts @@ -1,5 +1,5 @@ import test from 'ava' -import { initPlugin, callHook, fixture } from './_common' +import { initPlugin, callHook, fixture } from './_common.js' test('npm/yarn workspaces usage', async t => { process.chdir(fixture('02_workspaces/npm-and-yarn/one')) diff --git a/tsconfig.json b/tsconfig.json index 0ca5afa..e0d89a9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,27 +1,25 @@ { "files": [ - "src/index.ts" + "source/index.ts" ], "compilerOptions": { // Lib - "lib": [ "es2020" ], + "lib": [ "ESNext" ], + "skipLibCheck": true, "skipDefaultLibCheck": true, // Input "moduleResolution": "Node16", - "resolveJsonModule": true, - "esModuleInterop": true, "allowSyntheticDefaultImports": true, // Output - "outDir": "out", - "target": "es2020", - "module": "CommonJS", + "outDir": "dist", + "target": "ESNext", + "module": "ESNext", "declaration": true, - "declarationMap": false, + "declarationMap": true, "sourceMap": true, - "stripInternal": true, // Type checkings "strict": true, @@ -30,6 +28,5 @@ "noUnusedParameters": false, "noPropertyAccessFromIndexSignature": true, "noUncheckedIndexedAccess": false, - // "exactOptionalPropertyTypes": true, } }