@shopify/hydrogen 0.6.2 → 0.7.1
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/AddToCartButton/AddToCartButton.client.d.ts +1 -1
- package/dist/esnext/components/AddToCartButton/AddToCartButton.client.js +3 -3
- package/dist/esnext/components/CartLineProvider/context.d.ts +3 -3
- 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/MediaFile/MediaFile.d.ts +1 -1
- package/dist/esnext/components/Metafield/Metafield.client.d.ts +1 -1
- package/dist/esnext/components/Metafield/Metafield.client.js +8 -0
- package/dist/esnext/components/Metafield/MetafieldFragment.d.ts +16 -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 +3 -1
- package/dist/esnext/components/Model3D/Model3D.client.js +1 -1
- package/dist/esnext/components/Money/Money.client.d.ts +1 -1
- package/dist/esnext/components/ProductProvider/ProductProvider.client.d.ts +1 -1
- package/dist/esnext/components/ProductProvider/context.d.ts +2 -2
- package/dist/esnext/components/ProductProvider/types.d.ts +2 -2
- package/dist/esnext/components/SelectedVariantAddToCartButton/SelectedVariantAddToCartButton.client.d.ts +1 -1
- package/dist/esnext/components/SelectedVariantAddToCartButton/SelectedVariantAddToCartButton.client.js +1 -1
- package/dist/esnext/components/UnitPrice/UnitPrice.client.d.ts +1 -1
- package/dist/esnext/components/Video/Video.d.ts +1 -1
- package/dist/esnext/components/index.d.ts +2 -2
- package/dist/esnext/entry-server.js +43 -19
- package/dist/esnext/foundation/Router/ServerStateRouter.client.js +5 -3
- package/dist/esnext/foundation/ServerStateProvider/ServerStateProvider.client.d.ts +19 -11
- package/dist/esnext/foundation/ServerStateProvider/ServerStateProvider.client.js +21 -20
- package/dist/esnext/foundation/ServerStateProvider/index.d.ts +2 -1
- package/dist/esnext/foundation/ShopifyProvider/ShopifyServerProvider.server.js +1 -1
- package/dist/esnext/{hooks → foundation}/useQuery/QueryProvider.d.ts +0 -0
- package/dist/esnext/{hooks → foundation}/useQuery/QueryProvider.js +0 -0
- package/dist/esnext/{hooks → foundation}/useQuery/hooks.d.ts +0 -0
- package/dist/esnext/{hooks → foundation}/useQuery/hooks.js +13 -3
- package/dist/esnext/{hooks → foundation}/useQuery/index.d.ts +0 -0
- package/dist/esnext/{hooks → foundation}/useQuery/index.js +0 -0
- package/dist/esnext/foundation/useServerState/use-server-state.d.ts +2 -2
- package/dist/esnext/foundation/useServerState/use-server-state.js +1 -1
- package/dist/esnext/framework/ClientMarker/ClientMarker.js +0 -1
- package/dist/esnext/framework/Hydration/Cache.client.js +3 -1
- package/dist/esnext/framework/Hydration/ServerComponentResponse.server.d.ts +10 -0
- package/dist/esnext/framework/Hydration/ServerComponentResponse.server.js +13 -0
- package/dist/esnext/framework/Hydration/client-imports.d.ts +1 -1
- package/dist/esnext/framework/Hydration/client-imports.js +1 -1
- package/dist/esnext/framework/Hydration/wire.server.js +1 -1
- package/dist/esnext/framework/Hydration/writer.server.js +1 -0
- package/dist/esnext/framework/middleware.d.ts +5 -1
- package/dist/esnext/framework/middleware.js +12 -8
- package/dist/esnext/framework/plugins/resolver.d.ts +1 -0
- package/dist/esnext/framework/plugins/resolver.js +3 -0
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-config.js +4 -1
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-middleware.js +8 -2
- package/dist/esnext/framework/plugins/vite-plugin-react-server-components-shim.js +11 -9
- package/dist/esnext/framework/server-components.js +25 -47
- package/dist/esnext/graphql/graphql-constants.d.ts +74 -37
- package/dist/esnext/graphql/graphql-constants.js +89 -15
- package/dist/esnext/handle-event.js +8 -4
- 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/useMoney/hooks.js +2 -16
- package/dist/esnext/hooks/useParsedMetafields/useParsedMetafields.d.ts +2 -3
- package/dist/esnext/hooks/useProductOptions/types.d.ts +2 -3
- package/dist/esnext/hooks/useShopQuery/hooks.d.ts +4 -2
- package/dist/esnext/hooks/useShopQuery/hooks.js +6 -3
- package/dist/esnext/types.d.ts +19 -3
- package/dist/esnext/utilities/flattenConnection/flattenConnection.d.ts +0 -7
- package/dist/esnext/utilities/flattenConnection/flattenConnection.js +0 -7
- package/dist/esnext/utilities/isClient/isClient.d.ts +0 -4
- package/dist/esnext/utilities/isClient/isClient.js +0 -4
- package/dist/esnext/utilities/isServer/isServer.d.ts +0 -4
- package/dist/esnext/utilities/isServer/isServer.js +0 -4
- package/dist/esnext/utilities/parseMetafieldValue/parseMetafieldValue.d.ts +2 -33
- package/dist/esnext/utilities/parseMetafieldValue/parseMetafieldValue.js +0 -31
- 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 +7 -5
- package/dist/node/framework/Hydration/HydrationContext.server.js +1 -1
- package/dist/node/framework/Hydration/ServerComponentResponse.server.d.ts +10 -0
- package/dist/node/framework/Hydration/ServerComponentResponse.server.js +15 -2
- package/dist/node/framework/Hydration/client-imports.d.ts +1 -1
- package/dist/node/framework/Hydration/client-imports.js +2 -2
- package/dist/node/framework/Hydration/react-utils.js +3 -3
- package/dist/node/framework/Hydration/wire.server.js +2 -2
- package/dist/node/framework/Hydration/writer.server.js +1 -0
- package/dist/node/framework/cache.js +3 -3
- package/dist/node/framework/middleware.d.ts +5 -1
- package/dist/node/framework/middleware.js +17 -11
- package/dist/node/framework/plugin.js +5 -5
- package/dist/node/framework/plugins/resolver.d.ts +1 -0
- package/dist/node/framework/plugins/resolver.js +7 -0
- package/dist/node/framework/plugins/vite-plugin-hydrogen-config.js +4 -1
- package/dist/node/framework/plugins/vite-plugin-hydrogen-middleware.js +8 -2
- package/dist/node/framework/plugins/vite-plugin-react-server-components-shim.js +12 -10
- package/dist/node/framework/server-components.js +27 -49
- package/dist/node/handle-event.js +12 -8
- package/dist/node/types.d.ts +19 -3
- package/dist/node/utilities/fetch.js +1 -1
- package/dist/node/utilities/flattenConnection/flattenConnection.d.ts +0 -7
- package/dist/node/utilities/flattenConnection/flattenConnection.js +0 -7
- package/dist/node/utilities/isClient/isClient.d.ts +0 -4
- package/dist/node/utilities/isClient/isClient.js +0 -4
- package/dist/node/utilities/isServer/isServer.d.ts +0 -4
- package/dist/node/utilities/isServer/isServer.js +1 -5
- package/dist/node/utilities/parseMetafieldValue/parseMetafieldValue.d.ts +2 -33
- package/dist/node/utilities/parseMetafieldValue/parseMetafieldValue.js +0 -31
- 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/ServerComponentResponse.server.d.ts +10 -0
- package/dist/worker/framework/Hydration/ServerComponentResponse.server.js +13 -0
- package/dist/worker/handle-event.js +8 -4
- package/dist/worker/types.d.ts +19 -3
- package/package.json +9 -7
|
@@ -111,7 +111,9 @@ export async function convertHydrationResponseToReactComponents(response) {
|
|
|
111
111
|
function createManifestFromWirePayload(payload) {
|
|
112
112
|
return payload.split('\n').reduce((memo, row) => {
|
|
113
113
|
const [key, ...values] = row.split(':');
|
|
114
|
-
|
|
114
|
+
if (key) {
|
|
115
|
+
memo[key] = JSON.parse(values.join(':'));
|
|
116
|
+
}
|
|
115
117
|
return memo;
|
|
116
118
|
}, {});
|
|
117
119
|
}
|
|
@@ -2,6 +2,10 @@ import { CacheOptions } from '../../types';
|
|
|
2
2
|
export declare class ServerComponentResponse extends Response {
|
|
3
3
|
private wait;
|
|
4
4
|
private cacheOptions?;
|
|
5
|
+
customStatus?: {
|
|
6
|
+
code?: number;
|
|
7
|
+
text?: string;
|
|
8
|
+
};
|
|
5
9
|
/**
|
|
6
10
|
* Allow custom body to be a string or a Promise.
|
|
7
11
|
*/
|
|
@@ -14,6 +18,12 @@ export declare class ServerComponentResponse extends Response {
|
|
|
14
18
|
canStream(): boolean;
|
|
15
19
|
cache(options: CacheOptions): void;
|
|
16
20
|
get cacheControlHeader(): string;
|
|
21
|
+
writeHead({ status, statusText, headers, }?: {
|
|
22
|
+
status?: number;
|
|
23
|
+
statusText?: string;
|
|
24
|
+
headers?: Record<string, any>;
|
|
25
|
+
}): void;
|
|
26
|
+
redirect(location: string, status?: number): void;
|
|
17
27
|
/**
|
|
18
28
|
* Send the response from a Server Component. Renders React components to string,
|
|
19
29
|
* and returns `null` to make React happy.
|
|
@@ -30,6 +30,19 @@ export class ServerComponentResponse extends Response {
|
|
|
30
30
|
};
|
|
31
31
|
return generateCacheControlHeader(options);
|
|
32
32
|
}
|
|
33
|
+
writeHead({ status, statusText, headers, } = {}) {
|
|
34
|
+
if (status || statusText) {
|
|
35
|
+
this.customStatus = { code: status, text: statusText };
|
|
36
|
+
}
|
|
37
|
+
if (headers) {
|
|
38
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
39
|
+
this.headers.set(key, value);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
redirect(location, status = 307) {
|
|
44
|
+
this.writeHead({ status, headers: { location } });
|
|
45
|
+
}
|
|
33
46
|
/**
|
|
34
47
|
* Send the response from a Server Component. Renders React components to string,
|
|
35
48
|
* and returns `null` to make React happy.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function
|
|
1
|
+
export default function importClientComponent(moduleId: string): any;
|
|
@@ -16,7 +16,7 @@ const allClientComponents = {
|
|
|
16
16
|
// @ts-ignore
|
|
17
17
|
import.meta.glob('__USER_COMPONENTS_GLOB__'), `__USER_COMPONENTS_PREFIX__`),
|
|
18
18
|
};
|
|
19
|
-
export default function
|
|
19
|
+
export default function importClientComponent(moduleId) {
|
|
20
20
|
const modImport = allClientComponents[moduleId];
|
|
21
21
|
if (!modImport) {
|
|
22
22
|
throw new Error(`Could not find client component ${moduleId}`);
|
|
@@ -68,7 +68,7 @@ export function generateWireSyntaxFromRenderedHtml(html) {
|
|
|
68
68
|
.map((component, idx) => {
|
|
69
69
|
return `M${idx + 1}:${JSON.stringify(component)}`;
|
|
70
70
|
})
|
|
71
|
-
.join('\n') + `\nJ0:${JSON.stringify(wireModel)}`);
|
|
71
|
+
.join('\n') + `\nJ0:${JSON.stringify(wireModel)}`).trim();
|
|
72
72
|
}
|
|
73
73
|
function isDomNode(item) {
|
|
74
74
|
return item !== null && typeof item === 'object' && '_owner' in item;
|
|
@@ -10,9 +10,13 @@ declare type HydrogenMiddlewareArgs = {
|
|
|
10
10
|
devServer?: ViteDevServer;
|
|
11
11
|
cache?: Cache;
|
|
12
12
|
};
|
|
13
|
+
export declare function graphiqlMiddleware({ shopifyConfig, dev, }: {
|
|
14
|
+
shopifyConfig: ShopifyConfig;
|
|
15
|
+
dev: boolean;
|
|
16
|
+
}): (request: IncomingMessage, response: http.ServerResponse, next: NextFunction) => Promise<void>;
|
|
13
17
|
/**
|
|
14
18
|
* Provides middleware to Node.js Express-like servers. Used by the Hydrogen
|
|
15
19
|
* Vite dev server plugin as well as production Node.js implementation.
|
|
16
20
|
*/
|
|
17
|
-
export
|
|
21
|
+
export declare function hydrogenMiddleware({ dev, cache, indexTemplate, getServerEntrypoint, devServer, }: HydrogenMiddlewareArgs): (request: IncomingMessage, response: http.ServerResponse, next: NextFunction) => Promise<void>;
|
|
18
22
|
export {};
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import { graphiqlHtml } from './graphiql';
|
|
2
2
|
import handleEvent from '../handle-event';
|
|
3
|
-
|
|
4
|
-
* Provides middleware to Node.js Express-like servers. Used by the Hydrogen
|
|
5
|
-
* Vite dev server plugin as well as production Node.js implementation.
|
|
6
|
-
*/
|
|
7
|
-
export default function hydrogenMiddleware({ dev, shopifyConfig, cache, indexTemplate, getServerEntrypoint, devServer, }) {
|
|
3
|
+
export function graphiqlMiddleware({ shopifyConfig, dev, }) {
|
|
8
4
|
return async function (request, response, next) {
|
|
9
5
|
const graphiqlRequest = dev && isGraphiqlRequest(request);
|
|
10
6
|
if (graphiqlRequest) {
|
|
11
7
|
return respondWithGraphiql(response, shopifyConfig);
|
|
12
8
|
}
|
|
9
|
+
next();
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Provides middleware to Node.js Express-like servers. Used by the Hydrogen
|
|
14
|
+
* Vite dev server plugin as well as production Node.js implementation.
|
|
15
|
+
*/
|
|
16
|
+
export function hydrogenMiddleware({ dev, cache, indexTemplate, getServerEntrypoint, devServer, }) {
|
|
17
|
+
return async function (request, response, next) {
|
|
13
18
|
const url = new URL('http://' + request.headers.host + request.originalUrl);
|
|
14
19
|
const isReactHydrationRequest = url.pathname === '/react';
|
|
15
20
|
/**
|
|
@@ -96,9 +101,8 @@ export default function hydrogenMiddleware({ dev, shopifyConfig, cache, indexTem
|
|
|
96
101
|
}
|
|
97
102
|
function shouldInterceptRequest(request, isReactHydrationRequest) {
|
|
98
103
|
var _a;
|
|
99
|
-
return (
|
|
100
|
-
isReactHydrationRequest)
|
|
101
|
-
request.url !== '/favicon.ico');
|
|
104
|
+
return (/text\/html|application\/hydrogen/.test((_a = request.headers['accept']) !== null && _a !== void 0 ? _a : '') ||
|
|
105
|
+
isReactHydrationRequest);
|
|
102
106
|
}
|
|
103
107
|
/**
|
|
104
108
|
* /graphiql and /___graphql are supported
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function resolve(path: string): string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export default () => {
|
|
2
2
|
return {
|
|
3
3
|
name: 'vite-plugin-hydrogen-config',
|
|
4
|
-
config: () => ({
|
|
4
|
+
config: (_, env) => ({
|
|
5
5
|
resolve: {
|
|
6
6
|
alias: {
|
|
7
7
|
/**
|
|
@@ -52,6 +52,9 @@ export default () => {
|
|
|
52
52
|
'react-router-dom',
|
|
53
53
|
],
|
|
54
54
|
},
|
|
55
|
+
define: {
|
|
56
|
+
__DEV__: env.mode !== 'production',
|
|
57
|
+
},
|
|
55
58
|
}),
|
|
56
59
|
};
|
|
57
60
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import { promises as fs } from 'fs';
|
|
3
|
-
import hydrogenMiddleware from '../middleware';
|
|
3
|
+
import { hydrogenMiddleware, graphiqlMiddleware } from '../middleware';
|
|
4
4
|
import { InMemoryCache } from '../cache/in-memory';
|
|
5
5
|
export default (shopifyConfig, pluginOptions) => {
|
|
6
6
|
return {
|
|
@@ -17,7 +17,13 @@ export default (shopifyConfig, pluginOptions) => {
|
|
|
17
17
|
const indexHtml = await fs.readFile(resolve('index.html'), 'utf-8');
|
|
18
18
|
return await server.transformIndexHtml(url, indexHtml);
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
// The default vite middleware rewrites the URL `/graphqil` to `/index.html`
|
|
21
|
+
// By running this middleware first, we avoid that.
|
|
22
|
+
server.middlewares.use(graphiqlMiddleware({
|
|
23
|
+
shopifyConfig,
|
|
24
|
+
dev: true,
|
|
25
|
+
}));
|
|
26
|
+
return () => server.middlewares.use(hydrogenMiddleware({
|
|
21
27
|
dev: true,
|
|
22
28
|
shopifyConfig,
|
|
23
29
|
indexTemplate: getIndexTemplate,
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { normalizePath } from 'vite';
|
|
1
2
|
import path from 'path';
|
|
2
3
|
import { proxyClientComponent } from '../server-components';
|
|
4
|
+
import { resolve } from './resolver';
|
|
3
5
|
export default () => {
|
|
4
6
|
let config;
|
|
5
7
|
return {
|
|
@@ -32,7 +34,7 @@ export default () => {
|
|
|
32
34
|
'When using Hydrogen components within Client Components, use the `@shopify/hydrogen/client` entrypoint instead.');
|
|
33
35
|
}
|
|
34
36
|
},
|
|
35
|
-
load(id, options) {
|
|
37
|
+
async load(id, options) {
|
|
36
38
|
if (!isSSR(options))
|
|
37
39
|
return null;
|
|
38
40
|
// Wrapped components won't match this becase they end in ?no-proxy
|
|
@@ -54,19 +56,19 @@ export default () => {
|
|
|
54
56
|
*/
|
|
55
57
|
if (id.includes('/Hydration/client-imports')) {
|
|
56
58
|
// eslint-disable-next-line node/no-missing-require
|
|
57
|
-
const hydrogenPath = path.dirname(
|
|
59
|
+
const hydrogenPath = path.dirname(resolve('@shopify/hydrogen'));
|
|
58
60
|
const importerPath = path.join(hydrogenPath, 'framework', 'Hydration');
|
|
59
|
-
const importerToRootPath = path.relative(importerPath, config.root);
|
|
60
|
-
const [importerToRootNested] = importerToRootPath.match(/(\.\.\/)
|
|
61
|
-
const userPrefix = path.normalize(path.join(importerPath, importerToRootNested));
|
|
61
|
+
const importerToRootPath = normalizePath(path.relative(importerPath, config.root));
|
|
62
|
+
const [importerToRootNested] = importerToRootPath.match(/(\.\.\/)+(\.\.)?/) || [];
|
|
63
|
+
const userPrefix = path.normalize(path.join(importerPath, importerToRootNested.replace(/\/?$/, path.sep)));
|
|
62
64
|
const userGlob = path.join(importerToRootPath, 'src', '**/*.client.[jt]sx');
|
|
63
65
|
const libPrefix = hydrogenPath + path.sep;
|
|
64
66
|
const libGlob = path.join(path.relative(importerPath, hydrogenPath), 'components', '**/*.client.js');
|
|
65
67
|
return code
|
|
66
|
-
.replace('__USER_COMPONENTS_PREFIX__', userPrefix)
|
|
67
|
-
.replace('__USER_COMPONENTS_GLOB__', userGlob)
|
|
68
|
-
.replace('__LIB_COMPONENTS_PREFIX__', libPrefix)
|
|
69
|
-
.replace('__LIB_COMPONENTS_GLOB__', libGlob);
|
|
68
|
+
.replace('__USER_COMPONENTS_PREFIX__', normalizePath(userPrefix))
|
|
69
|
+
.replace('__USER_COMPONENTS_GLOB__', normalizePath(userGlob))
|
|
70
|
+
.replace('__LIB_COMPONENTS_PREFIX__', normalizePath(libPrefix))
|
|
71
|
+
.replace('__LIB_COMPONENTS_GLOB__', normalizePath(libGlob));
|
|
70
72
|
}
|
|
71
73
|
},
|
|
72
74
|
};
|
|
@@ -2,9 +2,8 @@ import { init, parse } from 'es-module-lexer';
|
|
|
2
2
|
import { promises as fs } from 'fs';
|
|
3
3
|
import { transformWithEsbuild } from 'vite';
|
|
4
4
|
import MagicString from 'magic-string';
|
|
5
|
+
const DEFAULT_EXPORT = 'default';
|
|
5
6
|
export async function proxyClientComponent({ id, src, }) {
|
|
6
|
-
var _a;
|
|
7
|
-
const defaultComponentName = (_a = id.split('/').pop()) === null || _a === void 0 ? void 0 : _a.split('.').shift();
|
|
8
7
|
// Modify the import ID to avoid infinite wraps
|
|
9
8
|
const importFrom = `${id}?no-proxy`;
|
|
10
9
|
await init;
|
|
@@ -13,56 +12,35 @@ export async function proxyClientComponent({ id, src, }) {
|
|
|
13
12
|
}
|
|
14
13
|
const { code } = await transformWithEsbuild(src, id);
|
|
15
14
|
const [, exportStatements] = parse(code);
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
acc.components.push(i);
|
|
26
|
-
}
|
|
15
|
+
// Classify exports in components to wrap vs. everything else (e.g. GQL Fragments)
|
|
16
|
+
const otherExports = [];
|
|
17
|
+
const componentExports = [];
|
|
18
|
+
for (const key of exportStatements) {
|
|
19
|
+
if (key !== DEFAULT_EXPORT &&
|
|
20
|
+
/^use[A-Z]|Fragment$|Context$|^[A-Z_]+$/.test(key)) {
|
|
21
|
+
otherExports.push(key);
|
|
27
22
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (!hasDefaultExport && namedImports.components.length === 0) {
|
|
31
|
-
return `export * from '${importFrom}';\n`;
|
|
32
|
-
}
|
|
33
|
-
const s = new MagicString(`import {wrapInClientMarker} from '@shopify/hydrogen/marker';`);
|
|
34
|
-
s.append('\nimport ');
|
|
35
|
-
if (hasDefaultExport) {
|
|
36
|
-
s.append(defaultComponentName);
|
|
37
|
-
if (namedImports.components.length > 0) {
|
|
38
|
-
s.append(', ');
|
|
23
|
+
else {
|
|
24
|
+
componentExports.push(key);
|
|
39
25
|
}
|
|
40
26
|
}
|
|
41
|
-
if (
|
|
42
|
-
|
|
27
|
+
if (componentExports.length === 0) {
|
|
28
|
+
return `export * from '${importFrom}';\n`;
|
|
43
29
|
}
|
|
44
|
-
s
|
|
30
|
+
const s = new MagicString(`import {wrapInClientMarker} from '@shopify/hydrogen/marker';\n` +
|
|
31
|
+
`import * as allImports from '${importFrom}';\n\n`);
|
|
45
32
|
// Re-export other stuff directly without wrapping
|
|
46
|
-
if (
|
|
47
|
-
s.append(`export {${
|
|
33
|
+
if (otherExports.length > 0) {
|
|
34
|
+
s.append(`export {${otherExports.join(', ')}} from '${importFrom}';\n`);
|
|
48
35
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
componentName: name,
|
|
59
|
-
isDefault: false,
|
|
60
|
-
})));
|
|
36
|
+
// Wrap components in Client Marker
|
|
37
|
+
componentExports.forEach((key) => {
|
|
38
|
+
var _a;
|
|
39
|
+
const isDefault = key === DEFAULT_EXPORT;
|
|
40
|
+
const componentName = isDefault
|
|
41
|
+
? (_a = id.split('/').pop()) === null || _a === void 0 ? void 0 : _a.split('.').shift()
|
|
42
|
+
: key;
|
|
43
|
+
s.append(`export ${isDefault ? DEFAULT_EXPORT : `const ${componentName} =`} wrapInClientMarker({ name: '${componentName}', id: '${id}', component: allImports['${key}'], named: ${!isDefault} });\n`);
|
|
44
|
+
});
|
|
61
45
|
return s.toString();
|
|
62
46
|
}
|
|
63
|
-
function generateComponentExport({ id, isDefault, componentName, }) {
|
|
64
|
-
const component = isDefault
|
|
65
|
-
? componentName
|
|
66
|
-
: `namedImports['${componentName}']`;
|
|
67
|
-
return `export ${isDefault ? 'default' : `const ${componentName} =`} wrapInClientMarker({ name: '${componentName}', id: '${id}', component: ${component}, named: ${!isDefault} });\n`;
|
|
68
|
-
}
|