@shopify/hydrogen 0.21.0 → 0.22.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 (110) hide show
  1. package/CHANGELOG.md +91 -0
  2. package/dist/esnext/client.d.ts +1 -0
  3. package/dist/esnext/client.js +1 -0
  4. package/dist/esnext/components/CartProvider/CartProvider.client.d.ts +7 -4
  5. package/dist/esnext/components/CartProvider/CartProvider.client.js +22 -12
  6. package/dist/esnext/components/Image/Image.d.ts +3 -3
  7. package/dist/esnext/components/Image/Image.js +12 -9
  8. package/dist/esnext/components/MediaFile/MediaFile.js +3 -2
  9. package/dist/esnext/components/Seo/NoIndexSeo.client.d.ts +3 -0
  10. package/dist/esnext/components/Seo/NoIndexSeo.client.js +10 -0
  11. package/dist/esnext/components/Seo/Seo.client.d.ts +4 -0
  12. package/dist/esnext/components/Seo/Seo.client.js +3 -0
  13. package/dist/esnext/config.d.ts +3 -3
  14. package/dist/esnext/entry-client.js +0 -3
  15. package/dist/esnext/entry-server.d.ts +2 -2
  16. package/dist/esnext/entry-server.js +70 -44
  17. package/dist/esnext/foundation/Analytics/Analytics.client.js +1 -1
  18. package/dist/esnext/foundation/Analytics/ClientAnalytics.js +2 -2
  19. package/dist/esnext/foundation/Analytics/connectors/PerformanceMetrics/PerformanceMetrics.client.js +2 -2
  20. package/dist/esnext/foundation/Analytics/index.d.ts +0 -1
  21. package/dist/esnext/foundation/Analytics/index.js +0 -1
  22. package/dist/esnext/foundation/FileRoutes/FileRoutes.server.js +5 -10
  23. package/dist/esnext/foundation/Router/BrowserRouter.client.d.ts +2 -1
  24. package/dist/esnext/foundation/Router/BrowserRouter.client.js +1 -1
  25. package/dist/esnext/foundation/ServerPropsProvider/ServerPropsProvider.js +0 -2
  26. package/dist/esnext/foundation/ShopifyProvider/ShopifyProvider.server.js +0 -1
  27. package/dist/esnext/foundation/useRouteParams/RouteParamsProvider.client.d.ts +2 -1
  28. package/dist/esnext/foundation/useRouteParams/RouteParamsProvider.client.js +1 -1
  29. package/dist/esnext/framework/Hydration/ServerComponentRequest.server.d.ts +2 -2
  30. package/dist/esnext/framework/Hydration/ServerComponentResponse.server.d.ts +0 -9
  31. package/dist/esnext/framework/Hydration/ServerComponentResponse.server.js +0 -19
  32. package/dist/esnext/framework/Hydration/rsc.js +2 -2
  33. package/dist/esnext/framework/middleware.js +1 -15
  34. package/dist/esnext/framework/plugin.js +2 -0
  35. package/dist/esnext/framework/plugins/vite-plugin-hydrogen-client-middleware.d.ts +1 -1
  36. package/dist/esnext/framework/plugins/vite-plugin-hydrogen-config.js +1 -1
  37. package/dist/esnext/framework/plugins/vite-plugin-hydrogen-middleware.js +6 -47
  38. package/dist/esnext/framework/plugins/vite-plugin-hydrogen-rsc.js +6 -11
  39. package/dist/esnext/framework/plugins/vite-plugin-hydrogen-virtual-files.d.ts +7 -0
  40. package/dist/esnext/framework/plugins/vite-plugin-hydrogen-virtual-files.js +99 -0
  41. package/dist/esnext/framework/plugins/vite-plugin-platform-entry.js +4 -4
  42. package/dist/esnext/framework/viteception.d.ts +4 -0
  43. package/dist/esnext/framework/viteception.js +15 -0
  44. package/dist/esnext/hooks/useShopQuery/hooks.d.ts +1 -2
  45. package/dist/esnext/hooks/useShopQuery/hooks.js +0 -1
  46. package/dist/esnext/index.d.ts +24 -13
  47. package/dist/esnext/index.js +24 -17
  48. package/dist/esnext/storefront-api-types.d.ts +1 -1
  49. package/dist/esnext/streaming.server.d.ts +3 -1
  50. package/dist/esnext/types.d.ts +12 -5
  51. package/dist/esnext/utilities/apiRoutes.d.ts +4 -5
  52. package/dist/esnext/utilities/apiRoutes.js +2 -8
  53. package/dist/esnext/utilities/fetch.d.ts +1 -2
  54. package/dist/esnext/utilities/fetch.js +1 -3
  55. package/dist/esnext/utilities/graphql-tag.d.ts +1 -0
  56. package/dist/esnext/utilities/graphql-tag.js +6 -0
  57. package/dist/esnext/utilities/graphql-tracker.d.ts +1 -1
  58. package/dist/esnext/utilities/graphql-tracker.js +4 -0
  59. package/dist/esnext/utilities/html-encoding.d.ts +0 -1
  60. package/dist/esnext/utilities/html-encoding.js +0 -8
  61. package/dist/esnext/utilities/index.d.ts +1 -1
  62. package/dist/esnext/utilities/index.js +1 -1
  63. package/dist/esnext/version.d.ts +1 -1
  64. package/dist/esnext/version.js +1 -1
  65. package/dist/node/components/Image/Image.d.ts +3 -3
  66. package/dist/node/components/Image/Image.js +12 -9
  67. package/dist/node/entry-server.d.ts +2 -2
  68. package/dist/node/entry-server.js +70 -44
  69. package/dist/node/foundation/Analytics/Analytics.client.js +6 -6
  70. package/dist/node/foundation/Analytics/ClientAnalytics.js +2 -2
  71. package/dist/node/foundation/Router/BrowserRouter.client.d.ts +2 -1
  72. package/dist/node/foundation/Router/BrowserRouter.client.js +1 -1
  73. package/dist/node/foundation/ServerPropsProvider/ServerPropsProvider.js +0 -2
  74. package/dist/node/framework/Hydration/ServerComponentRequest.server.d.ts +2 -2
  75. package/dist/node/framework/Hydration/ServerComponentResponse.server.d.ts +0 -9
  76. package/dist/node/framework/Hydration/ServerComponentResponse.server.js +0 -19
  77. package/dist/node/framework/Hydration/rsc.js +2 -2
  78. package/dist/node/framework/middleware.js +1 -15
  79. package/dist/node/framework/plugin.js +2 -0
  80. package/dist/node/framework/plugins/vite-plugin-hydrogen-client-middleware.d.ts +1 -1
  81. package/dist/node/framework/plugins/vite-plugin-hydrogen-config.js +1 -1
  82. package/dist/node/framework/plugins/vite-plugin-hydrogen-middleware.js +5 -46
  83. package/dist/node/framework/plugins/vite-plugin-hydrogen-rsc.js +6 -11
  84. package/dist/node/framework/plugins/vite-plugin-hydrogen-virtual-files.d.ts +7 -0
  85. package/dist/node/framework/plugins/vite-plugin-hydrogen-virtual-files.js +105 -0
  86. package/dist/node/framework/plugins/vite-plugin-platform-entry.js +4 -4
  87. package/dist/node/framework/viteception.d.ts +4 -0
  88. package/dist/node/framework/viteception.js +19 -0
  89. package/dist/node/storefront-api-types.d.ts +1 -1
  90. package/dist/node/streaming.server.d.ts +3 -1
  91. package/dist/node/types.d.ts +12 -5
  92. package/dist/node/utilities/apiRoutes.d.ts +4 -5
  93. package/dist/node/utilities/apiRoutes.js +2 -8
  94. package/dist/node/utilities/fetch.d.ts +1 -2
  95. package/dist/node/utilities/fetch.js +1 -3
  96. package/dist/node/utilities/html-encoding.d.ts +0 -1
  97. package/dist/node/utilities/html-encoding.js +1 -10
  98. package/dist/node/utilities/index.d.ts +1 -1
  99. package/dist/node/utilities/index.js +1 -2
  100. package/dist/node/version.d.ts +1 -1
  101. package/dist/node/version.js +1 -1
  102. package/package.json +4 -3
  103. package/vendor/react-server-dom-vite/cjs/react-server-dom-vite-plugin.js +19 -2
  104. package/vendor/react-server-dom-vite/esm/react-server-dom-vite-plugin.js +19 -2
  105. package/dist/esnext/utilities/findRoutePrefix.d.ts +0 -1
  106. package/dist/esnext/utilities/findRoutePrefix.js +0 -17
  107. package/dist/node/foundation/Analytics/index.d.ts +0 -2
  108. package/dist/node/foundation/Analytics/index.js +0 -7
  109. package/dist/node/utilities/findRoutePrefix.d.ts +0 -1
  110. package/dist/node/utilities/findRoutePrefix.js +0 -21
