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,6 +1,7 @@
1
1
  /** @jsxImportSource @octane-xplat/jsx */
2
2
  import { Text, View } from '@octane-xplat/ui'
3
3
  import { normalizeBadgeLabel } from './normalizeBadgeLabel'
4
+ import type { JSX } from '@octane-xplat/jsx/jsx-runtime'
4
5
  import type { BadgeProps } from './props'
5
6
 
6
7
  /**
@@ -12,10 +13,10 @@ import type { BadgeProps } from './props'
12
13
  * <Badge label="Ready" />
13
14
  * ```
14
15
  */
15
- export function Badge(props: BadgeProps) {
16
- return (
17
- <View className={props.className}>
18
- <Text>{normalizeBadgeLabel(props.label)}</Text>
19
- </View>
20
- )
16
+ export function Badge(props: BadgeProps): JSX.Element {
17
+ return (
18
+ <View className={props.className}>
19
+ <Text>{normalizeBadgeLabel(props.label)}</Text>
20
+ </View>
21
+ )
21
22
  }
@@ -1,6 +1,7 @@
1
1
  /** @jsxImportSource @octane-xplat/jsx/dom */
2
2
  import { Text, View } from '@octane-xplat/ui'
3
3
  import { normalizeBadgeLabel } from './normalizeBadgeLabel'
4
+ import type { JSX } from '@octane-xplat/jsx/dom/jsx-runtime'
4
5
  import type { BadgeProps } from './props'
5
6
 
6
7
  /**
@@ -12,10 +13,10 @@ import type { BadgeProps } from './props'
12
13
  * <Badge label="Ready" />
13
14
  * ```
14
15
  */
15
- export function Badge(props: BadgeProps) {
16
- return (
17
- <View className={props.className}>
18
- <Text>{normalizeBadgeLabel(props.label)}</Text>
19
- </View>
20
- )
16
+ export function Badge(props: BadgeProps): JSX.Element {
17
+ return (
18
+ <View className={props.className}>
19
+ <Text>{normalizeBadgeLabel(props.label)}</Text>
20
+ </View>
21
+ )
21
22
  }
@@ -0,0 +1,12 @@
1
+ import { defineStory } from '@octane-xplat/workshop'
2
+ import { Badge } from './Badge'
3
+
4
+ export const Basic = defineStory({
5
+ id: 'badge/basic',
6
+ title: 'Badge / Basic',
7
+ componentId: 'library/Badge',
8
+ targets: ['web', 'ios', 'android'],
9
+ component: Badge,
10
+ args: { label: 'Ready' },
11
+ controls: { label: { type: 'string' } },
12
+ })
@@ -8,5 +8,5 @@
8
8
  * ```
9
9
  */
10
10
  export function normalizeBadgeLabel(label: string): string {
11
- return label.trim()
11
+ return label.trim()
12
12
  }
@@ -1,14 +1,14 @@
1
1
  /** Props for the starter badge component. */
2
2
  export interface BadgeProps {
3
- /** Text displayed inside the badge.
4
- * @example
5
- * ```tsx
6
- * import { Badge } from 'octane-xplat-library'
7
- *
8
- * <Badge label="Ready" />
9
- * ```
10
- */
11
- label: string
12
- /** Optional class name forwarded to the outer view. */
13
- className?: string
3
+ /** Text displayed inside the badge.
4
+ * @example
5
+ * ```tsx
6
+ * import { Badge } from 'octane-xplat-library'
7
+ *
8
+ * <Badge label="Ready" />
9
+ * ```
10
+ */
11
+ label: string
12
+ /** Optional class name forwarded to the outer view. */
13
+ className?: string
14
14
  }
@@ -2,5 +2,5 @@ import { expect, it } from 'vitest'
2
2
  import { normalizeBadgeLabel } from '../src/normalizeBadgeLabel'
3
3
 
4
4
  it('trims surrounding whitespace from a badge label', () => {
5
- expect(normalizeBadgeLabel(' Ready ')).toBe('Ready')
5
+ expect(normalizeBadgeLabel(' Ready ')).toBe('Ready')
6
6
  })
@@ -1,14 +1,14 @@
1
1
  import assert from 'node:assert/strict'
2
2
  import { spawnSync } from 'node:child_process'
3
3
  import {
4
- cpSync,
5
- mkdirSync,
6
- mkdtempSync,
7
- readdirSync,
8
- readFileSync,
9
- rmSync,
10
- symlinkSync,
11
- writeFileSync,
4
+ cpSync,
5
+ mkdirSync,
6
+ mkdtempSync,
7
+ readdirSync,
8
+ readFileSync,
9
+ rmSync,
10
+ symlinkSync,
11
+ writeFileSync,
12
12
  } from 'node:fs'
13
13
 
14
14
  import { tmpdir } from 'node:os'
@@ -20,69 +20,85 @@ const sourceManifest = JSON.parse(readFileSync(join(packageRoot, 'package.json')
20
20
  const temporary = mkdtempSync(join(tmpdir(), 'octane-library-consumer-'))
21
21
 
22
22
  function run(command, args, cwd) {
23
- const result = spawnSync(command, args, { cwd, encoding: 'utf8', maxBuffer: 16 * 1024 * 1024 })
24
- if (result.stdout) {
25
- process.stdout.write(result.stdout)
26
- }
23
+ const result = spawnSync(command, args, { cwd, encoding: 'utf8', maxBuffer: 16 * 1024 * 1024 })
27
24
 
28
- if (result.stderr) {
29
- process.stderr.write(result.stderr)
30
- }
25
+ if (result.stdout) {
26
+ process.stdout.write(result.stdout)
27
+ }
31
28
 
32
- if (result.error) {
33
- throw result.error
34
- }
29
+ if (result.stderr) {
30
+ process.stderr.write(result.stderr)
31
+ }
35
32
 
36
- assert.equal(result.status, 0, `${command} ${args.join(' ')} failed`)
33
+ if (result.error) {
34
+ throw result.error
35
+ }
36
+
37
+ assert.equal(result.status, 0, `${command} ${args.join(' ')} failed`)
37
38
  }
38
39
 
39
40
  function installDirectory(root, name, destination) {
40
- const segments = name.split('/')
41
- const path = join(destination, 'node_modules', ...segments)
42
- mkdirSync(dirname(path), { recursive: true })
43
- cpSync(root, path, { recursive: true })
41
+ const segments = name.split('/')
42
+ const path = join(destination, 'node_modules', ...segments)
43
+
44
+ mkdirSync(dirname(path), { recursive: true })
45
+ cpSync(root, path, { recursive: true })
44
46
  }
45
47
 
46
48
  try {
47
- const pack = join(temporary, 'pack')
48
- const extracted = join(temporary, 'extracted')
49
- mkdirSync(pack)
50
- mkdirSync(extracted)
51
- run('pnpm', ['pack', '--pack-destination', pack], packageRoot)
52
- const tarball = readdirSync(pack).find((name) => name.endsWith('.tgz'))
53
- assert.ok(tarball)
54
- run('tar', ['-xzf', join(pack, tarball), '-C', extracted], temporary)
55
- const packed = join(extracted, 'package')
56
- const manifest = JSON.parse(readFileSync(join(packed, 'package.json'), 'utf8'))
57
- assert.ok(manifest.exports['.'].web.default.startsWith('./src/'))
58
- assert.ok(manifest.exports['.'].native.default.startsWith('./src/'))
59
- assert.ok(manifest.exports['.'].web.types)
60
- assert.ok(manifest.exports['.'].native.types)
61
-
62
- for (const target of ['web', 'native']) {
63
- for (const mode of ['bundler', 'nodenext']) {
64
- const consumer = join(temporary, `${target}-${mode}`)
65
- mkdirSync(consumer)
66
- mkdirSync(join(consumer, 'node_modules'), { recursive: true })
67
- installDirectory(packed, sourceManifest.name, consumer)
68
- for (const dependency of [
69
- 'octane',
70
- '@octane-xplat/jsx',
71
- '@octane-xplat/ui',
72
- ...(target === 'native'
73
- ? ['@nativescript-community/octane', '@nativescript/core', '@nativescript/types']
74
- : []),
75
- ]) {
76
- const source = join(packageRoot, 'node_modules', ...dependency.split('/'))
77
- const destination = join(consumer, 'node_modules', ...dependency.split('/'))
78
- mkdirSync(dirname(destination), { recursive: true })
79
- symlinkSync(source, destination, 'dir')
80
- }
81
-
82
- writeFileSync(join(consumer, 'package.json'), '{"type":"module"}')
83
- writeFileSync(
84
- join(consumer, 'consumer.tsx'),
85
- `import { Badge, type BadgeProps } from '${sourceManifest.name}'
49
+ const pack = join(temporary, 'pack')
50
+ const extracted = join(temporary, 'extracted')
51
+
52
+ mkdirSync(pack)
53
+ mkdirSync(extracted)
54
+
55
+ // Pack with the manager the scaffolded package.json declares.
56
+ const packer = (sourceManifest.packageManager ?? 'bun').split('@')[0]
57
+
58
+ if (packer === 'pnpm') {
59
+ run('pnpm', ['pack', '--pack-destination', pack], packageRoot)
60
+ } else {
61
+ run('bun', ['pm', 'pack', '--destination', pack], packageRoot)
62
+ }
63
+
64
+ const tarball = readdirSync(pack).find((name) => name.endsWith('.tgz'))
65
+
66
+ assert.ok(tarball)
67
+ run('tar', ['-xzf', join(pack, tarball), '-C', extracted], temporary)
68
+
69
+ const packed = join(extracted, 'package')
70
+ const manifest = JSON.parse(readFileSync(join(packed, 'package.json'), 'utf8'))
71
+
72
+ assert.ok(manifest.exports['.'].web.startsWith('./src/'))
73
+ assert.ok(manifest.exports['.'].native.startsWith('./src/'))
74
+ assert.ok(manifest.exports['.'].types)
75
+
76
+ for (const target of ['web', 'native']) {
77
+ for (const mode of ['bundler', 'nodenext']) {
78
+ const consumer = join(temporary, `${target}-${mode}`)
79
+
80
+ mkdirSync(consumer)
81
+ mkdirSync(join(consumer, 'node_modules'), { recursive: true })
82
+ installDirectory(packed, sourceManifest.name, consumer)
83
+ for (const dependency of [
84
+ 'octane',
85
+ '@octane-xplat/jsx',
86
+ '@octane-xplat/ui',
87
+ ...(target === 'native'
88
+ ? ['@nativescript-community/octane', '@nativescript/core', '@nativescript/types']
89
+ : []),
90
+ ]) {
91
+ const source = join(packageRoot, 'node_modules', ...dependency.split('/'))
92
+ const destination = join(consumer, 'node_modules', ...dependency.split('/'))
93
+
94
+ mkdirSync(dirname(destination), { recursive: true })
95
+ symlinkSync(source, destination, 'dir')
96
+ }
97
+
98
+ writeFileSync(join(consumer, 'package.json'), '{"type":"module"}')
99
+ writeFileSync(
100
+ join(consumer, 'consumer.tsx'),
101
+ `import { Badge, type BadgeProps } from '${sourceManifest.name}'
86
102
  const props: BadgeProps = { label: 'Ready' }
87
103
  const element = <Badge {...props} />
88
104
  // @ts-expect-error label is required
@@ -91,66 +107,67 @@ const missing = <Badge />
91
107
  const invalid = <Badge label={1} />
92
108
  void element; void missing; void invalid
93
109
  `,
94
- )
95
-
96
- writeFileSync(
97
- join(consumer, 'tsconfig.json'),
98
- JSON.stringify(
99
- {
100
- compilerOptions: {
101
- strict: true,
102
- noEmit: true,
103
- skipLibCheck: true,
104
- target: 'esnext',
105
- types: [],
106
- module: mode === 'bundler' ? 'esnext' : 'nodenext',
107
- moduleResolution: mode,
108
- jsx: 'react-jsx',
109
- jsxImportSource: target === 'native' ? '@octane-xplat/jsx' : '@octane-xplat/jsx/dom',
110
- customConditions: [target],
111
- moduleSuffixes: target === 'web' ? ['.web', ''] : ['.mobile', ''],
112
- },
113
- files: ['consumer.tsx'],
114
- },
115
- null,
116
- '\t',
117
- ),
118
- )
119
-
120
- run(
121
- process.execPath,
122
- [join(packageRoot, 'node_modules/typescript/bin/tsc'), '-p', 'tsconfig.json'],
123
- consumer,
124
- )
125
-
126
- const listed = spawnSync(
127
- process.execPath,
128
- [
129
- join(packageRoot, 'node_modules/typescript/bin/tsc'),
130
- '-p',
131
- 'tsconfig.json',
132
- '--listFilesOnly',
133
- ],
134
- { cwd: consumer, encoding: 'utf8' },
135
- )
136
-
137
- assert.equal(listed.status, 0, listed.stderr)
138
- const implementation = listed.stdout
139
- .split('\n')
140
- .filter(
141
- (file) =>
142
- file.includes(`/node_modules/${sourceManifest.name}/src/`) && !file.endsWith('.d.ts'),
143
- )
144
-
145
- assert.deepEqual(
146
- implementation,
147
- [],
148
- 'consumer types use declarations without package implementation',
149
- )
150
- }
151
- }
152
-
153
- console.log('packed consumer: web/native declarations pass Bundler and NodeNext')
110
+ )
111
+
112
+ writeFileSync(
113
+ join(consumer, 'tsconfig.json'),
114
+ JSON.stringify(
115
+ {
116
+ compilerOptions: {
117
+ strict: true,
118
+ noEmit: true,
119
+ skipLibCheck: true,
120
+ target: 'esnext',
121
+ types: [],
122
+ module: mode === 'bundler' ? 'esnext' : 'nodenext',
123
+ moduleResolution: mode,
124
+ jsx: 'react-jsx',
125
+ jsxImportSource: target === 'native' ? '@octane-xplat/jsx' : '@octane-xplat/jsx/dom',
126
+ customConditions: [target],
127
+ moduleSuffixes: target === 'web' ? ['.web', ''] : ['.mobile', ''],
128
+ },
129
+ files: ['consumer.tsx'],
130
+ },
131
+ null,
132
+ '\t',
133
+ ),
134
+ )
135
+
136
+ run(
137
+ process.execPath,
138
+ [join(packageRoot, 'node_modules/typescript/bin/tsc'), '-p', 'tsconfig.json'],
139
+ consumer,
140
+ )
141
+
142
+ const listed = spawnSync(
143
+ process.execPath,
144
+ [
145
+ join(packageRoot, 'node_modules/typescript/bin/tsc'),
146
+ '-p',
147
+ 'tsconfig.json',
148
+ '--listFilesOnly',
149
+ ],
150
+ { cwd: consumer, encoding: 'utf8' },
151
+ )
152
+
153
+ assert.equal(listed.status, 0, listed.stderr)
154
+
155
+ const implementation = listed.stdout
156
+ .split('\n')
157
+ .filter(
158
+ (file) =>
159
+ file.includes(`/node_modules/${sourceManifest.name}/src/`) && !file.endsWith('.d.ts'),
160
+ )
161
+
162
+ assert.deepEqual(
163
+ implementation,
164
+ [],
165
+ 'consumer types use declarations without package implementation',
166
+ )
167
+ }
168
+ }
169
+
170
+ console.log('packed consumer: web/native declarations pass Bundler and NodeNext')
154
171
  } finally {
155
- rmSync(temporary, { recursive: true, force: true })
172
+ rmSync(temporary, { recursive: true, force: true })
156
173
  }
