Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add esbuild #3

Merged
merged 51 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
c98d2cb
Create network model
arhtudormorar Apr 18, 2024
de506b2
Create network model
arhtudormorar Apr 26, 2024
eb4f05c
Create combined store
arhtudormorar Apr 26, 2024
20ff774
Added immer
arhtudormorar Apr 26, 2024
610db62
merged stores
arhtudormorar Apr 26, 2024
aa430e2
Not working immer
arhtudormorar Apr 27, 2024
9d0716b
Return to working version
arhtudormorar Apr 27, 2024
b0b7c40
Immer working
arhtudormorar Apr 27, 2024
95c6218
Network full state definition
arhtudormorar Apr 27, 2024
11fd7c9
Build store working
arhtudormorar Apr 27, 2024
5e0de1d
try refactor network
arhtudormorar Apr 29, 2024
37909e9
Export react store working
arhtudormorar Apr 29, 2024
b511bfa
Logger and shared slices working
arhtudormorar Apr 30, 2024
f437b49
Custom Events working
arhtudormorar Apr 30, 2024
81e38d3
Add logout to network
arhtudormorar Apr 30, 2024
393f817
Minor renamings
arhtudormorar Apr 30, 2024
56bc80c
Renamed models to slices
arhtudormorar Apr 30, 2024
eb0ceff
Migrate network related functions
arhtudormorar May 1, 2024
06299d7
Added absolute imports
arhtudormorar May 1, 2024
dd47fa2
Added storage
arhtudormorar May 1, 2024
6ff06d6
Added next tsconfig
arhtudormorar May 1, 2024
5ed8009
Fixed alpha
arhtudormorar May 1, 2024
2953489
0.0.1-alpha.0
arhtudormorar May 1, 2024
8e5d9fc
Revert 0
arhtudormorar May 1, 2024
30e4737
Revert 0
arhtudormorar May 1, 2024
5012314
0.0.0-alpha.0
arhtudormorar May 1, 2024
9588af4
Added github actions
arhtudormorar May 1, 2024
78295a0
Update changelog
arhtudormorar May 1, 2024
bcff059
Add eslint
arhtudormorar May 1, 2024
3116686
Add eslint
arhtudormorar May 1, 2024
c2f09a9
try verdaccio
arhtudormorar May 1, 2024
d49e690
Revert absolute imports
arhtudormorar May 1, 2024
a466fb8
Add jest
arhtudormorar May 1, 2024
6e01b2d
Merge main
arhtudormorar May 1, 2024
6d7b480
revert version
arhtudormorar May 1, 2024
832df2e
Update CHANGELOG
arhtudormorar May 1, 2024
ba4ddb6
Remove verdaccio publish
arhtudormorar May 1, 2024
0310d20
Update eslint
arhtudormorar May 2, 2024
72ec4fb
Try absolute imports
arhtudormorar May 2, 2024
5ee92a9
Revert absolute imports
arhtudormorar May 2, 2024
5f267c1
updated changelog
arhtudormorar May 2, 2024
8f0dbe7
0.0.0-alpha.1
arhtudormorar May 2, 2024
7a51cf3
Merge branch 'main' into tm/add/network
arhtudormorar May 2, 2024
b5e88ae
Removed unused chain id
arhtudormorar May 3, 2024
411afca
Esbuild working
arhtudormorar May 8, 2024
dc6fe0a
Work on esbuild
arhtudormorar May 8, 2024
893b790
Work on esbuild
arhtudormorar May 11, 2024
1f33166
Work on esbuild
arhtudormorar May 11, 2024
6aa4d09
Esbuild & tsc & tsc-alias workgin with absolute paths
arhtudormorar May 11, 2024
35c63da
Cleaned esbuild working
arhtudormorar May 13, 2024
8bf8c8e
Update CHANGELOG
arhtudormorar May 13, 2024
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
81 changes: 0 additions & 81 deletions .eslintrc

