create-octane-xplat 0.19.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 (63) hide show
  1. package/README.md +2 -147
  2. package/compatibility.json +74 -61
  3. package/compatibility.ts +134 -79
  4. package/dist/compatibility.js +45 -13
  5. package/dist/index.js +127 -64
  6. package/dist/package-manager.js +62 -0
  7. package/dist/scaffold.js +362 -57
  8. package/index.ts +256 -156
  9. package/library-template/AGENTS.md +1 -1
  10. package/library-template/README.md +4 -3
  11. package/library-template/bunfig +4 -0
  12. package/library-template/package.json +73 -70
  13. package/library-template/patches/@nativescript-community__octane@0.2.5.patch +161 -24
  14. package/library-template/patches/@nativescript__core@9.1.3.patch +98 -0
  15. package/library-template/patches/@nativescript__vite@8.0.20.patch +532 -17
  16. package/library-template/patches/@octane-xplat__nativescript-mason-core@1.0.0-beta.7.patch +65 -0
  17. package/library-template/patches/octane@0.16.3.patch +56 -2
  18. package/library-template/src/Badge.tsx +5 -5
  19. package/library-template/src/Badge.web.tsx +5 -5
  20. package/library-template/src/Welcome.stories.tsx +12 -0
  21. package/library-template/src/normalizeBadgeLabel.ts +1 -1
  22. package/library-template/src/props.ts +11 -11
  23. package/library-template/tests/normalizeBadgeLabel.test.ts +1 -1
  24. package/library-template/tests/packed-consumer.mjs +140 -123
  25. package/library-template/tsconfig.envs.json +1 -0
  26. package/library-template/tsconfig.json +1 -0
  27. package/library-template/tsconfig.types.json +15 -1
  28. package/library-template/tsrx-typegen.json +1 -1
  29. package/library-template/workshop.config.ts +3 -0
  30. package/package-manager.ts +93 -0
  31. package/package.json +10 -5
  32. package/scaffold.ts +1061 -449
  33. package/template/.agents/skills/xplat/SKILL.md +1 -1
  34. package/template/.agents/skills/xplat/references/styling.md +10 -10
  35. package/template/AGENTS.md +2 -2
  36. package/template/bunfig +4 -0
  37. package/template/nativescript.config.ts +13 -13
  38. package/template/package.json +69 -64
  39. package/template/patches/@nativescript-community__octane@0.2.5.patch +161 -24
  40. package/template/patches/@nativescript__core@9.1.3.patch +98 -0
  41. package/template/patches/@nativescript__vite@8.0.20.patch +532 -17
  42. package/template/patches/@octane-xplat__nativescript-mason-core@1.0.0-beta.7.patch +65 -0
  43. package/template/patches/octane@0.16.3.patch +56 -2
  44. package/template/src/App.tsrx +66 -64
  45. package/template/src/Welcome.stories.tsx +22 -0
  46. package/template/src/app.spec.tsrx +168 -158
  47. package/template/src/app.web.test.tsx +18 -13
  48. package/template/src/failure-reporting.spec.ts +3 -3
  49. package/template/src/main.ts +14 -13
  50. package/template/src/main.tsrx +2 -0
  51. package/template/src/native-runtime.spec.ts +13 -11
  52. package/template/src/test-setup.web.ts +9 -8
  53. package/template/src/test.ts +6 -6
  54. package/template/tsconfig.json +17 -1
  55. package/template/vite.config.native.mts +1 -2
  56. package/template/vite.config.ts +29 -23
  57. package/template/vitest.config.mts +17 -17
  58. package/template/vitest.web.config.mts +7 -7
  59. package/template/workshop.config.ts +3 -0
  60. package/library-template/patches/@tsrx__typescript-plugin@0.4.11.patch +0 -11
  61. package/template/patches/@tsrx__typescript-plugin@0.4.11.patch +0 -11
  62. /package/library-template/patches/{@octanejs__tiptap@0.0.61.patch → @octanejs__tiptap@0.0.62.patch} +0 -0
  63. /package/template/patches/{@octanejs__tiptap@0.0.61.patch → @octanejs__tiptap@0.0.62.patch} +0 -0
