Skip to content

Commit c833c70

Browse files
committed
Initial commit
0 parents  commit c833c70

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+10624
-0
lines changed

.editorconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = LF
5+
charset = utf-8
6+
max_line_length = 80
7+
indent_style = space
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
indent_size = 2
11+
12+
[*.{ts,tsx}]
13+
max_line_length = 80
14+
15+
[*.md]
16+
trim_trailing_whitespace = false
17+
max_line_length = 80

.eslintignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
cjs
3+
esm
4+
umd
5+
dist

.eslintrc.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
module.exports = {
2+
root: true,
3+
env: {
4+
browser: true,
5+
es2020: true,
6+
node: true,
7+
},
8+
extends: [
9+
'eslint:recommended',
10+
'plugin:react/recommended',
11+
'plugin:jsx-a11y/recommended',
12+
'prettier',
13+
'prettier/react',
14+
],
15+
plugins: ['react-hooks', 'jsx-a11y', 'no-only-tests'],
16+
settings: {
17+
react: {
18+
version: 'detect',
19+
},
20+
},
21+
rules: {
22+
'no-only-tests/no-only-tests': 'error',
23+
'no-console': 'error',
24+
'react-hooks/rules-of-hooks': 'error',
25+
'react-hooks/exhaustive-deps': 'error',
26+
'react/prop-types': 'off',
27+
},
28+
overrides: [
29+
{
30+
files: ['*.ts', '*.tsx'],
31+
parserOptions: {
32+
project: './tsconfig.json',
33+
tsconfigRootDir: __dirname,
34+
},
35+
extends: [
36+
'plugin:@typescript-eslint/recommended',
37+
'plugin:@typescript-eslint/recommended-requiring-type-checking',
38+
'prettier/@typescript-eslint',
39+
],
40+
rules: {
41+
'@typescript-eslint/no-use-before-define': 'off',
42+
'@typescript-eslint/no-unused-vars': 'off',
43+
},
44+
},
45+
],
46+
};

.github/dependabot.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: npm
4+
directory: '/'
5+
schedule:
6+
interval: daily
7+
open-pull-requests-limit: 10
8+
versioning-strategy: increase
9+
ignore:
10+
- dependency-name: '@types/node'
11+
versions:
12+
- '>=13'

.github/workflows/tests.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: tests
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
tests:
7+
name: node ${{ matrix.node-version }} / ${{ matrix.os }}
8+
runs-on: ${{ matrix.os }}
9+
strategy:
10+
matrix:
11+
node-version: [14, 12]
12+
os: [ubuntu-latest, windows-latest, macOS-latest]
13+
steps:
14+
- uses: actions/checkout@v2
15+
- name: Use Node.js ${{ matrix.node-version }}
16+
uses: actions/setup-node@v1
17+
with:
18+
node-version: ${{ matrix.node-version }}
19+
- run: npm i -g yarn@1
20+
- run: yarn
21+
- run: yarn test

.gitignore

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# build artifact folders
2+
cjs
3+
esm
4+
umd
5+
6+
# IDEs
7+
.idea
8+
.vscode
9+
10+
# OS-specific
11+
.DS_Store
12+
13+
# Below is a copy of https://github.com/github/gitignore/blob/master/Node.gitignore
14+
15+
# Logs
16+
logs
17+
*.log
18+
npm-debug.log*
19+
yarn-debug.log*
20+
yarn-error.log*
21+
lerna-debug.log*
22+
23+
# Diagnostic reports (https://nodejs.org/api/report.html)
24+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
25+
26+
# Runtime data
27+
pids
28+
*.pid
29+
*.seed
30+
*.pid.lock
31+
32+
# Directory for instrumented libs generated by jscoverage/JSCover
33+
lib-cov
34+
35+
# Coverage directory used by tools like istanbul
36+
coverage
37+
*.lcov
38+
39+
# nyc test coverage
40+
.nyc_output
41+
42+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
43+
.grunt
44+
45+
# Bower dependency directory (https://bower.io/)
46+
bower_components
47+
48+
# node-waf configuration
49+
.lock-wscript
50+
51+
# Compiled binary addons (https://nodejs.org/api/addons.html)
52+
build/Release
53+
54+
# Dependency directories
55+
node_modules/
56+
jspm_packages/
57+
58+
# Snowpack dependency directory (https://snowpack.dev/)
59+
web_modules/
60+
61+
# TypeScript cache
62+
*.tsbuildinfo
63+
64+
# Optional npm cache directory
65+
.npm
66+
67+
# Optional eslint cache
68+
.eslintcache
69+
70+
# Microbundle cache
71+
.rpt2_cache/
72+
.rts2_cache_cjs/
73+
.rts2_cache_es/
74+
.rts2_cache_umd/
75+
76+
# Optional REPL history
77+
.node_repl_history
78+
79+
# Output of 'npm pack'
80+
*.tgz
81+
82+
# Yarn Integrity file
83+
.yarn-integrity
84+
85+
# dotenv environment variables file
86+
.env
87+
.env.test
88+
89+
# parcel-bundler cache (https://parceljs.org/)
90+
.cache
91+
.parcel-cache
92+
93+
# Next.js build output
94+
.next
95+
out
96+
97+
# Nuxt.js build / generate output
98+
.nuxt
99+
dist
100+
101+
# Gatsby files
102+
.cache/
103+
# Comment in the public line in if your project uses Gatsby and not Next.js
104+
# https://nextjs.org/blog/next-9-1#public-directory-support
105+
# public
106+
107+
# vuepress build output
108+
.vuepress/dist
109+
110+
# Serverless directories
111+
.serverless/
112+
113+
# FuseBox cache
114+
.fusebox/
115+
116+
# DynamoDB Local files
117+
.dynamodb/
118+
119+
# TernJS port file
120+
.tern-port
121+
122+
# Stores VSCode versions used for testing VSCode extensions
123+
.vscode-test
124+
125+
# yarn v2
126+
127+
.yarn/cache
128+
.yarn/unplugged
129+
.yarn/build-state.yml
130+
.pnp.*

.huskyrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"hooks": {
3+
"pre-commit": "lint-staged && yarn pretest"
4+
}
5+
}

.prettierignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dist
2+
cjs
3+
esm
4+
tsconfig.json

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 Wix.com
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# sample-monorepo
2+
3+
[![Build Status](https://github.com/wixplosives/sample-monorepo/workflows/tests/badge.svg)](https://github.com/wixplosives/sample-monorepo/actions) [![lerna](https://img.shields.io/badge/maintained%20with-lerna-cc00ff.svg)](https://lerna.js.org)
4+
5+
Sample monorepo setup with yarn workspaces, typescript, and lerna.
6+
7+
## Setup explained
8+
9+
### Tooling
10+
11+
- Monorepo is installed using [yarn](https://github.com/yarnpkg/yarn).
12+
13+
- Packages are automatically linked together, meaning you can do cross-package work within the repo.
14+
- `devDependencies` are common, and only appear in the root `package.json`. Easier to manage and upgrade.
15+
- Each package has its own `scripts` and `dependencies`. They are being installed in the root `node_modules`, using the same deduping mechanism `yarn` uses for single packages.
16+
- Adding new packages is as simple as dropping an existing package in the `packages` folder, and re-running `yarn`.
17+
18+
- Monorepo scripts are being executed using [lerna](https://github.com/lerna/lerna).
19+
20+
- `lerna publish` - multi-package publishing.
21+
- `lerna run` - running package scripts.
22+
- `lerna updated` - shows changed packages (since last tag).
23+
24+
- Sources and tests are written in strict [TypeScript](https://github.com/Microsoft/TypeScript).
25+
26+
- Common base `tsconfig.json`.
27+
- [@ts-tools/node](https://github.com/AviVahl/ts-tools) is used to run code directly from sources.
28+
29+
- Testing is done using [mocha](https://github.com/mochajs/mocha) and [chai](https://github.com/chaijs/chai).
30+
- Light, battle-tested, projects with few dependencies.
31+
- Can be bundled and used in the browser.
32+
33+
### Included sample packages
34+
35+
- **@sample/components**
36+
37+
- [React](https://github.com/facebook/react) components library.
38+
- Built as `cjs` (Node consumption) and `esm` (bundler consumption).
39+
40+
- **@sample/app**
41+
42+
- [React](https://github.com/facebook/react) application.
43+
- Uses the `@sample/components` package (also inside monorepo).
44+
- Built as `cjs` (Node consumption) and `umd` (browser consumption).
45+
46+
- **@sample/server**
47+
- [Express](https://github.com/expressjs/express) application.
48+
- Uses the `@sample/app` package (also inside monorepo).
49+
- Listens on http://localhost:3000 (client only rendering) http://localhost:3000/server (SSR rendering).
50+
- Built as `cjs` (Node consumption).
51+
52+
### Basic structure and configurations
53+
54+
```
55+
.github // CI flow configuration (GitHub Actions)
56+
packages/
57+
some-package/
58+
src/
59+
index.ts
60+
test/
61+
test.spec.ts
62+
LICENSE // license file. included in npm artifact
63+
package.json // package-specific deps and scripts
64+
README.md // shown in npmjs.com. included in npm artifact
65+
66+
.eslintignore // eslint (linter) ignored directories/files
67+
.eslintrc // eslint (linter) configuration
68+
.gitignore // github's default node gitignore with customizations
69+
.mocharc.js // mocha (test runner) configuration
70+
lerna.json // lerna configuration
71+
LICENSE // root license file. picked up by github
72+
package.json // common dev deps and workspace-wide scripts
73+
README.md // workspace-wide information. shown in github
74+
tsconfig.json // common typescript configuration
75+
yarn.lock // the only lock file in the repo. all packages combined
76+
```
77+
78+
### Dependency management
79+
80+
Traditionally, working with projects in separate repositories makes it difficult to keep versions of `devDependencies` aligned, as each project can specify its own `devDependency` versions.
81+
82+
Monorepos simplify this, because `devDependencies` are shared between all packages within the monorepo.
83+
84+
Taking this into account, we use the following dependency structure:
85+
86+
- `devDependencies` are placed in the root `package.json`
87+
- `dependencies` and `peerDependencies` are placed in the `package.json` of the relevant package requiring them, as each package is published separately
88+
89+
New `devDependencies` can be added to the root `package.json` using yarn:
90+
91+
```sh
92+
yarn add <package name> --dev -W
93+
```
94+
95+
Some packages depend on sibling packages within the monorepo. For example, in this repo, `@sample/app` depends on `@sample/components`. This relationship is just a normal dependency, and can be described in the `package.json` of `app` like so:
96+
97+
```json
98+
"dependencies": {
99+
"@sample/components": "<package version>"
100+
}
101+
```
102+
103+
### Deployment
104+
105+
`yarn lerna publish` will publish new versions of the packages to npm.
106+
107+
Lerna asks for new version numbers for packages that changed since last release and their dependencies. Every package has a `prepack` script which automatically runs `build` prior to packing.
108+
109+
`yarn lerna publish --force-publish` will force a release of _all_ packages, regardless of which ones actually changed.
110+
111+
Deployment of app/server assets to any actual production servers is not shown.

0 commit comments

Comments
 (0)