@react-router/remix-routes-option-adapter 7.15.1 → 8.0.0-pre.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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # `@react-router/remix-config-routes-adapter`
2
2
 
3
+ ## v7.16.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies:
8
+ - [`@react-router/dev@7.16.0`](https://github.com/remix-run/react-router/releases/tag/@react-router/dev@7.16.0)
9
+
3
10
  ## v7.15.1
4
11
 
5
12
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1,63 +1,71 @@
1
- import { RouteConfigEntry } from '@react-router/dev/routes';
2
1
 
2
+ import { RouteConfigEntry } from "@react-router/dev/routes";
3
+
4
+ //#region manifest.d.ts
3
5
  interface RouteManifestEntry {
4
- path?: string;
5
- index?: boolean;
6
- caseSensitive?: boolean;
7
- id: string;
8
- parentId?: string;
9
- file: string;
6
+ path?: string;
7
+ index?: boolean;
8
+ caseSensitive?: boolean;
9
+ id: string;
10
+ parentId?: string;
11
+ file: string;
10
12
  }
11
13
  interface RouteManifest {
12
- [routeId: string]: RouteManifestEntry;
14
+ [routeId: string]: RouteManifestEntry;
13
15
  }
14
-
16
+ //#endregion
17
+ //#region defineRoutes.d.ts
15
18
  type DefineRoutesFunction = (callback: (defineRoute: DefineRouteFunction) => void) => RouteManifest;
16
19
  interface DefineRouteOptions {
17
- /**
18
- * Should be `true` if the route `path` is case-sensitive. Defaults to
19
- * `false`.
20
- */
21
- caseSensitive?: boolean;
22
- /**
23
- * Should be `true` if this is an index route that does not allow child routes.
24
- */
25
- index?: boolean;
26
- /**
27
- * An optional unique id string for this route. Use this if you need to aggregate
28
- * two or more routes with the same route file.
29
- */
30
- id?: string;
20
+ /**
21
+ * Should be `true` if the route `path` is case-sensitive. Defaults to
22
+ * `false`.
23
+ */
24
+ caseSensitive?: boolean;
25
+ /**
26
+ * Should be `true` if this is an index route that does not allow child routes.
27
+ */
28
+ index?: boolean;
29
+ /**
30
+ * An optional unique id string for this route. Use this if you need to aggregate
31
+ * two or more routes with the same route file.
32
+ */
33
+ id?: string;
31
34
  }
32
35
  interface DefineRouteChildren {
33
- (): void;
36
+ (): void;
34
37
  }
35
38
  interface DefineRouteFunction {
36
- (
37
- /**
38
- * The path this route uses to match the URL pathname.
39
- */
40
- path: string | undefined,
41
- /**
42
- * The path to the file that exports the React component rendered by this
43
- * route as its default export, relative to the `app` directory.
44
- */
45
- file: string,
46
- /**
47
- * Options for defining routes, or a function for defining child routes.
48
- */
49
- optionsOrChildren?: DefineRouteOptions | DefineRouteChildren,
50
- /**
51
- * A function for defining child routes.
52
- */
53
- children?: DefineRouteChildren): void;
54
- }
39
+ (
40
+ /**
41
+ * The path this route uses to match the URL pathname.
42
+ */
43
+
44
+ path: string | undefined,
45
+ /**
46
+ * The path to the file that exports the React component rendered by this
47
+ * route as its default export, relative to the `app` directory.
48
+ */
55
49
 
50
+ file: string,
51
+ /**
52
+ * Options for defining routes, or a function for defining child routes.
53
+ */
54
+
55
+ optionsOrChildren?: DefineRouteOptions | DefineRouteChildren,
56
+ /**
57
+ * A function for defining child routes.
58
+ */
59
+
60
+ children?: DefineRouteChildren): void;
61
+ }
62
+ //#endregion
63
+ //#region index.d.ts
56
64
  /**
57
65
  * Adapts routes defined using [Remix's `routes` config
58
66
  * option](https://v2.remix.run/docs/file-conventions/vite-config#routes) to
59
67
  * React Router's config format, for use within `routes.ts`.
60
68
  */
61
69
  declare function remixRoutesOptionAdapter(routes: (defineRoutes: DefineRoutesFunction) => ReturnType<DefineRoutesFunction> | Promise<ReturnType<DefineRoutesFunction>>): Promise<RouteConfigEntry[]>;
62
-
63
- export { type DefineRouteFunction, type DefineRoutesFunction, remixRoutesOptionAdapter };
70
+ //#endregion
71
+ export { type DefineRouteFunction, type DefineRoutesFunction, remixRoutesOptionAdapter };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/remix-routes-option-adapter v7.15.1
2
+ * @react-router/remix-routes-option-adapter v8.0.0-pre.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -8,133 +8,93 @@
8
8
  *
9
9
  * @license MIT
10
10
  */
