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

Remove Lerna #450

Merged
merged 13 commits into from
Jan 17, 2023
8 changes: 8 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
16 changes: 16 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": [
"@changesets/changelog-github",
{
"repo": "twilio-labs/serverless-toolkit"
}
],
"commit": false,
"fixed": [],
"linked": [],
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}
6 changes: 6 additions & 0 deletions .changeset/rare-gifts-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'twilio-run': patch
'@twilio-labs/plugin-serverless': patch
---

Removed key/value argument check from env:import command
21 changes: 11 additions & 10 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
name: Node CI

on:
push:
branches:
- main
- master
- 'features/*'
workflow_call:
# This gets run by on-merge-main.yml automatically
# push:
# branches:
# - main
# - master
# - 'features/*'
dkundel marked this conversation as resolved.
Show resolved Hide resolved
pull_request:
branches:
- main
Expand All @@ -19,12 +21,12 @@ jobs:
fail-fast: false
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
node-version: [14, 16]
node-version: [ lts/-2, lts/-1, lts/*]

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Update npm to 8.x
Expand All @@ -33,8 +35,7 @@ jobs:
- name: npm install, build, and test
run: |
npm install
npm run bootstrap
npm run build --if-present
npm run build
npm run test
env:
CI: true
Expand Down
42 changes: 42 additions & 0 deletions .github/workflows/on-merge-main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Merge to main

on:
push:
branches:
- main

jobs:
tests:
name: Run tests
uses: twilio-labs/serverless-toolkit/.github/workflows/nodejs.yml@main

release:
name: Run release work
needs: tests
runs-on: ubuntu-latest

steps:
- name: Checkout Repo
uses: actions/checkout@v3
- name: Setup Node.js 16
uses: actions/setup-node@v3
with:
node-version: 16
- name: Update npm to 8.x
run: |
npm i -g npm@8
dkundel marked this conversation as resolved.
Show resolved Hide resolved
- name: Install Dependencies
run: npm install
- name: Setup CI Git User
run: |
git config user.name twilio-labs-ci
git config user.email [email protected]
- name: "Create Pull Request or Publish to npm"
uses: changesets/action@v1
with:
version: npm run version
publish: npm run npm:publish
commit: "chore: version packages"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ To understand more about the structure and the design of the Toolkit check out t

## Setup & Development

This project uses [`lerna`](https://npm.im/lerna) as a tool to manage the monorepo. If you are unfamiliar with the tool, start by checking out the the [lerna docs](https://lerna.js.org/).
This project uses [`npm` workspaces](https://docs.npmjs.com/cli/v8/using-npm/workspaces) as a tool to manage the monorepo. If you are unfamiliar with the tool, start by checking out the the [`npm` docs](https://docs.npmjs.com/cli/v7/using-npm/workspaces) and make sure you use at least npm version 8 or newer (`npm install -g npm@8`).

```bash
git clone [email protected]:twilio-labs/serverless-toolkit.git
cd serverless-toolkit
npm install
npm run bootstrap
npm run build
```

## License
Expand Down
8 changes: 7 additions & 1 deletion commitlint.config.js
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
module.exports = { extends: ['@commitlint/config-conventional'] };
module.exports = {
extends: ['@commitlint/config-conventional'],
plugins: ['workspace-scopes'],
rules: {
'scope-enum': [2, 'always', []],
},
};
69 changes: 21 additions & 48 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## About the Project

This project is a "monorepo" meaning it contains several Node.js packages in one repository. The code for all packages are in the [`packages/`](../packages) directory. We are using a tool called [Lerna](https://lerna.js.org) to manage those multiple packages.
This project is a "monorepo" meaning it contains several Node.js packages in one repository. The code for all packages are in the [`packages/`](../packages) directory. We are using a concept called [`npm` workspaces](https://docs.npmjs.com/cli/v8/using-npm/workspaces) to manage those multiple packages and a tool called [`changesets`](https://github.com/changesets/changesets) to handle the versioning and releasing.

## Before you contribute

Expand All @@ -14,10 +14,10 @@ If you are planning to contribute something that does not have an open issue yet

## Requirements

Make sure you have Node.js 12 or newer installed. Due to compatibility with Twilio
Functions this project has to support at least Node.js 12.0.0.
Make sure you have Node.js 14 or newer installed. Due to compatibility with Twilio
Functions this project has to support at least Node.js 14.0.0.
dkundel marked this conversation as resolved.
Show resolved Hide resolved

We are using the npm CLI to manage our project. You should be able to use yarn but you might hit some issues.
We are using the npm CLI to manage our project. You'll need at least `npm` version 8 or newer.

## Setup your local project

Expand All @@ -32,79 +32,52 @@ npm run bootstrap

## Contributing

1. Perform changes. Check out [Working with Lerna](#working-with-lerna) for more info
1. Perform changes. Check out [Working with Workspaces](#working-with-workspaces) for more info
2. Make sure tests pass by running `npm test`
3. Stage the files you changed by running `git add` with the files you changed.
4. Run `git commit` to kick off validation and enter your commit message. We are using [conventional commits](https://www.conventionalcommits.org/en/) for this project. When you run `npm run cm` it will trigger [`commitizen`](https://npm.im/commitizen) to assist you with your commit message.
5. Submit a Pull Request
4. If you have a customer facing change make sure to run `npm run changeset` at the root of the project, select what type of version change it is and which packages are impacted and describe the change. Check out ["How we version"](#how-we-version) for more details.
5. Run `git commit` to kick off validation and enter your commit message. We are using [conventional commits](https://www.conventionalcommits.org/en/) for this project. When you run `npm run cm` it will trigger [`commitizen`](https://npm.im/commitizen) to assist you with your commit message.
6. Push your changes and submit a Pull Request

**Working on your first Pull Request?** You can learn how from this _free_ series [How to Contribute to an Open Source Project on GitHub](https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github)

## For Maintainers: Releasing

This project uses [`lerna version`](https://www.npmjs.com/package/@lerna/version) to create new releases for any package needed, create the respective git tag and update the necessary `CHANGELOG.md` files. We always pass certain flags, so please use it via `npm run release`. Here are the steps you need to run to release a new version:
Version bumps are handled automatically by [this GitHub Action](../.github/workflows/on-merge-main.yml) whenever changes have been merged to `main`. If the automation will detect any changeset files inside the `.changeset` directory it will either open a new Pull Request to bump the version or force-push to the currently open Pull Request. In order to release to `npm` you'll have to merge that Pull Request which will automatically kick off the release.

### Pre-release version (from `main` or any `features/*` branch):
## How we version

For example to release a new pre-release version containing `beta` and releasing it as `next`:
All packages that are part of this project follow the [SemVer convention](https://semver.org/). Specifically this means the following version changes apply for the following changes:
- `no change` (no changeset) - Changes in `devDependencies`, changes at the root of the project that don't result in a compilation output change, test changes, documentation changes, etc.
- `patch` - Any changes that do not add new features such as bug fixes that are not altering the behavior
- `minor` - New features that are additive and are not breaking current behavior
- `major` - Any changes that are breaking changes incl. dropping support for features or arguments or drastic changes in behavior

```bash
npm run release -- --conventional-prerelease --exact --preid beta
git push origin main --follow-tags
npm run npm:publish -- --otp=<OTP> --dist-tag next
```

If you want to turn a prerelease into a permanent version you can use:

```bash
npm run release -- --conventional-commits --conventional-graduate
git push origin main --follow-tags
npm run npm:publish -- --otp=<OTP>
```

### Normal release (from `main` branch):

For a normal release `standard-version` will detect the version increment automatically. Run:

```bash
npm run release
git push origin main --follow-tags
npm run npm:publish -- --otp=<OTP>
```

To ship a specific version instead (like a forced minor bump) you can run:

```bash
npm run release -- minor
git push origin main --follow-tags
npm run npm:publish -- --otp=<OTP>
```

## Working with Lerna
## Working with Workspaces

### Linking Packages

Lerna will automatically link together the different dependencies that are part of the project. You can run `npm run bootstrap` to create the links.
npm will automatically link together the different dependencies that are part of the project when you run `npm install` at the root.

### Installing Dependencies

Dev dependencies should ideally be installed at the top level using `npm install --save-dev`. If you want to execute a binary from a dependency in a particular package you should install it in that particular package instead.

Installing dependencies for packages can be done in two ways. You can either use the [`lerna add` command](https://github.com/lerna/lerna/tree/master/commands/add) or using `npm install` inside the respective package.
Installing dependencies for packages can be done in two ways. You can either use the `npm install <package-name> -w <package-to-install-dependency-in>` command (ex. `npm install lodash -w @twilio-labs/serverless-api`) or using `npm install` inside the respective package.

The later might be the more intuitive one but it might cause some bootstraping issues.

### Running Scripts

Scripts that are on the top level can be run via `npm run <script>`.

If you want to run a script in every individual package where it is defined you can run: [`lerna run <script>`](https://github.com/lerna/lerna/tree/master/commands/run).
If you want to run a script in every individual package where it is defined you can run: [`npm run <script> --workspaces --if-present`](https://docs.npmjs.com/cli/v8/using-npm/workspaces?v=true#running-commands-in-the-context-of-workspaces).

To execute any bash command inside every package you can use [`lerna exec`](https://github.com/lerna/lerna/tree/master/commands/exec).
To execute any bash command inside every package you can use [`npm exec`](https://docs.npmjs.com/cli/v8/commands/npm-exec).

### Resetting dependencies

You can run `lerna clean` to delete all `node_modules` folder. To reinstall them run `npm run bootstrap`
You can run `npm run reset` to delete all `node_modules` folder. To reinstall them run `npm install`

## Code of Conduct

Expand Down
21 changes: 0 additions & 21 deletions lerna.json

This file was deleted.

51 changes: 29 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,46 @@
"name": "@twilio-labs/serverless-toolkit",
"private": true,
"scripts": {
"bootstrap": "lerna bootstrap --no-ci",
"postbootstrap": "lerna run build",
"release": "lerna version --conventional-commits --no-commit-hooks --no-push",
"npm:publish": "lerna publish from-git",
"bootstrap": "npm run build",
"build": "npm run build --workspaces --if-present",
"changeset": "changeset",
"version-packages": "npm run create-version && npm run version-package --workspaces --if-present",
"create-version": "changeset version",
"npm:publish": "changeset publish",
"cm": "git-cz",
"jest": "jest",
"build:noemit": "lerna run build:noemit",
"clean": "lerna run clean",
"build:noemit": "npm run build:noemit --workspaces --if-present",
"clean": "npm run clean --workspaces --if-present",
"test": "run-s build:noemit jest",
dkundel marked this conversation as resolved.
Show resolved Hide resolved
"contrib:add": "all-contributors add",
"contrib:generate": "all-contributors generate",
"lint-staged": "lint-staged",
"docs": "lerna run docs",
"docs": "npm run docs --workspaces --if-present",
"prepare": "husky install",
"pre-commit": "lint-staged"
"pre-commit": "lint-staged",
"reset": "npm exec --workspaces -- npx rimraf node_modules && npx rimraf node_modules"
},
"devDependencies": {
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.26.0",
"@commitlint/cli": "^9.1.2",
"@commitlint/config-conventional": "^10.0.0",
"@types/jest": "^26.0.24",
"@types/jest": "^29.2.4",
"all-contributors-cli": "^6.1.2",
"commitizen": "^4.2.4",
"commitlint-plugin-workspace-scopes": "^1.1.0",
"conventional-changelog-cli": "^2.1.0",
"cz-conventional-changelog": "^2.1.0",
"husky": "^7.0.0",
"jest": "^26.6.3",
"husky": "^8.0.2",
"jest": "^28.1.3",
"jest-express": "^1.10.1",
"lerna": "^4.0.0",
"lint-staged": "^9.0.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.2.1",
"rimraf": "^3.0.2",
"ts-jest": "^26.5.0",
"typescript": "^3.9.7"
},
"overrides": {
"@types/prettier": "2.6.0",
"@types/express-serve-static-core": "ts3.9",
"@types/lodash": "ts3.9",
"@types/babel__traverse": "ts3.9"
"ts-jest": "^28.0.8",
"typescript": "^4.9.4",
"@twilio/test-dep": "npm:[email protected]"
},
"lint-staged": {
"*.{js,jsx,ts,tsx}": [
Expand All @@ -53,5 +53,12 @@
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
}
}
},
"workspaces": [
"./packages/serverless-api",
"./packages/serverless-runtime-types",
"./packages/runtime-handler",
"./packages/twilio-run",
"./packages/*"
]
}
2 changes: 1 addition & 1 deletion packages/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Packages Overview

This repository is structured as a monorepo using [Lerna](https://lerna.js.org) and contains multiple packages:
This repository is structured as a monorepo using [`npm` workspaces](https://docs.npmjs.com/cli/v8/using-npm/workspaces) and contains multiple packages:

| Package | Description | Changelog | |
| :-------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
Expand Down
2 changes: 0 additions & 2 deletions packages/create-twilio-function/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"bin": "./bin/create-twilio-function",
"main": "./src/create-twilio-function.js",
"scripts": {
"jest": "jest"
},
"keywords": [
"twilio",
Expand All @@ -27,7 +26,6 @@
"license": "MIT",
"devDependencies": {
"@twilio/runtime-handler": "^1.3.0",
"jest": "^26.6.3",
"nock": "^11.3.4"
},
"dependencies": {
Expand Down
Loading