From d8eee6cf9d2ff7aca68dfaed2de76824a3e0d9af Mon Sep 17 00:00:00 2001 From: Forrest L Norvell Date: Thu, 16 Apr 2015 22:33:51 -0700 Subject: init-package-json@1.4.1 * set a default (empty) value for the author field to make `npm init -y` work without user input * allow at most one scope on a package name, replacing the new scope if an existing one is available --- node_modules/init-package-json/.travis.yml | 4 ++ node_modules/init-package-json/README.md | 2 + node_modules/init-package-json/default-input.js | 12 ++++-- .../node_modules/promzard/package.json | 3 +- .../node_modules/builtins/package.json | 3 +- .../validate-npm-package-name/package.json | 3 +- node_modules/init-package-json/package.json | 43 +++++--------------- node_modules/init-package-json/test/basic.js | 31 +++++++++----- .../init-package-json/test/scope-in-config.js | 47 ++++++++++++++++++++++ .../init-package-json/test/yes-defaults.js | 27 +++++++++++++ 10 files changed, 124 insertions(+), 51 deletions(-) create mode 100644 node_modules/init-package-json/.travis.yml create mode 100644 node_modules/init-package-json/test/scope-in-config.js create mode 100644 node_modules/init-package-json/test/yes-defaults.js (limited to 'node_modules/init-package-json') diff --git a/node_modules/init-package-json/.travis.yml b/node_modules/init-package-json/.travis.yml new file mode 100644 index 000000000..05d299e67 --- /dev/null +++ b/node_modules/init-package-json/.travis.yml @@ -0,0 +1,4 @@ +language: node_js +node_js: + - "0.10" + - "0.11" diff --git a/node_modules/init-package-json/README.md b/node_modules/init-package-json/README.md index 3bdd35f6a..2cc79c4bf 100644 --- a/node_modules/init-package-json/README.md +++ b/node_modules/init-package-json/README.md @@ -2,6 +2,8 @@ A node module to get your node module started. +[![Build Status](https://secure.travis-ci.org/npm/init-package-json.svg)](http://travis-ci.org/npm/init-package-json) + ## Usage ```javascript diff --git a/node_modules/init-package-json/default-input.js b/node_modules/init-package-json/default-input.js index 7ae892229..3af2f62af 100644 --- a/node_modules/init-package-json/default-input.js +++ b/node_modules/init-package-json/default-input.js @@ -1,7 +1,8 @@ var fs = require('fs') var glob = require('glob') var path = require('path') -var validateName = require("validate-npm-package-name") +var validateName = require('validate-npm-package-name') +var npa = require('npm-package-arg') // more popular packages should go here, maybe? function isTestPkg (p) { @@ -40,10 +41,15 @@ function readDeps (test) { return function (cb) { }} var name = package.name || basename +var spec = npa(name) var scope = config.get('scope') if (scope) { if (scope.charAt(0) !== '@') scope = '@' + scope - name = scope + '/' + name + if (spec.scope) { + name = scope + '/' + spec.name.split('/')[1] + } else { + name = scope + '/' + name + } } exports.name = yes ? name : prompt('name', name, function (data) { var its = validateName(data) @@ -202,7 +208,7 @@ if (!package.author) { "url" : config.get('init.author.url') || config.get('init-author-url') } - : prompt('author') + : yes ? '' : prompt('author') } var license = package.license || diff --git a/node_modules/init-package-json/node_modules/promzard/package.json b/node_modules/init-package-json/node_modules/promzard/package.json index 1007cdde4..42900314b 100644 --- a/node_modules/init-package-json/node_modules/promzard/package.json +++ b/node_modules/init-package-json/node_modules/promzard/package.json @@ -46,6 +46,5 @@ "tarball": "http://registry.npmjs.org/promzard/-/promzard-0.3.0.tgz" }, "directories": {}, - "_resolved": "https://registry.npmjs.org/promzard/-/promzard-0.3.0.tgz", - "readme": "ERROR: No README data found!" + "_resolved": "https://registry.npmjs.org/promzard/-/promzard-0.3.0.tgz" } diff --git a/node_modules/init-package-json/node_modules/validate-npm-package-name/node_modules/builtins/package.json b/node_modules/init-package-json/node_modules/validate-npm-package-name/node_modules/builtins/package.json index 459d0793b..e650240c7 100644 --- a/node_modules/init-package-json/node_modules/validate-npm-package-name/node_modules/builtins/package.json +++ b/node_modules/init-package-json/node_modules/validate-npm-package-name/node_modules/builtins/package.json @@ -41,6 +41,5 @@ ], "directories": {}, "_shasum": "355219cd6cf18dbe7c01cc7fd2dce765cfdc549a", - "_resolved": "https://registry.npmjs.org/builtins/-/builtins-0.0.7.tgz", - "readme": "ERROR: No README data found!" + "_resolved": "https://registry.npmjs.org/builtins/-/builtins-0.0.7.tgz" } diff --git a/node_modules/init-package-json/node_modules/validate-npm-package-name/package.json b/node_modules/init-package-json/node_modules/validate-npm-package-name/package.json index 68bd5451b..d421ae9fa 100644 --- a/node_modules/init-package-json/node_modules/validate-npm-package-name/package.json +++ b/node_modules/init-package-json/node_modules/validate-npm-package-name/package.json @@ -53,6 +53,5 @@ "shasum": "ca006761b2b325f107fab172fb0cfcfc5e412c58", "tarball": "http://registry.npmjs.org/validate-npm-package-name/-/validate-npm-package-name-2.0.1.tgz" }, - "_resolved": "https://registry.npmjs.org/validate-npm-package-name/-/validate-npm-package-name-2.0.1.tgz", - "readme": "ERROR: No README data found!" + "_resolved": "https://registry.npmjs.org/validate-npm-package-name/-/validate-npm-package-name-2.0.1.tgz" } diff --git a/node_modules/init-package-json/package.json b/node_modules/init-package-json/package.json index 6cd75e79d..a7deb8823 100644 --- a/node_modules/init-package-json/package.json +++ b/node_modules/init-package-json/package.json @@ -1,13 +1,13 @@ { "name": "init-package-json", - "version": "1.4.0", + "version": "1.4.1", "main": "init-package-json.js", "scripts": { "test": "tap test/*.js" }, "repository": { "type": "git", - "url": "git://github.com/isaacs/init-package-json" + "url": "git://github.com/isaacs/init-package-json.git" }, "author": { "name": "Isaac Z. Schlueter", @@ -18,6 +18,7 @@ "description": "A node module to get your node module started", "dependencies": { "glob": "^5.0.3", + "npm-package-arg": "^4.0.0", "promzard": "^0.3.0", "read": "~1.0.1", "read-package-json": "1 || 2", @@ -39,38 +40,14 @@ "prompt", "start" ], - "gitHead": "c422f6b38ab02d0859d757ec381e473657d4d195", + "readme": "# init-package-json\n\nA node module to get your node module started.\n\n[![Build Status](https://secure.travis-ci.org/npm/init-package-json.svg)](http://travis-ci.org/npm/init-package-json)\n\n## Usage\n\n```javascript\nvar init = require('init-package-json')\nvar path = require('path')\n\n// a path to a promzard module. In the event that this file is\n// not found, one will be provided for you.\nvar initFile = path.resolve(process.env.HOME, '.npm-init')\n\n// the dir where we're doin stuff.\nvar dir = process.cwd()\n\n// extra stuff that gets put into the PromZard module's context.\n// In npm, this is the resolved config object. Exposed as 'config'\n// Optional.\nvar configData = { some: 'extra stuff' }\n\n// Any existing stuff from the package.json file is also exposed in the\n// PromZard module as the `package` object. There will also be free\n// vars for:\n// * `filename` path to the package.json file\n// * `basename` the tip of the package dir\n// * `dirname` the parent of the package dir\n\ninit(dir, initFile, configData, function (er, data) {\n // the data's already been written to {dir}/package.json\n // now you can do stuff with it\n})\n```\n\nOr from the command line:\n\n```\n$ npm-init\n```\n\nSee [PromZard](https://github.com/isaacs/promzard) for details about\nwhat can go in the config file.\n", + "readmeFilename": "README.md", + "gitHead": "037635311227464c4e512e79792616288683c3b9", "bugs": { "url": "https://github.com/isaacs/init-package-json/issues" }, - "homepage": "https://github.com/isaacs/init-package-json", - "_id": "init-package-json@1.4.0", - "_shasum": "50b49cbe284cb7a48e037f36d03817af1022f070", - "_from": "init-package-json@1.4.0", - "_npmVersion": "2.7.5", - "_nodeVersion": "1.6.2", - "_npmUser": { - "name": "iarna", - "email": "me@re-becca.org" - }, - "maintainers": [ - { - "name": "isaacs", - "email": "i@izs.me" - }, - { - "name": "othiym23", - "email": "ogd@aoaioxxysz.net" - }, - { - "name": "iarna", - "email": "me@re-becca.org" - } - ], - "dist": { - "shasum": "50b49cbe284cb7a48e037f36d03817af1022f070", - "tarball": "http://registry.npmjs.org/init-package-json/-/init-package-json-1.4.0.tgz" - }, - "directories": {}, - "_resolved": "https://registry.npmjs.org/init-package-json/-/init-package-json-1.4.0.tgz" + "homepage": "https://github.com/isaacs/init-package-json#readme", + "_id": "init-package-json@1.4.1", + "_shasum": "6f68a14e181941849d84f6861f946e0028716cee", + "_from": "init-package-json@>=1.4.1 <1.5.0" } diff --git a/node_modules/init-package-json/test/basic.js b/node_modules/init-package-json/test/basic.js index 409c16978..7e3134ee6 100644 --- a/node_modules/init-package-json/test/basic.js +++ b/node_modules/init-package-json/test/basic.js @@ -1,6 +1,7 @@ var tap = require('tap') var init = require('../') var rimraf = require('rimraf') +var semver = require('semver') tap.test('the basics', function (t) { var i = __dirname + '/basic.input' @@ -19,15 +20,27 @@ tap.test('the basics', function (t) { t.same(data, expect) t.end() }) - setTimeout(function () { - process.stdin.emit('data', 'the-name\n') - }, 50) - setTimeout(function () { - process.stdin.emit('data', 'description\n') - }, 100) - setTimeout(function () { - process.stdin.emit('data', 'yes\n') - }, 150) + var stdin = process.stdin + var name = 'the-name\n' + var desc = 'description\n' + var yes = 'yes\n' + if (semver.gte(process.versions.node, '0.11.0')) { + ;[name, desc, yes].forEach(function (chunk) { + stdin.push(chunk) + }) + } else { + function input (chunk, ms) { + setTimeout(function () { + stdin.emit('data', chunk) + }, ms) + } + stdin.once('readable', function () { + var ms = 0 + ;[name, desc, yes].forEach(function (chunk) { + input(chunk, ms += 50) + }) + }) + } }) tap.test('teardown', function (t) { diff --git a/node_modules/init-package-json/test/scope-in-config.js b/node_modules/init-package-json/test/scope-in-config.js new file mode 100644 index 000000000..1fa83d9c1 --- /dev/null +++ b/node_modules/init-package-json/test/scope-in-config.js @@ -0,0 +1,47 @@ +var fs = require('fs') +var path = require('path') + +var rimraf = require('rimraf') +var tap = require('tap') + +var init = require('../') + +var EXPECT = { + name: '@scoped/test', + version: '1.0.0', + description: '', + author: '', + scripts: { test: 'echo \"Error: no test specified\" && exit 1' }, + main: 'basic.js', + keywords: [], + license: 'ISC' +} + +tap.test('--yes with scope', function (t) { + init(__dirname, __dirname, { yes: 'yes', scope: '@scoped' }, function (er, data) { + if (er) throw er + + t.same(EXPECT, data) + t.end() + }) +}) + +var json = { + name: '@already/scoped', + version: '1.0.0' +} + +tap.test('with existing package.json', function (t) { + fs.writeFileSync(path.join(__dirname, 'package.json'), JSON.stringify(json, null, 2)) + init(__dirname, __dirname, { yes: 'yes', scope: '@still' }, function (er, data) { + if (er) throw er + + t.equal(data.name, '@still/scoped', 'new scope is added, basic name is kept') + t.end() + }) +}) + +tap.test('teardown', function (t) { + rimraf.sync(path.join(__dirname, 'package.json')) + t.end() +}) diff --git a/node_modules/init-package-json/test/yes-defaults.js b/node_modules/init-package-json/test/yes-defaults.js new file mode 100644 index 000000000..f1d50c025 --- /dev/null +++ b/node_modules/init-package-json/test/yes-defaults.js @@ -0,0 +1,27 @@ +var tap = require("tap") +var init = require("../") +var rimraf = require("rimraf") + +var EXPECT = { + name: "test" + , version: "1.0.0" + , description: "" + , author: "" + , scripts: { test: "echo \"Error: no test specified\" && exit 1" } + , main: "basic.js" + , keywords: [] + , license: "ISC" +} + +tap.test("--yes defaults", function (t) { + init(__dirname, __dirname, {yes: "yes"}, function (er, data) { + if (er) throw er + + t.same(EXPECT, data, 'used the default data') + t.end() + }) +}) + +tap.test("teardown", function (t) { + rimraf(__dirname + "/package.json", t.end.bind(t)) +}) -- cgit v1.2.3