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.
Files changed (77) hide show
  1. package/README.md +2 -144
  2. package/compatibility.json +97 -19
  3. package/compatibility.ts +141 -72
  4. package/dist/compatibility.js +66 -26
  5. package/dist/index.js +127 -64
  6. package/dist/package-manager.js +62 -0
  7. package/dist/scaffold.js +377 -127
  8. package/index.ts +256 -154
  9. package/library-template/AGENTS.md +6 -4
  10. package/library-template/README.md +22 -18
  11. package/library-template/bunfig +4 -0
  12. package/library-template/package.json +115 -18
  13. package/library-template/patches/@nativescript-community__octane@0.2.5.patch +1018 -0
  14. package/library-template/patches/@nativescript-community__sqlite-bridge@4.1.1.patch +30 -0
  15. package/library-template/patches/@nativescript-community__vite-octane@0.2.1.patch +72 -0
  16. package/library-template/patches/@nativescript__core@9.1.3.patch +1280 -0
  17. package/library-template/patches/@nativescript__doctor@2.0.18.patch +13 -0
  18. package/library-template/patches/@nativescript__vite@8.0.20.patch +2019 -0
  19. package/library-template/patches/@octane-xplat__nativescript-mason-core@1.0.0-beta.7.patch +65 -0
  20. package/library-template/patches/@octanejs__tiptap@0.0.62.patch +12 -0
  21. package/library-template/patches/@sveltejs__acorn-typescript@1.0.13.patch +16 -0
  22. package/library-template/patches/css@3.0.0.patch +52 -0
  23. package/library-template/patches/octane@0.16.3.patch +1479 -0
  24. package/library-template/src/Badge.tsx +7 -6
  25. package/library-template/src/Badge.web.tsx +7 -6
  26. package/library-template/src/Welcome.stories.tsx +12 -0
  27. package/library-template/src/normalizeBadgeLabel.ts +1 -1
  28. package/library-template/src/props.ts +11 -11
  29. package/library-template/tests/normalizeBadgeLabel.test.ts +1 -1
  30. package/library-template/tests/packed-consumer.mjs +140 -123
  31. package/library-template/tsconfig.envs.json +1 -0
  32. package/library-template/tsconfig.json +1 -0
  33. package/library-template/tsconfig.types.json +15 -1
  34. package/library-template/tsrx-typegen.json +1 -1
  35. package/library-template/workshop.config.ts +3 -0
  36. package/package-manager.ts +93 -0
  37. package/package.json +70 -58
  38. package/scaffold.ts +1056 -526
  39. package/template/.agents/skills/xplat/SKILL.md +6 -6
  40. package/template/.agents/skills/xplat/references/components.md +1 -1
  41. package/template/.agents/skills/xplat/references/navigation.md +1 -1
  42. package/template/.agents/skills/xplat/references/styling.md +14 -14
  43. package/template/AGENTS.md +10 -10
  44. package/template/bunfig +4 -0
  45. package/template/gitignore +1 -0
  46. package/template/nativescript.config.ts +13 -16
  47. package/template/package.json +119 -10
  48. package/template/patches/@nativescript-community__octane@0.2.5.patch +1018 -0
  49. package/template/patches/@nativescript-community__sqlite-bridge@4.1.1.patch +30 -0
  50. package/template/patches/@nativescript-community__vite-octane@0.2.1.patch +72 -0
  51. package/template/patches/@nativescript__core@9.1.3.patch +1280 -0
  52. package/template/patches/@nativescript__doctor@2.0.18.patch +13 -0
  53. package/template/patches/@nativescript__vite@8.0.20.patch +2019 -0
  54. package/template/patches/@octane-xplat__nativescript-mason-core@1.0.0-beta.7.patch +65 -0
  55. package/template/patches/@octanejs__tiptap@0.0.62.patch +12 -0
  56. package/template/patches/@sveltejs__acorn-typescript@1.0.13.patch +16 -0
  57. package/template/patches/css@3.0.0.patch +52 -0
  58. package/template/patches/octane@0.16.3.patch +1479 -0
  59. package/template/src/App.tsrx +77 -42
  60. package/template/src/Welcome.stories.tsx +22 -0
  61. package/template/src/app.spec.tsrx +169 -163
  62. package/template/src/app.web.test.tsx +18 -13
  63. package/template/src/failure-reporting.spec.ts +3 -3
  64. package/template/src/main.ts +14 -13
  65. package/template/src/main.tsrx +2 -0
  66. package/template/src/main.web.tsrx +5 -5
  67. package/template/src/native-runtime.spec.ts +13 -11
  68. package/template/src/test-setup.web.ts +9 -8
  69. package/template/src/test.ts +6 -6
  70. package/template/tsconfig.json +17 -1
  71. package/template/vite.config.native.mts +1 -2
  72. package/template/vite.config.ts +29 -23
  73. package/template/vitest.config.mts +18 -18
  74. package/template/vitest.web.config.mts +7 -7
  75. package/template/workshop.config.ts +3 -0
  76. package/library-template/pnpm-workspace.yaml +0 -171
  77. package/template/pnpm-workspace.yaml +0 -192
