diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a62db04..53d6705 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,7 +44,7 @@ jobs: - name: Build asset run: pnpm build:asset - - name: Test + - name: Typecheck run: pnpm typecheck - name: Test diff --git a/package.json b/package.json index 5635d6c..11ea4d4 100644 --- a/package.json +++ b/package.json @@ -17,12 +17,8 @@ "axios", "miniprogram", "request", - "promise", - "alipay", "uni-app", - "wechat", - "fetch", - "network" + "wechat" ], "author": "zjx0905 <954270063@qq.com>", "bugs": { @@ -54,6 +50,7 @@ "devDependencies": { "@commitlint/cli": "^17.4.4", "@commitlint/config-conventional": "^17.4.4", + "@rollup/plugin-typescript": "^11.1.0", "@types/node": "^18.15.5", "@typescript-eslint/eslint-plugin": "^5.55.0", "@typescript-eslint/parser": "^5.55.0", @@ -78,6 +75,7 @@ "rollup-plugin-esbuild": "^5.0.0", "semver": "^7.3.8", "simple-git-hooks": "^2.8.1", + "tslib": "^2.5.0", "typescript": "^5.0.2", "vitest": "^0.30.0" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ed2d888..1ac93a9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6,6 +6,7 @@ importers: specifiers: '@commitlint/cli': ^17.4.4 '@commitlint/config-conventional': ^17.4.4 + '@rollup/plugin-typescript': ^11.1.0 '@types/node': ^18.15.5 '@typescript-eslint/eslint-plugin': ^5.55.0 '@typescript-eslint/parser': ^5.55.0 @@ -30,11 +31,13 @@ importers: rollup-plugin-esbuild: ^5.0.0 semver: ^7.3.8 simple-git-hooks: ^2.8.1 + tslib: ^2.5.0 typescript: ^5.0.2 vitest: ^0.30.0 devDependencies: '@commitlint/cli': 17.5.0 '@commitlint/config-conventional': 17.4.4 + '@rollup/plugin-typescript': 11.1.0_7sniqkrn5rmxrmax2dmiqcv3qu '@types/node': 18.15.5 '@typescript-eslint/eslint-plugin': 5.56.0_2hcjazgfnbtq42tcc73br2vup4 '@typescript-eslint/parser': 5.56.0_j4766f7ecgqbon3u7zlxn5zszu @@ -59,6 +62,7 @@ importers: rollup-plugin-esbuild: 5.0.0_rollup@3.20.0 semver: 7.3.8 simple-git-hooks: 2.8.1 + tslib: 2.5.0 typescript: 5.0.2 vitest: 0.30.0 @@ -2136,6 +2140,26 @@ packages: rollup: 3.20.0 dev: true + /@rollup/plugin-typescript/11.1.0_7sniqkrn5rmxrmax2dmiqcv3qu: + resolution: {integrity: sha512-86flrfE+bSHB69znnTV6kVjkncs2LBMhcTCyxWgRxLyfXfQrxg4UwlAqENnjrrxnSNS/XKCDJCl8EkdFJVHOxw==} + engines: {node: '>=14.0.0'} + peerDependencies: + rollup: ^2.14.0||^3.0.0 + tslib: '*' + typescript: '>=3.7.0' + peerDependenciesMeta: + rollup: + optional: true + tslib: + optional: true + dependencies: + '@rollup/pluginutils': 5.0.2_rollup@3.20.0 + resolve: 1.22.1 + rollup: 3.20.0 + tslib: 2.5.0 + typescript: 5.0.2 + dev: true + /@rollup/pluginutils/3.1.0_rollup@2.79.1: resolution: {integrity: sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg==} engines: {node: '>= 8.0.0'} diff --git a/rollup.config.js b/rollup.config.ts similarity index 81% rename from rollup.config.js rename to rollup.config.ts index dfb3c71..6a6140c 100644 --- a/rollup.config.js +++ b/rollup.config.ts @@ -1,7 +1,8 @@ import { readFileSync } from 'node:fs'; +import { RollupOptions, OutputOptions, Plugin, ModuleFormat } from 'rollup'; import esbuildPlugin from 'rollup-plugin-esbuild'; import dtsPlugin from 'rollup-plugin-dts'; -import { __dirname, distPath, getPkgJSON, resolve } from './scripts/utils.js'; +import { __dirname, distPath, getPkgJSON, resolve } from './scripts/utils'; const pkg = getPkgJSON(); const inputPath = resolve('src/index.ts'); @@ -19,9 +20,9 @@ function main() { return configs; } -function buildConfig(format) { +function buildConfig(format: ModuleFormat | 'dts'): RollupOptions { const isDts = format === 'dts'; - const output = { + const output: OutputOptions = { file: resolveOutput(format, isDts), format: isDts ? 'es' : format, name: pkg.name, @@ -43,7 +44,7 @@ function buildConfig(format) { ] : esbuildPlugin({ tsconfig: resolve('tsconfig.json'), - sourceMap: output.sourcemap, + sourceMap: output.sourcemap as boolean, target: 'es2015', minify: true, }), @@ -51,11 +52,11 @@ function buildConfig(format) { }; } -function resolveOutput(format, isDts) { +function resolveOutput(format: string, isDts?: boolean) { return resolve(distPath, `${pkg.name}${isDts ? '.d.ts' : `.${format}.js`}`); } -function compleTypePlugin(files) { +function compleTypePlugin(files: string[]): Plugin { return { name: 'comple-type', renderChunk: (code) => diff --git a/scripts/build.ts b/scripts/build.ts index 0f2eda9..ae4bd6f 100644 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -16,7 +16,7 @@ function main() { consola.info('Rollup'); try { exec( - `rollup -c ${ + `rollup -c rollup.config.ts --configPlugin typescript ${ watch ? '-w' : '' } --environment SOURCE_MAP:${sourceMap},DTS:${dts}`, ); diff --git a/scripts/release.ts b/scripts/release.ts index 33f3b5e..6c247c5 100644 --- a/scripts/release.ts +++ b/scripts/release.ts @@ -36,6 +36,7 @@ function checkBranch() { const releaseBranch = 'main'; const currentBranch = exec('git branch --show-current', { stdio: 'pipe', + encoding: 'utf-8', }) .toString() .trim(); diff --git a/scripts/utils.js b/scripts/utils.ts similarity index 50% rename from scripts/utils.js rename to scripts/utils.ts index dd4f455..ad54dfe 100644 --- a/scripts/utils.js +++ b/scripts/utils.ts @@ -1,15 +1,25 @@ import path from 'node:path'; import { createRequire } from 'node:module'; import { fileURLToPath } from 'node:url'; -import { execSync } from 'node:child_process'; +import { + ExecSyncOptionsWithStringEncoding, + execSync, +} from 'node:child_process'; export const __dirname = fileURLToPath(new URL('../', import.meta.url)); export const require = createRequire(import.meta.url); export const pkgPath = path.resolve(__dirname, 'package.json'); export const distPath = path.resolve(__dirname, 'dist'); -export const resolve = (...paths) => path.resolve(__dirname, ...paths); -export const exec = (command, options) => - execSync(command, { stdio: 'inherit', ...(options ?? {}) }); +export const resolve = (...paths: string[]) => + path.resolve(__dirname, ...paths); + +export const exec = ( + command: string, + options?: ExecSyncOptionsWithStringEncoding, +) => execSync(command, { stdio: 'inherit', ...(options ?? {}) }); + export const getPkgJSON = () => require(pkgPath); -export const getFileName = (filePath) => filePath.match(/\/([^/]*)$/)[1]; + +export const getFileName = (filePath: string) => + filePath.match(/\/([^/]*)$/)![1]; diff --git a/tsconfig.json b/tsconfig.json index 457e5cf..e09d3b7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,10 +10,18 @@ "moduleResolution": "node", "skipLibCheck": true, "skipDefaultLibCheck": true, + "allowSyntheticDefaultImports": true, "paths": { "@/*": ["src/*"] } }, - "include": ["./src", "./test", "./global.d.ts", "./global.variables.d.ts"], + "include": [ + "./src", + "./test", + "./rollup.config.ts", + "./vitest.config.ts", + "./global.d.ts", + "./global.variables.d.ts" + ], "exclude": ["node_modules", "**/*.md", "**/dist"] }