Skip to content

Commit

Permalink
fix(engines): ensure correct required node version
Browse files Browse the repository at this point in the history
Closes #237

BREAKING CHANGE:

Changed `engines.node` from `>=16` to `>=18.18.0`.

`minimatch@10` was updated in `[email protected]` which required `node@>=20` and
caused issues in some projects.

This change adds a local linter to verify that the node engines of syncpack's
dependencies all satisfy syncpack's own node engine. Using this linter found
that the minimum node engine of all of syncpack's dependencies is v18.18.0.
  • Loading branch information
JamieMason committed Aug 25, 2024
1 parent f1e6ce2 commit e8df803
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
node-version: [16.x, 18.x, 20.x]
node-version: [18.18.0, 20.x, 22x]

steps:
- uses: actions/checkout@v4
Expand Down
6 changes: 6 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
# https://pnpm.io/next/npmrc#auto-install-peers
auto-install-peers=false
# https://pnpm.io/next/npmrc#strict-peer-dependencies
strict-peer-dependencies=true
# https://docs.npmjs.com/cli/v10/using-npm/config#strict-peer-deps
strict-peer-deps=true
# https://docs.npmjs.com/cli/v10/using-npm/config#engine-strict
engine-strict=true
12 changes: 2 additions & 10 deletions .syncpackrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,13 @@
/** @type {import("./src").RcFile} */
const config = {
semverGroups: [
{
dependencyTypes: ['overrides'],
isIgnored: true,
},
{
range: '',
},
],
versionGroups: [
{ dependencies: ['string-width'], pinVersion: '<5.0.0' },
{ dependencies: ['strip-ansi'], pinVersion: '<7.0.0' },
{ dependencies: ['wrap-ansi'], pinVersion: '<8.0.0' },
{ dependencies: ['chalk'], pinVersion: '4.1.2' },
{ dependencies: ['globby'], pinVersion: '11.1.0' },
{ dependencies: ['ora'], pinVersion: '5.4.1' },
// v10 does not support Node 18
{ dependencies: ['minimatch'], pinVersion: '9.0.5' },
],
};

Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"fast-check": "3.21.0",
"globby": "14.0.2",
"jsonc-parser": "3.3.1",
"minimatch": "10.0.1",
"minimatch": "9.0.5",
"npm-package-arg": "11.0.3",
"ora": "8.0.1",
"prompts": "2.4.2",
Expand Down Expand Up @@ -83,7 +83,7 @@
"vitest": "2.0.5"
},
"engines": {
"node": ">=16"
"node": ">=18.18.0"
},
"exports": "./dist/index.js",
"files": [
Expand Down Expand Up @@ -120,7 +120,9 @@
"format": "pnpm run format:source && pnpm run format:astro",
"format:astro": "prettier --write site/src",
"format:source": "biome check --write --unsafe",
"lint": "biome check && tsc --noEmit",
"lint": "npm run lint:source && npm run lint:engines",
"lint:engines": "node scripts/check-engines.mjs",
"lint:source": "biome check && tsc --noEmit",
"prepack": "pnpm run build",
"release": "release-it",
"test": "vitest run --coverage src",
Expand Down
12 changes: 2 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions scripts/check-engines.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { readFileSync } from 'node:fs';
import { globbySync } from 'globby';
import { satisfies } from 'semver';
import root from '../package.json' assert { type: 'json' };

const syncpackEngine = root.engines.node.replace('>=', '');

const unsatisfiedDependencies = globbySync('node_modules/**/package.json')
.map(filePath => readFileSync(filePath, 'utf8'))
.filter(json => json.includes('"engines"'))
.map(json => JSON.parse(json))
.filter(file => file.engines?.node)
.map(file => {
const name = file.name;
const dependencyEngine = file.engines.node;
const isSatisfied = satisfies(syncpackEngine, dependencyEngine);
return {
name,
expected: syncpackEngine,
actual: dependencyEngine,
isSatisfied,
};
})
.filter(result => !result.isSatisfied);

if (unsatisfiedDependencies.length) {
console.error(
'The following dependencies have incompatible engines:',
unsatisfiedDependencies,
);
process.exit(1);
} else {
console.info('All dependencies have compatible engines.');
}

0 comments on commit e8df803

Please sign in to comment.