Skip to content

Commit

Permalink
feat: add types, gh actions and remove unused methods (#89)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
hugomrdias authored Jan 15, 2021
1 parent 382f79b commit 707174c
Show file tree
Hide file tree
Showing 38 changed files with 703 additions and 949 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: ci
on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: npm install
- run: npx aegir lint
- uses: gozala/[email protected]
- run: npx aegir build
- run: npx aegir dep-check
- uses: ipfs/aegir/actions/bundle-size@master
name: size
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
test-node:
needs: check
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
node: [12, 14]
fail-fast: true
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- run: npm install
- run: npx nyc --reporter=lcov aegir test -t node -- --bail
- uses: codecov/codecov-action@v1
test-chrome:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: npm install
- run: npx aegir test -t browser -t webworker --bail
test-firefox:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: npm install
- run: npx aegir test -t browser -t webworker --bail -- --browsers FirefoxHeadless
test-electron-main:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: npm install
- run: npx xvfb-maybe aegir test -t electron-main --bail
test-electron-renderer:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: npm install
- run: npx xvfb-maybe aegir test -t electron-renderer --bail
52 changes: 0 additions & 52 deletions .travis.yml

This file was deleted.

48 changes: 32 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,22 @@
],
"browser": {
"./src/http/fetch.js": "./src/http/fetch.browser.js",
"./src/text-encoder.js": "./src/text-encoder.browser.js",
"./src/text-decoder.js": "./src/text-decoder.browser.js",
"./src/temp-dir.js": "./src/temp-dir.browser.js",
"./src/path-join.js": "./src/path-join.browser.js",
"./test/files/glob-source.spec.js": false,
"electron-fetch": false
},
"types": "dist/src/index.d.ts",
"typesVersions": {
"*": {
"src/*": [
"dist/src/*"
]
}
},
"repository": "github:ipfs/js-ipfs-utils",
"scripts": {
"prepare": "aegir build --no-bundle",
"test": "aegir test",
"test:browser": "aegir test -t browser",
"test:node": "aegir test -t node",
Expand All @@ -35,30 +42,39 @@
},
"license": "MIT",
"dependencies": {
"electron-fetch": "^1.7.2",
"abort-controller": "^3.0.0",
"any-signal": "^2.1.0",
"buffer": "^6.0.1",
"err-code": "^2.0.0",
"electron-fetch": "^1.7.2",
"err-code": "^2.0.3",
"fs-extra": "^9.0.1",
"is-electron": "^2.2.0",
"iso-url": "^1.0.0",
"it-glob": "0.0.10",
"merge-options": "^2.0.0",
"nanoid": "^3.1.3",
"it-to-stream": "^0.1.2",
"merge-options": "^3.0.4",
"nanoid": "^3.1.20",
"native-abort-controller": "0.0.3",
"native-fetch": "^2.0.0",
"node-fetch": "^2.6.0",
"stream-to-it": "^0.2.0",
"it-to-stream": "^0.1.2"
"native-fetch": "2.0.1",
"node-fetch": "^2.6.1",
"stream-to-it": "^0.2.2",
"web-encoding": "^1.0.6"
},
"devDependencies": {
"aegir": "^28.1.0",
"delay": "^4.3.0",
"it-all": "^1.0.2",
"it-drain": "^1.0.1",
"it-last": "^1.0.2",
"uint8arrays": "^1.1.0"
"@types/err-code": "^2.0.0",
"@types/fs-extra": "^9.0.5",
"aegir": "^30.3.0",
"delay": "^4.4.0",
"it-all": "^1.0.4",
"it-drain": "^1.0.3",
"it-last": "^1.0.4",
"uint8arrays": "^2.0.5"
},
"eslintConfig": {
"extends": "ipfs",
"env": {
"worker": true
}
},
"contributors": [
"Hugo Dias <[email protected]>",
Expand Down
2 changes: 1 addition & 1 deletion src/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ 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
// eslint-disable-next-line no-undef
// @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'

Expand Down
2 changes: 1 addition & 1 deletion src/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ const { isElectronMain } = require('./env')
if (isElectronMain) {
module.exports = require('electron-fetch')
} else {
// use window.fetch if it is available, fall back to node-fetch if not
// use window.fetch if it is available, fall back to node-fetch if not
module.exports = require('native-fetch')
}
66 changes: 0 additions & 66 deletions src/files/format-mode.js

This file was deleted.

21 changes: 0 additions & 21 deletions src/files/format-mtime.js

This file was deleted.

12 changes: 9 additions & 3 deletions src/files/glob-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ const errCode = require('err-code')
/**
* Create an async iterator that yields paths that match requested file paths.
*
* @param {Iterable | AsyncIterable | string} paths - File system path(s) to glob from
* @param {Iterable<string> | AsyncIterable<string> | string} paths - File system path(s) to glob from
* @param {Object} [options] - Optional options
* @param {boolean} [options.recursive] - Recursively glob all paths in directories
* @param {boolean} [options.hidden] - Include .dot files in matched paths
* @param {Array<string>} [options.ignore] - Glob paths to ignore
* @param {boolean} [options.followSymlinks] - follow symlinks
* @param {boolean} [options.preserveMode] - preserve mode
* @param {boolean} [options.preserveMtime] - preserve mtime
* @param {boolean} [options.mode] - mode to use - if preserveMode is true this will be ignored
* @param {boolean} [options.mtime] - mtime to use - if preserveMtime is true this will be ignored
* @param {number} [options.mode] - mode to use - if preserveMode is true this will be ignored
* @param {Date} [options.mtime] - mtime to use - if preserveMtime is true this will be ignored
* @yields {Object} File objects in the form `{ path: String, content: AsyncIterator<Buffer> }`
*/
module.exports = async function * globSource (paths, options) {
Expand Down Expand Up @@ -53,12 +53,14 @@ module.exports = async function * globSource (paths, options) {
let mode = options.mode

if (options.preserveMode) {
// @ts-ignore
mode = stat.mode
}

let mtime = options.mtime

if (options.preserveMtime) {
// @ts-ignore
mtime = stat.mtime
}

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

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

Expand Down Expand Up @@ -135,4 +138,7 @@ async function * toGlobSource ({ path, type, prefix, mode, mtime, preserveMode,
}
}

/**
* @param {string} path
*/
const toPosix = path => path.replace(/\\/g, '/')
Loading

0 comments on commit 707174c

Please sign in to comment.