Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/framework-info/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,18 @@ const getFrameworkVersion = async (projectDir, frameworkInfo) => {
// in the event that the project uses something like npm workspaces, and the installed framework package
// has been hoisted to the root directory of the project (which differs from the directory of the project/application being built)
const installedFrameworkPath = await findUp(join('node_modules', npmPackage, 'package.json'), { cwd: projectDir })

if (!installedFrameworkPath) {
return frameworkInfo
}

const { packageJson } = await getPackageJson(installedFrameworkPath)

return {
...frameworkInfo,
package: {
name: npmPackage,
version: packageJson.version || 'unknown',
version: packageJson?.version || 'unknown',
},
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "test",
"version": "1.0.0",
"dependencies": {
"docpad": "*"
}
}
5 changes: 5 additions & 0 deletions packages/framework-info/test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ test('Should return the version of the framework when the installed package is h
t.snapshot(frameworks)
})

test('Should work if version cannot be detected', async (t) => {
const frameworks = await getFrameworks('no-version')
t.snapshot(frameworks)
})

test('Should allow getting a specific framework', async (t) => {
const framework = await getFramework('simple', 'sapper')
t.snapshot(framework)
Expand Down
40 changes: 40 additions & 0 deletions packages/framework-info/test/snapshots/main.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,46 @@ Generated by [AVA](https://avajs.dev).
},
]

## Should work if version cannot be detected

> Snapshot 1

[
{
build: {
commands: [
'docpad generate',
],
directory: 'out',
},
category: 'static_site_generator',
dev: {
commands: [
'docpad run',
],
pollingStrategies: [
{
name: 'TCP',
},
{
name: 'HTTP',
},
],
port: 9778,
},
env: {},
id: 'docpad',
logo: undefined,
name: 'DocPad',
package: {
name: 'docpad',
version: 'unknown',
},
plugins: [],
staticAssetsDirectory: undefined,
},
]

## Should allow getting a specific framework

> Snapshot 1
Expand Down
Binary file modified packages/framework-info/test/snapshots/main.js.snap
Binary file not shown.