File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -22,13 +22,15 @@ describe("cli/init", () => {
2222 const cwd = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "paykit-init-" ) ) ;
2323
2424 try {
25- fs . writeFileSync ( path . join ( cwd , "package.json" ) , JSON . stringify ( { dependencies : { } } ) ) ;
26- expect ( detectPaykitCli ( cwd ) ) . toBe ( false ) ;
27-
2825 fs . writeFileSync (
2926 path . join ( cwd , "package.json" ) ,
3027 JSON . stringify ( { dependencies : { paykitjs : "workspace:*" } } ) ,
3128 ) ;
29+ expect ( detectPaykitCli ( cwd ) ) . toBe ( false ) ;
30+
31+ const packageDir = path . join ( cwd , "node_modules" , "paykitjs" ) ;
32+ fs . mkdirSync ( packageDir , { recursive : true } ) ;
33+ fs . writeFileSync ( path . join ( packageDir , "package.json" ) , JSON . stringify ( { name : "paykitjs" } ) ) ;
3234 expect ( detectPaykitCli ( cwd ) ) . toBe ( true ) ;
3335 } finally {
3436 fs . rmSync ( cwd , { force : true , recursive : true } ) ;
Original file line number Diff line number Diff line change 11import { exec } from "node:child_process" ;
22import fs from "node:fs" ;
3+ import { createRequire } from "node:module" ;
34import path from "node:path" ;
45import { promisify } from "node:util" ;
56
@@ -65,7 +66,13 @@ function stripeConfig(): string {
6566}
6667
6768export function detectPaykitCli ( cwd = process . cwd ( ) ) : boolean {
68- return isPackageInstalled ( cwd , "paykitjs" ) ;
69+ try {
70+ const projectRequire = createRequire ( path . join ( cwd , "package.json" ) ) ;
71+ projectRequire . resolve ( "paykitjs/package.json" ) ;
72+ return true ;
73+ } catch {
74+ return false ;
75+ }
6976}
7077
7178function getDevCommand ( pm : PackageManager ) : string {
You can’t perform that action at this time.
0 commit comments