Skip to content

Commit

Permalink
Merge branch 'master' of github.com:redwoodjs/redwood into mohsen--ts…
Browse files Browse the repository at this point in the history
…-refs
  • Loading branch information
mohsen1 committed Apr 17, 2020
2 parents 95156eb + 5b24553 commit 21dd173
Show file tree
Hide file tree
Showing 147 changed files with 3,827 additions and 421 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-eslint-jest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ on:

jobs:
build:
runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest]
os: [ubuntu-latest, windows-latest]
node-version: ['12']
fail-fast: false
name: ${{ matrix.os }} | Node ${{ matrix.node-version }} latest
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ packages/api/importAll.macro.js
lerna-debug.log
yarn-error.log
**/*.tsbuildinfo
tasks/.verdaccio
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"workbench.colorCustomizations": {
"statusBar.background": "#b85833",
"statusBarItem.hoverBackground": "#ce7350",
"statusBar.foreground": "#e7e7e7"
"statusBar.foreground": "#e7e7e7",
"statusBar.border": "#b85833"
},
"peacock.color": "#b85833"
}
91 changes: 49 additions & 42 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,89 +1,96 @@
# Setup and Process Overview
# Contributing

Before interacting with the Redwood community, please read and understand our [Code of Conduct](https://github.com/redwoodjs/redwood/blob/master/CODE_OF_CONDUCT.md).

**Table of Contents**

- [Local Package Development](#Local-Package-Development-Setup)
- [Local development](#Local-development)
- [Running the Local Server(s)](#Running-the-Local-Server(s))
- [CLI Package Development](#CLI-Package-Development)

<!-- toc -->

## Local Package Development Setup
## Local development

You'll want to run a local redwood app sandbox using your local @redwoodjs packages instead of the current releases from the package registry. To do this we use [`yarn link`](`https://classic.yarnpkg.com/en/docs/cli/link/).
When contributing to Redwood you'll often want to add, fix, or change something in the Redwood Framework's monorepo, and see the implementation "running "live" in your own side project or one of our example apps.

### Example Setup: Package `@redwoodjs/cli` Local Dev
We offer two workflows for making that possible: "watch and copy" with some restrictions, and "emulate npm" without restrictions. The consideration for using the "emulate npm" workflow is if you've installed or upgraded a dependency, otherwise the "watch and copy" workflow should be fine.

Assuming you've already cloned `redwoodjs/redwood` locally and run `yarn install` and `yarn build`, navigate to the `packages/cli` directory and run the following command:
### Watch and copy

```
yarn link
The first step is to watch files for changes and build those changes in the Redwood framework:

```terminal
cd redwood
yarn build:watch
@redwoodjs/api: $ nodemon --watch src -e ts,js --ignore dist --exec 'yarn build'
@redwoodjs/core: $ nodemon --ignore dist --exec 'yarn build'
create-redwood-app: $ nodemon --ignore dist --exec 'yarn build'
@redwoodjs/eslint-plugin-redwood: $ nodemon --ignore dist --exec 'yarn build'
```

You should see a message `success Registered "@redwoodjs/cli"`.
The second step is to watch and copy those changes into your Redwood project:

If you haven't created a local redwood app for testing, first run `yarn create redwood-app [app-name]` and then run `yarn` from the app's root directory. Still in the root directory of the app, run the following:
```terminal
cd example-invoice
yarn rwdev watch ../path/to/redwood
```
yarn link @redwoodjs/cli
Redwood Framework Path: /Users/peterp/Personal/redwoodjs/redwood
Trigger event: add
building file list ... done
```

> You can link as many packages as needed at a time. Note: although some packages include others, e.g. /scripts uses /cli as a dependency, you'll still need to link packages individually.
You can also create a `RW_PATH` env var and then you don't have to specify the path in the watch command.

You should see a success message and can confirm the symlink was created by viewing the `/node_modules/@redwoodjs` directory from your editor or via command line `$ ls -l node_modules/@redwoodjs`
Now any changes that are made in the framework are copied into your project.

> HEADS UP: it's easy to forget you're using linked local packages in your sandbox app instead of those published to the package registry. You'll need to manually `git pull` upstream changes to packages.
### Emulating package publishing

### `Yarn Build:Watch`
Sometimes you'll want to test the full development flow from building and publishing our packages, to installing them in your project. We facilitate this using a local NPM registry called [Verdaccio](https://github.com/verdaccio/verdaccio).

As you make changes to a package (in this example `packages/cli`), you'll need to publish locally so the updates are included in your sandbox app. You can manually publish using `yarn build`. But it's more convenient to have the package re-publish each time you make a change. Run the following from the root of the package you're developing, `packages/cli` in this example:
#### Setting up and running a local NPM registry

```
yarn build:watch
```terminal
yarn add global verdaccio
./tasks/run-local-npm
```

You'd think you could just go over to your sandbox app and run your `cli` command, like:
This starts Verdaccio (http://localhost:4873) with our configuration file.

```
yarn redwood generate scaffold MyModel
```
#### Publishing a package

Unfortunately thanks to a long-standing [issue](https://github.com/yarnpkg/yarn/issues/3587) in Yarn, the bin files that are generated are not executable. You can fix that before running your command like so:
`./tasks/publish-local` will build, unpublish, and publish all the Redwood packages to your local NPM registry with a "dev" tag, for the curious it is the equivalent of running:

```terminal
npm unpublish --tag dev --registry http://localhost:4873/ --force
npm publish --tag dev --registry http://localhost:4873/ --force
```
chmod +x node_modules/.bin/redwood && yarn redwood generate scaffold MyModel
```

### Unlinking Packages

Lastly, to reverse the process and remove the links, work backwords using `yarn unlink`. Starting first from the local redwood sandbox app root
You can build a particular package by specifying the path to the package: `./tasks/publish-local ./packages/api`.

```
yarn unlink @redwoodjs/cli
yarn install --force
```
#### Installing published packages

_The latter command reinstalls the current published package._
Redwood installs `rwdev` a companion CLI development tool that makes installing local npm packages easy: `yarn rwdev install @redwoodjs/dev-server`.

Then from the package directory `/redwoodjs/redwood/packages/cli` of your local clone, run:
This is equivilant to running:

```
yarn unlink
yarn install --force
```terminal
rm -rf <PROJECT_PATH>/node_modules/@redwoodjs/dev-server
yarn upgrade @redwoodjs/dev-server@dev --no-lockfile --registry http://localhost:4873/
```

### Running the Local Server(s)
## Running the Local Server(s)

You can run both the API and Web servers with a single command:

```
```terminal
yarn rw dev
```

However, for local package development, you'll need to manually stop/start the respective server to include changes. In this case you can run the servers for each of the yarn workspaces independently:

```
```terminal
yarn rw dev api
yarn rw dev web
```
Expand All @@ -97,7 +104,7 @@ _Historical note: originally implemented in react-ink (too slow!) then converted

Example dev command:

```
```javascript
export const command = 'dev [app..]'
export const desc = 'Run development servers.'
export const builder = {
Expand Down
29 changes: 29 additions & 0 deletions docs/connectionPooling.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Connection Pooling

Production Redwood apps should enable connection pooling in order to properly scale with your Serverless functions.

## Heroku
For Postgres, see [Postgres Connection Pooling](https://devcenter.heroku.com/articles/postgres-connection-pooling).

Heroku does not officially support MySQL.


## Digital Ocean
For Postgres, see [How to Manage Connection Pools](https://www.digitalocean.com/docs/databases/postgresql/how-to/manage-connection-pools)

Connection Pooling for MySQL is not yet supported.

## AWS
Use [Amazon RDS Proxy] https://aws.amazon.com/rds/proxy for MySQL or RDS PostgreSQL.


## Why Connection Pooling?

Relational databases have a maximum number of concurrent client connections.

* Postgres allows 100 by default
* MySQL allows 151 by default

In a traditional server environment, you would need a large amount of traffic (and therefore web servers) to exhaust these connections, since each web server instance typically leverages a single connection.

In a Serverless environment, each function connects directly to the database, which can exhaust limits quickly. To prevent connection errors, you should add a connection pooling service in front of your database. Think of it as a load balancer.
56 changes: 56 additions & 0 deletions docs/localPostgresSetup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Local Postgres Setup

RedwoodJS uses a SQLite database by default. While SQLite makes local development easy, you're
likely going to want to run the same database setup you use on production. Here's how to set up
Postgres.

## Install Postgres

Ensure you have Postgres installed and running on your machine. If you're on a Mac, we recommend
Homebrew:

```bash
brew install postgres
```

Follow the instructions provided. If you're using another platform, See
[postgresql.org/download](https://www.postgresql.org/download/).

## Update the Prisma Schema

Tell Prisma to use a Postgres database instead of SQLite by updating the `provider` attribute in your
`schema.prisma` file:

```prisma
// prisma/schema.prisma
datasource DS {
provider = "postgres"
url = env("DATABASE_URL")
}
```

Add a `DATABASE_URL` to your `.env` file with the URL of the database you'd like to use locally. The
following example uses `redwoodblog_dev` for the database. It also has `postgres` setup as a
superuser for ease of use.

```env
DATABASE_URL="postgresql://postgres@localhost/redwoodblog_dev?connection_limit=1"
```

Note the `connection_limit` parameter. This is [recommended by Prisma](https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-client/deployment#recommended-connection-limit) when working with
relational databases in a Serverless context. You should also append this parameter to your production
`DATABASE_URL` when configuring your deployments.

If you've already created migrations using SQLite, you just need to run migrations again:

```bash
yarn rw db up
```

If you haven't created migrations yet, use `save`:

```bash
yarn rw db save
```

Both commands will create and migrate the Postres database you specified in your `.env`.
4 changes: 4 additions & 0 deletions docs/redwood.toml.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ The port number (integer) to listen to for the web side.

TODO

### includeEnvironmentVariables

The set of environment variable keys (list of strings) to include for the web side, in addition to any that are prefixed with `REDWOOD_ENV_`.

## [api]

This table contains the configuration for api side.
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.4.0",
"version": "0.5.0",
"npmClient": "yarn",
"useWorkspaces": true,
"command": {
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
"typescript": "^3.8.3"
},
"eslintConfig": {
"extends": "@redwoodjs/eslint-config"
"extends": "@redwoodjs/eslint-config",
"ignorePatterns": [
"fixtures"
]
},
"eslintIgnore": [
"dist",
Expand All @@ -34,6 +37,7 @@
"build:clean": "lerna run build:clean",
"build:js": "cross-env NODE_ENV=production lerna run build",
"build:types": "tsc --build --clean && tsc --build",
"build:watch": "lerna run build:watch --parallel",
"test": "lerna run test --stream -- --colors",
"lint": "yarn eslint packages",
"lint:fix": "yarn eslint --fix packages"
Expand Down
11 changes: 7 additions & 4 deletions packages/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@redwoodjs/api",
"version": "0.4.0",
"version": "0.5.0",
"files": [
"dist",
"importAll.macro.js"
Expand All @@ -9,8 +9,8 @@
"types": "./dist/main.d.ts",
"license": "MIT",
"dependencies": {
"@prisma/client": "2.0.0-beta.1",
"@redwoodjs/internal": "^0.4.0",
"@prisma/client": "2.0.0-beta.2",
"@redwoodjs/internal": "^0.5.0",
"apollo-server-lambda": "2.11.0",
"babel-plugin-macros": "^2.8.0",
"core-js": "3.6.4",
Expand All @@ -37,7 +37,10 @@
]
},
"scripts": {
"build": "yarn del-cli importAll.macro.js && yarn cross-env NODE_ENV=production babel src -d dist --delete-dir-on-start --extensions \".js,.ts\" --source-maps inline",
"build": "yarn build:js && yarn build:types && yarn move-cli dist/importAll.macro.js ./importAll.macro.js",
"build:js": "yarn del-cli importAll.macro.js && yarn cross-env NODE_ENV=production babel src -d dist --delete-dir-on-start --extensions \".js,.ts\" --source-maps inline",
"build:types": "tsc --declaration --emitDeclarationOnly",
"prepublishOnly": "yarn build",
"build:watch": "nodemon --watch src -e ts,js --ignore dist --exec 'yarn build'",
"test": "yarn jest",
"test:watch": "yarn test --watch"
Expand Down
15 changes: 0 additions & 15 deletions packages/cli/__mocks__/@redwoodjs/internal.js

This file was deleted.

5 changes: 0 additions & 5 deletions packages/cli/__mocks__/fs.js

This file was deleted.

1 change: 1 addition & 0 deletions packages/cli/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module.exports = {
testMatch: ['**/__tests__/**/*.[jt]s?(x)', '**/*.test.[jt]s?(x)'],
testPathIgnorePatterns: ['fixtures'],
}
Loading

0 comments on commit 21dd173

Please sign in to comment.