Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies to enable Greenkeeper 🌴 #2323

Merged
merged 4 commits into from
Feb 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ matrix:
branches:
only:
- master
- /^greenkeeper/.*$/
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[![Travis Build Status](https://travis-ci.org/strongloop/loopback-next.svg?branch=master)](https://travis-ci.org/strongloop/loopback-next)
[![AppVeyor Build status](https://ci.appveyor.com/api/projects/status/q8vp7wrdn2ak6801/branch/master?svg=true)](https://ci.appveyor.com/project/strongloop/loopback-next/branch/master)
[![Coverage Status](https://coveralls.io/repos/github/strongloop/loopback-next/badge.svg?branch=master)](https://coveralls.io/github/strongloop/loopback-next?branch=master)
[![Greenkeeper badge](https://badges.greenkeeper.io/strongloop/loopback-next.svg)](https://greenkeeper.io/)

LoopBack makes it easy to build modern applications that require complex
integrations.
Expand Down
4 changes: 2 additions & 2 deletions benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@
"@loopback/openapi-spec-builder": "^1.0.5",
"@loopback/rest": "^1.5.4",
"@types/byline": "^4.2.31",
"@types/debug": "0.0.31",
"@types/debug": "^0.0.31",
"@types/p-event": "^1.3.0",
"@types/request-promise-native": "^1.0.15",
"autocannon": "^3.0.0",
"byline": "^5.0.0",
"debug": "^4.0.1",
"path-to-regexp": "^2.4.0",
"path-to-regexp": "^3.0.0",
"request": "^2.88.0",
"request-promise-native": "^1.0.5"
},
Expand Down
102 changes: 102 additions & 0 deletions bin/update-greenkeeper-json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/usr/bin/env node
// Copyright IBM Corp. 2018. All Rights Reserved.
// Node module: loopback-next
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

/**
* This is an internal script to update `greenkeeper.json` with lerna packages.
*/
'use strict';

const path = require('path');
const fs = require('fs');

const Project = require('@lerna/project');

async function updateGreenKeeperJson() {
const project = new Project(process.cwd());
const packages = await project.getPackages();
const rootPath = project.rootPath;
const packageJsonPaths = packages.map(p =>
path.relative(rootPath, p.manifestLocation),
);
const greenKeeperJson = {
groups: {
default: {
packages: ['package.json'],
},
},
};

for (const p of packageJsonPaths) {
greenKeeperJson.groups.default.packages.push(p);
}

const greenKeeperJsonFile = path.join(rootPath, 'greenkeeper.json');
let currentConfig = {};
if (fs.existsSync(greenKeeperJsonFile)) {
currentConfig = readJsonFile(greenKeeperJsonFile);
}

let updateRequired = false;
if (
!(
currentConfig.groups &&
currentConfig.groups.default &&
Array.isArray(currentConfig.groups.default.packages)
)
) {
// Current config does not exist
updateRequired = true;
}

if (!updateRequired) {
// Check if packages are the same
updateRequired = !arraysContainSameElements(
currentConfig.groups.default.packages,
greenKeeperJson.groups.default.packages,
);
}

if (!updateRequired) {
console.log('%s is up to date.', 'greenkeeper.json');
return;
}

if (process.argv[2] === '-f') {
// Update `greenkeeper.json`
writeJsonFile(greenKeeperJsonFile, greenKeeperJson);
} else {
// Print out `greenkeeper.json`
console.error('%s is out of date.', 'greenkeeper.json');
console.log(JSON.stringify(greenKeeperJson, null, 2));
}
}

if (require.main === module) updateGreenKeeperJson();

/**
* Test if two arrays contain the same set of elements
* @param {Array} actual
* @param {Array} expected
*/
function arraysContainSameElements(actual, expected) {
return (
// Same size
actual.length == expected.length &&
// `expected` contains all elements of `actual`
actual.every(e => expected.includes(e)) &&
// `actual` contains all elements of `expected`
expected.every(e => actual.includes(e))
);
}

function readJsonFile(filePath) {
return JSON.parse(fs.readFileSync(filePath, 'utf-8'));
}

function writeJsonFile(filePath, data) {
fs.writeFileSync(filePath, JSON.stringify(data, null, 2) + '\n', 'utf-8');
console.log('%s has been updated.', filePath);
}
2 changes: 1 addition & 1 deletion examples/log-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@loopback/build": "^1.2.1",
"@loopback/testlab": "^1.0.5",
"@loopback/tslint-config": "^2.0.0",
"@types/debug": "0.0.30",
"@types/debug": "^0.0.31",
"@types/node": "^10.11.2",
"tslint": "^5.12.0",
"typescript": "^3.3.1"
Expand Down
37 changes: 37 additions & 0 deletions greenkeeper.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"groups": {
"default": {
"packages": [
"package.json",
"benchmark/package.json",
"docs/package.json",
"examples/hello-world/package.json",
"examples/log-extension/package.json",
"examples/rpc-server/package.json",
"examples/soap-calculator/package.json",
"examples/todo-list/package.json",
"examples/todo/package.json",
"packages/authentication/package.json",
"packages/boot/package.json",
"packages/build/package.json",
"packages/cli/package.json",
"packages/context/package.json",
"packages/core/package.json",
"packages/http-caching-proxy/package.json",
"packages/http-server/package.json",
"packages/metadata/package.json",
"packages/openapi-spec-builder/package.json",
"packages/openapi-v3-types/package.json",
"packages/openapi-v3/package.json",
"packages/repository-json-schema/package.json",
"packages/repository/package.json",
"packages/rest-explorer/package.json",
"packages/rest/package.json",
"packages/service-proxy/package.json",
"packages/testlab/package.json",
"packages/tslint-config/package.json",
"sandbox/example/package.json"
]
}
}
}
28 changes: 24 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
},
"license": "MIT",
"devDependencies": {
"@commitlint/cli": "^7.4.0",
"@commitlint/config-conventional": "^7.3.1",
"@commitlint/travis-cli": "^7.4.0",
"@commitlint/cli": "^7.5.0",
"@commitlint/config-conventional": "^7.5.0",
"@commitlint/travis-cli": "^7.5.0",
"@types/mocha": "^5.0.0",
"coveralls": "^3.0.0",
"cz-conventional-changelog": "^2.1.0",
Expand All @@ -22,10 +22,11 @@
"typescript": "^3.3.1"
},
"scripts": {
"postinstall": "lerna bootstrap",
"postinstall": "lerna bootstrap && npm run -s update-greenkeeper-json",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not really solving the problem, is it? If the person does not run install after adding a new package, or perhaps revert changes made to greepkeeper config, then we won't know the pull request is not complete.

What I would like to see instead:

  • when update-greenkeeper-json.js is run with no arguments (or perhaps with a special new arg), and the config file requires an update, then the tool exits with non-zero status code
  • add a new entry to .travisyml to run consistency check, see commit-lint and code-lint for inspiration
  • add a new code block to bin/travis.sh implementing the new check by running update-greenkeeper-json.js

I am ok to defer this changes to a follow-up pull request if you prefer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's get greenkeeper to do the job first as it awaits this PR to be landed :-).

"prerelease": "npm run build:full && npm run mocha && npm run lint",
"release": "lerna version && lerna publish from-git --yes",
"update-template-deps": "node bin/update-template-deps -f",
"update-greenkeeper-json": "node bin/update-greenkeeper-json -f",
"sync-dev-deps": "node bin/sync-dev-deps",
"version": "npm run update-template-deps && npm run apidocs",
"outdated": "npm outdated --depth 0 && lerna exec --no-bail \"npm outdated --depth 0\"",
Expand Down Expand Up @@ -63,5 +64,24 @@
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},
"greenkeeper": {
"commitMessages": {
"initialBadge": "docs: add Greenkeeper badge",
"initialDependencies": "chore: update dependencies",
"initialBranches": "chore: whitelist greenkeeper branches",
"dependencyUpdate": "chore: update ${dependency} to version ${version}",
"devDependencyUpdate": "chore: update ${dependency} to version ${version}",
"dependencyPin": "chore: pin ${dependency} to ${oldVersion}",
"devDependencyPin": "chore: pin ${dependency} to ${oldVersion}"
},
"prTitles": {
"initialPR": "[greenkeeper] update dependencies to enable Greenkeeper",
"initialPrBadge": "[greenkeeper] add badge to enable Greenkeeper",
"initialPrBadgeOnly": "[greenkeeper] add Greenkeeper badge",
"initialSubgroupPR": "[greenkeeper] update dependencies for ${group}",
"basicPR": "[greenkeeper] update ${dependency} to the latest",
"groupPR": "[greenkeeper] update ${dependency} in group ${group} to the latest"
}
}
}
2 changes: 1 addition & 1 deletion packages/authentication/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@loopback/testlab": "^1.0.5",
"@loopback/tslint-config": "^2.0.0",
"@types/node": "^10.11.2",
"@types/passport": "^0.4.4",
"@types/passport": "^1.0.0",
"@types/passport-http": "^0.3.6",
"passport-http": "^0.3.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/boot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@loopback/core": "^1.1.5",
"@loopback/repository": "^1.1.4",
"@loopback/service-proxy": "^1.0.7",
"@types/debug": "0.0.30",
"@types/debug": "^0.0.31",
"@types/glob": "^7.1.1",
"debug": "^4.0.1",
"glob": "^7.1.2"
Expand Down
2 changes: 1 addition & 1 deletion packages/build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@
"mocha": "node bin/run-mocha --timeout 30000 \"test/integration/*.js\""
},
"devDependencies": {
"@loopback/tslint-config": "^1.0.0-1"
"@loopback/tslint-config": "^2.0.0"
}
}
10 changes: 5 additions & 5 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
"request": "^2.87.0",
"request-promise-native": "^1.0.5",
"rimraf": "^2.6.2",
"sinon": "^6.3.4",
"sinon": "^7.2.3",
"yeoman-assert": "^3.1.1",
"yeoman-environment": "^2.0.6",
"yeoman-test": "^1.7.0"
},
"dependencies": {
"@phenomnomnominal/tsquery": "^2.1.1",
"camelcase-keys": "^4.2.0",
"@phenomnomnominal/tsquery": "^3.0.0",
"camelcase-keys": "^5.0.0",
"chalk": "^2.3.2",
"change-case": "^3.0.2",
"debug": "^4.0.1",
Expand All @@ -55,8 +55,8 @@
"pluralize": "^7.0.0",
"regenerate": "^1.3.3",
"semver": "^5.5.0",
"swagger-parser": "^5.0.0",
"swagger2openapi": "^3.2.10",
"swagger-parser": "^6.0.5",
"swagger2openapi": "^5.1.0",
"typescript": "^3.1.1",
"unicode-10.0.0": "^0.7.4",
"update-notifier": "^2.5.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/context/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@loopback/testlab": "^1.0.5",
"@loopback/tslint-config": "^2.0.0",
"@types/bluebird": "^3.5.20",
"@types/debug": "^0.0.30",
"@types/debug": "^0.0.31",
"@types/node": "^10.11.2",
"@types/uuid": "^3.4.3",
"bluebird": "^3.5.1"
Expand Down
2 changes: 1 addition & 1 deletion packages/http-caching-proxy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@loopback/build": "^1.2.1",
"@loopback/testlab": "^1.0.5",
"@loopback/tslint-config": "^2.0.0",
"@types/debug": "^0.0.30",
"@types/debug": "^0.0.31",
"@types/node": "^10.11.2",
"@types/p-event": "^1.3.0",
"@types/request-promise-native": "^1.0.14",
Expand Down
2 changes: 1 addition & 1 deletion packages/metadata/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@loopback/build": "^1.2.1",
"@loopback/testlab": "^1.0.5",
"@loopback/tslint-config": "^2.0.0",
"@types/debug": "^0.0.30",
"@types/debug": "^0.0.31",
"@types/lodash": "^4.14.106",
"@types/node": "^10.11.2"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/openapi-v3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@loopback/repository": "^1.1.4",
"@loopback/testlab": "^1.0.5",
"@loopback/tslint-config": "^2.0.0",
"@types/debug": "0.0.30",
"@types/debug": "^0.0.31",
"@types/lodash": "^4.14.106",
"@types/node": "^10.11.2"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/repository/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"dependencies": {
"@loopback/context": "^1.5.0",
"@loopback/core": "^1.1.5",
"@types/debug": "0.0.30",
"@types/debug": "^0.0.31",
"debug": "^4.0.1",
"lodash": "^4.17.10",
"loopback-datasource-juggler": "^4.0.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"lodash": "^4.17.5",
"openapi-schema-to-json-schema": "^2.1.0",
"openapi3-ts": "^1.0.0",
"path-to-regexp": "^2.2.0",
"path-to-regexp": "^3.0.0",
"qs": "^6.5.2",
"strong-error-handler": "^3.2.0",
"type-is": "^1.6.16",
Expand All @@ -54,7 +54,7 @@
"@loopback/repository": "^1.1.4",
"@loopback/testlab": "^1.0.5",
"@loopback/tslint-config": "^2.0.0",
"@types/debug": "0.0.30",
"@types/debug": "^0.0.31",
"@types/js-yaml": "^3.11.1",
"@types/lodash": "^4.14.106",
"@types/multer": "^1.3.7",
Expand Down
6 changes: 5 additions & 1 deletion packages/rest/src/router/openapi-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ export function validateApiPath(path: string = '/') {
// Such as /(.*)
throw new Error(`Unnamed parameter is not allowed in path '${path}'`);
}
if (token.optional || token.repeat || token.pattern !== '[^\\/]+?') {
if (
(token.optional || token.repeat || token.pattern !== '[^\\/]+?') &&
// Required by path-to-regexp@3.x
token.prefix === '/'
) {
// Such as /:foo*, /:foo+, /:foo?, or /:foo(\\d+)
throw new Error(`Parameter modifier is not allowed in path '${path}'`);
}
Expand Down
5 changes: 5 additions & 0 deletions packages/rest/test/unit/router/openapi-path.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ describe('validateApiPath', () => {
expect(path).to.eql('/{foo}@{bar}');
});

it('allows /{foo}#{bar}', () => {
const path = validateApiPath('/{foo}#{bar}');
expect(path).to.eql('/{foo}#{bar}');
});

it('allows /{_foo}/{bar}', () => {
const path = validateApiPath('/{_foo}/{bar}');
expect(path).to.eql('/{_foo}/{bar}');
Expand Down
2 changes: 1 addition & 1 deletion packages/testlab/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@types/supertest": "^2.0.7",
"express": "^4.16.4",
"fs-extra": "^7.0.1",
"oas-validator": "^2.0.0",
"oas-validator": "^3.1.0",
"shot": "^4.0.7",
"should": "^13.2.3",
"sinon": "^7.2.2",
Expand Down