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

feat: use composite builds to speed up compilation #692

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from
Open
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = {
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
project: './tsconfig.json',
project: './tsconfig.base.json',
},
plugins: [
'@typescript-eslint',
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/devpackpublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
PACKAGE_VERSION: ${{ steps.package_version.outputs.package_version }}
run: yarn set:version $PACKAGE_VERSION --allow-same-version
- name: Build packages
run: yarn run build
run: yarn run build:release
- name: Bundle library
run: yarn run bundle
- name: Publish to npm
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/npmpublish-rc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
with:
node-version: 14
- run: yarn install --immutable
- run: yarn build
- run: yarn build:release
- run: yarn test:ci

publish-npm:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/npmpublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
with:
node-version: 14
- run: yarn install --immutable
- run: yarn build
- run: yarn build:release
- run: yarn test:ci

publish-npm:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests-polkadot-deps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
yarn.lock

- name: yarn build
run: yarn build
run: yarn build:release
- name: zip build
run: zip -r build.zip .
- name: upload build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
- name: yarn install
run: yarn install --immutable
- name: yarn build
run: yarn build
run: yarn build:release
- name: zip build
run: zip -r build.zip .
- name: upload build
Expand Down
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@ lib
.env.test.local
.env.production.local
settings.json
tsconfig.tsbuildinfo

# doc
**/docs/api
/docs/api

# misc
/.idea
.vscode

# doc
/docs/api
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ WORKDIR /app
COPY . ./

RUN yarn install
RUN yarn build
RUN yarn build:release
RUN yarn lint
RUN yarn test
16 changes: 8 additions & 8 deletions babel.config.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"presets": [
[
"@babel/preset-env",
{
"modules": "commonjs"
}
]
"presets": [
[
"@babel/preset-env",
{
"modules": "commonjs"
}
]
}
]
}
12 changes: 11 additions & 1 deletion docs/contribution-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ We're using [typedoc][typedoc] to generate the API doc from the docBlocks.

### Documenting modules

Direct child folders of `src` such as `attestation` should be marked as `@modules`, so that they're listed in the [online API Doc][apidoc] main menu.
Direct child folders of `src` such as `attestation` should be marked as `@module`, so that they're listed in the [online API Doc][apidoc] main menu.

Some of these modules are purely technical utilities, such as `crypto`. Others map to KILT concepts, such as `attestation`.

Expand Down Expand Up @@ -72,6 +72,16 @@ If you have a doubt:

⚠️ Make sure you don't commit these generated files.

## Building and testing

For development purposes you can build the SDK from typescript sources by running `yarn build` in the root folder of the repository.
After switching branches of if you experience issues during building or testing it is recommended to run `yarn clean` before building to delete all build artifacts and thus force a fresh build.

Before packaging the SDK e.g. for release on npm, you must run `yarn build:release`, which not only forces a clean build but also produces ES6 modules code in addition to CJS output.
Building ESM code is skipped in `yarn build` to speed up the build/rebuild process.

When running jest in `--watch` mode, you should have `yarn build:watch` running in a separate terminal window to make sure file changes are immediately picked up an trigger a rebuild.

## Tests

