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

Add broccoli-side-watch package #1693

Merged
Merged
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
21 changes: 21 additions & 0 deletions packages/broccoli-side-watch/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# @embroider/broccoli-side-watch

A micro library that allows watching folders for changes outside the `app` folder in Ember apps

## Usage

Let's assume you have a v2 addon in the `grand-prix` folder of your top-level folder of your Ember app.

Every time you change something in the source of that add-on, you can rebuild it by watching the addon's build (currently using Rollup). However, by default the host Ember app doesn't rebuild automatically, so you have to restart the Ember app every time this happens which is a slog.

With this library, you can add the following to your `ember-cli-build.js` to vastly improve your life as a developer:

```js
const sideWatch = require('@embroider/broccoli-side-watch');

const app = new EmberApp(defaults, {
trees: {
app: sideWatch('app', { watching: ['./grand-prix/src'] }),
},
});
```
24 changes: 24 additions & 0 deletions packages/broccoli-side-watch/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// From https://github.com/cardstack/boxel/blob/d54f834f/packages/host/lib/with-side-watch.js (MIT license)

const mergeTrees = require('broccoli-merge-trees');
const { WatchedDir } = require('broccoli-source');
const Plugin = require('broccoli-plugin');

class BroccoliNoOp extends Plugin {
constructor(path) {
super([new WatchedDir(path)]);
}
build() {}
}

/*
Doesn't change your actualTree, but causes a rebuild when any of opts.watching
trees change.

This is helpful when your build pipeline doesn't naturally watch some
dependencies that you're actively developing. For example, right now
@embroider/webpack doesn't rebuild itself when non-ember libraries change.
*/
module.exports = function sideWatch(actualTree, opts) {
return mergeTrees([actualTree, ...opts.watching.map(w => new BroccoliNoOp(w))]);
};
16 changes: 16 additions & 0 deletions packages/broccoli-side-watch/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "@embroider/broccoli-side-watch",
"version": "0.0.1",
"description": "Watch changes in other folders to rebuild Ember app",
"main": "index.js",
"keywords": [
"ember"
],
"author": "Balint Erdi",
"license": "MIT",
"dependencies": {
"broccoli-merge-trees": "^4.2.0",
"broccoli-plugin": "^4.0.7",
"broccoli-source": "^3.0.1"
}
}
12 changes: 12 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.