Skip to content

Commit 2e9ff5c

Browse files
authored
fix: Correctly handle missing node_modules (#4828)
1 parent 3bcb535 commit 2e9ff5c

File tree

5 files changed

+58
-1
lines changed

5 files changed

+58
-1
lines changed

packages/framework-info/src/main.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,18 @@ const getFrameworkVersion = async (projectDir, frameworkInfo) => {
6363
// in the event that the project uses something like npm workspaces, and the installed framework package
6464
// has been hoisted to the root directory of the project (which differs from the directory of the project/application being built)
6565
const installedFrameworkPath = await findUp(join('node_modules', npmPackage, 'package.json'), { cwd: projectDir })
66+
67+
if (!installedFrameworkPath) {
68+
return frameworkInfo
69+
}
70+
6671
const { packageJson } = await getPackageJson(installedFrameworkPath)
6772

6873
return {
6974
...frameworkInfo,
7075
package: {
7176
name: npmPackage,
72-
version: packageJson.version || 'unknown',
77+
version: packageJson?.version || 'unknown',
7378
},
7479
}
7580
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "test",
3+
"version": "1.0.0",
4+
"dependencies": {
5+
"docpad": "*"
6+
}
7+
}

packages/framework-info/test/main.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ test('Should return the version of the framework when the installed package is h
3232
t.snapshot(frameworks)
3333
})
3434

35+
test('Should work if version cannot be detected', async (t) => {
36+
const frameworks = await getFrameworks('no-version')
37+
t.snapshot(frameworks)
38+
})
39+
3540
test('Should allow getting a specific framework', async (t) => {
3641
const framework = await getFramework('simple', 'sapper')
3742
t.snapshot(framework)

packages/framework-info/test/snapshots/main.js.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,46 @@ Generated by [AVA](https://avajs.dev).
216216
},
217217
]
218218

219+
## Should work if version cannot be detected
220+
221+
> Snapshot 1
222+
223+
[
224+
{
225+
build: {
226+
commands: [
227+
'docpad generate',
228+
],
229+
directory: 'out',
230+
},
231+
category: 'static_site_generator',
232+
dev: {
233+
commands: [
234+
'docpad run',
235+
],
236+
pollingStrategies: [
237+
{
238+
name: 'TCP',
239+
},
240+
{
241+
name: 'HTTP',
242+
},
243+
],
244+
port: 9778,
245+
},
246+
env: {},
247+
id: 'docpad',
248+
logo: undefined,
249+
name: 'DocPad',
250+
package: {
251+
name: 'docpad',
252+
version: 'unknown',
253+
},
254+
plugins: [],
255+
staticAssetsDirectory: undefined,
256+
},
257+
]
258+
219259
## Should allow getting a specific framework
220260

221261
> Snapshot 1
210 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)