Skip to content

Commit

Permalink
ci: 调整打包器tsup为nubuild
Browse files Browse the repository at this point in the history
  • Loading branch information
renzp94 committed Aug 5, 2024
1 parent 48fb39c commit 484d61f
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 130 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 2 additions & 0 deletions bunfig.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
[install]
registry = "https://registry.npmmirror.com"
[test]
preload = "./test/happydom.test.ts"
13 changes: 13 additions & 0 deletions nubuild.config.ts
Original file line number Diff line number Diff line change
@@ -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',
})
44 changes: 19 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,50 +1,44 @@
{
"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",
"docs:dev": "vitepress dev docs",
"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"
}
13 changes: 0 additions & 13 deletions scripts/build.ts

This file was deleted.

40 changes: 2 additions & 38 deletions scripts/common.ts
Original file line number Diff line number Diff line change
@@ -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发布
Expand Down
25 changes: 2 additions & 23 deletions scripts/pub-all.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,6 @@
import { jsrPublish, npmPublish } from './common'
import { build, jsrPublish, npmPublish } from './common'

// biome-ignore lint/suspicious/noConsoleLog: <explanation>
console.log('📦 打包中...')
await Bun.$`bun run build:es6`
// biome-ignore lint/suspicious/noConsoleLog: <explanation>
console.log('📦 打包成功 🎉🎉🎉')
await build()
await npmPublish()
await jsrPublish()
await Bun.$`git push origin --follow-tags`

// // biome-ignore lint/suspicious/noConsoleLog: <explanation>
// console.log('📦 打包中...')
// const result = await build()

// if (result.success) {
// // biome-ignore lint/suspicious/noConsoleLog: <explanation>
// console.log('📦 打包成功 🎉🎉🎉')
// await npmPublish()
// await jsrPublish()
// await Bun.$`git push origin --follow-tags`
// } else {
// // biome-ignore lint/suspicious/noConsoleLog: <explanation>
// console.log('📦 打包失败 🚨\n')
// // biome-ignore lint/suspicious/noConsoleLog: <explanation>
// console.log(result.logs)
// }
20 changes: 2 additions & 18 deletions scripts/pub-npm.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
import { npmPublish } from './common'
import { build, npmPublish } from './common'

await Bun.$`bun run build:es6`
// biome-ignore lint/suspicious/noConsoleLog: <explanation>
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: <explanation>
// console.log('📦 打包成功 🎉🎉🎉')
// await npmPublish()
// await Bun.$`git push origin --follow-tags`
// } else {
// // biome-ignore lint/suspicious/noConsoleLog: <explanation>
// console.log('📦 打包失败 🚨\n')
// // biome-ignore lint/suspicious/noConsoleLog: <explanation>
// console.log(result.logs)
// }
13 changes: 0 additions & 13 deletions tsup.config.ts

This file was deleted.

0 comments on commit 484d61f

Please sign in to comment.