@shopify/hydrogen 1.3.1 → 1.4.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.
- package/dist/esnext/components/CartProvider/CartActions.client.d.ts +60 -0
- package/dist/esnext/components/CartProvider/CartActions.client.js +232 -0
- package/dist/esnext/components/CartProvider/CartProviderV2.client.d.ts +44 -0
- package/dist/esnext/components/CartProvider/CartProviderV2.client.js +232 -0
- package/dist/esnext/components/CartProvider/hooks.client.js +1 -1
- package/dist/esnext/components/CartProvider/types.d.ts +149 -0
- package/dist/esnext/components/CartProvider/useCartAPIStateMachine.client.d.ts +16 -0
- package/dist/esnext/components/CartProvider/useCartAPIStateMachine.client.js +231 -0
- package/dist/esnext/entry-client.js +27 -9
- package/dist/esnext/entry-server.js +20 -25
- package/dist/esnext/experimental.d.ts +1 -0
- package/dist/esnext/experimental.js +1 -0
- package/dist/esnext/foundation/HydrogenRequest/HydrogenRequest.server.d.ts +3 -2
- package/dist/esnext/foundation/HydrogenRequest/HydrogenRequest.server.js +1 -0
- package/dist/esnext/foundation/HydrogenResponse/HydrogenResponse.server.d.ts +4 -0
- package/dist/esnext/foundation/HydrogenResponse/HydrogenResponse.server.js +16 -1
- package/dist/esnext/foundation/ShopifyProvider/ShopifyProvider.client.d.ts +3 -3
- package/dist/esnext/foundation/ShopifyProvider/ShopifyProvider.server.d.ts +1 -0
- package/dist/esnext/foundation/ShopifyProvider/ShopifyProvider.server.js +21 -6
- package/dist/esnext/foundation/ShopifyProvider/types.d.ts +5 -2
- package/dist/esnext/foundation/fetchSync/ResponseSync.d.ts +2 -1
- package/dist/esnext/foundation/fetchSync/ResponseSync.js +14 -2
- package/dist/esnext/foundation/useShop/use-shop.d.ts +1 -1
- package/dist/esnext/framework/plugin.js +2 -2
- package/dist/esnext/framework/plugins/vite-plugin-assets-version.js +4 -0
- package/dist/esnext/framework/plugins/vite-plugin-client-imports.js +6 -3
- package/dist/esnext/framework/plugins/vite-plugin-css-modules-rsc.js +3 -0
- package/dist/esnext/framework/plugins/vite-plugin-css-rsc.js +8 -0
- package/dist/esnext/framework/plugins/vite-plugin-hydration-auto-import.js +7 -1
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-client-components-cache.d.ts +3 -0
- package/dist/esnext/framework/plugins/{vite-plugin-hydrogen-client-middleware.js → vite-plugin-hydrogen-client-components-cache.js} +2 -2
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-config.js +102 -91
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-middleware.js +6 -14
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-suppress-warnings.js +5 -0
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-virtual-files.js +21 -1
- package/dist/esnext/framework/plugins/vite-plugin-platform-entry.js +14 -1
- package/dist/esnext/framework/plugins/vite-plugin-ssr-interop.js +5 -1
- package/dist/esnext/framework/viteception.js +7 -1
- package/dist/esnext/hooks/useDelay/useDelay.d.ts +1 -0
- package/dist/esnext/hooks/useDelay/useDelay.js +17 -0
- package/dist/esnext/hooks/useShopQuery/hooks.js +4 -2
- package/dist/esnext/index.d.ts +1 -0
- package/dist/esnext/index.js +1 -0
- package/dist/esnext/shared-types.d.ts +2 -1
- package/dist/esnext/types.d.ts +2 -1
- package/dist/esnext/utilities/apiRoutes.d.ts +2 -0
- package/dist/esnext/utilities/apiRoutes.js +5 -2
- package/dist/esnext/utilities/log/log.js +12 -3
- package/dist/esnext/utilities/object.d.ts +1 -1
- package/dist/esnext/utilities/storefrontApi.d.ts +4 -2
- package/dist/esnext/utilities/storefrontApi.js +27 -6
- package/dist/esnext/utilities/template.d.ts +7 -6
- package/dist/esnext/utilities/template.js +39 -1
- package/dist/esnext/utilities/vite.d.ts +1 -0
- package/dist/esnext/utilities/vite.js +4 -0
- package/dist/esnext/version.d.ts +1 -1
- package/dist/esnext/version.js +1 -1
- package/dist/node/framework/plugin.js +2 -2
- package/dist/node/framework/plugins/vite-plugin-assets-version.js +4 -0
- package/dist/node/framework/plugins/vite-plugin-client-imports.js +6 -3
- package/dist/node/framework/plugins/vite-plugin-css-modules-rsc.js +3 -0
- package/dist/node/framework/plugins/vite-plugin-css-rsc.js +8 -0
- package/dist/node/framework/plugins/vite-plugin-hydration-auto-import.js +7 -1
- package/dist/node/framework/plugins/vite-plugin-hydrogen-client-components-cache.d.ts +3 -0
- package/dist/node/framework/plugins/{vite-plugin-hydrogen-client-middleware.js → vite-plugin-hydrogen-client-components-cache.js} +2 -2
- package/dist/node/framework/plugins/vite-plugin-hydrogen-config.js +102 -91
- package/dist/node/framework/plugins/vite-plugin-hydrogen-middleware.js +6 -14
- package/dist/node/framework/plugins/vite-plugin-hydrogen-suppress-warnings.js +5 -0
- package/dist/node/framework/plugins/vite-plugin-hydrogen-virtual-files.js +21 -1
- package/dist/node/framework/plugins/vite-plugin-platform-entry.js +14 -1
- package/dist/node/framework/plugins/vite-plugin-ssr-interop.js +5 -1
- package/dist/node/framework/viteception.js +7 -1
- package/dist/node/shared-types.d.ts +2 -1
- package/dist/node/utilities/vite.d.ts +1 -0
- package/dist/node/utilities/vite.js +30 -0
- package/package.json +5 -3
- package/vendor/react-server-dom-vite/cjs/react-server-dom-vite-plugin.js +31 -21
- package/vendor/react-server-dom-vite/cjs/react-server-dom-vite-writer.browser.development.server.js +105 -29
- package/vendor/react-server-dom-vite/cjs/react-server-dom-vite-writer.browser.production.min.server.js +30 -29
- package/vendor/react-server-dom-vite/cjs/react-server-dom-vite-writer.node.development.server.js +92 -29
- package/vendor/react-server-dom-vite/cjs/react-server-dom-vite-writer.node.production.min.server.js +31 -29
- package/vendor/react-server-dom-vite/esm/react-server-dom-vite-plugin.js +24 -14
- package/vendor/react-server-dom-vite/esm/react-server-dom-vite-writer.browser.server.js +105 -29
- package/vendor/react-server-dom-vite/esm/react-server-dom-vite-writer.node.server.js +92 -29
- package/vendor/react-server-dom-vite/package.json +2 -2
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-client-middleware.d.ts +0 -9
- package/dist/node/framework/plugins/vite-plugin-hydrogen-client-middleware.d.ts +0 -9
|
@@ -4,108 +4,119 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const crypto_1 = __importDefault(require("crypto"));
|
|
7
|
+
/* -- Plugin notes:
|
|
8
|
+
* Provide configuration options to Vite to ensure Hydrogen is built correctly
|
|
9
|
+
* for worker environments, using latest ES syntax, and some other requirements.
|
|
10
|
+
*/
|
|
7
11
|
exports.default = (pluginOptions) => {
|
|
8
12
|
const rollupOptions = {
|
|
9
13
|
output: {},
|
|
10
14
|
};
|
|
11
15
|
const isWorker = Boolean(process.env.WORKER) && process.env.WORKER !== 'undefined';
|
|
12
|
-
if (isWorker) {
|
|
13
|
-
/**
|
|
14
|
-
* By default, SSR dedupe logic gets bundled which runs `require('module')`.
|
|
15
|
-
* We don't want this in our workers runtime, because `require` is not supported.
|
|
16
|
-
*/
|
|
17
|
-
rollupOptions.output = {
|
|
18
|
-
format: 'es',
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
if (process.env.NODE_ENV !== 'development' && !process.env.LOCAL_DEV) {
|
|
22
|
-
/**
|
|
23
|
-
* Ofuscate production asset name - To prevent ad blocker logics that blocks
|
|
24
|
-
* certain files due to how it is named.
|
|
25
|
-
*/
|
|
26
|
-
rollupOptions.output = {
|
|
27
|
-
...rollupOptions.output,
|
|
28
|
-
chunkFileNames: 'assets/[hash].js',
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
16
|
return {
|
|
32
17
|
name: 'hydrogen:config',
|
|
33
|
-
config: async (config, env) =>
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
: rollupOptions,
|
|
46
|
-
target: config.build?.ssr
|
|
47
|
-
? isWorker
|
|
48
|
-
? 'es2022' // CFW (Updates weekly to latest V8)
|
|
49
|
-
: 'es2020' // Node (Support for v14.19 used in SB)
|
|
50
|
-
: 'modules', // Browsers (Vite default value)
|
|
51
|
-
},
|
|
52
|
-
ssr: {
|
|
18
|
+
config: async (config, env) => {
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
const isSsrBuild = env.ssrBuild ?? !!config.build?.ssr;
|
|
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.output = {
|
|
26
|
+
format: isWorker || !isSsrBuild ? 'es' : 'cjs',
|
|
27
|
+
inlineDynamicImports: isSsrBuild ? true : undefined,
|
|
28
|
+
};
|
|
29
|
+
if (process.env.NODE_ENV !== 'development' && !process.env.LOCAL_DEV) {
|
|
53
30
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
31
|
+
* Ofuscate production asset name - To prevent ad blocker logics that blocks
|
|
32
|
+
* certain files due to how it is named.
|
|
56
33
|
*/
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
34
|
+
rollupOptions.output = {
|
|
35
|
+
...rollupOptions.output,
|
|
36
|
+
chunkFileNames: 'assets/[hash].js',
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
resolve: {
|
|
41
|
+
alias: {
|
|
42
|
+
// This library is currently included as a compiled vendor lib, not published yet to NPM
|
|
43
|
+
'react-server-dom-vite/client-proxy': require.resolve('@shopify/hydrogen/vendor/react-server-dom-vite/esm/react-server-dom-vite-client-proxy.js'),
|
|
44
|
+
},
|
|
67
45
|
},
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
*/
|
|
82
|
-
'react-helmet-async',
|
|
83
|
-
'react-error-boundary',
|
|
46
|
+
build: {
|
|
47
|
+
minify: config.build?.minify ?? (process.env.LOCAL_DEV ? false : 'esbuild'),
|
|
48
|
+
sourcemap: true,
|
|
49
|
+
rollupOptions: config.build?.rollupOptions
|
|
50
|
+
? Object.assign(rollupOptions, config.build.rollupOptions)
|
|
51
|
+
: rollupOptions,
|
|
52
|
+
target: config.build?.ssr
|
|
53
|
+
? isWorker
|
|
54
|
+
? 'es2022' // CFW (Updates weekly to latest V8)
|
|
55
|
+
: 'es2020' // Node (Support for v14.19 used in SB)
|
|
56
|
+
: 'modules', // Browsers (Vite default value)
|
|
57
|
+
},
|
|
58
|
+
ssr: {
|
|
84
59
|
/**
|
|
85
|
-
* Vite
|
|
86
|
-
*
|
|
87
|
-
* at server start to avoid posterior page reloads and issues (#429 #430).
|
|
60
|
+
* Tell Vite to bundle everything when we're building for Workers.
|
|
61
|
+
* Otherwise, bundle RSC plugin as a workaround to apply the vendor alias above.
|
|
88
62
|
*/
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
'
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
:
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
63
|
+
noExternal: isWorker || [
|
|
64
|
+
/react-server-dom-vite/,
|
|
65
|
+
/@shopify\/hydrogen/,
|
|
66
|
+
],
|
|
67
|
+
target: isWorker ? 'webworker' : 'node',
|
|
68
|
+
},
|
|
69
|
+
// Reload when updating local Hydrogen lib
|
|
70
|
+
server: process.env.LOCAL_DEV && {
|
|
71
|
+
watch: {
|
|
72
|
+
ignored: [
|
|
73
|
+
'!**/node_modules/@shopify/hydrogen/**',
|
|
74
|
+
'!**/node_modules/@shopify/hydrogen-ui/**',
|
|
75
|
+
],
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
optimizeDeps: {
|
|
79
|
+
exclude: [
|
|
80
|
+
'@shopify/hydrogen',
|
|
81
|
+
'@shopify/hydrogen/client',
|
|
82
|
+
'@shopify/hydrogen/entry-client',
|
|
83
|
+
'@shopify/hydrogen-ui',
|
|
84
|
+
],
|
|
85
|
+
include: [
|
|
86
|
+
/**
|
|
87
|
+
* Additionally, the following dependencies have trouble loading the
|
|
88
|
+
* correct version of the dependency (server vs client). This tells Vite to take the
|
|
89
|
+
* server versions and optimize them for ESM.
|
|
90
|
+
*/
|
|
91
|
+
'react-helmet-async',
|
|
92
|
+
'react-error-boundary',
|
|
93
|
+
/**
|
|
94
|
+
* Vite cannot find the following dependencies since they might be
|
|
95
|
+
* required in RSC asynchronously. This tells Vite to optimize them
|
|
96
|
+
* at server start to avoid posterior page reloads and issues (#429 #430).
|
|
97
|
+
*/
|
|
98
|
+
'react',
|
|
99
|
+
'react-dom/client',
|
|
100
|
+
'react-server-dom-vite/client-proxy',
|
|
101
|
+
// https://github.com/vitejs/vite/issues/6215
|
|
102
|
+
'react/jsx-runtime',
|
|
103
|
+
// https://github.com/nfriedly/set-cookie-parser/issues/50
|
|
104
|
+
'set-cookie-parser',
|
|
105
|
+
'undici',
|
|
106
|
+
'@xstate/react/fsm',
|
|
107
|
+
],
|
|
108
|
+
},
|
|
109
|
+
define: {
|
|
110
|
+
__HYDROGEN_DEV__: env.mode !== 'production',
|
|
111
|
+
__HYDROGEN_WORKER__: isWorker,
|
|
112
|
+
__HYDROGEN_TEST__: false,
|
|
113
|
+
__HYDROGEN_CACHE_ID__: pluginOptions.purgeQueryCacheOnBuild
|
|
114
|
+
? `"${crypto_1.default.randomBytes(8).toString('hex').slice(0, 8)}"`
|
|
115
|
+
: '"__QUERY_CACHE_ID__"',
|
|
116
|
+
},
|
|
117
|
+
envPrefix: ['VITE_', 'PUBLIC_'],
|
|
118
|
+
base: process.env.HYDROGEN_ASSET_BASE_URL,
|
|
119
|
+
};
|
|
120
|
+
},
|
|
110
121
|
};
|
|
111
122
|
};
|
|
@@ -12,15 +12,15 @@ const middleware_js_1 = require("../middleware.js");
|
|
|
12
12
|
const in_memory_js_1 = require("../cache/in-memory.js");
|
|
13
13
|
const vite_plugin_hydrogen_virtual_files_js_1 = require("./vite-plugin-hydrogen-virtual-files.js");
|
|
14
14
|
exports.HYDROGEN_DEFAULT_SERVER_ENTRY = process.env.HYDROGEN_SERVER_ENTRY || '/src/App.server';
|
|
15
|
+
/* -- Plugin notes:
|
|
16
|
+
* By adding a middleware to the Vite dev server, we can handle SSR without needing
|
|
17
|
+
* a custom node script. It works by handling any requests for `text/html` documents,
|
|
18
|
+
* loading them in an SSR context, rendering them using the `entry-server` endpoint in the
|
|
19
|
+
* user's project, and injecting the static HTML into the template.
|
|
20
|
+
*/
|
|
15
21
|
exports.default = (pluginOptions) => {
|
|
16
22
|
return {
|
|
17
23
|
name: 'hydrogen:middleware',
|
|
18
|
-
/**
|
|
19
|
-
* By adding a middleware to the Vite dev server, we can handle SSR without needing
|
|
20
|
-
* a custom node script. It works by handling any requests for `text/html` documents,
|
|
21
|
-
* loading them in an SSR context, rendering them using the `entry-server` endpoint in the
|
|
22
|
-
* user's project, and injecting the static HTML into the template.
|
|
23
|
-
*/
|
|
24
24
|
async configureServer(server) {
|
|
25
25
|
const resolve = (p) => path_1.default.resolve(server.config.root, p);
|
|
26
26
|
async function getIndexTemplate(url) {
|
|
@@ -62,13 +62,5 @@ exports.default = (pluginOptions) => {
|
|
|
62
62
|
};
|
|
63
63
|
async function polyfillOxygenEnv(config) {
|
|
64
64
|
const env = await (0, vite_1.loadEnv)(config.mode, config.root, '');
|
|
65
|
-
const publicPrefixes = Array.isArray(config.envPrefix)
|
|
66
|
-
? config.envPrefix
|
|
67
|
-
: [config.envPrefix || ''];
|
|
68
|
-
for (const key of Object.keys(env)) {
|
|
69
|
-
if (publicPrefixes.some((prefix) => key.startsWith(prefix))) {
|
|
70
|
-
delete env[key];
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
65
|
globalThis.Oxygen = { env };
|
|
74
66
|
}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/* -- Plugin notes:
|
|
4
|
+
* Vite prints some warnings automatically are not important and
|
|
5
|
+
* not actionable. We hide them here to prevent confusing devs when
|
|
6
|
+
* real warnings or errors appear.
|
|
7
|
+
*/
|
|
3
8
|
exports.default = () => {
|
|
4
9
|
return {
|
|
5
10
|
name: 'hydrogen:suppress-warnings',
|
|
@@ -9,6 +9,14 @@ const path_1 = __importDefault(require("path"));
|
|
|
9
9
|
const fs_1 = require("fs");
|
|
10
10
|
const viteception_js_1 = require("../viteception.js");
|
|
11
11
|
const magic_string_1 = __importDefault(require("magic-string"));
|
|
12
|
+
const vite_js_1 = require("../../utilities/vite.js");
|
|
13
|
+
/* -- Plugin notes:
|
|
14
|
+
* The Hydrogen framework needs to import certain files from the user app, such as
|
|
15
|
+
* routes and config. A priori, we can't import these files from the framework
|
|
16
|
+
* because we don't know the user path to write it in an `import * from '...'` statement.
|
|
17
|
+
* Instead, we import "virtual files" that are resolved by Vite in this plugin.
|
|
18
|
+
* These virtual files can include the user path and re-export the in-app files.
|
|
19
|
+
*/
|
|
12
20
|
exports.HYDROGEN_DEFAULT_SERVER_ENTRY = process.env.HYDROGEN_SERVER_ENTRY || '/src/App.server';
|
|
13
21
|
// The character ":" breaks Vite with Node >= 16.15. Use "_" instead
|
|
14
22
|
const VIRTUAL_PREFIX = 'virtual__';
|
|
@@ -21,6 +29,7 @@ exports.VIRTUAL_PROXY_HYDROGEN_CONFIG_ID = VIRTUAL_PREFIX + PROXY_PREFIX + HYDRO
|
|
|
21
29
|
const HYDROGEN_ROUTES_ID = 'hydrogen-routes.server.jsx';
|
|
22
30
|
const VIRTUAL_HYDROGEN_ROUTES_ID = VIRTUAL_PREFIX + HYDROGEN_ROUTES_ID;
|
|
23
31
|
exports.VIRTUAL_PROXY_HYDROGEN_ROUTES_ID = VIRTUAL_PREFIX + PROXY_PREFIX + HYDROGEN_ROUTES_ID;
|
|
32
|
+
const VIRTUAL_STREAM_ID = 'virtual__stream';
|
|
24
33
|
exports.default = (pluginOptions) => {
|
|
25
34
|
let config;
|
|
26
35
|
let server;
|
|
@@ -47,6 +56,7 @@ exports.default = (pluginOptions) => {
|
|
|
47
56
|
exports.VIRTUAL_PROXY_HYDROGEN_ROUTES_ID,
|
|
48
57
|
VIRTUAL_HYDROGEN_ROUTES_ID,
|
|
49
58
|
VIRTUAL_ERROR_FILE,
|
|
59
|
+
VIRTUAL_STREAM_ID,
|
|
50
60
|
].includes(source)) {
|
|
51
61
|
// Virtual modules convention
|
|
52
62
|
// https://vitejs.dev/guide/api-plugin.html#virtual-modules-convention
|
|
@@ -54,6 +64,13 @@ exports.default = (pluginOptions) => {
|
|
|
54
64
|
}
|
|
55
65
|
},
|
|
56
66
|
load(id) {
|
|
67
|
+
if (id === '\0' + VIRTUAL_STREAM_ID) {
|
|
68
|
+
return {
|
|
69
|
+
code: process.env.WORKER
|
|
70
|
+
? `export default {};`
|
|
71
|
+
: `export {default} from 'stream';`,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
57
74
|
// Likely due to a bug in Vite, but virtual modules cannot be loaded
|
|
58
75
|
// directly using ssrLoadModule from a Vite plugin. It needs to be proxied as follows:
|
|
59
76
|
if (id === '\0' + exports.VIRTUAL_PROXY_HYDROGEN_CONFIG_ID) {
|
|
@@ -76,7 +93,10 @@ exports.default = (pluginOptions) => {
|
|
|
76
93
|
routesPath += '**/*.server.[jt](s|sx)';
|
|
77
94
|
}
|
|
78
95
|
const [dirPrefix] = routesPath.split('/*');
|
|
79
|
-
|
|
96
|
+
const importGlob = vite_js_1.isVite3
|
|
97
|
+
? `import.meta.glob('${routesPath}', {eager: true})`
|
|
98
|
+
: `import.meta.globEager('${routesPath}')`;
|
|
99
|
+
let code = `export default {\n dirPrefix: '${dirPrefix}',\n basePath: '${hc.routes?.basePath ?? ''}',\n files: ${importGlob}\n};`;
|
|
80
100
|
if (config.command === 'serve') {
|
|
81
101
|
// Add dependency on Hydrogen config for HMR
|
|
82
102
|
code += `\nimport '${VIRTUAL_HYDROGEN_CONFIG_ID}';`;
|
|
@@ -9,10 +9,23 @@ const magic_string_1 = __importDefault(require("magic-string"));
|
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
10
10
|
const fs_1 = __importDefault(require("fs"));
|
|
11
11
|
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
12
|
+
const vite_js_1 = require("../../utilities/vite.js");
|
|
12
13
|
const SSR_BUNDLE_NAME = 'index.js';
|
|
13
14
|
// Keep this in the outer scope to share it
|
|
14
15
|
// across client <> server builds.
|
|
15
16
|
let clientBuildPath;
|
|
17
|
+
/* -- Plugin notes:
|
|
18
|
+
* This plugin simplifies the way a platform entry file imports user files. This is
|
|
19
|
+
* needed to write generic integrations with different platform providers.
|
|
20
|
+
*
|
|
21
|
+
* Instead of using relative paths:
|
|
22
|
+
* `import handleRequest from '../../<arbitrary_path>/src/App.server';`
|
|
23
|
+
* `import indexTemplate from '../../<arbitrary_path>/dist/client/index.html?raw';`
|
|
24
|
+
*
|
|
25
|
+
* It allows importing from a known static path which dynamically resolves the user files:
|
|
26
|
+
* `import {handleRequest, indexTemplate} from '@shopify/hydrogen/platforms';`
|
|
27
|
+
*
|
|
28
|
+
*/
|
|
16
29
|
exports.default = () => {
|
|
17
30
|
let config;
|
|
18
31
|
let isESM;
|
|
@@ -23,7 +36,7 @@ exports.default = () => {
|
|
|
23
36
|
config = _config;
|
|
24
37
|
if (config.build.ssr) {
|
|
25
38
|
const { output = {} } = config.build.rollupOptions || {};
|
|
26
|
-
const { format = '' } = (Array.isArray(output) ? output[0] : output) || {};
|
|
39
|
+
const { format = vite_js_1.isVite3 ? 'es' : '' } = (Array.isArray(output) ? output[0] : output) || {};
|
|
27
40
|
isESM = Boolean(process.env.WORKER) || ['es', 'esm'].includes(format);
|
|
28
41
|
}
|
|
29
42
|
},
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/* -- Plugin notes:
|
|
4
|
+
* This plugin makes sure we don't leak server logic to the browser when importing
|
|
5
|
+
* the `useEnvContext` utility.
|
|
6
|
+
*/
|
|
3
7
|
exports.default = () => {
|
|
4
8
|
return {
|
|
5
|
-
name: '
|
|
9
|
+
name: 'hydrogen:ssr-interop',
|
|
6
10
|
enforce: 'pre',
|
|
7
11
|
transform(code, id, options = {}) {
|
|
8
12
|
if (options.ssr && id.includes('foundation/ssr-interop')) {
|
|
@@ -2,12 +2,18 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.viteception = void 0;
|
|
4
4
|
const vite_1 = require("vite");
|
|
5
|
+
const vite_js_1 = require("../utilities/vite.js");
|
|
5
6
|
async function viteception(paths, options) {
|
|
6
7
|
const isWorker = process.env.WORKER;
|
|
7
8
|
delete process.env.WORKER;
|
|
8
9
|
const server = await (0, vite_1.createServer)({
|
|
9
10
|
clearScreen: false,
|
|
10
|
-
server: {
|
|
11
|
+
server: {
|
|
12
|
+
middlewareMode: vite_js_1.isVite3 ? true : 'ssr',
|
|
13
|
+
hmr: false,
|
|
14
|
+
},
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
appType: 'custom',
|
|
11
17
|
...options,
|
|
12
18
|
});
|
|
13
19
|
if (isWorker) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isVite3: any;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.isVite3 = void 0;
|
|
27
|
+
// `version` is only exported in Vite 3
|
|
28
|
+
const vite = __importStar(require("vite"));
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
exports.isVite3 = vite.version?.startsWith('3.');
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"engines": {
|
|
8
8
|
"node": ">=14"
|
|
9
9
|
},
|
|
10
|
-
"version": "1.
|
|
10
|
+
"version": "1.4.0",
|
|
11
11
|
"description": "Modern custom Shopify storefronts",
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"main": "dist/esnext/index.js",
|
|
@@ -119,7 +119,7 @@
|
|
|
119
119
|
"react": "^18.2.0",
|
|
120
120
|
"react-dom": "^18.2.0",
|
|
121
121
|
"serve-static": "^1.14.1",
|
|
122
|
-
"vite": "^2.9.0"
|
|
122
|
+
"vite": "^2.9.0 || ^3.0.0"
|
|
123
123
|
},
|
|
124
124
|
"peerDependenciesMeta": {
|
|
125
125
|
"body-parser": {
|
|
@@ -134,6 +134,8 @@
|
|
|
134
134
|
},
|
|
135
135
|
"dependencies": {
|
|
136
136
|
"@vitejs/plugin-react": "^1.3.0",
|
|
137
|
+
"@xstate/fsm": "^2.0.0",
|
|
138
|
+
"@xstate/react": "^3.0.0",
|
|
137
139
|
"abort-controller": "^3.0.0",
|
|
138
140
|
"body-parser": "^1.20.0",
|
|
139
141
|
"compression": "^1.7.4",
|
|
@@ -151,7 +153,7 @@
|
|
|
151
153
|
"react-helmet-async": "^1.3.0",
|
|
152
154
|
"serve-static": "^1.15.0",
|
|
153
155
|
"set-cookie-parser": "^2.5.0",
|
|
154
|
-
"undici": "^5.
|
|
156
|
+
"undici": "^5.8.2",
|
|
155
157
|
"uuid": "^8.3.2",
|
|
156
158
|
"vite-plugin-inspect": "^0.3.6",
|
|
157
159
|
"web-streams-polyfill": "^3.2.0",
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
|
|
15
15
|
var esModuleLexer = require('es-module-lexer');
|
|
16
16
|
var MagicString = require('magic-string');
|
|
17
|
-
var vite = require('vite');
|
|
18
17
|
var fs = require('fs');
|
|
19
18
|
var path = require('path');
|
|
19
|
+
var vite = require('vite');
|
|
20
20
|
|
|
21
21
|
function _unsupportedIterableToArray(o, minLen) {
|
|
22
22
|
if (!o) return;
|
|
@@ -94,6 +94,10 @@ function _createForOfIteratorHelper(o, allowArrayLike) {
|
|
|
94
94
|
|
|
95
95
|
var assign = Object.assign;
|
|
96
96
|
|
|
97
|
+
var normalizePath = vite.normalizePath,
|
|
98
|
+
transformWithEsbuild = vite.transformWithEsbuild,
|
|
99
|
+
createServer = vite.createServer;
|
|
100
|
+
var isVite3 = vite.version && vite.version.startsWith('3.');
|
|
97
101
|
var rscViteFileRE = /\/react-server-dom-vite.js/;
|
|
98
102
|
var noProxyRE = /[&?]no-proxy($|&)/;
|
|
99
103
|
|
|
@@ -267,11 +271,11 @@ function ReactFlightVitePlugin() {
|
|
|
267
271
|
var injectGlobs = function (clientComponents) {
|
|
268
272
|
var importerPath = path.dirname(id);
|
|
269
273
|
var importers = clientComponents.map(function (absolutePath) {
|
|
270
|
-
return
|
|
274
|
+
return normalizePath(path.relative(importerPath, absolutePath));
|
|
271
275
|
});
|
|
272
276
|
var injectedGlobs = "Object.assign(Object.create(null), " + importers.map(function (glob) {
|
|
273
277
|
return (// Mark the globs to modify the result after Vite resolves them.
|
|
274
|
-
"\n/* HASH_BEGIN */ " + ("import.meta.glob('" +
|
|
278
|
+
"\n/* HASH_BEGIN */ " + ("import.meta.glob('" + normalizePath(glob) + "') /* HASH_END */")
|
|
275
279
|
);
|
|
276
280
|
}).join(', ') + ");";
|
|
277
281
|
s.replace(INJECTING_RE, injectedGlobs);
|
|
@@ -358,7 +362,7 @@ async function proxyClientComponent(filepath, src) {
|
|
|
358
362
|
src = await fs.promises.readFile(filepath, 'utf-8');
|
|
359
363
|
}
|
|
360
364
|
|
|
361
|
-
var _await$transformWithE = await
|
|
365
|
+
var _await$transformWithE = await transformWithEsbuild(src, filepath),
|
|
362
366
|
code = _await$transformWithE.code;
|
|
363
367
|
|
|
364
368
|
var _parse = esModuleLexer.parse(code),
|
|
@@ -407,12 +411,14 @@ function findClientBoundaries(moduleGraph) {
|
|
|
407
411
|
|
|
408
412
|
async function findClientBoundariesForClientBuild(serverEntries, optimizeBoundaries, root) {
|
|
409
413
|
// Viteception
|
|
410
|
-
var server = await
|
|
414
|
+
var server = await createServer({
|
|
411
415
|
root: root,
|
|
412
416
|
clearScreen: false,
|
|
413
417
|
server: {
|
|
414
|
-
middlewareMode: 'ssr'
|
|
415
|
-
|
|
418
|
+
middlewareMode: isVite3 ? true : 'ssr',
|
|
419
|
+
hmr: false
|
|
420
|
+
},
|
|
421
|
+
appType: 'custom'
|
|
416
422
|
});
|
|
417
423
|
|
|
418
424
|
try {
|
|
@@ -435,9 +441,10 @@ var hashImportsPlugin = {
|
|
|
435
441
|
if (rscViteFileRE.test(id)) {
|
|
436
442
|
var s = new MagicString(code);
|
|
437
443
|
s.replace(/\/\*\s*HASH_BEGIN\s*\*\/\s*([^]+?)\/\*\s*HASH_END\s*\*\//gm, function (_, imports) {
|
|
438
|
-
return imports.trim().replace(/"([^"]+?)":/gm, function (
|
|
444
|
+
return imports.trim().replace(/"([^"]+?)":/gm, function (all, relativePath) {
|
|
445
|
+
if (relativePath === '__VITE_PRELOAD__') return all;
|
|
439
446
|
var absolutePath = path.resolve(path.dirname(id.split('?')[0]), relativePath);
|
|
440
|
-
return "\"" + getComponentId(
|
|
447
|
+
return "\"" + getComponentId(normalizePath(absolutePath)) + "\":";
|
|
441
448
|
});
|
|
442
449
|
});
|
|
443
450
|
return {
|
|
@@ -529,17 +536,20 @@ function isDirectImportInServer(originalMod, currentMod, accModInfo) {
|
|
|
529
536
|
});
|
|
530
537
|
}
|
|
531
538
|
|
|
532
|
-
|
|
533
|
-
|
|
539
|
+
var RESOLVE_EXTENSIONS = ['', '.js', '.ts', '.jsx', '.tsx', '/index', '/index.js', '/index.ts', '/index.jsx', '/index.tsx']; // Resolve relative paths and aliases. Examples:
|
|
540
|
+
// - import {XYZ} from '~/components' => import {XYZ} from '<absolute>/src/components/index.ts'
|
|
541
|
+
// - import {XYZ} from '/src/component.client' => import {XYZ} from '<absolute>/src/component.client.jsx'`
|
|
534
542
|
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
+
function resolveModPath(modPath, dirname) {
|
|
544
|
+
var extensions = /\.[jt]sx?$/.test(modPath) ? [''] : RESOLVE_EXTENSIONS;
|
|
545
|
+
|
|
546
|
+
for (var i = 0; i < extensions.length; i++) {
|
|
547
|
+
var extension = extensions[i];
|
|
548
|
+
|
|
549
|
+
try {
|
|
550
|
+
var absolutePath = modPath.startsWith('.') ? normalizePath(path.resolve(dirname, modPath)) : modPath;
|
|
551
|
+
return normalizePath(require.resolve(absolutePath + extension));
|
|
552
|
+
} catch (error) {// Do not throw, this is likely a virtual module or another exception
|
|
543
553
|
}
|
|
544
554
|
}
|
|
545
555
|
}
|
|
@@ -551,7 +561,7 @@ function augmentModuleGraph(moduleGraph, id, code, root, resolveAlias) {
|
|
|
551
561
|
var _id$split = id.split('?'),
|
|
552
562
|
source = _id$split[0];
|
|
553
563
|
|
|
554
|
-
var dirname =
|
|
564
|
+
var dirname = normalizePath(path.dirname(source));
|
|
555
565
|
|
|
556
566
|
var _parse2 = esModuleLexer.parse(code),
|
|
557
567
|
rawImports = _parse2[0],
|
|
@@ -582,7 +592,7 @@ function augmentModuleGraph(moduleGraph, id, code, root, resolveAlias) {
|
|
|
582
592
|
|
|
583
593
|
if (modPath && modPath.startsWith('/src/')) {
|
|
584
594
|
// Vite default alias
|
|
585
|
-
modPath =
|
|
595
|
+
modPath = normalizePath(path.join(root, modPath));
|
|
586
596
|
}
|
|
587
597
|
|
|
588
598
|
var resolvedPath = resolveModPath(modPath, dirname);
|