< JavaScript Project Setup Conventions
The purpose of this document is to outline the code conventions used by all Edge JavaScript projects. It lists the recommendations for utilities, formatting, scripts, etc.
We use Yarn v1 to manage our package dependencies.
All repositories should commit a .yarnrc file with at least the following:
--ignore-scripts true
This will prevent scripts from running during package installation.
As a security measure, we do not allow scripts to run after package installation.
All build scripts should run with yarn prepare, separate from yarn.
Every developer must run yarn config set ignore-scripts true on their local development environment.
This prevents scripts from running during package installation for any project missing a properly configured .yarnrc (whether Edge's repo or a 3rd-party's).
A shell alias which combines yarn install and yarn prepare may be added to a developers shell config for convenience.
For example, add to your .zshrc or .bashrc:
alias yip='yarn && yarn prepare'// package.json
"test": "jest"// package.json
"flow": "flow"
Installing
yarn add -D husky// package.json
"pre-push": "yarn test"
-
Lint-staged - github
-
Import-sort - github
-
Sort-package-json - github
- Installing
yarn add sort-package-json import-sort-cli import-sort-style-module prettier-eslint-cli lint-staged
- Usage
// package.json "scripts": { "format": "sort-package-json; import-sort -l --write '*.js' 'src/**/*.js'; prettier-eslint --write '*.js' 'src/**/*.js'", "precommit": "lint-staged" }, "prettier": { "printWidth": 120 }, "lint-staged": { "*.js": ["yarn format", "git add"] }, "importSort": { ".js, .es": { "parser": "babylon", "style": "module" } }
All dependencies should be defined with their full URLs or NPM package version. GitHub short-hand URLs should not be used due to an outstanding issue with Yarn not running prepare/prepack for these types of dependencies.
{
"dependencies": {
"react": "^17.0.1",
"edge-currency-accountbased": "git://github.com/EdgeApp/edge-currency-accountbased.git#v0.7.33"
}
}{
"dependencies": {
"edge-currency-accountbased": "EdgeApp/edge-currency-accountbased#v0.7.33"
}
}
Each repo should have the following package.json scripts which accomplish the following:
build: If necessary, run rollup, webpack, and flow-copy to populatelibfolder. Should not run any lint, flow checking, or testsflow: Runflowlint: Runstandard.jsor equivalent andflowtest: Runlintandflow. Flow should exclude*.js.flowfiles. Lastly runmochaorjesttestsprecommit: Runbuildthentestprepare: Runbuild