@octane-xplat/build 0.0.0-stage → 0.20.0
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/LICENSE +21 -0
- package/README.md +4 -2
- package/dist/add-worker.js +66 -0
- package/dist/build-worker.js +276 -0
- package/dist/compatibility-check.js +153 -0
- package/dist/compatibility-data/compatibility.js +106 -0
- package/dist/compatibility-data/compatibility.json +305 -0
- package/dist/compatibility.js +229 -0
- package/dist/css-layers.js +63 -0
- package/dist/css-platform.js +230 -0
- package/dist/css-platform.types.d.ts +11 -0
- package/dist/dev-inspector.web.js +125 -0
- package/dist/dev-log-client.web.js +79 -0
- package/dist/dev-log-server.js +13 -0
- package/dist/doctor-checks.js +317 -0
- package/dist/doctor-tool.js +27 -0
- package/dist/env.js +3 -0
- package/dist/fmt-plan.js +149 -0
- package/dist/fonts-worker.js +31 -0
- package/dist/fonts.js +614 -0
- package/dist/inline-stylesheets.js +37 -0
- package/dist/linux/config.js +43 -0
- package/dist/linux/host/bridge-selftest.linux.js +255 -0
- package/dist/linux/host/gjs-host.js +1412 -0
- package/dist/linux/package.js +176 -0
- package/dist/linux-gtk/vite.d.ts +23 -0
- package/dist/linux-gtk/vite.js +194 -0
- package/dist/macos/config.js +141 -0
- package/dist/macos/doctor-checks.js +58 -0
- package/dist/macos/executables.js +39 -0
- package/dist/macos/jsc-host/runtime.js +134 -0
- package/dist/macos/native.js +287 -0
- package/dist/macos/runtime-package.js +30 -0
- package/dist/macos/tab-item.js +62 -0
- package/dist/macos/vite.d.ts +21 -0
- package/dist/macos/vite.js +111 -0
- package/dist/markdown.js +11 -0
- package/dist/mason-engine.js +20 -0
- package/dist/mcp/contracts/actions.js +133 -0
- package/dist/mcp/dev-bridge.js +363 -0
- package/dist/mcp/dev-socket.js +161 -0
- package/dist/mcp/dev-stack.js +134 -0
- package/dist/mcp/inspection/dom.web.js +46 -0
- package/dist/native-regex.js +123 -0
- package/dist/package-manager.js +106 -0
- package/dist/package-root.js +48 -0
- package/dist/patches.js +356 -0
- package/dist/route-config.js +53 -0
- package/dist/route-data.js +42 -0
- package/dist/route-generator.js +514 -0
- package/dist/route-path.js +29 -0
- package/dist/route-source.js +67 -0
- package/dist/targets.js +38 -0
- package/dist/tsconfig-envs.js +287 -0
- package/dist/tsrx-leaf.js +57 -0
- package/dist/typecheck-globals/macos.d.ts +21 -0
- package/dist/typecheck-globals/native.d.ts +26 -0
- package/dist/ui/src/markdown/markdown-ast.js +33 -0
- package/dist/ui/src/markdown/markdown-character-references.js +79 -0
- package/dist/ui/src/markdown/markdown-parse.js +1930 -0
- package/dist/ui/src/markdown/markdown-plugins.js +564 -0
- package/dist/ui/src/markdown/markdown-url.js +17 -0
- package/dist/updates-worker.js +34 -0
- package/dist/upgrade-worker.js +63 -0
- package/dist/vite.d.ts +85 -0
- package/dist/vite.js +628 -0
- package/dist/workshop-worker.js +181 -0
- package/package.json +72 -5
package/dist/vite.js
ADDED
|
@@ -0,0 +1,628 @@
|
|
|
1
|
+
import { installedPackageDir, installedPackageRoot } from "./package-root.js";
|
|
2
|
+
import { unwrapCssLayers } from "./css-layers.js";
|
|
3
|
+
import { xplatCss } from "./css-platform.js";
|
|
4
|
+
import { xplatDevBridge } from "./mcp/dev-bridge.js";
|
|
5
|
+
import { nativeDevSocketPlugin } from "./mcp/dev-socket.js";
|
|
6
|
+
import { masonCorePackage, masonEngine } from "./mason-engine.js";
|
|
7
|
+
import { nativeUnicodeRegex } from "./native-regex.js";
|
|
8
|
+
import { resolveTsrxLeaf } from "./tsrx-leaf.js";
|
|
9
|
+
import { serverBoundary } from "@octane-xplat/lib/server-boundary";
|
|
10
|
+
import { existsSync, readFileSync, realpathSync, statSync } from "node:fs";
|
|
11
|
+
import { createRequire } from "node:module";
|
|
12
|
+
import { dirname, join, relative, resolve } from "node:path";
|
|
13
|
+
import { pathToFileURL } from "node:url";
|
|
14
|
+
// ../cli/src/vite.ts
|
|
15
|
+
/** Select platform TSRX implementations in custom Vite and Vitest setups. */
|
|
16
|
+
function xplatTsrx(platform = "native") {
|
|
17
|
+
return {
|
|
18
|
+
name: "xplat-tsrx-resolution",
|
|
19
|
+
enforce: "post",
|
|
20
|
+
configResolved(config) {
|
|
21
|
+
for (const environment of Object.values(config.environments)) {
|
|
22
|
+
const options = environment.optimizeDeps.rolldownOptions ??= {};
|
|
23
|
+
const resolve = options.resolve ??= {};
|
|
24
|
+
resolve.extensions ??= [...environment.resolve.extensions];
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
resolveId: {
|
|
28
|
+
order: "pre",
|
|
29
|
+
handler(source, importer) {
|
|
30
|
+
return resolveTsrxLeaf(source, importer, platform);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
var importApp = (spec) => {
|
|
36
|
+
const req = createRequire(join(process.cwd(), "package.json"));
|
|
37
|
+
return import(pathToFileURL(realpathSync(req.resolve(spec))).href);
|
|
38
|
+
};
|
|
39
|
+
var NS_REALM = /* @__PURE__ */ new Set(["@nativescript/core", "@nativescript/vite"]);
|
|
40
|
+
/**
|
|
41
|
+
* Every installed package carrying a `nativescript` key in package.json,
|
|
42
|
+
* reachable from the app's dependency graph — the same BFS the `ns` CLI
|
|
43
|
+
* runs at `ns prepare` time (deps of deps, resolved from each package's
|
|
44
|
+
* real .pnpm dir, so plugin-bearing leaf packages like @octane-xplat/gif
|
|
45
|
+
* surface their native plugins here too). The app doesn't have to declare
|
|
46
|
+
* each plugin by hand.
|
|
47
|
+
*/
|
|
48
|
+
var collectNsPluginDeps = (rootDir) => {
|
|
49
|
+
const out = /* @__PURE__ */ new Set();
|
|
50
|
+
const visited = /* @__PURE__ */ new Set();
|
|
51
|
+
const queue = [rootDir];
|
|
52
|
+
while (queue.length) {
|
|
53
|
+
const dir = queue.shift();
|
|
54
|
+
let pkg;
|
|
55
|
+
try {
|
|
56
|
+
pkg = JSON.parse(readFileSync(join(dir, "package.json"), "utf8"));
|
|
57
|
+
} catch {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
for (const name of Object.keys(pkg.dependencies ?? {})) {
|
|
61
|
+
if (visited.has(name)) continue;
|
|
62
|
+
visited.add(name);
|
|
63
|
+
const depDir = installedPackageRoot(dir, name);
|
|
64
|
+
if (!depDir) continue;
|
|
65
|
+
if (JSON.parse(readFileSync(join(depDir, "package.json"), "utf8")).nativescript && !NS_REALM.has(name)) out.add(name);
|
|
66
|
+
queue.push(depDir);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return out;
|
|
70
|
+
};
|
|
71
|
+
/** CSS that NS parses but silently ignores or misreads — the app looks
|
|
72
|
+
* identical in source but diverges at runtime. Warned at build time so the
|
|
73
|
+
* divergence is loud instead of invisible. Each entry: pattern + the
|
|
74
|
+
* portable alternative. */
|
|
75
|
+
var CSS_DIVERGENCES = [
|
|
76
|
+
[/(?<![\w-])env\(\s*safe-area-inset-(?:top|right|bottom|left)\s*[,)]/i, "env(safe-area-inset-*) is unsupported on native and may contribute 0 — use useSafeAreaInsets() from @octane-xplat/ui with an inline style for native insets"],
|
|
77
|
+
[/margin-(?:left|right|top|bottom)\s*:\s*auto|margin\s*:[^;{}]*\bauto\b/, "auto margins are ignored on native — use justify-content, alignSelf, or a <Spacer/>"],
|
|
78
|
+
[/position\s*:\s*(fixed|sticky)\b/, "position: fixed/sticky does not exist on native — overlays go through Overlay/Modal services, not positioning"],
|
|
79
|
+
[/\bfloat\s*:/, "float is unsupported on native — use flex rows"],
|
|
80
|
+
[/\bbox-shadow\s*:/, "box-shadow is inert on native — Android elevation and iOS shadows do not map to it (framework mapping is a TODO)"],
|
|
81
|
+
[/white-space\s*:\s*pre-wrap\b/, "Label rejects white-space:pre-wrap — \"wrap\" is the native wrap value (no space/newline preservation)"],
|
|
82
|
+
[/letter-spacing\s*:\s*[^;{}]*\d(?:px|dip|pt)\b/, "letter-spacing has no length units on native — Android reads the number as em (setLetterSpacing), iOS as pt; use em so all three agree"]
|
|
83
|
+
];
|
|
84
|
+
/**
|
|
85
|
+
* Shared stylesheets are authored in web units and web semantics. For the
|
|
86
|
+
* native bundle this transform (a) rewrites `px` lengths to `dip` — NS CSS
|
|
87
|
+
* reads `px` as _device_ pixels, not dips (`width:88px` measures 29 dips on
|
|
88
|
+
* a 3x device); inline `style` props are already dips and untouched — and
|
|
89
|
+
* (b) warns once per file on declarations NS silently ignores, so the
|
|
90
|
+
* divergence is loud at build time.
|
|
91
|
+
*/
|
|
92
|
+
function processNativeCss(code, id, warn, options = {}) {
|
|
93
|
+
const warned = options.warned ?? /* @__PURE__ */ new Set();
|
|
94
|
+
code = code.replace(/\/\*\s*xplat-web-only:start[\s\S]*?\*\/[\s\S]*?\/\*\s*xplat-web-only:end[\s\S]*?\*\//g, "");
|
|
95
|
+
code = unwrapCssLayers(code);
|
|
96
|
+
const uncommented = code.replace(/\/\*[\s\S]*?\*\//g, "");
|
|
97
|
+
if (/@import\s+['"]/.test(uncommented) && !warned.has(id + "|@import")) {
|
|
98
|
+
warned.add(id + "|@import");
|
|
99
|
+
warn(`${id}: @import inlining bypasses the px→dip rewrite and the xplat-web-only strip — import css files as JS modules instead (import 'pkg/file.css')`);
|
|
100
|
+
}
|
|
101
|
+
const declarations = code.replace(/\/\*[\s\S]*?\*\/|"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'/g, "");
|
|
102
|
+
for (const [re, unsupportedHint] of CSS_DIVERGENCES) {
|
|
103
|
+
const hint = options.masonSafeAreaEnvironment && String(unsupportedHint).startsWith("env(") ? "env(safe-area-inset-*) uses the owning window on Mason containers; native inset dispatch/layout is not yet device-qualified. Ordinary NativeScript controls still need useSafeAreaInsets() with inline styles" : unsupportedHint;
|
|
104
|
+
const key = id + "|" + hint;
|
|
105
|
+
if (re.test(declarations) && !warned.has(key)) {
|
|
106
|
+
warned.add(key);
|
|
107
|
+
warn(`${id}: ${hint}`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
code = code.replace(/(letter-spacing\s*:\s*-?\d+(?:\.\d+)?)em\b/g, "$1");
|
|
111
|
+
return code.replace(/@[\w-]+[^{}]*\{|-?\d+(?:\.\d+)?px\b/g, (m) => m.endsWith("{") ? m : m.slice(0, -2) + "dip");
|
|
112
|
+
}
|
|
113
|
+
function pxToDip(options = {}) {
|
|
114
|
+
const warned = /* @__PURE__ */ new Set();
|
|
115
|
+
let isBuild = false;
|
|
116
|
+
const process = (code, id, warn) => processNativeCss(code, id, warn, {
|
|
117
|
+
...options,
|
|
118
|
+
warned
|
|
119
|
+
});
|
|
120
|
+
return {
|
|
121
|
+
name: "xplat-native-css",
|
|
122
|
+
enforce: "pre",
|
|
123
|
+
configResolved(config) {
|
|
124
|
+
isBuild = config.command === "build";
|
|
125
|
+
},
|
|
126
|
+
transform(code, id) {
|
|
127
|
+
if (isBuild && id.split("?")[0].endsWith("virtual:bamboo.css")) return;
|
|
128
|
+
if (!id.split("?")[0].endsWith(".css")) return;
|
|
129
|
+
return process(code, id, (m) => this.warn(m));
|
|
130
|
+
},
|
|
131
|
+
generateBundle(_opts, bundle) {
|
|
132
|
+
for (const file of Object.values(bundle)) if (file.type === "asset" && file.fileName.endsWith(".css")) {
|
|
133
|
+
const src = typeof file.source === "string" ? file.source : new TextDecoder().decode(file.source);
|
|
134
|
+
file.source = process(src, file.fileName, (m) => this.warn(m));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/** Vite merges `resolve.extensions` by concat, and the ns base config lands a
|
|
140
|
+
* generic list (`.tsx,.jsx,.ts,.js,…`) before ours — first-match resolution
|
|
141
|
+
* then prefers `svg.ts` over `svg.mobile.ts`, and `registerElement`-style
|
|
142
|
+
* side effects in platform leaves never load. Splice the platform chain to
|
|
143
|
+
* the front after every merge has run. */
|
|
144
|
+
function nativeExtensionOrder() {
|
|
145
|
+
return {
|
|
146
|
+
name: "xplat-native-extension-order",
|
|
147
|
+
configResolved(config) {
|
|
148
|
+
const ours = new Set(nativePlatformExtensions());
|
|
149
|
+
const rest = (config.resolve?.extensions ?? []).filter((ext) => !ours.has(ext));
|
|
150
|
+
config.resolve = {
|
|
151
|
+
...config.resolve,
|
|
152
|
+
extensions: [...ours, ...rest]
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
/** The ns platform resolver and Vite's extension fallback know nothing of the
|
|
158
|
+
* `.mobile` tier — upstream platform lists only carry `.ios`/`.android`. An
|
|
159
|
+
* unsuffixed relative import (`./svg`) therefore lands on the shared default
|
|
160
|
+
* (`svg.ts`) in dev while builds pick `svg.mobile.ts` — silently skipping
|
|
161
|
+
* `registerElement`-style side effects. Probe the platform chain for every
|
|
162
|
+
* relative specifier before the generic resolvers run.
|
|
163
|
+
*
|
|
164
|
+
* An explicit unsuffixed specifier is still the authored contract, not a
|
|
165
|
+
* literal file: `./Pressable.tsrx` must select `Pressable.<platform>.tsrx`
|
|
166
|
+
* exactly as the extensionless `./Pressable` does. Vite resolves an
|
|
167
|
+
* extensioned specifier literally, so strip the authored script extension
|
|
168
|
+
* and probe the chain on the stem. A platform-tagged request
|
|
169
|
+
* (`./foo.ios.tsrx`) names its leaf and resolves literally. */
|
|
170
|
+
function nativeRelativeResolution() {
|
|
171
|
+
const exts = nativePlatformExtensions();
|
|
172
|
+
return {
|
|
173
|
+
name: "xplat-native-relative-resolution",
|
|
174
|
+
resolveId: {
|
|
175
|
+
order: "pre",
|
|
176
|
+
handler(source, importer) {
|
|
177
|
+
if (!importer || !source.startsWith("./") && !source.startsWith("../")) return null;
|
|
178
|
+
const importerFile = importer.split(/[?#]/, 1)[0].replace(/^\/@fs\//, "/");
|
|
179
|
+
const request = source.split(/[?#]/, 1)[0];
|
|
180
|
+
const base = resolve(dirname(importerFile), request);
|
|
181
|
+
const stem = PLATFORM_TAG.test(base) ? base : base.replace(/\.(tsrx|tsx|ts|mts|jsx|js|json)$/, "");
|
|
182
|
+
if (importerFile.replace(/\.(web|mobile|ios|android|macos|windows|linux|gtk)(\.[^./\\]+)$/, "$2") === base) return existsSync(base) ? base.replaceAll("\\", "/") : null;
|
|
183
|
+
for (const ext of exts) if (existsSync(stem + ext)) return (stem + ext).replaceAll("\\", "/");
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
function nativeCoreHttpAliases(appRequire) {
|
|
190
|
+
try {
|
|
191
|
+
const coreRequire = createRequire(realpathSync(appRequire.resolve("@nativescript/core/package.json")));
|
|
192
|
+
return [{
|
|
193
|
+
find: /^\/node_modules\/source-map-js(?=\/|$)/,
|
|
194
|
+
replacement: dirname(coreRequire.resolve("source-map-js/package.json"))
|
|
195
|
+
}];
|
|
196
|
+
} catch (error) {
|
|
197
|
+
if (error?.code === "MODULE_NOT_FOUND") return [];
|
|
198
|
+
throw error;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* On-device HMR needs the app's websocket client to attach to /ns-hmr after
|
|
203
|
+
* the HTTP boot. When it never does — the websockets polyfill missing from
|
|
204
|
+
* the bundle, `adb reverse` not covering the vite port, or a boot error
|
|
205
|
+
* before the client import — every save logs `recipients=0` and the device
|
|
206
|
+
* silently stays stale. Warn once when a dev session was fetched but no
|
|
207
|
+
* client ever attached.
|
|
208
|
+
*/
|
|
209
|
+
function nsHmrClientWatchdog() {
|
|
210
|
+
return {
|
|
211
|
+
name: "xplat-ns-hmr-client-watchdog",
|
|
212
|
+
configureServer(server) {
|
|
213
|
+
let everConnected = false;
|
|
214
|
+
let timer;
|
|
215
|
+
server.httpServer?.on("request", (req) => {
|
|
216
|
+
if (!everConnected && req.url?.startsWith("/__ns_dev__/session")) {
|
|
217
|
+
clearTimeout(timer);
|
|
218
|
+
timer = setTimeout(() => {
|
|
219
|
+
if (!everConnected) console.warn("[xplat] the app fetched its dev session but no /ns-hmr websocket client connected — edits will not reach the device. Check that @valor/nativescript-websockets is installed, `adb reverse tcp:<port>` covers this vite port (physical Android), and the device log for hmr-client errors.");
|
|
220
|
+
}, 15e3);
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
server.httpServer?.on("upgrade", (req) => {
|
|
224
|
+
if (req.url?.startsWith("/ns-hmr")) {
|
|
225
|
+
everConnected = true;
|
|
226
|
+
clearTimeout(timer);
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
/** The full extension chain, most-specific first: .ios/.android → .mobile →
|
|
233
|
+
* the unsuffixed native default (windows joins per-platform at build time —
|
|
234
|
+
* its qualifier must never shadow `.mobile` on ios/android builds). NS's
|
|
235
|
+
* own file qualifiers (.land, .minWH600…) still apply to assets on top. */
|
|
236
|
+
var nativeExtensions = [
|
|
237
|
+
".ios.tsrx",
|
|
238
|
+
".android.tsrx",
|
|
239
|
+
".mobile.tsrx",
|
|
240
|
+
".tsrx",
|
|
241
|
+
".ios.tsx",
|
|
242
|
+
".android.tsx",
|
|
243
|
+
".mobile.tsx",
|
|
244
|
+
".tsx",
|
|
245
|
+
".ios.ts",
|
|
246
|
+
".android.ts",
|
|
247
|
+
".mobile.ts",
|
|
248
|
+
".ios.js",
|
|
249
|
+
".android.js",
|
|
250
|
+
".mobile.js",
|
|
251
|
+
".ts",
|
|
252
|
+
".mts",
|
|
253
|
+
".ts",
|
|
254
|
+
".jsx",
|
|
255
|
+
".js",
|
|
256
|
+
".json"
|
|
257
|
+
];
|
|
258
|
+
/** The bundle platform the current invocation targets, read from
|
|
259
|
+
* NATIVESCRIPT_BUNDLER_ENV or the ns/vite CLI args — undefined when the
|
|
260
|
+
* caller can't be identified (the generic native chain applies). */
|
|
261
|
+
function nativePlatform() {
|
|
262
|
+
let platform;
|
|
263
|
+
try {
|
|
264
|
+
const env = JSON.parse(process.env.NATIVESCRIPT_BUNDLER_ENV ?? "{}");
|
|
265
|
+
platform = env.platform ?? (env.android ? "android" : env.windows ? "windows" : env.visionos ? "visionos" : env.ios ? "ios" : void 0);
|
|
266
|
+
} catch {}
|
|
267
|
+
const args = process.argv.slice(2);
|
|
268
|
+
if (!platform) {
|
|
269
|
+
if (args.some((arg) => arg === "--visionos" || arg === "--env.visionos" || arg.startsWith("--env.visionos="))) platform = "visionos";
|
|
270
|
+
else if (args.some((arg) => arg === "--android" || arg === "--env.android" || arg.startsWith("--env.android="))) platform = "android";
|
|
271
|
+
else if (args.some((arg) => arg === "--ios" || arg === "--env.ios" || arg.startsWith("--env.ios="))) platform = "ios";
|
|
272
|
+
else if (args.some((arg) => arg === "--windows" || arg === "--env.windows" || arg.startsWith("--env.windows="))) platform = "windows";
|
|
273
|
+
else {
|
|
274
|
+
const platformIndex = args.indexOf("--platform");
|
|
275
|
+
platform = args.find((arg) => arg.startsWith("--platform="))?.slice(11) ?? (platformIndex >= 0 ? args[platformIndex + 1] : void 0);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return platform;
|
|
279
|
+
}
|
|
280
|
+
function nativePlatformExtensions() {
|
|
281
|
+
const platform = nativePlatform();
|
|
282
|
+
if (platform !== "android" && platform !== "ios" && platform !== "visionos" && platform !== "windows") return nativeExtensions;
|
|
283
|
+
const target = platform === "android" ? ".android" : platform === "windows" ? ".windows" : ".ios";
|
|
284
|
+
if (platform === "windows") return [
|
|
285
|
+
".windows.tsrx",
|
|
286
|
+
".tsrx",
|
|
287
|
+
".windows.tsx",
|
|
288
|
+
".tsx",
|
|
289
|
+
".windows.ts",
|
|
290
|
+
".ts",
|
|
291
|
+
".windows.js",
|
|
292
|
+
".ts",
|
|
293
|
+
".mts",
|
|
294
|
+
".jsx",
|
|
295
|
+
".js",
|
|
296
|
+
".json"
|
|
297
|
+
];
|
|
298
|
+
return [
|
|
299
|
+
`${target}.tsrx`,
|
|
300
|
+
".mobile.tsrx",
|
|
301
|
+
".tsrx",
|
|
302
|
+
`${target}.tsx`,
|
|
303
|
+
".mobile.tsx",
|
|
304
|
+
".tsx",
|
|
305
|
+
`${target}.ts`,
|
|
306
|
+
".mobile.ts",
|
|
307
|
+
".ts",
|
|
308
|
+
`${target}.js`,
|
|
309
|
+
".mobile.js",
|
|
310
|
+
".ts",
|
|
311
|
+
".mts",
|
|
312
|
+
".jsx",
|
|
313
|
+
".js",
|
|
314
|
+
".json"
|
|
315
|
+
];
|
|
316
|
+
}
|
|
317
|
+
/** Platform suffixes a module filename can carry. Unsuffixed modules are the
|
|
318
|
+
* native default — legal in every bundle; only a tag foreign to the target
|
|
319
|
+
* is a leak. */
|
|
320
|
+
var PLATFORM_TAG = /\.(web|mobile|ios|android|macos|windows|linux|gtk)\.[^./\\]+$/;
|
|
321
|
+
var boundaryAllowed = {
|
|
322
|
+
web: /* @__PURE__ */ new Set(["web"]),
|
|
323
|
+
ios: /* @__PURE__ */ new Set([
|
|
324
|
+
"ios",
|
|
325
|
+
"android",
|
|
326
|
+
"mobile"
|
|
327
|
+
]),
|
|
328
|
+
visionos: /* @__PURE__ */ new Set([
|
|
329
|
+
"ios",
|
|
330
|
+
"android",
|
|
331
|
+
"mobile"
|
|
332
|
+
]),
|
|
333
|
+
android: /* @__PURE__ */ new Set([
|
|
334
|
+
"ios",
|
|
335
|
+
"android",
|
|
336
|
+
"mobile"
|
|
337
|
+
]),
|
|
338
|
+
macos: /* @__PURE__ */ new Set(["macos"]),
|
|
339
|
+
windows: /* @__PURE__ */ new Set(["windows"]),
|
|
340
|
+
linux: /* @__PURE__ */ new Set(["linux", "web"]),
|
|
341
|
+
gtk: /* @__PURE__ */ new Set(["gtk"]),
|
|
342
|
+
native: /* @__PURE__ */ new Set([
|
|
343
|
+
"ios",
|
|
344
|
+
"android",
|
|
345
|
+
"mobile",
|
|
346
|
+
"windows"
|
|
347
|
+
])
|
|
348
|
+
};
|
|
349
|
+
function platformTag(id) {
|
|
350
|
+
const file = id.split(/[?#]/, 1)[0];
|
|
351
|
+
return PLATFORM_TAG.exec(file)?.[1];
|
|
352
|
+
}
|
|
353
|
+
/** Build-time enforcement of the platform-suffix boundary (invariant #1) —
|
|
354
|
+
* the lint rules catch direct imports, this catches transitive leakage:
|
|
355
|
+
* a `foo.web.tsrx` module reachable in a mobile bundle means the resolver
|
|
356
|
+
* picked a browser leaf into a native graph. Fails `vite build` with the
|
|
357
|
+
* import chain; warns once per module in dev.
|
|
358
|
+
*
|
|
359
|
+
* `platform` names the bundle target — 'web' | 'ios' | 'android' |
|
|
360
|
+
* 'macos' | 'windows' | 'linux' | 'native' (generic: any native tag ok). */
|
|
361
|
+
function xplatBoundary(platform = "native") {
|
|
362
|
+
const resolver = xplatTsrx(platform);
|
|
363
|
+
const allowed = boundaryAllowed[platform] ?? boundaryAllowed.native;
|
|
364
|
+
let command = "build";
|
|
365
|
+
let root = "";
|
|
366
|
+
const warned = /* @__PURE__ */ new Set();
|
|
367
|
+
const foreign = /* @__PURE__ */ new Set();
|
|
368
|
+
const chainFor = (getModuleInfo, id) => {
|
|
369
|
+
const chain = [];
|
|
370
|
+
let cur = id;
|
|
371
|
+
const seen = /* @__PURE__ */ new Set();
|
|
372
|
+
while (cur && !seen.has(cur)) {
|
|
373
|
+
seen.add(cur);
|
|
374
|
+
const info = getModuleInfo(cur);
|
|
375
|
+
const next = [...info?.importers ?? [], ...info?.dynamicImporters ?? []][0];
|
|
376
|
+
if (!next) break;
|
|
377
|
+
chain.push(next);
|
|
378
|
+
cur = next;
|
|
379
|
+
}
|
|
380
|
+
return chain;
|
|
381
|
+
};
|
|
382
|
+
return {
|
|
383
|
+
...serverBoundary(),
|
|
384
|
+
...resolver,
|
|
385
|
+
name: "xplat-platform-boundary",
|
|
386
|
+
configResolved(config) {
|
|
387
|
+
resolver.configResolved(config);
|
|
388
|
+
command = config.command;
|
|
389
|
+
root = config.root;
|
|
390
|
+
},
|
|
391
|
+
moduleParsed(info) {
|
|
392
|
+
const tag = platformTag(info.id);
|
|
393
|
+
if (!tag || allowed.has(tag)) return;
|
|
394
|
+
if (command === "serve") {
|
|
395
|
+
if (!warned.has(info.id)) {
|
|
396
|
+
warned.add(info.id);
|
|
397
|
+
const infoOf = typeof this.getModuleInfo === "function" ? (i) => this.getModuleInfo(i) : () => void 0;
|
|
398
|
+
this.warn(`xplat boundary — .${tag} module in a ${platform} graph: ${relative(root, info.id)} (importers: ${chainFor(infoOf, info.id).map((i) => relative(root, i)).join(" → ") || "unknown"})`);
|
|
399
|
+
}
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
foreign.add(info.id);
|
|
403
|
+
},
|
|
404
|
+
buildEnd() {
|
|
405
|
+
for (const id of foreign) {
|
|
406
|
+
const tag = platformTag(id);
|
|
407
|
+
const infoOf = typeof this.getModuleInfo === "function" ? (i) => this.getModuleInfo(i) : () => void 0;
|
|
408
|
+
const chain = chainFor(infoOf, id);
|
|
409
|
+
this.error(`xplat boundary — a .${tag} module is reachable in the ${platform} bundle:\n foreign: ${relative(root, id)}\n chain: ${[...chain.reverse(), id].map((i) => relative(root, i)).join(" → ") || relative(root, id)}\n Platform-suffixed leaves resolve per-target; a foreign tag here means a\n shared module imported a platform file directly — split it behind the\n suffix seam (a .${tag} import must sit in a .${tag} importer's subtree).`);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
/** Every Octane source module in the native graph, including installed
|
|
415
|
+
* packages, compiles under the nativescript renderer.
|
|
416
|
+
* `.web.*` leaves legitimately use DOM globals; they're
|
|
417
|
+
* unreachable from the native entry but must not fail validation, so each
|
|
418
|
+
* rule excludes them. */
|
|
419
|
+
var nativeRules = [{
|
|
420
|
+
include: "**/*.{ts,tsx,tsrx}",
|
|
421
|
+
exclude: "**/*.web.*",
|
|
422
|
+
renderer: "nativescript"
|
|
423
|
+
}];
|
|
424
|
+
/**
|
|
425
|
+
* Linked dependencies can realpath outside the app root even when install
|
|
426
|
+
* hooks leave registry specs in package.json. Vite gates
|
|
427
|
+
* `?inline`/`?raw`/`?url`/`?direct` transforms on `server.fs.allow`
|
|
428
|
+
* (`isServerAccessDeniedForTransform`), and the dev server's `/ns/m` css
|
|
429
|
+
* route compiles shared stylesheets through `?inline` — so a linked
|
|
430
|
+
* framework checkout's css (e.g. @octane-xplat/ui theme tokens) gets
|
|
431
|
+
* ERR_DENIED_ID and the DOM css module is served in its place, which
|
|
432
|
+
* crashes the device on `__vite__updateStyle`. Allow each linked dep's
|
|
433
|
+
* workspace root so content transforms can read it.
|
|
434
|
+
*/
|
|
435
|
+
var linkedDepFsRoots = (projectRoot, searchForWorkspaceRoot) => {
|
|
436
|
+
let pkg;
|
|
437
|
+
try {
|
|
438
|
+
pkg = JSON.parse(readFileSync(join(projectRoot, "package.json"), "utf8"));
|
|
439
|
+
} catch {
|
|
440
|
+
return [];
|
|
441
|
+
}
|
|
442
|
+
const roots = /* @__PURE__ */ new Set();
|
|
443
|
+
for (const section of [
|
|
444
|
+
"dependencies",
|
|
445
|
+
"devDependencies",
|
|
446
|
+
"optionalDependencies",
|
|
447
|
+
"peerDependencies"
|
|
448
|
+
]) for (const [name, spec] of Object.entries(pkg[section] ?? {})) {
|
|
449
|
+
try {
|
|
450
|
+
const depDir = realpathSync(installedPackageDir(projectRoot, name));
|
|
451
|
+
const rel = relative(realpathSync(projectRoot), depDir).replaceAll("\\", "/");
|
|
452
|
+
if ((rel === ".." || rel.startsWith("../")) && !depDir.replaceAll("\\", "/").includes("/node_modules/") && statSync(depDir).isDirectory()) roots.add(searchForWorkspaceRoot(depDir));
|
|
453
|
+
} catch {}
|
|
454
|
+
const linkTarget = /^(?:link|file|portal):(.+)$/.exec(spec)?.[1];
|
|
455
|
+
if (!linkTarget) continue;
|
|
456
|
+
try {
|
|
457
|
+
const depDir = realpathSync(resolve(projectRoot, linkTarget));
|
|
458
|
+
if (statSync(depDir).isDirectory()) roots.add(searchForWorkspaceRoot(depDir));
|
|
459
|
+
} catch {}
|
|
460
|
+
}
|
|
461
|
+
return [...roots];
|
|
462
|
+
};
|
|
463
|
+
/** Dependencies with subpath-only exports cannot supply the vendor bundle's
|
|
464
|
+
* bare root import. Source-only entries are handled by @nativescript/vite
|
|
465
|
+
* 8.0.20 (NativeScript#11560); retain only this separate rootless case. */
|
|
466
|
+
var sourceOnlyDeps = (projectRoot) => {
|
|
467
|
+
let pkg;
|
|
468
|
+
try {
|
|
469
|
+
pkg = JSON.parse(readFileSync(join(projectRoot, "package.json"), "utf8"));
|
|
470
|
+
} catch {
|
|
471
|
+
return [];
|
|
472
|
+
}
|
|
473
|
+
const names = /* @__PURE__ */ new Set();
|
|
474
|
+
for (const section of ["dependencies", "optionalDependencies"]) for (const name of Object.keys(pkg[section] ?? {})) try {
|
|
475
|
+
const depRoot = installedPackageRoot(projectRoot, name);
|
|
476
|
+
if (!depRoot) continue;
|
|
477
|
+
const exportsField = JSON.parse(readFileSync(join(depRoot, "package.json"), "utf8")).exports;
|
|
478
|
+
if (exportsField && typeof exportsField === "object" && !("." in exportsField) && Object.keys(exportsField).some((key) => key.startsWith("."))) names.add(name);
|
|
479
|
+
} catch {}
|
|
480
|
+
return [...names].sort();
|
|
481
|
+
};
|
|
482
|
+
/** Flags the NativeScript CLI hands the bundler through
|
|
483
|
+
* NATIVESCRIPT_BUNDLER_ENV (`--env.<name>` on `ns run`/`ns test`). */
|
|
484
|
+
function bundlerEnvFlags() {
|
|
485
|
+
try {
|
|
486
|
+
return JSON.parse(process.env.NATIVESCRIPT_BUNDLER_ENV ?? "{}");
|
|
487
|
+
} catch {
|
|
488
|
+
return {};
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
/** `--env.unitTesting` overlay — the vite counterpart of the upstream
|
|
492
|
+
* runner's webpack helper (@nativescript/unit-test-runner's
|
|
493
|
+
* nativescript.webpack.js, which only webpack auto-discovers). It does
|
|
494
|
+
* three things:
|
|
495
|
+
*
|
|
496
|
+
* - Swaps the bundle entry: virtual:entry-with-polyfills' import of the
|
|
497
|
+
* package `main` is redirected to the sibling `test.ts`/`test.js`, so the
|
|
498
|
+
* device boots the coordinator + host page instead of the app.
|
|
499
|
+
* - Aliases bare `vitest` spec imports to the runner's device-safe shim
|
|
500
|
+
* (@vitest/runner + @vitest/expect) — the full vitest package is
|
|
501
|
+
* Node-only and cannot load in the app runtime.
|
|
502
|
+
* - Defines `__NS_TEST_CONFIG__` so the coordinator can read the runner
|
|
503
|
+
* port (`--env.testRunnerPort`) without a network handshake.
|
|
504
|
+
*/
|
|
505
|
+
function unitTestingOverlay(projectRoot, appRequire, env) {
|
|
506
|
+
const pkg = JSON.parse(readFileSync(join(projectRoot, "package.json"), "utf8"));
|
|
507
|
+
const mainEntry = resolve(projectRoot, pkg.main ?? "src/index.ts");
|
|
508
|
+
const entryDir = dirname(mainEntry);
|
|
509
|
+
const testEntry = ["test.ts", "test.js"].map((name) => join(entryDir, name)).find((path) => existsSync(path));
|
|
510
|
+
if (!testEntry) throw new Error(`--env.unitTesting requires a test entry (${join(entryDir, "test.ts")}) — create one with \`ns test init --framework vitest\`.`);
|
|
511
|
+
let shimPath;
|
|
512
|
+
try {
|
|
513
|
+
shimPath = realpathSync(appRequire.resolve("@nativescript/unit-test-runner/runtime/shim"));
|
|
514
|
+
} catch {
|
|
515
|
+
throw new Error("--env.unitTesting requires @nativescript/unit-test-runner as a devDependency of the app (the vitest specifier in specs resolves to its device shim).");
|
|
516
|
+
}
|
|
517
|
+
const mainSpecifier = "/" + relative(projectRoot, mainEntry).replaceAll("\\", "/");
|
|
518
|
+
const port = Number(env.testRunnerPort);
|
|
519
|
+
return {
|
|
520
|
+
define: { __NS_TEST_CONFIG__: JSON.stringify({ port: Number.isInteger(port) ? port : void 0 }) },
|
|
521
|
+
resolve: { alias: [{
|
|
522
|
+
find: /^vitest$/,
|
|
523
|
+
replacement: shimPath
|
|
524
|
+
}] },
|
|
525
|
+
plugins: [{
|
|
526
|
+
name: "xplat-ns-unit-test-entry",
|
|
527
|
+
enforce: "pre",
|
|
528
|
+
resolveId(source, importer) {
|
|
529
|
+
if (importer?.includes("virtual:entry-with-polyfills") && source === mainSpecifier) return testEntry;
|
|
530
|
+
return null;
|
|
531
|
+
}
|
|
532
|
+
}]
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
/** `define` for the `process.env.NODE_ENV` npm convention — upstream octane
|
|
536
|
+
* packages (and much of the ecosystem) read it bare and assume the consumer
|
|
537
|
+
* bundler statically rewrites the member expression. The NativeScript
|
|
538
|
+
* runtime has no `process` global, so an unrewritten read throws at module
|
|
539
|
+
* eval; vite's define substitution is what makes the convention work.
|
|
540
|
+
*
|
|
541
|
+
* Scope: only the literal `process.env.NODE_ENV` expression is rewritten —
|
|
542
|
+
* `process.env.FOO`, `process.platform`, and whole-object `process` reads
|
|
543
|
+
* still crash on native. The NS dev server's per-module `globalThis.process`
|
|
544
|
+
* shim picks the value up too (it captures `process.env.*` define entries
|
|
545
|
+
* from the resolved config). */
|
|
546
|
+
var xplatNodeEnvDefine = (mode) => ({ "process.env.NODE_ENV": JSON.stringify(mode === "production" ? "production" : "development") });
|
|
547
|
+
/**
|
|
548
|
+
* Native (iOS/Android) Vite config. `env` is defineConfig's { mode }; `extra`
|
|
549
|
+
* is merged in last for app-specific additions (own plugins, extra
|
|
550
|
+
* optimizeDeps, server options).
|
|
551
|
+
*
|
|
552
|
+
* opts:
|
|
553
|
+
* - deps: extra optimizeDeps.exclude entries — nativescript-keyed deps are
|
|
554
|
+
* already collected automatically; use this for anything else that must
|
|
555
|
+
* stay per-module in dev (e.g. a plugin missed by the scan)
|
|
556
|
+
* - rules: renderer rules override (defaults cover src + packages source)
|
|
557
|
+
*/
|
|
558
|
+
async function xplatNative(env, opts = {}) {
|
|
559
|
+
const mode = typeof env === "string" ? env : env.mode;
|
|
560
|
+
const pkg = JSON.parse(readFileSync(join(process.cwd(), "package.json"), "utf8"));
|
|
561
|
+
const declared = Object.assign({}, pkg.dependencies, pkg.devDependencies, pkg.optionalDependencies, pkg.peerDependencies);
|
|
562
|
+
const engine = masonEngine(declared, nativePlatform() === "windows" || Boolean(pkg.xplat?.targets?.windows || declared["@nativescript/windows"]));
|
|
563
|
+
if (engine === "@octane-xplat/nativescript-mason-core" && !declared["@octane-xplat/nativescript-mason-core"]) throw new Error(`${masonCorePackage} is required for iOS/Android container layout; run xplat upgrade to add it.`);
|
|
564
|
+
const vendorExcludes = [.../* @__PURE__ */ new Set([...(process.env.NS_VENDOR_EXCLUDE ?? "").split(",").map((entry) => entry.trim()).filter(Boolean), ...sourceOnlyDeps(process.cwd())])];
|
|
565
|
+
if (vendorExcludes.length > 0) process.env.NS_VENDOR_EXCLUDE = vendorExcludes.join(",");
|
|
566
|
+
const appRequire = createRequire(join(process.cwd(), "package.json"));
|
|
567
|
+
const [{ mergeConfig, searchForWorkspaceRoot }, { octaneConfig }, { nativeScriptRenderer }] = await Promise.all([
|
|
568
|
+
importApp("vite"),
|
|
569
|
+
importApp("@nativescript-community/vite-octane"),
|
|
570
|
+
importApp("@nativescript-community/octane/config")
|
|
571
|
+
]);
|
|
572
|
+
const config = mergeConfig(octaneConfig({ mode }, { octane: { renderers: {
|
|
573
|
+
registry: { nativescript: {
|
|
574
|
+
...nativeScriptRenderer,
|
|
575
|
+
intrinsics: "@octane-xplat/jsx"
|
|
576
|
+
} },
|
|
577
|
+
rules: opts.rules ?? nativeRules
|
|
578
|
+
} } }), {
|
|
579
|
+
define: {
|
|
580
|
+
...xplatNodeEnvDefine(process.env.DEBUG ? "development" : mode),
|
|
581
|
+
__WINDOWS__: JSON.stringify(nativePlatform() === "windows")
|
|
582
|
+
},
|
|
583
|
+
oxc: { decorator: { legacy: true } },
|
|
584
|
+
plugins: [
|
|
585
|
+
nativeUnicodeRegex(),
|
|
586
|
+
xplatCss(nativePlatform() ?? "native"),
|
|
587
|
+
pxToDip({ masonSafeAreaEnvironment: engine === masonCorePackage }),
|
|
588
|
+
nsHmrClientWatchdog(),
|
|
589
|
+
xplatBoundary(nativePlatform() ?? "native"),
|
|
590
|
+
nativeExtensionOrder(),
|
|
591
|
+
nativeRelativeResolution(),
|
|
592
|
+
nativeDevSocketPlugin({ deviceRelay: true }) ?? xplatDevBridge()
|
|
593
|
+
],
|
|
594
|
+
server: { fs: { allow: [...new Set([
|
|
595
|
+
searchForWorkspaceRoot(process.cwd()),
|
|
596
|
+
process.cwd(),
|
|
597
|
+
...linkedDepFsRoots(process.cwd(), searchForWorkspaceRoot)
|
|
598
|
+
].filter(Boolean))] } },
|
|
599
|
+
build: { rolldownOptions: {
|
|
600
|
+
moduleTypes: { ".tsrx": "tsx" },
|
|
601
|
+
output: { sourcemapExcludeSources: true }
|
|
602
|
+
} },
|
|
603
|
+
optimizeDeps: {
|
|
604
|
+
noDiscovery: true,
|
|
605
|
+
exclude: [...collectNsPluginDeps(process.cwd()), ...opts.deps ?? []]
|
|
606
|
+
},
|
|
607
|
+
resolve: {
|
|
608
|
+
conditions: nativePlatform() === "windows" ? ["windows", "native"] : ["native"],
|
|
609
|
+
alias: [
|
|
610
|
+
{
|
|
611
|
+
find: /^octane$/,
|
|
612
|
+
replacement: "octane/universal/native"
|
|
613
|
+
},
|
|
614
|
+
...nativeCoreHttpAliases(appRequire),
|
|
615
|
+
...declared[engine] ? [{
|
|
616
|
+
find: /^@octane-xplat\/nativescript-masonkit(?=\/|$)/,
|
|
617
|
+
replacement: dirname(appRequire.resolve(`${engine}/package.json`))
|
|
618
|
+
}] : []
|
|
619
|
+
],
|
|
620
|
+
preserveSymlinks: false,
|
|
621
|
+
extensions: nativePlatformExtensions()
|
|
622
|
+
}
|
|
623
|
+
});
|
|
624
|
+
const envFlags = bundlerEnvFlags();
|
|
625
|
+
if (envFlags.unitTesting) return mergeConfig(mergeConfig(config, unitTestingOverlay(process.cwd(), appRequire, envFlags)), opts.extra ?? {});
|
|
626
|
+
return mergeConfig(config, opts.extra ?? {});
|
|
627
|
+
}
|
|
628
|
+
export { linkedDepFsRoots, nativeExtensions, nativeRelativeResolution, processNativeCss, pxToDip, sourceOnlyDeps, xplatBoundary, xplatCss, xplatDevBridge, xplatNative, xplatNodeEnvDefine, xplatTsrx };
|