@@ -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 { parseDocument } from "yaml";
4
+ import { parse } from "yaml";
5
5
  import { createRequire } from "node:module";
6
- //#region compatibility.ts
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 pnpm specifier, keeping preview URLs separate from package versions. */
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 pnpm catalog reserved for this compatibility profile. */
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
- /** Add missing pins when enabling a target in an older scaffold. Existing pins stay intact. */
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
- let at = resolve(appRoot);
46
- while (!existsSync(join(at, "pnpm-workspace.yaml")) && dirname(at) !== at) at = dirname(at);
47
- const workspace = existsSync(join(at, "pnpm-workspace.yaml")) ? at : appRoot;
48
- const path = join(workspace, "pnpm-workspace.yaml");
49
- const before = existsSync(path) ? readFileSync(path, "utf8") : "";
50
- const doc = parseDocument(before || "{}\n");
51
- if (doc.errors.length) throw new Error(`${path}: ${doc.errors[0].message}`);
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
- for (const section of dependencySections) for (const [name, spec] of Object.entries(pkg[section] ?? {})) {
54
- if (spec !== `catalog:${managedCatalog(profile)}`) continue;
55
- const key = [
56
- "catalogs",
57
- managedCatalog(profile),
58
- name
59
- ];
60
- if (!doc.hasIn(key)) doc.setIn(key, managedSpecifier(name, profile));
61
- }
62
- const after = String(doc);
63
- if (after !== before) writeFileSync(path, after);
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
- //#endregion
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
- //#region index.ts
7
- var argv = process.argv.slice(2);
8
- var noInstall = argv.includes("--no-install");
9
- var templateIndex = argv.findIndex((arg) => arg === "--template" || arg.startsWith("--template="));
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 optionValues = new Set([
35
- targetsValueIndex,
36
- templateValueIndex,
37
- nameValueIndex
38
- ].filter((index) => index !== -1));
39
- var positional = argv.filter((arg, i) => !arg.startsWith("-") && !optionValues.has(i));
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(positional[0] ?? defaultDir);
42
- if (templateArg === "library" && targetsIndex !== -1) {
43
- console.error("✗ --targets applies to the app template; libraries start with web and native builds");
44
- process.exit(1);
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 = nameArg ?? basename(dir);
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 (targetsArg !== void 0) try {
72
- ids = parseTargets(targetsArg);
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
- composeTargets(ids, dir);
97
- console.log(`\n✓ scaffolded ${dir} (${[...new Set(resolveTargets(ids))].filter((id) => !targets[id].hidden).join(", ")})`);
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 install = spawnSync("pnpm", ["install"], {
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 (pnpm missing?). To run manually:`);
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("pnpm", ["dev"], {
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 pnpm install`);
189
+ function printNextSteps(dir, ids, template, pm) {
190
+ console.log(` cd ${dir}\n ${pm} install`);
127
191
  if (template === "library") {
128
- console.log(" pnpm typecheck\n pnpm lint\n pnpm typegen\n pnpm test\n pnpm test:packed");
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(" pnpm dev");
132
- else console.log(" pnpm xplat dev");
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 };