create-octane-xplat 0.19.0 → 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/README.md +2 -147
- package/compatibility.json +74 -61
- package/compatibility.ts +134 -79
- package/dist/compatibility.js +45 -13
- package/dist/index.js +127 -64
- package/dist/package-manager.js +62 -0
- package/dist/scaffold.js +362 -57
- package/index.ts +256 -156
- package/library-template/AGENTS.md +1 -1
- package/library-template/README.md +4 -3
- package/library-template/bunfig +4 -0
- package/library-template/package.json +73 -70
- package/library-template/patches/@nativescript-community__octane@0.2.5.patch +161 -24
- package/library-template/patches/@nativescript__core@9.1.3.patch +98 -0
- package/library-template/patches/@nativescript__vite@8.0.20.patch +532 -17
- package/library-template/patches/@octane-xplat__nativescript-mason-core@1.0.0-beta.7.patch +65 -0
- package/library-template/patches/octane@0.16.3.patch +56 -2
- package/library-template/src/Badge.tsx +5 -5
- package/library-template/src/Badge.web.tsx +5 -5
- package/library-template/src/Welcome.stories.tsx +12 -0
- package/library-template/src/normalizeBadgeLabel.ts +1 -1
- package/library-template/src/props.ts +11 -11
- package/library-template/tests/normalizeBadgeLabel.test.ts +1 -1
- package/library-template/tests/packed-consumer.mjs +140 -123
- package/library-template/tsconfig.envs.json +1 -0
- package/library-template/tsconfig.json +1 -0
- package/library-template/tsconfig.types.json +15 -1
- package/library-template/tsrx-typegen.json +1 -1
- package/library-template/workshop.config.ts +3 -0
- package/package-manager.ts +93 -0
- package/package.json +10 -5
- package/scaffold.ts +1061 -449
- package/template/.agents/skills/xplat/SKILL.md +1 -1
- package/template/.agents/skills/xplat/references/styling.md +10 -10
- package/template/AGENTS.md +2 -2
- package/template/bunfig +4 -0
- package/template/nativescript.config.ts +13 -13
- package/template/package.json +69 -64
- package/template/patches/@nativescript-community__octane@0.2.5.patch +161 -24
- package/template/patches/@nativescript__core@9.1.3.patch +98 -0
- package/template/patches/@nativescript__vite@8.0.20.patch +532 -17
- package/template/patches/@octane-xplat__nativescript-mason-core@1.0.0-beta.7.patch +65 -0
- package/template/patches/octane@0.16.3.patch +56 -2
- package/template/src/App.tsrx +66 -64
- package/template/src/Welcome.stories.tsx +22 -0
- package/template/src/app.spec.tsrx +168 -158
- package/template/src/app.web.test.tsx +18 -13
- package/template/src/failure-reporting.spec.ts +3 -3
- package/template/src/main.ts +14 -13
- package/template/src/main.tsrx +2 -0
- package/template/src/native-runtime.spec.ts +13 -11
- package/template/src/test-setup.web.ts +9 -8
- package/template/src/test.ts +6 -6
- package/template/tsconfig.json +17 -1
- package/template/vite.config.native.mts +1 -2
- package/template/vite.config.ts +29 -23
- package/template/vitest.config.mts +17 -17
- package/template/vitest.web.config.mts +7 -7
- package/template/workshop.config.ts +3 -0
- package/library-template/patches/@tsrx__typescript-plugin@0.4.11.patch +0 -11
- package/template/patches/@tsrx__typescript-plugin@0.4.11.patch +0 -11
- /package/library-template/patches/{@octanejs__tiptap@0.0.61.patch → @octanejs__tiptap@0.0.62.patch} +0 -0
- /package/template/patches/{@octanejs__tiptap@0.0.61.patch → @octanejs__tiptap@0.0.62.patch} +0 -0
package/dist/scaffold.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { compatibilityRoot,
|
|
2
|
-
import { cpSync, existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
|
|
3
|
-
import { basename, dirname, join, resolve } from "node:path";
|
|
1
|
+
import { compatibility, compatibilityRoot, mergeCompatibilityCatalog, requestedCatalogPins } from "./compatibility.js";
|
|
2
|
+
import { cpSync, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
|
-
|
|
5
|
+
import { createHash } from "node:crypto";
|
|
6
|
+
import { isMap, parseDocument, stringify } from "yaml";
|
|
7
|
+
// scaffold.ts
|
|
6
8
|
var moduleDir = dirname(fileURLToPath(import.meta.url));
|
|
7
9
|
var pkgRoot = basename(moduleDir) === "dist" ? join(moduleDir, "..") : moduleDir;
|
|
8
10
|
var TEMPLATE_DIR = join(pkgRoot, "template");
|
|
@@ -26,9 +28,14 @@ var targets = {
|
|
|
26
28
|
"dev",
|
|
27
29
|
"build",
|
|
28
30
|
"test",
|
|
29
|
-
"test:web"
|
|
31
|
+
"test:web",
|
|
32
|
+
"workshop"
|
|
30
33
|
],
|
|
31
|
-
devDeps: [
|
|
34
|
+
devDeps: [
|
|
35
|
+
"@octanejs/vite-plugin",
|
|
36
|
+
"jsdom",
|
|
37
|
+
"@octane-xplat/workshop"
|
|
38
|
+
]
|
|
32
39
|
},
|
|
33
40
|
ios: {
|
|
34
41
|
label: "iOS (NativeScript)",
|
|
@@ -56,6 +63,7 @@ var targets = {
|
|
|
56
63
|
},
|
|
57
64
|
"native-shared": {
|
|
58
65
|
hidden: true,
|
|
66
|
+
builds: ["nativescript"],
|
|
59
67
|
patches: [
|
|
60
68
|
"@nativescript/core",
|
|
61
69
|
"@nativescript/types",
|
|
@@ -81,11 +89,13 @@ var targets = {
|
|
|
81
89
|
"@valor/nativescript-websockets"
|
|
82
90
|
],
|
|
83
91
|
devDeps: [
|
|
92
|
+
"@octane-xplat/workshop",
|
|
84
93
|
"@nativescript-community/vite-octane",
|
|
85
94
|
"@nativescript/types",
|
|
86
95
|
"@nativescript/unit-test-runner",
|
|
87
96
|
"@nativescript/vite",
|
|
88
|
-
"nativescript"
|
|
97
|
+
"nativescript",
|
|
98
|
+
"typescript-classic"
|
|
89
99
|
],
|
|
90
100
|
typecheck: "xplat typecheck"
|
|
91
101
|
}
|
|
@@ -142,9 +152,10 @@ function pickKeys(source, names, label) {
|
|
|
142
152
|
}
|
|
143
153
|
/**
|
|
144
154
|
* The package.json a given target set produces. With every target selected
|
|
145
|
-
* this is identical to template/package.json.
|
|
155
|
+
* this is identical to template/package.json. For pnpm the Bun-config homes
|
|
156
|
+
* move to pnpm-workspace.yaml — composePnpmWorkspace emits the other half.
|
|
146
157
|
*/
|
|
147
|
-
function composeManifest(ids) {
|
|
158
|
+
function composeManifest(ids, packageManager = "bun") {
|
|
148
159
|
const resolved = resolveTargets(ids);
|
|
149
160
|
const tpl = templateManifest();
|
|
150
161
|
const manifest = { ...tpl };
|
|
@@ -175,32 +186,120 @@ function composeManifest(ids) {
|
|
|
175
186
|
xplat: Object.fromEntries(Object.entries(tpl.workspaces.catalogs.xplat).filter(([name]) => used.has(name)))
|
|
176
187
|
}
|
|
177
188
|
};
|
|
178
|
-
return manifest;
|
|
189
|
+
if (packageManager === "bun") return manifest;
|
|
190
|
+
return splitForPnpm(manifest, new Set(resolved)).manifest;
|
|
179
191
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
192
|
+
var deniedBuilds = [{ name: "@nativescript/core" }, { name: "protobufjs" }];
|
|
193
|
+
/**
|
|
194
|
+
* The allowBuilds map for a resolved target set: trusted dependencies (with
|
|
195
|
+
* target claims applied) approve, everything pnpm reported denies.
|
|
196
|
+
*/
|
|
197
|
+
function allowBuildsFor(manifest, resolved) {
|
|
198
|
+
const wanted = /* @__PURE__ */ new Set();
|
|
199
|
+
for (const id of resolved) for (const name of targets[id].builds ?? []) wanted.add(name);
|
|
200
|
+
const builds = {};
|
|
201
|
+
for (const name of manifest.trustedDependencies ?? []) if (!Object.values(targets).some((target) => (target.builds ?? []).includes(name)) || wanted.has(name)) builds[name] = true;
|
|
202
|
+
for (const entry of deniedBuilds) if (!entry.target || resolved.has(entry.target)) builds[entry.name] = false;
|
|
203
|
+
return Object.fromEntries(Object.keys(builds).sort().map((name) => [name, builds[name]]));
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Move Bun's config homes — catalogs, overrides, patches, trusted
|
|
207
|
+
* dependencies, the bun engine — out of the composed manifest into the
|
|
208
|
+
* pnpm-workspace.yaml object. Both manager variants come from the same
|
|
209
|
+
* composed manifest so pins can never disagree.
|
|
210
|
+
*/
|
|
211
|
+
function splitForPnpm(manifest, resolved) {
|
|
212
|
+
const next = { ...manifest };
|
|
213
|
+
const workspace = {};
|
|
214
|
+
workspace.packages = next.workspaces?.packages ?? [];
|
|
215
|
+
if (next.workspaces?.catalogs) workspace.catalogs = next.workspaces.catalogs;
|
|
216
|
+
delete next.workspaces;
|
|
217
|
+
if (next.overrides) {
|
|
218
|
+
workspace.overrides = next.overrides;
|
|
219
|
+
delete next.overrides;
|
|
220
|
+
}
|
|
221
|
+
if (next.patchedDependencies) {
|
|
222
|
+
workspace.patchedDependencies = next.patchedDependencies;
|
|
223
|
+
delete next.patchedDependencies;
|
|
224
|
+
}
|
|
225
|
+
workspace.allowUnusedPatches = true;
|
|
226
|
+
workspace.allowBuilds = allowBuildsFor(next, resolved);
|
|
227
|
+
delete next.trustedDependencies;
|
|
228
|
+
workspace.nodeLinker = "hoisted";
|
|
229
|
+
workspace.saveExact = true;
|
|
230
|
+
if (next.engines) {
|
|
231
|
+
delete next.engines.bun;
|
|
232
|
+
if (Object.keys(next.engines).length === 0) delete next.engines;
|
|
233
|
+
}
|
|
234
|
+
next.packageManager = `pnpm@${compatibility.tools.pnpm}`;
|
|
235
|
+
return {
|
|
236
|
+
manifest: next,
|
|
237
|
+
workspace
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
/** The pnpm-workspace.yaml a given target set produces. */
|
|
241
|
+
function composePnpmWorkspace(ids) {
|
|
242
|
+
const resolved = resolveTargets(ids);
|
|
243
|
+
const { workspace } = splitForPnpm(composeManifest(resolved), new Set(resolved));
|
|
244
|
+
return stringify(workspace);
|
|
245
|
+
}
|
|
246
|
+
/** Patch [specifier, path] entries the enabled targets need and `present` lacks. */
|
|
247
|
+
function neededPatchEntries(enabledIds, present) {
|
|
185
248
|
const needed = new Set(enabledIds.flatMap((id) => targets[id].patches ?? []));
|
|
186
|
-
const
|
|
187
|
-
const
|
|
188
|
-
let changed = false;
|
|
189
|
-
pkg.patchedDependencies ??= {};
|
|
190
|
-
for (const [specifier, path] of Object.entries(template.patchedDependencies)) {
|
|
249
|
+
const out = [];
|
|
250
|
+
for (const [specifier, path] of Object.entries(templateManifest().patchedDependencies)) {
|
|
191
251
|
const name = specifier.slice(0, specifier.indexOf("@", 1));
|
|
192
252
|
if (!needed.has(name) || present.has(name)) continue;
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
253
|
+
out.push([specifier, path]);
|
|
254
|
+
}
|
|
255
|
+
return out;
|
|
256
|
+
}
|
|
257
|
+
/** Copy a canonical patch into the root patches/ dir unless it already matches. */
|
|
258
|
+
function stagePatchFile(root, path, read, write) {
|
|
259
|
+
const source = join(TEMPLATE_DIR, path);
|
|
260
|
+
const destination = join(root, path);
|
|
261
|
+
const before = read(destination);
|
|
262
|
+
if (before !== null && !readFileSync(source).equals(before)) throw new Error(`Custom patch ${destination} differs from the framework patch; reconcile it first`);
|
|
263
|
+
write(destination, readFileSync(source), statSync(source).mode & 511);
|
|
264
|
+
}
|
|
265
|
+
var specifierName = (specifier) => specifier.slice(0, specifier.indexOf("@", 1));
|
|
266
|
+
/** Add target-owned local patches before installing newly enabled dependencies. */
|
|
267
|
+
function ensurePatchEntries(enabledIds, root, pkg, read, write) {
|
|
268
|
+
const present = new Set(Object.keys(pkg.patchedDependencies ?? {}).map(specifierName));
|
|
269
|
+
pkg.patchedDependencies ??= {};
|
|
270
|
+
let changed = false;
|
|
271
|
+
for (const [specifier, path] of neededPatchEntries(enabledIds, present)) {
|
|
272
|
+
stagePatchFile(root, path, read, write);
|
|
198
273
|
pkg.patchedDependencies[specifier] = path;
|
|
199
274
|
changed = true;
|
|
200
275
|
}
|
|
201
|
-
if (changed && root !== resolve(appRoot)) writeFileSync(file, JSON.stringify(pkg, null, " ") + "\n");
|
|
202
276
|
return changed;
|
|
203
277
|
}
|
|
278
|
+
/** The selected manager at a workspace root — mirrors the CLI's detection. */
|
|
279
|
+
function managerForRoot(root, pkg) {
|
|
280
|
+
const declared = pkg?.packageManager?.split("@")[0];
|
|
281
|
+
if (declared !== void 0) {
|
|
282
|
+
if (declared === "bun" || declared === "pnpm") return declared;
|
|
283
|
+
throw new Error(`Xplat supports Bun and pnpm projects; found packageManager ${declared}.`);
|
|
284
|
+
}
|
|
285
|
+
const bun = existsSync(join(root, "bun.lock")) || existsSync(join(root, "bun.lockb"));
|
|
286
|
+
const pnpm = existsSync(join(root, "pnpm-lock.yaml"));
|
|
287
|
+
if (bun && pnpm) throw new Error("Both Bun and pnpm lockfiles exist. Set packageManager in package.json or pass --package-manager.");
|
|
288
|
+
if (bun) return "bun";
|
|
289
|
+
if (pnpm) return "pnpm";
|
|
290
|
+
if (pkg?.patchedDependencies) return "bun";
|
|
291
|
+
return existsSync(join(root, "pnpm-workspace.yaml")) ? "pnpm" : "bun";
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Native tsconfig `paths` pinning `@nativescript/core` to the app's own
|
|
295
|
+
* install. Without it, a `link:`/`file:`/`portal:` framework checkout's core
|
|
296
|
+
* imports resolve to that checkout's own copy and checkers see two distinct
|
|
297
|
+
* `View`/`Page`/`Color` type identities (private-member conflicts, issue #66).
|
|
298
|
+
*/
|
|
299
|
+
var nativeCorePaths = {
|
|
300
|
+
"@nativescript/core": ["./node_modules/@nativescript/core"],
|
|
301
|
+
"@nativescript/core/*": ["./node_modules/@nativescript/core/*"]
|
|
302
|
+
};
|
|
204
303
|
/**
|
|
205
304
|
* The tsconfig.json a given target set produces. One program covers every
|
|
206
305
|
* platform suffix (moduleSuffixes is the fixed precedence order); a web-only
|
|
@@ -211,43 +310,84 @@ function composeTsconfig(ids) {
|
|
|
211
310
|
const config = JSON.parse(readFileSync(join(TEMPLATE_DIR, "tsconfig.json"), "utf8"));
|
|
212
311
|
if (!resolved.has("native-shared")) {
|
|
213
312
|
delete config.files;
|
|
313
|
+
delete config.compilerOptions.paths;
|
|
214
314
|
config.compilerOptions.types = (config.compilerOptions.types ?? []).filter((t) => t !== "@nativescript/types");
|
|
215
315
|
config.exclude = [.../* @__PURE__ */ new Set([...config.exclude ?? [], "src/main.ts"])];
|
|
216
316
|
}
|
|
217
317
|
return JSON.stringify(config, null, " ") + "\n";
|
|
218
318
|
}
|
|
319
|
+
/**
|
|
320
|
+
* Starter text files whose command forms follow the chosen package manager.
|
|
321
|
+
* Nothing under patches/ is ever transformed — patch bytes must equal the
|
|
322
|
+
* canonical copies.
|
|
323
|
+
*/
|
|
324
|
+
var managerTextFiles = [
|
|
325
|
+
"AGENTS.md",
|
|
326
|
+
"README.md",
|
|
327
|
+
"nativescript.config.ts",
|
|
328
|
+
"vitest.config.mts",
|
|
329
|
+
"src/app.spec.tsrx"
|
|
330
|
+
];
|
|
331
|
+
var isManagerTextFile = (rel) => managerTextFiles.includes(rel) || rel.startsWith(".agents/skills/xplat/");
|
|
332
|
+
var renamedFiles = {
|
|
333
|
+
gitignore: ".gitignore",
|
|
334
|
+
bunfig: "bunfig.toml"
|
|
335
|
+
};
|
|
336
|
+
var destName = (rel) => renamedFiles[rel] ?? rel;
|
|
337
|
+
/**
|
|
338
|
+
* Rewrite the canonical Bun command forms in starter text for another
|
|
339
|
+
* manager. Applied only to managerTextFiles.
|
|
340
|
+
*/
|
|
341
|
+
function localizeCommands(text, manager) {
|
|
342
|
+
if (manager === "bun") return text;
|
|
343
|
+
return text.replace(/\bbun run (\S+) -- /g, "pnpm run $1 ").replace(/\bbunx\b/g, "pnpm dlx").replace(/\bbun pm pack\b/g, "pnpm pack").replace(/\bbun run\b/g, "pnpm run").replace(/\bbun add\b/g, "pnpm add").replace(/\bbun install\b/g, "pnpm install").replace(/packageManager: 'bun'/g, "packageManager: 'pnpm'");
|
|
344
|
+
}
|
|
219
345
|
/** Write a scaffold with tests for `ids` into `dir` (must not exist or be empty). */
|
|
220
|
-
function composeTargets(ids, dir) {
|
|
346
|
+
function composeTargets(ids, dir, options) {
|
|
347
|
+
const packageManager = options?.packageManager ?? "bun";
|
|
221
348
|
const resolved = new Set(resolveTargets(ids));
|
|
222
349
|
mkdirSync(dir, { recursive: true });
|
|
223
350
|
for (const rel of walk(TEMPLATE_DIR)) {
|
|
224
351
|
if (rel === "package.json" || rel === "tsconfig.json") continue;
|
|
352
|
+
if (packageManager === "pnpm" && rel === "bunfig") continue;
|
|
225
353
|
const owner = ownerOf(rel);
|
|
226
354
|
if (owner && !resolved.has(owner)) continue;
|
|
227
|
-
const
|
|
355
|
+
const source = join(TEMPLATE_DIR, rel);
|
|
356
|
+
const dest = join(dir, destName(rel));
|
|
228
357
|
mkdirSync(dirname(dest), { recursive: true });
|
|
229
|
-
|
|
358
|
+
if (packageManager === "pnpm" && isManagerTextFile(rel)) writeFileSync(dest, localizeCommands(readFileSync(source, "utf8"), packageManager));
|
|
359
|
+
else cpSync(source, dest, { recursive: true });
|
|
230
360
|
}
|
|
231
|
-
writeFileSync(join(dir, "package.json"), JSON.stringify(composeManifest(ids), null, " ") + "\n");
|
|
361
|
+
writeFileSync(join(dir, "package.json"), JSON.stringify(composeManifest(ids, packageManager), null, " ") + "\n");
|
|
232
362
|
writeFileSync(join(dir, "tsconfig.json"), composeTsconfig(ids));
|
|
363
|
+
if (packageManager === "pnpm") writeFileSync(join(dir, "pnpm-workspace.yaml"), composePnpmWorkspace(ids));
|
|
233
364
|
return [...resolved];
|
|
234
365
|
}
|
|
235
366
|
/** Write the cross-platform library starter into `dir`. */
|
|
236
|
-
function composeLibrary(dir, packageName = basename(resolve(dir))) {
|
|
367
|
+
function composeLibrary(dir, packageName = basename(resolve(dir)), options) {
|
|
237
368
|
if (packageName.length > 214 || !/^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/.test(packageName)) throw new Error(`invalid npm package name "${packageName}" — use lowercase letters, numbers, dots, underscores, or hyphens`);
|
|
369
|
+
const packageManager = options?.packageManager ?? "bun";
|
|
238
370
|
mkdirSync(dir, { recursive: true });
|
|
239
371
|
for (const rel of walk(LIBRARY_TEMPLATE_DIR)) {
|
|
240
|
-
if (rel === "package.json") continue;
|
|
241
|
-
const dest = join(dir, rel
|
|
372
|
+
if (rel === "package.json" || packageManager === "pnpm" && rel === "bunfig") continue;
|
|
373
|
+
const dest = join(dir, destName(rel));
|
|
242
374
|
mkdirSync(dirname(dest), { recursive: true });
|
|
243
375
|
const source = join(LIBRARY_TEMPLATE_DIR, rel);
|
|
244
376
|
if (/\.(?:md|ts|tsx|mjs|json)$/.test(rel)) {
|
|
245
|
-
|
|
377
|
+
let content = readFileSync(source, "utf8").replaceAll("octane-xplat-library", packageName);
|
|
378
|
+
if (packageManager === "pnpm" && isManagerTextFile(rel)) content = localizeCommands(content, packageManager);
|
|
246
379
|
writeFileSync(dest, content);
|
|
247
380
|
} else cpSync(source, dest, { recursive: true });
|
|
248
381
|
}
|
|
249
382
|
const manifest = JSON.parse(readFileSync(join(LIBRARY_TEMPLATE_DIR, "package.json"), "utf8"));
|
|
250
383
|
manifest.name = packageName;
|
|
384
|
+
if (packageManager === "pnpm") {
|
|
385
|
+
for (const [name, script] of Object.entries(manifest.scripts ?? {})) manifest.scripts[name] = localizeCommands(String(script), packageManager);
|
|
386
|
+
const { manifest: split, workspace } = splitForPnpm(manifest, /* @__PURE__ */ new Set(["native-shared"]));
|
|
387
|
+
writeFileSync(join(dir, "package.json"), JSON.stringify(split, null, " ") + "\n");
|
|
388
|
+
writeFileSync(join(dir, "pnpm-workspace.yaml"), stringify(workspace));
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
251
391
|
writeFileSync(join(dir, "package.json"), JSON.stringify(manifest, null, " ") + "\n");
|
|
252
392
|
}
|
|
253
393
|
var readJson = (file) => {
|
|
@@ -273,15 +413,14 @@ function targetEnabled(appRoot, id) {
|
|
|
273
413
|
return runtime ? typeof declared[runtime] === "string" : false;
|
|
274
414
|
}
|
|
275
415
|
/** Copy a template file/dir into the app unless the destination exists. */
|
|
276
|
-
function copyMissing(rel, appRoot, report) {
|
|
416
|
+
function copyMissing(rel, appRoot, report, present, copy) {
|
|
277
417
|
const src = join(TEMPLATE_DIR, rel);
|
|
278
|
-
const dest = join(appRoot, rel
|
|
279
|
-
if (
|
|
418
|
+
const dest = join(appRoot, destName(rel));
|
|
419
|
+
if (present(dest)) {
|
|
280
420
|
report.skipped.push(rel);
|
|
281
421
|
return;
|
|
282
422
|
}
|
|
283
|
-
|
|
284
|
-
cpSync(src, dest, { recursive: true });
|
|
423
|
+
copy(src, dest);
|
|
285
424
|
report.copied.push(rel);
|
|
286
425
|
}
|
|
287
426
|
/**
|
|
@@ -290,27 +429,112 @@ function copyMissing(rel, appRoot, report) {
|
|
|
290
429
|
* suffix — so enabling native means wiring the ambient declaration file and
|
|
291
430
|
* the entrypoint into the app's own config.
|
|
292
431
|
*/
|
|
293
|
-
function enableNativeInTsconfig(appRoot) {
|
|
432
|
+
function enableNativeInTsconfig(appRoot, read, write) {
|
|
294
433
|
const path = join(appRoot, "tsconfig.json");
|
|
295
|
-
const text =
|
|
296
|
-
|
|
434
|
+
const text = read(path)?.toString("utf8") ?? "";
|
|
435
|
+
let config;
|
|
436
|
+
try {
|
|
437
|
+
config = JSON.parse(text);
|
|
438
|
+
} catch {
|
|
439
|
+
return false;
|
|
440
|
+
}
|
|
297
441
|
if (!config || typeof config !== "object") return false;
|
|
298
442
|
const indent = text.match(/\n(\s+)"/)?.[1] ?? " ";
|
|
299
443
|
config.files = [.../* @__PURE__ */ new Set(["references.d.ts", ...config.files ?? []])];
|
|
300
444
|
config.exclude = (config.exclude ?? []).filter((e) => e !== "src/main.ts");
|
|
301
445
|
const types = config.compilerOptions?.types;
|
|
302
446
|
if (config.compilerOptions && Array.isArray(types) && !types.includes("@nativescript/types")) config.compilerOptions.types = [...types, "@nativescript/types"];
|
|
303
|
-
|
|
447
|
+
if (config.compilerOptions && typeof config.compilerOptions === "object") {
|
|
448
|
+
const paths = config.compilerOptions.paths ??= {};
|
|
449
|
+
for (const [key, value] of Object.entries(nativeCorePaths)) if (!(key in paths)) paths[key] = value;
|
|
450
|
+
}
|
|
451
|
+
write(path, Buffer.from(JSON.stringify(config, null, indent) + "\n"), 420);
|
|
304
452
|
return true;
|
|
305
453
|
}
|
|
306
454
|
/**
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
*
|
|
455
|
+
* Plan enabling `id` and unmet requirements without writing. Existing target
|
|
456
|
+
* files, scripts and dependency choices stay intact; managed config and catalog
|
|
457
|
+
* changes carry raw-byte input hashes for the publisher.
|
|
310
458
|
*/
|
|
311
|
-
function
|
|
459
|
+
function planTarget(appRoot, id) {
|
|
460
|
+
appRoot = resolve(appRoot);
|
|
461
|
+
const root = compatibilityRoot(appRoot);
|
|
462
|
+
const inputs = /* @__PURE__ */ new Map();
|
|
463
|
+
const contents = /* @__PURE__ */ new Map();
|
|
464
|
+
const files = /* @__PURE__ */ new Map();
|
|
465
|
+
const directories = /* @__PURE__ */ new Map();
|
|
466
|
+
const hash = (bytes) => createHash("sha256").update(bytes).digest("hex");
|
|
467
|
+
const within = (path) => {
|
|
468
|
+
const rel = relative(root, path);
|
|
469
|
+
return rel === "" || rel !== ".." && !rel.startsWith(".." + sep) && !isAbsolute(rel);
|
|
470
|
+
};
|
|
471
|
+
const observe = (path) => {
|
|
472
|
+
path = resolve(path);
|
|
473
|
+
if (!within(path)) throw new Error(`Scaffold path leaves its workspace: ${path}`);
|
|
474
|
+
if (inputs.has(path)) return inputs.get(path);
|
|
475
|
+
let info;
|
|
476
|
+
try {
|
|
477
|
+
info = lstatSync(path);
|
|
478
|
+
} catch (error) {
|
|
479
|
+
if (error.code !== "ENOENT") throw error;
|
|
480
|
+
const input = {
|
|
481
|
+
path,
|
|
482
|
+
kind: "missing"
|
|
483
|
+
};
|
|
484
|
+
inputs.set(path, input);
|
|
485
|
+
return input;
|
|
486
|
+
}
|
|
487
|
+
if (info.isSymbolicLink() || !info.isDirectory() && !info.isFile()) throw new Error(`Scaffold path must be an ordinary file or directory: ${path}`);
|
|
488
|
+
const input = {
|
|
489
|
+
path,
|
|
490
|
+
kind: info.isDirectory() ? "directory" : "file",
|
|
491
|
+
mode: info.mode & 511
|
|
492
|
+
};
|
|
493
|
+
if (input.kind === "file") {
|
|
494
|
+
if (info.size > 16777216) throw new Error(`Scaffold input exceeds 16 MiB: ${path}`);
|
|
495
|
+
const bytes = readFileSync(path);
|
|
496
|
+
input.sha256 = hash(bytes);
|
|
497
|
+
contents.set(path, bytes);
|
|
498
|
+
}
|
|
499
|
+
inputs.set(path, input);
|
|
500
|
+
return input;
|
|
501
|
+
};
|
|
502
|
+
const read = (path) => {
|
|
503
|
+
const input = observe(path);
|
|
504
|
+
if (input.kind === "missing") return null;
|
|
505
|
+
if (input.kind !== "file") throw new Error(`Expected scaffold file: ${path}`);
|
|
506
|
+
return contents.get(resolve(path));
|
|
507
|
+
};
|
|
508
|
+
const directory = (path, mode = 493) => {
|
|
509
|
+
if (path === root || path === appRoot) return;
|
|
510
|
+
const input = observe(path);
|
|
511
|
+
if (input.kind === "directory") return;
|
|
512
|
+
if (input.kind !== "missing") throw new Error(`Expected scaffold directory: ${path}`);
|
|
513
|
+
directory(dirname(path));
|
|
514
|
+
directories.set(path, mode);
|
|
515
|
+
};
|
|
516
|
+
const write = (path, bytes, mode) => {
|
|
517
|
+
const before = read(path);
|
|
518
|
+
if (before !== null && before.equals(bytes)) return;
|
|
519
|
+
directory(dirname(path));
|
|
520
|
+
files.set(path, {
|
|
521
|
+
path,
|
|
522
|
+
before: before === null ? null : hash(before),
|
|
523
|
+
content: bytes.toString("base64"),
|
|
524
|
+
mode: before === null ? mode : observe(path).mode
|
|
525
|
+
});
|
|
526
|
+
};
|
|
527
|
+
const copy = (source, dest) => {
|
|
528
|
+
const info = lstatSync(source);
|
|
529
|
+
if (info.isDirectory()) {
|
|
530
|
+
directory(dest, info.mode & 511);
|
|
531
|
+
for (const name of readdirSync(source).sort()) copy(join(source, name), join(dest, name));
|
|
532
|
+
} else if (info.isFile()) write(dest, readFileSync(source), info.mode & 511);
|
|
533
|
+
else throw new Error(`Scaffold template must not contain aliases: ${source}`);
|
|
534
|
+
};
|
|
312
535
|
const manifestPath = join(appRoot, "package.json");
|
|
313
|
-
const raw =
|
|
536
|
+
const raw = read(manifestPath)?.toString("utf8");
|
|
537
|
+
if (raw === void 0) throw new Error(`No package.json at ${appRoot}`);
|
|
314
538
|
const manifest = JSON.parse(raw);
|
|
315
539
|
const tpl = templateManifest();
|
|
316
540
|
const report = {
|
|
@@ -323,13 +547,21 @@ function applyTarget(appRoot, id) {
|
|
|
323
547
|
depsAdded: []
|
|
324
548
|
};
|
|
325
549
|
for (const tid of resolveTargets([id])) {
|
|
326
|
-
|
|
550
|
+
const declared = {
|
|
551
|
+
...manifest.dependencies,
|
|
552
|
+
...manifest.devDependencies
|
|
553
|
+
};
|
|
554
|
+
const runtime = {
|
|
555
|
+
ios: "@nativescript/ios",
|
|
556
|
+
android: "@nativescript/android"
|
|
557
|
+
}[tid];
|
|
558
|
+
if (tid === "web" ? observe(join(appRoot, "vite.config.ts")).kind !== "missing" || observe(join(appRoot, "vite.config.mts")).kind !== "missing" : tid === "native-shared" ? observe(join(appRoot, "nativescript.config.ts")).kind !== "missing" : runtime !== void 0 && typeof declared[runtime] === "string") {
|
|
327
559
|
report.already.push(tid);
|
|
328
560
|
continue;
|
|
329
561
|
}
|
|
330
562
|
report.enabled.push(tid);
|
|
331
563
|
const t = targets[tid];
|
|
332
|
-
for (const rel of t.files) copyMissing(rel, appRoot, report);
|
|
564
|
+
for (const rel of t.files) copyMissing(rel, appRoot, report, (path) => observe(path).kind !== "missing", copy);
|
|
333
565
|
for (const [section, key] of [["dependencies", "deps"], ["devDependencies", "devDeps"]]) for (const name of t[key] ?? []) {
|
|
334
566
|
manifest[section] ??= {};
|
|
335
567
|
if (manifest[section][name] === void 0) {
|
|
@@ -351,16 +583,89 @@ function applyTarget(appRoot, id) {
|
|
|
351
583
|
}
|
|
352
584
|
if (tid === "native-shared") {
|
|
353
585
|
if (manifest.main === void 0) manifest.main = tpl.main;
|
|
354
|
-
report.tsconfigUpdated = enableNativeInTsconfig(appRoot);
|
|
586
|
+
report.tsconfigUpdated = enableNativeInTsconfig(appRoot, read, write);
|
|
355
587
|
}
|
|
356
588
|
}
|
|
357
|
-
|
|
358
|
-
|
|
589
|
+
const enabledTargets = [...report.enabled, ...report.already];
|
|
590
|
+
if (managerForRoot(root, root === appRoot ? manifest : JSON.parse(read(join(root, "package.json"))?.toString("utf8") ?? "null")) === "pnpm") {
|
|
591
|
+
const yamlPath = join(root, "pnpm-workspace.yaml");
|
|
592
|
+
const doc = parseDocument(read(yamlPath)?.toString("utf8") ?? "packages: []\n");
|
|
593
|
+
const { catalog, pins } = requestedCatalogPins(manifest);
|
|
594
|
+
for (const [name, spec] of Object.entries(pins)) if (doc.getIn([
|
|
595
|
+
"catalogs",
|
|
596
|
+
catalog,
|
|
597
|
+
name
|
|
598
|
+
]) === void 0) doc.setIn([
|
|
599
|
+
"catalogs",
|
|
600
|
+
catalog,
|
|
601
|
+
name
|
|
602
|
+
], spec);
|
|
603
|
+
const existing = doc.get("patchedDependencies");
|
|
604
|
+
const patches = neededPatchEntries(enabledTargets, new Set((isMap(existing) ? existing.items : []).map((pair) => specifierName(String(pair.key)))));
|
|
605
|
+
for (const [specifier, path] of patches) {
|
|
606
|
+
stagePatchFile(root, path, read, write);
|
|
607
|
+
doc.setIn(["patchedDependencies", specifier], path);
|
|
608
|
+
}
|
|
609
|
+
if (patches.length) report.patchesAdded = true;
|
|
610
|
+
const resolved = new Set(resolveTargets(enabledTargets));
|
|
611
|
+
for (const id of resolved) for (const name of targets[id].builds ?? []) if (doc.getIn(["allowBuilds", name]) === void 0) {
|
|
612
|
+
doc.setIn(["allowBuilds", name], true);
|
|
613
|
+
report.allowBuildsAdded = true;
|
|
614
|
+
}
|
|
615
|
+
for (const entry of deniedBuilds) if ((!entry.target || resolved.has(entry.target)) && doc.getIn(["allowBuilds", entry.name]) === void 0) {
|
|
616
|
+
doc.setIn(["allowBuilds", entry.name], false);
|
|
617
|
+
report.allowBuildsAdded = true;
|
|
618
|
+
}
|
|
619
|
+
write(yamlPath, Buffer.from(String(doc)), 420);
|
|
620
|
+
} else {
|
|
621
|
+
const owner = root === appRoot ? manifest : JSON.parse(read(join(root, "package.json")).toString("utf8"));
|
|
622
|
+
if (ensurePatchEntries(enabledTargets, root, owner, read, write)) report.patchesAdded = true;
|
|
623
|
+
mergeCompatibilityCatalog(manifest, owner);
|
|
624
|
+
if (root !== appRoot) write(join(root, "package.json"), Buffer.from(JSON.stringify(owner, null, " ") + "\n"), 420);
|
|
625
|
+
}
|
|
359
626
|
if (JSON.stringify(manifest) !== JSON.stringify(JSON.parse(raw))) {
|
|
360
627
|
const indent = raw.match(/\n(\s+)"/)?.[1] ?? " ";
|
|
361
|
-
|
|
628
|
+
write(manifestPath, Buffer.from(JSON.stringify(manifest, null, indent) + "\n"), 420);
|
|
629
|
+
}
|
|
630
|
+
if (files.size > 8192 || inputs.size > 2e4 || directories.size > 8192) throw new Error("Scaffold plan exceeds inventory limits");
|
|
631
|
+
let total = 0;
|
|
632
|
+
for (const file of files.values()) {
|
|
633
|
+
const bytes = Buffer.from(file.content, "base64").length;
|
|
634
|
+
total += bytes;
|
|
635
|
+
if (bytes > 16777216 || total > 33554432) throw new Error("Scaffold plan exceeds byte limits");
|
|
636
|
+
}
|
|
637
|
+
return {
|
|
638
|
+
version: 1,
|
|
639
|
+
root,
|
|
640
|
+
appRoot,
|
|
641
|
+
id,
|
|
642
|
+
files: [...files.values()],
|
|
643
|
+
directories: [...directories].map(([path, mode]) => ({
|
|
644
|
+
path,
|
|
645
|
+
mode
|
|
646
|
+
})),
|
|
647
|
+
inputs: [...inputs.values()],
|
|
648
|
+
report
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
/** Apply the same read-only plan used by native CLI orchestration. */
|
|
652
|
+
function applyTarget(appRoot, id) {
|
|
653
|
+
const plan = planTarget(appRoot, id);
|
|
654
|
+
for (const input of plan.inputs) {
|
|
655
|
+
let info;
|
|
656
|
+
try {
|
|
657
|
+
info = lstatSync(input.path);
|
|
658
|
+
} catch (error) {
|
|
659
|
+
if (error.code !== "ENOENT") throw error;
|
|
660
|
+
}
|
|
661
|
+
const kind = !info ? "missing" : info.isFile() ? "file" : info.isDirectory() ? "directory" : "alias";
|
|
662
|
+
if (kind !== input.kind || kind === "file" && createHash("sha256").update(readFileSync(input.path)).digest("hex") !== input.sha256) throw new Error(`Scaffold input changed; retry: ${input.path}`);
|
|
362
663
|
}
|
|
363
|
-
|
|
664
|
+
for (const entry of plan.directories) mkdirSync(entry.path, {
|
|
665
|
+
recursive: true,
|
|
666
|
+
mode: entry.mode
|
|
667
|
+
});
|
|
668
|
+
for (const entry of plan.files) writeFileSync(entry.path, Buffer.from(entry.content, "base64"), { mode: entry.mode });
|
|
669
|
+
return plan.report;
|
|
364
670
|
}
|
|
365
|
-
|
|
366
|
-
export { LIBRARY_TEMPLATE_DIR, TEMPLATE_DIR, applyTarget, composeLibrary, composeManifest, composeTargets, composeTsconfig, defaultTargets, resolveTargets, selectableTargets, targetEnabled, targets };
|
|
671
|
+
export { LIBRARY_TEMPLATE_DIR, TEMPLATE_DIR, applyTarget, composeLibrary, composeManifest, composePnpmWorkspace, composeTargets, composeTsconfig, defaultTargets, localizeCommands, nativeCorePaths, planTarget, resolveTargets, selectableTargets, targetEnabled, targets };
|