@shopify/hydrogen 0.6.3 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. package/dist/esnext/components/AddToCartButton/AddToCartButton.client.d.ts +1 -1
  2. package/dist/esnext/components/AddToCartButton/AddToCartButton.client.js +3 -3
  3. package/dist/esnext/components/CartEstimatedCost/CartEstimatedCost.client.d.ts +1 -1
  4. package/dist/esnext/components/CartEstimatedCost/CartEstimatedCost.client.js +1 -1
  5. package/dist/esnext/components/CartLineProvider/context.d.ts +3 -3
  6. package/dist/esnext/components/CartProvider/CartProvider.client.js +0 -1
  7. package/dist/esnext/components/ExternalVideo/ExternalVideo.d.ts +1 -1
  8. package/dist/esnext/components/Image/Image.d.ts +1 -1
  9. package/dist/esnext/components/LocalizationProvider/index.d.ts +1 -0
  10. package/dist/esnext/components/LocalizationProvider/index.js +1 -0
  11. package/dist/esnext/components/MediaFile/MediaFile.d.ts +1 -1
  12. package/dist/esnext/components/Metafield/Metafield.client.d.ts +1 -1
  13. package/dist/esnext/components/Metafield/Metafield.client.js +8 -0
  14. package/dist/esnext/components/Metafield/MetafieldFragment.d.ts +16 -1
  15. package/dist/esnext/components/Metafield/components/StarRating/StarRating.d.ts +1 -1
  16. package/dist/esnext/components/Metafield/index.d.ts +2 -2
  17. package/dist/esnext/components/Model3D/Model3D.client.d.ts +3 -1
  18. package/dist/esnext/components/Model3D/Model3D.client.js +1 -1
  19. package/dist/esnext/components/Money/Money.client.d.ts +1 -1
  20. package/dist/esnext/components/ProductPrice/ProductPrice.client.d.ts +1 -3
  21. package/dist/esnext/components/ProductPrice/ProductPrice.client.js +1 -3
  22. package/dist/esnext/components/ProductProvider/ProductProvider.client.d.ts +1 -1
  23. package/dist/esnext/components/ProductProvider/context.d.ts +2 -2
  24. package/dist/esnext/components/ProductProvider/types.d.ts +2 -2
  25. package/dist/esnext/components/SelectedVariantAddToCartButton/SelectedVariantAddToCartButton.client.d.ts +1 -1
  26. package/dist/esnext/components/SelectedVariantAddToCartButton/SelectedVariantAddToCartButton.client.js +1 -1
  27. package/dist/esnext/components/UnitPrice/UnitPrice.client.d.ts +2 -3
  28. package/dist/esnext/components/UnitPrice/UnitPrice.client.js +1 -2
  29. package/dist/esnext/components/Video/Video.d.ts +1 -1
  30. package/dist/esnext/components/index.d.ts +3 -2
  31. package/dist/esnext/components/index.js +1 -0
  32. package/dist/esnext/entry-client.js +4 -6
  33. package/dist/esnext/entry-server.js +49 -32
  34. package/dist/esnext/foundation/RenderCacheProvider/RenderCacheContext.d.ts +2 -0
  35. package/dist/esnext/foundation/RenderCacheProvider/RenderCacheContext.js +4 -0
  36. package/dist/esnext/foundation/RenderCacheProvider/RenderCacheProvider.d.ts +2 -0
  37. package/dist/esnext/foundation/RenderCacheProvider/RenderCacheProvider.js +5 -0
  38. package/dist/esnext/foundation/RenderCacheProvider/hook.d.ts +11 -0
  39. package/dist/esnext/foundation/RenderCacheProvider/hook.js +34 -0
  40. package/dist/esnext/foundation/RenderCacheProvider/index.d.ts +1 -0
  41. package/dist/esnext/foundation/RenderCacheProvider/index.js +1 -0
  42. package/dist/esnext/foundation/RenderCacheProvider/types.d.ts +11 -0
  43. package/dist/esnext/foundation/RenderCacheProvider/types.js +1 -0
  44. package/dist/esnext/foundation/Router/ServerStateRouter.client.js +5 -3
  45. package/dist/esnext/foundation/ServerStateProvider/ServerStateProvider.client.d.ts +19 -11
  46. package/dist/esnext/foundation/ServerStateProvider/ServerStateProvider.client.js +21 -20
  47. package/dist/esnext/foundation/ServerStateProvider/index.d.ts +2 -1
  48. package/dist/esnext/foundation/ShopifyProvider/ShopifyServerProvider.server.d.ts +1 -3
  49. package/dist/esnext/foundation/ShopifyProvider/ShopifyServerProvider.server.js +2 -4
  50. package/dist/esnext/foundation/ShopifyProvider/types.d.ts +0 -5
  51. package/dist/esnext/foundation/useQuery/hooks.d.ts +17 -0
  52. package/dist/esnext/{hooks → foundation}/useQuery/hooks.js +14 -6
  53. package/dist/esnext/foundation/useQuery/index.d.ts +1 -0
  54. package/dist/esnext/foundation/useQuery/index.js +1 -0
  55. package/dist/esnext/foundation/useServerState/use-server-state.d.ts +2 -2
  56. package/dist/esnext/foundation/useServerState/use-server-state.js +1 -1
  57. package/dist/esnext/framework/ClientMarker/ClientMarker.js +0 -1
  58. package/dist/esnext/framework/Hydration/Cache.client.js +3 -1
  59. package/dist/esnext/framework/Hydration/ServerComponentResponse.server.d.ts +10 -0
  60. package/dist/esnext/framework/Hydration/ServerComponentResponse.server.js +13 -0
  61. package/dist/esnext/framework/Hydration/wire.server.js +1 -1
  62. package/dist/esnext/framework/Hydration/writer.server.js +1 -0
  63. package/dist/esnext/framework/cache.d.ts +2 -2
  64. package/dist/esnext/framework/cache.js +1 -1
  65. package/dist/esnext/framework/middleware.d.ts +5 -1
  66. package/dist/esnext/framework/middleware.js +12 -8
  67. package/dist/esnext/framework/plugins/resolver.d.ts +1 -0
  68. package/dist/esnext/framework/plugins/resolver.js +3 -0
  69. package/dist/esnext/framework/plugins/vite-plugin-hydrogen-config.js +15 -1
  70. package/dist/esnext/framework/plugins/vite-plugin-hydrogen-middleware.js +8 -2
  71. package/dist/esnext/framework/plugins/vite-plugin-react-server-components-shim.js +10 -20
  72. package/dist/esnext/framework/server-components.js +25 -47
  73. package/dist/esnext/graphql/graphql-constants.d.ts +74 -37
  74. package/dist/esnext/graphql/graphql-constants.js +89 -15
  75. package/dist/esnext/handle-event.d.ts +1 -1
  76. package/dist/esnext/handle-event.js +8 -4
  77. package/dist/esnext/hooks/index.d.ts +1 -1
  78. package/dist/esnext/hooks/index.js +1 -1
  79. package/dist/esnext/hooks/useCartLine/useCartLine.d.ts +3 -3
  80. package/dist/esnext/hooks/useMoney/hooks.js +2 -16
  81. package/dist/esnext/hooks/useParsedMetafields/useParsedMetafields.d.ts +2 -3
  82. package/dist/esnext/hooks/useProductOptions/types.d.ts +2 -3
  83. package/dist/esnext/hooks/useShopQuery/hooks.d.ts +4 -2
  84. package/dist/esnext/hooks/useShopQuery/hooks.js +22 -13
  85. package/dist/esnext/types.d.ts +21 -4
  86. package/dist/esnext/utilities/flattenConnection/flattenConnection.d.ts +0 -7
  87. package/dist/esnext/utilities/flattenConnection/flattenConnection.js +0 -7
  88. package/dist/esnext/utilities/isClient/isClient.d.ts +0 -4
  89. package/dist/esnext/utilities/isClient/isClient.js +0 -4
  90. package/dist/esnext/utilities/isServer/isServer.d.ts +0 -4
  91. package/dist/esnext/utilities/isServer/isServer.js +0 -4
  92. package/dist/esnext/utilities/parseMetafieldValue/parseMetafieldValue.d.ts +2 -33
  93. package/dist/esnext/utilities/parseMetafieldValue/parseMetafieldValue.js +0 -31
  94. package/dist/esnext/utilities/suspense.d.ts +2 -2
  95. package/dist/esnext/utilities/suspense.js +0 -6
  96. package/dist/esnext/version.d.ts +1 -1
  97. package/dist/esnext/version.js +1 -1
  98. package/dist/node/framework/ClientMarker/ClientMarker.js +2 -3
  99. package/dist/node/framework/Hydration/Cache.client.js +7 -5
  100. package/dist/node/framework/Hydration/HydrationContext.server.js +1 -1
  101. package/dist/node/framework/Hydration/ServerComponentResponse.server.d.ts +10 -0
  102. package/dist/node/framework/Hydration/ServerComponentResponse.server.js +15 -2
  103. package/dist/node/framework/Hydration/react-utils.js +3 -3
  104. package/dist/node/framework/Hydration/wire.server.js +2 -2
  105. package/dist/node/framework/Hydration/writer.server.js +1 -0
  106. package/dist/node/framework/cache.d.ts +2 -2
  107. package/dist/node/framework/cache.js +5 -4
  108. package/dist/node/framework/middleware.d.ts +5 -1
  109. package/dist/node/framework/middleware.js +17 -11
  110. package/dist/node/framework/plugin.js +5 -5
  111. package/dist/node/framework/plugins/resolver.d.ts +1 -0
  112. package/dist/node/framework/plugins/resolver.js +7 -0
  113. package/dist/node/framework/plugins/vite-plugin-hydrogen-config.js +15 -1
  114. package/dist/node/framework/plugins/vite-plugin-hydrogen-middleware.js +8 -2
  115. package/dist/node/framework/plugins/vite-plugin-react-server-components-shim.js +11 -21
  116. package/dist/node/framework/server-components.js +27 -49
  117. package/dist/node/handle-event.d.ts +1 -1
  118. package/dist/node/handle-event.js +12 -8
  119. package/dist/node/types.d.ts +21 -4
  120. package/dist/node/utilities/fetch.js +1 -1
  121. package/dist/node/utilities/flattenConnection/flattenConnection.d.ts +0 -7
  122. package/dist/node/utilities/flattenConnection/flattenConnection.js +0 -7
  123. package/dist/node/utilities/isClient/isClient.d.ts +0 -4
  124. package/dist/node/utilities/isClient/isClient.js +0 -4
  125. package/dist/node/utilities/isServer/isServer.d.ts +0 -4
  126. package/dist/node/utilities/isServer/isServer.js +1 -5
  127. package/dist/node/utilities/parseMetafieldValue/parseMetafieldValue.d.ts +2 -33
  128. package/dist/node/utilities/parseMetafieldValue/parseMetafieldValue.js +0 -31
  129. package/dist/node/utilities/suspense.d.ts +2 -2
  130. package/dist/node/utilities/suspense.js +0 -6
  131. package/dist/node/utilities/video_parameters.js +1 -1
  132. package/dist/node/version.d.ts +1 -1
  133. package/dist/node/version.js +1 -1
  134. package/dist/worker/framework/Hydration/ServerComponentResponse.server.d.ts +10 -0
  135. package/dist/worker/framework/Hydration/ServerComponentResponse.server.js +13 -0
  136. package/dist/worker/framework/cache.d.ts +2 -2
  137. package/dist/worker/framework/cache.js +1 -1
  138. package/dist/worker/handle-event.d.ts +1 -1
  139. package/dist/worker/handle-event.js +8 -4
  140. package/dist/worker/types.d.ts +21 -4
  141. package/package.json +11 -9
  142. package/dist/esnext/hooks/useQuery/QueryProvider.d.ts +0 -6
  143. package/dist/esnext/hooks/useQuery/QueryProvider.js +0 -13
  144. package/dist/esnext/hooks/useQuery/hooks.d.ts +0 -15
  145. package/dist/esnext/hooks/useQuery/index.d.ts +0 -2
  146. package/dist/esnext/hooks/useQuery/index.js +0 -2
