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

support EMBROIDER_REBUILD_ADDONS for pure v2 addons #715

Merged
merged 1 commit into from
Mar 9, 2021
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
9 changes: 5 additions & 4 deletions packages/compat/src/build-compat-addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
Expand All @@ -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'],
});
}
12 changes: 11 additions & 1 deletion packages/compat/src/compat-addons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
);
Expand Down
8 changes: 8 additions & 0 deletions packages/compat/src/moved-package-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export class MovedPackageCache extends PackageCache {
readonly appDestDir: string;
private commonSegmentCount: number;
readonly moved: Map<Package, Package> = new Map();
readonly unmovedAddons: Set<Package>;

constructor(
rootCache: PackageCache['rootCache'],
Expand Down Expand Up @@ -82,6 +83,7 @@ export class MovedPackageCache extends PackageCache {
}
this.rootCache = rootCache;
this.resolutionCache = resolutionCache;
this.unmovedAddons = movedSet.unmovedAddons;
}

private movedPackage(originalPkg: Package): Package {
Expand Down Expand Up @@ -215,6 +217,7 @@ function pathSegments(filename: string) {

class MovedSet {
private mustMove: Map<Package, boolean> = new Map();
unmovedAddons: Set<Package> = new Set();

constructor(private app: Package) {
this.check(app);
Expand Down Expand Up @@ -256,6 +259,11 @@ class MovedSet {
mustMove = this.check(dep) || mustMove;
}
this.mustMove.set(pkg, mustMove);

if (!mustMove) {
this.unmovedAddons.add(pkg);
}

return mustMove;
}

Expand Down