-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
convert to esm #265
base: master
Are you sure you want to change the base?
convert to esm #265
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,10 +13,16 @@ | |
"url": "https://github.com/ipfs/js-ipfs-utils/issues" | ||
}, | ||
"engines": { | ||
"node": ">=16.0.0", | ||
"node": ">=16.8.0", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
"npm": ">=7.0.0" | ||
}, | ||
"main": "src/index.js", | ||
"type": "module", | ||
"exports": { | ||
".": { | ||
"types": "./dist/src/index.d.ts", | ||
"import": "./dist/src/index.js" | ||
} | ||
}, | ||
"types": "dist/src/index.d.ts", | ||
"typesVersions": { | ||
"*": { | ||
|
@@ -39,7 +45,11 @@ | |
"eslintConfig": { | ||
"extends": "ipfs", | ||
"env": { | ||
"worker": true | ||
"worker": true, | ||
"es6": true | ||
}, | ||
"parserOptions": { | ||
"sourceType": "module" | ||
} | ||
}, | ||
"release": { | ||
|
@@ -155,14 +165,16 @@ | |
"it-to-stream": "^1.0.0", | ||
"merge-options": "^3.0.4", | ||
"nanoid": "^3.1.20", | ||
"native-fetch": "^3.0.0", | ||
"native-fetch": "^4.0.2", | ||
"node-fetch": "^2.6.8", | ||
"react-native-fetch-api": "^3.0.0", | ||
"stream-to-it": "^0.2.2" | ||
"stream-to-it": "^0.2.2", | ||
"undici": "^5.21.0" | ||
}, | ||
"devDependencies": { | ||
"aegir": "^36.1.1", | ||
"aegir": "^38.1.7", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to support es module in testing |
||
"delay": "^5.0.0", | ||
"eslint-plugin-n": "^15.6.1", | ||
"events": "^3.3.0", | ||
"ipfs-unixfs": "^6.0.4", | ||
"it-drain": "^1.0.3", | ||
|
@@ -171,6 +183,7 @@ | |
"react-native-polyfill-globals": "^3.0.0", | ||
"readable-stream": "^4.3.0", | ||
"uint8arrays": "^3.0.0", | ||
"url": "^0.11.0", | ||
"util": "^0.12.3" | ||
}, | ||
"browser": { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
'use strict' | ||
|
||
module.exports = { | ||
require: require.resolve('./rn-test.require.js'), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,22 @@ | ||
'use strict' | ||
const isElectron = require('is-electron') | ||
|
||
const IS_ENV_WITH_DOM = typeof window === 'object' && typeof document === 'object' && document.nodeType === 9 | ||
// @ts-ignore | ||
const IS_ELECTRON = isElectron() | ||
const IS_BROWSER = IS_ENV_WITH_DOM && !IS_ELECTRON | ||
const IS_ELECTRON_MAIN = IS_ELECTRON && !IS_ENV_WITH_DOM | ||
const IS_ELECTRON_RENDERER = IS_ELECTRON && IS_ENV_WITH_DOM | ||
const IS_NODE = typeof require === 'function' && typeof process !== 'undefined' && typeof process.release !== 'undefined' && process.release.name === 'node' && !IS_ELECTRON | ||
import isElectronFn from 'is-electron' | ||
const isEnvWithDom = typeof window === 'object' && typeof document === 'object' && document.nodeType === 9 | ||
const isElectron = isElectronFn() | ||
const isBrowser = isEnvWithDom && !isElectron | ||
const isElectronMain = isElectron && !isEnvWithDom | ||
const isElectronRenderer = isElectron && isEnvWithDom | ||
const isNode = typeof process !== 'undefined' && typeof process.release !== 'undefined' && process.release.name === 'node' && !isElectron | ||
// @ts-ignore - we either ignore worker scope or dom scope | ||
const IS_WEBWORKER = typeof importScripts === 'function' && typeof self !== 'undefined' && typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope | ||
const IS_TEST = typeof process !== 'undefined' && typeof process.env !== 'undefined' && process.env.NODE_ENV === 'test' | ||
const IS_REACT_NATIVE = typeof navigator !== 'undefined' && navigator.product === 'ReactNative' | ||
|
||
module.exports = { | ||
isTest: IS_TEST, | ||
isElectron: IS_ELECTRON, | ||
isElectronMain: IS_ELECTRON_MAIN, | ||
isElectronRenderer: IS_ELECTRON_RENDERER, | ||
isNode: IS_NODE, | ||
const isWebWorker = typeof importScripts === 'function' && typeof self !== 'undefined' && typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope | ||
const isTest = typeof process !== 'undefined' && typeof process.env !== 'undefined' && process.env.NODE_ENV === 'test' | ||
const isReactNative = typeof navigator !== 'undefined' && navigator.product === 'ReactNative' | ||
export { | ||
isTest, isElectron, isElectronMain, isElectronRenderer, isNode, | ||
/** | ||
* Detects browser main thread **NOT** web worker or service worker | ||
*/ | ||
isBrowser: IS_BROWSER, | ||
isWebWorker: IS_WEBWORKER, | ||
isEnvWithDom: IS_ENV_WITH_DOM, | ||
isReactNative: IS_REACT_NATIVE | ||
isBrowser, isWebWorker, isEnvWithDom, isReactNative | ||
} | ||
|
||
export default { | ||
isTest, isElectron, isElectronMain, isElectronRenderer, isNode, isBrowser, isWebWorker, isEnvWithDom, isReactNative | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
'use strict' | ||
|
||
/** | ||
* @typedef {globalThis.Headers} Headers | ||
* @typedef {globalThis.Request} Request | ||
* @typedef {globalThis.Response} Response | ||
*/ | ||
|
||
import { fetch, Request, Response, Headers } from 'native-fetch' | ||
|
||
// use window.fetch if it is available, fall back to node-fetch if not | ||
module.exports = require('native-fetch') | ||
export default fetch | ||
export { Request, Response, Headers } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,22 @@ | ||
'use strict' | ||
|
||
/** | ||
* @typedef {globalThis.Headers} Headers | ||
* @typedef {globalThis.Request} Request | ||
* @typedef {globalThis.Response} Response | ||
*/ | ||
|
||
const { isElectronMain } = require('./env') | ||
|
||
import { isElectronMain } from './env.js' | ||
// use window.fetch if it is available, fall back to node-fetch if not | ||
let impl = 'native-fetch' | ||
|
||
if (isElectronMain) { | ||
impl = 'electron-fetch' | ||
} | ||
|
||
module.exports = require(impl) | ||
const fetchImpl = await import(impl) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. replace dynamic |
||
|
||
export const fetch = fetchImpl.fetch | ||
export const Request = fetchImpl.Request | ||
export const Response = fetchImpl.Response | ||
export const Headers = fetchImpl.Headers | ||
|
||
export default fetch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
atm it fails bc of esbuild:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason might be this: evanw/esbuild#2780 or this: hugomrdias/playwright-test#530