Skip to content
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

fix: issues with using in ESM webui #356

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 15 additions & 7 deletions src/bundles/explore.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,24 @@ async function getIpld () {
import(/* webpackChunkName: "ipld" */ '@ipld/dag-cbor'),
import(/* webpackChunkName: "ipld" */ '@ipld/dag-pb'),
import(/* webpackChunkName: "ipld" */ 'ipld-git'),
import(/* webpackChunkName: "ipld" */ 'ipld-raw'),
import(/* webpackChunkName: "ipld" */ 'ipld-ethereum')
import(/* webpackChunkName: "ipld" */ 'ipld-raw')
])

// CommonJs exports object is .default when imported ESM style
const [ipld, ...formats] = ipldDeps.map(mod => mod.default)
const [ipld, ...formatImports] = ipldDeps.map(mod => {
// CommonJs exports object is .default when imported ESM style
const actualModule = mod.default ?? mod
return actualModule
})
SgtPooki marked this conversation as resolved.
Show resolved Hide resolved
const formats = formatImports.map((actualModule) => {
if (actualModule.util == null) {
// actualModule has no util. using blockcodec-to-ipld-format
return convert(actualModule)
}
return actualModule
SgtPooki marked this conversation as resolved.
Show resolved Hide resolved
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this convert method handle if util exists or not?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it cannot, unfortunately. though it probably should do some assertion on the format and return untouched if it matches the expected format.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


// ipldEthereum is an Object, each key points to a ipld format impl
const ipldEthereum = formats.pop()
formats.push(...Object.values(ipldEthereum))
const ipldEthereum = await import(/* webpackChunkName: "ipld" */ 'ipld-ethereum')
formats.push(...Object.values(ipldEthereum.default ?? ipldEthereum))

// ipldJson uses the new format, use the conversion tool
const ipldJson = await import(/* webpackChunkName: "ipld" */ '@ipld/dag-json')
Expand Down
3 changes: 3 additions & 0 deletions src/components/object-info/ObjectInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { withTranslation } from 'react-i18next'
import { ObjectInspector, chromeLight } from '@tableflip/react-inspector'
import filesize from 'filesize'
import LinksTable from './LinksTable'
import { decodeCid } from '../cid-info/decode-cid'
const humansize = filesize.partial({ round: 0 })

const objectInspectorTheme = {
Expand Down Expand Up @@ -63,6 +64,8 @@ const DagNodeIcon = ({ type, ...props }) => (
)

const ObjectInfo = ({ t, tReady, className, type, cid, localPath, size, data, links, format, onLinkClick, gatewayUrl, publicGatewayUrl, ...props }) => {
const cidInfo = decodeCid(cid)
type = cidInfo.cid.codec ?? type
SgtPooki marked this conversation as resolved.
Show resolved Hide resolved
return (
<section className={`pa4 sans-serif ${className}`} {...props}>
<h2 className='ma0 lh-title f4 fw4 montserrat pb2' title={type}>
Expand Down