diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index be954c9..333bf3e 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -8,17 +8,21 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v3 + - name: Setup Node uses: actions/setup-node@v3 with: node-version: 18.x + - uses: oven-sh/setup-bun@v1 + - name: Setup pnpm uses: pnpm/action-setup@v2 with: version: 8 + - name: Install dependencies run: pnpm install @@ -34,6 +38,9 @@ jobs: - name: Run example build run: pnpm --filter=example-app build + - name: Run bun example + run: cd bun-example && bun install && bun index.ts && bun build index.ts + - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v4.0.1 with: diff --git a/bun-example/.gitignore b/bun-example/.gitignore new file mode 100644 index 0000000..9b1ee42 --- /dev/null +++ b/bun-example/.gitignore @@ -0,0 +1,175 @@ +# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore + +# Logs + +logs +_.log +npm-debug.log_ +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Caches + +.cache + +# Diagnostic reports (https://nodejs.org/api/report.html) + +report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json + +# Runtime data + +pids +_.pid +_.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover + +lib-cov + +# Coverage directory used by tools like istanbul + +coverage +*.lcov + +# nyc test coverage + +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) + +.grunt + +# Bower dependency directory (https://bower.io/) + +bower_components + +# node-waf configuration + +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) + +build/Release + +# Dependency directories + +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) + +web_modules/ + +# TypeScript cache + +*.tsbuildinfo + +# Optional npm cache directory + +.npm + +# Optional eslint cache + +.eslintcache + +# Optional stylelint cache + +.stylelintcache + +# Microbundle cache + +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history + +.node_repl_history + +# Output of 'npm pack' + +*.tgz + +# Yarn Integrity file + +.yarn-integrity + +# dotenv environment variable files + +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# parcel-bundler cache (https://parceljs.org/) + +.parcel-cache + +# Next.js build output + +.next +out + +# Nuxt.js build / generate output + +.nuxt +dist + +# Gatsby files + +# Comment in the public line in if your project uses Gatsby and not Next.js + +# https://nextjs.org/blog/next-9-1#public-directory-support + +# public + +# vuepress build output + +.vuepress/dist + +# vuepress v2.x temp and cache directory + +.temp + +# Docusaurus cache and generated files + +.docusaurus + +# Serverless directories + +.serverless/ + +# FuseBox cache + +.fusebox/ + +# DynamoDB Local files + +.dynamodb/ + +# TernJS port file + +.tern-port + +# Stores VSCode versions used for testing VSCode extensions + +.vscode-test + +# yarn v2 + +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* + +# IntelliJ based IDEs +.idea + +# Finder (MacOS) folder config +.DS_Store diff --git a/bun-example/README.md b/bun-example/README.md new file mode 100644 index 0000000..f459f6a --- /dev/null +++ b/bun-example/README.md @@ -0,0 +1,15 @@ +# bun-example + +To install dependencies: + +```bash +bun install +``` + +To run: + +```bash +bun run index.ts +``` + +This project was created using `bun init` in bun v1.0.29. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime. diff --git a/bun-example/bun.lockb b/bun-example/bun.lockb new file mode 100755 index 0000000..a05c6de Binary files /dev/null and b/bun-example/bun.lockb differ diff --git a/bun-example/index.ts b/bun-example/index.ts new file mode 100644 index 0000000..37fadb1 --- /dev/null +++ b/bun-example/index.ts @@ -0,0 +1,33 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +// @ts-ignore +import stringify from 'qs/lib/stringify'; +import xior, { merge, delay, buildSortedURL } from 'xior'; +import cachePlugin from 'xior/plugins/cache'; +import errorRetryPlugin from 'xior/plugins/error-retry'; +import uploadDownloadProgressPlugin from 'xior/plugins/progress'; +import throttlePlugin from 'xior/plugins/throttle'; + +// console.log(merge, delay, buildSortedURL); + +const instance = xior.create({ + encode: (params: Record) => stringify(params), +}); +instance.plugins.use(errorRetryPlugin({})); +instance.plugins.use(cachePlugin({})); +instance.plugins.use(throttlePlugin({})); +instance.plugins.use(uploadDownloadProgressPlugin({})); + +instance.plugins.use((adapter) => { + return async (config) => { + const res = await adapter(config); + console.log(`%s %s -> %s`, config.method, config.url, res.status); + return res; + }; +}); + +instance.get('https://google.com', { + progressDuration: 500, + onDownloadProgress(e) { + console.log(`Download %s%`, e.progress); + }, +}); diff --git a/bun-example/package.json b/bun-example/package.json new file mode 100644 index 0000000..aacdf91 --- /dev/null +++ b/bun-example/package.json @@ -0,0 +1,15 @@ +{ + "name": "bun-example", + "module": "index.ts", + "type": "module", + "dependencies": { + "xior": "file:..", + "qs": "^6.11.2" + }, + "devDependencies": { + "@types/bun": "latest" + }, + "peerDependencies": { + "typescript": "^5.0.0" + } +} \ No newline at end of file diff --git a/bun-example/tsconfig.json b/bun-example/tsconfig.json new file mode 100644 index 0000000..0fef23a --- /dev/null +++ b/bun-example/tsconfig.json @@ -0,0 +1,27 @@ +{ + "compilerOptions": { + // Enable latest features + "lib": ["ESNext"], + "target": "ESNext", + "module": "ESNext", + "moduleDetection": "force", + "jsx": "react-jsx", + "allowJs": true, + + // Bundler mode + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "verbatimModuleSyntax": true, + "noEmit": true, + + // Best practices + "strict": true, + "skipLibCheck": true, + "noFallthroughCasesInSwitch": true, + + // Some stricter flags (disabled by default) + "noUnusedLocals": false, + "noUnusedParameters": false, + "noPropertyAccessFromIndexSignature": false + } +} diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index a5d0870..e34e28e 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -8,3 +8,4 @@ packages: # Fix turbo error: error preparing engine: Invalid turbo.json # No "extends" key found - '!./package.json' + - '!./bun-example'