Skip to content

Commit cfaa437

Browse files
committed
feat: add mode option for dependents and update test logic
1 parent 380269e commit cfaa437

File tree

5 files changed

+43
-21
lines changed

5 files changed

+43
-21
lines changed

.wiby.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22
"dependents": [
33
{
44
"repository": "https://github.com/wiby-test/partial",
5-
"pullRequest": false
5+
"pullRequest": false,
6+
"mode": "download"
67
},
78
{
89
"repository": "git://github.com/wiby-test/fail",
9-
"pullRequest": false
10+
"pullRequest": false,
11+
"mode": "download"
1012
},
1113
{
1214
"repository": "git+https://github.com/wiby-test/pass",
13-
"pullRequest": true
15+
"pullRequest": true,
16+
"mode": "download"
1417
}
1518
]
1619
}

bin/commands/test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ exports.builder = (yargs) => yargs
1818
})
1919
.option('sha', {
2020
desc: 'Test against a specific commit or branch',
21-
type: 'string'})
21+
type: 'string'
22+
})
2223
.option('mode', {
2324
desc: 'Choose the mode in which the package will be tested',
2425
type: 'string',

lib/test.js

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
const context = require('./context')
44
const github = require('./github')
55
const gitURLParse = require('git-url-parse')
6+
const { exec } = require('child_process')
67
const logger = require('./logger')
8+
const tmp = require('tmp')
9+
const { cp } = require('fs/promises')
10+
const path = require('path')
711

812
// setup logger namespace
913
const testCommandNamespace = 'wiby:test'
@@ -21,19 +25,33 @@ module.exports = async function ({ dependents }) {
2125
const parentDependencyLink = await context.getDependencyLink(parentRepositoryInfo.owner, parentRepositoryInfo.name, parentBranchName)
2226
debug('Commit URL to test:', parentDependencyLink)
2327

24-
for (const { repository: url, pullRequest, sha } of dependents) {
28+
for (const { repository: url, pullRequest, sha, mode } of dependents) {
2529
const dependentRepositoryInfo = gitURLParse(url)
26-
const dependentPkgJson = await github.getPackageJson(dependentRepositoryInfo.owner, dependentRepositoryInfo.name, sha)
27-
debug(`Dependent module: ${dependentRepositoryInfo.owner}/${dependentRepositoryInfo.name}, sha ${sha}`)
2830

29-
if (!context.checkDependentUsesParent(parentPkgJSON.name, dependentPkgJson)) {
30-
throw new Error(`${parentRepositoryInfo.owner}/${parentPkgJSON.name} not found in the package.json of ${dependentRepositoryInfo.owner}/${dependentRepositoryInfo.name}`)
31-
}
32-
33-
const patchedPackageJSON = applyPatch(parentDependencyLink, parentPkgJSON.name, dependentPkgJson, parentPkgJSON.name)
34-
await pushPatch(patchedPackageJSON, dependentRepositoryInfo.owner, dependentRepositoryInfo.name, parentPkgJSON.name, parentBranchName, sha)
35-
if (pullRequest) {
36-
await createPR(dependentRepositoryInfo.owner, dependentRepositoryInfo.name, parentBranchName, parentDependencyLink)
31+
if (mode === 'download') {
32+
debug('Generating tarball')
33+
exec('npm pack')
34+
const { name: tmpDir } = tmp.dirSync()
35+
36+
debug(`Temporary directory: ${tmpDir}`)
37+
debug(`Copying package to ${tmpDir}`)
38+
cp(`${parentPkgJSON.name}-${parentPkgJSON.version}.tgz`, path.join(tmpDir, `${parentPkgJSON.name}-${parentPkgJSON.version}.tgz`))
39+
40+
debug(`Cloning dependent repository ${url} into ${tmpDir}`)
41+
exec(`git clone ${url} ${tmpDir}`, { cwd: tmpDir })
42+
} else {
43+
const dependentPkgJson = await github.getPackageJson(dependentRepositoryInfo.owner, dependentRepositoryInfo.name, sha)
44+
debug(`Dependent module: ${dependentRepositoryInfo.owner}/${dependentRepositoryInfo.name}, sha ${sha}`)
45+
46+
if (!context.checkDependentUsesParent(parentPkgJSON.name, dependentPkgJson)) {
47+
throw new Error(`${parentRepositoryInfo.owner}/${parentPkgJSON.name} not found in the package.json of ${dependentRepositoryInfo.owner}/${dependentRepositoryInfo.name}`)
48+
}
49+
50+
const patchedPackageJSON = applyPatch(parentDependencyLink, parentPkgJSON.name, dependentPkgJson, parentPkgJSON.name)
51+
await pushPatch(patchedPackageJSON, dependentRepositoryInfo.owner, dependentRepositoryInfo.name, parentPkgJSON.name, parentBranchName, sha)
52+
if (pullRequest) {
53+
await createPR(dependentRepositoryInfo.owner, dependentRepositoryInfo.name, parentBranchName, parentDependencyLink)
54+
}
3755
}
3856
}
3957
}

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@
3636
"dotenv": "^16.0.0",
3737
"git-url-parse": "^11.1.2",
3838
"joi": "^17.2.1",
39+
"simple-git": "~3.15.0",
40+
"tmp": "^0.2.1",
3941
"yargs": "^17.0.0"
4042
},
4143
"devDependencies": {
4244
"nock": "^13.0.3",
4345
"semver": "^7.7.1",
44-
"simple-git": "~3.15.0",
4546
"standard": "^16.0.0",
46-
"tap": "^16.0.0",
47-
"tmp": "^0.2.1"
47+
"tap": "^16.0.0"
4848
},
4949
"standard": {
5050
"ignore": [

test/config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,19 @@ tap.test('config validation', async (tap) => {
3737
repository: 'https://github.com/wiby-test/partial',
3838
pullRequest: false,
3939
sha: 'HEAD',
40-
mode: "pull-request"
40+
mode: 'pull-request'
4141
},
4242
{
4343
repository: 'git://github.com/wiby-test/fail',
4444
pullRequest: false,
4545
sha: 'HEAD',
46-
mode: "pull-request"
46+
mode: 'pull-request'
4747
},
4848
{
4949
repository: 'git+https://github.com/wiby-test/pass',
5050
pullRequest: true,
5151
sha: 'HEAD',
52-
mode: "pull-request"
52+
mode: 'pull-request'
5353
}
5454
]
5555
})

0 commit comments

Comments
 (0)