Skip to content

feat: add support for full semantic versioning in engines field #22

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ available:
}
}
```
If you want to use full semantic versioning for the `engines` field, you can enable the `updaters.engines.fullVersion` input.
```yaml
- uses: hongaar/update-node-versions@v2
with:
updaters.engines.fullVersion: true
```
This will update the `engines` field to include the full version.
```json
{
"engines": {
"node": ">=18.0.0"
}
}
```
- **Files**
This will update arbitrary files in your repository. You can specify a glob
pattern of files to update, a regex to match and a replacement template to
Expand All @@ -112,6 +126,7 @@ available:
| `updaters.workflows` | `true` | Update GitHub workflows. |
| `updaters.workflows.variable` | `"node-version"` | Use this name as the matrix strategy variable to update the Node versions in. |
| `updaters.engines` | `true` | Update package.json `engines`. |
| `updaters.engines.fullVersion`| `false` | Use full semantic versioning for engines. |
| `updaters.files` | `false` | Update arbitrary files. |
| `updaters.files.glob` | | Glob pattern for files to update. |
| `updaters.files.regex` | | Matches will be replaced with the template. |
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ inputs:
description: Update package.json `engines`
required: false
default: true
updaters.engines.fullVersion:
description: Use full semantic versioning for engines
required: false
default: false
updaters.files:
description: Update arbitrary files
required: false
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const updatersFiles = getBooleanInput("updaters.files");
const updatersFilesGlob = getMultilineInput("updaters.files.glob");
const updatersFilesRegex = getMultilineInput("updaters.files.regex");
const updatersFilesTemplate = getMultilineInput("updaters.files.template");
const updatersEnginesFullVersion = getBooleanInput("updaters.engines.fullVersion");

const inputs = {
versions,
Expand All @@ -28,6 +29,7 @@ const inputs = {
updatersFilesGlob,
updatersFilesRegex,
updatersFilesTemplate,
updatersEnginesFullVersion,
};

updateNodeVersions(inputs)
Expand Down
3 changes: 2 additions & 1 deletion src/updateNodeVersions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Inputs = {
updatersFilesGlob: string[];
updatersFilesRegex: string[];
updatersFilesTemplate: string[];
updatersEnginesFullVersion: boolean;
};

type Outputs = {
Expand Down Expand Up @@ -47,7 +48,7 @@ export async function updateNodeVersions(inputs: Inputs) {
}

if (inputs.updatersEngines) {
await engines(outputs.versions);
await engines(outputs.versions, process.cwd(), inputs.updatersEnginesFullVersion);
}

if (inputs.updatersFiles) {
Expand Down
4 changes: 2 additions & 2 deletions src/updaters/engines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async function getPackageJson(cwd = process.cwd()) {
return;
}

export async function engines(versions: number[], cwd = process.cwd()) {
export async function engines(versions: number[], cwd = process.cwd(), fullVersion = false) {
const packageJson = await getPackageJson(cwd);

if (!packageJson) {
Expand All @@ -25,7 +25,7 @@ export async function engines(versions: number[], cwd = process.cwd()) {

if (packageJson.engines && packageJson.engines["node"]) {
info(`Updating engines.node in package.json`);
packageJson.engines["node"] = `>=${versions[0]}`;
packageJson.engines["node"] = `>=${fullVersion ? versions.join(".") : versions[0]}`;

await writeFile(
join(cwd, PACKAGE_PATH),
Expand Down
Loading