Skip to content

Commit

Permalink
feat: inject adds the same dependencies as init now
Browse files Browse the repository at this point in the history
this reduces boilerplate post-inject fixup for the most common plugin workflow
  • Loading branch information
snorrees committed Oct 31, 2022
1 parent c8c8c8a commit dd30373
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 25 deletions.
22 changes: 0 additions & 22 deletions src/actions/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,6 @@ export const initFlags = {

export type InitFlags = TypedFlags<typeof initFlags>

const defaultDependencies = [incompatiblePluginPackage]

const defaultDevDependencies = {
react: forcedPackageVersions.react,
sanity: forcedPackageVersions.sanity,
}
const defaultPeerDependencies = {
react: forcedPackageVersions.react,
sanity: forcedPackageVersions.sanity,
}

export interface InitOptions {
basePath: string
flags: InitFlags
Expand All @@ -88,17 +77,6 @@ export async function init(options: InitOptions) {
let devDependencies = {}
let peerDependencies = {}

dependencies = {...dependencies, ...(await resolveLatestVersions(defaultDependencies))}
devDependencies = {
...devDependencies,
...defaultDevDependencies,
...(await resolveLatestVersions(['rimraf'])),
}
peerDependencies = {
...peerDependencies,
...defaultPeerDependencies,
}

await inject({
...options,
requireUserConfirmation: !options.flags.force,
Expand Down
16 changes: 13 additions & 3 deletions src/npm/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@ import {getPaths, ManifestOptions} from '../sanity/manifest'
import {resolveLatestVersions} from './resolveLatestVersions'
import {hasSourceEquivalent, writeJsonFile} from '../util/files'
import log from '../util/log'
import {cliName} from '../constants'
import {cliName, incompatiblePluginPackage} from '../constants'
import {InjectOptions, PackageData} from '../actions/inject'
import {expectedScripts} from '../actions/verify/validations'
import {PackageJson} from '../actions/verify/types'
import {forcedPackageVersions} from '../configs/forced-package-versions'

const defaultDependencies = [incompatiblePluginPackage]

const defaultDevDependencies = ['rimraf', 'react', 'sanity']
const defaultPeerDependencies = ['react', 'sanity']

const readFile = util.promisify(fs.readFile)

const pathKeys: (keyof PackageJson)[] = ['main', 'module', 'browser', 'types', 'typings']
Expand Down Expand Up @@ -224,16 +229,21 @@ export async function writePackageJson(data: PackageData, options: InjectOptions
}

log.debug('Resolving latest versions for %s', newDevDependencies.join(', '))
const dependencies = forceDependencyVersions({...(prev.dependencies || {}), ...(addDeps || {})})
const dependencies = forceDependencyVersions({
...(prev.dependencies || {}),
...(addDeps || {}),
...(await resolveLatestVersions(defaultDependencies)),
})
const devDependencies = forceDependencyVersions({
...(addDevDeps || {}),
...(prev.devDependencies || {}),
...(await resolveLatestVersions(newDevDependencies)),
...(await resolveLatestVersions([...newDevDependencies, ...defaultDevDependencies])),
})
console.log(devDependencies)
const peerDependencies = forceDependencyVersions({
...(prev.peerDependencies || {}),
...(addPeers || {}),
...(await resolveLatestVersions(defaultPeerDependencies)),
})

const alwaysOnTop = {
Expand Down

0 comments on commit dd30373

Please sign in to comment.