-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Publish both esm and cjs. Also, default types to browser fetch.
- Loading branch information
1 parent
141068d
commit cbe0f25
Showing
8 changed files
with
78 additions
and
43 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ package-lock.json | |
.DS_Store | ||
dist | ||
docs | ||
*.tsbuildinfo | ||
types |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,19 +2,48 @@ | |
"name": "native-fetch", | ||
"version": "4.0.0", | ||
"description": "Returns native fetch if available or the undici module if not", | ||
"main": "src/index.js", | ||
"types": "dist/src/index.d.ts", | ||
"type": "module", | ||
"files": [ | ||
"src", | ||
"dist" | ||
"*", | ||
"!**/*.tsbuildinfo" | ||
], | ||
"publishConfig": { | ||
"directory": "dist" | ||
}, | ||
"exports": { | ||
".": { | ||
"browser": "./src/index.js", | ||
"import": "./src/index-node.js" | ||
} | ||
}, | ||
"types": "./types/index.d.ts", | ||
"typesVersions": { | ||
"*": { | ||
"src/*": [ | ||
"types/src/*", | ||
"types/src/*/index" | ||
] | ||
} | ||
}, | ||
"eslintConfig": { | ||
"extends": "ipfs", | ||
"parserOptions": { | ||
"sourceType": "module" | ||
} | ||
}, | ||
"scripts": { | ||
"test": "aegir test -t node -t browser -t webworker -t electron-main -t electron-renderer", | ||
"lint": "aegir lint && aegir ts -p check", | ||
"build": "aegir build --no-bundle", | ||
"release": "aegir release --docs false", | ||
"release-minor": "aegir release --type minor --docs false", | ||
"release-major": "aegir release --type major --docs false" | ||
"pretest": "npm run build", | ||
"test": "npm run test:node && npm run test:browser && npm run test:electron-main && npm run test:electron-renderer", | ||
"test:node": "aegir test -t node", | ||
"test:browser": "aegir test -t browser", | ||
"test:electron-main": "aegir build --esm-tests && aegir test -t electron-main -f ./dist/cjs/node-test/**/*.spec.js", | ||
"test:electron-renderer": "aegir build --esm-tests && aegir test -t electron-renderer -f ./dist/cjs/browser-test/**/*.spec.js", | ||
"lint": "aegir ts -p check && aegir lint", | ||
"release": "aegir release --docs", | ||
"release-minor": "aegir release --target node --type minor --docs", | ||
"release-major": "aegir release --type major --docs", | ||
"build": "aegir build", | ||
"dep-check": "aegir dep-check dist/src/**/*.js dist/test/**/*.js" | ||
}, | ||
"author": "Alex Potsides <[email protected]>", | ||
"license": "MIT", | ||
|
@@ -27,7 +56,8 @@ | |
}, | ||
"devDependencies": { | ||
"aegir": "^36.0.0", | ||
"undici": "^4.10.0" | ||
"undici": "^4.10.0", | ||
"native-fetch": "./dist" | ||
}, | ||
"contributors": [ | ||
"achingbrain <[email protected]>" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import * as undici from 'undici' | ||
|
||
export const fetch = globalThis.fetch ? globalThis.fetch : undici.fetch | ||
export const Headers = globalThis.Headers ? globalThis.Headers : undici.Headers | ||
export const Request = globalThis.Request ? globalThis.Request : undici.Request | ||
export const Response = globalThis.Response ? globalThis.Response : undici.Response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,9 @@ | ||
'use strict' | ||
const globalFetch = globalThis.fetch | ||
const globalHeaders = globalThis.Headers | ||
const globalRequest = globalThis.Request | ||
const globalResponse = globalThis.Response | ||
|
||
// @ts-expect-error globalThis.fetch is defined according to the env types but it's not in node | ||
if (globalThis.fetch && globalThis.Headers && globalThis.Request && globalThis.Response) { | ||
module.exports = { | ||
fetch: globalThis.fetch, | ||
Headers: globalThis.Headers, | ||
Request: globalThis.Request, | ||
Response: globalThis.Response | ||
} | ||
} else { | ||
module.exports = { | ||
fetch: require('undici').fetch, | ||
Headers: require('undici').Headers, | ||
Request: require('undici').Request, | ||
Response: require('undici').Response | ||
} | ||
} | ||
export { globalFetch as fetch } | ||
export { globalHeaders as Headers } | ||
export { globalRequest as Request } | ||
export { globalResponse as Response } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
{ | ||
"extends": "aegir/src/config/tsconfig.aegir.json", | ||
"compilerOptions": { | ||
"outDir": "dist" | ||
"outDir": "types" | ||
}, | ||
"include": [ | ||
"src", | ||
"test" | ||
"src" | ||
], | ||
"exclude": [ | ||
"dist" | ||
] | ||
} |