Test coverage does not seem to be fail in all cases, except for testWatch.
Expand Down
19 changes: 11 additions & 8 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ module.exports = {
// Parachain block time is 12s
testTimeout: 15000,
setupFilesAfterEnv: ['../jest-setup/setup.js'],
transformIgnorePatterns: ['/node_modules/(?!@polkadot|@babel/runtime/helpers/esm/)'],
transformIgnorePatterns: [
'/node_modules/(?!@polkadot|@babel/runtime/helpers/esm/)',
],
coverageThreshold: {
global: {
branches: 70,
Expand All @@ -16,8 +18,8 @@ module.exports = {
},
},
transform: {
"\\.js$": "babel-jest",
"\\.ts$": "ts-jest"
'\\.js$': 'babel-jest',
'\\.ts$': 'ts-jest',
},
collectCoverageFrom: [
'**/*/src/**/*.ts',
Expand All @@ -40,11 +42,12 @@ module.exports = {
'!did/src/Did.utils.ts',
'!utils/src/jsonabc.ts',
],
resolver: "ts-jest-resolver",
resolver: 'ts-jest-resolver',
rootDir: 'packages',
coverageDirectory: 'coverage',
moduleDirectories: [
"node_modules",
"packages/*/src"
]
globals: {
'ts-jest': {
tsconfig: 'tsconfig.base.json',
},
},
}
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
{
"repository": "https://github.com/kiltprotocol/sdk-js",
"name": "root-workspace",
"private": true,
"workspaces": [
"packages/*",
"docs/*"
],
"license": "BSD-4-Clause",
"scripts": {
"check": "tsc -p tsconfig.json --noEmit",
"build": "yarn workspaces foreach -p -t --exclude '{root-workspace}' run build",
"check": "tsc -b tsconfig.json",
"build:release": "yarn clean && yarn workspaces foreach -pt --exclude 'root-workspace' run build",
"build": "yarn workspaces foreach -pt --exclude 'root-workspace' run build:cjs",
"build:watch": "yarn build:dev && tsc -b tsconfig.json --watch",
Copy link
Member

Choose a reason for hiding this comment

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

What's the benefit of this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It complains as soon as you break something and is more efficient as running yarn check or yarn build:dev repeatedly. Also I would have to double check but potentially you need to have it running if you are using jest in watch mode.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

just checked, you would want to have this running as well if jest is running in watch mode to make sure packages are being rebuild on changes. Otherwise imports from another package may use out of date versions.

Copy link
Member

Choose a reason for hiding this comment

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

So this is supposed to be run before and during tests? And yarn build:dev alone then when?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Again, this is for watch mode. As in, you keep jest running and it re-executes tests whenever you change a file. So far we didn't have a solution for that. You can also just run yarn build:dev && yarn test whenever you want to test of course. It's a question of preference.

As for the naming, I was considering making yarn build:dev the new yarn build and introducing a yarn build:production instead for release builds. Do you think that's better? I decided to go the other way because there is no harm in running the production build in a development scenario (it's just slower) but it would be bad to release a development build because the esm files are missing.

Copy link
Member

Choose a reason for hiding this comment

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

This makes sense. Rather use the build for development and something else for production.

"build:docs": "typedoc --theme default --out docs/api --tsconfig tsconfig.docs.json && touch docs/.nojekyll",
"bundle": "yarn workspace @kiltprotocol/sdk-js run bundle",
"clean": "rimraf tests/dist && yarn workspaces foreach -p --exclude '{root-workspace}' run clean",
"clean": "rimraf tests/dist && yarn workspaces foreach -p --exclude 'root-workspace' run clean",
"clean:docs": "rimraf docs/api",
"prepublish": "yarn workspaces foreach -p --no-private exec cp -f ../../LICENSE .",
"publish": "yarn workspaces foreach -pt --no-private npm publish",
Expand Down
15 changes: 10 additions & 5 deletions packages/asset-did/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
}
},
"files": [
"lib/**/*"
"lib/**/*.js",
"lib/**/*.d.ts",
"lib/**/*.json"
],
"scripts": {
"clean": "rimraf ./lib",
"build": "yarn clean && yarn build:ts",
"build:ts": "yarn build:cjs && yarn build:esm",
"build:cjs": "tsc --declaration -p tsconfig.build.json && echo '{\"type\":\"commonjs\"}' > ./lib/cjs/package.json",
"build:esm": "tsc --declaration -p tsconfig.esm.json && echo '{\"type\":\"module\"}' > ./lib/esm/package.json"
"build": "yarn build:cjs && yarn build:esm",
"build:cjs": "tsc -b && echo '{\"type\":\"commonjs\"}' > ./lib/cjs/package.json",
"build:esm": "tsc -p tsconfig.esm.json && echo '{\"type\":\"module\"}' > ./lib/esm/package.json"
},
"repository": "github:kiltprotocol/sdk-js",
"engines": {
Expand All @@ -32,5 +33,9 @@
"dependencies": {
"@kiltprotocol/types": "workspace:*",
"@kiltprotocol/utils": "workspace:*"
},
"devDependencies": {
"rimraf": "^3.0.2",
"typescript": "^4.8.3"
}
}
17 changes: 0 additions & 17 deletions packages/asset-did/tsconfig.build.json

This file was deleted.

6 changes: 4 additions & 2 deletions packages/asset-did/tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"extends": "./tsconfig.build.json",
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "ES6",
"outDir": "./lib/esm"
"outDir": "./lib/esm",
"declaration": false,
"composite": false
}
}
18 changes: 18 additions & 0 deletions packages/asset-did/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "./lib/cjs",
"rootDir": "./src"
},
"include": ["src/**/*.ts", "src/**/*.js"],
"exclude": ["coverage", "**/*.spec.ts"],
// indicates package dependencies; must be in sync with @kiltprotocol imports in package.json
"references": [
{
"path": "../types"
},
{
"path": "../utils"
}
]
}
11 changes: 6 additions & 5 deletions packages/augment-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@
}
},
"files": [
"lib/**/*"
"lib/**/*.js",
"lib/**/*.d.ts",
"lib/**/*.json"
],
"scripts": {
"clean": "rimraf ./lib",
"build": "yarn clean && yarn build:ts",
"build": "yarn build:cjs && yarn build:esm",
"build:cjs": "tsc -b tsconfig.json && echo '{\"type\":\"commonjs\"}' > ./lib/cjs/package.json",
"build:esm": "tsc -p tsconfig.esm.json && echo '{\"type\":\"module\"}' > ./lib/esm/package.json",
"build:types": "yarn generate:defs && yarn generate:meta && yarn build:fixes",
"build:fixes": "node scripts/fixTypes.mjs",
"build:ts": "yarn build:cjs && yarn build:esm",
"build:cjs": "tsc --declaration -p tsconfig.build.json && echo '{\"type\":\"commonjs\"}' > ./lib/cjs/package.json",
"build:esm": "tsc --declaration -p tsconfig.esm.json && echo '{\"type\":\"module\"}' > ./lib/esm/package.json",
"generate:defs": "ts-node --skip-project ../../node_modules/.bin/polkadot-types-from-defs --package @kiltprotocol/augment-api --input ./src/interfaces --endpoint ./metadata/spiritnet.json",
"generate:meta": "ts-node --skip-project ../../node_modules/.bin/polkadot-types-from-chain --package @kiltprotocol/augment-api --endpoint ./metadata/spiritnet.json --output ./src/interfaces --strict",
"update-metadata": "node ./scripts/fetchMetadata.js -o './metadata/spiritnet.json' -e 'wss://spiritnet.kilt.io/'"
Expand Down
29 changes: 0 additions & 29 deletions packages/augment-api/tsconfig.build.json

This file was deleted.

6 changes: 4 additions & 2 deletions packages/augment-api/tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"extends": "./tsconfig.build.json",
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "ES6",
"outDir": "./lib/esm"
"outDir": "./lib/esm",
"declaration": false,
"composite": false
}
}
22 changes: 22 additions & 0 deletions packages/augment-api/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "./lib/cjs",
"rootDir": "./src",
"skipLibCheck": true,
"noUnusedLocals": false,
"paths": {
"@kiltprotocol/augment-api/*": ["./src/*"],
"@polkadot/api/augment": ["./src/interfaces/augment-api.ts"],
"@polkadot/types/augment": ["./src/interfaces/augment-types.ts"]
}
},
"include": ["src/**/*.ts", "src/**/*.js"],
"exclude": ["coverage", "**/*.spec.ts", "src/**/definitions.ts"],
// indicates package dependencies; must be in sync with @kiltprotocol imports in package.json
"references": [
{
"path": "../type-definitions"
}
]
}
11 changes: 6 additions & 5 deletions packages/chain-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
}
},
"files": [
"lib/**/*"
"lib/**/*.js",
"lib/**/*.d.ts",
"lib/**/*.json"
],
"scripts": {
"clean": "rimraf ./lib",
"build": "yarn clean && yarn build:ts",
"build:ts": "yarn build:cjs && yarn build:esm",
"build:cjs": "tsc --declaration -p tsconfig.build.json && echo '{\"type\":\"commonjs\"}' > ./lib/cjs/package.json",
"build:esm": "tsc --declaration -p tsconfig.esm.json && echo '{\"type\":\"module\"}' > ./lib/esm/package.json"
"build": "yarn build:cjs && yarn build:esm",
"build:cjs": "tsc -b tsconfig.json && echo '{\"type\":\"commonjs\"}' > ./lib/cjs/package.json",
"build:esm": "tsc -p tsconfig.esm.json && echo '{\"type\":\"module\"}' > ./lib/esm/package.json"
},
"repository": "github:kiltprotocol/sdk-js",
"engines": {
Expand Down
16 changes: 0 additions & 16 deletions packages/chain-helpers/tsconfig.build.json

This file was deleted.

Loading