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
|
@@ -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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
+
})
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/** Props for the starter badge component. */
|
|
2
2
|
export interface BadgeProps {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
if (result.stdout) {
|
|
26
|
+
process.stdout.write(result.stdout)
|
|
27
|
+
}
|
|
31
28
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
if (result.stderr) {
|
|
30
|
+
process.stderr.write(result.stderr)
|
|
31
|
+
}
|
|
35
32
|
|
|
36
|
-
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
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
|
-
|
|
172
|
+
rmSync(temporary, { recursive: true, force: true })
|
|
156
173
|
}
|
|
@@ -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
|
}
|
|
@@ -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
|
+
}
|