From bedd869ce87e8d8d3bca391329f81f4174df2974 Mon Sep 17 00:00:00 2001 From: Mykhailo Marynenko <0x77dev@protonmail.com> Date: Thu, 24 Mar 2022 20:29:20 +0100 Subject: [PATCH] feat(lib, ipfs, transport, relay, explorer): namespacing (#70) * feat(transport, relay, explorer): add namespacing, fork transport, update explorer * feat(ipfs, transport, relay): namespacing proof-of-concept * feat(lib, relay): add namespacing support close #65 --- .vscode/settings.json | 3 + babel.config.json | 3 +- package.json | 6 +- packages/explorer/project.json | 78 +- packages/explorer/src/app/app.spec.tsx | 27 - packages/explorer/src/app/app.tsx | 55 - packages/explorer/src/app/nx-welcome.tsx | 820 ----- .../src/environments/environment.prod.ts | 3 - .../explorer/src/environments/environment.ts | 6 - packages/explorer/src/main.tsx | 22 +- packages/explorer/src/polyfills.ts | 1 + packages/ipfs/package.json | 8 +- packages/ipfs/src/addresses.ts | 3 - packages/ipfs/src/bootstrap.ts | 32 + packages/ipfs/src/index.ts | 65 +- packages/ipfs/tsconfig.json | 2 +- packages/lib/package.json | 1 + packages/lib/src/stack.ts | 46 +- packages/relay/Dockerfile | 3 + packages/relay/src/generate.ts | 3 + packages/relay/src/index.ts | 21 +- packages/relay/src/interfaces.ts | 7 + packages/relay/src/services/schema.ts | 19 + .../relay/src/services/signaling/index.ts | 43 +- packages/relay/src/services/signaling/peer.ts | 30 +- packages/relay/src/types.ts | 4 +- packages/transport/.eslintrc.json | 18 + packages/transport/README.md | 7 + packages/transport/jest.config.js | 14 + packages/transport/package.json | 30 + packages/transport/project.json | 32 + packages/transport/src/constants.js | 8 + packages/transport/src/index.js | 238 ++ packages/transport/src/listener.js | 155 + packages/transport/src/socket-to-conn.js | 119 + packages/transport/src/utils.js | 48 + packages/transport/tsconfig.json | 24 + packages/transport/tsconfig.lib.json | 10 + packages/transport/tsconfig.spec.json | 9 + tsconfig.base.json | 3 +- webpack.config.js | 35 + workspace.json | 3 +- yarn.lock | 3171 ++++++++--------- 43 files changed, 2550 insertions(+), 2685 deletions(-) delete mode 100644 packages/explorer/src/app/app.spec.tsx delete mode 100644 packages/explorer/src/app/app.tsx delete mode 100644 packages/explorer/src/app/nx-welcome.tsx delete mode 100644 packages/explorer/src/environments/environment.prod.ts delete mode 100644 packages/explorer/src/environments/environment.ts delete mode 100644 packages/ipfs/src/addresses.ts create mode 100644 packages/ipfs/src/bootstrap.ts create mode 100644 packages/relay/src/generate.ts create mode 100644 packages/relay/src/interfaces.ts create mode 100644 packages/relay/src/services/schema.ts create mode 100644 packages/transport/.eslintrc.json create mode 100644 packages/transport/README.md create mode 100644 packages/transport/jest.config.js create mode 100644 packages/transport/package.json create mode 100644 packages/transport/project.json create mode 100644 packages/transport/src/constants.js create mode 100644 packages/transport/src/index.js create mode 100644 packages/transport/src/listener.js create mode 100644 packages/transport/src/socket-to-conn.js create mode 100644 packages/transport/src/utils.js create mode 100644 packages/transport/tsconfig.json create mode 100644 packages/transport/tsconfig.lib.json create mode 100644 packages/transport/tsconfig.spec.json create mode 100644 webpack.config.js diff --git a/.vscode/settings.json b/.vscode/settings.json index aad8b85..6cafc30 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -29,5 +29,8 @@ }, "[javascript]": { "editor.defaultFormatter": "vscode.typescript-language-features" + }, + "[typescriptreact]": { + "editor.defaultFormatter": "vscode.typescript-language-features" } } diff --git a/babel.config.json b/babel.config.json index 065aee7..177f366 100644 --- a/babel.config.json +++ b/babel.config.json @@ -1,3 +1,4 @@ { - "babelrcRoots": ["*"] + "babelrcRoots": ["*"], + "plugins": ["@babel/plugin-transform-typescript"] } diff --git a/package.json b/package.json index 7e338f9..56572fd 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "tslib": "2.3.1" }, "devDependencies": { + "@babel/plugin-transform-typescript": "^7.16.8", "@commitlint/cli": "16.2.3", "@commitlint/config-conventional": "16.2.1", "@emotion/babel-plugin": "11.7.2", @@ -56,13 +57,16 @@ "jest": "27.5.1", "lerna": "4.0.0", "lint-staged": "12.3.7", + "node-polyfill-webpack-plugin": "^1.1.4", "npm-run-all": "4.1.5", "patch-package": "6.4.7", "prettier": "2.6.0", + "process": "^0.11.10", "react-test-renderer": "17.0.2", "standard-version": "9.3.2", "ts-jest": "27.1.3", - "typescript": "4.6.2", + "typescript": "^4.6.2", + "util": "^0.12.4", "yaml-crypt": "0.7.6", "zx": "6.0.6" }, diff --git a/packages/explorer/project.json b/packages/explorer/project.json index 60e9d69..911a727 100644 --- a/packages/explorer/project.json +++ b/packages/explorer/project.json @@ -1,73 +1,67 @@ { + "projectType": "application", "root": "packages/explorer", "sourceRoot": "packages/explorer/src", - "projectType": "application", + "tags": [], "targets": { "build": { - "executor": "@nrwl/web:webpack", - "outputs": ["{options.outputPath}"], + "configurations": { + "production": { + "extractLicenses": true, + "namedChunks": false, + "optimization": true, + "outputHashing": "all", + "sourceMap": false, + "vendorChunk": false + } + }, "defaultConfiguration": "production", + "executor": "@nrwl/web:webpack", "options": { - "compiler": "babel", - "outputPath": "dist/packages/explorer", - "index": "packages/explorer/src/index.html", - "baseHref": "/", - "main": "packages/explorer/src/main.tsx", - "polyfills": "packages/explorer/src/polyfills.ts", - "tsConfig": "packages/explorer/tsconfig.app.json", "assets": [ "packages/explorer/src/favicon.ico", "packages/explorer/src/assets" ], - "styles": [], + "baseHref": "/", + "compiler": "babel", + "index": "packages/explorer/src/index.html", + "main": "packages/explorer/src/main.tsx", + "outputPath": "dist/packages/explorer", + "polyfills": "packages/explorer/src/polyfills.ts", "scripts": [], - "webpackConfig": "@nrwl/react/plugins/webpack" + "styles": [], + "tsConfig": "packages/explorer/tsconfig.app.json", + "webpackConfig": "webpack.config.js" }, - "configurations": { - "production": { - "fileReplacements": [ - { - "replace": "packages/explorer/src/environments/environment.ts", - "with": "packages/explorer/src/environments/environment.prod.ts" - } - ], - "optimization": true, - "outputHashing": "all", - "sourceMap": false, - "namedChunks": false, - "extractLicenses": true, - "vendorChunk": false - } - } + "outputs": ["{options.outputPath}"] }, - "serve": { - "executor": "@nrwl/web:dev-server", + "lint": { + "executor": "@nrwl/linter:eslint", "options": { - "buildTarget": "explorer:build", - "hmr": true + "lintFilePatterns": ["packages/explorer/**/*.{ts,tsx,js,jsx}"] }, + "outputs": ["{options.outputFile}"] + }, + "serve": { "configurations": { "production": { "buildTarget": "explorer:build:production", "hmr": false } - } - }, - "lint": { - "executor": "@nrwl/linter:eslint", - "outputs": ["{options.outputFile}"], + }, + "executor": "@nrwl/web:dev-server", "options": { - "lintFilePatterns": ["packages/explorer/**/*.{ts,tsx,js,jsx}"] + "buildTarget": "explorer:build", + "hmr": true } }, "test": { "executor": "@nrwl/jest:jest", - "outputs": ["coverage/packages/explorer"], "options": { "jestConfig": "packages/explorer/jest.config.js", "passWithNoTests": true - } + }, + "outputs": ["coverage/packages/explorer"] } - }, - "tags": [] + } } diff --git a/packages/explorer/src/app/app.spec.tsx b/packages/explorer/src/app/app.spec.tsx deleted file mode 100644 index 8f94598..0000000 --- a/packages/explorer/src/app/app.spec.tsx +++ /dev/null @@ -1,27 +0,0 @@ -import { render } from '@testing-library/react' - -import { BrowserRouter } from 'react-router-dom' - -import App from './app' - -describe('App', () => { - it('should render successfully', () => { - const { baseElement } = render( - - - - ) - - expect(baseElement).toBeTruthy() - }) - - it('should have a greeting as the title', () => { - const { getByText } = render( - - - - ) - - expect(getByText(/Welcome explorer/gi)).toBeTruthy() - }) -}) diff --git a/packages/explorer/src/app/app.tsx b/packages/explorer/src/app/app.tsx deleted file mode 100644 index f804e82..0000000 --- a/packages/explorer/src/app/app.tsx +++ /dev/null @@ -1,55 +0,0 @@ -import styled from '@emotion/styled' -import NxWelcome from './nx-welcome' - -import { Route, Link } from 'react-router-dom' - -const StyledApp = styled.div` - // Your style here -` - -export function App() { - return ( - - - - {/* START: routes */} - {/* These routes and navigation have been generated for you */} - {/* Feel free to move and update them to fit your needs */} -
-
-
-
-
    -
  • - Home -
  • -
  • - Page 2 -
  • -
-
- ( -
- This is the generated root route.{' '} - Click here for page 2. -
- )} - /> - ( -
- Click here to go back to root page. -
- )} - /> - {/* END: routes */} -
- ) -} - -export default App diff --git a/packages/explorer/src/app/nx-welcome.tsx b/packages/explorer/src/app/nx-welcome.tsx deleted file mode 100644 index ab88f6d..0000000 --- a/packages/explorer/src/app/nx-welcome.tsx +++ /dev/null @@ -1,820 +0,0 @@ -/* - * * * * * * * * * * * * * * * * * * * * * * * * * * * * - This is a starter component and can be deleted. - * * * * * * * * * * * * * * * * * * * * * * * * * * * * - Delete this file and get started with your project! - * * * * * * * * * * * * * * * * * * * * * * * * * * * * - */ -export function NxWelcome({ title }: { title: string }) { - return ( - <> -