`packemon build` set the wrong `main` field
azu opened this issue · 3 comments
I have used following config.
"packemon": [
{
"inputs": {
"index": "src/some.ts"
},
"format": "esm",
"platform": "browser"
},
{
"inputs": {
"index": "src/some.ts"
},
"format": "cjs",
"platform": "node"
}
],
Then, run packemon build
and packemon set the wrong main
field
"main": "./cjs/index.cjs",
"module": "./esm/index.js",
./cjs/index.cjs
is not found.
Actually, packemon build
generate ./cjs/some.cjs
.
Actual
"main": "./cjs/index.cjs",
Expected
"main": "./cjs/some.cjs",
Workaround
Use src/index.ts
as inputs
Right now its hard-coded to index. Mainly because I wasn't sure what the best approach for this would be. https://github.com/milesj/packemon/blob/master/packages/packemon/src/Package.ts#L446
Curious on your thoughts. Always use the 1st input?
In my case, I met this issue when migrating existing project to packemon. (I've used src/another-name.ts
as entry point in existing project)
Curious on your thoughts. Always use the 1st input?
Probably, I have used a single entry point in 95+% cases.
Some package has used multiple entry points for each enviroments.
e.g. https://github.com/azu/kvs/tree/master/packages/env has multiple entry points for browser and node.
e.g. https://github.com/TypeStrong/ts-node has ts-node/register
as another entry point.
However, both cases may not related with this issue.
My thoughts:
- If
inputs.index
is defeind, does set it tomain
- If
inputs.index
is not defeind, does not updatemain
- If more than one
inputs.index
exists in same platform x format, throw an error
📝 There may be a case that we are missing something.
Examples:
"packemon": [
{
"inputs": {
"index": "src/mjs.ts"
},
"format": "mjs",
"platform": "node"
},
{
"inputs": {
"index": "src/cjs.ts"
},
"format": "cjs",
"platform": "node"
}
],
- Result:
main
will becjs/cjs.mjs
- 💭 Probably, Prefer to use cjs for
main
"packemon": [
"inputs": {
"foor": "src/some.ts"
},
{
"format": "cjs",
"platform": "node"
}
],
- Result:
main
will not be updated
"packemon": [
{
"format": "cjs",
"platform": "node"
}
],
- Result:
main
will becjs/index.cjs
"packemon": [
{
"inputs": {
"index": "src/foo.ts"
},
"format": "cjs",
"platform": "node"
},
{
"inputs": {
"index": "src/bar.ts"
},
"format": "cjs",
"platform": "node"
}
],
- Result: throw an error
It means that the index
is given special treatment.
bin
is already given special treatment.
Yeah this seems fair enough.
I'll patch it to always use the 1st input for now, but the rest feels like a breaking change so I'll save it for v3.