Skip to content

Commit dc220cb

Browse files
author
Lukas Holzer
authored
fix: fixes an issue where it could not retrieve the settings for the same root as projectdir (#4996)
* fix: fixes an issue where it could not retrieve the settings for the same root as projectdir * chore: run snapshots not on windows due to path mismatches * chore: fix windows
1 parent 0c15369 commit dc220cb

File tree

4 files changed

+277
-7
lines changed

4 files changed

+277
-7
lines changed
Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`should retrieve the build info for providing a rootDir 1`] = `
4+
{
5+
"buildSystems": [
6+
{
7+
"id": "pnpm",
8+
"name": "PNPM",
9+
"version": undefined,
10+
},
11+
],
12+
"frameworks": [],
13+
"jsWorkspaces": WorkspaceInfo {
14+
"isRoot": true,
15+
"packages": [
16+
{
17+
"name": "@evilcorp/blog",
18+
"path": "packages/blog",
19+
},
20+
{
21+
"name": "@evilcorp/website",
22+
"path": "packages/website",
23+
},
24+
],
25+
"rootDir": "/cleaned-for-snapshot",
26+
},
27+
"packageManager": {
28+
"forceEnvironment": "NETLIFY_USE_PNPM",
29+
"installCommand": "pnpm install",
30+
"lockFile": "pnpm-lock.yaml",
31+
"name": "pnpm",
32+
"runCommand": "pnpm run",
33+
"version": SemVer {
34+
"build": [],
35+
"includePrerelease": false,
36+
"loose": false,
37+
"major": 6,
38+
"minor": 32,
39+
"options": {},
40+
"patch": 18,
41+
"prerelease": [],
42+
"raw": "6.32.18",
43+
"version": "6.32.18",
44+
},
45+
},
46+
"settings": [
47+
{
48+
"baseDirectory": "",
49+
"buildCommand": "pnpm run build --filter @evilcorp/blog",
50+
"devCommand": "pnpm run dev --filter @evilcorp/blog",
51+
"dist": "packages/blog/public",
52+
"env": {},
53+
"framework": {
54+
"id": "astro",
55+
"name": "Astro",
56+
},
57+
"frameworkPort": 3000,
58+
"name": "PNPM + Astro packages/blog",
59+
"packagePath": "packages/blog",
60+
"plugins": [],
61+
"pollingStrategies": [
62+
"TCP",
63+
"HTTP",
64+
],
65+
},
66+
{
67+
"baseDirectory": "",
68+
"buildCommand": "pnpm run build --filter @evilcorp/website",
69+
"devCommand": "pnpm run dev --filter @evilcorp/website",
70+
"dist": "packages/website/.next",
71+
"env": {},
72+
"framework": {
73+
"id": "next",
74+
"name": "Next.js",
75+
},
76+
"frameworkPort": 3000,
77+
"name": "PNPM + Next.js packages/website",
78+
"packagePath": "packages/website",
79+
"plugins": [
80+
"@netlify/plugin-nextjs",
81+
],
82+
"pollingStrategies": [
83+
"TCP",
84+
],
85+
},
86+
],
87+
}
88+
`;
89+
90+
exports[`should retrieve the build info for providing a rootDir and a nested projectDir 1`] = `
91+
{
92+
"buildSystems": [
93+
{
94+
"id": "pnpm",
95+
"name": "PNPM",
96+
"version": undefined,
97+
},
98+
],
99+
"frameworks": [],
100+
"jsWorkspaces": WorkspaceInfo {
101+
"isRoot": false,
102+
"packages": [
103+
{
104+
"name": "@evilcorp/blog",
105+
"path": "packages/blog",
106+
},
107+
{
108+
"name": "@evilcorp/website",
109+
"path": "packages/website",
110+
},
111+
],
112+
"rootDir": "/cleaned-for-snapshot",
113+
},
114+
"packageManager": {
115+
"forceEnvironment": "NETLIFY_USE_PNPM",
116+
"installCommand": "pnpm install",
117+
"lockFile": "pnpm-lock.yaml",
118+
"name": "pnpm",
119+
"runCommand": "pnpm run",
120+
"version": SemVer {
121+
"build": [],
122+
"includePrerelease": false,
123+
"loose": false,
124+
"major": 6,
125+
"minor": 32,
126+
"options": {},
127+
"patch": 18,
128+
"prerelease": [],
129+
"raw": "6.32.18",
130+
"version": "6.32.18",
131+
},
132+
},
133+
"settings": [
134+
{
135+
"baseDirectory": "",
136+
"buildCommand": "pnpm run build --filter @evilcorp/blog",
137+
"devCommand": "pnpm run dev --filter @evilcorp/blog",
138+
"dist": "packages/blog/public",
139+
"env": {},
140+
"framework": {
141+
"id": "astro",
142+
"name": "Astro",
143+
},
144+
"frameworkPort": 3000,
145+
"name": "PNPM + Astro packages/blog",
146+
"packagePath": "packages/blog",
147+
"plugins": [],
148+
"pollingStrategies": [
149+
"TCP",
150+
"HTTP",
151+
],
152+
},
153+
],
154+
}
155+
`;
156+
157+
exports[`should retrieve the build info for providing a rootDir and the same projectDir 1`] = `
158+
{
159+
"buildSystems": [
160+
{
161+
"id": "pnpm",
162+
"name": "PNPM",
163+
"version": undefined,
164+
},
165+
],
166+
"frameworks": [],
167+
"jsWorkspaces": WorkspaceInfo {
168+
"isRoot": true,
169+
"packages": [
170+
{
171+
"name": "@evilcorp/blog",
172+
"path": "packages/blog",
173+
},
174+
{
175+
"name": "@evilcorp/website",
176+
"path": "packages/website",
177+
},
178+
],
179+
"rootDir": "/cleaned-for-snapshot",
180+
},
181+
"packageManager": {
182+
"forceEnvironment": "NETLIFY_USE_PNPM",
183+
"installCommand": "pnpm install",
184+
"lockFile": "pnpm-lock.yaml",
185+
"name": "pnpm",
186+
"runCommand": "pnpm run",
187+
"version": SemVer {
188+
"build": [],
189+
"includePrerelease": false,
190+
"loose": false,
191+
"major": 6,
192+
"minor": 32,
193+
"options": {},
194+
"patch": 18,
195+
"prerelease": [],
196+
"raw": "6.32.18",
197+
"version": "6.32.18",
198+
},
199+
},
200+
"settings": [
201+
{
202+
"baseDirectory": "",
203+
"buildCommand": "pnpm run build --filter @evilcorp/blog",
204+
"devCommand": "pnpm run dev --filter @evilcorp/blog",
205+
"dist": "packages/blog/public",
206+
"env": {},
207+
"framework": {
208+
"id": "astro",
209+
"name": "Astro",
210+
},
211+
"frameworkPort": 3000,
212+
"name": "PNPM + Astro packages/blog",
213+
"packagePath": "packages/blog",
214+
"plugins": [],
215+
"pollingStrategies": [
216+
"TCP",
217+
"HTTP",
218+
],
219+
},
220+
{
221+
"baseDirectory": "",
222+
"buildCommand": "pnpm run build --filter @evilcorp/website",
223+
"devCommand": "pnpm run dev --filter @evilcorp/website",
224+
"dist": "packages/website/.next",
225+
"env": {},
226+
"framework": {
227+
"id": "next",
228+
"name": "Next.js",
229+
},
230+
"frameworkPort": 3000,
231+
"name": "PNPM + Next.js packages/website",
232+
"packagePath": "packages/website",
233+
"plugins": [
234+
"@netlify/plugin-nextjs",
235+
],
236+
"pollingStrategies": [
237+
"TCP",
238+
],
239+
},
240+
],
241+
}
242+
`;

