Skip to content

Commit

Permalink
added ESM build to SDK packages. (#1027)
Browse files Browse the repository at this point in the history
* added ESM build to base packages.
  • Loading branch information
b4rtaz authored Mar 10, 2023
1 parent ab1be10 commit 521534f
Show file tree
Hide file tree
Showing 85 changed files with 1,458 additions and 297 deletions.
18 changes: 18 additions & 0 deletions .changeset/eight-owls-eat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
'@moralisweb3/common-streams-utils': patch
'@moralisweb3/common-aptos-utils': patch
'@moralisweb3/common-auth-utils': patch
'@moralisweb3/common-evm-utils': patch
'@moralisweb3/common-sol-utils': patch
'@moralisweb3/common-core': patch
'@moralisweb3/api-utils': patch
'@moralisweb3/evm-utils': patch
'@moralisweb3/sol-utils': patch
'@moralisweb3/streams': patch
'@moralisweb3/evm-api': patch
'@moralisweb3/sol-api': patch
'@moralisweb3/auth': patch
'@moralisweb3/moralis': patch
---

Added ESM build.
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,5 @@ jobs:
streams, ./packages/streams/coverage/coverage-summary.json
- name: Find missing dependencies
run: node scripts/findMissingDependencies.js
- name: Find invalid exports
run: node scripts/findInvalidExports.js
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ yarn-error.log
packages/**/build
packages/**/dist
packages/**/lib
packages/**/lib.esm
packages/**/coverage
coverage/

Expand Down
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ README.md

# Output folders
packages/**/lib/**/*
packages/**/build/**/*
dist
coverage/
lib.esm

# Generated files
packages/**/generated/**/*
Expand All @@ -14,6 +14,7 @@ packages/core/src/version.ts
**/src/operations/openapi.ts

node_modules
.yarn/
.yarnrc.yml

# Demos
Expand Down
15 changes: 15 additions & 0 deletions demos/cli-common-js/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const Moralis = require('moralis').default;

Moralis.start({
apiKey: 'REPLACE_ME',
});

console.log(typeof Moralis.Auth);
console.log(typeof Moralis.Core);
console.log(typeof Moralis.EvmApi);
console.log(typeof Moralis.EvmUtils);
console.log(typeof Moralis.SolApi);
console.log(typeof Moralis.SolUtils);
console.log(typeof Moralis.start);

console.log('Done! 🦋');
12 changes: 12 additions & 0 deletions demos/cli-common-js/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "demo-cli-common-js",
"author": "Moralis",
"private": true,
"version": "1.0.0",
"scripts": {
"start": "node index.js"
},
"dependencies": {
"moralis": "^2.14.3"
}
}
15 changes: 15 additions & 0 deletions demos/cli-esm-js/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Moralis from 'moralis';

Moralis.start({
apiKey: 'REPLACE_ME',
});

console.log(typeof Moralis.Auth);
console.log(typeof Moralis.Core);
console.log(typeof Moralis.EvmApi);
console.log(typeof Moralis.EvmUtils);
console.log(typeof Moralis.SolApi);
console.log(typeof Moralis.SolUtils);
console.log(typeof Moralis.start);

