diff --git a/packages/framework-info/src/main.js b/packages/framework-info/src/main.js index e3ef48e7c2..c41f386556 100644 --- a/packages/framework-info/src/main.js +++ b/packages/framework-info/src/main.js @@ -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', }, } } diff --git a/packages/framework-info/test/fixtures/no-version/package.json b/packages/framework-info/test/fixtures/no-version/package.json new file mode 100644 index 0000000000..19a60488b3 --- /dev/null +++ b/packages/framework-info/test/fixtures/no-version/package.json @@ -0,0 +1,7 @@ +{ + "name": "test", + "version": "1.0.0", + "dependencies": { + "docpad": "*" + } +} diff --git a/packages/framework-info/test/main.js b/packages/framework-info/test/main.js index 4686d22e56..28777e2061 100644 --- a/packages/framework-info/test/main.js +++ b/packages/framework-info/test/main.js @@ -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) diff --git a/packages/framework-info/test/snapshots/main.js.md b/packages/framework-info/test/snapshots/main.js.md index d61b6f971b..e00c91b5fa 100644 --- a/packages/framework-info/test/snapshots/main.js.md +++ b/packages/framework-info/test/snapshots/main.js.md @@ -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 diff --git a/packages/framework-info/test/snapshots/main.js.snap b/packages/framework-info/test/snapshots/main.js.snap index 9234effb8a..390814c6ec 100644 Binary files a/packages/framework-info/test/snapshots/main.js.snap and b/packages/framework-info/test/snapshots/main.js.snap differ