Skip to content

Commit

Permalink
feat: multiple resolve targets when parsing manifest (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryan Powell authored and lcampos committed Dec 3, 2020
1 parent 1a4f35a commit cede5f6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/collections/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface FromSourceOptions extends WorkingSetOptions {
}

export interface FromManifestOptions extends FromSourceOptions {
resolve?: string;
resolve?: Iterable<string>;
literalWildcard?: boolean;
}

Expand Down
14 changes: 9 additions & 5 deletions src/collections/workingSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class WorkingSet implements MetadataSet, Iterable<MetadataComponent> {
): Promise<WorkingSet> {
const registry = options?.registry ?? new RegistryAccess();
const tree = options?.tree ?? new NodeFSTreeContainer();
const shouldResolve = options?.resolve;
const shouldResolve = !!options?.resolve;

const ws = new WorkingSet(options?.registry);
const filterSet = new ComponentSet<MetadataComponent>();
Expand All @@ -93,10 +93,14 @@ export class WorkingSet implements MetadataSet, Iterable<MetadataComponent> {
}

if (shouldResolve) {
ws.resolveSourceComponents(options.resolve, {
tree,
filter: filterSet,
});
// if it's a string, don't iterate over the characters
const toResolve = typeof options.resolve === 'string' ? [options.resolve] : options.resolve;
for (const fsPath of toResolve) {
ws.resolveSourceComponents(fsPath, {
tree,
filter: filterSet,
});
}
}

return ws;
Expand Down
16 changes: 15 additions & 1 deletion test/collections/workingSet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ describe('WorkingSet', () => {
]);
});

it('should initialize with source backed components when specifying resolve option', async () => {
it('should initialize with source backed components when specifying string resolve option', async () => {
const ws = await WorkingSet.fromManifestFile('subset.xml', {
registry: mockRegistry,
tree,
Expand All @@ -201,6 +201,20 @@ describe('WorkingSet', () => {
expect(Array.from(ws)).to.deep.equal(expected);
});

it('should initialize with source backed components when specifying non-string iterable resolve option', async () => {
const ws = await WorkingSet.fromManifestFile('subset.xml', {
registry: mockRegistry,
tree,
resolve: ['decomposedTopLevels', 'mixedSingleFiles'],
});

const expected = new MetadataResolver(mockRegistry, tree).getComponentsFromPath('.');
const missingIndex = expected.findIndex((c) => c.fullName === 'c');
expected.splice(missingIndex, 1);

expect(Array.from(ws)).to.deep.equal(expected);
});

it('should interpret wildcard members literally by default', async () => {
const ws = await WorkingSet.fromManifestFile('wildcard.xml', {
registry: mockRegistry,
Expand Down

0 comments on commit cede5f6

Please sign in to comment.