This file was deleted.

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- [Removed chain id from network slice & added esbuild and absolute imports](https://github.com/multiversx/mx-sdk-dapp-core/pull/3)
- [Reverted absolute imports](https://github.com/multiversx/mx-sdk-dapp-core/pull/2)
- [Added network store](https://github.com/multiversx/mx-sdk-dapp-core/pull/1)

Expand Down
50 changes: 50 additions & 0 deletions esbuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const esbuild = require('esbuild');
const glob = require('glob');

/*
The reason why we use esbuild instead of tsc is because esbuild can output .mjs files
*/

const filesToInclude = ['./src/**/*.ts'].join(',');

const allFiles = glob.sync(filesToInclude);

const files = allFiles.filter((file) => {
const hasTestFiles = file.includes('/tests/') || file.includes('/stories/');
return !hasTestFiles;
});

const executeBuild = () =>
esbuild
.build({
entryPoints: files,
splitting: true,
format: 'esm',
outdir: 'out',
treeShaking: true,
minify: true,
bundle: true,
sourcemap: true,
chunkNames: '__chunks__/[name]-[hash]',
target: ['es2021'],
outExtension: { '.js': '.mjs' },
tsconfig: './tsconfig.json',
platform: 'node',
define: {
global: 'global',
process: 'process',
Buffer: 'Buffer'
}
})
.then(() => {
console.log(
'\x1b[36m%s\x1b[0m',
`[${new Date().toLocaleTimeString()}] sdk-dapp-core build succeeded for esm types`
);
})
.catch((err) => {
console.log(11, err);
process.exit(1);
});

executeBuild();
89 changes: 89 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
[
{
env: {
es2021: true,
node: true
},
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2021,
sourceType: 'module',
ecmaFeatures: {
jsx: true
},
project: './tsconfig.json'
},
settings: {
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx']
},
'import/resolver': {
node: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
moduleDirectory: ['node_modules', 'src/']
},
typescript: {
alwaysTryTypes: true
}
}
},
extends: [
'plugin:@typescript-eslint/recommended',
'prettier',
'plugin:prettier/recommended'
],
plugins: ['prettier', 'import'],
rules: {
'import/order': [
'warn',
{
groups: ['builtin', 'external', 'internal'],
pathGroups: [
{
pattern: 'react',
group: 'external',
position: 'before'
}
],
'newlines-between': 'ignore',
alphabetize: {
order: 'asc',
caseInsensitive: true
}
}
],
'prettier/prettier': [
'error',
{
endOfLine: 'lf'
}
],
'@typescript-eslint/indent': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-use-before-define': [
'error',
{ functions: false, classes: false }
],
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{ argsIgnorePattern: '^_' }
],
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'linebreak-style': ['error', 'unix'],
quotes: ['error', 'single'],
semi: ['error', 'always'],
'object-curly-newline': 'off',
'arrow-body-style': 'off',
'implicit-arrow-linebreak': 'off',
'func-names': 'off',
curly: ['error', 'all'],
'operator-linebreak': 'off',
'function-paren-newline': 'off',
'no-shadow': 'off',
'@typescript-eslint/no-shadow': 'off'
}
}
];
52 changes: 32 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "@multiversx/sdk-dapp-core",
"version": "0.0.0-alpha.0",
"version": "0.0.0-alpha.1",
"main": "out/index.js",
"module": "out/index.js",
"module": "out/index.mjs",
"types": "out/index.d.ts",
"description": "A library to hold core logic for building TypeScript dApps on the MultiversX blockchain",
"author": "MultiversX",
Expand All @@ -19,9 +19,11 @@
"url": "git+https://github.com/multiversx/mx-sdk-dapp-core.git"
},
"scripts": {
"compile": "tsc",
"test": "jest",
"compile-next": "tsc --p tsconfig.next.json"
"compile": "tsc && tsc-alias",
"compile-next": "rimraf out && tsc --p tsconfig.next.json && tsc-alias --project tsconfig.next.json",
"build-esbuild": "rimraf out && node esbuild.js",
"build": "yarn build-esbuild && yarn compile",
"test": "jest"
},
"publishConfig": {
"access": "public"
Expand All @@ -31,29 +33,39 @@
"zustand": "^4.4.7"
},
"peerDependencies": {
"@multiversx/sdk-dapp-utils": "^0.0.1",
"@multiversx/sdk-core": ">= 12.18.0",
"axios": ">=1.6.5"
},
"devDependencies": {
"@multiversx/sdk-dapp-utils": "^0.0.1",
"@multiversx/sdk-core": ">= 12.18.0",
"@swc/core": "^1.4.17",
"@swc/jest": "^0.2.36",
"@types/node": "18.19.0",
"@typescript-eslint/eslint-plugin": "5.0.0",
"@typescript-eslint/parser": "5.14.0",
"@types/node": "20.12.8",
"@typescript-eslint/eslint-plugin": "7.8.0",
"@typescript-eslint/parser": "7.8.0",
"axios": ">=1.6.5",
"eslint": "8.1.0",
"eslint-config-prettier": "8.5.0",
"eslint-config-standard": "17.0.0",
"eslint-import-resolver-typescript": "2.4.0",
"eslint-plugin-import": "2.26.0",
"esbuild": "^0.21.1",
"eslint": "9.1.1",
"eslint-config-prettier": "9.1.0",
"eslint-config-standard": "17.1.0",
"eslint-import-resolver-typescript": "3.6.1",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-prettier": "5.0.0",
"eslint-plugin-promise": "6.0.0",
"jest": "29.6.2",
"jest-environment-jsdom": "28.1.3",
"prettier": "3.1.0",
"ts-jest": "29.1.1",
"typescript": "^5.4.2"
"eslint-plugin-prettier": "5.1.3",
"eslint-plugin-promise": "6.1.1",
"glob": "^10.3.14",
"immer": "^10.1.1",
"jest": "29.7.0",
"jest-environment-jsdom": "29.7.0",
"lit": "^3.1.3",
"prettier": "3.2.5",
"protobufjs": "^7.3.0",
"react": "^18.3.1",
"rimraf": "^5.0.6",
"ts-jest": "29.1.2",
"tsc-alias": "^1.8.9",
"typescript": "^5.4.5"
}
}
2 changes: 1 addition & 1 deletion src/apiCalls/configuration/getNetworkConfigFromApi.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import axios from 'axios';
import { getCleanApiAddress } from '../../store/slices/network/actions/getCleanApiAddress';
import { getCleanApiAddress } from 'store/slices/network/actions/getCleanApiAddress';
import { ApiNetworkConfigType } from '../../types/network.types';
import { NETWORK_CONFIG_ENDPOINT } from '../endpoints';