@@ -10,16 +10,11 @@ const path_1 = __importDefault(require("path"));
10
10
  const fs_1 = require("fs");
11
11
  const middleware_1 = require("../middleware");
12
12
  const in_memory_1 = require("../cache/in-memory");
13
+ const vite_plugin_hydrogen_virtual_files_1 = require("./vite-plugin-hydrogen-virtual-files");
13
14
  exports.HYDROGEN_DEFAULT_SERVER_ENTRY = process.env.HYDROGEN_SERVER_ENTRY || '/src/App.server';
14
- const virtualModuleId = 'virtual:hydrogen-config';
15
- const virtualProxyModuleId = virtualModuleId + ':proxy';
16
15
  exports.default = (pluginOptions) => {
17
- let config;
18
16
  return {
19
- name: 'vite-plugin-hydrogen-middleware',
20
- configResolved(_config) {
21
- config = _config;
22
- },
17
+ name: 'hydrogen:middleware',
23
18
  /**
24
19
  * By adding a middleware to the Vite dev server, we can handle SSR without needing
25
20
  * a custom node script. It works by handling any requests for `text/html` documents,
@@ -39,7 +34,7 @@ exports.default = (pluginOptions) => {
39
34
  dev: true,
40
35
  getShopifyConfig: async (incomingMessage) => {
41
36
  var _a;
42
- const { default: hydrogenConfig } = await server.ssrLoadModule('virtual:hydrogen-config:proxy');
37
+ const { default: hydrogenConfig } = await server.ssrLoadModule(vite_plugin_hydrogen_virtual_files_1.VIRTUAL_PROXY_HYDROGEN_CONFIG_ID);
43
38
  // @ts-ignore
44
39
  const { address = 'localhost', port = '3000' } = ((_a = server.httpServer) === null || _a === void 0 ? void 0 : _a.address()) || {};
45
40
  const url = new URL(`http://${address}:${port}${incomingMessage.url}`);
@@ -49,9 +44,8 @@ exports.default = (pluginOptions) => {
49
44
  // @ts-expect-error Manually set `normalizedUrl` which a developer expects to be available
50
45
  // via `ServerComponentRequest` during production runtime.
51
46
  request.normalizedUrl = request.url;
52
- return typeof hydrogenConfig.shopify === 'function'
53
- ? hydrogenConfig.shopify(request)
54
- : hydrogenConfig.shopify;
47
+ const { shopify } = hydrogenConfig;
48
+ return typeof shopify === 'function' ? shopify(request) : shopify;
55
49
  },
56
50
  }));
57
51
  server.middlewares.use(body_parser_1.default.raw({ type: '*/*' }));
@@ -65,26 +59,6 @@ exports.default = (pluginOptions) => {
65
59
  : undefined,
66
60
  }));