11
- "use strict";
12
- var __create = Object.create;
13
- var __defProp = Object.defineProperty;
14
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
15
- var __getOwnPropNames = Object.getOwnPropertyNames;
16
- var __getProtoOf = Object.getPrototypeOf;
17
- var __hasOwnProp = Object.prototype.hasOwnProperty;
18
- var __export = (target, all) => {
19
- for (var name in all)
20
- __defProp(target, name, { get: all[name], enumerable: true });
21
- };
22
- var __copyProps = (to, from, except, desc) => {
23
- if (from && typeof from === "object" || typeof from === "function") {
24
- for (let key of __getOwnPropNames(from))
25
- if (!__hasOwnProp.call(to, key) && key !== except)
26
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
27
- }
28
- return to;
29
- };
30
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
31
- // If the importer is in node compatibility mode or this is not an ESM
32
- // file that has been converted to a CommonJS file using a Babel-
33
- // compatible transform (i.e. "__esModule" has not been set), then set
34
- // "default" to the CommonJS "module.exports" for node compatibility.
35
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
36
- mod
37
- ));
38
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
39
-
40
- // index.ts
41
- var index_exports = {};
42
- __export(index_exports, {
43
- remixRoutesOptionAdapter: () => remixRoutesOptionAdapter
44
- });
45
- module.exports = __toCommonJS(index_exports);
46
-
47
- // manifest.ts
11
+ import "@react-router/dev/routes";
12
+ import path from "node:path";
13
+ //#region manifest.ts
48
14
  function routeManifestToRouteConfig(routeManifest, rootId = "root") {
49
- let routeConfigById = {};
50
- for (let id in routeManifest) {
51
- let route = routeManifest[id];
52
- routeConfigById[id] = {
53
- id: route.id,
54
- file: route.file,
55
- path: route.path,
56
- index: route.index,
57
- caseSensitive: route.caseSensitive
58
- };
59
- }
60
- let routeConfig = [];
61
- for (let id in routeConfigById) {
62
- let route = routeConfigById[id];
63
- let parentId = routeManifest[route.id].parentId;
64
- if (parentId === rootId) {
65
- routeConfig.push(route);
66
- } else {
67
- let parentRoute = parentId && routeConfigById[parentId];
68
- if (parentRoute) {
69
- parentRoute.children = parentRoute.children || [];
70
- parentRoute.children.push(route);
71
- }
72
- }
73
- }
74
- return routeConfig;
15
+ let routeConfigById = {};
16
+ for (let id in routeManifest) {
17
+ let route = routeManifest[id];
18
+ routeConfigById[id] = {
19
+ id: route.id,
20
+ file: route.file,
21
+ path: route.path,
22
+ index: route.index,
23
+ caseSensitive: route.caseSensitive
24
+ };
25
+ }
26
+ let routeConfig = [];
27
+ for (let id in routeConfigById) {
28
+ let route = routeConfigById[id];
29
+ let parentId = routeManifest[route.id].parentId;
30
+ if (parentId === rootId) routeConfig.push(route);
31
+ else {
32
+ let parentRoute = parentId && routeConfigById[parentId];
33
+ if (parentRoute) {
34
+ parentRoute.children = parentRoute.children || [];
35
+ parentRoute.children.push(route);
36
+ }
37
+ }
38
+ }
39
+ return routeConfig;
75
40
  }
76
-
77
- // normalizeSlashes.ts
78
- var import_node_path = __toESM(require("path"));
41
+ //#endregion
42
+ //#region normalizeSlashes.ts
79
43
  function normalizeSlashes(file) {
80
- return file.replaceAll(import_node_path.default.win32.sep, "/");
44
+ return file.replaceAll(path.win32.sep, "/");
81
45
  }
