Skip to content

Commit d2a2c07

Browse files
committed
fix: test external modules that have transitive dep on ipfs
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.
1 parent 7ee3d14 commit d2a2c07

File tree

1 file changed

+14
-22
lines changed

1 file changed

+14
-22
lines changed

src/test-external/index.js

+14-22
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,6 @@ const findHttpClientPkg = (targetDir) => {
1818
return require(location.replace('src/index.js', 'package.json'))
1919
}
2020

21-
const isDep = (name, pkg) => {
22-
return Object.keys(pkg.dependencies || {}).filter(dep => dep === name).pop()
23-
}
24-
25-
const isDevDep = (name, pkg) => {
26-
return Object.keys(pkg.devDependencies || {}).filter(dep => dep === name).pop()
27-
}
28-
29-
const isOptionalDep = (name, pkg) => {
30-
return Object.keys(pkg.optionalDendencies || {}).filter(dep => dep === name).pop()
31-
}
32-
33-
const dependsOn = (name, pkg) => {
34-
return isDep(name, pkg) || isDevDep(name, pkg) || isOptionalDep(name, pkg)
35-
}
36-
3721
const isMonoRepo = (targetDir) => {
3822
return fs.existsSync(path.join(targetDir, 'lerna.json'))
3923
}
@@ -64,12 +48,16 @@ const installDependencies = async (targetDir) => {
6448
}
6549
}
6650

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

58+
const linkIPFSInDir = async (targetDir, ipfsDir, ipfsPkg, httpClientPkg) => {
7159
// if the project also depends on the http client, upgrade it to the same version we are using
72-
if (dependsOn('ipfs-http-client', modulePkg)) {
60+
if (fs.existsSync(path.join(targetDir, 'node_modules', 'ipfs-http-client'))) {
7361
console.info('Upgrading ipfs-http-client dependency to', httpClientPkg.version) // eslint-disable-line no-console
7462
await exec('npm', ['install', `ipfs-http-client@${httpClientPkg.version}`], {
7563
cwd: targetDir
@@ -83,6 +71,10 @@ const linkIPFSInDir = async (targetDir, ipfsDir, ipfsPkg, httpClientPkg) => {
8371
await exec('npx', ['connect-deps', 'connect'], {
8472
cwd: targetDir
8573
})
74+
75+
// remove extraneous `ipfs` and `ipfs-http-client` dependencies
76+
console.info('Removing any non-top-level ipfs/ipfs-http-client deps') // eslint-disable-line no-console
77+
await removeExtraIPFSInstalls(targetDir)
8678
}
8779

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

9789
const modulePkg = require(pkgPath)
9890

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

10294
return
10395
}

0 commit comments

Comments
 (0)