Skip to content
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

feat: add @nodevu/latest module #76

Merged
merged 3 commits into from
Nov 8, 2024
Merged
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
27 changes: 27 additions & 0 deletions .github/workflows/lint-newest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: "Test Suite: Linter (newest)"

on:
push:
pull_request:
paths:
- 'newest/**'
branches:
- main
workflow_dispatch:
workflow_call:

jobs:
tests:
if: github.repository == 'cutenode/nodevu'
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: current
- name: Run npm install -w newest
run: npm install -w newest
- name: Run npm run lint -w newest
run: npm run lint -w newest
22 changes: 22 additions & 0 deletions .github/workflows/publish-newest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Publish @nodevu/newest to npmjs
on:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
# Setup .npmrc file to publish to npm
- uses: actions/setup-node@v4
with:
node-version: 'latest'
registry-url: 'https://registry.npmjs.org'
- run: npm install -w newest
- run: npm run lint -w newest
- run: npm run coverage -w newest
- run: npm publish --provenance --access public -w newest
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
31 changes: 31 additions & 0 deletions .github/workflows/tests-newest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: "Test Suite: @nodevu/newest"

on:
pull_request:
paths:
- 'newest/**'
branches:
- main
workflow_dispatch:
workflow_call:

jobs:
tests:
if: github.repository == 'cutenode/nodevu'
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [current, lts/*, lts/-1]
steps:
- name: Checkout the repository
uses: actions/checkout@v4
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install most recent npm
run: npm install -g npm
- name: Run npm install -w newest
run: npm install -w newest
- name: Run npm test -w newest
run: npm test -w newest
21 changes: 21 additions & 0 deletions newest/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License Copyright (c) 2022 Tierney Cyren

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
(including the next paragraph) 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.
31 changes: 31 additions & 0 deletions newest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# @nodevu/newest

A module that returns newest LTS or Security release of a given Node.js release line.

## Usage

```js
const { newest } = require('@nodevu/newest')

const newestLts = newest('v16', 'lts')
const newestSecurity = newest('v16', 'security')
```

```js
const { lts, security } = require('@nodevu/newest')

const newestLts = lts('v16')
const newestSecurity = security('v16')
```

## API

This module exports three functions:

- `newest(name, type)`
- `name` (string): Node.js release line name. Examples: `v16`, `v11`, `v8`, `v0.10`.
- `type` (string): `lts` or `security`.
- `lts(name)`
- `name` (string): Node.js release line name. Examples: `v16`, `v11`, `v8`, `v0.10`.
- `security(name)`
- `name` (string): Node.js release line name. Examples: `v16`, `v11`, `v8`, `v0.10`.
17 changes: 17 additions & 0 deletions newest/biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "https://biomejs.dev/schemas/1.6.1/schema.json",
"organizeImports": {
"enabled": true
},
"javascript": {
"formatter": {
"quoteStyle": "single"
}
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
}
}
25 changes: 25 additions & 0 deletions newest/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const nodevu = require('@nodevu/core');

async function newest(name, type) {
const data = await nodevu();

if (type === 'lts') {
return data[name].support.lts.newest;
}

if (type === 'security') {
return data[name].security.newest;
}
}

async function lts(name) {
return await newest(name, 'lts');
}

async function security(name) {
return await newest(name, 'security');
}

module.exports.newest = newest;
module.exports.lts = lts;
module.exports.security = security;
33 changes: 33 additions & 0 deletions newest/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "@nodevu/newest",
"version": "0.1.0",
"description": "a module that returns the newest lts or security release of the release line passed.",
"main": "index.js",
"files": ["index.js", "LICENSE"],
"scripts": {
"lint": "biome check ./",
"lint:write": "biome check ./ --write",
"test": "node --test",
"coverage": "c8 node --test",
"updates:check": "npx npm-check-updates",
"updates:update": "npx npm-check-updates -u"
},
"repository": {
"type": "git",
"url": "git+https://github.com/cutenode/nodevu.git"
},
"keywords": ["node.js", "versions"],
"author": "Tierney Cyren <[email protected]> (https://bnb.im/)",
"license": "MIT",
"bugs": {
"url": "https://github.com/cutenode/nodevu/issues"
},
"homepage": "https://github.com/cutenode/nodevu#readme",
"dependencies": {
"@nodevu/core": "^0.3.0"
},
"devDependencies": {
"@biomejs/biome": "1.9.4",
"c8": "^10.1.2"
}
}
31 changes: 31 additions & 0 deletions newest/test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const assert = require('node:assert');
const { newest, lts, security } = require('../index');
const { describe, it } = require('node:test');

describe('check v10', async () => {
describe('running newest', async () => {
it('should return the correct security version for v10', async () => {
const data = await newest('v10', 'security');
assert.equal(data, '10.24.1');
});

it('should return the correct lts version for v10', async () => {
const data = await newest('v10', 'lts');
assert.equal(data, '10.24.1');
});
});

describe('running security', async () => {
it('should return the correct security version for v10', async () => {
const data = await security('v10');
assert.equal(data, '10.24.1');
});
});

describe('running lts', async () => {
it('should return the correct lts version for v10', async () => {
const data = await lts('v10');
assert.equal(data, '10.24.1');
});
});
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"static",
"parsefiles",
"earliest",
"newest",
"ranges",
"aliases",
"translate"
Expand Down