Skip to content

Commit

Permalink
feat: add @nodevu/fetchindex
Browse files Browse the repository at this point in the history
Signed-off-by: Tierney Cyren <hello@bnb.im>
  • Loading branch information
bnb committed Nov 8, 2024
1 parent 7026d6d commit a63c597
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 1 deletion.
21 changes: 21 additions & 0 deletions fetchindex/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.
13 changes: 13 additions & 0 deletions fetchindex/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# @nodevu/fetchindex

A tool that fetches the /dist/index.json file from the Node.js website.

## Usage

```js
```

```js
```

## API
17 changes: 17 additions & 0 deletions fetchindex/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
}
}
}
13 changes: 13 additions & 0 deletions fetchindex/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
async function versions(options) {
// parse our options and set up fetch if a custom fetch is passed
const fetch = options.fetch;
const url = options.urls.index;

// fetch the url, get the json from the fetched URL that we're going to use
const raw = await fetch(url);
const versions = await raw.json();

return versions;
}

module.exports = versions;
32 changes: 32 additions & 0 deletions fetchindex/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "@nodevu/fetchindex",
"version": "0.1.0",
"description": "A tool that fetches the /dist/index.json file from the Node.js website.",
"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 <hello@bnb.im> (https://bnb.im/)",
"license": "MIT",
"bugs": {
"url": "https://github.com/cutenode/nodevu/issues"
},
"homepage": "https://github.com/cutenode/nodevu#readme",
"devDependencies": {
"@biomejs/biome": "1.9.4",
"c8": "^10.1.2",
"luxon": "^3.5.0",
"undici": "^6.20.1"
}
}
59 changes: 59 additions & 0 deletions fetchindex/test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
const { deepStrictEqual } = require('node:assert');
const { describe, it } = require('node:test');
const { fetch: undiciFetch } = require('undici');
const { DateTime } = require('luxon');
const nodevu = require('../index');
const versions = require('../index');
const optionsParser = require('../../core/util/prod/optionsParser');

// checks that verify the result of data returned
function check(data) {
deepStrictEqual(typeof data[0].version, 'string');
deepStrictEqual(typeof data[0].date, 'string');
deepStrictEqual(Array.isArray(data[0].files), true);
deepStrictEqual(typeof data[0].npm, 'string');
deepStrictEqual(typeof data[0].v8, 'string');
deepStrictEqual(typeof data[0].uv, 'string');
deepStrictEqual(typeof data[0].zlib, 'string');
deepStrictEqual(typeof data[0].openssl, 'string');
deepStrictEqual(typeof data[0].modules, 'string');
deepStrictEqual(typeof data[0].lts, 'boolean');
deepStrictEqual(typeof data[0].security, 'boolean');
}

// set up options object that would normally be passed to the module
const options = {
fetch: globalThis.fetch,
urls: {
index: 'https://nodejs.org/dist/index.json',
},
};

describe('under normal condiditons, versions should work', async () => {
it('should work with default options', async () => {
const data = await versions(options);
check(data);
});

it('should work with Undici fetch', async () => {
options.fetch = undiciFetch;
const data = await versions(options);
check(data);
});
});

describe('versions should work with optionsParser', async () => {
it('should work with the default output of optionsParser', async () => {
const parsedOptions = optionsParser({});
const data = await versions(parsedOptions);
check(data);
});

it('should work with a different fetch pased to optionsParser', async () => {
const parsedOptions = optionsParser({
fetch: undiciFetch,
});
const data = await versions(parsedOptions);
check(data);
});
});
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"newest",
"ranges",
"aliases",
"translate"
"translate",
"fetchindex"
]
}

0 comments on commit a63c597

Please sign in to comment.