@getcortexlabs/create-mavis 0.1.0-alpha.8 → 0.1.0-rc.11.1

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 (36) hide show
  1. package/README.md +31 -6
  2. package/package.json +7 -2
  3. package/src/add-target.mjs +378 -0
  4. package/src/cli.mjs +231 -107
  5. package/src/doctor.mjs +9 -0
  6. package/src/package-manager.mjs +105 -0
  7. package/src/portability.mjs +460 -0
  8. package/src/presets.mjs +25 -7
  9. package/src/reference.mjs +45 -0
  10. package/src/scaffold.mjs +124 -32
  11. package/src/shared-api.mjs +57 -0
  12. package/src/ui.mjs +276 -0
  13. package/templates/directory/mobile/src/App.vue +4 -0
  14. package/templates/directory/mobile/src/app.ts +32 -0
  15. package/templates/directory/nuxt/app/app.vue +1 -0
  16. package/templates/directory/nuxt/app/pages/entries/[id]/edit.vue +5 -0
  17. package/templates/directory/nuxt/app/pages/entries/[id]/index.vue +5 -0
  18. package/templates/directory/nuxt/app/pages/index.vue +4 -0
  19. package/templates/directory/nuxt/app/plugins/mavis.ts +34 -0
  20. package/templates/directory/shared/Details.vue +26 -0
  21. package/templates/directory/shared/Directory.vue +51 -0
  22. package/templates/directory/shared/Edit.vue +99 -0
  23. package/templates/directory/shared/directory-store.ts +82 -0
  24. package/templates/directory/shared/routes.ts +9 -0
  25. package/templates/directory/vite/src/App.vue +4 -0
  26. package/templates/directory/vite/src/main.ts +34 -0
  27. package/templates/mobile/src/App.vue +1 -3
  28. package/templates/mobile/src/mavis.ts +84 -0
  29. package/templates/mobile/tsconfig.json +9 -2
  30. package/templates/mobile/webpack.config.js +2 -0
  31. package/templates/nuxt/app/mavis.ts +84 -0
  32. package/templates/nuxt/nuxt.config.ts +5 -0
  33. package/templates/shared/Welcome.vue +114 -32
  34. package/templates/vite/src/mavis.ts +84 -0
  35. package/templates/vite/tsconfig.json +5 -1
  36. package/templates/vite/vite.config.ts +8 -1
package/src/cli.mjs CHANGED
@@ -1,165 +1,289 @@
1
1
  #!/usr/bin/env node
2
2
  import { parseArgs } from 'node:util'
3
- import { createInterface } from 'node:readline/promises'
3
+ import { join } from 'node:path'
4
+ import { confirm, isCancel } from '@clack/prompts'
5
+ import { readFile } from 'node:fs/promises'
4
6
  import { scaffold, installProject } from './scaffold.mjs'
7
+ import { planTarget, applyTarget } from './add-target.mjs'
8
+ import { checkPortability } from './portability.mjs'
5
9
  import { doctor } from './doctor.mjs'
10
+ import {
11
+ checkPackageManager,
12
+ detectPackageManager,
13
+ packageCommands,
14
+ runInstall,
15
+ } from './package-manager.mjs'
16
+ import { resolvePreset } from './presets.mjs'
17
+ import { nextSteps, projectSummary, sharedEntry, terminalUI, wizard } from './ui.mjs'
6
18
 
