Skip to content

Commit

Permalink
VDX-167: ESM version
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderPostma committed Aug 9, 2023
1 parent ad405bf commit 20e2263
Show file tree
Hide file tree
Showing 9 changed files with 249 additions and 18 deletions.
6 changes: 5 additions & 1 deletion generator/schemaGenerator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Ajv from 'ajv';
import standaloneCode from 'ajv/dist/standalone';
import standaloneCode from 'ajv/dist/standalone/index.cjs';

Check failure on line 2 in generator/schemaGenerator.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find module 'ajv/dist/standalone/index.cjs' or its corresponding type declarations.
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import {
BaseType,
createFormatter,
Expand All @@ -15,6 +16,9 @@ import {
} from 'ts-json-schema-generator';
import { Schema } from 'ts-json-schema-generator/src/Schema/Schema';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

class CustomTypeFormatter implements SubTypeFormatter {
public supportsType(type: FunctionType): boolean {
return type instanceof FunctionType;
Expand Down
42 changes: 36 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
{
"name": "@sphereon/did-auth-siop",
"version": "0.3.0-unstable.17",
"type": "module",
"main": "dist/main/index.js",
"types": "dist/main/index.d.ts",
"typings": "dist/main/index.d.ts",
"browser": "dist/browser/index.js",
"module": "dist/module/index.js",
"types": "dist/module/index.d.ts",
"license": "Apache-2.0",
"repository": {
"url": "https://github.com/Sphereon-Opensource/did-auth-siop.git"
},
"author": "Sphereon",
"description": "Self Issued OpenID V2 (SIOPv2) and OpenID 4 Verifiable Presentations (OID4VP)",
"scripts": {
"build": "npm-run-all build:schemaGenerator build:main",
"build:main": "tsc -p tsconfig.build.json",
"build:schemaGenerator": "node --loader ts-node/esm generator/schemaGenerator.ts",
"build": "npm-run-all build:schemaGenerator build:schemaPatch build:main build:browser build:module",
"build:main": "tsc -p tsconfig.main.json",
"build:browser": "tsc -p tsconfig.browser.json",
"build:module": "rollup -c",
"build:schemaGenerator": "ts-node --esm generator/schemaGenerator.ts",
"build:schemaPatch": "echo \"export const AuthorizationRequestPayloadVID1Schema = validate10;\nexport const AuthorizationRequestPayloadVD11Schema = validate57;\nexport const AuthorizationResponseOptsSchema = validate102;\nexport const RPRegistrationMetadataPayloadSchema = validate144;\nexport const DiscoveryMetadataPayloadSchema = validate147;\n\" >> src/main/schemas/validation/schemaValidation.js",
"clean": "rimraf dist coverage",
"fix": "run-s fix:*",
"fix:prettier": "prettier \"{src,test}/**/*.ts\" --write",
Expand Down Expand Up @@ -60,14 +67,16 @@
"@digitalcredentials/ed25519-signature-2020": "^3.0.2",
"@digitalcredentials/jsonld-signatures": "^9.3.1",
"@digitalcredentials/vc": "^5.0.0",
"@rollup/plugin-terser": "^0.4.3",
"@rollup/plugin-typescript": "^11.1.2",
"@types/jest": "^29.4.0",
"@types/language-tags": "^1.0.1",
"@typescript-eslint/eslint-plugin": "^5.52.0",
"@typescript-eslint/parser": "^5.52.0",
"ajv": "^8.12.0",
"codecov": "^3.8.3",
"cspell": "^6.26.3",
"dotenv": "^16.0.3",
"ajv": "^8.12.0",
"eslint": "^8.34.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-eslint-comments": "^3.2.0",
Expand All @@ -80,18 +89,39 @@
"npm-run-all": "^4.1.5",
"open-cli": "^7.1.0",
"prettier": "^2.8.4",
"rollup": "^3.28.0",
"ts-jest": "^29.0.5",
"ts-json-schema-generator": "^1.2.0",
"ts-node": "^10.9.1",
"typescript": "4.6.4"
},
"files": [
"dist/main"
"dist/main",
"dist/module",
"dist/browser"
],
"prettier": {
"singleQuote": true,
"printWidth": 150
},
"exports": {
".": {
"import": {
"types": "./dist/module/index.d.ts",
"default": "./dist/index.mjs"
},
"require": {
"types": "./dist/main/index.d.ts",
"default": "./dist/main/index.js"
},
"browser": {
"types": "./dist/browser/index.d.ts",
"default": "./dist/browser/index.js"
},
"default": "./dist/module/index.mjs"
},
"./package.json": "./package.json"
},
"keywords": [
"Sphereon",
"SSI",
Expand Down
26 changes: 26 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import typescript from '@rollup/plugin-typescript';
import terser from '@rollup/plugin-terser';

export default {
input: 'src/main/index.ts',
output: {
dir: 'dist/module',
format: 'esm',
entryFileNames: '[name].mjs'
},
plugins: [
typescript( {
tsconfig: 'tsconfig.module.json'
}),
terser({
format: {
comments: 'some',
beautify: true,
ecma: '2022',
},
compress: false,
mangle: false,
module: true,
}),
]
};
25 changes: 25 additions & 0 deletions tsconfig.browser.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"extends": "./tsconfig",
"compilerOptions": {
"target": "ES6",
"outDir": "dist/browser",
"module": "commonjs"
},
"lib": [
"es2015", "dom", "es6"
],
"include": [
"declarations.d.ts",
"index.ts",
"src/**/*.ts",
"src/**/*.js",
],
"exclude": [
"node_modules/**",
"coverage/**",
"resources/**",
"dist/**",
"test/**",
"generator/**/*.ts"
]
}
7 changes: 0 additions & 7 deletions tsconfig.build.json

This file was deleted.

9 changes: 6 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"compilerOptions": {
"incremental": true,
"target": "ES6",
"target": "ES2022",
"outDir": "dist/main",
"moduleResolution": "node",
"module": "commonjs",
"module": "ESNext",
"declaration": true,
"inlineSourceMap": true,
"allowJs": true,
Expand Down Expand Up @@ -41,7 +41,10 @@
"src/**/*.ts",
"src/**/*.js",
"test/**/*.ts",
"generator/**/*.ts"
"generator/**/*.ts",
"./package.json",
"./README.md",
"./LICENSE"
],
"exclude": [
"node_modules/**",
Expand Down
26 changes: 26 additions & 0 deletions tsconfig.main.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"extends": "./tsconfig",
"compilerOptions": {
"target": "ES6",
"outDir": "dist/main",
"module": "CommonJS",
"moduleResolution": "node",
"esModuleInterop": true
},

"include": [
"declarations.d.ts",
"index.ts",
"src/**/*.ts",
"src/**/*.js",
],
"exclude": [
"node_modules/**",
"coverage/**",
"resources/**",
"dist/**",
"test/**",
"generator/**/*.ts"
],

}
24 changes: 24 additions & 0 deletions tsconfig.module.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"extends": "./tsconfig",
"compilerOptions": {
"target": "ES2022",
"outDir": "dist/module",
"module": "ESNext",
"moduleResolution": "node",
"esModuleInterop": true
},
"include": [
"declarations.d.ts",
"index.ts",
"src/**/*.ts",
"src/**/*.js"
],
"exclude": [
"node_modules/**",
"coverage/**",
"resources/**",
"dist/**",
"test/**",
"generator/**/*.ts"
]
}
Loading

0 comments on commit 20e2263

Please sign in to comment.