@@ -3,7 +3,6 @@ import { createWriteStream, existsSync, promises as fsp } from 'node:fs'
3
3
import http from 'node:http'
4
4
import https from 'node:https'
5
5
import path from 'node:path'
6
- import process from 'node:process'
7
6
import { fileURLToPath } from 'node:url'
8
7
import * as tar from 'tar'
9
8
/**
@@ -28,9 +27,17 @@ export async function fetchAndExtractPackage(options: { name: string, dist?: str
28
27
// 为了兼容低版本 npm,需要 package.json, 这里把外层的 package.json copy 一份到当前位置
29
28
// 判断当前位置是否有 package.json, 如果无从外层 copy 进来
30
29
const commonIntellisensePackageJsonPath = path . join ( url , '..' , 'package.json' )
31
- const distPackageJsonPath = process . env . VITEST ? path . join ( tempDir , '../../' , 'package.json' ) : path . join ( tempDir , 'package.json' )
32
- if ( ! existsSync ( distPackageJsonPath ) ) {
33
- await fsp . copyFile ( commonIntellisensePackageJsonPath , distPackageJsonPath )
30
+ const distPackageJsonPath = path . join ( commonIntellisensePackageJsonPath , '..' , 'package.json' )
31
+ if ( ! existsSync ( commonIntellisensePackageJsonPath ) ) {
32
+ if ( ! existsSync ( distPackageJsonPath ) ) {
33
+ await fsp . writeFile ( commonIntellisensePackageJsonPath , JSON . stringify ( {
34
+ name : 'temp' ,
35
+ version : '1.0.0' ,
36
+ } ) , 'utf-8' )
37
+ }
38
+ else {
39
+ await fsp . copyFile ( commonIntellisensePackageJsonPath , distPackageJsonPath )
40
+ }
34
41
}
35
42
// Create temporary directory
36
43
await fsp . mkdir ( tempDir , { recursive : true } )
0 commit comments