chore(node-utils): migrate build to tsdown

This commit is contained in:
xingyu4j
2026-03-15 19:40:09 +08:00
parent c1b1fe90fd
commit a1ca296fc0
7 changed files with 69 additions and 17 deletions

View File

@@ -1,7 +0,0 @@
import { defineBuildConfig } from 'unbuild';
export default defineBuildConfig({
clean: true,
declaration: true,
entries: ['src/index'],
});

View File

@@ -12,7 +12,8 @@
"license": "MIT",
"type": "module",
"scripts": {
"stub": "pnpm unbuild --stub"
"build": "node ./scripts/build.mjs",
"stub": "node ./scripts/build.mjs"
},
"files": [
"dist"
@@ -22,7 +23,7 @@
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./src/index.ts",
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"default": "./dist/index.mjs"
}

View File

@@ -0,0 +1,37 @@
import { spawnSync } from 'node:child_process';
const pnpmCommand =
process.env.npm_execpath &&
process.env.npm_execpath.endsWith('.cjs')
? [process.execPath, process.env.npm_execpath]
: [process.platform === 'win32' ? 'pnpm.cmd' : 'pnpm'];
const steps = [
['exec', 'tsdown', '--no-dts'],
[
'exec',
'tsc',
'-p',
'tsconfig.build.json',
'--emitDeclarationOnly',
'--declaration',
'--outDir',
'dist',
],
];
for (const args of steps) {
const [command, ...commandArgs] = pnpmCommand;
const result = spawnSync(command, [...commandArgs, ...args], {
shell: false,
stdio: 'inherit',
});
if (result.error) {
throw result.error;
}
if (result.status !== 0) {
process.exit(result.status ?? 1);
}
}

View File

@@ -1,6 +1,6 @@
import dayjs from 'dayjs';
import timezone from 'dayjs/plugin/timezone';
import utc from 'dayjs/plugin/utc';
import timezone from 'dayjs/plugin/timezone.js';
import utc from 'dayjs/plugin/utc.js';
dayjs.extend(utc);
dayjs.extend(timezone);

View File

@@ -1,10 +1,13 @@
import type { Package } from '@manypkg/get-packages';
import { dirname } from 'node:path';
import {
getPackages as getPackagesFunc,
getPackagesSync as getPackagesSyncFunc,
} from '@manypkg/get-packages';
import { findUpSync } from 'find-up';
import * as manypkg from '@manypkg/get-packages';
import * as findUp from 'find-up';
const { getPackages: getPackagesFunc, getPackagesSync: getPackagesSyncFunc } =
manypkg;
const { findUpSync } = findUp;
/**
* 查找大仓的根目录
@@ -40,7 +43,7 @@ async function getPackages() {
*/
async function getPackage(pkgName: string) {
const { packages } = await getPackages();
return packages.find((pkg) => pkg.packageJson.name === pkgName);
return packages.find((pkg: Package) => pkg.packageJson.name === pkgName);
}
export { findMonorepoRoot, getPackage, getPackages, getPackagesSync };

View File

@@ -0,0 +1,8 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "./tsconfig.json",
"compilerOptions": {
"noEmit": false
},
"exclude": ["node_modules", "src/__tests__"]
}

View File

@@ -0,0 +1,10 @@
import { defineConfig } from 'tsdown';
export default defineConfig({
clean: false,
deps: {
skipNodeModulesBundle: true,
},
entry: ['src/index.ts'],
format: ['esm'],
});