one 1.1.539 → 1.1.540

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.
Files changed (27) hide show
  1. package/dist/cjs/typed-routes/generateRouteTypes.cjs +23 -2
  2. package/dist/cjs/typed-routes/generateRouteTypes.js +20 -2
  3. package/dist/cjs/typed-routes/generateRouteTypes.js.map +1 -1
  4. package/dist/cjs/typed-routes/generateRouteTypes.native.js +25 -2
  5. package/dist/cjs/typed-routes/generateRouteTypes.native.js.map +1 -1
  6. package/dist/cjs/vite/plugins/generateFileSystemRouteTypesPlugin.cjs +1 -1
  7. package/dist/cjs/vite/plugins/generateFileSystemRouteTypesPlugin.js +1 -3
  8. package/dist/cjs/vite/plugins/generateFileSystemRouteTypesPlugin.js.map +1 -1
  9. package/dist/cjs/vite/plugins/generateFileSystemRouteTypesPlugin.native.js +1 -3
  10. package/dist/cjs/vite/plugins/generateFileSystemRouteTypesPlugin.native.js.map +1 -1
  11. package/dist/esm/typed-routes/generateRouteTypes.js +22 -4
  12. package/dist/esm/typed-routes/generateRouteTypes.js.map +1 -1
  13. package/dist/esm/typed-routes/generateRouteTypes.mjs +25 -4
  14. package/dist/esm/typed-routes/generateRouteTypes.mjs.map +1 -1
  15. package/dist/esm/typed-routes/generateRouteTypes.native.js +27 -4
  16. package/dist/esm/typed-routes/generateRouteTypes.native.js.map +1 -1
  17. package/dist/esm/vite/plugins/generateFileSystemRouteTypesPlugin.js +2 -4
  18. package/dist/esm/vite/plugins/generateFileSystemRouteTypesPlugin.js.map +1 -1
  19. package/dist/esm/vite/plugins/generateFileSystemRouteTypesPlugin.mjs +2 -2
  20. package/dist/esm/vite/plugins/generateFileSystemRouteTypesPlugin.mjs.map +1 -1
  21. package/dist/esm/vite/plugins/generateFileSystemRouteTypesPlugin.native.js +2 -4
  22. package/dist/esm/vite/plugins/generateFileSystemRouteTypesPlugin.native.js.map +1 -1
  23. package/package.json +9 -9
  24. package/src/typed-routes/generateRouteTypes.ts +39 -3
  25. package/src/vite/plugins/generateFileSystemRouteTypesPlugin.tsx +3 -11
  26. package/types/typed-routes/generateRouteTypes.d.ts.map +1 -1
  27. package/types/vite/plugins/generateFileSystemRouteTypesPlugin.d.ts.map +1 -1
@@ -49,6 +49,27 @@ async function generateRouteTypes(outFile, routerRoot, ignoredRouteFiles) {
49
49
  }));
50
50
  const routes = routePaths.reduce((acc, cur) => (acc[cur] = {}, acc), {}),
51
51
  context = (0, import_useViteRoutes.globbedRoutesToRouteContext)(routes, routerRoot),
52
- declarations = (0, import_getTypedRoutesDeclarationFile.getTypedRoutesDeclarationFile)(context);
53
- await import_fs_extra.default.ensureDir((0, import_node_path.dirname)(outFile)), await (0, import_promises.writeFile)(outFile, declarations);
52
+ declarations = (0, import_getTypedRoutesDeclarationFile.getTypedRoutesDeclarationFile)(context),
53
+ outDir = (0, import_node_path.dirname)(outFile);
54
+ if (await import_fs_extra.default.ensureDir(outDir), await (0, import_promises.writeFile)(outFile, declarations), outFile.includes("node_modules/@types/one-routes")) {
55
+ const packageJsonPath = (0, import_node_path.join)(outDir, "package.json");
56
+ await (0, import_promises.writeFile)(packageJsonPath, JSON.stringify({
57
+ name: "@types/one-routes",
58
+ version: "1.0.0",
59
+ private: !0,
60
+ types: "index.d.ts"
61
+ }, null, 2)), await ensureTsconfigIncludesOneRoutes(outDir);
62
+ }
63
+ }
64
+ async function ensureTsconfigIncludesOneRoutes(typesDir) {
65
+ const projectRoot = (0, import_node_path.join)(typesDir, "../../.."),
66
+ tsconfigPath = (0, import_node_path.join)(projectRoot, "tsconfig.json");
67
+ try {
68
+ const tsconfigContent = await (0, import_promises.readFile)(tsconfigPath, "utf-8"),
69
+ tsconfig = JSON.parse(tsconfigContent);
70
+ tsconfig.compilerOptions?.types && Array.isArray(tsconfig.compilerOptions.types) && (tsconfig.compilerOptions.types.includes("one-routes") || (tsconfig.compilerOptions.types.push("one-routes"), await (0, import_promises.writeFile)(tsconfigPath, JSON.stringify(tsconfig, null, 2) + `
71
+ `)));
72
+ } catch (error) {
73
+ console.warn("Could not update tsconfig.json:", error);
74
+ }
54
75
  }
@@ -32,7 +32,25 @@ async function generateRouteTypes(outFile, routerRoot, ignoredRouteFiles) {
32
32
  // The path starts with './', such as './foo/bar/baz.test.tsx', and ignoredRouteFiles is like ['**/*.test.*'], so we need matchBase here.
33
33
  matchBase: !0
34
34
  }));
35
- const routes = routePaths.reduce((acc, cur) => (acc[cur] = {}, acc), {}), context = (0, import_useViteRoutes.globbedRoutesToRouteContext)(routes, routerRoot), declarations = (0, import_getTypedRoutesDeclarationFile.getTypedRoutesDeclarationFile)(context);
36
- await import_fs_extra.default.ensureDir((0, import_node_path.dirname)(outFile)), await (0, import_promises.writeFile)(outFile, declarations);
35
+ const routes = routePaths.reduce((acc, cur) => (acc[cur] = {}, acc), {}), context = (0, import_useViteRoutes.globbedRoutesToRouteContext)(routes, routerRoot), declarations = (0, import_getTypedRoutesDeclarationFile.getTypedRoutesDeclarationFile)(context), outDir = (0, import_node_path.dirname)(outFile);
36
+ if (await import_fs_extra.default.ensureDir(outDir), await (0, import_promises.writeFile)(outFile, declarations), outFile.includes("node_modules/@types/one-routes")) {
37
+ const packageJsonPath = (0, import_node_path.join)(outDir, "package.json");
38
+ await (0, import_promises.writeFile)(packageJsonPath, JSON.stringify({
39
+ name: "@types/one-routes",
40
+ version: "1.0.0",
41
+ private: !0,
42
+ types: "index.d.ts"
43
+ }, null, 2)), await ensureTsconfigIncludesOneRoutes(outDir);
44
+ }
45
+ }
46
+ async function ensureTsconfigIncludesOneRoutes(typesDir) {
47
+ const projectRoot = (0, import_node_path.join)(typesDir, "../../.."), tsconfigPath = (0, import_node_path.join)(projectRoot, "tsconfig.json");
48
+ try {
49
+ const tsconfigContent = await (0, import_promises.readFile)(tsconfigPath, "utf-8"), tsconfig = JSON.parse(tsconfigContent);
50
+ tsconfig.compilerOptions?.types && Array.isArray(tsconfig.compilerOptions.types) && (tsconfig.compilerOptions.types.includes("one-routes") || (tsconfig.compilerOptions.types.push("one-routes"), await (0, import_promises.writeFile)(tsconfigPath, JSON.stringify(tsconfig, null, 2) + `
51
+ `)));
52
+ } catch (error) {
53
+ console.warn("Could not update tsconfig.json:", error);
54
+ }
37
55
  }
38
56
  //# sourceMappingURL=generateRouteTypes.js.map
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/typed-routes/generateRouteTypes.ts"],
4
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAoB,iCACpB,kBAA0B,6BAC1B,mBAAwB,sBACxB,oBAAuB,mCACvB,uBAA4C,oCAC5C,iBAAwB,6BACxB,uCAA8C;AAE9C,eAAsB,mBACpB,SACA,YACA,mBACA;AACA,MAAI,iBAAa,wBAAQ,UAAU;AACnC,EAAI,qBAAqB,kBAAkB,SAAS,MAClD,aAAa,kBAAAA,QAAW,IAAI,YAAY,mBAAmB;AAAA;AAAA,IAEzD,WAAW;AAAA,EACb,CAAC;AAEH,QAAM,SAAS,WAAW,OAAO,CAAC,KAAK,SACrC,IAAI,GAAG,IAAI,CAAC,GACL,MACN,CAAC,CAAC,GACC,cAAU,kDAA4B,QAAQ,UAAU,GACxD,mBAAe,oEAA8B,OAAO;AAC1D,QAAM,gBAAAC,QAAQ,cAAU,0BAAQ,OAAO,CAAC,GACxC,UAAM,2BAAU,SAAS,YAAY;AACvC;",
4
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAoB,iCACpB,kBAAoC,6BACpC,mBAA8B,sBAC9B,oBAAuB,mCACvB,uBAA4C,oCAC5C,iBAAwB,6BACxB,uCAA8C;AAE9C,eAAsB,mBACpB,SACA,YACA,mBACA;AACA,MAAI,iBAAa,wBAAQ,UAAU;AACnC,EAAI,qBAAqB,kBAAkB,SAAS,MAClD,aAAa,kBAAAA,QAAW,IAAI,YAAY,mBAAmB;AAAA;AAAA,IAEzD,WAAW;AAAA,EACb,CAAC;AAEH,QAAM,SAAS,WAAW,OAAO,CAAC,KAAK,SACrC,IAAI,GAAG,IAAI,CAAC,GACL,MACN,CAAC,CAAC,GACC,cAAU,kDAA4B,QAAQ,UAAU,GACxD,mBAAe,oEAA8B,OAAO,GACpD,aAAS,0BAAQ,OAAO;AAK9B,MAJA,MAAM,gBAAAC,QAAQ,UAAU,MAAM,GAC9B,UAAM,2BAAU,SAAS,YAAY,GAGjC,QAAQ,SAAS,gCAAgC,GAAG;AACtD,UAAM,sBAAkB,uBAAK,QAAQ,cAAc;AAOnD,cAAM,2BAAU,iBAAiB,KAAK,UANlB;AAAA,MAClB,MAAM;AAAA,MACN,SAAS;AAAA,MACT,SAAS;AAAA,MACT,OAAO;AAAA,IACT,GAC6D,MAAM,CAAC,CAAC,GACrE,MAAM,gCAAgC,MAAM;AAAA,EAC9C;AACF;AAEA,eAAe,gCAAgC,UAAkB;AAC/D,QAAM,kBAAc,uBAAK,UAAU,UAAU,GACvC,mBAAe,uBAAK,aAAa,eAAe;AAEtD,MAAI;AACF,UAAM,kBAAkB,UAAM,0BAAS,cAAc,OAAO,GACtD,WAAW,KAAK,MAAM,eAAe;AAI3C,IAAI,SAAS,iBAAiB,SAAS,MAAM,QAAQ,SAAS,gBAAgB,KAAK,MAC5E,SAAS,gBAAgB,MAAM,SAAS,YAAY,MACvD,SAAS,gBAAgB,MAAM,KAAK,YAAY,GAChD,UAAM,2BAAU,cAAc,KAAK,UAAU,UAAU,MAAM,CAAC,IAAI;AAAA,CAAI;AAAA,EAG5E,SAAS,OAAO;AAEd,YAAQ,KAAK,mCAAmC,KAAK;AAAA,EACvD;AACF;",
5
5
  "names": ["micromatch", "FSExtra"]
