Skip to content

Commit 707174c

Browse files
authored
feat: add types, gh actions and remove unused methods (#89)
- add http, fetch types - remove globalThis, this is supported everywhere now - add types for env, path, supports and temp-dir - use web-encoding for encoder/decoder - add types for files functions - remove some files functions that are in ipfs-core-utils BREAKING CHANGE: removed globalThis and normalise-input, format-mode and format-mtime
1 parent 382f79b commit 707174c

38 files changed

+703
-949
lines changed

.github/workflows/main.yml

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: ci
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
branches:
8+
- master
9+
10+
jobs:
11+
check:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
- run: npm install
16+
- run: npx aegir lint
17+
- uses: gozala/[email protected]
18+
- run: npx aegir build
19+
- run: npx aegir dep-check
20+
- uses: ipfs/aegir/actions/bundle-size@master
21+
name: size
22+
with:
23+
github_token: ${{ secrets.GITHUB_TOKEN }}
24+
test-node:
25+
needs: check
26+
runs-on: ${{ matrix.os }}
27+
strategy:
28+
matrix:
29+
os: [windows-latest, ubuntu-latest, macos-latest]
30+
node: [12, 14]
31+
fail-fast: true
32+
steps:
33+
- uses: actions/checkout@v2
34+
- uses: actions/setup-node@v1
35+
with:
36+
node-version: ${{ matrix.node }}
37+
- run: npm install
38+
- run: npx nyc --reporter=lcov aegir test -t node -- --bail
39+
- uses: codecov/codecov-action@v1
40+
test-chrome:
41+
needs: check
42+
runs-on: ubuntu-latest
43+
steps:
44+
- uses: actions/checkout@v2
45+
- run: npm install
46+
- run: npx aegir test -t browser -t webworker --bail
47+
test-firefox:
48+
needs: check
49+
runs-on: ubuntu-latest
50+
steps:
51+
- uses: actions/checkout@v2
52+
- run: npm install
53+
- run: npx aegir test -t browser -t webworker --bail -- --browsers FirefoxHeadless
54+
test-electron-main:
55+
needs: check
56+
runs-on: ubuntu-latest
57+
steps:
58+
- uses: actions/checkout@v2
59+
- run: npm install
60+
- run: npx xvfb-maybe aegir test -t electron-main --bail
61+
test-electron-renderer:
62+
needs: check
63+
runs-on: ubuntu-latest
64+
steps:
65+
- uses: actions/checkout@v2
66+
- run: npm install
67+
- run: npx xvfb-maybe aegir test -t electron-renderer --bail

.travis.yml

-52
This file was deleted.

package.json

+32-16
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,22 @@
1313
],
1414
"browser": {
1515
"./src/http/fetch.js": "./src/http/fetch.browser.js",
16-
"./src/text-encoder.js": "./src/text-encoder.browser.js",
17-
"./src/text-decoder.js": "./src/text-decoder.browser.js",
1816
"./src/temp-dir.js": "./src/temp-dir.browser.js",
1917
"./src/path-join.js": "./src/path-join.browser.js",
2018
"./test/files/glob-source.spec.js": false,
2119
"electron-fetch": false
2220
},
21+
"types": "dist/src/index.d.ts",
22+
"typesVersions": {
23+
"*": {
24+
"src/*": [
25+
"dist/src/*"
26+
]
27+
}
28+
},
2329
"repository": "github:ipfs/js-ipfs-utils",
2430
"scripts": {
31+
"prepare": "aegir build --no-bundle",
2532
"test": "aegir test",
2633
"test:browser": "aegir test -t browser",
2734
"test:node": "aegir test -t node",
@@ -35,30 +42,39 @@
3542
},
3643
"license": "MIT",
3744
"dependencies": {
38-
"electron-fetch": "^1.7.2",
3945
"abort-controller": "^3.0.0",
4046
"any-signal": "^2.1.0",
4147
"buffer": "^6.0.1",
42-
"err-code": "^2.0.0",
48+
"electron-fetch": "^1.7.2",
49+
"err-code": "^2.0.3",
4350
"fs-extra": "^9.0.1",
4451
"is-electron": "^2.2.0",
4552
"iso-url": "^1.0.0",
4653
"it-glob": "0.0.10",
47-
"merge-options": "^2.0.0",
48-
"nanoid": "^3.1.3",
54+
"it-to-stream": "^0.1.2",
55+
"merge-options": "^3.0.4",
56+
"nanoid": "^3.1.20",
4957
"native-abort-controller": "0.0.3",
50-
"native-fetch": "^2.0.0",
51-
"node-fetch": "^2.6.0",
52-
"stream-to-it": "^0.2.0",
53-
"it-to-stream": "^0.1.2"
58+
"native-fetch": "2.0.1",
59+
"node-fetch": "^2.6.1",
60+
"stream-to-it": "^0.2.2",
61+
"web-encoding": "^1.0.6"
5462
},
5563
"devDependencies": {
56-
"aegir": "^28.1.0",
57-
"delay": "^4.3.0",
58-
"it-all": "^1.0.2",
59-
"it-drain": "^1.0.1",
60-
"it-last": "^1.0.2",
61-
"uint8arrays": "^1.1.0"
64+
"@types/err-code": "^2.0.0",
65+
"@types/fs-extra": "^9.0.5",
66+
"aegir": "^30.3.0",
67+
"delay": "^4.4.0",
68+
"it-all": "^1.0.4",
69+
"it-drain": "^1.0.3",
70+
"it-last": "^1.0.4",
71+
"uint8arrays": "^2.0.5"
72+
},
73+
"eslintConfig": {
74+
"extends": "ipfs",
75+
"env": {
76+
"worker": true
77+
}
6278
},
6379
"contributors": [
6480
"Hugo Dias <[email protected]>",

src/env.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const IS_BROWSER = IS_ENV_WITH_DOM && !IS_ELECTRON
77
const IS_ELECTRON_MAIN = IS_ELECTRON && !IS_ENV_WITH_DOM
88
const IS_ELECTRON_RENDERER = IS_ELECTRON && IS_ENV_WITH_DOM
99
const IS_NODE = typeof require === 'function' && typeof process !== 'undefined' && typeof process.release !== 'undefined' && process.release.name === 'node' && !IS_ELECTRON
10-
// eslint-disable-next-line no-undef
10+
// @ts-ignore - we either ignore worker scope or dom scope
1111
const IS_WEBWORKER = typeof importScripts === 'function' && typeof self !== 'undefined' && typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope
1212
const IS_TEST = typeof process !== 'undefined' && typeof process.env !== 'undefined' && process.env.NODE_ENV === 'test'
1313

src/fetch.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ const { isElectronMain } = require('./env')
55
if (isElectronMain) {
66
module.exports = require('electron-fetch')
77
} else {
8-
// use window.fetch if it is available, fall back to node-fetch if not
8+
// use window.fetch if it is available, fall back to node-fetch if not
99
module.exports = require('native-fetch')
1010
}

src/files/format-mode.js

-66
This file was deleted.

src/files/format-mtime.js

-21
This file was deleted.

src/files/glob-source.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ const errCode = require('err-code')
88
/**
99
* Create an async iterator that yields paths that match requested file paths.
1010
*
11-
* @param {Iterable | AsyncIterable | string} paths - File system path(s) to glob from
11+
* @param {Iterable<string> | AsyncIterable<string> | string} paths - File system path(s) to glob from
1212
* @param {Object} [options] - Optional options
1313
* @param {boolean} [options.recursive] - Recursively glob all paths in directories
1414
* @param {boolean} [options.hidden] - Include .dot files in matched paths
1515
* @param {Array<string>} [options.ignore] - Glob paths to ignore
1616
* @param {boolean} [options.followSymlinks] - follow symlinks
1717
* @param {boolean} [options.preserveMode] - preserve mode
1818
* @param {boolean} [options.preserveMtime] - preserve mtime
19-
* @param {boolean} [options.mode] - mode to use - if preserveMode is true this will be ignored
20-
* @param {boolean} [options.mtime] - mtime to use - if preserveMtime is true this will be ignored
19+
* @param {number} [options.mode] - mode to use - if preserveMode is true this will be ignored
20+
* @param {Date} [options.mtime] - mtime to use - if preserveMtime is true this will be ignored
2121
* @yields {Object} File objects in the form `{ path: String, content: AsyncIterator<Buffer> }`
2222
*/
2323
module.exports = async function * globSource (paths, options) {
@@ -53,12 +53,14 @@ module.exports = async function * globSource (paths, options) {
5353
let mode = options.mode
5454

5555
if (options.preserveMode) {
56+
// @ts-ignore
5657
mode = stat.mode
5758
}
5859

5960
let mtime = options.mtime
6061

6162
if (options.preserveMtime) {
63+
// @ts-ignore
6264
mtime = stat.mtime
6365
}
6466

@@ -82,6 +84,7 @@ module.exports = async function * globSource (paths, options) {
8284
}
8385
}
8486

87+
// @ts-ignore
8588
async function * toGlobSource ({ path, type, prefix, mode, mtime, preserveMode, preserveMtime }, options) {
8689
options = options || {}
8790

@@ -135,4 +138,7 @@ async function * toGlobSource ({ path, type, prefix, mode, mtime, preserveMode,
135138
}
136139
}
137140

141+
/**
142+
* @param {string} path
143+
*/
138144
const toPosix = path => path.replace(/\\/g, '/')

0 commit comments

Comments
 (0)