From f33284e9e117a0f16a66b16a0788d3e185e5b92b Mon Sep 17 00:00:00 2001 From: Daniel Tschinder <231804+danez@users.noreply.github.com> Date: Tue, 17 Jan 2023 15:54:05 +0100 Subject: [PATCH] fix: Correctly handle missing node_modules --- packages/framework-info/src/main.js | 7 ++- .../test/fixtures/no-version/package.json | 7 +++ packages/framework-info/test/main.js | 5 +++ .../framework-info/test/snapshots/main.js.md | 40 ++++++++++++++++++ .../test/snapshots/main.js.snap | Bin 2110 -> 2320 bytes 5 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 packages/framework-info/test/fixtures/no-version/package.json 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 9234effb8aea6c80f2a05cce41fb58464a9f6373..390814c6ec7bd2441b266c02cfbb352f0191770b 100644 GIT binary patch literal 2320 zcmV+r3GennRzV9vIxC?&K43Z z7}RHGXXa+UnVp&aOolQ4*esj68o%p-i`k(`Hhr_E zi3eEL*%}`oXV_teWf?ZlvNt%5@}I-+A>bRpE5LbkKg%#z0@nc_0}S90YX=^>t2~E( zu_Azf@Vh-S6g>}kc<)mfEl#w$3n+i>@C!dV%hPnu0OcU?Rhl{ydR}`9j{2q` z=1IyLz%%^v0A?%d!h)zs^a$o8dekOMrPggNm5OAkp=yQ|lCwg-5grmpM$*eiCL3zK zE-SOU4b7a0GNI4Pn_;bg_|&Pq6W>pfL~Y*r=lYsqH1sXSqC0)3Wu>YX6k^on>VX3K zTQujKUTk%}D3PkztQ!S=ah8gku@4O(bh<9j*7_83n#n$s_D|?!~eGQxE($s^JrJt!(Zir#VhbUSukXzZP;pX<-vMZj& z-?nGZE=OcOXp4+SjHadtMvVye-4WEPK*U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