Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

init-package-json

npm8.3mISC8.0.0TypeScript support: definitely-typed

A node module to get your node module started

init, package.json, package, helper, wizard, wizerd, prompt, start

readme

init-package-json

A node module to get your node module started.

Usage

const init = require('init-package-json')
const path = require('path')

// a path to a promzard module.  In the event that this file is
// not found, one will be provided for you.
const initFile = path.resolve(process.env.HOME, '.npm-init')

// the dir where we're doin stuff.
const dir = process.cwd()

// extra stuff that gets put into the PromZard module's context.
// In npm, this is the resolved config object.  Exposed as 'config'
// Optional.
const configData = { some: 'extra stuff' }

// Any existing stuff from the package.json file is also exposed in the
// PromZard module as the `package` object.  There will also be three
// vars for:
// * `filename` path to the package.json file
// * `basename` the tip of the package dir
// * `dirname` the parent of the package dir

const data = await init(dir, initFile, configData)
// the data's already been written to {dir}/package.json
// now you can do stuff with it

See PromZard for details about what can go in the config file.

changelog

Changelog

8.0.0 (2024-12-02)

⚠️ BREAKING CHANGES

  • this module is now compatible with the following node versions: ^20.17.0 || >=22.9.0
  • adds a new type prompt and changes the sort order of created packages

    Features

  • 5eeea50 #313 adds type, sorting (#313) (@reggi)

    Bug Fixes

  • f4c1430 update node engines to ^20.17.0 || >=22.9.0 (#318) (@wraithgar)

    Chores

  • 47339ef #311 bump @npmcli/config from 8.3.4 to 9.0.0 (#311) (@dependabot[bot])
  • 2ccbf30 #310 bump @npmcli/template-oss from 4.23.3 to 4.23.4 (#310) (@dependabot[bot], @npm-cli-bot)

7.0.2 (2024-12-02)

Bug Fixes

  • c96ad4a #315 default git repository value if exist (#315) (@milaninfy)

7.0.1 (2024-10-02)

Dependencies

7.0.0 (2024-09-26)

⚠️ BREAKING CHANGES

6.0.3 (2024-05-04)

Bug Fixes

Chores

  • c089e8c #284 increase tap timeout (@lukekarrys)
  • d9deb25 #284 bump @npmcli/template-oss to 4.22.0 (@lukekarrys)
  • 5b599d7 #284 postinstall for dependabot template-oss PR (@lukekarrys)
  • 2421ced #282 bump @npmcli/template-oss from 4.21.3 to 4.21.4 (@dependabot[bot])

6.0.2 (2024-03-01)

Dependencies

  • 4e2383e #275 bump @npmcli/package-json from 4.0.1 to 5.0.0 (#275) (@dependabot[bot])

6.0.1 (2024-02-29)

Bug Fixes

  • 4eca245 #263 move to @npmcli/package-json (@wraithgar)

Dependencies

Chores

  • 0a12bd7 #273 bump @npmcli/config from 7.2.0 to 8.2.0 (#273) (@dependabot[bot])
  • b216462 #267 postinstall for dependabot template-oss PR (@lukekarrys)
  • 36addd8 #267 bump @npmcli/template-oss from 4.21.1 to 4.21.3 (@dependabot[bot])
  • 38ee762 #261 postinstall for dependabot template-oss PR (@lukekarrys)
  • 642e170 #261 bump @npmcli/template-oss from 4.19.0 to 4.21.1 (@dependabot[bot])
  • 4a9b5f1 #239 postinstall for dependabot template-oss PR (@lukekarrys)
  • 0920582 #239 bump @npmcli/template-oss from 4.18.1 to 4.19.0 (@dependabot[bot])
  • 9e08db3 #238 postinstall for dependabot template-oss PR (@lukekarrys)
  • 4a274d1 #238 bump @npmcli/template-oss from 4.18.0 to 4.18.1 (@dependabot[bot])

6.0.0 (2023-08-15)

⚠️ BREAKING CHANGES

  • support for node 14 has been removed

Bug Fixes

Dependencies

  • 9eccb04 #233 bump read-package-json from 6.0.4 to 7.0.0
  • 3024040 #234 bump npm-package-arg from 10.1.0 to 11.0.0

5.0.0 (2023-02-06)

⚠️ BREAKING CHANGES

  • this module is now Promise only and no longer accepts a callback parameter

Features

4.0.1 (2022-10-18)

Dependencies

  • 4dea768 #172 bump npm-package-arg from 9.1.2 to 10.0.0

4.0.0 (2022-10-14)

⚠️ BREAKING CHANGES

  • init-package-json is now compatible with the following semver range for node: ^14.17.0 || ^16.13.0 || >=18.0.0

Features

  • e8ea83a #159 postinstall for dependabot template-oss PR (@lukekarrys)

Dependencies

  • b869b31 #170 bump read-package-json from 5.0.2 to 6.0.0 (#170)
  • d342821 #168 bump validate-npm-package-name from 4.0.0 to 5.0.0 (#168)

3.0.2 (2022-03-29)

Dependencies

  • bump validate-npm-package-name from 3.0.0 to 4.0.0 (#144) (fa7574a)
  • update npm-package-arg requirement from ^9.0.0 to ^9.0.1 (#136) (b1ec548)

3.0.1 (2022-03-15)

Dependencies

  • bump read-package-json from 4.1.2 to 5.0.0 (#134) (3b7a109)

3.0.0 (2022-02-16)

⚠ BREAKING CHANGES

  • this drops support for node10 and non-LTS versions of node12 and node14

Dependencies

2.0.0 (2020-10-09)

  • BREAKING: requires node10+
  • fix: compat with new @npmcli/config module
  • chore: update deps to latest and greatest

1.10.3 (2018-03-07)

1.10.2 (2018-03-07)

Bug Fixes

  • default-input: Catch errors from npa (#71) (11aee1e)
  • grammar: Fix minor style issue in final prompt (#76) (ba259ce)