@xrystal/core 3.39.0 → 3.41.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 (42) hide show
  1. package/README.md +65 -34
  2. package/package.json +2 -4
  3. package/x/bin/commands/create.mjs +2 -1
  4. package/x/bin/commands/doctor.mjs +9 -7
  5. package/x/bin/commands/hooks.mjs +4 -2
  6. package/x/bin/commands/project.mjs +2 -1
  7. package/x/bin/commands/release.mjs +5 -3
  8. package/x/bin/commands/sync.mjs +51 -0
  9. package/x/bin/commands/tmp.mjs +4 -2
  10. package/x/bin/helpers/.generated/tmp-schema.mjs +110 -86
  11. package/x/bin/helpers/banner.mjs +4 -3
  12. package/x/bin/helpers/build-config.mjs +11 -2
  13. package/x/bin/helpers/cli-help.mjs +12 -11
  14. package/x/bin/helpers/cli-identity.mjs +7 -17
  15. package/x/bin/helpers/defaults.json +14 -30
  16. package/x/bin/helpers/package-defaults.mjs +43 -12
  17. package/x/bin/helpers/project-artifacts.mjs +9 -2
  18. package/x/bin/helpers/project-root.mjs +4 -4
  19. package/x/bin/helpers/seed-from-tmp.mjs +69 -0
  20. package/x/bin/helpers/tmp-config.mjs +2 -1
  21. package/x/bin/helpers/tmp-layout.mjs +5 -5
  22. package/x/bin/helpers/toolchain-config.mjs +7 -13
  23. package/x/bin/main-cli.js +3 -3
  24. package/x/bin/scripts/install-git-hooks.mjs +5 -3
  25. package/x/bin/scripts/release-prepare.mjs +2 -2
  26. package/x/bin/scripts/sync-cli-defaults.mjs +7 -2
  27. package/x/dist/utils/constants/defaults.json +14 -30
  28. package/x/dist/utils/constants/index.d.ts +19 -12
  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 +2 -0
  32. package/x/dist/utils/helpers/tmp/index.js +1 -1
  33. package/x/dist/utils/helpers/tmp/path-normalize.d.ts +8 -0
  34. package/x/dist/utils/helpers/tmp/path-normalize.js +1 -0
  35. package/x/dist/utils/helpers/tmp/seed-from-tmp.d.ts +10 -0
  36. package/x/dist/utils/helpers/tmp/seed-from-tmp.js +1 -0
  37. package/x/dist/utils/helpers/tmp/tmp-loader.js +1 -1
  38. package/x/dist/utils/helpers/tmp/tmp-schema.d.ts +0 -3
  39. package/x/dist/utils/helpers/tmp/tmp-schema.js +1 -1
  40. package/x/dist/utils/helpers/tmp/tmp-watch.js +1 -1
  41. package/x/dist/utils/models/classes/class.x.js +1 -1
  42. package/x/bin/commands/sync-toolchain.mjs +0 -43
@@ -0,0 +1,69 @@
1
+ import fs from 'node:fs'
2
+ import path from 'node:path'
3
+ import { fileURLToPath } from 'node:url'
4
+ import yaml from 'yaml'
5
+
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 ?? {}
62
+
63
+ 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),
68
+ }
69
+ }
@@ -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: [
@@ -43,7 +43,7 @@ export function assertCoreTmpGuard(projectRoot, tmpFilePath) {
43
43
  const canonical = coreCanonicalTmpPath(projectRoot)
44
44
  if (path.resolve(tmpFilePath) !== path.resolve(canonical)) {
45
45
  throw new Error(
46
- `@xrystal/core: tmp.yml must stay at ${packageDefaults.packageRootFolder}/tmp.yml (expected ${canonical}, got ${tmpFilePath})`,
46
+ `${packageDefaults.packageName}: tmp.yml must stay at ${packageDefaults.packageRootFolder}/tmp.yml (expected ${canonical}, got ${tmpFilePath})`,
47
47
  )
48
48
  }
49
49
  }
@@ -58,7 +58,7 @@ function findStrayCoreTmpFiles(projectRoot, canonicalPath) {
58
58
  export function ensureCoreTmpEntry(projectRoot = process.cwd(), options = {}) {
59
59
  const resolvedRoot = path.resolve(projectRoot)
60
60
  if (!isCorePackageRoot(resolvedRoot)) {
61
- throw new Error('ensureCoreTmpEntry is only for @xrystal/core package root')
61
+ throw new Error(`ensureCoreTmpEntry is only for ${packageDefaults.packageName} package root`)
62
62
  }
63
63
 
64
64
  const canonical = coreCanonicalTmpPath(resolvedRoot)
@@ -66,7 +66,7 @@ export function ensureCoreTmpEntry(projectRoot = process.cwd(), options = {}) {
66
66
  if (strays.length > 0) {
67
67
  const rel = strays.map((p) => path.relative(resolvedRoot, p)).join(', ')
68
68
  throw new Error(
69
- `@xrystal/core: tmp.yml must only exist under ${packageDefaults.packageRootFolder}/. Remove extra copies: ${rel}`,
69
+ `${packageDefaults.packageName}: tmp.yml must only exist under ${packageDefaults.packageRootFolder}/. Remove extra copies: ${rel}`,
70
70
  )
71
71
  }
72
72
 
@@ -207,7 +207,7 @@ export function ensureTmpFile(projectRoot = process.cwd(), { patchServiceName =
207
207
  if (strays.length > 0) {
208
208
  const rel = strays.map((p) => path.relative(resolvedRoot, p)).join(', ')
209
209
  throw new Error(
210
- `@xrystal/core: tmp.yml must only exist under ${packageDefaults.packageRootFolder}/. Remove extra copies: ${rel}`,
210
+ `${packageDefaults.packageName}: tmp.yml must only exist under ${packageDefaults.packageRootFolder}/. Remove extra copies: ${rel}`,
211
211
  )
212
212
  }
213
213
 
@@ -237,7 +237,7 @@ export function ensureTmpFile(projectRoot = process.cwd(), { patchServiceName =
237
237
 
238
238
  const templatePath = getBundledCoreTmpPath()
239
239
  if (!fs.existsSync(templatePath)) {
240
- throw new Error('@xrystal/core bundled x/tmp.yml not found in package')
240
+ throw new Error(`${packageDefaults.packageName} bundled ${packageDefaults.packageRootFolder}/tmp.yml not found in package`)
241
241
  }
242
242
 
243
243
  const layout = buildTmpLayout(resolvedRoot, null, null)
@@ -1,3 +1,4 @@
1
+ import { CLI_PRIMARY_NAME } from './cli-identity.mjs'
1
2
  import fs from 'node:fs'
2
3
  import path from 'node:path'
3
4
 
@@ -32,7 +33,7 @@ export function resolveToolchainPaths(options = {}) {
32
33
  outDir: `./${rootFolder}/${distSegment}`,
33
34
  include: [mainFolder],
34
35
  exclude: [`${rootFolder}/${testsSegment}`],
35
- pathAliasKey: packageDefaults.tsconfigDefaults?.pathAliasKey ?? '@/*',
36
+ pathAliasKey: packageDefaults.pathAliasKey,
36
37
  pathAliasTarget: [`${mainFolder}/*`],
37
38
  eslintFiles: [`${mainFolder}/**/*.ts`, `${mainFolder}/**/*.tsx`],
38
39
  eslintIgnores: [
@@ -51,23 +52,16 @@ export function resolveToolchainPathsFromProject(root = process.cwd()) {
51
52
 
52
53
  export function resolveRecommendedTsconfig(options = {}) {
53
54
  const paths = resolveToolchainPaths(options)
54
- const baseOptions = packageDefaults.tsconfigDefaults?.compilerOptions ?? {}
55
-
55
+ // compilerOptions language lives in tsconfig.base.json (extends);
56
+ // sync only overlays layout fields from tmp.yml
56
57
  return {
57
58
  include: [...paths.include],
58
59
  exclude: [...paths.exclude],
59
60
  compilerOptions: {
60
- target: 'ESNext',
61
- module: 'ESNext',
62
- moduleResolution: 'Bundler',
63
61
  baseUrl: '.',
64
62
  paths: { [paths.pathAliasKey]: paths.pathAliasTarget },
65
63
  rootDir: paths.mainSourceFolder,
66
64
  outDir: paths.outDir,
67
- esModuleInterop: true,
68
- forceConsistentCasingInFileNames: true,
69
- skipLibCheck: true,
70
- ...baseOptions,
71
65
  },
72
66
  }
73
67
  }
@@ -80,7 +74,7 @@ export function resolveRecommendedTsconfigFromProject(root = process.cwd()) {
80
74
  export function resolveTsconfigExtends(root) {
81
75
  const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'))
82
76
  if (pkg.name === packageDefaults.packageName) return './tsconfig.base.json'
83
- return '@xrystal/core/tsconfig.base.json'
77
+ return `${packageDefaults.packageName}/tsconfig.base.json`
84
78
  }
85
79
 
86
80
  export function mergeTsconfigWithLayout(recommended, existing = {}, extendsPath) {
@@ -148,7 +142,7 @@ export function auditTsconfigAlignment(root, options = null) {
148
142
  const recommended = resolveRecommendedTsconfig(resolvedOptions)
149
143
  const onDisk = readProjectTsconfig(root)
150
144
  if (!onDisk) {
151
- return { ok: false, missing: true, notes: ['tsconfig.json not found — run xcore sync-toolchain'] }
145
+ return { ok: false, missing: true, notes: [`tsconfig.json not found — run ${CLI_PRIMARY_NAME} sync`] }
152
146
  }
153
147
 
154
148
  const notes = []
@@ -175,7 +169,7 @@ export function auditTsconfigAlignment(root, options = null) {
175
169
 
176
170
  export function createEslintConfigFromProject(root = process.cwd(), tseslint) {
177
171
  const paths = resolveToolchainPathsFromProject(root)
178
- const depth = packageDefaults.eslintDefaults?.restrictedImportDepth ?? 2
172
+ const depth = packageDefaults.eslintRestrictedImportDepth ?? 2
179
173
  const deepRelative = '../'.repeat(depth + 1)
180
174
 
181
175
  return tseslint.config(
package/x/bin/main-cli.js CHANGED
@@ -7,7 +7,7 @@ import { registerCreateCommand } from './commands/create.mjs'
7
7
  import { registerDoctorCommand } from './commands/doctor.mjs'
8
8
  import { registerProjectCommands } from './commands/project.mjs'
9
9
  import { registerTmpCommand } from './commands/tmp.mjs'
10
- import { registerSyncToolchainCommand } from './commands/sync-toolchain.mjs'
10
+ import { registerSyncCommand } from './commands/sync.mjs'
11
11
  import { registerTagCommand, registerVersionCommand } from './commands/release.mjs'
12
12
  import { registerHooksCommand } from './commands/hooks.mjs'
13
13
  import { printBanner, shouldShowBanner } from './helpers/banner.mjs'
@@ -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,
@@ -65,7 +65,7 @@ registerVersionCommand(cli, cliContext)
65
65
  registerTagCommand(cli, cliContext)
66
66
  registerDoctorCommand(cli, cliContext)
67
67
  registerTmpCommand(cli, cliContext)
68
- registerSyncToolchainCommand(cli, cliContext)
68
+ registerSyncCommand(cli, cliContext)
69
69
  registerHooksCommand(cli, cliContext)
70
70
  registerProjectCommands(cli, cliContext)
71
71
 
@@ -4,9 +4,11 @@ import path from 'node:path'
4
4
  import { fileURLToPath } from 'node:url'
5
5
 
6
6
  import { resolveProjectRoot } from '../helpers/project-root.mjs'
7
+ import { CLI_PRIMARY_NAME } from '../helpers/cli-identity.mjs'
8
+ import { packageDefaults } from '../helpers/package-defaults.mjs'
7
9
 
8
10
  const verifyScriptPath = path.join(path.dirname(fileURLToPath(import.meta.url)), 'verify-version-bump.mjs')
9
- const HOOK_MARKER = '@xrystal/core version-bump pre-commit'
11
+ const HOOK_MARKER = `${packageDefaults.packageName} version-bump pre-commit`
10
12
 
11
13
  export function resolveVerifyScriptPath() {
12
14
  return verifyScriptPath
@@ -50,7 +52,7 @@ set -e
50
52
  }
51
53
 
52
54
 
53
- export function ensureHooksInstallScript(projectRoot, cliName = 'xcore') {
55
+ export function ensureHooksInstallScript(projectRoot, cliName = CLI_PRIMARY_NAME) {
54
56
  const packageJsonPath = path.join(projectRoot, 'package.json')
55
57
  if (!fs.existsSync(packageJsonPath)) return false
56
58
 
@@ -66,7 +68,7 @@ export function ensureHooksInstallScript(projectRoot, cliName = 'xcore') {
66
68
  }
67
69
 
68
70
  /** Install pre-commit hook + package.json hooks:install script (create + manual). */
69
- export function setupProjectGitHooks(projectRoot, { cliName = 'xcore' } = {}) {
71
+ export function setupProjectGitHooks(projectRoot, { cliName = CLI_PRIMARY_NAME } = {}) {
70
72
  ensureHooksInstallScript(projectRoot, cliName)
71
73
  const refreshed = isGitHookInstalled(projectRoot)
72
74
  const result = installGitHooks(projectRoot)
@@ -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,4 +1,9 @@
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
+ */
2
7
  import fs from 'node:fs'
3
8
  import path from 'node:path'
4
9
 
@@ -7,10 +12,10 @@ const src = path.join(root, 'source/utils/constants/defaults.json')
7
12
  const dest = path.join(root, 'x/bin/helpers/defaults.json')
8
13
 
9
14
  if (!fs.existsSync(src)) {
10
- console.error('sync-cli-defaults: source defaults.json missing')
15
+ console.error('sync-cli-defaults: source/utils/constants/defaults.json missing')
11
16
  process.exit(1)
12
17
  }
13
18
 
14
19
  fs.mkdirSync(path.dirname(dest), { recursive: true })
15
20
  fs.copyFileSync(src, dest)
16
- console.log('sync-cli-defaults: copied → x/bin/helpers/defaults.json')
21
+ console.log('sync-cli-defaults: publish copy → x/bin/helpers/defaults.json')
@@ -1,13 +1,21 @@
1
1
  {
2
2
  "packageName": "@xrystal/core",
3
3
  "packageRootFolder": "x",
4
+ "cliName": "xry",
5
+ "cliBinNames": [
6
+ "xry"
7
+ ],
4
8
  "tmpBaseName": "tmp",
5
9
  "tmpExtension": ".yml",
6
- "mainSourceFolder": "./source",
7
- "layoutPaths": {
8
- "tests": "tests",
9
- "environments": "environments",
10
- "dist": "dist"
10
+ "templateRepoUri": "https://github.com/xdloper/api-gpt-svc",
11
+ "publicFolderName": "public",
12
+ "kafkaLogsTopic": "log",
13
+ "pathAliasKey": "@/*",
14
+ "eslintRestrictedImportDepth": 2,
15
+ "tmpWatchDefaults": {
16
+ "intervalMs": 500,
17
+ "minIntervalMs": 100,
18
+ "maxIntervalMs": 10000
11
19
  },
12
20
  "buildDefaults": {
13
21
  "tsconfig": "tsconfig.json",
@@ -16,29 +24,5 @@
16
24
  "declarations": false,
17
25
  "sourcemap": false,
18
26
  "minify": false
19
- },
20
- "tsconfigDefaults": {
21
- "pathAliasKey": "@/*",
22
- "compilerOptions": {
23
- "noEmit": false,
24
- "noEmitOnError": false,
25
- "declaration": true,
26
- "emitDeclarationOnly": false,
27
- "sourceMap": false,
28
- "declarationMap": false,
29
- "strict": true,
30
- "noImplicitAny": true
31
- }
32
- },
33
- "eslintDefaults": {
34
- "restrictedImportDepth": 2
35
- },
36
- "tmpWatchDefaults": {
37
- "intervalMs": 500,
38
- "minIntervalMs": 100,
39
- "maxIntervalMs": 10000
40
- },
41
- "publicFolderName": "public",
42
- "kafkaLogsTopic": "log",
43
- "templateRepoUri": "https://github.com/xdloper/api-gpt-svc"
27
+ }
44
28
  }
@@ -1,8 +1,15 @@
1
1
  import defaults from './defaults.json';
2
- export type PackageDefaults = typeof defaults;
3
- export declare const packageDefaults: Readonly<PackageDefaults & {
4
- layoutPaths: Readonly<PackageDefaults["layoutPaths"]>;
5
- }>;
2
+ export type PackageDefaults = typeof defaults & {
3
+ mainSourceFolder: string;
4
+ framework: string;
5
+ layoutPaths: {
6
+ tests: string;
7
+ environments: string;
8
+ dist: string;
9
+ };
10
+ cliBinNames: readonly string[];
11
+ };
12
+ export declare const packageDefaults: Readonly<PackageDefaults>;
6
13
  export declare const coreVersionPattern: RegExp;
7
14
  export declare const semverVersionPattern: RegExp;
8
15
  export declare class Constants {
@@ -10,18 +17,18 @@ export declare class Constants {
10
17
  static readonly packageRootFolder: string;
11
18
  static readonly tmpBaseName: string;
12
19
  static readonly tmpExtension: string;
20
+ static readonly publicFolderName: string;
21
+ static readonly kafkaLogsTopic: string;
22
+ static readonly templateRepoUri: string;
23
+ static readonly cliName: string;
24
+ static readonly cliBinNames: string[] & readonly string[];
25
+ static readonly pathAliasKey: string;
13
26
  static readonly mainSourceFolder: string;
14
27
  static readonly layoutPaths: {
15
28
  tests: string;
16
29
  environments: string;
17
30
  dist: string;
18
- } & Readonly<{
19
- tests: string;
20
- environments: string;
21
- dist: string;
22
- }>;
23
- static readonly publicFolderName: string;
24
- static readonly kafkaLogsTopic: string;
25
- static readonly templateRepoUri: string;
31
+ };
26
32
  static readonly bundledCoreTmpPath: string;
27
33
  }
34
+ export { seedFromTmp, loadSeedFromBundledTmp } from '../../utils/helpers/tmp/seed-from-tmp';
@@ -1 +1 @@
1
- import e from"node:path";import{packageRootDir as a}from"../../utils/package-root";import t from"./defaults.json" with { type: 'json' };export const packageDefaults=Object.freeze({...t,layoutPaths:Object.freeze({...t.layoutPaths}),buildDefaults:Object.freeze({...t.buildDefaults}),tsconfigDefaults:Object.freeze({...t.tsconfigDefaults,compilerOptions:Object.freeze({...t.tsconfigDefaults.compilerOptions})}),eslintDefaults:Object.freeze({...t.eslintDefaults}),tmpWatchDefaults:Object.freeze({...t.tmpWatchDefaults})}),coreVersionPattern=/^\d{2}\.\d{2}\.\d{2}-v\d+$/,semverVersionPattern=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z-.]+)?(?:\+[0-9A-Za-z-.]+)?$/;const o=`${packageDefaults.tmpBaseName}${packageDefaults.tmpExtension}`;export class Constants{static packageName=packageDefaults.packageName;static packageRootFolder=packageDefaults.packageRootFolder;static tmpBaseName=packageDefaults.tmpBaseName;static tmpExtension=packageDefaults.tmpExtension;static mainSourceFolder=packageDefaults.mainSourceFolder;static layoutPaths=packageDefaults.layoutPaths;static publicFolderName=packageDefaults.publicFolderName;static kafkaLogsTopic=packageDefaults.kafkaLogsTopic;static templateRepoUri=packageDefaults.templateRepoUri;static bundledCoreTmpPath=e.join(a,packageDefaults.packageRootFolder,o)}
1
+ import n from"node:path";import{packageRootDir as q}from"../../utils/package-root";import b from"./defaults.json" with { type: 'json' };import{seedFromTmp as j}from"../../utils/helpers/tmp/seed-from-tmp";export const packageDefaults=Object.freeze({...b,mainSourceFolder:j.sourceFolder,framework:j.framework,layoutPaths:Object.freeze({...j.layout}),buildDefaults:Object.freeze({...b.buildDefaults}),tmpWatchDefaults:Object.freeze({...b.tmpWatchDefaults}),cliBinNames:Object.freeze([...b.cliBinNames??[b.cliName]])}),coreVersionPattern=/^\d{2}\.\d{2}\.\d{2}-v\d+$/,semverVersionPattern=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z-.]+)?(?:\+[0-9A-Za-z-.]+)?$/;const v=`${packageDefaults.tmpBaseName}${packageDefaults.tmpExtension}`;export class Constants{static packageName=packageDefaults.packageName;static packageRootFolder=packageDefaults.packageRootFolder;static tmpBaseName=packageDefaults.tmpBaseName;static tmpExtension=packageDefaults.tmpExtension;static publicFolderName=packageDefaults.publicFolderName;static kafkaLogsTopic=packageDefaults.kafkaLogsTopic;static templateRepoUri=packageDefaults.templateRepoUri;static cliName=packageDefaults.cliName;static cliBinNames=packageDefaults.cliBinNames;static pathAliasKey=packageDefaults.pathAliasKey;static mainSourceFolder=packageDefaults.mainSourceFolder;static layoutPaths=packageDefaults.layoutPaths;static bundledCoreTmpPath=n.join(q,packageDefaults.packageRootFolder,v)}export{seedFromTmp,loadSeedFromBundledTmp}from"../../utils/helpers/tmp/seed-from-tmp";
@@ -1 +1 @@
1
- import U from"node:fs";import I from"node:path";import z from"yaml";import{Constants as J}from"../../../utils/constants";import{findAllFilesRecursively as L,findFileRecursively as A}from"../../../utils/helpers/core/paths";import{normalizeTmpDocument as D,readTmpServiceBlock as B,normalizeRootFolder as b,normalizeSourceFolder as x,resolveServiceLayoutPaths as k}from"../../../utils/helpers/tmp/tmp-schema";function M(E,q){return`${E}${q.startsWith(".")?q:`.${q}`}`}export function coreCanonicalTmpPath(E=process.cwd()){return I.join(I.resolve(E),J.packageRootFolder,M(J.tmpBaseName,J.tmpExtension))}export function assertCoreTmpGuard(E,q){if(!isCorePackageRoot(E))return;const H=coreCanonicalTmpPath(E);if(I.resolve(q)!==I.resolve(H))throw Error(`@xrystal/core: tmp.yml must stay at ${J.packageRootFolder}/tmp.yml (expected ${H}, got ${q})`)}function N(E,q){const H=I.resolve(E),K=I.resolve(q);return L(H,J.tmpBaseName,J.tmpExtension).filter((Q)=>I.resolve(Q)!==K)}export function ensureCoreTmpEntry(E=process.cwd(),q={}){const H=I.resolve(E);if(!isCorePackageRoot(H))throw Error("ensureCoreTmpEntry is only for @xrystal/core package root");const K=coreCanonicalTmpPath(H),Q=N(H,K);if(Q.length>0){const X=Q.map((W)=>I.relative(H,W)).join(", ");throw Error(`@xrystal/core: tmp.yml must only exist under ${J.packageRootFolder}/. Remove extra copies: ${X}`)}if(U.existsSync(K)){assertCoreTmpGuard(H,K);return{tmpFilePath:K,created:!1,layout:buildTmpLayout(H,_(K),K)}}return ensureTmpFile(H,{...q,patchServiceName:!1})}function S(E,q,H){const K=I.resolve(E);if(isCorePackageRoot(K)){const Q=coreCanonicalTmpPath(K);return U.existsSync(Q)?Q:null}return A(K,q,H)}function _(E){return z.parse(U.readFileSync(E,"utf8"))}export function isCorePackageRoot(E){const q=I.join(I.resolve(E),"package.json");if(!U.existsSync(q))return!1;try{return JSON.parse(U.readFileSync(q,"utf8")).name===J.packageName}catch{return!1}}export function resolveRootFolderPath(E,q,H){const K=D(E).configs,Q=B(K);if(Q.paths?.root?.trim())return b(Q.paths.root);const X=E.project;if(typeof X?.name==="string"&&X.name.trim())return X.name.trim();const W=I.relative(I.resolve(H),I.dirname(I.resolve(q)));if(W&&W!==".")return W;return J.packageRootFolder}export function resolveLayoutPaths(E){const q=B(E);return k(q)}export function resolveMainFolderPath(E){const q=B(E);if(q.paths?.source?.trim())return x(q.paths.source);return J.mainSourceFolder}export function buildTmpLayout(E,q,H){const K=I.resolve(E),Q=q?D(q).configs:void 0,X=q&&H&&!isCorePackageRoot(K)?resolveRootFolderPath(q,H,K):J.packageRootFolder,W=I.join(K,X),Y=resolveLayoutPaths(Q),V=resolveMainFolderPath(Q),Z={tests:I.join(W,Y.tests),environments:I.join(W,Y.environments),dist:I.join(W,Y.dist)};return{projectRoot:K,rootFolderPath:X,rootFolderAbs:W,tmpFilePath:H,mainFolderPath:V,paths:Y,pathsAbs:Z}}export function resolveTmpLayout(E=process.cwd(),q={}){const H=q.tmpFileName??J.tmpBaseName,K=q.ext??J.tmpExtension,Q=S(E,H,K);if(!Q)throw Error(`${M(H,K)} not found under ${I.resolve(E)}`);if(isCorePackageRoot(I.resolve(E)))assertCoreTmpGuard(E,Q);return buildTmpLayout(E,_(Q),Q)}export function resolveTmpLayoutOrDefaults(E=process.cwd()){const q=S(E,J.tmpBaseName,J.tmpExtension);if(!q)return buildTmpLayout(E,null,null);return buildTmpLayout(E,_(q),q)}export function resolveBundledCoreTmpPath(E=process.cwd()){if(U.existsSync(J.bundledCoreTmpPath))return J.bundledCoreTmpPath;let q=I.resolve(E);while(q!==I.dirname(q)){const H=I.join(q,"node_modules","@xrystal","core",J.packageRootFolder,M(J.tmpBaseName,J.tmpExtension));if(U.existsSync(H))return H;const K=I.join(q,"package.json");if(U.existsSync(K)){if(JSON.parse(U.readFileSync(K,"utf8")).name===J.packageName){const X=I.join(q,J.packageRootFolder,M(J.tmpBaseName,J.tmpExtension));if(U.existsSync(X))return X}}q=I.dirname(q)}throw Error("@xrystal/core bundled x/tmp.yml not found")}export function ownerTmpFilePath(E=process.cwd(),q){const H=q??resolveTmpLayoutOrDefaults(E);return I.join(H.rootFolderAbs,M(J.tmpBaseName,J.tmpExtension))}export function ensureTmpFile(E=process.cwd(),q={}){const H=I.resolve(E),K=q.patchServiceName??!0;if(isCorePackageRoot(H)){const V=coreCanonicalTmpPath(H),Z=N(H,V);if(Z.length>0){const $=Z.map((w)=>I.relative(H,w)).join(", ");throw Error(`@xrystal/core: tmp.yml must only exist under ${J.packageRootFolder}/. Remove extra copies: ${$}`)}if(U.existsSync(V)){assertCoreTmpGuard(H,V);return{tmpFilePath:V,created:!1,layout:buildTmpLayout(H,_(V),V)}}}else{const V=A(H,J.tmpBaseName,J.tmpExtension);if(V)return{tmpFilePath:V,created:!1,layout:buildTmpLayout(H,_(V),V)}}const Q=q.templatePath??resolveBundledCoreTmpPath(H);if(!U.existsSync(Q))throw Error("@xrystal/core bundled x/tmp.yml not found");const X=buildTmpLayout(H,null,null);U.mkdirSync(X.rootFolderAbs,{recursive:!0});const W=ownerTmpFilePath(H,X);let Y=U.readFileSync(Q,"utf8");if(K)try{const V=I.join(H,"package.json");if(U.existsSync(V)){const Z=JSON.parse(U.readFileSync(V,"utf8")),$=typeof Z.name==="string"?Z.name.replace(/^@/,"").replace(/\//g,"-"):null;if($){const w=z.parse(Y),G=w.configs??{},O=G.service;if(typeof O==="object"&&O!==null&&!Array.isArray(O))O.name=$;else G.service={name:$};w.configs=G;Y=z.stringify(w)}}}catch{}U.writeFileSync(W,Y);return{tmpFilePath:W,created:!0,layout:buildTmpLayout(H,_(W),W)}}export function resolveTmpLayoutEnsured(E=process.cwd()){return ensureTmpFile(E).layout}
1
+ import U from"node:fs";import J from"node:path";import z from"yaml";import{Constants as I}from"../../../utils/constants";import{findAllFilesRecursively as L,findFileRecursively as A}from"../../../utils/helpers/core/paths";import{normalizeTmpDocument as D,readTmpServiceBlock as B,normalizeRootFolder as b,normalizeSourceFolder as x,resolveServiceLayoutPaths as k}from"../../../utils/helpers/tmp/tmp-schema";function M(E,q){return`${E}${q.startsWith(".")?q:`.${q}`}`}export function coreCanonicalTmpPath(E=process.cwd()){return J.join(J.resolve(E),I.packageRootFolder,M(I.tmpBaseName,I.tmpExtension))}export function assertCoreTmpGuard(E,q){if(!isCorePackageRoot(E))return;const H=coreCanonicalTmpPath(E);if(J.resolve(q)!==J.resolve(H))throw Error(`${I.packageName}: tmp.yml must stay at ${I.packageRootFolder}/tmp.yml (expected ${H}, got ${q})`)}function N(E,q){const H=J.resolve(E),K=J.resolve(q);return L(H,I.tmpBaseName,I.tmpExtension).filter((Q)=>J.resolve(Q)!==K)}export function ensureCoreTmpEntry(E=process.cwd(),q={}){const H=J.resolve(E);if(!isCorePackageRoot(H))throw Error(`ensureCoreTmpEntry is only for ${I.packageName} package root`);const K=coreCanonicalTmpPath(H),Q=N(H,K);if(Q.length>0){const X=Q.map((W)=>J.relative(H,W)).join(", ");throw Error(`${I.packageName}: tmp.yml must only exist under ${I.packageRootFolder}/. Remove extra copies: ${X}`)}if(U.existsSync(K)){assertCoreTmpGuard(H,K);return{tmpFilePath:K,created:!1,layout:buildTmpLayout(H,_(K),K)}}return ensureTmpFile(H,{...q,patchServiceName:!1})}function S(E,q,H){const K=J.resolve(E);if(isCorePackageRoot(K)){const Q=coreCanonicalTmpPath(K);return U.existsSync(Q)?Q:null}return A(K,q,H)}function _(E){return z.parse(U.readFileSync(E,"utf8"))}export function isCorePackageRoot(E){const q=J.join(J.resolve(E),"package.json");if(!U.existsSync(q))return!1;try{return JSON.parse(U.readFileSync(q,"utf8")).name===I.packageName}catch{return!1}}export function resolveRootFolderPath(E,q,H){const K=D(E).configs,Q=B(K);if(Q.paths?.root?.trim())return b(Q.paths.root);const X=E.project;if(typeof X?.name==="string"&&X.name.trim())return X.name.trim();const W=J.relative(J.resolve(H),J.dirname(J.resolve(q)));if(W&&W!==".")return W;return I.packageRootFolder}export function resolveLayoutPaths(E){const q=B(E);return k(q)}export function resolveMainFolderPath(E){const q=B(E);if(q.paths?.source?.trim())return x(q.paths.source);return I.mainSourceFolder}export function buildTmpLayout(E,q,H){const K=J.resolve(E),Q=q?D(q).configs:void 0,X=q&&H&&!isCorePackageRoot(K)?resolveRootFolderPath(q,H,K):I.packageRootFolder,W=J.join(K,X),Y=resolveLayoutPaths(Q),V=resolveMainFolderPath(Q),Z={tests:J.join(W,Y.tests),environments:J.join(W,Y.environments),dist:J.join(W,Y.dist)};return{projectRoot:K,rootFolderPath:X,rootFolderAbs:W,tmpFilePath:H,mainFolderPath:V,paths:Y,pathsAbs:Z}}export function resolveTmpLayout(E=process.cwd(),q={}){const H=q.tmpFileName??I.tmpBaseName,K=q.ext??I.tmpExtension,Q=S(E,H,K);if(!Q)throw Error(`${M(H,K)} not found under ${J.resolve(E)}`);if(isCorePackageRoot(J.resolve(E)))assertCoreTmpGuard(E,Q);return buildTmpLayout(E,_(Q),Q)}export function resolveTmpLayoutOrDefaults(E=process.cwd()){const q=S(E,I.tmpBaseName,I.tmpExtension);if(!q)return buildTmpLayout(E,null,null);return buildTmpLayout(E,_(q),q)}export function resolveBundledCoreTmpPath(E=process.cwd()){if(U.existsSync(I.bundledCoreTmpPath))return I.bundledCoreTmpPath;let q=J.resolve(E);while(q!==J.dirname(q)){const H=J.join(q,"node_modules","@xrystal","core",I.packageRootFolder,M(I.tmpBaseName,I.tmpExtension));if(U.existsSync(H))return H;const K=J.join(q,"package.json");if(U.existsSync(K)){if(JSON.parse(U.readFileSync(K,"utf8")).name===I.packageName){const X=J.join(q,I.packageRootFolder,M(I.tmpBaseName,I.tmpExtension));if(U.existsSync(X))return X}}q=J.dirname(q)}throw Error(`${I.packageName} bundled ${I.packageRootFolder}/tmp.yml not found`)}export function ownerTmpFilePath(E=process.cwd(),q){const H=q??resolveTmpLayoutOrDefaults(E);return J.join(H.rootFolderAbs,M(I.tmpBaseName,I.tmpExtension))}export function ensureTmpFile(E=process.cwd(),q={}){const H=J.resolve(E),K=q.patchServiceName??!0;if(isCorePackageRoot(H)){const V=coreCanonicalTmpPath(H),Z=N(H,V);if(Z.length>0){const $=Z.map((w)=>J.relative(H,w)).join(", ");throw Error(`${I.packageName}: tmp.yml must only exist under ${I.packageRootFolder}/. Remove extra copies: ${$}`)}if(U.existsSync(V)){assertCoreTmpGuard(H,V);return{tmpFilePath:V,created:!1,layout:buildTmpLayout(H,_(V),V)}}}else{const V=A(H,I.tmpBaseName,I.tmpExtension);if(V)return{tmpFilePath:V,created:!1,layout:buildTmpLayout(H,_(V),V)}}const Q=q.templatePath??resolveBundledCoreTmpPath(H);if(!U.existsSync(Q))throw Error(`${I.packageName} bundled ${I.packageRootFolder}/tmp.yml not found`);const X=buildTmpLayout(H,null,null);U.mkdirSync(X.rootFolderAbs,{recursive:!0});const W=ownerTmpFilePath(H,X);let Y=U.readFileSync(Q,"utf8");if(K)try{const V=J.join(H,"package.json");if(U.existsSync(V)){const Z=JSON.parse(U.readFileSync(V,"utf8")),$=typeof Z.name==="string"?Z.name.replace(/^@/,"").replace(/\//g,"-"):null;if($){const w=z.parse(Y),G=w.configs??{},O=G.service;if(typeof O==="object"&&O!==null&&!Array.isArray(O))O.name=$;else G.service={name:$};w.configs=G;Y=z.stringify(w)}}}catch{}U.writeFileSync(W,Y);return{tmpFilePath:W,created:!0,layout:buildTmpLayout(H,_(W),W)}}export function resolveTmpLayoutEnsured(E=process.cwd()){return ensureTmpFile(E).layout}
@@ -3,3 +3,5 @@ export { getTmpLoader, getTmpLoaderPath, getTmpSnapshot, onTmpReload, resetTmpLo
3
3
  export { bindLoaderTmpSync, type ITmpSyncLoader, } from '../../../utils/helpers/tmp/loader-tmp-sync';
4
4
  export { resolveTmpWatchIntervalMs } from '../../../utils/helpers/tmp/tmp-watch';
5
5
  export { normalizeTmpDocument, normalizeRootFolder, normalizeSourceFolder, readTmpCoreBlock, readTmpServiceBlock, resolveServiceLayoutPaths, resolveTmpRuntimeConfigs, } from '../../../utils/helpers/tmp/tmp-schema';
6
+ export { loadSeedFromBundledTmp, seedFromTmp, type SeedFromTmp, type SeedLayoutPaths, } from '../../../utils/helpers/tmp/seed-from-tmp';
7
+ export { normalizeLayoutPaths, type LayoutPaths, } from '../../../utils/helpers/tmp/path-normalize';
@@ -1 +1 @@
1
- export{setRuntimeTmpConfigs,getRuntimeTmpConfigs,onRuntimeTmpChange,notifyRuntimeTmpChange,clearRuntimeTmpConfigs}from"../../../utils/helpers/tmp/runtime-tmp";export{getTmpLoader,getTmpLoaderPath,getTmpSnapshot,onTmpReload,resetTmpLoaderForTests,stopTmpLoader}from"../../../utils/helpers/tmp/tmp-loader";export{bindLoaderTmpSync}from"../../../utils/helpers/tmp/loader-tmp-sync";export{resolveTmpWatchIntervalMs}from"../../../utils/helpers/tmp/tmp-watch";export{normalizeTmpDocument,normalizeRootFolder,normalizeSourceFolder,readTmpCoreBlock,readTmpServiceBlock,resolveServiceLayoutPaths,resolveTmpRuntimeConfigs}from"../../../utils/helpers/tmp/tmp-schema";
1
+ export{setRuntimeTmpConfigs,getRuntimeTmpConfigs,onRuntimeTmpChange,notifyRuntimeTmpChange,clearRuntimeTmpConfigs}from"../../../utils/helpers/tmp/runtime-tmp";export{getTmpLoader,getTmpLoaderPath,getTmpSnapshot,onTmpReload,resetTmpLoaderForTests,stopTmpLoader}from"../../../utils/helpers/tmp/tmp-loader";export{bindLoaderTmpSync}from"../../../utils/helpers/tmp/loader-tmp-sync";export{resolveTmpWatchIntervalMs}from"../../../utils/helpers/tmp/tmp-watch";export{normalizeTmpDocument,normalizeRootFolder,normalizeSourceFolder,readTmpCoreBlock,readTmpServiceBlock,resolveServiceLayoutPaths,resolveTmpRuntimeConfigs}from"../../../utils/helpers/tmp/tmp-schema";export{loadSeedFromBundledTmp,seedFromTmp}from"../../../utils/helpers/tmp/seed-from-tmp";export{normalizeLayoutPaths}from"../../../utils/helpers/tmp/path-normalize";
@@ -0,0 +1,8 @@
1
+ export type LayoutPaths = {
2
+ tests: string;
3
+ environments: string;
4
+ dist: string;
5
+ };
6
+ export declare function normalizeRootFolder(value: unknown, fallback: string): string;
7
+ export declare function normalizeSourceFolder(value: unknown, fallback: string): string;
8
+ export declare function normalizeLayoutPaths(special: unknown, fallback: LayoutPaths): LayoutPaths;
@@ -0,0 +1 @@
1
+ export function normalizeRootFolder(t,n){if(typeof t!=="string"||!t.trim())return n;return t.trim().replace(/^\.\/+/,"")}export function normalizeSourceFolder(t,n){if(typeof t!=="string"||!t.trim())return n;const r=t.trim();if(r.startsWith("./")||r.startsWith("../"))return r;return`./${r}`}export function normalizeLayoutPaths(t,n){const r=t&&typeof t==="object"&&!Array.isArray(t)?t:{},o=(e)=>{const i=r[e];return typeof i==="string"&&i.trim()?i.trim():n[e]};return{tests:o("tests"),environments:o("environments"),dist:o("dist")}}
@@ -0,0 +1,10 @@
1
+ import { type LayoutPaths } from '../../../utils/helpers/tmp/path-normalize';
2
+ export type SeedLayoutPaths = LayoutPaths;
3
+ export type SeedFromTmp = {
4
+ rootFolder: string;
5
+ sourceFolder: string;
6
+ framework: string;
7
+ layout: SeedLayoutPaths;
8
+ };
9
+ export declare function loadSeedFromBundledTmp(tmpFilePath?: string): SeedFromTmp;
10
+ export declare const seedFromTmp: SeedFromTmp;
@@ -0,0 +1 @@
1
+ import K from"node:fs";import J from"node:path";import{fileURLToPath as V}from"node:url";import W from"yaml";import D from"../../../utils/constants/defaults.json" with { type: 'json' };import{normalizeRootFolder as X,normalizeSourceFolder as Y}from"../../../utils/helpers/tmp/path-normalize";const O=J.dirname(V(import.meta.url)),Q=`${D.tmpBaseName}${D.tmpExtension}`;function I(j,A){if(typeof j!=="string"||!j.trim())throw Error(`${D.packageName}: bundled tmp.yml missing ${A}`);return j.trim()}function Z(j){const A=j&&typeof j==="object"&&!Array.isArray(j)?j:{};return{tests:I(A.tests,"configs.service.paths.special.tests"),environments:I(A.environments,"configs.service.paths.special.environments"),dist:I(A.dist,"configs.service.paths.special.dist")}}function _(j){if(j){if(!K.existsSync(j))throw Error(`${D.packageName}: bundled tmp.yml missing at ${j}`);return j}const A=[O,process.cwd()];for(const H of A){let C=J.resolve(H);for(;;){const E=J.join(C,D.packageRootFolder,Q);if(K.existsSync(E))return E;const G=J.dirname(C);if(G===C)break;C=G}}throw Error(`${D.packageName}: bundled ${D.packageRootFolder}/${Q} not found from ${O}`)}export function loadSeedFromBundledTmp(j){const A=_(j),H=W.parse(K.readFileSync(A,"utf8")),C=H?.configs&&typeof H.configs==="object"?H.configs:{},E=C.service&&typeof C.service==="object"?C.service:{},G=E.paths&&typeof E.paths==="object"?E.paths:{},M=I(G.source,"configs.service.paths.source");return{rootFolder:X(G.root,D.packageRootFolder),sourceFolder:Y(M,M),framework:I(E.framework,"configs.service.framework"),layout:Z(G.special)}}export const seedFromTmp=loadSeedFromBundledTmp();
@@ -1 +1 @@
1
- import J from"node:fs";import K from"node:path";import{Constants as E}from"../../../utils/constants";import{assertCoreTmpGuard as M,coreCanonicalTmpPath as O,isCorePackageRoot as Q}from"../../../utils/helpers/core/tmp-layout";import{findFileRecursively as U}from"../../../utils/helpers/core/paths";import{TmpFileLoader as V}from"../../../utils/models/classes/class.tmp-file-loader";import{registerGracefulShutdown as W}from"../../../utils/helpers/runtime/shutdown";let q=null,A=null;function X(B=process.cwd(),j=E.tmpBaseName,b=E.tmpExtension){const z=K.resolve(B);if(Q(z)){const D=O(z);if(!J.existsSync(D))throw Error(`${E.packageRootFolder}/tmp.yml not found. Run xcore tmp or ensureCoreTmpEntry() before starting @xrystal/core`);M(z,D);return D}const H=U(z,j,b);if(!H)throw Error(`${j}${b.startsWith(".")?b:`.${b}`} file not found`);return H}export function getTmpLoaderPath(){if(!A)A=X();return A}export function getTmpLoader(){if(!q){q=new V({filePath:getTmpLoaderPath()});W()}return q}export function getTmpSnapshot(){return getTmpLoader().getResolvedTmpFile()}export function onTmpReload(B){const j=getTmpLoader(),b=()=>B(j.getResolvedTmpFile());j.on("reload",b);return()=>j.off("reload",b)}export function stopTmpLoader(){if(q){q.stop();q=null;A=null}}export function resetTmpLoaderForTests(){stopTmpLoader()}
1
+ import J from"node:fs";import K from"node:path";import{Constants as z}from"../../../utils/constants";import{assertCoreTmpGuard as M,coreCanonicalTmpPath as O,isCorePackageRoot as Q}from"../../../utils/helpers/core/tmp-layout";import{findFileRecursively as U}from"../../../utils/helpers/core/paths";import{TmpFileLoader as V}from"../../../utils/models/classes/class.tmp-file-loader";import{registerGracefulShutdown as W}from"../../../utils/helpers/runtime/shutdown";let q=null,B=null;function X(D=process.cwd(),j=z.tmpBaseName,b=z.tmpExtension){const A=K.resolve(D);if(Q(A)){const E=O(A);if(!J.existsSync(E))throw Error(`${z.packageRootFolder}/tmp.yml not found. Run ${z.cliName} tmp or ensureCoreTmpEntry() before starting ${z.packageName}`);M(A,E);return E}const H=U(A,j,b);if(!H)throw Error(`${j}${b.startsWith(".")?b:`.${b}`} file not found`);return H}export function getTmpLoaderPath(){if(!B)B=X();return B}export function getTmpLoader(){if(!q){q=new V({filePath:getTmpLoaderPath()});W()}return q}export function getTmpSnapshot(){return getTmpLoader().getResolvedTmpFile()}export function onTmpReload(D){const j=getTmpLoader(),b=()=>D(j.getResolvedTmpFile());j.on("reload",b);return()=>j.off("reload",b)}export function stopTmpLoader(){if(q){q.stop();q=null;B=null}}export function resetTmpLoaderForTests(){stopTmpLoader()}
@@ -35,13 +35,10 @@ export type TmpRuntimeConfigs = {
35
35
  core: TmpCoreBlock;
36
36
  rootFolderPath: string;
37
37
  };
38
- /** `paths.root` → folder name under project root (`x`, `infra`). */
39
38
  export declare function normalizeRootFolder(value?: string): string;
40
- /** `paths.source` → dev/build source folder (`./source`, `./src`). */
41
39
  export declare function normalizeSourceFolder(value?: string): string;
42
40
  export declare function readTmpCoreBlock(configs?: Record<string, unknown>): TmpCoreBlock;
43
41
  export declare function readTmpServiceBlock(configs?: Record<string, unknown>): TmpServiceBlock;
44
42
  export declare function resolveServiceLayoutPaths(service: TmpServiceBlock): TmpLayoutPathsFlat;
45
- /** Canonical tmp.yml shape — `service` + `core` + derived `rootFolderPath`. */
46
43
  export declare function resolveTmpRuntimeConfigs(tmp?: Record<string, unknown> | null): TmpRuntimeConfigs;
47
44
  export declare function normalizeTmpDocument(tmp: Record<string, unknown>): Record<string, unknown>;
@@ -1 +1 @@
1
- import{Constants as G}from"../../../utils/constants";function A(j){return typeof j==="object"&&j!==null&&!Array.isArray(j)}function M(j){if(typeof j==="number"||typeof j==="string")return j;return}export function normalizeRootFolder(j){if(!j?.trim())return G.packageRootFolder;return j.trim().replace(/^\.\/+/,"")}export function normalizeSourceFolder(j){if(!j?.trim())return G.mainSourceFolder;const q=j.trim();if(q.startsWith("./")||q.startsWith("../"))return q;return`./${q}`}export function readTmpCoreBlock(j){const q=A(j?.core)?j.core:{},x=A(q.tmp)?q.tmp:{};return{tmp:{fileWatchIntervalMs:M(x.fileWatchIntervalMs)}}}export function readTmpServiceBlock(j){const q=A(j?.service)?j.service:{},x=A(q.paths)?q.paths:{},D=A(x.special)?x.special:{};let E=A(q.loaders)?{...q.loaders}:void 0,H=A(q.build)?q.build:void 0;if(E&&A(E.build)){const{build:J,...K}=E;E=K;if(!H&&A(J))H=J}return{name:typeof q.name==="string"?q.name:void 0,framework:typeof q.framework==="string"?q.framework:void 0,paths:{root:typeof x.root==="string"?x.root:void 0,source:typeof x.source==="string"?x.source:void 0,special:{tests:typeof D.tests==="string"?D.tests:void 0,environments:typeof D.environments==="string"?D.environments:void 0,dist:typeof D.dist==="string"?D.dist:void 0}},protocols:q.protocols,loaders:E,build:H}}export function resolveServiceLayoutPaths(j){const q=j.paths?.special??{};return{tests:q.tests?.trim()||G.layoutPaths.tests,environments:q.environments?.trim()||G.layoutPaths.environments,dist:q.dist?.trim()||G.layoutPaths.dist}}function O(j){const q=resolveServiceLayoutPaths(j);return{name:j.name,framework:j.framework??"elysia",paths:{root:j.paths?.root??G.packageRootFolder,source:j.paths?.source??G.mainSourceFolder,special:q},protocols:j.protocols,loaders:j.loaders,build:j.build}}function Q(j){return{tmp:{fileWatchIntervalMs:j.tmp?.fileWatchIntervalMs}}}export function resolveTmpRuntimeConfigs(j){const q=A(j?.configs)?j.configs:{},x=readTmpServiceBlock(q),D=readTmpCoreBlock(q),E=O(x);return{service:E,core:Q(D),rootFolderPath:normalizeRootFolder(E.paths.root)}}export function normalizeTmpDocument(j){return{...j,configs:resolveTmpRuntimeConfigs(j)}}
1
+ import K from"../../../utils/constants/defaults.json" with { type: 'json' };import{seedFromTmp as G}from"../../../utils/helpers/tmp/seed-from-tmp";import{normalizeLayoutPaths as O,normalizeRootFolder as Q,normalizeSourceFolder as U}from"../../../utils/helpers/tmp/path-normalize";function A(j){return typeof j==="object"&&j!==null&&!Array.isArray(j)}function X(j){if(typeof j==="number"||typeof j==="string")return j;return}export function normalizeRootFolder(j){return Q(j,K.packageRootFolder)}export function normalizeSourceFolder(j){return U(j,G.sourceFolder)}export function readTmpCoreBlock(j){const q=A(j?.core)?j.core:{},x=A(q.tmp)?q.tmp:{};return{tmp:{fileWatchIntervalMs:X(x.fileWatchIntervalMs)}}}export function readTmpServiceBlock(j){const q=A(j?.service)?j.service:{},x=A(q.paths)?q.paths:{},D=A(x.special)?x.special:{};let E=A(q.loaders)?{...q.loaders}:void 0,H=A(q.build)?q.build:void 0;if(E&&A(E.build)){const{build:J,...M}=E;E=M;if(!H&&A(J))H=J}return{name:typeof q.name==="string"?q.name:void 0,framework:typeof q.framework==="string"?q.framework:void 0,paths:{root:typeof x.root==="string"?x.root:void 0,source:typeof x.source==="string"?x.source:void 0,special:{tests:typeof D.tests==="string"?D.tests:void 0,environments:typeof D.environments==="string"?D.environments:void 0,dist:typeof D.dist==="string"?D.dist:void 0}},protocols:q.protocols,loaders:E,build:H}}export function resolveServiceLayoutPaths(j){return O(j.paths?.special,G.layout)}function Y(j){const q=resolveServiceLayoutPaths(j);return{name:j.name,framework:j.framework??G.framework,paths:{root:j.paths?.root??K.packageRootFolder,source:j.paths?.source??G.sourceFolder,special:q},protocols:j.protocols,loaders:j.loaders,build:j.build}}function Z(j){return{tmp:{fileWatchIntervalMs:j.tmp?.fileWatchIntervalMs}}}export function resolveTmpRuntimeConfigs(j){const q=A(j?.configs)?j.configs:{},x=readTmpServiceBlock(q),D=readTmpCoreBlock(q),E=Y(x);return{service:E,core:Z(D),rootFolderPath:normalizeRootFolder(E.paths.root)}}export function normalizeTmpDocument(j){return{...j,configs:resolveTmpRuntimeConfigs(j)}}
@@ -1 +1 @@
1
- import I from"../../../utils/constants/defaults.json" with { type: 'json' };import{readTmpCoreBlock as J}from"../../../utils/helpers/tmp/tmp-schema";const b=I.tmpWatchDefaults??{intervalMs:500,minIntervalMs:100,maxIntervalMs:1e4};export function resolveTmpWatchIntervalMs(q){const v=q?.configs,y=J(v).tmp?.fileWatchIntervalMs??b.intervalMs,j=Number(y);if(!Number.isFinite(j))return b.intervalMs;const z=b.minIntervalMs??100,G=b.maxIntervalMs??1e4;return Math.min(G,Math.max(z,Math.round(j)))}
1
+ import{packageDefaults as I}from"../../../utils/constants";import{readTmpCoreBlock as J}from"../../../utils/helpers/tmp/tmp-schema";const b=I.tmpWatchDefaults;export function resolveTmpWatchIntervalMs(q){const v=q?.configs,y=J(v).tmp?.fileWatchIntervalMs??b.intervalMs,j=Number(y);if(!Number.isFinite(j))return b.intervalMs;const z=b.minIntervalMs??100,G=b.maxIntervalMs??1e4;return Math.min(G,Math.max(z,Math.round(j)))}
@@ -1 +1 @@
1
- var __filename="/home/runner/work/-xrystal-core/-xrystal-core/x/dist/utils/models/classes/class.x.js";import{createContainer as w,asClass as y,asValue as L,InjectionMode as z,listModules as C,Lifetime as h}from"awilix";import p from"node:path";import{pathToFileURL as A}from"node:url";export const xSymbol=Symbol.for("@xrystal/core/di-container");class I{checkRegistration(e,t){return!!e.registrations[t]}}class N extends I{container;initializedNames=new Set;loadedPaths=new Set;registeredClasses=new Set;isInitializing=!1;constructor(){super();this.container=w({injectionMode:z.PROXY,strict:!0})}getName(e){if(typeof e==="string")return e.charAt(0).toLowerCase()+e.slice(1);if(typeof e==="function"&&e.name)return e.name.charAt(0).toLowerCase()+e.name.slice(1);return""}async load(e,t={}){const{verbose:r=!1,exclude:m=[],lifetime:s=h.SINGLETON}=t,i=process.cwd(),n=(Array.isArray(e)?e:[e]).map((c)=>{return(p.isAbsolute(c)?c:p.resolve(i,c)).replace(/\\/g,"/").toLowerCase()});let a=[];try{a=C(n)}catch(c){return this}for(const c of a){const f=c.path.replace(/\\/g,"/").toLowerCase();if(this.loadedPaths.has(f))continue;if(f===__filename.replace(/\\/g,"/").toLowerCase()||f.endsWith(".d.ts"))continue;try{const g=await import(A(c.path).href);let o=g.default;if(!o)o=Object.values(g).find((l)=>typeof l==="function"&&!!l.prototype&&!!l.name);if(typeof o==="function"&&!!o.prototype&&!!o.name){if(this.registeredClasses.has(o))continue;const l=this.getName(o);if(l&&!this.checkRegistration(this.container,l)){this.container.register({[l]:y(o).setLifetime(s)});this.loadedPaths.add(f);this.registeredClasses.add(o)}}}catch(u){if(r)console.error("[DI] Load Error:",u.message)}}return this}register(e,t=h.SINGLETON){const r=this.getName(e);if(!r||this.registeredClasses.has(e))return this;if(this.checkRegistration(this.container,r))return this;this.container.register({[r]:y(e).setLifetime(t)});this.registeredClasses.add(e);return this}registerInstance(e,t){if(!e)return this;const r=this.getName(e);this.container.register({[r]:L(t)});return this}async initialize(e,t=!1){if(this.isInitializing)return this;this.isInitializing=!0;try{const r=e?Array.isArray(e)?e:[e]:[];for(const s of r){const i=this.getName(s.service);if(!i||this.initializedNames.has(i))continue;const n=this.container.registrations[i];if(!n||n.lifetime!==h.SINGLETON)continue;try{const a=this.container.cradle[i];if(a&&typeof a.onInit==="function")await a.onInit(s.props||{});this.initializedNames.add(i)}catch(a){if(t)console.error(`[DI] Priority onInit Failed (${i}):`,a.message)}}const m=Object.keys(this.container.registrations);for(const s of m){if(this.initializedNames.has(s))continue;if(this.container.registrations[s].lifetime!==h.SINGLETON)continue;try{const n=this.container.cradle[s];if(n&&typeof n.onInit==="function")await n.onInit({});this.initializedNames.add(s)}catch(n){if(t)console.error(`[DI] Auto onInit Failed (${s}):`,n.message)}}for(const s of this.initializedNames)try{const i=this.container.cradle[s];if(i&&typeof i.onAfterInit==="function")await i.onAfterInit()}catch(i){if(t)console.error(`[DI] onAfterInit Failed (${s}):`,i.message)}}finally{this.isInitializing=!1}return this}get(e){const t=this.getName(e);return this.container.resolve(t)}async shutdown(){for(const e of this.initializedNames)try{const t=this.container.cradle[e];if(t&&typeof t.onDispose==="function")await t.onDispose()}catch(t){console.error(`[DI] onDispose Failed (${e})`)}await this.container.dispose()}get cradle(){return this.container.cradle}}const d=globalThis;if(!d[xSymbol])d[xSymbol]=new N;export default d[xSymbol];
1
+ var __filename="/home/runner/work/-xrystal-core/-xrystal-core/x/dist/utils/models/classes/class.x.js";import{createContainer as V,asClass as K,asValue as j,InjectionMode as N,listModules as X,Lifetime as Z}from"awilix";import R from"node:path";import{pathToFileURL as x}from"node:url";import C from"../../../utils/constants/defaults.json" with { type: 'json' };export const xSymbol=Symbol.for(`${C.packageName}/di-container`);class T{checkRegistration(q,A){return!!q.registrations[A]}}class U extends T{container;initializedNames=new Set;loadedPaths=new Set;registeredClasses=new Set;isInitializing=!1;constructor(){super();this.container=V({injectionMode:N.PROXY,strict:!0})}getName(q){if(typeof q==="string")return q.charAt(0).toLowerCase()+q.slice(1);if(typeof q==="function"&&q.name)return q.name.charAt(0).toLowerCase()+q.name.slice(1);return""}async load(q,A={}){const{verbose:H=!1,exclude:$=[],lifetime:E=Z.SINGLETON}=A,B=process.cwd(),G=(Array.isArray(q)?q:[q]).map((Q)=>{return(R.isAbsolute(Q)?Q:R.resolve(B,Q)).replace(/\\/g,"/").toLowerCase()});let O=[];try{O=X(G)}catch(Q){return this}for(const Q of O){const Y=Q.path.replace(/\\/g,"/").toLowerCase();if(this.loadedPaths.has(Y))continue;if(Y===__filename.replace(/\\/g,"/").toLowerCase()||Y.endsWith(".d.ts"))continue;try{const F=await import(x(Q.path).href);let J=F.default;if(!J)J=Object.values(F).find((W)=>typeof W==="function"&&!!W.prototype&&!!W.name);if(typeof J==="function"&&!!J.prototype&&!!J.name){if(this.registeredClasses.has(J))continue;const W=this.getName(J);if(W&&!this.checkRegistration(this.container,W)){this.container.register({[W]:K(J).setLifetime(E)});this.loadedPaths.add(Y);this.registeredClasses.add(J)}}}catch(w){if(H)console.error("[DI] Load Error:",w.message)}}return this}register(q,A=Z.SINGLETON){const H=this.getName(q);if(!H||this.registeredClasses.has(q))return this;if(this.checkRegistration(this.container,H))return this;this.container.register({[H]:K(q).setLifetime(A)});this.registeredClasses.add(q);return this}registerInstance(q,A){if(!q)return this;const H=this.getName(q);this.container.register({[H]:j(A)});return this}async initialize(q,A=!1){if(this.isInitializing)return this;this.isInitializing=!0;try{const H=q?Array.isArray(q)?q:[q]:[];for(const E of H){const B=this.getName(E.service);if(!B||this.initializedNames.has(B))continue;const G=this.container.registrations[B];if(!G||G.lifetime!==Z.SINGLETON)continue;try{const O=this.container.cradle[B];if(O&&typeof O.onInit==="function")await O.onInit(E.props||{});this.initializedNames.add(B)}catch(O){if(A)console.error(`[DI] Priority onInit Failed (${B}):`,O.message)}}const $=Object.keys(this.container.registrations);for(const E of $){if(this.initializedNames.has(E))continue;if(this.container.registrations[E].lifetime!==Z.SINGLETON)continue;try{const G=this.container.cradle[E];if(G&&typeof G.onInit==="function")await G.onInit({});this.initializedNames.add(E)}catch(G){if(A)console.error(`[DI] Auto onInit Failed (${E}):`,G.message)}}for(const E of this.initializedNames)try{const B=this.container.cradle[E];if(B&&typeof B.onAfterInit==="function")await B.onAfterInit()}catch(B){if(A)console.error(`[DI] onAfterInit Failed (${E}):`,B.message)}}finally{this.isInitializing=!1}return this}get(q){const A=this.getName(q);return this.container.resolve(A)}async shutdown(){for(const q of this.initializedNames)try{const A=this.container.cradle[q];if(A&&typeof A.onDispose==="function")await A.onDispose()}catch(A){console.error(`[DI] onDispose Failed (${q})`)}await this.container.dispose()}get cradle(){return this.container.cradle}}const _=globalThis;if(!_[xSymbol])_[xSymbol]=new U;export default _[xSymbol];
@@ -1,43 +0,0 @@
1
- import chalk from 'chalk'
2
- import { printCommandHeader } from '../helpers/banner.mjs'
3
- import { readCliPackageJson } from '../helpers/project-root.mjs'
4
-
5
- import { syncProjectToolchain, auditTsconfigAlignment } from '../helpers/toolchain-config.mjs'
6
- import { getProjectRoot } from '../helpers/project-root.mjs'
7
-
8
- export function registerSyncToolchainCommand(cli, { cliName = 'xcore' } = {}) {
9
- cli
10
- .command('sync-toolchain')
11
- .description('Sync tsconfig paths from tmp.yml layout')
12
- .option('--dry-run', 'Show changes without writing tsconfig.json')
13
- .action((options) => {
14
- const root = getProjectRoot()
15
- const auditBefore = auditTsconfigAlignment(root)
16
-
17
- printCommandHeader({ cliName, command: 'sync-toolchain', version: readCliPackageJson().version })
18
- console.log(chalk.gray(` root: ${root}`))
19
-
20
- const lo = auditBefore.layoutOptions ?? {}
21
- console.log(chalk.gray(' tmp.yml layout:'))
22
- console.log(chalk.gray(` paths.root: ${lo.rootFolderPath ?? 'x'}`))
23
- console.log(chalk.gray(` paths.source: ${lo.mainFolderPath ?? './source'}`))
24
- console.log(chalk.gray(` paths.dist: ${lo.pathsDist ?? 'dist'}`))
25
-
26
- if (options.dryRun) {
27
- const preview = syncProjectToolchain(root, { write: false })
28
- console.log(chalk.gray('\n would write tsconfig.json:'))
29
- console.log(chalk.gray(` include: ${JSON.stringify(preview.merged.include)}`))
30
- console.log(chalk.gray(` outDir: ${preview.merged.compilerOptions.outDir}`))
31
- console.log(chalk.gray(` paths: ${JSON.stringify(preview.merged.compilerOptions.paths)}`))
32
- console.log(chalk.gray(`\n bunfig.toml → ${preview.paths.bunfigAliasLine}\n`))
33
- return
34
- }
35
-
36
- const result = syncProjectToolchain(root, { write: true })
37
- console.log(result.created ? chalk.green(` created ${result.tsconfigRel}`) : chalk.green(` updated ${result.tsconfigRel}`))
38
- console.log(chalk.gray(` include → ${JSON.stringify(result.merged.include)}`))
39
- console.log(chalk.gray(` outDir → ${result.merged.compilerOptions.outDir}`))
40
- console.log(chalk.gray(` eslint → ${result.paths.eslintFiles.join(', ')}`))
41
- console.log(chalk.yellow(`\n bunfig.toml [resolve.alias]: ${result.paths.bunfigAliasLine}\n`))
42
- })
43
- }