diff options
author | Rebecca Turner <me@re-becca.org> | 2017-02-09 01:13:51 +0300 |
---|---|---|
committer | C J Silverio <ceejceej@gmail.com> | 2017-02-10 02:37:51 +0300 |
commit | d85d58d4a352660aeac5c98c4a257e5eb4070bb6 (patch) | |
tree | 164779ef48e9b29ab75f97a4815ae136caef0cff | |
parent | 6faa46294cfda64ac923024cbcf01888f477e79a (diff) |
npm: Lazy load caching-registry-client (#15631)
PR-URL: https://github.com/npm/npm/pull/15631
Credit: @iarna
Reviewed-By: @zkat
-rw-r--r-- | lib/npm.js | 24 | ||||
-rw-r--r-- | node_modules/lazy-property/.npmignore | 16 | ||||
-rw-r--r-- | node_modules/lazy-property/LICENSE | 22 | ||||
-rw-r--r-- | node_modules/lazy-property/README.md | 44 | ||||
-rw-r--r-- | node_modules/lazy-property/component.json | 7 | ||||
-rw-r--r-- | node_modules/lazy-property/lazyProperty.js | 19 | ||||
-rw-r--r-- | node_modules/lazy-property/package.json | 91 | ||||
-rw-r--r-- | npm-shrinkwrap.json | 5 | ||||
-rw-r--r-- | package.json | 2 |
9 files changed, 221 insertions, 9 deletions
diff --git a/lib/npm.js b/lib/npm.js index 890c369cc..b3806120e 100644 --- a/lib/npm.js +++ b/lib/npm.js @@ -31,7 +31,7 @@ var which = require('which') var glob = require('glob') var rimraf = require('rimraf') - var CachingRegClient = require('./cache/caching-client.js') + var lazyProperty = require('lazy-property') var parseJSON = require('./utils/parse-json.js') var aliases = require('./config/cmd-list').aliases var cmdList = require('./config/cmd-list').cmdList @@ -79,6 +79,9 @@ return littleGuys.indexOf(c) === -1 }) + var registryRefer + var registryLoaded + Object.keys(abbrevs).concat(plumbing).forEach(function addCommand (c) { Object.defineProperty(npm.commands, c, { get: function () { if (!loaded) { @@ -112,9 +115,8 @@ } }) - npm.registry.version = npm.version - if (!npm.registry.refer) { - npm.registry.refer = [a].concat(args[0]).map(function (arg) { + if (!registryRefer) { + registryRefer = [a].concat(args[0]).map(function (arg) { // exclude anything that might be a URL, path, or private module // Those things will always have a slash in them somewhere if (arg && arg.match && arg.match(/\/|\\/)) { @@ -125,6 +127,7 @@ }).filter(function (arg) { return arg && arg.match }).join(' ') + if (registryLoaded) npm.registry.refer = registryRefer } cmd.apply(npm, args) @@ -299,10 +302,6 @@ log.resume() - // at this point the configs are all set. - // go ahead and spin up the registry client. - npm.registry = new CachingRegClient(npm.config) - var umask = npm.config.get('umask') npm.modes = { exec: parseInt('0777', 8) & (~umask), @@ -322,7 +321,14 @@ // at this point the configs are all set. // go ahead and spin up the registry client. - npm.registry = new CachingRegClient(npm.config) + lazyProperty(npm, 'registry', function () { + registryLoaded = true + var CachingRegClient = require('./cache/caching-client.js') + var registry = new CachingRegClient(npm.config) + registry.version = npm.version + registry.refer = registryRefer + return registry + }) startMetrics() diff --git a/node_modules/lazy-property/.npmignore b/node_modules/lazy-property/.npmignore new file mode 100644 index 000000000..038e0242e --- /dev/null +++ b/node_modules/lazy-property/.npmignore @@ -0,0 +1,16 @@ +lib-cov +*.seed +*.log +*.csv +*.dat +*.out +*.pid +*.gz + +pids +logs +results + +npm-debug.log +node_modules/* +test/*
\ No newline at end of file diff --git a/node_modules/lazy-property/LICENSE b/node_modules/lazy-property/LICENSE new file mode 100644 index 000000000..8ce206a84 --- /dev/null +++ b/node_modules/lazy-property/LICENSE @@ -0,0 +1,22 @@ + +The MIT License (MIT) + +Copyright (c) 2013 Mikola Lysenko + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/node_modules/lazy-property/README.md b/node_modules/lazy-property/README.md new file mode 100644 index 000000000..d339c8f46 --- /dev/null +++ b/node_modules/lazy-property/README.md @@ -0,0 +1,44 @@ +lazy-property +============= +Adds a lazily initialized property to an object. + +## Example + +```javascript +var addLazyProperty = require("lazy-property") + +var obj = {} + +addLazyProperty(obj, "foo", function() { + console.log("initialized!") + return "bar" +}) + +//Access the property +console.log(obj.foo) +console.log(obj.foo) + +//Prints out: +// +// initialized! +// bar +// bar +// +``` + +## Install + + npm install lazy-property + +## API + +### `require("lazy-property")(obj, name, init[, enumerable])` +Adds a lazily initialized property to the object. + +* `obj` is the object to add the property to +* `name` is the name of the property +* `init` is a function that computes the value of the property +* `enumerable` if the property is enumerable (default `false`) + +## Credits +(c) 2013 Mikola Lysenko. MIT License diff --git a/node_modules/lazy-property/component.json b/node_modules/lazy-property/component.json new file mode 100644 index 000000000..142938e49 --- /dev/null +++ b/node_modules/lazy-property/component.json @@ -0,0 +1,7 @@ +{ + "name": "lazy-property", + "version": "0.0.2", + "description": "Lazily initialized properties for objects", + "main": "lazyProperty.js", + "scripts": ["lazyProperty.js"] +} diff --git a/node_modules/lazy-property/lazyProperty.js b/node_modules/lazy-property/lazyProperty.js new file mode 100644 index 000000000..20e5fe191 --- /dev/null +++ b/node_modules/lazy-property/lazyProperty.js @@ -0,0 +1,19 @@ +"use strict" + +function addLazyProperty(object, name, initializer, enumerable) { + Object.defineProperty(object, name, { + get: function() { + var v = initializer.call(this) + Object.defineProperty(this, name, { value: v, enumerable: !!enumerable, writable: true }) + return v + }, + set: function(v) { + Object.defineProperty(this, name, { value: v, enumerable: !!enumerable, writable: true }) + return v + }, + enumerable: !!enumerable, + configurable: true + }) +} + +module.exports = addLazyProperty diff --git a/node_modules/lazy-property/package.json b/node_modules/lazy-property/package.json new file mode 100644 index 000000000..a11a94076 --- /dev/null +++ b/node_modules/lazy-property/package.json @@ -0,0 +1,91 @@ +{ + "_args": [ + [ + { + "raw": "lazy-property", + "scope": null, + "escapedName": "lazy-property", + "name": "lazy-property", + "rawSpec": "", + "spec": "latest", + "type": "tag" + }, + "/Users/rebecca/code/npm" + ] + ], + "_from": "lazy-property@latest", + "_id": "lazy-property@1.0.0", + "_inCache": true, + "_location": "/lazy-property", + "_npmUser": { + "name": "mikolalysenko", + "email": "mikolalysenko@gmail.com" + }, + "_npmVersion": "1.4.3", + "_phantomChildren": {}, + "_requested": { + "raw": "lazy-property", + "scope": null, + "escapedName": "lazy-property", + "name": "lazy-property", + "rawSpec": "", + "spec": "latest", + "type": "tag" + }, + "_requiredBy": [ + "#USER", + "/" + ], + "_resolved": "https://registry.npmjs.org/lazy-property/-/lazy-property-1.0.0.tgz", + "_shasum": "84ddc4b370679ba8bd4cdcfa4c06b43d57111147", + "_shrinkwrap": null, + "_spec": "lazy-property", + "_where": "/Users/rebecca/code/npm", + "author": { + "name": "Mikola Lysenko" + }, + "bugs": { + "url": "https://github.com/mikolalysenko/lazy-property/issues" + }, + "dependencies": {}, + "description": "Lazily initialized properties for objects", + "devDependencies": { + "tape": "^2.12.3" + }, + "directories": { + "test": "test" + }, + "dist": { + "shasum": "84ddc4b370679ba8bd4cdcfa4c06b43d57111147", + "tarball": "https://registry.npmjs.org/lazy-property/-/lazy-property-1.0.0.tgz" + }, + "gitHead": "850a27f710ec72f05b534805c31f095ff590f1ea", + "homepage": "https://github.com/mikolalysenko/lazy-property", + "keywords": [ + "lazy", + "property", + "object", + "initialize", + "array", + "dictionary" + ], + "license": "MIT", + "main": "lazyProperty.js", + "maintainers": [ + { + "name": "mikolalysenko", + "email": "mikolalysenko@gmail.com" + } + ], + "name": "lazy-property", + "optionalDependencies": {}, + "readme": "ERROR: No README data found!", + "repository": { + "type": "git", + "url": "git://github.com/mikolalysenko/lazy-property.git" + }, + "scripts": { + "test": "tape test/*.js" + }, + "version": "1.0.0" +} diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 9f381bf60..48c8abada 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -301,6 +301,11 @@ } } }, + "lazy-property": { + "version": "1.0.0", + "from": "lazy-property@latest", + "resolved": "https://registry.npmjs.org/lazy-property/-/lazy-property-1.0.0.tgz" + }, "lockfile": { "version": "1.0.3", "from": "lockfile@>=1.0.3 <2.0.0", diff --git a/package.json b/package.json index daed5a474..b48f78709 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,7 @@ "inherits": "~2.0.3", "ini": "~1.3.4", "init-package-json": "~1.9.4", + "lazy-property": "~1.0.0", "lockfile": "~1.0.3", "lodash._baseuniq": "~4.6.0", "lodash.clonedeep": "~4.5.0", @@ -137,6 +138,7 @@ "ini", "init-package-json", "JSONStream", + "lazy-property", "lockfile", "lodash._baseindexof", "lodash._baseuniq", |