19
+ const { version } = JSON.parse(await readFile(new URL('../package.json', import.meta.url), 'utf8'))
7
20
  const help = `Create Mavis — Vue Web, Nuxt and NativeScript
8
21
 
9
- create-mavis [name] [options]
10
- create-mavis my-app --target both --web nuxt --rendering ssr --no-install
22
+ npm create @getcortexlabs/mavis@latest
23
+ create-mavis my-app --target both --web nuxt --package-manager pnpm --no-install
11
24
 
12
25
  --target mobile|web|both Default: web
26
+ --add-native Add apps/mobile to an existing Vue/Vite or Nuxt app
27
+ --add-web Add apps/web to an existing NativeScript-Vue app
28
+ --screen path.vue Reuse an existing screen without moving it
29
+ --screen-root screen|content Existing MScreen or content to wrap (auto-detected)
13
30
  --web vite|nuxt Default: vite
14
31
  --rendering client|ssr|ssg Default: client (Vite), ssr (Nuxt)
32
+ --example welcome|directory Starter or shared search/detail/edit reference
33
+ --check-portability Audit shared sources without SDK checks
34
+ --path directory Override the configured shared source directory
35
+ --fix-imports Preview safe renderer-import replacements
36
+ --write Apply the previewed import migration
37
+ --json Machine-readable portability diagnostics
15
38
  --theme mavis|midnight Default: mavis
16
- --framework vue Other adapters are planned, not generated
17
- --authoring vue Portable JSX/React-style authoring is planned
18
- --yes Use defaults without prompts
19
- --install / --no-install npm is the supported package manager
39
+ --package-manager npm|pnpm|yarn
40
+ Default: the invoking manager, or npm
41
+ --framework vue Vue is currently supported
42
+ --authoring vue Vue templates are currently supported
43
+ --yes, -y Use defaults without prompts (skip installation)
44
+ --install / --no-install Install dependencies now or later
20
45
  --dry-run Show the complete file plan without writing
21
- --doctor Check the current generated project prerequisites
22
- --help Show this help
46
+ --doctor Check a generated project's prerequisites
47
+ --version, -v Show the creator version
48
+ --help, -h Show this help
23
49
 
24
- Interactive prompts accept "back" or "cancel". Existing directories are never overwritten.
50
+ Use arrow keys and Enter in the wizard. Choose Back to revisit an answer.
51
+ Ctrl-C or Escape cancels. Existing directories are never overwritten.
25
52
  `
26
53
 
27
- async function wizard(initial, signal) {
28
- const answers = { ...initial }
29
- const supplied = new Set(Object.keys(initial).filter((key) => initial[key] !== undefined))
30
- const io = createInterface({ input: process.stdin, output: process.stdout })
31
- const steps = [
32
- { key: 'name', question: 'Project name', fallback: 'my-mavis-app' },
33
- {
34
- key: 'target',
35
- question: 'Where will it run? 1 Web · 2 Mobile · 3 Mobile + Web',
36
- choices: ['web', 'mobile', 'both'],
37
- },
38
- {
39
- key: 'web',
40
- question: 'Web host? 1 Vue + Vite · 2 Nuxt',
41
- choices: ['vite', 'nuxt'],
42
- when: () => answers.target !== 'mobile',
43
- },
44
- {
45
- key: 'rendering',
46
- question: 'Rendering? 1 Server rendering · 2 Static generation',
47
- choices: ['ssr', 'ssg'],
48
- when: () => answers.target !== 'mobile' && answers.web === 'nuxt',
49
- },
50
- {
51
- key: 'theme',
52
- question: 'Initial theme? 1 Mavis · 2 Midnight',
53
- choices: ['mavis', 'midnight'],
54
- },
55
- {
56
- key: 'install',
57
- question: 'Install dependencies with npm? 1 No · 2 Yes',
58
- choices: [false, true],
59
- },
60
- ]
61
- console.log(
62
- 'Vue templates are available today. React-style authoring for Vue is on the roadmap.\n',
63
- )
64
- try {
65
- for (let index = 0; index < steps.length;) {
66
- const step = steps[index]
67
- if (supplied.has(step.key)) {
68
- index++
69
- continue
70
- }
71
- if (step.when && !step.when()) {
72
- delete answers[step.key]
73
- index++
74
- continue
75
- }
76
- const value = (
77
- await io.question(`${step.question} [${answers[step.key] ?? step.fallback ?? '1'}]: `, {
78
- signal,
79
- })
80
- ).trim()
81
- if (value.toLowerCase() === 'cancel') return null
82
- if (value.toLowerCase() === 'back') {
83
- do {
84
- index = Math.max(0, index - 1)
85
- } while (
86
- index > 0 &&
87
- (supplied.has(steps[index].key) || (steps[index].when && !steps[index].when()))
88
- )
89
- continue
90
- }
91
- if (step.choices) {
92
- const selection =
93
- value === '' ? (answers[step.key] ?? step.choices[0]) : step.choices[Number(value) - 1]
94
- if (selection === undefined) {
95
- console.log('Choose one of the numbered options.')
96
- continue
97
- }
98
- answers[step.key] = selection
99
- } else answers[step.key] = value || answers[step.key] || step.fallback
100
- index++
101
- }
102
- } finally {
103
- io.close()
104
- }
105
- return answers
106
- }
107
-
108
54
  const cancellation = new AbortController()
