one 1.2.16 → 1.2.17

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 (125) hide show
  1. package/dist/cjs/cli/generateRoutes.cjs +20 -5
  2. package/dist/cjs/cli/generateRoutes.js +18 -3
  3. package/dist/cjs/cli/generateRoutes.js.map +1 -1
  4. package/dist/cjs/cli/generateRoutes.native.js +30 -5
  5. package/dist/cjs/cli/generateRoutes.native.js.map +1 -1
  6. package/dist/cjs/cli.cjs +4 -0
  7. package/dist/cjs/cli.js +4 -0
  8. package/dist/cjs/cli.js.map +1 -1
  9. package/dist/cjs/cli.native.js +4 -0
  10. package/dist/cjs/cli.native.js.map +1 -1
  11. package/dist/cjs/index.js.map +1 -1
  12. package/dist/cjs/index.native.js.map +1 -1
  13. package/dist/cjs/router/createRoute.cjs +12 -1
  14. package/dist/cjs/router/createRoute.js +12 -1
  15. package/dist/cjs/router/createRoute.js.map +1 -1
  16. package/dist/cjs/router/createRoute.native.js +13 -2
  17. package/dist/cjs/router/createRoute.native.js.map +1 -1
  18. package/dist/cjs/typed-routes/generateRouteTypes.cjs +14 -3
  19. package/dist/cjs/typed-routes/generateRouteTypes.js +12 -3
  20. package/dist/cjs/typed-routes/generateRouteTypes.js.map +1 -1
  21. package/dist/cjs/typed-routes/generateRouteTypes.native.js +29 -3
  22. package/dist/cjs/typed-routes/generateRouteTypes.native.js.map +1 -1
  23. package/dist/cjs/typed-routes/getTypedRoutesDeclarationFile.cjs +39 -2
  24. package/dist/cjs/typed-routes/getTypedRoutesDeclarationFile.js +38 -2
  25. package/dist/cjs/typed-routes/getTypedRoutesDeclarationFile.js.map +1 -1
  26. package/dist/cjs/typed-routes/getTypedRoutesDeclarationFile.native.js +40 -2
  27. package/dist/cjs/typed-routes/getTypedRoutesDeclarationFile.native.js.map +1 -1
  28. package/dist/cjs/typed-routes/injectRouteHelpers.cjs +136 -0
  29. package/dist/cjs/typed-routes/injectRouteHelpers.js +104 -0
  30. package/dist/cjs/typed-routes/injectRouteHelpers.js.map +6 -0
  31. package/dist/cjs/typed-routes/injectRouteHelpers.native.js +146 -0
  32. package/dist/cjs/typed-routes/injectRouteHelpers.native.js.map +1 -0
  33. package/dist/cjs/vite/loadConfig.cjs +18 -12
  34. package/dist/cjs/vite/loadConfig.js +20 -13
  35. package/dist/cjs/vite/loadConfig.js.map +1 -1
  36. package/dist/cjs/vite/loadConfig.native.js +18 -11
  37. package/dist/cjs/vite/loadConfig.native.js.map +1 -1
  38. package/dist/cjs/vite/plugins/generateFileSystemRouteTypesPlugin.cjs +3 -2
  39. package/dist/cjs/vite/plugins/generateFileSystemRouteTypesPlugin.js +13 -3
  40. package/dist/cjs/vite/plugins/generateFileSystemRouteTypesPlugin.js.map +1 -1
  41. package/dist/cjs/vite/plugins/generateFileSystemRouteTypesPlugin.native.js +9 -6
  42. package/dist/cjs/vite/plugins/generateFileSystemRouteTypesPlugin.native.js.map +1 -1
  43. package/dist/esm/cli/generateRoutes.js +19 -2
  44. package/dist/esm/cli/generateRoutes.js.map +1 -1
  45. package/dist/esm/cli/generateRoutes.mjs +19 -4
  46. package/dist/esm/cli/generateRoutes.mjs.map +1 -1
  47. package/dist/esm/cli/generateRoutes.native.js +29 -4
  48. package/dist/esm/cli/generateRoutes.native.js.map +1 -1
  49. package/dist/esm/cli.js +4 -0
  50. package/dist/esm/cli.js.map +1 -1
  51. package/dist/esm/cli.mjs +4 -0
  52. package/dist/esm/cli.mjs.map +1 -1
  53. package/dist/esm/cli.native.js +4 -0
  54. package/dist/esm/cli.native.js.map +1 -1
  55. package/dist/esm/index.js.map +1 -1
  56. package/dist/esm/index.mjs.map +1 -1
  57. package/dist/esm/index.native.js.map +1 -1
  58. package/dist/esm/router/createRoute.js +12 -1
  59. package/dist/esm/router/createRoute.js.map +1 -1
  60. package/dist/esm/router/createRoute.mjs +12 -1
  61. package/dist/esm/router/createRoute.mjs.map +1 -1
  62. package/dist/esm/router/createRoute.native.js +13 -2
  63. package/dist/esm/router/createRoute.native.js.map +1 -1
  64. package/dist/esm/typed-routes/generateRouteTypes.js +14 -3
  65. package/dist/esm/typed-routes/generateRouteTypes.js.map +1 -1
  66. package/dist/esm/typed-routes/generateRouteTypes.mjs +14 -3
  67. package/dist/esm/typed-routes/generateRouteTypes.mjs.map +1 -1
  68. package/dist/esm/typed-routes/generateRouteTypes.native.js +29 -3
  69. package/dist/esm/typed-routes/generateRouteTypes.native.js.map +1 -1
  70. package/dist/esm/typed-routes/getTypedRoutesDeclarationFile.js +38 -2
  71. package/dist/esm/typed-routes/getTypedRoutesDeclarationFile.js.map +1 -1
  72. package/dist/esm/typed-routes/getTypedRoutesDeclarationFile.mjs +39 -2
  73. package/dist/esm/typed-routes/getTypedRoutesDeclarationFile.mjs.map +1 -1
  74. package/dist/esm/typed-routes/getTypedRoutesDeclarationFile.native.js +40 -2
  75. package/dist/esm/typed-routes/getTypedRoutesDeclarationFile.native.js.map +1 -1
  76. package/dist/esm/typed-routes/injectRouteHelpers.js +89 -0
  77. package/dist/esm/typed-routes/injectRouteHelpers.js.map +6 -0
  78. package/dist/esm/typed-routes/injectRouteHelpers.mjs +113 -0
  79. package/dist/esm/typed-routes/injectRouteHelpers.mjs.map +1 -0
  80. package/dist/esm/typed-routes/injectRouteHelpers.native.js +120 -0
  81. package/dist/esm/typed-routes/injectRouteHelpers.native.js.map +1 -0
  82. package/dist/esm/vite/loadConfig.js +20 -13
  83. package/dist/esm/vite/loadConfig.js.map +1 -1
  84. package/dist/esm/vite/loadConfig.mjs +18 -12
  85. package/dist/esm/vite/loadConfig.mjs.map +1 -1
  86. package/dist/esm/vite/loadConfig.native.js +18 -11
  87. package/dist/esm/vite/loadConfig.native.js.map +1 -1
  88. package/dist/esm/vite/plugins/generateFileSystemRouteTypesPlugin.js +13 -3
  89. package/dist/esm/vite/plugins/generateFileSystemRouteTypesPlugin.js.map +1 -1
  90. package/dist/esm/vite/plugins/generateFileSystemRouteTypesPlugin.mjs +3 -2
  91. package/dist/esm/vite/plugins/generateFileSystemRouteTypesPlugin.mjs.map +1 -1
  92. package/dist/esm/vite/plugins/generateFileSystemRouteTypesPlugin.native.js +9 -6
  93. package/dist/esm/vite/plugins/generateFileSystemRouteTypesPlugin.native.js.map +1 -1
  94. package/package.json +10 -10
  95. package/src/cli/generateRoutes.ts +52 -4
  96. package/src/cli.ts +5 -0
  97. package/src/index.ts +13 -0
  98. package/src/interfaces/router.ts +19 -0
  99. package/src/router/createRoute.ts +16 -3
  100. package/src/typed-routes/generateRouteTypes.ts +46 -2
  101. package/src/typed-routes/getTypedRoutesDeclarationFile.ts +70 -0
  102. package/src/typed-routes/injectRouteHelpers.ts +186 -0
  103. package/src/vite/loadConfig.ts +29 -17
  104. package/src/vite/plugins/generateFileSystemRouteTypesPlugin.tsx +14 -3
  105. package/src/vite/types.ts +26 -0
  106. package/types/cli/generateRoutes.d.ts +1 -0
  107. package/types/cli/generateRoutes.d.ts.map +1 -1
  108. package/types/index.d.ts +13 -3
  109. package/types/index.d.ts.map +1 -1
  110. package/types/interfaces/router.d.ts +16 -0
  111. package/types/interfaces/router.d.ts.map +1 -1
  112. package/types/router/createRoute.d.ts +28 -13
  113. package/types/router/createRoute.d.ts.map +1 -1
  114. package/types/typed-routes/generateRouteTypes.d.ts +1 -1
  115. package/types/typed-routes/generateRouteTypes.d.ts.map +1 -1
  116. package/types/typed-routes/getTypedRoutesDeclarationFile.d.ts.map +1 -1
  117. package/types/typed-routes/injectRouteHelpers.d.ts +12 -0
  118. package/types/typed-routes/injectRouteHelpers.d.ts.map +1 -0
  119. package/types/utils/redirect.d.ts +1 -3
  120. package/types/utils/redirect.d.ts.map +1 -1
  121. package/types/vite/loadConfig.d.ts +1 -1
  122. package/types/vite/loadConfig.d.ts.map +1 -1
  123. package/types/vite/plugins/generateFileSystemRouteTypesPlugin.d.ts.map +1 -1
  124. package/types/vite/types.d.ts +25 -0
  125. package/types/vite/types.d.ts.map +1 -1