package/index.ts CHANGED
@@ -2,204 +2,304 @@
2
2
  import { existsSync, readdirSync } from 'node:fs'
3
3
  import { basename, resolve } from 'node:path'
4
4
  import { spawnSync } from 'node:child_process'
5
+ import { parseArgs } from 'node:util'
5
6
  import {
6
- composeLibrary,
7
- composeTargets,
8
- defaultTargets,
9
- resolveTargets,
10
- selectableTargets,
11
- targets,
7
+ composeLibrary,
8
+ composeTargets,
9
+ defaultTargets,
10
+ resolveTargets,
11
+ selectableTargets,
12
+ targets,
12
13
  } from './scaffold.ts'
13
14
 
14
- const argv = process.argv.slice(2)
15
- const noInstall = argv.includes('--no-install')
16
- const templateIndex = argv.findIndex((arg) => arg === '--template' || arg.startsWith('--template='))
17
- const templateValueIndex =
18
- templateIndex !== -1 && argv[templateIndex] === '--template' ? templateIndex + 1 : -1
19
-
20
- const templateArg =
21
- templateIndex === -1
22
- ? 'app'
23
- : templateValueIndex !== -1
24
- ? argv[templateValueIndex]
25
- : argv[templateIndex].slice('--template='.length)
26
-
27
- const nameIndex = argv.findIndex((arg) => arg === '--name' || arg.startsWith('--name='))
28
- const nameValueIndex = nameIndex !== -1 && argv[nameIndex] === '--name' ? nameIndex + 1 : -1
29
- const nameArg =
30
- nameIndex === -1
31
- ? undefined
32
- : nameValueIndex !== -1
33
- ? argv[nameValueIndex]
34
- : argv[nameIndex].slice('--name='.length)
15
+ import { compatibility } from './compatibility.ts'
16
+ import {
17
+ decidePackageManager,
18
+ installedManagers,
19
+ managerVersion,
20
+ type PackageManager,
21
+ } from './package-manager.ts'
35
22
 
