Giter Site home page Giter Site logo

init-package-json's Introduction

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.

init-package-json's People

Contributors

addaleax avatar apaleslimghost avatar bertday avatar dependabot[bot] avatar github-actions[bot] avatar gustavnikolaj avatar iarna avatar isaacs avatar kemitchell avatar legodude17 avatar lewiscowper avatar lucthev avatar luk- avatar lukekarrys avatar mfncooper avatar michaelnisi avatar mikolalysenko avatar misumirize avatar mmmm1998 avatar nizaroni avatar othiym23 avatar pke avatar ruyadorno avatar rvagg avatar sammwyy avatar timoxley avatar watilde avatar wraithgar avatar zearin avatar zkat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

init-package-json's Issues

Add option to toggle overwriting of file

At the moment it overwrites the original package file.
There should be an option to prevent this.

Maybe:

init(dir, initFile, {yes: true, overwrite: false}, (error, data) => {
  // …
})

running npm init with --scope is not idempotent

If you run npm init --scope=npm-examples twice in the same project, it will duplicate the scope.

name: (@npm-examples/@npm-examples/scoped-package)

Can @ be part of the project name? If not, then it seems like we could check for an @ in the name and if it's found, split the package name and prepend the new scope.

Wrong message in link for "help"

When you type npm init, it says "See npm help json for definitive documentation on these fields
and exactly what they do." When you type this says No results for "json".

If you type npm help init you receive the correct help page.

The message should be changed to say "See npm help init ..."

Default to "^" instead of "~" for semantic version of dependencies

"~" is confusing and undermines the purpose of semantic versioning. Consider either:

  • Default locking version strings to a specific version (ie no automatic upgrading)
  • Or default to properly following semantic versioning.

The current behavior using "~" is highly inconsistent. It does not protect users from malicious or accidental mistakes in package upgrades, since it still automatically upgrades patch versions. And it does not properly follow semver, so it does not ensure the current package is at the latest version.

Of the two options, I lean toward the second as it encourages users to choose to follow semantic versioning.

Document configuration

It seems that it listens for a bunch in certain config keys (like init.license). It would be nice to document these somewhere.

I think they are:

  • init.license — defaults to ISC
  • init.version — defaults to 1.0.0
  • init.author.name
  • init.author.email
  • init.author.url

And you can set them via:

$ npm config set init.author.name "Lightning McQueen"

[BUG] <title>

What / Why

n/a

When

  • n/a

Where

  • n/a

How

Current Behavior

  • n/a

Steps to Reproduce

  • n/a

Expected Behavior

  • n/a

Who

  • n/a

References

  • n/a

Input Redirection / Piping into 'npm init' command not working

I'm trying to write a setup script that automatically runs and fills out the npm init prompts. It appears something is causing npm init to crash when I get to the entry point for the entry point.

Using this sample input file: https://gist.github.com/derekaug/d3c7cfc1fa7e6538de0e

When I run npm init < sample_input or cat sample_input | npm init, npm init crashes when it hits the entry point. See example output here: https://gist.github.com/derekaug/c0c1ace1e828e4c83f27

When run from the command line init throws an exception on names with spaces

npm's name field does not support spaces (at some point this would be nice to update) but when running npm init in the command line then specifying a name with spaces it will continue through the entire process then fail at the end.

Suggest adding validation to the entered fields to avoid a failing at the end causing the user to re-enter all of their information again just to correct one field.

Running `npm init` inside a folder with a space doesn't work as expected

I like storing projects in folders with spaces in the name. I know this is not compatible with npm's project naming conventions but I still feel like this should not prevent npm init from working at all.

As it stands, if you run npm init inside a folder with a space, it prints an error and refuses to prompt for anything besides the "complete" file, which is anything but complete.

Steps to reproduce

mkdir "Foo Bar"
cd "Foo Bar"
npm init

And then npm will error:

This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See `npm help json` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
npm ERR! code EINVALIDTAGNAME
npm ERR! Invalid tag name "Foo Bar": Tags may not have any characters that encodeURIComponent encodes.
About to write to C:\Users\Cameron\git\Foo Bar\package.json:

