File tree 2 files changed +30
-9
lines changed
2 files changed +30
-9
lines changed Original file line number Diff line number Diff line change @@ -82,6 +82,18 @@ export async function findProjectDir(
82
82
pkgJsonPath : null ,
83
83
} ,
84
84
) : Promise < ProjectInfo > {
85
+ // Ensure we check for `package.json` first as this defines
86
+ // the root project location.
87
+ if ( result . pkgJsonPath === null ) {
88
+ const pkgJsonPath = path . join ( dir , "package.json" ) ;
89
+ if ( await fileExists ( pkgJsonPath ) ) {
90
+ logDebug ( `Found package.json at ${ pkgJsonPath } ` ) ;
91
+ logDebug ( `Setting project directory to ${ dir } ` ) ;
92
+ result . projectDir = dir ;
93
+ result . pkgJsonPath = pkgJsonPath ;
94
+ }
95
+ }
96
+
85
97
const npmLockfile = path . join ( dir , "package-lock.json" ) ;
86
98
if ( await fileExists ( npmLockfile ) ) {
87
99
logDebug ( `Detected npm from lockfile ${ npmLockfile } ` ) ;
@@ -113,15 +125,6 @@ export async function findProjectDir(
113
125
return result ;
114
126
}
115
127
116
- if ( result . pkgJsonPath === null ) {
117
- const pkgJsonPath = path . join ( dir , "package.json" ) ;
118
- if ( await fileExists ( pkgJsonPath ) ) {
119
- logDebug ( `Found package.json at ${ pkgJsonPath } ` ) ;
120
- result . projectDir = dir ;
121
- result . pkgJsonPath = pkgJsonPath ;
122
- }
123
- }
124
-
125
128
const prev = dir ;
126
129
dir = path . dirname ( dir ) ;
127
130
if ( dir === prev ) {
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import {
12
12
} from "./test_utils" ;
13
13
import * as assert from "node:assert/strict" ;
14
14
import {
15
+ exec ,
15
16
PkgJson ,
16
17
readJson ,
17
18
readTextFile ,
@@ -289,6 +290,23 @@ describe("install", () => {
289
290
) ;
290
291
} ) ;
291
292
293
+ it ( "pnpm install into existing project" , async ( ) => {
294
+ await runInTempDir ( async ( dir ) => {
295
+ const sub = path . join ( dir , "sub" , "sub1" ) ;
296
+ await fs . promises . mkdir ( sub , {
297
+ recursive : true ,
298
+ } ) ;
299
+
300
+ await exec ( "pnpm" , [ "i" , "preact" ] , dir ) ;
301
+
302
+ await runJsr ( [ "i" , "--pnpm" , "@std/encoding@0.216.0" ] , sub ) ;
303
+ assert . ok (
304
+ await isFile ( path . join ( dir , "pnpm-lock.yaml" ) ) ,
305
+ "pnpm lockfile not created" ,
306
+ ) ;
307
+ } ) ;
308
+ } ) ;
309
+
292
310
if ( process . platform !== "win32" ) {
293
311
it ( "jsr add --bun @std/encoding@0.216.0 - forces bun" , async ( ) => {
294
312
await withTempEnv (
You can’t perform that action at this time.
0 commit comments