Skip to content

Commit

Permalink
Merge pull request #5160 from Shopify/01-07-fix_extension_directories…
Browse files Browse the repository at this point in the history
…_wildcards_to_always_be_recursive

Fix extension_directories wildcards to always be recursive
  • Loading branch information
isaacroldan authored Jan 13, 2025
2 parents acbd399 + b874496 commit 6b8c002
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
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 @@ 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 Expand Up @@ -91,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
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 @@ 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,14 @@ 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) {
// 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 @@ 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 6b8c002

Please sign in to comment.