Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

6 changes: 0 additions & 6 deletions .eslintrc

This file was deleted.

41 changes: 41 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: CI

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
check-format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- run: bun install
- run: bun run check-format

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- run: bun install
- run: bun run lint

type-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- run: bun install
- run: bun run type-check

build:
runs-on: ubuntu-latest
needs: [check-format, lint, type-check]
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- run: bun install
- run: bun run build
32 changes: 0 additions & 32 deletions .github/workflows/lint.yml

This file was deleted.

30 changes: 17 additions & 13 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
name: Publish
name: Publish Package to npmjs

on:
push:
branches:
- main
release:
types: [published]

jobs:
publish:
build:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- run: bun install
- run: bun run build
- uses: actions/setup-node@v4
with:
node-version: 12
- run: yarn config delete proxy
- run: yarn
- uses: JS-DevTools/npm-publish@v1
with:
token: ${{ secrets.NPM_TOKEN }}
node-version: "22.x"
registry-url: "https://registry.npmjs.org"
- run: npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
.vscode
dist/
418 changes: 418 additions & 0 deletions bun.lock

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineConfig, globalIgnores } from "eslint/config";

export default defineConfig([
globalIgnores([".github/workflows/**/*", "dist/**/*"]),
{
languageOptions: {
ecmaVersion: "latest",
sourceType: "module",
},
},
]);
57 changes: 47 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,57 @@
{
"name": "edam2json-js",
"version": "0.3.2",
"version": "0.4.0",
"description": "Javascript library to convert EDAM to JSON/CSV/TSV",
"main": "index.js",
"type": "module",
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"browser": "dist/index.umd.js",
"types": "dist/index.d.ts",
"files": [
"dist"
],
"sideEffects": false,
"exports": {
".": {
"import": "./dist/index.esm.js",
"require": "./dist/index.cjs.js",
"types": "./dist/index.d.ts"
},
"./browser": {
"import": "./dist/browser.umd.js",
"require": "./dist/browser.umd.js",
"types": "./dist/index.d.ts"
}
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"clean": "rimraf dist",
"lint": "eslint .",
"type-check": "tsc --noEmit",
"check-format": "prettier --check src/",
"check": "bun run check-format && bun run lint && bun run type-check",
"prepare": "npm run build",
"build": "rollup -c",
"prepublishOnly": "npm test"
},
"dependencies": {
"axios": "^0.21.1",
"commander": "^8.1.0",
"eslint": "^7.32.0",
"prettier": "^2.3.2",
"rdfxml-streaming-parser": "^1.4.0"
"rdfxml-streaming-parser": "^1.4.0",
"tslib": "^2.8.1"
},
"browser": "browser.js",
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"devDependencies": {
"@rollup/plugin-commonjs": "^28.0.6",
"@rollup/plugin-node-resolve": "^16.0.1",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^12.1.3",
"@types/node": "^24.0.3",
"eslint": "^9.29.0",
"prettier": "^3.5.3",
"rimraf": "^6.0.1",
"rollup": "^4.43.0",
"rollup-plugin-dts": "^6.2.1",
"rollup-plugin-polyfill-node": "^0.13.0",
"typescript": "^5.8.3"
},
"repository": {
"type": "git",
Expand Down
83 changes: 83 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import typescript from "@rollup/plugin-typescript";
import dts from "rollup-plugin-dts";
import terser from "@rollup/plugin-terser";
import polyfillNode from "rollup-plugin-polyfill-node";

// suppress rollup warnings we know are benign
const onwarn = (warning, defaultHandler) => {
// polyfill-node circular deps
if (
warning.code === "CIRCULAR_DEPENDENCY" &&
/polyfill-node/.test(warning.importer)
) {
return;
}
if (
warning.code === "THIS_IS_UNDEFINED" &&
warning.message.includes("sax.js")
) {
return;
}
// suppress empty chunk warning for d.ts rollup
if (warning.code === "EMPTY_CHUNK") {
return;
}
defaultHandler(warning);
};

const sharedPlugins = [
resolve(),
commonjs(),
typescript({ tsconfig: "./tsconfig.json" }),
];

const browserPlugins = [
polyfillNode(),
resolve({ browser: true, preferBuiltins: false }),
commonjs(),
typescript({ tsconfig: "./tsconfig.json" }),
];

export default [
// 1) Node/CJS + ESM build
{
input: "src/index.ts",
onwarn,
output: [
{ file: "dist/index.cjs.js", format: "cjs", sourcemap: true },
{ file: "dist/index.esm.js", format: "es", sourcemap: true },
],
plugins: sharedPlugins,
},
// 2) Browser UMD build (with polyfills)
{
input: "src/browser.ts",
onwarn,
plugins: browserPlugins,
context: "window", // Moved to the correct top-level position
output: [
{
file: "dist/browser.umd.js",
format: "umd",
name: "Edam2JSON",
sourcemap: true,
},
{
file: "dist/browser.umd.min.js",
format: "umd",
name: "Edam2JSON",
sourcemap: true,
plugins: [terser()],
},
],
},
// 3) Roll up d.ts
{
input: "dist/index.d.ts",
onwarn, // Added onwarn here to suppress the empty chunk warning
output: [{ file: "dist/index.d.ts", format: "es" }],
plugins: [dts()],
},
];
32 changes: 18 additions & 14 deletions browser.js → src/browser.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
import { parseToJSON } from "./src/parser.js";
import axios from "axios";
import { parseToJSON } from "./parser";

/**
* Parses an OWL file to a json tree of nodes
* @param {string} url The URL of the owl file in raw format e.g "https://raw.githubusercontent.com/edamontology/edamontology/main/releases/EDAM_1.25.owl"
* @param {function} onSuccess The callback function to be executed after the tree is ready e.g (tree) => {console.log(tree)}
* @param {function} onError The callback function to be executed in case of an error
*/
const jsonTreeFromURL = (url, onSuccess, onError) => {
axios
.get(url)
.then((resp) => {
parseToJSON(resp.data, onSuccess);
})
.catch((err) => {
onError(err);
});
};
async function jsonTreeFromURL(
url: string,
onSuccess: () => void,
onError: (err: Error) => void,
) {
try {
const response = await fetch(url);
if (!response.ok) throw new Error("Fetch call failed");

const data = await response.json();
parseToJSON(data, onSuccess);
} catch (err) {
onError(err);
}
}

/**
* Parses an OWL file to a json tree of nodes
* @param {string} text the string containing the OWL file content
* @param {function} onSuccess The callback function to be executed after the tree is ready e.g (tree) => {console.log(tree)}
*/
const jsonTreeFromString = (text, onSuccess) => {
function jsonTreeFromString(text: string, onSuccess: () => void) {
parseToJSON(text, onSuccess);
};
}

export { jsonTreeFromURL, jsonTreeFromString };
Loading