one 1.2.16 → 1.2.18
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/cjs/cli/generateRoutes.cjs +20 -5
- package/dist/cjs/cli/generateRoutes.js +18 -3
- package/dist/cjs/cli/generateRoutes.js.map +1 -1
- package/dist/cjs/cli/generateRoutes.native.js +30 -5
- package/dist/cjs/cli/generateRoutes.native.js.map +1 -1
- package/dist/cjs/cli.cjs +4 -0
- package/dist/cjs/cli.js +4 -0
- package/dist/cjs/cli.js.map +1 -1
- package/dist/cjs/cli.native.js +4 -0
- package/dist/cjs/cli.native.js.map +1 -1
- package/dist/cjs/getDevServer.cjs +29 -0
- package/dist/cjs/getDevServer.js +24 -0
- package/dist/cjs/getDevServer.js.map +6 -0
- package/dist/cjs/getDevServer.native.js +40 -0
- package/dist/cjs/getDevServer.native.js.map +1 -0
- package/dist/cjs/getURL.native.js +8 -18
- package/dist/cjs/getURL.native.js.map +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/router/createRoute.cjs +12 -1
- package/dist/cjs/router/createRoute.js +12 -1
- package/dist/cjs/router/createRoute.js.map +1 -1
- package/dist/cjs/router/createRoute.native.js +13 -2
- package/dist/cjs/router/createRoute.native.js.map +1 -1
- package/dist/cjs/typed-routes/generateRouteTypes.cjs +14 -3
- package/dist/cjs/typed-routes/generateRouteTypes.js +12 -3
- package/dist/cjs/typed-routes/generateRouteTypes.js.map +1 -1
- package/dist/cjs/typed-routes/generateRouteTypes.native.js +29 -3
- package/dist/cjs/typed-routes/generateRouteTypes.native.js.map +1 -1
- package/dist/cjs/typed-routes/getTypedRoutesDeclarationFile.cjs +39 -2
- package/dist/cjs/typed-routes/getTypedRoutesDeclarationFile.js +38 -2
- package/dist/cjs/typed-routes/getTypedRoutesDeclarationFile.js.map +1 -1
- package/dist/cjs/typed-routes/getTypedRoutesDeclarationFile.native.js +40 -2
- package/dist/cjs/typed-routes/getTypedRoutesDeclarationFile.native.js.map +1 -1
- package/dist/cjs/typed-routes/injectRouteHelpers.cjs +136 -0
- package/dist/cjs/typed-routes/injectRouteHelpers.js +104 -0
- package/dist/cjs/typed-routes/injectRouteHelpers.js.map +6 -0
- package/dist/cjs/typed-routes/injectRouteHelpers.native.js +146 -0
- package/dist/cjs/typed-routes/injectRouteHelpers.native.js.map +1 -0
- package/dist/cjs/vite/loadConfig.cjs +18 -12
- package/dist/cjs/vite/loadConfig.js +20 -13
- package/dist/cjs/vite/loadConfig.js.map +1 -1
- package/dist/cjs/vite/loadConfig.native.js +18 -11
- package/dist/cjs/vite/loadConfig.native.js.map +1 -1
- package/dist/cjs/vite/plugins/generateFileSystemRouteTypesPlugin.cjs +3 -2
- package/dist/cjs/vite/plugins/generateFileSystemRouteTypesPlugin.js +13 -3
- package/dist/cjs/vite/plugins/generateFileSystemRouteTypesPlugin.js.map +1 -1
- package/dist/cjs/vite/plugins/generateFileSystemRouteTypesPlugin.native.js +9 -6
- package/dist/cjs/vite/plugins/generateFileSystemRouteTypesPlugin.native.js.map +1 -1
- package/dist/esm/cli/generateRoutes.js +19 -2
- package/dist/esm/cli/generateRoutes.js.map +1 -1
- package/dist/esm/cli/generateRoutes.mjs +19 -4
- package/dist/esm/cli/generateRoutes.mjs.map +1 -1
- package/dist/esm/cli/generateRoutes.native.js +29 -4
- package/dist/esm/cli/generateRoutes.native.js.map +1 -1
- package/dist/esm/cli.js +4 -0
- package/dist/esm/cli.js.map +1 -1
- package/dist/esm/cli.mjs +4 -0
- package/dist/esm/cli.mjs.map +1 -1
- package/dist/esm/cli.native.js +4 -0
- package/dist/esm/cli.native.js.map +1 -1
- package/dist/esm/getDevServer.js +8 -0
- package/dist/esm/getDevServer.js.map +6 -0
- package/dist/esm/getDevServer.mjs +6 -0
- package/dist/esm/getDevServer.mjs.map +1 -0
- package/dist/esm/getDevServer.native.js +3 -0
- package/dist/esm/getDevServer.native.js.map +1 -0
- package/dist/esm/getURL.native.js +3 -2
- package/dist/esm/getURL.native.js.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/index.native.js.map +1 -1
- package/dist/esm/router/createRoute.js +12 -1
- package/dist/esm/router/createRoute.js.map +1 -1
- package/dist/esm/router/createRoute.mjs +12 -1
- package/dist/esm/router/createRoute.mjs.map +1 -1
- package/dist/esm/router/createRoute.native.js +13 -2
- package/dist/esm/router/createRoute.native.js.map +1 -1
- package/dist/esm/typed-routes/generateRouteTypes.js +14 -3
- package/dist/esm/typed-routes/generateRouteTypes.js.map +1 -1
- package/dist/esm/typed-routes/generateRouteTypes.mjs +14 -3
- package/dist/esm/typed-routes/generateRouteTypes.mjs.map +1 -1
- package/dist/esm/typed-routes/generateRouteTypes.native.js +29 -3
- package/dist/esm/typed-routes/generateRouteTypes.native.js.map +1 -1
- package/dist/esm/typed-routes/getTypedRoutesDeclarationFile.js +38 -2
- package/dist/esm/typed-routes/getTypedRoutesDeclarationFile.js.map +1 -1
- package/dist/esm/typed-routes/getTypedRoutesDeclarationFile.mjs +39 -2
- package/dist/esm/typed-routes/getTypedRoutesDeclarationFile.mjs.map +1 -1
- package/dist/esm/typed-routes/getTypedRoutesDeclarationFile.native.js +40 -2
- package/dist/esm/typed-routes/getTypedRoutesDeclarationFile.native.js.map +1 -1
- package/dist/esm/typed-routes/injectRouteHelpers.js +89 -0
- package/dist/esm/typed-routes/injectRouteHelpers.js.map +6 -0
- package/dist/esm/typed-routes/injectRouteHelpers.mjs +113 -0
- package/dist/esm/typed-routes/injectRouteHelpers.mjs.map +1 -0
- package/dist/esm/typed-routes/injectRouteHelpers.native.js +120 -0
- package/dist/esm/typed-routes/injectRouteHelpers.native.js.map +1 -0
- package/dist/esm/vite/loadConfig.js +20 -13
- package/dist/esm/vite/loadConfig.js.map +1 -1
- package/dist/esm/vite/loadConfig.mjs +18 -12
- package/dist/esm/vite/loadConfig.mjs.map +1 -1
- package/dist/esm/vite/loadConfig.native.js +18 -11
- package/dist/esm/vite/loadConfig.native.js.map +1 -1
- package/dist/esm/vite/plugins/generateFileSystemRouteTypesPlugin.js +13 -3
- package/dist/esm/vite/plugins/generateFileSystemRouteTypesPlugin.js.map +1 -1
- package/dist/esm/vite/plugins/generateFileSystemRouteTypesPlugin.mjs +3 -2
- package/dist/esm/vite/plugins/generateFileSystemRouteTypesPlugin.mjs.map +1 -1
- package/dist/esm/vite/plugins/generateFileSystemRouteTypesPlugin.native.js +9 -6
- package/dist/esm/vite/plugins/generateFileSystemRouteTypesPlugin.native.js.map +1 -1
- package/package.json +10 -10
- package/src/cli/generateRoutes.ts +52 -4
- package/src/cli.ts +5 -0
- package/src/getDevServer.native.ts +5 -0
- package/src/getDevServer.ts +5 -0
- package/src/getURL.native.ts +10 -5
- package/src/index.ts +13 -0
- package/src/interfaces/router.ts +19 -0
- package/src/router/createRoute.ts +16 -3
- package/src/typed-routes/generateRouteTypes.ts +46 -2
- package/src/typed-routes/getTypedRoutesDeclarationFile.ts +70 -0
- package/src/typed-routes/injectRouteHelpers.ts +186 -0
- package/src/vite/loadConfig.ts +29 -17
- package/src/vite/plugins/generateFileSystemRouteTypesPlugin.tsx +14 -3
- package/src/vite/types.ts +26 -0
- package/types/cli/generateRoutes.d.ts +1 -0
- package/types/cli/generateRoutes.d.ts.map +1 -1
- package/types/getDevServer.d.ts +5 -0
- package/types/getDevServer.d.ts.map +1 -0
- package/types/getDevServer.native.d.ts +2 -0
- package/types/getDevServer.native.d.ts.map +1 -0
- package/types/getURL.native.d.ts.map +1 -1
- package/types/index.d.ts +13 -3
- package/types/index.d.ts.map +1 -1
- package/types/interfaces/router.d.ts +16 -0
- package/types/interfaces/router.d.ts.map +1 -1
- package/types/router/createRoute.d.ts +28 -13
- package/types/router/createRoute.d.ts.map +1 -1
- package/types/typed-routes/generateRouteTypes.d.ts +1 -1
- package/types/typed-routes/generateRouteTypes.d.ts.map +1 -1
- package/types/typed-routes/getTypedRoutesDeclarationFile.d.ts.map +1 -1
- package/types/typed-routes/injectRouteHelpers.d.ts +12 -0
- package/types/typed-routes/injectRouteHelpers.d.ts.map +1 -0
- package/types/utils/redirect.d.ts +1 -3
- package/types/utils/redirect.d.ts.map +1 -1
- package/types/vite/loadConfig.d.ts +1 -1
- package/types/vite/loadConfig.d.ts.map +1 -1
- package/types/vite/plugins/generateFileSystemRouteTypesPlugin.d.ts.map +1 -1
- package/types/vite/types.d.ts +25 -0
- package/types/vite/types.d.ts.map +1 -1
|
@@ -11,11 +11,12 @@ function generateFileSystemRouteTypesPlugin(options) {
|
|
|
11
11
|
const appDir = join(process.cwd(), getRouterRootFromOneOptions(options)),
|
|
12
12
|
outFile = join(appDir, "routes.d.ts"),
|
|
13
13
|
routerRoot = getRouterRootFromOneOptions(options),
|
|
14
|
+
typedRoutesGeneration = options.router?.experimental?.typedRoutesGeneration || void 0,
|
|
14
15
|
fileWatcherChangeListener = debounce(async (type, path) => {
|
|
15
|
-
(type === "add" || type === "delete") && path.startsWith(appDir) && generateRouteTypes(outFile, routerRoot, options.router?.ignoredRouteFiles);
|
|
16
|
+
(type === "add" || type === "delete" || type === "change") && path.startsWith(appDir) && generateRouteTypes(outFile, routerRoot, options.router?.ignoredRouteFiles, typedRoutesGeneration);
|
|
16
17
|
}, 100);
|
|
17
18
|
return server.watcher.addListener("all", fileWatcherChangeListener), () => {
|
|
18
|
-
generateRouteTypes(outFile, routerRoot, options.router?.ignoredRouteFiles);
|
|
19
|
+
generateRouteTypes(outFile, routerRoot, options.router?.ignoredRouteFiles, typedRoutesGeneration);
|
|
19
20
|
};
|
|
20
21
|
}
|
|
21
22
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["join","debounce","generateRouteTypes","getRouterRootFromOneOptions","generateFileSystemRouteTypesPlugin","options","name","enforce","apply","configureServer","server","appDir","process","cwd","outFile","routerRoot","fileWatcherChangeListener","type","path","startsWith","
|
|
1
|
+
{"version":3,"names":["join","debounce","generateRouteTypes","getRouterRootFromOneOptions","generateFileSystemRouteTypesPlugin","options","name","enforce","apply","configureServer","server","appDir","process","cwd","outFile","routerRoot","typedRoutesGeneration","router","experimental","fileWatcherChangeListener","type","path","startsWith","ignoredRouteFiles","watcher","addListener"],"sources":["../../../../src/vite/plugins/generateFileSystemRouteTypesPlugin.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,IAAA,QAAY;AACrB,SAASC,QAAA,QAAgB;AAEzB,SAASC,kBAAA,QAA0B;AACnC,SAASC,2BAAA,QAAmC;AAGrC,SAASC,mCAAmCC,OAAA,EAAoC;EACrF,OAAO;IACLC,IAAA,EAAM;IACNC,OAAA,EAAS;IACTC,KAAA,EAAO;IAEPC,gBAAgBC,MAAA,EAAQ;MACtB,MAAMC,MAAA,GAASX,IAAA,CAAKY,OAAA,CAAQC,GAAA,CAAI,GAAGV,2BAAA,CAA4BE,OAAO,CAAC;QAEjES,OAAA,GAAUd,IAAA,CAAKW,MAAA,EAAQ,aAAa;QAEpCI,UAAA,GAAaZ,2BAAA,CAA4BE,OAAO;QAChDW,qBAAA,GAAwBX,OAAA,CAAQY,MAAA,EAAQC,YAAA,EAAcF,qBAAA,IAAyB;QAG/EG,yBAAA,GAA4BlB,QAAA,CAAS,OAAOmB,IAAA,EAAcC,IAAA,KAAiB;UAC/E,CAAID,IAAA,KAAS,SAASA,IAAA,KAAS,YAAYA,IAAA,KAAS,aAC9CC,IAAA,CAAKC,UAAA,CAAWX,MAAM,KAExBT,kBAAA,CACEY,OAAA,EACAC,UAAA,EACAV,OAAA,CAAQY,MAAA,EAAQM,iBAAA,EAChBP,qBACF;QAGN,GAAG,GAAG;MAEN,OAAAN,MAAA,CAAOc,OAAA,CAAQC,WAAA,CAAY,OAAON,yBAAyB,GAEpD,MAAM;QAGXjB,kBAAA,CACEY,OAAA,EACAC,UAAA,EACAV,OAAA,CAAQY,MAAA,EAAQM,iBAAA,EAChBP,qBACF;MACF;IACF;EACF;AACF","ignoreList":[]}
|
|
@@ -8,18 +8,21 @@ function generateFileSystemRouteTypesPlugin(options) {
|
|
|
8
8
|
enforce: "post",
|
|
9
9
|
apply: "serve",
|
|
10
10
|
configureServer(server) {
|
|
11
|
-
var
|
|
11
|
+
var _options_router_experimental,
|
|
12
|
+
_options_router,
|
|
13
|
+
appDir = join(process.cwd(), getRouterRootFromOneOptions(options)),
|
|
12
14
|
outFile = join(appDir, "routes.d.ts"),
|
|
13
15
|
routerRoot = getRouterRootFromOneOptions(options),
|
|
16
|
+
typedRoutesGeneration = ((_options_router = options.router) === null || _options_router === void 0 || (_options_router_experimental = _options_router.experimental) === null || _options_router_experimental === void 0 ? void 0 : _options_router_experimental.typedRoutesGeneration) || void 0,
|
|
14
17
|
fileWatcherChangeListener = debounce(async function (type, path) {
|
|
15
|
-
if ((type === "add" || type === "delete") && path.startsWith(appDir)) {
|
|
16
|
-
var
|
|
17
|
-
generateRouteTypes(outFile, routerRoot, (
|
|
18
|
+
if ((type === "add" || type === "delete" || type === "change") && path.startsWith(appDir)) {
|
|
19
|
+
var _options_router2;
|
|
20
|
+
generateRouteTypes(outFile, routerRoot, (_options_router2 = options.router) === null || _options_router2 === void 0 ? void 0 : _options_router2.ignoredRouteFiles, typedRoutesGeneration);
|
|
18
21
|
}
|
|
19
22
|
}, 100);
|
|
20
23
|
return server.watcher.addListener("all", fileWatcherChangeListener), function () {
|
|
21
|
-
var
|
|
22
|
-
generateRouteTypes(outFile, routerRoot, (
|
|
24
|
+
var _options_router2;
|
|
25
|
+
generateRouteTypes(outFile, routerRoot, (_options_router2 = options.router) === null || _options_router2 === void 0 ? void 0 : _options_router2.ignoredRouteFiles, typedRoutesGeneration);
|
|
23
26
|
};
|
|
24
27
|
}
|
|
25
28
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["join","debounce","generateRouteTypes","getRouterRootFromOneOptions","generateFileSystemRouteTypesPlugin","options","name","enforce","apply","configureServer","server","appDir","process","cwd","outFile","routerRoot","fileWatcherChangeListener","type","path","startsWith","
|
|
1
|
+
{"version":3,"names":["join","debounce","generateRouteTypes","getRouterRootFromOneOptions","generateFileSystemRouteTypesPlugin","options","name","enforce","apply","configureServer","server","_options_router_experimental","_options_router","appDir","process","cwd","outFile","routerRoot","typedRoutesGeneration","router","experimental","fileWatcherChangeListener","type","path","startsWith","_options_router2","ignoredRouteFiles","watcher","addListener"],"sources":["../../../../src/vite/plugins/generateFileSystemRouteTypesPlugin.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,IAAA,QAAY;AACrB,SAASC,QAAA,QAAgB;AAEzB,SAASC,kBAAA,QAA0B;AACnC,SAASC,2BAAA,QAAmC;AAGrC,SAASC,mCAAmCC,OAAA,EAAoC;EACrF,OAAO;IACLC,IAAA,EAAM;IACNC,OAAA,EAAS;IACTC,KAAA,EAAO;IAEPC,gBAAgBC,MAAA,EAAQ;MACtB,IAAAC,4BAAgC;QAAAC,eAAG;QAAAC,MAAA,GAAAb,IAA4B,CAAAc,OAAQ,CAAAC,GAEjE,IAAAZ,2BAAuB,CAAAE,OAEvB;QAAAW,OAAa,GAAAhB,IAAA,CAAAa,MAAA,eAA4B;QAAAI,UACzC,GAAAd,2BAAgC,CAAAE,OAAQ;QAAAa,qBAAc,KAAAN,eAAyB,GAG/EP,OAAA,CAAAc,MAAA,cAA4BP,eAAgB,KAAc,UAAiB,CAAAD,4BAAA,GAAAC,eAAA,CAAAQ,YAAA,cAAAT,4BAAA,uBAAAA,4BAAA,CAAAO,qBAAA;QAAAG,yBAAA,GAAApB,QAAA,iBAAAqB,IAAA,EAAAC,IAAA;UAC/E,IAAI,CAAAD,IAAA,KAAS,KAAS,IAAAA,IAAA,KAAS,QAAY,IAAAA,IAAA,KAAS,aAC9CC,IAAK,CAAAC,UAAW,CAAAX,MAAM,CAExB;YACE,IAAAY,gBAAA;YACAvB,kBAAA,CAAAc,OAAA,EAAAC,UAAA,GAAAQ,gBAAA,GAAApB,OAAA,CAAAc,MAAA,cAAAM,gBAAA,uBAAAA,gBAAA,CAAAC,iBAAA,EAAAR,qBAAA;UAAA;QACgB,MAChB;MAAA,OACFR,MAAA,CAAAiB,OAAA,CAAAC,WAAA,QAAAP,yBAAA;QAGN,IAAMI,gBAAA;QAENvB,kBAAO,CAAAc,OAAQ,EAAAC,UAAY,EAAO,CAAAQ,gBAAA,GAAApB,OAE3B,CAAAc,MAAM,cAAAM,gBAAA,uBAAAA,gBAAA,CAAAC,iBAAA,EAAAR,qBAAA;MAGX;IAAA;EACE;AACA;AACgB,SAChBd,kCACF","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "one",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.18",
|
|
4
4
|
"license": "BSD-3-Clause",
|
|
5
5
|
"sideEffects": [
|
|
6
6
|
"setup.mjs",
|
|
@@ -121,17 +121,17 @@
|
|
|
121
121
|
"@react-navigation/routers": "~7.5.1",
|
|
122
122
|
"@swc/core": "^1.14.0",
|
|
123
123
|
"@ungap/structured-clone": "^1.2.0",
|
|
124
|
-
"@vxrn/compiler": "1.2.
|
|
125
|
-
"@vxrn/resolve": "1.2.
|
|
126
|
-
"@vxrn/tslib-lite": "1.2.
|
|
127
|
-
"@vxrn/universal-color-scheme": "1.2.
|
|
128
|
-
"@vxrn/use-isomorphic-layout-effect": "1.2.
|
|
129
|
-
"@vxrn/vite-plugin-metro": "1.2.
|
|
124
|
+
"@vxrn/compiler": "1.2.18",
|
|
125
|
+
"@vxrn/resolve": "1.2.18",
|
|
126
|
+
"@vxrn/tslib-lite": "1.2.18",
|
|
127
|
+
"@vxrn/universal-color-scheme": "1.2.18",
|
|
128
|
+
"@vxrn/use-isomorphic-layout-effect": "1.2.18",
|
|
129
|
+
"@vxrn/vite-plugin-metro": "1.2.18",
|
|
130
130
|
"babel-dead-code-elimination": "^1.0.10",
|
|
131
131
|
"babel-plugin-module-resolver": "^5.0.2",
|
|
132
132
|
"citty": "^0.1.6",
|
|
133
133
|
"core-js": "^3.38.1",
|
|
134
|
-
"create-vxrn": "1.2.
|
|
134
|
+
"create-vxrn": "1.2.18",
|
|
135
135
|
"escape-string-regexp": "^5.0.0",
|
|
136
136
|
"expo-linking": "~8.0.8",
|
|
137
137
|
"expo-modules-core": "~3.0.24",
|
|
@@ -157,7 +157,7 @@
|
|
|
157
157
|
"vite": "^7.1.12",
|
|
158
158
|
"vite-plugin-barrel": "^0.4.1",
|
|
159
159
|
"vite-tsconfig-paths": "^5.1.4",
|
|
160
|
-
"vxrn": "1.2.
|
|
160
|
+
"vxrn": "1.2.18",
|
|
161
161
|
"ws": "^8.18.0",
|
|
162
162
|
"xxhashjs": "^0.2.2"
|
|
163
163
|
},
|
|
@@ -175,7 +175,7 @@
|
|
|
175
175
|
"devDependencies": {
|
|
176
176
|
"@react-navigation/core": "^7.13.0",
|
|
177
177
|
"@react-navigation/native": "~7.1.19",
|
|
178
|
-
"@tamagui/build": "^1.
|
|
178
|
+
"@tamagui/build": "^1.137.3",
|
|
179
179
|
"@types/node": "^24.10.0",
|
|
180
180
|
"@types/react-dom": "^19.2.2",
|
|
181
181
|
"@types/xxhashjs": "^0.2.4",
|
|
@@ -1,12 +1,39 @@
|
|
|
1
1
|
import { existsSync } from 'node:fs'
|
|
2
2
|
import { join } from 'node:path'
|
|
3
3
|
import { generateRouteTypes } from '../typed-routes/generateRouteTypes'
|
|
4
|
+
import { getRouterRootFromOneOptions } from '../utils/getRouterRootFromOneOptions'
|
|
5
|
+
import { loadUserOneOptions } from '../vite/loadConfig'
|
|
4
6
|
|
|
5
|
-
export async function run(args: { appDir?: string } = {}) {
|
|
7
|
+
export async function run(args: { appDir?: string; typed?: string } = {}) {
|
|
6
8
|
const cwd = process.cwd()
|
|
7
9
|
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
+
// Try to load config to get One options
|
|
11
|
+
let oneOptions
|
|
12
|
+
let routerRoot: string
|
|
13
|
+
let ignoredRouteFiles: string[] | undefined
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
// Suppress stderr during config load (Vite may output resolution errors)
|
|
17
|
+
const originalStderrWrite = process.stderr.write
|
|
18
|
+
let stderrBuffer = ''
|
|
19
|
+
process.stderr.write = ((chunk: any) => {
|
|
20
|
+
stderrBuffer += chunk
|
|
21
|
+
return true
|
|
22
|
+
}) as any
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
const loaded = await loadUserOneOptions('build')
|
|
26
|
+
oneOptions = loaded.oneOptions
|
|
27
|
+
routerRoot = args.appDir || getRouterRootFromOneOptions(oneOptions)
|
|
28
|
+
ignoredRouteFiles = oneOptions.router?.ignoredRouteFiles
|
|
29
|
+
} finally {
|
|
30
|
+
process.stderr.write = originalStderrWrite
|
|
31
|
+
}
|
|
32
|
+
} catch (error) {
|
|
33
|
+
// Config loading failed - use defaults
|
|
34
|
+
routerRoot = args.appDir || 'app'
|
|
35
|
+
}
|
|
36
|
+
|
|
10
37
|
const appDir = join(cwd, routerRoot)
|
|
11
38
|
|
|
12
39
|
if (!existsSync(appDir)) {
|
|
@@ -19,5 +46,26 @@ export async function run(args: { appDir?: string } = {}) {
|
|
|
19
46
|
|
|
20
47
|
const outFile = join(appDir, 'routes.d.ts')
|
|
21
48
|
|
|
22
|
-
|
|
49
|
+
// Get typed routes mode from CLI arg or config (CLI arg takes precedence)
|
|
50
|
+
let typedRoutesMode: 'type' | 'runtime' | undefined
|
|
51
|
+
|
|
52
|
+
if (args.typed) {
|
|
53
|
+
// CLI arg provided - validate and use it
|
|
54
|
+
if (args.typed === 'type' || args.typed === 'runtime') {
|
|
55
|
+
typedRoutesMode = args.typed
|
|
56
|
+
} else {
|
|
57
|
+
console.error(`Error: Invalid --typed value "${args.typed}". Must be "type" or "runtime"`)
|
|
58
|
+
process.exit(1)
|
|
59
|
+
}
|
|
60
|
+
} else if (oneOptions) {
|
|
61
|
+
// No CLI arg - use config value if available
|
|
62
|
+
typedRoutesMode = oneOptions.router?.experimental?.typedRoutesGeneration || undefined
|
|
63
|
+
}
|
|
64
|
+
if (typedRoutesMode) {
|
|
65
|
+
} else if (!args.typed) {
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
await generateRouteTypes(outFile, routerRoot, ignoredRouteFiles, typedRoutesMode)
|
|
69
|
+
if (typedRoutesMode) {
|
|
70
|
+
}
|
|
23
71
|
}
|
package/src/cli.ts
CHANGED
|
@@ -251,6 +251,11 @@ const generateRoutes = defineCommand({
|
|
|
251
251
|
type: 'string',
|
|
252
252
|
description: 'Path to app directory (default: "app")',
|
|
253
253
|
},
|
|
254
|
+
typed: {
|
|
255
|
+
type: 'string',
|
|
256
|
+
description:
|
|
257
|
+
'Auto-generate route helpers. Options: "type" (type-only helpers) or "runtime" (runtime helpers)',
|
|
258
|
+
},
|
|
254
259
|
},
|
|
255
260
|
async run({ args }) {
|
|
256
261
|
const { run } = await import('./cli/generateRoutes')
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// Isolated to suppress deprecation warning for deep import
|
|
2
|
+
// React Native 0.81+ discourages deep imports but doesn't provide official alternative yet
|
|
3
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
4
|
+
// @ts-ignore - Types not exported from react-native
|
|
5
|
+
export { default as getDevServer } from 'react-native/Libraries/Core/Devtools/getDevServer'
|
package/src/getURL.native.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import getDevServer from '
|
|
1
|
+
import { getDevServer } from './getDevServer'
|
|
2
|
+
|
|
3
|
+
let hasWarnedOnce = false
|
|
2
4
|
|
|
3
5
|
export function getURL() {
|
|
4
6
|
let url = process.env.ONE_SERVER_URL
|
|
@@ -6,12 +8,15 @@ export function getURL() {
|
|
|
6
8
|
if (__DEV__) {
|
|
7
9
|
// We'll be using the development server in development mode, but we still need to warn the user to set SERVER_URL for things to work in production.
|
|
8
10
|
if (!url) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
if (hasWarnedOnce) {
|
|
12
|
+
hasWarnedOnce = true
|
|
13
|
+
console.warn(
|
|
14
|
+
`The ONE_SERVER_URL environment variable is not set. While things will work in development mode as we'll be using your development server, you should still set ONE_SERVER_URL in your .env file for your production builds to work.`
|
|
15
|
+
)
|
|
16
|
+
}
|
|
12
17
|
}
|
|
13
18
|
|
|
14
|
-
const { url: devServerUrl } = getDevServer()
|
|
19
|
+
const { url: devServerUrl } = getDevServer()
|
|
15
20
|
url = devServerUrl
|
|
16
21
|
}
|
|
17
22
|
|
package/src/index.ts
CHANGED
|
@@ -9,6 +9,19 @@ export type Href = '__branded__' extends keyof OneRouter.Href ? string : OneRout
|
|
|
9
9
|
|
|
10
10
|
export type LinkProps<T extends string | object = string> = OneRouter.LinkProps<T>
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Helper type to get route information including params and loader props.
|
|
14
|
+
* Can be overridden in generated routes.d.ts for per-route types.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* import type { RouteType } from 'one'
|
|
18
|
+
*
|
|
19
|
+
* type MyRoute = RouteType<'(site)/docs/[slug]'>
|
|
20
|
+
* // MyRoute.Params = { slug: string }
|
|
21
|
+
* // MyRoute.LoaderProps = { params: { slug: string }, path: string, request?: Request }
|
|
22
|
+
*/
|
|
23
|
+
export type RouteType<Path extends string = string> = OneRouter.RouteType<Path>
|
|
24
|
+
|
|
12
25
|
// hooks
|
|
13
26
|
export { useIsFocused } from '@react-navigation/core'
|
|
14
27
|
// re-export
|
package/src/interfaces/router.ts
CHANGED
|
@@ -16,6 +16,25 @@ export namespace OneRouter {
|
|
|
16
16
|
Loader: (props: { params: InputRouteParams<Path> }) => any
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Helper type to get route information including params and loader props.
|
|
21
|
+
* Uses generated RouteTypes from routes.d.ts if available for better intellisense.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* const route = createRoute<'/docs/[slug]'>()
|
|
25
|
+
* // route.createLoader gets params typed as { slug: string }
|
|
26
|
+
*
|
|
27
|
+
* type Route = RouteType<'/docs/[slug]'>
|
|
28
|
+
* // Route.Params = { slug: string }
|
|
29
|
+
* // Route.LoaderProps = { path: string; params: { slug: string }; request?: Request }
|
|
30
|
+
*/
|
|
31
|
+
export type RouteType<Path extends string> = Path extends keyof __routes['RouteTypes']
|
|
32
|
+
? __routes['RouteTypes'][Path]
|
|
33
|
+
: {
|
|
34
|
+
Params: InputRouteParams<Path>
|
|
35
|
+
LoaderProps: import('../types').LoaderProps<InputRouteParams<Path>>
|
|
36
|
+
}
|
|
37
|
+
|
|
19
38
|
type StaticRoutes = __routes extends { StaticRoutes: string } ? __routes['StaticRoutes'] : string
|
|
20
39
|
|
|
21
40
|
type DynamicRoutes<T extends string> = __routes<T> extends { DynamicRoutes: any }
|
|
@@ -1,14 +1,27 @@
|
|
|
1
1
|
import { useActiveParams, useParams, usePathname } from '../hooks'
|
|
2
2
|
import type { OneRouter } from '../interfaces/router'
|
|
3
|
+
import type { LoaderProps } from '../types'
|
|
3
4
|
|
|
4
|
-
export function createRoute<Path>() {
|
|
5
|
-
type Route = OneRouter.
|
|
5
|
+
export function createRoute<Path extends string = string>() {
|
|
6
|
+
type Route = OneRouter.RouteType<Path>
|
|
6
7
|
type Params = Route['Params']
|
|
8
|
+
type TypedLoaderProps = LoaderProps<Params>
|
|
7
9
|
|
|
8
10
|
return {
|
|
9
11
|
useParams: () => useParams<Params>(),
|
|
10
12
|
useActiveParams: () => useActiveParams<Params>(),
|
|
11
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Creates a typed loader function for this route.
|
|
15
|
+
* The loader receives LoaderProps with typed params.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* const route = createRoute<'(site)/docs/[slug]'>()
|
|
19
|
+
* export const loader = route.createLoader(({ params }) => {
|
|
20
|
+
* // params is typed as { slug: string }
|
|
21
|
+
* return { doc: getDoc(params.slug) }
|
|
22
|
+
* })
|
|
23
|
+
*/
|
|
24
|
+
createLoader: <T>(fn: (props: TypedLoaderProps) => T) => fn,
|
|
12
25
|
}
|
|
13
26
|
}
|
|
14
27
|
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import { writeFile } from 'node:fs/promises'
|
|
2
|
-
import { dirname } from 'node:path'
|
|
2
|
+
import { dirname, join } from 'node:path'
|
|
3
3
|
import FSExtra from 'fs-extra'
|
|
4
4
|
import micromatch from 'micromatch'
|
|
5
5
|
import { globbedRoutesToRouteContext } from '../router/useViteRoutes'
|
|
6
6
|
import { globDir } from '../utils/globDir'
|
|
7
|
+
import type { One } from '../vite/types'
|
|
7
8
|
import { getTypedRoutesDeclarationFile } from './getTypedRoutesDeclarationFile'
|
|
9
|
+
import { injectRouteHelpers, type InjectMode } from './injectRouteHelpers'
|
|
10
|
+
import { removeSupportedExtensions } from '../router/matchers'
|
|
8
11
|
|
|
9
12
|
export async function generateRouteTypes(
|
|
10
13
|
outFile: string,
|
|
11
14
|
routerRoot: string,
|
|
12
|
-
ignoredRouteFiles?: string[]
|
|
15
|
+
ignoredRouteFiles?: string[],
|
|
16
|
+
typedRoutesMode?: 'type' | 'runtime'
|
|
13
17
|
) {
|
|
14
18
|
let routePaths = globDir(routerRoot)
|
|
15
19
|
if (ignoredRouteFiles && ignoredRouteFiles.length > 0) {
|
|
@@ -27,4 +31,44 @@ export async function generateRouteTypes(
|
|
|
27
31
|
const outDir = dirname(outFile)
|
|
28
32
|
await FSExtra.ensureDir(outDir)
|
|
29
33
|
await writeFile(outFile, declarations)
|
|
34
|
+
|
|
35
|
+
// If experimental.typedRoutesGeneration is enabled, inject helpers into route files
|
|
36
|
+
if (typedRoutesMode) {
|
|
37
|
+
const mode: InjectMode = typedRoutesMode === 'type' ? 'type' : 'runtime'
|
|
38
|
+
|
|
39
|
+
// Inject helpers into each route file
|
|
40
|
+
for (const routePath of routePaths) {
|
|
41
|
+
// Skip non-route files (layouts, middlewares, type definitions, etc.)
|
|
42
|
+
if (
|
|
43
|
+
routePath.includes('_layout') ||
|
|
44
|
+
routePath.includes('+api') ||
|
|
45
|
+
routePath.startsWith('_') ||
|
|
46
|
+
routePath.endsWith('.d.ts')
|
|
47
|
+
) {
|
|
48
|
+
continue
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Convert route path to route name
|
|
52
|
+
// e.g., "./app/(site)/docs/[slug]+ssg.tsx" -> "/(site)/docs/[slug]"
|
|
53
|
+
const fullPath = join(process.cwd(), routerRoot, routePath)
|
|
54
|
+
const routeName = routePath
|
|
55
|
+
.replace(/^\.\//, '')
|
|
56
|
+
.replace(/\+[^/]*$/, '') // Remove +ssg, +ssr, etc.
|
|
57
|
+
.replace(/\/index$/, '')
|
|
58
|
+
.replace(/index$/, '')
|
|
59
|
+
let cleanRouteName = removeSupportedExtensions(routeName).replace(/\/?index$/, '')
|
|
60
|
+
|
|
61
|
+
// Ensure leading slash
|
|
62
|
+
if (!cleanRouteName.startsWith('/')) {
|
|
63
|
+
cleanRouteName = '/' + cleanRouteName
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Skip routes without dynamic segments (no params to type)
|
|
67
|
+
if (!cleanRouteName.includes('[')) {
|
|
68
|
+
continue
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
await injectRouteHelpers(fullPath, cleanRouteName, mode)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
30
74
|
}
|
|
@@ -26,6 +26,8 @@ export function getTypedRoutesDeclarationFile(ctx: One.RouteContext) {
|
|
|
26
26
|
dynamicRouteContextKeys
|
|
27
27
|
)
|
|
28
28
|
|
|
29
|
+
const hasRoutes = dynamicRouteContextKeys.size > 0
|
|
30
|
+
|
|
29
31
|
return `// deno-lint-ignore-file
|
|
30
32
|
/* eslint-disable */
|
|
31
33
|
// biome-ignore: needed import
|
|
@@ -38,12 +40,80 @@ declare module 'one' {
|
|
|
38
40
|
DynamicRoutes: ${setToUnionType(dynamicRoutes)}
|
|
39
41
|
DynamicRouteTemplate: ${setToUnionType(dynamicRouteContextKeys)}
|
|
40
42
|
IsTyped: true
|
|
43
|
+
${hasRoutes ? `RouteTypes: ${generateRouteTypesMap(dynamicRouteContextKeys)}` : ''}
|
|
41
44
|
}
|
|
42
45
|
}
|
|
43
46
|
}
|
|
47
|
+
${
|
|
48
|
+
hasRoutes
|
|
49
|
+
? `
|
|
50
|
+
/**
|
|
51
|
+
* Helper type for route information
|
|
52
|
+
*/
|
|
53
|
+
type RouteInfo<Params = Record<string, never>> = {
|
|
54
|
+
Params: Params
|
|
55
|
+
LoaderProps: { path: string; params: Params; request?: Request }
|
|
56
|
+
}`
|
|
57
|
+
: ''
|
|
58
|
+
}
|
|
44
59
|
`.trim()
|
|
45
60
|
}
|
|
46
61
|
|
|
62
|
+
/**
|
|
63
|
+
* Generates a mapped type for all routes with their expanded types
|
|
64
|
+
* This improves intellisense by showing actual param types instead of aliases
|
|
65
|
+
*/
|
|
66
|
+
function generateRouteTypesMap(dynamicRouteContextKeys: Set<string>): string {
|
|
67
|
+
if (dynamicRouteContextKeys.size === 0) {
|
|
68
|
+
return '{}'
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const routes = [...dynamicRouteContextKeys].sort()
|
|
72
|
+
|
|
73
|
+
const entries = routes
|
|
74
|
+
.map((routePath) => {
|
|
75
|
+
// Generate the param type inline for better intellisense
|
|
76
|
+
const params = extractParams(routePath)
|
|
77
|
+
const paramsType = params.length === 0 ? '{}' : generateInlineParamsType(params)
|
|
78
|
+
|
|
79
|
+
return ` '${routePath}': RouteInfo<${paramsType}>`
|
|
80
|
+
})
|
|
81
|
+
.join('\n')
|
|
82
|
+
|
|
83
|
+
return `{\n${entries}\n }`
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Extract parameter names from a route path
|
|
88
|
+
* e.g., "/docs/[slug]/[id]" -> ["slug", "id"]
|
|
89
|
+
*/
|
|
90
|
+
function extractParams(routePath: string): Array<{ name: string; isCatchAll: boolean }> {
|
|
91
|
+
const params: Array<{ name: string; isCatchAll: boolean }> = []
|
|
92
|
+
const paramRegex = /\[(\.\.\.)?([\w]+)\]/g
|
|
93
|
+
let match
|
|
94
|
+
|
|
95
|
+
while ((match = paramRegex.exec(routePath)) !== null) {
|
|
96
|
+
params.push({
|
|
97
|
+
name: match[2],
|
|
98
|
+
isCatchAll: match[1] === '...',
|
|
99
|
+
})
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return params
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Generate inline params type for better intellisense
|
|
107
|
+
* e.g., [{ name: "slug", isCatchAll: false }] -> "{ slug: string }"
|
|
108
|
+
*/
|
|
109
|
+
function generateInlineParamsType(params: Array<{ name: string; isCatchAll: boolean }>): string {
|
|
110
|
+
const entries = params.map((p) => {
|
|
111
|
+
const type = p.isCatchAll ? 'string[]' : 'string'
|
|
112
|
+
return `${p.name}: ${type}`
|
|
113
|
+
})
|
|
114
|
+
return `{ ${entries.join('; ')} }`
|
|
115
|
+
}
|
|
116
|
+
|
|
47
117
|
/**
|
|
48
118
|
* Walks a RouteNode tree and adds the routes to the provided sets
|
|
49
119
|
*/
|