create-octane-xplat 0.18.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 -144
- package/compatibility.json +97 -19
- package/compatibility.ts +141 -72
- package/dist/compatibility.js +66 -26
- package/dist/index.js +127 -64
- package/dist/package-manager.js +62 -0
- package/dist/scaffold.js +377 -127
- package/index.ts +256 -154
- package/library-template/AGENTS.md +6 -4
- package/library-template/README.md +22 -18
- package/library-template/bunfig +4 -0
- package/library-template/package.json +115 -18
- package/library-template/patches/@nativescript-community__octane@0.2.5.patch +1018 -0
- package/library-template/patches/@nativescript-community__sqlite-bridge@4.1.1.patch +30 -0
- package/library-template/patches/@nativescript-community__vite-octane@0.2.1.patch +72 -0
- package/library-template/patches/@nativescript__core@9.1.3.patch +1280 -0
- package/library-template/patches/@nativescript__doctor@2.0.18.patch +13 -0
- package/library-template/patches/@nativescript__vite@8.0.20.patch +2019 -0
- package/library-template/patches/@octane-xplat__nativescript-mason-core@1.0.0-beta.7.patch +65 -0
- package/library-template/patches/@octanejs__tiptap@0.0.62.patch +12 -0
- package/library-template/patches/@sveltejs__acorn-typescript@1.0.13.patch +16 -0
- package/library-template/patches/css@3.0.0.patch +52 -0
- package/library-template/patches/octane@0.16.3.patch +1479 -0
- package/library-template/src/Badge.tsx +7 -6
- package/library-template/src/Badge.web.tsx +7 -6
- 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 +70 -58
- package/scaffold.ts +1056 -526
- package/template/.agents/skills/xplat/SKILL.md +6 -6
- package/template/.agents/skills/xplat/references/components.md +1 -1
- package/template/.agents/skills/xplat/references/navigation.md +1 -1
- package/template/.agents/skills/xplat/references/styling.md +14 -14
- package/template/AGENTS.md +10 -10
- package/template/bunfig +4 -0
- package/template/gitignore +1 -0
- package/template/nativescript.config.ts +13 -16
- package/template/package.json +119 -10
- package/template/patches/@nativescript-community__octane@0.2.5.patch +1018 -0
- package/template/patches/@nativescript-community__sqlite-bridge@4.1.1.patch +30 -0
- package/template/patches/@nativescript-community__vite-octane@0.2.1.patch +72 -0
- package/template/patches/@nativescript__core@9.1.3.patch +1280 -0
- package/template/patches/@nativescript__doctor@2.0.18.patch +13 -0
- package/template/patches/@nativescript__vite@8.0.20.patch +2019 -0
- package/template/patches/@octane-xplat__nativescript-mason-core@1.0.0-beta.7.patch +65 -0
- package/template/patches/@octanejs__tiptap@0.0.62.patch +12 -0
- package/template/patches/@sveltejs__acorn-typescript@1.0.13.patch +16 -0
- package/template/patches/css@3.0.0.patch +52 -0
- package/template/patches/octane@0.16.3.patch +1479 -0
- package/template/src/App.tsrx +77 -42
- package/template/src/Welcome.stories.tsx +22 -0
- package/template/src/app.spec.tsrx +169 -163
- 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/main.web.tsrx +5 -5
- 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 +18 -18
- package/template/vitest.web.config.mts +7 -7
- package/template/workshop.config.ts +3 -0
- package/library-template/pnpm-workspace.yaml +0 -171
- package/template/pnpm-workspace.yaml +0 -192
package/dist/compatibility.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
1
|
+
import { existsSync, globSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { basename, dirname, join, resolve } from "node:path";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
|
-
import {
|
|
4
|
+
import { parse } from "yaml";
|
|
5
5
|
import { createRequire } from "node:module";
|
|
6
|
-
|
|
6
|
+
// compatibility.ts
|
|
7
7
|
var dir = dirname(fileURLToPath(import.meta.url));
|
|
8
8
|
var root = basename(dir) === "dist" ? dirname(dir) : dir;
|
|
9
9
|
var compatibility = createRequire(import.meta.url)(join(root, "compatibility.json"));
|
|
@@ -20,12 +20,12 @@ function managedPackage(name, profile = "default") {
|
|
|
20
20
|
...compatibility.profiles[profile]?.[name]
|
|
21
21
|
} : void 0;
|
|
22
22
|
}
|
|
23
|
-
/** Return the
|
|
23
|
+
/** Return the install specifier, keeping preview URLs separate from package versions. */
|
|
24
24
|
function managedSpecifier(name, profile = "default") {
|
|
25
25
|
const entry = managedPackage(name, profile);
|
|
26
26
|
return entry?.specifier ?? entry?.version;
|
|
27
27
|
}
|
|
28
|
-
/** Named
|
|
28
|
+
/** Named catalog reserved for this compatibility profile. */
|
|
29
29
|
var managedCatalog = (profile = "default") => profile === "default" ? "xplat" : `xplat-${profile}`;
|
|
30
30
|
/** Installed dependency fields; library consumer peers intentionally keep their ranges. */
|
|
31
31
|
var dependencySections = [
|
|
@@ -40,27 +40,67 @@ function projectProfile(pkg) {
|
|
|
40
40
|
if (windows && (deps["@nativescript/ios"] || deps["@nativescript/android"])) throw new Error("Windows preview and mobile need separate workspace packages: their NativeScript pins differ");
|
|
41
41
|
return windows ? "windows" : "default";
|
|
42
42
|
}
|
|
43
|
-
/**
|
|
43
|
+
/**
|
|
44
|
+
* An ancestor's workspace membership patterns: pnpm-workspace.yaml `packages`
|
|
45
|
+
* wins when the ancestor is not Bun-pinned, matching the CLI's root rules.
|
|
46
|
+
*/
|
|
47
|
+
function workspacePatterns(root) {
|
|
48
|
+
const yamlFile = join(root, "pnpm-workspace.yaml");
|
|
49
|
+
const pkgFile = join(root, "package.json");
|
|
50
|
+
const pkg = existsSync(pkgFile) ? JSON.parse(readFileSync(pkgFile, "utf8")) : {};
|
|
51
|
+
if (pkg.packageManager?.split("@")[0] !== "bun" && existsSync(yamlFile)) {
|
|
52
|
+
const packages = parse(readFileSync(yamlFile, "utf8"))?.packages;
|
|
53
|
+
return Array.isArray(packages) ? packages : [];
|
|
54
|
+
}
|
|
55
|
+
const patterns = Array.isArray(pkg.workspaces) ? pkg.workspaces : pkg.workspaces?.packages;
|
|
56
|
+
return Array.isArray(patterns) ? patterns : [];
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Find the workspace that owns this app, respecting package membership.
|
|
60
|
+
* Mirrors the CLI's packageManagerRoot: ancestors need a package.json or a
|
|
61
|
+
* pnpm-workspace.yaml, and membership comes from the manager's config home.
|
|
62
|
+
*/
|
|
63
|
+
function compatibilityRoot(appRoot) {
|
|
64
|
+
const app = resolve(appRoot);
|
|
65
|
+
for (let at = dirname(app); dirname(at) !== at; at = dirname(at)) {
|
|
66
|
+
if (!existsSync(join(at, "package.json")) && !existsSync(join(at, "pnpm-workspace.yaml"))) continue;
|
|
67
|
+
const patterns = workspacePatterns(at);
|
|
68
|
+
if (!patterns.length) continue;
|
|
69
|
+
const included = patterns.filter((p) => !p.startsWith("!"));
|
|
70
|
+
const exclude = ["**/node_modules/**", ...patterns.filter((p) => p.startsWith("!")).map((p) => p.slice(1))];
|
|
71
|
+
if (globSync(included, {
|
|
72
|
+
cwd: at,
|
|
73
|
+
exclude
|
|
74
|
+
}).some((p) => resolve(at, p) === app)) return at;
|
|
75
|
+
}
|
|
76
|
+
return app;
|
|
77
|
+
}
|
|
78
|
+
/** Add missing Bun catalog pins when enabling a target. Existing pins stay intact. */
|
|
44
79
|
function ensureCompatibilityCatalog(appRoot, pkg) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
80
|
+
const root = compatibilityRoot(appRoot);
|
|
81
|
+
const file = join(root, "package.json");
|
|
82
|
+
const owner = root === resolve(appRoot) ? pkg : JSON.parse(readFileSync(file, "utf8"));
|
|
83
|
+
mergeCompatibilityCatalog(pkg, owner);
|
|
84
|
+
if (owner !== pkg) writeFileSync(file, JSON.stringify(owner, null, " ") + "\n");
|
|
85
|
+
}
|
|
86
|
+
/** Catalog pins a package requests via `catalog:` specifiers, managed set only. */
|
|
87
|
+
function requestedCatalogPins(pkg) {
|
|
52
88
|
const profile = projectProfile(pkg);
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (
|
|
89
|
+
const catalog = managedCatalog(profile);
|
|
90
|
+
const pins = {};
|
|
91
|
+
for (const section of dependencySections) for (const [name, spec] of Object.entries(pkg[section] ?? {})) if (spec === `catalog:${catalog}` && pins[name] === void 0) pins[name] = managedSpecifier(name, profile);
|
|
92
|
+
return {
|
|
93
|
+
catalog,
|
|
94
|
+
pins
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/** Merge catalog policy without filesystem effects; shared by scaffold plans. */
|
|
98
|
+
function mergeCompatibilityCatalog(pkg, owner) {
|
|
99
|
+
if (Array.isArray(owner.workspaces)) owner.workspaces = { packages: owner.workspaces };
|
|
100
|
+
owner.workspaces ??= { packages: [] };
|
|
101
|
+
const catalogs = owner.catalogs ?? (owner.workspaces.catalogs ??= {});
|
|
102
|
+
const { catalog, pins } = requestedCatalogPins(pkg);
|
|
103
|
+
const target = catalogs[catalog] ??= {};
|
|
104
|
+
for (const [name, spec] of Object.entries(pins)) target[name] ??= spec;
|
|
64
105
|
}
|
|
65
|
-
|
|
66
|
-
export { compatibility, dependencySections, ensureCompatibilityCatalog, managedCatalog, managedPackage, managedSpecifier, projectProfile };
|
|
106
|
+
export { compatibility, compatibilityRoot, dependencySections, ensureCompatibilityCatalog, managedCatalog, managedPackage, managedSpecifier, mergeCompatibilityCatalog, projectProfile, requestedCatalogPins };
|
package/dist/index.js
CHANGED
|
@@ -1,75 +1,111 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { composeLibrary, composeTargets, defaultTargets, resolveTargets, selectableTargets, targets } from "./scaffold.js";
|
|
3
|
+
import { compatibility } from "./compatibility.js";
|
|
4
|
+
import { decidePackageManager, installedManagers, managerVersion } from "./package-manager.js";
|
|
3
5
|
import { existsSync, readdirSync } from "node:fs";
|
|
4
6
|
import { basename, resolve } from "node:path";
|
|
5
7
|
import { spawnSync } from "node:child_process";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
var templateValueIndex = templateIndex !== -1 && argv[templateIndex] === "--template" ? templateIndex + 1 : -1;
|
|
11
|
-
var templateArg = templateIndex === -1 ? "app" : templateValueIndex !== -1 ? argv[templateValueIndex] : argv[templateIndex].slice(11);
|
|
12
|
-
var nameIndex = argv.findIndex((arg) => arg === "--name" || arg.startsWith("--name="));
|
|
13
|
-
var nameValueIndex = nameIndex !== -1 && argv[nameIndex] === "--name" ? nameIndex + 1 : -1;
|
|
14
|
-
var nameArg = nameIndex === -1 ? void 0 : nameValueIndex !== -1 ? argv[nameValueIndex] : argv[nameIndex].slice(7);
|
|
15
|
-
if (templateIndex !== -1 && (!templateArg || templateArg.startsWith("-"))) {
|
|
16
|
-
console.error("✗ --template needs a value: app or library");
|
|
17
|
-
process.exit(1);
|
|
18
|
-
}
|
|
19
|
-
if (!["app", "library"].includes(templateArg)) {
|
|
20
|
-
console.error(`✗ unknown template "${templateArg}" — expected app or library`);
|
|
21
|
-
process.exit(1);
|
|
22
|
-
}
|
|
23
|
-
if (nameIndex !== -1 && (!nameArg || nameArg.startsWith("-"))) {
|
|
24
|
-
console.error("✗ --name needs an npm package name");
|
|
25
|
-
process.exit(1);
|
|
26
|
-
}
|
|
27
|
-
var targetsIndex = argv.findIndex((arg) => arg === "--targets" || arg.startsWith("--targets="));
|
|
28
|
-
var targetsValueIndex = targetsIndex !== -1 && argv[targetsIndex] === "--targets" ? targetsIndex + 1 : -1;
|
|
29
|
-
var targetsArg = targetsIndex === -1 ? void 0 : targetsValueIndex !== -1 ? argv[targetsValueIndex] : argv[targetsIndex].slice(10);
|
|
30
|
-
if (targetsIndex !== -1 && (targetsArg === void 0 || targetsArg.startsWith("-"))) {
|
|
31
|
-
console.error(`✗ --targets needs a comma list: ${selectableTargets.join(", ")}`);
|
|
8
|
+
import { parseArgs } from "node:util";
|
|
9
|
+
// index.ts
|
|
10
|
+
var fail = (message) => {
|
|
11
|
+
console.error(`✗ ${message}`);
|
|
32
12
|
process.exit(1);
|
|
13
|
+
};
|
|
14
|
+
function parseCli() {
|
|
15
|
+
try {
|
|
16
|
+
return parseArgs({
|
|
17
|
+
args: process.argv.slice(2),
|
|
18
|
+
allowPositionals: true,
|
|
19
|
+
options: {
|
|
20
|
+
template: {
|
|
21
|
+
type: "string",
|
|
22
|
+
default: "app"
|
|
23
|
+
},
|
|
24
|
+
name: { type: "string" },
|
|
25
|
+
targets: { type: "string" },
|
|
26
|
+
"package-manager": { type: "string" },
|
|
27
|
+
"no-install": {
|
|
28
|
+
type: "boolean",
|
|
29
|
+
default: false
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
} catch (error) {
|
|
34
|
+
return fail(error.message);
|
|
35
|
+
}
|
|
33
36
|
}
|
|
34
|
-
var
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
var { values, positionals } = parseCli();
|
|
38
|
+
var oneOf = (flag, value, choices) => value === void 0 || choices.includes(value) ? value : fail(`--${flag} must be ${choices.join(" or ")}`);
|
|
39
|
+
var templateArg = oneOf("template", values.template, ["app", "library"]);
|
|
40
|
+
var managerFlag = oneOf("package-manager", values["package-manager"], ["bun", "pnpm"]);
|
|
41
|
+
var noInstall = values["no-install"];
|
|
42
|
+
if (values.name === "") fail("--name needs an npm package name");
|
|
43
|
+
if (positionals.length > 1) fail(`expected one project directory, got ${positionals.join(" ")}`);
|
|
40
44
|
var defaultDir = templateArg === "library" ? "octane-xplat-library" : "octane-xplat-app";
|
|
41
|
-
var dir = resolve(
|
|
42
|
-
if (templateArg === "library" &&
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
if (templateArg === "app" && nameIndex !== -1) {
|
|
47
|
-
console.error("✗ --name applies only to the library template");
|
|
48
|
-
process.exit(1);
|
|
49
|
-
}
|
|
50
|
-
if (existsSync(dir) && readdirSync(dir).length > 0) {
|
|
51
|
-
console.error(`✗ ${dir} exists and is not empty`);
|
|
52
|
-
process.exit(1);
|
|
53
|
-
}
|
|
45
|
+
var dir = resolve(positionals[0] ?? defaultDir);
|
|
46
|
+
if (templateArg === "library" && values.targets !== void 0) fail("--targets applies to the app template; libraries start with web and native builds");
|
|
47
|
+
if (templateArg === "app" && values.name !== void 0) fail("--name applies only to the library template");
|
|
48
|
+
if (existsSync(dir) && readdirSync(dir).length > 0) fail(`${dir} exists and is not empty`);
|
|
54
49
|
var parseTargets = (value) => {
|
|
55
50
|
const ids = value.split(",").map((s) => s.trim()).filter(Boolean);
|
|
56
51
|
if (ids.length === 0) throw new Error(`--targets needs a comma list: ${selectableTargets.join(", ")}`);
|
|
57
52
|
for (const id of ids) if (!selectableTargets.includes(id)) throw new Error(`unknown target "${id}" — expected a comma list of: ${selectableTargets.join(", ")}`);
|
|
58
53
|
return resolveTargets(ids);
|
|
59
54
|
};
|
|
55
|
+
var decision = decidePackageManager({
|
|
56
|
+
flag: managerFlag,
|
|
57
|
+
userAgent: process.env.npm_config_user_agent,
|
|
58
|
+
installed: installedManagers(),
|
|
59
|
+
interactive: Boolean(process.stdout.isTTY)
|
|
60
|
+
});
|
|
61
|
+
var packageManager = decision.kind === "use" ? decision.manager : "bun";
|
|
62
|
+
var managerNotice;
|
|
63
|
+
if (decision.kind === "missing") managerNotice = `! Neither Bun nor pnpm was found. Installing dependencies, applying framework
|
|
64
|
+
patches (xplat patches apply) and running the app all need one of them.
|
|
65
|
+
Install Bun ${compatibility.tools.bun}+ (https://bun.sh) or pnpm ${compatibility.tools.pnpm}+ (https://pnpm.io), then:
|
|
66
|
+
cd ${dir} && bun install
|
|
67
|
+
To use pnpm instead, recreate the project with --package-manager pnpm.`;
|
|
68
|
+
else if (decision.kind === "use" && !decision.installed.includes(decision.manager)) managerNotice = `! ${managerLabel(decision.manager)} was selected but is not installed — the
|
|
69
|
+
${decision.manager} project was scaffolded without installing dependencies.
|
|
70
|
+
Install ${managerLabel(decision.manager)} ${compatibility.tools[decision.manager]}+, then run the
|
|
71
|
+
package manager's install command inside ${dir}.`;
|
|
72
|
+
/** The manager `select`, joining the caller's clack session. */
|
|
73
|
+
async function promptForManager(p) {
|
|
74
|
+
const picked = await p.select({
|
|
75
|
+
message: "Package manager",
|
|
76
|
+
options: [{
|
|
77
|
+
value: "bun",
|
|
78
|
+
label: "Bun"
|
|
79
|
+
}, {
|
|
80
|
+
value: "pnpm",
|
|
81
|
+
label: "pnpm"
|
|
82
|
+
}],
|
|
83
|
+
initialValue: "bun"
|
|
84
|
+
});
|
|
85
|
+
if (p.isCancel(picked)) {
|
|
86
|
+
p.cancel("Cancelled");
|
|
87
|
+
process.exit(0);
|
|
88
|
+
}
|
|
89
|
+
packageManager = picked;
|
|
90
|
+
}
|
|
60
91
|
var ids = [];
|
|
61
92
|
if (templateArg === "library") {
|
|
62
|
-
const packageName =
|
|
93
|
+
const packageName = values.name ?? basename(dir);
|
|
94
|
+
if (decision.kind === "prompt") {
|
|
95
|
+
const p = await import("@clack/prompts");
|
|
96
|
+
p.intro("create-octane-xplat");
|
|
97
|
+
await promptForManager(p);
|
|
98
|
+
}
|
|
63
99
|
try {
|
|
64
|
-
composeLibrary(dir, packageName);
|
|
100
|
+
composeLibrary(dir, packageName, { packageManager });
|
|
65
101
|
} catch (error) {
|
|
66
102
|
console.error(`✗ ${error.message}`);
|
|
67
103
|
process.exit(1);
|
|
68
104
|
}
|
|
69
|
-
console.log(`\n✓ scaffolded ${dir} (library: ${packageName}; web + iOS + Android)`);
|
|
105
|
+
console.log(`\n✓ scaffolded ${dir} (library: ${packageName}; web + iOS + Android; ${packageManager})`);
|
|
70
106
|
} else {
|
|
71
|
-
if (
|
|
72
|
-
ids = parseTargets(
|
|
107
|
+
if (values.targets !== void 0) try {
|
|
108
|
+
ids = parseTargets(values.targets);
|
|
73
109
|
} catch (error) {
|
|
74
110
|
console.error(`✗ ${error.message}`);
|
|
75
111
|
process.exit(1);
|
|
@@ -92,43 +128,70 @@ if (templateArg === "library") {
|
|
|
92
128
|
process.exit(0);
|
|
93
129
|
}
|
|
94
130
|
ids = picked;
|
|
131
|
+
if (decision.kind === "prompt") await promptForManager(p);
|
|
95
132
|
} else ids = defaultTargets;
|
|
96
|
-
|
|
97
|
-
|
|
133
|
+
if (decision.kind === "prompt" && values.targets !== void 0) {
|
|
134
|
+
const p = await import("@clack/prompts");
|
|
135
|
+
p.intro("create-octane-xplat");
|
|
136
|
+
await promptForManager(p);
|
|
137
|
+
}
|
|
138
|
+
composeTargets(ids, dir, { packageManager });
|
|
139
|
+
console.log(`\n✓ scaffolded ${dir} (${[...new Set(resolveTargets(ids))].filter((id) => !targets[id].hidden).join(", ")}; ${packageManager})`);
|
|
140
|
+
}
|
|
141
|
+
if (managerNotice) {
|
|
142
|
+
console.log(`\n${managerNotice}`);
|
|
143
|
+
if (decision.kind === "use") printNextSteps(dir, ids, templateArg, packageManager);
|
|
144
|
+
process.exit(0);
|
|
98
145
|
}
|
|
99
146
|
if (noInstall) {
|
|
100
147
|
console.log("\nSkipped install (--no-install). To run manually:");
|
|
101
|
-
printNextSteps(dir, ids, templateArg);
|
|
148
|
+
printNextSteps(dir, ids, templateArg, packageManager);
|
|
102
149
|
process.exit(0);
|
|
103
150
|
}
|
|
104
|
-
var
|
|
151
|
+
var managerFloor = compatibility.tools[packageManager];
|
|
152
|
+
var managerInstalled = managerVersion(packageManager);
|
|
153
|
+
if (managerInstalled !== void 0 && versionBelow(managerInstalled, managerFloor)) console.log(`! ${managerLabel(packageManager)} ${managerInstalled} is below the supported ${managerFloor}+ — install may fail`);
|
|
154
|
+
var install = spawnSync(packageManager, ["install"], {
|
|
105
155
|
cwd: dir,
|
|
106
156
|
stdio: "inherit",
|
|
107
157
|
shell: process.platform === "win32"
|
|
108
158
|
});
|
|
109
159
|
if (install.status !== 0) {
|
|
110
|
-
console.log(`\nInstall didn't finish (
|
|
111
|
-
printNextSteps(dir, ids, templateArg);
|
|
160
|
+
console.log(`\nInstall didn't finish (${managerLabel(packageManager)} missing?). To run manually:`);
|
|
161
|
+
printNextSteps(dir, ids, templateArg, packageManager);
|
|
112
162
|
process.exit(install.status ?? 1);
|
|
113
163
|
}
|
|
114
164
|
if (templateArg === "app" && ids.includes("web")) {
|
|
115
165
|
console.log("\n✓ installed — starting dev server (Ctrl+C to stop)\n");
|
|
116
|
-
spawnSync("
|
|
166
|
+
spawnSync(packageManager, ["run", "dev"], {
|
|
117
167
|
cwd: dir,
|
|
118
168
|
stdio: "inherit",
|
|
119
169
|
shell: process.platform === "win32"
|
|
120
170
|
});
|
|
121
171
|
} else {
|
|
122
172
|
console.log("\n✓ installed. Next steps:");
|
|
123
|
-
printNextSteps(dir, ids, templateArg);
|
|
173
|
+
printNextSteps(dir, ids, templateArg, packageManager);
|
|
174
|
+
}
|
|
175
|
+
function managerLabel(manager) {
|
|
176
|
+
return manager === "bun" ? "Bun" : "pnpm";
|
|
177
|
+
}
|
|
178
|
+
function versionBelow(version, floor) {
|
|
179
|
+
const parts = (value) => value.split(".").map((n) => Number.parseInt(n, 10) || 0);
|
|
180
|
+
const got = parts(version);
|
|
181
|
+
const min = parts(floor);
|
|
182
|
+
for (let i = 0; i < Math.max(got.length, min.length); i++) {
|
|
183
|
+
const a = got[i] ?? 0;
|
|
184
|
+
const b = min[i] ?? 0;
|
|
185
|
+
if (a !== b) return a < b;
|
|
186
|
+
}
|
|
187
|
+
return false;
|
|
124
188
|
}
|
|
125
|
-
function printNextSteps(dir, ids, template) {
|
|
126
|
-
console.log(` cd ${dir}\n
|
|
189
|
+
function printNextSteps(dir, ids, template, pm) {
|
|
190
|
+
console.log(` cd ${dir}\n ${pm} install`);
|
|
127
191
|
if (template === "library") {
|
|
128
|
-
console.log(
|
|
192
|
+
console.log(` ${pm} run typecheck\n ${pm} run lint\n ${pm} run typegen\n ${pm} run test\n ${pm} run test:packed`);
|
|
129
193
|
return;
|
|
130
194
|
}
|
|
131
|
-
if (ids.includes("web")) console.log(
|
|
132
|
-
else console.log(
|
|
195
|
+
if (ids.includes("web")) console.log(` ${pm} run dev`);
|
|
196
|
+
else console.log(` ${pm} run xplat dev`);
|
|
133
197
|
}
|
|
134
|
-
//#endregion
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
// package-manager.ts
|
|
4
|
+
var managers = ["bun", "pnpm"];
|
|
5
|
+
/** The tool that launched the creator (`bun create`, `pnpm dlx`, `npx`, …). */
|
|
6
|
+
function managerFromUserAgent(ua) {
|
|
7
|
+
const tool = ua?.split(" ")[0]?.split("/")[0];
|
|
8
|
+
return tool === "bun" || tool === "pnpm" ? tool : void 0;
|
|
9
|
+
}
|
|
10
|
+
/** The manager's version, or undefined when it is not runnable on PATH. */
|
|
11
|
+
function managerVersion(manager) {
|
|
12
|
+
const result = spawnSync(manager, ["--version"], {
|
|
13
|
+
encoding: "utf8",
|
|
14
|
+
cwd: tmpdir(),
|
|
15
|
+
shell: process.platform === "win32"
|
|
16
|
+
});
|
|
17
|
+
if (result.error || result.status !== 0) return;
|
|
18
|
+
return result.stdout.trim();
|
|
19
|
+
}
|
|
20
|
+
/** Managers runnable on this machine, in fixed order. */
|
|
21
|
+
function installedManagers() {
|
|
22
|
+
return managers.filter((manager) => managerVersion(manager) !== void 0);
|
|
23
|
+
}
|
|
24
|
+
function decidePackageManager(input) {
|
|
25
|
+
if (input.flag !== void 0) {
|
|
26
|
+
if (input.flag !== "bun" && input.flag !== "pnpm") throw new Error("--package-manager must be bun or pnpm");
|
|
27
|
+
return {
|
|
28
|
+
kind: "use",
|
|
29
|
+
manager: input.flag,
|
|
30
|
+
source: "flag",
|
|
31
|
+
installed: input.installed
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
const fromAgent = managerFromUserAgent(input.userAgent);
|
|
35
|
+
if (fromAgent) return {
|
|
36
|
+
kind: "use",
|
|
37
|
+
manager: fromAgent,
|
|
38
|
+
source: "user-agent",
|
|
39
|
+
installed: input.installed
|
|
40
|
+
};
|
|
41
|
+
if (input.installed.length === 0) return {
|
|
42
|
+
kind: "missing",
|
|
43
|
+
manager: "bun"
|
|
44
|
+
};
|
|
45
|
+
if (input.installed.length === 1) return {
|
|
46
|
+
kind: "use",
|
|
47
|
+
manager: input.installed[0],
|
|
48
|
+
source: "only-installed",
|
|
49
|
+
installed: input.installed
|
|
50
|
+
};
|
|
51
|
+
if (input.interactive) return {
|
|
52
|
+
kind: "prompt",
|
|
53
|
+
options: [...managers]
|
|
54
|
+
};
|
|
55
|
+
return {
|
|
56
|
+
kind: "use",
|
|
57
|
+
manager: "bun",
|
|
58
|
+
source: "fallback",
|
|
59
|
+
installed: input.installed
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export { decidePackageManager, installedManagers, managerFromUserAgent, managerVersion };
|