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: ast mono repo poc #15610

Merged
merged 9 commits into from
Aug 11, 2022
Merged
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
3 changes: 2 additions & 1 deletion app/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@
"test:unit": "$(npm bin)/jest -b --colors --no-cache --silent --coverage --collectCoverage=true --coverageDirectory='../../' --coverageReporters='json-summary'",
"test:jest": "$(npm bin)/jest --watch",
"generate:widget": "plop --plopfile generators/index.js",
"postinstall": "patch-package"
"postinstall": "patch-package && CURRENT_SCOPE=client node ../shared/install-dependencies.js",
"preinstall": "CURRENT_SCOPE=client node ../shared/build-shared-dep.js"
},
"browserslist": [
">0.2%",
Expand Down
5 changes: 3 additions & 2 deletions app/client/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4307,8 +4307,9 @@ astral-regex@^2.0.0:
resolved "https://registry.npmjs.org/astral-regex/-/astral-regex-2.0.0.tgz"

astring@^1.7.5:
version "1.7.5"
resolved "https://registry.npmjs.org/astring/-/astring-1.7.5.tgz"
version "1.8.3"
resolved "https://registry.yarnpkg.com/astring/-/astring-1.8.3.tgz#1a0ae738c7cc558f8e5ddc8e3120636f5cebcb85"
integrity sha512-sRpyiNrx2dEYIMmUXprS8nlpRg2Drs8m9ElX9vVEXaCB4XEAJhKfs7IcX0IwShjuOAjLR6wzIrgoptz1n19i1A==

async-limiter@~1.0.0:
version "1.0.1"
Expand Down
4 changes: 4 additions & 0 deletions app/rts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,9 @@
"socket.io-adapter": "^2.3.2",
"source-map-support": "^0.5.19",
"typescript": "^4.2.3"
},
"scripts": {
"preinstall": "CURRENT_SCOPE=rts node ../shared/build-shared-dep.js",
"postinstall": "CURRENT_SCOPE=rts node ../shared/install-dependencies.js"
}
}
4 changes: 4 additions & 0 deletions app/shared/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
**build
**node_modules
yarn-error.log
yarn.lock
19 changes: 19 additions & 0 deletions app/shared/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Shared Dependencies
We wanted to share common logic with different applications within our repo, so we picked [yarn symlinks](https://classic.yarnpkg.com/en/docs/cli/link) as our approach to tackle this problem. Following are the way in which you can take advantage of the module sharing architecture.

## Creation of a Shared Module
- Create a directory inside `shared` directory with name eg. `abc`
- Inside `package.json` of module, keep the name like `@shared/abc`
- Add a rollup config to generate `package.json` after the module is build

## Installation of Shared Modules
- Add an entry for an application inside `shared-dependencies.json` eg. for `client` there should be an entry `"client": []`
- Add the name of the shared module in the entry of the application in the above file eg. `"client": ["@shared/abc"]`
- If the application does not have any postinstall or preinstall scripts for shared modules then add the two commands described below in the application's (eg. `client`) `package.json` :
`"postinstall": "CURRENT_SCOPE=client node ../shared/install-dependencies.js"`
`"preinstall": "CURRENT_SCOPE=client node ../shared/build-shared-dep.js"`
CURRENT_SCOPE is the environment variable that's being used in the scripts

## Verifying the Installed Shared Modules
- Run `yarn run verify` inside `shared` directory to verify shared dependencies for an application.

1 change: 1 addition & 0 deletions app/shared/ast/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module "@shared/ast";
37 changes: 37 additions & 0 deletions app/shared/ast/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "@shared/ast",
"version": "1.0.0",
"description": "",
"main": "build/index.js",
"module": "build/index.es.js",
"types": "build/index.d.ts",
"files": [
"build"
],
"publishConfig": {
"directory": "build"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "rollup -c",
"start": "rollup -c",
"link-package": "yarn install && rollup -c && cd build && yarn link"
},
"dependencies": {
"acorn-walk": "^8.2.0",
"rollup": "^2.77.0",
"typescript": "4.5.5"
},
"devDependencies": {
"@babel/preset-typescript": "^7.17.12",
"@rollup/plugin-commonjs": "^22.0.0",
"@typescript-eslint/eslint-plugin": "^5.25.0",
"@typescript-eslint/parser": "^5.25.0",
"rollup-plugin-generate-package-json": "^3.2.0",
"rollup-plugin-peer-deps-external": "^2.2.4",
"rollup-plugin-typescript2": "^0.32.0",
"ts-jest": "27.0.0"
},
"author": "",
"license": "ISC"
}
31 changes: 31 additions & 0 deletions app/shared/ast/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import peerDepsExternal from "rollup-plugin-peer-deps-external";
import commonjs from "@rollup/plugin-commonjs";
import typescript from "rollup-plugin-typescript2";
import generatePackageJson from "rollup-plugin-generate-package-json";

const packageJson = require("./package.json");

export default {
// TODO: Figure out regex where each directory can be a separate module without having to manually add them
input: ["src/index.ts"],
output: [
{
file: packageJson.module,
format: "esm",
sourcemap: true,
},
{
file: packageJson.main,
format: "cjs",
sourcemap: true,
},
],
plugins: [
peerDepsExternal(),
commonjs(),
typescript({ useTsconfigDeclarationDir: true }),
generatePackageJson({
baseContents: (pkg) => pkg,
}),
],
};
9 changes: 9 additions & 0 deletions app/shared/ast/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const isNullOrWhitespace = (value: string) =>
value === undefined || value === null || !value.trim();
const isNullX = (value: string) => value === undefined || value === null;

export type Animal = {
name: string;
age: number;
};
export { isNullOrWhitespace, isNullX };
37 changes: 37 additions & 0 deletions app/shared/ast/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"compilerOptions": {
"target": "ES6",
"lib": [
"DOM",
"ES6",
"DOM.Iterable",
"ScriptHost",
"ES2016.Array.Include",
"es2020.string",
"esnext"
],
"strict": true,
"declaration": true,
"declarationDir": "build",
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react",
"downlevelIteration": true,
"experimentalDecorators": true,
"importHelpers": true,
"typeRoots": ["./typings", "./node_modules/@types"],
"sourceMap": true,
"baseUrl": "./src",
"noFallthroughCasesInSwitch": true
},
"include": ["./src/**/*", "index.d.ts"],
"exclude": ["node_modules", "build"]
}
Loading
Loading