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

Initial work on moving to pnpm from npm #2213

Closed
wants to merge 5 commits into from
Closed
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: 3 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# Please see the documentation for all configuration options:
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

# TODO: update for pnpm when possible:
# https://github.com/dependabot/dependabot-core/issues/1736

version: 2
updates:
# Root package.json
Expand Down
87 changes: 59 additions & 28 deletions .github/workflows/node-js-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,22 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2.1.5
- name: Install dependencies and run prettier-check
- uses: pnpm/action-setup@v2.0.1
with:
version: 6.0.2
run_install: true
- name: Cache pnpm modules
uses: actions/cache@v2.1.5
env:
cache-name: cache-pnpm-modules
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-${{ hashFiles('**/package.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-
- name: Run prettier-check
run: |
npm install
npm run prettier-check
pnpm run prettier-check

# Make sure eslint passes
eslint:
Expand All @@ -28,10 +40,22 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2.1.5
- name: Install dependencies and run eslint
- uses: pnpm/action-setup@v2.0.1
with:
version: 6.0.2
run_install: true
- name: Cache pnpm modules
uses: actions/cache@v2.1.5
env:
cache-name: cache-pnpm-modules
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-${{ hashFiles('**/package.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-
- name: Run eslint
run: |
npm install
npm run eslint
pnpm run eslint

# Run unit tests on all platforms/versions of node
unit:
Expand All @@ -43,25 +67,25 @@ jobs:
node-version: [12.x, 14.x]
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2.1.5
- uses: actions/setup-node@v2.1.5
- uses: pnpm/action-setup@v2.0.1
with:
version: 6.0.2
run_install: true
- name: Cache pnpm modules
uses: actions/cache@v2.1.5
env:
cache-name: cache-node-modules
cache-name: cache-pnpm-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package.json') }}
path: ~/.pnpm-store
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-${{ hashFiles('**/package.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- uses: actions/setup-node@v2.1.5
with:
node-version: ${{ matrix.node-version }}
${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-
- name: Get number of CPU cores
uses: SimenB/github-actions-cpu-cores@v1
- name: Install dependencies and run tests with default env
- name: Run unit tests with default env
run: |
npm install
# pnpm can't handle passing args through to run scripts: https://github.com/pnpm/pnpm/issues/2764
npm run jest --max-workers ${{ steps.cpu-cores.outputs.count }}

# Run end-to-end tests along with the microservices in docker-compose on Linux
Expand All @@ -72,19 +96,26 @@ jobs:
matrix:
node-version: [12.x, 14.x]
steps:
- uses: actions/cache@v2.1.5
- uses: actions/checkout@v2
- uses: actions/setup-node@v2.1.5
- uses: pnpm/action-setup@v2.0.1
with:
version: 6.0.2
run_install: true
- name: Cache pnpm modules
uses: actions/cache@v2.1.5
env:
cache-name: cache-pnpm-modules
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
path: ~/.pnpm-store
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-${{ hashFiles('**/package.json') }}
restore-keys: |
${{ runner.os }}-buildx-
- uses: actions/checkout@v2
${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-
- uses: actions/setup-node@v2.1.5
with:
node-version: ${{ matrix.node-version }}
- uses: microsoft/playwright-github-action@v1
- name: Start microservices and run tests
- name: Start microservices and run e2e tests
run: |
npm install
npm run services:start
npm run jest:e2e
pnpm run services:start
pnpm run jest:e2e
81 changes: 55 additions & 26 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,48 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Cache pnpm modules
uses: actions/cache@v2.1.5
env:
cache-name: cache-pnpm-modules
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-${{ hashFiles('**/package.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-
- uses: actions/setup-node@v2.1.5
- name: Install dependencies and run prettier-check
- uses: pnpm/action-setup@v1.2.1
with:
version: 6.0.1
run_install: true
- name: Run prettier-check
run: |
npm install
npm run prettier-check
pnpm run prettier-check

# Make sure eslint passes
# Make sure eslint passes
eslint:
name: ESLint Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Cache pnpm modules
uses: actions/cache@v2.1.5
env:
cache-name: cache-pnpm-modules
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-${{ hashFiles('**/package.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-
- uses: actions/setup-node@v2.1.5
- name: Install dependencies and run eslint
- uses: pnpm/action-setup@v1.2.1
with:
version: 6.0.1
run_install: true
- name: Run eslint
run: |
npm install
npm run eslint
pnpm run eslint

# Run unit tests on all platforms/versions of node
unit:
Expand All @@ -43,26 +68,27 @@ jobs:
node-version: [12.x, 14.x]
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2.1.5
- name: Cache pnpm modules
uses: actions/cache@v2.1.5
env:
cache-name: cache-node-modules
cache-name: cache-pnpm-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package.json') }}
path: ~/.pnpm-store
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-${{ hashFiles('**/package.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-
- uses: actions/setup-node@v2.1.5
with:
node-version: ${{ matrix.node-version }}
- uses: pnpm/action-setup@v1.2.1
with:
version: 6.0.1
run_install: true
- name: Get number of CPU cores
uses: SimenB/github-actions-cpu-cores@v1
- name: Install dependencies and run tests with default env
- name: Run unit tests with default env
run: |
npm install
npm run jest --max-workers ${{ steps.cpu-cores.outputs.count }}
pnpm run jest --max-workers ${{ steps.cpu-cores.outputs.count }}

# Run end-to-end tests along with the microservices in docker-compose on Linux
e2e:
Expand All @@ -72,22 +98,25 @@ jobs:
matrix:
node-version: [12.x, 14.x]
steps:
- uses: actions/cache@v2.1.5
- uses: actions/checkout@v2
- name: Cache pnpm modules
uses: actions/cache@v2.1.5
env:
cache-name: cache-pnpm-modules
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
path: ~/.pnpm-store
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-${{ hashFiles('**/package.json') }}
restore-keys: |
${{ runner.os }}-buildx-
- uses: actions/checkout@v2
${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-
- uses: actions/setup-node@v2.1.5
with:
node-version: ${{ matrix.node-version }}
- uses: microsoft/playwright-github-action@v1
- name: Start microservices and run tests
- name: Start microservices and run e2e tests
run: |
npm install
npm run services:start
npm run jest:e2e
pnpm run services:start
pnpm run jest:e2e

release:
needs: [prettier, eslint, unit, e2e]
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run pre-commit
pnpm run pre-commit
8 changes: 0 additions & 8 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
# Don't create or read package-lock.json
package-lock=false
# Use exact versions of dependencies vs. semver minor updates
save-exact=true

# Allow running postinstall script in Docker
unsafe-perm=true

# Set empty tag version prefix
tag-version-prefix=""

#Set legacy peer dependencies to 'true', (needed for npm7.x compatibility for now)
legacy-peer-deps=true
45 changes: 36 additions & 9 deletions docs/environment-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

### Prerequisites:

- [Node.js (npm)](https://nodejs.org/en/download/)
- [Node.js](https://nodejs.org/en/download/)
- [pnpm](https://pnpm.io/) (we use `pnpm` vs. `npm` for package installation)
- [Redis](https://redis.io/) (2 methods)
- Use [Docker and docker-compose](https://docs.docker.com/install/)
- Install as a [native application](#Install-Redis-as-a-native-application)
Expand Down Expand Up @@ -137,6 +138,32 @@ _NOTE: This will not work on WSL (Windows Subsystem for Linux). Use the approach

## After installing the prerequisites:

### Installing Dependencies with pnpm

Telescope is structured as a [monrepo](https://en.wikipedia.org/wiki/Monorepo) with more than a dozen separate projects all contained within a single git repository. Because monorepos often share many of the same dependencies, there can be a lot of duplication (and waste) when installing packages.

To help reduce the number of packages that must be stored in `node_modules`, we use [pnpm](https://pnpm.io/) intead of the usual `npm` command. With [pnpm we can save a lot of disk space and installation time](https://pnpm.io/motivation).

The cost of using pnpm is that there are a few differences in how [packages are installed](https://pnpm.io/cli/install), [added to package.json](https://pnpm.io/cli/add), etc. The [docs](https://pnpm.io/pnpm-cli) have full details on how it works, and after a few minutes you'll have no trouble.

To install all of Telescope's dependencies, use the following command:

```bash
pnpm install
```

Similarly, to run tests:

```bash
pnpm test
```

And to run npm scripts:

```bash
pnpm run <script-name>
```

### Start Docker

```bash
Expand All @@ -162,9 +189,9 @@ _Note: Make sure you're running these commands in the root of telescope project.
This is the default setting, you do not need to copy or modify any `env` file.

```bash
npm run services:start
pnpm run services:start

npm run dev
pnpm run dev
```

Microservices will start downloading feeds and processing them until stopped. For more information about the services, please read [Telescope API Services](../src/api/readme.md).
Expand All @@ -176,7 +203,7 @@ If this doesn't work for you, it is possible that you have an old `.env` file in
```bash
cp config/env.staging .env

npm run dev
pnpm run dev
```

This will provide you staging back-end without running it locally.
Expand All @@ -190,22 +217,22 @@ This one depends on which part you're working with. For example, if you want to
After modify the `.env` file, run these commands,

```bash
npm run services:start
pnpm run services:start

npm run dev
pnpm run dev
```

#### Want to run `auth/image/posts` service solely

`npm run services:start auth` or `npm run services:start image` or `npm run services:start posts`
`pnpm run services:start auth` or `pnpm run services:start image` or `pnpm run services:start posts`

#### Want to update the Docker image(s) after making some changes

Run the following commands to rebuild the image(s):

```bash
npm run services:clean
npm run services:start
pnpm run services:clean
pnpm run services:start
```

#### Login/SSO:
Expand Down
Loading