Skip to content

Commit

Permalink
Allow exemptions
Browse files Browse the repository at this point in the history
  • Loading branch information
iObject committed Aug 21, 2024
1 parent bc387e8 commit 7721a4d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
30 changes: 28 additions & 2 deletions src/findNodes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,12 @@ describe('findnode', () => {
`);
});


it('it works when provide an excludeFiles config', async () => {
program.options.autoFindNode = {

Check failure on line 233 in src/findNodes.spec.ts

View workflow job for this annotation

GitHub Actions / create-package

Property 'autoFindNode' does not exist on type 'BsConfig'.

Check failure on line 233 in src/findNodes.spec.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

Property 'autoFindNode' does not exist on type 'BsConfig'.
'excludeFiles': ['components/noreplace/**/*']
'excludeFiles': [
'components/noreplace/**/*',
"!components/noreplace/sub/**/*"
]
};

program.setFile('components/replace/BaseKeyboard.bs', `
Expand Down Expand Up @@ -280,5 +282,29 @@ describe('findnode', () => {
m.helloText.text = "HELLO ZOMBIE"
end sub
`);

// Now we test the same code in the folder that should be excluded
program.setFile('components/noreplace/sub/BaseKeyboard.bs', `
sub init()
m.helloText.text = "HELLO ZOMBIE"
end sub
`);

program.setFile('components/noreplace/sub/BaseKeyboard.xml', `
<component name="BaseKeyboard">
<script uri="BaseKeyboard.bs" />
<children>
<label id="helloText" />
</children>
</component>
`);

result = await program.getTranspiledFileContents('components/noreplace/sub/BaseKeyboard.bs');
expect(result.code).to.equal(undent`
sub init()
m.helloText = m.top.findNode("helloText")
m.helloText.text = "HELLO ZOMBIE"
end sub
`);
});
});
16 changes: 14 additions & 2 deletions src/findNodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,25 @@ function getFilteredScopes(program: Program) {
const excludeScopes = program.options?.autoFindNode?.excludeFiles || [];

Check failure on line 22 in src/findNodes.ts

View workflow job for this annotation

GitHub Actions / create-package

Property 'autoFindNode' does not exist on type 'BsConfig'.

Check failure on line 22 in src/findNodes.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

Property 'autoFindNode' does not exist on type 'BsConfig'.
let scopes: XmlScope[] = [];

const hasExclusions = excludeScopes.length > 0;
const includePatterns = excludeScopes.filter(pattern => pattern.startsWith('!')).map(pattern => pattern.slice(1));
const excludePatterns = excludeScopes.filter(pattern => !pattern.startsWith('!'));

const hasExclusions = excludePatterns.length > 0;

for (const filteredScope of program.getScopes().filter((scope) => isXmlScope(scope))) {
let isIncluded = includePatterns.some((pattern: string) =>
minimatch.match([filteredScope.name], pattern).length > 0
);

if (isIncluded) {
scopes.push(filteredScope);

Check failure on line 36 in src/findNodes.ts

View workflow job for this annotation

GitHub Actions / create-package

Argument of type 'Scope' is not assignable to parameter of type 'XmlScope'.

Check failure on line 36 in src/findNodes.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

Argument of type 'Scope' is not assignable to parameter of type 'XmlScope'.
continue; // Skip further checks since it's explicitly included
}

if (!hasExclusions) {
scopes.push(filteredScope);

Check failure on line 41 in src/findNodes.ts

View workflow job for this annotation

GitHub Actions / create-package

Argument of type 'Scope' is not assignable to parameter of type 'XmlScope'.

Check failure on line 41 in src/findNodes.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

Argument of type 'Scope' is not assignable to parameter of type 'XmlScope'.
} else {
let isExcluded = excludeScopes.some((pattern: string) =>
let isExcluded = excludePatterns.some((pattern: string) =>
minimatch.match([filteredScope.name], pattern).length > 0
);
if (!isExcluded) {
Expand Down

0 comments on commit 7721a4d

Please sign in to comment.