@@ -10,7 +10,7 @@ import {
1010 writeFileSync ,
1111 writeJSONSync ,
1212} from 'fs-extra' ;
13- import { resolve } from 'node:path' ;
13+ import { dirname , resolve } from 'node:path' ;
1414
1515import type { Patch } from './types' ;
1616import { rules } from './rules' ;
@@ -34,25 +34,16 @@ export function build(): void {
3434 const unpatchFlag = process . argv . includes ( '--unpatch' ) ;
3535 const forcePatchFlag = process . argv . includes ( '--force-patch' ) ;
3636
37- // Try to find node_modules directory
38- let nodeModulesPath = resolve ( process . cwd ( ) , '../node_modules' ) ;
37+ const unleashedDirectory = resolve ( __dirname , '../unleashed-typescript' ) ;
3938
40- if ( ! existsSync ( nodeModulesPath ) ) {
41- nodeModulesPath = resolve ( process . cwd ( ) , 'node_modules' ) ;
39+ if ( ! existsSync ( unleashedDirectory ) ) {
40+ error ( `unleashed-typescript directory not found at ${ unleashedDirectory } ` ) ;
4241 }
4342
44- if ( ! existsSync ( nodeModulesPath ) ) {
45- error ( 'node_modules direcotry not found.' ) ;
46- }
47-
48- const unleashedDirectory = resolve ( nodeModulesPath , 'unleashed-typescript' ) ;
4943 const unleashedJSON = resolve ( unleashedDirectory , 'unleashed-typescript.json' ) ;
50-
5144 const unleashedDTS = resolve ( unleashedDirectory , 'typescript.d.ts' ) ;
5245 const unleashedJS = resolve ( unleashedDirectory , 'typescript.js' ) ;
5346
54- info ( `unleashed-typescript found at ${ unleashedDirectory } ` ) ;
55-
5647 // Clean build
5748 if ( unpatchFlag || forcePatchFlag ) {
5849 info ( 'Unpatch unleashed-typescript.' ) ;
@@ -70,8 +61,9 @@ export function build(): void {
7061
7162 // Try to find the local typescript package
7263 try {
73- typescript . path = resolve ( nodeModulesPath , 'typescript' ) ;
74- typescript . version = ( readJsonSync ( resolve ( typescript . path , 'package.json' ) ) as { version : string } ) . version ;
64+ typescript . path = dirname ( require . resolve ( 'typescript' ) ) ;
65+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
66+ typescript . version = require ( 'typescript' ) . version as string ;
7567 } catch {
7668 error ( 'typescript package does not seem to be installed.' ) ;
7769 }
0 commit comments