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

Re-factor build scripts to TypeScript #202

Merged
merged 23 commits into from
Sep 10, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d7c26fd
Re-factor scripts for building, development, linting, and cleaning to…
smithki Sep 1, 2021
7fa7da1
Remove remnants of old test runner (ava)
smithki Sep 1, 2021
a210f1b
Re-factor scripts for unit testing to TypeScript
smithki Sep 1, 2021
e2ccc67
Small cleanups
smithki Sep 1, 2021
d258eeb
Refactor to merge `ViewController` and `PayloadTransport` classes (#203)
smithki Sep 2, 2021
9a59d3f
Make script code more DRY
smithki Sep 2, 2021
d12760f
Update TypeScript & make scripts more DRY
smithki Sep 2, 2021
94efcb4
Fix typo and add 'printSeparator' script utility
smithki Sep 2, 2021
a2325a2
Fix 'inject-env.ts' script following re-organization of code
smithki Sep 2, 2021
d5e2f35
Remove outdated / unused dependencies from root PackageJSON
smithki Sep 8, 2021
a858d16
Progress towards integrating microbundle
smithki Sep 9, 2021
69d343f
Update build scripts to bundle all packages via microbundle
smithki Sep 10, 2021
50a0a03
Remove unnecessary console statement
smithki Sep 10, 2021
e8c7fde
Run pre-commit hooks against all packages
smithki Sep 10, 2021
2e0e32c
Add more memory for tasks spawned via 'wsrun'
smithki Sep 10, 2021
3e28ee0
Raise the resource class in CI
smithki Sep 10, 2021
66a3346
Try to fix ENOMEM errors in CI by limiting concurrency
smithki Sep 10, 2021
89a4660
Replace 'p-limit' dependency with prior version (new version is ESM-o…
smithki Sep 10, 2021
b529dd4
Better caching in CircleCI
smithki Sep 10, 2021
f80e463
Update test script to work with Yarn 2
smithki Sep 10, 2021
494fe08
Fix tests related to ViewController refactor
smithki Sep 10, 2021
f1066f4
Reduce the CircleCI resource class back to medium
smithki Sep 10, 2021
62b4874
Fix tests related to ViewController refactor
smithki Sep 10, 2021
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
Prev Previous commit
Next Next commit
Update build scripts to bundle all packages via microbundle
  • Loading branch information
smithki committed Sep 10, 2021
commit 69d343f97e40d5d7c4050edfa39f100d81af9e13
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ jobs:
- run:
name: Apply semver updates (if any)
command: |
AUTO_VERSION=$(yarn --silent auto version)
AUTO_VERSION=$(yarn auto version)
if [[ $AUTO_VERSION ]]; then
yarn lerna version $(echo $AUTO_VERSION) --no-git-tag-version --yes
fi
Expand Down
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
/package-lock.json
/**/package-lock.json
/**/yarn-error.log
.yarn/*
!.yarn/patches
!.yarn/releases
!.yarn/plugins
!.yarn/sdks
!.yarn/versions
.pnp.*

# Output files
/**/dist
Expand Down
28 changes: 28 additions & 0 deletions .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs

Large diffs are not rendered by default.

631 changes: 631 additions & 0 deletions .yarn/releases/yarn-berry.js

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
nmHoistingLimits: workspaces

nodeLinker: node-modules

plugins:
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
spec: "@yarnpkg/plugin-workspace-tools"

yarnPath: ./.yarn/releases/yarn-berry.js
2 changes: 0 additions & 2 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"packages": ["packages/@magic-sdk/*", "packages/magic-sdk"],
"workspaces": ["packages/@magic-sdk/*", "packages/magic-sdk"],
"version": "independent",
"npmClient": "yarn",
"useWorkspaces": true
Expand Down
23 changes: 12 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,26 @@
"name": "magic-sdk-monorepo",
"version": "0.0.0",
"scripts": {
"bootstrap": "yarn install && lerna link",
"wsrun": "wsrun --bin $INIT_CWD/scripts/bin/wsrun/bin.ts -p $PKG",
"wsrun:paths": "yarn --silent wsrun --parallel --no-prefix -r -c $INIT_CWD/scripts/bin/wsrun/resolve-paths.ts",
"wsrun": "$INIT_CWD/scripts/bin/wsrun-wrapper.ts",
"wsrun:all": "$INIT_CWD/scripts/bin/wsrun-wrapper.ts --all",
"wsrun:paths": "yarn wsrun --stages --no-prefix -r -c $INIT_CWD/scripts/bin/wsrun/resolve-paths.ts",
"dev": "$INIT_CWD/scripts/bin/clean.ts && $INIT_CWD/scripts/bin/dev.ts",
"build": "$INIT_CWD/scripts/bin/clean.ts && $INIT_CWD/scripts/bin/build.ts",
"clean": "$INIT_CWD/scripts/bin/clean.ts",
"lint": "$INIT_CWD/scripts/bin/lint.ts",
"test": "$INIT_CWD/scripts/bin/test.ts",
"postinstall": "husky install"
"postinstall": "husky install && lerna link"
},
"devDependencies": {
"@ikscodes/browser-env": "~0.3.1",
"@ikscodes/eslint-config": "~7.0.2",
"@ikscodes/prettier-config": "~2.0.1",
"@istanbuljs/nyc-config-typescript": "~0.1.3",
"@types/inquirer": "^8.1.1",
"@types/is-ci": "^3.0.0",
"@types/jest": "^27.0.0",
"@types/jsdom": "~12.2.4",
"@types/lodash": "^4.14.172",
"@types/react": "^16.9.34",
"@types/react-native": "^0.62.2",
"@types/rimraf": "^3.0.2",
Expand All @@ -37,9 +40,12 @@
"eslint-plugin-react-hooks": "~4.0.4",
"execa": "~5.1.1",
"husky": "^7.0.1",
"inquirer": "^8.1.2",
"is-ci": "^3.0.0",
"jest": "^27.0.6",
"lerna": "^3.21.0",
"lint-staged": "^10.0.7",
"lodash": "^4.17.21",
"meow": "9.0.0",
"microbundle": "0.13.3",
"npm-run-all": "^4.1.5",
Expand All @@ -48,25 +54,20 @@
"prettier": "~2.3.2",
"react": "^16.13.1",
"react-native": "^0.62.2",
"regenerator-runtime": "0.13.9",
"replace-in-file": "^6.1.0",
"rimraf": "~3.0.2",
"ts-jest": "^27.0.4",
"tslib": "^2.3.1",
"ts-node": "^10.2.0",
"tsc-watch": "^4.2.9",
"tslib": "^2.3.1",
"typescript": "~4.4.2",
"wsrun": "^5.2.1"
},
"workspaces": {
"packages": [
"packages/@magic-sdk/*",
"packages/magic-sdk"
],
"nohoist": [
"@magic-sdk/react-native/buffer",
"@magic-sdk/react-native/buffer/**",
"@magic-sdk/react-native/process",
"@magic-sdk/react-native/process/**"
]
},
"repository": "magiclabs/magic-js",
Expand Down
1 change: 0 additions & 1 deletion packages/@magic-sdk/commons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"dist/**/*.js.map",
"dist/**/*.d.ts"
],
"builder": "tsc",
"target": "web",
"main": "./dist/cjs/index.js",
"module": "./dist/es/index.js",
Expand Down
19 changes: 0 additions & 19 deletions packages/@magic-sdk/commons/tsconfig.cjs.json

This file was deleted.

1 change: 0 additions & 1 deletion packages/@magic-sdk/commons/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"rootDir": "src",
"outDir": "dist/es",
"declarationDir": "dist/types",
"tsBuildInfoFile": "node_modules/.cache/.tsbuildinfo/es",
},

