From 99d5be0079ca74062f878b330e4099496844de64 Mon Sep 17 00:00:00 2001 From: David Glasser Date: Thu, 9 May 2013 11:17:36 -0700 Subject: [PATCH] Mimize shrinkwrap files so that they change less in git. --- .../coffeescript/.npm/npm-shrinkwrap.json | 4 +- packages/email/.npm/npm-shrinkwrap.json | 20 ++------ packages/less/.npm/npm-shrinkwrap.json | 6 +-- packages/livedata/.npm/npm-shrinkwrap.json | 14 ++---- .../mongo-livedata/.npm/npm-shrinkwrap.json | 6 +-- packages/stylus/.npm/npm-shrinkwrap.json | 18 ++----- tools/meteor_npm.js | 48 ++++++++++++++++++- 7 files changed, 61 insertions(+), 55 deletions(-) diff --git a/packages/coffeescript/.npm/npm-shrinkwrap.json b/packages/coffeescript/.npm/npm-shrinkwrap.json index 8463f1d69a2..0c35769b4e7 100644 --- a/packages/coffeescript/.npm/npm-shrinkwrap.json +++ b/packages/coffeescript/.npm/npm-shrinkwrap.json @@ -1,9 +1,7 @@ { "dependencies": { "coffee-script": { - "version": "1.6.2", - "from": "coffee-script@1.6.2", - "resolved": "https://registry.npmjs.org/coffee-script/-/coffee-script-1.6.2.tgz" + "version": "1.6.2" } } } diff --git a/packages/email/.npm/npm-shrinkwrap.json b/packages/email/.npm/npm-shrinkwrap.json index c4f33506ebc..e5d3a7cb308 100644 --- a/packages/email/.npm/npm-shrinkwrap.json +++ b/packages/email/.npm/npm-shrinkwrap.json @@ -2,37 +2,25 @@ "dependencies": { "mailcomposer": { "version": "0.1.15", - "from": "mailcomposer@0.1.15", - "resolved": "https://registry.npmjs.org/mailcomposer/-/mailcomposer-0.1.15.tgz", "dependencies": { "mimelib-noiconv": { - "version": "0.1.9", - "from": "mimelib-noiconv@*", - "resolved": "https://registry.npmjs.org/mimelib-noiconv/-/mimelib-noiconv-0.1.9.tgz" + "version": "0.1.9" } } }, "simplesmtp": { "version": "0.1.25", - "from": "simplesmtp@0.1.25", - "resolved": "https://registry.npmjs.org/simplesmtp/-/simplesmtp-0.1.25.tgz", "dependencies": { "rai": { - "version": "0.1.7", - "from": "rai@*", - "resolved": "https://registry.npmjs.org/rai/-/rai-0.1.7.tgz" + "version": "0.1.7" }, "xoauth2": { - "version": "0.1.6", - "from": "https://registry.npmjs.org/xoauth2/-/xoauth2-0.1.6.tgz", - "resolved": "https://registry.npmjs.org/xoauth2/-/xoauth2-0.1.6.tgz" + "version": "0.1.8" } } }, "stream-buffers": { - "version": "0.2.3", - "from": "stream-buffers@0.2.3", - "resolved": "https://registry.npmjs.org/stream-buffers/-/stream-buffers-0.2.3.tgz" + "version": "0.2.3" } } } diff --git a/packages/less/.npm/npm-shrinkwrap.json b/packages/less/.npm/npm-shrinkwrap.json index a2cb8489045..257eeb99516 100644 --- a/packages/less/.npm/npm-shrinkwrap.json +++ b/packages/less/.npm/npm-shrinkwrap.json @@ -2,13 +2,9 @@ "dependencies": { "less": { "version": "1.3.3", - "from": "less@1.3.3", - "resolved": "https://registry.npmjs.org/less/-/less-1.3.3.tgz", "dependencies": { "ycssmin": { - "version": "1.0.1", - "from": "ycssmin@>=1.0.1", - "resolved": "https://registry.npmjs.org/ycssmin/-/ycssmin-1.0.1.tgz" + "version": "1.0.1" } } } diff --git a/packages/livedata/.npm/npm-shrinkwrap.json b/packages/livedata/.npm/npm-shrinkwrap.json index d0804a5f3e8..e94a8d0227e 100644 --- a/packages/livedata/.npm/npm-shrinkwrap.json +++ b/packages/livedata/.npm/npm-shrinkwrap.json @@ -2,25 +2,17 @@ "dependencies": { "sockjs": { "version": "0.3.4", - "from": "sockjs@0.3.4", - "resolved": "https://registry.npmjs.org/sockjs/-/sockjs-0.3.4.tgz", "dependencies": { "node-uuid": { - "version": "1.3.3", - "from": "node-uuid@1.3.3", - "resolved": "https://registry.npmjs.org/node-uuid/-/node-uuid-1.3.3.tgz" + "version": "1.3.3" }, "faye-websocket": { - "version": "0.4.0", - "from": "faye-websocket@0.4.0", - "resolved": "https://registry.npmjs.org/faye-websocket/-/faye-websocket-0.4.0.tgz" + "version": "0.4.0" } } }, "websocket": { - "version": "1.0.7", - "from": "websocket@1.0.7", - "resolved": "https://registry.npmjs.org/websocket/-/websocket-1.0.7.tgz" + "version": "1.0.7" } } } diff --git a/packages/mongo-livedata/.npm/npm-shrinkwrap.json b/packages/mongo-livedata/.npm/npm-shrinkwrap.json index cb8b20df8aa..81fdc99dda3 100644 --- a/packages/mongo-livedata/.npm/npm-shrinkwrap.json +++ b/packages/mongo-livedata/.npm/npm-shrinkwrap.json @@ -2,13 +2,9 @@ "dependencies": { "mongodb": { "version": "1.2.13", - "from": "mongodb@1.2.13", - "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-1.2.13.tgz", "dependencies": { "bson": { - "version": "0.1.8", - "from": "bson@0.1.8", - "resolved": "https://registry.npmjs.org/bson/-/bson-0.1.8.tgz" + "version": "0.1.8" } } } diff --git a/packages/stylus/.npm/npm-shrinkwrap.json b/packages/stylus/.npm/npm-shrinkwrap.json index 0d114c6d209..165ee0fffa0 100644 --- a/packages/stylus/.npm/npm-shrinkwrap.json +++ b/packages/stylus/.npm/npm-shrinkwrap.json @@ -1,29 +1,19 @@ { "dependencies": { "nib": { - "version": "0.8.2", - "from": "nib@0.8.2", - "resolved": "https://registry.npmjs.org/nib/-/nib-0.8.2.tgz" + "version": "0.8.2" }, "stylus": { "version": "0.30.1", - "from": "stylus@0.30.1", - "resolved": "https://registry.npmjs.org/stylus/-/stylus-0.30.1.tgz", "dependencies": { "cssom": { - "version": "0.2.5", - "from": "cssom@0.2.x", - "resolved": "https://registry.npmjs.org/cssom/-/cssom-0.2.5.tgz" + "version": "0.2.5" }, "mkdirp": { - "version": "0.3.5", - "from": "mkdirp@0.3.x", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.3.5.tgz" + "version": "0.3.5" }, "debug": { - "version": "0.7.2", - "from": "debug@*", - "resolved": "https://registry.npmjs.org/debug/-/debug-0.7.2.tgz" + "version": "0.7.2" } } } diff --git a/tools/meteor_npm.js b/tools/meteor_npm.js index cfcd1c57e5a..6b3c73c42d7 100644 --- a/tools/meteor_npm.js +++ b/tools/meteor_npm.js @@ -299,6 +299,7 @@ _.extend(exports, { // npm-shrinkwrap.json with keys like "version" and "from") to the canonical // version that matches what users put in the `Npm.depends` clause. ie, // either the version or the tarball URL. + // If more logic is added here, it should probably go in minimizeModule too. _canonicalVersion: function (depObj) { var self = this; if (self._isGitHubTarball(depObj.from)) @@ -368,14 +369,59 @@ _.extend(exports, { // `npm shrinkwrap` _shrinkwrap: function(dir) { + var self = this; // We don't use npm.commands.shrinkwrap for two reasons: // 1. As far as we could tell there's no way to completely silence the output // (the `silent` flag isn't piped in to the call to npm.commands.ls) // 2. In various (non-deterministic?) cases we observed the // npm-shrinkwrap.json file not being updated - this._execFileSync(path.join(files.get_dev_bundle(), "bin", "npm"), + self._execFileSync(path.join(files.get_dev_bundle(), "bin", "npm"), ["shrinkwrap"], {cwd: dir}); + self._minimizeShrinkwrap(dir); + }, + + // The shrinkwrap file format contains a lot of extra data that can change as + // you re-run the NPM-update process without actually affecting what is + // installed. This step trims everything but the most important bits from the + // file, so that the file doesn't change unnecessary. + // + // This is based on an analysis of install.js in the npm module: + // https://github.com/isaacs/npm/blob/master/lib/install.js + // It appears that the only things actually read from a given dependency are + // its sub-dependencies and a single version, which is read by the readWrap + // function; and furthermore, we can just put all versions in the "version" + // field. + _minimizeShrinkwrap: function (dir) { + var self = this; + var topLevel = self._shrinkwrappedDependenciesTree(dir); + + var minimizeModule = function (module) { + var minimized = {}; + if (self._isGitHubTarball(module.from)) + minimized.from = module.from; + else + minimized.version = module.version; + + if (module.dependencies) { + minimized.dependencies = {}; + _.each(module.dependencies, function (subModule, name) { + minimized.dependencies[name] = minimizeModule(subModule); + }); + } + return minimized; + }; + + var newTopLevelDependencies = {}; + _.each(topLevel.dependencies, function (module, name) { + newTopLevelDependencies[name] = minimizeModule(module); + }); + + fs.writeFileSync( + path.join(dir, 'npm-shrinkwrap.json'), + // Matches the formatting done by 'npm shrinkwrap'. + JSON.stringify({dependencies: newTopLevelDependencies}, null, 2) + + '\n'); }, _logUpdateDependencies: function(packageName, npmDependencies) {