one 1.2.45 → 1.2.47

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 (105) hide show
  1. package/dist/cjs/babel-plugins/remove-server-code.cjs +105 -0
  2. package/dist/cjs/babel-plugins/remove-server-code.js +125 -0
  3. package/dist/cjs/babel-plugins/remove-server-code.js.map +6 -0
  4. package/dist/cjs/babel-plugins/remove-server-code.native.js +153 -0
  5. package/dist/cjs/babel-plugins/remove-server-code.native.js.map +1 -0
  6. package/dist/cjs/cli/buildPage.cjs +16 -7
  7. package/dist/cjs/cli/buildPage.js +14 -5
  8. package/dist/cjs/cli/buildPage.js.map +1 -1
  9. package/dist/cjs/cli/buildPage.native.js +17 -8
  10. package/dist/cjs/cli/buildPage.native.js.map +1 -1
  11. package/dist/cjs/metro-config/getViteMetroPluginOptions.cjs +8 -3
  12. package/dist/cjs/metro-config/getViteMetroPluginOptions.js +9 -1
  13. package/dist/cjs/metro-config/getViteMetroPluginOptions.js.map +1 -1
  14. package/dist/cjs/metro-config/getViteMetroPluginOptions.native.js +8 -3
  15. package/dist/cjs/metro-config/getViteMetroPluginOptions.native.js.map +1 -1
  16. package/dist/cjs/polyfills-mobile.cjs +3 -1
  17. package/dist/cjs/polyfills-mobile.js +2 -1
  18. package/dist/cjs/polyfills-mobile.js.map +2 -2
  19. package/dist/cjs/polyfills-mobile.native.js +8 -4
  20. package/dist/cjs/polyfills-mobile.native.js.map +1 -1
  21. package/dist/cjs/router/router.cjs +3 -1
  22. package/dist/cjs/router/router.js +2 -1
  23. package/dist/cjs/router/router.js.map +1 -1
  24. package/dist/cjs/router/router.native.js +7 -3
  25. package/dist/cjs/router/router.native.js.map +1 -1
  26. package/dist/cjs/server/oneServe.cjs +10 -2
  27. package/dist/cjs/server/oneServe.js +12 -1
  28. package/dist/cjs/server/oneServe.js.map +1 -1
  29. package/dist/cjs/server/oneServe.native.js +10 -3
  30. package/dist/cjs/server/oneServe.native.js.map +1 -1
  31. package/dist/cjs/vite/plugins/fileSystemRouterPlugin.cjs +1 -0
  32. package/dist/cjs/vite/plugins/fileSystemRouterPlugin.js +2 -0
  33. package/dist/cjs/vite/plugins/fileSystemRouterPlugin.js.map +1 -1
  34. package/dist/cjs/vite/plugins/fileSystemRouterPlugin.native.js +1 -0
  35. package/dist/cjs/vite/plugins/fileSystemRouterPlugin.native.js.map +1 -1
  36. package/dist/cjs/vite/plugins/virtualEntryPlugin.cjs +7 -3
  37. package/dist/cjs/vite/plugins/virtualEntryPlugin.js +4 -3
  38. package/dist/cjs/vite/plugins/virtualEntryPlugin.js.map +1 -1
  39. package/dist/cjs/vite/plugins/virtualEntryPlugin.native.js +5 -2
  40. package/dist/cjs/vite/plugins/virtualEntryPlugin.native.js.map +1 -1
  41. package/dist/esm/babel-plugins/remove-server-code.js +102 -0
  42. package/dist/esm/babel-plugins/remove-server-code.js.map +6 -0
  43. package/dist/esm/babel-plugins/remove-server-code.mjs +71 -0
  44. package/dist/esm/babel-plugins/remove-server-code.mjs.map +1 -0
  45. package/dist/esm/babel-plugins/remove-server-code.native.js +116 -0
  46. package/dist/esm/babel-plugins/remove-server-code.native.js.map +1 -0
  47. package/dist/esm/cli/buildPage.js +14 -4
  48. package/dist/esm/cli/buildPage.js.map +1 -1
  49. package/dist/esm/cli/buildPage.mjs +16 -7
  50. package/dist/esm/cli/buildPage.mjs.map +1 -1
  51. package/dist/esm/cli/buildPage.native.js +17 -8
  52. package/dist/esm/cli/buildPage.native.js.map +1 -1
  53. package/dist/esm/metro-config/getViteMetroPluginOptions.js +9 -1
  54. package/dist/esm/metro-config/getViteMetroPluginOptions.js.map +1 -1
  55. package/dist/esm/metro-config/getViteMetroPluginOptions.mjs +7 -2
  56. package/dist/esm/metro-config/getViteMetroPluginOptions.mjs.map +1 -1
  57. package/dist/esm/metro-config/getViteMetroPluginOptions.native.js +7 -2
  58. package/dist/esm/metro-config/getViteMetroPluginOptions.native.js.map +1 -1
  59. package/dist/esm/polyfills-mobile.js +2 -0
  60. package/dist/esm/polyfills-mobile.js.map +1 -1
  61. package/dist/esm/polyfills-mobile.mjs +2 -0
  62. package/dist/esm/polyfills-mobile.mjs.map +1 -1
  63. package/dist/esm/polyfills-mobile.native.js +5 -3
  64. package/dist/esm/polyfills-mobile.native.js.map +1 -1
  65. package/dist/esm/router/router.js +2 -1
  66. package/dist/esm/router/router.js.map +1 -1
  67. package/dist/esm/router/router.mjs +3 -1
  68. package/dist/esm/router/router.mjs.map +1 -1
  69. package/dist/esm/router/router.native.js +7 -3
  70. package/dist/esm/router/router.native.js.map +1 -1
  71. package/dist/esm/server/oneServe.js +12 -1
  72. package/dist/esm/server/oneServe.js.map +1 -1
  73. package/dist/esm/server/oneServe.mjs +10 -2
  74. package/dist/esm/server/oneServe.mjs.map +1 -1
  75. package/dist/esm/server/oneServe.native.js +10 -3
  76. package/dist/esm/server/oneServe.native.js.map +1 -1
  77. package/dist/esm/vite/plugins/fileSystemRouterPlugin.js +2 -0
  78. package/dist/esm/vite/plugins/fileSystemRouterPlugin.js.map +1 -1
  79. package/dist/esm/vite/plugins/fileSystemRouterPlugin.mjs +1 -0
  80. package/dist/esm/vite/plugins/fileSystemRouterPlugin.mjs.map +1 -1
  81. package/dist/esm/vite/plugins/fileSystemRouterPlugin.native.js +1 -0
  82. package/dist/esm/vite/plugins/fileSystemRouterPlugin.native.js.map +1 -1
  83. package/dist/esm/vite/plugins/virtualEntryPlugin.js +4 -2
  84. package/dist/esm/vite/plugins/virtualEntryPlugin.js.map +1 -1
  85. package/dist/esm/vite/plugins/virtualEntryPlugin.mjs +6 -2
  86. package/dist/esm/vite/plugins/virtualEntryPlugin.mjs.map +1 -1
  87. package/dist/esm/vite/plugins/virtualEntryPlugin.native.js +4 -1
  88. package/dist/esm/vite/plugins/virtualEntryPlugin.native.js.map +1 -1
  89. package/package.json +15 -9
  90. package/src/babel-plugins/remove-server-code.ts +227 -0
  91. package/src/cli/buildPage.ts +23 -4
  92. package/src/metro-config/getViteMetroPluginOptions.ts +10 -2
  93. package/src/polyfills-mobile.ts +7 -0
  94. package/src/router/router.ts +1 -1
  95. package/src/server/oneServe.ts +16 -1
  96. package/src/vite/plugins/fileSystemRouterPlugin.tsx +5 -0
  97. package/src/vite/plugins/virtualEntryPlugin.ts +6 -0
  98. package/types/babel-plugins/remove-server-code.d.ts +23 -0
  99. package/types/babel-plugins/remove-server-code.d.ts.map +1 -0
  100. package/types/cli/buildPage.d.ts.map +1 -1
  101. package/types/metro-config/getViteMetroPluginOptions.d.ts.map +1 -1
  102. package/types/polyfills-mobile.d.ts.map +1 -1
  103. package/types/server/oneServe.d.ts.map +1 -1
  104. package/types/vite/plugins/fileSystemRouterPlugin.d.ts.map +1 -1
  105. package/types/vite/plugins/virtualEntryPlugin.d.ts.map +1 -1
