diff --git a/bun.lockb b/bun.lockb index 6d4a570..11b2e88 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/bunfig.toml b/bunfig.toml index d41b9b8..c15aabd 100644 --- a/bunfig.toml +++ b/bunfig.toml @@ -1,2 +1,4 @@ +[install] +registry = "https://registry.npmmirror.com" [test] preload = "./test/happydom.test.ts" \ No newline at end of file diff --git a/nubuild.config.ts b/nubuild.config.ts new file mode 100644 index 0000000..75ec1ad --- /dev/null +++ b/nubuild.config.ts @@ -0,0 +1,13 @@ +import { defineConfig } from '@nubuild/cli' + +export default defineConfig({ + entrypoints: ['./src/index.ts'], + clean: true, + dts: true, + naming: '[name].[ext]', + splitting: true, + minify: true, + format: 'esm', + swc: { jsc: { target: 'es2015' } }, + sourcemap: 'external', +}) diff --git a/package.json b/package.json index 6f3e091..1073cfa 100644 --- a/package.json +++ b/package.json @@ -1,33 +1,37 @@ { "name": "@renzp/utils", "version": "0.3.8", - "description": "一款零依赖、实用的Javascript/Typescript工具库", - "type": "module", - "main": "dist/index.js", - "files": [ - "dist" - ], - "types": "dist/index.d.ts", "author": "renzp <1074720760.qq.com>", "repository": { "type": "git", "url": "git+https://github.com/renzp94/utils.git" }, - "homepage": "https://github.com/renzp94/utils#readme", + "main": "dist/index.js", + "devDependencies": { + "@biomejs/biome": "^1.8.1", + "@happy-dom/global-registrator": "^14.12.0", + "@nubuild/cli": "^0.0.3", + "@type-challenges/utils": "^0.1.1", + "@types/bun": "^1.1.4", + "vitepress": "^1.2.3" + }, + "peerDependencies": { + "typescript": "^5.4.5" + }, "bugs": { "url": "https://github.com/renzp94/utils/issues" }, - "keywords": [ - "utils" - ], + "description": "一款零依赖、实用的Javascript/Typescript工具库", + "files": ["dist"], + "homepage": "https://github.com/renzp94/utils#readme", + "keywords": ["utils"], "license": "MIT", "publishConfig": { "registry": "https://registry.npmjs.org", "access": "public" }, "scripts": { - "build": "bun run scripts/build.ts", - "build:es6": "tsup", + "build": "nubuild build", "pub:npm": "bun run scripts/pub-npm.ts", "pub:jsr": "bun run scripts/pub-jsr.ts", "pub:all": "bun run scripts/pub-all.ts", @@ -35,16 +39,6 @@ "docs:build": "vitepress build docs", "docs:preview": "vitepress preview docs" }, - "devDependencies": { - "@biomejs/biome": "^1.8.1", - "@happy-dom/global-registrator": "^14.12.0", - "@type-challenges/utils": "^0.1.1", - "@types/bun": "^1.1.4", - "bun-plugin-dts": "^0.2.3", - "tsup": "^8.1.0", - "vitepress": "^1.2.3" - }, - "peerDependencies": { - "typescript": "^5.4.5" - } + "type": "module", + "types": "dist/index.d.ts" } diff --git a/scripts/build.ts b/scripts/build.ts deleted file mode 100644 index 0a60a34..0000000 --- a/scripts/build.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { build } from './common' - -const result = await build() - -if (result.success) { - // biome-ignore lint/suspicious/noConsoleLog: - console.log('📦 打包成功 🎉🎉🎉') -} else { - // biome-ignore lint/suspicious/noConsoleLog: - console.log('📦 打包失败 🚨\n') - // biome-ignore lint/suspicious/noConsoleLog: - console.log(result.logs) -} diff --git a/scripts/common.ts b/scripts/common.ts index 0301fb4..934244c 100644 --- a/scripts/common.ts +++ b/scripts/common.ts @@ -1,45 +1,9 @@ -import fs from 'node:fs' -import { exists, readdir, unlink } from 'node:fs/promises' -import path from 'node:path' -import dts from 'bun-plugin-dts' - -/** - * 删除dist 目录 - */ -export const rmDist = async (dir = './dist') => { - const hasDist = await exists('./dist') - if (hasDist) { - const distFiles = await readdir(dir) - const rmFiles = distFiles.map((file) => { - const filepath = `${dir}/${file}` - const stat = fs.statSync(filepath) - if (stat.isDirectory()) { - rmDist(filepath) - } else { - return unlink(`${dir}/${file}`) - } - }) - - return Promise.all(rmFiles) - } -} +import { exists } from 'node:fs/promises' /** * 打包 */ -export const build = async () => { - await rmDist() - return Bun.build({ - entrypoints: ['./src/index.ts'], - outdir: './dist', - naming: '[name].[ext]', - splitting: true, - minify: true, - format: 'esm', - sourcemap: 'external', - plugins: [dts()], - }) -} +export const build = () => Bun.$`bun run build` /** * npm发布 diff --git a/scripts/pub-all.ts b/scripts/pub-all.ts index 3adf293..ceabf0f 100644 --- a/scripts/pub-all.ts +++ b/scripts/pub-all.ts @@ -1,27 +1,6 @@ -import { jsrPublish, npmPublish } from './common' +import { build, jsrPublish, npmPublish } from './common' -// biome-ignore lint/suspicious/noConsoleLog: -console.log('📦 打包中...') -await Bun.$`bun run build:es6` -// biome-ignore lint/suspicious/noConsoleLog: -console.log('📦 打包成功 🎉🎉🎉') +await build() await npmPublish() await jsrPublish() await Bun.$`git push origin --follow-tags` - -// // biome-ignore lint/suspicious/noConsoleLog: -// console.log('📦 打包中...') -// const result = await build() - -// if (result.success) { -// // biome-ignore lint/suspicious/noConsoleLog: -// console.log('📦 打包成功 🎉🎉🎉') -// await npmPublish() -// await jsrPublish() -// await Bun.$`git push origin --follow-tags` -// } else { -// // biome-ignore lint/suspicious/noConsoleLog: -// console.log('📦 打包失败 🚨\n') -// // biome-ignore lint/suspicious/noConsoleLog: -// console.log(result.logs) -// } diff --git a/scripts/pub-npm.ts b/scripts/pub-npm.ts index 924695c..4118894 100644 --- a/scripts/pub-npm.ts +++ b/scripts/pub-npm.ts @@ -1,21 +1,5 @@ -import { npmPublish } from './common' +import { build, npmPublish } from './common' -await Bun.$`bun run build:es6` -// biome-ignore lint/suspicious/noConsoleLog: -console.log('📦 打包成功 🎉🎉🎉') +await build() await npmPublish() await Bun.$`git push origin --follow-tags` - -// const result = await build() - -// if (result.success) { -// // biome-ignore lint/suspicious/noConsoleLog: -// console.log('📦 打包成功 🎉🎉🎉') -// await npmPublish() -// await Bun.$`git push origin --follow-tags` -// } else { -// // biome-ignore lint/suspicious/noConsoleLog: -// console.log('📦 打包失败 🚨\n') -// // biome-ignore lint/suspicious/noConsoleLog: -// console.log(result.logs) -// } diff --git a/tsup.config.ts b/tsup.config.ts deleted file mode 100644 index 4707c4d..0000000 --- a/tsup.config.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { defineConfig } from 'tsup' - -export default defineConfig({ - entry: ['./src/index.ts'], - outDir: './dist', - splitting: true, - target: 'es6', - minify: true, - format: 'esm', - sourcemap: true, - dts: true, - clean: true, -})