Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: npm-version does not git-commit nor git-tag when package in subdirectory #4885

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion workspaces/libnpmversion/lib/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ module.exports = async (newversion, opts) => {
})
}

const isGitDir = newversion === 'from-git' || await git.is(opts)
const isGitDir = newversion === 'from-git' || Boolean(await git.find(opts))

// ok! now we know the new version, and the old version is in pkg

Expand Down
20 changes: 18 additions & 2 deletions workspaces/libnpmversion/test/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const requireInject = require('require-inject')
const actionLog = []

const gitMock = {
find: async opts => !opts.path.includes('not-git') ? "git" : null,
is: async opts => !/\bnot-git$/.test(opts.path),
spawn: async (args, opts) => actionLog.push(['spawn', args, opts]),
}
Expand Down Expand Up @@ -42,6 +43,9 @@ t.test('test out bumping the version in all the ways', async t => {
git: {
'package-lock.json': JSON.stringify(lock, null, 2),
},
'git/package/a': {
'package-lock.json': JSON.stringify(lock, null, 2),
},
'not-git': {
'npm-shrinkwrap.json': JSON.stringify({
...lock,
Expand All @@ -50,13 +54,21 @@ t.test('test out bumping the version in all the ways', async t => {
},
}, null, 2),
},
'not-git/package/b': {
'npm-shrinkwrap.json': JSON.stringify({
...lock,
packages: {
'': { ...pkg },
},
}, null, 2),
},
})

await t.test('git dir', async t => {
t.afterEach(async () => {
actionLog.length = 0
})
const path = `${dir}/git`
var path = `${dir}/git`
await t.test('major', async t => {
// for this one, let's pretend that the package-lock.json is .gitignored
const { spawn } = gitMock
Expand Down Expand Up @@ -153,6 +165,8 @@ t.test('test out bumping the version in all the ways', async t => {
])
t.equal(pkg.version, '2.2.0')
})
// for these, let's test subdirectories
path = `${dir}/git/packages/a`
await t.test('explicit version', async t => {
t.equal(await version('=v3.2.1', { path, pkg, gitTagVersion: true }), '3.2.1')
t.match(actionLog, [
Expand Down Expand Up @@ -238,7 +252,7 @@ t.test('test out bumping the version in all the ways', async t => {
t.afterEach(async () => {
actionLog.length = 0
})
const path = `${dir}/not-git`
var path = `${dir}/not-git`
await t.test('major', async t => {
t.equal(await version('major', { path, pkg }), '2.0.0')
t.match(actionLog, [
Expand Down Expand Up @@ -312,6 +326,8 @@ t.test('test out bumping the version in all the ways', async t => {
])
t.equal(pkg.version, '3.2.1')
})
// for these, let's test subdirectories
path = `${dir}/not-git/packages/b`
await t.test('invalid version', async t => {
await t.rejects(version('invalid version', { path, pkg }), {
message: 'Invalid version: invalid version',
Expand Down