Skip to content

Commit

Permalink
fix(core): allow studio manifest without name & version props
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed Sep 7, 2021
1 parent 85f1d42 commit 8e6d736
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions packages/@sanity/core/src/util/checkRequiredDependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ import semver, {SemVer} from 'semver'
import resolveFrom from 'resolve-from'
import {readJSON, access} from 'fs-extra'
import oneline from 'oneline'
import type {CliCommandContext} from '../types'

import {CliCommandContext} from '../types'
const defaultStudioManifestProps: PartialPackageManifest = {
name: 'studio',
version: '1.0.0',
}

/**
* Checks that the studio has declared and installed the required dependencies
Expand All @@ -24,7 +28,7 @@ export async function checkRequiredDependencies(context: CliCommandContext): Pro
installedStyledComponentsVersion,
] = await Promise.all([
await readBasePeerDependencies(studioPath),
await readPackageManifest(path.join(studioPath, 'package.json')),
await readPackageManifest(path.join(studioPath, 'package.json'), defaultStudioManifestProps),
await readModuleVersion(studioPath, 'styled-components'),
])

Expand Down Expand Up @@ -138,10 +142,13 @@ async function readModuleVersion(studioPath: string, moduleName: string): Promis
* @param packageJsonPath Path to package.json to read
* @returns Reduced package.json with guarantees for name, version and dependency fields
*/
async function readPackageManifest(packageJsonPath: string): Promise<PackageManifest> {
async function readPackageManifest(
packageJsonPath: string,
defaults: Partial<PartialPackageManifest> = {}
): Promise<PackageManifest> {
let manifest: unknown
try {
manifest = await readJSON(packageJsonPath)
manifest = {...defaults, ...(await readJSON(packageJsonPath))}
} catch (err) {
throw new Error(`Failed to read "${packageJsonPath}": ${err.message}`)
}
Expand Down

2 comments on commit 8e6d736

@vercel
Copy link

@vercel vercel bot commented on 8e6d736 Sep 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

test-studio – ./

test-studio-git-next.sanity.build
test-studio.sanity.build

@vercel
Copy link

@vercel vercel bot commented on 8e6d736 Sep 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

perf-studio – ./

perf-studio-git-next.sanity.build
perf-studio.sanity.build

Please sign in to comment.