Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix extension_directories wildcards to always be recursive #5160

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 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 @@ -30,6 +31,7 @@
path: '',
name: 'app 1',
client_id: '12345',
extension_directories: ['extensions/*'],
webhooks: {
api_version: '2023-04',
privacy_compliance: {
Expand Down Expand Up @@ -91,6 +93,33 @@

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 Expand Up @@ -211,9 +240,9 @@
configuration_ui: true,
metafields: [],
name: 'test function extension',
type: type || 'product_discounts',

Check warning on line 243 in packages/app/src/cli/models/app/app.test.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/app/src/cli/models/app/app.test.ts#L243

[@typescript-eslint/prefer-nullish-coalescing] Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator.
ui: {
handle: uiHandle || 'test-ui-handle',

Check warning on line 245 in packages/app/src/cli/models/app/app.test.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/app/src/cli/models/app/app.test.ts#L245

[@typescript-eslint/prefer-nullish-coalescing] Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator.
},
})

Expand Down
18 changes: 16 additions & 2 deletions packages/app/src/cli/models/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@

// Schemas for loading app configuration

const ExtensionDirectoriesSchema = zod
.array(zod.string())
.optional()
.transform(removeTrailingPathSeparator)
.transform(fixSingleWildcards)

/**
* Schema for a freshly minted app template.
*/
Expand All @@ -34,7 +40,7 @@
.string()
.transform((scopes) => normalizeDelimitedString(scopes) ?? '')
.default(''),
extension_directories: zod.array(zod.string()).optional().transform(removeTrailingPathSeparator),
extension_directories: ExtensionDirectoriesSchema,
web_directories: zod.array(zod.string()).optional(),
webhooks: zod
.object({
Expand All @@ -49,6 +55,14 @@
// eslint-disable-next-line no-useless-escape
return value?.map((dir) => dir.replace(/[\/\\]+$/, ''))
}

// 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) {
// eslint-disable-next-line no-useless-escape
return value?.map((dir) => dir.replace(/([^\*])\*$/, '$1**'))
}

/**
* Schema for a normal, linked app. Properties from modules are not validated.
*/
Expand All @@ -62,7 +76,7 @@
include_config_on_deploy: zod.boolean().optional(),
})
.optional(),
extension_directories: zod.array(zod.string()).optional().transform(removeTrailingPathSeparator),
extension_directories: ExtensionDirectoriesSchema,
web_directories: zod.array(zod.string()).optional(),
})

Expand Down Expand Up @@ -416,7 +430,7 @@
const frontendConfig = this.webs.find((web) => isWebType(web, WebType.Frontend))
const backendConfig = this.webs.find((web) => isWebType(web, WebType.Backend))

return Boolean(frontendConfig || backendConfig)

Check warning on line 433 in packages/app/src/cli/models/app/app.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/app/src/cli/models/app/app.ts#L433

[@typescript-eslint/prefer-nullish-coalescing] Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator.
}

creationDefaultOptions(): AppCreationDefaultOptions {
Expand Down
Loading