@xrystal/core 3.40.0 → 3.42.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 (40) hide show
  1. package/README.md +7 -7
  2. package/package.json +1 -1
  3. package/x/bin/commands/doctor.mjs +4 -3
  4. package/x/bin/commands/hooks.mjs +2 -1
  5. package/x/bin/commands/release.mjs +2 -1
  6. package/x/bin/commands/tmp.mjs +2 -1
  7. package/x/bin/helpers/.generated/.generated-from +1 -0
  8. package/x/bin/helpers/.generated/seed-from-tmp.mjs +115 -0
  9. package/x/bin/helpers/.generated/tmp-schema.mjs +74 -13
  10. package/x/bin/helpers/banner.mjs +22 -20
  11. package/x/bin/helpers/build-config.mjs +7 -6
  12. package/x/bin/helpers/cli-help.mjs +3 -2
  13. package/x/bin/helpers/cli-identity.mjs +1 -1
  14. package/x/bin/helpers/package-defaults.mjs +14 -11
  15. package/x/bin/helpers/project-artifacts.mjs +90 -36
  16. package/x/bin/helpers/project-root.mjs +5 -5
  17. package/x/bin/helpers/seed-from-tmp.mjs +13 -48
  18. package/x/bin/helpers/tmp-config.mjs +2 -1
  19. package/x/bin/helpers/tmp-layout.mjs +13 -9
  20. package/x/bin/helpers/toolchain-config.mjs +4 -3
  21. package/x/bin/main-cli.js +1 -1
  22. package/x/bin/paths.mjs +13 -2
  23. package/x/bin/scripts/install-git-hooks.mjs +2 -1
  24. package/x/bin/scripts/publish-guard.mjs +36 -15
  25. package/x/bin/scripts/release-prepare.mjs +2 -2
  26. package/x/bin/scripts/sync-cli-defaults.mjs +10 -15
  27. package/x/dist/utils/constants/defaults.json +6 -0
  28. package/x/dist/utils/constants/index.d.ts +8 -2
  29. package/x/dist/utils/constants/index.js +1 -1
  30. package/x/dist/utils/helpers/core/tmp-layout.js +1 -1
  31. package/x/dist/utils/helpers/tmp/index.d.ts +1 -1
  32. package/x/dist/utils/helpers/tmp/index.js +1 -1
  33. package/x/dist/utils/helpers/tmp/path-normalize.d.ts +3 -5
  34. package/x/dist/utils/helpers/tmp/path-normalize.js +1 -1
  35. package/x/dist/utils/helpers/tmp/seed-from-tmp.d.ts +3 -0
  36. package/x/dist/utils/helpers/tmp/seed-from-tmp.js +1 -1
  37. package/x/dist/utils/helpers/tmp/tmp-schema.d.ts +0 -4
  38. package/x/dist/utils/helpers/tmp/tmp-schema.js +1 -1
  39. package/x/dist/utils/models/classes/class.x.js +1 -1
  40. package/x/bin/helpers/defaults.json +0 -28
