@xrystal/core 3.41.0 → 3.44.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 (38) hide show
  1. package/README.md +28 -24
  2. package/package.json +1 -1
  3. package/x/bin/commands/project.mjs +23 -10
  4. package/x/bin/commands/sync.mjs +1 -1
  5. package/x/bin/helpers/.generated/.generated-from +1 -0
  6. package/x/bin/helpers/.generated/seed-from-tmp.mjs +115 -0
  7. package/x/bin/helpers/.generated/tmp-schema.mjs +98 -14
  8. package/x/bin/helpers/banner.mjs +27 -26
  9. package/x/bin/helpers/build-config.mjs +78 -23
  10. package/x/bin/helpers/cli-identity.mjs +1 -1
  11. package/x/bin/helpers/package-defaults.mjs +11 -5
  12. package/x/bin/helpers/project-artifacts.mjs +101 -38
  13. package/x/bin/helpers/project-root.mjs +1 -1
  14. package/x/bin/helpers/seed-from-tmp.mjs +12 -64
  15. package/x/bin/helpers/tmp-layout.mjs +8 -4
  16. package/x/bin/helpers/tmp-schema.mjs +5 -0
  17. package/x/bin/helpers/toolchain-config.mjs +3 -2
  18. package/x/bin/paths.mjs +13 -2
  19. package/x/bin/scripts/publish-guard.mjs +36 -15
  20. package/x/bin/scripts/sync-cli-defaults.mjs +10 -15
  21. package/x/dist/utils/constants/defaults.json +6 -0
  22. package/x/dist/utils/constants/index.d.ts +7 -0
  23. package/x/dist/utils/constants/index.js +1 -1
  24. package/x/dist/utils/helpers/tmp/index.d.ts +2 -1
  25. package/x/dist/utils/helpers/tmp/index.js +1 -1
  26. package/x/dist/utils/helpers/tmp/runtime-tmp.js +1 -1
  27. package/x/dist/utils/helpers/tmp/seed-from-tmp.d.ts +2 -0
  28. package/x/dist/utils/helpers/tmp/seed-from-tmp.js +1 -1
  29. package/x/dist/utils/helpers/tmp/tmp-interpolate.d.ts +1 -0
  30. package/x/dist/utils/helpers/tmp/tmp-interpolate.js +1 -0
  31. package/x/dist/utils/helpers/tmp/tmp-schema.d.ts +12 -0
  32. package/x/dist/utils/helpers/tmp/tmp-schema.js +1 -1
  33. package/x/dist/utils/helpers/tmp/toolchain-heal.d.ts +46 -0
  34. package/x/dist/utils/helpers/tmp/toolchain-heal.js +2 -0
  35. package/x/dist/utils/models/enums/index.d.ts +10 -0
  36. package/x/dist/utils/models/enums/index.js +1 -1
  37. package/x/tmp.yml +7 -1
  38. package/x/bin/helpers/defaults.json +0 -28
@@ -4,7 +4,13 @@ import yaml from 'yaml'
4
4
 
5
5
  import { packageDefaults } from '../paths.mjs'
6
6
  import { ensureTmpFile, relativeFromRoot } from './tmp-layout.mjs'
7
- import { normalizeTmpDocument, readTmpServiceBlock } from './tmp-schema.mjs'
7
+ import {
8
+ normalizeTmpDocument,
9
+ readTmpServiceBlock,
10
+ readTmpGlobalBlock,
11
+ normalizeBundler,
12
+ resolveEffectiveBundler,
13
+ } from './tmp-schema.mjs'
8
14
 
9
15
  import { CLI_BIN_NAMES, CLI_PRIMARY_NAME } from './cli-identity.mjs'
10
16
 
@@ -36,7 +42,9 @@ export function readTmpBuildContext(root) {
36
42
  const tmp = normalizeTmpDocument(yaml.parse(fs.readFileSync(ensured.tmpFilePath, 'utf8')))
37
43
  const configs = tmp.configs ?? {}
38
44
  const build = readTmpServiceBlock(configs).build ?? {}
39
- return { layout: ensured.layout, configs, build }
45
+ const global = readTmpGlobalBlock(configs)
46
+ const bundler = resolveEffectiveBundler(normalizeBundler(build.bundler), global.runtime)
47
+ return { layout: ensured.layout, configs, build, global, runtime: global.runtime, bundler }
40
48
  }
41
49
 
