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: issue-5280 Ensure save flags update package.json #7233

Open
wants to merge 6 commits into
base: latest
Choose a base branch
from
6 changes: 6 additions & 0 deletions workspaces/config/lib/definitions/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1813,6 +1813,7 @@ define('save-dev', {
return
}

flatOptions.save = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

save-dev

flatOptions.saveType = 'dev'
},
})
Expand Down Expand Up @@ -1849,6 +1850,8 @@ define('save-optional', {
return
}

flatOptions.save = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

save-optional


if (flatOptions.saveType === 'peerOptional') {
return
}
Expand Down Expand Up @@ -1877,6 +1880,8 @@ define('save-peer', {
return
}

flatOptions.save = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

save-peer


if (flatOptions.saveType === 'peerOptional') {
return
}
Expand Down Expand Up @@ -1928,6 +1933,7 @@ define('save-prod', {
return
}

flatOptions.save = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

save-prod

flatOptions.saveType = 'prod'
},
})
Expand Down
41 changes: 27 additions & 14 deletions workspaces/config/test/definitions/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,8 @@ t.test('saveType', t => {
t.strictSame(flat, { saveType: 'dev' }, 'ignore if false and not already prod')
obj['save-prod'] = true
mockDefs()['save-prod'].flatten('save-prod', obj, flat)
t.strictSame(flat, { saveType: 'prod' }, 'set to prod if true')
t.strictSame(flat,
{ saveType: 'prod', save: true }, 'set to prod if true, and set save to true')
t.end()
})

Expand All @@ -601,7 +602,7 @@ t.test('saveType', t => {
t.strictSame(flat, { saveType: 'prod' }, 'ignore if false and not already dev')
obj['save-dev'] = true
mockDefs()['save-dev'].flatten('save-dev', obj, flat)
t.strictSame(flat, { saveType: 'dev' }, 'set to dev if true')
t.strictSame(flat, { saveType: 'dev', save: true }, 'set to dev if true, and set save to true')
t.end()
})

Expand All @@ -625,27 +626,33 @@ t.test('saveType', t => {

t.test('save-peer', t => {
const obj = { 'save-peer': false }
const flat = {}
let flat = {}
mockDefs()['save-peer'].flatten('save-peer', obj, flat)
t.strictSame(flat, {}, 'no effect if false and not yet set')

obj['save-peer'] = true
mockDefs()['save-peer'].flatten('save-peer', obj, flat)
t.strictSame(flat, { saveType: 'peer' }, 'set saveType to peer if unset')
t.strictSame(flat,
{ saveType: 'peer', save: true }, 'set saveType to peer if unset, and set save to true')

flat.saveType = 'optional'
flat = { saveType: 'optional' }
mockDefs()['save-peer'].flatten('save-peer', obj, flat)
t.strictSame(flat, { saveType: 'peerOptional' }, 'set to peerOptional if optional already')
t.strictSame(flat,
{ saveType: 'peerOptional', save: true },
'set to peerOptional, and set save to true if optional already')

flat = { saveType: 'optional' }
mockDefs()['save-peer'].flatten('save-peer', obj, flat)
t.strictSame(flat, { saveType: 'peerOptional' }, 'no effect if already peerOptional')
t.strictSame(flat,
{ saveType: 'peerOptional', save: true }, 'just set save to true if already peerOptional')

obj['save-peer'] = false
flat = { saveType: 'optional' }
mockDefs()['save-peer'].flatten('save-peer', obj, flat)
t.strictSame(flat, { saveType: 'optional' }, 'switch peerOptional to optional if false')

obj['save-peer'] = false
flat.saveType = 'peer'
flat = { saveType: 'peer' }
mockDefs()['save-peer'].flatten('save-peer', obj, flat)
t.strictSame(flat, {}, 'remove saveType if peer and setting false')

Expand All @@ -654,26 +661,32 @@ t.test('saveType', t => {

t.test('save-optional', t => {
const obj = { 'save-optional': false }
const flat = {}
let flat = {}
mockDefs()['save-optional'].flatten('save-optional', obj, flat)
t.strictSame(flat, {}, 'no effect if false and not yet set')

obj['save-optional'] = true
mockDefs()['save-optional'].flatten('save-optional', obj, flat)
t.strictSame(flat, { saveType: 'optional' }, 'set saveType to optional if unset')
t.strictSame(flat, { saveType: 'optional', save: true },
'set saveType to optional if unset, and set save to true')

flat.saveType = 'peer'
flat = { saveType: 'peer' }
mockDefs()['save-optional'].flatten('save-optional', obj, flat)
t.strictSame(flat, { saveType: 'peerOptional' }, 'set to peerOptional if peer already')
t.strictSame(flat,
{ saveType: 'peerOptional', save: true },
'set to peerOptional if peer already, and set save to true')

flat = { saveType: 'peer' }
mockDefs()['save-optional'].flatten('save-optional', obj, flat)
t.strictSame(flat, { saveType: 'peerOptional' }, 'no effect if already peerOptional')
t.strictSame(flat,
{ saveType: 'peerOptional', save: true }, 'just set save to true if already peerOptional')

obj['save-optional'] = false
flat = { saveType: 'peer' }
mockDefs()['save-optional'].flatten('save-optional', obj, flat)
t.strictSame(flat, { saveType: 'peer' }, 'switch peerOptional to peer if false')

flat.saveType = 'optional'
flat = { saveType: 'optional' }
mockDefs()['save-optional'].flatten('save-optional', obj, flat)
t.strictSame(flat, {}, 'remove saveType if optional and setting false')

Expand Down
Loading