vxrn 0.1.16 → 0.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/VXRNConfigFilled.js +53 -0
- package/dist/cjs/VXRNConfigFilled.js.map +6 -0
- package/dist/cjs/VXRNConfigFilled.native.js +307 -0
- package/dist/cjs/VXRNConfigFilled.native.js.map +6 -0
- package/dist/cjs/build.js +96 -0
- package/dist/cjs/build.js.map +6 -0
- package/dist/cjs/build.native.js +237 -0
- package/dist/cjs/build.native.js.map +6 -0
- package/dist/cjs/commands/cli-build.js +36 -0
- package/dist/cjs/commands/cli-build.js.map +6 -0
- package/dist/cjs/commands/cli-build.native.js +171 -0
- package/dist/cjs/commands/cli-build.native.js.map +6 -0
- package/dist/cjs/commands/cli-dev.js +2 -2
- package/dist/cjs/commands/cli-dev.js.map +1 -1
- package/dist/cjs/commands/cli-dev.native.js +2 -2
- package/dist/cjs/commands/cli-dev.native.js.map +2 -2
- package/dist/cjs/commands/index.js +3 -1
- package/dist/cjs/commands/index.js.map +1 -1
- package/dist/cjs/commands/index.native.js +4 -0
- package/dist/cjs/commands/index.native.js.map +2 -2
- package/dist/cjs/createDevServer.js +602 -0
- package/dist/cjs/createDevServer.js.map +6 -0
- package/dist/cjs/createDevServer.native.js +1222 -0
- package/dist/cjs/createDevServer.native.js.map +6 -0
- package/dist/cjs/getBaseViteConfig.js +40 -0
- package/dist/cjs/getBaseViteConfig.js.map +6 -0
- package/dist/cjs/getBaseViteConfig.native.js +46 -0
- package/dist/cjs/getBaseViteConfig.native.js.map +6 -0
- package/dist/cjs/getOptionsFIlled.js +53 -0
- package/dist/cjs/getOptionsFIlled.js.map +6 -0
- package/dist/cjs/getOptionsFIlled.native.js +307 -0
- package/dist/cjs/getOptionsFIlled.native.js.map +6 -0
- package/dist/cjs/index.js +3 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/index.native.js +4 -2
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/nativePlugin.js +1 -1
- package/dist/cjs/nativePlugin.native.js +1 -1
- package/dist/cjs/types.native.js.map +1 -1
- package/dist/cjs/utils/getBaseViteConfig.js +40 -0
- package/dist/cjs/utils/getBaseViteConfig.js.map +6 -0
- package/dist/cjs/utils/getBaseViteConfig.native.js +46 -0
- package/dist/cjs/utils/getBaseViteConfig.native.js.map +6 -0
- package/dist/cjs/utils/getOptionsFilled.js +53 -0
- package/dist/cjs/utils/getOptionsFilled.js.map +6 -0
- package/dist/cjs/utils/getOptionsFilled.native.js +307 -0
- package/dist/cjs/utils/getOptionsFilled.native.js.map +6 -0
- package/dist/cjs/utils/getVitePath.js +49 -0
- package/dist/cjs/utils/getVitePath.js.map +6 -0
- package/dist/cjs/utils/getVitePath.native.js +198 -0
- package/dist/cjs/utils/getVitePath.native.js.map +6 -0
- package/dist/esm/VXRNConfigFilled.js +30 -0
- package/dist/esm/VXRNConfigFilled.js.map +6 -0
- package/dist/esm/VXRNConfigFilled.mjs +34 -0
- package/dist/esm/VXRNConfigFilled.native.js +279 -0
- package/dist/esm/VXRNConfigFilled.native.js.map +6 -0
- package/dist/esm/build.js +83 -0
- package/dist/esm/build.js.map +6 -0
- package/dist/esm/build.mjs +56 -0
- package/dist/esm/build.native.js +217 -0
- package/dist/esm/build.native.js.map +6 -0
- package/dist/esm/commands/cli-build.js +23 -0
- package/dist/esm/commands/cli-build.js.map +6 -0
- package/dist/esm/commands/cli-build.mjs +22 -0
- package/dist/esm/commands/cli-build.native.js +156 -0
- package/dist/esm/commands/cli-build.native.js.map +6 -0
- package/dist/esm/commands/cli-dev.js +2 -2
- package/dist/esm/commands/cli-dev.js.map +1 -1
- package/dist/esm/commands/cli-dev.mjs +2 -2
- package/dist/esm/commands/cli-dev.native.js +2 -2
- package/dist/esm/commands/cli-dev.native.js.map +2 -2
- package/dist/esm/commands/index.js +3 -1
- package/dist/esm/commands/index.js.map +1 -1
- package/dist/esm/commands/index.mjs +3 -1
- package/dist/esm/commands/index.native.js +4 -0
- package/dist/esm/commands/index.native.js.map +2 -2
- package/dist/esm/createDevServer.js +613 -0
- package/dist/esm/createDevServer.js.map +6 -0
- package/dist/esm/createDevServer.mjs +574 -0
- package/dist/esm/createDevServer.native.js +1211 -0
- package/dist/esm/createDevServer.native.js.map +6 -0
- package/dist/esm/getBaseViteConfig.js +24 -0
- package/dist/esm/getBaseViteConfig.js.map +6 -0
- package/dist/esm/getBaseViteConfig.mjs +23 -0
- package/dist/esm/getBaseViteConfig.native.js +25 -0
- package/dist/esm/getBaseViteConfig.native.js.map +6 -0
- package/dist/esm/getOptionsFIlled.js +30 -0
- package/dist/esm/getOptionsFIlled.js.map +6 -0
- package/dist/esm/getOptionsFIlled.mjs +34 -0
- package/dist/esm/getOptionsFIlled.native.js +279 -0
- package/dist/esm/getOptionsFIlled.native.js.map +6 -0
- package/dist/esm/index.js +4 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +3 -2
- package/dist/esm/index.native.js +4 -2
- package/dist/esm/index.native.js.map +2 -2
- package/dist/esm/nativePlugin.js +1 -1
- package/dist/esm/nativePlugin.mjs +1 -1
- package/dist/esm/nativePlugin.native.js +1 -1
- package/dist/esm/utils/getBaseViteConfig.js +24 -0
- package/dist/esm/utils/getBaseViteConfig.js.map +6 -0
- package/dist/esm/utils/getBaseViteConfig.mjs +23 -0
- package/dist/esm/utils/getBaseViteConfig.native.js +25 -0
- package/dist/esm/utils/getBaseViteConfig.native.js.map +6 -0
- package/dist/esm/utils/getOptionsFilled.js +30 -0
- package/dist/esm/utils/getOptionsFilled.js.map +6 -0
- package/dist/esm/utils/getOptionsFilled.mjs +34 -0
- package/dist/esm/utils/getOptionsFilled.native.js +279 -0
- package/dist/esm/utils/getOptionsFilled.native.js.map +6 -0
- package/dist/esm/utils/getVitePath.js +27 -0
- package/dist/esm/utils/getVitePath.js.map +6 -0
- package/dist/esm/utils/getVitePath.mjs +20 -0
- package/dist/esm/utils/getVitePath.native.js +171 -0
- package/dist/esm/utils/getVitePath.native.js.map +6 -0
- package/package.json +6 -6
- package/src/build.ts +96 -0
- package/src/commands/cli-build.ts +25 -0
- package/src/commands/cli-dev.ts +2 -2
- package/src/commands/index.ts +2 -1
- package/src/{create.ts → createDevServer.ts} +122 -180
- package/src/index.ts +2 -1
- package/src/nativePlugin.ts +1 -1
- package/src/types.ts +2 -1
- package/src/utils/getBaseViteConfig.ts +22 -0
- package/src/utils/getOptionsFilled.ts +43 -0
- package/src/{getVitePath.ts → utils/getVitePath.ts} +17 -17
- package/types/VXRNConfigFilled.d.ts +21 -0
- package/types/build.d.ts +4 -0
- package/types/commands/cli-build.d.ts +3 -0
- package/types/commands/index.d.ts +1 -0
- package/types/create.d.ts +2 -1
- package/types/createDevServer.d.ts +13 -0
- package/types/getBaseViteConfig.d.ts +5 -0
- package/types/getOptionsFIlled.d.ts +21 -0
- package/types/index.d.ts +2 -1
- package/types/types.d.ts +2 -1
- package/types/utils/getBaseViteConfig.d.ts +5 -0
- package/types/utils/getOptionsFilled.d.ts +22 -0
- package/types/utils/getVitePath.d.ts +2 -0
|
@@ -0,0 +1,574 @@
|
|
|
1
|
+
import wsAdapter from "crossws/adapters/node";
|
|
2
|
+
import findNodeModules from "find-node-modules";
|
|
3
|
+
import { createApp, createRouter, defineEventHandler, defineWebSocketHandler, eventHandler, getQuery, toNodeListener } from "h3";
|
|
4
|
+
import { createProxyEventHandler } from "h3-proxy";
|
|
5
|
+
import { readFile } from "node:fs/promises";
|
|
6
|
+
import { createServer as nodeCreateServer } from "node:http";
|
|
7
|
+
import { dirname, join, relative, resolve } from "node:path";
|
|
8
|
+
import readline from "node:readline";
|
|
9
|
+
import { WebSocket } from "ws";
|
|
10
|
+
import * as babel from "@babel/core";
|
|
11
|
+
import { buildReact, buildReactJSX, buildReactNative } from "@vxrn/react-native-prebuilt";
|
|
12
|
+
import viteReactPlugin, { swcTransform, transformForBuild } from "@vxrn/vite-native-swc";
|
|
13
|
+
import { parse } from "es-module-lexer";
|
|
14
|
+
import FSExtra from "fs-extra";
|
|
15
|
+
import { build, createServer, mergeConfig, resolveConfig, transformWithEsbuild } from "vite";
|
|
16
|
+
import createViteFlow from "@vxrn/vite-flow";
|
|
17
|
+
import { resolve as importMetaResolve } from "import-meta-resolve";
|
|
18
|
+
import { clientInjectionsPlugin } from "./dev/clientInjectPlugin.mjs";
|
|
19
|
+
import { nativePlugin } from "./nativePlugin.mjs";
|
|
20
|
+
import { getBaseViteConfig } from "./utils/getBaseViteConfig.mjs";
|
|
21
|
+
import { getOptionsFilled } from "./utils/getOptionsFilled.mjs";
|
|
22
|
+
import { getVitePath } from "./utils/getVitePath.mjs";
|
|
23
|
+
const resolveFile = path => {
|
|
24
|
+
try {
|
|
25
|
+
return importMetaResolve(path, import.meta.url).replace("file://", "");
|
|
26
|
+
} catch {
|
|
27
|
+
return require.resolve(path);
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
nativeExtensions = [".native.tsx", ".native.jsx", ".native.js", ".tsx", ".ts", ".js", ".css", ".json"],
|
|
31
|
+
extensions = [".web.tsx", ".tsx", ".web.ts", ".ts", ".web.jsx", ".jsx", ".web.js", ".js", ".css", ".json"],
|
|
32
|
+
{
|
|
33
|
+
ensureDir,
|
|
34
|
+
pathExists,
|
|
35
|
+
pathExistsSync
|
|
36
|
+
} = FSExtra,
|
|
37
|
+
patches = [{
|
|
38
|
+
module: "react-native-screens",
|
|
39
|
+
patchFile: "react-native-screens+3.22.1.patch"
|
|
40
|
+
}];
|
|
41
|
+
async function checkPatches(options) {
|
|
42
|
+
if (options.state.applyPatches === !1) return;
|
|
43
|
+
const nodeModulesDirs = findNodeModules({
|
|
44
|
+
cwd: options.root
|
|
45
|
+
}).map(relativePath => join(options.root, relativePath)),
|
|
46
|
+
patchesToCopy = /* @__PURE__ */new Set();
|
|
47
|
+
await Promise.all(patches.flatMap(patch => nodeModulesDirs.flatMap(async dir => {
|
|
48
|
+
(await FSExtra.pathExists(join(dir, patch.module))) && patchesToCopy.add(patch);
|
|
49
|
+
})));
|
|
50
|
+
let didCopy = !1;
|
|
51
|
+
for (const patch of [...patchesToCopy]) {
|
|
52
|
+
const dest = join(options.userPatchesDir, patch.patchFile);
|
|
53
|
+
if (!(await pathExists(dest))) {
|
|
54
|
+
didCopy = !0, console.info(`Copying patch ${patch.module}`);
|
|
55
|
+
const src = join(options.internalPatchesDir, patch.patchFile);
|
|
56
|
+
await FSExtra.copy(src, dest);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
didCopy && (console.info(`
|
|
60
|
+
Please restart after applying the patch by running "npx patch-package".
|
|
61
|
+
Ideally add it to your devDependencies and as a postinstall script.
|
|
62
|
+
`), process.exit(0));
|
|
63
|
+
}
|
|
64
|
+
const createDevServer = async optionsIn => {
|
|
65
|
+
const options = await getOptionsFilled(optionsIn),
|
|
66
|
+
{
|
|
67
|
+
host,
|
|
68
|
+
port,
|
|
69
|
+
root,
|
|
70
|
+
cacheDir
|
|
71
|
+
} = options;
|
|
72
|
+
bindKeypressInput();
|
|
73
|
+
let entryRoot = "";
|
|
74
|
+
checkPatches(options).catch(err => {
|
|
75
|
+
console.error(`
|
|
76
|
+
\u{1F97A} couldn't patch`, err);
|
|
77
|
+
}), await ensureDir(cacheDir);
|
|
78
|
+
const prebuilds = {
|
|
79
|
+
reactJSX: join(cacheDir, "react-jsx-runtime.js"),
|
|
80
|
+
react: join(cacheDir, "react.js"),
|
|
81
|
+
reactNative: join(cacheDir, "react-native.js")
|
|
82
|
+
};
|
|
83
|
+
(await pathExists(prebuilds.reactNative)) || (console.info("Pre-building react, react-native react/jsx-runtime (one time cost)..."), await Promise.all([buildReactNative({
|
|
84
|
+
entryPoints: [resolveFile("react-native")],
|
|
85
|
+
outfile: prebuilds.reactNative
|
|
86
|
+
}), buildReact({
|
|
87
|
+
entryPoints: [resolveFile("react")],
|
|
88
|
+
outfile: prebuilds.react
|
|
89
|
+
}), buildReactJSX({
|
|
90
|
+
entryPoints: [resolveFile("react/jsx-dev-runtime")],
|
|
91
|
+
outfile: prebuilds.reactJSX
|
|
92
|
+
})]));
|
|
93
|
+
const viteFlow = options.flow ? createViteFlow(options.flow) : null,
|
|
94
|
+
templateFile = resolveFile("vxrn/react-native-template.js"),
|
|
95
|
+
hotUpdatedCJSFiles = /* @__PURE__ */new Map(),
|
|
96
|
+
jsxRuntime = {
|
|
97
|
+
// alias: 'virtual:react-jsx',
|
|
98
|
+
alias: prebuilds.reactJSX,
|
|
99
|
+
contents: await readFile(prebuilds.reactJSX, "utf-8")
|
|
100
|
+
},
|
|
101
|
+
virtualModules = {
|
|
102
|
+
"react-native": {
|
|
103
|
+
// alias: 'virtual:react-native',
|
|
104
|
+
alias: prebuilds.reactNative,
|
|
105
|
+
contents: await readFile(prebuilds.reactNative, "utf-8")
|
|
106
|
+
},
|
|
107
|
+
react: {
|
|
108
|
+
// alias: 'virtual:react',
|
|
109
|
+
alias: prebuilds.react,
|
|
110
|
+
contents: await readFile(prebuilds.react, "utf-8")
|
|
111
|
+
},
|
|
112
|
+
"react/jsx-runtime": jsxRuntime,
|
|
113
|
+
"react/jsx-dev-runtime": jsxRuntime
|
|
114
|
+
},
|
|
115
|
+
swapRnPlugin = {
|
|
116
|
+
name: "swap-react-native",
|
|
117
|
+
enforce: "pre",
|
|
118
|
+
resolveId(id, importer = "") {
|
|
119
|
+
if (id.startsWith("react-native/Libraries")) return `virtual:rn-internals:${id}`;
|
|
120
|
+
if (id === "react-native-web") return prebuilds.reactNative;
|
|
121
|
+
for (const targetId in virtualModules) if (id === targetId || id.includes(`node_modules/${targetId}/`)) return virtualModules[targetId].alias;
|
|
122
|
+
if (id[0] === ".") {
|
|
123
|
+
const absolutePath = resolve(dirname(importer), id),
|
|
124
|
+
nativePath = absolutePath.replace(/(.m?js)/, ".native.js");
|
|
125
|
+
if (nativePath === id) return;
|
|
126
|
+
try {
|
|
127
|
+
const directoryPath = absolutePath + "/index.native.js",
|
|
128
|
+
directoryNonNativePath = absolutePath + "/index.js";
|
|
129
|
+
if (pathExistsSync(directoryPath)) return directoryPath;
|
|
130
|
+
if (pathExistsSync(directoryNonNativePath)) return directoryNonNativePath;
|
|
131
|
+
if (pathExistsSync(nativePath)) return nativePath;
|
|
132
|
+
} catch (err) {
|
|
133
|
+
console.warn("error probably fine", err);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
load(id) {
|
|
138
|
+
if (id.startsWith("virtual:rn-internals")) return `const ___val = __cachedModules["${id.replace("virtual:rn-internals:", "")}"]
|
|
139
|
+
const ___defaultVal = ___val ? ___val.default || ___val : ___val
|
|
140
|
+
export default ___defaultVal`;
|
|
141
|
+
for (const targetId in virtualModules) {
|
|
142
|
+
const info = virtualModules[targetId];
|
|
143
|
+
if (id === info.alias) return info.contents;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
depsToOptimize = ["react", "react-dom", "@react-native/normalize-color"],
|
|
148
|
+
reactNativeHMRPlugin = {
|
|
149
|
+
name: "client-transform",
|
|
150
|
+
async handleHotUpdate({
|
|
151
|
+
read,
|
|
152
|
+
modules,
|
|
153
|
+
file
|
|
154
|
+
}) {
|
|
155
|
+
try {
|
|
156
|
+
if (!isWithin(root, file)) return;
|
|
157
|
+
const [module] = modules;
|
|
158
|
+
if (!module) return;
|
|
159
|
+
const id = module?.url || file.replace(root, ""),
|
|
160
|
+
code = await read();
|
|
161
|
+
if (code.startsWith("'use strict';") || !code) return;
|
|
162
|
+
let source = code;
|
|
163
|
+
source = (await transformForBuild(id, source))?.code || "";
|
|
164
|
+
const importsMap = {},
|
|
165
|
+
[imports] = parse(source);
|
|
166
|
+
let accumulatedSliceOffset = 0;
|
|
167
|
+
for (const specifier of imports) {
|
|
168
|
+
const {
|
|
169
|
+
n: importName,
|
|
170
|
+
s: start
|
|
171
|
+
} = specifier;
|
|
172
|
+
if (importName) {
|
|
173
|
+
const id2 = await getVitePath(entryRoot, file, importName);
|
|
174
|
+
if (!id2) {
|
|
175
|
+
console.warn("???");
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
importsMap[id2] = id2.replace(/^(\.\.\/)+/, "");
|
|
179
|
+
const len = importName.length,
|
|
180
|
+
extraLen = id2.length - len;
|
|
181
|
+
source = source.slice(0, start + accumulatedSliceOffset) + id2 + source.slice(start + accumulatedSliceOffset + len), accumulatedSliceOffset += extraLen;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if (source = (await swcTransform(id, source, {
|
|
185
|
+
mode: "serve-cjs"
|
|
186
|
+
}))?.code || "", !source) throw "\u274C no source";
|
|
187
|
+
importsMap.currentPath = id;
|
|
188
|
+
const hotUpdateSource = `exports = ((exports) => {
|
|
189
|
+
const require = createRequire(${JSON.stringify(importsMap, null, 2)})
|
|
190
|
+
${source.replace("import.meta.hot.accept(() => {})", "").replaceAll(/import.meta.glob\(.*\)/gi, "globalThis['__importMetaGlobbed'] || {}")};
|
|
191
|
+
return exports })({})`;
|
|
192
|
+
process.env.DEBUG && console.info("Sending hot update", hotUpdateSource), hotUpdatedCJSFiles.set(id, hotUpdateSource);
|
|
193
|
+
} catch (err) {
|
|
194
|
+
console.error("Error processing hmr update:", err);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
let serverConfig = mergeConfig(getBaseViteConfig({
|
|
199
|
+
mode: "development"
|
|
200
|
+
}), {
|
|
201
|
+
root,
|
|
202
|
+
clearScreen: !1,
|
|
203
|
+
plugins: [reactNativeHMRPlugin],
|
|
204
|
+
optimizeDeps: {
|
|
205
|
+
include: depsToOptimize,
|
|
206
|
+
exclude: Object.values(virtualModules).map(v => v.alias),
|
|
207
|
+
force: !0,
|
|
208
|
+
esbuildOptions: {
|
|
209
|
+
resolveExtensions: extensions
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
server: {
|
|
213
|
+
hmr: {
|
|
214
|
+
path: "/__vxrnhmr"
|
|
215
|
+
},
|
|
216
|
+
cors: !0,
|
|
217
|
+
host
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
options.webConfig && (serverConfig = mergeConfig(serverConfig, options.webConfig));
|
|
221
|
+
const resolvedConfig = await resolveConfig(serverConfig, "serve"),
|
|
222
|
+
viteRNClientPlugin = clientInjectionsPlugin(resolvedConfig);
|
|
223
|
+
serverConfig = {
|
|
224
|
+
...serverConfig,
|
|
225
|
+
plugins: [...serverConfig.plugins]
|
|
226
|
+
};
|
|
227
|
+
const viteServer = await createServer(serverConfig);
|
|
228
|
+
viteServer.watcher.addListener("change", async path => {
|
|
229
|
+
const id = path.replace(process.cwd(), "");
|
|
230
|
+
if (!(!id.endsWith("tsx") && !id.endsWith("jsx"))) try {
|
|
231
|
+
viteServer.transformRequest(id);
|
|
232
|
+
} catch (err) {
|
|
233
|
+
console.info("err", err);
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
let isBuilding = null;
|
|
237
|
+
await viteServer.listen();
|
|
238
|
+
const vitePort = viteServer.config.server.port;
|
|
239
|
+
console.info("vite running on", vitePort);
|
|
240
|
+
const router = createRouter(),
|
|
241
|
+
app = createApp({
|
|
242
|
+
onError: error => {
|
|
243
|
+
console.error(error);
|
|
244
|
+
},
|
|
245
|
+
onRequest: event => {
|
|
246
|
+
console.info(" \u2192", event.path);
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
router.get("/file", defineEventHandler(e => {
|
|
250
|
+
const query = getQuery(e);
|
|
251
|
+
if (typeof query.file == "string") {
|
|
252
|
+
const source = hotUpdatedCJSFiles.get(query.file);
|
|
253
|
+
return new Response(source, {
|
|
254
|
+
headers: {
|
|
255
|
+
"content-type": "text/javascript"
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
})), router.get("/index.bundle", defineEventHandler(async e => new Response(await getBundleCode(), {
|
|
260
|
+
headers: {
|
|
261
|
+
"content-type": "text/javascript"
|
|
262
|
+
}
|
|
263
|
+
}))), router.get("/status", defineEventHandler(() => "packager-status:running")), app.use(router), app.use(defineEventHandler(async ({
|
|
264
|
+
node: {
|
|
265
|
+
req
|
|
266
|
+
}
|
|
267
|
+
}) => {
|
|
268
|
+
if (req.headers["user-agent"]?.match(/Expo|React/) && (req.url === "/" || req.url?.startsWith("/?platform="))) return getIndexJsonResponse({
|
|
269
|
+
port,
|
|
270
|
+
root
|
|
271
|
+
});
|
|
272
|
+
}));
|
|
273
|
+
const {
|
|
274
|
+
handleUpgrade
|
|
275
|
+
} = wsAdapter(app.websocket);
|
|
276
|
+
if (vitePort) {
|
|
277
|
+
const clients = /* @__PURE__ */new Set(),
|
|
278
|
+
socket = new WebSocket(`ws://localhost:${vitePort}/__vxrnhmr`, "vite-hmr");
|
|
279
|
+
console.info("connecting to vite..."), socket.on("open", () => {
|
|
280
|
+
console.info("...connected to vite!");
|
|
281
|
+
}), socket.on("message", msg => {
|
|
282
|
+
const message = msg.toString();
|
|
283
|
+
console.info(clients.size, "message", message);
|
|
284
|
+
for (const listener of [...clients]) listener.send(message);
|
|
285
|
+
}), socket.on("error", err => {
|
|
286
|
+
console.info("err", err);
|
|
287
|
+
}), app.use("/__vxrnhmr", defineWebSocketHandler({
|
|
288
|
+
open(peer) {
|
|
289
|
+
console.debug("[hmr:web] open", peer), clients.add(peer);
|
|
290
|
+
},
|
|
291
|
+
message(peer, message) {
|
|
292
|
+
socket.send(message.rawData);
|
|
293
|
+
},
|
|
294
|
+
close(peer, event) {
|
|
295
|
+
console.info("[hmr:web] close", peer, event), clients.delete(peer);
|
|
296
|
+
},
|
|
297
|
+
error(peer, error) {
|
|
298
|
+
console.error("[hmr:web] error", peer, error);
|
|
299
|
+
}
|
|
300
|
+
}));
|
|
301
|
+
}
|
|
302
|
+
app.use("/__hmr", defineWebSocketHandler({
|
|
303
|
+
open(peer) {
|
|
304
|
+
console.debug("[hmr] open", peer);
|
|
305
|
+
},
|
|
306
|
+
message(peer, message) {
|
|
307
|
+
console.info("[hmr] message", peer, message), message.text().includes("ping") && peer.send("pong");
|
|
308
|
+
},
|
|
309
|
+
close(peer, event) {
|
|
310
|
+
console.info("[hmr] close", peer, event);
|
|
311
|
+
},
|
|
312
|
+
error(peer, error) {
|
|
313
|
+
console.error("[hmr] error", peer, error);
|
|
314
|
+
}
|
|
315
|
+
})), app.use("/__client", defineWebSocketHandler({
|
|
316
|
+
open(peer) {
|
|
317
|
+
console.info("[client] open", peer);
|
|
318
|
+
},
|
|
319
|
+
message(peer, messageRaw) {
|
|
320
|
+
const message = JSON.parse(messageRaw.text());
|
|
321
|
+
switch (message.type) {
|
|
322
|
+
case "client-log":
|
|
323
|
+
{
|
|
324
|
+
console.info(`\u{1FAB5} [${message.level}]`, ...message.data);
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
default:
|
|
328
|
+
console.warn("[client] Unknown message type", message);
|
|
329
|
+
}
|
|
330
|
+
},
|
|
331
|
+
close(peer, event) {
|
|
332
|
+
console.info("[client] close", peer, event);
|
|
333
|
+
},
|
|
334
|
+
error(peer, error) {
|
|
335
|
+
console.error("[client] error", peer, error);
|
|
336
|
+
}
|
|
337
|
+
}));
|
|
338
|
+
const proxyEventHandler = createProxyEventHandler({
|
|
339
|
+
target: `http://127.0.0.1:${vitePort}`,
|
|
340
|
+
enableLogger: !!process.env.DEBUG
|
|
341
|
+
});
|
|
342
|
+
app.use(eventHandler(proxyEventHandler));
|
|
343
|
+
const server = nodeCreateServer(toNodeListener(app));
|
|
344
|
+
return server.on("upgrade", handleUpgrade), {
|
|
345
|
+
nativeServer: server,
|
|
346
|
+
viteServer,
|
|
347
|
+
async start() {
|
|
348
|
+
return server.listen(port), console.info(`Server running on http://localhost:${port}`), {
|
|
349
|
+
closePromise: new Promise(res => viteServer.httpServer?.on("close", res))
|
|
350
|
+
};
|
|
351
|
+
},
|
|
352
|
+
stop: async () => {
|
|
353
|
+
await Promise.all([server.close(), viteServer.close()]);
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
async function getBundleCode() {
|
|
357
|
+
if (process.env.LOAD_TMP_BUNDLE) {
|
|
358
|
+
const tmpBundle = join(process.cwd(), "bundle.tmp.js");
|
|
359
|
+
if (await pathExists(tmpBundle)) return console.info("\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F returning temp bundle \u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F", tmpBundle), await readFile(tmpBundle, "utf-8");
|
|
360
|
+
}
|
|
361
|
+
if (isBuilding) return await isBuilding;
|
|
362
|
+
let done;
|
|
363
|
+
isBuilding = new Promise(res => {
|
|
364
|
+
done = res;
|
|
365
|
+
});
|
|
366
|
+
async function babelReanimated(input, filename) {
|
|
367
|
+
return await new Promise((res, rej) => {
|
|
368
|
+
babel.transform(input, {
|
|
369
|
+
plugins: ["react-native-reanimated/plugin"],
|
|
370
|
+
filename
|
|
371
|
+
}, (err, result) => {
|
|
372
|
+
(!result || err) && rej(err || "no res"), res(result.code);
|
|
373
|
+
});
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
const buildInput = options.entryNative || "index.jsx";
|
|
377
|
+
let buildConfig = {
|
|
378
|
+
plugins: [viteFlow, swapRnPlugin, {
|
|
379
|
+
name: "reanimated",
|
|
380
|
+
async transform(code, id) {
|
|
381
|
+
if (code.includes("worklet")) return await babelReanimated(code, id);
|
|
382
|
+
}
|
|
383
|
+
}, viteRNClientPlugin, nativePlugin({
|
|
384
|
+
root,
|
|
385
|
+
port,
|
|
386
|
+
mode: "build"
|
|
387
|
+
}), viteReactPlugin({
|
|
388
|
+
tsDecorators: !0,
|
|
389
|
+
mode: "build"
|
|
390
|
+
}),
|
|
391
|
+
// viteInspectPlugin({
|
|
392
|
+
// build: true,
|
|
393
|
+
// outputDir: '.vite-inspect',
|
|
394
|
+
// }),
|
|
395
|
+
{
|
|
396
|
+
name: "treat-js-files-as-jsx",
|
|
397
|
+
async transform(code, id) {
|
|
398
|
+
return id.match(/expo-status-bar/) ? transformWithEsbuild(code, id, {
|
|
399
|
+
loader: "jsx",
|
|
400
|
+
jsx: "automatic"
|
|
401
|
+
}) : null;
|
|
402
|
+
}
|
|
403
|
+
}].filter(Boolean),
|
|
404
|
+
appType: "custom",
|
|
405
|
+
root,
|
|
406
|
+
clearScreen: !1,
|
|
407
|
+
optimizeDeps: {
|
|
408
|
+
include: depsToOptimize,
|
|
409
|
+
esbuildOptions: {
|
|
410
|
+
jsx: "automatic"
|
|
411
|
+
}
|
|
412
|
+
},
|
|
413
|
+
resolve: {
|
|
414
|
+
extensions: nativeExtensions
|
|
415
|
+
},
|
|
416
|
+
mode: "development",
|
|
417
|
+
define: {
|
|
418
|
+
"process.env.NODE_ENV": '"development"'
|
|
419
|
+
},
|
|
420
|
+
build: {
|
|
421
|
+
ssr: !1,
|
|
422
|
+
minify: !1,
|
|
423
|
+
commonjsOptions: {
|
|
424
|
+
transformMixedEsModules: !0
|
|
425
|
+
},
|
|
426
|
+
rollupOptions: {
|
|
427
|
+
treeshake: !1,
|
|
428
|
+
preserveEntrySignatures: "strict",
|
|
429
|
+
output: {
|
|
430
|
+
preserveModules: !0,
|
|
431
|
+
format: "cjs"
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
options.buildConfig && (buildConfig = mergeConfig(buildConfig, options.buildConfig)), await resolveConfig(buildConfig, "build");
|
|
437
|
+
const buildOutput = await build(buildConfig);
|
|
438
|
+
if (!("output" in buildOutput)) throw "\u274C";
|
|
439
|
+
let appCode = buildOutput.output.sort((a, b) => a.isEntry ? 1 : -1).map(outputModule => {
|
|
440
|
+
if (outputModule.type == "chunk") {
|
|
441
|
+
const importsMap = {
|
|
442
|
+
currentPath: outputModule.fileName
|
|
443
|
+
};
|
|
444
|
+
for (const imp of outputModule.imports) {
|
|
445
|
+
const relativePath = relative(dirname(outputModule.fileName), imp);
|
|
446
|
+
importsMap[relativePath[0] === "." ? relativePath : "./" + relativePath] = imp;
|
|
447
|
+
}
|
|
448
|
+
return outputModule.isEntry && (entryRoot = dirname(outputModule.fileName)), `
|
|
449
|
+
___modules___["${outputModule.fileName}"] = ((exports, module) => {
|
|
450
|
+
const require = createRequire(${JSON.stringify(importsMap, null, 2)})
|
|
451
|
+
|
|
452
|
+
${outputModule.code}
|
|
453
|
+
})
|
|
454
|
+
|
|
455
|
+
${outputModule.isEntry ? `
|
|
456
|
+
// run entry
|
|
457
|
+
const __require = createRequire({})
|
|
458
|
+
__require("react-native")
|
|
459
|
+
__require("${outputModule.fileName}")
|
|
460
|
+
` : ""}
|
|
461
|
+
`;
|
|
462
|
+
}
|
|
463
|
+
}).join(`
|
|
464
|
+
`);
|
|
465
|
+
if (!appCode) throw "\u274C";
|
|
466
|
+
appCode = appCode.replaceAll("undefined.accept(() => {})", "").replaceAll("undefined.accept(function() {});", "").replaceAll("(void 0).accept(() => {})", "").replaceAll("(void 0).accept(function() {});", "");
|
|
467
|
+
const appRootParent = join(root, "..", ".."),
|
|
468
|
+
out = (await readFile(templateFile, "utf-8")).replace("_virtual/virtual_react-native.js", relative(appRootParent, prebuilds.reactNative)).replace("_virtual/virtual_react.js", relative(appRootParent, prebuilds.react)).replaceAll("_virtual/virtual_react-jsx.js", relative(appRootParent, prebuilds.reactJSX)) + appCode;
|
|
469
|
+
return done(out), isBuilding = null, out;
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
function getIndexJsonResponse({
|
|
473
|
+
port,
|
|
474
|
+
root
|
|
475
|
+
}) {
|
|
476
|
+
return {
|
|
477
|
+
name: "myapp",
|
|
478
|
+
slug: "myapp",
|
|
479
|
+
scheme: "myapp",
|
|
480
|
+
version: "1.0.0",
|
|
481
|
+
jsEngine: "jsc",
|
|
482
|
+
orientation: "portrait",
|
|
483
|
+
icon: "./assets/icon.png",
|
|
484
|
+
userInterfaceStyle: "light",
|
|
485
|
+
splash: {
|
|
486
|
+
image: "./assets/splash.png",
|
|
487
|
+
resizeMode: "contain",
|
|
488
|
+
backgroundColor: "#ffffff",
|
|
489
|
+
imageUrl: "http://127.0.0.1:8081/assets/./assets/splash.png"
|
|
490
|
+
},
|
|
491
|
+
updates: {
|
|
492
|
+
fallbackToCacheTimeout: 0
|
|
493
|
+
},
|
|
494
|
+
assetBundlePatterns: ["**/*"],
|
|
495
|
+
ios: {
|
|
496
|
+
supportsTablet: !0,
|
|
497
|
+
bundleIdentifier: "com.natew.myapp"
|
|
498
|
+
},
|
|
499
|
+
android: {
|
|
500
|
+
package: "com.tamagui.myapp",
|
|
501
|
+
adaptiveIcon: {
|
|
502
|
+
foregroundImage: "./assets/adaptive-icon.png",
|
|
503
|
+
backgroundColor: "#FFFFFF",
|
|
504
|
+
foregroundImageUrl: "http://127.0.0.1:8081/assets/./assets/adaptive-icon.png"
|
|
505
|
+
}
|
|
506
|
+
},
|
|
507
|
+
web: {
|
|
508
|
+
favicon: "./assets/favicon.png"
|
|
509
|
+
},
|
|
510
|
+
extra: {
|
|
511
|
+
eas: {
|
|
512
|
+
projectId: "061b4470-78c7-4d6a-b850-8167fb0a3434"
|
|
513
|
+
}
|
|
514
|
+
},
|
|
515
|
+
_internal: {
|
|
516
|
+
isDebug: !1,
|
|
517
|
+
projectRoot: root,
|
|
518
|
+
dynamicConfigPath: null,
|
|
519
|
+
staticConfigPath: join(root, "app.json"),
|
|
520
|
+
packageJsonPath: join(root, "package.json")
|
|
521
|
+
},
|
|
522
|
+
sdkVersion: "47.0.0",
|
|
523
|
+
platforms: ["ios", "android", "web"],
|
|
524
|
+
iconUrl: `http://127.0.0.1:${port}/assets/./assets/icon.png`,
|
|
525
|
+
debuggerHost: `127.0.0.1:${port}`,
|
|
526
|
+
logUrl: `http://127.0.0.1:${port}/logs`,
|
|
527
|
+
developer: {
|
|
528
|
+
tool: "expo-cli",
|
|
529
|
+
projectRoot: root
|
|
530
|
+
},
|
|
531
|
+
packagerOpts: {
|
|
532
|
+
dev: !0
|
|
533
|
+
},
|
|
534
|
+
mainModuleName: "index",
|
|
535
|
+
__flipperHack: "React Native packager is running",
|
|
536
|
+
hostUri: `127.0.0.1:${port}`,
|
|
537
|
+
bundleUrl: `http://127.0.0.1:${port}/index.bundle?platform=ios&dev=true&hot=false&lazy=true`,
|
|
538
|
+
id: "@anonymous/myapp-473c4543-3c36-4786-9db1-c66a62ac9b78"
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
function bindKeypressInput() {
|
|
542
|
+
if (!process.stdin.setRawMode) {
|
|
543
|
+
console.warn({
|
|
544
|
+
msg: "Interactive mode is not supported in this environment"
|
|
545
|
+
});
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
readline.emitKeypressEvents(process.stdin), process.stdin.setRawMode(!0), process.stdin.on("keypress", (_key, data) => {
|
|
549
|
+
const {
|
|
550
|
+
ctrl,
|
|
551
|
+
name
|
|
552
|
+
} = data;
|
|
553
|
+
if (ctrl === !0) switch (name) {
|
|
554
|
+
case "c":
|
|
555
|
+
process.exit();
|
|
556
|
+
case "z":
|
|
557
|
+
process.emit("SIGTSTP", "SIGTSTP");
|
|
558
|
+
break;
|
|
559
|
+
} else switch (name) {
|
|
560
|
+
case "r":
|
|
561
|
+
break;
|
|
562
|
+
case "d":
|
|
563
|
+
break;
|
|
564
|
+
case "c":
|
|
565
|
+
process.stdout.write("\x1B[2J\x1B[0;0H");
|
|
566
|
+
break;
|
|
567
|
+
}
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
function isWithin(outer, inner) {
|
|
571
|
+
const rel = relative(outer, inner);
|
|
572
|
+
return !rel.startsWith("../") && rel !== "..";
|
|
573
|
+
}
|
|
574
|
+
export { bindKeypressInput, createDevServer, resolveFile };
|