Skip to content

Extract extension_directories transforms from Zod schema#6950

Draft
ryancbahan wants to merge 1 commit intorcb/config-model-extract-pathfrom
rcb/extract-extension-dir-transforms
Draft

Extract extension_directories transforms from Zod schema#6950
ryancbahan wants to merge 1 commit intorcb/config-model-extract-pathfrom
rcb/extract-extension-dir-transforms

Conversation

@ryancbahan
Copy link
Contributor

@ryancbahan ryancbahan commented Mar 7, 2026

WHY are these changes introduced?

ExtensionDirectoriesSchema chains two Zod .transform() calls that silently reshape the parsed value:

  • removeTrailingPathSeparator — strips trailing / or \ (e.g. extensions/extensions)
  • fixSingleWildcards — converts a single trailing * to ** for glob compatibility (e.g. extensions/*extensions/**)

After parsing, config.extension_directories no longer matches what the user wrote in their TOML. This means writing the config back to disk would persist the transformed values instead of the originals — a data corruption risk during config link/pull. It also violates the contract established earlier in this stack: AppConfiguration should describe what's in the file, nothing more.

WHAT is this pull request doing?

Removes both transforms from the Zod schema so the parsed config preserves the raw TOML value. Adds an explicit normalizeExtensionDirectories() helper that consumers call at point of use:

  • loader.tscreateExtensionInstances() normalizes before globbing for extension TOMLs
  • file-watcher.tsstart() normalizes before passing directories to chokidar

These are the only two consumers that need normalized paths. All other readers (deploy, config write-back, display) should see the raw user-authored value.

The snapshot tests from #6947 confirm no change in end-to-end TOML output.

How to test your changes?

npx vitest run packages/app/src/cli/models/app/app.test.ts
npx vitest run packages/app/src/cli/services/app/config-pipeline-snapshot.test.ts

Measuring impact

  • n/a - this doesn't need measurement, e.g. a linting rule or a bug-fix

Checklist

  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've considered possible documentation changes

@github-actions
Copy link
Contributor

github-actions bot commented Mar 7, 2026

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements 79.24% 14600/18426
🟡 Branches 73.5% 7252/9866
🟡 Functions 79.38% 3718/4684
🟡 Lines 79.56% 13795/17339

Test suite run success

3833 tests passing in 1467 suites.

Report generated by 🧪jest coverage report action from 70f379b

@github-actions
Copy link
Contributor

Differences in type declarations

We detected differences in the type declarations generated by Typescript for this branch compared to the baseline ('main' branch). Please, review them to ensure they are backward-compatible. Here are some important things to keep in mind:

  • Some seemingly private modules might be re-exported through public modules.
  • If the branch is behind main you might see odd diffs, rebase main into this branch.

New type declarations

packages/cli-kit/dist/public/node/toml/codec.d.ts
import { JsonMap } from '../../../private/common/json.js';
export type JsonMapType = JsonMap;
/**
 * Given a TOML string, it returns a JSON object.
 *
 * @param input - TOML string.
 * @returns JSON object.
 */
export declare function decodeToml(input: string): JsonMapType;
/**
 * Given a JSON object, it returns a TOML string.
 *
 * @param content - JSON object.
 * @returns TOML string.
 */
export declare function encodeToml(content: JsonMap | object): string;
packages/cli-kit/dist/public/node/toml/index.d.ts
export type { JsonMapType } from './codec.js';
packages/cli-kit/dist/public/node/toml/toml-file.d.ts
import { JsonMapType } from './codec.js';
/**
 * Thrown when a TOML file cannot be parsed. Includes the file path for context.
 */
export declare class TomlParseError extends Error {
    readonly path: string;
    constructor(path: string, cause: Error);
}
/**
 * General-purpose TOML file abstraction.
 *
 * Provides a unified interface for reading, patching, removing keys from, and replacing
 * the content of TOML files on disk.
 *
 * - `read` populates content from disk
 * - `patch` does surgical WASM-based edits (preserves comments and formatting)
 * - `remove` deletes a key by dotted path (preserves comments and formatting)
 * - `replace` does a full re-serialization (comments and formatting are NOT preserved).
 * - `transformRaw` applies a function to the raw TOML string on disk.
 */
export declare class TomlFile {
    /**
     * Read and parse a TOML file from disk. Throws if the file doesn't exist or contains invalid TOML.
     * Parse errors are wrapped in {@link TomlParseError} with the file path for context.
     *
     * @param path - Absolute path to the TOML file.
     * @returns A TomlFile instance with parsed content.
     */
    static read(path: string): Promise<TomlFile>;
    readonly path: string;
    content: JsonMapType;
    constructor(path: string, content: JsonMapType);
    /**
     * Surgically patch values in the TOML file, preserving comments and formatting.
     *
     * Accepts a nested object whose leaf values are set in the TOML. Intermediate tables are
     * created automatically. Setting a leaf to `undefined` removes it (use `remove()` for a
     * clearer API when deleting keys).
     *
     * @example
     * ```ts
     * await file.patch({build: {dev_store_url: 'my-store.myshopify.com'}})
     * await file.patch({application_url: 'https://example.com', auth: {redirect_urls: ['...']}})
     * ```
     */
    patch(changes: {
        [key: string]: unknown;
    }): Promise<void>;
    /**
     * Remove a key from the TOML file by dotted path, preserving comments and formatting.
     *
     * @param keyPath - Dotted key path to remove (e.g. 'build.include_config_on_deploy').
     * @example
     * ```ts
     * await file.remove('build.include_config_on_deploy')
     * ```
     */
    remove(keyPath: string): Promise<void>;
    /**
     * Replace the entire file content. The file is fully re-serialized — comments and formatting
     * are NOT preserved.
     *
     * @param content - The new content to write.
     * @example
     * ```ts
     * await file.replace({client_id: 'abc', name: 'My App'})
     * ```
     */
    replace(content: JsonMapType): Promise<void>;
    /**
     * Transform the raw TOML string on disk. Reads the file, applies the transform function
     * to the raw text, writes back, and re-parses to keep `content` in sync.
     *
     * Use this for text-level operations that can't be expressed as structured edits —
     * e.g. Injecting comments or positional insertion of keys in arrays-of-tables.
     * Subsequent `patch()` calls will preserve any comments added this way.
     *
     * @param transform - A function that receives the raw TOML string and returns the modified string.
     * @example
     * ```ts
     * await file.transformRaw((raw) => `# Header comment\n${raw}`)
     * ```
     */
    transformRaw(transform: (raw: string) => string): Promise<void>;
    private decode;
}

Existing type declarations

We found no diffs with existing type declarations

@ryancbahan ryancbahan force-pushed the rcb/config-model-extract-path branch from 5028d72 to 49d9789 Compare March 11, 2026 22:13
@ryancbahan ryancbahan force-pushed the rcb/extract-extension-dir-transforms branch from c8f3dde to 23b6a86 Compare March 11, 2026 22:13
Move removeTrailingPathSeparator and fixSingleWildcards out of
ExtensionDirectoriesSchema so parsed config preserves the raw TOML
value. Consumers (loader, file-watcher) now call the explicit
normalizeExtensionDirectories() helper at point of use.

Phase 2 of the config model cleanup — extension_directories is a
CLI-only field with no write-path or API impact.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ryancbahan ryancbahan force-pushed the rcb/extract-extension-dir-transforms branch from 23b6a86 to 70f379b Compare March 12, 2026 14:53
@ryancbahan ryancbahan force-pushed the rcb/config-model-extract-path branch from 49d9789 to 29d8b4d Compare March 12, 2026 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant