"npm init --yes" generates an illegal "name" field


(南漂一卒) #1

What I Wanted to Do

package.json generated by npm init --yes has legal name field, no matter what the name of current directory is.

What Happened Instead

package.json generated by npm init --yes has wrong name field, when the name of current directory has Uppercases or other illegal characters of Package name.

Reproduction Steps

mkdir Upper_Case
cd ./Upper_Case
npm init -y

There is "name": "Upper_Case" field in package.json, not the default value shown in npm init.

Platform Info

$ npm --versions
{ npm: '6.4.1',
  ares: '1.10.1-DEV',
  cldr: '32.0',
  http_parser: '2.8.0',
  icu: '60.1',
  modules: '57',
  napi: '3',
  nghttp2: '1.32.0',
  node: '8.12.0',
  openssl: '1.0.2p',
  tz: '2017c',
  unicode: '10.0',
  uv: '1.19.2',
  v8: '6.2.414.66',
  zlib: '1.2.11' }
$ node -p process.platform
win32

(Joshua) #2

I found the source of this bug and submitted a PR to fix it: https://github.com/npm/init-package-json/pull/81