Skip to content

Commit

Permalink
Improve regex and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacroldan committed Jan 8, 2025
1 parent 55c6e45 commit b874496
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
28 changes: 28 additions & 0 deletions packages/app/src/cli/models/app/app.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
AppSchema,
CurrentAppConfiguration,
LegacyAppConfiguration,
getAppScopes,
Expand Down Expand Up @@ -92,6 +93,33 @@ describe('app schema validation', () => {

expect(isCurrentAppSchema(config)).toBe(false)
})

test('extension_directories should be transformed to double asterisks', () => {
const config = {
...CORRECT_CURRENT_APP_SCHEMA,
extension_directories: ['extensions/*'],
}
const parsed = AppSchema.parse(config)
expect(parsed.extension_directories).toEqual(['extensions/**'])
})

test('extension_directories is not transformed if it ends with double asterisks', () => {
const config = {
...CORRECT_CURRENT_APP_SCHEMA,
extension_directories: ['extensions/**'],
}
const parsed = AppSchema.parse(config)
expect(parsed.extension_directories).toEqual(['extensions/**'])
})

test('extension_directories is not transformed if it doesnt end with a wildcard', () => {
const config = {
...CORRECT_CURRENT_APP_SCHEMA,
extension_directories: ['extensions'],
}
const parsed = AppSchema.parse(config)
expect(parsed.extension_directories).toEqual(['extensions'])
})
})
})

Expand Down
3 changes: 2 additions & 1 deletion packages/app/src/cli/models/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ function removeTrailingPathSeparator(value: string[] | undefined) {
// If a path ends with a single asterisk, modify it to end with a double asterisk.
// This is to support the glob pattern used by chokidar and watch for changes in subfolders.
function fixSingleWildcards(value: string[] | undefined) {
return value?.map((dir) => dir.replace(/\*$/, '**'))
// eslint-disable-next-line no-useless-escape
return value?.map((dir) => dir.replace(/([^\*])\*$/, '$1**'))
}

/**
Expand Down

0 comments on commit b874496

Please sign in to comment.