diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1b70b01..ef6160b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -38,7 +38,7 @@ pnpm test:watch - 应该对新功能进行单元测试。 - 应该在文档中添加相关的使用介绍及方法。 -## Project Structure +## 项目结构 ``` src/ - 源代码 diff --git a/rollup.config.js b/rollup.config.js index 1c606f2..dfb3c71 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,11 +1,10 @@ -import path from 'node:path'; import { readFileSync } from 'node:fs'; import esbuildPlugin from 'rollup-plugin-esbuild'; import dtsPlugin from 'rollup-plugin-dts'; -import { __dirname, distPath, getPkgJSON } from './scripts/utils.js'; +import { __dirname, distPath, getPkgJSON, resolve } from './scripts/utils.js'; const pkg = getPkgJSON(); -const inputPath = path.resolve(__dirname, 'src/index.ts'); +const inputPath = resolve('src/index.ts'); const sourceMap = process.env.SOURCE_MAP === 'true'; const dts = process.env.DTS === 'true'; @@ -38,12 +37,12 @@ function buildConfig(format) { isDts ? [ dtsPlugin({ - tsconfig: path.resolve(__dirname, 'tsconfig.json'), + tsconfig: resolve('tsconfig.json'), }), - compleTypePlugin([path.resolve(__dirname, 'global.d.ts')]), + compleTypePlugin([resolve('global.d.ts')]), ] : esbuildPlugin({ - tsconfig: path.resolve(__dirname, 'tsconfig.json'), + tsconfig: resolve('tsconfig.json'), sourceMap: output.sourcemap, target: 'es2015', minify: true, @@ -53,10 +52,7 @@ function buildConfig(format) { } function resolveOutput(format, isDts) { - return path.resolve( - distPath, - `${pkg.name}${isDts ? '.d.ts' : `.${format}.js`}`, - ); + return resolve(distPath, `${pkg.name}${isDts ? '.d.ts' : `.${format}.js`}`); } function compleTypePlugin(files) { diff --git a/scripts/releaselog.ts b/scripts/releaselog.ts index 54c471c..40380a2 100644 --- a/scripts/releaselog.ts +++ b/scripts/releaselog.ts @@ -1,10 +1,9 @@ import fs from 'node:fs'; -import path from 'node:path'; import readline from 'node:readline'; -import { __dirname, getPkgJSON } from './utils'; +import { getPkgJSON, resolve } from './utils'; -const changelogPath = path.resolve(__dirname, 'CHANGELOG.md'); -const releaselogPath = path.resolve(__dirname, 'RELEASELOG.md'); +const changelogPath = resolve('CHANGELOG.md'); +const releaselogPath = resolve('RELEASELOG.md'); const { version } = getPkgJSON(); const versionRE = new RegExp(`^# \\[?${version}\\]?[ (]`); diff --git a/scripts/utils.js b/scripts/utils.js index 2835036..dd4f455 100644 --- a/scripts/utils.js +++ b/scripts/utils.js @@ -8,6 +8,7 @@ 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 getPkgJSON = () => require(pkgPath); diff --git a/vitest.config.ts b/vitest.config.ts index f6aac11..c302594 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -1,8 +1,5 @@ -import path from 'node:path'; import { defineConfig } from 'vitest/config'; -import { __dirname } from './scripts/utils'; - -const resolve = (...paths) => path.resolve(__dirname, ...paths); +import { __dirname, resolve } from './scripts/utils'; export default defineConfig({ test: {