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 init flat-options #2213

Closed
wants to merge 1 commit into from
Closed
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
1 change: 0 additions & 1 deletion lib/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ const init = async args => {
}
}
npm.config.set('package', [])
npm.flatOptions = { ...npm.flatOptions, package: [] }
return new Promise((res, rej) => {
npm.commands.exec([packageName, ...args.slice(1)], er => er ? rej(er) : res())
})
Expand Down
33 changes: 29 additions & 4 deletions test/lib/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ t.afterEach(cb => {
result = ''
npm.config = { get: () => '', set () {} }
npm.commands = {}
npm.flatOptions = {}
Object.defineProperty(npm, 'flatOptions', { value: {} })
npm.log = npmLog
cb()
})
Expand All @@ -52,9 +52,7 @@ t.test('classic npm init -y', t => {
npm.config = {
get: () => '~/.npm-init.js',
}
npm.flatOptions = {
yes: true,
}
Object.defineProperty(npm, 'flatOptions', { value: { yes: true} })
npm.log = { ...npm.log }
npm.log.silly = (title, msg) => {
t.equal(title, 'package data', 'should print title')
Expand Down Expand Up @@ -179,6 +177,33 @@ t.test('npm init exec error', t => {
})
})

t.test('should not rewrite flatOptions', t => {
t.plan(4)
Object.defineProperty(npm, 'flatOptions', {
get: () => ({}),
set () {
throw new Error('Should not set flatOptions')
},
})
npm.config = {
set (key, val) {
t.equal(key, 'package', 'should set package key')
t.deepEqual(val, [], 'should set empty array value')
},
}
npm.commands.exec = (arr, cb) => {
t.deepEqual(
arr,
['create-react-app', 'my-app'],
'should npx with extra args'
)
cb()
}
init(['react-app', 'my-app'], err => {
t.ifError(err, 'npm init react-app')
})
})

t.test('npm init cancel', t => {
t.plan(3)
const init = requireInject('../../lib/init.js', {
Expand Down