82
-
83
- // defineRoutes.ts
84
- var defineRoutes = (callback) => {
85
- let routes = /* @__PURE__ */ Object.create(null);
86
- let parentRoutes = [];
87
- let alreadyReturned = false;
88
- let defineRoute = (path2, file, optionsOrChildren, children) => {
89
- if (alreadyReturned) {
90
- throw new Error(
91
- "You tried to define routes asynchronously but started defining routes before the async work was done. Please await all async data before calling `defineRoutes()`"
92
- );
93
- }
94
- let options;
95
- if (typeof optionsOrChildren === "function") {
96
- options = {};
97
- children = optionsOrChildren;
98
- } else {
99
- options = optionsOrChildren || {};
100
- }
101
- let route = {
102
- path: path2 ? path2 : void 0,
103
- index: options.index ? true : void 0,
104
- caseSensitive: options.caseSensitive ? true : void 0,
105
- id: options.id || createRouteId(file),
106
- parentId: parentRoutes.length > 0 ? parentRoutes[parentRoutes.length - 1].id : "root",
107
- file
108
- };
109
- if (route.id in routes) {
110
- throw new Error(
111
- `Unable to define routes with duplicate route id: "${route.id}"`
112
- );
113
- }
114
- routes[route.id] = route;
115
- if (children) {
116
- parentRoutes.push(route);
117
- children();
118
- parentRoutes.pop();
119
- }
120
- };
121
- callback(defineRoute);
122
- alreadyReturned = true;
123
- return routes;
46
+ //#endregion
47
+ //#region defineRoutes.ts
48
+ /**
49
+ * A function for defining routes programmatically, instead of using the
50
+ * filesystem convention.
51
+ */
52
+ const defineRoutes = (callback) => {
53
+ let routes = Object.create(null);
54
+ let parentRoutes = [];
55
+ let alreadyReturned = false;
56
+ let defineRoute = (path, file, optionsOrChildren, children) => {
57
+ if (alreadyReturned) throw new Error("You tried to define routes asynchronously but started defining routes before the async work was done. Please await all async data before calling `defineRoutes()`");
58
+ let options;
59
+ if (typeof optionsOrChildren === "function") {
60
+ options = {};
61
+ children = optionsOrChildren;
62
+ } else options = optionsOrChildren || {};
63
+ let route = {
64
+ path: path ? path : void 0,
65
+ index: options.index ? true : void 0,
66
+ caseSensitive: options.caseSensitive ? true : void 0,
67
+ id: options.id || createRouteId(file),
68
+ parentId: parentRoutes.length > 0 ? parentRoutes[parentRoutes.length - 1].id : "root",
69
+ file
70
+ };
71
+ if (route.id in routes) throw new Error(`Unable to define routes with duplicate route id: "${route.id}"`);
72
+ routes[route.id] = route;
73
+ if (children) {
74
+ parentRoutes.push(route);
75
+ children();
76
+ parentRoutes.pop();
77
+ }
78
+ };
79
+ callback(defineRoute);
80
+ alreadyReturned = true;
81
+ return routes;
124
82
  };
125
83
  function createRouteId(file) {
126
- return normalizeSlashes(stripFileExtension(file));
84
+ return normalizeSlashes(stripFileExtension(file));
127
85
  }
128
86
  function stripFileExtension(file) {
129
- return file.replace(/\.[a-z0-9]+$/i, "");
87
+ return file.replace(/\.[a-z0-9]+$/i, "");
130
88
  }
131
-
132
- // index.ts
89
+ //#endregion
90
+ //#region index.ts
91
+ /**
92
+ * Adapts routes defined using [Remix's `routes` config
93
+ * option](https://v2.remix.run/docs/file-conventions/vite-config#routes) to
94
+ * React Router's config format, for use within `routes.ts`.
95
+ */
133
96
  async function remixRoutesOptionAdapter(routes) {
134
- let routeManifest = await routes(defineRoutes);
135
- return routeManifestToRouteConfig(routeManifest);
97
+ return routeManifestToRouteConfig(await routes(defineRoutes));
136
98
  }
137
- // Annotate the CommonJS export names for ESM import in node:
138
- 0 && (module.exports = {
139
- remixRoutesOptionAdapter
140
- });
99
+ //#endregion
100
+ export { remixRoutesOptionAdapter };
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@react-router/remix-routes-option-adapter",
3
- "version": "7.15.1",
3
+ "type": "module",
4
+ "version": "8.0.0-pre.0",
4
5
  "description": "Adapter for Remix's \"routes\" config option, for use within routes.ts",
5
6
  "bugs": {
6
7
  "url": "https://github.com/remix-run/react-router/issues"
@@ -22,7 +23,7 @@
22
23
  },
23
24
  "wireit": {
24
25
  "build": {
25
- "command": "tsup",
26
+ "command": "tsdown",
26
27
  "files": [
27
28
  "../../pnpm-workspace.yaml",
28
29
  "*.ts",
@@ -35,14 +36,15 @@
35
36
  }
36
37
  },
37
38
  "devDependencies": {
38
- "tsup": "^8.3.0",
39
- "typescript": "^5.4.5",
40
- "wireit": "0.14.9",
41
- "@react-router/dev": "7.15.1"
39
+ "@types/node": "^22.19.19",
40
+ "tsdown": "^0.22.0",
41
+ "typescript": "^6.0.3",
42
+ "wireit": "0.14.12",
43
+ "@react-router/dev": "8.0.0-pre.0"
42
44
  },
43
45
  "peerDependencies": {
44
46
  "typescript": "^5.1.0 || ^6.0.0",
45
- "@react-router/dev": "^7.15.1"
47
+ "@react-router/dev": "^8.0.0-pre.0"
46
48
  },
47
49
  "peerDependenciesMeta": {
48
50
  "typescript": {
@@ -50,7 +52,7 @@
50
52
  }
51
53
  },
52
54
  "engines": {
53
- "node": ">=20.0.0"
55
+ "node": ">=22.12.0"
54
56
  },
55
57
  "files": [
56
58
  "dist/",