@@ -22,18 +22,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
22
22
  return (mod && mod.__esModule) ? mod : { "default": mod };
23
23
  };
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.hydrogenMiddleware = exports.graphiqlMiddleware = void 0;
25
26
  const graphiql_1 = require("./graphiql");
26
27
  const handle_event_1 = __importDefault(require("../handle-event"));
27
- /**
28
- * Provides middleware to Node.js Express-like servers. Used by the Hydrogen
29
- * Vite dev server plugin as well as production Node.js implementation.
30
- */
31
- function hydrogenMiddleware({ dev, shopifyConfig, cache, indexTemplate, getServerEntrypoint, devServer, }) {
28
+ function graphiqlMiddleware({ shopifyConfig, dev, }) {
32
29
  return async function (request, response, next) {
33
30
  const graphiqlRequest = dev && isGraphiqlRequest(request);
34
31
  if (graphiqlRequest) {
35
32
  return respondWithGraphiql(response, shopifyConfig);
36
33
  }
34
+ next();
35
+ };
36
+ }
37
+ exports.graphiqlMiddleware = graphiqlMiddleware;
38
+ /**
39
+ * Provides middleware to Node.js Express-like servers. Used by the Hydrogen
40
+ * Vite dev server plugin as well as production Node.js implementation.
41
+ */
42
+ function hydrogenMiddleware({ dev, cache, indexTemplate, getServerEntrypoint, devServer, }) {
43
+ return async function (request, response, next) {
37
44
  const url = new URL('http://' + request.headers.host + request.originalUrl);
38
45
  const isReactHydrationRequest = url.pathname === '/react';
39
46
  /**
@@ -67,7 +74,7 @@ function hydrogenMiddleware({ dev, shopifyConfig, cache, indexTemplate, getServe
67
74
  * polyfill has loaded above.
68
75
  */
69
76
  const { ServerComponentRequest } = await Promise.resolve().then(() => __importStar(require('./Hydration/ServerComponentRequest.server')));
70
- const eventResponse = await handle_event_1.default(
77
+ const eventResponse = await (0, handle_event_1.default)(
71
78
  /**
72
79
  * Mimic a `FetchEvent`
73
80
  */
@@ -118,12 +125,11 @@ function hydrogenMiddleware({ dev, shopifyConfig, cache, indexTemplate, getServe
118
125
  }
119
126
  };
120
127
  }
121
- exports.default = hydrogenMiddleware;
128
+ exports.hydrogenMiddleware = hydrogenMiddleware;
122
129
  function shouldInterceptRequest(request, isReactHydrationRequest) {
123
130
  var _a;
124
- return ((/text\/html|application\/hydrogen/.test((_a = request.headers['accept']) !== null && _a !== void 0 ? _a : '') ||
125
- isReactHydrationRequest) &&
126
- request.url !== '/favicon.ico');
131
+ return (/text\/html|application\/hydrogen/.test((_a = request.headers['accept']) !== null && _a !== void 0 ? _a : '') ||
132
+ isReactHydrationRequest);
127
133
  }
128
134
  /**
129
135
  * /graphiql and /___graphql are supported
@@ -137,5 +143,5 @@ async function respondWithGraphiql(response, shopifyConfig) {
137
143
  }
138
144
  const { storeDomain, storefrontToken, graphqlApiVersion } = shopifyConfig;
139
145
  response.setHeader('Content-Type', 'text/html');
140
- response.end(graphiql_1.graphiqlHtml(storeDomain === null || storeDomain === void 0 ? void 0 : storeDomain.replace(/^https?:\/\//, ''), storefrontToken, graphqlApiVersion));
146
+ response.end((0, graphiql_1.graphiqlHtml)(storeDomain === null || storeDomain === void 0 ? void 0 : storeDomain.replace(/^https?:\/\//, ''), storefrontToken, graphqlApiVersion));
141
147
  }
@@ -10,10 +10,10 @@ const vite_plugin_inspect_1 = __importDefault(require("vite-plugin-inspect"));
10
10
  const plugin_react_1 = __importDefault(require("@vitejs/plugin-react"));
11
11
  exports.default = (shopifyConfig, pluginOptions) => {
12
12
  return [
13
- process.env.VITE_INSPECT && vite_plugin_inspect_1.default(),
14
- vite_plugin_hydrogen_config_1.default(),
15
- vite_plugin_hydrogen_middleware_1.default(shopifyConfig, pluginOptions),
16
- vite_plugin_react_server_components_shim_1.default(),
17
- plugin_react_1.default(),
13
+ process.env.VITE_INSPECT && (0, vite_plugin_inspect_1.default)(),
14
+ (0, vite_plugin_hydrogen_config_1.default)(),
15
+ (0, vite_plugin_hydrogen_middleware_1.default)(shopifyConfig, pluginOptions),
16
+ (0, vite_plugin_react_server_components_shim_1.default)(),
17
+ (0, plugin_react_1.default)(),
18
18
  ];
19
19
  };
@@ -0,0 +1 @@
1
+ export declare function resolve(path: string): string;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolve = void 0;
4
+ function resolve(path) {
5
+ return require.resolve(path);
6
+ }
7
+ exports.resolve = resolve;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = () => {
4
4
  return {
5
5
  name: 'vite-plugin-hydrogen-config',
6
- config: () => ({
6
+ config: (_, env) => ({
7
7
  resolve: {
8
8
  alias: {
9
9
  /**
@@ -18,6 +18,17 @@ exports.default = () => {
18
18
  },
19
19
  build: {
20
20
  sourcemap: true,
21
+ /**
22
+ * By default, SSR dedupe logic gets bundled which runs `require('module')`.
23
+ * We don't want this in our workers runtime, because `require` is not supported.
24
+ */
25
+ rollupOptions: process.env.WORKER
26
+ ? {
27
+ output: {
28
+ format: 'es',
29
+ },
30
+ }
31
+ : {},
21
32
  },
22
33
  ssr: {
23
34
  external: ['isomorphic-dompurify'],
@@ -54,6 +65,9 @@ exports.default = () => {
54
65
  'react-router-dom',
55
66
  ],
56
67
  },
68
+ define: {
69
+ __DEV__: env.mode !== 'production',
70
+ },
57
71
  }),
58
72
  };