@@ -0,0 +1,105 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf,
6
+ __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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
26
+ value: mod,
27
+ enumerable: !0
28
+ }) : target, mod)),
29
+ __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
30
+ value: !0
31
+ }), mod);
32
+ var remove_server_code_exports = {};
33
+ __export(remove_server_code_exports, {
34
+ default: () => remove_server_code_default
35
+ });
36
+ module.exports = __toCommonJS(remove_server_code_exports);
37
+ var t = __toESM(require("@babel/types"), 1),
38
+ import_babel_dead_code_elimination = require("babel-dead-code-elimination");
39
+ const SERVER_EXPORTS = ["loader", "generateStaticParams"];
40
+ function removeServerCodePlugin(_, options) {
41
+ const {
42
+ routerRoot = "app"
43
+ } = options;
44
+ return {
45
+ name: "one-remove-server-code",
46
+ visitor: {
47
+ Program: {
48
+ enter(path, state) {
49
+ const filename = state.filename;
50
+ if (!filename || !new RegExp(`[/\\\\]${routerRoot}[/\\\\]`).test(filename) || filename.includes("node_modules")) return;
51
+ const code = path.toString();
52
+ if (/generateStaticParams|loader/.test(code)) try {
53
+ state.referenced = (0, import_babel_dead_code_elimination.findReferencedIdentifiers)(path.node);
54
+ } catch (error) {
55
+ console.warn(`[one/metro] Skipping tree shaking for ${filename} due to identifier analysis error:`, error instanceof Error ? error.message : String(error));
56
+ }
57
+ },
58
+ exit(path, state) {
59
+ const filename = state.filename;
60
+ if (!filename || !new RegExp(`[/\\\\]${routerRoot}[/\\\\]`).test(filename) || filename.includes("node_modules") || !state.referenced) return;
61
+ const removedExports = /* @__PURE__ */new Set();
62
+ if (path.traverse({
63
+ ExportNamedDeclaration(exportPath) {
64
+ const declaration = exportPath.node.declaration;
65
+ if (t.isFunctionDeclaration(declaration) && declaration.id) {
66
+ const name = declaration.id.name;
67
+ SERVER_EXPORTS.includes(name) && (removedExports.add(name), exportPath.remove());
68
+ } else if (t.isVariableDeclaration(declaration)) for (let i = declaration.declarations.length - 1; i >= 0; i--) {
69
+ const declarator = declaration.declarations[i];
70
+ if (t.isIdentifier(declarator.id)) {
71
+ const name = declarator.id.name;
72
+ SERVER_EXPORTS.includes(name) && (removedExports.add(name), declaration.declarations.length === 1 ? exportPath.remove() : declaration.declarations.splice(i, 1));
73
+ }
74
+ }
75
+ },
76
+ // Also remove helper functions created by babel's async-to-generator transform
77
+ // These are named _loader, _generateStaticParams, etc.
78
+ FunctionDeclaration(funcPath) {
79
+ if (!funcPath.node.id) return;
80
+ const name = funcPath.node.id.name;
81
+ for (const serverExport of SERVER_EXPORTS) if (name === `_${serverExport}`) {
82
+ let isAsyncHelper = !1;
83
+ funcPath.traverse({
84
+ Identifier(idPath) {
85
+ idPath.node.name === "_asyncToGenerator" && (isAsyncHelper = !0, idPath.stop());
86
+ }
87
+ }), isAsyncHelper && (removedExports.add(serverExport), funcPath.remove());
88
+ }
89
+ }
90
+ }), removedExports.size === 0) return;
91
+ try {
92
+ (0, import_babel_dead_code_elimination.deadCodeElimination)(path.node, state.referenced);
93
+ } catch (error) {
94
+ console.warn(`[one/metro] Dead code elimination failed for ${filename}:`, error instanceof Error ? error.message : String(error));
95
+ }
96
+ const stubs = [];
97
+ removedExports.has("loader") && stubs.push(t.exportNamedDeclaration(t.functionDeclaration(t.identifier("loader"), [], t.blockStatement([t.returnStatement(t.stringLiteral("__vxrn__loader__"))])))), removedExports.has("generateStaticParams") && stubs.push(t.exportNamedDeclaration(t.functionDeclaration(t.identifier("generateStaticParams"), [], t.blockStatement([]))));
98
+ for (const stub of stubs) path.pushContainer("body", stub);
99
+ console.info(` \u{1F9F9} [one/metro] ${filename} removed ${removedExports.size} server-only exports`);
100
+ }
101
+ }
102
+ }
103
+ };
104
+ }
105
+ var remove_server_code_default = removeServerCodePlugin;
@@ -0,0 +1,125 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: !0 });
9
+ }, __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from == "object" || typeof from == "function")
11
+ for (let key of __getOwnPropNames(from))
12
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ return to;
14
+ };
15
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
16
+ // If the importer is in node compatibility mode or this is not an ESM
17
+ // file that has been converted to a CommonJS file using a Babel-
18
+ // compatible transform (i.e. "__esModule" has not been set), then set
19
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
21
+ mod
22
+ )), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
23
+ var remove_server_code_exports = {};
24
+ __export(remove_server_code_exports, {
25
+ default: () => remove_server_code_default
26
+ });
27
+ module.exports = __toCommonJS(remove_server_code_exports);
28
+ var t = __toESM(require("@babel/types"), 1), import_babel_dead_code_elimination = require("babel-dead-code-elimination");
29
+ const SERVER_EXPORTS = ["loader", "generateStaticParams"];
30
+ function removeServerCodePlugin(_, options) {
31
+ const { routerRoot = "app" } = options;
32
+ return {
33
+ name: "one-remove-server-code",
34
+ visitor: {
35
+ Program: {
36
+ enter(path, state) {
37
+ const filename = state.filename;
38
+ if (!filename || !new RegExp(`[/\\\\]${routerRoot}[/\\\\]`).test(filename) || filename.includes("node_modules"))
39
+ return;
40
+ const code = path.toString();
41
+ if (/generateStaticParams|loader/.test(code))
42
+ try {
43
+ state.referenced = (0, import_babel_dead_code_elimination.findReferencedIdentifiers)(path.node);
44
+ } catch (error) {
45
+ console.warn(
46
+ `[one/metro] Skipping tree shaking for ${filename} due to identifier analysis error:`,
47
+ error instanceof Error ? error.message : String(error)
48
+ );
49
+ }
50
+ },
51
+ exit(path, state) {
52
+ const filename = state.filename;
53
+ if (!filename || !new RegExp(`[/\\\\]${routerRoot}[/\\\\]`).test(filename) || filename.includes("node_modules") || !state.referenced)
54
+ return;
55
+ const removedExports = /* @__PURE__ */ new Set();
56
+ if (path.traverse({
57
+ ExportNamedDeclaration(exportPath) {
58
+ const declaration = exportPath.node.declaration;
59
+ if (t.isFunctionDeclaration(declaration) && declaration.id) {
60
+ const name = declaration.id.name;
61
+ SERVER_EXPORTS.includes(name) && (removedExports.add(name), exportPath.remove());
62
+ } else if (t.isVariableDeclaration(declaration))
63
+ for (let i = declaration.declarations.length - 1; i >= 0; i--) {
64
+ const declarator = declaration.declarations[i];
65
+ if (t.isIdentifier(declarator.id)) {
66
+ const name = declarator.id.name;
67
+ SERVER_EXPORTS.includes(name) && (removedExports.add(name), declaration.declarations.length === 1 ? exportPath.remove() : declaration.declarations.splice(i, 1));
68
+ }
69
+ }
70
+ },
71
+ // Also remove helper functions created by babel's async-to-generator transform
72
+ // These are named _loader, _generateStaticParams, etc.
73
+ FunctionDeclaration(funcPath) {
74
+ if (!funcPath.node.id) return;
75
+ const name = funcPath.node.id.name;
76
+ for (const serverExport of SERVER_EXPORTS)
77
+ if (name === `_${serverExport}`) {
78
+ let isAsyncHelper = !1;
79
+ funcPath.traverse({
80
+ Identifier(idPath) {
81
+ idPath.node.name === "_asyncToGenerator" && (isAsyncHelper = !0, idPath.stop());
82
+ }
83
+ }), isAsyncHelper && (removedExports.add(serverExport), funcPath.remove());
84
+ }
85
+ }
86
+ }), removedExports.size === 0)
87
+ return;
88
+ try {
89
+ (0, import_babel_dead_code_elimination.deadCodeElimination)(path.node, state.referenced);
90
+ } catch (error) {
91
+ console.warn(
92
+ `[one/metro] Dead code elimination failed for ${filename}:`,
93
+ error instanceof Error ? error.message : String(error)
94
+ );
95
+ }
96
+ const stubs = [];
97
+ removedExports.has("loader") && stubs.push(
98
+ t.exportNamedDeclaration(
99
+ t.functionDeclaration(
100
+ t.identifier("loader"),
101
+ [],
102
+ t.blockStatement([t.returnStatement(t.stringLiteral("__vxrn__loader__"))])
103
+ )
104
+ )
105
+ ), removedExports.has("generateStaticParams") && stubs.push(
106
+ t.exportNamedDeclaration(
107
+ t.functionDeclaration(
108
+ t.identifier("generateStaticParams"),
109
+ [],
110
+ t.blockStatement([])
111
+ )
112
+ )
113
+ );
114
+ for (const stub of stubs)
115
+ path.pushContainer("body", stub);
116
+ console.info(
117
+ ` \u{1F9F9} [one/metro] ${filename} removed ${removedExports.size} server-only exports`
118
+ );
119
+ }
120
+ }
121
+ }
122
+ };
123
+ }
124
+ var remove_server_code_default = removeServerCodePlugin;
125
+ //# sourceMappingURL=remove-server-code.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/babel-plugins/remove-server-code.ts"],
4
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBA,QAAmB,qCACnB,qCAA+D;AAE/D,MAAM,iBAAiB,CAAC,UAAU,sBAAsB;AAQxD,SAAS,uBAAuB,GAAY,SAAmC;AAC7E,QAAM,EAAE,aAAa,MAAM,IAAI;AAE/B,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,MACP,SAAS;AAAA,QACP,MAAM,MAA2B,OAAwD;AACvF,gBAAM,WAAW,MAAM;AAcvB,cAXI,CAAC,YAMD,CADsB,IAAI,OAAO,UAAU,UAAU,SAAS,EAC3C,KAAK,QAAQ,KAKhC,SAAS,SAAS,cAAc;AAClC;AAIF,gBAAM,OAAO,KAAK,SAAS;AAC3B,cAAK,8BAA8B,KAAK,IAAI;AAM5C,gBAAI;AACF,oBAAM,iBAAa,8DAA0B,KAAK,IAAW;AAAA,YAC/D,SAAS,OAAO;AACd,sBAAQ;AAAA,gBACN,yCAAyC,QAAQ;AAAA,gBACjD,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAAA,cACvD;AAAA,YACF;AAAA,QACF;AAAA,QAE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B,SAAS,OAAO;AAAA,gBAEpB;AAAA,YAEJ;AAAA,UACF,CAAC,GAGG,eAAe,SAAS;AAC1B;AAIF,cAAI;AACF,wEAAoB,KAAK,MAAa,MAAM,UAAiB;AAAA,UAC/D,SAAS,OAAO;AACd,oBAAQ;AAAA,cACN,gDAAgD,QAAQ;AAAA,cACxD,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAAA,YACvD;AAAA,UACF;AAGA,gBAAM,QAAuB,CAAC;AAE9B,UAAI,eAAe,IAAI,QAAQ,KAE7B,MAAM;AAAA,YACJ,EAAE;AAAA,cACA,EAAE;AAAA,gBACA,EAAE,WAAW,QAAQ;AAAA,gBACrB,CAAC;AAAA,gBACD,EAAE,eAAe,CAAC,EAAE,gBAAgB,EAAE,cAAc,kBAAkB,CAAC,CAAC,CAAC;AAAA,cAC3E;AAAA,YACF;AAAA,UACF,GAGE,eAAe,IAAI,sBAAsB,KAE3C,MAAM;AAAA,YACJ,EAAE;AAAA,cACA,EAAE;AAAA,gBACA,EAAE,WAAW,sBAAsB;AAAA,gBACnC,CAAC;AAAA,gBACD,EAAE,eAAe,CAAC,CAAC;AAAA,cACrB;AAAA,YACF;AAAA,UACF;AAIF,qBAAW,QAAQ;AACjB,iBAAK,cAAc,QAAQ,IAAI;AAGjC,kBAAQ;AAAA,YACN,0BAAmB,QAAQ,YAAY,eAAe,IAAI;AAAA,UAC5D;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAEA,IAAO,6BAAQ;",
5
+ "names": []
6
+ }
@@ -0,0 +1,153 @@
1
+ "use strict";
2
+
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf,
8
+ __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all) __defProp(target, name, {
11
+ get: all[name],
12
+ enumerable: !0
13
+ });
14
+ },
15
+ __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
17
+ get: () => from[key],
18
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
+ });
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
+ // If the importer is in node compatibility mode or this is not an ESM
24
+ // file that has been converted to a CommonJS file using a Babel-
25
+ // compatible transform (i.e. "__esModule" has not been set), then set
26
+ // "default" to the CommonJS "module.exports" for node compatibility.
27
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
28
+ value: mod,
29
+ enumerable: !0
30
+ }) : target, mod)),
31
+ __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
+ value: !0
33
+ }), mod);
34
+ var remove_server_code_exports = {};
35
+ __export(remove_server_code_exports, {
36
+ default: () => remove_server_code_default
37
+ });
38
+ module.exports = __toCommonJS(remove_server_code_exports);
39
+ var t = __toESM(require("@babel/types"), 1),
40
+ import_babel_dead_code_elimination = require("babel-dead-code-elimination");
41
+ function _instanceof(left, right) {
42
+ return right != null && typeof Symbol < "u" && right[Symbol.hasInstance] ? !!right[Symbol.hasInstance](left) : left instanceof right;
43
+ }
44
+ var SERVER_EXPORTS = ["loader", "generateStaticParams"];
45
+ function removeServerCodePlugin(_, options) {
46
+ var {
47
+ routerRoot = "app"
48
+ } = options;
49
+ return {
50
+ name: "one-remove-server-code",
51
+ visitor: {
52
+ Program: {
53
+ enter(path, state) {
54
+ var filename = state.filename;
55
+ if (filename) {
56
+ var routerRootPattern = new RegExp(`[/\\\\]${routerRoot}[/\\\\]`);
57
+ if (routerRootPattern.test(filename) && !filename.includes("node_modules")) {
58
+ var code = path.toString();
59
+ if (/generateStaticParams|loader/.test(code)) try {
60
+ state.referenced = (0, import_babel_dead_code_elimination.findReferencedIdentifiers)(path.node);
61
+ } catch (error) {
62
+ console.warn(`[one/metro] Skipping tree shaking for ${filename} due to identifier analysis error:`, _instanceof(error, Error) ? error.message : String(error));
63
+ }
64
+ }
65
+ }
66
+ },
67
+ exit(path, state) {
68
+ var filename = state.filename;
69
+ if (filename) {
70
+ var routerRootPattern = new RegExp(`[/\\\\]${routerRoot}[/\\\\]`);
71
+ if (routerRootPattern.test(filename) && !filename.includes("node_modules") && state.referenced) {
72
+ var removedExports = /* @__PURE__ */new Set();
73
+ if (path.traverse({
74
+ ExportNamedDeclaration(exportPath) {
75
+ var declaration = exportPath.node.declaration;
76
+ if (t.isFunctionDeclaration(declaration) && declaration.id) {
77
+ var name = declaration.id.name;
78
+ SERVER_EXPORTS.includes(name) && (removedExports.add(name), exportPath.remove());
79
+ } else if (t.isVariableDeclaration(declaration)) for (var i = declaration.declarations.length - 1; i >= 0; i--) {
80
+ var declarator = declaration.declarations[i];
81
+ if (t.isIdentifier(declarator.id)) {
82
+ var name1 = declarator.id.name;
83
+ SERVER_EXPORTS.includes(name1) && (removedExports.add(name1), declaration.declarations.length === 1 ? exportPath.remove() : declaration.declarations.splice(i, 1));
84
+ }
85
+ }
86
+ },
87
+ // Also remove helper functions created by babel's async-to-generator transform
88
+ // These are named _loader, _generateStaticParams, etc.
89
+ FunctionDeclaration(funcPath) {
90
+ if (funcPath.node.id) {
91
+ var name = funcPath.node.id.name,
92
+ _iteratorNormalCompletion2 = !0,
93
+ _didIteratorError2 = !1,
94
+ _iteratorError2 = void 0;
95
+ try {
96
+ for (var _loop = function () {
97
+ var serverExport = _step2.value;
98
+ if (name === `_${serverExport}`) {
99
+ var isAsyncHelper = !1;
100
+ funcPath.traverse({
101
+ Identifier(idPath) {
102
+ idPath.node.name === "_asyncToGenerator" && (isAsyncHelper = !0, idPath.stop());
103
+ }
104
+ }), isAsyncHelper && (removedExports.add(serverExport), funcPath.remove());
105
+ }
106
+ }, _iterator2 = SERVER_EXPORTS[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = !0) _loop();
107
+ } catch (err) {
108
+ _didIteratorError2 = !0, _iteratorError2 = err;
109
+ } finally {
110
+ try {
111
+ !_iteratorNormalCompletion2 && _iterator2.return != null && _iterator2.return();
112
+ } finally {
113
+ if (_didIteratorError2) throw _iteratorError2;
114
+ }
115
+ }
116
+ }
117
+ }
118
+ }), removedExports.size !== 0) {
119
+ try {
120
+ (0, import_babel_dead_code_elimination.deadCodeElimination)(path.node, state.referenced);
121
+ } catch (error) {
122
+ console.warn(`[one/metro] Dead code elimination failed for ${filename}:`, _instanceof(error, Error) ? error.message : String(error));
123
+ }
124
+ var stubs = [];
125
+ removedExports.has("loader") && stubs.push(t.exportNamedDeclaration(t.functionDeclaration(t.identifier("loader"), [], t.blockStatement([t.returnStatement(t.stringLiteral("__vxrn__loader__"))])))), removedExports.has("generateStaticParams") && stubs.push(t.exportNamedDeclaration(t.functionDeclaration(t.identifier("generateStaticParams"), [], t.blockStatement([]))));
126
+ var _iteratorNormalCompletion = !0,
127
+ _didIteratorError = !1,
128
+ _iteratorError = void 0;
129
+ try {
130
+ for (var _iterator = stubs[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
131
+ var stub = _step.value;
132
+ path.pushContainer("body", stub);
133
+ }
134
+ } catch (err) {
135
+ _didIteratorError = !0, _iteratorError = err;
136
+ } finally {
137
+ try {
138
+ !_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
139
+ } finally {
140
+ if (_didIteratorError) throw _iteratorError;
141
+ }
142
+ }
143
+ console.info(` \u{1F9F9} [one/metro] ${filename} removed ${removedExports.size} server-only exports`);
144
+ }
145
+ }
146
+ }
147
+ }
148
+ }
149
+ }
150
+ };
151
+ }
152
+ var remove_server_code_default = removeServerCodePlugin;
153
+ //# sourceMappingURL=remove-server-code.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","remove_server_code_exports","__export","default","remove_server_code_default","module","exports","t","__toESM","require","import_babel_dead_code_elimination","_instanceof","left","right","Symbol","hasInstance","SERVER_EXPORTS","removeServerCodePlugin","_","options","routerRoot","name","visitor","Program","enter","path","state","filename","routerRootPattern","RegExp","test","includes","code","toString","referenced","findReferencedIdentifiers","node","error","console","warn","Error","message","String","exit","removedExports","Set","traverse","ExportNamedDeclaration","exportPath","declaration","isFunctionDeclaration","id","add","remove","isVariableDeclaration","i","declarations","length","declarator","isIdentifier","name1","splice","FunctionDeclaration","funcPath","_iteratorNormalCompletion2","_didIteratorError2","_iteratorError2","_loop","serverExport","_step2","isAsyncHelper","Identifier","idPath","stop","_iterator2","iterator","next","done","err","return","size","deadCodeElimination","stubs","has","push","exportNamedDeclaration","functionDeclaration","identifier","blockStatement","returnStatement","stringLiteral","_iteratorNormalCompletion","_didIteratorError","_iteratorError","_iterator","_step","stub","pushContainer"],"sources":["../../../src/babel-plugins/remove-server-code.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,OAAA,EAAAA,CAAA,KAAAC;AAAA;AAkBAC,MAAA,CAAAC,OAAmB,GAAAV,YAAA,CAAAK,0BACnB;AAEA,IAAAM,CAAA,GAAMC,OAAA,CAAAC,OAAiB,CAAC,cAAU;EAAAC,kCAAsB,GAAAD,OAAA;AAQxD,SAASE,YAAAC,IAAA,EAAAC,KAAuB;EAC9B,OAAMA,KAAE,YAAa,OAAUC,MAAA,UAAAD,KAAA,CAAAC,MAAA,CAAAC,WAAA,MAAAF,KAAA,CAAAC,MAAA,CAAAC,WAAA,EAAAH,IAAA,IAAAA,IAAA,YAAAC,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,CAAA7E,CAAA,CAAA8E,sBAAA,CAAA9E,CAAA,CAAA+E,mBAAA,CAAA/E,CAAA,CAAAgF,UAAA,8BAAAhF,CAAA,CAAAiF,cAAA;gBAC5D,IAAAG,yBAAA;kBAAAC,iBAAA;kBAAAC,cAAA;gBACF;kBACF,SAAAC,SAAA,GAAAZ,KAAA,CAAApE,MAAA,CAAA6D,QAAA,KAAAoB,KAAA,IAAAJ,yBAAA,IAAAI,KAAA,GAAAD,SAAA,CAAAlB,IAAA,IAAAC,IAAA,GAAAc,yBAAA;oBACF,IAAAK,IAAA,GAAAD,KAAA,CAAA/F,KAAA;oBACFyB,IAAA,CAAAwE,aAAA,SAAAD,IAAA;kBACF;gBAEO,SAAAlB,GAAA","ignoreList":[]}
@@ -38,12 +38,17 @@ var import_node_path = require("node:path"),
38
38
  import_fs_extra = __toESM(require("fs-extra"), 1),
39
39
  constants = __toESM(require("../constants.cjs"), 1),
40
40
  import_cleanUrl = require("../utils/cleanUrl.cjs"),
41
+ import_isResponse = require("../utils/isResponse.cjs"),
41
42
  import_toAbsolute = require("../utils/toAbsolute.cjs"),
42
43
  import_replaceLoader = require("../vite/replaceLoader.cjs");
43
44
  const {
44
45
  readFile,
45
46
  outputFile
46
47
  } = import_fs_extra.default;
48
+ function urlPathToFilePath(urlPath) {
49
+ const parts = urlPath.replace(/^\//, "").split("/");
50
+ return (0, import_node_path.join)(...parts);
51
+ }
47
52
  async function buildPage(serverEntry, path, relativeId, params, foundRoute, clientManifestEntry, staticDir, clientDir, builtMiddlewares, serverJsPath, preloads, allCSS, routePreloads, allCSSContents, criticalPreloads, deferredPreloads, useAfterLCP, useAfterLCPAggressive) {
48
53
  const render = await getRender(serverEntry),
49
54
  htmlPath = `${path.endsWith("/") ? `${removeTrailingSlash(path)}/index` : path}.html`,
@@ -70,7 +75,7 @@ async function buildPage(serverEntry, path, relativeId, params, foundRoute, clie
70
75
  // register all route modules using window global
71
76
  ...registrationCalls].join(`
72
77
  `);
73
- await import_fs_extra.default.writeFile((0, import_node_path.join)(clientDir, preloadPath), preloadContent);
78
+ await import_fs_extra.default.writeFile((0, import_node_path.join)(clientDir, urlPathToFilePath(preloadPath)), preloadContent);
74
79
  const uniqueCSS = [...new Set(allCSS)],
75
80
  cssPreloadContent = `
76
81
  const CSS_TIMEOUT = 1000
@@ -127,13 +132,17 @@ export function injectCSS() {
127
132
  // For backwards compatibility, also prefetch on import
128
133
  prefetchCSS()
129
134
  `;
130
- await import_fs_extra.default.writeFile((0, import_node_path.join)(clientDir, cssPreloadPath), cssPreloadContent);
135
+ await import_fs_extra.default.writeFile((0, import_node_path.join)(clientDir, urlPathToFilePath(cssPreloadPath)), cssPreloadContent);
131
136
  const exported = await import((0, import_toAbsolute.toAbsolute)(serverJsPath));
132
137
  if (exported.loader) {
133
- loaderData = (await exported.loader?.({
134
- path,
135
- params
136
- })) ?? null;
138
+ try {
139
+ loaderData = (await exported.loader?.({
140
+ path,
141
+ params
142
+ })) ?? null;
143
+ } catch (err) {
144
+ if (!(0, import_isResponse.isResponse)(err)) throw err;
145
+ }
137
146
  const code = await readFile(clientJsPath, "utf-8"),
138
147
  withLoader =
139
148
  // super dirty to quickly make ssr loaders work until we have better
@@ -143,7 +152,7 @@ if (typeof document === 'undefined') globalThis.document = {}
143
152
  code,
144
153
  loaderData
145
154
  }),
146
- loaderPartialPath = (0, import_node_path.join)(clientDir, (0, import_cleanUrl.getLoaderPath)(path));
155
+ loaderPartialPath = (0, import_node_path.join)(clientDir, urlPathToFilePath((0, import_cleanUrl.getLoaderPath)(path)));
147
156
  await outputFile(loaderPartialPath, withLoader), loaderPath = (0, import_cleanUrl.getLoaderPath)(path);
148
157
  }
149
158
  if (foundRoute.type !== "ssr") {
@@ -25,8 +25,12 @@ __export(buildPage_exports, {
25
25
  buildPage: () => buildPage
26
26
  });
27
27
  module.exports = __toCommonJS(buildPage_exports);
28
- var import_node_path = require("node:path"), import_fs_extra = __toESM(require("fs-extra"), 1), constants = __toESM(require("../constants"), 1), import_cleanUrl = require("../utils/cleanUrl"), import_toAbsolute = require("../utils/toAbsolute"), import_replaceLoader = require("../vite/replaceLoader");
28
+ var import_node_path = require("node:path"), import_fs_extra = __toESM(require("fs-extra"), 1), constants = __toESM(require("../constants"), 1), import_cleanUrl = require("../utils/cleanUrl"), import_isResponse = require("../utils/isResponse"), import_toAbsolute = require("../utils/toAbsolute"), import_replaceLoader = require("../vite/replaceLoader");
29
29
  const { readFile, outputFile } = import_fs_extra.default;
30
+ function urlPathToFilePath(urlPath) {
31
+ const parts = urlPath.replace(/^\//, "").split("/");
32
+ return (0, import_node_path.join)(...parts);
33
+ }
30
34
  async function buildPage(serverEntry, path, relativeId, params, foundRoute, clientManifestEntry, staticDir, clientDir, builtMiddlewares, serverJsPath, preloads, allCSS, routePreloads, allCSSContents, criticalPreloads, deferredPreloads, useAfterLCP, useAfterLCPAggressive) {
31
35
  const render = await getRender(serverEntry), htmlPath = `${path.endsWith("/") ? `${removeTrailingSlash(path)}/index` : path}.html`, clientJsPath = (0, import_node_path.join)("dist/client", clientManifestEntry.file), htmlOutPath = (0, import_toAbsolute.toAbsolute)((0, import_node_path.join)(staticDir, htmlPath)), preloadPath = (0, import_cleanUrl.getPreloadPath)(path), cssPreloadPath = (0, import_cleanUrl.getPreloadCSSPath)(path);
32
36
  let loaderPath = "", loaderData = {};
@@ -48,7 +52,7 @@ async function buildPage(serverEntry, path, relativeId, params, foundRoute, clie
48
52
  ...registrationCalls
49
53
  ].join(`
50
54
  `);
51
- await import_fs_extra.default.writeFile((0, import_node_path.join)(clientDir, preloadPath), preloadContent);
55
+ await import_fs_extra.default.writeFile((0, import_node_path.join)(clientDir, urlPathToFilePath(preloadPath)), preloadContent);
52
56
  const uniqueCSS = [...new Set(allCSS)], cssPreloadContent = `
53
57
  const CSS_TIMEOUT = 1000
54
58
  const cssUrls = ${JSON.stringify(uniqueCSS)}
@@ -104,10 +108,15 @@ export function injectCSS() {
104
108
  // For backwards compatibility, also prefetch on import
105
109
  prefetchCSS()
106
110
  `;
107
- await import_fs_extra.default.writeFile((0, import_node_path.join)(clientDir, cssPreloadPath), cssPreloadContent);
111
+ await import_fs_extra.default.writeFile((0, import_node_path.join)(clientDir, urlPathToFilePath(cssPreloadPath)), cssPreloadContent);
108
112
  const exported = await import((0, import_toAbsolute.toAbsolute)(serverJsPath));
109
113
  if (exported.loader) {
110
- loaderData = await exported.loader?.({ path, params }) ?? null;
114
+ try {
115
+ loaderData = await exported.loader?.({ path, params }) ?? null;
116
+ } catch (err) {
117
+ if (!(0, import_isResponse.isResponse)(err))
118
+ throw err;
119
+ }
111
120
  const code = await readFile(clientJsPath, "utf-8"), withLoader = (
112
121
  // super dirty to quickly make ssr loaders work until we have better
113
122
  `
@@ -116,7 +125,7 @@ if (typeof document === 'undefined') globalThis.document = {}
116
125
  code,
117
126
  loaderData
118
127
  })
119
- ), loaderPartialPath = (0, import_node_path.join)(clientDir, (0, import_cleanUrl.getLoaderPath)(path));
128
+ ), loaderPartialPath = (0, import_node_path.join)(clientDir, urlPathToFilePath((0, import_cleanUrl.getLoaderPath)(path)));
120
129
  await outputFile(loaderPartialPath, withLoader), loaderPath = (0, import_cleanUrl.getLoaderPath)(path);
121
130
  }
122
131
  if (foundRoute.type !== "ssr") {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/cli/buildPage.ts"],
4
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAqB,sBACrB,kBAAoB,iCACpB,YAA2B,qCAE3B,kBAAiE,8BACjE,oBAA2B,gCAC3B,uBAA8B;AAG9B,MAAM,EAAE,UAAU,WAAW,IAAI,gBAAAA;AAEjC,eAAsB,UACpB,aACA,MACA,YACA,QACA,YACA,qBACA,WACA,WACA,kBACA,cACA,UACA,QACA,eACA,gBACA,kBACA,kBACA,aACA,uBAC6B;AAC7B,QAAM,SAAS,MAAM,UAAU,WAAW,GACpC,WAAW,GAAG,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AA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEA,eAAe,UAAU,aAAqB;AAC5C,MAAI,SAA2B;AAE/B,MAAI;AACF,UAAM,eAAe,MAAM,OAAO;AAElC,aACE,aAAa,QAAQ;AAAA,IAErB,aAAa,QAAQ,SAAS,QAE5B,OAAO,UAAW,eACpB,QAAQ,MAAM,sDAAiD,YAAY,GAC3E,QAAQ,KAAK,CAAC;AAAA,EAElB,SAAS,KAAK;AACZ,YAAQ,MAAM,wCAAmC,GACjD,QAAQ,MAAM,4CAA4C,WAAW,EAAE,GAEvE,QAAQ,MAAM,IAAI,KAAQ,GAC1B,QAAQ,KAAK,CAAC;AAAA,EAChB;AAEA,SAAO;AACT;AAEA,SAAS,oBAAoB,MAAc;AACzC,SAAO,KAAK,SAAS,GAAG,IAAI,KAAK,MAAM,GAAG,KAAK,SAAS,CAAC,IAAI;AAC/D;AAOA,SAAS,wBAAwB,MAAc,UAA4B;AAGzE,SAAO,KAAK,QAAQ,uDAAuD,EAAE;AAI7E,QAAM,eAAe;AAAA;AAAA;AAAA,kBAGL,KAAK,UAAU,QAAQ,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA2BxC,gBAAO,KAAK,QAAQ,WAAW,GAAG,YAAY,SAAS,GAEhD;AACT;",
5
5
  "names": ["FSExtra"]
6
6
  }
@@ -40,6 +40,7 @@ var import_path = require("path"),
40
40
  import_fs_extra = __toESM(require("fs-extra"), 1),
41
41
  constants = __toESM(require("../constants.native.js"), 1),
42
42
  import_cleanUrl = require("../utils/cleanUrl.native.js"),
43
+ import_isResponse = require("../utils/isResponse.native.js"),
43
44
  import_toAbsolute = require("../utils/toAbsolute.native.js"),
44
45
  import_replaceLoader = require("../vite/replaceLoader.native.js");
45
46
  function _instanceof(left, right) {
@@ -49,6 +50,10 @@ var {
49
50
  readFile,
50
51
  outputFile
51
52
  } = import_fs_extra.default;
53
+ function urlPathToFilePath(urlPath) {
54
+ var parts = urlPath.replace(/^\//, "").split("/");
55
+ return (0, import_path.join)(...parts);
56
+ }
52
57
  async function buildPage(serverEntry, path, relativeId, params, foundRoute, clientManifestEntry, staticDir, clientDir, builtMiddlewares, serverJsPath, preloads, allCSS, routePreloads, allCSSContents, criticalPreloads, deferredPreloads, useAfterLCP, useAfterLCPAggressive) {
53
58
  var render = await getRender(serverEntry),
54
59
  htmlPath = `${path.endsWith("/") ? `${removeTrailingSlash(path)}/index` : path}.html`,
@@ -93,7 +98,7 @@ async function buildPage(serverEntry, path, relativeId, params, foundRoute, clie
93
98
  // register all route modules using window global
94
99
  ...registrationCalls].join(`
95
100
  `);
96
- await import_fs_extra.default.writeFile((0, import_path.join)(clientDir, preloadPath), preloadContent);
101
+ await import_fs_extra.default.writeFile((0, import_path.join)(clientDir, urlPathToFilePath(preloadPath)), preloadContent);
97
102
  var uniqueCSS = [...new Set(allCSS)],
98
103
  cssPreloadContent = `
99
104
  const CSS_TIMEOUT = 1000
@@ -150,14 +155,18 @@ export function injectCSS() {
150
155
  // For backwards compatibility, also prefetch on import
151
156
  prefetchCSS()
152
157
  `;
153
- await import_fs_extra.default.writeFile((0, import_path.join)(clientDir, cssPreloadPath), cssPreloadContent);
158
+ await import_fs_extra.default.writeFile((0, import_path.join)(clientDir, urlPathToFilePath(cssPreloadPath)), cssPreloadContent);
154
159
  var exported = await import((0, import_toAbsolute.toAbsolute)(serverJsPath));
155
160
  if (exported.loader) {
156
- var _exported_loader, _ref;
157
- loaderData = (_ref = await ((_exported_loader = exported.loader) === null || _exported_loader === void 0 ? void 0 : _exported_loader.call(exported, {
158
- path,
159
- params
160
- }))) !== null && _ref !== void 0 ? _ref : null;
161
+ try {
162
+ var _exported_loader, _ref;
163
+ loaderData = (_ref = await ((_exported_loader = exported.loader) === null || _exported_loader === void 0 ? void 0 : _exported_loader.call(exported, {
164
+ path,
165
+ params
166
+ }))) !== null && _ref !== void 0 ? _ref : null;
167
+ } catch (err) {
168
+ if (!(0, import_isResponse.isResponse)(err)) throw err;
169
+ }
161
170
  var code = await readFile(clientJsPath, "utf-8"),
162
171
  withLoader =
163
172
  // super dirty to quickly make ssr loaders work until we have better
@@ -167,7 +176,7 @@ if (typeof document === 'undefined') globalThis.document = {}
167
176
  code,
168
177
  loaderData
169
178
  }),
170
- loaderPartialPath = (0, import_path.join)(clientDir, (0, import_cleanUrl.getLoaderPath)(path));
179
+ loaderPartialPath = (0, import_path.join)(clientDir, urlPathToFilePath((0, import_cleanUrl.getLoaderPath)(path)));
171
180
  await outputFile(loaderPartialPath, withLoader), loaderPath = (0, import_cleanUrl.getLoaderPath)(path);
172
181
  }
173
182
  if (foundRoute.type !== "ssr") {