42
50
  export function normalizeMainFolder(mainFolderPath = packageDefaults.mainSourceFolder) {
@@ -225,24 +233,28 @@ export function resolveSourcemapFlag(buildConfig = {}, tsconfig = null) {
225
233
  return ''
226
234
  }
227
235
 
228
- function withTscProject(root, buildConfig, extraArgs) {
236
+ function resolveTscBin(runtime = 'bun') {
237
+ return runtime === 'node' ? 'npx tsc' : 'bunx tsc'
238
+ }
239
+
240
+ function withTscProject(root, buildConfig, extraArgs, runtime = 'bun') {
229
241
  const tsconfigRel = resolveTsconfigRel(root, buildConfig)
230
242
  const projectFlag = tsconfigRel ? `--project ${tsconfigRel} ` : ''
231
- return `bunx tsc ${projectFlag}${extraArgs}`.replace(/\s+/g, ' ').trim()
243
+ return `${resolveTscBin(runtime)} ${projectFlag}${extraArgs}`.replace(/\s+/g, ' ').trim()
232
244
  }
233
245
 
234
- export function resolveTypecheckCommand(root, buildConfig = {}) {
246
+ export function resolveTypecheckCommand(root, buildConfig = {}, runtime = 'bun') {
235
247
  const tsconfigRel = resolveTsconfigRel(root, buildConfig)
236
248
  if (!tsconfigRel) {
237
249
  throw new Error(
238
250
  'build.typecheck is enabled but tsconfig was not found. Set build.tsconfig or add tsconfig.json.',
239
251
  )
240
252
  }
241
- return withTscProject(root, buildConfig, '--noEmit')
253
+ return withTscProject(root, buildConfig, '--noEmit', runtime)
242
254
  }
243
255
 
244
- export function resolveTscCommand(root, distRel, buildConfig = {}) {
245
- const cmd = withTscProject(root, buildConfig, `--emitDeclarationOnly --declaration --outDir ${distRel}`)
256
+ export function resolveTscCommand(root, distRel, buildConfig = {}, runtime = 'bun') {
257
+ const cmd = withTscProject(root, buildConfig, `--emitDeclarationOnly --declaration --outDir ${distRel}`, runtime)
246
258
  return buildConfig.tscLenient ? `${cmd} || true` : cmd
247
259
  }
248
260
 
@@ -253,16 +265,42 @@ export function resolveBunBuildCommand(entryGlobs, distRel, buildConfig = {}, ts
253
265
  return `bun build ${entryGlobs.join(' ')} ${flags.join(' ')}`.replace(/\s+/g, ' ').trim()
254
266
  }
255
267
 
256
- export function resolveEffectiveBuildOptions(root, layout, buildConfig = {}) {
268
+ export function resolveTscBuildCommand(root, distRel, buildConfig = {}, runtime = 'bun') {
269
+ return withTscProject(root, buildConfig, `--outDir ${distRel}`, runtime)
270
+ }
271
+
272
+ export function resolveEsbuildBuildCommand(entryGlobs, distRel, buildConfig = {}, tsconfig = null, runtime = 'bun') {
273
+ const minify = resolveMinifyEnabled(buildConfig) ? ' --minify' : ''
274
+ const sourcemapFlag = resolveSourcemapFlag(buildConfig, tsconfig)
275
+ const sourcemap = sourcemapFlag ? ' --sourcemap' : ''
276
+ const bin = runtime === 'node' ? 'npx esbuild' : 'bunx esbuild'
277
+ const entries = entryGlobs.join(' ')
278
+ return `${bin} ${entries} --bundle --platform=node --packages=external --outdir=${distRel}${minify}${sourcemap}`.replace(/\s+/g, ' ').trim()
279
+ }
280
+
281
+ export function resolveServiceBundleCommand(root, plan, buildConfig = {}, runtime = 'bun', bundler = 'bun') {
282
+ if (bundler === 'tsc') {
283
+ return resolveTscBuildCommand(root, plan.distRel, buildConfig, runtime)
284
+ }
285
+ if (bundler === 'esbuild') {
286
+ return resolveEsbuildBuildCommand(plan.entryGlobs, plan.distRel, buildConfig, plan.tsconfig, runtime)
287
+ }
288
+ return resolveBunBuildCommand(plan.entryGlobs, plan.distRel, buildConfig, plan.tsconfig)
289
+ }
290
+
291
+ export function resolveEffectiveBuildOptions(root, layout, buildConfig = {}, runtime = 'bun') {
257
292
  const tsconfig = readTsconfigJson(root, buildConfig)
258
293
  const distRel = resolveDistRelWithTsconfig(root, layout, buildConfig, tsconfig)
259
294
  const entryGlobs = resolveBuildEntryGlobs(layout.mainFolderPath, buildConfig, tsconfig)
295
+ const bundler = resolveEffectiveBundler(normalizeBundler(buildConfig.bundler), runtime)
260
296
 
261
297
  return {
262
298
  tsconfig,
263
299
  tsconfigRel: tsconfig?.rel ?? null,
264
300
  distRel,
265
301
  entryGlobs,
302
+ runtime,
303
+ bundler,
266
304
  typecheck: resolveTypecheckEnabled(buildConfig),
267
305
  declarations: resolveDeclarationsEnabled(buildConfig, tsconfig),
268
306
  sourcemap: resolveSourcemapFlag(buildConfig, tsconfig) || 'false',
@@ -285,48 +323,51 @@ export function resolveEffectiveBuildOptions(root, layout, buildConfig = {}) {
285
323
  }
286
324
 
287
325
  export function resolveCoreBuildSteps(root, distRel, buildConfig = {}) {
288
- const tsconfigRel = resolveTsconfigRel(root, buildConfig) ?? 'tsconfig.json'
326
+ const tsconfigRel = resolveTsconfigRel(root, buildConfig) ?? packageDefaults.buildDefaults.tsconfig
327
+ const scripts = `node ${packageDefaults.packageRootFolder}/bin/scripts`
289
328
  const steps = [
290
- 'node x/bin/scripts/sync-cli-defaults.mjs',
329
+ `${scripts}/sync-cli-defaults.mjs`,
291
330
  `rm -rf ${distRel}`,
292
331
  `bun run tsc --project ${tsconfigRel}`,
293
332
  `bunx tsc-alias -p ${tsconfigRel}`,
294
333
  ]
295
334
  if (resolveMinifyEnabled(buildConfig)) {
296
- steps.push('node x/bin/scripts/minify-dist.mjs')
335
+ steps.push(`${scripts}/minify-dist.mjs`)
297
336
  }
298
- steps.push('node x/bin/scripts/fix-dist-imports.mjs')
299
- steps.push('node x/bin/scripts/clean-dist-tests.mjs')
300
- steps.push('node x/bin/scripts/clean-source-types.mjs')
337
+ steps.push(`${scripts}/fix-dist-imports.mjs`)
338
+ steps.push(`${scripts}/clean-dist-tests.mjs`)
339
+ steps.push(`${scripts}/clean-source-types.mjs`)
301
340
  return steps
302
341
  }
303
342
 
304
- export function resolveServiceBuildSteps(root, layout, buildConfig = {}) {
305
- const plan = resolveEffectiveBuildOptions(root, layout, buildConfig)
343
+ export function resolveServiceBuildSteps(root, layout, buildConfig = {}, runtime = 'bun') {
344
+ const plan = resolveEffectiveBuildOptions(root, layout, buildConfig, runtime)
306
345
  const steps = []
307
346
 
308
347
  if (plan.typecheck) {
309
- steps.push(resolveTypecheckCommand(root, buildConfig))
348
+ steps.push(resolveTypecheckCommand(root, buildConfig, runtime))
310
349
  }
311
350
 
312
351
  steps.push(
313
352
  `rm -rf ${plan.distRel}`,
314
- resolveBunBuildCommand(plan.entryGlobs, plan.distRel, buildConfig, plan.tsconfig),
353
+ resolveServiceBundleCommand(root, plan, buildConfig, runtime, plan.bundler),
315
354
  )
316
355
 
317
- if (plan.declarations) {
318
- steps.push(resolveTscCommand(root, plan.distRel, buildConfig))
356
+ if (plan.declarations && plan.bundler !== 'tsc') {
357
+ steps.push(resolveTscCommand(root, plan.distRel, buildConfig, runtime))
319
358
  }
320
359
 
321
360
  return steps
322
361
  }
323
362
 
324
- export function summarizeBuildPlan(root, layout, buildConfig = {}) {
325
- const plan = resolveEffectiveBuildOptions(root, layout, buildConfig)
363
+ export function summarizeBuildPlan(root, layout, buildConfig = {}, runtime = 'bun') {
364
+ const plan = resolveEffectiveBuildOptions(root, layout, buildConfig, runtime)
326
365
  return {
327
366
  distRel: plan.distRel,
328
367
  entryGlobs: plan.entryGlobs,
329
368
  tsconfigRel: plan.tsconfigRel,
369
+ runtime: plan.runtime,
370
+ bundler: plan.bundler,
330
371
  typecheck: plan.typecheck,
331
372
  declarations: plan.declarations,
332
373
  sourcemap: plan.sourcemap,
@@ -351,3 +392,17 @@ export function resolveEnvFiles(envDir, names) {
351
392
  .map((name) => path.join(envDir, name))
352
393
  .filter((file) => fs.existsSync(file))
353
394
  }
395
+
396
+
397
+ export function resolveRuntimeRunner(runtime = 'bun') {
398
+ return runtime === 'node' ? 'node' : 'bun'
399
+ }
400
+
401
+ export function resolvePackageScriptRunner(runtime = 'bun') {
402
+ return runtime === 'node' ? 'npm run' : 'bun run'
403
+ }
404
+
405
+ export function resolveTestCommand(runtime = 'bun', target) {
406
+ if (runtime === 'node') return `node --test ${target}`
407
+ return `bun test ${target}`
408
+ }
@@ -1,7 +1,7 @@
1
- /** @deprecated import from package-defaults.mjs — kept as stable path for existing imports */
2
1
  export {
3
2
  CLI_PRIMARY_NAME,
4
3
  CLI_BIN_NAMES,
5
4
  resolveInvokedAs,
6
5
  isKnownCliBin,
6
+ packageDefaults,
7
7
  } from './package-defaults.mjs'
@@ -2,20 +2,25 @@ import fs from 'node:fs'
2
2
  import path from 'node:path'
3
3
  import { fileURLToPath } from 'node:url'
4
4
 
5
- import { loadSeedLayoutFromBundledTmp } from './seed-from-tmp.mjs'
5
+ import {
6
+ loadSeedLayoutFromBundledTmp,
7
+ packageIdentityDefaults,
8
+ } from './seed-from-tmp.mjs'
6
9
 
7
10
  const here = path.dirname(fileURLToPath(import.meta.url))
8
11
  const packageRoot = path.resolve(here, '..', '..', '..')
9
12
 
10
13
  const AUTHORED_DEFAULTS = path.join(packageRoot, 'source', 'utils', 'constants', 'defaults.json')
11
- const PUBLISHED_DEFAULTS = path.join(here, 'defaults.json')
12
14
 
13
15
  function loadRawDefaults() {
14
- for (const file of [AUTHORED_DEFAULTS, PUBLISHED_DEFAULTS]) {
15
- if (fs.existsSync(file)) return JSON.parse(fs.readFileSync(file, 'utf8'))
16
+ if (fs.existsSync(AUTHORED_DEFAULTS)) {
17
+ return JSON.parse(fs.readFileSync(AUTHORED_DEFAULTS, 'utf8'))
18
+ }
19
+ if (packageIdentityDefaults && typeof packageIdentityDefaults === 'object') {
20
+ return packageIdentityDefaults
16
21
  }
17
22
  throw new Error(
18
- `package defaults.json not found. Expected ${AUTHORED_DEFAULTS} or ${PUBLISHED_DEFAULTS}`,
23
+ `package defaults missing. Expected authored ${AUTHORED_DEFAULTS} or embedded packageIdentityDefaults`,
19
24
  )
20
25
  }
21
26
 
@@ -27,6 +32,7 @@ export const packageDefaults = Object.freeze({
27
32
  mainSourceFolder: seed.mainSourceFolder,
28
33
  framework: seed.framework,
29
34
  layoutPaths: seed.layoutPaths,
35
+ brand: Object.freeze({ ...(raw.brand ?? {}) }),
30
36
  buildDefaults: Object.freeze({ ...(raw.buildDefaults ?? {}) }),
31
37
  tmpWatchDefaults: Object.freeze({ ...(raw.tmpWatchDefaults ?? {}) }),
32
38
  cliBinNames: Object.freeze([...(raw.cliBinNames ?? [raw.cliName])]),
@@ -4,13 +4,23 @@ import path from 'node:path'
4
4
  import { fileURLToPath } from 'node:url'
5
5
 
6
6
  import { isCorePackageName } from './build-config.mjs'
7
- import { syncProjectToolchain } from './toolchain-config.mjs'
7
+ import { auditTsconfigAlignment, syncProjectToolchain } from './toolchain-config.mjs'
8
8
  import { ensureTmpFile, relativeFromRoot } from './tmp-layout.mjs'
9
9
  import { packageDefaults } from './package-defaults.mjs'
10
10
 
11
11
  const CLI_BIN_DIR = path.dirname(fileURLToPath(import.meta.url))
12
- const CLI_GENERATED_SCHEMA = path.join(CLI_BIN_DIR, '.generated/tmp-schema.mjs')
13
- const CLI_SCHEMA_SOURCE = 'source/utils/helpers/tmp/tmp-schema.ts'
12
+ const CLI_GENERATED_DIR = path.join(CLI_BIN_DIR, '.generated')
13
+
14
+ const CLI_GENERATED_MODULES = [
15
+ {
16
+ source: 'source/utils/helpers/tmp/tmp-schema.ts',
17
+ outfile: path.join(CLI_GENERATED_DIR, 'tmp-schema.mjs'),
18
+ },
19
+ {
20
+ source: 'source/utils/helpers/tmp/seed-from-tmp.ts',
21
+ outfile: path.join(CLI_GENERATED_DIR, 'seed-from-tmp.mjs'),
22
+ },
23
+ ]
14
24
 
15
25
  const CORE_EXPORT_SUBPATHS = [
16
26
  'utils',
@@ -56,11 +66,21 @@ export function buildCorePackageExports(distPrefix) {
56
66
  return exports
57
67
  }
58
68
 
59
- const CORE_PUBLISH_FILES_STATIC = ['x/bin', 'x/tmp.yml', 'x/assets', 'tsconfig.base.json', 'README.md']
69
+ function corePublishFilesStatic() {
70
+ const root = packageDefaults.packageRootFolder
71
+ const tmpName = `${packageDefaults.tmpBaseName}${packageDefaults.tmpExtension}`
72
+ return [
73
+ `${root}/bin`,
74
+ `${root}/${tmpName}`,
75
+ `${root}/assets`,
76
+ 'tsconfig.base.json',
77
+ 'README.md',
78
+ ]
79
+ }
60
80
 
61
81
  function normalizeFilesList(files, distRel) {
62
82
  const distEntry = distRel.replace(/^\.\//, '')
63
- const base = [...CORE_PUBLISH_FILES_STATIC]
83
+ const base = [...corePublishFilesStatic()]
64
84
  if (!base.includes(distEntry)) base.unshift(distEntry)
65
85
  return base
66
86
  }
@@ -76,39 +96,74 @@ function stablePackageShape(pkg) {
76
96
  }
77
97
 
78
98
 
79
- /** Publish artifact copy of authored source/utils/constants/defaults.json */
80
- export function syncCliDefaults(root = process.cwd()) {
81
- const src = path.join(root, 'source/utils/constants/defaults.json')
82
- const dest = path.join(root, 'x/bin/helpers/defaults.json')
83
- if (!fs.existsSync(src)) return { synced: false, reason: 'missing source' }
84
- const needs = !fs.existsSync(dest) || fs.statSync(src).mtimeMs > fs.statSync(dest).mtimeMs
85
- if (!needs) return { synced: false, reason: 'up-to-date', dest }
86
- fs.mkdirSync(path.dirname(dest), { recursive: true })
87
- fs.copyFileSync(src, dest)
88
- return { synced: true, dest }
89
- }
99
+ /**
100
+ * Defaults identity is authored at source/utils/constants/defaults.json.
101
+ * npm has no source/ — defaults are embedded into .generated/seed-from-tmp.mjs via bun build.
102
+ * This sync rebuilds generated CLI modules when authored defaults/seed sources change.
103
+ */
104
+ export function syncCliDefaults(root = process.cwd(), { force = false } = {}) {
105
+ const authored = path.join(root, 'source/utils/constants/defaults.json')
106
+ const seedOut = path.join(CLI_GENERATED_DIR, 'seed-from-tmp.mjs')
107
+ const needs = force
108
+ || !fs.existsSync(seedOut)
109
+ || (fs.existsSync(authored) && fs.statSync(authored).mtimeMs > fs.statSync(seedOut).mtimeMs)
110
+
111
+ if (!needs) {
112
+ return { synced: false, reason: 'up-to-date', embeddedIn: seedOut }
113
+ }
90
114
 
91
- export function syncCliTmpSchema(root = process.cwd(), { force = false } = {}) {
92
- const srcAbs = path.join(root, CLI_SCHEMA_SOURCE)
93
- if (!fs.existsSync(srcAbs)) {
94
- return { synced: false, reason: 'missing source' }
115
+ const generated = syncCliGeneratedModules(root, { force: true })
116
+ return {
117
+ synced: generated.synced,
118
+ reason: 'embedded into .generated/seed-from-tmp.mjs',
119
+ embeddedIn: seedOut,
120
+ generated,
95
121
  }
122
+ }
123
+
124
+ export function syncCliGeneratedModules(root = process.cwd(), { force = false } = {}) {
125
+ const results = []
126
+ fs.mkdirSync(CLI_GENERATED_DIR, { recursive: true })
96
127
 
97
- const outDir = path.dirname(CLI_GENERATED_SCHEMA)
98
- const needsSync = force
99
- || !fs.existsSync(CLI_GENERATED_SCHEMA)
100
- || fs.statSync(srcAbs).mtimeMs > fs.statSync(CLI_GENERATED_SCHEMA).mtimeMs
128
+ for (const mod of CLI_GENERATED_MODULES) {
129
+ const srcAbs = path.join(root, mod.source)
130
+ if (!fs.existsSync(srcAbs)) {
131
+ results.push({ source: mod.source, synced: false, reason: 'missing source' })
132
+ continue
133
+ }
101
134
 
102
- if (!needsSync) return { synced: false, reason: 'up-to-date', out: CLI_GENERATED_SCHEMA }
135
+ const needsSync = force
136
+ || !fs.existsSync(mod.outfile)
137
+ || fs.statSync(srcAbs).mtimeMs > fs.statSync(mod.outfile).mtimeMs
103
138
 
104
- fs.mkdirSync(outDir, { recursive: true })
105
- execSync(
106
- `bun build "${srcAbs}" --outfile "${CLI_GENERATED_SCHEMA}" --target node --format esm --external yaml`,
107
- { cwd: root, stdio: 'pipe' },
108
- )
109
- fs.writeFileSync(path.join(outDir, '.generated-from'), `${CLI_SCHEMA_SOURCE}\n`)
139
+ if (!needsSync) {
140
+ results.push({ source: mod.source, synced: false, reason: 'up-to-date', out: mod.outfile })
141
+ continue
142
+ }
110
143
 
111
- return { synced: true, out: CLI_GENERATED_SCHEMA }
144
+ execSync(
145
+ `bun build "${srcAbs}" --outfile "${mod.outfile}" --target node --format esm --external yaml --external handlebars`,
146
+ { cwd: root, stdio: 'pipe' },
147
+ )
148
+ results.push({ source: mod.source, synced: true, out: mod.outfile })
149
+ }
150
+
151
+ const fromLines = CLI_GENERATED_MODULES.map((m) => m.source).join('\n')
152
+ fs.writeFileSync(path.join(CLI_GENERATED_DIR, '.generated-from'), `${fromLines}\n`)
153
+ return { synced: results.some((r) => r.synced), results }
154
+ }
155
+
156
+ /** @deprecated use syncCliGeneratedModules */
157
+ export function syncCliTmpSchema(root = process.cwd(), options = {}) {
158
+ const result = syncCliGeneratedModules(root, options)
159
+ const schema = result.results.find((r) => r.source.includes('tmp-schema'))
160
+ return { synced: Boolean(schema?.synced), out: schema?.out, reason: schema?.reason }
161
+ }
162
+
163
+ export function syncCliRuntime(root = process.cwd(), { force = false } = {}) {
164
+ const defaults = syncCliDefaults(root, { force })
165
+ const generated = defaults.generated ?? syncCliGeneratedModules(root, { force })
166
+ return { defaults, generated }
112
167
  }
113
168
 
114
169
  export function syncPackageManifest(root = process.cwd(), { write = true } = {}) {
@@ -120,7 +175,7 @@ export function syncPackageManifest(root = process.cwd(), { write = true } = {})
120
175
  }
121
176
 
122
177
  const { distPrefix, distRel } = resolveDistLayout(root)
123
- const binEntry = './x/bin/main-cli.js'
178
+ const binEntry = `./${packageDefaults.packageRootFolder}/bin/main-cli.js`
124
179
  const bin = Object.fromEntries(packageDefaults.cliBinNames.map((name) => [name, binEntry]))
125
180
 
126
181
  const next = {
@@ -140,7 +195,7 @@ export function syncPackageManifest(root = process.cwd(), { write = true } = {})
140
195
  return { synced: true, wrote: write && changed, distPrefix, distRel, changed }
141
196
  }
142
197
 
143
- /** tmp.yml → toolchain + CLI schema (+ core package exports on build/release). */
198
+ /** tmp.yml → toolchain (+ CLI schema / package exports). Heals tsconfig when layout drifts. */
144
199
  export function ensureProjectArtifacts(root = process.cwd(), options = {}) {
145
200
  const {
146
201
  writeToolchain = false,
@@ -148,9 +203,17 @@ export function ensureProjectArtifacts(root = process.cwd(), options = {}) {
148
203
  forceSchema = false,
149
204
  } = options
150
205
 
151
- const schema = syncCliTmpSchema(root, { force: forceSchema })
152
- const defaults = syncCliDefaults(root)
153
- const toolchain = syncProjectToolchain(root, { write: writeToolchain })
206
+ const { generated, defaults } = syncCliRuntime(root, { force: forceSchema })
207
+ const audit = auditTsconfigAlignment(root)
208
+ const shouldWriteToolchain = writeToolchain || !audit.ok
209
+ const toolchain = syncProjectToolchain(root, { write: shouldWriteToolchain })
210
+ if (shouldWriteToolchain && !writeToolchain && !audit.ok) {
211
+ toolchain.healed = true
212
+ toolchain.healNotes = audit.notes
213
+ if (process.env.XRY_QUIET !== '1') {
214
+ console.info(`[${packageDefaults.packageName}] toolchain auto-synced (tsconfig) — layout drift`)
215
+ }
216
+ }
154
217
  let manifest = { synced: false, reason: 'skipped' }
155
218
 
156
219
  const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'))
@@ -158,5 +221,5 @@ export function ensureProjectArtifacts(root = process.cwd(), options = {}) {
158
221
  manifest = syncPackageManifest(root, { write: true })
159
222
  }
160
223
 
161
- return { schema, defaults, toolchain, manifest }
224
+ return { generated, defaults, toolchain, manifest, audit }
162
225
  }
@@ -52,7 +52,7 @@ export function getInstalledCoreVersion(root = resolveProjectRoot()) {
52
52
  ?? project.devDependencies?.[packageDefaults.packageName]
53
53
  ?? null
54
54
 
55
- const installedPath = path.join(root, 'node_modules', '@xrystal', 'core', 'package.json')
55
+ const installedPath = path.join(root, 'node_modules', ...packageDefaults.packageName.split('/'), 'package.json')
56
56
  if (!fs.existsSync(installedPath)) {
57
57
  if (root === packageRoot) {
58
58
  const cli = readCliPackageJson()
@@ -1,69 +1,17 @@
1
- import fs from 'node:fs'
2
- import path from 'node:path'
3
- import { fileURLToPath } from 'node:url'
4
- import yaml from 'yaml'
1
+ import {
2
+ loadSeedFromBundledTmp,
3
+ seedFromTmp,
4
+ packageIdentityDefaults,
5
+ } from './.generated/seed-from-tmp.mjs'
5
6
 
6
- const here = path.dirname(fileURLToPath(import.meta.url))
7
-
8
- function requireString(value, label) {
9
- if (typeof value !== 'string' || !value.trim()) {
10
- throw new Error(label)
11
- }
12
- return value.trim()
13
- }
14
-
15
- function normalizeRootFolder(value, fallback) {
16
- if (typeof value !== 'string' || !value.trim()) return fallback
17
- return value.trim().replace(/^\.\/+/, '')
18
- }
19
-
20
- function normalizeSourceFolder(value, packageName) {
21
- const trimmed = requireString(value, `${packageName}: bundled tmp.yml missing configs.service.paths.source`)
22
- if (trimmed.startsWith('./') || trimmed.startsWith('../')) return trimmed
23
- return `./${trimmed}`
24
- }
25
-
26
- function readLayout(special, packageName) {
27
- const block = special && typeof special === 'object' && !Array.isArray(special) ? special : {}
28
- const miss = (field) => `${packageName}: bundled tmp.yml missing configs.service.paths.special.${field}`
29
- return Object.freeze({
30
- tests: requireString(block.tests, miss('tests')),
31
- environments: requireString(block.environments, miss('environments')),
32
- dist: requireString(block.dist, miss('dist')),
33
- })
34
- }
35
-
36
- function findBundledTmpFile(packageRoot, raw) {
37
- const packageName = requireString(raw.packageName, 'defaults.packageName required')
38
- const rootFolder = requireString(raw.packageRootFolder, `${packageName}: defaults.packageRootFolder required`)
39
- const tmpBase = requireString(raw.tmpBaseName, `${packageName}: defaults.tmpBaseName required`)
40
- const tmpExt = requireString(raw.tmpExtension, `${packageName}: defaults.tmpExtension required`)
41
- const tmpFileName = `${tmpBase}${tmpExt}`
42
- const direct = path.join(packageRoot, rootFolder, tmpFileName)
43
- if (fs.existsSync(direct)) return { file: direct, rootFolder, packageName }
44
-
45
- let dir = path.resolve(here)
46
- for (;;) {
47
- const candidate = path.join(dir, rootFolder, tmpFileName)
48
- if (fs.existsSync(candidate)) return { file: candidate, rootFolder, packageName }
49
- const parent = path.dirname(dir)
50
- if (parent === dir) break
51
- dir = parent
52
- }
53
-
54
- throw new Error(`${packageName}: bundled ${rootFolder}/${tmpFileName} not found`)
55
- }
56
-
57
- export function loadSeedLayoutFromBundledTmp(packageRoot, raw = {}) {
58
- const { file, rootFolder, packageName } = findBundledTmpFile(packageRoot, raw)
59
- const doc = yaml.parse(fs.readFileSync(file, 'utf8'))
60
- const service = doc?.configs?.service ?? {}
61
- const paths = service.paths ?? {}
7
+ export { loadSeedFromBundledTmp, seedFromTmp, packageIdentityDefaults }
62
8
 
9
+ export function loadSeedLayoutFromBundledTmp(_packageRoot = process.cwd(), _raw = {}) {
10
+ const seed = loadSeedFromBundledTmp()
63
11
  return {
64
- rootFolder: normalizeRootFolder(paths.root, rootFolder),
65
- mainSourceFolder: normalizeSourceFolder(paths.source, packageName),
66
- framework: requireString(service.framework, `${packageName}: bundled tmp.yml missing configs.service.framework`),
67
- layoutPaths: readLayout(paths.special, packageName),
12
+ rootFolder: seed.rootFolder,
13
+ mainSourceFolder: seed.sourceFolder,
14
+ framework: seed.framework,
15
+ layoutPaths: Object.freeze({ ...seed.layout }),
68
16
  }
69
17
  }
@@ -7,8 +7,6 @@ import { findAllFilesRecursively, findFileRecursively } from './index.mjs'
7
7
  import { getBundledCoreTmpPath } from './project-root.mjs'
8
8
  import { normalizeTmpDocument, normalizeRootFolder, normalizeSourceFolder, readTmpServiceBlock, resolveServiceLayoutPaths } from './tmp-schema.mjs'
9
9
 
10
- const DEFAULT_PATHS = packageDefaults.layoutPaths
11
-
12
10
  function formatTmpTarget(name, ext) {
13
11
  return `${name}${ext.startsWith('.') ? ext : `.${ext}`}`
14
12
  }
@@ -259,8 +257,14 @@ export function ensureTmpFile(projectRoot = process.cwd(), { patchServiceName =
259
257
  : null
260
258
  if (serviceName) {
261
259
  const tmp = yaml.parse(content)
262
- tmp.configs = tmp.configs ?? {}
263
- tmp.configs.service = serviceName
260
+ const configs = tmp.configs ?? {}
261
+ const service = configs.service
262
+ if (typeof service === 'object' && service !== null && !Array.isArray(service)) {
263
+ service.name = serviceName
264
+ } else {
265
+ configs.service = { name: serviceName }
266
+ }
267
+ tmp.configs = configs
264
268
  content = yaml.stringify(tmp)
265
269
  }
266
270
  }
@@ -2,8 +2,13 @@ export {
2
2
  normalizeRootFolder,
3
3
  normalizeSourceFolder,
4
4
  normalizeTmpDocument,
5
+ normalizeRuntime,
6
+ normalizeBundler,
7
+ resolveEffectiveBundler,
5
8
  readTmpCoreBlock,
6
9
  readTmpServiceBlock,
10
+ readTmpGlobalBlock,
11
+ applyTmpGlobalVars,
7
12
  resolveServiceLayoutPaths,
8
13
  resolveTmpRuntimeConfigs,
9
14
  } from './.generated/tmp-schema.mjs'
@@ -142,7 +142,7 @@ export function auditTsconfigAlignment(root, options = null) {
142
142
  const recommended = resolveRecommendedTsconfig(resolvedOptions)
143
143
  const onDisk = readProjectTsconfig(root)
144
144
  if (!onDisk) {
145
- return { ok: false, missing: true, notes: [`tsconfig.json not found — run ${CLI_PRIMARY_NAME} sync`] }
145
+ return { ok: false, missing: true, notes: [`tsconfig.json not found — auto-healed on layout change, next ${CLI_PRIMARY_NAME} command, or ${CLI_PRIMARY_NAME} sync`] }
146
146
  }
147
147
 
148
148
  const notes = []
@@ -201,8 +201,9 @@ export function resolveCoreBuildEntries(root) {
201
201
  const addEntry = (spec) => {
202
202
  if (typeof spec !== 'string' || !spec) return
203
203
  const normalized = spec.startsWith('./') ? spec : `./${spec}`
204
+ const sourcePrefix = String(packageDefaults.mainSourceFolder).replace(/^\.\//, '')
204
205
  const tsPath = normalized
205
- .replace(/^\.\/[^/]+\/dist\//, './source/')
206
+ .replace(new RegExp('^\\./[^/]+/dist/'), `./${sourcePrefix}/`)
206
207
  .replace(/\.js$/, '.ts')
207
208
  if (tsPath.endsWith('.ts') && fs.existsSync(path.join(root, tsPath))) {
208
209
  entries.add(tsPath)
package/x/bin/paths.mjs CHANGED
@@ -1,14 +1,25 @@
1
1
  import path from 'node:path'
2
2
  import { fileURLToPath } from 'node:url'
3
3
 
4
+ import {
5
+ packageDefaults,
6
+ coreVersionPattern,
7
+ semverVersionPattern,
8
+ } from './helpers/package-defaults.mjs'
9
+
4
10
  const binDir = path.dirname(fileURLToPath(import.meta.url))
5
11
 
6
12
  export const packageRoot = path.resolve(binDir, '..', '..')
7
- export const sourceDir = path.join(packageRoot, 'source')
13
+
14
+ function stripDotSlash(value) {
15
+ return String(value ?? '').replace(/^\.\//, '')
16
+ }
17
+
18
+ export const sourceDir = path.join(packageRoot, stripDotSlash(packageDefaults.mainSourceFolder))
8
19
 
9
20
  export {
10
21
  packageDefaults,
11
22
  packageDefaults as Constants,
12
23
  coreVersionPattern,
13
24
  semverVersionPattern,
14
- } from './helpers/package-defaults.mjs'
25
+ }