From cfb2db4f8eed3292cee64d03654e140ca5647744 Mon Sep 17 00:00:00 2001 From: fz6m <59400654+fz6m@users.noreply.github.com> Date: Mon, 29 Aug 2022 18:39:52 +0800 Subject: [PATCH] fix(run): tsx bin path --- packages/plugin-run/src/index.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/plugin-run/src/index.ts b/packages/plugin-run/src/index.ts index ad3408136a7f..b922765dffee 100644 --- a/packages/plugin-run/src/index.ts +++ b/packages/plugin-run/src/index.ts @@ -1,9 +1,9 @@ import assert from 'assert'; import { fork } from 'child_process'; import { writeFileSync } from 'fs'; -import { dirname, join, resolve } from 'path'; +import { dirname, join } from 'path'; import { IApi } from 'umi'; -import { fsExtra } from 'umi/plugin-utils'; +import { fsExtra, resolve } from 'umi/plugin-utils'; export default (api: IApi) => { api.describe({ @@ -49,9 +49,10 @@ export default (api: IApi) => { }; export function getBinPath() { - const pkgPath = join(__dirname, '../node_modules/tsx/package.json'); + // tsx does not export `package.json` subpath, use `resolve` instead of `require.resolve` + const pkgPath = resolve.sync('tsx/package.json', { basedir: __dirname }); const pkgContent = require(pkgPath); - return resolve(dirname(pkgPath), pkgContent.bin); + return join(dirname(pkgPath), pkgContent.bin); } export function getFileNameByPath(params: string) {