59
73
  };
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const path_1 = __importDefault(require("path"));
7
7
  const fs_1 = require("fs");
8
- const middleware_1 = __importDefault(require("../middleware"));
8
+ const middleware_1 = require("../middleware");
9
9
  const in_memory_1 = require("../cache/in-memory");
10
10
  exports.default = (shopifyConfig, pluginOptions) => {
11
11
  return {
@@ -22,7 +22,13 @@ exports.default = (shopifyConfig, pluginOptions) => {
22
22
  const indexHtml = await fs_1.promises.readFile(resolve('index.html'), 'utf-8');
23
23
  return await server.transformIndexHtml(url, indexHtml);
24
24
  }
25
- server.middlewares.use(middleware_1.default({
25
+ // The default vite middleware rewrites the URL `/graphqil` to `/index.html`
26
+ // By running this middleware first, we avoid that.
27
+ server.middlewares.use((0, middleware_1.graphiqlMiddleware)({
28
+ shopifyConfig,
29
+ dev: true,
30
+ }));
31
+ return () => server.middlewares.use((0, middleware_1.hydrogenMiddleware)({
26
32
  dev: true,
27
33
  shopifyConfig,
28
34
  indexTemplate: getIndexTemplate,
@@ -3,8 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ const vite_1 = require("vite");
6
7
  const path_1 = __importDefault(require("path"));
7
8
  const server_components_1 = require("../server-components");
9
+ const resolver_1 = require("./resolver");
8
10
  exports.default = () => {
9
11
  let config;
10
12
  return {
@@ -37,12 +39,12 @@ exports.default = () => {
37
39
  'When using Hydrogen components within Client Components, use the `@shopify/hydrogen/client` entrypoint instead.');
38
40
  }
39
41
  },
40
- load(id, options) {
42
+ async load(id, options) {
41
43
  if (!isSSR(options))
42
44
  return null;
43
45
  // Wrapped components won't match this becase they end in ?no-proxy
44
46
  if (/\.client\.[jt]sx?$/.test(id)) {
45
- return server_components_1.proxyClientComponent({ id });
47
+ return (0, server_components_1.proxyClientComponent)({ id });
46
48
  }
47
49
  return null;
48
50
  },
@@ -59,35 +61,23 @@ exports.default = () => {
59
61
  */
60
62
  if (id.includes('/Hydration/client-imports')) {
61
63
  // eslint-disable-next-line node/no-missing-require
62
- const hydrogenPath = path_1.default.dirname(require.resolve('@shopify/hydrogen'));
64
+ const hydrogenPath = path_1.default.dirname((0, resolver_1.resolve)('@shopify/hydrogen'));
63
65
  const importerPath = path_1.default.join(hydrogenPath, 'framework', 'Hydration');
64
- const importerToRootPath = path_1.default.relative(importerPath, config.root);
66
+ const importerToRootPath = (0, vite_1.normalizePath)(path_1.default.relative(importerPath, config.root));
65
67
  const [importerToRootNested] = importerToRootPath.match(/(\.\.\/)+(\.\.)?/) || [];
66
68
  const userPrefix = path_1.default.normalize(path_1.default.join(importerPath, importerToRootNested.replace(/\/?$/, path_1.default.sep)));
67
69
  const userGlob = path_1.default.join(importerToRootPath, 'src', '**/*.client.[jt]sx');
68
70
  const libPrefix = hydrogenPath + path_1.default.sep;
69
71
  const libGlob = path_1.default.join(path_1.default.relative(importerPath, hydrogenPath), 'components', '**/*.client.js');
70
72
  return code
71
- .replace('__USER_COMPONENTS_PREFIX__', userPrefix)
72
- .replace('__USER_COMPONENTS_GLOB__', userGlob)
73
- .replace('__LIB_COMPONENTS_PREFIX__', libPrefix)
74
- .replace('__LIB_COMPONENTS_GLOB__', libGlob);
73
+ .replace('__USER_COMPONENTS_PREFIX__', (0, vite_1.normalizePath)(userPrefix))
74
+ .replace('__USER_COMPONENTS_GLOB__', (0, vite_1.normalizePath)(userGlob))
75
+ .replace('__LIB_COMPONENTS_PREFIX__', (0, vite_1.normalizePath)(libPrefix))
76
+ .replace('__LIB_COMPONENTS_GLOB__', (0, vite_1.normalizePath)(libGlob));
75
77
  }
76
78
  },
77
79
  };
78
- // Mitigation for upcoming minor Vite update
79
- // https://github.com/vitejs/vite/pull/5253
80
- // TO-DO: When the vite package is updated with the above Vite PR,
81
- // clean up this function and treat `options` param as objects
82
- // from this point forward
83
- // Timeline: Targetting for Vite 2.7
84
80
  function isSSR(options) {
85
- if (typeof options === 'boolean') {
86
- return options;
87
- }
88
- if (typeof options === 'object') {
89
- return !!options.ssr;
90
- }
91
- return false;
81
+ return !!(options === null || options === void 0 ? void 0 : options.ssr);
92
82
  }
93
83
  };
@@ -8,68 +8,46 @@ const es_module_lexer_1 = require("es-module-lexer");
8
8
  const fs_1 = require("fs");
9
9
  const vite_1 = require("vite");
10
10
  const magic_string_1 = __importDefault(require("magic-string"));
11
+ const DEFAULT_EXPORT = 'default';
11
12
  async function proxyClientComponent({ id, src, }) {
12
- var _a;
13
- const defaultComponentName = (_a = id.split('/').pop()) === null || _a === void 0 ? void 0 : _a.split('.').shift();
14
13
  // Modify the import ID to avoid infinite wraps
15
14
  const importFrom = `${id}?no-proxy`;
16
15
  await es_module_lexer_1.init;
17
16
  if (!src) {
18
17
  src = await fs_1.promises.readFile(id, 'utf-8');
19
18
  }
20
- const { code } = await vite_1.transformWithEsbuild(src, id);
21
- const [, exportStatements] = es_module_lexer_1.parse(code);
22
- const hasDefaultExport = exportStatements.includes('default');
23
- // Split namedImports in components to wrap and everything else (e.g. GQL Fragments)
24
- const namedImports = exportStatements.reduce((acc, i) => {
25
- if (i !== 'default') {
26
- // Add here any other naming pattern for a non-component export
27
- if (/^use[A-Z]|Fragment$|Context$|^[A-Z_]+$/.test(i)) {
28
- acc.other.push(i);
29
- }
30
- else {
31
- acc.components.push(i);
32
- }
19
+ const { code } = await (0, vite_1.transformWithEsbuild)(src, id);
20
+ const [, exportStatements] = (0, es_module_lexer_1.parse)(code);
21
+ // Classify exports in components to wrap vs. everything else (e.g. GQL Fragments)
22
+ const otherExports = [];
23
+ const componentExports = [];
24
+ for (const key of exportStatements) {
25
+ if (key !== DEFAULT_EXPORT &&
26
+ /^use[A-Z]|Fragment$|Context$|^[A-Z_]+$/.test(key)) {
27
+ otherExports.push(key);
33
28
  }
34
- return acc;
35
- }, { components: [], other: [] });
36
- if (!hasDefaultExport && namedImports.components.length === 0) {
37
- return `export * from '${importFrom}';\n`;
38
- }
39
- const s = new magic_string_1.default(`import {wrapInClientMarker} from '@shopify/hydrogen/marker';`);
40
- s.append('\nimport ');
41
- if (hasDefaultExport) {
42
- s.append(defaultComponentName);
43
- if (namedImports.components.length > 0) {
44
- s.append(', ');
29
+ else {
30
+ componentExports.push(key);
45
31
  }
46
32
  }
47
- if (namedImports.components.length) {
48
- s.append('* as namedImports');
33
+ if (componentExports.length === 0) {
34
+ return `export * from '${importFrom}';\n`;
49
35
  }
50
- s.append(` from '${importFrom}';\n\n`);
36
+ const s = new magic_string_1.default(`import {wrapInClientMarker} from '@shopify/hydrogen/marker';\n` +
37
+ `import * as allImports from '${importFrom}';\n\n`);
51
38
  // Re-export other stuff directly without wrapping
52
- if (namedImports.other.length > 0) {
53
- s.append(`export {${namedImports.other.join(', ')}} from '${importFrom}';\n`);
39
+ if (otherExports.length > 0) {
40
+ s.append(`export {${otherExports.join(', ')}} from '${importFrom}';\n`);
54
41
  }
55
- if (hasDefaultExport) {
56
- s.append(generateComponentExport({
57
- id,
58
- componentName: defaultComponentName,
59
- isDefault: true,
60
- }));
61
- }
62
- namedImports.components.forEach((name) => s.append(generateComponentExport({
63
- id,
64
- componentName: name,
65
- isDefault: false,
66
- })));
42
+ // Wrap components in Client Marker
43
+ componentExports.forEach((key) => {
44
+ var _a;
45
+ const isDefault = key === DEFAULT_EXPORT;
46
+ const componentName = isDefault
47
+ ? (_a = id.split('/').pop()) === null || _a === void 0 ? void 0 : _a.split('.').shift()
48
+ : key;
49
+ s.append(`export ${isDefault ? DEFAULT_EXPORT : `const ${componentName} =`} wrapInClientMarker({ name: '${componentName}', id: '${id}', component: allImports['${key}'], named: ${!isDefault} });\n`);
50
+ });
67
51
  return s.toString();
68
52
  }
69
53
  exports.proxyClientComponent = proxyClientComponent;
70
- function generateComponentExport({ id, isDefault, componentName, }) {
71
- const component = isDefault
72
- ? componentName
73
- : `namedImports['${componentName}']`;
74
- return `export ${isDefault ? 'default' : `const ${componentName} =`} wrapInClientMarker({ name: '${componentName}', id: '${id}', component: ${component}, named: ${!isDefault} });\n`;
75
- }
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import type { ServerResponse } from 'http';
2
+ import { ServerResponse } from 'http';
3
3
  import type { ServerComponentRequest } from './framework/Hydration/ServerComponentRequest.server';
4
4
  import { RuntimeContext } from './framework/runtime';
5
5
  interface HydrogenFetchEvent {
@@ -4,14 +4,14 @@ const cache_1 = require("./framework/cache");
4
4
  const runtime_1 = require("./framework/runtime");
5
5
  const config_1 = require("./framework/config");
6
6
  async function handleEvent(event, { request, entrypoint, indexTemplate, assetHandler, streamableResponse, dev, cache, context, }) {
7
- var _a, _b, _c;
7
+ var _a, _b, _c, _d, _e;
8
8
  const url = new URL(request.url);
9
9
  /**
10
10
  * Inject the cache & context into the module loader so we can pull it out for subrequests.
11
11
  */
12
- runtime_1.setCache(cache);
13
- runtime_1.setContext(context);
14
- config_1.setConfig({ dev });
12
+ (0, runtime_1.setCache)(cache);
13
+ (0, runtime_1.setContext)(context);
14
+ (0, config_1.setConfig)({ dev });
15
15
  const isReactHydrationRequest = url.pathname === '/react';
16
16
  const template = typeof indexTemplate === 'function'
17
17
  ? await indexTemplate(url.toString())
@@ -56,17 +56,19 @@ async function handleEvent(event, { request, entrypoint, indexTemplate, assetHan
56
56
  * TODO: Also add `Vary` headers for `accept-language` and any other keys
57
57
  * we want to shard our full-page cache for all Hydrogen storefronts.
58
58
  */
59
- headers.set(cache_1.getCacheControlHeader({ dev }), componentResponse.cacheControlHeader);
59
+ headers.set((0, cache_1.getCacheControlHeader)({ dev }), componentResponse.cacheControlHeader);
60
60
  if (componentResponse.customBody) {
61
+ const { status, customStatus } = componentResponse;
61
62
  return new Response(await componentResponse.customBody, {
62
- status: (_a = componentResponse.status) !== null && _a !== void 0 ? _a : 200,
63
+ status: (_b = (_a = customStatus === null || customStatus === void 0 ? void 0 : customStatus.code) !== null && _a !== void 0 ? _a : status) !== null && _b !== void 0 ? _b : 200,
64
+ statusText: customStatus === null || customStatus === void 0 ? void 0 : customStatus.text,
63
65
  headers,
64
66
  });
65
67
  }
66
68
  let response;
67
69
  if (isReactHydrationRequest) {
68
70
  response = new Response(body, {
69
- status: (_b = componentResponse.status) !== null && _b !== void 0 ? _b : 200,
71
+ status: (_c = componentResponse.status) !== null && _c !== void 0 ? _c : 200,
70
72
  headers,
71
73
  });
72
74
  }
@@ -77,8 +79,10 @@ async function handleEvent(event, { request, entrypoint, indexTemplate, assetHan
77
79
  .replace('<body', bodyAttributes ? `<body ${bodyAttributes}` : '$&')
78
80
  .replace('<html', htmlAttributes ? `<html ${htmlAttributes}` : '$&');
79
81
  headers.append('content-type', 'text/html');
82
+ const { status, customStatus } = componentResponse;
80
83
  response = new Response(html, {
81
- status: (_c = componentResponse.status) !== null && _c !== void 0 ? _c : 200,
84
+ status: (_e = (_d = customStatus === null || customStatus === void 0 ? void 0 : customStatus.code) !== null && _d !== void 0 ? _d : status) !== null && _e !== void 0 ? _e : 200,
85
+ statusText: customStatus === null || customStatus === void 0 ? void 0 : customStatus.text,
82
86
  headers,
83
87
  });
84
88
  }
@@ -1,8 +1,8 @@
1
1
  /// <reference types="node" />
2
- import type { ServerResponse } from 'http';
2
+ import { ServerResponse } from 'http';
3
3
  import type { ServerComponentResponse } from './framework/Hydration/ServerComponentResponse.server';
4
4
  import type { ServerComponentRequest } from './framework/Hydration/ServerComponentRequest.server';
5
- import type { Metafield } from './graphql/types/types';
5
+ import type { Metafield, Image, MediaContentType } from './graphql/types/types';
6
6
  export declare type Renderer = (url: URL, options: {
7
7
  request: ServerComponentRequest;
8
8
  context?: Record<string, any>;
@@ -50,9 +50,24 @@ export interface GraphQLConnection<T> {
50
50
  node: T;
51
51
  }[];
52
52
  }
53
- export declare type RawMetafield = Partial<Metafield>;
54
- export declare type ParsedMetafield = Omit<Partial<Metafield>, 'value'> & {
53
+ export interface MediaImage {
54
+ __typename?: string;
55
+ id?: string;
56
+ mediaContentType?: MediaContentType;
57
+ image?: Pick<Image, 'altText' | 'url' | 'id' | 'width' | 'height'>;
58
+ }
59
+ interface ProductVariant {
60
+ __typename?: string;
61
+ }
62
+ interface Product {
63
+ __typename?: string;
64
+ }
65
+ export declare type RawMetafield = Omit<Partial<Metafield>, 'reference'> & {
66
+ reference?: MediaImage | ProductVariant | Product | null;
67
+ };
68
+ export declare type ParsedMetafield = Omit<Partial<Metafield>, 'value' | 'reference'> & {
55
69
  value?: string | number | boolean | Record<any, string> | Date | Rating | Measurement;
70
+ reference?: MediaImage | ProductVariant | Product | null;
56
71
  };
57
72
  export interface Rating {
58
73
  value: number;
@@ -63,6 +78,7 @@ export interface Measurement {
63
78
  unit: string;
64
79
  value: number;
65
80
  }
81
+ export declare type QueryKey = string | readonly unknown[];
66
82
  export interface CacheOptions {
67
83
  private?: boolean;
68
84
  maxAge?: number;
@@ -72,3 +88,4 @@ export interface CacheOptions {
72
88
  export interface HydrogenVitePluginOptions {
73
89
  devCache?: boolean;
74
90
  }
91
+ export {};
@@ -47,7 +47,7 @@ function fetchBuilder(request) {
47
47
  }
48
48
  exports.fetchBuilder = fetchBuilder;
49
49
  function graphqlRequestBody(query, variables) {
50
- const queryString = typeof query === 'string' ? query : graphql_1.print(query);
50
+ const queryString = typeof query === 'string' ? query : (0, graphql_1.print)(query);
51
51
  return JSON.stringify({
52
52
  query: queryString,
53
53
  variables,
@@ -1,12 +1,5 @@
1
1
  import { GraphQLConnection } from '../../types';
2
2
  /**
3
3
  * The `flattenConnection` utility transforms a connection object from the Storefront API (for example, [Product-related connections](api/storefront/reference/products/product#connections)) into a flat array of nodes.
4
- * ## Arguments
5
- * | Description | Required |
6
- * | ------------| --------- |
7
- * | A connection object with the field `edges` whose value is an array of objects corresponding to `{node: Value}`. For example, any of the [Product connections](api/storefront/reference/products/product#connections) | Yes |
8
- *
9
- * ## Return type
10
- * A flat array whose elements correspond to the `node` value in each element of the original `edges` array.
11
4
  */
12
5
  export declare function flattenConnection<T>(connection: GraphQLConnection<T>): T[];
@@ -3,13 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.flattenConnection = void 0;
4
4
  /**
5
5
  * The `flattenConnection` utility transforms a connection object from the Storefront API (for example, [Product-related connections](api/storefront/reference/products/product#connections)) into a flat array of nodes.
6
- * ## Arguments
7
- * | Description | Required |
8
- * | ------------| --------- |
9
- * | A connection object with the field `edges` whose value is an array of objects corresponding to `{node: Value}`. For example, any of the [Product connections](api/storefront/reference/products/product#connections) | Yes |
10
- *
11
- * ## Return type
12
- * A flat array whose elements correspond to the `node` value in each element of the original `edges` array.
13
6
  */
14
7
  function flattenConnection(connection) {
15
8
  var _a;
@@ -1,8 +1,4 @@
1
1
  /** The `isClient` utility is a function that returns a boolean indicating
2
2
  * if the code was run on the client.
3
- * ## Arguments
4
- * None
5
- * ## Return type
6
- * A `boolean` indicating if the code was run on the client.
7
3
  */
8
4
  export declare function isClient(): boolean;
@@ -3,10 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isClient = void 0;
4
4
  /** The `isClient` utility is a function that returns a boolean indicating
5
5
  * if the code was run on the client.
6
- * ## Arguments
7
- * None
8
- * ## Return type
9
- * A `boolean` indicating if the code was run on the client.
10
6
  */
11
7
  function isClient() {
12
8
  return typeof window !== 'undefined';
@@ -1,8 +1,4 @@
1
1
  /** The `isServer` utility is a function that returns a `boolean` indicating
2
2
  * if the code was run on the server.
3
- * ## Arguments
4
- * None
5
- * ## Return type
6
- * A `boolean` indicating if the code was run on the server.
7
3
  */
8
4
  export declare function isServer(): boolean;
@@ -4,12 +4,8 @@ exports.isServer = void 0;
4
4
  const isClient_1 = require("../isClient");
5
5
  /** The `isServer` utility is a function that returns a `boolean` indicating
6
6
  * if the code was run on the server.
7
- * ## Arguments
8
- * None
9
- * ## Return type
10
- * A `boolean` indicating if the code was run on the server.
11
7
  */
12
8
  function isServer() {
13
- return !isClient_1.isClient();
9
+ return !(0, isClient_1.isClient)();
14
10
  }
15
11
  exports.isServer = isServer;
@@ -1,36 +1,5 @@
1
- import { Metafield } from '../../graphql/types/types';
1
+ import { RawMetafield } from '../../types';
2
2
  /**
3
3
  * The `parseMetafieldValue` function parses a [Metafield](/api/storefront/reference/common-objects/metafield)'s `value` from a string into a sensible type corresponding to the [Metafield](/api/storefront/reference/common-objects/metafield)'s `type`.
4
- *
5
- * ## Arguments
6
- *
7
- * | Description | Required |
8
- * | ------------------------------------------------------------------------- | -------- |
9
- * | A [Metafield object](/api/storefront/reference/common-objects/metafield). | Yes |
10
- *
11
- * ## Return type
12
- *
13
- * Depending on the `type` specified in the passed [Metafield](/api/storefront/reference/common-objects/metafield), the following type is returned:
14
- *
15
- * | Metafield `type` | `value` type |
16
- * | ------------------------ | --------------------------------------------------------------------------------------------- |
17
- * | `date` | [Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) |
18
- * | `date_time` | [Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) |
19
- * | `boolean` | boolean |
20
- * | `number_integer` | int |
21
- * | `number_decimal` | float |
22
- * | `json` | An object |
23
- * | `weight` | An object with `value` and `unit` keys |
24
- * | `dimension` | An object with `value` and `unit` keys |
25
- * | `volume` | An object with `value` and `unit` keys |
26
- * | `rating` | An object with `scale_min`, `scale_max`, and `value` keys |
27
- * | `color` | string |
28
- * | `single_line_text_field` | string |
29
- * | `multi_line_text_field` | string |
30
- * | `product_reference` | string |
31
- * | `file_reference` | string |
32
- * | `page_reference` | string |
33
- * | `variant_reference` | string |
34
- * | `url` | string |
35
4
  */
36
- export declare function parseMetafieldValue(metafield: Partial<Metafield>): any;
5
+ export declare function parseMetafieldValue(metafield: Partial<RawMetafield>): any;
@@ -3,37 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseMetafieldValue = void 0;
4
4
  /**
5
5
  * The `parseMetafieldValue` function parses a [Metafield](/api/storefront/reference/common-objects/metafield)'s `value` from a string into a sensible type corresponding to the [Metafield](/api/storefront/reference/common-objects/metafield)'s `type`.
6
- *
7
- * ## Arguments
8
- *
9
- * | Description | Required |
10
- * | ------------------------------------------------------------------------- | -------- |
11
- * | A [Metafield object](/api/storefront/reference/common-objects/metafield). | Yes |
12
- *
13
- * ## Return type
14
- *
15
- * Depending on the `type` specified in the passed [Metafield](/api/storefront/reference/common-objects/metafield), the following type is returned:
16
- *
17
- * | Metafield `type` | `value` type |
18
- * | ------------------------ | --------------------------------------------------------------------------------------------- |
19
- * | `date` | [Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) |
20
- * | `date_time` | [Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) |
21
- * | `boolean` | boolean |
22
- * | `number_integer` | int |
23
- * | `number_decimal` | float |
24
- * | `json` | An object |
25
- * | `weight` | An object with `value` and `unit` keys |
26
- * | `dimension` | An object with `value` and `unit` keys |
27
- * | `volume` | An object with `value` and `unit` keys |
28
- * | `rating` | An object with `scale_min`, `scale_max`, and `value` keys |
29
- * | `color` | string |
30
- * | `single_line_text_field` | string |
31
- * | `multi_line_text_field` | string |
32
- * | `product_reference` | string |
33
- * | `file_reference` | string |
34
- * | `page_reference` | string |
35
- * | `variant_reference` | string |
36
- * | `url` | string |
37
6
  */
38
7
  function parseMetafieldValue(metafield) {
39
8
  if (metafield.value == null) {
@@ -2,6 +2,6 @@
2
2
  * Wrap the fetch promise in a way that React Suspense understands.
3
3
  * Essentially, keep throwing something until you have legit data.
4
4
  */
5
- export declare function wrapPromise(promise: Promise<any>): {
6
- read: () => any;
5
+ export declare function wrapPromise<T>(promise: Promise<T>): {
6
+ read: () => T;
7
7
  };
@@ -14,14 +14,8 @@ function wrapPromise(promise) {
14
14
  }, (err) => {
15
15
  status = 'error';
16
16
  response = err;
17
- throw err;
18
17
  });
19
18
  const read = () => {
20
- /**
21
- * TODO: This logic doesn't hold up when an error is thrown. For some reason.
22
- * We instead throw the exception above in the suspender. We should revisit
23
- * this and add a better server fetch implementation.
24
- */
25
19
  switch (status) {
26
20
  case 'pending':
27
21
  throw suspender;
@@ -17,7 +17,7 @@ function addParametersToEmbeddedVideoUrl(url, parameters) {
17
17
  }
18
18
  exports.addParametersToEmbeddedVideoUrl = addParametersToEmbeddedVideoUrl;
19
19
  function useEmbeddedVideoUrl(url, parameters) {
20
- return react_1.useMemo(() => {
20
+ return (0, react_1.useMemo)(() => {
21
21
  if (!parameters) {
22
22
  return url;
23
23
  }