Skip to content

Commit

Permalink
chore(example): add bun example
Browse files Browse the repository at this point in the history
  • Loading branch information
suhaotian committed Feb 26, 2024
1 parent 67ba188 commit 92fa566
Show file tree
Hide file tree
Showing 8 changed files with 273 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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/[email protected]
with:
Expand Down
175 changes: 175 additions & 0 deletions bun-example/.gitignore
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions bun-example/README.md
Original file line number Diff line number Diff line change
@@ -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.
Binary file added bun-example/bun.lockb
Binary file not shown.
33 changes: 33 additions & 0 deletions bun-example/index.ts
Original file line number Diff line number Diff line change
@@ -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<string, any>) => 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);
},
});
15 changes: 15 additions & 0 deletions bun-example/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
27 changes: 27 additions & 0 deletions bun-example/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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
}
}
1 change: 1 addition & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ packages:
# Fix turbo error: error preparing engine: Invalid turbo.json
# No "extends" key found
- '!./package.json'
- '!./bun-example'

0 comments on commit 92fa566

Please sign in to comment.