Skip to content

Commit

Permalink
new: Add engines version constraint.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Oct 24, 2020
1 parent 3ef5b38 commit 549ee48
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 1 deletion.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
"@milesj/build-tools": "^2.13.1",
"@types/fs-extra": "^9.0.2",
"@types/node": "^14.14.2",
"@types/react": "^16.9.53"
"@types/react": "^16.9.53",
"@types/semver": "^7.3.4"
},
"dependencies": {
"@babel/core": "^7.12.3",
Expand Down Expand Up @@ -92,6 +93,7 @@
"react": "^16.14.0",
"rollup": "^2.32.1",
"rollup-plugin-node-externals": "^2.2.0",
"semver": "^7.3.2",
"spdx-license-list": "^6.3.0",
"typescript": "^4.0.3"
}
Expand Down
2 changes: 2 additions & 0 deletions src/Packemon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ export default class Packemon {
this.project = new Project(this.root);

debug('Initializing packemon in project %s', this.root);

this.project.checkEngineVersionConstraint();
}

async build(baseOptions: BuildOptions) {
Expand Down
13 changes: 13 additions & 0 deletions src/Project.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import execa from 'execa';
import semver from 'semver';
import { Memoize, Project as BaseProject } from '@boost/common';
import Package from './Package';

Expand All @@ -7,6 +8,18 @@ export default class Project extends BaseProject {

private buildPromise?: Promise<unknown>;

checkEngineVersionConstraint() {
// eslint-disable-next-line
const { version } = require('../package.json');
const versionConstraint = this.rootPackage.packageJson.engines?.packemon;

if (version && versionConstraint && !semver.satisfies(version, versionConstraint)) {
throw new Error(
`Project requires a packemon version compatible with ${versionConstraint}, found ${version}.`,
);
}
}

isWorkspacesEnabled(): boolean {
return this.workspaces.length > 0;
}
Expand Down
15 changes: 15 additions & 0 deletions website/docs/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,18 @@ module scope will be executed immediately when the file is executed by Node.js.
## Referencing sibling inputs

Coming soon...

## Version constraints

If you're using packemon as a global dependency and want to ensure all contributors of your project
are using the correct packemon version, you can provide an `engines` constraint to your root
`package.json`.

```json title="package.json"
{
"name": "package",
"engines": {
"packemon": "^1.0.0"
}
}
```
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1922,6 +1922,11 @@
dependencies:
"@types/node" "*"

"@types/semver@^7.3.4":
version "7.3.4"
resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.3.4.tgz#43d7168fec6fa0988bb1a513a697b29296721afb"
integrity sha512-+nVsLKlcUCeMzD2ufHEYuJ9a2ovstb6Dp52A5VsoKxDXgvE051XgHI/33I1EymwkRGQkwnA0LkhnUzituGs4EQ==

"@types/stack-utils@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-2.0.0.tgz#7036640b4e21cc2f259ae826ce843d277dad8cff"
Expand Down

0 comments on commit 549ee48

Please sign in to comment.