console.log('Done! 🐝');
13 changes: 13 additions & 0 deletions demos/cli-esm-js/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "demo-cli-esm-js",
"author": "Moralis",
"private": true,
"version": "1.0.0",
"type": "module",
"scripts": {
"start": "node index.js"
},
"dependencies": {
"moralis": "^2.14.3"
}
}
6 changes: 6 additions & 0 deletions demos/client-webpack/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ module.exports = {
entry: './src/main.ts',
module: {
rules: [
{
test: /\.m?js/,
resolve: {
fullySpecified: false,
},
},
{
test: /\.ts?$/,
use: 'ts-loader',
Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = {
'^@moralisweb3/common-streams-utils': path.join(__dirname, 'packages/common/streamsUtils/src'),
'^@moralisweb3/common-auth-utils': path.join(__dirname, 'packages/common/authUtils/src'),
'^@moralisweb3/common-core': path.join(__dirname, 'packages/common/core/src'),
'^@create-moralis-dapp/toolkit': path.join(__dirname, 'packages/create-moralis-dapp/toolkit/src'),
'^@moralisweb3/(.*)$': path.join(__dirname, 'packages/$1/src'),
},
modulePaths: ['<rootDir>'],
Expand Down
File renamed without changes.
34 changes: 27 additions & 7 deletions packages/apiUtils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,50 @@
"author": "Moralis",
"version": "2.14.3",
"license": "MIT",
"main": "./lib/index.js",
"type": "module",
"main": "./lib/esm/index.js",
"types": "./lib/index.d.ts",
"typings": "./lib/index.d.ts",
"exports": {
".": {
"types": {
"default": "./lib/index.d.ts"
},
"default": {
"require": "./lib/cjs/index.cjs",
"default": "./lib/esm/index.js"
}
}
},
"files": [
"lib/*"
],
"sideEffects": false,
"moralis": {
"name": "Api Utilities",
"type": "utils",
"scope": "server",
"description": "Utilities and types to handle logic for api calls"
},
"files": [
"lib/*"
],
"scripts": {
"test": "jest --runInBand --detectOpenHandles --forceExit --ci",
"test:coverage": "yarn run test --coverage",
"test:watch": "yarn run test --watch",
"lint": "eslint . --ext .js,.ts,.tsx,jsx",
"clean": "rm -rf lib && rm -rf tsconfig.tsbuildinfo && rm -rf tsconfig.build.tsbuildinfo && rm -rf ./node_modules/.cache/nx",
"build": "tsc",
"clean": "rm -rf lib && rm -rf ./node_modules/.cache/nx",
"build": "rollup -c",
"dev": "tsc --watch"
},
"devDependencies": {
"@moralisweb3/common-evm-utils": "^2.14.3",
"jest": "29.3.1"
"@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-node-resolve": "^15.0.1",
"jest": "29.3.1",
"rollup": "^3.10.1",
"rollup-plugin-cleaner": "^1.0.0",
"rollup-plugin-dts": "^5.2.0",
"rollup-plugin-node-polyfills": "^0.2.1",
"rollup-plugin-typescript2": "^0.34.1"
},
"dependencies": {
"@moralisweb3/common-core": "^2.14.3",
Expand Down
4 changes: 0 additions & 4 deletions packages/apiUtils/rollup.config.js

This file was deleted.

46 changes: 46 additions & 0 deletions packages/apiUtils/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import typescript from 'rollup-plugin-typescript2';
import cleaner from 'rollup-plugin-cleaner';
import dts from 'rollup-plugin-dts';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import fs from 'fs';

const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
const external = Object.keys(packageJson.dependencies);

export default [
{
input: './src/index.ts',
plugins: [
cleaner({
targets: ['./lib'],
}),
typescript({
useTsconfigDeclarationDir: true,
}),
nodeResolve(),
],
cache: false,
external,
output: [
{
file: './lib/cjs/index.cjs',
format: 'cjs',
exports: 'named',
},
{
file: './lib/esm/index.js',
format: 'esm',
},
],
},
{
input: './build/index.d.ts',
output: [
{
file: './lib/index.d.ts',
format: 'es',
},
],
plugins: [dts()],
},
];
4 changes: 2 additions & 2 deletions packages/apiUtils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"extends": "../../tsconfig.package.json",
"compilerOptions": {
"outDir": "./lib/",
"declarationDir": "./lib/",
"outDir": "./build",
"declarationDir": "./build",
"rootDir": "./src"
},
"include": ["src/**/*", "types/**/*"]
Expand Down
File renamed without changes.
34 changes: 27 additions & 7 deletions packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,50 @@
"author": "Moralis",
"version": "2.14.3",
"license": "MIT",
"main": "./lib/index.js",
"type": "module",
"main": "./lib/esm/index.js",
"types": "./lib/index.d.ts",
"typings": "./lib/index.d.ts",
"exports": {
".": {
"types": {
"default": "./lib/index.d.ts"
},
"default": {
"require": "./lib/cjs/index.cjs",
"default": "./lib/esm/index.js"
}
}
},
"files": [
"lib/*"
],
"sideEffects": false,
"moralis": {
"name": "Auth",
"type": "feature",
"scope": "server",
"description": "Authenticate via web3"
},
"files": [
"lib/*"
],
"scripts": {
"test": "jest --runInBand --detectOpenHandles --forceExit --ci",
"test:coverage": "yarn run test --coverage --coverageReporters json-summary",
"test:watch": "yarn run test --watch",
"lint": "eslint . --ext .js,.ts,.tsx,jsx",
"clean": "rm -rf lib && rm -rf tsconfig.tsbuildinfo && rm -rf tsconfig.build.tsbuildinfo && rm -rf ./node_modules/.cache/nx",
"build": "tsc -p tsconfig.build.json",
"clean": "rm -rf lib && rm -rf ./node_modules/.cache/nx",
"build": "rollup -c",
"dev": "tsc --watch"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-node-resolve": "^15.0.1",
"jest": "29.3.1",
"openapi-typescript": "^5.2.0"
"openapi-typescript": "^5.2.0",
"rollup": "^3.10.1",
"rollup-plugin-cleaner": "^1.0.0",
"rollup-plugin-dts": "^5.2.0",
"rollup-plugin-node-polyfills": "^0.2.1",
"rollup-plugin-typescript2": "^0.34.1"
},
"dependencies": {
"@moralisweb3/api-utils": "^2.14.3",
Expand Down
4 changes: 0 additions & 4 deletions packages/auth/rollup.config.js

This file was deleted.

46 changes: 46 additions & 0 deletions packages/auth/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import typescript from 'rollup-plugin-typescript2';
import cleaner from 'rollup-plugin-cleaner';
import dts from 'rollup-plugin-dts';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import fs from 'fs';

const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
const external = Object.keys(packageJson.dependencies);

export default [
{
input: './src/index.ts',
plugins: [
cleaner({
targets: ['./lib'],
}),
typescript({
useTsconfigDeclarationDir: true,
}),
nodeResolve(),
],
cache: false,
external,
output: [
{
file: './lib/cjs/index.cjs',
format: 'cjs',
exports: 'named',
},
{
file: './lib/esm/index.js',
format: 'esm',
},
],
},
{
input: './build/index.d.ts',
output: [
{
file: './lib/index.d.ts',
format: 'es',
},
],
plugins: [dts()],
},
];
9 changes: 0 additions & 9 deletions packages/auth/tsconfig.build.json

This file was deleted.

8 changes: 6 additions & 2 deletions packages/auth/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"extends": "../../tsconfig.package.json",
"compilerOptions": {},
"include": ["src/**/*", "types/**/*", "integration/**/*"]
"compilerOptions": {
"outDir": "./build",
"declarationDir": "./build",
"rootDir": "./src"
},
"include": ["src/**/*", "types/**/*"]
}
File renamed without changes.
Loading

1 comment on commit 521534f

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test coverage

Title Lines Statements Branches Functions
api-utils Coverage: 29%
29.95% (62/207) 32.78% (20/61) 30% (12/40)
auth Coverage: 90%
92.59% (100/108) 83.33% (20/24) 86.2% (25/29)
evm-api Coverage: 100%
100% (82/82) 66.66% (6/9) 100% (50/50)
common-aptos-utils Coverage: 75%
75.13% (142/189) 73.52% (25/34) 77.58% (45/58)
common-evm-utils Coverage: 64%
64.59% (987/1528) 20.02% (134/669) 35.21% (212/602)
sol-api Coverage: 96%
96.66% (29/30) 66.66% (6/9) 91.66% (11/12)
common-sol-utils Coverage: 74%
74.55% (167/224) 66.66% (18/27) 65.38% (51/78)
common-streams-utils Coverage: 91%
91.58% (1176/1284) 78.83% (406/515) 82.45% (423/513)
streams Coverage: 88%
87.81% (555/632) 65.88% (56/85) 87.59% (120/137)

Please sign in to comment.