diff --git a/bun.config.ts b/bun.config.ts new file mode 100644 index 0000000..8885ce3 --- /dev/null +++ b/bun.config.ts @@ -0,0 +1,18 @@ +import glob from 'fast-glob'; +import dts from 'bun-plugin-dts'; + +const services = await glob('src/services/*.ts'); + +await Bun.build({ + entrypoints: ['src/index.ts', ...services], + outdir: './dist', + target: 'node', + format: 'esm', + splitting: false, + sourcemap: 'none', + minify: false, + external: ['minio'], + plugins: [dts()], +}); + +console.log('Build completed!'); diff --git a/package.json b/package.json index c72adca..e4da053 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,9 @@ { "name": "@kevisual/oss", - "version": "0.0.12", + "version": "0.0.13", "main": "dist/index.js", "scripts": { - "build": "tsup", - "dev": "tsup --watch", - "dev:lib": "tsup --watch" + "build": "bun run bun.config.ts" }, "files": [ "dist" @@ -15,6 +13,9 @@ "license": "MIT", "type": "module", "devDependencies": { + "@types/bun": "^1.3.3", + "@types/node": "^24.10.1", + "bun-plugin-dts": "^0.3.0", "dotenv": "^16.5.0", "minio": "^8.0.5", "tsup": "^8.4.0" @@ -35,5 +36,10 @@ }, "publishConfig": { "access": "public" + }, + "dependencies": { + "@types/lodash": "^4.17.21", + "fast-glob": "^3.3.3", + "lodash": "^4.17.21" } } \ No newline at end of file diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml new file mode 100644 index 0000000..efc037a --- /dev/null +++ b/pnpm-workspace.yaml @@ -0,0 +1,2 @@ +onlyBuiltDependencies: + - esbuild diff --git a/src/index.ts b/src/index.ts index aae370c..1a0950e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -84,18 +84,20 @@ export class OssBase implements OssBaseOperation { let size: number = opts?.size; const isStream = opts?.isStream; if (!isStream) { - if (data instanceof Object) { - putData = JSON.stringify(data); - size = putData.length; - } else if (typeof data === 'string') { + if (typeof data === 'string') { putData = data; size = putData.length; } else { - putData = data; + putData = JSON.stringify(data); + size = putData.length; } } else { putData = data as any; - size = null; + // 对于流式上传,如果没有提供 size,会导致多部分上传,ETag 会是 ****-1 格式 + // 必须提供准确的 size 才能得到标准的 MD5 格式 ETag + if (!size) { + throw new Error('Stream upload requires size parameter to avoid multipart upload and get standard MD5 ETag'); + } } if (opts?.check) { const obj = await this.statObject(objectName, true); diff --git a/tsup.config.ts b/tsup.config.ts deleted file mode 100644 index 9797437..0000000 --- a/tsup.config.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { defineConfig } from 'tsup'; -import glob from 'fast-glob'; -const services = glob.sync('src/services/*.ts'); - -export default defineConfig({ - entry: ['src/index.ts', ...services], - target: 'node22', - splitting: false, - sourcemap: false, - clean: true, - format: 'esm', - external: ['minio'], - dts: true, - outDir: 'dist', - tsconfig: 'tsconfig.json', -});