biud436 / stingerloom

Node.js Server Framework
6 stars 1 forks source link

chore: 모노레포 순환 참조 문제로 인해 상위 패키지 core로 통합 필요 #52

Closed biud436 closed 1 month ago

biud436 commented 1 month ago
image

신규 프로젝트를 아래와 같이 세팅 후, 위와 같이 타입을 찾을 수 없는 문제가 있습니다. 빌드 스크립트를 생성된 dist 폴더를 참조하도록 변경하였지만 모노레포를 빌드하는 과정에서 각 모노레포의 dist 폴더까지 순환 참조하는 문제가 발생하여 오류가 발생하는 것으로 추측됩니다.

npm install @stingerloom/bootstrap @stingerloom/common

빌드에 실패하면 npm에는 반영되지 않는 것으로 보여지며, 대신 깃허브에 태그가 만들어집니다. 모노레포 배포까진 성공하였지만 각 모노레포의 배포 시, 실제로 불러올 때 타입스크립트 정의 파일과의 연결성은 추가 연구를 해야 할 것으로 보입니다.

lerna info lifecycle @stingerloom/factory@1.0.6~prepublish: @stingerloom/factory@1.0.6

> @stingerloom/factory@1.0.6 prepublish /Users/u/custom-server-framework/packages/factory
> npm run build

lerna info lifecycle @stingerloom/services@1.0.6~prepublish: @stingerloom/services@1.0.6

> @stingerloom/services@1.0.6 prepublish /Users/u/custom-server-framework/packages/services
> npm run build

(#####⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂) ⠧ npm pack: info lifecycle @stingerloom/services@1.0.6~prepublish: @stingerloom/services@1.0.6
> @stingerloom/utils@1.0.6 build
> npm run build:tsc

(#####⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂) ⠇ npm pack: info lifecycle @stingerloom/services@1.0.6~prepublish: @stingerloom/services@1.0.6
> @stingerloom/utils@1.0.6 build:tsc
> tsc

(#####⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂) ⠹ npm pack: verb packed packages/utils
> @stingerloom/router@1.0.6 build
> npm run build:tsc

(#####⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂) ⠸ npm pack: verb packed packages/utils
> @stingerloom/router@1.0.6 build:tsc
> rimraf dist && tsc

(######⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂) ⠇ npm pack: verb packed packages/router
> @stingerloom/factory@1.0.6 build
> npm run build:tsc

(######⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂) ⠏ npm pack: verb packed packages/router
> @stingerloom/factory@1.0.6 build:tsc
> rimraf dist && tsc

(#######⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂) ⠼ npm pack: verb packed packages/factory
> @stingerloom/services@1.0.6 build
> npm run build:tsc

(#######⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂) ⠴ npm pack: verb packed packages/factory
> @stingerloom/services@1.0.6 build:tsc
> rimraf dist && tsc

lerna info lifecycle @stingerloom/bootstrap@1.0.5~prepublish: @stingerloom/bootstrap@1.0.5

> @stingerloom/bootstrap@1.0.5 prepublish /Users/u/custom-server-framework/packages/bootstrap
> npm run build

(########⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂) ⠙ npm pack: info lifecycle @stingerloom/bootstrap@1.0.5~prepublish: @stingerloom/bootstrap@1.0.5
> @stingerloom/bootstrap@1.0.5 build
> npm run build:tsc

(########⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂) ⠹ npm pack: info lifecycle @stingerloom/bootstrap@1.0.5~prepublish: @stingerloom/bootstrap@1.0.5
> @stingerloom/bootstrap@1.0.5 build:tsc
> rimraf dist && tsc -p tsconfig.json

../ioc/ContainerManager.ts:129:17 - error TS2345: Argument of type 'import("/Users/u/custom-server-framework/packages/ioc/scanners/InstanceScanner").InstanceScanner' is not assignable to parameter of type 'import("/Users/u/custom-server-framework/packages/ioc/dist/ioc/scanners/InstanceScanner").InstanceScanner'.
  Property 'mapper' is protected but type 'InstanceScanner' is not a class derived from 'InstanceScanner'.

129                 instanceScanner,
                    ~~~~~~~~~~~~~~~

Found 1 error in ../ioc/ContainerManager.ts:129

npm error Lifecycle script `build:tsc` failed with error:
npm error code 2
npm error path /Users/u/custom-server-framework/packages/bootstrap
npm error workspace @stingerloom/bootstrap@1.0.5
npm error location /Users/u/custom-server-framework/packages/bootstrap
npm error command failed
npm error command sh -c rimraf dist && tsc -p tsconfig.json
npm error Lifecycle script `build` failed with error:
npm error code 2
npm error path /Users/u/custom-server-framework/packages/bootstrap
npm error workspace @stingerloom/bootstrap@1.0.5
npm error location /Users/u/custom-server-framework/packages/bootstrap
npm error command failed
npm error command sh -c npm run build:tsc
lerna ERR! lifecycle "prepublish" errored in "@stingerloom/bootstrap", exiting 2

dist에 생성된 타입스크립트 파일과 겹치는 문제로, tsconfig.json을 적절히 수정해야 할 것으로 보입니다. 아니면 orm 패키지를 제외한 대부분의 모노레포 패키지를 core 패키지로 통합해야 할 것으로 추측됩니다.

biud436 commented 1 month ago

순환 참조 문제 발생

error TS6202: Project references may not form a circular graph. Cycle detected: /Users/u/custom-server-framework/packages/bootstrap/tsconfig.json
/Users/u/custom-server-framework/packages/common/tsconfig.json
/Users/u/custom-server-framework/packages/error/tsconfig.json
/Users/u/custom-server-framework/packages/ioc/tsconfig.json
/Users/u/custom-server-framework/packages/utils/tsconfig.json
/Users/u/custom-server-framework/packages/factory/tsconfig.json
/Users/u/custom-server-framework/packages/services/tsconfig.json
/Users/u/custom-server-framework/packages/orm/tsconfig.json
/Users/u/custom-server-framework/packages/router/tsconfig.json
/Users/u/custom-server-framework/packages/compiler/tsconfig.json

순환 참조 문제를 해결하려면 각 패키지 간의 의존성을 꼼꼼히 파악하고 불필요한 의존성을 제거하거나 공통 기능을 분리하여 의존성을 재구성해야 합니다.

biud436 commented 1 month ago

@stingerloom/common으로 통합한다면 좋을 것입니다.