-
Notifications
You must be signed in to change notification settings - Fork 31
convert to esm #265
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
Closed
Closed
convert to esm #265
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
8e64039
convert to esm and bump dependencies so it works with esm
e9dba3a
formatting
9bed611
remove lockfile
dce478c
remove .vscode folder
7415bbd
fix fetch.browser.js incorrect import and try to make aegir esbuild work
b288b13
Merge branch 'master' of https://github.com/ipfs/js-ipfs-utils into m…
talentlessguy 0856a23
chore: remove redundant fetch polyfills, wip fetch progress rewrite
talentlessguy 098b385
fix: make electron tests pass!!
talentlessguy 86e04e0
chore: remove it-to-stream
talentlessguy 57db545
chore: require node 18.x
talentlessguy d42ebca
chore: install mocha as a dev dep and fix tests on chrome
talentlessguy 5851e54
chore: make tests pass on all environments, at alst
talentlessguy 36dbdce
chore: remove native-fetch
talentlessguy b9356a1
chore: fmt
talentlessguy 3747a0a
Update src/env.js
talentlessguy addf98b
chore: code-review
talentlessguy a6ce74b
chore: bump dependencies
talentlessguy c65e482
Merge branch 'move-to-esm' of https://github.com/talentlessguy/js-ipf…
talentlessguy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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,5 +1,6 @@ | ||
package-lock.json | ||
yarn.lock | ||
pnpm-lock.yaml | ||
# Logs | ||
logs | ||
*.log | ||
|
This file contains hidden or 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 @@ | ||
export { Buffer } from 'buffer' |
This file contains hidden or 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 hidden or 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,5 +1,3 @@ | ||
'use strict' | ||
|
||
module.exports = { | ||
require: require.resolve('./rn-test.require.js'), | ||
runner: 'mocha', | ||
|
This file contains hidden or 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 hidden or 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,29 +1,19 @@ | ||
'use strict' | ||
const isElectron = require('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 | ||
|
||
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 | ||
// @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 | ||
} | ||
|
This file contains hidden or 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,4 @@ | ||
'use strict' | ||
const { fetch, Request, Response, Headers } = globalThis | ||
|
||
/** | ||
* @typedef {globalThis.Headers} Headers | ||
* @typedef {globalThis.Request} Request | ||
* @typedef {globalThis.Response} Response | ||
*/ | ||
|
||
// 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 } |
This file contains hidden or 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,25 @@ | ||
'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' | ||
const fetchImpl = isElectronMain | ||
? await import('electron-fetch') | ||
: { | ||
default: globalThis.fetch, | ||
Request: globalThis.Request, | ||
Response: globalThis.Response, | ||
Headers: globalThis.Headers | ||
} | ||
|
||
if (isElectronMain) { | ||
impl = 'electron-fetch' | ||
} | ||
export const fetch = fetchImpl.default | ||
export const Request = fetchImpl.Request | ||
/** @type {typeof globalThis.Response} */ | ||
// @ts-expect-error | ||
export const Response = fetchImpl.Response | ||
export const Headers = fetchImpl.Headers | ||
|
||
module.exports = require(impl) | ||
export default fetch |
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
According to the
npm
package-lock.json
description, the package manager manifest is meant to be included in source control.It's how someone else building the project can guarantee they get the same versions of libraries that were used.
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.
I'm aware of that, though there were other lockfilels in gitignore so I decided not to touch it. Also because i'm using
pnpm
and someone else would use something else.