6
6
  }
@@ -53,7 +53,30 @@ async function generateRouteTypes(outFile, routerRoot, ignoredRouteFiles) {
53
53
  return acc[cur] = {}, acc;
54
54
  }, {}),
55
55
  context = (0, import_useViteRoutes.globbedRoutesToRouteContext)(routes, routerRoot),
56
- declarations = (0, import_getTypedRoutesDeclarationFile.getTypedRoutesDeclarationFile)(context);
57
- await import_fs_extra.default.ensureDir((0, import_path.dirname)(outFile)), await (0, import_promises.writeFile)(outFile, declarations);
56
+ declarations = (0, import_getTypedRoutesDeclarationFile.getTypedRoutesDeclarationFile)(context),
57
+ outDir = (0, import_path.dirname)(outFile);
58
+ if (await import_fs_extra.default.ensureDir(outDir), await (0, import_promises.writeFile)(outFile, declarations), outFile.includes("node_modules/@types/one-routes")) {
59
+ var packageJsonPath = (0, import_path.join)(outDir, "package.json"),
60
+ packageJson = {
61
+ name: "@types/one-routes",
62
+ version: "1.0.0",
63
+ private: !0,
64
+ types: "index.d.ts"
65
+ };
66
+ await (0, import_promises.writeFile)(packageJsonPath, JSON.stringify(packageJson, null, 2)), await ensureTsconfigIncludesOneRoutes(outDir);
67
+ }
68
+ }
69
+ async function ensureTsconfigIncludesOneRoutes(typesDir) {
70
+ var projectRoot = (0, import_path.join)(typesDir, "../../.."),
71
+ tsconfigPath = (0, import_path.join)(projectRoot, "tsconfig.json");
72
+ try {
73
+ var _tsconfig_compilerOptions,
74
+ tsconfigContent = await (0, import_promises.readFile)(tsconfigPath, "utf-8"),
75
+ tsconfig = JSON.parse(tsconfigContent);
76
+ !((_tsconfig_compilerOptions = tsconfig.compilerOptions) === null || _tsconfig_compilerOptions === void 0) && _tsconfig_compilerOptions.types && Array.isArray(tsconfig.compilerOptions.types) && (tsconfig.compilerOptions.types.includes("one-routes") || (tsconfig.compilerOptions.types.push("one-routes"), await (0, import_promises.writeFile)(tsconfigPath, JSON.stringify(tsconfig, null, 2) + `
77
+ `)));
78
+ } catch (error) {
79
+ console.warn("Could not update tsconfig.json:", error);
80
+ }
58
81
  }
59
82
  //# sourceMappingURL=generateRouteTypes.native.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","generateRouteTypes_exports","__export","generateRouteTypes","module","exports","import_fs_extra","__toESM","require","import_promises","import_path","import_micromatch","import_useViteRoutes","import_globDir","import_getTypedRoutesDeclarationFile","outFile","routerRoot","ignoredRouteFiles","routePaths","globDir","length","default","not","matchBase","routes","reduce","acc","cur"],"sources":["../../../src/typed-routes/generateRouteTypes.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAAA;EAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;IAAAC,KAAA;EAAA,IAAAH,GAAA;AAAA,IAAAI,0BAAA;AAAAC,QAAA,CAAAD,0BAAA;EAAAE,kBAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAT,YAAoB,CAAAK,0BACpB;AAOA,IAAAK,eAAsB,GAAAC,OAAA,CAAAC,OACpB,WACA;EACAC,eAAA,GAAAD,OACA;EAAAE,WAAA,GAAAF,OAAA;EAAAG,iBAAA,GAAAJ,OAAA,CAAAC,OAAA;EAAAI,oBAAA,GAAAJ,OAAA;EAAAK,cAAA,GAAAL,OAAA;EAAAM,oCAAA,GAAAN,OAAA;AACA,eAAIL,kBAAaA,CAAAY,OAAA,EAAAC,UAAQ,EAAAC,iBAAU;EAC/B,IAAAC,UAAA,OAAqBL,cAAA,CAAAM,OAAkB,EAAAH,UACzC;EAA2DC,iBAAA,IAAAA,iBAAA,CAAAG,MAAA,SAAAF,UAAA,GAAAP,iBAAA,CAAAU,OAAA,CAAAC,GAAA,CAAAJ,UAAA,EAAAD,iBAAA;IAEzD;IACDM,SAAA;EAEH;EAMA,IAAAC,MAAM,GAAAN,UAAA,CAAAO,MAAQ,WAAAC,GAAA,EAAUC,GAAA;MAE1B,OAAAD,GAAA,CAAAC,GAAA,QAAAD,GAAA","ignoreList":[]}
