Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions workspaces/config/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,12 @@ class Config {
for (const { data } of this.data.values()) {
this.#flatten(data, this.#flatOptions)
}

// Only set 'save' to true if a saveType has been specified
// and if 'save' is false due to non-default config
if (!this.isDefault('save') && this.#flatOptions.saveType) {
this.#flatOptions.save = true
}
this.#flatOptions.nodeBin = this.execPath
this.#flatOptions.npmBin = this.npmBin
process.emit('timeEnd', 'config:load:flatten')
Expand Down
39 changes: 39 additions & 0 deletions workspaces/config/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,45 @@ t.test('finding the global prefix', t => {
t.end()
})

t.test('manages the save flag when flat is retrieved', t => {
const npmPath = __dirname
const buildConfig = async (args = [], envSave = false) => {
const c = new Config({
argv: [process.execPath, __filename, ...args],
shorthands,
definitions,
npmPath,
flatten,
env: {
save: envSave,
},
})
await c.load()
// Ensure test runner environment's npm settings do not change test outcomes
c.set('save', envSave, 'user')
c.set('save', envSave, 'global')
c.set('save', envSave, 'project')
return c
}
t.test('does not override save to true if a save flag is not passed', async t => {
const c = await buildConfig([], false)
t.equal(c.flat.save, false)
})
t.test('does not override save to true if a negative save flag is passed', async t => {
const c = await buildConfig(['--save-dev=false'], false)
t.equal(c.flat.save, false)
})
t.test('overrides save to true if a save flag is passed', async t => {
const c = await buildConfig(['--save-prod'], false)
t.equal(c.flat.save, true)
})
t.test('does not overwrite save if --no-save is present', async t => {
const c = await buildConfig(['--no-save'], true)
t.equal(c.flat.save, false)
})
t.end()
})

t.test('finding the local prefix', t => {
const path = t.testdir({
hasNM: {
Expand Down