Skip to content

Commit e3c99a7

Browse files
author
Lukas Holzer
authored
feat: add detection for nix build system (#4818)
* feat: add detection for nix build system * chore: add tests
1 parent 8eb4160 commit e3c99a7

File tree

2 files changed

+43
-21
lines changed

2 files changed

+43
-21
lines changed

packages/build-info/src/detect-build-system.ts

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ const BUILD_SYSTEMS: Record<string, BuildSystemHandler> = {
3333
const pkgJson = getPkgJson(nxConfigPath)
3434
const { devDependencies } = pkgJson
3535

36-
return Promise.resolve({
36+
return {
3737
name: 'nx',
3838
version: devDependencies?.nx,
39-
})
39+
}
4040
}
4141
},
4242

@@ -48,10 +48,10 @@ const BUILD_SYSTEMS: Record<string, BuildSystemHandler> = {
4848
const pkgJson = getPkgJson(lernaConfigPath)
4949
const { devDependencies } = pkgJson
5050

51-
return Promise.resolve({
51+
return {
5252
name: 'lerna',
5353
version: devDependencies?.lerna,
54-
})
54+
}
5555
}
5656
},
5757

@@ -63,10 +63,10 @@ const BUILD_SYSTEMS: Record<string, BuildSystemHandler> = {
6363
const pkgJson = getPkgJson(turboConfigPath)
6464
const { devDependencies } = pkgJson
6565

66-
return Promise.resolve({
66+
return {
6767
name: 'turbo',
6868
version: devDependencies?.turbo,
69-
})
69+
}
7070
}
7171
},
7272

@@ -78,10 +78,10 @@ const BUILD_SYSTEMS: Record<string, BuildSystemHandler> = {
7878
const pkgJson = getPkgJson(rushConfigPath)
7979
const { devDependencies } = pkgJson
8080

81-
return Promise.resolve({
81+
return {
8282
name: 'rush',
8383
version: devDependencies?.rush,
84-
})
84+
}
8585
}
8686
},
8787

@@ -92,10 +92,10 @@ const BUILD_SYSTEMS: Record<string, BuildSystemHandler> = {
9292
const pkgJson = getPkgJson(lageConfigPath)
9393
const { devDependencies } = pkgJson
9494

95-
return Promise.resolve({
95+
return {
9696
name: 'lage',
9797
version: devDependencies?.lage,
98-
})
98+
}
9999
}
100100
},
101101

@@ -104,9 +104,9 @@ const BUILD_SYSTEMS: Record<string, BuildSystemHandler> = {
104104
const pantsConfigPath = lookFor(pants, baseDir, rootDir)
105105

106106
if (pantsConfigPath) {
107-
return Promise.resolve({
107+
return {
108108
name: 'pants',
109-
})
109+
}
110110
}
111111
},
112112

@@ -115,9 +115,9 @@ const BUILD_SYSTEMS: Record<string, BuildSystemHandler> = {
115115
const buckConfigPath = lookFor(buck, baseDir, rootDir)
116116

117117
if (buckConfigPath) {
118-
return Promise.resolve({
118+
return {
119119
name: 'buck',
120-
})
120+
}
121121
}
122122
},
123123

@@ -126,9 +126,9 @@ const BUILD_SYSTEMS: Record<string, BuildSystemHandler> = {
126126
const gradleConfigPath = lookFor(gradle, baseDir, rootDir)
127127

128128
if (gradleConfigPath) {
129-
return Promise.resolve({
129+
return {
130130
name: 'gradle',
131-
})
131+
}
132132
}
133133
},
134134

@@ -137,12 +137,22 @@ const BUILD_SYSTEMS: Record<string, BuildSystemHandler> = {
137137
const bazelConfigPath = lookFor(bazel, baseDir, rootDir)
138138

139139
if (bazelConfigPath) {
140-
return Promise.resolve({
140+
return {
141141
name: 'bazel',
142-
})
142+
}
143143
}
144144
},
145145

146+
nix: async (baseDir, rootDir) => {
147+
const nix = ['default.nix', 'shell.nix', 'release.nix']
148+
const nixConfigPath = lookFor(nix, baseDir, rootDir)
149+
150+
if (nixConfigPath) {
151+
return {
152+
name: 'nix',
153+
}
154+
}
155+
},
146156
moon: async (baseDir, rootDir) => {
147157
const moon = ['.moon']
148158
const moonConfigPath = lookFor(moon, baseDir, rootDir, 'directory')
@@ -151,10 +161,10 @@ const BUILD_SYSTEMS: Record<string, BuildSystemHandler> = {
151161
const pkgJson = getPkgJson(moonConfigPath)
152162
const { devDependencies } = pkgJson
153163

154-
return Promise.resolve({
164+
return {
155165
name: 'moon',
156166
version: devDependencies?.moon,
157-
})
167+
}
158168
}
159169
},
160170
}

packages/build-info/tests/detect-build-systems.test.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import path from 'path'
1+
import path, { join } from 'path'
22

33
import { expect, test } from 'vitest'
44

@@ -103,6 +103,18 @@ test('detects moonrepo when .moon directory is present', async () => {
103103
expect(buildSystems[0]).toEqual({ name: 'moon', version: '^0.5.1' })
104104
})
105105

106+
test('detects nix when .nix files are present', async () => {
107+
const cwd = mockFileSystem({
108+
'default.nix': '',
109+
'other/shell.nix': '',
110+
})
111+
112+
let buildSystems = await detectBuildSystems(cwd)
113+
expect(buildSystems[0]).toEqual({ name: 'nix' })
114+
buildSystems = await detectBuildSystems(join(cwd, 'other'))
115+
expect(buildSystems[0]).toEqual({ name: 'nix' })
116+
})
117+
106118
test('detects build system in a monorepo setup', async () => {
107119
const cwd = mockFileSystem({
108120
'packages/website/package.json': JSON.stringify({ devDependencies: { turbo: '^1.6.3' } }),

0 commit comments

Comments
 (0)