1
+ {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","generateRouteTypes_exports","__export","generateRouteTypes","module","exports","import_fs_extra","__toESM","require","import_promises","import_path","import_micromatch","import_useViteRoutes","import_globDir","import_getTypedRoutesDeclarationFile","outFile","routerRoot","ignoredRouteFiles","routePaths","globDir","length","default","not","matchBase","routes","reduce","acc","cur","context","globbedRoutesToRouteContext","declarations","getTypedRoutesDeclarationFile","outDir","dirname","ensureDir","writeFile","includes","packageJsonPath","join","packageJson","name","version","private","types","JSON","stringify","ensureTsconfigIncludesOneRoutes","typesDir","projectRoot","tsconfigPath","_tsconfig_compilerOptions","tsconfigContent","readFile","tsconfig","parse","compilerOptions","Array","isArray","push","error"],"sources":["../../../src/typed-routes/generateRouteTypes.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAAA;EAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;IAAAC,KAAA;EAAA,IAAAH,GAAA;AAAA,IAAAI,0BAAA;AAAAC,QAAA,CAAAD,0BAAA;EAAAE,kBAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAT,YAAoB,CAAAK,0BACpB;AAOA,IAAAK,eAAsB,GAAAC,OAAA,CAAAC,OACpB,WACA;EACAC,eAAA,GAAAD,OACA;EAAAE,WAAA,GAAAF,OAAA;EAAAG,iBAAA,GAAAJ,OAAA,CAAAC,OAAA;EAAAI,oBAAA,GAAAJ,OAAA;EAAAK,cAAA,GAAAL,OAAA;EAAAM,oCAAA,GAAAN,OAAA;AACA,eAAIL,kBAAaA,CAAAY,OAAA,EAAAC,UAAQ,EAAAC,iBAAU;EAC/B,IAAAC,UAAA,OAAqBL,cAAA,CAAAM,OAAkB,EAAAH,UACzC;EAA2DC,iBAAA,IAAAA,iBAAA,CAAAG,MAAA,SAAAF,UAAA,GAAAP,iBAAA,CAAAU,OAAA,CAAAC,GAAA,CAAAJ,UAAA,EAAAD,iBAAA;IAEzD;IACDM,SAAA;EAEH;EAWA,IAJAC,MAAM,GAAAN,UAAA,CAAAO,MAAA,WAAQC,GAAA,EAAUC,GAAA,EAAM;MAK5B,OAAMD,GAAA,CAAAC,GAAA,QAAAD,GAAA;IAON;IAAAE,OAAM,OAAAhB,oBAAU,CAAAiB,2BAAsB,EANlBL,MAAA,EAAAR,UAAA;IAAAc,YAAA,OAAAhB,oCAAA,CAAAiB,6BAAA,EAAAH,OAAA;IAAAI,MAAA,OAAAtB,WAAA,CAAAuB,OAAA,EAAAlB,OAAA;EAAA,IAClB,MAAMT,eAAA,CAAAe,OAAA,CAAAa,SAAA,CAAAF,MAAA,aAAAvB,eAAA,CAAA0B,SAAA,EAAApB,OAAA,EAAAe,YAAA,GAAAf,OAAA,CAAAqB,QAAA;IAAA,IACNC,eAAS,OAAA3B,WAAA,CAAA4B,IAAA,EAAAN,MAAA;MAAAO,WAAA;QACTC,IAAA,qBAAS;QACTC,OAAO;QACTC,OACmE,EAAE;QAEvEC,KAAA;MACF;IAEA,UAAAlC,eAAe,CAAA0B,SAAA,EAAAE,eAAgC,EAAkBO,IAAA,CAAAC,SAAA,CAAAN,WAAA,mBAAAO,+BAAA,CAAAd,MAAA;EAC/D;AAGA;AACE,eAAMc,+BAAwBA,CAAAC,QAAA;EAK9B,IAAIC,WAAS,OAAAtC,WAAiB,CAAA4B,IAAS,EAAAS,QAAM,YAAiB;IAAAE,YAAA,GAAgB,IAAKvC,WAC5E,CAAA4B,IAAS,EAAAU,WAAA,EAAgB,eAAe;EAE2B;IAG5E,IAAAE,yBAAgB;MAAAC,eAAA,aAAA1C,eAAA,CAAA2C,QAAA,EAAAH,YAAA;MAAAI,QAAA,GAAAT,IAAA,CAAAU,KAAA,CAAAH,eAAA;IAEd,GAAAD,yBAAa,GAAAG,QAAA,CAAAE,eAAwC,cAAAL,yBAAA,gBAAAA,yBAAA,CAAAP,KAAA,IAAAa,KAAA,CAAAC,OAAA,CAAAJ,QAAA,CAAAE,eAAA,CAAAZ,KAAA,MAAAU,QAAA,CAAAE,eAAA,CAAAZ,KAAA,CAAAP,QAAA,mBAAAiB,QAAA,CAAAE,eAAA,CAAAZ,KAAA,CAAAe,IAAA,0BAAAjD,eAAA,CAAA0B,SAAA,EAAAc,YAAA,EAAAL,IAAA,CAAAC,SAAA,CAAAQ,QAAA;AAAA,EACvD;EACF,SAAAM,KAAA","ignoreList":[]}
@@ -34,7 +34,7 @@ function generateFileSystemRouteTypesPlugin(options) {
34
34
  apply: "serve",
35
35
  configureServer(server) {
36
36
  const appDir = (0, import_node_path.join)(process.cwd(), (0, import_getRouterRootFromOneOptions.getRouterRootFromOneOptions)(options)),
37
- outFile = (0, import_node_path.dirname)(appDir) !== process.cwd() ? (console.warn("Seems that the router root has been customized and is in a nested folder. For now we will generate the routes.d.ts file beside the app folder. This behavior might be changed in the future."), (0, import_node_path.join)((0, import_node_path.dirname)(appDir), "routes.d.ts")) : (0, import_node_path.join)(process.cwd(), "routes.d.ts"),
37
+ outFile = (0, import_node_path.join)(process.cwd(), "node_modules", "@types", "one-routes", "index.d.ts"),
38
38
  routerRoot = (0, import_getRouterRootFromOneOptions.getRouterRootFromOneOptions)(options),
39
39
  fileWatcherChangeListener = (0, import_perfect_debounce.debounce)(async (type, path) => {
40
40
  (type === "add" || type === "delete") && path.startsWith(appDir) && (0, import_generateRouteTypes.generateRouteTypes)(outFile, routerRoot, options.router?.ignoredRouteFiles);
@@ -24,9 +24,7 @@ function generateFileSystemRouteTypesPlugin(options) {
24
24
  enforce: "post",
25
25
  apply: "serve",
26
26
  configureServer(server) {
27
- const appDir = (0, import_node_path.join)(process.cwd(), (0, import_getRouterRootFromOneOptions.getRouterRootFromOneOptions)(options)), outFile = (0, import_node_path.dirname)(appDir) !== process.cwd() ? (console.warn(
28
- "Seems that the router root has been customized and is in a nested folder. For now we will generate the routes.d.ts file beside the app folder. This behavior might be changed in the future."
29
- ), (0, import_node_path.join)((0, import_node_path.dirname)(appDir), "routes.d.ts")) : (0, import_node_path.join)(process.cwd(), "routes.d.ts"), routerRoot = (0, import_getRouterRootFromOneOptions.getRouterRootFromOneOptions)(options), fileWatcherChangeListener = (0, import_perfect_debounce.debounce)(async (type, path) => {
27
+ const appDir = (0, import_node_path.join)(process.cwd(), (0, import_getRouterRootFromOneOptions.getRouterRootFromOneOptions)(options)), outFile = (0, import_node_path.join)(process.cwd(), "node_modules", "@types", "one-routes", "index.d.ts"), routerRoot = (0, import_getRouterRootFromOneOptions.getRouterRootFromOneOptions)(options), fileWatcherChangeListener = (0, import_perfect_debounce.debounce)(async (type, path) => {
30
28
  (type === "add" || type === "delete") && path.startsWith(appDir) && (0, import_generateRouteTypes.generateRouteTypes)(outFile, routerRoot, options.router?.ignoredRouteFiles);
31
29
  }, 100);
32
30
  return server.watcher.addListener("all", fileWatcherChangeListener), () => {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/vite/plugins/generateFileSystemRouteTypesPlugin.tsx"],
4
- "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAA8B,sBAC9B,0BAAyB,6BAGzB,4BAAmC,kDACnC,qCAA4C;AAErC,SAAS,mCAAmC,SAAoC;AACrF,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IACT,OAAO;AAAA,IAEP,gBAAgB,QAAQ;AACtB,YAAM,aAAS,uBAAK,QAAQ,IAAI,OAAG,gEAA4B,OAAO,CAAC,GACjE,cACA,0BAAQ,MAAM,MAAM,QAAQ,IAAI,KAClC,QAAQ;AAAA,QACN;AAAA,MACF,OACO,2BAAK,0BAAQ,MAAM,GAAG,aAAa,SAGrC,uBAAK,QAAQ,IAAI,GAAG,aAAa,GAGpC,iBAAa,gEAA4B,OAAO,GAGhD,gCAA4B,kCAAS,OAAO,MAAc,SAAiB;AAC/E,SAAI,SAAS,SAAS,SAAS,aACzB,KAAK,WAAW,MAAM,SAExB,8CAAmB,SAAS,YAAY,QAAQ,QAAQ,iBAAiB;AAAA,MAG/E,GAAG,GAAG;AAEN,oBAAO,QAAQ,YAAY,OAAO,yBAAyB,GAEpD,MAAM;AAGX,0DAAmB,SAAS,YAAY,QAAQ,QAAQ,iBAAiB;AAAA,MAC3E;AAAA,IACF;AAAA,EACF;AACF;",
4
+ "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAqB,sBACrB,0BAAyB,6BAGzB,4BAAmC,kDACnC,qCAA4C;AAErC,SAAS,mCAAmC,SAAoC;AACrF,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IACT,OAAO;AAAA,IAEP,gBAAgB,QAAQ;AACtB,YAAM,aAAS,uBAAK,QAAQ,IAAI,OAAG,gEAA4B,OAAO,CAAC,GAEjE,cAAU,uBAAK,QAAQ,IAAI,GAAG,gBAAgB,UAAU,cAAc,YAAY,GAElF,iBAAa,gEAA4B,OAAO,GAGhD,gCAA4B,kCAAS,OAAO,MAAc,SAAiB;AAC/E,SAAI,SAAS,SAAS,SAAS,aACzB,KAAK,WAAW,MAAM,SAExB,8CAAmB,SAAS,YAAY,QAAQ,QAAQ,iBAAiB;AAAA,MAG/E,GAAG,GAAG;AAEN,oBAAO,QAAQ,YAAY,OAAO,yBAAyB,GAEpD,MAAM;AAGX,0DAAmB,SAAS,YAAY,QAAQ,QAAQ,iBAAiB;AAAA,MAC3E;AAAA,IACF;AAAA,EACF;AACF;",
5
5
  "names": []
6
6
  }
@@ -36,9 +36,7 @@ function generateFileSystemRouteTypesPlugin(options) {
36
36
  apply: "serve",
37
37
  configureServer(server) {
38
38
  var appDir = (0, import_path.join)(process.cwd(), (0, import_getRouterRootFromOneOptions.getRouterRootFromOneOptions)(options)),
39
- outFile = function () {
40
- return (0, import_path.dirname)(appDir) !== process.cwd() ? (console.warn("Seems that the router root has been customized and is in a nested folder. For now we will generate the routes.d.ts file beside the app folder. This behavior might be changed in the future."), (0, import_path.join)((0, import_path.dirname)(appDir), "routes.d.ts")) : (0, import_path.join)(process.cwd(), "routes.d.ts");
41
- }(),
39
+ outFile = (0, import_path.join)(process.cwd(), "node_modules", "@types", "one-routes", "index.d.ts"),
42
40
  routerRoot = (0, import_getRouterRootFromOneOptions.getRouterRootFromOneOptions)(options),
43
41
  fileWatcherChangeListener = (0, import_perfect_debounce.debounce)(async function (type, path) {
44
42
  if ((type === "add" || type === "delete") && path.startsWith(appDir)) {
@@ -1 +1 @@
1
- {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","generateFileSystemRouteTypesPlugin_exports","__export","generateFileSystemRouteTypesPlugin","module","exports","import_path","require","import_perfect_debounce","import_generateRouteTypes","import_getRouterRootFromOneOptions","options","name","enforce","apply","configureServer","server","appDir","join","process","cwd","getRouterRootFromOneOptions","outFile","dirname","console","warn","routerRoot","fileWatcherChangeListener","debounce","type","path","startsWith","_options_router","generateRouteTypes","router","ignoredRouteFiles","watcher","addListener"],"sources":["../../../../src/vite/plugins/generateFileSystemRouteTypesPlugin.tsx"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,0CAAA;AAAAC,QAAA,CAAAD,0CAAA;EAAAE,kCAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAT,YAA8B,CAAAK,0CACL;AAMlB,IAAAK,WAAS,GAAAC,OAAA;EAAAC,uBAAuE,GAAAD,OAAA;EAAAE,yBAAA,GAAAF,OAAA;EAAAG,kCAAA,GAAAH,OAAA;AACrF,SAAOJ,mCAAAQ,OAAA;EAAA,OACL;IACAC,IAAA,+BAAS;IACTC,OAAO;IAEPC,KAAA;IACEC,eAAMA,CAAAC,MAAS;MAGH,IACNC,MAAA,OAAAX,WAAA,CAAAY,IAAA,EAAAC,OAAA,CAAAC,GAAA,QAAAV,kCAAA,CAAAW,2BAAA,EAAAV,OAAA;QAAAW,OAAA;UACF,OACO,IAAAhB,WAAA,CAAAiB,OAAA,EAAKN,MAAA,MAAAE,OAAA,CAAAC,GAAA,MAAQI,OAAS,CAAAC,IAAA,+LAS3B,GAA4B,IAAAnB,WAAA,CAAAY,IAAA,MAAAZ,WAAS,CAAAiB,OAAO,EAAcN,MAAA,GAAiB,sBAAAX,WAAA,CAAAY,IAAA,EAAAC,OAAA,CAAAC,GAAA;QAC/E,EAAI;QAAAM,UAAS,KAAS,EAAAhB,kCACX,CAAAW,2BAEP,EAAAV,OAAA;QAAAgB,yBAAmB,OAASnB,uBAAoB,CAAAoB,QAAQ,kBAAiBC,IAAA,EAAAC,IAAA;UAG/E,IAAM,CAAAD,IAAA,cAAAA,IAAA,kBAAAC,IAAA,CAAAC,UAAA,CAAAd,MAAA;YAEN,IAAAe,eAAe;YAKb,IAAAvB,yBAAA,CAAAwB,kBAAmB,EAAAX,OAAS,EAAAI,UAAY,GAAAM,eAAgB,GAAArB,OAAA,CAAAuB,MAAiB,cAAAF,eAAA,uBAAAA,eAAA,CAAAG,iBAAA;UAC3E;QACF;MACF,OAAAnB,MAAA,CAAAoB,OAAA,CAAAC,WAAA,QAAAV,yBAAA;QACF,IAAAK,eAAA","ignoreList":[]}
1
+ {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","generateFileSystemRouteTypesPlugin_exports","__export","generateFileSystemRouteTypesPlugin","module","exports","import_path","require","import_perfect_debounce","import_generateRouteTypes","import_getRouterRootFromOneOptions","options","name","enforce","apply","configureServer","server","appDir","join","process","cwd","getRouterRootFromOneOptions","outFile","routerRoot","fileWatcherChangeListener","debounce","type","path","startsWith","_options_router","generateRouteTypes","router","ignoredRouteFiles","watcher","addListener"],"sources":["../../../../src/vite/plugins/generateFileSystemRouteTypesPlugin.tsx"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,0CAAA;AAAAC,QAAA,CAAAD,0CAAA;EAAAE,kCAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAT,YAAqB,CAAAK,0CACI;AAMlB,IAAAK,WAAS,GAAAC,OAAA;EAAAC,uBAAuE,GAAAD,OAAA;EAAAE,yBAAA,GAAAF,OAAA;EAAAG,kCAAA,GAAAH,OAAA;AACrF,SAAOJ,mCAAAQ,OAAA;EAAA,OACL;IACAC,IAAA,+BAAS;IACTC,OAAO;IAEPC,KAAA;IACEC,eAAMA,CAAAC,MAAS;MAQb,IAAIC,MAAA,GAAS,IAAAX,WAAS,CAAAY,IAAS,EAAAC,OAAA,CACzBC,GAAA,EAAK,MAAAV,kCAEP,CAAAW,2BAAA,EAAAV,OAAmB;QAASW,OAAA,KAAY,EAAAhB,WAAQ,CAAAY,IAAQ,EAAAC,OAAA,CAAAC,GAAA,EAAiB;QAAAG,UAAA,OAAAb,kCAAA,CAAAW,2BAAA,EAAAV,OAAA;QAAAa,yBAAA,OAAAhB,uBAAA,CAAAiB,QAAA,kBAAAC,IAAA,EAAAC,IAAA;UAG/E,IAAM,CAAAD,IAAA,cAAAA,IAAA,kBAAAC,IAAA,CAAAC,UAAA,CAAAX,MAAA;YAEN,IAAAY,eAAe;YAKb,IAAApB,yBAAA,CAAAqB,kBAAmB,EAAAR,OAAS,EAAAC,UAAY,GAAAM,eAAgB,GAAAlB,OAAA,CAAAoB,MAAiB,cAAAF,eAAA,uBAAAA,eAAA,CAAAG,iBAAA;UAC3E;QACF;MACF,OAAAhB,MAAA,CAAAiB,OAAA,CAAAC,WAAA,QAAAV,yBAAA;QACF,IAAAK,eAAA","ignoreList":[]}
@@ -1,6 +1,6 @@
1
1
  import FSExtra from "fs-extra";
2
- import { writeFile } from "node:fs/promises";
3
- import { dirname } from "node:path";
2
+ import { writeFile, readFile } from "node:fs/promises";
3
+ import { dirname, join } from "node:path";
4
4
  import micromatch from "micromatch";
5
5
  import { globbedRoutesToRouteContext } from "../router/useViteRoutes";
6
6
  import { globDir } from "../utils/globDir";
@@ -11,8 +11,26 @@ async function generateRouteTypes(outFile, routerRoot, ignoredRouteFiles) {
11
11
  // The path starts with './', such as './foo/bar/baz.test.tsx', and ignoredRouteFiles is like ['**/*.test.*'], so we need matchBase here.
12
12
  matchBase: !0
13
13
  }));
14
- const routes = routePaths.reduce((acc, cur) => (acc[cur] = {}, acc), {}), context = globbedRoutesToRouteContext(routes, routerRoot), declarations = getTypedRoutesDeclarationFile(context);
15
- await FSExtra.ensureDir(dirname(outFile)), await writeFile(outFile, declarations);
14
+ const routes = routePaths.reduce((acc, cur) => (acc[cur] = {}, acc), {}), context = globbedRoutesToRouteContext(routes, routerRoot), declarations = getTypedRoutesDeclarationFile(context), outDir = dirname(outFile);
15
+ if (await FSExtra.ensureDir(outDir), await writeFile(outFile, declarations), outFile.includes("node_modules/@types/one-routes")) {
16
+ const packageJsonPath = join(outDir, "package.json");
17
+ await writeFile(packageJsonPath, JSON.stringify({
18
+ name: "@types/one-routes",
19
+ version: "1.0.0",
20
+ private: !0,
21
+ types: "index.d.ts"
22
+ }, null, 2)), await ensureTsconfigIncludesOneRoutes(outDir);
23
+ }
24
+ }
25
+ async function ensureTsconfigIncludesOneRoutes(typesDir) {
26
+ const projectRoot = join(typesDir, "../../.."), tsconfigPath = join(projectRoot, "tsconfig.json");
27
+ try {
28
+ const tsconfigContent = await readFile(tsconfigPath, "utf-8"), tsconfig = JSON.parse(tsconfigContent);
29
+ tsconfig.compilerOptions?.types && Array.isArray(tsconfig.compilerOptions.types) && (tsconfig.compilerOptions.types.includes("one-routes") || (tsconfig.compilerOptions.types.push("one-routes"), await writeFile(tsconfigPath, JSON.stringify(tsconfig, null, 2) + `
30
+ `)));
31
+ } catch (error) {
32
+ console.warn("Could not update tsconfig.json:", error);
33
+ }
16
34
  }
17
35
  export {
18
36
  generateRouteTypes
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/typed-routes/generateRouteTypes.ts"],
4
- "mappings": "AAAA,OAAO,aAAa;AACpB,SAAS,iBAAiB;AAC1B,SAAS,eAAe;AACxB,OAAO,gBAAgB;AACvB,SAAS,mCAAmC;AAC5C,SAAS,eAAe;AACxB,SAAS,qCAAqC;AAE9C,eAAsB,mBACpB,SACA,YACA,mBACA;AACA,MAAI,aAAa,QAAQ,UAAU;AACnC,EAAI,qBAAqB,kBAAkB,SAAS,MAClD,aAAa,WAAW,IAAI,YAAY,mBAAmB;AAAA;AAAA,IAEzD,WAAW;AAAA,EACb,CAAC;AAEH,QAAM,SAAS,WAAW,OAAO,CAAC,KAAK,SACrC,IAAI,GAAG,IAAI,CAAC,GACL,MACN,CAAC,CAAC,GACC,UAAU,4BAA4B,QAAQ,UAAU,GACxD,eAAe,8BAA8B,OAAO;AAC1D,QAAM,QAAQ,UAAU,QAAQ,OAAO,CAAC,GACxC,MAAM,UAAU,SAAS,YAAY;AACvC;",
4
+ "mappings": "AAAA,OAAO,aAAa;AACpB,SAAS,WAAW,gBAAgB;AACpC,SAAS,SAAS,YAAY;AAC9B,OAAO,gBAAgB;AACvB,SAAS,mCAAmC;AAC5C,SAAS,eAAe;AACxB,SAAS,qCAAqC;AAE9C,eAAsB,mBACpB,SACA,YACA,mBACA;AACA,MAAI,aAAa,QAAQ,UAAU;AACnC,EAAI,qBAAqB,kBAAkB,SAAS,MAClD,aAAa,WAAW,IAAI,YAAY,mBAAmB;AAAA;AAAA,IAEzD,WAAW;AAAA,EACb,CAAC;AAEH,QAAM,SAAS,WAAW,OAAO,CAAC,KAAK,SACrC,IAAI,GAAG,IAAI,CAAC,GACL,MACN,CAAC,CAAC,GACC,UAAU,4BAA4B,QAAQ,UAAU,GACxD,eAAe,8BAA8B,OAAO,GACpD,SAAS,QAAQ,OAAO;AAK9B,MAJA,MAAM,QAAQ,UAAU,MAAM,GAC9B,MAAM,UAAU,SAAS,YAAY,GAGjC,QAAQ,SAAS,gCAAgC,GAAG;AACtD,UAAM,kBAAkB,KAAK,QAAQ,cAAc;AAOnD,UAAM,UAAU,iBAAiB,KAAK,UANlB;AAAA,MAClB,MAAM;AAAA,MACN,SAAS;AAAA,MACT,SAAS;AAAA,MACT,OAAO;AAAA,IACT,GAC6D,MAAM,CAAC,CAAC,GACrE,MAAM,gCAAgC,MAAM;AAAA,EAC9C;AACF;AAEA,eAAe,gCAAgC,UAAkB;AAC/D,QAAM,cAAc,KAAK,UAAU,UAAU,GACvC,eAAe,KAAK,aAAa,eAAe;AAEtD,MAAI;AACF,UAAM,kBAAkB,MAAM,SAAS,cAAc,OAAO,GACtD,WAAW,KAAK,MAAM,eAAe;AAI3C,IAAI,SAAS,iBAAiB,SAAS,MAAM,QAAQ,SAAS,gBAAgB,KAAK,MAC5E,SAAS,gBAAgB,MAAM,SAAS,YAAY,MACvD,SAAS,gBAAgB,MAAM,KAAK,YAAY,GAChD,MAAM,UAAU,cAAc,KAAK,UAAU,UAAU,MAAM,CAAC,IAAI;AAAA,CAAI;AAAA,EAG5E,SAAS,OAAO;AAEd,YAAQ,KAAK,mCAAmC,KAAK;AAAA,EACvD;AACF;",
5
5
  "names": []
6
6
  }
@@ -1,6 +1,6 @@
1
1
  import FSExtra from "fs-extra";
2
- import { writeFile } from "node:fs/promises";
3
- import { dirname } from "node:path";
2
+ import { writeFile, readFile } from "node:fs/promises";
3
+ import { dirname, join } from "node:path";
4
4
  import micromatch from "micromatch";
5
5
  import { globbedRoutesToRouteContext } from "../router/useViteRoutes.mjs";
6
6
  import { globDir } from "../utils/globDir.mjs";
@@ -13,8 +13,29 @@ async function generateRouteTypes(outFile, routerRoot, ignoredRouteFiles) {
13
13
  }));
14
14
  const routes = routePaths.reduce((acc, cur) => (acc[cur] = {}, acc), {}),
15
15
  context = globbedRoutesToRouteContext(routes, routerRoot),
16
- declarations = getTypedRoutesDeclarationFile(context);
17
- await FSExtra.ensureDir(dirname(outFile)), await writeFile(outFile, declarations);
16
+ declarations = getTypedRoutesDeclarationFile(context),
17
+ outDir = dirname(outFile);
18
+ if (await FSExtra.ensureDir(outDir), await writeFile(outFile, declarations), outFile.includes("node_modules/@types/one-routes")) {
19
+ const packageJsonPath = join(outDir, "package.json");
20
+ await writeFile(packageJsonPath, JSON.stringify({
21
+ name: "@types/one-routes",
22
+ version: "1.0.0",
23
+ private: !0,
24
+ types: "index.d.ts"
25
+ }, null, 2)), await ensureTsconfigIncludesOneRoutes(outDir);
26
+ }
27
+ }
28
+ async function ensureTsconfigIncludesOneRoutes(typesDir) {
29
+ const projectRoot = join(typesDir, "../../.."),
30
+ tsconfigPath = join(projectRoot, "tsconfig.json");
31
+ try {
32
+ const tsconfigContent = await readFile(tsconfigPath, "utf-8"),
33
+ tsconfig = JSON.parse(tsconfigContent);
34
+ tsconfig.compilerOptions?.types && Array.isArray(tsconfig.compilerOptions.types) && (tsconfig.compilerOptions.types.includes("one-routes") || (tsconfig.compilerOptions.types.push("one-routes"), await writeFile(tsconfigPath, JSON.stringify(tsconfig, null, 2) + `
35
+ `)));
36
+ } catch (error) {
37
+ console.warn("Could not update tsconfig.json:", error);
38
+ }
18
39
  }
19
40
  export { generateRouteTypes };
20
41
  //# sourceMappingURL=generateRouteTypes.mjs.map
@@ -1 +1 @@
1
- {"version":3,"names":["FSExtra","writeFile","dirname","micromatch","globbedRoutesToRouteContext","globDir","getTypedRoutesDeclarationFile","generateRouteTypes","outFile","routerRoot","ignoredRouteFiles","routePaths","length","not","matchBase","routes","reduce","acc","cur","context","declarations","ensureDir"],"sources":["../../../src/typed-routes/generateRouteTypes.ts"],"sourcesContent":[null],"mappings":"AAAA,OAAOA,OAAA,MAAa;AACpB,SAASC,SAAA,QAAiB;AAC1B,SAASC,OAAA,QAAe;AACxB,OAAOC,UAAA,MAAgB;AACvB,SAASC,2BAAA,QAAmC;AAC5C,SAASC,OAAA,QAAe;AACxB,SAASC,6BAAA,QAAqC;AAE9C,eAAsBC,mBACpBC,OAAA,EACAC,UAAA,EACAC,iBAAA,EACA;EACA,IAAIC,UAAA,GAAaN,OAAA,CAAQI,UAAU;EAC/BC,iBAAA,IAAqBA,iBAAA,CAAkBE,MAAA,GAAS,MAClDD,UAAA,GAAaR,UAAA,CAAWU,GAAA,CAAIF,UAAA,EAAYD,iBAAA,EAAmB;IAAA;IAEzDI,SAAA,EAAW;EACb,CAAC;EAEH,MAAMC,MAAA,GAASJ,UAAA,CAAWK,MAAA,CAAO,CAACC,GAAA,EAAKC,GAAA,MACrCD,GAAA,CAAIC,GAAG,IAAI,CAAC,GACLD,GAAA,GACN,CAAC,CAAC;IACCE,OAAA,GAAUf,2BAAA,CAA4BW,MAAA,EAAQN,UAAU;IACxDW,YAAA,GAAed,6BAAA,CAA8Ba,OAAO;EAC1D,MAAMnB,OAAA,CAAQqB,SAAA,CAAUnB,OAAA,CAAQM,OAAO,CAAC,GACxC,MAAMP,SAAA,CAAUO,OAAA,EAASY,YAAY;AACvC","ignoreList":[]}
1
+ {"version":3,"names":["FSExtra","writeFile","readFile","dirname","join","micromatch","globbedRoutesToRouteContext","globDir","getTypedRoutesDeclarationFile","generateRouteTypes","outFile","routerRoot","ignoredRouteFiles","routePaths","length","not","matchBase","routes","reduce","acc","cur","context","declarations","outDir","ensureDir","includes","packageJsonPath","JSON","stringify","name","version","private","types","ensureTsconfigIncludesOneRoutes","typesDir","projectRoot","tsconfigPath","tsconfigContent","tsconfig","parse","compilerOptions","Array","isArray","push","error","console","warn"],"sources":["../../../src/typed-routes/generateRouteTypes.ts"],"sourcesContent":[null],"mappings":"AAAA,OAAOA,OAAA,MAAa;AACpB,SAASC,SAAA,EAAWC,QAAA,QAAgB;AACpC,SAASC,OAAA,EAASC,IAAA,QAAY;AAC9B,OAAOC,UAAA,MAAgB;AACvB,SAASC,2BAAA,QAAmC;AAC5C,SAASC,OAAA,QAAe;AACxB,SAASC,6BAAA,QAAqC;AAE9C,eAAsBC,mBACpBC,OAAA,EACAC,UAAA,EACAC,iBAAA,EACA;EACA,IAAIC,UAAA,GAAaN,OAAA,CAAQI,UAAU;EAC/BC,iBAAA,IAAqBA,iBAAA,CAAkBE,MAAA,GAAS,MAClDD,UAAA,GAAaR,UAAA,CAAWU,GAAA,CAAIF,UAAA,EAAYD,iBAAA,EAAmB;IAAA;IAEzDI,SAAA,EAAW;EACb,CAAC;EAEH,MAAMC,MAAA,GAASJ,UAAA,CAAWK,MAAA,CAAO,CAACC,GAAA,EAAKC,GAAA,MACrCD,GAAA,CAAIC,GAAG,IAAI,CAAC,GACLD,GAAA,GACN,CAAC,CAAC;IACCE,OAAA,GAAUf,2BAAA,CAA4BW,MAAA,EAAQN,UAAU;IACxDW,YAAA,GAAed,6BAAA,CAA8Ba,OAAO;IACpDE,MAAA,GAASpB,OAAA,CAAQO,OAAO;EAK9B,IAJA,MAAMV,OAAA,CAAQwB,SAAA,CAAUD,MAAM,GAC9B,MAAMtB,SAAA,CAAUS,OAAA,EAASY,YAAY,GAGjCZ,OAAA,CAAQe,QAAA,CAAS,gCAAgC,GAAG;IACtD,MAAMC,eAAA,GAAkBtB,IAAA,CAAKmB,MAAA,EAAQ,cAAc;IAOnD,MAAMtB,SAAA,CAAUyB,eAAA,EAAiBC,IAAA,CAAKC,SAAA,CANlB;MAClBC,IAAA,EAAM;MACNC,OAAA,EAAS;MACTC,OAAA,EAAS;MACTC,KAAA,EAAO;IACT,GAC6D,MAAM,CAAC,CAAC,GACrE,MAAMC,+BAAA,CAAgCV,MAAM;EAC9C;AACF;AAEA,eAAeU,gCAAgCC,QAAA,EAAkB;EAC/D,MAAMC,WAAA,GAAc/B,IAAA,CAAK8B,QAAA,EAAU,UAAU;IACvCE,YAAA,GAAehC,IAAA,CAAK+B,WAAA,EAAa,eAAe;EAEtD,IAAI;IACF,MAAME,eAAA,GAAkB,MAAMnC,QAAA,CAASkC,YAAA,EAAc,OAAO;MACtDE,QAAA,GAAWX,IAAA,CAAKY,KAAA,CAAMF,eAAe;IAIvCC,QAAA,CAASE,eAAA,EAAiBR,KAAA,IAASS,KAAA,CAAMC,OAAA,CAAQJ,QAAA,CAASE,eAAA,CAAgBR,KAAK,MAC5EM,QAAA,CAASE,eAAA,CAAgBR,KAAA,CAAMP,QAAA,CAAS,YAAY,MACvDa,QAAA,CAASE,eAAA,CAAgBR,KAAA,CAAMW,IAAA,CAAK,YAAY,GAChD,MAAM1C,SAAA,CAAUmC,YAAA,EAAcT,IAAA,CAAKC,SAAA,CAAUU,QAAA,EAAU,MAAM,CAAC,IAAI;AAAA,CAAI;EAG5E,SAASM,KAAA,EAAO;IAEdC,OAAA,CAAQC,IAAA,CAAK,mCAAmCF,KAAK;EACvD;AACF","ignoreList":[]}
@@ -1,6 +1,6 @@
1
1
  import FSExtra from "fs-extra";
2
- import { writeFile } from "fs/promises";
3
- import { dirname } from "path";
2
+ import { writeFile, readFile } from "fs/promises";
3
+ import { dirname, join } from "path";
4
4
  import micromatch from "micromatch";
5
5
  import { globbedRoutesToRouteContext } from "../router/useViteRoutes.native.js";
6
6
  import { globDir } from "../utils/globDir.native.js";
@@ -15,8 +15,31 @@ async function generateRouteTypes(outFile, routerRoot, ignoredRouteFiles) {
15
15
  return acc[cur] = {}, acc;
16
16
  }, {}),
17
17
  context = globbedRoutesToRouteContext(routes, routerRoot),
18
- declarations = getTypedRoutesDeclarationFile(context);
19
- await FSExtra.ensureDir(dirname(outFile)), await writeFile(outFile, declarations);
18
+ declarations = getTypedRoutesDeclarationFile(context),
19
+ outDir = dirname(outFile);
20
+ if (await FSExtra.ensureDir(outDir), await writeFile(outFile, declarations), outFile.includes("node_modules/@types/one-routes")) {
21
+ var packageJsonPath = join(outDir, "package.json"),
22
+ packageJson = {
23
+ name: "@types/one-routes",
24
+ version: "1.0.0",
25
+ private: !0,
26
+ types: "index.d.ts"
27
+ };
28
+ await writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2)), await ensureTsconfigIncludesOneRoutes(outDir);
29
+ }
30
+ }
31
+ async function ensureTsconfigIncludesOneRoutes(typesDir) {
32
+ var projectRoot = join(typesDir, "../../.."),
33
+ tsconfigPath = join(projectRoot, "tsconfig.json");
34
+ try {
35
+ var _tsconfig_compilerOptions,
36
+ tsconfigContent = await readFile(tsconfigPath, "utf-8"),
37
+ tsconfig = JSON.parse(tsconfigContent);
38
+ !((_tsconfig_compilerOptions = tsconfig.compilerOptions) === null || _tsconfig_compilerOptions === void 0) && _tsconfig_compilerOptions.types && Array.isArray(tsconfig.compilerOptions.types) && (tsconfig.compilerOptions.types.includes("one-routes") || (tsconfig.compilerOptions.types.push("one-routes"), await writeFile(tsconfigPath, JSON.stringify(tsconfig, null, 2) + `
39
+ `)));
40
+ } catch (error) {
41
+ console.warn("Could not update tsconfig.json:", error);
42
+ }
20
43
  }
21
44
  export { generateRouteTypes };
22
45
  //# sourceMappingURL=generateRouteTypes.native.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["FSExtra","writeFile","dirname","micromatch","globbedRoutesToRouteContext","globDir","getTypedRoutesDeclarationFile","generateRouteTypes","outFile","routerRoot","ignoredRouteFiles","routePaths","length","not","matchBase","routes","reduce","acc","cur","context","declarations"],"sources":["../../../src/typed-routes/generateRouteTypes.ts"],"sourcesContent":[null],"mappings":"AAAA,OAAOA,OAAA,MAAa;AACpB,SAASC,SAAA,QAAiB;AAC1B,SAASC,OAAA,QAAe;AACxB,OAAOC,UAAA,MAAgB;AACvB,SAASC,2BAAA,QAAmC;AAC5C,SAASC,OAAA,QAAe;AACxB,SAASC,6BAAA,QAAqC;AAE9C,eAAsBC,mBACpBC,OAAA,EACAC,UAAA,EACAC,iBAAA,EACA;EACA,IAAIC,UAAA,GAAaN,OAAA,CAAQI,UAAU;EAC/BC,iBAAA,IAAqBA,iBAAA,CAAkBE,MAAA,GAAS,MAClDD,UAAA,GAAaR,UAAA,CAAWU,GAAA,CAAIF,UAAA,EAAYD,iBAAA,EAAmB;IAAA;IAEzDI,SAAA,EAAW;EACb,CAAC;EAEH,IAAAC,MAAM,GAAAJ,UAAS,CAAAK,MAAW,WAAaC,GAAA,EAAAC,GACrC;MAKF,OAAMD,GAAA,CAAAC,GAAQ,QAAUD,GAAA;IAE1B;IAAAE,OAAA,GAAAf,2BAAA,CAAAW,MAAA,EAAAN,UAAA;IAAAW,YAAA,GAAAd,6BAAA,CAAAa,OAAA","ignoreList":[]}
1
+ {"version":3,"names":["FSExtra","writeFile","readFile","dirname","join","micromatch","globbedRoutesToRouteContext","globDir","getTypedRoutesDeclarationFile","generateRouteTypes","outFile","routerRoot","ignoredRouteFiles","routePaths","length","not","matchBase","routes","reduce","acc","cur","context","declarations","outDir","ensureDir","includes","packageJsonPath","packageJson","name","version","private","types","JSON","stringify","ensureTsconfigIncludesOneRoutes","typesDir","projectRoot","tsconfigPath","_tsconfig_compilerOptions","tsconfigContent","tsconfig","parse","compilerOptions","Array","isArray","push","error","console","warn"],"sources":["../../../src/typed-routes/generateRouteTypes.ts"],"sourcesContent":[null],"mappings":"AAAA,OAAOA,OAAA,MAAa;AACpB,SAASC,SAAA,EAAWC,QAAA,QAAgB;AACpC,SAASC,OAAA,EAASC,IAAA,QAAY;AAC9B,OAAOC,UAAA,MAAgB;AACvB,SAASC,2BAAA,QAAmC;AAC5C,SAASC,OAAA,QAAe;AACxB,SAASC,6BAAA,QAAqC;AAE9C,eAAsBC,mBACpBC,OAAA,EACAC,UAAA,EACAC,iBAAA,EACA;EACA,IAAIC,UAAA,GAAaN,OAAA,CAAQI,UAAU;EAC/BC,iBAAA,IAAqBA,iBAAA,CAAkBE,MAAA,GAAS,MAClDD,UAAA,GAAaR,UAAA,CAAWU,GAAA,CAAIF,UAAA,EAAYD,iBAAA,EAAmB;IAAA;IAEzDI,SAAA,EAAW;EACb,CAAC;EAEH,IAAAC,MAAM,GAAAJ,UAAS,CAAAK,MAAW,WAAaC,GAAA,EAAAC,GACrC;MAUF,OAJAD,GAAM,CAAAC,GAAA,IAAQ,IAAAD,GAAA;IAKZ;IAAME,OAAA,GAAAf,2BAA+B,CAAAW,MAAA,EAAcN,UAAA;IAAAW,YAAA,GAAAd,6BAAA,CAAAa,OAAA;IAAAE,MAAA,GAAApB,OAAA,CAAAO,OAAA;EAOnD,UAAMV,OAAA,CAAUwB,SAAA,CAAAD,MAAA,CAAiB,QAAKtB,SANlB,CAAAS,OAAA,EAAAY,YAAA,GAAAZ,OAAA,CAAAe,QAAA;IAAA,IAClBC,eAAM,GAAAtB,IAAA,CAAAmB,MAAA;MAAAI,WAAA;QACNC,IAAA,qBAAS;QACTC,OAAA,EAAS;QACTC,OAAO;QACTC,KAC6D,EAAM;MAErE;IACF,MAAA9B,SAAA,CAAAyB,eAAA,EAAAM,IAAA,CAAAC,SAAA,CAAAN,WAAA,mBAAAO,+BAAA,CAAAX,MAAA;EAEA;AACE;AAGA,eAAIW,gCAAAC,QAAA;EACF,IAAAC,WAAM,GAAAhC,IAAA,CAAA+B,QAAkB,EAAM,UAAS;IAAAE,YAAc,GAAAjC,IAC/C,CAAAgC,WAAW,iBAAW;EAI5B,IAAI;IAGsE,IAAAE,yBAAA;MAAAC,eAAA,SAAArC,QAAA,CAAAmC,YAAA;MAAAG,QAAA,GAAAR,IAAA,CAAAS,KAAA,CAAAF,eAAA;IAG5E,GAAAD,yBAAgB,GAAAE,QAAA,CAAAE,eAAA,cAAAJ,yBAAA,gBAAAA,yBAAA,CAAAP,KAAA,IAAAY,KAAA,CAAAC,OAAA,CAAAJ,QAAA,CAAAE,eAAA,CAAAX,KAAA,MAAAS,QAAA,CAAAE,eAAA,CAAAX,KAAA,CAAAN,QAAA,mBAAAe,QAAA,CAAAE,eAAA,CAAAX,KAAA,CAAAc,IAAA,sBAAA5C,SAAA,CAAAoC,YAAA,EAAAL,IAAA,CAAAC,SAAA,CAAAO,QAAA;AAEd;EACF,SAAAM,KAAA;IACFC,OAAA,CAAAC,IAAA,oCAAAF,KAAA","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- import { dirname, join } from "node:path";
1
+ import { join } from "node:path";
2
2
  import { debounce } from "perfect-debounce";
3
3
  import { generateRouteTypes } from "../../typed-routes/generateRouteTypes";
4
4
  import { getRouterRootFromOneOptions } from "../../utils/getRouterRootFromOneOptions";
@@ -8,9 +8,7 @@ function generateFileSystemRouteTypesPlugin(options) {
8
8
  enforce: "post",
9
9
  apply: "serve",
10
10
  configureServer(server) {
11
- const appDir = join(process.cwd(), getRouterRootFromOneOptions(options)), outFile = dirname(appDir) !== process.cwd() ? (console.warn(
12
- "Seems that the router root has been customized and is in a nested folder. For now we will generate the routes.d.ts file beside the app folder. This behavior might be changed in the future."
13
- ), join(dirname(appDir), "routes.d.ts")) : join(process.cwd(), "routes.d.ts"), routerRoot = getRouterRootFromOneOptions(options), fileWatcherChangeListener = debounce(async (type, path) => {
11
+ const appDir = join(process.cwd(), getRouterRootFromOneOptions(options)), outFile = join(process.cwd(), "node_modules", "@types", "one-routes", "index.d.ts"), routerRoot = getRouterRootFromOneOptions(options), fileWatcherChangeListener = debounce(async (type, path) => {
14
12
  (type === "add" || type === "delete") && path.startsWith(appDir) && generateRouteTypes(outFile, routerRoot, options.router?.ignoredRouteFiles);
15
13
  }, 100);
16
14
  return server.watcher.addListener("all", fileWatcherChangeListener), () => {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/vite/plugins/generateFileSystemRouteTypesPlugin.tsx"],
4
- "mappings": "AAAA,SAAS,SAAS,YAAY;AAC9B,SAAS,gBAAgB;AAGzB,SAAS,0BAA0B;AACnC,SAAS,mCAAmC;AAErC,SAAS,mCAAmC,SAAoC;AACrF,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IACT,OAAO;AAAA,IAEP,gBAAgB,QAAQ;AACtB,YAAM,SAAS,KAAK,QAAQ,IAAI,GAAG,4BAA4B,OAAO,CAAC,GACjE,UACA,QAAQ,MAAM,MAAM,QAAQ,IAAI,KAClC,QAAQ;AAAA,QACN;AAAA,MACF,GACO,KAAK,QAAQ,MAAM,GAAG,aAAa,KAGrC,KAAK,QAAQ,IAAI,GAAG,aAAa,GAGpC,aAAa,4BAA4B,OAAO,GAGhD,4BAA4B,SAAS,OAAO,MAAc,SAAiB;AAC/E,SAAI,SAAS,SAAS,SAAS,aACzB,KAAK,WAAW,MAAM,KAExB,mBAAmB,SAAS,YAAY,QAAQ,QAAQ,iBAAiB;AAAA,MAG/E,GAAG,GAAG;AAEN,oBAAO,QAAQ,YAAY,OAAO,yBAAyB,GAEpD,MAAM;AAGX,2BAAmB,SAAS,YAAY,QAAQ,QAAQ,iBAAiB;AAAA,MAC3E;AAAA,IACF;AAAA,EACF;AACF;",
4
+ "mappings": "AAAA,SAAS,YAAY;AACrB,SAAS,gBAAgB;AAGzB,SAAS,0BAA0B;AACnC,SAAS,mCAAmC;AAErC,SAAS,mCAAmC,SAAoC;AACrF,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IACT,OAAO;AAAA,IAEP,gBAAgB,QAAQ;AACtB,YAAM,SAAS,KAAK,QAAQ,IAAI,GAAG,4BAA4B,OAAO,CAAC,GAEjE,UAAU,KAAK,QAAQ,IAAI,GAAG,gBAAgB,UAAU,cAAc,YAAY,GAElF,aAAa,4BAA4B,OAAO,GAGhD,4BAA4B,SAAS,OAAO,MAAc,SAAiB;AAC/E,SAAI,SAAS,SAAS,SAAS,aACzB,KAAK,WAAW,MAAM,KAExB,mBAAmB,SAAS,YAAY,QAAQ,QAAQ,iBAAiB;AAAA,MAG/E,GAAG,GAAG;AAEN,oBAAO,QAAQ,YAAY,OAAO,yBAAyB,GAEpD,MAAM;AAGX,2BAAmB,SAAS,YAAY,QAAQ,QAAQ,iBAAiB;AAAA,MAC3E;AAAA,IACF;AAAA,EACF;AACF;",
5
5
  "names": []
6
6
  }
@@ -1,4 +1,4 @@
1
- import { dirname, join } from "node:path";
1
+ import { join } from "node:path";
2
2
  import { debounce } from "perfect-debounce";
3
3
  import { generateRouteTypes } from "../../typed-routes/generateRouteTypes.mjs";
4
4
  import { getRouterRootFromOneOptions } from "../../utils/getRouterRootFromOneOptions.mjs";
@@ -9,7 +9,7 @@ function generateFileSystemRouteTypesPlugin(options) {
9
9
  apply: "serve",
10
10
  configureServer(server) {
11
11
  const appDir = join(process.cwd(), getRouterRootFromOneOptions(options)),
12
- outFile = dirname(appDir) !== process.cwd() ? (console.warn("Seems that the router root has been customized and is in a nested folder. For now we will generate the routes.d.ts file beside the app folder. This behavior might be changed in the future."), join(dirname(appDir), "routes.d.ts")) : join(process.cwd(), "routes.d.ts"),
12
+ outFile = join(process.cwd(), "node_modules", "@types", "one-routes", "index.d.ts"),
13
13
  routerRoot = getRouterRootFromOneOptions(options),
14
14
  fileWatcherChangeListener = debounce(async (type, path) => {
15
15
  (type === "add" || type === "delete") && path.startsWith(appDir) && generateRouteTypes(outFile, routerRoot, options.router?.ignoredRouteFiles);
@@ -1 +1 @@
1
- {"version":3,"names":["dirname","join","debounce","generateRouteTypes","getRouterRootFromOneOptions","generateFileSystemRouteTypesPlugin","options","name","enforce","apply","configureServer","server","appDir","process","cwd","outFile","console","warn","routerRoot","fileWatcherChangeListener","type","path","startsWith","router","ignoredRouteFiles","watcher","addListener"],"sources":["../../../../src/vite/plugins/generateFileSystemRouteTypesPlugin.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,OAAA,EAASC,IAAA,QAAY;AAC9B,SAASC,QAAA,QAAgB;AAGzB,SAASC,kBAAA,QAA0B;AACnC,SAASC,2BAAA,QAAmC;AAErC,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;QACjES,OAAA,GACAf,OAAA,CAAQY,MAAM,MAAMC,OAAA,CAAQC,GAAA,CAAI,KAClCE,OAAA,CAAQC,IAAA,CACN,8LACF,GACOhB,IAAA,CAAKD,OAAA,CAAQY,MAAM,GAAG,aAAa,KAGrCX,IAAA,CAAKY,OAAA,CAAQC,GAAA,CAAI,GAAG,aAAa;QAGpCI,UAAA,GAAad,2BAAA,CAA4BE,OAAO;QAGhDa,yBAAA,GAA4BjB,QAAA,CAAS,OAAOkB,IAAA,EAAcC,IAAA,KAAiB;UAC/E,CAAID,IAAA,KAAS,SAASA,IAAA,KAAS,aACzBC,IAAA,CAAKC,UAAA,CAAWV,MAAM,KAExBT,kBAAA,CAAmBY,OAAA,EAASG,UAAA,EAAYZ,OAAA,CAAQiB,MAAA,EAAQC,iBAAiB;QAG/E,GAAG,GAAG;MAEN,OAAAb,MAAA,CAAOc,OAAA,CAAQC,WAAA,CAAY,OAAOP,yBAAyB,GAEpD,MAAM;QAGXhB,kBAAA,CAAmBY,OAAA,EAASG,UAAA,EAAYZ,OAAA,CAAQiB,MAAA,EAAQC,iBAAiB;MAC3E;IACF;EACF;AACF","ignoreList":[]}
1
+ {"version":3,"names":["join","debounce","generateRouteTypes","getRouterRootFromOneOptions","generateFileSystemRouteTypesPlugin","options","name","enforce","apply","configureServer","server","appDir","process","cwd","outFile","routerRoot","fileWatcherChangeListener","type","path","startsWith","router","ignoredRouteFiles","watcher","addListener"],"sources":["../../../../src/vite/plugins/generateFileSystemRouteTypesPlugin.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,IAAA,QAAY;AACrB,SAASC,QAAA,QAAgB;AAGzB,SAASC,kBAAA,QAA0B;AACnC,SAASC,2BAAA,QAAmC;AAErC,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,CAAKY,OAAA,CAAQC,GAAA,CAAI,GAAG,gBAAgB,UAAU,cAAc,YAAY;QAElFE,UAAA,GAAaZ,2BAAA,CAA4BE,OAAO;QAGhDW,yBAAA,GAA4Bf,QAAA,CAAS,OAAOgB,IAAA,EAAcC,IAAA,KAAiB;UAC/E,CAAID,IAAA,KAAS,SAASA,IAAA,KAAS,aACzBC,IAAA,CAAKC,UAAA,CAAWR,MAAM,KAExBT,kBAAA,CAAmBY,OAAA,EAASC,UAAA,EAAYV,OAAA,CAAQe,MAAA,EAAQC,iBAAiB;QAG/E,GAAG,GAAG;MAEN,OAAAX,MAAA,CAAOY,OAAA,CAAQC,WAAA,CAAY,OAAOP,yBAAyB,GAEpD,MAAM;QAGXd,kBAAA,CAAmBY,OAAA,EAASC,UAAA,EAAYV,OAAA,CAAQe,MAAA,EAAQC,iBAAiB;MAC3E;IACF;EACF;AACF","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- import { dirname, join } from "path";
1
+ import { join } from "path";
2
2
  import { debounce } from "perfect-debounce";
3
3
  import { generateRouteTypes } from "../../typed-routes/generateRouteTypes.native.js";
4
4
  import { getRouterRootFromOneOptions } from "../../utils/getRouterRootFromOneOptions.native.js";
@@ -9,9 +9,7 @@ function generateFileSystemRouteTypesPlugin(options) {
9
9
  apply: "serve",
10
10
  configureServer(server) {
11
11
  var appDir = join(process.cwd(), getRouterRootFromOneOptions(options)),
12
- outFile = function () {
13
- return dirname(appDir) !== process.cwd() ? (console.warn("Seems that the router root has been customized and is in a nested folder. For now we will generate the routes.d.ts file beside the app folder. This behavior might be changed in the future."), join(dirname(appDir), "routes.d.ts")) : join(process.cwd(), "routes.d.ts");
14
- }(),
12
+ outFile = join(process.cwd(), "node_modules", "@types", "one-routes", "index.d.ts"),
15
13
  routerRoot = getRouterRootFromOneOptions(options),
16
14
  fileWatcherChangeListener = debounce(async function (type, path) {
17
15
  if ((type === "add" || type === "delete") && path.startsWith(appDir)) {
@@ -1 +1 @@
1
- {"version":3,"names":["dirname","join","debounce","generateRouteTypes","getRouterRootFromOneOptions","generateFileSystemRouteTypesPlugin","options","name","enforce","apply","configureServer","server","appDir","process","cwd","outFile","console","warn","routerRoot","fileWatcherChangeListener","type","path","startsWith","_options_router","router","ignoredRouteFiles","watcher","addListener"],"sources":["../../../../src/vite/plugins/generateFileSystemRouteTypesPlugin.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,OAAA,EAASC,IAAA,QAAY;AAC9B,SAASC,QAAA,QAAgB;AAGzB,SAASC,kBAAA,QAA0B;AACnC,SAASC,2BAAA,QAAmC;AAErC,SAASC,mCAAmCC,OAAA,EAAoC;EACrF,OAAO;IACLC,IAAA,EAAM;IACNC,OAAA,EAAS;IACTC,KAAA,EAAO;IAEPC,gBAAgBC,MAAA,EAAQ;MACtB,IAAAC,MAAM,GAAAX,IAAS,CAAAY,OAAK,CAAAC,GAAQ,IAAIV,2BAAG,CAAAE,OAA4B,EAAO;QAACS,OACjE,eACQ;UAER,OAAAf,OAAA,CAAAY,MAAA,MAAAC,OAAA,CAAAC,GAAA,MAAAE,OAAA,CAAAC,IAAA,kMAAAhB,IAAA,CAAAD,OAAA,CAAAY,MAAA,qBAAAX,IAAA,CAAAY,OAAA,CAAAC,GAAA;QACF,EACO;QAAAI,UAAa,GAAAd,2BAGf,CAAAE,OAAK;QAAQa,yBAGhB,GAAAjB,QAAa,iBAAAkB,IAAA,EAAAC,IAAA,EAA4B;UAI7C,IAAI,CAAAD,IAAA,KAAS,KAAS,IAAAA,IAAA,KAAS,aACzBC,IAAK,CAAAC,UAAW,CAAAV,MAAM,CAExB;YAGH,IAAGW,eAAA;YAENpB,kBAAe,CAAAY,OAAA,EAAAG,UAAmB,GAAAK,eAAA,GAAAjB,OAE3B,CAAAkB,MAAM,cAAAD,eAAA,uBAAAA,eAAA,CAAAE,iBAAA;UAGX;QACF;MACF,OAAAd,MAAA,CAAAe,OAAA,CAAAC,WAAA,QAAAR,yBAAA;QACF,IAAAI,eAAA;QACFpB,kBAAA,CAAAY,OAAA,EAAAG,UAAA,GAAAK,eAAA,GAAAjB,OAAA,CAAAkB,MAAA,cAAAD,eAAA,uBAAAA,eAAA,CAAAE,iBAAA","ignoreList":[]}
1
+ {"version":3,"names":["join","debounce","generateRouteTypes","getRouterRootFromOneOptions","generateFileSystemRouteTypesPlugin","options","name","enforce","apply","configureServer","server","appDir","process","cwd","outFile","routerRoot","fileWatcherChangeListener","type","path","startsWith","_options_router","router","ignoredRouteFiles","watcher","addListener"],"sources":["../../../../src/vite/plugins/generateFileSystemRouteTypesPlugin.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,IAAA,QAAY;AACrB,SAASC,QAAA,QAAgB;AAGzB,SAASC,kBAAA,QAA0B;AACnC,SAASC,2BAAA,QAAmC;AAErC,SAASC,mCAAmCC,OAAA,EAAoC;EACrF,OAAO;IACLC,IAAA,EAAM;IACNC,OAAA,EAAS;IACTC,KAAA,EAAO;IAEPC,gBAAgBC,MAAA,EAAQ;MACtB,IAAAC,MAAM,GAAAX,IAAS,CAAAY,OAAK,CAAAC,GAAQ,IAAIV,2BAAG,CAAAE,OAA4B,EAAO;QAACS,OAEjE,GAAAd,IAAU,CAAAY,OAAK,CAAAC,GAAQ,IAAI,cAAG,UAAgB,cAAU,cAAc;QAAYE,UAElF,GAAAZ,2BAAa,CAAAE,OAA4B;QAAOW,yBAGhD,GAAAf,QAA4B,iBAA8BgB,IAAA,EAAAC,IAAiB;UAC/E,IAAI,CAAAD,IAAA,KAAS,KAAS,IAAAA,IAAA,KAAS,aACzBC,IAAK,CAAAC,UAAW,CAAAR,MAAM,CAExB;YAGH,IAAGS,eAAA;YAENlB,kBAAe,CAAAY,OAAA,EAAAC,UAAmB,GAAAK,eAAA,GAAAf,OAE3B,CAAAgB,MAAM,cAAAD,eAAA,uBAAAA,eAAA,CAAAE,iBAAA;UAGX;QACF;MACF,OAAAZ,MAAA,CAAAa,OAAA,CAAAC,WAAA,QAAAR,yBAAA;QACF,IAAAI,eAAA;QACFlB,kBAAA,CAAAY,OAAA,EAAAC,UAAA,GAAAK,eAAA,GAAAf,OAAA,CAAAgB,MAAA,cAAAD,eAAA,uBAAAA,eAAA,CAAAE,iBAAA","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "one",
3
- "version": "1.1.539",
3
+ "version": "1.1.540",
4
4
  "license": "BSD-3-Clause",
5
5
  "sideEffects": [
6
6
  "setup.mjs",
@@ -111,17 +111,17 @@
111
111
  "@react-navigation/routers": "~7.3.2",
112
112
  "@swc/core": "^1.10.4",
113
113
  "@ungap/structured-clone": "^1.2.0",
114
- "@vxrn/compiler": "1.1.539",
115
- "@vxrn/resolve": "1.1.539",
116
- "@vxrn/tslib-lite": "1.1.539",
117
- "@vxrn/universal-color-scheme": "1.1.539",
118
- "@vxrn/use-isomorphic-layout-effect": "1.1.539",
119
- "@vxrn/vite-plugin-metro": "1.1.539",
114
+ "@vxrn/compiler": "1.1.540",
115
+ "@vxrn/resolve": "1.1.540",
116
+ "@vxrn/tslib-lite": "1.1.540",
117
+ "@vxrn/universal-color-scheme": "1.1.540",
118
+ "@vxrn/use-isomorphic-layout-effect": "1.1.540",
119
+ "@vxrn/vite-plugin-metro": "1.1.540",
120
120
  "babel-dead-code-elimination": "^1.0.9",
121
121
  "babel-plugin-module-resolver": "^5",
122
122
  "citty": "^0.1.6",
123
123
  "core-js": "^3.38.1",
124
- "create-vxrn": "1.1.539",
124
+ "create-vxrn": "1.1.540",
125
125
  "escape-string-regexp": "^5.0.0",
126
126
  "expo-linking": "~6.3.1",
127
127
  "expo-modules-core": "~2.5.0",
@@ -146,7 +146,7 @@
146
146
  "vite": "^7.1.12",
147
147
  "vite-plugin-barrel": "^0.4.1",
148
148
  "vite-tsconfig-paths": "^5.1.4",
149
- "vxrn": "1.1.539",
149
+ "vxrn": "1.1.540",
150
150
  "ws": "^8.18.0",
151
151
  "xxhashjs": "^0.2.2"
152
152
  },
@@ -1,6 +1,6 @@
1
1
  import FSExtra from 'fs-extra'
2
- import { writeFile } from 'node:fs/promises'
3
- import { dirname } from 'node:path'
2
+ import { writeFile, readFile } from 'node:fs/promises'
3
+ import { dirname, join } from 'node:path'
4
4
  import micromatch from 'micromatch'
5
5
  import { globbedRoutesToRouteContext } from '../router/useViteRoutes'
6
6
  import { globDir } from '../utils/globDir'
@@ -24,6 +24,42 @@ export async function generateRouteTypes(
24
24
  }, {})
25
25
  const context = globbedRoutesToRouteContext(routes, routerRoot)
26
26
  const declarations = getTypedRoutesDeclarationFile(context)
27
- await FSExtra.ensureDir(dirname(outFile))
27
+ const outDir = dirname(outFile)
28
+ await FSExtra.ensureDir(outDir)
28
29
  await writeFile(outFile, declarations)
30
+
31
+ // If generating in node_modules/@types/one-routes, create package.json and update tsconfig
32
+ if (outFile.includes('node_modules/@types/one-routes')) {
33
+ const packageJsonPath = join(outDir, 'package.json')
34
+ const packageJson = {
35
+ name: '@types/one-routes',
36
+ version: '1.0.0',
37
+ private: true,
38
+ types: 'index.d.ts',
39
+ }
40
+ await writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2))
41
+ await ensureTsconfigIncludesOneRoutes(outDir)
42
+ }
43
+ }
44
+
45
+ async function ensureTsconfigIncludesOneRoutes(typesDir: string) {
46
+ const projectRoot = join(typesDir, '../../..')
47
+ const tsconfigPath = join(projectRoot, 'tsconfig.json')
48
+
49
+ try {
50
+ const tsconfigContent = await readFile(tsconfigPath, 'utf-8')
51
+ const tsconfig = JSON.parse(tsconfigContent)
52
+
53
+ // Add one-routes to the types array if it exists
54
+ // This ensures TypeScript picks up the types even when types array is specified
55
+ if (tsconfig.compilerOptions?.types && Array.isArray(tsconfig.compilerOptions.types)) {
56
+ if (!tsconfig.compilerOptions.types.includes('one-routes')) {
57
+ tsconfig.compilerOptions.types.push('one-routes')
58
+ await writeFile(tsconfigPath, JSON.stringify(tsconfig, null, 2) + '\n')
59
+ }
60
+ }
61
+ } catch (error) {
62
+ // Ignore errors - tsconfig might not exist or might be malformed
63
+ console.warn('Could not update tsconfig.json:', error)
64
+ }
29
65
  }
@@ -1,4 +1,4 @@
1
- import { dirname, join } from 'node:path'
1
+ import { join } from 'node:path'
2
2
  import { debounce } from 'perfect-debounce'
3
3
  import type { Plugin } from 'vite'
4
4
  import type { One } from '../types'
@@ -13,16 +13,8 @@ export function generateFileSystemRouteTypesPlugin(options: One.PluginOptions):
13
13
 
14
14
  configureServer(server) {
15
15
  const appDir = join(process.cwd(), getRouterRootFromOneOptions(options))
16
- const outFile = (() => {
17
- if (dirname(appDir) !== process.cwd()) {
18
- console.warn(
19
- 'Seems that the router root has been customized and is in a nested folder. For now we will generate the routes.d.ts file beside the app folder. This behavior might be changed in the future.'
20
- )
21
- return join(dirname(appDir), 'routes.d.ts')
22
- }
23
-
24
- return join(process.cwd(), 'routes.d.ts')
25
- })()
16
+ // Generate types in node_modules/@types/one-routes to keep them out of the source tree
17
+ const outFile = join(process.cwd(), 'node_modules', '@types', 'one-routes', 'index.d.ts')
26
18
 
27
19
  const routerRoot = getRouterRootFromOneOptions(options)
28
20
 
@@ -1 +1 @@
1
- {"version":3,"file":"generateRouteTypes.d.ts","sourceRoot":"","sources":["../../src/typed-routes/generateRouteTypes.ts"],"names":[],"mappings":"AAQA,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,iBAAiB,CAAC,EAAE,MAAM,EAAE,iBAiB7B"}
1
+ {"version":3,"file":"generateRouteTypes.d.ts","sourceRoot":"","sources":["../../src/typed-routes/generateRouteTypes.ts"],"names":[],"mappings":"AAQA,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,iBAAiB,CAAC,EAAE,MAAM,EAAE,iBA+B7B"}
@@ -1 +1 @@
1
- {"version":3,"file":"generateFileSystemRouteTypesPlugin.d.ts","sourceRoot":"","sources":["../../../src/vite/plugins/generateFileSystemRouteTypesPlugin.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAClC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAInC,wBAAgB,kCAAkC,CAAC,OAAO,EAAE,GAAG,CAAC,aAAa,GAAG,MAAM,CAwCrF"}
1
+ {"version":3,"file":"generateFileSystemRouteTypesPlugin.d.ts","sourceRoot":"","sources":["../../../src/vite/plugins/generateFileSystemRouteTypesPlugin.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAClC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAInC,wBAAgB,kCAAkC,CAAC,OAAO,EAAE,GAAG,CAAC,aAAa,GAAG,MAAM,CAgCrF"}