Skip to content
This repository has been archived by the owner on Jul 31, 2024. It is now read-only.

Commit

Permalink
refactor: migrate to TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
fraxken committed Jul 5, 2024
1 parent 3f14f46 commit 85aac78
Show file tree
Hide file tree
Showing 16 changed files with 693 additions and 296 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x, 20.x]
node-version: [20.x]
fail-fast: false
steps:
- name: Harden Runner
Expand All @@ -28,5 +28,7 @@ jobs:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: npm install
- name: Build source
run: npm run build
- name: Run tests
run: npm run test
20 changes: 9 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ NodeSecure [SPDX licenses](https://spdx.org/licenses/) conformance. Project fork

## Requirements

- [Node.js](https://nodejs.org/en/) v18 or higher
- [Node.js](https://nodejs.org/en/) v20 or higher

## Getting Started

Expand All @@ -30,10 +30,9 @@ $ yarn add @nodesecure/licenses-conformance
```js
import { licenseIdConformance } from "@nodesecure/licenses-conformance";

const result = licenseIdConformance("MIT");
if (result.ok) {
console.log(result.value);
}
const conformance = licenseIdConformance("MIT").unwrap();
console.log(conformance);

/*
{
uniqueLicenseIds: ["MIT"],
Expand All @@ -51,10 +50,9 @@ if (result.ok) {
## API

```ts
interface spdxLicenseConformance {
uniqueLicenseIds: string[];
spdxLicenseLinks: string[];
spdx?: {
export interface SpdxLicenseConformance {
licenses: Record<string, string>
spdx: {
osi: boolean;
fsf: boolean;
fsfAndOsi: boolean;
Expand All @@ -64,14 +62,14 @@ interface spdxLicenseConformance {

function licenseIdConformance(
licenseID: string
): { ok: true, value: spdxLicenseConformance } | { ok: false, value: Error };
): Result<SpdxLicenseConformance, Error>;

function searchSpdxLicenseId(contentStr: string): string | null;
```

## Updating SPDX licenses

To update the `src/spdx.js` file just run the following npm script:
To update the `src/data/spdx.ts` file just run the following npm script:

```bash
$ npm run spdx:refresh
Expand Down
24 changes: 0 additions & 24 deletions index.d.ts

This file was deleted.

108 changes: 0 additions & 108 deletions index.js

This file was deleted.

37 changes: 21 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,54 @@
"name": "@nodesecure/licenses-conformance",
"version": "2.1.0",
"description": "Check spdx license expressions",
"main": "index.js",
"type": "module",
"exports": "./dist/index.js",
"types": "./dist/index.d.ts",
"scripts": {
"start": "node index.js",
"lint": "eslint index.js",
"test-only": "node --test",
"test": "npm run lint && npm run test-only",
"coverage": "c8 -r html npm test",
"build": "tsc",
"prepublishOnly": "npm run build",
"test": "npm run test-only",
"test-only": "glob -c \"tsx --test\" \"./test/**/*.test.ts\"",
"coverage": "c8 -r html npm run test-only",
"spdx:refresh": "node ./scripts/fetchSpdxLicenses.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/NodeSecure/licenses-conformance.git"
},
"files": [
"index.js",
"index.d.ts",
"src"
"dist"
],
"keywords": [
"spdx",
"licenses"
],
"author": "NodeSecure",
"type": "module",
"license": "MIT",
"bugs": {
"url": "https://github.com/NodeSecure/licenses-conformance/issues"
},
"types": "index.d.ts",
"homepage": "https://github.com/NodeSecure/licenses-conformance#readme",
"dependencies": {
"@openally/result": "^1.2.1",
"fastest-levenshtein": "^1.0.16",
"spdx-expression-parse": "^4.0.0"
},
"devDependencies": {
"@myunisoft/httpie": "^4.0.1",
"@nodesecure/eslint-config": "^1.8.0",
"@myunisoft/httpie": "^5.0.0",
"@nodesecure/eslint-config": "^1.9.0",
"@types/node": "^20.14.9",
"@types/spdx-expression-parse": "^3.0.5",
"astring": "^1.8.6",
"c8": "^9.1.0",
"eslint": "^8.31.0",
"node-estree": "^4.0.0"
"c8": "^10.1.2",
"eslint": "^8.57.0",
"glob": "^10.4.2",
"node-estree": "^4.0.0",
"tsx": "^4.16.2",
"typescript": "^5.5.3"
},
"engines": {
"node": ">=18"
"node": ">=20"
}
}
4 changes: 2 additions & 2 deletions scripts/fetchSpdxLicenses.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as astring from "astring";
import { ESTree, Helpers, VarDeclaration } from "node-estree";

// CONSTANTS
const kSrcDirectory = new URL("../src/", import.meta.url);
const kSrcDirectory = new URL("../src/data/", import.meta.url);

const { data } = await httpie.get(
"https://raw.githubusercontent.com/spdx/license-list-data/main/json/licenses.json"
Expand Down Expand Up @@ -46,6 +46,6 @@ const prog = ESTree.Program("module", [
]);

fs.writeFileSync(
new URL("spdx.js", kSrcDirectory),
new URL("spdx.ts", kSrcDirectory),
`/* eslint-disable max-lines */\n\n` + astring.generate(prog)
);
Loading

0 comments on commit 85aac78

Please sign in to comment.