Skip to content

Commit 5db8673

Browse files
chore: switch to ESM (#161)
Co-authored-by: Alex Potsides <[email protected]>
1 parent 532a15b commit 5db8673

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+452
-494
lines changed

.travis.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ jobs:
8787
name: electron main
8888
addons:
8989
firefox: latest
90-
script: npm run test -- -- -- -t electron-main
90+
script:
91+
- npm run build
92+
- npx lerna link # use publishConfig.directory
93+
- npm run test -- -- -- -t electron-main -f dist/cjs/node-test/*js
9194

9295
- stage: release
9396
# only run on changes to master
File renamed without changes.

packages/ipfs-unixfs-exporter/package.json

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
"description": "JavaScript implementation of the UnixFs exporter used by IPFS",
55
"leadMaintainer": "Alex Potsides <[email protected]>",
66
"main": "src/index.js",
7+
"type": "module",
78
"browser": {
89
"fs": false
910
},
1011
"scripts": {
1112
"prepare": "aegir build --no-bundle",
1213
"test": "aegir test",
13-
"build": "aegir build",
14+
"build": "aegir build --esm-tests",
1415
"clean": "rimraf ./dist",
1516
"lint": "aegir ts -p check && aegir lint",
1617
"coverage": "nyc -s npm run test -t node && nyc report --reporter=html",
@@ -32,14 +33,16 @@
3233
"npm": ">=7.0.0"
3334
},
3435
"homepage": "https://github.com/ipfs/js-ipfs-unixfs#readme",
36+
"publishConfig": {
37+
"directory": "dist"
38+
},
3539
"devDependencies": {
3640
"@types/mocha": "^8.2.1",
3741
"@types/sinon": "^10.0.0",
3842
"abort-controller": "^3.0.0",
39-
"aegir": "^34.0.0",
43+
"aegir": "^35.0.1",
4044
"copy": "^0.3.2",
4145
"crypto-browserify": "^3.12.0",
42-
"detect-node": "^2.0.4",
4346
"events": "^3.3.0",
4447
"ipfs-unixfs-importer": "^8.0.2",
4548
"it-all": "^1.0.5",
@@ -52,7 +55,6 @@
5255
"readable-stream": "^3.6.0",
5356
"rimraf": "^3.0.2",
5457
"sinon": "^11.1.1",
55-
"uint8arrays": "^2.1.2",
5658
"util": "^0.12.3"
5759
},
5860
"dependencies": {
@@ -65,14 +67,13 @@
6567
"it-last": "^1.0.5",
6668
"multiformats": "^9.4.2",
6769
"murmurhash3js-revisited": "^3.0.0",
68-
"uint8arrays": "^2.1.7"
70+
"uint8arrays": "^3.0.0"
6971
},
7072
"types": "dist/src/index.d.ts",
71-
"files": [
72-
"src",
73-
"dist"
74-
],
7573
"eslintConfig": {
76-
"extends": "ipfs"
74+
"extends": "ipfs",
75+
"parserOptions": {
76+
"sourceType": "module"
77+
}
7778
}
7879
}

packages/ipfs-unixfs-exporter/src/index.js

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict'
2-
3-
const errCode = require('err-code')
4-
const { CID } = require('multiformats/cid')
5-
const resolve = require('./resolvers')
6-
const last = require('it-last')
1+
import errCode from 'err-code'
2+
import { CID } from 'multiformats/cid'
3+
import resolve from './resolvers/index.js'
4+
import last from 'it-last'
75

86
/**
97
* @typedef {import('ipfs-unixfs').UnixFS} UnixFS
@@ -65,7 +63,7 @@ const cidAndRest = (path) => {
6563
* @param {Blockstore} blockstore
6664
* @param {ExporterOptions} [options]
6765
*/
68-
async function * walkPath (path, blockstore, options = {}) {
66+
export async function * walkPath (path, blockstore, options = {}) {
6967
let {
7068
cid,
7169
toResolve
@@ -102,7 +100,7 @@ async function * walkPath (path, blockstore, options = {}) {
102100
* @param {Blockstore} blockstore
103101
* @param {ExporterOptions} [options]
104102
*/
105-
async function exporter (path, blockstore, options = {}) {
103+
export async function exporter (path, blockstore, options = {}) {
106104
const result = await last(walkPath(path, blockstore, options))
107105

108106
if (!result) {
@@ -117,7 +115,7 @@ async function exporter (path, blockstore, options = {}) {
117115
* @param {Blockstore} blockstore
118116
* @param {ExporterOptions} [options]
119117
*/
120-
async function * recursive (path, blockstore, options = {}) {
118+
export async function * recursive (path, blockstore, options = {}) {
121119
const node = await exporter(path, blockstore, options)
122120

123121
if (!node) {
@@ -151,9 +149,3 @@ async function * recursive (path, blockstore, options = {}) {
151149
}
152150
}
153151
}
154-
155-
module.exports = {
156-
exporter,
157-
walkPath,
158-
recursive
159-
}

packages/ipfs-unixfs-exporter/src/resolvers/dag-cbor.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
'use strict'
2-
3-
const { CID } = require('multiformats/cid')
4-
const errCode = require('err-code')
5-
const dagCbor = require('@ipld/dag-cbor')
1+
import { CID } from 'multiformats/cid'
2+
import errCode from 'err-code'
3+
import * as dagCbor from '@ipld/dag-cbor'
64

75
/**
86
* @typedef {import('../types').Resolver} Resolver
@@ -72,4 +70,4 @@ const resolve = async (cid, name, path, toResolve, resolve, depth, blockstore, o
7270
}
7371
}
7472

75-
module.exports = resolve
73+
export default resolve

packages/ipfs-unixfs-exporter/src/resolvers/identity.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict'
2-
3-
const errCode = require('err-code')
4-
const extractDataFromBlock = require('../utils/extract-data-from-block')
5-
const validateOffsetAndLength = require('../utils/validate-offset-and-length')
6-
const mh = require('multiformats/hashes/digest')
1+
import errCode from 'err-code'
2+
import extractDataFromBlock from '../utils/extract-data-from-block.js'
3+
import validateOffsetAndLength from '../utils/validate-offset-and-length.js'
4+
import * as mh from 'multiformats/hashes/digest'
75

86
/**
97
* @typedef {import('../types').ExporterOptions} ExporterOptions
@@ -52,4 +50,4 @@ const resolve = async (cid, name, path, toResolve, resolve, depth, blockstore, o
5250
}
5351
}
5452

55-
module.exports = resolve
53+
export default resolve
Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
'use strict'
1+
import errCode from 'err-code'
22

3-
const errCode = require('err-code')
3+
import * as dagPb from '@ipld/dag-pb'
4+
import * as dagCbor from '@ipld/dag-cbor'
5+
import * as raw from 'multiformats/codecs/raw'
6+
import { identity } from 'multiformats/hashes/identity'
47

5-
const dagPb = require('@ipld/dag-pb')
6-
const dagCbor = require('@ipld/dag-cbor')
7-
const raw = require('multiformats/codecs/raw')
8-
const { identity } = require('multiformats/hashes/identity')
8+
import dagPbResolver from './unixfs-v1/index.js'
9+
import rawResolver from './raw.js'
10+
import dagCborResolver from './dag-cbor.js'
11+
import identifyResolver from './identity.js'
912

1013
/**
1114
* @typedef {import('../types').Resolver} Resolver
@@ -16,10 +19,10 @@ const { identity } = require('multiformats/hashes/identity')
1619
* @type {{ [ key: string ]: Resolver }}
1720
*/
1821
const resolvers = {
19-
[dagPb.code]: require('./unixfs-v1'),
20-
[raw.code]: require('./raw'),
21-
[dagCbor.code]: require('./dag-cbor'),
22-
[identity.code]: require('./identity')
22+
[dagPb.code]: dagPbResolver,
23+
[raw.code]: rawResolver,
24+
[dagCbor.code]: dagCborResolver,
25+
[identity.code]: identifyResolver
2326
}
2427

2528
/**
@@ -35,4 +38,4 @@ function resolve (cid, name, path, toResolve, depth, blockstore, options) {
3538
return resolver(cid, name, path, toResolve, resolve, depth, blockstore, options)
3639
}
3740

38-
module.exports = resolve
41+
export default resolve

packages/ipfs-unixfs-exporter/src/resolvers/raw.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
'use strict'
2-
3-
const errCode = require('err-code')
4-
const extractDataFromBlock = require('../utils/extract-data-from-block')
5-
const validateOffsetAndLength = require('../utils/validate-offset-and-length')
1+
import errCode from 'err-code'
2+
import extractDataFromBlock from '../utils/extract-data-from-block.js'
3+
import validateOffsetAndLength from '../utils/validate-offset-and-length.js'
64

75
/**
86
* @typedef {import('../types').ExporterOptions} ExporterOptions
@@ -51,4 +49,4 @@ const resolve = async (cid, name, path, toResolve, resolve, depth, blockstore, o
5149
}
5250
}
5351

54-
module.exports = resolve
52+
export default resolve

packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/directory.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict'
2-
31
/**
42
* @typedef {import('../../../types').ExporterOptions} ExporterOptions
53
* @typedef {import('../../../types').UnixfsV1DirectoryContent} UnixfsV1DirectoryContent
@@ -31,4 +29,4 @@ const directoryContent = (cid, node, unixfs, path, resolve, depth, blockstore) =
3129
return yieldDirectoryContent
3230
}
3331

34-
module.exports = directoryContent
32+
export default directoryContent

packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/file.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
'use strict'
2-
3-
const extractDataFromBlock = require('../../../utils/extract-data-from-block')
4-
const validateOffsetAndLength = require('../../../utils/validate-offset-and-length')
5-
const { UnixFS } = require('ipfs-unixfs')
6-
const errCode = require('err-code')
7-
const dagPb = require('@ipld/dag-pb')
8-
const dagCbor = require('@ipld/dag-cbor')
9-
const raw = require('multiformats/codecs/raw')
1+
import extractDataFromBlock from '../../../utils/extract-data-from-block.js'
2+
import validateOffsetAndLength from '../../../utils/validate-offset-and-length.js'
3+
import { UnixFS } from 'ipfs-unixfs'
4+
import errCode from 'err-code'
5+
import * as dagPb from '@ipld/dag-pb'
6+
import * as dagCbor from '@ipld/dag-cbor'
7+
import * as raw from 'multiformats/codecs/raw'
108

119
/**
1210
* @typedef {import('../../../types').ExporterOptions} ExporterOptions
@@ -126,4 +124,4 @@ const fileContent = (cid, node, unixfs, path, resolve, depth, blockstore) => {
126124
return yieldFileContent
127125
}
128126

129-
module.exports = fileContent
127+
export default fileContent

0 commit comments

Comments
 (0)