Skip to content

Commit

Permalink
Merge pull request #623 from simonihmig/optimize-watched-directories
Browse files Browse the repository at this point in the history
Optimize watched directories
  • Loading branch information
ef4 authored Sep 12, 2024
2 parents 3883cd8 + d874b84 commit 73b6acd
Show file tree
Hide file tree
Showing 6 changed files with 371 additions and 4 deletions.
23 changes: 22 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/ember-auto-import/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@
"fs-extra": "^10.0.0",
"fs-tree-diff": "^2.0.0",
"handlebars": "^4.3.1",
"is-subdir": "^1.2.0",
"js-string-escape": "^1.0.1",
"lodash": "^4.17.19",
"mini-css-extract-plugin": "^2.5.2",
"minimatch": "^3.0.0",
"parse5": "^6.0.1",
"pkg-entry-points": "^1.1.0",
"resolve": "^1.20.0",
"resolve-package-path": "^4.0.3",
"semver": "^7.3.4",
Expand Down
3 changes: 3 additions & 0 deletions packages/ember-auto-import/ts/auto-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ import type { TransformOptions } from '@babel/core';
import { MARKER } from './analyzer-syntax';
import path from 'path';
import funnel from 'broccoli-funnel';
import makeDebug from 'debug';

const debugTree = buildDebugCallback('ember-auto-import');
const debugWatch = makeDebug('ember-auto-import:watch');

// This interface must be stable across all versions of ember-auto-import that
// speak the same leader-election protocol. So don't change this unless you know
Expand Down Expand Up @@ -244,6 +246,7 @@ function depsFor(allAppTree: Node, packages: Set<Package>) {
let watched = pkg.watchedDirectories;
if (watched) {
deps = deps.concat(watched.map((dir) => new WatchedDir(dir)));
debugWatch(`Adding watched directories: ${watched.join(', ')}`);
}
}
return deps;
Expand Down
9 changes: 6 additions & 3 deletions packages/ember-auto-import/ts/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type { PluginItem, TransformOptions } from '@babel/core';
import { MacrosConfig } from '@embroider/macros/src/node';
import minimatch from 'minimatch';
import { stripQuery } from './util';
import { getWatchedDirectories } from './watch-utils';

// from child addon instance to their parent package
const parentCache: WeakMap<AddonInstance, Package> = new WeakMap();
Expand Down Expand Up @@ -514,13 +515,15 @@ export default class Package {
for (let name of names) {
let path = resolvePackagePath(name, cursor);
if (!path) {
return undefined;
return [];
}
cursor = dirname(path);
}
return cursor;
return getWatchedDirectories(cursor).map((relativeDir) =>
join(cursor, relativeDir)
);
})
.filter(Boolean) as string[];
.flat();
}
}

Expand Down
Loading

0 comments on commit 73b6acd

Please sign in to comment.