├── CONTRIBUTING.md ├── vitest.setup.ts ├── test ├── fixtures │ └── .gitkeep └── index.test.ts ├── .husky ├── pre-commit └── commit-msg ├── src ├── util.ts └── index.ts ├── .npmrc ├── commitlint.config.ts ├── eslint.config.js ├── .github ├── FUNDING.yml ├── workflows │ ├── test.yml │ └── release.yml └── ISSUE_TEMPLATE │ ├── config.yml │ └── bug_report.yml ├── .editorconfig ├── release.config.js ├── lint-staged.config.js ├── tsconfig.scripts.json ├── scripts ├── clean.ts ├── types.ts └── init │ ├── bin.ts │ └── rename.ts ├── tsup.config.ts ├── vitest.config.ts ├── renovate.json ├── SECURITY.md ├── tsconfig.json ├── README.md ├── LICENSE ├── .gitignore ├── package.json ├── CODE_OF_CONDUCT.md └── .gitattributes /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /vitest.setup.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | npx lint-staged -------------------------------------------------------------------------------- /.husky/commit-msg: -------------------------------------------------------------------------------- 1 | npm run commitlint ${1} 2 | -------------------------------------------------------------------------------- /src/util.ts: -------------------------------------------------------------------------------- 1 | export const hello = () => 'world' 2 | 3 | console.log('Load util 0') 4 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | ## 国内npm源 2 | # registry=http://registry.npmmirror.com/ 3 | 4 | # msvs_version=2017 5 | 6 | # package-manager-strict=false -------------------------------------------------------------------------------- /commitlint.config.ts: -------------------------------------------------------------------------------- 1 | import type { UserConfig } from '@commitlint/types' 2 | 3 | export default { 4 | extends: ['@commitlint/config-conventional'], 5 | } 6 | -------------------------------------------------------------------------------- /eslint.config.js: -------------------------------------------------------------------------------- 1 | import { icebreaker } from '@icebreakers/eslint-config' 2 | 3 | export default icebreaker( 4 | { 5 | ignores: ['test/fixtures'], 6 | }, 7 | ) 8 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/displaying-a-sponsor-button-in-your-repository 2 | 3 | github: [sonofmagic] 4 | custom: ["https://github.com/sonofmagic/sponsors"] 5 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: https://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | [*] 7 | indent_style = space 8 | indent_size = 2 9 | end_of_line = lf 10 | charset = utf-8 11 | trim_trailing_whitespace = false 12 | insert_final_newline = false -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | export const foo = 'bar' 2 | 3 | export function wait(timeout?: number) { 4 | return new Promise((resolve) => { 5 | setTimeout(() => { 6 | resolve(true) 7 | }, timeout) 8 | }) 9 | } 10 | 11 | export const dirname = __dirname 12 | 13 | export * from '@/util' 14 | -------------------------------------------------------------------------------- /test/index.test.ts: -------------------------------------------------------------------------------- 1 | import { foo, wait } from '@/index' 2 | 3 | describe('[Default]', () => { 4 | it('foo should be bar', () => { 5 | expect(foo).toBe('bar') 6 | }) 7 | 8 | it('wait 100ms', async () => { 9 | const flag = await wait(100) 10 | expect(flag).toBe(true) 11 | }) 12 | }) 13 | -------------------------------------------------------------------------------- /release.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('semantic-release').Options} */ 2 | const options = { 3 | branches: [ 4 | 'master', 5 | 'main', 6 | '+([0-9])?(.{+([0-9]),x}).x', 7 | 'next', 8 | { name: 'beta', prerelease: true }, 9 | { name: 'alpha', prerelease: true }, 10 | ], 11 | } 12 | export default options 13 | -------------------------------------------------------------------------------- /lint-staged.config.js: -------------------------------------------------------------------------------- 1 | export default { 2 | '*.{js,jsx,mjs,ts,tsx,mts}': [ 3 | 'eslint --fix', 4 | ], 5 | // '*.{json,md,mdx,css,html,yml,yaml,scss}': [ 6 | // // 'prettier --with-node-modules --ignore-path .prettierignore --write', 7 | // 'eslint --fix', 8 | // ], 9 | // for rust 10 | // '*.rs': ['cargo fmt --'], 11 | } 12 | -------------------------------------------------------------------------------- /tsconfig.scripts.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "target": "ES2022", 5 | "module": "NodeNext", 6 | "moduleResolution": "NodeNext", 7 | "types": [ 8 | "node" 9 | ], 10 | "allowImportingTsExtensions": true 11 | }, 12 | "include": [ 13 | "scripts/**/*.ts" 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /scripts/clean.ts: -------------------------------------------------------------------------------- 1 | import process from 'node:process' 2 | import { deleteAsync } from 'del' 3 | 4 | // 同时兼容 `pnpm clean` and `pnpm clean xxx yyy zzz` 5 | const dirs = process.argv.slice(2) 6 | if (dirs.length === 0) { 7 | dirs.push('dist') 8 | } 9 | const deletedDirectoryPaths = await deleteAsync(dirs) 10 | console.log('Deleted directories:') 11 | console.log(deletedDirectoryPaths.join('\n')) 12 | -------------------------------------------------------------------------------- /scripts/types.ts: -------------------------------------------------------------------------------- 1 | export interface PackageJson { 2 | name: string 3 | description?: string 4 | homepage?: string 5 | bugs?: { 6 | url?: string 7 | [key: string]: unknown 8 | } 9 | repository?: { 10 | url?: string 11 | type?: string 12 | [key: string]: unknown 13 | } 14 | bin?: Record 15 | files?: string[] 16 | [key: string]: unknown 17 | } 18 | -------------------------------------------------------------------------------- /tsup.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'tsup' 2 | 3 | export default defineConfig({ 4 | entry: ['src/index.ts'], // 'src/util.ts'], // , 'src/cli.ts'], 5 | shims: true, 6 | format: ['cjs', 'esm'], 7 | clean: true, 8 | dts: true, 9 | // https://github.com/egoist/tsup/pull/1056 10 | // https://github.com/egoist/tsup/issues?q=cjsInterop 11 | // cjsInterop: true, 12 | // splitting: true, 13 | }) 14 | -------------------------------------------------------------------------------- /vitest.config.ts: -------------------------------------------------------------------------------- 1 | import path from 'node:path' 2 | import { defineConfig } from 'vitest/config' 3 | 4 | export default defineConfig({ 5 | test: { 6 | alias: [ 7 | { 8 | find: '@', 9 | replacement: path.resolve(__dirname, './src'), 10 | }, 11 | ], 12 | globals: true, 13 | coverage: { 14 | enabled: true, 15 | include: ['src/**'], 16 | }, 17 | testTimeout: 60_000, 18 | setupFiles: ['./vitest.setup.ts'], 19 | }, 20 | }) 21 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "extends": [ 4 | "config:recommended", 5 | "group:allNonMajor", 6 | ":semanticCommitTypeAll(chore)" 7 | ], 8 | "commitBody": "[skip netlify]", 9 | "rangeStrategy": "bump", 10 | "npm": { 11 | "commitMessageTopic": "{{prettyDepType}} {{depName}}" 12 | }, 13 | "ignoreDeps": [ 14 | "node" 15 | ], 16 | "automerge": true, 17 | "automergeType": "pr", 18 | "packageRules": [ 19 | { 20 | "matchUpdateTypes": [ 21 | "minor", 22 | "patch", 23 | "pin", 24 | "digest" 25 | ] 26 | } 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Supported Versions 4 | 5 | Use this section to tell people about which versions of your project are 6 | currently being supported with security updates. 7 | 8 | | Version | Supported | 9 | | ------- | ------------------ | 10 | | 5.1.x | :white_check_mark: | 11 | | 5.0.x | :x: | 12 | | 4.0.x | :white_check_mark: | 13 | | < 4.0 | :x: | 14 | 15 | ## Reporting a Vulnerability 16 | 17 | Use this section to tell people how to report a vulnerability. 18 | 19 | Tell them where to go, how often they can expect to get an update on a 20 | reported vulnerability, what to expect if the vulnerability is accepted or 21 | declined, etc. 22 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@tsconfig/recommended/tsconfig.json", 3 | "compilerOptions": { 4 | "target": "es6", 5 | // path 6 | "baseUrl": ".", 7 | "module": "esnext", 8 | "moduleResolution": "Bundler", 9 | "paths": { 10 | "@/*": [ 11 | "src/*" 12 | ] 13 | }, 14 | "types": [ 15 | "vitest/globals", 16 | "node" 17 | ], 18 | "strict": true, 19 | "noEmit": true, 20 | "allowSyntheticDefaultImports": true, 21 | "esModuleInterop": true, 22 | "forceConsistentCasingInFileNames": true, 23 | "isolatedModules": true, 24 | "skipLibCheck": true 25 | }, 26 | "include": [ 27 | "src", 28 | "test" 29 | ], 30 | "exclude": [ 31 | "dist", 32 | "node_modules" 33 | ] 34 | } 35 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: test 2 | 3 | on: 4 | # push: 5 | # branches: 6 | # - main 7 | pull_request: 8 | branches: 9 | - main 10 | - next 11 | - alpha 12 | - beta 13 | workflow_dispatch: 14 | 15 | jobs: 16 | build: 17 | strategy: 18 | fail-fast: false 19 | matrix: 20 | os: [ubuntu-latest, windows-latest, macos-latest] 21 | node-version: [20, 22, 24] 22 | runs-on: ${{ matrix.os }} 23 | steps: 24 | - uses: actions/checkout@v6 25 | - uses: pnpm/action-setup@v4 26 | - uses: actions/setup-node@v6 27 | with: 28 | node-version: ${{ matrix.node-version }} 29 | cache: "pnpm" 30 | 31 | - run: pnpm i 32 | - run: pnpm build 33 | - run: pnpm test 34 | 35 | - uses: codecov/codecov-action@v5 36 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: Feature Request 4 | url: https://github.com/sonofmagic/npm-lib-template/discussions 5 | about: Suggest new features for consideration 6 | # - name: Discord Chat 7 | # url: https://chat.vuejs.org 8 | # about: Ask questions and discuss with other Vue users in real time. 9 | # - name: Questions & Discussions 10 | # url: https://github.com/vuejs/core/discussions 11 | # about: Use GitHub discussions for message-board style questions and discussions. 12 | # - name: Patreon 13 | # url: https://www.patreon.com/evanyou 14 | # about: Love Vue.js? Please consider supporting us via Patreon. 15 | # - name: Open Collective 16 | # url: https://opencollective.com/vuejs/donate 17 | # about: Love Vue.js? Please consider supporting us via Open Collective. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # npm-lib-template 2 | 3 | [![codecov](https://codecov.io/gh/sonofmagic/npm-lib-template/branch/main/graph/badge.svg?token=zn05qXYznt)](https://codecov.io/gh/sonofmagic/npm-lib-template) 4 | 5 | [icebreaker](https://github.com/sonofmagic) 编写的一个 `npm` 包的一个模板 6 | 7 | - 使用 `tsup` 打包 , `rollup` 打包版本在 [rollup](https://github.com/sonofmagic/npm-lib-template/tree/rollup) 分支 (兼容 `tsc`) 8 | - 使用 `vitest` 作为单元测试框架 9 | - 使用 `eslint` 来规范代码风格 10 | - 输出 `dist` -> `cjs`,`esm` and `.d.ts` 11 | - 使用 `semantic-release` 来发布 `npm`/`github` 12 | 13 | ## 为什么使用 `vitest` 而不是原先的 `jest` 14 | 15 | `vitest` 开箱即用, `jest` 在同时遇到 `cjs` 和 `esm` 依赖的时候,支持差,而且配置复杂,依赖的 `preset` 多,比如 `ts-jest`.. 16 | 17 | ## scripts 18 | 19 | ### rename 20 | 21 | 执行 `npm run init:rename` 22 | 23 | 作用为替换 `package.json` 中默认包含的所有名称为 `npm-lib-template` 的字段 24 | 25 | 默认替换为新建代码仓库的文件夹名称! 26 | 27 | ### bin 28 | 29 | 执行 `npm run init:bin` 30 | 31 | 作用为 `package.json` 添加 `files` 和 `bin`,同时生成 `bin/{{pkg.name}}.js` 和 `src/cli.ts` 文件 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 ice breaker 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /scripts/init/bin.ts: -------------------------------------------------------------------------------- 1 | import type { PackageJson } from '../types.ts' 2 | import { access, mkdir, writeFile } from 'node:fs/promises' 3 | import pkgJson from '../../package.json' with { type: 'json' } 4 | 5 | const pkgName = pkgJson.name 6 | 7 | function addBin(json: PackageJson, filename: string): PackageJson { 8 | const next: PackageJson = { 9 | ...json, 10 | bin: { 11 | ...(json.bin ?? {}), 12 | [pkgName]: filename, 13 | }, 14 | } 15 | next.files = Array.isArray(json.files) ? [...json.files, 'bin'] : ['dist', 'bin'] 16 | return next 17 | } 18 | 19 | async function ensureBinDirectory() { 20 | try { 21 | await access('bin') 22 | } 23 | catch { 24 | await mkdir('bin') 25 | } 26 | } 27 | 28 | async function createBin(name: string) { 29 | await ensureBinDirectory() 30 | const filename = `bin/${name}.js` 31 | await writeFile( 32 | filename, 33 | '#!/usr/bin/env node\nimport \'../dist/cli.js\'\n', 34 | ) 35 | return filename 36 | } 37 | 38 | function createCli() { 39 | return writeFile('./src/cli.ts', '// get params from process.argv') 40 | } 41 | 42 | const filename = await createBin(pkgName) 43 | await createCli() 44 | const pkg = addBin({ ...pkgJson } as PackageJson, filename) 45 | await writeFile('./package.json', JSON.stringify(pkg, null, 2)) 46 | console.log('bin create successfully!') 47 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | permissions: 4 | contents: read 5 | 6 | on: 7 | workflow_dispatch: 8 | push: 9 | branches: 10 | - main 11 | - next 12 | - alpha 13 | - beta 14 | 15 | jobs: 16 | release: 17 | permissions: 18 | contents: write # to be able to publish a GitHub release 19 | issues: write # to be able to comment on released issues 20 | pull-requests: write # to be able to comment on released pull requests 21 | id-token: write # to enable use of OIDC for npm provenance 22 | runs-on: ubuntu-latest 23 | steps: 24 | - uses: actions/checkout@v6 25 | with: 26 | fetch-depth: 0 27 | # run before Set node , otherwise show Unable to locate executable file: pnpm error 28 | - name: Install pnpm 29 | uses: pnpm/action-setup@v4 30 | 31 | - name: Set node 32 | uses: actions/setup-node@v6 33 | with: 34 | node-version: 24 35 | cache: pnpm 36 | registry-url: 'https://registry.npmjs.org' 37 | 38 | - name: Install Dependencies 39 | run: pnpm i 40 | 41 | - name: Build 42 | run: pnpm run build 43 | - name: Test 44 | run: pnpm run test 45 | - uses: codecov/codecov-action@v5 46 | - name: Release 47 | run: npx semantic-release 48 | env: 49 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 50 | # NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 51 | # https://github.com/semantic-release/semantic-release/issues/2313 52 | # continue-on-error: true 53 | 54 | # - name: Publish to NPM 55 | # run: pnpm publish --access public --no-git-checks 56 | # env: 57 | # NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} 58 | # NPM_CONFIG_PROVENANCE: true 59 | -------------------------------------------------------------------------------- /scripts/init/rename.ts: -------------------------------------------------------------------------------- 1 | import type { PackageJson } from '../types.ts' 2 | import { writeFile } from 'node:fs/promises' 3 | import path from 'node:path' 4 | import process from 'node:process' 5 | import pkgJson from '../../package.json' with { type: 'json' } 6 | 7 | type ReplaceableKey 8 | = | 'name' 9 | | 'description' 10 | | 'bugs.url' 11 | | 'repository.url' 12 | | 'homepage' 13 | 14 | const TEMPLATE_NAME = 'npm-lib-template' 15 | 16 | /** 17 | * 临时解决方案 18 | * @param ref 19 | * @param name 20 | */ 21 | function doReplace(pkg: PackageJson, ref: ReplaceableKey, name: string) { 22 | switch (ref) { 23 | case 'name': 24 | case 'description': 25 | case 'homepage': { 26 | const current = pkg[ref] 27 | if (typeof current === 'string') { 28 | pkg[ref] = current.replaceAll(TEMPLATE_NAME, name) 29 | } 30 | break 31 | } 32 | case 'bugs.url': { 33 | const current = pkg.bugs?.url 34 | if (typeof current === 'string') { 35 | pkg.bugs = { ...(pkg.bugs ?? {}), url: current.replaceAll(TEMPLATE_NAME, name) } 36 | } 37 | break 38 | } 39 | case 'repository.url': { 40 | const current = pkg.repository?.url 41 | if (typeof current === 'string') { 42 | pkg.repository = { ...(pkg.repository ?? {}), url: current.replaceAll(TEMPLATE_NAME, name) } 43 | } 44 | break 45 | } 46 | } 47 | } 48 | 49 | function replacePkg(name: string) { 50 | const pkg: PackageJson = { ...pkgJson } 51 | 52 | for (const ref of [ 53 | 'name', 54 | 'description', 55 | 'bugs.url', 56 | 'repository.url', 57 | 'homepage', 58 | ] satisfies ReplaceableKey[]) { 59 | doReplace(pkg, ref, name) 60 | console.log(`[${ref}] replace over`) 61 | } 62 | 63 | return pkg 64 | } 65 | 66 | ;(async () => { 67 | const cwd = process.cwd() 68 | const dirname = path.basename(cwd) 69 | const pkg = replacePkg(dirname) 70 | await writeFile('./package.json', JSON.stringify(pkg, null, 2)) 71 | console.log('rename successfully!') 72 | })() 73 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | 106 | types 107 | 108 | stats/*.html 109 | .DS_Store -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "npm-lib-template", 3 | "type": "module", 4 | "version": "0.0.0", 5 | "packageManager": "pnpm@10.25.0", 6 | "description": "icebreaker's npm-lib-template", 7 | "author": "SonOfMagic ", 8 | "license": "MIT", 9 | "homepage": "https://github.com/sonofmagic/npm-lib-template#readme", 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/sonofmagic/npm-lib-template.git" 13 | }, 14 | "bugs": { 15 | "url": "https://github.com/sonofmagic/npm-lib-template/issues" 16 | }, 17 | "keywords": [ 18 | "npm", 19 | "lib", 20 | "ts", 21 | "template" 22 | ], 23 | "exports": { 24 | ".": { 25 | "types": "./dist/index.d.ts", 26 | "import": "./dist/index.js", 27 | "require": "./dist/index.cjs" 28 | }, 29 | "./package.json": "./package.json", 30 | "./*": "./*" 31 | }, 32 | "main": "dist/index.cjs", 33 | "module": "dist/index.js", 34 | "types": "dist/index.d.ts", 35 | "typesVersions": { 36 | "*": { 37 | "*": [ 38 | "./dist/*", 39 | "./dist/index.d.ts" 40 | ] 41 | } 42 | }, 43 | "files": [ 44 | "dist" 45 | ], 46 | "scripts": { 47 | "dev": "tsup --watch --sourcemap", 48 | "build:dev": "tsup --sourcemap", 49 | "build": "tsup", 50 | "test:dev": "vitest", 51 | "test": "vitest run", 52 | "lint": "eslint src", 53 | "lint:fix": "eslint src --fix", 54 | "init:rename": "tsx scripts/init/rename.ts", 55 | "init:bin": "tsx scripts/init/bin.ts", 56 | "clean": "tsx scripts/clean.ts", 57 | "ls:pack": "npm pack --dry-run", 58 | "semantic-release": "semantic-release", 59 | "prepare": "husky", 60 | "commitlint": "commitlint --edit" 61 | }, 62 | "publishConfig": { 63 | "access": "public", 64 | "registry": "https://registry.npmjs.org" 65 | }, 66 | "devDependencies": { 67 | "@commitlint/cli": "^20.2.0", 68 | "@commitlint/config-conventional": "^20.2.0", 69 | "@commitlint/types": "^20.2.0", 70 | "@icebreakers/eslint-config": "^1.6.7", 71 | "@tsconfig/recommended": "^1.0.13", 72 | "@types/fs-extra": "^11.0.4", 73 | "@types/node": "^24.10.4", 74 | "@vitest/coverage-v8": "^4.0.15", 75 | "cross-env": "^10.1.0", 76 | "defu": "^6.1.4", 77 | "del": "^8.0.1", 78 | "es-toolkit": "^1.43.0", 79 | "eslint": "9.39.2", 80 | "fs-extra": "^11.3.2", 81 | "husky": "^9.1.7", 82 | "lint-staged": "^16.2.7", 83 | "pathe": "^2.0.3", 84 | "semantic-release": "^25.0.2", 85 | "tsup": "^8.5.1", 86 | "tsx": "^4.21.0", 87 | "typescript": "^5.9.3", 88 | "vitest": "^4.0.15" 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.yml: -------------------------------------------------------------------------------- 1 | name: "\U0001F41E Bug report" 2 | description: Create a report to help us improve 3 | title: "[Bug]: " 4 | labels: ["bug"] 5 | assignees: 6 | - sonofmagic 7 | body: 8 | - type: markdown 9 | attributes: 10 | value: | 11 | **Before You Start...** 12 | 13 | This form is only for submitting bug reports. If you have a usage question 14 | or are unsure if this is really a bug, make sure to: 15 | 16 | Also try to search for your issue - it may have already been answered or even fixed in the development branch. 17 | However, if you find that an old, closed issue still persists in the latest version, 18 | you should open a new issue using the form below instead of commenting on the old issue. 19 | - type: input 20 | id: version 21 | attributes: 22 | label: version 23 | validations: 24 | required: true 25 | - type: input 26 | id: reproduction-link 27 | attributes: 28 | label: Link to minimal reproduction 29 | description: | 30 | You can always provide a GitHub repository. 31 | 32 | The reproduction should be **minimal** - i.e. it should contain only the bare minimum amount of code needed 33 | to show the bug. 34 | 35 | Please do not just fill in a random link. The issue will be closed if no valid reproduction is provided. 36 | placeholder: Reproduction Link 37 | validations: 38 | required: true 39 | - type: textarea 40 | id: steps-to-reproduce 41 | attributes: 42 | label: Steps to reproduce 43 | description: | 44 | What do we need to do after opening your repro in order to make the bug happen? Clear and concise reproduction instructions are important for us to be able to triage your issue in a timely manner. Note that you can use [Markdown](https://guides.github.com/features/mastering-markdown/) to format lists and code. 45 | placeholder: Steps to reproduce 46 | validations: 47 | required: true 48 | - type: textarea 49 | id: expected 50 | attributes: 51 | label: What is expected? 52 | validations: 53 | required: true 54 | - type: textarea 55 | id: actually-happening 56 | attributes: 57 | label: What is actually happening? 58 | validations: 59 | required: true 60 | - type: textarea 61 | id: system-info 62 | attributes: 63 | label: System Info 64 | description: Output of `npx envinfo --system --npmPackages --binaries` 65 | render: shell 66 | placeholder: System, Binaries 67 | - type: textarea 68 | id: additional-comments 69 | attributes: 70 | label: Any additional comments? 71 | description: e.g. some background/context of how you ran into this bug. 72 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our 6 | community a harassment-free experience for everyone, regardless of age, body 7 | size, visible or invisible disability, ethnicity, sex characteristics, gender 8 | identity and expression, level of experience, education, socio-economic status, 9 | nationality, personal appearance, race, religion, or sexual identity 10 | and orientation. 11 | 12 | We pledge to act and interact in ways that contribute to an open, welcoming, 13 | diverse, inclusive, and healthy community. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to a positive environment for our 18 | community include: 19 | 20 | - Demonstrating empathy and kindness toward other people 21 | - Being respectful of differing opinions, viewpoints, and experiences 22 | - Giving and gracefully accepting constructive feedback 23 | - Accepting responsibility and apologizing to those affected by our mistakes, 24 | and learning from the experience 25 | - Focusing on what is best not just for us as individuals, but for the 26 | overall community 27 | 28 | Examples of unacceptable behavior include: 29 | 30 | - The use of sexualized language or imagery, and sexual attention or 31 | advances of any kind 32 | - Trolling, insulting or derogatory comments, and personal or political attacks 33 | - Public or private harassment 34 | - Publishing others' private information, such as a physical or email 35 | address, without their explicit permission 36 | - Other conduct which could reasonably be considered inappropriate in a 37 | professional setting 38 | 39 | ## Enforcement Responsibilities 40 | 41 | Community leaders are responsible for clarifying and enforcing our standards of 42 | acceptable behavior and will take appropriate and fair corrective action in 43 | response to any behavior that they deem inappropriate, threatening, offensive, 44 | or harmful. 45 | 46 | Community leaders have the right and responsibility to remove, edit, or reject 47 | comments, commits, code, wiki edits, issues, and other contributions that are 48 | not aligned to this Code of Conduct, and will communicate reasons for moderation 49 | decisions when appropriate. 50 | 51 | ## Scope 52 | 53 | This Code of Conduct applies within all community spaces, and also applies when 54 | an individual is officially representing the community in public spaces. 55 | Examples of representing our community include using an official e-mail address, 56 | posting via an official social media account, or acting as an appointed 57 | representative at an online or offline event. 58 | 59 | ## Enforcement 60 | 61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 | reported to the community leaders responsible for enforcement at 63 | <1324318532@qq.com>. 64 | All complaints will be reviewed and investigated promptly and fairly. 65 | 66 | All community leaders are obligated to respect the privacy and security of the 67 | reporter of any incident. 68 | 69 | ## Enforcement Guidelines 70 | 71 | Community leaders will follow these Community Impact Guidelines in determining 72 | the consequences for any action they deem in violation of this Code of Conduct: 73 | 74 | ### 1. Correction 75 | 76 | **Community Impact**: Use of inappropriate language or other behavior deemed 77 | unprofessional or unwelcome in the community. 78 | 79 | **Consequence**: A private, written warning from community leaders, providing 80 | clarity around the nature of the violation and an explanation of why the 81 | behavior was inappropriate. A public apology may be requested. 82 | 83 | ### 2. Warning 84 | 85 | **Community Impact**: A violation through a single incident or series 86 | of actions. 87 | 88 | **Consequence**: A warning with consequences for continued behavior. No 89 | interaction with the people involved, including unsolicited interaction with 90 | those enforcing the Code of Conduct, for a specified period of time. This 91 | includes avoiding interactions in community spaces as well as external channels 92 | like social media. Violating these terms may lead to a temporary or 93 | permanent ban. 94 | 95 | ### 3. Temporary Ban 96 | 97 | **Community Impact**: A serious violation of community standards, including 98 | sustained inappropriate behavior. 99 | 100 | **Consequence**: A temporary ban from any sort of interaction or public 101 | communication with the community for a specified period of time. No public or 102 | private interaction with the people involved, including unsolicited interaction 103 | with those enforcing the Code of Conduct, is allowed during this period. 104 | Violating these terms may lead to a permanent ban. 105 | 106 | ### 4. Permanent Ban 107 | 108 | **Community Impact**: Demonstrating a pattern of violation of community 109 | standards, including sustained inappropriate behavior, harassment of an 110 | individual, or aggression toward or disparagement of classes of individuals. 111 | 112 | **Consequence**: A permanent ban from any sort of public interaction within 113 | the community. 114 | 115 | ## Attribution 116 | 117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 118 | version 2.0, available at 119 | . 120 | 121 | Community Impact Guidelines were inspired by [Mozilla's code of conduct 122 | enforcement ladder](https://github.com/mozilla/diversity). 123 | 124 | [homepage]: https://www.contributor-covenant.org 125 | 126 | For answers to common questions about this code of conduct, see the FAQ at 127 | . Translations are available at 128 | . 129 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # From https://github.com/gitattributes/gitattributes/blob/master/Web.gitattributes 2 | ## GITATTRIBUTES FOR WEB PROJECTS 3 | # 4 | # These settings are for any web project. 5 | # 6 | # Details per file setting: 7 | # text These files should be normalized (i.e. convert CRLF to LF). 8 | # binary These files are binary and should be left untouched. 9 | # 10 | # Note that binary is a macro for -text -diff. 11 | ###################################################################### 12 | 13 | # Auto detect 14 | ## Handle line endings automatically for files detected as 15 | ## text and leave all files detected as binary untouched. 16 | ## This will handle all files NOT defined below. 17 | * text=auto 18 | 19 | # Source code 20 | *.bash text eol=lf 21 | *.bat text eol=crlf 22 | *.cmd text eol=crlf 23 | *.coffee text 24 | *.css text diff=css 25 | *.htm text diff=html 26 | *.html text diff=html 27 | *.inc text 28 | *.ini text 29 | *.js text 30 | *.mjs text 31 | *.cjs text 32 | *.json text 33 | *.jsx text 34 | *.less text 35 | *.ls text 36 | *.map text -diff 37 | *.od text 38 | *.onlydata text 39 | *.php text diff=php 40 | *.pl text 41 | *.ps1 text eol=crlf 42 | *.py text diff=python 43 | *.rb text diff=ruby 44 | *.sass text 45 | *.scm text 46 | *.scss text diff=css 47 | *.sh text eol=lf 48 | .husky/* text eol=lf 49 | *.sql text 50 | *.styl text 51 | *.tag text 52 | *.ts text 53 | *.tsx text 54 | *.xml text 55 | *.xhtml text diff=html 56 | 57 | # Docker 58 | Dockerfile text 59 | 60 | # Documentation 61 | *.ipynb text eol=lf 62 | *.markdown text diff=markdown 63 | *.md text diff=markdown 64 | *.mdwn text diff=markdown 65 | *.mdown text diff=markdown 66 | *.mkd text diff=markdown 67 | *.mkdn text diff=markdown 68 | *.mdtxt text 69 | *.mdtext text 70 | *.txt text 71 | AUTHORS text 72 | CHANGELOG text 73 | CHANGES text 74 | CONTRIBUTING text 75 | COPYING text 76 | copyright text 77 | *COPYRIGHT* text 78 | INSTALL text 79 | license text 80 | LICENSE text 81 | NEWS text 82 | readme text 83 | *README* text 84 | TODO text 85 | 86 | # Templates 87 | *.dot text 88 | *.ejs text 89 | *.erb text 90 | *.haml text 91 | *.handlebars text 92 | *.hbs text 93 | *.hbt text 94 | *.jade text 95 | *.latte text 96 | *.mustache text 97 | *.njk text 98 | *.phtml text 99 | *.svelte text 100 | *.tmpl text 101 | *.tpl text 102 | *.twig text 103 | *.vue text 104 | 105 | # Configs 106 | *.cnf text 107 | *.conf text 108 | *.config text 109 | .editorconfig text 110 | .env text 111 | .gitattributes text 112 | .gitconfig text 113 | .htaccess text 114 | *.lock text -diff 115 | package.json text eol=lf 116 | package-lock.json text eol=lf -diff 117 | pnpm-lock.yaml text eol=lf -diff 118 | .prettierrc text 119 | yarn.lock text -diff 120 | *.toml text 121 | *.yaml text 122 | *.yml text 123 | browserslist text 124 | Makefile text 125 | makefile text 126 | # Fixes syntax highlighting on GitHub to allow comments 127 | tsconfig.json linguist-language=JSON-with-Comments 128 | 129 | # Heroku 130 | Procfile text 131 | 132 | # Graphics 133 | *.ai binary 134 | *.bmp binary 135 | *.eps binary 136 | *.gif binary 137 | *.gifv binary 138 | *.ico binary 139 | *.jng binary 140 | *.jp2 binary 141 | *.jpg binary 142 | *.jpeg binary 143 | *.jpx binary 144 | *.jxr binary 145 | *.pdf binary 146 | *.png binary 147 | *.psb binary 148 | *.psd binary 149 | # SVG treated as an asset (binary) by default. 150 | *.svg text 151 | # If you want to treat it as binary, 152 | # use the following line instead. 153 | # *.svg binary 154 | *.svgz binary 155 | *.tif binary 156 | *.tiff binary 157 | *.wbmp binary 158 | *.webp binary 159 | 160 | # Audio 161 | *.kar binary 162 | *.m4a binary 163 | *.mid binary 164 | *.midi binary 165 | *.mp3 binary 166 | *.ogg binary 167 | *.ra binary 168 | 169 | # Video 170 | *.3gpp binary 171 | *.3gp binary 172 | *.as binary 173 | *.asf binary 174 | *.asx binary 175 | *.avi binary 176 | *.fla binary 177 | *.flv binary 178 | *.m4v binary 179 | *.mng binary 180 | *.mov binary 181 | *.mp4 binary 182 | *.mpeg binary 183 | *.mpg binary 184 | *.ogv binary 185 | *.swc binary 186 | *.swf binary 187 | *.webm binary 188 | 189 | # Archives 190 | *.7z binary 191 | *.gz binary 192 | *.jar binary 193 | *.rar binary 194 | *.tar binary 195 | *.zip binary 196 | 197 | # Fonts 198 | *.ttf binary 199 | *.eot binary 200 | *.otf binary 201 | *.woff binary 202 | *.woff2 binary 203 | 204 | # Executables 205 | *.exe binary 206 | *.pyc binary 207 | # Prevents massive diffs caused by vendored, minified files 208 | **/.yarn/releases/** binary 209 | **/.yarn/plugins/** binary 210 | 211 | # RC files (like .babelrc or .eslintrc) 212 | *.*rc text 213 | 214 | # Ignore files (like .npmignore or .gitignore) 215 | *.*ignore text 216 | 217 | # Prevents massive diffs from built files 218 | dist/* binary --------------------------------------------------------------------------------