I have a mono repo with two typescript projects. ProjectB references functions from ProjectA.
project A package.json
{
"name": "@monorepo/utils",
"version": "1.0.0",
"description": "The package containing some utility functions",
"main": "./build/index.js",
"type": "commonjs",
"scripts": {
"build": "tsc --build"
}
}
src/index.ts
export function isEven(n: number): boolean {
return n % 2 === 0
}
src/maths.ts
export function DamoAdd(a: number, b: number): number {
return a + b
}
project B package.json
{
"name": "@monorepo/ui",
"version": "1.0.0",
"description": "The UI package",
"main": "./build/index.js",
"type": "commonjs",
"scripts": {
"build": "tsc --build"
},
"dependencies": {
"@monorepo/utils": "^1.0.0",
}
}
The issue I’m having is in project B
projectb/src/app.ts
import { isEven } from "@monorepo/utils"
import { Add } from "@monorepo/utils/**build**/maths"
It seems fine to me to be importing IsEven from @monorepo/utils, however seems ‘wrong’ to me to have to specify @monorepo/utils/build/maths. Specifically the ‘build’ part of that path. Perhaps I’m just being picky, but these seems out of place.
Is there a better way to do this? Googling around I’m finding people writing scripts to generate imports and exports in an index.ts file… but that seems pretty out there too. Is there some clean way to deal with this?
I hope that makes sense. Thank you! 🙂