{
  "name": "",
  "version": ""
}


Is this ok? (yes) no
Aborted.

Expected Results

No error. Not a nearly empty package.json. I'd expect to be prompted with which name I'd like to use and appropriate handlers if I specify a space. As in, similar to the old behavior from 4.2.0.

Environment

Tested on Windows 10 with npm version 5.0.3 and 5.3.0. Also tested with linux.

Does not error on npm version 4.2.0

[FEATURE] Create the main file inside the current directory

What / Why

When I run npm init -y inside the cwd (empty) I should end up with two files, package.json and index.js.

When

On running npm init

Where

cwd

How

Current Behavior

Doesn't create index.js

Expected Behavior

Creates index.js

Who

n/a

References

n/a

Trying to provide default option values

My code example (below) is pretty much exactly what was taken from the README file, just with less comments and the configData populated differently.

I thought that passing an object to the 3rd parameter of the init method would provide it with default options, but I guess thats not the case?

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

var initFile = path.resolve(process.env.HOME, '.npm-init')

var dir = process.cwd()

// Desired default settings/options
var configData = { 
    name: 'Default Name..',
    description: 'Default description..',
    some: 'extra stuff' // What is this one even suppose to do then?..
}

init(dir, initFile, configData, ( er, data ) => {
    console.log('Result:', err || data)
})

Is there a way to provide default options? Short of creating the package.json manually

Thanks

new init variable github init.github.username

Right now, npm init is working well for me and the only routine is to type iamstarkov/new-repo into repo field suggestion.

So I want to request new init variable init.github.username and to suggest github repo’s name from folder name. What do you think?

If this idea is welcome I can try to implement it and send a patch

make default version 0.1.0

New projects are typically in very exploratory phase and may have many breaking changes early on. To stick with semantic versioning I think its better to have a default version of 0.1.0 instead of 1.0.0.

auto confirm flag doesn't work when running npm init

What / Why

Autoconfirm mode doesn't work when running

npm init package-json -y

How

Current Behavior

npm init package-json -y

Asks for each configuration option instead of auto confirming defaults.

Expected Behavior

There should not be any console input requests.

Fetch default license from LICENSE

npm init does a great job of intelligent defaults (name from directory name, repo url from .git, and so forth). However, even when there is a LICENSE file specifying a license, npm init pulls its default license from config:init-license. Pulling at least the most common few licenses from LICENSE would be really slick.

Copied from npm/npm#6947

[FEATURE] services

What / Why

n/a

When

  • n/a

Where

  • n/a

How

Current Behavior

  • n/a

Expected Behavior

  • n/a

Who

  • n/a

References

  • n/a

Cannot find module 'init-package-json'

Node doesn't find init-package-json
var init = require('init-package-json');

STACKTRACE

PS C:\DEV\npm-package-boilerplate-cli> node index.js
module.js:471
    throw err;
    ^

Error: Cannot find module 'init-package-json'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (C:\DEV\npm-package-boilerplate-cli\index.js:1:74)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)

Errors when searching for libs

I am interested in customising my 'npm init' process (e.g. defining different default values or adding new settings to the generated 'package.json') and was under the impression that this could be done by adding a '~/.npm-init.js' file with contents similar as to the one described in the 'README.md' of the 'init-package-json' project.

However, I am stumbling upon what I believe are some path/configuration issues, mainly consisting of 'node_modules' not being found, despite the necessary dependencies being available in the global 'node_modules' dir.

Here is a simple example:

[myuser ~/test]$ npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sane defaults.