"include": [
Expand Down
12 changes: 7 additions & 5 deletions packages/@magic-sdk/provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"dist/**/*.js.map",
"dist/**/*.d.ts"
],
"builder": "tsc",
"target": "web",
"main": "./dist/cjs/index.js",
"module": "./dist/es/index.js",
Expand All @@ -23,12 +22,15 @@
"@babel/plugin-transform-runtime": "^7.9.6",
"@peculiar/webcrypto": "^1.1.7",
"@types/semver": "^7.3.4",
"@magic-sdk/types": "^4.0.0",
"eventemitter3": "^4.0.4",
"semver": "^7.3.2",
"web3-core": "1.5.2",
"localforage": "^1.7.4",
"localforage-driver-memory": "^1.0.5"
"localforage-driver-memory": "^1.0.5",
"semver": "^7.3.2",
"tslib": "^2.3.1",
"web3-core": "1.5.2"
},
"dependencies": {
"@magic-sdk/types": "^4.0.0"
},
"peerDependencies": {
"localforage": "^1.7.4"
Expand Down
8 changes: 4 additions & 4 deletions packages/@magic-sdk/provider/src/core/sdk-environment.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import localForage from 'localforage';
import { ViewController } from './view-controller';
import { SDKBase } from './sdk';
import { WithExtensions } from '../modules/base-extension';
import type localForage from 'localforage';
import type { ViewController } from './view-controller';
import type { SDKBase } from './sdk';
import type { WithExtensions } from '../modules/base-extension';

type ConstructorOf<C> = { new (...args: any[]): C };

Expand Down
6 changes: 6 additions & 0 deletions packages/@magic-sdk/provider/src/core/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ export class SDKBase {
protected get overlay(): ViewController {
if (!SDKBase.__overlays__.has(this.parameters)) {
const controller = new SDKEnvironment.ViewController(this.endpoint, this.parameters);

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore - We don't want to expose this method to the user, but we
// need to invoke in here so that the `ViewController` is ready for use.
controller.init();

SDKBase.__overlays__.set(this.parameters, controller);
}

Expand Down
1 change: 0 additions & 1 deletion packages/@magic-sdk/provider/src/core/view-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ export abstract class ViewController {
*/
constructor(protected readonly endpoint: string, protected readonly parameters: string) {
this.ready = this.waitForReady();
this.init();
this.listen();
}

Expand Down
6 changes: 3 additions & 3 deletions packages/@magic-sdk/provider/src/modules/base-module.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { JsonRpcRequestPayload, MagicOutgoingWindowMessage, MagicIncomingWindowMessage } from '@magic-sdk/types';
import { createMalformedResponseError, MagicRPCError } from '../core/sdk-exceptions';
import { SDKBase } from '../core/sdk';
import type { SDKBase } from '../core/sdk';
import { standardizeJsonRpcRequestPayload } from '../core/json-rpc';
import { createPromiEvent } from '../util/promise-tools';
import { ViewController } from '../core/view-controller';
import { EventsDefinition } from '../util/events';
import type { ViewController } from '../core/view-controller';
import type { EventsDefinition } from '../util/events';

export class BaseModule {
constructor(protected sdk: SDKBase) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ beforeEach(() => {
});

test('Instantiates `ViewController`', async () => {
const initStub = jest.fn().mockImplementation(() => new Promise(() => {}));
const listenStub = jest.fn();
const waitForReadyStub = jest.fn();

(ViewController.prototype as any).init = initStub;
(ViewController.prototype as any).listen = listenStub;
(ViewController.prototype as any).waitForReady = waitForReadyStub;

Expand All @@ -21,7 +19,6 @@ test('Instantiates `ViewController`', async () => {
expect(overlay instanceof ViewController).toBe(true);
expect(overlay.endpoint).toBe('testing123');
expect(overlay.parameters).toBe('qwerty');
expect(initStub).toBeCalledTimes(1);
expect(listenStub).toBeCalledTimes(1);
expect(waitForReadyStub).toBeCalledTimes(1);
});
19 changes: 0 additions & 19 deletions packages/@magic-sdk/provider/tsconfig.cjs.json

This file was deleted.

1 change: 0 additions & 1 deletion packages/@magic-sdk/provider/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"rootDir": "src",
"outDir": "dist/es",
"declarationDir": "dist/types",
"tsBuildInfoFile": "node_modules/.cache/.tsbuildinfo/es",
},

"include": [
Expand Down
25 changes: 12 additions & 13 deletions packages/@magic-sdk/react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,33 @@
"dist/**/*.js.map",
"dist/**/*.d.ts"
],
"builder": "tsc",
"target": "node",
"main": "./dist/cjs/index.js",
"module": "./dist/es/index.js",
"types": "./dist/types/index.d.ts",
"dependencies": {
"devDependencies": {
"@aveq-research/localforage-asyncstorage-driver": "^3.0.1",
"@babel/core": "~7.10.4",
"@babel/plugin-transform-flow-strip-types": "^7.14.5",
"@babel/runtime": "~7.10.4",
"@magic-sdk/commons": "^1.2.1",
"@magic-sdk/provider": "^5.1.0",
"@magic-sdk/types": "^4.0.0",
"@react-native-async-storage/async-storage": "^1.15.5",
"@types/lodash": "^4.14.158",
"babel-jest": "^27.0.6",
"buffer": "~5.6.0",
"localforage": "^1.7.4",
"localforage-driver-memory": "^1.0.5",
"lodash": "^4.17.19",
"process": "~0.11.10",
"tslib": "^2.3.1",
"whatwg-url": "~8.1.0"
},
"devDependencies": {
"@babel/plugin-transform-flow-strip-types": "^7.14.5",
"babel-jest": "^27.0.6",
"metro-react-native-babel-preset": "^0.66.2",
"process": "~0.11.10",
"react": "^16.13.1",
"react-native": "^0.62.2",
"react-native-webview": "8.1.2"
"react-native-webview": "8.1.2",
"whatwg-url": "~8.1.0"
},
"dependencies": {
"@magic-sdk/commons": "^1.2.1",
"@magic-sdk/provider": "^5.1.0",
"@magic-sdk/types": "^4.0.0"
},
"peerDependencies": {
"react": ">=16",
Expand Down
10 changes: 6 additions & 4 deletions packages/@magic-sdk/react-native/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

/* istanbul ignore file */

import 'regenerator-runtime/runtime';

import { createSDK } from '@magic-sdk/provider';
import * as processPolyfill from 'process';
import localForage from 'localforage';
Expand All @@ -18,6 +20,9 @@ import * as memoryDriver from 'localforage-driver-memory';
import { ReactNativeWebViewController } from './react-native-webview-controller';
import { SDKBaseReactNative } from './react-native-sdk-base';

// Web3 assumes a browser context, so we need
// to provide `btoa` and `atob` shims.

// We expect `global.process` to be a Node Process for web3.js usage
// so we replace it here.
global.process = _.merge(global.process, processPolyfill);
Expand All @@ -31,9 +36,6 @@ global.Buffer = Buffer;
global.URL = URLPolyfill as any;
global.URLSearchParams = URLSearchParamsPolyfill as any;

// Web3 assumes a browser context, so we need
// to provide `btoa` and `atob` shims.

/* istanbul ignore next */
global.btoa = (str) => Buffer.from(str, 'binary').toString('base64');
/* istanbul ignore next */
Expand All @@ -44,7 +46,7 @@ export * from '@magic-sdk/commons';
export const Magic = createSDK(SDKBaseReactNative, {
platform: 'react-native',
sdkName: '@magic-sdk/react-native',
version: '%REACT_NATIVE_VERSION%',
version: process.env.REACT_NATIVE_VERSION!,
defaultEndpoint: 'https://box.magic.link/',
ViewController: ReactNativeWebViewController,
configureStorage: /* istanbul ignore next */ async () => {
Expand Down
21 changes: 0 additions & 21 deletions packages/@magic-sdk/react-native/tsconfig.cjs.json

This file was deleted.

7 changes: 3 additions & 4 deletions packages/@magic-sdk/react-native/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"rootDir": "src",
"outDir": "dist/es",
"declarationDir": "dist/types",
"tsBuildInfoFile": "node_modules/.cache/.tsbuildinfo/es",
},

"include": [
Expand All @@ -14,8 +13,8 @@
],

"references": [
{ "path": "../types/tsconfig.json" },
{ "path": "../provider/tsconfig.json" },
{ "path": "../commons/tsconfig.json" },
{ "path": "../types" },
{ "path": "../provider" },
{ "path": "../commons" },
]
}
Loading