@shopify/cli-hydrogen 4.1.0 → 4.1.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.
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { RemixConfig } from '@remix-run/dev/dist/config.js';
|
|
2
2
|
|
|
3
|
-
declare function findMissingRoutes(config:
|
|
3
|
+
declare function findMissingRoutes(config: {
|
|
4
|
+
routes: RemixConfig['routes'];
|
|
5
|
+
}, requiredRoutes?: string[]): string[];
|
|
4
6
|
declare function logMissingRoutes(routes: string[]): void;
|
|
5
7
|
|
|
6
8
|
export { findMissingRoutes, logMissingRoutes };
|
|
@@ -20,13 +20,13 @@ const REQUIRED_ROUTES = [
|
|
|
20
20
|
"account/reset/:id/:token",
|
|
21
21
|
"account/activate/:id/:token"
|
|
22
22
|
];
|
|
23
|
-
function findMissingRoutes(config) {
|
|
23
|
+
function findMissingRoutes(config, requiredRoutes = REQUIRED_ROUTES) {
|
|
24
24
|
const userRoutes = Object.values(config.routes);
|
|
25
|
-
const
|
|
25
|
+
const missingRoutes = new Set(requiredRoutes);
|
|
26
26
|
for (const requiredRoute of requiredRoutes) {
|
|
27
27
|
for (const userRoute of userRoutes) {
|
|
28
28
|
if (!requiredRoute && !userRoute.path) {
|
|
29
|
-
|
|
29
|
+
missingRoutes.delete(requiredRoute);
|
|
30
30
|
} else if (requiredRoute && userRoute.path) {
|
|
31
31
|
const currentRoute = {
|
|
32
32
|
path: userRoute.path,
|
|
@@ -41,14 +41,15 @@ function findMissingRoutes(config) {
|
|
|
41
41
|
currentRoute.path = `${parentRoute.path}/${currentRoute.path}`;
|
|
42
42
|
currentRoute.parentId = parentRoute.parentId;
|
|
43
43
|
}
|
|
44
|
-
const
|
|
44
|
+
const optionalSegment = ":?[^\\/\\?]+\\?";
|
|
45
|
+
const reString = `^(${optionalSegment}\\/)?` + requiredRoute.replaceAll(".", "\\.").replace(/\//g, `\\/(${optionalSegment}\\/)?`).replace(/:[^/)?]+/g, ":[^\\/]+") + `(\\/${optionalSegment})?$`;
|
|
45
46
|
if (new RegExp(reString).test(currentRoute.path)) {
|
|
46
|
-
|
|
47
|
+
missingRoutes.delete(requiredRoute);
|
|
47
48
|
}
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
51
|
}
|
|
51
|
-
return [...
|
|
52
|
+
return [...missingRoutes];
|
|
52
53
|
}
|
|
53
54
|
const LINE_LIMIT = 100;
|
|
54
55
|
function logMissingRoutes(routes) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { findMissingRoutes } from './missing-routes.js';
|
|
3
|
+
|
|
4
|
+
const createRoute = (path) => ({
|
|
5
|
+
routes: {
|
|
6
|
+
"route-id": {
|
|
7
|
+
file: "a/file",
|
|
8
|
+
id: "route-id",
|
|
9
|
+
path
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
describe("missing-routes", () => {
|
|
14
|
+
it("matches routes with dots", async () => {
|
|
15
|
+
const requiredRoutes = ["sitemap.xml"];
|
|
16
|
+
expect(findMissingRoutes({ routes: {} }, requiredRoutes)).toHaveLength(1);
|
|
17
|
+
expect(
|
|
18
|
+
findMissingRoutes(createRoute("sitemap.xml"), requiredRoutes)
|
|
19
|
+
).toHaveLength(0);
|
|
20
|
+
});
|
|
21
|
+
it("matches routes with different parameter names", async () => {
|
|
22
|
+
const requiredRoutes = ["collections/:collectionHandle"];
|
|
23
|
+
expect(findMissingRoutes({ routes: {} }, requiredRoutes)).toHaveLength(1);
|
|
24
|
+
expect(
|
|
25
|
+
findMissingRoutes(createRoute("collections/:param"), requiredRoutes)
|
|
26
|
+
).toHaveLength(0);
|
|
27
|
+
});
|
|
28
|
+
it("matches optional segments in different positions", async () => {
|
|
29
|
+
const requiredRoutes = ["collections/products"];
|
|
30
|
+
const validRoutes = [
|
|
31
|
+
"segment?/collections/products",
|
|
32
|
+
":segment?/collections/products",
|
|
33
|
+
"collections/segment?/products",
|
|
34
|
+
"collections/:segment?/products",
|
|
35
|
+
"collections/products/segment?",
|
|
36
|
+
"collections/products/:segment?"
|
|
37
|
+
];
|
|
38
|
+
expect(findMissingRoutes({ routes: {} }, requiredRoutes)).toHaveLength(1);
|
|
39
|
+
for (const validRoute of validRoutes) {
|
|
40
|
+
expect(
|
|
41
|
+
findMissingRoutes(createRoute(validRoute), requiredRoutes)
|
|
42
|
+
).toHaveLength(0);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
});
|
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"4.1.
|
|
1
|
+
{"version":"4.1.1","commands":{"hydrogen:build":{"id":"hydrogen:build","description":"Builds a Hydrogen storefront for production.","strict":true,"pluginName":"@shopify/cli-hydrogen","pluginAlias":"@shopify/cli-hydrogen","pluginType":"core","aliases":[],"flags":{"path":{"name":"path","type":"option","description":"The path to the directory of the Hydrogen storefront. The default is the current directory.","multiple":false},"sourcemap":{"name":"sourcemap","type":"boolean","description":"Generate sourcemaps for the build.","allowNo":false},"disable-route-warning":{"name":"disable-route-warning","type":"boolean","description":"Disable warning about missing standard routes.","allowNo":false},"base":{"name":"base","type":"option","hidden":true,"multiple":false},"entry":{"name":"entry","type":"option","hidden":true,"multiple":false},"target":{"name":"target","type":"option","hidden":true,"multiple":false}},"args":[]},"hydrogen:check":{"id":"hydrogen:check","description":"Returns diagnostic information about a Hydrogen storefront.","strict":true,"pluginName":"@shopify/cli-hydrogen","pluginAlias":"@shopify/cli-hydrogen","pluginType":"core","aliases":[],"flags":{"path":{"name":"path","type":"option","description":"The path to the directory of the Hydrogen storefront. The default is the current directory.","multiple":false}},"args":[{"name":"resource","description":"The resource to check. Currently only 'routes' is supported.","required":true,"options":["routes"]}]},"hydrogen:dev":{"id":"hydrogen:dev","description":"Runs Hydrogen storefront in an Oxygen worker for development.","strict":true,"pluginName":"@shopify/cli-hydrogen","pluginAlias":"@shopify/cli-hydrogen","pluginType":"core","aliases":[],"flags":{"path":{"name":"path","type":"option","description":"The path to the directory of the Hydrogen storefront. The default is the current directory.","multiple":false},"port":{"name":"port","type":"option","description":"Port to run the server on.","multiple":false,"default":3000},"disable-virtual-routes":{"name":"disable-virtual-routes","type":"boolean","description":"Disable rendering fallback routes when a route file doesn't exist","allowNo":false},"host":{"name":"host","type":"option","hidden":true,"multiple":false}},"args":[]},"hydrogen:g":{"id":"hydrogen:g","description":"Shortcut for `hydrogen generate`. See `hydrogen generate --help` for more information.","strict":false,"pluginName":"@shopify/cli-hydrogen","pluginAlias":"@shopify/cli-hydrogen","pluginType":"core","hidden":true,"aliases":[],"flags":{},"args":[]},"hydrogen:init":{"id":"hydrogen:init","description":"Creates a new Hydrogen storefront.","strict":true,"pluginName":"@shopify/cli-hydrogen","pluginAlias":"@shopify/cli-hydrogen","pluginType":"core","aliases":[],"flags":{"force":{"name":"force","type":"boolean","char":"f","description":"Overwrite the destination directory and files if they already exist.","allowNo":false},"path":{"name":"path","type":"option","description":"The path to the directory of the new Hydrogen storefront.","multiple":false},"language":{"name":"language","type":"option","description":"Sets the template language to use. One of `js` or `ts`.","multiple":false},"template":{"name":"template","type":"option","description":"Sets the template to use. One of `demo-store` or `hello-world`.","multiple":false},"install-deps":{"name":"install-deps","type":"boolean","description":"Auto install dependencies using the active package manager","allowNo":true}},"args":[]},"hydrogen:preview":{"id":"hydrogen:preview","description":"Runs a Hydrogen storefront in an Oxygen worker for production.","strict":true,"pluginName":"@shopify/cli-hydrogen","pluginAlias":"@shopify/cli-hydrogen","pluginType":"core","aliases":[],"flags":{"path":{"name":"path","type":"option","description":"The path to the directory of the Hydrogen storefront. The default is the current directory.","multiple":false},"port":{"name":"port","type":"option","description":"Port to run the server on.","multiple":false,"default":3000}},"args":[]},"hydrogen:shortcut":{"id":"hydrogen:shortcut","description":"Creates a global `h2` shortcut for the Hydrogen CLI","strict":true,"pluginName":"@shopify/cli-hydrogen","pluginAlias":"@shopify/cli-hydrogen","pluginType":"core","aliases":[],"flags":{},"args":[]},"hydrogen:generate:route":{"id":"hydrogen:generate:route","description":"Generates a standard Shopify route.","strict":true,"pluginName":"@shopify/cli-hydrogen","pluginAlias":"@shopify/cli-hydrogen","pluginType":"core","aliases":[],"flags":{"adapter":{"name":"adapter","type":"option","description":"Remix adapter used in the route. The default is `@shopify/remix-oxygen`.","multiple":false},"typescript":{"name":"typescript","type":"boolean","description":"Generate TypeScript files","allowNo":false},"force":{"name":"force","type":"boolean","char":"f","description":"Overwrite the destination directory and files if they already exist.","allowNo":false},"path":{"name":"path","type":"option","description":"The path to the directory of the Hydrogen storefront. The default is the current directory.","multiple":false}},"args":[{"name":"route","description":"The route to generate. One of home,page,cart,products,collections,policies,robots,sitemap,account,all.","required":true,"options":["home","page","cart","products","collections","policies","robots","sitemap","account","all"]}]},"hydrogen:generate:routes":{"id":"hydrogen:generate:routes","description":"Generates all supported standard shopify routes.","strict":true,"pluginName":"@shopify/cli-hydrogen","pluginAlias":"@shopify/cli-hydrogen","pluginType":"core","aliases":[],"flags":{"adapter":{"name":"adapter","type":"option","description":"Remix adapter used in the route. The default is `@shopify/remix-oxygen`.","multiple":false},"typescript":{"name":"typescript","type":"boolean","description":"Generate TypeScript files","allowNo":false},"force":{"name":"force","type":"boolean","char":"f","description":"Overwrite the destination directory and files if they already exist.","allowNo":false},"path":{"name":"path","type":"option","description":"The path to the directory of the Hydrogen storefront. The default is the current directory.","multiple":false}},"args":[]}}}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public",
|
|
5
5
|
"@shopify:registry": "https://registry.npmjs.org"
|
|
6
6
|
},
|
|
7
|
-
"version": "4.1.
|
|
7
|
+
"version": "4.1.1",
|
|
8
8
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
9
9
|
"type": "module",
|
|
10
10
|
"scripts": {
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"@remix-run/react": "^1.15.0",
|
|
30
|
-
"@shopify/hydrogen-react": "^2023.
|
|
30
|
+
"@shopify/hydrogen-react": "^2023.4.0",
|
|
31
31
|
"@shopify/remix-oxygen": "^1.0.5"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|