Skip to content

Commit

Permalink
feat!: use native fetch & update deps (#68)
Browse files Browse the repository at this point in the history
* deps: update aegir and typescript

* feat!: use native fetch, update all deps

* docs: update instructions for devs

* chore: update to latest aegir

* chore: use lts node in github actions
  • Loading branch information
SgtPooki authored Aug 27, 2024
1 parent 5c079ba commit 77dac71
Show file tree
Hide file tree
Showing 16 changed files with 109 additions and 130 deletions.
29 changes: 23 additions & 6 deletions .aegir.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
import { MockServerController } from './dist/test/MockServerController.js'

/** @type {import('aegir').PartialOptions} */
const config = {
export default {
typescript: true,
dependencyCheck: {
ignore: [
'@swc/cli',
'@swc/core',
'@swc/helpers',
'cors',
'dotenvrc',
'express',
'express-promise-router',
'mock-ipfs-pinning-service',
'portscanner',
'regenerator-runtime',
'winston',
]
},
docs: {
publish: true,
entryPoint: './'
},
build: {
types: true,
config: {
platform: 'node'
format: 'esm',
platform: 'node',
external: ['electron', '#ansi-styles', 'yargs/yargs', '#supports-color']
},
bundlesizeMax: '44KB'
},
Expand All @@ -17,6 +35,7 @@ const config = {
progress: true,
cov: false,
async before () {
const { MockServerController } = await import('./dist/test/MockServerController.js')
return {
env: {
MOCK_PINNING_SERVER_SECRET: 'ci',
Expand All @@ -26,12 +45,10 @@ const config = {
},
/**
* @param {import('aegir').GlobalOptions & import('aegir').TestOptions} _
* @param { {controller: MockServerController} } beforeResult
* @param { { controller: import('./test/MockServerController.js').MockServerController } } beforeResult
*/
async after (_, {controller}) {
await controller.shutdown()
}
}
}

export default config
10 changes: 5 additions & 5 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint", "import"],
"extends": ["ipfs"],
"parserOptions": {
"project": true,
"sourceType": "module"
},
"overrides": [
{
"parserOptions": {
Expand All @@ -13,7 +15,6 @@
"./types/**/*.ts"
],
"rules": {
"@typescript-eslint/strict-boolean-expressions": "off"
}
},
{
Expand All @@ -32,8 +33,7 @@
"semi": "off",
"indent": "off",
"no-unused-vars": "off",
"no-undef": "off",
"@typescript-eslint/strict-boolean-expressions": "off"
"no-undef": "off"
}
}
],
Expand Down
38 changes: 19 additions & 19 deletions .github/workflows/js-test-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- uses: ipfs/aegir/actions/cache-node-modules@master
Expand All @@ -27,11 +27,11 @@ jobs:
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
node: [16]
node: [20]
fail-fast: true
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- uses: ipfs/aegir/actions/cache-node-modules@master
Expand All @@ -46,8 +46,8 @@ jobs:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- uses: ipfs/aegir/actions/cache-node-modules@master
Expand All @@ -62,8 +62,8 @@ jobs:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- uses: ipfs/aegir/actions/cache-node-modules@master
Expand All @@ -78,8 +78,8 @@ jobs:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- uses: ipfs/aegir/actions/cache-node-modules@master
Expand All @@ -94,8 +94,8 @@ jobs:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- uses: ipfs/aegir/actions/cache-node-modules@master
Expand All @@ -110,8 +110,8 @@ jobs:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- uses: ipfs/aegir/actions/cache-node-modules@master
Expand All @@ -126,8 +126,8 @@ jobs:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- uses: ipfs/aegir/actions/cache-node-modules@master
Expand All @@ -143,10 +143,10 @@ jobs:
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main' # with #262 - 'refs/heads/${{{ github.default_branch }}}'
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v2
- uses: actions/setup-node@v4
with:
node-version: lts/*
- uses: ipfs/aegir/actions/cache-node-modules@master
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ logs
.tsbuildinfo*
# generated by nektos/act cli
workflow
.coverage
13 changes: 0 additions & 13 deletions .vscode/settings.json

This file was deleted.

8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type { PinsGetRequest, PinResults } from '@ipfs-shipyard/pinning-service-
const config = new Configuration({
endpointUrl, // the URI for your pinning provider, e.g. `http://localhost:3000`
accessToken, // the secret token/key given to you by your pinning provider
// fetchApi: fetch, // You can pass your own fetchApi implementation, but we use fetch-ponyfill by default.
// fetchApi: fetch, // You can pass your own fetchApi implementation, but we use NodeJS fetch by default.
})

const client = new RemotePinningServiceClient(config)
Expand Down Expand Up @@ -49,6 +49,12 @@ npm install
npm run build
```

### Updating the generated client

To update the client, you need to `npm run gen` npm script. This will fetch the latest version of the OpenAPI spec and generate the client. However, openapi-generator-cli does not currently generate the client code with proper import syntax. So you must modify the imports in `generated/fetch/**` directly, or just `git checkout -p` to remove the invalid import path changes.

If you need to modify the generated code's import paths, you will have to run `npm run postgen` manually.

### Contributing

See [CONTRIBUTING.md](CONTRIBUTING.md).
Expand Down
1 change: 0 additions & 1 deletion fixtures.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

// @ts-check
// export async function mochaGlobalSetup () {

Expand Down
52 changes: 18 additions & 34 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,6 @@
"require": "./dist/dist.generated/apis"
}
},
"eslintConfig": {
"extends": "ipfs",
"parserOptions": {
"sourceType": "module"
}
},
"release": {
"branches": [
"main"
Expand Down Expand Up @@ -147,7 +141,7 @@
},
"scripts": {
"ci:test": "run-s test:*",
"dep-check": "aegir dep-check dist/**/*.js -- --ignore @openapitools/openapi-generator-cli @typescript-eslint/eslint-plugin @typescript-eslint/parser",
"dep-check": "aegir dep-check dist/**/*.js",
"fix": "run-s fix:*",
"fix:lint": "aegir lint --fix",
"release": "aegir release",
Expand All @@ -165,49 +159,39 @@
"test:firefox": "aegir test -t browser -- --browser firefox",
"test:firefox-webworker": "aegir test -t webworker -- --browser firefox",
"test:electron-main": "aegir test -t electron-main",
"posttest": "npx nyc report",
"posttest": "npx nyc report || echo 'coverage report temporarily broken'",
"pregen": "openapi-generator-cli validate -i https://raw.githubusercontent.com/ipfs/pinning-services-api-spec/v1.0.0/ipfs-pinning-service.yaml",
"gen": "run-p gen:fetch",
"postgen": "run-s build:generated",
"gen:fetch": "openapi-generator-cli generate --generator-key fetch",
"gen:node": "openapi-generator-cli generate --generator-key node",
"gen:ts": "openapi-generator-cli generate --generator-key ts",
"clean": "aegir clean",
"reset": "aegir clean node_modules dist dist.generated",
"lint": "aegir lint"
},
"dependencies": {
"fetch-ponyfill": "^7.1.0"
},
"devDependencies": {
"@openapitools/openapi-generator-cli": "^2.4.26",
"@swc/cli": "^0.1.55",
"@swc/core": "^1.2.157",
"@swc/helpers": "^0.3.3",
"@types/cors": "^2.8.12",
"@types/eslint": "^8.4.2",
"@types/express": "^4.17.13",
"@types/mocha": "^10.0.0",
"@types/node": "^18.8.2",
"@types/portscanner": "^2.1.1",
"@openapitools/openapi-generator-cli": "^2.13.5",
"@swc/cli": "^0.4.0",
"@swc/core": "^1.7.18",
"@swc/helpers": "^0.5.12",
"@types/cors": "^2.8.17",
"@types/express": "^4.17.21",
"@types/mocha": "^10.0.7",
"@types/node": "^22.5.0",
"@types/portscanner": "^2.1.4",
"@types/winston": "^2.4.4",
"@typescript-eslint/eslint-plugin": "^5.22.0",
"@typescript-eslint/parser": "^5.22.0",
"aegir": "^37.0.15",
"check-aegir-project": "^1.0.3",
"aegir": "^44.1.1",
"cors": "^2.8.5",
"cp-cli": "^2.0.0",
"dotenvrc": "^1.0.1",
"eslint": "^8.14.0",
"eslint-plugin-import": "^2.26.0",
"express": "^4.17.3",
"express": "^4.19.2",
"express-promise-router": "^4.1.1",
"mock-ipfs-pinning-service": "^0.4.0",
"mock-ipfs-pinning-service": "^0.4.2",
"npm-run-all": "^4.1.5",
"portscanner": "^2.2.0",
"regenerator-runtime": "^0.13.9",
"ts-node": "^10.7.0",
"tsc-silent": "^1.2.1",
"typescript": "^4.6.4",
"winston": "^3.6.0"
"regenerator-runtime": "^0.14.1",
"tsc-silent": "^1.2.2",
"winston": "^3.14.2"
}
}
8 changes: 3 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import fetchPonyfill from 'fetch-ponyfill'

import { PinsApi as RemotePinningServiceClient } from '../dist.generated/apis/index.js'
import { Configuration as GeneratedConfiguration } from '../dist.generated/index.js'
import type { ConfigurationParameters as GeneratedConfigurationParameters } from '../dist.generated/index.js'
import { PinsApi as RemotePinningServiceClient } from '../dist.generated/apis/index.js'

interface ConfigurationParameters extends Omit<GeneratedConfigurationParameters, 'basePath'>{
interface ConfigurationParameters extends Omit<GeneratedConfigurationParameters, 'basePath'> {
endpointUrl?: string
}
class Configuration extends GeneratedConfiguration {
Expand All @@ -14,7 +12,7 @@ class Configuration extends GeneratedConfiguration {
* Prevent the need for everyone to have to override the fetch API...
*/
if (options.fetchApi == null) {
finalOptions.fetchApi = fetchPonyfill().fetch
finalOptions.fetchApi = fetch
}

// @see https://github.com/ipfs-shipyard/js-pinning-service-http-client/issues/3
Expand Down
Loading

0 comments on commit 77dac71

Please sign in to comment.