Skip to content

Commit

Permalink
Merge pull request #1693 from balinterdi/add-broccoli-side-watch-package
Browse files Browse the repository at this point in the history
Add broccoli-side-watch package
  • Loading branch information
ef4 authored Dec 3, 2023
2 parents 05badd2 + 2f24591 commit ba9fd29
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
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.

0 comments on commit ba9fd29

Please sign in to comment.