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

chore: [DX-2673] - use nx to speed up builds #1699

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .github/workflows/build-lint-typecheck-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
run: yarn syncpack:check

- name: Build
run: yarn build
run: yarn bootstrap && yarn nx build @imtbl/sdk

- name: Typecheck
run: yarn typecheck
Expand Down Expand Up @@ -60,7 +60,7 @@ jobs:
run: yarn install --immutable

- name: Build
run: yarn build
run: yarn bootstrap && yarn nx build @imtbl/sdk

- name: Test
run: yarn test
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ yalc.lock
package-lock.json

docs/


.nx/cache
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ To test this SDK locally, you can:
yarn

# Build
yarn build
yarn bootstrap && yarn nx build @imtbl/sdk

# Runs all tests, but skip the ones that require a VPN
yarn test
Expand Down
18 changes: 18 additions & 0 deletions nx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "./node_modules/nx/schemas/nx-schema.json",
"defaultBase": "main",
"targetDefaults": {
"build": {
"cache": true
}
},
"plugins": [
{
"plugin": "@nx/rollup/plugin",
"options": {
"buildTargetName": "build"
}
}
],
"nxCloudAccessToken": "Y2Q5NmEyMjUtMmJmNC00YjQyLTkyODMtNDM5Y2IzMGU3ZDdjfHJlYWQtd3JpdGU="
}
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"devDependencies": {
"@actions/core": "^1.10.1",
"@emotion/react": "^11.11.3",
"@nx/rollup": "18.3.1",
"@release-it-plugins/workspaces": "^4.0.0",
"@rollup/plugin-json": "^6.1.0",
"@typescript-eslint/eslint-plugin": "^5.57.1",
"@typescript-eslint/parser": "^5.57.1",
"eslint": "^8.40.0",
Expand All @@ -20,6 +22,7 @@
"husky": "^8.0.3",
"lint-staged": "^13.2.0",
"node-gyp": "^9.3.1",
"nx": "18.3.1",
"release-it": "^16.1.3",
"syncpack": "^9.8.4",
"typedoc": "^0.24.8",
Expand All @@ -41,13 +44,15 @@
"responselike": "^2.0.0"
},
"scripts": {
"bootstrap": "test -f sdk/workspace-packages.json || yarn prepare",
"build": "NODE_OPTIONS=--max-old-space-size=14366 wsrun -y 4 -p @imtbl/sdk -p @imtbl/checkout-widgets -e -r --serial build && yarn syncpack:format && yarn wsrun -p @imtbl/sdk -a -m copyBrowserBundles",
"build:onlysdk": "NODE_OPTIONS=--max-old-space-size=14366 wsrun -y 4 -p @imtbl/sdk --stages build && yarn syncpack:format",
"docs:build": "typedoc",
"docs:serve": "http-server ./docs --cors -p 8080 -c-1",
"lint": "wsrun --exclude-missing -e lint --no-error-on-unmatched-pattern",
"lint:ci": "./lint-ci.sh",
"postinstall": "husky install; ./.husky/install_gitleaks.sh",
"prepare": "cd sdk && yarn bootstrap",
"release": "release-it",
"scan:secrets": "./.husky/run_gitleaks.sh",
"syncpack:check": "yarn syncpack list-mismatches",
Expand Down
2 changes: 1 addition & 1 deletion packages/checkout/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@parcel/packager-ts": "^2.8.3",
"@parcel/transformer-typescript-types": "^2.8.3",
"@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.0.2",
"@rollup/plugin-replace": "^5.0.2",
"@rollup/plugin-terser": "^0.4.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/checkout/widgets-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
},
"devDependencies": {
"@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.0.2",
"@rollup/plugin-replace": "^5.0.2",
"@rollup/plugin-terser": "^0.4.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/internal/bridge/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"devDependencies": {
"@ethersproject/providers": "^5.7.2",
"@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.0.2",
"@rollup/plugin-replace": "^5.0.2",
"@rollup/plugin-typescript": "^11.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/internal/dex/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"ethers": "^5.7.2"
},
"devDependencies": {
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-json": "^6.1.0",
"@swc/core": "^1.3.36",
"@swc/jest": "^0.2.24",
"@typechain/ethers-v5": "^10.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/internal/factory/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"devDependencies": {
"@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.0.2",
"@rollup/plugin-typescript": "^11.0.0",
"@swc/core": "^1.3.36",
Expand Down
2 changes: 1 addition & 1 deletion packages/internal/guardian/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"axios": "^1.6.5"
},
"devDependencies": {
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-json": "^6.1.0",
"@swc/core": "^1.3.36",
"@swc/jest": "^0.2.24",
"@typechain/ethers-v5": "^10.2.0",
Expand Down
1 change: 1 addition & 0 deletions packages/internal/version-check/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"axios": "^1.6.5"
},
"devDependencies": {
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-typescript": "^11.0.0",
"@swc/jest": "^0.2.24",
"@types/jest": "^29.4.3",
Expand Down
6 changes: 5 additions & 1 deletion packages/internal/version-check/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import typescript from '@rollup/plugin-typescript';
import replace from '@rollup/plugin-replace';
import pkg from '../../../sdk/package.json' assert { type: 'json' };
import json from '@rollup/plugin-json';
import {readFileSync} from 'fs';

const pkg = JSON.parse(readFileSync(new URL('../../../sdk/package.json', import.meta.url), 'utf8'));

export default {
input: 'src/index.ts',
Expand All @@ -9,6 +12,7 @@ export default {
format: 'es',
},
plugins: [
json(),
typescript(),
replace({
exclude: 'node_modules/**',
Expand Down
5 changes: 3 additions & 2 deletions sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"@imtbl/x-provider": "0.0.0",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.0.2",
"@rollup/plugin-replace": "^5.0.2",
"@rollup/plugin-terser": "^0.4.3",
Expand Down Expand Up @@ -141,7 +141,8 @@
"@openzeppelin/contracts": "3.4.2-solc-0.7"
},
"scripts": {
"build": "yarn packageList && yarn updateDependencies && yarn regenModules && rm -rf dist && NODE_ENV=production node --max-old-space-size=8192 ../node_modules/rollup/dist/bin/rollup --config rollup.config.js && rm -rf dist/types",
"bootstrap": "yarn packageList && yarn updateDependencies && yarn regenModules",
"build": "yarn bootstrap && rm -rf dist && NODE_ENV=production node --max-old-space-size=8192 ../node_modules/rollup/dist/bin/rollup --config rollup.config.js && rm -rf dist/types",
"build:only": "rm -rf dist && NODE_ENV=production node --max-old-space-size=8192 ../node_modules/rollup/dist/bin/rollup --config rollup.config.js && rm -rf dist/types",
"copyBrowserBundles": "node scripts/copyBrowserBundles.js",
"generateIndex": "node scripts/generateIndex.js",
Expand Down
35 changes: 35 additions & 0 deletions sdk/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"targets": {
"build": {
"cache": {
"enabled": true
},
"dependsOn": [
{
"projects": [
"@imtbl/blockchain-data",
"@imtbl/bridge-sdk",
"@imtbl/checkout-sdk",
"@imtbl/config",
"@imtbl/cryptofiat",
"@imtbl/dex-sdk",
"@imtbl/factory-sdk",
"@imtbl/game-bridge",
"@imtbl/generated-clients",
"@imtbl/guardian",
"@imtbl/metrics",
"@imtbl/orderbook",
"@imtbl/passport",
"@imtbl/toolkit",
"@imtbl/version-check",
"@imtbl/x-client",
"@imtbl/x-provider"
],
"target": "build",
"params": "ignore"
}
]
}
},
"name": "@imtbl/sdk"
}
23 changes: 17 additions & 6 deletions sdk/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
import typescript from '@rollup/plugin-typescript';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import { readFileSync } from 'fs';
import { readFileSync, existsSync } from 'fs';
import commonJs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import dts from 'rollup-plugin-dts';
import replace from '@rollup/plugin-replace';
import pkg from './package.json' assert { type: 'json' };
import moduleReleases from './module-release.json' assert { type: 'json' };
// import moduleReleases from './module-release.json' assert { type: 'json' };
import terser from '@rollup/plugin-terser';
import nodePolyfills from 'rollup-plugin-polyfill-node';
import babel from '@rollup/plugin-babel';
import { exec } from 'child_process';

// RELEASE_TYPE environment variable is set by the CI/CD pipeline
const releaseType = process.env.RELEASE_TYPE || 'alpha';

const packages = JSON.parse(
readFileSync('./workspace-packages.json', { encoding: 'utf8' })
);
const pkg = JSON.parse(readFileSync(new URL('package.json', import.meta.url), 'utf8'));
const moduleReleases = JSON.parse(readFileSync(new URL('module-release.json', import.meta.url), 'utf8'));

const workspacePackages = new URL('workspace-packages.json', import.meta.url);
let packages;
if (!existsSync(workspacePackages)) {
console.error('workspace-packages.json not found. Please run "yarn bootstrap" first');
} else {
packages = JSON.parse(readFileSync(workspacePackages, 'utf8'));
}

// Gets generated by: yarn packageList && yarn updateDependencies && yarn regenModules
// const packages = JSON.parse(readFileSync(workspacePackages, 'utf8'));


const getPackages = () => packages.map((pkg) => pkg.name);

Expand Down
Loading
Loading