Skip to content

Commit

Permalink
Fix extension_directories wildcards to always be recursive
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacroldan committed Jan 7, 2025
1 parent e72a072 commit 9d66cb8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/app/src/cli/models/app/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const CORRECT_CURRENT_APP_SCHEMA: CurrentAppConfiguration = {
path: '',
name: 'app 1',
client_id: '12345',
extension_directories: ['extensions/*'],
webhooks: {
api_version: '2023-04',
privacy_compliance: {
Expand Down
17 changes: 15 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 @@ import {getArrayRejectingUndefined} from '@shopify/cli-kit/common/array'

// 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 @@ export const LegacyAppSchema = zod
.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,13 @@ function removeTrailingPathSeparator(value: string[] | undefined) {
// 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) {
return value?.map((dir) => dir.replace(/\*$/, '**'))
}

/**
* Schema for a normal, linked app. Properties from modules are not validated.
*/
Expand All @@ -62,7 +75,7 @@ export const AppSchema = zod.object({
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

0 comments on commit 9d66cb8

Please sign in to comment.