-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* POC for Shared AST Logic using Yarn Symlinks * fix: preinstall script for bundling shared packages * Merge commit * fix: updated the script to link, unlink the package as shared dep * fix: updated dependencies * Add a post-install script and fix yarn.lock file * Remove commented code * fix: added verification script, readme, moved scripts to shared Co-authored-by: Ayangade Adeoluwa <[email protected]>
- Loading branch information
1 parent
ee32ffb
commit 3b00508
Showing
15 changed files
with
1,632 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
**build | ||
**node_modules | ||
yarn-error.log | ||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
declare module "@shared/ast"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}), | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} |
Oops, something went wrong.