@@ -9,8 +9,18 @@ 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
+ }
96
123
 
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
124
+ export function syncCliGeneratedModules(root = process.cwd(), { force = false } = {}) {
125
+ const results = []
126
+ fs.mkdirSync(CLI_GENERATED_DIR, { recursive: true })
127
+
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`,
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
+ }
143
+
144
+ execSync(
145
+ `bun build "${srcAbs}" --outfile "${mod.outfile}" --target node --format esm --external yaml`,
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
+ }
110
162
 
111
- return { synced: true, out: CLI_GENERATED_SCHEMA }
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 } = {}) {
@@ -116,11 +171,11 @@ export function syncPackageManifest(root = process.cwd(), { write = true } = {})
116
171
  const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
117
172
 
118
173
  if (!isCorePackageName(pkg.name)) {
119
- return { synced: false, reason: 'not @xrystal/core' }
174
+ return { synced: false, reason: `not ${packageDefaults.packageName}` }
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 = {
@@ -148,8 +203,7 @@ 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)
206
+ const { generated, defaults } = syncCliRuntime(root, { force: forceSchema })
153
207
  const toolchain = syncProjectToolchain(root, { write: writeToolchain })
154
208
  let manifest = { synced: false, reason: 'skipped' }
155
209
 
@@ -158,5 +212,5 @@ export function ensureProjectArtifacts(root = process.cwd(), options = {}) {
158
212
  manifest = syncPackageManifest(root, { write: true })
159
213
  }
160
214
 
161
- return { schema, defaults, toolchain, manifest }
215
+ return { generated, defaults, toolchain, manifest }
162
216
  }
@@ -14,10 +14,10 @@ export function resolveProjectRoot(startDir = process.cwd()) {
14
14
  const pkgPath = path.join(dir, 'package.json')
15
15
  if (fs.existsSync(pkgPath)) {
16
16
  const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
17
- if (pkg.name === '@xrystal/core') return dir
17
+ if (pkg.name === packageDefaults.packageName) return dir
18
18
 
19
19
  const deps = { ...pkg.dependencies, ...pkg.devDependencies }
20
- if (deps['@xrystal/core']) return dir
20
+ if (deps[packageDefaults.packageName]) return dir
21
21
  }
22
22
  dir = path.dirname(dir)
23
23
  }
@@ -48,11 +48,11 @@ export function readProjectPackageJson(root = resolveProjectRoot()) {
48
48
  export function getInstalledCoreVersion(root = resolveProjectRoot()) {
49
49
  const project = readProjectPackageJson(root)
50
50
  const declared =
51
- project.dependencies?.['@xrystal/core']
52
- ?? project.devDependencies?.['@xrystal/core']
51
+ project.dependencies?.[packageDefaults.packageName]
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,52 +1,17 @@
1
- import fs from 'node:fs'
2
- import path from 'node:path'
3
- import yaml from 'yaml'
1
+ import {
2
+ loadSeedFromBundledTmp,
3
+ seedFromTmp,
4
+ packageIdentityDefaults,
5
+ } from './.generated/seed-from-tmp.mjs'
4
6
 
5
- /**
6
- * CLI twin of source/utils/helpers/tmp/seed-from-tmp.ts
7
- * Layout seed = bundled x/tmp.yml (not defaults.json).
8
- */
9
- export function loadSeedLayoutFromBundledTmp(packageRoot, raw = {}) {
10
- const rootFolder = raw.packageRootFolder || 'x'
11
- const tmpFile = path.join(
12
- packageRoot,
13
- rootFolder,
14
- `${raw.tmpBaseName || 'tmp'}${raw.tmpExtension || '.yml'}`,
15
- )
7
+ export { loadSeedFromBundledTmp, seedFromTmp, packageIdentityDefaults }
16
8
 
17
- const fallback = {
18
- rootFolder,
19
- mainSourceFolder: './source',
20
- layoutPaths: Object.freeze({
21
- tests: 'tests',
22
- environments: 'environments',
23
- dist: 'dist',
24
- }),
25
- }
26
-
27
- if (!fs.existsSync(tmpFile)) return fallback
28
-
29
- try {
30
- const doc = yaml.parse(fs.readFileSync(tmpFile, 'utf8'))
31
- const paths = doc?.configs?.service?.paths ?? {}
32
- const special = paths.special ?? {}
33
- const sourceRaw = typeof paths.source === 'string' && paths.source.trim()
34
- ? paths.source.trim()
35
- : './source'
36
- const mainSourceFolder = sourceRaw.startsWith('.') ? sourceRaw : `./${sourceRaw}`
37
-
38
- return {
39
- rootFolder: typeof paths.root === 'string' && paths.root.trim()
40
- ? paths.root.trim().replace(/^\.\/+/, '')
41
- : rootFolder,
42
- mainSourceFolder,
43
- layoutPaths: Object.freeze({
44
- tests: special.tests || 'tests',
45
- environments: special.environments || 'environments',
46
- dist: special.dist || 'dist',
47
- }),
48
- }
49
- } catch {
50
- return fallback
9
+ export function loadSeedLayoutFromBundledTmp(_packageRoot = process.cwd(), _raw = {}) {
10
+ const seed = loadSeedFromBundledTmp()
11
+ return {
12
+ rootFolder: seed.rootFolder,
13
+ mainSourceFolder: seed.sourceFolder,
14
+ framework: seed.framework,
15
+ layoutPaths: Object.freeze({ ...seed.layout }),
51
16
  }
52
17
  }
@@ -1,4 +1,5 @@
1
1
  import { readTmpServiceBlock } from './tmp-schema.mjs'
2
+ import { packageDefaults } from './package-defaults.mjs'
2
3
  const PROTOCOL_ALIASES = {
3
4
  http: 'http',
4
5
  https: 'https',
@@ -26,7 +27,7 @@ export function summarizeLoaders(tmp = {}) {
26
27
  const service = configs.service ?? readTmpServiceBlock(configs)
27
28
 
28
29
  return {
29
- framework: service.framework ?? 'elysia',
30
+ framework: service.framework ?? packageDefaults.framework,
30
31
  protocols: resolveProtocolsFromConfig(service),
31
32
  service: service.name,
32
33
  items: [
@@ -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
  }
@@ -43,7 +41,7 @@ export function assertCoreTmpGuard(projectRoot, tmpFilePath) {
43
41
  const canonical = coreCanonicalTmpPath(projectRoot)
44
42
  if (path.resolve(tmpFilePath) !== path.resolve(canonical)) {
45
43
  throw new Error(
46
- `@xrystal/core: tmp.yml must stay at ${packageDefaults.packageRootFolder}/tmp.yml (expected ${canonical}, got ${tmpFilePath})`,
44
+ `${packageDefaults.packageName}: tmp.yml must stay at ${packageDefaults.packageRootFolder}/tmp.yml (expected ${canonical}, got ${tmpFilePath})`,
47
45
  )
48
46
  }
49
47
  }
@@ -58,7 +56,7 @@ function findStrayCoreTmpFiles(projectRoot, canonicalPath) {
58
56
  export function ensureCoreTmpEntry(projectRoot = process.cwd(), options = {}) {
59
57
  const resolvedRoot = path.resolve(projectRoot)
60
58
  if (!isCorePackageRoot(resolvedRoot)) {
61
- throw new Error('ensureCoreTmpEntry is only for @xrystal/core package root')
59
+ throw new Error(`ensureCoreTmpEntry is only for ${packageDefaults.packageName} package root`)
62
60
  }
63
61
 
64
62
  const canonical = coreCanonicalTmpPath(resolvedRoot)
@@ -66,7 +64,7 @@ export function ensureCoreTmpEntry(projectRoot = process.cwd(), options = {}) {
66
64
  if (strays.length > 0) {
67
65
  const rel = strays.map((p) => path.relative(resolvedRoot, p)).join(', ')
68
66
  throw new Error(
69
- `@xrystal/core: tmp.yml must only exist under ${packageDefaults.packageRootFolder}/. Remove extra copies: ${rel}`,
67
+ `${packageDefaults.packageName}: tmp.yml must only exist under ${packageDefaults.packageRootFolder}/. Remove extra copies: ${rel}`,
70
68
  )
71
69
  }
72
70
 
@@ -207,7 +205,7 @@ export function ensureTmpFile(projectRoot = process.cwd(), { patchServiceName =
207
205
  if (strays.length > 0) {
208
206
  const rel = strays.map((p) => path.relative(resolvedRoot, p)).join(', ')
209
207
  throw new Error(
210
- `@xrystal/core: tmp.yml must only exist under ${packageDefaults.packageRootFolder}/. Remove extra copies: ${rel}`,
208
+ `${packageDefaults.packageName}: tmp.yml must only exist under ${packageDefaults.packageRootFolder}/. Remove extra copies: ${rel}`,
211
209
  )
212
210
  }
213
211
 
@@ -237,7 +235,7 @@ export function ensureTmpFile(projectRoot = process.cwd(), { patchServiceName =
237
235
 
238
236
  const templatePath = getBundledCoreTmpPath()
239
237
  if (!fs.existsSync(templatePath)) {
240
- throw new Error('@xrystal/core bundled x/tmp.yml not found in package')
238
+ throw new Error(`${packageDefaults.packageName} bundled ${packageDefaults.packageRootFolder}/tmp.yml not found in package`)
241
239
  }
242
240
 
243
241
  const layout = buildTmpLayout(resolvedRoot, null, null)
@@ -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
  }
@@ -33,7 +33,7 @@ export function resolveToolchainPaths(options = {}) {
33
33
  outDir: `./${rootFolder}/${distSegment}`,
34
34
  include: [mainFolder],
35
35
  exclude: [`${rootFolder}/${testsSegment}`],
36
- pathAliasKey: packageDefaults.pathAliasKey ?? '@/*',
36
+ pathAliasKey: packageDefaults.pathAliasKey,
37
37
  pathAliasTarget: [`${mainFolder}/*`],
38
38
  eslintFiles: [`${mainFolder}/**/*.ts`, `${mainFolder}/**/*.tsx`],
39
39
  eslintIgnores: [
@@ -74,7 +74,7 @@ export function resolveRecommendedTsconfigFromProject(root = process.cwd()) {
74
74
  export function resolveTsconfigExtends(root) {
75
75
  const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'))
76
76
  if (pkg.name === packageDefaults.packageName) return './tsconfig.base.json'
77
- return '@xrystal/core/tsconfig.base.json'
77
+ return `${packageDefaults.packageName}/tsconfig.base.json`
78
78
  }
79
79
 
80
80
  export function mergeTsconfigWithLayout(recommended, existing = {}, extendsPath) {
@@ -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/main-cli.js CHANGED
@@ -51,7 +51,7 @@ const cli = new Command()
51
51
  cli
52
52
  .name(cliName)
53
53
  .description('xrystal core — microservice runtime library')
54
- .version(pkg.version, '-V, --version', 'Show @xrystal/core CLI version')
54
+ .version(pkg.version, '-V, --version', `Show ${pkg.name} CLI version`)
55
55
  .configureHelp({
56
56
  helpWidth: () => Math.min(100, Math.max(56, process.stdout.columns || 80)),
57
57
  sortSubcommands: true,
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
+ }
@@ -5,9 +5,10 @@ import { fileURLToPath } from 'node:url'
5
5
 
6
6
  import { resolveProjectRoot } from '../helpers/project-root.mjs'
7
7
  import { CLI_PRIMARY_NAME } from '../helpers/cli-identity.mjs'
8
+ import { packageDefaults } from '../helpers/package-defaults.mjs'
8
9
 
9
10
  const verifyScriptPath = path.join(path.dirname(fileURLToPath(import.meta.url)), 'verify-version-bump.mjs')
10
- const HOOK_MARKER = '@xrystal/core version-bump pre-commit'
11
+ const HOOK_MARKER = `${packageDefaults.packageName} version-bump pre-commit`
11
12
 
12
13
  export function resolveVerifyScriptPath() {
13
14
  return verifyScriptPath
@@ -2,6 +2,8 @@ import { execSync } from 'node:child_process'
2
2
  import fs from 'node:fs'
3
3
  import path from 'node:path'
4
4
 
5
+ import { packageDefaults } from '../helpers/package-defaults.mjs'
6
+
5
7
  export class PublishGuardError extends Error {
6
8
  constructor(message) {
7
9
  super(message)
@@ -9,6 +11,21 @@ export class PublishGuardError extends Error {
9
11
  }
10
12
  }
11
13
 
14
+ function distRelFromPackage(pkg) {
15
+ const main = String(pkg.main ?? '').replace(/^\.\//, '')
16
+ const match = main.match(/^(.+\/dist)\//)
17
+ if (match) return match[1]
18
+ return path.posix.join(packageDefaults.packageRootFolder, packageDefaults.layoutPaths.dist)
19
+ }
20
+
21
+ function resolveMainEntry(root, pkg) {
22
+ const main = String(pkg.main ?? '').replace(/^\.\//, '')
23
+ if (!main) {
24
+ throw new PublishGuardError('package.json main is empty')
25
+ }
26
+ return path.join(root, main)
27
+ }
28
+
12
29
  export function readPackage(root = process.cwd()) {
13
30
  return JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'))
14
31
  }
@@ -26,22 +43,23 @@ export function assertFilesListNoSource(pkg) {
26
43
 
27
44
  export function assertFilesListHasDist(pkg) {
28
45
  const files = Array.isArray(pkg.files) ? pkg.files : []
46
+ const distRel = distRelFromPackage(pkg)
29
47
  if (!files.some((entry) => String(entry).replace(/^\.\//, '').includes('dist'))) {
30
- throw new PublishGuardError('package.json files must include x/dist')
48
+ throw new PublishGuardError(`package.json files must include ${distRel}`)
31
49
  }
32
50
  }
33
51
 
34
52
  export function assertMainExportsPointToDist(pkg) {
35
53
  const main = String(pkg.main ?? '')
36
54
  if (!main.includes('/dist/')) {
37
- throw new PublishGuardError(`package.json main must point to x/dist (got ${main || 'empty'})`)
55
+ throw new PublishGuardError(`package.json main must point to dist (got ${main || 'empty'})`)
38
56
  }
39
57
  const exports = pkg.exports ?? {}
40
58
  for (const [key, value] of Object.entries(exports)) {
41
59
  if (key === './tsconfig.base.json') continue
42
60
  const target = typeof value === 'string' ? value : value?.default
43
61
  if (target && !String(target).includes('/dist/')) {
44
- throw new PublishGuardError(`exports[${key}] must point to x/dist (got ${target})`)
62
+ throw new PublishGuardError(`exports[${key}] must point to dist (got ${target})`)
45
63
  }
46
64
  }
47
65
  }
@@ -52,8 +70,8 @@ export function assertSourceAbsentOnDisk(root = process.cwd()) {
52
70
  }
53
71
  }
54
72
 
55
- export function countDistJs(root = process.cwd()) {
56
- const distDir = path.join(root, 'x', 'dist')
73
+ export function countDistJs(root = process.cwd(), pkg = readPackage(root)) {
74
+ const distDir = path.join(root, distRelFromPackage(pkg))
57
75
  if (!fs.existsSync(distDir)) return 0
58
76
  let count = 0
59
77
  const walk = (dir) => {
@@ -68,22 +86,25 @@ export function countDistJs(root = process.cwd()) {
68
86
  }
69
87
 
70
88
  export function assertDistTree(root = process.cwd(), minJs = 10) {
71
- const distIndex = path.join(root, 'x/dist/index.js')
72
- if (!fs.existsSync(distIndex)) {
73
- throw new PublishGuardError('x/dist/index.js missing — run build first')
89
+ const pkg = readPackage(root)
90
+ const entry = resolveMainEntry(root, pkg)
91
+ if (!fs.existsSync(entry)) {
92
+ throw new PublishGuardError(`${path.relative(root, entry) || entry} missing — run build first`)
74
93
  }
75
- const jsCount = countDistJs(root)
94
+ const jsCount = countDistJs(root, pkg)
76
95
  if (jsCount < minJs) {
77
- throw new PublishGuardError(`x/dist incomplete (${jsCount} .js files, need >= ${minJs})`)
96
+ throw new PublishGuardError(`dist incomplete (${jsCount} .js files, need >= ${minJs})`)
78
97
  }
79
98
  }
80
99
 
81
100
  export function assertDistMinified(root = process.cwd()) {
82
- const indexJs = fs.readFileSync(path.join(root, 'x/dist/index.js'), 'utf8')
101
+ const pkg = readPackage(root)
102
+ const entry = resolveMainEntry(root, pkg)
103
+ const indexJs = fs.readFileSync(entry, 'utf8')
83
104
  const lines = indexJs.split('\n').filter((line) => line.trim().length > 0)
84
105
  const looksReadable = lines.length > 3 && indexJs.includes("from './") && !indexJs.includes('from"')
85
106
  if (looksReadable) {
86
- throw new PublishGuardError('x/dist/index.js looks unminified — enable build.minify before publish')
107
+ throw new PublishGuardError(`${path.relative(root, entry)} looks unminified — enable build.minify before publish`)
87
108
  }
88
109
  }
89
110
 
@@ -92,8 +113,8 @@ export function assertNpmPackClean(root = process.cwd()) {
92
113
  if (/source\/.*\.ts/.test(dryRun) || /npm notice.*source\//.test(dryRun)) {
93
114
  throw new PublishGuardError('npm pack tarball lists source/ — TypeScript source must not ship')
94
115
  }
95
- if (!/x\/dist\/.*\.js/.test(dryRun)) {
96
- throw new PublishGuardError('npm pack tarball must include x/dist/**/*.js')
116
+ if (!/\/dist\/.*\.js/.test(dryRun)) {
117
+ throw new PublishGuardError('npm pack tarball must include dist/**/*.js')
97
118
  }
98
119
  return dryRun
99
120
  }
@@ -109,5 +130,5 @@ export function runPublishGuards(root = process.cwd(), { strictDisk = false } =
109
130
  assertSourceAbsentOnDisk(root)
110
131
  assertDistMinified(root)
111
132
  }
112
- return { pkg, jsCount: countDistJs(root) }
133
+ return { pkg, jsCount: countDistJs(root, pkg) }
113
134
  }
@@ -34,12 +34,12 @@ export function isCorePackageProject(root) {
34
34
  export function runReleasePrepare({ root = resolveProjectRoot(), dryRun = false, skipPrepare = false } = {}) {
35
35
  if (skipPrepare || !isCorePackageProject(root)) {
36
36
  if (!skipPrepare && !isCorePackageProject(root)) {
37
- console.log('\nRelease prepare skipped (not @xrystal/core).\n')
37
+ console.log(`\nRelease prepare skipped (not ${packageDefaults.packageName}).\n`)
38
38
  }
39
39
  return { skipped: true }
40
40
  }
41
41
 
42
- console.log('\nRelease prepare (@xrystal/core):\n')
42
+ console.log(`\nRelease prepare (${packageDefaults.packageName}):\n`)
43
43
  console.log(' (npm publish CI converts source → .js; git keeps TypeScript)\n')
44
44
 
45
45
  for (const step of PREPARE_STEPS) {
@@ -1,21 +1,16 @@
1
1
  #!/usr/bin/env node
2
- /**
3
- * Publish artifact only.
4
- * Authoring source of truth: source/utils/constants/defaults.json
5
- * Local CLI prefers the authored file; npm pack needs this copy under x/bin.
6
- */
7
- import fs from 'node:fs'
8
- import path from 'node:path'
2
+ import { syncCliRuntime } from '../helpers/project-artifacts.mjs'
9
3
 
10
4
  const root = process.cwd()
11
- const src = path.join(root, 'source/utils/constants/defaults.json')
12
- const dest = path.join(root, 'x/bin/helpers/defaults.json')
5
+ const result = syncCliRuntime(root, { force: process.argv.includes('--force') })
13
6
 
14
- if (!fs.existsSync(src)) {
15
- console.error('sync-cli-defaults: source/utils/constants/defaults.json missing')
16
- process.exit(1)
7
+ if (result.defaults.synced) {
8
+ console.log(`sync-cli-defaults: ${result.defaults.reason}`)
9
+ } else {
10
+ console.log(`sync-cli-defaults: ${result.defaults.reason ?? 'ok'}`)
17
11
  }
18
12
 
19
- fs.mkdirSync(path.dirname(dest), { recursive: true })
20
- fs.copyFileSync(src, dest)
21
- console.log('sync-cli-defaults: publish copy → x/bin/helpers/defaults.json')
13
+ for (const item of result.generated.results ?? []) {
14
+ const state = item.synced ? 'built' : (item.reason ?? 'ok')
15
+ console.log(`sync-cli-defaults: ${item.source} → ${state}`)
16
+ }
@@ -12,6 +12,12 @@
12
12
  "kafkaLogsTopic": "log",
13
13
  "pathAliasKey": "@/*",
14
14
  "eslintRestrictedImportDepth": 2,
15
+ "brand": {
16
+ "primary": "xrystal",
17
+ "secondary": "core",
18
+ "tagline": "microservice runtime library",
19
+ "capabilities": "loaders \u00b7 tmp.yml \u00b7 dto \u00b7 i18n \u00b7 multi-protocol \u00b7 scaffold"
20
+ },
15
21
  "tmpWatchDefaults": {
16
22
  "intervalMs": 500,
17
23
  "minIntervalMs": 100,
@@ -1,6 +1,7 @@
1
1
  import defaults from './defaults.json';
2
2
  export type PackageDefaults = typeof defaults & {
3
3
  mainSourceFolder: string;
4
+ framework: string;
4
5
  layoutPaths: {
5
6
  tests: string;
6
7
  environments: string;
@@ -22,8 +23,14 @@ export declare class Constants {
22
23
  static readonly cliName: string;
23
24
  static readonly cliBinNames: string[] & readonly string[];
24
25
  static readonly pathAliasKey: string;
25
- /** From bundled x/tmp.yml — used only when project tmp.yml omits paths */
26
+ static readonly brand: {
27
+ primary: string;
28
+ secondary: string;
29
+ tagline: string;
30
+ capabilities: string;
31
+ };
26
32
  static readonly mainSourceFolder: string;
33
+ static readonly framework: string;
27
34
  static readonly layoutPaths: {
28
35
  tests: string;
29
36
  environments: string;
@@ -31,5 +38,4 @@ export declare class Constants {
31
38
  };
32
39
  static readonly bundledCoreTmpPath: string;
33
40
  }
34
- /** Stable public re-exports — implementation lives in helpers/tmp. */
35
41
  export { seedFromTmp, loadSeedFromBundledTmp } from '../../utils/helpers/tmp/seed-from-tmp';