@@ -1,4 +1,5 @@
1
1
  {
2
+ "contentMappers": [{ "package": "@octane-xplat/cli", "extensions": [".tsrx"] }],
2
3
  "extends": "./tsconfig.json",
3
4
  "compilerOptions": {
4
5
  "jsxImportSource": "@octane-xplat/jsx"
@@ -1,4 +1,5 @@
1
1
  {
2
+ "contentMappers": [{ "package": "@octane-xplat/cli", "extensions": [".tsrx"] }],
2
3
  "compilerOptions": {
3
4
  "strict": true,
4
5
  "target": "es2022",
@@ -1,4 +1,12 @@
1
1
  {
2
+ "contentMappers": [
3
+ {
4
+ "package": "@octane-xplat/cli",
5
+ "extensions": [
6
+ ".tsrx"
7
+ ]
8
+ }
9
+ ],
2
10
  "extends": "./tsconfig.json",
3
11
  "compilerOptions": {
4
12
  "declaration": true,
@@ -7,5 +15,11 @@
7
15
  "noEmitOnError": true,
8
16
  "rootDir": "src",
9
17
  "outDir": "types"
10
- }
18
+ },
19
+ "exclude": [
20
+ "src/**/*.stories.*",
21
+ "dist",
22
+ "types",
23
+ "node_modules"
24
+ ]
11
25
  }
@@ -8,7 +8,7 @@
8
8
  ".": {
9
9
  "source": "src/index.ts",
10
10
  "runtime": ["./src/index.ts", "./src/index.web.ts"],
11
- "types": ["./types/index.d.ts", "./types/index.web.d.ts"]
11
+ "types": ["./types/index.d.ts"]
12
12
  }
13
13
  }
14
14
  }
@@ -0,0 +1,3 @@
1
+ import { defineWorkshopConfig } from '@octane-xplat/workshop'
2
+
3
+ export default defineWorkshopConfig({ stories: { include: 'src/**/*.stories.{tsx,tsrx}' } })
@@ -0,0 +1,93 @@
1
+ // Package-manager selection for the creator: --package-manager > the
2
+ // invoking tool's user agent > the installed-manager probe > prompt/fallback.
3
+ // Bun is the historical default, so it wins every tie.
4
+ import { spawnSync } from 'node:child_process'
5
+ import { tmpdir } from 'node:os'
6
+
7
+ export type PackageManager = 'bun' | 'pnpm'
8
+
9
+ export type ManagerSource = 'flag' | 'user-agent' | 'only-installed' | 'prompt' | 'fallback'
10
+
11
+ export type ManagerDecision =
12
+ | {
13
+ kind: 'use'
14
+ manager: PackageManager
15
+ source: Exclude<ManagerSource, 'prompt'>
16
+ installed: PackageManager[]
17
+ }
18
+ // Both managers installed, interactive, no flag/user-agent — the caller
19
+ // joins a clack session and asks.
20
+ | { kind: 'prompt'; options: PackageManager[] }
21
+ // Neither installed — scaffold the Bun variant, skip install, warn.
22
+ | { kind: 'missing'; manager: 'bun' }
23
+
24
+ const managers: PackageManager[] = ['bun', 'pnpm']
25
+
26
+ /** The tool that launched the creator (`bun create`, `pnpm dlx`, `npx`, …). */
27
+ export function managerFromUserAgent(ua: string | undefined): PackageManager | undefined {
28
+ const tool = ua?.split(' ')[0]?.split('/')[0]
29
+
30
+ return tool === 'bun' || tool === 'pnpm' ? tool : undefined
31
+ }
32
+
33
+ /** The manager's version, or undefined when it is not runnable on PATH. */
34
+ export function managerVersion(manager: PackageManager): string | undefined {
35
+ const result = spawnSync(manager, ['--version'], {
36
+ encoding: 'utf8',
37
+ // A manager pinned by the caller's cwd package.json can refuse to run;
38
+ // probe from a neutral directory.
39
+ cwd: tmpdir(),
40
+ shell: process.platform === 'win32',
41
+ })
42
+
43
+ if (result.error || result.status !== 0) {
44
+ return undefined
45
+ }
46
+
47
+ return result.stdout.trim()
48
+ }
49
+
50
+ /** Managers runnable on this machine, in fixed order. */
51
+ export function installedManagers(): PackageManager[] {
52
+ return managers.filter((manager) => managerVersion(manager) !== undefined)
53
+ }
54
+
55
+ export function decidePackageManager(input: {
56
+ flag?: string
57
+ userAgent?: string
58
+ installed: PackageManager[]
59
+ interactive: boolean
60
+ }): ManagerDecision {
61
+ if (input.flag !== undefined) {
62
+ if (input.flag !== 'bun' && input.flag !== 'pnpm') {
63
+ throw new Error('--package-manager must be bun or pnpm')
64
+ }
65
+
66
+ return { kind: 'use', manager: input.flag, source: 'flag', installed: input.installed }
67
+ }
68
+
69
+ const fromAgent = managerFromUserAgent(input.userAgent)
70
+
71
+ if (fromAgent) {
72
+ return { kind: 'use', manager: fromAgent, source: 'user-agent', installed: input.installed }
73
+ }
74
+
75
+ if (input.installed.length === 0) {
76
+ return { kind: 'missing', manager: 'bun' }
77
+ }
78
+
79
+ if (input.installed.length === 1) {
80
+ return {
81
+ kind: 'use',
82
+ manager: input.installed[0],
83
+ source: 'only-installed',
84
+ installed: input.installed,
85
+ }
86
+ }
87
+
88
+ if (input.interactive) {
89
+ return { kind: 'prompt', options: [...managers] }
90
+ }
91
+
92
+ return { kind: 'use', manager: 'bun', source: 'fallback', installed: input.installed }
93
+ }