diff --git a/README.md b/README.md index 127d1204..64435c9d 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Import: // ESM / Typescript import { $fetch } from 'ohmyfetch' -// CommonJS +// CommonJS (only $fetch export is available) const { $fetch } = require('ohmyfetch') ``` diff --git a/build.config.ts b/build.config.ts index a8d886d4..54096eae 100644 --- a/build.config.ts +++ b/build.config.ts @@ -2,6 +2,7 @@ import { defineBuildConfig } from 'unbuild' export default defineBuildConfig({ declaration: true, + emitCJS: false, entries: [ 'src/index', 'src/node' diff --git a/cjs/index.cjs b/cjs/index.cjs new file mode 100644 index 00000000..83b4d3ab --- /dev/null +++ b/cjs/index.cjs @@ -0,0 +1,3 @@ +exports.$fetch = (...args) => import('../dist/index.mjs') + .then(r => r.$fetch) + .then($fetch => $fetch(...args)) diff --git a/cjs/node.cjs b/cjs/node.cjs new file mode 100644 index 00000000..77e46efb --- /dev/null +++ b/cjs/node.cjs @@ -0,0 +1,3 @@ +exports.$fetch = (...args) => import('../dist/node.mjs') + .then(r => r.$fetch) + .then($fetch => $fetch(...args)) diff --git a/package.json b/package.json index 04d816ed..af43fb71 100644 --- a/package.json +++ b/package.json @@ -9,23 +9,24 @@ ".": { "node": { "import": "./dist/node.mjs", - "require": "./dist/node.cjs" + "require": "./cjs/node.cjs" }, "default": { "import": "./dist/index.mjs", - "require": "./dist/index.cjs" + "require": "./cjs/index.cjs" } }, "./node": { "import": "./dist/node.mjs", - "require": "./dist/node.cjs" + "require": "./cjs/node.cjs" } }, - "main": "./dist/node.cjs", + "main": "./cjs/node.cjs", "module": "./dist/index.mjs", "types": "./dist/index.d.ts", "files": [ - "dist" + "dist", + "cjs" ], "scripts": { "build": "unbuild", @@ -37,7 +38,7 @@ }, "dependencies": { "destr": "^1.1.0", - "node-fetch": "^2.6.1", + "node-fetch": "^3.0.0", "ufo": "^0.7.9" }, "devDependencies": { @@ -45,7 +46,7 @@ "@types/flat": "latest", "@types/jest": "latest", "@types/node": "latest", - "@types/node-fetch": "^2.5.12", + "@types/node-fetch": "^3.0.3", "eslint": "^7", "h3": "latest", "jest": "latest", diff --git a/yarn.lock b/yarn.lock index 5406f428..15a19924 100644 --- a/yarn.lock +++ b/yarn.lock @@ -761,13 +761,12 @@ resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.2.tgz#ee771e2ba4b3dc5b372935d549fd9617bf345b8c" integrity sha512-jhuKLIRrhvCPLqwPcx6INqmKeiA5EWrsCOPhrlFSrbrmU4ZMPjj5Ul/oLCMDO98XRUIwVm78xICz4EPCektzeQ== -"@types/node-fetch@^2.5.12": - version "2.5.12" - resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.5.12.tgz#8a6f779b1d4e60b7a57fb6fd48d84fb545b9cc66" - integrity sha512-MKgC4dlq4kKNa/mYrwpKfzQMB5X3ee5U6fSprkKpToBqBmX4nFZL9cW5jl6sWn+xpRJ7ypWh2yyqqr8UUCstSw== +"@types/node-fetch@^3.0.3": + version "3.0.3" + resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-3.0.3.tgz#9d969c9a748e841554a40ee435d26e53fa3ee899" + integrity sha512-HhggYPH5N+AQe/OmN6fmhKmRRt2XuNJow+R3pQwJxOOF9GuwM7O2mheyGeIrs5MOIeNjDEdgdoyHBOrFeJBR3g== dependencies: - "@types/node" "*" - form-data "^3.0.0" + node-fetch "*" "@types/node@*", "@types/node@latest": version "16.11.3" @@ -1568,6 +1567,11 @@ dargs@^7.0.0: resolved "https://registry.yarnpkg.com/dargs/-/dargs-7.0.0.tgz#04015c41de0bcb69ec84050f3d9be0caf8d6d5cc" integrity sha512-2iy1EkLdlBzQGvbweYRFxmFath8+K7+AKB0TlhHWkNuH+TmovaMH/Wp7V7R4u7f4SnX3OgLsU9t1NI9ioDnUpg== +data-uri-to-buffer@^3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/data-uri-to-buffer/-/data-uri-to-buffer-3.0.1.tgz#594b8973938c5bc2c33046535785341abc4f3636" + integrity sha512-WboRycPNsVw3B3TL559F7kuBUM4d8CgMEvk6xEJlOp7OBPjt6G7z8WMWlD2rOFZLk6OYfFIUGsCOWzcQH9K2og== + data-urls@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/data-urls/-/data-urls-2.0.0.tgz#156485a72963a970f5d5821aaf642bef2bf2db9b" @@ -2275,6 +2279,13 @@ fb-watchman@^2.0.0: dependencies: bser "2.1.1" +fetch-blob@^3.1.2: + version "3.1.2" + resolved "https://registry.yarnpkg.com/fetch-blob/-/fetch-blob-3.1.2.tgz#6bc438675f3851ecea51758ac91f6a1cd1bacabd" + integrity sha512-hunJbvy/6OLjCD0uuhLdp0mMPzP/yd2ssd1t2FCJsaA7wkWhpbp9xfuNVpv7Ll4jFhzp6T4LAupSiV9uOeg0VQ== + dependencies: + web-streams-polyfill "^3.0.3" + figures@^3.1.0: version "3.2.0" resolved "https://registry.yarnpkg.com/figures/-/figures-3.2.0.tgz#625c18bd293c604dc4a8ddb2febf0c88341746af" @@ -3791,12 +3802,13 @@ nice-try@^1.0.4: resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366" integrity sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ== -node-fetch@^2.6.1: - version "2.6.5" - resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.5.tgz#42735537d7f080a7e5f78b6c549b7146be1742fd" - integrity sha512-mmlIVHJEu5rnIxgEgez6b9GgWXbkZj5YZ7fx+2r94a2E+Uirsp6HsPTPlomfdHtpt/B0cdKviwkoaM6pyvUOpQ== +node-fetch@*, node-fetch@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-3.0.0.tgz#79da7146a520036f2c5f644e4a26095f17e411ea" + integrity sha512-bKMI+C7/T/SPU1lKnbQbwxptpCrG9ashG+VkytmXCPZyuM9jB6VU+hY0oi4lC8LxTtAeWdckNCTa3nrGsAdA3Q== dependencies: - whatwg-url "^5.0.0" + data-uri-to-buffer "^3.0.1" + fetch-blob "^3.1.2" node-forge@^0.10.0: version "0.10.0" @@ -4814,11 +4826,6 @@ tr46@^2.1.0: dependencies: punycode "^2.1.1" -tr46@~0.0.3: - version "0.0.3" - resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a" - integrity sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o= - trim-newlines@^3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/trim-newlines/-/trim-newlines-3.0.1.tgz#260a5d962d8b752425b32f3a7db0dcacd176c144" @@ -5054,10 +5061,10 @@ walker@^1.0.7: dependencies: makeerror "1.0.x" -webidl-conversions@^3.0.0: - version "3.0.1" - resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871" - integrity sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE= +web-streams-polyfill@^3.0.3: + version "3.1.1" + resolved "https://registry.yarnpkg.com/web-streams-polyfill/-/web-streams-polyfill-3.1.1.tgz#1516f2d4ea8f1bdbfed15eb65cb2df87098c8364" + integrity sha512-Czi3fG883e96T4DLEPRvufrF2ydhOOW1+1a6c3gNjH2aIh50DNFBdfwh2AKoOf1rXvpvavAoA11Qdq9+BKjE0Q== webidl-conversions@^5.0.0: version "5.0.0" @@ -5081,14 +5088,6 @@ whatwg-mimetype@^2.3.0: resolved "https://registry.yarnpkg.com/whatwg-mimetype/-/whatwg-mimetype-2.3.0.tgz#3d4b1e0312d2079879f826aff18dbeeca5960fbf" integrity sha512-M4yMwr6mAnQz76TbJm914+gPpB/nCwvZbJU28cUD6dR004SAxDLOOSUaB1JDRqLtaOV/vi0IC5lEAGFgrjGv/g== -whatwg-url@^5.0.0: - version "5.0.0" - resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d" - integrity sha1-lmRU6HZUYuN2RNNib2dCzotwll0= - dependencies: - tr46 "~0.0.3" - webidl-conversions "^3.0.0" - whatwg-url@^8.0.0, whatwg-url@^8.5.0: version "8.7.0" resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-8.7.0.tgz#656a78e510ff8f3937bc0bcbe9f5c0ac35941b77"