109
55
  const cancel = () => cancellation.abort()
56
+ const interactive = Boolean(
57
+ process.stdin.isTTY && process.stdout.isTTY && process.env.TERM !== 'dumb' && !process.env.CI,
58
+ )
59
+ const ui = terminalUI(interactive)
60
+ let plan
110
61
  process.once('SIGINT', cancel)
62
+ process.once('SIGTERM', cancel)
111
63
  try {
112
64
  const { values, positionals } = parseArgs({
113
65
  allowPositionals: true,
114
66
  options: {
115
67
  target: { type: 'string' },
68
+ 'add-native': { type: 'boolean' },
69
+ 'add-web': { type: 'boolean' },
70
+ screen: { type: 'string' },
71
+ 'screen-root': { type: 'string' },
116
72
  web: { type: 'string' },
117
73
  rendering: { type: 'string' },
118
74
  theme: { type: 'string' },
75
+ example: { type: 'string' },
76
+ 'check-portability': { type: 'boolean' },
77
+ path: { type: 'string' },
78
+ 'fix-imports': { type: 'boolean' },
79
+ write: { type: 'boolean' },
80
+ json: { type: 'boolean' },
119
81
  framework: { type: 'string' },
120
82
  authoring: { type: 'string' },
121
- yes: { type: 'boolean' },
83
+ 'package-manager': { type: 'string' },
84
+ yes: { type: 'boolean', short: 'y' },
122
85
  install: { type: 'boolean' },
123
86
  'no-install': { type: 'boolean' },
124
87
  'dry-run': { type: 'boolean' },
125
88
  doctor: { type: 'boolean' },
89
+ version: { type: 'boolean', short: 'v' },
126
90
  help: { type: 'boolean', short: 'h' },
127
91
  },
128
92
  })
129
93
  if (values.help) console.log(help)
130
- else if (values.doctor) {
94
+ else if (values.version) console.log(version)
95
+ else if (values['add-native'] || values['add-web']) {
96
+ const [major, minor] = process.versions.node.split('.').map(Number)
97
+ if (major < 22 || (major === 22 && minor < 16))
98
+ throw new Error(`Mavis needs Node.js 22.16 or newer. You are using ${process.version}.`)
99
+ if (values['add-native'] && values['add-web']) throw new Error('Add one target at a time.')
100
+ if (
101
+ positionals.length ||
102
+ values.target ||
103
+ values['check-portability'] ||
104
+ values['fix-imports'] ||
105
+ values.write ||
106
+ values.path ||
107
+ values.doctor ||
108
+ values.example ||
109
+ values.theme ||
110
+ values.framework ||
111
+ values.authoring
112
+ )
113
+ throw new Error(
114
+ 'Run --add-native or --add-web inside the existing host package, without create/audit options.',
115
+ )
116
+ if (values['add-native'] && (values.web || values.rendering))
117
+ throw new Error('--web and --rendering belong to --add-web.')
118
+ if (values.install && values['no-install'])
119
+ throw new Error('Choose either --install or --no-install.')
120
+ if (values['screen-root'] && !values.screen) throw new Error('--screen-root requires --screen.')
121
+ const target = await planTarget({
122
+ target: values['add-native'] ? 'mobile' : 'web',
123
+ web: values.web,
124
+ rendering: values.rendering,
125
+ screen: values.screen,
126
+ screenRoot: values['screen-root'],
127
+ packageManager: values['package-manager'],
128
+ })
129
+ const summary = {
130
+ host: target.host,
131
+ directory: target.destination,
132
+ manager: target.manager,
133
+ screen: target.screen,
134
+ alreadyAdded: target.alreadyAdded,
135
+ create: [...target.files.keys()].map((file) => `${target.destination}/${file}`),
136
+ packageScripts: target.scripts,
137
+ diagnostics: target.diagnostics,
138
+ }
139
+ if (values.json) console.log(JSON.stringify(summary, null, 2))
140
+ else {
141
+ ui.message(
142
+ `${target.alreadyAdded ? 'Already configured' : 'Plan'}: ${target.host} in ${target.destination} (${target.manager})`,
143
+ )
144
+ for (const file of summary.create) console.log(` + ${file}`)
145
+ if (!target.alreadyAdded)
146
+ console.log(` package.json: add scripts ${Object.keys(target.scripts).join(', ')}`)
147
+ for (const item of target.diagnostics)
148
+ console.log(`${item.file}:${item.line}:${item.column} [${item.code}] ${item.message}`)
149
+ }
150
+ if (!values['dry-run'] && !target.alreadyAdded) {
151
+ if (values.install) {
152
+ const manager = checkPackageManager(target.manager)
153
+ if (!manager.ok)
154
+ throw new Error(`${manager.detail}\nUse --no-install to add the host and install later.`)
155
+ }
156
+ const accepted =
157
+ interactive && !values.yes
158
+ ? await confirm({
159
+ message: 'Add this host and the listed package scripts?',
160
+ signal: cancellation.signal,
161
+ })
162
+ : true
163
+ if (isCancel(accepted) || !accepted) process.exitCode = 130
164
+ else {
165
+ await applyTarget(target, { signal: cancellation.signal })
166
+ if (values.install)
167
+ await runInstall(
168
+ target.manager,
169
+ join(target.root, target.destination),
170
+ cancellation.signal,
171
+ )
172
+ if (!values.json) {
173
+ const commands = packageCommands(target.manager)
174
+ ui.success(`Added ${target.destination}. Existing sources and lockfiles were preserved.`)
175
+ ui.note(
176
+ [
177
+ ...(values.install
178
+ ? []
179
+ : [commands.run(target.host === 'mobile' ? 'install:mobile' : 'install:web')]),
180
+ commands.run(target.host === 'mobile' ? 'ios' : 'dev:web'),
181
+ ...(target.host === 'mobile' ? [commands.run('android')] : []),
182
+ `Read ${target.destination}/README.md${target.diagnostics.length ? ' and resolve the portability findings before using the selected screen.' : '.'}`,
183
+ ].join('\n'),
184
+ 'Next steps',
185
+ )
186
+ }
187
+ }
188
+ }
189
+ } else if (values['check-portability'] || values['fix-imports']) {
190
+ if (values.write && !values['fix-imports']) throw new Error('--write requires --fix-imports.')
191
+ const result = await checkPortability(process.cwd(), {
192
+ path: values.path,
193
+ fixImports: values['fix-imports'],
194
+ write: values.write,
195
+ })
196
+ if (values.json) console.log(JSON.stringify(result, null, 2))
197
+ else {
198
+ for (const item of result.diagnostics)
199
+ console.log(`${item.file}:${item.line}:${item.column} [${item.code}] ${item.message}`)
200
+ for (const fix of result.fixes)
201
+ console.log(
202
+ `${result.written ? 'Updated' : 'Would update'} ${fix.file}: renderer import → #mavis`,
203
+ )
204
+ console.log(
205
+ `${result.files.length} files checked; ${result.diagnostics.length} findings. ${values['fix-imports'] && !values.write ? 'Preview only. Use --write to apply safe import changes.' : ''}`,
206
+ )
207
+ }
208
+ if (result.diagnostics.length) process.exitCode = 1
209
+ } else if (values.doctor) {
131
210
  const results = await doctor()
132
211
  for (const item of results) console.log(`${item.ok ? '✓' : '—'} ${item.name}: ${item.detail}`)
133
212
  if (results.some((item) => !item.ok)) process.exitCode = 1
134
213
  } else {
214
+ if (values.screen || values['screen-root'])
215
+ throw new Error('--screen requires --add-native or --add-web.')
216
+ if (values.write || values.path || values.json)
217
+ throw new Error('--write, --path and --json require --check-portability or --fix-imports.')
135
218
  if (positionals.length > 1) throw new Error('Provide one project name.')
136
219
  if (values.install && values['no-install'])
137
220
  throw new Error('Choose either --install or --no-install.')
221
+ const [major, minor] = process.versions.node.split('.').map(Number)
222
+ if (major < 22 || (major === 22 && minor < 16))
223
+ throw new Error(`Mavis needs Node.js 22.16 or newer. You are using ${process.version}.`)
138
224
  let options = {
139
225
  ...values,
140
226
  name: positionals[0],
227
+ packageManager: values['package-manager'],
141
228
  install: values['no-install'] ? false : values.install,
142
229
  dryRun: Boolean(values['dry-run']),
143
230
  }
144
- if (process.stdin.isTTY && process.stdout.isTTY && !values.yes && !values['dry-run'])
145
- options = await wizard(options, cancellation.signal)
146
- if (!options) console.log('Cancelled. No files written.')
147
- else {
231
+ resolvePreset({ ...options, name: options.name ?? 'my-mavis-app' })
232
+ ui.intro(version)
233
+ const useWizard = interactive && !values.yes && !options.dryRun
234
+ if (useWizard) options = await wizard(options, cancellation.signal)
235
+ if (!options) {
236
+ ui.cancel('Cancelled. No files written.')
237
+ process.exitCode = 130
238
+ } else {
148
239
  if (!options.name)
149
240
  throw new Error('Provide a project name in non-interactive mode. Use --help for examples.')
150
- const plan = await scaffold({ ...options, signal: cancellation.signal })
151
- console.log(`${options.dryRun ? 'Planned' : 'Created'} ${plan.destination}`)
152
- for (const file of plan.files.keys()) console.log(` ${file}`)
153
- if (options.install && !options.dryRun) await installProject(plan)
154
- if (!options.dryRun)
155
- console.log(
156
- `\ncd ${plan.preset.name}\n${options.install ? '' : plan.preset.target === 'both' ? 'npm run install:apps\n' : 'npm install\n'}${plan.preset.target === 'mobile' ? 'npm run ios # or npm run android' : plan.preset.target === 'both' ? 'npm run dev:web' : 'npm run dev'}`,
157
- )
241
+ options.packageManager ??= detectPackageManager()
242
+ if (options.install && !options.dryRun && !useWizard) {
243
+ const manager = checkPackageManager(options.packageManager)
244
+ if (!manager.ok)
245
+ throw new Error(
246
+ `${manager.detail}\nUse --no-install to create the project and install later.`,
247
+ )
248
+ }
249
+ plan = await scaffold({ ...options, signal: cancellation.signal })
250
+ ui.message(`${options.dryRun ? 'Planned' : 'Created'} ${plan.destination}`)
251
+ if (options.dryRun) {
252
+ console.log(projectSummary(plan.preset, options.install))
253
+ for (const file of plan.files.keys()) console.log(` ${file}`)
254
+ } else {
255
+ if (options.install)
256
+ await installProject(plan, {
257
+ signal: cancellation.signal,
258
+ onProgress: (directory) =>
259
+ ui.message(
260
+ `Installing with ${plan.preset.packageManager}${directory === '.' ? '' : ` in ${directory}`}…`,
261
+ ),
262
+ })
263
+ ui.note(nextSteps(plan.preset, options.install), 'Next steps')
264
+ ui.message(`Make it yours: ${sharedEntry(plan.preset)}`)
265
+ if (plan.preset.target !== 'web')
266
+ ui.message(
267
+ 'Mobile needs the NativeScript CLI and platform SDKs. Check your setup with --doctor.',
268
+ )
269
+ ui.success('Your Mavis project is ready. Happy building!')
270
+ }
158
271
  }
159
272
  }
160
273
  } catch (error) {
161
- console.error(cancellation.signal.aborted ? '\nCancelled.' : `\n${error.message}`)
162
- process.exitCode = cancellation.signal.aborted ? 130 : 1
274
+ if (cancellation.signal.aborted) {
275
+ ui.cancel(
276
+ plan
277
+ ? `Cancelled. Project files are preserved in ${plan.destination}.`
278
+ : 'Cancelled. No files written.',
279
+ )
280
+ if (plan) ui.note(nextSteps(plan.preset), 'Resume when ready')
281
+ process.exitCode = 130
282
+ } else {
283
+ ui.error(error.message)
284
+ process.exitCode = 1
285
+ }
163
286
  } finally {
164
287
  process.off('SIGINT', cancel)
288
+ process.off('SIGTERM', cancel)
165
289
  }
package/src/doctor.mjs CHANGED
@@ -1,6 +1,8 @@
1
1
  import { spawnSync } from 'node:child_process'
2
2
  import { readFile } from 'node:fs/promises'
3
+ import { checkPortability } from './portability.mjs'
3
4
  import { join } from 'node:path'
5
+ import { checkPackageManager } from './package-manager.mjs'
4
6
 
5
7
  export async function doctor(cwd = process.cwd()) {
6
8
  let config
@@ -16,6 +18,7 @@ export async function doctor(cwd = process.cwd()) {
16
18
  ok: major > 22 || (major === 22 && minor >= 16),
17
19
  detail: process.version,
18
20
  },
21
+ checkPackageManager(config.packageManager ?? 'npm'),
19
22
  ]
20
23
  if (config.target !== 'web') {
21
24
  const probe = (name, command, args) => {
@@ -43,5 +46,11 @@ export async function doctor(cwd = process.cwd()) {
43
46
  detail: 'iOS builds require macOS and Xcode; Android remains available.',
44
47
  })
45
48
  }
49
+ const portability = await checkPortability(cwd)
50
+ results.push({
51
+ name: 'Shared source portability',
52
+ ok: portability.diagnostics.length === 0,
53
+ detail: `${portability.files.length} files, ${portability.diagnostics.length} findings. Run --check-portability for locations and suggestions.`,
54
+ })
46
55
  return results
47
56
  }
@@ -0,0 +1,105 @@
1
+ import { spawn, spawnSync } from 'node:child_process'
2
+
3
+ export const packageManagers = ['npm', 'pnpm', 'yarn']
4
+
5
+ export function detectPackageManager(userAgent = process.env.npm_config_user_agent ?? '') {
6
+ const name = userAgent.split('/')[0]
7
+ return packageManagers.includes(name) ? name : 'npm'
8
+ }
9
+
10
+ export function packageCommands(manager = 'npm') {
11
+ if (!packageManagers.includes(manager))
12
+ throw new Error('Package manager must be npm, pnpm or yarn.')
13
+ const directoryFlag = { npm: '--prefix', pnpm: '--dir', yarn: '--cwd' }[manager]
14
+ return {
15
+ creator:
16
+ manager === 'npm'
17
+ ? 'npx @getcortexlabs/create-mavis'
18
+ : `${manager} create @getcortexlabs/mavis`,
19
+ install: `${manager} install`,
20
+ setup: (shared) =>
21
+ !shared
22
+ ? `${manager} install`
23
+ : manager === 'yarn'
24
+ ? 'yarn install\nyarn --cwd apps/mobile install'
25
+ : `${manager} run install:apps`,
26
+ run: (script, directory) =>
27
+ `${manager}${directory ? ` ${directoryFlag} ${directory}` : ''} run ${script}`,
28
+ installAt: (directory) => `${manager} ${directoryFlag} ${directory} install`,
29
+ lockfile: { npm: 'package-lock.json', pnpm: 'pnpm-lock.yaml', yarn: 'yarn.lock' }[manager],
30
+ }
31
+ }
32
+
33
+ export function checkPackageManager(manager) {
34
+ packageCommands(manager)
35
+ const result = spawnSync(manager, ['--version'], {
36
+ encoding: 'utf8',
37
+ timeout: 10000,
38
+ shell: process.platform === 'win32',
39
+ env: { ...process.env, COREPACK_ENABLE_AUTO_PIN: '0' },
40
+ })
41
+ if (result.error?.code === 'ENOENT')
42
+ return {
43
+ name: manager,
44
+ ok: false,
45
+ detail: `${manager} was not found on this terminal's PATH. If you just changed your shell setup, restart the creator from the updated terminal.`,
46
+ }
47
+ if (result.error?.code === 'ETIMEDOUT')
48
+ return {
49
+ name: manager,
50
+ ok: false,
51
+ detail: `${manager} --version timed out after 10 seconds. Check its setup and try again.`,
52
+ }
53
+ if (result.error || result.status !== 0) {
54
+ const detail = (
55
+ result.error?.message ||
56
+ result.stderr ||
57
+ result.stdout ||
58
+ `Exit ${result.status}`
59
+ )
60
+ .trim()
61
+ .split('\n')[0]
62
+ return { name: manager, ok: false, detail: `Could not run ${manager} --version: ${detail}` }
63
+ }
64
+ const version = result.stdout.trim().split('\n').at(-1)
65
+ if (!/^\d+\.\d+\.\d+(?:-[\w.-]+)?(?:\+[\w.-]+)?$/.test(version))
66
+ return {
67
+ name: manager,
68
+ ok: false,
69
+ detail: `${manager} --version did not return a valid version.`,
70
+ }
71
+ const [major, minor] = version.split('.').map(Number)
72
+ const supported = manager !== 'pnpm' || major > 10 || (major === 10 && minor >= 26)
73
+ return {
74
+ name: manager,
75
+ ok: supported,
76
+ detail: supported ? version : `pnpm 10.26+ is required (found ${version}).`,
77
+ }
78
+ }
79
+
80
+ export async function runInstall(manager, cwd, signal) {
81
+ packageCommands(manager)
82
+ signal?.throwIfAborted()
83
+ await new Promise((resolve, reject) => {
84
+ const child = spawn(manager, ['install'], {
85
+ cwd,
86
+ stdio: 'inherit',
87
+ // Commands and arguments are fixed; cwd is never interpolated into a shell command.
88
+ shell: process.platform === 'win32',
89
+ env: { ...process.env, COREPACK_ENABLE_AUTO_PIN: '0' },
90
+ })
91
+ const abort = () => child.kill('SIGINT')
92
+ signal?.addEventListener('abort', abort, { once: true })
93
+ const cleanup = () => signal?.removeEventListener('abort', abort)
94
+ child.once('error', (error) => {
95
+ cleanup()
96
+ reject(error)
97
+ })
98
+ child.once('close', (code, stopped) => {
99
+ cleanup()
100
+ if (signal?.aborted) reject(signal.reason)
101
+ else if (code === 0) resolve()
102
+ else reject(new Error(`${manager} install stopped (${stopped ?? code}).`))
103
+ })
104
+ })
105
+ }