Skip to content

Commit

Permalink
feat: improve project registry invalidation logic (#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
lifeart committed May 27, 2021
1 parent 450415e commit be54957
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/project.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { addToRegistry, removeFromRegistry, normalizeMatchNaming, NormalizedRegistryItem, IRegistry, getRegistryForRoots } from './utils/registry-api';
import {
addToRegistry,
removeFromRegistry,
normalizeMatchNaming,
NormalizedRegistryItem,
IRegistry,
getRegistryForRoots,
existsInRegistry,
} from './utils/registry-api';
import { ProjectProviders, collectProjectProviders, AddonMeta, DependencyMeta } from './utils/addon-api';
import {
findTestsForProject,
Expand Down Expand Up @@ -95,11 +103,15 @@ export class Project extends BaseProject {
}
} else {
if (normalizedItem) {
if (!existsInRegistry(normalizedItem.name, normalizedItem.type, filePath)) {
this.registryVersion++;
}

// we still call it, because for template case, we have to update it's tokens
addToRegistry(normalizedItem.name, normalizedItem.type, [filePath]);
}

if (!this.files.has(filePath)) {
this.registryVersion++;
this.files.set(filePath, { version: 0 });
}

Expand Down
14 changes: 14 additions & 0 deletions src/utils/registry-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,20 @@ export function getRegistryForRoot(rawRoot: string): IRegistry {
return _getRegistryForRoots([rawRoot]);
}

export function existsInRegistry(name: string, kind: REGISTRY_KIND, file: string) {
const regItem = GLOBAL_REGISTRY[kind];

if (!regItem) {
return false;
}

if (!regItem.has(name)) {
return false;
}

return regItem.get(name)?.has(path.resolve(file));
}

export function addToRegistry(normalizedName: string, kind: REGISTRY_KIND, files: string[]) {
if (!(kind in GLOBAL_REGISTRY)) {
return;
Expand Down

0 comments on commit be54957

Please sign in to comment.