Skip to content

Commit

Permalink
Noviny/add bolt check package (#55)
Browse files Browse the repository at this point in the history
* add bolt check package

* add repository field to package.jsons
  • Loading branch information
Noviny committed May 31, 2019
1 parent 7399648 commit a966701
Show file tree
Hide file tree
Showing 100 changed files with 442 additions and 10 deletions.
1 change: 1 addition & 0 deletions .changeset/6005af8b/changes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "releases": [{ "name": "bolt-check", "type": "minor" }], "dependents": [] }
1 change: 1 addition & 0 deletions .changeset/6005af8b/changes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Initial Release
9 changes: 9 additions & 0 deletions .changeset/81dea29c/changes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"releases": [
{ "name": "bolt-check", "type": "patch" },
{ "name": "@changesets/cli", "type": "patch" },
{ "name": "@changesets/get-github-info", "type": "patch" },
{ "name": "get-workspaces", "type": "patch" }
],
"dependents": []
}
1 change: 1 addition & 0 deletions .changeset/81dea29c/changes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add repository information to package.json
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"name": "yarn-workspace-base-pkg-a",
"version": "1.0.0",
"dependencies": {
"pkg-b": "1.0.0"
"yarn-workspace-base-pkg-b": "1.0.0"
}
}
12 changes: 12 additions & 0 deletions __fixtures__/yarn-workspace-mismatched-external/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"private": true,
"name": "yarn-workspace-base",
"description": "Base yarn workspace work",
"version": "1.0.0",
"workspaces": [
"packages/*"
],
"dependencies": {
"get-workspaces": "^0.2.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "yarn-workspace-base-pkg-a",
"version": "1.0.0",
"dependencies": {
"get-workspaces": "^0.2.1"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "yarn-workspace-base-pkg-b",
"version": "1.0.0"
}
9 changes: 9 additions & 0 deletions __fixtures__/yarn-workspace-mismatched-internal/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"private": true,
"name": "yarn-workspace-base",
"description": "Base yarn workspace work",
"version": "1.0.0",
"workspaces": [
"packages/*"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "yarn-workspace-base-pkg-a",
"version": "1.0.0",
"dependencies": {
"yarn-workspace-base-pkg-b": "^0.1.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "yarn-workspace-base-pkg-b",
"version": "1.0.0"
}
9 changes: 9 additions & 0 deletions __fixtures__/yarn-workspace-missing-external/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"private": true,
"name": "yarn-workspace-base",
"description": "Base yarn workspace work",
"version": "1.0.0",
"workspaces": [
"packages/*"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "yarn-workspace-base-pkg-a",
"version": "1.0.0",
"dependencies": {
"get-workspaces": "^0.2.1"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "yarn-workspace-base-pkg-b",
"version": "1.0.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"name": "yarn-workspace-package-pkg-a",
"version": "1.0.0",
"dependencies": {
"pkg-b": "1.0.0"
"yarn-workspace-package-pkg-b": "1.0.0"
}
}
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
"check-all": "yarn test && yarn lint && yarn types:check",
"release": "yarn build && packages/cli/bin.js release --public"
},
"repository": {
"type": "git",
"url": "https://github.com/changesets/changesets.git"
},
"workspaces": [
"packages/*"
],
Expand Down Expand Up @@ -69,7 +73,7 @@
"jest": "^24.7.1",
"jest-fixtures": "^0.5.0",
"jest-junit": "^6.4.0",
"preconstruct": "^0.0.70"
"preconstruct": "^0.0.76"
},
"preconstruct": {
"packages": [
Expand Down
21 changes: 21 additions & 0 deletions packages/bolt-check/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Ben Conolly

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.
29 changes: 29 additions & 0 deletions packages/bolt-check/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# bolt-check

> A very simple command line utility to perform some of bolt's checks in yarn workspaces
Recently have been looking at using yarn workspaces over bolt, but was missing
bolt's checks. This very simple utility does the two checks I want the most.

## Make sure internal dependencies are compatible

We want to ensure we always use local versions of packages through yarn link, not
versions installed from npm. This ensures as we release new suites of packages,
they will all work together.

## Make sure external dependencies are all on the same version

When doing installs, we would like each package to use the same version of external
packages. We do this by having the 'correct' version recorded in the root `package.json`,
then ensuring that all workspaces a) rely on the same version as the root, and b) do
not contain any dependencies that are not in the root.

## So I don't need bolt anymore?

Depends! This package is not a replacement for bolt, doesn't do nearly as much as bolt,
and implements the two above checks in a fairly naive/simple way. Bolt is still a great
tool, and a great way to manage projects.

Most importantly, we aren't doing any work installing packages, so guarantees that bolt
can make by owning that, this won't have. Also, since `bolt-check` must be separately
installed, you won't gain benefits from short-circuiting installs.
4 changes: 4 additions & 0 deletions packages/bolt-check/bin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env node
"use strict";

require("./");
30 changes: 30 additions & 0 deletions packages/bolt-check/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "bolt-check",
"version": "0.0.0",
"description": "Run the two major checks that the bolt package does in yarn workspaces",
"main": "dist/bolt-check.cjs.js",
"module": "dist/bolt-check.esm.js",
"author": "Ben Conolly",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/changesets/changesets.git",
"directory": "packages/bolt-check"
},
"bin": {
"bolt-check": "bin.js"
},
"files": [
"dist",
"bin.js"
],
"dependencies": {
"chalk": "^2.1.0",
"semver": "^5.4.1",
"fs-extra": "^7.0.1",
"get-workspaces": "^0.2.1"
},
"devDependencies": {
"jest-fixtures": "^0.5.0"
}
}
69 changes: 69 additions & 0 deletions packages/bolt-check/src/bolt-check.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import boltCheck from "./bolt-check";
import { getFixturePath } from "jest-fixtures";

