Skip to content

Commit

Permalink
feat: open source
Browse files Browse the repository at this point in the history
  • Loading branch information
evocateur committed Aug 31, 2018
0 parents commit ce2d5cb
Show file tree
Hide file tree
Showing 50 changed files with 13,344 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 4
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[{package.json,lerna.json}]
indent_style = space
indent_size = 2

[*.yaml]
indent_style = space
indent_size = 2
33 changes: 33 additions & 0 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
extends:
- plugin:zillow/recommended
- plugin:zillow/jest
- plugin:node/recommended
env:
browser: false
node: true
plugins:
- node
rules:
node/no-unsupported-features:
- error
# version controlled by "engines" field in package.json
padding-line-between-statements:
- error
# blank line before return statements
- { blankLine: "always", prev: "*", next: "return" }
# blank line after const/let statement(s)
- { blankLine: "always", prev: ["const", "let"], next: "*" }
- { blankLine: "any", prev: ["const", "let"], next: ["const", "let"] }
# blank line before and after multi-line block-like statements
- { blankLine: "always", prev: "*", next: "multiline-block-like" }
- { blankLine: "always", prev: "multiline-block-like", next: "*" }
strict: off
root: true
overrides:
- files:
- "packages/*/test/**"
rules:
# dev dependencies are hoisted to the root
zillow/import/no-extraneous-dependencies: off
node/no-extraneous-require: off
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
coverage
dist
*.log
.vscode
4 changes: 4 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'use strict';

// just here so the editor plugins don't get fired
module.exports = require('eslint-plugin-zillow/prettier.config');
15 changes: 15 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ISC License

Copyright (c) 2018, Daniel Stockman

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
68 changes: 68 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Pectin

> [Rollup][]-related tools for incremental transpilation of packages in [Lerna][]-based monorepos
## Getting Started

The easiest way to start using Pectin is to install the CLI and run it during an npm lifecycle, such as `"prerelease"`:

```sh
npm i -D @pectin/cli
```

In your monorepo's root `package.json` (aka "manifest"):

```json
{
"scripts": {
"clean": "git clean -fdx packages",
"prerelease": "npm run clean && pectin",
"release": "lerna publish",
"lint": "eslint .",
"pretest": "pectin && npm run lint",
"test": "jest"
}
}
```

Configured this way, you can always ensure your packages have the latest build output whenever anyone executes `npm run release` _or_ incrementally build recent changes before `npm test`.

Once installed locally, you can experiment with the CLI via `npx`:

```sh
npx pectin -h
```

To watch packages and rebuild on source change, pass `-w`, just like Rollup's CLI:

```sh
npx pectin -w
```

## Motivation

One advantage of a [Lerna][] monorepo is that you can reduce the amount of repetition between modules by running all development-related tasks (build, lint, test, and so on) from the root of the repository instead of each package one-by-one. This works fine for tools that are capable of running over many packages simultaneously without breaking a sweat, like `jest` and `eslint`.

Running Rollup builds over many different package roots, however, is a much trickier business. Pectin was built to facilitate running Rollup builds for all packages in a monorepo, with special consideration for unique monorepo circumstances such as incremental builds, npm lifecycle behavior, and per-package options.

For example, it isn't always the case that _every_ package in a monorepo actually needs to be rebuilt every time the build is run. Consider running `jest --watch` in a monorepo with 15 packages, but you're only working on one. The naïve approach finds all the packages and passes all of them to Rollup, which means Rollup builds for every package. Pectin optimizes this by testing the "freshness" of the built output against the source tree and only building when a file in the source tree has a more recent change (a higher `mtime`, for filesystem wizards).

Pectin's CLI was written to seamlessly wrap `rollup`. It helps avoid, among other things, Rollup's CLI emitting a warning and exiting non-zero when you pass an empty array (that is, no changes since the last build) to Rollup via the default export of `rollup.config.js`. Pectin's CLI supports all options supported by Rollup's CLI.

## Packages

- [`@pectin/api`](./packages/pectin-api)
- [`@pectin/babelrc`](./packages/pectin-babelrc)
- [`@pectin/cli`](./packages/pectin-cli)
- [`@pectin/core`](./packages/pectin-core)
- [`rollup-config-pectin`](./packages/rollup-config-pectin)
- [`rollup-plugin-main-entry`](./packages/rollup-plugin-main-entry)
- [`rollup-plugin-subpath-externals`](./packages/rollup-plugin-subpath-externals)

## Related

- [Lerna][]
- [Rollup][]

[lerna]: https://github.com/lerna/lerna#readme
[rollup]: https://github.com/rollup/rollup#readme
19 changes: 19 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

// http://facebook.github.io/jest/docs/en/configuration.html#content
module.exports = {
clearMocks: true,
collectCoverageFrom: ['**/lib/*.js'],
coverageDirectory: '<rootDir>/coverage',
coverageReporters: ['cobertura', 'html', 'text'],
coverageThreshold: {
global: {
branches: 100,
functions: 100,
lines: 100,
statements: 100,
},
},
roots: ['<rootDir>/packages'],
testEnvironment: 'node',
};
19 changes: 19 additions & 0 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"command": {
"publish": {
"allowBranch": "latest",
"conventionalCommits": true,
"message": "chore(release): %s"
}
},
"ignoreChanges": [
"**/__tests__/**",
"**/test/**",
"*.test.js",
"*.md"
],
"packages": [
"packages/*"
],
"version": "1.0.0"
}
Loading

0 comments on commit ce2d5cb

Please sign in to comment.