Skip to content

Commit

Permalink
fix: test external modules that have transitive dep on ipfs
Browse files Browse the repository at this point in the history
Goes some way to address ipfs/js-ipfs#2542 in that it changes our
definition of how a module 'depends' on IPFS.  If it's in your
`node_modules` folder, it'll get upgrade to the current release we
are testing.

This means if we're testing module `A` and `A` has a depdendency
graph like `A -> B -> C -> ipfs`, as long as `ipfs` has been hoisted
to the the top level `node_modules` folder, we'll swap it out with
the new version we're trying to release.

It also dedupes `ipfs` and `ipfs-http-client` in the dep tree so
we can be sure we're testing against our `rc`, though this may
cause problems where intermediate deps need updating, but at least
the need for them to be updated will  be visible.
  • Loading branch information
achingbrain committed Oct 21, 2019
1 parent 7ee3d14 commit d2a2c07
Showing 1 changed file with 14 additions and 22 deletions.
36 changes: 14 additions & 22 deletions src/test-external/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,6 @@ const findHttpClientPkg = (targetDir) => {
return require(location.replace('src/index.js', 'package.json'))
}

const isDep = (name, pkg) => {
return Object.keys(pkg.dependencies || {}).filter(dep => dep === name).pop()
}

const isDevDep = (name, pkg) => {
return Object.keys(pkg.devDependencies || {}).filter(dep => dep === name).pop()
}

const isOptionalDep = (name, pkg) => {
return Object.keys(pkg.optionalDendencies || {}).filter(dep => dep === name).pop()
}

const dependsOn = (name, pkg) => {
return isDep(name, pkg) || isDevDep(name, pkg) || isOptionalDep(name, pkg)
}

const isMonoRepo = (targetDir) => {
return fs.existsSync(path.join(targetDir, 'lerna.json'))
}
Expand Down Expand Up @@ -64,12 +48,16 @@ const installDependencies = async (targetDir) => {
}
}

const linkIPFSInDir = async (targetDir, ipfsDir, ipfsPkg, httpClientPkg) => {
const modulePkgPath = path.join(targetDir, 'package.json')
const modulePkg = require(modulePkgPath)
const removeExtraIPFSInstalls = async (targetDir) => {
for await (const extra of glob(targetDir, 'node_modules/**/node_modules/{ipfs,ipfs-http-client}')) {
console.info('Removing extra module', extra) // eslint-disable-line no-console
await fs.remove(extra)
}
}

const linkIPFSInDir = async (targetDir, ipfsDir, ipfsPkg, httpClientPkg) => {
// if the project also depends on the http client, upgrade it to the same version we are using
if (dependsOn('ipfs-http-client', modulePkg)) {
if (fs.existsSync(path.join(targetDir, 'node_modules', 'ipfs-http-client'))) {
console.info('Upgrading ipfs-http-client dependency to', httpClientPkg.version) // eslint-disable-line no-console
await exec('npm', ['install', `ipfs-http-client@${httpClientPkg.version}`], {
cwd: targetDir
Expand All @@ -83,6 +71,10 @@ const linkIPFSInDir = async (targetDir, ipfsDir, ipfsPkg, httpClientPkg) => {
await exec('npx', ['connect-deps', 'connect'], {
cwd: targetDir
})

// remove extraneous `ipfs` and `ipfs-http-client` dependencies
console.info('Removing any non-top-level ipfs/ipfs-http-client deps') // eslint-disable-line no-console
await removeExtraIPFSInstalls(targetDir)
}

const testModule = async (targetDir, ipfsDir, ipfsPkg, httpClientPkg) => {
Expand All @@ -96,8 +88,8 @@ const testModule = async (targetDir, ipfsDir, ipfsPkg, httpClientPkg) => {

const modulePkg = require(pkgPath)

if (!dependsOn('ipfs', modulePkg) && !dependsOn('ipfs-http-client', modulePkg)) {
console.info(`Module ${modulePkg.name} does not depend on IPFS or the IPFS HTTP Client`) // eslint-disable-line no-console
if (!fs.existsSync(path.join(targetDir, 'node_modules', 'ipfs')) && !fs.existsSync(path.join(targetDir, 'node_modules', 'ipfs'))) {
console.info(`Module ${modulePkg.name} have IPFS or the IPFS HTTP Client in it's dependency tree`) // eslint-disable-line no-console

return
}
Expand Down

0 comments on commit d2a2c07

Please sign in to comment.