@@ -14,7 +14,13 @@ import { parseRawConfig } from './utils.js'
1414export const rcOptionsTypes = cliOptionsTypes
1515
1616export function cliOptionsTypes ( ) : Record < string , unknown > {
17- return pick ( [ 'init-type' , 'init-package-manager' ] , allTypes )
17+ return {
18+ ...pick ( [
19+ 'init-package-manager' ,
20+ 'init-type' ,
21+ ] , allTypes ) ,
22+ bare : Boolean ,
23+ }
1824}
1925
2026export const commandNames = [ 'init' ]
@@ -34,6 +40,10 @@ export function help (): string {
3440 description : 'Pin the project to the current pnpm version by adding a "packageManager" field to package.json' ,
3541 name : '--init-package-manager' ,
3642 } ,
43+ {
44+ description : 'Create a package.json file with the bare minimum of required fields' ,
45+ name : '--bare' ,
46+ } ,
3747 ] ,
3848 } ,
3949 ] ,
@@ -42,10 +52,17 @@ export function help (): string {
4252 } )
4353}
4454
45- export async function handler (
46- opts : Pick < UniversalOptions , 'rawConfig' > & Pick < Config , 'cliOptions' > & Partial < Pick < Config , 'initPackageManager' | 'initType' > > ,
47- params ?: string [ ]
48- ) : Promise < string > {
55+ export type InitOptions =
56+ & Pick < UniversalOptions , 'rawConfig' >
57+ & Pick < Config , 'cliOptions' >
58+ & Partial < Pick < Config ,
59+ | 'initPackageManager'
60+ | 'initType'
61+ > > & {
62+ bare ?: boolean
63+ }
64+
65+ export async function handler ( opts : InitOptions , params ?: string [ ] ) : Promise < string > {
4966 if ( params ?. length ) {
5067 throw new PnpmError ( 'INIT_ARG' , 'init command does not accept any arguments' , {
5168 hint : `Maybe you wanted to run "pnpm create ${ params . join ( ' ' ) } "` ,
@@ -58,18 +75,20 @@ export async function handler (
5875 if ( fs . existsSync ( manifestPath ) ) {
5976 throw new PnpmError ( 'PACKAGE_JSON_EXISTS' , 'package.json already exists' )
6077 }
61- const manifest : ProjectManifest = {
62- name : path . basename ( process . cwd ( ) ) ,
63- version : '1.0.0' ,
64- description : '' ,
65- main : 'index.js' ,
66- scripts : {
67- test : 'echo "Error: no test specified" && exit 1' ,
68- } ,
69- keywords : [ ] ,
70- author : '' ,
71- license : 'ISC' ,
72- }
78+ const manifest : ProjectManifest = opts . bare
79+ ? { }
80+ : {
81+ name : path . basename ( process . cwd ( ) ) ,
82+ version : '1.0.0' ,
83+ description : '' ,
84+ main : 'index.js' ,
85+ scripts : {
86+ test : 'echo "Error: no test specified" && exit 1' ,
87+ } ,
88+ keywords : [ ] ,
89+ author : '' ,
90+ license : 'ISC' ,
91+ }
7392
7493 if ( opts . initType === 'module' ) {
7594 manifest . type = opts . initType
@@ -83,6 +102,7 @@ export async function handler (
83102 const priority = Object . fromEntries ( [
84103 'name' ,
85104 'version' ,
105+ 'private' ,
86106 'description' ,
87107 'main' ,
88108 'scripts' ,
0 commit comments