Skip to content

Commit

Permalink
build: convert veramo modules to ESM instead of CommonJS (#1103)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: this is a breaking change as modules will have to be imported differently: 
* https://www.typescriptlang.org/docs/handbook/esm-node.html
* https://nodejs.org/api/esm.html
* https://caniuse.com/?search=modules

test(did-provider-ion): skip a couple of tests that fail with unreasonable errors
chore: use ubuntu-latest on CI
fix: temporarily remove puppeteer tests
fix: use craco for test-react-app to enable babel config
test: fix unit and integration tests (browser tests still broken)
fix: fix some build issues that prevented tests from working
fix: missing deps flagged by pnpm
build: migrate esm branch from yarn to pnpm (#1099)
fix: remove schemas
fix: use requireCjs for importing JSON files
build: use local veramo cli in CI scripts
build: fix api-extractor and schema generation scripts
fix(cli): esm objectCreator
fix(cli): ignore types in schema generation
fix: requireCjs
refactor: convert all modules to ESM

Co-authored-by: nickreynolds <nicholas.s.reynolds@gmail.com>
  • Loading branch information
mirceanis and nickreynolds authored Jan 30, 2023
1 parent 17a7c51 commit b5cea3c
Show file tree
Hide file tree
Showing 216 changed files with 2,438 additions and 1,540 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-and-test-on-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Build and Test PR
on: [pull_request, workflow_dispatch]
jobs:
build-test:
runs-on: ubuntu-18.04
runs-on: ubuntu-latest
services:
postgres:
image: postgres:15.1
Expand All @@ -23,7 +23,7 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 14
node-version: 18
cache: 'pnpm'

- run: pnpm install
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/build-test-publish-on-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
GH_TOKEN: ${{secrets.GH_TOKEN}}
GH_USER: ${{secrets.GH_USER}}
GH_EMAIL: ${{secrets.GH_EMAIL}}
runs-on: ubuntu-18.04
runs-on: ubuntu-latest
services:
postgres:
image: postgres:15.1
Expand All @@ -36,7 +36,7 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 14
node-version: 18
cache: 'pnpm'

- run: pnpm install
Expand All @@ -54,6 +54,8 @@ jobs:
- name: run browser tests
run: pnpm test:browser

- run: pnpm run docs

- name: setup git coordinates
run: |
git remote set-url origin https://uport-project:$GH_TOKEN@github.com/uport-project/veramo.git
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sync-next-with-latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- 'main'
jobs:
merge-branch:
runs-on: ubuntu-18.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: everlytic/branch-merge@1.1.5
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ This monorepo uses [pnpm](https://pnpm.io/) and [lerna](https://lerna.js.org/)
Install dependencies

```bash
npm -g i pnpm
pnpm install
```

Expand Down
7 changes: 7 additions & 0 deletions __tests__/initial.migration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ import { getResolver as ethrDidResolver } from 'ethr-did-resolver'
import { getResolver as webDidResolver } from 'web-did-resolver'
import * as fs from 'fs'

import { jest } from '@jest/globals'
import { fileURLToPath } from 'url';
import { dirname } from 'path';

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

jest.setTimeout(60000)

const infuraProjectId = '3586660d179141e3801c3895de1c2eba'
Expand Down
2 changes: 2 additions & 0 deletions __tests__/localAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ import { getResolver as ethrDidResolver } from 'ethr-did-resolver'
import { getResolver as webDidResolver } from 'web-did-resolver'
import { contexts as credential_contexts } from '@transmute/credentials-context'
import * as fs from 'fs'
import { jest } from '@jest/globals'

// Shared tests
import verifiableDataJWT from './shared/verifiableDataJWT'
import verifiableDataLD from './shared/verifiableDataLD'
Expand Down
1 change: 1 addition & 0 deletions __tests__/localJsonStoreAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import { getResolver as ethrDidResolver } from 'ethr-did-resolver'
import { getResolver as webDidResolver } from 'web-did-resolver'
import { contexts as credential_contexts } from '@transmute/credentials-context'
import * as fs from 'fs'
import { jest } from '@jest/globals'

// Shared tests
import verifiableDataJWT from './shared/verifiableDataJWT'
Expand Down
2 changes: 2 additions & 0 deletions __tests__/localMemoryStoreAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ import { getResolver as ethrDidResolver } from 'ethr-did-resolver'
import { getResolver as webDidResolver } from 'web-did-resolver'
import { contexts as credential_contexts } from '@transmute/credentials-context'
import * as fs from 'fs'
import { jest } from '@jest/globals'

// Shared tests
import verifiableDataJWT from './shared/verifiableDataJWT'
import verifiableDataLD from './shared/verifiableDataLD'
Expand Down
3 changes: 2 additions & 1 deletion __tests__/restAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* This suite also runs a messaging server to run through some examples of DIDComm using did:fake identifiers.
* See didWithFakeDidFlow() for more details.
*/
import 'cross-fetch/polyfill'
import {
Agent,
createAgent,
Expand Down Expand Up @@ -77,6 +76,8 @@ import express from 'express'
import { Server } from 'http'
import { contexts as credential_contexts } from '@transmute/credentials-context'
import * as fs from 'fs'
import { jest } from '@jest/globals'

// Shared tests
import verifiableDataJWT from './shared/verifiableDataJWT'
import verifiableDataLD from './shared/verifiableDataLD'
Expand Down
1 change: 1 addition & 0 deletions __tests__/shared/credentialStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
TAgent,
} from '../../packages/core/src'
import { CredentialStatusPlugin } from '../../packages/credential-status/src'
import { jest } from '@jest/globals'

type ConfiguredAgent = TAgent<IDIDManager & ICredentialPlugin & IDataStore & IDataStoreORM>

Expand Down
31 changes: 16 additions & 15 deletions __tests__/shared/didCommAndDataStoreWithCredentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ import {
TAgent,
} from '../../packages/core/src'
import { IDIDComm, IPackedDIDCommMessage } from '../../packages/did-comm/src'
import { v4 } from "uuid"
import { v4 } from 'uuid'
import { VerifiableCredential } from '../../packages/core/src'
import { jest } from '@jest/globals'

type ConfiguredAgent = TAgent<IDIDManager & IKeyManager & IResolver & IDIDComm>

const DIDCommEventSniffer: IEventListener = {
eventTypes: ['DIDCommV2Message-sent', 'DIDCommV2Message-received'],
onEvent: jest.fn(),
onEvent: jest.fn(() => Promise.resolve()),
}

export default (testContext: {
Expand Down Expand Up @@ -129,18 +130,21 @@ export default (testContext: {
}

const packed = (vc: VerifiableCredential): Promise<IPackedDIDCommMessage> => {
return agent.packDIDCommMessage({ packing: 'none', message: {
id: v4(),
type: 'w3c.vc',
from: sender.did,
to: receiver.did,
body: vc
}})
return agent.packDIDCommMessage({
packing: 'none',
message: {
id: v4(),
type: 'w3c.vc',
from: sender.did,
to: receiver.did,
body: vc,
},
})
}

it('should save LDS credential found inside DIDCommMessage', async () => {
expect.assertions(2)
const creator = await agent.didManagerGetOrCreate({ alias: 'messageCreator1', provider: 'did:ethr'})
const creator = await agent.didManagerGetOrCreate({ alias: 'messageCreator1', provider: 'did:ethr' })

const numMessagesBefore = await agent.dataStoreORMGetMessagesCount({})
const numVCsBefore = await agent.dataStoreORMGetVerifiableCredentialsCount({})
Expand All @@ -161,8 +165,7 @@ export default (testContext: {

it('should save JWT credential found inside DIDCommMessage', async () => {
expect.assertions(2)
const creator = await agent.didManagerGetOrCreate({ alias: 'messageCreator1', provider: 'did:ethr'})

const creator = await agent.didManagerGetOrCreate({ alias: 'messageCreator1', provider: 'did:ethr' })
const numMessagesBefore = await agent.dataStoreORMGetMessagesCount({})
const numVCsBefore = await agent.dataStoreORMGetVerifiableCredentialsCount({})

Expand All @@ -180,11 +183,9 @@ export default (testContext: {
expect(vcs).toEqual(numVCsBefore + 1)
})


it('should save JWT credential found inside DIDCommMessage', async () => {
expect.assertions(2)
const creator = await agent.didManagerGetOrCreate({ alias: 'messageCreator1', provider: 'did:ethr'})

const creator = await agent.didManagerGetOrCreate({ alias: 'messageCreator1', provider: 'did:ethr' })
const numMessagesBefore = await agent.dataStoreORMGetMessagesCount({})
const numVCsBefore = await agent.dataStoreORMGetVerifiableCredentialsCount({})

Expand Down
11 changes: 6 additions & 5 deletions __tests__/shared/didCommWithEthrDidFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ import {
} from '../../packages/core/src'
import { IDIDComm } from '../../packages/did-comm/src'
import { MessagingRouter, RequestWithAgentRouter } from '../../packages/remote-server/src'
import * as u8a from 'uint8arrays'
// @ts-ignore
import express from 'express'
import { Server } from 'http'
import { jest } from '@jest/globals'
import { bytesToBase58, hexToBytes } from '../../packages/utils/src'

type ConfiguredAgent = TAgent<IDIDManager & IKeyManager & IResolver & IDIDComm & IMessageHandler>

const DIDCommEventSniffer: IEventListener = {
eventTypes: ['DIDCommV2Message-sent', 'DIDCommV2Message-received'],
onEvent: jest.fn(),
onEvent: jest.fn(() => Promise.resolve()),
}

export default (testContext: {
Expand Down Expand Up @@ -585,9 +586,9 @@ export default (testContext: {
key: newKey,
})

expect(result.substr(0, 2)).toEqual('0x')
expect(result.substring(0, 2)).toEqual('0x')
const resolution = await agent.resolveDid({ didUrl: alice.did })
const expectedBase58Key = u8a.toString(u8a.fromString(newKey.publicKeyHex, 'base16'), 'base58btc')
const expectedBase58Key = bytesToBase58(hexToBytes(newKey.publicKeyHex))
expect(resolution?.didDocument?.verificationMethod?.[2].publicKeyBase58).toEqual(expectedBase58Key)
expect(resolution?.didDocument?.keyAgreement?.[0]).toEqual(
resolution?.didDocument?.verificationMethod?.[2].id,
Expand Down Expand Up @@ -692,7 +693,7 @@ export default (testContext: {

expect(result.substr(0, 2)).toEqual('0x')
const resolution = await agent.resolveDid({ didUrl: bob.did })
const expectedBase58Key = u8a.toString(u8a.fromString(newKey.publicKeyHex, 'base16'), 'base58btc')
const expectedBase58Key = bytesToBase58(hexToBytes(newKey.publicKeyHex))
expect(resolution?.didDocument?.verificationMethod?.[2].publicKeyBase58).toEqual(expectedBase58Key)
expect(resolution?.didDocument?.keyAgreement?.[0]).toEqual(
resolution?.didDocument?.verificationMethod?.[2].id,
Expand Down
3 changes: 2 additions & 1 deletion __tests__/shared/didCommWithFakeDidFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import {
TAgent,
} from '../../packages/core/src'
import { IDIDComm } from '../../packages/did-comm/src'
import { jest } from '@jest/globals'

type ConfiguredAgent = TAgent<IDIDManager & IKeyManager & IResolver & IDIDComm>

const DIDCommEventSniffer: IEventListener = {
eventTypes: ['DIDCommV2Message-sent', 'DIDCommV2Message-received'],
onEvent: jest.fn(),
onEvent: jest.fn(() => Promise.resolve()),
}

export default (testContext: {
Expand Down
5 changes: 2 additions & 3 deletions __tests__/utils/ganache-provider.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Web3Provider } from '@ethersproject/providers'
import { Contract, ContractFactory } from '@ethersproject/contracts'
// @ts-ignore
import DidRegistryContract from 'ethr-did-registry'
import { EthereumDIDRegistry } from 'ethr-did-resolver'
import ganache from 'ganache'

/**
Expand Down Expand Up @@ -58,7 +57,7 @@ export async function createGanacheProvider(): Promise<{ provider: Web3Provider;
}) as any
)
await provider.ready
const factory = ContractFactory.fromSolidity(DidRegistryContract).connect(provider.getSigner(0))
const factory = ContractFactory.fromSolidity(EthereumDIDRegistry).connect(provider.getSigner(0))

let registryContract: Contract = await factory.deploy()
registryContract = await registryContract.deployed()
Expand Down
46 changes: 33 additions & 13 deletions jest.config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
{
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "jsonld"],
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"jsonld"
],
"collectCoverage": false,
"collectCoverageFrom": [
"packages/**/src/**/*.ts",
Expand All @@ -9,19 +16,32 @@
"!**/build/**",
"!**/node_modules/**"
],
"coverageReporters": ["text", "lcov", "json"],
"coverageReporters": [
"text",
"lcov",
"json"
],
"coverageProvider": "v8",
"coverageDirectory": "./coverage",
"transform": {
"\\.jsx?$": "babel-jest",
"\\.tsx?$": "ts-jest"
},
"testMatch": ["**/__tests__/**/*.test.*"],
"globals": {
"ts-jest": {
"tsconfig": "./packages/tsconfig.settings.json"
}
},
"extensionsToTreatAsEsm": [".ts"],
"testMatch": [
"**/__tests__/**/*.test.*"
],
"testEnvironment": "node",
"automock": false,
"setupFiles": ["./setupJest.js"]
"setupFiles": [
"./setupJest.js"
],
"moduleNameMapper": {
"^(\\.{1,2}/.*)\\.js$": "$1"
},
"transform": {
"^.+\\.m?tsx?$": [
"ts-jest",
{
"useESM": true,
"tsconfig": "./packages/tsconfig.settings.json"
}
]
}
}
6 changes: 2 additions & 4 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"version": "4.3.0",
"packages": [
"packages/*"
],
"npmClient": "pnpm",
"changelog": {
"repo": "uport-project/veramo",
Expand All @@ -13,7 +10,8 @@
"allowBranch": [
"main",
"next",
"master"
"master",
"unstable"
],
"conventionalCommits": true,
"gitRemote": "origin",
Expand Down
Loading

0 comments on commit b5cea3c

Please sign in to comment.