describe("bolt-check", () => {
it("should validate a project with no errors", async () => {
const cwd = await getFixturePath(__dirname, "yarn-workspace-base");

const errors = await boltCheck({ cwd, silent: true });
expect(errors).toEqual([]);
});
it("should error if a package contains an external dependency missing at root", async () => {
const cwd = await getFixturePath(
__dirname,
"yarn-workspace-missing-external"
);

const errors = await boltCheck({ cwd, silent: true });

expect(errors).toEqual([
{
dependency: "get-workspaces",
pkgName: "yarn-workspace-base-pkg-a",
type: "missingDependency"
}
]);
});
it("should error if a package contains an external dependency at a mistmatched version", async () => {
const cwd = await getFixturePath(
__dirname,
"yarn-workspace-mismatched-external"
);

const errors = await boltCheck({ cwd, silent: true });
expect(errors).toEqual([
{
dependency: "get-workspaces",
pkgName: "yarn-workspace-base-pkg-a",
type: "externalMismatch",
rootVersion: "^0.2.0",
pkgVersion: "^0.2.1"
}
]);
});
it("should error if a package contains an internal dependency at an incompatible version", async () => {
const cwd = await getFixturePath(
__dirname,
"yarn-workspace-mismatched-internal"
);

const errors = await boltCheck({ cwd, silent: true });
expect(errors).toEqual([
{
dependency: "yarn-workspace-base-pkg-b",
pkgName: "yarn-workspace-base-pkg-a",
type: "internalMismatch",
version: "1.0.0"
}
]);
});
it.skip("should print errors for both external and internal dependencies at once", async () => {
throw new Error("write this test");
});
it.skip("should print multiple errors for multiple internal mismatches", async () => {
throw new Error("write this test");
});
it.skip("should print multiple errors for multiple external mismatches", async () => {
throw new Error("write this test");
});
});

0 comments on commit a966701

Please sign in to comment.