gencow 0.1.126 → 0.1.127
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.
- package/bin/gencow.mjs +38 -11
- package/package.json +1 -1
package/bin/gencow.mjs
CHANGED
|
@@ -425,6 +425,40 @@ function spawnInServer(cmd, args, env = process.env) {
|
|
|
425
425
|
return spawn(cmd, args, { cwd: serverRoot, stdio: "inherit", shell: true, env });
|
|
426
426
|
}
|
|
427
427
|
|
|
428
|
+
// ─── Core Import Resolution ───────────────────────────────
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* @gencow/core import 경로 해석 — 3단계 fallback
|
|
432
|
+
*
|
|
433
|
+
* 1. CLI 패키지 내 번들된 core (../core/index.js relative to server/)
|
|
434
|
+
* 2. 사용자 프로젝트 node_modules/@gencow/core/dist/index.js (절대 경로)
|
|
435
|
+
* 3. bare specifier "@gencow/core" (모노레포 등 이미 resolve 가능한 경우)
|
|
436
|
+
*
|
|
437
|
+
* Bun ESM은 NODE_PATH를 무시하므로, bare specifier fallback은
|
|
438
|
+
* .gencow-extract.ts 파일 위치(CLI server 디렉토리) 기준으로만 해석됨.
|
|
439
|
+
* 따라서 2단계에서 프로젝트 node_modules의 절대 경로를 명시적으로 시도하여
|
|
440
|
+
* 글로벌/npx 설치 환경에서도 안정적으로 resolve.
|
|
441
|
+
*
|
|
442
|
+
* @param {string} serverRoot - findServerRoot()가 반환한 서버 루트 경로
|
|
443
|
+
* @returns {string} import 경로 (절대 경로 또는 bare specifier)
|
|
444
|
+
*/
|
|
445
|
+
function resolveCoreImport(serverRoot) {
|
|
446
|
+
// 1차: CLI 패키지 내 번들된 core
|
|
447
|
+
const bundledCorePath = resolve(serverRoot, "../core/index.js");
|
|
448
|
+
if (existsSync(bundledCorePath)) return bundledCorePath.replace(/\\/g, "/");
|
|
449
|
+
|
|
450
|
+
// 2차: 사용자 프로젝트 node_modules (절대 경로 — Bun ESM에서 확실히 resolve)
|
|
451
|
+
const cwdCoreDist = resolve(process.cwd(), "node_modules/@gencow/core/dist/index.js");
|
|
452
|
+
if (existsSync(cwdCoreDist)) return cwdCoreDist.replace(/\\/g, "/");
|
|
453
|
+
|
|
454
|
+
// 2차-b: src/ 직접 참조 (모노레포 workspace 등에서 dist 미빌드 시)
|
|
455
|
+
const cwdCoreSrc = resolve(process.cwd(), "node_modules/@gencow/core/src/index.ts");
|
|
456
|
+
if (existsSync(cwdCoreSrc)) return cwdCoreSrc.replace(/\\/g, "/");
|
|
457
|
+
|
|
458
|
+
// 3차: bare specifier — 모노레포 또는 이미 resolve 가능한 환경
|
|
459
|
+
return "@gencow/core";
|
|
460
|
+
}
|
|
461
|
+
|
|
428
462
|
// ─── API Codegen ──────────────────────────────────────────
|
|
429
463
|
|
|
430
464
|
function generateApiTs(config) {
|
|
@@ -433,11 +467,8 @@ function generateApiTs(config) {
|
|
|
433
467
|
const apiTsPath = resolve(absoluteFunctions, "api.ts");
|
|
434
468
|
const extractTsPath = resolve(serverRoot, ".gencow-extract.ts");
|
|
435
469
|
|
|
436
|
-
// Resolve @gencow/core — bundled
|
|
437
|
-
const
|
|
438
|
-
const coreImport = existsSync(bundledCorePath)
|
|
439
|
-
? bundledCorePath.replace(/\\/g, "/") // Windows 호환
|
|
440
|
-
: "@gencow/core"; // 모노레포 등 이미 resolve 가능한 경우
|
|
470
|
+
// Resolve @gencow/core — 3단계 fallback (bundled → CWD node_modules → bare specifier)
|
|
471
|
+
const coreImport = resolveCoreImport(serverRoot);
|
|
441
472
|
|
|
442
473
|
const script = `
|
|
443
474
|
import { getRegisteredQueries, getRegisteredMutations } from "${coreImport}";
|
|
@@ -3994,12 +4025,8 @@ ${BOLD}Examples:${RESET}
|
|
|
3994
4025
|
try { runtimeRoot = findServerRoot(); } catch { runtimeRoot = process.cwd(); }
|
|
3995
4026
|
const extractTsPath = resolve(runtimeRoot, ".gencow-extract.ts");
|
|
3996
4027
|
|
|
3997
|
-
// @gencow/core —
|
|
3998
|
-
|
|
3999
|
-
const bundledCorePath = resolve(runtimeRoot, "../core/index.js");
|
|
4000
|
-
const coreImport = existsSync(bundledCorePath)
|
|
4001
|
-
? bundledCorePath.replace(/\\/g, "/")
|
|
4002
|
-
: "@gencow/core";
|
|
4028
|
+
// @gencow/core — 3단계 fallback (bundled → CWD node_modules → bare specifier)
|
|
4029
|
+
const coreImport = resolveCoreImport(runtimeRoot);
|
|
4003
4030
|
|
|
4004
4031
|
const script = `
|
|
4005
4032
|
import { getRegisteredQueries, getRegisteredMutations } from "${coreImport}";
|