|
4 | 4 | * Sucrase plugin docs: https://github.com/rollup/plugins/tree/master/packages/sucrase
|
5 | 5 | */
|
6 | 6 |
|
| 7 | +import * as path from 'path'; |
| 8 | + |
7 | 9 | // We need both replacement plugins because one handles regex and the other runs both before and after rollup does its
|
8 | 10 | // bundling work.
|
9 | 11 | import regexReplace from 'rollup-plugin-re';
|
@@ -98,4 +100,38 @@ export function makeRemoveBlankLinesPlugin() {
|
98 | 100 | });
|
99 | 101 | }
|
100 | 102 |
|
| 103 | +/** |
| 104 | + * Create a plugin to manually add packages to a build's watch. |
| 105 | + * |
| 106 | + * Unlike tsc, rollup doesn't seem to be able to follow the symlinks that yarn workspaces uses to link our packages into |
| 107 | + * one another, with the result that changes don't automatically cascade in watch mode. This plugin sets that up |
| 108 | + * manually. |
| 109 | + * |
| 110 | + * TODO: This currently only works when running `build:watch` or `build:dev:watch` at the repo level, not the individual |
| 111 | + * package level. |
| 112 | + * |
| 113 | + * TODO: At the moment, in the interests (current) time and (future) build spped, the watch list for each package is |
| 114 | + * hardcoded into its rollup config. While the values in those lists are likely to be highly stable over time, there's |
| 115 | + * also no mechanism to guarantee that changes in a package's intra-package dependencies will be reflected in the lists. |
| 116 | + * It shouldn't be that hard to write a script to generate the correct lists at build time, though, and hopefully it |
| 117 | + * wouldn't add a ton of time to the build. (It'd be a lot of file IO reading all of the `package.json` files, but |
| 118 | + * computers are also fast. We'd have to experiement.) |
| 119 | + * |
| 120 | + * @param watchPackages The packages to watch. Shouldn't include any transitive dependencies, even if they're also |
| 121 | + * direct dependencies. (In other words, if A depends on B and C, and B depends on C, then A should only list B, not C.) |
| 122 | + * |
| 123 | + * @returns A plugin which will add the given packages to a build's watch list if the build is running in watch mode. |
| 124 | + */ |
| 125 | +export function makeWatchDependenciesPlugin(watchPackages) { |
| 126 | + return { |
| 127 | + name: 'watch-dependencies', |
| 128 | + buildStart: function () { |
| 129 | + if (this.meta.watchMode) { |
| 130 | + const cwd = process.cwd(); |
| 131 | + watchPackages.forEach(pkg => this.addWatchFile(path.resolve(cwd, `../${pkg}`))); |
| 132 | + } |
| 133 | + }, |
| 134 | + }; |
| 135 | +} |
| 136 | + |
101 | 137 | export { makeExtractPolyfillsPlugin } from './extractPolyfillsPlugin.js';
|
0 commit comments