vxrn 0.1.83 → 0.1.85
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.depcheckrc +1 -0
- package/LICENSE +22 -0
- package/dist/cjs/cli.native.js +53 -58
- package/dist/cjs/cli.native.js.map +1 -1
- package/dist/cjs/exports/build.js +4 -3
- package/dist/cjs/exports/build.js.map +1 -1
- package/dist/cjs/exports/build.native.js +59 -61
- package/dist/cjs/exports/build.native.js.map +1 -1
- package/dist/cjs/exports/createServer.native.js +53 -58
- package/dist/cjs/exports/createServer.native.js.map +1 -1
- package/dist/cjs/exports/dev.native.js +65 -79
- package/dist/cjs/exports/dev.native.js.map +1 -1
- package/dist/cjs/exports/serve.native.js +53 -58
- package/dist/cjs/exports/serve.native.js.map +1 -1
- package/dist/cjs/plugins/clientInjectPlugin.native.js +53 -58
- package/dist/cjs/plugins/clientInjectPlugin.native.js.map +1 -1
- package/dist/cjs/plugins/reactNativeCommonJsPlugin.js +1 -2
- package/dist/cjs/plugins/reactNativeCommonJsPlugin.js.map +1 -1
- package/dist/cjs/plugins/reactNativeCommonJsPlugin.native.js +60 -72
- package/dist/cjs/plugins/reactNativeCommonJsPlugin.native.js.map +1 -1
- package/dist/cjs/plugins/reactNativeHMRPlugin.js +1 -2
- package/dist/cjs/plugins/reactNativeHMRPlugin.js.map +1 -1
- package/dist/cjs/plugins/reactNativeHMRPlugin.native.js +59 -70
- package/dist/cjs/plugins/reactNativeHMRPlugin.native.js.map +1 -1
- package/dist/cjs/utils/findDepsToOptimize.js +167 -0
- package/dist/cjs/utils/findDepsToOptimize.js.map +6 -0
- package/dist/cjs/utils/findDepsToOptimize.native.js +564 -0
- package/dist/cjs/utils/findDepsToOptimize.native.js.map +6 -0
- package/dist/cjs/utils/getBaseViteConfig.js +12 -1
- package/dist/cjs/utils/getBaseViteConfig.js.map +1 -1
- package/dist/cjs/utils/getBaseViteConfig.native.js +12 -1
- package/dist/cjs/utils/getBaseViteConfig.native.js.map +2 -2
- package/dist/cjs/utils/getOptimizeDeps.native.js +6 -12
- package/dist/cjs/utils/getOptimizeDeps.native.js.map +1 -1
- package/dist/cjs/utils/getOptionsFilled.native.js +59 -70
- package/dist/cjs/utils/getOptionsFilled.native.js.map +1 -1
- package/dist/cjs/utils/getReactNativeBundle.native.js +53 -58
- package/dist/cjs/utils/getReactNativeBundle.native.js.map +1 -1
- package/dist/cjs/utils/getVitePath.native.js +53 -58
- package/dist/cjs/utils/getVitePath.native.js.map +1 -1
- package/dist/cjs/utils/getViteServerConfig.native.js +59 -70
- package/dist/cjs/utils/getViteServerConfig.native.js.map +1 -1
- package/dist/cjs/utils/patches.native.js +59 -70
- package/dist/cjs/utils/patches.native.js.map +1 -1
- package/dist/cjs/utils/readVXRNConfig.native.js +53 -58
- package/dist/cjs/utils/readVXRNConfig.native.js.map +1 -1
- package/dist/cjs/utils/swapPrebuiltReactModules.js +1 -2
- package/dist/cjs/utils/swapPrebuiltReactModules.js.map +1 -1
- package/dist/cjs/utils/swapPrebuiltReactModules.native.js +54 -60
- package/dist/cjs/utils/swapPrebuiltReactModules.native.js.map +1 -1
- package/dist/cjs/utils/uniq.native.js +6 -12
- package/dist/cjs/utils/uniq.native.js.map +1 -1
- package/dist/cjs/vendor/debugger-app/index.js +0 -22
- package/dist/cjs/vendor/debugger-app/index.js.map +2 -2
- package/dist/cjs/vendor/debugger-app/index.native.js +0 -22
- package/dist/cjs/vendor/debugger-app/index.native.js.map +3 -3
- package/dist/cjs/vendor/debugger-app/src/debuggerWorker.js +0 -46
- package/dist/cjs/vendor/debugger-app/src/debuggerWorker.js.map +3 -3
- package/dist/cjs/vendor/debugger-app/src/debuggerWorker.native.js +0 -54
- package/dist/cjs/vendor/debugger-app/src/debuggerWorker.native.js.map +3 -3
- package/dist/cjs/vendor/debugger-app/src/index.js +0 -104
- package/dist/cjs/vendor/debugger-app/src/index.js.map +3 -3
- package/dist/cjs/vendor/debugger-app/src/index.native.js +0 -132
- package/dist/cjs/vendor/debugger-app/src/index.native.js.map +3 -3
- package/dist/esm/cli.native.js +53 -58
- package/dist/esm/cli.native.js.map +1 -1
- package/dist/esm/exports/build.js +4 -3
- package/dist/esm/exports/build.js.map +1 -1
- package/dist/esm/exports/build.mjs +4 -3
- package/dist/esm/exports/build.native.js +59 -61
- package/dist/esm/exports/build.native.js.map +1 -1
- package/dist/esm/exports/createServer.native.js +53 -58
- package/dist/esm/exports/createServer.native.js.map +1 -1
- package/dist/esm/exports/dev.native.js +65 -79
- package/dist/esm/exports/dev.native.js.map +1 -1
- package/dist/esm/exports/serve.native.js +53 -58
- package/dist/esm/exports/serve.native.js.map +1 -1
- package/dist/esm/plugins/clientInjectPlugin.native.js +53 -58
- package/dist/esm/plugins/clientInjectPlugin.native.js.map +1 -1
- package/dist/esm/plugins/reactNativeCommonJsPlugin.js +1 -2
- package/dist/esm/plugins/reactNativeCommonJsPlugin.js.map +1 -1
- package/dist/esm/plugins/reactNativeCommonJsPlugin.native.js +60 -72
- package/dist/esm/plugins/reactNativeCommonJsPlugin.native.js.map +1 -1
- package/dist/esm/plugins/reactNativeHMRPlugin.js +1 -2
- package/dist/esm/plugins/reactNativeHMRPlugin.js.map +1 -1
- package/dist/esm/plugins/reactNativeHMRPlugin.native.js +59 -70
- package/dist/esm/plugins/reactNativeHMRPlugin.native.js.map +1 -1
- package/dist/esm/utils/findDepsToOptimize.js +145 -0
- package/dist/esm/utils/findDepsToOptimize.js.map +6 -0
- package/dist/esm/utils/findDepsToOptimize.mjs +130 -0
- package/dist/esm/utils/findDepsToOptimize.native.js +530 -0
- package/dist/esm/utils/findDepsToOptimize.native.js.map +6 -0
- package/dist/esm/utils/getBaseViteConfig.js +12 -1
- package/dist/esm/utils/getBaseViteConfig.js.map +1 -1
- package/dist/esm/utils/getBaseViteConfig.mjs +3 -1
- package/dist/esm/utils/getBaseViteConfig.native.js +12 -1
- package/dist/esm/utils/getBaseViteConfig.native.js.map +2 -2
- package/dist/esm/utils/getOptimizeDeps.native.js +6 -12
- package/dist/esm/utils/getOptimizeDeps.native.js.map +1 -1
- package/dist/esm/utils/getOptionsFilled.native.js +59 -70
- package/dist/esm/utils/getOptionsFilled.native.js.map +1 -1
- package/dist/esm/utils/getReactNativeBundle.native.js +53 -58
- package/dist/esm/utils/getReactNativeBundle.native.js.map +1 -1
- package/dist/esm/utils/getVitePath.native.js +53 -58
- package/dist/esm/utils/getVitePath.native.js.map +1 -1
- package/dist/esm/utils/getViteServerConfig.native.js +59 -70
- package/dist/esm/utils/getViteServerConfig.native.js.map +1 -1
- package/dist/esm/utils/patches.native.js +59 -70
- package/dist/esm/utils/patches.native.js.map +1 -1
- package/dist/esm/utils/readVXRNConfig.native.js +53 -58
- package/dist/esm/utils/readVXRNConfig.native.js.map +1 -1
- package/dist/esm/utils/swapPrebuiltReactModules.js +1 -2
- package/dist/esm/utils/swapPrebuiltReactModules.js.map +1 -1
- package/dist/esm/utils/swapPrebuiltReactModules.native.js +54 -60
- package/dist/esm/utils/swapPrebuiltReactModules.native.js.map +1 -1
- package/dist/esm/utils/uniq.native.js +6 -12
- package/dist/esm/utils/uniq.native.js.map +1 -1
- package/dist/esm/vendor/debugger-app/index.js +0 -5
- package/dist/esm/vendor/debugger-app/index.js.map +2 -2
- package/dist/esm/vendor/debugger-app/index.mjs +0 -3
- package/dist/esm/vendor/debugger-app/index.native.js +0 -5
- package/dist/esm/vendor/debugger-app/index.native.js.map +3 -3
- package/dist/esm/vendor/debugger-app/src/debuggerWorker.js +0 -46
- package/dist/esm/vendor/debugger-app/src/debuggerWorker.js.map +3 -3
- package/dist/esm/vendor/debugger-app/src/debuggerWorker.mjs +0 -47
- package/dist/esm/vendor/debugger-app/src/debuggerWorker.native.js +0 -54
- package/dist/esm/vendor/debugger-app/src/debuggerWorker.native.js.map +3 -3
- package/dist/esm/vendor/debugger-app/src/index.js +0 -86
- package/dist/esm/vendor/debugger-app/src/index.js.map +2 -2
- package/dist/esm/vendor/debugger-app/src/index.mjs +0 -125
- package/dist/esm/vendor/debugger-app/src/index.native.js +0 -115
- package/dist/esm/vendor/debugger-app/src/index.native.js.map +3 -3
- package/package.json +10 -26
- package/src/exports/build.ts +3 -2
- package/src/types.ts +2 -3
- package/src/utils/findDepsToOptimize.ts +293 -0
- package/src/utils/getBaseViteConfig.ts +12 -0
- package/src/vendor/debugger-app/index.js +2 -2
- package/src/vendor/debugger-app/src/debuggerWorker.js +77 -77
- package/src/vendor/debugger-app/src/index.js +199 -199
- package/src/vendor/debugger-app/webpack.config.cjs +70 -70
- package/types/types.d.ts +2 -3
- package/types/utils/findDepsToOptimize.d.ts +19 -0
- package/types/utils/getOptionsFilled.d.ts +1 -0
- package/src/vendor/debugger-app/index.d.ts +0 -2
|
@@ -1,116 +1 @@
|
|
|
1
|
-
import "./index.css";
|
|
2
|
-
import DebuggerWorker from "./debuggerWorker.js";
|
|
3
|
-
var blueIcon = "", grayIcon = "", orangeIcon = "", isMacLike = /(Mac|iPhone|iPod|iPad)/i.test(navigator.platform), refreshShortcut = isMacLike ? "\u2318R" : "Ctrl R";
|
|
4
|
-
window.onload = function() {
|
|
5
|
-
isMacLike || (document.getElementById("shortcut").innerHTML = "Ctrl\u21E7J"), Page.render();
|
|
6
|
-
};
|
|
7
|
-
window.onReloadClicked = function() {
|
|
8
|
-
var xhr = new XMLHttpRequest();
|
|
9
|
-
xhr.open("GET", "".concat(window.location.origin, "/reload"), !0), xhr.send();
|
|
10
|
-
};
|
|
11
|
-
var Page = window.Page = {
|
|
12
|
-
state: {
|
|
13
|
-
isDark: localStorage.getItem("darkTheme") === null ? window.matchMedia("(prefers-color-scheme: dark)").matches : localStorage.getItem("darkTheme") === "on",
|
|
14
|
-
isPriorityMaintained: localStorage.getItem("maintainPriority") === "on",
|
|
15
|
-
status: {
|
|
16
|
-
type: "disconnected"
|
|
17
|
-
},
|
|
18
|
-
visibilityState: document.visibilityState
|
|
19
|
-
},
|
|
20
|
-
setState: function(partialState) {
|
|
21
|
-
Page.state = Object.assign({}, Page.state, partialState), Page.render();
|
|
22
|
-
},
|
|
23
|
-
render: function() {
|
|
24
|
-
var _Page_state = Page.state, isDark = _Page_state.isDark, isPriorityMaintained = _Page_state.isPriorityMaintained, status = _Page_state.status, visibilityState = _Page_state.visibilityState, statusNode = document.getElementById("status");
|
|
25
|
-
switch (status.type) {
|
|
26
|
-
case "connected":
|
|
27
|
-
statusNode.innerHTML = "Debugger session #" + status.id + " active.";
|
|
28
|
-
break;
|
|
29
|
-
case "error":
|
|
30
|
-
statusNode.innerHTML = status.error.reason || "Disconnected from proxy. Attempting reconnection. Is node server running?";
|
|
31
|
-
break;
|
|
32
|
-
case "connecting":
|
|
33
|
-
case "disconnected":
|
|
34
|
-
default:
|
|
35
|
-
statusNode.innerHTML = 'Waiting, press <span class="shortcut">' + refreshShortcut + "</span> in simulator to reload and connect.";
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
var linkNode = document.querySelector("link[rel=icon]");
|
|
39
|
-
status.type === "disconnected" || status.type === "error" ? linkNode.href = grayIcon : visibilityState === "visible" || isPriorityMaintained ? linkNode.href = blueIcon : linkNode.href = orangeIcon;
|
|
40
|
-
var darkCheckbox = document.getElementById("dark");
|
|
41
|
-
document.body.classList.toggle("dark", isDark), darkCheckbox.checked = isDark, localStorage.setItem("darkTheme", isDark ? "on" : "");
|
|
42
|
-
var maintainPriorityCheckbox = document.getElementById("maintain-priority");
|
|
43
|
-
maintainPriorityCheckbox.checked = isPriorityMaintained, localStorage.setItem("maintainPriority", isPriorityMaintained ? "on" : "");
|
|
44
|
-
},
|
|
45
|
-
toggleDarkTheme: function() {
|
|
46
|
-
Page.setState({
|
|
47
|
-
isDark: !Page.state.isDark
|
|
48
|
-
});
|
|
49
|
-
},
|
|
50
|
-
togglePriorityMaintenance: function() {
|
|
51
|
-
Page.setState({
|
|
52
|
-
isPriorityMaintained: !Page.state.isPriorityMaintained
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
function connectToDebuggerProxy() {
|
|
57
|
-
var ws = new WebSocket("ws://" + window.location.host + "/debugger-proxy?role=debugger&name=Chrome"), worker;
|
|
58
|
-
function createJSRuntime() {
|
|
59
|
-
worker = new DebuggerWorker(), worker.onmessage = function(message) {
|
|
60
|
-
ws.send(JSON.stringify(message.data));
|
|
61
|
-
}, window.onbeforeunload = function() {
|
|
62
|
-
return "If you reload this page, it is going to break the debugging session. Press " + refreshShortcut + " on the device to reload.";
|
|
63
|
-
}, updateVisibility();
|
|
64
|
-
}
|
|
65
|
-
function shutdownJSRuntime() {
|
|
66
|
-
worker && (worker.terminate(), worker = null, window.onbeforeunload = null);
|
|
67
|
-
}
|
|
68
|
-
function updateVisibility() {
|
|
69
|
-
worker && !Page.state.isPriorityMaintained && worker.postMessage({
|
|
70
|
-
method: "setDebuggerVisibility",
|
|
71
|
-
visibilityState: document.visibilityState
|
|
72
|
-
}), Page.setState({
|
|
73
|
-
visibilityState: document.visibilityState
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
ws.onopen = function() {
|
|
77
|
-
Page.setState({
|
|
78
|
-
status: {
|
|
79
|
-
type: "connecting"
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
}, ws.onmessage = function(message) {
|
|
83
|
-
if (message.data) {
|
|
84
|
-
var object = JSON.parse(message.data);
|
|
85
|
-
if (object.$event === "client-disconnected") {
|
|
86
|
-
shutdownJSRuntime(), Page.setState({
|
|
87
|
-
status: {
|
|
88
|
-
type: "disconnected"
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
object.method && (object.method === "prepareJSRuntime" ? (shutdownJSRuntime(), console.clear(), createJSRuntime(), ws.send(JSON.stringify({
|
|
94
|
-
replyID: object.id
|
|
95
|
-
})), Page.setState({
|
|
96
|
-
status: {
|
|
97
|
-
type: "connected",
|
|
98
|
-
id: object.id
|
|
99
|
-
}
|
|
100
|
-
})) : object.method === "$disconnected" ? (shutdownJSRuntime(), Page.setState({
|
|
101
|
-
status: {
|
|
102
|
-
type: "disconnected"
|
|
103
|
-
}
|
|
104
|
-
})) : worker.postMessage(object));
|
|
105
|
-
}
|
|
106
|
-
}, ws.onclose = function(error) {
|
|
107
|
-
shutdownJSRuntime(), Page.setState({
|
|
108
|
-
status: {
|
|
109
|
-
type: "error",
|
|
110
|
-
error
|
|
111
|
-
}
|
|
112
|
-
}), error.reason && console.warn(error.reason), setTimeout(connectToDebuggerProxy, 500);
|
|
113
|
-
}, document.addEventListener("visibilitychange", updateVisibility, !1);
|
|
114
|
-
}
|
|
115
|
-
connectToDebuggerProxy();
|
|
116
1
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": [
|
|
4
|
-
"mappings": "
|
|
5
|
-
"names": [
|
|
3
|
+
"sources": [],
|
|
4
|
+
"mappings": "",
|
|
5
|
+
"names": []
|
|
6
6
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vxrn",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.85",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"types": "./types/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"scripts": {
|
|
13
13
|
"build": "tamagui-build",
|
|
14
14
|
"watch": "yarn build --watch",
|
|
15
|
+
"check": "yarn depcheck",
|
|
15
16
|
"clean": "tamagui-build clean",
|
|
16
17
|
"clean:build": "tamagui-build clean:build"
|
|
17
18
|
},
|
|
@@ -31,52 +32,35 @@
|
|
|
31
32
|
}
|
|
32
33
|
},
|
|
33
34
|
"dependencies": {
|
|
34
|
-
"@babel/
|
|
35
|
+
"@babel/core": "^7.21.8",
|
|
35
36
|
"@hono/node-server": "^1.11.1",
|
|
36
|
-
"@vitejs/plugin-react": "^4.2.1",
|
|
37
37
|
"@vitejs/plugin-react-swc": "^3.6.0",
|
|
38
|
-
"@vxrn/react-native-prebuilt": "0.1.
|
|
39
|
-
"@vxrn/safe-area": "0.1.
|
|
40
|
-
"@vxrn/vite-flow": "0.1.
|
|
41
|
-
"@vxrn/vite-native-
|
|
42
|
-
"@vxrn/vite-native-hmr": "0.1.83",
|
|
43
|
-
"@vxrn/vite-native-swc": "0.1.83",
|
|
38
|
+
"@vxrn/react-native-prebuilt": "0.1.85",
|
|
39
|
+
"@vxrn/safe-area": "0.1.85",
|
|
40
|
+
"@vxrn/vite-flow": "0.1.85",
|
|
41
|
+
"@vxrn/vite-native-swc": "0.1.85",
|
|
44
42
|
"citty": "^0.1.6",
|
|
45
43
|
"crossws": "^0.2.4",
|
|
46
44
|
"es-module-lexer": "^1.3.0",
|
|
47
45
|
"esbuild": "~0.19.3",
|
|
48
|
-
"esm-resolve": "^1.0.8",
|
|
49
|
-
"fast-glob": "^3.2.11",
|
|
50
46
|
"find-node-modules": "^2.1.3",
|
|
51
47
|
"fs-extra": "^11.2.0",
|
|
52
48
|
"get-port-please": "^3.1.2",
|
|
53
49
|
"h3": "^1.11.1",
|
|
54
|
-
"h3-compression": "^0.3.2",
|
|
55
50
|
"h3-proxy": "^1.13.0",
|
|
56
51
|
"hono": "^4.3.10",
|
|
57
|
-
"import-meta-resolve": "^4.
|
|
58
|
-
"jiti": "^1.21.0",
|
|
59
|
-
"metro-inspector-proxy": "^0.71.0",
|
|
60
|
-
"mime": "^3.0.0",
|
|
61
|
-
"open-editor": "^4.1.1",
|
|
52
|
+
"import-meta-resolve": "^4.1.0",
|
|
62
53
|
"pkg-types": "^1.0.3",
|
|
63
|
-
"pretty-format": "^28.1.0",
|
|
64
|
-
"prompts": "^2.4.2",
|
|
65
|
-
"readline": "^1.3.0",
|
|
66
|
-
"rollup-plugin-node-externals": "^7.1.2",
|
|
67
|
-
"sirv": "^2.0.4",
|
|
68
|
-
"source-map": "^0.7.3",
|
|
69
|
-
"url": "^0.11.0",
|
|
70
54
|
"vite": "6.0.0-alpha.17",
|
|
71
55
|
"vite-bundle-analyzer": "^0.9.4",
|
|
72
|
-
"vxs": "0.1.83",
|
|
73
56
|
"ws": "^8.7.0"
|
|
74
57
|
},
|
|
75
58
|
"devDependencies": {
|
|
76
59
|
"@biomejs/biome": "^1.6.3",
|
|
77
|
-
"@tamagui/build": "^1.
|
|
60
|
+
"@tamagui/build": "^1.100.0",
|
|
78
61
|
"@types/find-node-modules": "^2.1.2",
|
|
79
62
|
"@types/ws": "^8.5.10",
|
|
63
|
+
"depcheck": "^1.4.7",
|
|
80
64
|
"rollup": "^3.29.4"
|
|
81
65
|
}
|
|
82
66
|
}
|
package/src/exports/build.ts
CHANGED
|
@@ -101,7 +101,7 @@ export const build = async (optionsIn: VXRNConfig, buildArgs: BuildArgs = {}) =>
|
|
|
101
101
|
manifest: true,
|
|
102
102
|
|
|
103
103
|
rollupOptions: {
|
|
104
|
-
input: ['
|
|
104
|
+
input: ['virtual:vxs-entry'],
|
|
105
105
|
},
|
|
106
106
|
},
|
|
107
107
|
} satisfies UserConfig)
|
|
@@ -133,10 +133,11 @@ export const build = async (optionsIn: VXRNConfig, buildArgs: BuildArgs = {}) =>
|
|
|
133
133
|
build: {
|
|
134
134
|
// we want one big file of css
|
|
135
135
|
cssCodeSplit: false,
|
|
136
|
-
ssr:
|
|
136
|
+
ssr: true,
|
|
137
137
|
outDir: 'dist/server',
|
|
138
138
|
rollupOptions: {
|
|
139
139
|
external: [],
|
|
140
|
+
input: ['virtual:vxs-entry'],
|
|
140
141
|
},
|
|
141
142
|
},
|
|
142
143
|
} satisfies UserConfig)
|
package/src/types.ts
CHANGED
|
@@ -31,15 +31,14 @@ export type ClientManifestEntry = {
|
|
|
31
31
|
|
|
32
32
|
export type VXRNConfig = {
|
|
33
33
|
/**
|
|
34
|
-
* The entry points to your app. For web, it
|
|
34
|
+
* The entry points to your app. For web, it defaults to using your `root` to look for an index.html
|
|
35
35
|
*
|
|
36
36
|
* Defaults:
|
|
37
37
|
* native: ./src/entry-native.tsx
|
|
38
|
-
* server: ./src/entry-server.tsx
|
|
39
38
|
*/
|
|
40
39
|
entries?: {
|
|
41
40
|
native?: string
|
|
42
|
-
|
|
41
|
+
web?: string
|
|
43
42
|
}
|
|
44
43
|
root?: string
|
|
45
44
|
host?: string
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
// forked from https://github.com/svitejs/vitefu/blob/main/src/index.js
|
|
2
|
+
|
|
3
|
+
import fs from 'node:fs/promises'
|
|
4
|
+
import fsSync from 'node:fs'
|
|
5
|
+
import path from 'node:path'
|
|
6
|
+
|
|
7
|
+
// let pnp
|
|
8
|
+
// if (process.versions.pnp) {
|
|
9
|
+
// try {
|
|
10
|
+
// const { createRequire } = (await import('node:module')).default
|
|
11
|
+
// pnp = createRequire(import.meta.url)('pnpapi')
|
|
12
|
+
// } catch {}
|
|
13
|
+
// }
|
|
14
|
+
|
|
15
|
+
export { isDepIncluded, isDepExcluded, isDepNoExternaled, isDepExternaled }
|
|
16
|
+
|
|
17
|
+
export async function crawlFrameworkPkgs(options) {
|
|
18
|
+
const pkgJsonPath = await findClosestPkgJsonPath(options.root)
|
|
19
|
+
if (!pkgJsonPath) {
|
|
20
|
+
// @ts-expect-error don't throw in deno as package.json is not required
|
|
21
|
+
if (typeof Deno !== 'undefined') {
|
|
22
|
+
return {
|
|
23
|
+
optimizeDeps: { include: [], exclude: [] },
|
|
24
|
+
ssr: { noExternal: [], external: [] },
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
throw new Error(`Cannot find package.json from ${options.root}`)
|
|
28
|
+
}
|
|
29
|
+
const pkgJson = await readJson(pkgJsonPath).catch((e) => {
|
|
30
|
+
throw new Error(`Unable to read ${pkgJsonPath}`, { cause: e })
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
let optimizeDepsInclude: string[] = []
|
|
34
|
+
let optimizeDepsExclude: string[] = []
|
|
35
|
+
let ssrNoExternal: string[] = []
|
|
36
|
+
let ssrExternal: string[] = []
|
|
37
|
+
|
|
38
|
+
await crawl(pkgJsonPath, pkgJson)
|
|
39
|
+
|
|
40
|
+
// respect vite user config
|
|
41
|
+
if (options.viteUserConfig) {
|
|
42
|
+
// remove includes that are explicitly excluded in optimizeDeps
|
|
43
|
+
const _optimizeDepsExclude = options.viteUserConfig?.optimizeDeps?.exclude
|
|
44
|
+
if (_optimizeDepsExclude) {
|
|
45
|
+
optimizeDepsInclude = optimizeDepsInclude.filter(
|
|
46
|
+
(dep) => !isDepExcluded(dep, _optimizeDepsExclude)
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
// remove excludes that are explicitly included in optimizeDeps
|
|
50
|
+
const _optimizeDepsInclude = options.viteUserConfig?.optimizeDeps?.include
|
|
51
|
+
if (_optimizeDepsInclude) {
|
|
52
|
+
optimizeDepsExclude = optimizeDepsExclude.filter(
|
|
53
|
+
(dep) => !isDepIncluded(dep, _optimizeDepsInclude)
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
// remove noExternals that are explicitly externalized
|
|
57
|
+
const _ssrExternal = options.viteUserConfig?.ssr?.external
|
|
58
|
+
if (_ssrExternal) {
|
|
59
|
+
ssrNoExternal = ssrNoExternal.filter((dep) => !isDepExternaled(dep, _ssrExternal))
|
|
60
|
+
}
|
|
61
|
+
// remove externals that are explicitly noExternal
|
|
62
|
+
const _ssrNoExternal = options.viteUserConfig?.ssr?.noExternal
|
|
63
|
+
if (_ssrNoExternal) {
|
|
64
|
+
ssrExternal = ssrExternal.filter((dep) => !isDepNoExternaled(dep, _ssrNoExternal))
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
optimizeDeps: {
|
|
70
|
+
include: optimizeDepsInclude,
|
|
71
|
+
exclude: optimizeDepsExclude,
|
|
72
|
+
},
|
|
73
|
+
ssr: {
|
|
74
|
+
noExternal: ssrNoExternal,
|
|
75
|
+
external: ssrExternal,
|
|
76
|
+
},
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* crawl the package.json dependencies for framework packages. rules:
|
|
81
|
+
* 1. a framework package should be `optimizeDeps.exclude` and `ssr.noExternal`.
|
|
82
|
+
* 2. the deps of the framework package should be `optimizeDeps.include` and `ssr.external`
|
|
83
|
+
* unless the dep is also a framework package, in which case do no1 & no2 recursively.
|
|
84
|
+
* 3. any non-framework packages that aren't imported by a framework package can be skipped entirely.
|
|
85
|
+
* 4. a semi-framework package is like a framework package, except it isn't `optimizeDeps.exclude`,
|
|
86
|
+
* but only applies `ssr.noExternal`.
|
|
87
|
+
* @param {string} pkgJsonPath
|
|
88
|
+
* @param {Record<string, any>} pkgJson
|
|
89
|
+
* @param {string[]} [parentDepNames]
|
|
90
|
+
*/
|
|
91
|
+
async function crawl(
|
|
92
|
+
pkgJsonPath: string,
|
|
93
|
+
pkgJson: Record<string, any>,
|
|
94
|
+
parentDepNames: string[] = []
|
|
95
|
+
) {
|
|
96
|
+
const isRoot = parentDepNames.length === 0
|
|
97
|
+
|
|
98
|
+
let deps = [
|
|
99
|
+
...Object.keys(pkgJson.dependencies || {}),
|
|
100
|
+
...(isRoot ? Object.keys(pkgJson.devDependencies || {}) : []),
|
|
101
|
+
]
|
|
102
|
+
|
|
103
|
+
deps = deps.filter((dep) => {
|
|
104
|
+
// skip circular deps
|
|
105
|
+
if (parentDepNames.includes(dep)) {
|
|
106
|
+
return false
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const isFrameworkPkg = options.isFrameworkPkgByName?.(dep)
|
|
110
|
+
const isSemiFrameworkPkg = options.isSemiFrameworkPkgByName?.(dep)
|
|
111
|
+
if (isFrameworkPkg) {
|
|
112
|
+
// framework packages should be excluded from optimization as esbuild can't handle them.
|
|
113
|
+
// otherwise it'll cause https://github.com/vitejs/vite/issues/3910
|
|
114
|
+
optimizeDepsExclude.push(dep)
|
|
115
|
+
// framework packages should be noExternal so that they go through vite's transformation
|
|
116
|
+
// pipeline, since nodejs can't support them.
|
|
117
|
+
ssrNoExternal.push(dep)
|
|
118
|
+
} else if (isSemiFrameworkPkg) {
|
|
119
|
+
// semi-framework packages should do the same except for optimization exclude as they
|
|
120
|
+
// aren't needed to work (they don't contain raw framework components)
|
|
121
|
+
ssrNoExternal.push(dep)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// only those that are explictly false can skip crawling since we don't need to do anything
|
|
125
|
+
// special for them
|
|
126
|
+
if (isFrameworkPkg === false || isSemiFrameworkPkg === false) {
|
|
127
|
+
return false
|
|
128
|
+
}
|
|
129
|
+
// if `true`, we need to crawl the nested deps to deep include and ssr externalize them in dev.
|
|
130
|
+
// if `undefined`, it's the same as "i don't know". we need to crawl and find the package.json
|
|
131
|
+
// to find out.
|
|
132
|
+
return true
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
const promises = deps.map(async (dep) => {
|
|
136
|
+
const depPkgJsonPath = await findDepPkgJsonPath(dep, pkgJsonPath)
|
|
137
|
+
if (!depPkgJsonPath) return
|
|
138
|
+
const depPkgJson = await readJson(depPkgJsonPath).catch(() => {})
|
|
139
|
+
if (!depPkgJson) return
|
|
140
|
+
|
|
141
|
+
// fast path if this dep is already a framework dep based on the filter condition above
|
|
142
|
+
const cachedIsFrameworkPkg = ssrNoExternal.includes(dep)
|
|
143
|
+
if (cachedIsFrameworkPkg) {
|
|
144
|
+
return crawl(depPkgJsonPath, depPkgJson, parentDepNames.concat(dep))
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// check if this dep is a framework dep, if so, track and crawl it
|
|
148
|
+
const isFrameworkPkg = options.isFrameworkPkgByJson?.(depPkgJson)
|
|
149
|
+
const isSemiFrameworkPkg = options.isSemiFrameworkPkgByJson?.(depPkgJson)
|
|
150
|
+
if (isFrameworkPkg || isSemiFrameworkPkg) {
|
|
151
|
+
// see explanation in filter condition above
|
|
152
|
+
if (isFrameworkPkg) {
|
|
153
|
+
optimizeDepsExclude.push(dep)
|
|
154
|
+
ssrNoExternal.push(dep)
|
|
155
|
+
} else if (isSemiFrameworkPkg) {
|
|
156
|
+
ssrNoExternal.push(dep)
|
|
157
|
+
}
|
|
158
|
+
return crawl(depPkgJsonPath, depPkgJson, parentDepNames.concat(dep))
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// if we're crawling in a non-root state, the parent is 100% a framework package
|
|
162
|
+
// because of the above if block. in this case, if it's dep of a non-framework
|
|
163
|
+
// package, handle special cases for them.
|
|
164
|
+
if (!isRoot) {
|
|
165
|
+
// deep include it if it's a CJS package, so it becomes ESM and vite is happy.
|
|
166
|
+
if (await pkgNeedsOptimization(depPkgJson, depPkgJsonPath)) {
|
|
167
|
+
optimizeDepsInclude.push(parentDepNames.concat(dep).join(' > '))
|
|
168
|
+
}
|
|
169
|
+
// also externalize it in dev so it doesn't trip vite's SSR transformation.
|
|
170
|
+
// we do in dev only as build cannot access deep external packages in strict
|
|
171
|
+
// dependency installations, such as pnpm.
|
|
172
|
+
if (!options.isBuild && !ssrExternal.includes(dep)) {
|
|
173
|
+
ssrExternal.push(dep)
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
await Promise.all(promises)
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export async function findDepPkgJsonPath(dep, parent) {
|
|
183
|
+
// if (pnp) {
|
|
184
|
+
// try {
|
|
185
|
+
// const depRoot = pnp.resolveToUnqualified(dep, parent)
|
|
186
|
+
// if (!depRoot) return
|
|
187
|
+
// return path.join(depRoot, 'package.json')
|
|
188
|
+
// } catch {
|
|
189
|
+
// return
|
|
190
|
+
// }
|
|
191
|
+
// }
|
|
192
|
+
|
|
193
|
+
let root = parent
|
|
194
|
+
while (root) {
|
|
195
|
+
const pkg = path.join(root, 'node_modules', dep, 'package.json')
|
|
196
|
+
try {
|
|
197
|
+
await fs.access(pkg)
|
|
198
|
+
// use 'node:fs' version to match 'vite:resolve' and avoid realpath.native quirk
|
|
199
|
+
// https://github.com/sveltejs/vite-plugin-svelte/issues/525#issuecomment-1355551264
|
|
200
|
+
return fsSync.realpathSync(pkg)
|
|
201
|
+
} catch {}
|
|
202
|
+
const nextRoot = path.dirname(root)
|
|
203
|
+
if (nextRoot === root) break
|
|
204
|
+
root = nextRoot
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export async function findClosestPkgJsonPath(dir: string, predicate?: Function) {
|
|
209
|
+
if (dir.endsWith('package.json')) {
|
|
210
|
+
dir = path.dirname(dir)
|
|
211
|
+
}
|
|
212
|
+
while (dir) {
|
|
213
|
+
const pkg = path.join(dir, 'package.json')
|
|
214
|
+
try {
|
|
215
|
+
const stat = await fs.stat(pkg)
|
|
216
|
+
if (stat.isFile() && (!predicate || (await predicate(pkg)))) {
|
|
217
|
+
return pkg
|
|
218
|
+
}
|
|
219
|
+
} catch {}
|
|
220
|
+
const nextDir = path.dirname(dir)
|
|
221
|
+
if (nextDir === dir) break
|
|
222
|
+
dir = nextDir
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export async function pkgNeedsOptimization(pkgJson: any, pkgJsonPath: string) {
|
|
227
|
+
// only optimize if is cjs, using the below as heuristic
|
|
228
|
+
// see https://github.com/sveltejs/vite-plugin-svelte/issues/162
|
|
229
|
+
if (pkgJson.module || pkgJson.exports) return false
|
|
230
|
+
// if have main, ensure entry is js so vite can prebundle it
|
|
231
|
+
// see https://github.com/sveltejs/vite-plugin-svelte/issues/233
|
|
232
|
+
if (pkgJson.main) {
|
|
233
|
+
const entryExt = path.extname(pkgJson.main)
|
|
234
|
+
return !entryExt || entryExt === '.js' || entryExt === '.cjs'
|
|
235
|
+
}
|
|
236
|
+
// check if has implicit index.js entrypoint to prebundle
|
|
237
|
+
// see https://github.com/sveltejs/vite-plugin-svelte/issues/281
|
|
238
|
+
// see https://github.com/solidjs/vite-plugin-solid/issues/70#issuecomment-1306488154
|
|
239
|
+
try {
|
|
240
|
+
await fs.access(path.join(path.dirname(pkgJsonPath), 'index.js'))
|
|
241
|
+
return true
|
|
242
|
+
} catch {
|
|
243
|
+
return false
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
async function readJson(findDepPkgJsonPath) {
|
|
248
|
+
return JSON.parse(await fs.readFile(findDepPkgJsonPath, 'utf8'))
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function isDepIncluded(dep, optimizeDepsInclude) {
|
|
252
|
+
return optimizeDepsInclude.some((id) => parseIncludeStr(id) === dep)
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function isDepExcluded(dep, optimizeDepsExclude) {
|
|
256
|
+
dep = parseIncludeStr(dep)
|
|
257
|
+
return optimizeDepsExclude.some((id) => id === dep || dep.startsWith(`${id}/`))
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function isDepNoExternaled(dep, ssrNoExternal) {
|
|
261
|
+
if (ssrNoExternal === true) {
|
|
262
|
+
return true
|
|
263
|
+
}
|
|
264
|
+
return isMatch(dep, ssrNoExternal)
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function isDepExternaled(dep, ssrExternal) {
|
|
268
|
+
return ssrExternal.includes(dep)
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* @param {string} raw could be "foo" or "foo > bar" etc
|
|
273
|
+
*/
|
|
274
|
+
function parseIncludeStr(raw) {
|
|
275
|
+
const lastArrow = raw.lastIndexOf('>')
|
|
276
|
+
return lastArrow === -1 ? raw : raw.slice(lastArrow + 1).trim()
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* @param {string} target
|
|
281
|
+
* @param {string | RegExp | (string | RegExp)[]} pattern
|
|
282
|
+
*/
|
|
283
|
+
function isMatch(target, pattern) {
|
|
284
|
+
if (Array.isArray(pattern)) {
|
|
285
|
+
return pattern.some((p) => isMatch(target, p))
|
|
286
|
+
}
|
|
287
|
+
if (typeof pattern === 'string') {
|
|
288
|
+
return target === pattern
|
|
289
|
+
}
|
|
290
|
+
if (pattern instanceof RegExp) {
|
|
291
|
+
return pattern.test(target)
|
|
292
|
+
}
|
|
293
|
+
}
|
|
@@ -19,6 +19,18 @@ export function getBaseViteConfig({ mode }: { mode: 'development' | 'production'
|
|
|
19
19
|
'react-native': 'react-native-web',
|
|
20
20
|
'react-native-safe-area-context': '@vxrn/safe-area',
|
|
21
21
|
},
|
|
22
|
+
|
|
23
|
+
// TODO auto dedupe all include optimize deps?
|
|
24
|
+
dedupe: [
|
|
25
|
+
'vxs',
|
|
26
|
+
'@vxrn/safe-area',
|
|
27
|
+
'react',
|
|
28
|
+
'react-dom',
|
|
29
|
+
'react-dom/client',
|
|
30
|
+
'react-native-web',
|
|
31
|
+
'@tamagui/core',
|
|
32
|
+
'@tamagui/web',
|
|
33
|
+
],
|
|
22
34
|
},
|
|
23
35
|
|
|
24
36
|
build: {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { URL, fileURLToPath } from 'url';
|
|
1
|
+
// import { URL, fileURLToPath } from 'url';
|
|
2
2
|
|
|
3
|
-
export default fileURLToPath(new URL('./dist', import.meta.url));
|
|
3
|
+
// export default fileURLToPath(new URL('./dist', import.meta.url));
|