@@ -21,7 +21,7 @@ var import_getRoutes = require("../router/getRoutes"), import_matchers = require
21
21
  const CATCH_ALL = /\[\.\.\..+?\]/g, SLUG = /\[.+?\]/g;
22
22
  function getTypedRoutesDeclarationFile(ctx) {
23
23
  const staticRoutes = /* @__PURE__ */ new Set(), dynamicRoutes = /* @__PURE__ */ new Set(), dynamicRouteContextKeys = /* @__PURE__ */ new Set();
24
- return walkRouteNode(
24
+ walkRouteNode(
25
25
  (0, import_getRoutes.getRoutes)(ctx, {
26
26
  platformRoutes: !1,
27
27
  // We don't need to generate platform specific routes
@@ -33,7 +33,9 @@ function getTypedRoutesDeclarationFile(ctx) {
33
33
  staticRoutes,
34
34
  dynamicRoutes,
35
35
  dynamicRouteContextKeys
36
- ), `// deno-lint-ignore-file
36
+ );
37
+ const hasRoutes = dynamicRouteContextKeys.size > 0;
38
+ return `// deno-lint-ignore-file
37
39
  /* eslint-disable */
38
40
  // biome-ignore: needed import
39
41
  import type { OneRouter } from 'one'
@@ -45,11 +47,45 @@ declare module 'one' {
45
47
  DynamicRoutes: ${setToUnionType(dynamicRoutes)}
46
48
  DynamicRouteTemplate: ${setToUnionType(dynamicRouteContextKeys)}
47
49
  IsTyped: true
50
+ ${hasRoutes ? `RouteTypes: ${generateRouteTypesMap(dynamicRouteContextKeys)}` : ""}
48
51
  }
49
52
  }
50
53
  }
54
+ ${hasRoutes ? `
55
+ /**
56
+ * Helper type for route information
57
+ */
58
+ type RouteInfo<Params = Record<string, never>> = {
59
+ Params: Params
60
+ LoaderProps: { path: string; params: Params; request?: Request }
61
+ }` : ""}
51
62
  `.trim();
52
63
  }
64
+ function generateRouteTypesMap(dynamicRouteContextKeys) {
65
+ return dynamicRouteContextKeys.size === 0 ? "{}" : `{
66
+ ${[...dynamicRouteContextKeys].sort().map((routePath) => {
67
+ const params = extractParams(routePath), paramsType = params.length === 0 ? "{}" : generateInlineParamsType(params);
68
+ return ` '${routePath}': RouteInfo<${paramsType}>`;
69
+ }).join(`
70
+ `)}
71
+ }`;
72
+ }
73
+ function extractParams(routePath) {
74
+ const params = [], paramRegex = /\[(\.\.\.)?([\w]+)\]/g;
75
+ let match;
76
+ for (; (match = paramRegex.exec(routePath)) !== null; )
77
+ params.push({
78
+ name: match[2],
79
+ isCatchAll: match[1] === "..."
80
+ });
81
+ return params;
82
+ }
83
+ function generateInlineParamsType(params) {
84
+ return `{ ${params.map((p) => {
85
+ const type = p.isCatchAll ? "string[]" : "string";
86
+ return `${p.name}: ${type}`;
87
+ }).join("; ")} }`;
88
+ }
53
89
  function walkRouteNode(routeNode, parentRoutePath, staticRoutes, dynamicRoutes, dynamicRouteContextKeys) {
54
90
  if (routeNode) {
55
91
  addRouteNode(routeNode, parentRoutePath, staticRoutes, dynamicRoutes, dynamicRouteContextKeys), parentRoutePath = `${(0, import_matchers.removeSupportedExtensions)(`${parentRoutePath}/${routeNode.route}`).replace(/\/?index$/, "")}`;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/typed-routes/getTypedRoutesDeclarationFile.ts"],
4
- "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAA0B,gCAC1B,kBAAwD;AAKxD,MAAM,YAAY,kBAEZ,OAAO;AAEN,SAAS,8BAA8B,KAAuB;AACnE,QAAM,eAAe,oBAAI,IAAY,GAC/B,gBAAgB,oBAAI,IAAY,GAChC,0BAA0B,oBAAI,IAAY;AAEhD;AAAA,QACE,4BAAU,KAAK;AAAA,MACb,gBAAgB;AAAA;AAAA,MAChB,mBAAmB;AAAA,MACnB,qBAAqB;AAAA;AAAA,IAEvB,CAAC;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAEO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAQa,eAAe,YAAY,CAAC;AAAA,uBAC3B,eAAe,aAAa,CAAC;AAAA,8BACtB,eAAe,uBAAuB,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA,EAKnE,KAA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,eAAW,eAAe,qBAAqB,SAAS;AACtD,mBAAa,IAAI,WAAW;AAGlC;AAKA,MAAM,iBAAiB,CAAI,QAClB,IAAI,OAAO,IACd,CAAC,GAAG,GAAG,EACJ,KAAK,EACL,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,EACrB,KAAK,KAAK,IACb;AAGN,SAAS,qBAAqB,UAAU;AACtC,QAAM,SAAS,SAAS,MAAM,GAAG,EAAE,OAAO,CAAC,SAAS,KAAK,WAAW,GAAG,KAAK,KAAK,SAAS,GAAG,CAAC,GACxF,eAAyB,CAAC;AAEhC,WAAS,SAAS,cAAc,aAAa;AAC3C,QAAI,iBAAiB,OAAO,QAAQ;AAClC,mBAAa,KAAK,YAAY,QAAQ,WAAW,GAAG,CAAC;AACrD;AAAA,IACF;AAEA,UAAM,QAAQ,OAAO,YAAY,GAC3B,eAAe,YAAY,QAAQ,IAAI,KAAK,IAAI,EAAE;AACxD,aAAS,eAAe,GAAG,YAAY,GACvC,SAAS,eAAe,GAAG,WAAW;AAAA,EACxC;AAEA,kBAAS,GAAG,QAAQ,GACb;AACT;",
5
5
  "names": []
6
6
  }
@@ -33,14 +33,16 @@ function getTypedRoutesDeclarationFile(ctx) {
33
33
  var staticRoutes = /* @__PURE__ */new Set(),
34
34
  dynamicRoutes = /* @__PURE__ */new Set(),
35
35
  dynamicRouteContextKeys = /* @__PURE__ */new Set();
36
- return walkRouteNode((0, import_getRoutes.getRoutes)(ctx, {
36
+ walkRouteNode((0, import_getRoutes.getRoutes)(ctx, {
37
37
  platformRoutes: !1,
38
38
  // We don't need to generate platform specific routes
39
39
  ignoreEntryPoints: !0,
40
40
  ignoreRequireErrors: !0
41
41
  }),
42
42
  // importMode: 'async',
43
- "", staticRoutes, dynamicRoutes, dynamicRouteContextKeys), `// deno-lint-ignore-file
43
+ "", staticRoutes, dynamicRoutes, dynamicRouteContextKeys);
44
+ var hasRoutes = dynamicRouteContextKeys.size > 0;
45
+ return `// deno-lint-ignore-file
44
46
  /* eslint-disable */
45
47
  // biome-ignore: needed import
46
48
  import type { OneRouter } from 'one'
@@ -52,11 +54,47 @@ declare module 'one' {
52
54
  DynamicRoutes: ${setToUnionType(dynamicRoutes)}
53
55
  DynamicRouteTemplate: ${setToUnionType(dynamicRouteContextKeys)}
54
56
  IsTyped: true
57
+ ${hasRoutes ? `RouteTypes: ${generateRouteTypesMap(dynamicRouteContextKeys)}` : ""}
55
58
  }
56
59
  }
57
60
  }
61
+ ${hasRoutes ? `
62
+ /**
63
+ * Helper type for route information
64
+ */
65
+ type RouteInfo<Params = Record<string, never>> = {
66
+ Params: Params
67
+ LoaderProps: { path: string; params: Params; request?: Request }
68
+ }` : ""}
58
69
  `.trim();
59
70
  }
71
+ function generateRouteTypesMap(dynamicRouteContextKeys) {
72
+ if (dynamicRouteContextKeys.size === 0) return "{}";
73
+ var routes = [...dynamicRouteContextKeys].sort(),
74
+ entries = routes.map(function (routePath) {
75
+ var params = extractParams(routePath),
76
+ paramsType = params.length === 0 ? "{}" : generateInlineParamsType(params);
77
+ return ` '${routePath}': RouteInfo<${paramsType}>`;
78
+ }).join(`
79
+ `);
80
+ return `{
81
+ ${entries}
82
+ }`;
83
+ }
84
+ function extractParams(routePath) {
85
+ for (var params = [], paramRegex = /\[(\.\.\.)?([\w]+)\]/g, match; (match = paramRegex.exec(routePath)) !== null;) params.push({
86
+ name: match[2],
87
+ isCatchAll: match[1] === "..."
88
+ });
89
+ return params;
90
+ }
91
+ function generateInlineParamsType(params) {
92
+ var entries = params.map(function (p) {
93
+ var type = p.isCatchAll ? "string[]" : "string";
94
+ return `${p.name}: ${type}`;
95
+ });
96
+ return `{ ${entries.join("; ")} }`;
97
+ }
60
98
  function walkRouteNode(routeNode, parentRoutePath, staticRoutes, dynamicRoutes, dynamicRouteContextKeys) {
61
99
  if (routeNode) {
62
100
  addRouteNode(routeNode, parentRoutePath, staticRoutes, dynamicRoutes, dynamicRouteContextKeys), parentRoutePath = `${(0, import_matchers.removeSupportedExtensions)(`${parentRoutePath}/${routeNode.route}`).replace(/\/?index$/, "")}`;
@@ -1 +1 @@
1
- {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","getTypedRoutesDeclarationFile_exports","__export","getTypedRoutesDeclarationFile","module","exports","import_getRoutes","require","import_matchers","CATCH_ALL","SLUG","ctx","staticRoutes","Set","dynamicRoutes","dynamicRouteContextKeys","walkRouteNode","getRoutes","platformRoutes","ignoreEntryPoints","ignoreRequireErrors","setToUnionType","trim","routeNode","parentRoutePath","addRouteNode","removeSupportedExtensions","route","replace","_iteratorNormalCompletion","_didIteratorError","_iteratorError","_iterator","children","Symbol","iterator","_step","next","done","child","err","return","isTypedRoute","routePath","startsWith","dynamic","generateCombinations","path","add","replaceAll"],"sources":["../../../src/typed-routes/getTypedRoutesDeclarationFile.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,qCAAA;AAAAC,QAAA,CAAAD,qCAAA;EAAAE,6BAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAT,YAA0B,CAAAK,qCAC1B;AAKA,IAAAK,gBAAkB,GAAAC,OAAA,gCAEL;EAAAC,eAAA,GAAAD,OAAA;EAAAE,SAAA;EAAAC,IAAA;AAEN,SAASP,8BAA8BQ,GAAA,EAAuB;EACnE,IAAAC,YAAM,kBAAe,IAAAC,GAAI;IAAYC,aAC/B,kBAAgB,IAAAD,GAAI;IAAYE,uBAChC,kBAA0B,IAAAF,GAAI;EAEpC,OAAAG,aAAA,KACEV,gBAAA,CAAAW,SAAA,EAAUN,GAAA,EAAK;IACbO,cAAA,EAAgB;IAAA;IAChBC,iBAAA,EAAmB;IACnBC,mBAAA,EAAqB;EAAA;EAEvB;EACA,IACAR,YAAA,EACAE,aAAA,EACAC,uBACF,GAEO;AAAA;AAAA;A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SAAM,EAASI,KAAA,IAAS,IAAAnB,eAAmB,CAAAkC,YAAS,EAAKnB,SAAA,CAAWI,KAAG,GAAK;IAG5E,IAAAgB,SAAS,GAAS,GAAAnB,eAAc,QAAAhB,eAAa,CAAAkB,yBAAA,EAAAH,SAAA,CAAAI,KAAA,EAAAC,OAAA;IAC3C,IAAIe,SAAA,CAAAC,UAAiB,IAAO,MAAAD,SAAQ,OAAAA,SAAA,KAAApB,SAAA,CAAAsB,OAAA;MAClC,IAAAhB,yBAAkB,GAAY;QAAAC,iBAAuB;QAAAC,cAAA;MACrD;QACF,SAAAC,SAAA,GAAAc,oBAAA,CAAAH,SAAA,EAAAT,MAAA,CAAAC,QAAA,KAAAC,KAAA,IAAAP,yBAAA,IAAAO,KAAA,GAAAJ,SAAA,CAAAK,IAAA,IAAAC,IAAA,GAAAT,yBAAA;UAEM,IAAAkB,IAAQ,GAAAX,KAAO,CAAApC,KAAA;UAErBe,uBAA2B,CAAAiC,GAAA,CAAAD,IAAA,CAAY,EAAAjC,aAC9B,CAAAkC,GAAA;UACX;UAEA,GAAAD,IAAS,CAAAE,UAAW,CAAAxC,SACb,eAAAwC,UAAA,CAAAvC,IAAA,sCACT","ignoreList":[]}
1
+ {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","getTypedRoutesDeclarationFile_exports","__export","getTypedRoutesDeclarationFile","module","exports","import_getRoutes","require","import_matchers","CATCH_ALL","SLUG","ctx","staticRoutes","Set","dynamicRoutes","dynamicRouteContextKeys","walkRouteNode","getRoutes","platformRoutes","ignoreEntryPoints","ignoreRequireErrors","hasRoutes","size","setToUnionType","generateRouteTypesMap","trim","routes","sort","entries","map","routePath","params","extractParams","paramsType","length","generateInlineParamsType","join","paramRegex","match","exec","push","name","isCatchAll","p","type","routeNode","parentRoutePath","addRouteNode","removeSupportedExtensions","route","replace","_iteratorNormalCompletion","_didIteratorError","_iteratorError","_iterator","children","Symbol","iterator","_step","next","done","child","err","return","isTypedRoute","startsWith","dynamic","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List":[]}
@@ -0,0 +1,136 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: !0
9
+ });
10
+ },
11
+ __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
13
+ get: () => from[key],
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
16
+ return to;
17
+ };
18
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
19
+ value: !0
20
+ }), mod);
21
+ var injectRouteHelpers_exports = {};
22
+ __export(injectRouteHelpers_exports, {
23
+ injectRouteHelpers: () => injectRouteHelpers
24
+ });
25
+ module.exports = __toCommonJS(injectRouteHelpers_exports);
26
+ var import_promises = require("node:fs/promises"),
27
+ import_node_fs = require("node:fs");
28
+ async function injectRouteHelpers(filePath, routePath, mode) {
29
+ if (!(0, import_node_fs.existsSync)(filePath)) return !1;
30
+ try {
31
+ let content = await (0, import_promises.readFile)(filePath, "utf-8"),
32
+ modified = !1;
33
+ const hasTypeRoute = /^type\s+Route\s*=/m.test(content),
34
+ hasConstRoute = /^const\s+route\s*=/m.test(content);
35
+ if (mode === "runtime" && !hasConstRoute) {
36
+ const {
37
+ updatedContent
38
+ } = addCreateRouteImport(content);
39
+ content = updatedContent;
40
+ const routeDeclaration = `const route = createRoute<'${routePath}'>()`;
41
+ content = insertAfterImports(content, routeDeclaration), modified = !0;
42
+ }
43
+ if (mode === "type" && !hasTypeRoute) {
44
+ const {
45
+ updatedContent
46
+ } = addRouteTypeImport(content);
47
+ content = updatedContent;
48
+ const typeDeclaration = `type Route = RouteType<'${routePath}'>`;
49
+ content = insertAfterImports(content, typeDeclaration), modified = !0;
50
+ }
51
+ return modified ? (await (0, import_promises.writeFile)(filePath, content, "utf-8"), !0) : !1;
52
+ } catch (error) {
53
+ return console.error(`Failed to inject route helpers into ${filePath}:`, error), !1;
54
+ }
55
+ }
56
+ function addCreateRouteImport(content) {
57
+ if (/import\s+[^'"]*createRoute[^'"]*from\s+['"]one['"]/m.test(content)) return {
58
+ updatedContent: content,
59
+ importAdded: !1
60
+ };
61
+ const oneImportRegex = /import\s+{([^}]*)}\s+from\s+['"]one['"]/m,
62
+ match = content.match(oneImportRegex);
63
+ if (match) {
64
+ const existingImports = match[1].trim(),
65
+ newImports = existingImports ? `${existingImports}, createRoute` : "createRoute";
66
+ return {
67
+ updatedContent: content.replace(oneImportRegex, `import { ${newImports} } from 'one'`),
68
+ importAdded: !0
69
+ };
70
+ }
71
+ const lastImportIndex = findLastImportIndex(content);
72
+ if (lastImportIndex >= 0) {
73
+ const lines = content.split(`
74
+ `);
75
+ return lines.splice(lastImportIndex + 1, 0, "import { createRoute } from 'one'"), {
76
+ updatedContent: lines.join(`
77
+ `),
78
+ importAdded: !0
79
+ };
80
+ }
81
+ return {
82
+ updatedContent: `import { createRoute } from 'one'
83
+ ` + content,
84
+ importAdded: !0
85
+ };
86
+ }
87
+ function addRouteTypeImport(content) {
88
+ if (/import\s+type\s+[^'"]*RouteType[^'"]*from\s+['"]one['"]/m.test(content)) return {
89
+ updatedContent: content,
90
+ importAdded: !1
91
+ };
92
+ const oneTypeImportRegex = /import\s+type\s+{([^}]*)}\s+from\s+['"]one['"]/m,
93
+ match = content.match(oneTypeImportRegex);
94
+ if (match) {
95
+ const existingImports = match[1].trim(),
96
+ newImports = existingImports ? `${existingImports}, RouteType` : "RouteType";
97
+ return {
98
+ updatedContent: content.replace(oneTypeImportRegex, `import type { ${newImports} } from 'one'`),
99
+ importAdded: !0
100
+ };
101
+ }
102
+ const lastImportIndex = findLastImportIndex(content);
103
+ if (lastImportIndex >= 0) {
104
+ const lines = content.split(`
105
+ `);
106
+ return lines.splice(lastImportIndex + 1, 0, "import type { RouteType } from 'one'"), {
107
+ updatedContent: lines.join(`
108
+ `),
109
+ importAdded: !0
110
+ };
111
+ }
112
+ return {
113
+ updatedContent: `import type { RouteType } from 'one'
114
+ ` + content,
115
+ importAdded: !0
116
+ };
117
+ }
118
+ function findLastImportIndex(content) {
119
+ const lines = content.split(`
120
+ `);
121
+ let lastImportIndex = -1;
122
+ for (let i = 0; i < lines.length; i++) {
123
+ const line = lines[i].trim();
124
+ if (line.startsWith("import ") || lastImportIndex >= 0 && (line.startsWith("from ") || line === "}")) lastImportIndex = i;else if (lastImportIndex >= 0 && line && !line.startsWith("//")) break;
125
+ }
126
+ return lastImportIndex;
127
+ }
128
+ function insertAfterImports(content, codeToInsert) {
129
+ const lines = content.split(`
130
+ `),
131
+ lastImportIndex = findLastImportIndex(content);
132
+ return lastImportIndex >= 0 ? (lines[lastImportIndex + 1] === "" ? lines.splice(lastImportIndex + 2, 0, codeToInsert, "") : lines.splice(lastImportIndex + 1, 0, "", codeToInsert, ""), lines.join(`
133
+ `)) : codeToInsert + `
134
+
135
+ ` + content;
136
+ }
@@ -0,0 +1,104 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: !0 });
8
+ }, __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from == "object" || typeof from == "function")
10
+ for (let key of __getOwnPropNames(from))
11
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
15
+ var injectRouteHelpers_exports = {};
16
+ __export(injectRouteHelpers_exports, {
17
+ injectRouteHelpers: () => injectRouteHelpers
18
+ });
19
+ module.exports = __toCommonJS(injectRouteHelpers_exports);
20
+ var import_promises = require("node:fs/promises"), import_node_fs = require("node:fs");
21
+ async function injectRouteHelpers(filePath, routePath, mode) {
22
+ if (!(0, import_node_fs.existsSync)(filePath))
23
+ return !1;
24
+ try {
25
+ let content = await (0, import_promises.readFile)(filePath, "utf-8"), modified = !1;
26
+ const hasTypeRoute = /^type\s+Route\s*=/m.test(content), hasConstRoute = /^const\s+route\s*=/m.test(content);
27
+ if (mode === "runtime" && !hasConstRoute) {
28
+ const { updatedContent } = addCreateRouteImport(content);
29
+ content = updatedContent;
30
+ const routeDeclaration = `const route = createRoute<'${routePath}'>()`;
31
+ content = insertAfterImports(content, routeDeclaration), modified = !0;
32
+ }
33
+ if (mode === "type" && !hasTypeRoute) {
34
+ const { updatedContent } = addRouteTypeImport(content);
35
+ content = updatedContent;
36
+ const typeDeclaration = `type Route = RouteType<'${routePath}'>`;
37
+ content = insertAfterImports(content, typeDeclaration), modified = !0;
38
+ }
39
+ return modified ? (await (0, import_promises.writeFile)(filePath, content, "utf-8"), !0) : !1;
40
+ } catch (error) {
41
+ return console.error(`Failed to inject route helpers into ${filePath}:`, error), !1;
42
+ }
43
+ }
44
+ function addCreateRouteImport(content) {
45
+ if (/import\s+[^'"]*createRoute[^'"]*from\s+['"]one['"]/m.test(content))
46
+ return { updatedContent: content, importAdded: !1 };
47
+ const oneImportRegex = /import\s+{([^}]*)}\s+from\s+['"]one['"]/m, match = content.match(oneImportRegex);
48
+ if (match) {
49
+ const existingImports = match[1].trim(), newImports = existingImports ? `${existingImports}, createRoute` : "createRoute";
50
+ return { updatedContent: content.replace(oneImportRegex, `import { ${newImports} } from 'one'`), importAdded: !0 };
51
+ }
52
+ const lastImportIndex = findLastImportIndex(content);
53
+ if (lastImportIndex >= 0) {
54
+ const lines = content.split(`
55
+ `);
56
+ return lines.splice(lastImportIndex + 1, 0, "import { createRoute } from 'one'"), { updatedContent: lines.join(`
57
+ `), importAdded: !0 };
58
+ }
59
+ return { updatedContent: `import { createRoute } from 'one'
60
+ ` + content, importAdded: !0 };
61
+ }
62
+ function addRouteTypeImport(content) {
63
+ if (/import\s+type\s+[^'"]*RouteType[^'"]*from\s+['"]one['"]/m.test(content))
64
+ return { updatedContent: content, importAdded: !1 };
65
+ const oneTypeImportRegex = /import\s+type\s+{([^}]*)}\s+from\s+['"]one['"]/m, match = content.match(oneTypeImportRegex);
66
+ if (match) {
67
+ const existingImports = match[1].trim(), newImports = existingImports ? `${existingImports}, RouteType` : "RouteType";
68
+ return { updatedContent: content.replace(
69
+ oneTypeImportRegex,
70
+ `import type { ${newImports} } from 'one'`
71
+ ), importAdded: !0 };
72
+ }
73
+ const lastImportIndex = findLastImportIndex(content);
74
+ if (lastImportIndex >= 0) {
75
+ const lines = content.split(`
76
+ `);
77
+ return lines.splice(lastImportIndex + 1, 0, "import type { RouteType } from 'one'"), { updatedContent: lines.join(`
78
+ `), importAdded: !0 };
79
+ }
80
+ return { updatedContent: `import type { RouteType } from 'one'
81
+ ` + content, importAdded: !0 };
82
+ }
83
+ function findLastImportIndex(content) {
84
+ const lines = content.split(`
85
+ `);
86
+ let lastImportIndex = -1;
87
+ for (let i = 0; i < lines.length; i++) {
88
+ const line = lines[i].trim();
89
+ if (line.startsWith("import ") || lastImportIndex >= 0 && (line.startsWith("from ") || line === "}"))
90
+ lastImportIndex = i;
91
+ else if (lastImportIndex >= 0 && line && !line.startsWith("//"))
92
+ break;
93
+ }
94
+ return lastImportIndex;
95
+ }
96
+ function insertAfterImports(content, codeToInsert) {
97
+ const lines = content.split(`
98
+ `), lastImportIndex = findLastImportIndex(content);
99
+ return lastImportIndex >= 0 ? (lines[lastImportIndex + 1] === "" ? lines.splice(lastImportIndex + 2, 0, codeToInsert, "") : lines.splice(lastImportIndex + 1, 0, "", codeToInsert, ""), lines.join(`
100
+ `)) : codeToInsert + `
101
+
102
+ ` + content;
103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AE,KAAK;AAC3B,QACE,KAAK,WAAW,SAAS,KACxB,mBAAmB,MAAM,KAAK,WAAW,OAAO,KAAK,SAAS;AAE/D,wBAAkB;AAAA,aACT,mBAAmB,KAAK,QAAQ,CAAC,KAAK,WAAW,IAAI;AAE9D;AAAA,EAEJ;AAEA,SAAO;AACT;AAMA,SAAS,mBAAmB,SAAiB,cAA8B;AACzE,QAAM,QAAQ,QAAQ,MAAM;AAAA,CAAI,GAC1B,kBAAkB,oBAAoB,OAAO;AAEnD,SAAI,mBAAmB,KAEJ,MAAM,kBAAkB,CAAC,MACR,KAIhC,MAAM,OAAO,kBAAkB,GAAG,GAAG,cAAc,EAAE,IAGrD,MAAM,OAAO,kBAAkB,GAAG,GAAG,IAAI,cAAc,EAAE,GAGpD,MAAM,KAAK;AAAA,CAAI,KAIjB,eAAe;AAAA;AAAA,IAAS;AACjC;",
5
+ "names": []
6
+ }
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: !0
11
+ });
12
+ },
13
+ __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
15
+ get: () => from[key],
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ return to;
19
+ };
20
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
+ value: !0
22
+ }), mod);
23
+ var injectRouteHelpers_exports = {};
24
+ __export(injectRouteHelpers_exports, {
25
+ injectRouteHelpers: () => injectRouteHelpers
26
+ });
27
+ module.exports = __toCommonJS(injectRouteHelpers_exports);
28
+ var import_promises = require("fs/promises"),
29
+ import_fs = require("fs");
30
+ async function injectRouteHelpers(filePath, routePath, mode) {
31
+ if (!(0, import_fs.existsSync)(filePath)) return !1;
32
+ try {
33
+ var content = await (0, import_promises.readFile)(filePath, "utf-8"),
34
+ modified = !1,
35
+ hasTypeRoute = /^type\s+Route\s*=/m.test(content),
36
+ hasConstRoute = /^const\s+route\s*=/m.test(content);
37
+ if (mode === "runtime" && !hasConstRoute) {
38
+ var {
39
+ updatedContent
40
+ } = addCreateRouteImport(content);
41
+ content = updatedContent;
42
+ var routeDeclaration = `const route = createRoute<'${routePath}'>()`;
43
+ content = insertAfterImports(content, routeDeclaration), modified = !0;
44
+ }
45
+ if (mode === "type" && !hasTypeRoute) {
46
+ var {
47
+ updatedContent: updatedContent1
48
+ } = addRouteTypeImport(content);
49
+ content = updatedContent1;
50
+ var typeDeclaration = `type Route = RouteType<'${routePath}'>`;
51
+ content = insertAfterImports(content, typeDeclaration), modified = !0;
52
+ }
53
+ return modified ? (await (0, import_promises.writeFile)(filePath, content, "utf-8"), !0) : !1;
54
+ } catch (error) {
55
+ return console.error(`Failed to inject route helpers into ${filePath}:`, error), !1;
56
+ }
57
+ }
58
+ function addCreateRouteImport(content) {
59
+ if (/import\s+[^'"]*createRoute[^'"]*from\s+['"]one['"]/m.test(content)) return {
60
+ updatedContent: content,
61
+ importAdded: !1
62
+ };
63
+ var oneImportRegex = /import\s+{([^}]*)}\s+from\s+['"]one['"]/m,
64
+ match = content.match(oneImportRegex);
65
+ if (match) {
66
+ var existingImports = match[1].trim(),
67
+ newImports = existingImports ? `${existingImports}, createRoute` : "createRoute",
68
+ updatedContent = content.replace(oneImportRegex, `import { ${newImports} } from 'one'`);
69
+ return {
70
+ updatedContent,
71
+ importAdded: !0
72
+ };
73
+ }
74
+ var lastImportIndex = findLastImportIndex(content);
75
+ if (lastImportIndex >= 0) {
76
+ var lines = content.split(`
77
+ `);
78
+ return lines.splice(lastImportIndex + 1, 0, "import { createRoute } from 'one'"), {
79
+ updatedContent: lines.join(`
80
+ `),
81
+ importAdded: !0
82
+ };
83
+ }
84
+ var newImport = `import { createRoute } from 'one'
85
+ `;
86
+ return {
87
+ updatedContent: newImport + content,
88
+ importAdded: !0
89
+ };
90
+ }
91
+ function addRouteTypeImport(content) {
92
+ if (/import\s+type\s+[^'"]*RouteType[^'"]*from\s+['"]one['"]/m.test(content)) return {
93
+ updatedContent: content,
94
+ importAdded: !1
95
+ };
96
+ var oneTypeImportRegex = /import\s+type\s+{([^}]*)}\s+from\s+['"]one['"]/m,
97
+ match = content.match(oneTypeImportRegex);
98
+ if (match) {
99
+ var existingImports = match[1].trim(),
100
+ newImports = existingImports ? `${existingImports}, RouteType` : "RouteType",
101
+ updatedContent = content.replace(oneTypeImportRegex, `import type { ${newImports} } from 'one'`);
102
+ return {
103
+ updatedContent,
104
+ importAdded: !0
105
+ };
106
+ }
107
+ var lastImportIndex = findLastImportIndex(content);
108
+ if (lastImportIndex >= 0) {
109
+ var lines = content.split(`
110
+ `);
111
+ return lines.splice(lastImportIndex + 1, 0, "import type { RouteType } from 'one'"), {
112
+ updatedContent: lines.join(`
113
+ `),
114
+ importAdded: !0
115
+ };
116
+ }
117
+ var newImport = `import type { RouteType } from 'one'
118
+ `;
119
+ return {
120
+ updatedContent: newImport + content,
121
+ importAdded: !0
122
+ };
123
+ }
124
+ function findLastImportIndex(content) {
125
+ for (var lines = content.split(`
126
+ `), lastImportIndex = -1, i = 0; i < lines.length; i++) {
127
+ var line = lines[i].trim();
128
+ if (line.startsWith("import ") || lastImportIndex >= 0 && (line.startsWith("from ") || line === "}")) lastImportIndex = i;else if (lastImportIndex >= 0 && line && !line.startsWith("//")) break;
129
+ }
130
+ return lastImportIndex;
131
+ }
132
+ function insertAfterImports(content, codeToInsert) {
133
+ var lines = content.split(`
134
+ `),
135
+ lastImportIndex = findLastImportIndex(content);
136
+ if (lastImportIndex >= 0) {
137
+ var nextLine = lines[lastImportIndex + 1],
138
+ hasBlankLine = nextLine === "";
139
+ return hasBlankLine ? lines.splice(lastImportIndex + 2, 0, codeToInsert, "") : lines.splice(lastImportIndex + 1, 0, "", codeToInsert, ""), lines.join(`
140
+ `);
141
+ }
142
+ return codeToInsert + `
143
+
144
+ ` + content;
145
+ }
146
+ //# sourceMappingURL=injectRouteHelpers.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","injectRouteHelpers_exports","__export","injectRouteHelpers","module","exports","import_promises","require","import_fs","filePath","routePath","mode","existsSync","content","readFile","modified","hasTypeRoute","test","hasConstRoute","updatedContent","addCreateRouteImport","routeDeclaration","insertAfterImports","updatedContent1","addRouteTypeImport","typeDeclaration","writeFile","error","console","importAdded","oneImportRegex","match","existingImports","trim","newImports","replace","lastImportIndex","findLastImportIndex","lines","split","splice","join","newImport","oneTypeImportRegex"],"sources":["../../../src/typed-routes/injectRouteHelpers.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,0BAAA;AAAAC,QAAA,CAAAD,0BAAA;EAAAE,kBAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAT,YAAoC,CAAAK,0BACpC;AAaA,IAAAK,eAAsB,GAAAC,OAAA,cACpB,CACA;EAAAC,SACA,GAAAD,OACkB;AAClB,eAAKJ,mBAAAM,QAAW,EAAAC,SAAQ,EAAAC,IAAA;EACtB,SAAOH,SAAA,CAAAI,UAAA,EAAAH,QAAA,GAGT,OAAI;EACF;IAIA,IAAAI,OAAM,UAAe,GAAAP,eAAA,CAAAQ,QAA0B,EAAAL,QACzC;MAAAM,QAAgB;MAAAC,YAAsB,GAAK,oBAAO,CAAAC,IAAA,CAAAJ,OAAA;MAAAK,aAAA,yBAAAD,IAAA,CAAAJ,OAAA;IAGxD,IAAIF,IAAA,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AE,KAAS,GAAAzB,OAAA,CAAA0B,KAAkB;AAClE;IAKA,OAASD,KAAA,CAAAE,MAAA,CAAAJ,eAAsF;MAEzFjB,cAAA,EAAAmB,KAAA,CAAAG,IAAA;AACF;MAIFZ,WAAM;IAGN;EAEE;EAMA,IAAAa,SAAS;AAJsB;EAC7B,OACA;IACFvB,cACyB,EAAauB,SAAK,GAAA7B,OAAA;IAC7CgB,WAAA;EAGA;AACA;AACE,SAAAL,kBAAsBA,CAAAX,OAAM;EAAI,+DAAAI,IAAA,CAAAJ,OAAA,GAChC;IAC2CM,cAAkB,EAAAN,OAAA;IAC/DgB,WAAA;EAIA;EADkB,IACmBc,kBAAS,GAAa,iDAAK;IAAAZ,KAAA,GAAAlB,OAAA,CAAAkB,KAAA,CAAAY,kBAAA;EAClE,IAAAZ,KAAA;IAKA,IAAAC,eAAS,GAAAD,KAAoB,IAAAE,IAAyB;MAAAC,UAAA,GAAAF,eAAA,MAAAA,eAAA;MAAAb,cAAA,GAAAN,OAAA,CAAAsB,OAAA,CAAAQ,kBAAA,mBAAAT,UAAA;IACpD,OAAM;MAA0Bf,cAAA;MAC5BU,WAAA;IAEJ;EACE;EACA,IAAAO,eACO,GAAWC,mBACf,CAAAxB,OAAA;EAED,IAAAuB,eAAA,IAAkB;IAAA,IAAAE,KACT,GAAAzB,OAAA,CAAA0B,KAAA;AAET;IAEJ,OAAAD,KAAA,CAAAE,MAAA,CAAAJ,eAAA;MAEAjB,cAAO,EAAAmB,KAAA,CAAAG,IAAA;AACT;MAMAZ,WAAS;IACP;EAAgC;EAGhC,IAAAa,SAAI;AAagB,CAAI;EAIF;IAASvB,cAAA,EAAAuB,SAAA,GAAA7B,OAAA;IACjCgB,WAAA","ignoreList":[]}
@@ -33,16 +33,22 @@ function getUserOneOptions() {
33
33
  if (!globalThis.__oneOptions) throw new Error("One not loaded properly, is the one() plugin in your vite.config.ts?");
34
34
  return globalThis.__oneOptions;
35
35
  }
36
- async function loadUserOneOptions(command) {
37
- const config = await (0, import_vite.loadConfigFromFile)({
38
- mode: command === "serve" ? "dev" : "prod",
39
- command
40
- });
41
- if (!config) throw new Error(`No config config in ${process.cwd()}. Is this the correct directory?`);
42
- const oneOptions = getUserOneOptions();
43
- if (!oneOptions) throw new Error("No One plugin config in this vite.config");
44
- return {
45
- config,
46
- oneOptions
47
- };
36
+ async function loadUserOneOptions(command, silent = !1) {
37
+ const originalConsoleError = console.error;
38
+ silent && (console.error = () => {});
39
+ try {
40
+ const config = await (0, import_vite.loadConfigFromFile)({
41
+ mode: command === "serve" ? "dev" : "prod",
42
+ command
43
+ });
44
+ if (!config) throw new Error(`No config config in ${process.cwd()}. Is this the correct directory?`);
45
+ const oneOptions = getUserOneOptions();
46
+ if (!oneOptions) throw new Error("No One plugin config in this vite.config");
47
+ return {
48
+ config,
49
+ oneOptions
50
+ };
51
+ } finally {
52
+ silent && (console.error = originalConsoleError);
53
+ }
48
54
  }