Skip to content

Commit

Permalink
Make --root the default in workspaces mode. Closes #1353.
Browse files Browse the repository at this point in the history
  • Loading branch information
raineorshine committed Nov 21, 2023
1 parent 5cb1457 commit f9d5bbe
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
3 changes: 2 additions & 1 deletion src/cli-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -797,8 +797,9 @@ const cliOptions: CLIOption[] = [
},
{
long: 'root',
default: true,
description:
'Runs updates on the root project in addition to specified workspaces. Only allowed with `--workspace` or `--workspaces`. (default: false)',
'Runs updates on the root project in addition to specified workspaces. Only allowed with `--workspace` or `--workspaces`. (default: true)',
type: 'boolean',
},
{
Expand Down
47 changes: 26 additions & 21 deletions test/workspaces.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ describe('workspaces', () => {
const tempDir = await setup(['packages/a'])
try {
const output = await spawn('node', [bin, '--jsonAll', '--workspaces'], { cwd: tempDir }).then(JSON.parse)
output.should.not.have.property('package.json')
output.should.have.property('packages/a/package.json')
output.should.not.have.property('packages/b/package.json')
output['packages/a/package.json'].dependencies.should.have.property('ncu-test-tag')
Expand All @@ -150,7 +149,6 @@ describe('workspaces', () => {
const tempDir = await setup()
try {
const output = await spawn('node', [bin, '--jsonAll', '--workspaces'], { cwd: tempDir }).then(JSON.parse)
output.should.not.have.property('package.json')
output.should.have.property('packages/a/package.json')
output.should.have.property('packages/b/package.json')
output['packages/a/package.json'].dependencies.should.have.property('ncu-test-tag')
Expand All @@ -164,7 +162,6 @@ describe('workspaces', () => {
const tempDir = await setup()
try {
const output = await spawn('node', [bin, '--jsonAll', '-ws'], { cwd: tempDir }).then(JSON.parse)
output.should.not.have.property('package.json')
output.should.have.property('packages/a/package.json')
output.should.have.property('packages/b/package.json')
output['packages/a/package.json'].dependencies.should.have.property('ncu-test-tag')
Expand All @@ -189,7 +186,6 @@ describe('workspaces', () => {

try {
const output = await spawn('node', [bin, '--jsonAll', '--workspaces'], { cwd: tempDir }).then(JSON.parse)
output.should.not.have.property('package.json')
output.should.have.property('packages/a/package.json')
output.should.have.property('packages/b/package.json')
output.should.not.have.property('other/package.json')
Expand All @@ -206,7 +202,6 @@ describe('workspaces', () => {
const tempDir = await setup({ packages: ['packages/**'] })
try {
const output = await spawn('node', [bin, '--jsonAll', '--workspaces'], { cwd: tempDir }).then(JSON.parse)
output.should.not.have.property('package.json')
output.should.have.property('packages/a/package.json')
output.should.have.property('packages/b/package.json')
output['packages/a/package.json'].dependencies.should.have.property('ncu-test-tag')
Expand All @@ -224,6 +219,7 @@ describe('workspaces', () => {
JSON.parse,
)
upgrades.should.deep.equal({
'package.json': {},
'packages/foo/package.json': {
'ncu-test-v2': '2.0.0',
},
Expand All @@ -243,6 +239,7 @@ describe('workspaces', () => {
JSON.parse,
)
upgrades.should.deep.equal({
'package.json': {},
'packages/foo/package.json': {
'ncu-test-v2': '2.0.0',
},
Expand Down Expand Up @@ -271,7 +268,6 @@ describe('workspaces', () => {
const tempDir = await setup()
try {
const output = await spawn('node', [bin, '--jsonAll', '--workspace', 'a'], { cwd: tempDir }).then(JSON.parse)
output.should.not.have.property('package.json')
output.should.have.property('packages/a/package.json')
output.should.not.have.property('packages/b/package.json')
output['packages/a/package.json'].dependencies.should.have.property('ncu-test-tag')
Expand All @@ -284,7 +280,6 @@ describe('workspaces', () => {
const tempDir = await setup()
try {
const output = await spawn('node', [bin, '--jsonAll', '-w', 'a'], { cwd: tempDir }).then(JSON.parse)
output.should.not.have.property('package.json')
output.should.have.property('packages/a/package.json')
output.should.not.have.property('packages/b/package.json')
output['packages/a/package.json'].dependencies.should.have.property('ncu-test-tag')
Expand All @@ -299,7 +294,6 @@ describe('workspaces', () => {
const output = await spawn('node', [bin, '--jsonAll', '--workspace', 'a', '--workspace', 'b'], {
cwd: tempDir,
}).then(JSON.parse)
output.should.not.have.property('package.json')
output.should.have.property('packages/a/package.json')
output.should.have.property('packages/b/package.json')
output['packages/a/package.json'].dependencies.should.have.property('ncu-test-tag')
Expand All @@ -316,7 +310,6 @@ describe('workspaces', () => {
const output = await spawn('node', [bin, '--jsonAll', '--workspace', 'a', '--cwd', '../../'], {
cwd: path.join(tempDir, 'packages', 'a'),
}).then(JSON.parse)
output.should.not.have.property('package.json')
output.should.have.property('packages/a/package.json')
output.should.not.have.property('packages/b/package.json')
output['packages/a/package.json'].dependencies.should.have.property('ncu-test-tag')
Expand All @@ -333,6 +326,7 @@ describe('workspaces', () => {
cwd: tempDir,
}).then(JSON.parse)
upgrades.should.deep.equal({
'package.json': {},
'packages/bar/package.json': {
'ncu-test-v2': '2.0.0',
},
Expand All @@ -343,10 +337,10 @@ describe('workspaces', () => {
})
})

describe('--workspaces --root', function () {
describe('--root/--no-root', function () {
this.timeout(60000)

it('update root project and workspaces', async () => {
it('update root project by default', async () => {
const tempDir = await setup()
try {
const output = await spawn('node', [bin, '--jsonAll', '--workspaces', '--root'], { cwd: tempDir }).then(
Expand All @@ -363,10 +357,26 @@ describe('workspaces', () => {
}
})

it('do not update the root project with --no-root', async () => {
const tempDir = await setup()
try {
const output = await spawn('node', [bin, '--jsonAll', '--workspaces', '--no-root'], { cwd: tempDir }).then(
JSON.parse,
)
output.should.not.have.property('package.json')
output.should.have.property('packages/a/package.json')
output.should.have.property('packages/b/package.json')
output['packages/a/package.json'].dependencies.should.have.property('ncu-test-tag')
output['packages/b/package.json'].dependencies.should.have.property('ncu-test-return-version')
} finally {
await fs.rm(tempDir, { recursive: true, force: true })
}
})

it('update root project and workspaces if errorLevel=2', async () => {
const tempDir = await setup()
try {
await spawn('node', [bin, '--upgrade', '--workspaces', '--root', '--errorLevel', '2'], {
await spawn('node', [bin, '--upgrade', '--workspaces', '--errorLevel', '2'], {
cwd: tempDir,
}).should.eventually.be.rejectedWith('Dependencies not up-to-date')
const upgradedPkg = JSON.parse(await fs.readFile(path.join(tempDir, 'package.json'), 'utf-8'))
Expand Down Expand Up @@ -400,9 +410,7 @@ describe('workspaces', () => {
)

try {
const output = await spawn('node', [bin, '--jsonAll', '--workspaces', '--root'], { cwd: tempDir }).then(
JSON.parse,
)
const output = await spawn('node', [bin, '--jsonAll', '--workspaces'], { cwd: tempDir }).then(JSON.parse)
output.should.have.property('package.json')
output.should.have.property('packages/a/package.json')
output.should.have.property('packages/b/package.json')
Expand All @@ -416,15 +424,13 @@ describe('workspaces', () => {
})
})

describe('--workspace and --root', function () {
describe('--workspace should include --root by default', function () {
this.timeout(60000)

it('update root project and single workspace', async () => {
const tempDir = await setup()
try {
const output = await spawn('node', [bin, '--jsonAll', '--workspace', 'a', '--root'], { cwd: tempDir }).then(
JSON.parse,
)
const output = await spawn('node', [bin, '--jsonAll', '--workspace', 'a'], { cwd: tempDir }).then(JSON.parse)
output.should.have.property('package.json')
output.should.have.property('packages/a/package.json')
output.should.not.have.property('packages/b/package.json')
Expand All @@ -438,7 +444,7 @@ describe('workspaces', () => {
it('update more than one workspace', async () => {
const tempDir = await setup()
try {
const output = await spawn('node', [bin, '--jsonAll', '--workspace', 'a', '--workspace', 'b', '--root'], {
const output = await spawn('node', [bin, '--jsonAll', '--workspace', 'a', '--workspace', 'b'], {
cwd: tempDir,
}).then(JSON.parse)
output.should.have.property('package.json')
Expand All @@ -458,7 +464,6 @@ describe('workspaces', () => {
const tempDir = await setup(['packages/**'], { pnpm: true })
try {
const output = await spawn('node', [bin, '--jsonAll', '--workspaces'], { cwd: tempDir }).then(JSON.parse)
output.should.not.have.property('package.json')
output.should.have.property('packages/a/package.json')
output.should.have.property('packages/b/package.json')
output['packages/a/package.json'].dependencies.should.have.property('ncu-test-tag')
Expand Down

0 comments on commit f9d5bbe

Please sign in to comment.