67
61
  },
68
- async resolveId(source, importer) {
69
- if (source === virtualModuleId) {
70
- const configPath = await findHydrogenConfigPath(config.root, pluginOptions.configPath);
71
- return this.resolve(configPath, importer, {
72
- skipSelf: true,
73
- });
74
- }
75
- if (source === virtualProxyModuleId) {
76
- // Virtual modules convention
77
- // https://vitejs.dev/guide/api-plugin.html#virtual-modules-convention
78
- return '\0' + virtualProxyModuleId;
79
- }
80
- },
81
- async load(id) {
82
- if (id === '\0' + virtualProxyModuleId) {
83
- // Likely due to a bug in Vite, but the config cannot be loaded
84
- // directly using ssrLoadModule. It needs to be proxied as follows:
85
- return `import hc from 'virtual:hydrogen-config'; export default hc;`;
86
- }
87
- },
88
62
  };
89
63
  };
90
64
  async function polyfillOxygenEnv(config) {
@@ -99,18 +73,3 @@ async function polyfillOxygenEnv(config) {
99
73
  }
100
74
  globalThis.Oxygen = { env };
101
75
  }
102
- async function findHydrogenConfigPath(root, userProvidedPath) {
103
- let configPath = userProvidedPath;
104
- if (!configPath) {
105
- // Find the config file in the project root
106
- const files = await fs_1.promises.readdir(root);
107
- configPath = files.find((file) => /^hydrogen\.config\.[jt]s$/.test(file));
108
- }
109
- if (configPath) {
110
- configPath = (0, vite_1.normalizePath)(configPath);
111
- if (!configPath.startsWith('/'))
112
- configPath = path_1.default.resolve(root, configPath);
113
- }
114
- return (configPath ||
115
- require.resolve('@shopify/hydrogen/dist/esnext/utilities/empty-hydrogen-config.js'));
116
- }
@@ -6,7 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  // @ts-ignore
7
7
  const plugin_1 = __importDefault(require("@shopify/hydrogen/vendor/react-server-dom-vite/plugin"));
8
8
  const vite_plugin_hydrogen_middleware_1 = require("./vite-plugin-hydrogen-middleware");
