From a43103a843fa31762954fa943b102082c913ce6c Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Fri, 17 May 2024 10:33:23 +0100 Subject: [PATCH] feat: deploy to npm --- .github/workflows/release.yml | 9 +++++++-- package.json | 14 +++++++++++--- src/worker.d.ts | 9 +++++++++ src/worker.js | 10 +++------- 4 files changed, 30 insertions(+), 12 deletions(-) create mode 100644 src/worker.d.ts diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ea6f760..1aaa1e6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -57,13 +57,18 @@ jobs: registry-url: https://registry.npmjs.org/ cache: 'pnpm' if: ${{ steps.release.outputs.release_created }} - - name: Install + - name: Install Dependencies run: pnpm install if: ${{ steps.release.outputs.release_created }} - name: Build run: pnpm build if: ${{ steps.release.outputs.release_created }} - - name: Deploy to Production + - name: Publish to npm + run: npm publish --access=public + env: + NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} + if: ${{ steps.release.outputs.release_created }} + - name: Deploy to Cloudflare uses: cloudflare/wrangler-action@2.0.0 with: apiToken: ${{ secrets.CF_TOKEN }} diff --git a/package.json b/package.json index 79384d2..d0d0db3 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { - "name": "public-r2-bucket", + "name": "@web3-storage/public-r2-bucket", "version": "1.1.0", "description": "Cloudflare worker allowing read access (with byte range request support) to R2 buckets.", - "main": "index.js", + "main": "src/worker.js", "type": "module", "private": true, "scripts": { @@ -12,6 +12,9 @@ }, "author": "Alan Shaw", "license": "Apache-2.0 OR MIT", + "files": [ + "src" + ], "devDependencies": { "@cloudflare/workers-types": "^4.20240512.0", "buffer": "^6.0.3", @@ -34,5 +37,10 @@ "bugs": { "url": "https://github.com/nftstorage/dagcargo-bucket/issues" }, - "homepage": "https://github.com/nftstorage/dagcargo-bucket#readme" + "homepage": "https://github.com/nftstorage/dagcargo-bucket#readme", + "standard": { + "ignore": [ + "*.ts" + ] + } } diff --git a/src/worker.d.ts b/src/worker.d.ts new file mode 100644 index 0000000..166aa13 --- /dev/null +++ b/src/worker.d.ts @@ -0,0 +1,9 @@ +import { R2Bucket } from '@cloudflare/workers-types' + +export { R2Bucket } + +export interface Environment { + BUCKET: R2Bucket +} + +export declare function handler (request: Request, env: Environment): Promise diff --git a/src/worker.js b/src/worker.js index 32d8fcd..ef151e9 100644 --- a/src/worker.js +++ b/src/worker.js @@ -11,15 +11,11 @@ import { import { HttpError, decodeRangeHeader, resolveRange } from '@web3-storage/gateway-lib/util' import { MultipartByteRange } from 'multipart-byte-range' -/** - * @typedef {{ BUCKET: import('@cloudflare/workers-types').R2Bucket }} Environment - */ - /** * @param {Request} request - * @param {Environment} env + * @param {import('./worker.js').Environment} env */ -const handler = async (request, env) => { +export const handler = async (request, env) => { const url = new URL(request.url) const key = url.pathname.slice(1) @@ -112,7 +108,7 @@ const handleMultipartRange = async (bucket, key, size, ranges, options) => { } export default { - /** @type {import('@web3-storage/gateway-lib').Handler} */ + /** @type {import('@web3-storage/gateway-lib').Handler} */ fetch (request, env, ctx) { console.log(request.method, request.url) const middleware = composeMiddleware(