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 3 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.

33 changes: 26 additions & 7 deletions src/bundles/explore.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ const makeBundle = () => {
IpldResolver = ipld
ipldFormats = formats
}
console.log('IpldResolver: ', IpldResolver)
console.log('ipldFormats: ', ipldFormats)
console.log('getIpfs: ', getIpfs)
const ipld = makeIpld(IpldResolver, ipldFormats, getIpfs)
console.log('ipld: ', ipld)
// TODO: handle ipns, which would give us a fqdn in the cid position.
const cid = new Cid(cidOrFqdn)
const {
Expand Down Expand Up @@ -185,20 +189,35 @@ 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.name != null && actualModule.code != null && actualModule.codec == null) {
// // fix throw new Error(`Resolver already exists for codec "${codecName}"`) from ipld when `codecName` is undefined
// actualModule.codec = actualModule.code
// }
SgtPooki marked this conversation as resolved.
Show resolved Hide resolved
if (actualModule.util == null) {
// actualModule has no util. using blockcodec-to-ipld-format
const convertedModule = convert(actualModule)
console.log('convertedModule: ', convertedModule)
return convertedModule
}
return actualModule
SgtPooki marked this conversation as resolved.
Show resolved Hide resolved
})

// 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')
formats.push(convert(ipldJson))
console.log('formats: ', formats)

return { ipld, formats }
}
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