-
Notifications
You must be signed in to change notification settings - Fork 6
ποΈ build: add file specific exports to packagejson #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
I also added an export for the guard since that would make a lot of sense for checking at runtime which specific module should be applied. Unfortunately, node10 can't resolve the guard export and I have no idea why. Maybe you have an idea on this? |
|
Hey, @sinclairzx81, did you maybe have time to take a look yet/do you have any questions? |
|
@m1212e Hi, Hey sorry for the delay on getting to this PR. Have been exceptionally busy with other projects of late, and have been in a state of trying to catch up on various issues and PR's. I think this PR is a good one tho, so can go ahead with it. ExportsSo, I think it should be ok to export each sub module individually, but would need to configure the build slightly differently to keep inline with the current TypeBox setup. TypeMap uses the same build setup as TypeBox, but where TypeBox exports submodules via computed named / directory paths. TypeBox Setuphttps://github.com/sinclairzx81/typebox/blob/master/task/build/package/build.ts#L33-L38 /** Builds package.json and redirect directories */
export async function build(target: string) {
console.log('building...package.json')
const submodules = ['compiler', 'errors', 'parser', 'syntax', 'system', 'type', 'value']
await createPackageJsonRedirect(target, submodules)
await createPackageJson(target, submodules)
}TypeMap Setuphttps://github.com/sinclairzx81/typemap/blob/main/task/build/package/build.ts#L32C1-L38C2 /** Builds package.json and redirect directories */
export async function build(target: string) {
console.log('building...package.json')
const submodules = [] as string[] // TODO <-- ['compile', 'syntax', 'typebox', 'valibot', 'zod']
await createPackageJsonRedirect(target, submodules)
await createPackageJson(target, submodules)
}If you add this (and remove the explicit configurations), you can test the build with ... That should run a module resolution test (CJS, ESM) and confirm the sub modules are correctly resolvable. The submodule may need an additional Are you able to take a quick look at this? Again, sorry for the delay here. |
|
Absolutely no problem, you do this for free so no worries at all! I'll take a look, thanks for the response! |
|
@m1212e Hi, thanks for the additional updates. I've just made a few updates here to fix up some of the build, mostly just setting up the library submodules as proper submodules (just needed a βββββββββββββββββββββ¬ββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββ
β β "@sinclair/typemap" β "@sinclair/typemap/compile" β "@sinclair/typemap/guard" β "@sinclair/typemap/typebox" β "@sinclair/typemap/valibot" β "@sinclair/typemap/zod" β
βββββββββββββββββββββΌββββββββββββββββββββββΌββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββ€
β node10 β π’ β π’ β π’ β π’ β π’ β π’ β
βββββββββββββββββββββΌββββββββββββββββββββββΌββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββ€
β node16 (from CJS) β π’ (CJS) β π’ (CJS) β π’ (CJS) β π’ (CJS) β π’ (CJS) β π’ (CJS) β
βββββββββββββββββββββΌββββββββββββββββββββββΌββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββ€
β node16 (from ESM) β π’ (ESM) β π’ (ESM) β π’ (ESM) β π’ (ESM) β π’ (ESM) β π’ (ESM) β
βββββββββββββββββββββΌββββββββββββββββββββββΌββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββ€
β bundler β π’ β π’ β π’ β π’ β π’ β π’ β
βββββββββββββββββββββ΄ββββββββββββββββββββββ΄ββββββββββββββββββββββββββββββ΄ββββββββββββββββββββββββββββ΄ββββββββββββββββββββββββββββββ΄ββββββββββββββββββββββββββββββ΄ββββββββββββββββββββββββββBefore merging through, need to check a couple of things. PeerDependenciesMetaYour update removed Zod and Valibot from It would be much better if users needed to explicitly install Zod and Valibot. I wasn't keen on the automatic installation of these libraries previously, so if "peerDependenciesMeta": {
"zod": {
"optional": true
},
"valibot": {
"optional": true
}
},Submodule ImportsThis setup should support selectively importing from the library sub modules, but are you able to run a test on your setup to make sure everything is working ok? You should be able to create a build with: $ npm run buildThis should write a import { Zod } from '@sinclair/typemap/zod'Would be good to get some info on the above before merging. |
|
Hey, thanks for your answer. Actually, I think you cannot remove the peer dependencies completely, but you must have them in addition to the optional config. So this would be correct, as far as I know: "peerDependencies": {
"@sinclair/typebox": "^0.34.30",
"valibot": "^1.0.0",
"zod": "^3.24.1"
},
"peerDependenciesMeta": {
"zod": {
"optional": true
},
"valibot": {
"optional": true
}
}this way the user can decide on whether they wanna install valibot or zod. The generated module exports do work but are not really that useful as they are, at least not for my usecase. Since the index re-export modules use the * to re-export everything from every submodule, the "zod" import still requires valibot to be installed and vice versa: So to prevent the necessity of both validators beeing installed, one would need to be able to import the actual function modules like EDIT: |
|
Ok, I think this is still the proper way to handle the dependencies: https://stackoverflow.com/a/66228639/11988368 |
This would allow granular imports from the specific function modules and would remove the necessity of having all three validator libraries in the dependencies.