@shopify/hydrogen 0.7.0 → 0.8.2
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.
- package/dist/esnext/components/CartEstimatedCost/CartEstimatedCost.client.d.ts +1 -1
- package/dist/esnext/components/CartEstimatedCost/CartEstimatedCost.client.js +1 -1
- package/dist/esnext/components/CartLineProvider/context.d.ts +3 -3
- package/dist/esnext/components/CartLineQuantityAdjustButton/CartLineQuantityAdjustButton.js +4 -0
- package/dist/esnext/components/CartProvider/CartProvider.client.js +0 -1
- package/dist/esnext/components/ExternalVideo/ExternalVideo.d.ts +1 -1
- package/dist/esnext/components/Image/Image.d.ts +1 -1
- package/dist/esnext/components/LocalizationProvider/index.d.ts +1 -0
- package/dist/esnext/components/LocalizationProvider/index.js +1 -0
- package/dist/esnext/components/MediaFile/MediaFile.d.ts +1 -1
- package/dist/esnext/components/Metafield/Metafield.client.d.ts +1 -1
- package/dist/esnext/components/Metafield/components/StarRating/StarRating.d.ts +1 -1
- package/dist/esnext/components/Metafield/index.d.ts +2 -2
- package/dist/esnext/components/Model3D/Model3D.client.d.ts +1 -1
- package/dist/esnext/components/Money/Money.client.d.ts +1 -1
- package/dist/esnext/components/ProductPrice/ProductPrice.client.d.ts +1 -3
- package/dist/esnext/components/ProductPrice/ProductPrice.client.js +1 -3
- package/dist/esnext/components/ProductProvider/ProductProvider.client.d.ts +1 -1
- package/dist/esnext/components/ShopPayButton/ShopPayButton.client.js +1 -1
- package/dist/esnext/components/UnitPrice/UnitPrice.client.d.ts +2 -3
- package/dist/esnext/components/UnitPrice/UnitPrice.client.js +1 -2
- package/dist/esnext/components/Video/Video.d.ts +1 -1
- package/dist/esnext/components/index.d.ts +3 -2
- package/dist/esnext/components/index.js +1 -0
- package/dist/esnext/entry-client.js +4 -6
- package/dist/esnext/entry-server.js +77 -47
- package/dist/esnext/foundation/RenderCacheProvider/RenderCacheContext.d.ts +2 -0
- package/dist/esnext/foundation/RenderCacheProvider/RenderCacheContext.js +4 -0
- package/dist/esnext/foundation/RenderCacheProvider/RenderCacheProvider.d.ts +2 -0
- package/dist/esnext/foundation/RenderCacheProvider/RenderCacheProvider.js +5 -0
- package/dist/esnext/foundation/RenderCacheProvider/hook.d.ts +11 -0
- package/dist/esnext/foundation/RenderCacheProvider/hook.js +34 -0
- package/dist/esnext/foundation/RenderCacheProvider/index.d.ts +1 -0
- package/dist/esnext/foundation/RenderCacheProvider/index.js +1 -0
- package/dist/esnext/foundation/RenderCacheProvider/types.d.ts +18 -0
- package/dist/esnext/foundation/RenderCacheProvider/types.js +1 -0
- package/dist/esnext/foundation/Router/DefaultRoutes.d.ts +3 -1
- package/dist/esnext/foundation/Router/DefaultRoutes.js +2 -2
- package/dist/esnext/foundation/ServerStateProvider/ServerStateProvider.client.js +4 -2
- package/dist/esnext/foundation/ServerStateProvider/index.d.ts +2 -1
- package/dist/esnext/foundation/ShopifyProvider/ShopifyServerProvider.server.d.ts +1 -3
- package/dist/esnext/foundation/ShopifyProvider/ShopifyServerProvider.server.js +2 -4
- package/dist/esnext/foundation/ShopifyProvider/types.d.ts +0 -5
- package/dist/esnext/foundation/useQuery/hooks.d.ts +8 -6
- package/dist/esnext/foundation/useQuery/hooks.js +13 -14
- package/dist/esnext/foundation/useQuery/index.d.ts +0 -1
- package/dist/esnext/foundation/useQuery/index.js +0 -1
- package/dist/esnext/foundation/useServerState/use-server-state.d.ts +1 -1
- package/dist/esnext/foundation/useServerState/use-server-state.js +1 -1
- package/dist/esnext/foundation/useShop/use-shop.d.ts +1 -1
- package/dist/esnext/foundation/useShop/use-shop.js +1 -1
- package/dist/esnext/framework/ClientMarker/ClientMarker.js +0 -1
- package/dist/esnext/framework/Hydration/ServerComponentRequest.server.d.ts +1 -0
- package/dist/esnext/framework/Hydration/ServerComponentRequest.server.js +2 -0
- package/dist/esnext/framework/Hydration/writer.server.js +1 -0
- package/dist/esnext/framework/cache.d.ts +2 -2
- package/dist/esnext/framework/cache.js +1 -1
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-config.d.ts +1 -1
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-config.js +13 -1
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-middleware.d.ts +7 -1
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-middleware.js +15 -1
- package/dist/esnext/framework/plugins/vite-plugin-react-server-components-shim.js +1 -23
- package/dist/esnext/framework/server-components.js +25 -47
- package/dist/esnext/graphql/graphql-constants.d.ts +23 -23
- package/dist/esnext/handle-event.d.ts +1 -1
- package/dist/esnext/handle-event.js +68 -10
- package/dist/esnext/hooks/index.d.ts +1 -1
- package/dist/esnext/hooks/index.js +1 -1
- package/dist/esnext/hooks/useCartLine/useCartLine.d.ts +3 -3
- package/dist/esnext/hooks/useShopQuery/hooks.d.ts +5 -5
- package/dist/esnext/hooks/useShopQuery/hooks.js +45 -17
- package/dist/esnext/index.d.ts +2 -1
- package/dist/esnext/index.js +2 -1
- package/dist/esnext/types.d.ts +2 -1
- package/dist/esnext/utilities/fetch.js +3 -6
- package/dist/esnext/utilities/index.d.ts +1 -0
- package/dist/esnext/utilities/index.js +1 -0
- package/dist/esnext/utilities/log/index.d.ts +1 -0
- package/dist/esnext/utilities/log/index.js +1 -0
- package/dist/esnext/utilities/log/log.d.ts +17 -0
- package/dist/esnext/utilities/log/log.js +70 -0
- package/dist/esnext/utilities/suspense.d.ts +2 -2
- package/dist/esnext/utilities/suspense.js +0 -6
- package/dist/esnext/utilities/timing.d.ts +7 -0
- package/dist/esnext/utilities/timing.js +14 -0
- package/dist/esnext/version.d.ts +1 -1
- package/dist/esnext/version.js +1 -1
- package/dist/node/framework/ClientMarker/ClientMarker.js +2 -3
- package/dist/node/framework/Hydration/Cache.client.js +4 -4
- package/dist/node/framework/Hydration/HydrationContext.server.js +1 -1
- package/dist/node/framework/Hydration/ServerComponentRequest.server.d.ts +1 -0
- package/dist/node/framework/Hydration/ServerComponentRequest.server.js +2 -0
- package/dist/node/framework/Hydration/ServerComponentResponse.server.js +2 -2
- package/dist/node/framework/Hydration/react-utils.js +3 -3
- package/dist/node/framework/Hydration/wire.server.js +1 -1
- package/dist/node/framework/Hydration/writer.server.js +1 -0
- package/dist/node/framework/cache.d.ts +2 -2
- package/dist/node/framework/cache.js +5 -4
- package/dist/node/framework/middleware.js +2 -2
- package/dist/node/framework/plugin.js +5 -5
- package/dist/node/framework/plugins/vite-plugin-hydrogen-config.d.ts +1 -1
- package/dist/node/framework/plugins/vite-plugin-hydrogen-config.js +13 -1
- package/dist/node/framework/plugins/vite-plugin-hydrogen-middleware.d.ts +7 -1
- package/dist/node/framework/plugins/vite-plugin-hydrogen-middleware.js +17 -3
- package/dist/node/framework/plugins/vite-plugin-react-server-components-shim.js +8 -30
- package/dist/node/framework/server-components.js +27 -49
- package/dist/node/handle-event.d.ts +1 -1
- package/dist/node/handle-event.js +72 -14
- package/dist/node/types.d.ts +2 -1
- package/dist/node/utilities/fetch.js +4 -7
- package/dist/node/utilities/index.d.ts +1 -0
- package/dist/node/utilities/index.js +3 -1
- package/dist/node/utilities/isServer/isServer.js +1 -1
- package/dist/node/utilities/suspense.d.ts +2 -2
- package/dist/node/utilities/suspense.js +0 -6
- package/dist/node/utilities/timing.d.ts +7 -0
- package/dist/node/utilities/timing.js +18 -0
- package/dist/node/utilities/video_parameters.js +1 -1
- package/dist/node/version.d.ts +1 -1
- package/dist/node/version.js +1 -1
- package/dist/worker/framework/Hydration/ServerComponentRequest.server.d.ts +1 -0
- package/dist/worker/framework/Hydration/ServerComponentRequest.server.js +2 -0
- package/dist/worker/framework/cache.d.ts +2 -2
- package/dist/worker/framework/cache.js +1 -1
- package/dist/worker/handle-event.d.ts +1 -1
- package/dist/worker/handle-event.js +68 -10
- package/dist/worker/types.d.ts +2 -1
- package/dist/worker/utilities/timing.d.ts +7 -0
- package/dist/worker/utilities/timing.js +14 -0
- package/package.json +10 -10
- package/dist/esnext/foundation/useQuery/QueryProvider.d.ts +0 -6
- package/dist/esnext/foundation/useQuery/QueryProvider.js +0 -13
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { yellow, red, green, italic, lightBlue } from 'kolorist';
|
|
2
|
+
import { getTime } from '../timing';
|
|
3
|
+
const defaultLogger = {
|
|
4
|
+
trace(context, ...args) {
|
|
5
|
+
console.log(...args);
|
|
6
|
+
},
|
|
7
|
+
debug(context, ...args) {
|
|
8
|
+
console.log(...args);
|
|
9
|
+
},
|
|
10
|
+
warn(context, ...args) {
|
|
11
|
+
console.warn(yellow('WARN: '), ...args);
|
|
12
|
+
},
|
|
13
|
+
error(context, ...args) {
|
|
14
|
+
console.error(red('ERROR: '), ...args);
|
|
15
|
+
},
|
|
16
|
+
fatal(context, ...args) {
|
|
17
|
+
console.error(red('FATAL: '), ...args);
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
let logger = defaultLogger;
|
|
21
|
+
export function getLoggerFromContext(context) {
|
|
22
|
+
return {
|
|
23
|
+
trace: (...args) => logger.trace(context, ...args),
|
|
24
|
+
debug: (...args) => logger.debug(context, ...args),
|
|
25
|
+
warn: (...args) => logger.warn(context, ...args),
|
|
26
|
+
error: (...args) => logger.error(context, ...args),
|
|
27
|
+
fatal: (...args) => logger.fatal(context, ...args),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export function setLogger(newLogger) {
|
|
31
|
+
logger = newLogger;
|
|
32
|
+
}
|
|
33
|
+
export function resetLogger() {
|
|
34
|
+
logger = defaultLogger;
|
|
35
|
+
}
|
|
36
|
+
export const log = {
|
|
37
|
+
trace(...args) {
|
|
38
|
+
return logger.trace({}, ...args);
|
|
39
|
+
},
|
|
40
|
+
debug(...args) {
|
|
41
|
+
return logger.debug({}, ...args);
|
|
42
|
+
},
|
|
43
|
+
warn(...args) {
|
|
44
|
+
return logger.warn({}, ...args);
|
|
45
|
+
},
|
|
46
|
+
error(...args) {
|
|
47
|
+
return logger.error({}, ...args);
|
|
48
|
+
},
|
|
49
|
+
fatal(...args) {
|
|
50
|
+
return logger.fatal({}, ...args);
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
export function logServerResponse(type, log, request, responseStatus) {
|
|
54
|
+
const coloredResponseStatus = responseStatus >= 500
|
|
55
|
+
? red(responseStatus)
|
|
56
|
+
: responseStatus >= 400
|
|
57
|
+
? yellow(responseStatus)
|
|
58
|
+
: responseStatus >= 300
|
|
59
|
+
? lightBlue(responseStatus)
|
|
60
|
+
: green(responseStatus);
|
|
61
|
+
const styledType = italic(type);
|
|
62
|
+
const paddedTiming = pad((getTime() - request.time).toFixed(2) + ' ms', ' ');
|
|
63
|
+
const url = type === 'rsc'
|
|
64
|
+
? decodeURIComponent(request.url.substring(request.url.indexOf('=') + 1))
|
|
65
|
+
: request.url;
|
|
66
|
+
log.debug(`${request.method} ${styledType} ${coloredResponseStatus} ${paddedTiming} ${url}`);
|
|
67
|
+
}
|
|
68
|
+
function pad(str, _pad) {
|
|
69
|
+
return (str + _pad).substring(0, _pad.length);
|
|
70
|
+
}
|
|
@@ -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<
|
|
6
|
-
read: () =>
|
|
5
|
+
export declare function wrapPromise<T>(promise: Promise<T>): {
|
|
6
|
+
read: () => T;
|
|
7
7
|
};
|
|
@@ -11,14 +11,8 @@ export function wrapPromise(promise) {
|
|
|
11
11
|
}, (err) => {
|
|
12
12
|
status = 'error';
|
|
13
13
|
response = err;
|
|
14
|
-
throw err;
|
|
15
14
|
});
|
|
16
15
|
const read = () => {
|
|
17
|
-
/**
|
|
18
|
-
* TODO: This logic doesn't hold up when an error is thrown. For some reason.
|
|
19
|
-
* We instead throw the exception above in the suspender. We should revisit
|
|
20
|
-
* this and add a better server fetch implementation.
|
|
21
|
-
*/
|
|
22
16
|
switch (status) {
|
|
23
17
|
case 'pending':
|
|
24
18
|
throw suspender;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Not all environments have access to Performance.now(). This is to prevent
|
|
3
|
+
* timing side channel attacks.
|
|
4
|
+
*
|
|
5
|
+
* See: https://community.cloudflare.com/t/cloudflare-workers-how-do-i-measure-execution-time-of-my-method/69672
|
|
6
|
+
*/
|
|
7
|
+
export declare function getTime(): number;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Not all environments have access to Performance.now(). This is to prevent
|
|
3
|
+
* timing side channel attacks.
|
|
4
|
+
*
|
|
5
|
+
* See: https://community.cloudflare.com/t/cloudflare-workers-how-do-i-measure-execution-time-of-my-method/69672
|
|
6
|
+
*/
|
|
7
|
+
export function getTime() {
|
|
8
|
+
if (typeof performance !== 'undefined' && performance.now) {
|
|
9
|
+
return performance.now();
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
return Date.now();
|
|
13
|
+
}
|
|
14
|
+
}
|
package/dist/esnext/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const LIB_VERSION = "0.
|
|
1
|
+
export declare const LIB_VERSION = "0.8.2";
|
package/dist/esnext/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const LIB_VERSION = '0.
|
|
1
|
+
export const LIB_VERSION = '0.8.2';
|
|
@@ -34,7 +34,6 @@ function wrapInClientMarker(meta) {
|
|
|
34
34
|
// Use object syntax here to make sure the function name
|
|
35
35
|
// comes from the meta params for better error stacks.
|
|
36
36
|
const wrappedComponent = {
|
|
37
|
-
// eslint-disable-next-line react/display-name
|
|
38
37
|
[name]: (props) => react_1.default.createElement(ClientMarker, { ...{ props, meta } }),
|
|
39
38
|
}[name];
|
|
40
39
|
// Relay component properties such as `Image.Fragment`
|
|
@@ -48,7 +47,7 @@ function wrapInClientMarker(meta) {
|
|
|
48
47
|
}
|
|
49
48
|
exports.wrapInClientMarker = wrapInClientMarker;
|
|
50
49
|
function ClientMarker({ props: allProps, meta: { name, id, component: Component, named }, }) {
|
|
51
|
-
const isHydrating = react_1.useContext(HydrationContext_server_1.HydrationContext);
|
|
50
|
+
const isHydrating = (0, react_1.useContext)(HydrationContext_server_1.HydrationContext);
|
|
52
51
|
if (!isHydrating)
|
|
53
52
|
return react_1.default.createElement(Component, { ...allProps });
|
|
54
53
|
let { children, ...props } = allProps;
|
|
@@ -58,7 +57,7 @@ function ClientMarker({ props: allProps, meta: { name, id, component: Component,
|
|
|
58
57
|
* serialize props to JSON below, and React element Functions
|
|
59
58
|
* cannot be serialized.
|
|
60
59
|
*/
|
|
61
|
-
props = react_utils_1.renderReactProps(props);
|
|
60
|
+
props = (0, react_utils_1.renderReactProps)(props);
|
|
62
61
|
/**
|
|
63
62
|
* Components ending in *Provider are special components to
|
|
64
63
|
* Hydrogen's RSC implementation. They are rendered during
|
|
@@ -31,7 +31,7 @@ exports.useServerResponse = useServerResponse;
|
|
|
31
31
|
* promise events to the Suspense boundary until the content has loaded.
|
|
32
32
|
*/
|
|
33
33
|
function createFromFetch(fetchPromise) {
|
|
34
|
-
return utilities_1.wrapPromise(fetchPromise
|
|
34
|
+
return (0, utilities_1.wrapPromise)(fetchPromise
|
|
35
35
|
.then((response) => {
|
|
36
36
|
if (!response.ok) {
|
|
37
37
|
throw new Error(`Hydration request failed: ${response.statusText}`);
|
|
@@ -68,7 +68,7 @@ async function convertHydrationResponseToReactComponents(response) {
|
|
|
68
68
|
return null;
|
|
69
69
|
// Assume it's an array of tuples, defined in the component as a fragment.
|
|
70
70
|
if (!isReactTuple(item)) {
|
|
71
|
-
return react_1.createElement(react_1.Fragment, {
|
|
71
|
+
return (0, react_1.createElement)(react_1.Fragment, {
|
|
72
72
|
children: item.map(wireSyntaxToReactElement),
|
|
73
73
|
});
|
|
74
74
|
}
|
|
@@ -105,7 +105,7 @@ async function convertHydrationResponseToReactComponents(response) {
|
|
|
105
105
|
const mod = modules[type.replace('@', 'M')];
|
|
106
106
|
type = module.named ? mod[module.name] : mod.default;
|
|
107
107
|
}
|
|
108
|
-
return react_1.createElement(type, { ...allProps, key });
|
|
108
|
+
return (0, react_1.createElement)(type, { ...allProps, key });
|
|
109
109
|
}
|
|
110
110
|
/**
|
|
111
111
|
* The manifest is listed as `J0` for some reason. This is how React does it.
|
|
@@ -133,7 +133,7 @@ async function eagerLoadModules(manifest) {
|
|
|
133
133
|
if (moduleCache.has(module.id)) {
|
|
134
134
|
return moduleCache.get(module.id);
|
|
135
135
|
}
|
|
136
|
-
const mod = await client_imports_1.default(module.id);
|
|
136
|
+
const mod = await (0, client_imports_1.default)(module.id);
|
|
137
137
|
moduleCache.set(module.id, mod);
|
|
138
138
|
return mod;
|
|
139
139
|
})
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ServerComponentRequest = void 0;
|
|
4
|
+
const timing_1 = require("../../utilities/timing");
|
|
4
5
|
/**
|
|
5
6
|
* This augments the `Request` object from the Fetch API:
|
|
6
7
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/Request
|
|
@@ -19,6 +20,7 @@ class ServerComponentRequest extends Request {
|
|
|
19
20
|
method: input.method,
|
|
20
21
|
});
|
|
21
22
|
}
|
|
23
|
+
this.time = (0, timing_1.getTime)();
|
|
22
24
|
this.cookies = this.parseCookies();
|
|
23
25
|
}
|
|
24
26
|
parseCookies() {
|
|
@@ -31,7 +31,7 @@ class ServerComponentResponse extends Response {
|
|
|
31
31
|
...DEFAULT_CACHE_OPTIONS,
|
|
32
32
|
...((_a = this.cacheOptions) !== null && _a !== void 0 ? _a : {}),
|
|
33
33
|
};
|
|
34
|
-
return cache_1.generateCacheControlHeader(options);
|
|
34
|
+
return (0, cache_1.generateCacheControlHeader)(options);
|
|
35
35
|
}
|
|
36
36
|
writeHead({ status, statusText, headers, } = {}) {
|
|
37
37
|
if (status || statusText) {
|
|
@@ -53,7 +53,7 @@ class ServerComponentResponse extends Response {
|
|
|
53
53
|
send(body) {
|
|
54
54
|
if (typeof body === 'object' &&
|
|
55
55
|
body.$$typeof === Symbol.for('react.element')) {
|
|
56
|
-
this.customBody = server_1.renderToString(body);
|
|
56
|
+
this.customBody = (0, server_1.renderToString)(body);
|
|
57
57
|
}
|
|
58
58
|
else {
|
|
59
59
|
this.customBody = body;
|
|
@@ -45,7 +45,7 @@ function renderReactProp(prop) {
|
|
|
45
45
|
* set expectations as thus when passing components as
|
|
46
46
|
* props within Server Components.
|
|
47
47
|
*/
|
|
48
|
-
return parseReactFromString(server_1.renderToString(prop));
|
|
48
|
+
return parseReactFromString((0, server_1.renderToString)(prop));
|
|
49
49
|
}
|
|
50
50
|
else {
|
|
51
51
|
return {
|
|
@@ -57,8 +57,8 @@ function renderReactProp(prop) {
|
|
|
57
57
|
return prop;
|
|
58
58
|
}
|
|
59
59
|
function parseReactFromString(input, options = {}) {
|
|
60
|
-
return dom_to_react_1.default(
|
|
60
|
+
return (0, dom_to_react_1.default)(
|
|
61
61
|
// @ts-ignore
|
|
62
|
-
html_dom_parser_1.default(input, { lowerCaseTags: false, lowerCaseAttributeNames: false }), options);
|
|
62
|
+
(0, html_dom_parser_1.default)(input, { lowerCaseTags: false, lowerCaseAttributeNames: false }), options);
|
|
63
63
|
}
|
|
64
64
|
exports.parseReactFromString = parseReactFromString;
|
|
@@ -8,7 +8,7 @@ const react_utils_1 = require("./react-utils");
|
|
|
8
8
|
*/
|
|
9
9
|
function generateWireSyntaxFromRenderedHtml(html) {
|
|
10
10
|
const clientComponents = new ClientComponents_server_1.ClientComponents();
|
|
11
|
-
const wireModel = react_utils_1.parseReactFromString(html, {
|
|
11
|
+
const wireModel = (0, react_utils_1.parseReactFromString)(html, {
|
|
12
12
|
library: {
|
|
13
13
|
// @ts-ignore
|
|
14
14
|
createElement: convertToWireSyntax,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.HydrationWriter = void 0;
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-empty-function */
|
|
4
5
|
/**
|
|
5
6
|
* HydrationWriter is an implementation of `WritableStream` which
|
|
6
7
|
* keeps track of chunks emitted from React's `pipeToNodeWritable`.
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { QueryKey } from '
|
|
2
|
-
import type { CacheOptions } from '../types';
|
|
1
|
+
import type { CacheOptions, QueryKey } from '../types';
|
|
3
2
|
export declare function generateCacheControlHeader(options: CacheOptions): string;
|
|
4
3
|
/**
|
|
5
4
|
* Use a preview header during development.
|
|
@@ -9,6 +8,7 @@ export declare function generateCacheControlHeader(options: CacheOptions): strin
|
|
|
9
8
|
export declare function getCacheControlHeader({ dev }: {
|
|
10
9
|
dev?: boolean;
|
|
11
10
|
}): "cache-control-preview" | "cache-control";
|
|
11
|
+
export declare function hashKey(key: QueryKey): string;
|
|
12
12
|
/**
|
|
13
13
|
* Get an item from the cache. If a match is found, returns a tuple
|
|
14
14
|
* containing the `JSON.parse` version of the response as well
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isStale = exports.deleteItemFromCache = exports.setItemInCache = exports.getItemFromCache = exports.getCacheControlHeader = exports.generateCacheControlHeader = void 0;
|
|
3
|
+
exports.isStale = exports.deleteItemFromCache = exports.setItemInCache = exports.getItemFromCache = exports.hashKey = exports.getCacheControlHeader = exports.generateCacheControlHeader = void 0;
|
|
4
4
|
const runtime_1 = require("./runtime");
|
|
5
5
|
const DEFAULT_SUBREQUEST_CACHE_OPTIONS = {
|
|
6
6
|
maxAge: 1,
|
|
@@ -33,6 +33,7 @@ function hashKey(key) {
|
|
|
33
33
|
*/
|
|
34
34
|
return rawKey.map((k) => JSON.stringify(k)).join('');
|
|
35
35
|
}
|
|
36
|
+
exports.hashKey = hashKey;
|
|
36
37
|
/**
|
|
37
38
|
* Cache API is weird. We just need a full URL, so we make one up.
|
|
38
39
|
*/
|
|
@@ -45,7 +46,7 @@ function getKeyUrl(key) {
|
|
|
45
46
|
* as the response itself so it can be checked for staleness.
|
|
46
47
|
*/
|
|
47
48
|
async function getItemFromCache(key) {
|
|
48
|
-
const cache = runtime_1.getCache();
|
|
49
|
+
const cache = (0, runtime_1.getCache)();
|
|
49
50
|
if (!cache) {
|
|
50
51
|
return;
|
|
51
52
|
}
|
|
@@ -61,7 +62,7 @@ exports.getItemFromCache = getItemFromCache;
|
|
|
61
62
|
* Put an item into the cache.
|
|
62
63
|
*/
|
|
63
64
|
async function setItemInCache(key, value, userCacheOptions) {
|
|
64
|
-
const cache = runtime_1.getCache();
|
|
65
|
+
const cache = (0, runtime_1.getCache)();
|
|
65
66
|
if (!cache) {
|
|
66
67
|
return;
|
|
67
68
|
}
|
|
@@ -83,7 +84,7 @@ async function setItemInCache(key, value, userCacheOptions) {
|
|
|
83
84
|
}
|
|
84
85
|
exports.setItemInCache = setItemInCache;
|
|
85
86
|
async function deleteItemFromCache(key) {
|
|
86
|
-
const cache = runtime_1.getCache();
|
|
87
|
+
const cache = (0, runtime_1.getCache)();
|
|
87
88
|
if (!cache)
|
|
88
89
|
return;
|
|
89
90
|
const url = getKeyUrl(hashKey(key));
|
|
@@ -74,7 +74,7 @@ function hydrogenMiddleware({ dev, cache, indexTemplate, getServerEntrypoint, de
|
|
|
74
74
|
* polyfill has loaded above.
|
|
75
75
|
*/
|
|
76
76
|
const { ServerComponentRequest } = await Promise.resolve().then(() => __importStar(require('./Hydration/ServerComponentRequest.server')));
|
|
77
|
-
const eventResponse = await handle_event_1.default(
|
|
77
|
+
const eventResponse = await (0, handle_event_1.default)(
|
|
78
78
|
/**
|
|
79
79
|
* Mimic a `FetchEvent`
|
|
80
80
|
*/
|
|
@@ -143,5 +143,5 @@ async function respondWithGraphiql(response, shopifyConfig) {
|
|
|
143
143
|
}
|
|
144
144
|
const { storeDomain, storefrontToken, graphqlApiVersion } = shopifyConfig;
|
|
145
145
|
response.setHeader('Content-Type', 'text/html');
|
|
146
|
-
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));
|
|
147
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
|
};
|
|
@@ -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: async (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'],
|
|
@@ -57,6 +68,7 @@ exports.default = () => {
|
|
|
57
68
|
define: {
|
|
58
69
|
__DEV__: env.mode !== 'production',
|
|
59
70
|
},
|
|
71
|
+
envPrefix: ['VITE_', 'PUBLIC_'],
|
|
60
72
|
}),
|
|
61
73
|
};
|
|
62
74
|
};
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
2
|
import type { HydrogenVitePluginOptions, ShopifyConfig } from '../../types';
|
|
3
3
|
declare const _default: (shopifyConfig: ShopifyConfig, pluginOptions: HydrogenVitePluginOptions) => Plugin;
|
|
4
4
|
export default _default;
|
|
5
|
+
declare global {
|
|
6
|
+
var Oxygen: {
|
|
7
|
+
env: Record<string, string | undefined>;
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
@@ -3,6 +3,7 @@ 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 fs_1 = require("fs");
|
|
8
9
|
const middleware_1 = require("../middleware");
|
|
@@ -16,19 +17,20 @@ exports.default = (shopifyConfig, pluginOptions) => {
|
|
|
16
17
|
* loading them in an SSR context, rendering them using the `entry-server` endpoint in the
|
|
17
18
|
* user's project, and injecting the static HTML into the template.
|
|
18
19
|
*/
|
|
19
|
-
configureServer(server) {
|
|
20
|
+
async configureServer(server) {
|
|
20
21
|
const resolve = (p) => path_1.default.resolve(server.config.root, p);
|
|
21
22
|
async function getIndexTemplate(url) {
|
|
22
23
|
const indexHtml = await fs_1.promises.readFile(resolve('index.html'), 'utf-8');
|
|
23
24
|
return await server.transformIndexHtml(url, indexHtml);
|
|
24
25
|
}
|
|
26
|
+
await polyfillOxygenEnv(server.config);
|
|
25
27
|
// The default vite middleware rewrites the URL `/graphqil` to `/index.html`
|
|
26
28
|
// By running this middleware first, we avoid that.
|
|
27
|
-
server.middlewares.use(middleware_1.graphiqlMiddleware({
|
|
29
|
+
server.middlewares.use((0, middleware_1.graphiqlMiddleware)({
|
|
28
30
|
shopifyConfig,
|
|
29
31
|
dev: true,
|
|
30
32
|
}));
|
|
31
|
-
return () => server.middlewares.use(middleware_1.hydrogenMiddleware({
|
|
33
|
+
return () => server.middlewares.use((0, middleware_1.hydrogenMiddleware)({
|
|
32
34
|
dev: true,
|
|
33
35
|
shopifyConfig,
|
|
34
36
|
indexTemplate: getIndexTemplate,
|
|
@@ -41,3 +43,15 @@ exports.default = (shopifyConfig, pluginOptions) => {
|
|
|
41
43
|
},
|
|
42
44
|
};
|
|
43
45
|
};
|
|
46
|
+
async function polyfillOxygenEnv(config) {
|
|
47
|
+
const env = await (0, vite_1.loadEnv)(config.mode, config.root, '');
|
|
48
|
+
const publicPrefixes = Array.isArray(config.envPrefix)
|
|
49
|
+
? config.envPrefix
|
|
50
|
+
: [config.envPrefix || ''];
|
|
51
|
+
for (const key of Object.keys(env)) {
|
|
52
|
+
if (publicPrefixes.some((prefix) => key.startsWith(prefix))) {
|
|
53
|
+
delete env[key];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
globalThis.Oxygen = { env };
|
|
57
|
+
}
|
|
@@ -7,7 +7,6 @@ const vite_1 = require("vite");
|
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const server_components_1 = require("../server-components");
|
|
9
9
|
const resolver_1 = require("./resolver");
|
|
10
|
-
const fs_1 = require("fs");
|
|
11
10
|
exports.default = () => {
|
|
12
11
|
let config;
|
|
13
12
|
return {
|
|
@@ -45,16 +44,7 @@ exports.default = () => {
|
|
|
45
44
|
return null;
|
|
46
45
|
// Wrapped components won't match this becase they end in ?no-proxy
|
|
47
46
|
if (/\.client\.[jt]sx?$/.test(id)) {
|
|
48
|
-
return server_components_1.proxyClientComponent({ id });
|
|
49
|
-
}
|
|
50
|
-
// Temporary fix for sourcemap warnings in client components. This can be fixed in @vitejs/react-plugin.
|
|
51
|
-
// `react-ssr-prepass` sourcemap seems to be broken and crashes in workers/Jest.
|
|
52
|
-
if (id.endsWith('?no-proxy') ||
|
|
53
|
-
id.includes('dist/react-ssr-prepass.es.js')) {
|
|
54
|
-
return {
|
|
55
|
-
code: await fs_1.promises.readFile(id.split('?')[0], 'utf-8'),
|
|
56
|
-
map: { mappings: '' },
|
|
57
|
-
};
|
|
47
|
+
return (0, server_components_1.proxyClientComponent)({ id });
|
|
58
48
|
}
|
|
59
49
|
return null;
|
|
60
50
|
},
|
|
@@ -71,35 +61,23 @@ exports.default = () => {
|
|
|
71
61
|
*/
|
|
72
62
|
if (id.includes('/Hydration/client-imports')) {
|
|
73
63
|
// eslint-disable-next-line node/no-missing-require
|
|
74
|
-
const hydrogenPath = path_1.default.dirname(resolver_1.resolve('@shopify/hydrogen'));
|
|
64
|
+
const hydrogenPath = path_1.default.dirname((0, resolver_1.resolve)('@shopify/hydrogen'));
|
|
75
65
|
const importerPath = path_1.default.join(hydrogenPath, 'framework', 'Hydration');
|
|
76
|
-
const importerToRootPath = vite_1.normalizePath(path_1.default.relative(importerPath, config.root));
|
|
66
|
+
const importerToRootPath = (0, vite_1.normalizePath)(path_1.default.relative(importerPath, config.root));
|
|
77
67
|
const [importerToRootNested] = importerToRootPath.match(/(\.\.\/)+(\.\.)?/) || [];
|
|
78
68
|
const userPrefix = path_1.default.normalize(path_1.default.join(importerPath, importerToRootNested.replace(/\/?$/, path_1.default.sep)));
|
|
79
69
|
const userGlob = path_1.default.join(importerToRootPath, 'src', '**/*.client.[jt]sx');
|
|
80
70
|
const libPrefix = hydrogenPath + path_1.default.sep;
|
|
81
71
|
const libGlob = path_1.default.join(path_1.default.relative(importerPath, hydrogenPath), 'components', '**/*.client.js');
|
|
82
72
|
return code
|
|
83
|
-
.replace('__USER_COMPONENTS_PREFIX__', vite_1.normalizePath(userPrefix))
|
|
84
|
-
.replace('__USER_COMPONENTS_GLOB__', vite_1.normalizePath(userGlob))
|
|
85
|
-
.replace('__LIB_COMPONENTS_PREFIX__', vite_1.normalizePath(libPrefix))
|
|
86
|
-
.replace('__LIB_COMPONENTS_GLOB__', vite_1.normalizePath(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));
|
|
87
77
|
}
|
|
88
78
|
},
|
|
89
79
|
};
|
|
90
|
-
// Mitigation for upcoming minor Vite update
|
|
91
|
-
// https://github.com/vitejs/vite/pull/5253
|
|
92
|
-
// TO-DO: When the vite package is updated with the above Vite PR,
|
|
93
|
-
// clean up this function and treat `options` param as objects
|
|
94
|
-
// from this point forward
|
|
95
|
-
// Timeline: Targetting for Vite 2.7
|
|
96
80
|
function isSSR(options) {
|
|
97
|
-
|
|
98
|
-
return options;
|
|
99
|
-
}
|
|
100
|
-
if (typeof options === 'object') {
|
|
101
|
-
return !!options.ssr;
|
|
102
|
-
}
|
|
103
|
-
return false;
|
|
81
|
+
return !!(options === null || options === void 0 ? void 0 : options.ssr);
|
|
104
82
|
}
|
|
105
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
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
35
|
-
|
|
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 (
|
|
48
|
-
|
|
33
|
+
if (componentExports.length === 0) {
|
|
34
|
+
return `export * from '${importFrom}';\n`;
|
|
49
35
|
}
|
|
50
|
-
s.
|
|
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 (
|
|
53
|
-
s.append(`export {${
|
|
39
|
+
if (otherExports.length > 0) {
|
|
40
|
+
s.append(`export {${otherExports.join(', ')}} from '${importFrom}';\n`);
|
|
54
41
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
}
|