diff --git a/packages/compat/src/build-compat-addon.ts b/packages/compat/src/build-compat-addon.ts index bb259525f..96a7d5bfc 100644 --- a/packages/compat/src/build-compat-addon.ts +++ b/packages/compat/src/build-compat-addon.ts @@ -5,7 +5,7 @@ import broccoliMergeTrees from 'broccoli-merge-trees'; import { Node } from 'broccoli-node-api'; import OneShot from './one-shot'; import Funnel from 'broccoli-funnel'; -import { UnwatchedDir } from 'broccoli-source'; +import { UnwatchedDir, WatchedDir } from 'broccoli-source'; import EmptyPackageTree from './empty-package-tree'; export default function cachedBuildCompatAddon(originalPackage: Package, v1Cache: V1InstanceCache): Node { @@ -22,7 +22,7 @@ function buildCompatAddon(originalPackage: Package, v1Cache: V1InstanceCache): N // non-native-v2 addon. (The non-native one will get rewritten and // therefore moved, so to continue depending on it the native one needs to // move too.) - return withoutNodeModules(originalPackage.root); + return withoutNodeModules(originalPackage); } let oldPackages = v1Cache.getAddons(originalPackage.root); @@ -49,8 +49,9 @@ function buildCompatAddon(originalPackage: Package, v1Cache: V1InstanceCache): N } } -function withoutNodeModules(root: string): Node { - return new Funnel(new UnwatchedDir(root), { +function withoutNodeModules(originalPackage: Package): Node { + let Klass = originalPackage.mayRebuild ? WatchedDir : UnwatchedDir; + return new Funnel(new Klass(originalPackage.root), { exclude: ['node_modules'], }); } diff --git a/packages/compat/src/compat-addons.ts b/packages/compat/src/compat-addons.ts index edce88c4a..dba557c1f 100644 --- a/packages/compat/src/compat-addons.ts +++ b/packages/compat/src/compat-addons.ts @@ -11,6 +11,7 @@ import Options, { optionsWithDefaults } from './options'; import V1App from './v1-app'; import { createHash } from 'crypto'; import TreeSync from 'tree-sync'; +import { WatchedDir } from 'broccoli-source'; export default class CompatAddons implements Stage { private didBuild = false; @@ -42,9 +43,18 @@ export default class CompatAddons implements Stage { get tree(): Node { let movedAddons = [...this.packageCache.moved.keys()].map(oldPkg => buildCompatAddon(oldPkg, this.v1Cache)); + + // these get watched so that EMBROIDER_REBUILD_ADDONS will still work + // correctly, even for v2 addons that have no v1 addon deps and therefore + // don't need to be moved. We don't consume these trees in our build step, + // we only do this to trigger rebuilds to happen. + let watchedUnmovedAddons = [...this.packageCache.unmovedAddons] + .filter(pkg => pkg.mayRebuild) + .map(pkg => new WatchedDir(pkg.root)); + let { synthVendor, synthStyles } = this.getSyntheticPackages(this.v1Cache.app, movedAddons); return new WaitForTrees( - { movedAddons, synthVendor, synthStyles }, + { movedAddons, synthVendor, synthStyles, watchedUnmovedAddons }, '@embroider/compat/addons', this.build.bind(this) ); diff --git a/packages/compat/src/moved-package-cache.ts b/packages/compat/src/moved-package-cache.ts index 85068ccf4..30619deeb 100644 --- a/packages/compat/src/moved-package-cache.ts +++ b/packages/compat/src/moved-package-cache.ts @@ -33,6 +33,7 @@ export class MovedPackageCache extends PackageCache { readonly appDestDir: string; private commonSegmentCount: number; readonly moved: Map = new Map(); + readonly unmovedAddons: Set; constructor( rootCache: PackageCache['rootCache'], @@ -82,6 +83,7 @@ export class MovedPackageCache extends PackageCache { } this.rootCache = rootCache; this.resolutionCache = resolutionCache; + this.unmovedAddons = movedSet.unmovedAddons; } private movedPackage(originalPkg: Package): Package { @@ -215,6 +217,7 @@ function pathSegments(filename: string) { class MovedSet { private mustMove: Map = new Map(); + unmovedAddons: Set = new Set(); constructor(private app: Package) { this.check(app); @@ -256,6 +259,11 @@ class MovedSet { mustMove = this.check(dep) || mustMove; } this.mustMove.set(pkg, mustMove); + + if (!mustMove) { + this.unmovedAddons.add(pkg); + } + return mustMove; }