Skip to content

Commit

Permalink
[cli] Delete Sanity-modules that needs upgrading to work around yarn …
Browse files Browse the repository at this point in the history
…bug (#774)

* [cli] Skip @sanity/cli when resolving versions on `sanity upgrade`

* [cli] Delete Sanity-modules that needs upgrading to work around yarn bug
  • Loading branch information
rexxars committed May 3, 2018
1 parent 0de2f0b commit ceb237c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ import dynamicRequire from '../../util/dynamicRequire'
import getLocalVersion from '../../util/getLocalVersion'
import pkg from '../../../package.json'

export default async (context, target) => {
const defaultOptions = {
includeCli: true
}

export default async (context, target, opts = {}) => {
const {spinner} = context.output
const options = Object.assign({}, defaultOptions, opts)

const sanityModules = filterSanityModules(getLocalManifest(context.workDir))
const resolveOpts = {includeCli: true, target}
const resolveOpts = {includeCli: options.includeCli, target}
const spin = spinner('Resolving latest versions').start()
const versions = await promiseProps(
buildPackageArray(sanityModules, context.workDir, resolveOpts)
Expand Down
26 changes: 24 additions & 2 deletions packages/@sanity/cli/src/commands/upgrade/upgradeDependencies.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import path from 'path'
import fse from 'fs-extra'
import semver from 'semver'
import {padStart} from 'lodash'
import {padStart, noop} from 'lodash'
import readLocalManifest from '@sanity/util/lib/readLocalManifest'
import findSanityModuleVersions from '../../actions/versions/findSanityModuleVersions'
import {getFormatters} from '../versions/printVersionResult'
import debug from '../../debug'

async function deleteIfNotSymlink(modPath) {
const stats = await fse.lstat(modPath).catch(noop)
if (!stats || stats.isSymbolicLink()) {
return null
}

return fse.remove(modPath)
}

export default async (args, context) => {
const {output, workDir, yarn, chalk} = context
Expand All @@ -24,6 +34,7 @@ export default async (args, context) => {

// Find which modules needs update according to the target range
const allNeedsUpdate = await getModulesInNeedOfUpdate(context, targetRange)
debug('In need of update: %s', allNeedsUpdate.map(mod => mod.name).join(', '))

const needsUpdate =
modules.length === 0
Expand All @@ -37,6 +48,15 @@ export default async (args, context) => {
return
}

// Forcefully remove non-symlinked module paths to force upgrade
await Promise.all(
needsUpdate.map(mod =>
deleteIfNotSymlink(
path.join(context.workDir, 'node_modules', mod.name.replace(/\//g, path.sep))
)
)
)

// Replace versions in `package.json`
const versionPrefix = saveExact ? '' : '^'
const oldManifest = await readLocalManifest(workDir)
Expand Down Expand Up @@ -71,6 +91,8 @@ export default async (args, context) => {
// Run `yarn install`
const flags = extOptions.offline ? ['--offline'] : []
const cmd = ['install'].concat(flags)

debug('Running yarn %s', cmd.join(' '))
await yarn(cmd, {...output, rootDir: workDir})

context.output.print('')
Expand All @@ -85,6 +107,6 @@ export default async (args, context) => {
}

async function getModulesInNeedOfUpdate(context, target) {
const versions = await findSanityModuleVersions(context, target)
const versions = await findSanityModuleVersions(context, target, {includeCli: false})
return versions.filter(mod => mod.needsUpdate)
}

0 comments on commit ceb237c

Please sign in to comment.