36
- if (templateIndex !== -1 && (!templateArg || templateArg.startsWith('-'))) {
37
- console.error('✗ --template needs a value: app or library')
38
- process.exit(1)
23
+ const fail = (message: string): never => {
24
+ console.error(`✗ ${message}`)
25
+ process.exit(1)
39
26
  }
40
27
 
41
- if (!['app', 'library'].includes(templateArg)) {
42
- console.error(`✗ unknown template "${templateArg}" — expected app or library`)
43
- process.exit(1)
28
+ function parseCli() {
29
+ try {
30
+ return parseArgs({
31
+ args: process.argv.slice(2),
32
+ allowPositionals: true,
33
+ options: {
34
+ template: { type: 'string', default: 'app' },
35
+ name: { type: 'string' },
36
+ targets: { type: 'string' },
37
+ 'package-manager': { type: 'string' },
38
+ 'no-install': { type: 'boolean', default: false },
39
+ },
40
+ })
41
+ } catch (error) {
42
+ return fail(error.message)
43
+ }
44
44
  }
45
45
 
46
- if (nameIndex !== -1 && (!nameArg || nameArg.startsWith('-'))) {
47
- console.error('✗ --name needs an npm package name')
48
- process.exit(1)
49
- }
46
+ const { values, positionals } = parseCli()
50
47
 
51
- const targetsIndex = argv.findIndex((arg) => arg === '--targets' || arg.startsWith('--targets='))
52
- const targetsValueIndex =
53
- targetsIndex !== -1 && argv[targetsIndex] === '--targets' ? targetsIndex + 1 : -1
48
+ const oneOf = <T extends string>(flag: string, value: string | undefined, choices: readonly T[]) =>
49
+ value === undefined || (choices as readonly string[]).includes(value)
50
+ ? (value as T | undefined)
51
+ : fail(`--${flag} must be ${choices.join(' or ')}`)
54
52
 
55
- const targetsArg =
56
- targetsIndex === -1
57
- ? undefined
58
- : targetsValueIndex !== -1
59
- ? argv[targetsValueIndex]
60
- : argv[targetsIndex].slice('--targets='.length)
53
+ const templateArg = oneOf('template', values.template, ['app', 'library'] as const)!
54
+ const managerFlag = oneOf('package-manager', values['package-manager'], ['bun', 'pnpm'] as const)
55
+ const noInstall = values['no-install']
61
56
 
62
- if (targetsIndex !== -1 && (targetsArg === undefined || targetsArg.startsWith('-'))) {
63
- console.error(`✗ --targets needs a comma list: ${selectableTargets.join(', ')}`)
64
- process.exit(1)
57
+ if (values.name === '') {
58
+ fail('--name needs an npm package name')
65
59
  }
66
60
 
67
- const optionValues = new Set(
68
- [targetsValueIndex, templateValueIndex, nameValueIndex].filter((index) => index !== -1),
69
- )
61
+ if (positionals.length > 1) {
62
+ fail(`expected one project directory, got ${positionals.join(' ')}`)
63
+ }
70
64
 
71
- const positional = argv.filter((arg, i) => !arg.startsWith('-') && !optionValues.has(i))
72
65
  const defaultDir = templateArg === 'library' ? 'octane-xplat-library' : 'octane-xplat-app'
73
- const dir = resolve(positional[0] ?? defaultDir)
74
-
75
- if (templateArg === 'library' && targetsIndex !== -1) {
76
- console.error(
77
- '✗ --targets applies to the app template; libraries start with web and native builds',
78
- )
66
+ const dir = resolve(positionals[0] ?? defaultDir)
79
67
 
80
- process.exit(1)
68
+ if (templateArg === 'library' && values.targets !== undefined) {
69
+ fail('--targets applies to the app template; libraries start with web and native builds')
81
70
  }
82
71
 
83
- if (templateArg === 'app' && nameIndex !== -1) {
84
- console.error('✗ --name applies only to the library template')
85
- process.exit(1)
72
+ if (templateArg === 'app' && values.name !== undefined) {
73
+ fail('--name applies only to the library template')
86
74
  }
87
75
 
88
76
  if (existsSync(dir) && readdirSync(dir).length > 0) {
89
- console.error(`✗ ${dir} exists and is not empty`)
90
- process.exit(1)
77
+ fail(`${dir} exists and is not empty`)
91
78
  }
92
79
 
93
80
  const parseTargets = (value) => {
94
- const ids = value
95
- .split(',')
96
- .map((s) => s.trim())
97
- .filter(Boolean)
81
+ const ids = value
82
+ .split(',')
83
+ .map((s) => s.trim())
84
+ .filter(Boolean)
98
85
 
99
- if (ids.length === 0) {
100
- throw new Error(`--targets needs a comma list: ${selectableTargets.join(', ')}`)
101
- }
86
+ if (ids.length === 0) {
87
+ throw new Error(`--targets needs a comma list: ${selectableTargets.join(', ')}`)
88
+ }
102
89
 
103
- for (const id of ids) {
104
- if (!selectableTargets.includes(id)) {
105
- throw new Error(
106
- `unknown target "${id}" — expected a comma list of: ${selectableTargets.join(', ')}`,
107
- )
108
- }
109
- }
90
+ for (const id of ids) {
91
+ if (!selectableTargets.includes(id)) {
92
+ throw new Error(
93
+ `unknown target "${id}" — expected a comma list of: ${selectableTargets.join(', ')}`,
94
+ )
95
+ }
96
+ }
110
97
 
111
- return resolveTargets(ids)
98
+ return resolveTargets(ids)
99
+ }
100
+
101
+ const decision = decidePackageManager({
102
+ flag: managerFlag,
103
+ userAgent: process.env.npm_config_user_agent,
104
+ installed: installedManagers(),
105
+ interactive: Boolean(process.stdout.isTTY),
106
+ })
107
+
108
+ let packageManager: PackageManager = decision.kind === 'use' ? decision.manager : 'bun'
109
+ let managerNotice: string | undefined
110
+
111
+ if (decision.kind === 'missing') {
112
+ managerNotice = `! Neither Bun nor pnpm was found. Installing dependencies, applying framework
113
+ patches (xplat patches apply) and running the app all need one of them.
114
+ Install Bun ${compatibility.tools.bun}+ (https://bun.sh) or pnpm ${compatibility.tools.pnpm}+ (https://pnpm.io), then:
115
+ cd ${dir} && bun install
116
+ To use pnpm instead, recreate the project with --package-manager pnpm.`
117
+ } else if (decision.kind === 'use' && !decision.installed.includes(decision.manager)) {
118
+ managerNotice = `! ${managerLabel(decision.manager)} was selected but is not installed — the
119
+ ${decision.manager} project was scaffolded without installing dependencies.
120
+ Install ${managerLabel(decision.manager)} ${compatibility.tools[decision.manager]}+, then run the
121
+ package manager's install command inside ${dir}.`
122
+ }
123
+
124
+ /** The manager `select`, joining the caller's clack session. */
125
+ async function promptForManager(p: typeof import('@clack/prompts')) {
126
+ const picked = await p.select<PackageManager>({
127
+ message: 'Package manager',
128
+ options: [
129
+ { value: 'bun', label: 'Bun' },
130
+ { value: 'pnpm', label: 'pnpm' },
131
+ ],
132
+ initialValue: 'bun',
133
+ })
134
+
135
+ if (p.isCancel(picked)) {
136
+ p.cancel('Cancelled')
137
+ process.exit(0)
138
+ }
139
+
140
+ packageManager = picked
112
141
  }
113
142
 
114
143
  let ids: string[] = []
144
+
115
145
  if (templateArg === 'library') {
116
- const packageName = nameArg ?? basename(dir)
117
- try {
118
- composeLibrary(dir, packageName)
119
- } catch (error) {
120
- console.error(`✗ ${error.message}`)
121
- process.exit(1)
122
- }
123
-
124
- console.log(`\n✓ scaffolded ${dir} (library: ${packageName}; web + iOS + Android)`)
146
+ const packageName = values.name ?? basename(dir)
147
+
148
+ if (decision.kind === 'prompt') {
149
+ const p = await import('@clack/prompts')
150
+
151
+ p.intro('create-octane-xplat')
152
+ await promptForManager(p)
153
+ }
154
+
155
+ try {
156
+ composeLibrary(dir, packageName, { packageManager })
157
+ } catch (error) {
158
+ console.error(`✗ ${error.message}`)
159
+ process.exit(1)
160
+ }
161
+
162
+ console.log(
163
+ `\n✓ scaffolded ${dir} (library: ${packageName}; web + iOS + Android; ${packageManager})`,
164
+ )
125
165
  } else {
126
- if (targetsArg !== undefined) {
127
- try {
128
- ids = parseTargets(targetsArg)
129
- } catch (error) {
130
- console.error(`✗ ${error.message}`)
131
- process.exit(1)
132
- }
133
- } else if (process.stdout.isTTY) {
134
- // Non-interactive creation does not need the prompt module.
135
- const p = await import('@clack/prompts')
136
- p.intro('create-octane-xplat')
137
- const picked = await p.multiselect({
138
- message: 'Target platforms',
139
- options: selectableTargets.map((id) => ({
140
- value: id,
141
- label: targets[id].label,
142
- hint: targets[id].note,
143
- })),
144
- initialValues: [...defaultTargets],
145
- required: true,
146
- })
147
-
148
- if (p.isCancel(picked)) {
149
- p.cancel('Cancelled')
150
- process.exit(0)
151
- }
152
-
153
- ids = picked
154
- } else {
155
- ids = defaultTargets
156
- }
157
-
158
- composeTargets(ids, dir)
159
- console.log(
160
- `\n✓ scaffolded ${dir} (${[...new Set(resolveTargets(ids))].filter((id) => !targets[id].hidden).join(', ')})`,
161
- )
166
+ if (values.targets !== undefined) {
167
+ try {
168
+ ids = parseTargets(values.targets)
169
+ } catch (error) {
170
+ console.error(`✗ ${error.message}`)
171
+ process.exit(1)
172
+ }
173
+ } else if (process.stdout.isTTY) {
174
+ // Non-interactive creation does not need the prompt module.
175
+ const p = await import('@clack/prompts')
176
+
177
+ p.intro('create-octane-xplat')
178
+
179
+ const picked = await p.multiselect({
180
+ message: 'Target platforms',
181
+ options: selectableTargets.map((id) => ({
182
+ value: id,
183
+ label: targets[id].label,
184
+ hint: targets[id].note,
185
+ })),
186
+ initialValues: [...defaultTargets],
187
+ required: true,
188
+ })
189
+
190
+ if (p.isCancel(picked)) {
191
+ p.cancel('Cancelled')
192
+ process.exit(0)
193
+ }
194
+
195
+ ids = picked
196
+ if (decision.kind === 'prompt') {
197
+ await promptForManager(p)
198
+ }
199
+ } else {
200
+ ids = defaultTargets
201
+ }
202
+
203
+ // Targets from the flag skip the multiselect; the manager choice still asks.
204
+ if (decision.kind === 'prompt' && values.targets !== undefined) {
205
+ const p = await import('@clack/prompts')
206
+
207
+ p.intro('create-octane-xplat')
208
+ await promptForManager(p)
209
+ }
210
+
211
+ composeTargets(ids, dir, { packageManager })
212
+ console.log(
213
+ `\n✓ scaffolded ${dir} (${[...new Set(resolveTargets(ids))].filter((id) => !targets[id].hidden).join(', ')}; ${packageManager})`,
214
+ )
215
+ }
216
+
217
+ if (managerNotice) {
218
+ console.log(`\n${managerNotice}`)
219
+ if (decision.kind === 'use') {
220
+ printNextSteps(dir, ids, templateArg, packageManager)
221
+ }
222
+
223
+ process.exit(0)
162
224
  }
163
225
 
164
226
  if (noInstall) {
165
- console.log('\nSkipped install (--no-install). To run manually:')
166
- printNextSteps(dir, ids, templateArg)
167
- process.exit(0)
227
+ console.log('\nSkipped install (--no-install). To run manually:')
228
+ printNextSteps(dir, ids, templateArg, packageManager)
229
+ process.exit(0)
168
230
  }
169
231
 
170
- const install = spawnSync('bun', ['install'], {
171
- cwd: dir,
172
- stdio: 'inherit',
173
- shell: process.platform === 'win32',
232
+ const managerFloor = compatibility.tools[packageManager]
233
+ const managerInstalled = managerVersion(packageManager)
234
+
235
+ if (managerInstalled !== undefined && versionBelow(managerInstalled, managerFloor)) {
236
+ console.log(
237
+ `! ${managerLabel(packageManager)} ${managerInstalled} is below the supported ${managerFloor}+ — install may fail`,
238
+ )
239
+ }
240
+
241
+ const install = spawnSync(packageManager, ['install'], {
242
+ cwd: dir,
243
+ stdio: 'inherit',
244
+ shell: process.platform === 'win32',
174
245
  })
175
246
 
176
247
  if (install.status !== 0) {
177
- console.log(`\nInstall didn't finish (Bun missing?). To run manually:`)
178
- printNextSteps(dir, ids, templateArg)
179
- process.exit(install.status ?? 1)
248
+ console.log(
249
+ `\nInstall didn't finish (${managerLabel(packageManager)} missing?). To run manually:`,
250
+ )
251
+
252
+ printNextSteps(dir, ids, templateArg, packageManager)
253
+ process.exit(install.status ?? 1)
180
254
  }
181
255
 
182
256
  if (templateArg === 'app' && ids.includes('web')) {
183
- console.log('\n✓ installed — starting dev server (Ctrl+C to stop)\n')
184
- spawnSync('bun', ['dev'], { cwd: dir, stdio: 'inherit', shell: process.platform === 'win32' })
257
+ console.log('\n✓ installed — starting dev server (Ctrl+C to stop)\n')
258
+ spawnSync(packageManager, ['run', 'dev'], {
259
+ cwd: dir,
260
+ stdio: 'inherit',
261
+ shell: process.platform === 'win32',
262
+ })
185
263
  } else {
186
- console.log('\n✓ installed. Next steps:')
187
- printNextSteps(dir, ids, templateArg)
188
- }
189
-
190
- function printNextSteps(dir, ids, template) {
191
- console.log(` cd ${dir}\n bun install`)
192
- if (template === 'library') {
193
- console.log(
194
- ' bun run typecheck\n bun run lint\n bun run typegen\n bun run test\n bun run test:packed',
195
- )
196
- return
197
- }
198
-
199
- if (ids.includes('web')) {
200
- console.log(' bun run dev')
201
- } else {
202
- // No web entry — `xplat dev` discovers whichever native targets exist.
203
- console.log(' bun run xplat dev')
204
- }
264
+ console.log('\n✓ installed. Next steps:')
265
+ printNextSteps(dir, ids, templateArg, packageManager)
266
+ }
267
+
268
+ function managerLabel(manager: PackageManager) {
269
+ return manager === 'bun' ? 'Bun' : 'pnpm'
270
+ }
271
+
272
+ function versionBelow(version: string, floor: string) {
273
+ const parts = (value: string) => value.split('.').map((n) => Number.parseInt(n, 10) || 0)
274
+ const got = parts(version)
275
+ const min = parts(floor)
276
+
277
+ for (let i = 0; i < Math.max(got.length, min.length); i++) {
278
+ const a = got[i] ?? 0
279
+ const b = min[i] ?? 0
280
+
281
+ if (a !== b) {
282
+ return a < b
283
+ }
284
+ }
285
+
286
+ return false
287
+ }
288
+
289
+ function printNextSteps(dir, ids, template, pm: PackageManager) {
290
+ console.log(` cd ${dir}\n ${pm} install`)
291
+ if (template === 'library') {
292
+ console.log(
293
+ ` ${pm} run typecheck\n ${pm} run lint\n ${pm} run typegen\n ${pm} run test\n ${pm} run test:packed`,
294
+ )
295
+
296
+ return
297
+ }
298
+
299
+ if (ids.includes('web')) {
300
+ console.log(` ${pm} run dev`)
301
+ } else {
302
+ // No web entry — `xplat dev` discovers whichever native targets exist.
303
+ console.log(` ${pm} run xplat dev`)
304
+ }
205
305
  }
@@ -1,6 +1,6 @@
1
1
  # Library package notes
2
2
 
3
- - Use Bun 1.4.4 for package management.
3
+ - Use the package manager pinned in `package.json` `packageManager`.
4
4
  - Keep build dependencies in `catalog:xplat`. Use `bunx @octane-xplat/cli@latest upgrade --check` to preview a workspace-wide version/patch update and `bunx @octane-xplat/cli@latest upgrade` to apply it. Keep consumer peer ranges under the library's control; run `bun run xplat doctor` and the package checks afterward.
5
5
  - Keep the public API in `src/index.ts` and `src/index.web.ts`; both barrels
6
6
  must export the same names and types.
@@ -18,7 +18,7 @@ Render the example component from your app:
18
18
  import { Badge } from 'octane-xplat-library'
19
19
 
20
20
  export function Welcome() {
21
- return <Badge label="Ready" />
21
+ return <Badge label="Ready" />
22
22
  }
23
23
  ```
24
24
 
@@ -49,8 +49,9 @@ The package publishes authored source for the app's bundler to compile.
49
49
  declarations. `bun run test:packed` packs the package, places that artifact into
50
50
  small web and native TypeScript consumers, and checks both export conditions.
51
51
 
52
- The package sets `linker = "hoisted"` in `bunfig.toml` because the
53
- NativeScript bundler expects a flat dependency tree.
52
+ The starter configures a hoisted dependency tree
53
+ (`linker = "hoisted"` / `nodeLinker: hoisted`) because the NativeScript
54
+ bundler expects a flat dependency tree.
54
55
 
55
56
  Its `catalog:xplat` build dependencies and patches follow one framework
56
57
  compatibility set. Update that set together; consumer `peerDependencies`
@@ -0,0 +1,4 @@
1
+ [install]
2
+ # NativeScript resolves plugins from the app’s flat dependency tree.
3
+ linker = "hoisted"
4
+ exact = true