From d89dae19a40229317236cbd2940ee26d49ed1662 Mon Sep 17 00:00:00 2001 From: guitavano Date: Tue, 23 Jun 2026 01:18:43 -0300 Subject: [PATCH] refactor(vtex): move inline-loaders to CMS key paths Move vtex/inline-loaders/ into vtex/loaders/ subdirectories that match CMS keys (e.g. intelligentSearch/productList.ts, legacy/*, workflow/*). This enables filesystem-based auto-discovery in the schema generator instead of a hardcoded mapping. Re-export files preserve backward compat for alias CMS keys. package.json exports keep old inline-loaders paths pointing to new locations. Co-Authored-By: Claude Opus 4.6 --- knip.json | 4 +++- package.json | 20 ++++++++++--------- vtex/commerceLoaders.ts | 16 +++++++-------- vtex/loaders/ProductDetailsPage.ts | 1 + vtex/loaders/ProductList.ts | 1 + vtex/loaders/ProductListingPage.ts | 1 + .../__tests__/productListingPage.test.ts | 0 .../intelligentSearch}/productDetailsPage.ts | 10 +++++----- .../intelligentSearch/productList.ts} | 8 ++++---- .../intelligentSearch}/productListingPage.ts | 6 +++--- .../intelligentSearch}/suggestions.ts | 8 ++++---- vtex/loaders/legacy/productDetailsPage.ts | 1 + vtex/loaders/legacy/productList.ts | 1 + .../legacy/relatedProductsLoader.ts} | 10 +++++----- vtex/{inline-loaders => loaders}/minicart.ts | 4 ++-- .../productListFull.ts} | 0 .../workflow/products.ts} | 8 ++++---- 17 files changed, 54 insertions(+), 45 deletions(-) create mode 100644 vtex/loaders/ProductDetailsPage.ts create mode 100644 vtex/loaders/ProductList.ts create mode 100644 vtex/loaders/ProductListingPage.ts rename vtex/{inline-loaders => loaders/intelligentSearch}/__tests__/productListingPage.test.ts (100%) rename vtex/{inline-loaders => loaders/intelligentSearch}/productDetailsPage.ts (89%) rename vtex/{inline-loaders/productListShelf.ts => loaders/intelligentSearch/productList.ts} (94%) rename vtex/{inline-loaders => loaders/intelligentSearch}/productListingPage.ts (98%) rename vtex/{inline-loaders => loaders/intelligentSearch}/suggestions.ts (81%) create mode 100644 vtex/loaders/legacy/productDetailsPage.ts create mode 100644 vtex/loaders/legacy/productList.ts rename vtex/{inline-loaders/relatedProducts.ts => loaders/legacy/relatedProductsLoader.ts} (87%) rename vtex/{inline-loaders => loaders}/minicart.ts (95%) rename vtex/{inline-loaders/productList.ts => loaders/productListFull.ts} (100%) rename vtex/{inline-loaders/workflowProducts.ts => loaders/workflow/products.ts} (89%) diff --git a/knip.json b/knip.json index 20ac8c1..c11bb27 100644 --- a/knip.json +++ b/knip.json @@ -6,7 +6,9 @@ "vtex/hooks/*.ts", "vtex/loaders/*.ts", "vtex/utils/*.ts", - "vtex/inline-loaders/*.ts", + "vtex/loaders/intelligentSearch/*.ts", + "vtex/loaders/legacy/*.ts", + "vtex/loaders/workflow/*.ts", "shopify/*.ts", "shopify/actions/**/*.ts", "shopify/loaders/*.ts", diff --git a/package.json b/package.json index d5f74a5..827194c 100644 --- a/package.json +++ b/package.json @@ -50,17 +50,19 @@ "./vtex/loaders/*": "./vtex/loaders/*.ts", "./vtex/utils": "./vtex/utils/index.ts", "./vtex/utils/*": "./vtex/utils/*.ts", - "./vtex/inline-loaders/*": "./vtex/inline-loaders/*.ts", - "./vtex/inline-loaders/productDetailsPage": "./vtex/inline-loaders/productDetailsPage.ts", - "./vtex/inline-loaders/productListingPage": "./vtex/inline-loaders/productListingPage.ts", - "./vtex/inline-loaders/productList": "./vtex/inline-loaders/productList.ts", - "./vtex/inline-loaders/productListShelf": "./vtex/inline-loaders/productListShelf.ts", - "./vtex/inline-loaders/relatedProducts": "./vtex/inline-loaders/relatedProducts.ts", - "./vtex/inline-loaders/suggestions": "./vtex/inline-loaders/suggestions.ts", - "./vtex/inline-loaders/minicart": "./vtex/inline-loaders/minicart.ts", + "./vtex/loaders/intelligentSearch/*": "./vtex/loaders/intelligentSearch/*.ts", + "./vtex/loaders/legacy/*": "./vtex/loaders/legacy/*.ts", + "./vtex/loaders/workflow/*": "./vtex/loaders/workflow/*.ts", + "./vtex/inline-loaders/productDetailsPage": "./vtex/loaders/intelligentSearch/productDetailsPage.ts", + "./vtex/inline-loaders/productListingPage": "./vtex/loaders/intelligentSearch/productListingPage.ts", + "./vtex/inline-loaders/productList": "./vtex/loaders/productListFull.ts", + "./vtex/inline-loaders/productListShelf": "./vtex/loaders/intelligentSearch/productList.ts", + "./vtex/inline-loaders/relatedProducts": "./vtex/loaders/legacy/relatedProductsLoader.ts", + "./vtex/inline-loaders/suggestions": "./vtex/loaders/intelligentSearch/suggestions.ts", + "./vtex/inline-loaders/minicart": "./vtex/loaders/minicart.ts", + "./vtex/inline-loaders/workflowProducts": "./vtex/loaders/workflow/products.ts", "./vtex/hooks": "./vtex/hooks/index.ts", "./vtex/hooks/*": "./vtex/hooks/*.ts", - "./vtex/inline-loaders/workflowProducts": "./vtex/inline-loaders/workflowProducts.ts", "./vtex/middleware": "./vtex/middleware.ts", "./resend": "./resend/index.ts", "./resend/mod": "./resend/mod.ts", diff --git a/vtex/commerceLoaders.ts b/vtex/commerceLoaders.ts index a684199..53d2d41 100644 --- a/vtex/commerceLoaders.ts +++ b/vtex/commerceLoaders.ts @@ -1,7 +1,7 @@ /** * Standard VTEX commerce loader map factory for CMS block resolution. * - * Wraps all VTEX inline loaders with createCachedLoader, applies universal + * Wraps all VTEX loaders with createCachedLoader, applies universal * workarounds (slug fallback, IS sort sanitization, map=productClusterIds), * and registers both `.ts` and `.ts`-less aliases. * @@ -11,14 +11,14 @@ import { createCachedLoader } from "@decocms/start/sdk/cachedLoader"; import type { CacheProfileName } from "@decocms/start/sdk/cacheHeaders"; -import vtexProductDetailsPage from "./inline-loaders/productDetailsPage"; -import vtexProductList from "./inline-loaders/productList"; -import vtexProductListingPage from "./inline-loaders/productListingPage"; -import vtexProductListShelf from "./inline-loaders/productListShelf"; -import vtexRelatedProducts from "./inline-loaders/relatedProducts"; -import vtexSuggestions from "./inline-loaders/suggestions"; -import vtexWorkflowProducts from "./inline-loaders/workflowProducts"; import { getCategoryTree } from "./loaders/catalog"; +import vtexProductDetailsPage from "./loaders/intelligentSearch/productDetailsPage"; +import vtexProductListShelf from "./loaders/intelligentSearch/productList"; +import vtexProductListingPage from "./loaders/intelligentSearch/productListingPage"; +import vtexSuggestions from "./loaders/intelligentSearch/suggestions"; +import vtexRelatedProducts from "./loaders/legacy/relatedProductsLoader"; +import vtexProductList from "./loaders/productListFull"; +import vtexWorkflowProducts from "./loaders/workflow/products"; import { VALID_IS_SORTS } from "./utils/intelligentSearch"; export type CommerceLoaderFn = (props: any) => Promise; diff --git a/vtex/loaders/ProductDetailsPage.ts b/vtex/loaders/ProductDetailsPage.ts new file mode 100644 index 0000000..522b243 --- /dev/null +++ b/vtex/loaders/ProductDetailsPage.ts @@ -0,0 +1 @@ +export { default, type PDPProps } from "./intelligentSearch/productDetailsPage"; diff --git a/vtex/loaders/ProductList.ts b/vtex/loaders/ProductList.ts new file mode 100644 index 0000000..399e6d7 --- /dev/null +++ b/vtex/loaders/ProductList.ts @@ -0,0 +1 @@ +export { default, type ProductListProps } from "./intelligentSearch/productList"; diff --git a/vtex/loaders/ProductListingPage.ts b/vtex/loaders/ProductListingPage.ts new file mode 100644 index 0000000..1b184a4 --- /dev/null +++ b/vtex/loaders/ProductListingPage.ts @@ -0,0 +1 @@ +export { default, type PLPProps } from "./intelligentSearch/productListingPage"; diff --git a/vtex/inline-loaders/__tests__/productListingPage.test.ts b/vtex/loaders/intelligentSearch/__tests__/productListingPage.test.ts similarity index 100% rename from vtex/inline-loaders/__tests__/productListingPage.test.ts rename to vtex/loaders/intelligentSearch/__tests__/productListingPage.test.ts diff --git a/vtex/inline-loaders/productDetailsPage.ts b/vtex/loaders/intelligentSearch/productDetailsPage.ts similarity index 89% rename from vtex/inline-loaders/productDetailsPage.ts rename to vtex/loaders/intelligentSearch/productDetailsPage.ts index 7f8ee7b..e299a5f 100644 --- a/vtex/inline-loaders/productDetailsPage.ts +++ b/vtex/loaders/intelligentSearch/productDetailsPage.ts @@ -4,11 +4,11 @@ * following the same pattern as deco-cx/apps. */ -import type { ProductDetailsPage } from "../../commerce/types/commerce"; -import { getVtexConfig, vtexCachedFetch } from "../client"; -import { searchBySlug } from "../utils/slugCache"; -import { pickSku, toProductPage } from "../utils/transform"; -import type { LegacyProduct } from "../utils/types"; +import type { ProductDetailsPage } from "../../../commerce/types/commerce"; +import { getVtexConfig, vtexCachedFetch } from "../../client"; +import { searchBySlug } from "../../utils/slugCache"; +import { pickSku, toProductPage } from "../../utils/transform"; +import type { LegacyProduct } from "../../utils/types"; export interface PDPProps { slug?: string; diff --git a/vtex/inline-loaders/productListShelf.ts b/vtex/loaders/intelligentSearch/productList.ts similarity index 94% rename from vtex/inline-loaders/productListShelf.ts rename to vtex/loaders/intelligentSearch/productList.ts index d7a988a..9abce9c 100644 --- a/vtex/inline-loaders/productListShelf.ts +++ b/vtex/loaders/intelligentSearch/productList.ts @@ -6,10 +6,10 @@ * (name, URL, images, price, installments, PIX, availability, brand). */ -import type { Product } from "../../commerce/types/commerce"; -import { getVtexConfig, intelligentSearch, toFacetPath } from "../client"; -import { pickSku, sortProducts, toProductShelf } from "../utils/transform"; -import type { Product as ProductVTEX } from "../utils/types"; +import type { Product } from "../../../commerce/types/commerce"; +import { getVtexConfig, intelligentSearch, toFacetPath } from "../../client"; +import { pickSku, sortProducts, toProductShelf } from "../../utils/transform"; +import type { Product as ProductVTEX } from "../../utils/types"; export interface ProductListProps { props?: CollectionProps | QueryProps | ProductIDProps | FacetsProps; diff --git a/vtex/inline-loaders/productListingPage.ts b/vtex/loaders/intelligentSearch/productListingPage.ts similarity index 98% rename from vtex/inline-loaders/productListingPage.ts rename to vtex/loaders/intelligentSearch/productListingPage.ts index 0a921ac..de290b7 100644 --- a/vtex/inline-loaders/productListingPage.ts +++ b/vtex/loaders/intelligentSearch/productListingPage.ts @@ -5,9 +5,9 @@ import { type PageType, pageTypesFromPath, toFacetPath, -} from "../client"; -import { pickSku, toProduct } from "../utils/transform"; -import type { Product as ProductVTEX, Sort } from "../utils/types"; +} from "../../client"; +import { pickSku, toProduct } from "../../utils/transform"; +import type { Product as ProductVTEX, Sort } from "../../utils/types"; export interface SelectedFacet { key: string; diff --git a/vtex/inline-loaders/suggestions.ts b/vtex/loaders/intelligentSearch/suggestions.ts similarity index 81% rename from vtex/inline-loaders/suggestions.ts rename to vtex/loaders/intelligentSearch/suggestions.ts index 988a78b..c3adda4 100644 --- a/vtex/inline-loaders/suggestions.ts +++ b/vtex/loaders/intelligentSearch/suggestions.ts @@ -3,10 +3,10 @@ * Maps VTEX IS response to commerce Suggestion type. */ -import type { Product, Suggestion } from "../../commerce/types/commerce"; -import { getVtexConfig, intelligentSearch } from "../client"; -import { pickSku, toProduct } from "../utils/transform"; -import type { Product as ProductVTEX } from "../utils/types"; +import type { Product, Suggestion } from "../../../commerce/types/commerce"; +import { getVtexConfig, intelligentSearch } from "../../client"; +import { pickSku, toProduct } from "../../utils/transform"; +import type { Product as ProductVTEX } from "../../utils/types"; export interface SuggestionsProps { query?: string; diff --git a/vtex/loaders/legacy/productDetailsPage.ts b/vtex/loaders/legacy/productDetailsPage.ts new file mode 100644 index 0000000..5bb4399 --- /dev/null +++ b/vtex/loaders/legacy/productDetailsPage.ts @@ -0,0 +1 @@ +export { default, type PDPProps } from "../intelligentSearch/productDetailsPage"; diff --git a/vtex/loaders/legacy/productList.ts b/vtex/loaders/legacy/productList.ts new file mode 100644 index 0000000..8874bf1 --- /dev/null +++ b/vtex/loaders/legacy/productList.ts @@ -0,0 +1 @@ +export { default, type ProductListProps } from "../intelligentSearch/productList"; diff --git a/vtex/inline-loaders/relatedProducts.ts b/vtex/loaders/legacy/relatedProductsLoader.ts similarity index 87% rename from vtex/inline-loaders/relatedProducts.ts rename to vtex/loaders/legacy/relatedProductsLoader.ts index 2959ed7..b01574b 100644 --- a/vtex/inline-loaders/relatedProducts.ts +++ b/vtex/loaders/legacy/relatedProductsLoader.ts @@ -7,11 +7,11 @@ * single search/{slug}/p call instead of each doing their own. */ -import type { Product } from "../../commerce/types/commerce"; -import { getVtexConfig, vtexCachedFetch } from "../client"; -import { resolveProductIdBySlug } from "../utils/slugCache"; -import { pickSku, toProduct } from "../utils/transform"; -import type { LegacyProduct } from "../utils/types"; +import type { Product } from "../../../commerce/types/commerce"; +import { getVtexConfig, vtexCachedFetch } from "../../client"; +import { resolveProductIdBySlug } from "../../utils/slugCache"; +import { pickSku, toProduct } from "../../utils/transform"; +import type { LegacyProduct } from "../../utils/types"; export type CrossSellingType = | "similars" diff --git a/vtex/inline-loaders/minicart.ts b/vtex/loaders/minicart.ts similarity index 95% rename from vtex/inline-loaders/minicart.ts rename to vtex/loaders/minicart.ts index 7693d43..5237ee0 100644 --- a/vtex/inline-loaders/minicart.ts +++ b/vtex/loaders/minicart.ts @@ -12,8 +12,8 @@ * @example * ```ts * // setup/commerce-loaders.ts - * import minicart from "@decocms/apps/vtex/inline-loaders/minicart"; - * registerInlineLoader("vtex/inline-loaders/minicart", minicart); + * import minicart from "@decocms/apps/vtex/loaders/minicart"; + * registerInlineLoader("vtex/loaders/minicart", minicart); * ``` */ diff --git a/vtex/inline-loaders/productList.ts b/vtex/loaders/productListFull.ts similarity index 100% rename from vtex/inline-loaders/productList.ts rename to vtex/loaders/productListFull.ts diff --git a/vtex/inline-loaders/workflowProducts.ts b/vtex/loaders/workflow/products.ts similarity index 89% rename from vtex/inline-loaders/workflowProducts.ts rename to vtex/loaders/workflow/products.ts index f35f0cb..890baea 100644 --- a/vtex/inline-loaders/workflowProducts.ts +++ b/vtex/loaders/workflow/products.ts @@ -3,10 +3,10 @@ * Maps IS response to schema.org Product[] following deco-cx/apps pattern. */ -import type { Product } from "../../commerce/types/commerce"; -import { getVtexConfig, intelligentSearch, toFacetPath } from "../client"; -import { pickSku, toProduct } from "../utils/transform"; -import type { Product as ProductVTEX } from "../utils/types"; +import type { Product } from "../../../commerce/types/commerce"; +import { getVtexConfig, intelligentSearch, toFacetPath } from "../../client"; +import { pickSku, toProduct } from "../../utils/transform"; +import type { Product as ProductVTEX } from "../../utils/types"; export interface WorkflowProductsProps { props?: {