Skip to content

Commit

Permalink
Merge fdff38d into 547b520
Browse files Browse the repository at this point in the history
  • Loading branch information
rmg committed Sep 6, 2017
2 parents 547b520 + fdff38d commit ccd1264
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 22 deletions.
11 changes: 10 additions & 1 deletion .eslintrc.json
@@ -1,3 +1,12 @@
{
"extends": "strongloop"
"extends": "strongloop",
"rules": {
"indent": ["error", 2, {
"CallExpression": {
"arguments": "first"
},
"MemberExpression": "off",
"SwitchCase": 1
}]
}
}
4 changes: 1 addition & 3 deletions .travis.yml
@@ -1,9 +1,7 @@
language: node_js
node_js:
- "7"
- "8"
- "6"
- "4"
git:
depth: 10000 # need the whole thing
after_script:
- "./node_modules/.bin/tap --coverage --coverage-report=text-lcov | ./node_modules/.bin/codacy-coverage"
9 changes: 6 additions & 3 deletions bin/slt-release.sh
Expand Up @@ -17,8 +17,11 @@ used.
What slt-release will do:
- generate a CHANGES.md file
- increment package version in package.json and bower.json (if present)
- commit CHANGES.md, package.json, bower.json, and npm-shrinkwrap.json
- increment package version in package metadata files (when present):
- package.json, bower.json, npm-shrinkwrap.json, package-lock.json
- commit CHANGES.md, package.json
- also commit bower.json, npm-shrinkwrap.json, package-lock.json
if present
- tag commit with an annotated tag
- merge tag back in to base branch
- IF npm-shrinkwrap.json was not previously part of that branch then
Expand Down Expand Up @@ -125,7 +128,7 @@ echo "Updating package version to $V"
slt version set "$V"

echo "Committing package and CHANGES for v$V"
TO_ADD="$(git ls-files bower.json) package.json CHANGES.md"
TO_ADD="$(git ls-files bower.json package-lock.json) package.json CHANGES.md"
TO_REMOVE=""
if [ -e npm-shrinkwrap.json ]; then
if ! git cat-file -e "$BASE":npm-shrinkwrap.json; then
Expand Down
4 changes: 0 additions & 4 deletions lib/license.js
Expand Up @@ -9,7 +9,6 @@ var Promise = require('bluebird');
var _ = require('lodash');
var assert = require('assert');
var copyright = require('./copyright');
var debug = require('debug')('strong-tools:fix-license');
var fs = require('fs');
var git = require('./git');
var json = require('json-file-plus');
Expand All @@ -31,7 +30,6 @@ exports.cli = fixCli;

function fixCli(pkgPath) {
pkgPath = pkgPath || 'package.json';
debug(pkgPath);
var setLicense = pkgPath.match(/^--(.*)/);
if (setLicense) {
pkgPath = 'package.json';
Expand Down Expand Up @@ -88,8 +86,6 @@ function fixCli(pkgPath) {
process.exit(1);
}

debug('license: %j', license);

// License object
switch (license.name) {
case 'StrongLoop': // OBSOLETE
Expand Down
42 changes: 40 additions & 2 deletions lib/project.js
Expand Up @@ -41,6 +41,8 @@ function Project(pkgPath, cb) {
}

this.bowerJSONPath = path.resolve(this.rootPath, 'bower.json');
this.shrinkwrapJSONPath = path.resolve(this.rootPath, 'npm-shrinkwrap.json');
this.packageLockJSONPath = path.resolve(this.rootPath, 'package-lock.json');

// test for bower.json existence
try {
Expand All @@ -49,6 +51,20 @@ function Project(pkgPath, cb) {
this.rawBowerJSON = null;
}

try {
this.rawShrinkwrapJSON = JSON.parse(
fs.readFileSync(this.shrinkwrapJSONPath, 'utf8'));
} catch (e) {
this.rawShrinkwrapJSON = null;
}

try {
this.rawPackageLockJSON = JSON.parse(
fs.readFileSync(this.packageLockJSONPath, 'utf8'));
} catch (e) {
this.rawPackageLockJSON = null;
}

try {
this.rawPkgJSON = JSON.parse(fs.readFileSync(this.pkgJSONPath, 'utf8'));
} catch (e) {
Expand Down Expand Up @@ -102,7 +118,7 @@ function Project$get(key, dflt) {
break;
}
return _.get(this.normalizedPkgJSON, key,
_.get(this.rawPkgJSON, key, dflt));
_.get(this.rawPkgJSON, key, dflt));
}

var GH_SSH = /^(?:git\+ssh:\/\/)?git@github.com[:\/]([^/]+)\/([^/]+?)(\.git)?$/;
Expand Down Expand Up @@ -135,6 +151,14 @@ function Project$version(v) {
this.rawBowerJSON.version = v;
}

if (this.rawShrinkwrapJSON) {
this.rawShrinkwrapJSON.version = v;
}

if (this.rawPackageLockJSON) {
this.rawPackageLockJSON.version = v;
}

this.normalizedPkgJSON = normalize(this.rawPkgJSON);
return v;
} else {
Expand All @@ -150,11 +174,25 @@ function Project$persist() {
var newJSON = JSON.stringify(this.rawPkgJSON, null, 2) + '\n';
fs.writeFileSync(this.pkgJSONPath, newJSON);

// write bower json if necessary
// re-write bower.json if necessary
if (this.rawBowerJSON) {
var newBowerJSON = JSON.stringify(this.rawBowerJSON, null, 2) + '\n';
fs.writeFileSync(this.bowerJSONPath, newBowerJSON);
}

// re-write npm-shrinkwrap.json if necessary
if (this.rawShrinkwrapJSON) {
var newShrinkwrapJSON =
JSON.stringify(this.rawShrinkwrapJSON, null, 2) + '\n';
fs.writeFileSync(this.shrinkwrapJSONPath, newShrinkwrapJSON);
}

// re-write package-lock.json if necessary
if (this.rawPackageLockJSON) {
var newPackageLockJSON =
JSON.stringify(this.rawPackageLockJSON, null, 2) + '\n';
fs.writeFileSync(this.packageLockJSONPath, newPackageLockJSON);
}
}

function normalize(raw, warn, strict) {
Expand Down
2 changes: 0 additions & 2 deletions lib/shrinkwrap.js
Expand Up @@ -6,7 +6,6 @@
'use strict';

var _ = require('lodash');
var debug = require('debug')('strong-tools:fix-license');
var json = require('json-file-plus');
var path = require('path');

Expand All @@ -15,7 +14,6 @@ exports.cli = updateShrinkwrap;

function updateShrinkwrap(shrinkwrap) {
shrinkwrap = path.resolve(shrinkwrap || 'npm-shrinkwrap.json');
debug(shrinkwrap);

return json(shrinkwrap).then(rewrite).then(function() {
updateShrinkwrap.out('removed resolution URLs from %s', shrinkwrap);
Expand Down
2 changes: 1 addition & 1 deletion lib/wrapped.js
Expand Up @@ -17,7 +17,7 @@ function wrapped(path) {
return require('module')._load(
path, // path
null, // parent
true // isMain
true // isMain
);
},
};
Expand Down
4 changes: 1 addition & 3 deletions package.json
Expand Up @@ -25,7 +25,6 @@
"homepage": "https://github.com/strongloop/strong-tools",
"dependencies": {
"bluebird": "^3.1.1",
"debug": "^2.2.0",
"gift": "^0.10.0",
"glob": "^7.0.3",
"json-file-plus": "^3.0.1",
Expand All @@ -44,8 +43,7 @@
"node": ">=4"
},
"devDependencies": {
"codacy-coverage": "^2.0.0",
"eslint": "^3.14.1",
"eslint": "^4.6.1",
"eslint-config-strongloop": "^2",
"mkdirp": "^0.5.1",
"rimraf": "^2.2.8",
Expand Down
34 changes: 31 additions & 3 deletions test/test-project.js
Expand Up @@ -16,6 +16,8 @@ var Project = require('../lib/project');
var SANDBOX = path.resolve(__dirname, 'SANDBOX-project');
var SANDBOX_PKG = path.resolve(SANDBOX, 'package.json');
var SANDBOX_BOWER = path.resolve(SANDBOX, 'bower.json');
var SANDBOX_SHRINKWRAP = path.resolve(SANDBOX, 'npm-shrinkwrap.json');
var SANDBOX_PACKAGE_LOCK = path.resolve(SANDBOX, 'package-lock.json');

test('setup', function(t) {
helpers.resetSandboxSync(t, SANDBOX, SANDBOX_PKG, {
Expand All @@ -26,7 +28,7 @@ test('setup', function(t) {

test('API', function(t) {
t.strictEqual(typeof require('../lib/project'), 'function',
'project exports a function');
'project exports a function');
t.ok(new Project('') instanceof Project,
'Project is a constructor');
t.ok(Project('') instanceof Project,
Expand All @@ -46,13 +48,13 @@ test('package parsing', function(t) {
t.strictEqual(p1.nameVer(), 'testing@1.0.0-0');
t.strictEqual(p1.license(), 'SEE LICENSE.md');
t.strictEqual(p1.version(), '1.0.0-0',
'reports 1.0.0-0 as version if missing');
'reports 1.0.0-0 as version if missing');
p1.version(p1.version());
p1.persist();
var updated = JSON.parse(fs.readFileSync(SANDBOX_PKG, 'utf8'));
t.notEqual(updated, original, 'file has changed');
t.strictEqual(updated.version, '1.0.0-0',
'persists the updated version');
'persists the updated version');
// test ghSlug generation BEFORE we've looked at git repo
t.equal(p1.ghSlug(), 'myOrg/testing');
t.end();
Expand Down Expand Up @@ -143,6 +145,32 @@ test('bower support', function(t) {
t.end();
});

test('package-lock support', function(t) {
var pkgjson = JSON.parse(fs.readFileSync(SANDBOX_PKG, 'utf8'));
fs.writeFileSync(SANDBOX_PACKAGE_LOCK, JSON.stringify(pkgjson), 'utf8');
var p1 = new Project(SANDBOX);
t.strictEqual(p1.version(), '2.3.4');
p1.version('4.5.6');
p1.persist();
var pkgLock = JSON.parse(fs.readFileSync(SANDBOX_PACKAGE_LOCK, 'utf8'));
t.strictEqual(p1.version(), '4.5.6');
t.strictEqual(pkgLock.version, '4.5.6');
t.end();
});

test('shrinkwrap support', function(t) {
var pkgjson = JSON.parse(fs.readFileSync(SANDBOX_PKG, 'utf8'));
fs.writeFileSync(SANDBOX_SHRINKWRAP, JSON.stringify(pkgjson), 'utf8');
var p1 = new Project(SANDBOX);
t.strictEqual(p1.version(), '4.5.6');
p1.version('3.4.5');
p1.persist();
var shrinkwrap = JSON.parse(fs.readFileSync(SANDBOX_SHRINKWRAP, 'utf8'));
t.strictEqual(p1.version(), '3.4.5');
t.strictEqual(shrinkwrap.version, '3.4.5');
t.end();
});

test('package inference without package.json', function(t) {
var SANDBOX_NOJSON = path.resolve(__dirname, 'SANDBOX-no-json');
rimraf.sync(SANDBOX_NOJSON);
Expand Down

0 comments on commit ccd1264

Please sign in to comment.