diff --git a/packages/broccoli-side-watch/README.md b/packages/broccoli-side-watch/README.md new file mode 100644 index 000000000..0bc931eee --- /dev/null +++ b/packages/broccoli-side-watch/README.md @@ -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'] }), + }, +}); +``` diff --git a/packages/broccoli-side-watch/index.js b/packages/broccoli-side-watch/index.js new file mode 100644 index 000000000..441f57850 --- /dev/null +++ b/packages/broccoli-side-watch/index.js @@ -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))]); +}; diff --git a/packages/broccoli-side-watch/package.json b/packages/broccoli-side-watch/package.json new file mode 100644 index 000000000..7bb3fcd66 --- /dev/null +++ b/packages/broccoli-side-watch/package.json @@ -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" + } +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2c78f928a..ece15bae2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -146,6 +146,18 @@ importers: specifier: workspace:^ version: link:../core + packages/broccoli-side-watch: + dependencies: + broccoli-merge-trees: + specifier: ^4.2.0 + version: 4.2.0 + broccoli-plugin: + specifier: ^4.0.7 + version: 4.0.7 + broccoli-source: + specifier: ^3.0.1 + version: 3.0.1 + packages/compat: dependencies: '@babel/code-frame':