See `npm help json` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg> --save` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
npm ERR! Linux 2.6.32-504.8.1.el6.centos.plus.x86_64
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "init"
npm ERR! node v0.12.0
npm ERR! npm  v2.5.1
npm ERR! code MODULE_NOT_FOUND

npm ERR! Cannot find module 'glob'
npm ERR! 
npm ERR! If you need help, you may report this error at:
npm ERR!     <http://github.com/npm/npm/issues>
About to write to /home/myuser/test/package.json:

{
  "name": "",
  "version": ""
}


Is this ok? (yes) no
Aborted.

As already stated, glob is already globally available (installed with -g).
Now, if I try to explicitly set the node path, I get errors regarding other libs not available globally:

[myuser ~/test]$ NODE_PATH=/usr/lib/node_modules npm init

npm ERR! code MODULE_NOT_FOUND
npm ERR! Cannot find module 'validate-npm-package-name'

I could globally install the other necessary packages... but I feel that I may be tackling this problem the wrong way, and that manually specifying the node path plus manually installing dependencies seems like overkill. Am I missing some step/configuration that should allow the '~/.node-init.js' integration work more seamlessly?

[BUG] <title>

What / Why

n/a

When

  • n/a

Where

  • n/a

How

Current Behavior

  • n/a

Steps to Reproduce

  • n/a

Expected Behavior

  • n/a

Who

  • n/a

References

  • n/a

tests: two-thirds of `npm-defaults.js` doesn't work

Changing the input configs of two of npm-defaults.js tests do not make the test fail:

diff --git a/test/npm-defaults.js b/test/npm-defaults.js
index 666e9a1..06a2221 100644
--- a/test/npm-defaults.js
+++ b/test/npm-defaults.js
@@ -55,7 +55,7 @@ test("npm configuration values pulled from dotted config", function (t) {
   var config = {
     yes : "yes",

-    "init.author.name"  : "npmbot",
+    "init.author.name"  : "kenan",
     "init.author.email" : "[email protected]",
     "init.author.url"   : "http://npm.im",

@@ -81,7 +81,7 @@ test("npm configuration values pulled from dashed config", function (t) {
   var config = {
     yes : "yes",

-    "init-author-name"  : "npmbot",
+    "init-author-name"  : "kenan",
     "init-author-email" : "[email protected]",
     "init-author-url"   : "http://npm.im",

AFAICT, this is because npm.load() caches a loaded boolean and as such only its first execution here determines the config used in all the tests in this file. The other npm.load()s change nothing, so it seems to me like these tests aren't actually testing what they should be testing.

I spent some time this morning trying to work around this but I'm at a lost now :(

[BUG] <title>

What / Why

n/a

When

  • n/a

Where

  • n/a

How

Current Behavior

  • n/a

Steps to Reproduce

  • n/a

Expected Behavior

  • n/a

Who

  • n/a

References

  • n/a

Fetching author information from git config

Hi everyone,

I think it would be nice if npm init would fetch for the author the information from the git config if it's provided. I could see two potential orders of preference here:

Option 1:
local .git/config > npm config > global git config > empty string

Option 2:
npm config > git config > empty string

There would be also the option to actually execute the respective git config --get user.name etc. commands which would respect both local and global config.

Let me know what you think. Happy to work on the PR for this.

Add jest & jasmine to isTestPkg regex

jest & jasmine are test frameworks that're not covered by isTestPkg:

// more popular packages should go here, maybe?
function isTestPkg (p) {
return !!p.match(/^(expresso|mocha|tap|coffee-script|coco|streamline)$/)
}

I don't know the impact of this, but it's clearly looking for testing frameworks 😄

Missing license

Please add a license file to clarify what license this is distributed under.

I'd like to use node/npm for a project at work, but npm depends on this package and I'm not allowed to use software that doesn't have a clear license.

Thanks!

Add a flag for selecting devDependency as a default

The current method for selecting whether to list a package to be a devDependency vs. regular dependency is a bit ad-hoc:

https://github.com/isaacs/init-package-json/blob/master/default-input.js#L7

It would be nice if modules could specify somewhere in their package.json whether they should be installed by default as a devDependency vs. as a normal dependency. For example, I use tape a lot for the browser based test harness and it is a bit annoying having to go back and fix the dependency each time I do npm init.

As a sketch of how this could work, you could just add a field like the preferGlobal (call it preferDevelopment for example) that init-package-json checks to determine whether the dependency gets added as a normal dependency or a devDependency.

Considering to init ESM default package.json?

What / Why

Considering to init package.json with ESM default behaviour?

When

Init package.json

Where

npm init / npm init -y

Current Behavior

didn't default to any module type

Expected Behavior

default to "module" type

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.