Skip to content

Commit

Permalink
feat: add support for full semantic versioning in engines field
Browse files Browse the repository at this point in the history
Fixes #21

Add support for full semantic versioning in `engines` field of `package.json`.

* **action.yml**
  - Add a new input `updaters.engines.fullVersion` to enable full semantic versioning.

* **src/index.ts**
  - Add a new constant `updatersEnginesFullVersion` to get the input for full semantic versioning.
  - Add `updatersEnginesFullVersion` to the `inputs` object.

* **src/updateNodeVersions.ts**
  - Add `updatersEnginesFullVersion` to the `Inputs` type.
  - Pass `updatersEnginesFullVersion` to the `engines` function.

* **src/updaters/engines.ts**
  - Add a new parameter `fullVersion` to the `engines` function.
  - Update the `engines` function to set the `engines.node` field to `>=` followed by the full version if `fullVersion` is true.

* **README.md**
  - Update the `Engines` section to mention support for full semantic versioning.
  - Add an example of using the `updaters.engines.fullVersion` input.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/hongaar/update-node-versions/issues/21?shareId=XXXX-XXXX-XXXX-XXXX).
  • Loading branch information
hongaar committed Nov 7, 2024
1 parent 0b2ce8f commit 42906d1
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
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

0 comments on commit 42906d1

Please sign in to comment.