@@ -234,55 +234,60 @@ module.exports = create({
234234 message : 'Save exact versions:'
235235 }
236236 }
237- }
238- } , async ( initOpts , input ) => {
239- const directory = input . directory || process . cwd ( )
240- const pkgPath = path . resolve ( directory , input . pkgPath || 'package.json' )
237+ } ,
238+ initOptions : async ( input ) => {
239+ const directory = input . directory || process . cwd ( )
240+ const pkgPath = path . resolve ( directory , input . pkgPath || 'package.json' )
241241
242- // Read existing package.json
243- const pkg = input . ignoreExisting ? { } : await readPackageJson ( pkgPath )
242+ // Read existing package.json
243+ const pkg = input . ignoreExisting ? { } : await readPackageJson ( pkgPath )
244244
245- // Derive defaults from input and existing package.json
246- const version = input . version || pkg . version || '1.0.0'
247- const name = scopeAndName ( input . scope , input . name || pkg . name , directory )
248- const type = input . type || pkg . type || 'commonjs'
249- const author = input . author || pkg . author || await git . author ( )
250- const description = input . description || pkg . description
251- const repository = input . repository || ( pkg . repository && pkg . repository . url ) || await git . remote ( input )
252- const keywords = parseList ( input . keywords || pkg . keywords )
245+ // Derive defaults from input and existing package.json
246+ const version = input . version || pkg . version || '1.0.0'
247+ const name = scopeAndName ( input . scope , input . name || pkg . name , directory )
248+ const type = input . type || pkg . type || 'commonjs'
249+ const author = input . author || pkg . author || await git . author ( )
250+ const description = input . description || pkg . description
251+ const repository = input . repository || ( pkg . repository && pkg . repository . url ) || await git . remote ( input )
252+ const keywords = parseList ( input . keywords || pkg . keywords )
253253
254- // Dependencies
255- const dependencies = parseList ( input . dependencies )
256- const devDependencies = parseList ( input . devDependencies )
257- const peerDependencies = parseList ( input . peerDependencies )
254+ // Dependencies
255+ const dependencies = parseList ( input . dependencies )
256+ const devDependencies = parseList ( input . devDependencies )
257+ const peerDependencies = parseList ( input . peerDependencies )
258258
259- // Derive standard scripts
260- const scriptsTest = input . scriptsTest || ( pkg . scripts && pkg . scripts . test ) || 'echo "Error: no test specified" && exit 1'
261- const scriptsPrepare = input . scriptsPrepare || ( pkg . scripts && pkg . scripts . prepare )
262- const scriptsPreVersion = input . scriptsPreVersion || ( pkg . scripts && pkg . scripts . preversion )
263- const scriptsPostPublish = input . scriptsPostPublish || ( pkg . scripts && pkg . scripts . postpublish )
259+ // Derive standard scripts
260+ const scriptsTest = input . scriptsTest || ( pkg . scripts && pkg . scripts . test ) || 'echo "Error: no test specified" && exit 1'
261+ const scriptsPrepare = input . scriptsPrepare || ( pkg . scripts && pkg . scripts . prepare )
262+ const scriptsPreVersion = input . scriptsPreVersion || ( pkg . scripts && pkg . scripts . preversion )
263+ const scriptsPostPublish = input . scriptsPostPublish || ( pkg . scripts && pkg . scripts . postpublish )
264264
265+ return {
266+ pkg,
267+ directory,
268+ pkgPath,
269+ version,
270+ name,
271+ type,
272+ description,
273+ author,
274+ repository,
275+ keywords,
276+ dependencies,
277+ devDependencies,
278+ peerDependencies,
279+ scriptsTest,
280+ scriptsPrepare,
281+ scriptsPreVersion,
282+ scriptsPostPublish
283+ }
284+ }
285+ } , async ( initOpts ) => {
265286 // Process options & prompt for input
266- const opts = await initOpts ( {
267- directory,
268- version,
269- name,
270- type,
271- description,
272- author,
273- repository,
274- keywords,
275- dependencies,
276- devDependencies,
277- peerDependencies,
278- scriptsTest,
279- scriptsPrepare,
280- scriptsPreVersion,
281- scriptsPostPublish
282- } )
287+ const opts = await initOpts ( )
283288
284289 // Format the json and write it out
285- return write ( pkgPath , opts , await format ( opts , pkg ) )
290+ return write ( opts . pkgPath , opts , await format ( opts , opts . pkg ) )
286291} )
287292
288293module . exports . readPackageJson = readPackageJson
0 commit comments