packages/build-info/src/node/get-build-info.test.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { expect, test, afterEach, describe } from 'vitest'
1+
import { platform } from 'os'
2+
import { join } from 'path'
3+
4+
import { afterEach, describe, expect, test } from 'vitest'
25

36
import { createFixture } from '../../tests/helpers.js'
47
import { mockFileSystem } from '../../tests/mock-file-system.js'
@@ -44,6 +47,36 @@ test('should not crash on invalid projects', async (ctx) => {
4447
expect(frameworks).toEqual([])
4548
})
4649

50+
test.skipIf(platform() === 'win32')('should retrieve the build info for providing a rootDir', async (ctx) => {
51+
const fixture = await createFixture('pnpm-workspace', ctx)
52+
const info = await getBuildInfo({ rootDir: fixture.cwd })
53+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
54+
info.jsWorkspaces!.rootDir = '/cleaned-for-snapshot'
55+
expect(info).toMatchSnapshot()
56+
})
57+
58+
test.skipIf(platform() === 'win32')(
59+
'should retrieve the build info for providing a rootDir and the same projectDir',
60+
async (ctx) => {
61+
const fixture = await createFixture('pnpm-workspace', ctx)
62+
const info = await getBuildInfo({ rootDir: fixture.cwd, projectDir: fixture.cwd })
63+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
64+
info.jsWorkspaces!.rootDir = '/cleaned-for-snapshot'
65+
expect(info).toMatchSnapshot()
66+
},
67+
)
68+
69+
test.skipIf(platform() === 'win32')(
70+
'should retrieve the build info for providing a rootDir and a nested projectDir',
71+
async (ctx) => {
72+
const fixture = await createFixture('pnpm-workspace', ctx)
73+
const info = await getBuildInfo({ rootDir: fixture.cwd, projectDir: join(fixture.cwd, 'packages/blog') })
74+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
75+
info.jsWorkspaces!.rootDir = '/cleaned-for-snapshot'
76+
expect(info).toMatchSnapshot()
77+
},
78+
)
79+
4780
describe('Golang', () => {
4881
test('should not detect anything inside a golang workspace', async (ctx) => {
4982
const fixture = await createFixture('go-workspace', ctx)

packages/build-info/src/project.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ describe.concurrent('should resolve paths correctly', () => {
9292
const project = new Project(fs, '', '/root')
9393
expect(project.baseDirectory).toBe(resolve('/root'))
9494
expect(project.relativeBaseDirectory).toBe('')
95-
expect(project.root).toBeUndefined()
95+
expect(project.root).toBe(fs.cwd)
9696
expect(await project.getRootPackageJSON()).toEqual({})
9797
})
9898

packages/build-info/src/project.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,6 @@ export class Project {
9191
this.baseDirectory = fs.resolve(root || '', baseDirectory !== undefined ? baseDirectory : fs.cwd)
9292
this.root = root ? fs.resolve(fs.cwd, root) : undefined
9393

94-
// if the root and the base directory are the same unset the root again as it's not a workspace
95-
if (this.root === this.baseDirectory) {
96-
this.root = undefined
97-
}
98-
9994
this.relativeBaseDirectory =
10095
baseDirectory !== undefined && !fs.isAbsolute(baseDirectory)
10196
? baseDirectory

0 commit comments

Comments
 (0)