Expand Down
2 changes: 2 additions & 0 deletions src/apiCalls/configuration/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './getServerConfiguration';
export * from './getNetworkConfigFromApi';
2 changes: 2 additions & 0 deletions src/apiCalls/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './configuration';
export * from './endpoints';
3 changes: 3 additions & 0 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './network';
export * from './storage';
export * from './window';
2 changes: 1 addition & 1 deletion src/constants/storage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createJSONStorage } from 'zustand/middleware';
import { safeWindow } from './window';

const persistConfig: {
export const persistConfig: {
persistReducersStorageType: 'localStorage' | 'sessionStorage';
} = {
persistReducersStorageType: 'localStorage'
Expand Down
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export * from './core';
export * from './constants';
export * from './apiCalls';
export * from './store';
export * from './types';
2 changes: 2 additions & 0 deletions src/store/actions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './constants';
export * from './sharedActions';
6 changes: 4 additions & 2 deletions src/store/helpers/eventHandlers.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { safeWindow } from '../../constants/window';

export function createCustomEvent<T>(eventName: string, eventData: T) {
const event = new CustomEvent(eventName, { detail: eventData });
document.dispatchEvent(event);
safeWindow?.document.dispatchEvent(event);
}

// Function to listen to the custom event
export function listenToCustomEvent<T>(
eventName: string,
callback: (event: CustomEvent<T>) => void
) {
document.addEventListener(eventName, (evt) => {
safeWindow?.document.addEventListener(eventName, (evt) => {
callback(evt as CustomEvent<T>);
});
}
2 changes: 2 additions & 0 deletions src/store/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './actions';
export * from './slices';
6 changes: 3 additions & 3 deletions src/store/slices/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const handleLogout = listenToLogout((state: StateType) => {
});

// vanilla store
export const store = createStore<StateType>()(
export const accountStore = createStore<StateType>()(
devtools(
persist(
immer((...a) => ({
Expand All @@ -53,7 +53,7 @@ export const store = createStore<StateType>()(
);

// react store
export const useStore = getReactStore({
export const useAccountStore = getReactStore({
initialState,
store
store: accountStore
});
2 changes: 2 additions & 0 deletions src/store/slices/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './network';
export * from './account';
Loading