Skip to content

Commit 16ef96d

Browse files
authored
Really fix pnpm this time (#111)
* Really fix pnpm this time * Beta 3
1 parent c9d6ac0 commit 16ef96d

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "create-rescript-app",
3-
"version": "1.12.0-beta.2",
3+
"version": "1.12.0-beta.3",
44
"description": "Quickly create new ReScript apps from project templates.",
55
"main": "out/create-rescript-app.cjs",
66
"scripts": {

src/PackageManagers.res

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,23 @@ let defaultPackagerInfo = {packageManager: Npm, command: "npm"}
1717
@scope(("process", "env"))
1818
external npm_execpath: option<string> = "npm_execpath"
1919

20+
@scope(("process", "env"))
21+
external npm_config_user_agent: option<string> = "npm_config_user_agent"
22+
23+
let isPnpmUserAgent = () =>
24+
switch npm_config_user_agent {
25+
| Some(userAgent) =>
26+
userAgent
27+
->String.toLowerCase
28+
->String.split(" ")
29+
->Array.some(segment => segment->String.startsWith("pnpm/"))
30+
| None => false
31+
}
32+
2033
let getPackageManagerInfo = async () =>
34+
// Note: pnpm does not set npm_execpath
2135
switch npm_execpath {
36+
| None if isPnpmUserAgent() => {packageManager: Pnpm, command: "pnpm"}
2237
| None => defaultPackagerInfo
2338
| Some(execPath) =>
2439
// #58: Windows: packageManager may be something like
@@ -41,7 +56,7 @@ let getPackageManagerInfo = async () =>
4156
let isYarn1 = CompareVersions.compareVersions(version, "2.0.0")->Ordering.isLess
4257

4358
Some(isYarn1 ? Yarn1 : YarnBerry)
44-
| _ if filename->String.includes("pnpm") => Some(Pnpm)
59+
| _ if filename->String.includes("pnpm") => Some(Pnpm) // in case pnpm sets npm_execpath in a future version
4560
| _ if filename->String.includes("npm") => Some(Npm) // make sure this goes after pnpm ...
4661
| _ if filename->String.includes("bun") => Some(Bun)
4762
| _ => None

src/RescriptVersions.res

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ let installVersions = async ({rescriptVersion, rescriptCoreVersion}) => {
8585

8686
switch packageManager {
8787
| YarnBerry => await ensureYarnNodeModulesLinker()
88-
| Pnpm => await execCommand("import") // import versions from package-lock.json
88+
| Pnpm =>
89+
let hasPackageLock = Path.join2(Process.cwd(), "package-lock.json")->Fs.existsSync
90+
if hasPackageLock {
91+
await execCommand("import") // import versions from package-lock.json
92+
}
8993
| _ => ()
9094
}
9195

0 commit comments

Comments
 (0)