9
- const vite_1 = require("vite");
9
+ const vite_plugin_hydrogen_virtual_files_1 = require("./vite-plugin-hydrogen-virtual-files");
10
+ const viteception_1 = require("../viteception");
10
11
  function default_1() {
11
12
  return (0, plugin_1.default)({
12
13
  isServerComponentImporterAllowed(importer, source) {
@@ -20,19 +21,13 @@ function default_1() {
20
21
  /\.test\.[tj]sx?$/.test(importer));
21
22
  },
22
23
  async findClientComponentsForClientBuild() {
23
- // In client build, we create a local server to discover client compoents.
24
- const server = await (0, vite_1.createServer)({
25
- clearScreen: false,
26
- server: { middlewareMode: 'ssr' },
27
- });
28
- await Promise.all([
24
+ const { server } = await (0, viteception_1.viteception)([
29
25
  // Load server entry to discover client components early
30
- server.ssrLoadModule(vite_plugin_hydrogen_middleware_1.HYDROGEN_DEFAULT_SERVER_ENTRY),
31
- // Route globs are placed in hydrogen.config.js and need to
26
+ vite_plugin_hydrogen_middleware_1.HYDROGEN_DEFAULT_SERVER_ENTRY,
27
+ // Route globs are placed in a virtual module and need to
32
28
  // be loaded to discover client components in routes
33
- server.ssrLoadModule('virtual:hydrogen-config:proxy'),
29
+ vite_plugin_hydrogen_virtual_files_1.VIRTUAL_PROXY_HYDROGEN_ROUTES_ID,
34
30
  ]);
35
- await server.close();
36
31
  // At this point, the server has loaded all the components in the module graph
37
32
  return plugin_1.default.findClientComponentsFromServer(server);
38
33
  },
@@ -0,0 +1,7 @@
1
+ import { Plugin } from 'vite';
2
+ import type { HydrogenVitePluginOptions } from '../../types';
3
+ export declare const HYDROGEN_DEFAULT_SERVER_ENTRY: string;
4
+ export declare const VIRTUAL_PROXY_HYDROGEN_CONFIG_ID: string;
5
+ export declare const VIRTUAL_PROXY_HYDROGEN_ROUTES_ID: string;
6
+ declare const _default: (pluginOptions: HydrogenVitePluginOptions) => Plugin;
7
+ export default _default;
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.VIRTUAL_PROXY_HYDROGEN_ROUTES_ID = exports.VIRTUAL_PROXY_HYDROGEN_CONFIG_ID = exports.HYDROGEN_DEFAULT_SERVER_ENTRY = void 0;
7
+ const vite_1 = require("vite");
8
+ const path_1 = __importDefault(require("path"));
9
+ const fs_1 = require("fs");
10
+ const viteception_1 = require("../viteception");
11
+ exports.HYDROGEN_DEFAULT_SERVER_ENTRY = process.env.HYDROGEN_SERVER_ENTRY || '/src/App.server';
12
+ // The character ":" breaks Vite with Node >= 16.15. Use "_" instead
13
+ const VIRTUAL_PREFIX = 'virtual__';
14
+ const PROXY_PREFIX = 'proxy__';
15
+ const HYDROGEN_CONFIG_ID = 'hydrogen.config.ts';
16
+ const VIRTUAL_HYDROGEN_CONFIG_ID = VIRTUAL_PREFIX + HYDROGEN_CONFIG_ID;
17
+ exports.VIRTUAL_PROXY_HYDROGEN_CONFIG_ID = VIRTUAL_PREFIX + PROXY_PREFIX + HYDROGEN_CONFIG_ID;
18
+ const HYDROGEN_ROUTES_ID = 'hydrogen-routes.server.jsx';
19
+ const VIRTUAL_HYDROGEN_ROUTES_ID = VIRTUAL_PREFIX + HYDROGEN_ROUTES_ID;
20
+ exports.VIRTUAL_PROXY_HYDROGEN_ROUTES_ID = VIRTUAL_PREFIX + PROXY_PREFIX + HYDROGEN_ROUTES_ID;
21
+ exports.default = (pluginOptions) => {
22
+ let config;
23
+ let server;
24
+ return {
25
+ name: 'hydrogen:virtual-files',
26
+ configResolved(_config) {
27
+ config = _config;
28
+ },
29
+ configureServer(_server) {
30
+ server = _server;
31
+ },
32
+ resolveId(source, importer) {
33
+ if (source === VIRTUAL_HYDROGEN_CONFIG_ID) {
34
+ return findHydrogenConfigPath(config.root, pluginOptions.configPath).then((hcPath) =>
35
+ // This direct dependency on a real file
36
+ // makes HMR work for the virtual module.
37
+ this.resolve(hcPath, importer, { skipSelf: true }));
38
+ }
39
+ if ([
40
+ exports.VIRTUAL_PROXY_HYDROGEN_CONFIG_ID,
41
+ exports.VIRTUAL_PROXY_HYDROGEN_ROUTES_ID,
42
+ VIRTUAL_HYDROGEN_ROUTES_ID,
43
+ ].includes(source)) {
44
+ // Virtual modules convention
45
+ // https://vitejs.dev/guide/api-plugin.html#virtual-modules-convention
46
+ return '\0' + source;
47
+ }
48
+ },
49
+ load(id) {
50
+ // Likely due to a bug in Vite, but virtual modules cannot be loaded
51
+ // directly using ssrLoadModule from a Vite plugin. It needs to be proxied as follows:
52
+ if (id === '\0' + exports.VIRTUAL_PROXY_HYDROGEN_CONFIG_ID) {
53
+ return `import hc from '${VIRTUAL_HYDROGEN_CONFIG_ID}'; export default hc;`;
54
+ }
55
+ if (id === '\0' + exports.VIRTUAL_PROXY_HYDROGEN_ROUTES_ID) {
56
+ return `import hr from '${VIRTUAL_HYDROGEN_ROUTES_ID}'; export default hr;`;
57
+ }
58
+ if (id === '\0' + VIRTUAL_HYDROGEN_ROUTES_ID) {
59
+ return importHydrogenConfig().then((hc) => {
60
+ var _a, _b, _c, _d;
61
+ let routesPath = (_b = (typeof hc.routes === 'string' ? hc.routes : (_a = hc.routes) === null || _a === void 0 ? void 0 : _a.files)) !== null && _b !== void 0 ? _b : '/src/routes';
62
+ if (routesPath.startsWith('./')) {
63
+ routesPath = routesPath.slice(1);
64
+ }
65
+ if (!routesPath.includes('*')) {
66
+ if (!routesPath.endsWith('/')) {
67
+ routesPath += '/';
68
+ }
69
+ routesPath += '**/*.server.[jt](s|sx)';
70
+ }
71
+ const [dirPrefix] = routesPath.split('/*');
72
+ let code = `export default {\n dirPrefix: '${dirPrefix}',\n basePath: '${(_d = (_c = hc.routes) === null || _c === void 0 ? void 0 : _c.basePath) !== null && _d !== void 0 ? _d : ''}',\n files: import.meta.globEager('${routesPath}')\n};`;
73
+ if (config.command === 'serve') {
74
+ // Add dependency on Hydrogen config for HMR
75
+ code += `\nimport '${VIRTUAL_HYDROGEN_CONFIG_ID}';`;
76
+ }
77
+ return { code };
78
+ });
79
+ }
80
+ },
81
+ };
82
+ async function importHydrogenConfig() {
83
+ if (server) {
84
+ const loaded = await server.ssrLoadModule(exports.VIRTUAL_PROXY_HYDROGEN_CONFIG_ID);
85
+ return loaded.default;
86
+ }
87
+ const { loaded } = await (0, viteception_1.viteception)([exports.VIRTUAL_PROXY_HYDROGEN_CONFIG_ID]);
88
+ return loaded[0].default;
89
+ }
90
+ };
91
+ async function findHydrogenConfigPath(root, userProvidedPath) {
92
+ let configPath = userProvidedPath;
93
+ if (!configPath) {
94
+ // Find the config file in the project root
95
+ const files = await fs_1.promises.readdir(root);
96
+ configPath = files.find((file) => /^hydrogen\.config\.[jt]s$/.test(file));
97
+ }
98
+ if (configPath) {
99
+ configPath = (0, vite_1.normalizePath)(configPath);
100
+ if (!configPath.startsWith('/'))
101
+ configPath = path_1.default.resolve(root, configPath);
102
+ }
103
+ return (configPath ||
104
+ require.resolve('@shopify/hydrogen/dist/esnext/utilities/empty-hydrogen-config.js'));
105
+ }
@@ -36,10 +36,10 @@ exports.default = () => {
36
36
  },
37
37
  transform(code, id) {
38
38
  if ((0, vite_1.normalizePath)(id).includes('/hydrogen/dist/esnext/platforms/')) {
39
- code = code
40
- .replace('__SERVER_ENTRY__', vite_plugin_hydrogen_middleware_1.HYDROGEN_DEFAULT_SERVER_ENTRY)
41
- .replace('__INDEX_TEMPLATE__', (0, vite_1.normalizePath)(path_1.default.resolve(config.root, config.build.outDir, '..', 'client', 'index.html')));
42
39
  const ms = new magic_string_1.default(code);
40
+ ms.replace('__SERVER_ENTRY__', vite_plugin_hydrogen_middleware_1.HYDROGEN_DEFAULT_SERVER_ENTRY);
41
+ const indexTemplatePath = (0, vite_1.normalizePath)(path_1.default.resolve(config.root, config.build.outDir, '..', 'client', 'index.html'));
42
+ ms.replace('__INDEX_TEMPLATE__', indexTemplatePath);
43
43
  return {
44
44
  code: ms.toString(),
45
45
  map: ms.generateMap({ file: id, source: id }),
@@ -56,7 +56,7 @@ exports.default = () => {
56
56
  // default export instead of exporting an
57
57
  // object containing a 'default' property.
58
58
  if (value.type === 'chunk' && !isESM) {
59
- value.code = value.code.replace(/((^|;)[\s]*)exports\[['"]default['"]\]\s*=/m, '$1module.exports =');
59
+ value.code += `\nmodule.exports = exports.default || exports;`;
60
60
  }
61
61
  }
62
62
  },
@@ -0,0 +1,4 @@
1
+ export declare function viteception(paths: string[]): Promise<{
2
+ server: import("vite").ViteDevServer;
3
+ loaded: Record<string, any>[];
4
+ }>;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.viteception = void 0;
4
+ const vite_1 = require("vite");
5
+ async function viteception(paths) {
6
+ const isWorker = process.env.WORKER;
7
+ delete process.env.WORKER;
8
+ const server = await (0, vite_1.createServer)({
9
+ clearScreen: false,
10
+ server: { middlewareMode: 'ssr' },
11
+ });
12
+ if (isWorker) {
13
+ process.env.WORKER = isWorker;
14
+ }
15
+ const loaded = await Promise.all(paths.map((path) => server.ssrLoadModule(path)));
16
+ await server.close();
17
+ return { server, loaded };
18
+ }
19
+ exports.viteception = viteception;
@@ -699,7 +699,7 @@ export declare type CartLineEstimatedCost = {
699
699
  /** The amount of the merchandise line. */
700
700
  amount: MoneyV2;
701
701
  /** The compare at amount of the merchandise line. */
702
- compareAtAmount: MoneyV2;
702
+ compareAtAmount?: Maybe<MoneyV2>;
703
703
  /** The estimated cost of the merchandise line before discounts. */
704
704
  subtotalAmount: MoneyV2;
705
705
  /** The estimated total cost of the merchandise line. */
@@ -1,5 +1,7 @@
1
1
  import type { Writable } from 'stream';
2
- export declare const rscRenderToReadableStream: (App: JSX.Element) => ReadableStream<Uint8Array>;
2
+ export declare const rscRenderToReadableStream: (App: JSX.Element, options?: {
3
+ onError?: ((error: Error) => void) | undefined;
4
+ } | undefined) => ReadableStream<Uint8Array>;
3
5
  export declare const createFromReadableStream: (rs: ReadableStream<Uint8Array>) => {
4
6
  readRoot: () => JSX.Element;
5
7
  };
@@ -36,23 +36,30 @@ export declare type Hook = (params: {
36
36
  url: URL;
37
37
  } & Record<string, any>) => any | Promise<any>;
38
38
  export declare type ImportGlobEagerOutput = Record<string, Record<'default' | 'api', any>>;
39
- export declare type HydrogenConfigRoutes = {
40
- files?: ImportGlobEagerOutput;
39
+ export declare type InlineHydrogenRoutes = string | {
40
+ files: string;
41
41
  basePath?: string;
42
- dirPrefix?: string;
42
+ };
43
+ export declare type ResolvedHydrogenRoutes = {
44
+ files: ImportGlobEagerOutput;
45
+ dirPrefix: string;
46
+ basePath: string;
43
47
  };
44
48
  declare type ConfigFetcher<T> = (request: ServerComponentRequest) => T | Promise<T>;
45
49
  export declare type ShopifyConfigFetcher = ConfigFetcher<ShopifyConfig>;
46
50
  export declare type ServerAnalyticsConnector = {
47
51
  request: (request: Request, data?: any, contentType?: 'json' | 'text') => void;
48
52
  };
49
- export declare type HydrogenConfig = {
50
- routes?: HydrogenConfigRoutes | ImportGlobEagerOutput;
53
+ export declare type InlineHydrogenConfig = {
54
+ routes?: InlineHydrogenRoutes;
51
55
  shopify?: ShopifyConfig | ShopifyConfigFetcher;
52
56
  serverAnalyticsConnectors?: Array<ServerAnalyticsConnector>;
53
57
  session?: (log: Logger) => SessionStorageAdapter;
54
58
  enableStreaming?: (request: ServerComponentRequest) => boolean;
55
59
  };
60
+ export declare type ResolvedHydrogenConfig = Omit<InlineHydrogenConfig, 'routes'> & {
61
+ routes: ResolvedHydrogenRoutes;
62
+ };
56
63
  export declare type ClientHandlerConfig = {
57
64
  /** React's StrictMode is on by default for your client side app; if you want to turn it off (not recommended), you can pass `false` */
58
65
  strictMode?: boolean;
@@ -1,6 +1,5 @@
1
- import { HydrogenConfig, HydrogenConfigRoutes } from '../types';
1
+ import { InlineHydrogenConfig, ResolvedHydrogenRoutes } from '../types';
2
2
  import type { ServerComponentRequest } from '../framework/Hydration/ServerComponentRequest.server';
3
- import type { ASTNode } from 'graphql';
4
3
  import { SessionApi, SessionStorageAdapter } from '../foundation/session/session';
5
4
  declare type RouteParams = Record<string, string>;
6
5
  declare type RequestOptions = {
@@ -20,7 +19,7 @@ export declare type ApiRouteMatch = {
20
19
  params: RouteParams;
21
20
  };
22
21
  export declare function extractPathFromRoutesKey(routesKey: string, dirPrefix: string | RegExp): string;
23
- export declare function getApiRoutes(rawRoutes: HydrogenConfigRoutes): Array<HydrogenApiRoute>;
22
+ export declare function getApiRoutes({ files: routes, basePath: topLevelPath, dirPrefix, }: Partial<ResolvedHydrogenRoutes>): Array<HydrogenApiRoute>;
24
23
  export declare function getApiRouteFromURL(url: URL, routes: Array<HydrogenApiRoute>): ApiRouteMatch | null;
25
24
  /** The `queryShop` utility is a function that helps you query the Storefront API.
26
25
  * It's similar to the `useShopQuery` hook, which is available in server components.
@@ -30,9 +29,9 @@ interface QueryShopArgs {
30
29
  /** A string of the GraphQL query.
31
30
  * If no query is provided, then the `useShopQuery` makes no calls to the Storefront API.
32
31
  */
33
- query: ASTNode | string;
32
+ query: string;
34
33
  /** An object of the variables for the GraphQL query. */
35
34
  variables?: Record<string, any>;
36
35
  }
37
- export declare function renderApiRoute(request: ServerComponentRequest, route: ApiRouteMatch, shopifyConfig: HydrogenConfig['shopify'], session?: SessionStorageAdapter): Promise<Response | Request>;
36
+ export declare function renderApiRoute(request: ServerComponentRequest, route: ApiRouteMatch, shopifyConfig: InlineHydrogenConfig['shopify'], session?: SessionStorageAdapter): Promise<Response | Request>;
38
37
  export {};
@@ -4,7 +4,6 @@ exports.renderApiRoute = exports.getApiRouteFromURL = exports.getApiRoutes = exp
4
4
  const matchPath_1 = require("./matchPath");
5
5
  const log_1 = require("../utilities/log/");
6
6
  const fetch_1 = require("./fetch");
7
- const findRoutePrefix_1 = require("./findRoutePrefix");
8
7
  const storefrontApi_1 = require("./storefrontApi");
9
8
  const session_1 = require("../foundation/session/session");
10
9
  let memoizedApiRoutes = [];
@@ -32,20 +31,15 @@ function extractPathFromRoutesKey(routesKey, dirPrefix) {
32
31
  return path;
33
32
  }
34
33
  exports.extractPathFromRoutesKey = extractPathFromRoutesKey;
35
- function getApiRoutes(rawRoutes) {
36
- var _a, _b;
37
- const routes = ((_a = rawRoutes.files) !== null && _a !== void 0 ? _a : rawRoutes);
38
- const topLevelPath = ((_b = rawRoutes.basePath) !== null && _b !== void 0 ? _b : '*');
39
- const dirPrefix = rawRoutes.dirPrefix;
34
+ function getApiRoutes({ files: routes, basePath: topLevelPath = '', dirPrefix = '', }) {
40
35
  if (!routes || memoizedRawRoutes === routes)
41
36
  return memoizedApiRoutes;
42
37
  const topLevelPrefix = topLevelPath.replace('*', '').replace(/\/$/, '');
43
38
  const keys = Object.keys(routes);
44
- const commonRoutePrefix = dirPrefix !== null && dirPrefix !== void 0 ? dirPrefix : (0, findRoutePrefix_1.findRoutePrefix)(keys);
45
39
  const apiRoutes = keys
46
40
  .filter((key) => routes[key].api)
47
41
  .map((key) => {
48
- const path = extractPathFromRoutesKey(key, commonRoutePrefix);
42
+ const path = extractPathFromRoutesKey(key, dirPrefix);
49
43
  /**
50
44
  * Catch-all routes [...handle].jsx don't need an exact match
51
45
  * https://reactrouter.com/core/api/Route/exact-bool
@@ -1,10 +1,9 @@
1
- import { ASTNode } from 'graphql';
2
1
  declare type FetchInit = {
3
2
  body?: string;
4
3
  method?: string;
5
4
  headers?: Record<string, string>;
6
5
  };
7
6
  export declare function fetchBuilder<T>(url: string, options?: FetchInit): () => Promise<T>;
8
- export declare function graphqlRequestBody(query: ASTNode | string, variables?: Record<string, any>): string;
7
+ export declare function graphqlRequestBody(query: string, variables?: Record<string, any>): string;
9
8
  export declare function decodeShopifyId(id: string): string;
10
9
  export {};
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.decodeShopifyId = exports.graphqlRequestBody = exports.fetchBuilder = void 0;
4
- const graphql_1 = require("graphql");
5
4
  const version_1 = require("../version");
6
5
  const defaultHeaders = {
7
6
  'content-type': 'application/json',
@@ -23,9 +22,8 @@ function fetchBuilder(url, options = {}) {
23
22
  }
24
23
  exports.fetchBuilder = fetchBuilder;
25
24
  function graphqlRequestBody(query, variables) {
26
- const queryString = typeof query === 'string' ? query : (0, graphql_1.print)(query);
27
25
  return JSON.stringify({
28
- query: queryString,
26
+ query,
29
27
  variables,
30
28
  });
31
29
  }
@@ -1,2 +1 @@
1
1
  export declare function htmlEncode(html: string): string;
2
- export declare function htmlDecode(text: string): string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.htmlDecode = exports.htmlEncode = void 0;
3
+ exports.htmlEncode = void 0;
4
4
  function htmlEncode(html) {
5
5
  return html
6
6
  .replace(/&/g, '&amp;')
@@ -10,12 +10,3 @@ function htmlEncode(html) {
10
10
  .replace(/'/g, '&#39;');
11
11
  }
12
12
  exports.htmlEncode = htmlEncode;
13
- function htmlDecode(text) {
14
- return text
15
- .replace(/&amp;/g, '&')
16
- .replace(/&lt;/g, '<')
17
- .replace(/&gt;/g, '>')
18
- .replace(/&quot;/g, '"')
19
- .replace(/&#39;/g, "'");
20
- }
21
- exports.htmlDecode = htmlDecode;
@@ -9,4 +9,4 @@ export { getMeasurementAsParts, getMeasurementAsString } from './measurement';
9
9
  export { parseMetafieldValue } from './parseMetafieldValue';
10
10
  export { fetchBuilder, graphqlRequestBody, decodeShopifyId } from './fetch';
11
11
  export { getTime } from './timing';
12
- export { htmlEncode, htmlDecode } from './html-encoding';
12
+ export { htmlEncode } from './html-encoding';
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.htmlDecode = exports.htmlEncode = exports.getTime = exports.decodeShopifyId = exports.graphqlRequestBody = exports.fetchBuilder = exports.parseMetafieldValue = exports.getMeasurementAsString = exports.getMeasurementAsParts = exports.isServer = exports.isClient = exports.flattenConnection = exports.wrapPromise = exports.loadScript = exports.useEmbeddedVideoUrl = exports.addParametersToEmbeddedVideoUrl = exports.shopifyImageLoader = exports.getShopifyImageDimensions = exports.addImageSizeParametersToUrl = void 0;
3
+ exports.htmlEncode = exports.getTime = exports.decodeShopifyId = exports.graphqlRequestBody = exports.fetchBuilder = exports.parseMetafieldValue = exports.getMeasurementAsString = exports.getMeasurementAsParts = exports.isServer = exports.isClient = exports.flattenConnection = exports.wrapPromise = exports.loadScript = exports.useEmbeddedVideoUrl = exports.addParametersToEmbeddedVideoUrl = exports.shopifyImageLoader = exports.getShopifyImageDimensions = exports.addImageSizeParametersToUrl = void 0;
4
4
  var image_size_1 = require("./image_size");
5
5
  Object.defineProperty(exports, "addImageSizeParametersToUrl", { enumerable: true, get: function () { return image_size_1.addImageSizeParametersToUrl; } });
6
6
  Object.defineProperty(exports, "getShopifyImageDimensions", { enumerable: true, get: function () { return image_size_1.getShopifyImageDimensions; } });
@@ -31,4 +31,3 @@ var timing_1 = require("./timing");
31
31
  Object.defineProperty(exports, "getTime", { enumerable: true, get: function () { return timing_1.getTime; } });
32
32
  var html_encoding_1 = require("./html-encoding");
33
33
  Object.defineProperty(exports, "htmlEncode", { enumerable: true, get: function () { return html_encoding_1.htmlEncode; } });
34
- Object.defineProperty(exports, "htmlDecode", { enumerable: true, get: function () { return html_encoding_1.htmlDecode; } });
@@ -1 +1 @@
1
- export declare const LIB_VERSION = "0.21.0";
1
+ export declare const LIB_VERSION = "0.22.0";
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LIB_VERSION = void 0;
4
- exports.LIB_VERSION = '0.21.0';
4
+ exports.LIB_VERSION = '0.22.0';
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "engines": {
8
8
  "node": ">=14"
9
9
  },
10
- "version": "0.21.0",
10
+ "version": "0.22.0",
11
11
  "description": "Modern custom Shopify storefronts",
12
12
  "license": "MIT",
13
13
  "main": "dist/esnext/index.js",
@@ -70,12 +70,13 @@
70
70
  "@types/graphql": "^14.5.0",
71
71
  "@types/node": "^16.11.7",
72
72
  "@types/node-fetch": "^2.5.9",
73
- "@types/react": "^17.0.3",
74
- "@types/react-dom": "^17.0.3",
73
+ "@types/react": "^18.0.9",
74
+ "@types/react-dom": "^18.0.5",
75
75
  "@types/uuid": "^8.3.4",
76
76
  "@types/ws": "^8.2.0",
77
77
  "babel-loader": "^8.2.2",
78
78
  "cpy-cli": "3.1.1",
79
+ "graphql-tag": "^2.12.6",
79
80
  "mkdirp": "^1.0.4",
80
81
  "npm-run-all": "^4.1.5",
81
82
  "postcss": "^8",
@@ -93,6 +93,7 @@ function _createForOfIteratorHelper(o, allowArrayLike) {
93
93
  }
94
94
 
95
95
  var rscViteFileRE = /\/react-server-dom-vite.js/;
96
+ var noProxyRE = /[&?]no-proxy($|&)/;
96
97
  function ReactFlightVitePlugin() {
97
98
  var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
98
99
  _ref$isServerComponen = _ref.isServerComponentImporterAllowed,
@@ -161,7 +162,23 @@ function ReactFlightVitePlugin() {
161
162
  },
162
163
  load: function (id) {
163
164
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
164
- return options.ssr && shouldCheckClientComponent(id) ? wrapIfClientComponent(id) : null;
165
+ if (!options.ssr || !shouldCheckClientComponent(id)) return;
166
+
167
+ if (server) {
168
+ var mod = server.moduleGraph.idToModuleMap.get(id.replace('/@fs', ''));
169
+
170
+ if (mod && mod.importers) {
171
+ if (Array.from(mod.importers).every(function (impMod) {
172
+ return noProxyRE.test(impMod.id);
173
+ })) {
174
+ // This module is only imported from client components
175
+ // so we don't need to create a module reference
176
+ return;
177
+ }
178
+ }
179
+ }
180
+
181
+ return wrapIfClientComponent(id);
165
182
  },
166
183
  transform: function (code, id) {
167
184
  var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
@@ -284,7 +301,7 @@ async function proxyClientComponent(filepath, src) {
284
301
  }
285
302
 
286
303
  function shouldCheckClientComponent(id) {
287
- return /\.[jt]sx?($|\?)/.test(id) && !/[&?]no-proxy($|&)/.test(id);
304
+ return /\.[jt]sx?($|\?)/.test(id) && !noProxyRE.test(id);
288
305
  }
289
306
 
290
307
  function findClientComponentsForDev(server) {
@@ -89,6 +89,7 @@ function _createForOfIteratorHelper(o, allowArrayLike) {
89
89
  }
90
90
 
91
91
  var rscViteFileRE = /\/react-server-dom-vite.js/;
92
+ var noProxyRE = /[&?]no-proxy($|&)/;
92
93
  function ReactFlightVitePlugin() {
93
94
  var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
94
95
  _ref$isServerComponen = _ref.isServerComponentImporterAllowed,
@@ -157,7 +158,23 @@ function ReactFlightVitePlugin() {
157
158
  },
158
159
  load: function (id) {
159
160
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
160
- return options.ssr && shouldCheckClientComponent(id) ? wrapIfClientComponent(id) : null;
161
+ if (!options.ssr || !shouldCheckClientComponent(id)) return;
162
+
163
+ if (server) {
164
+ var mod = server.moduleGraph.idToModuleMap.get(id.replace('/@fs', ''));
165
+
166
+ if (mod && mod.importers) {
167
+ if (Array.from(mod.importers).every(function (impMod) {
168
+ return noProxyRE.test(impMod.id);
169
+ })) {
170
+ // This module is only imported from client components
171
+ // so we don't need to create a module reference
172
+ return;
173
+ }
174
+ }
175
+ }
176
+
177
+ return wrapIfClientComponent(id);
161
178
  },
162
179
  transform: function (code, id) {
163
180
  var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
@@ -280,7 +297,7 @@ async function proxyClientComponent(filepath, src) {
280
297
  }
281
298
 
282
299
  function shouldCheckClientComponent(id) {
283
- return /\.[jt]sx?($|\?)/.test(id) && !/[&?]no-proxy($|&)/.test(id);
300
+ return /\.[jt]sx?($|\?)/.test(id) && !noProxyRE.test(id);
284
301
  }
285
302
 
286
303
  function findClientComponentsForDev(server) {
@@ -1 +0,0 @@
1
- export declare function findRoutePrefix([first, ...rest]: string[]): string | RegExp;
@@ -1,17 +0,0 @@
1
- const DEFAULT_ROUTE_PREFIX = /^\.(\/src)?\/routes/;
2
- export function findRoutePrefix([first, ...rest]) {
3
- if (!(first === null || first === void 0 ? void 0 : first.startsWith('./')))
4
- return '';
5
- let commonPrefix = '.';
6
- if (rest.length > 0) {
7
- const parts = first.split('/');
8
- parts.pop(); // Last part is always different and has extension
9
- for (const string of rest) {
10
- const tmp = string.split('/');
11
- const diffIndex = parts.findIndex((part, index) => part !== tmp[index]);
12
- diffIndex >= 0 && parts.splice(diffIndex);
13
- }
14
- commonPrefix = parts.join('/');
15
- }
16
- return commonPrefix === '.' ? DEFAULT_ROUTE_PREFIX : commonPrefix;
17
- }
@@ -1,2 +0,0 @@
1
- export { useServerAnalytics } from './hook';
2
- export { ClientAnalytics } from './ClientAnalytics';
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ClientAnalytics = exports.useServerAnalytics = void 0;
4
- var hook_1 = require("./hook");
5
- Object.defineProperty(exports, "useServerAnalytics", { enumerable: true, get: function () { return hook_1.useServerAnalytics; } });
6
- var ClientAnalytics_1 = require("./ClientAnalytics");
7
- Object.defineProperty(exports, "ClientAnalytics", { enumerable: true, get: function () { return ClientAnalytics_1.ClientAnalytics; } });
@@ -1 +0,0 @@
1
- export declare function findRoutePrefix([first, ...rest]: string[]): string | RegExp;