-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
fix: avoid packageJson without name in resolveLibCssFilename
#19324
Conversation
Why does the
Maybe we should improve the error instead saying that the package.json is malformed? |
I think those requirements are only enforced for published packages. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this part needs to be fixed as well.
vite/packages/vite/src/node/build.ts
Lines 922 to 932 in e8c783f
const packageJson = findNearestPackageData(root, packageCache)?.data | |
const name = | |
libOptions.fileName || | |
(packageJson && typeof libOptions.entry === 'string' | |
? getPkgName(packageJson.name) | |
: entryName) | |
if (!name) | |
throw new Error( | |
'Name in package.json is required if option "build.lib.fileName" is not provided.', | |
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sapphi-red Just confirm: I saw several test cases particular on packages/noname
. Do you think it should be updated to packages/name
as well? Thanks.
https://github.com/vitejs/vite/blob/main/packages/vite/src/node/__tests__/build.spec.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be packages/noname
as-is, but the resolved name should be updated so that we test the fallback behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test case updated. I also added an additional packages/vite/src/node/__tests__/packages/package.json
to catch the resolver for noname. Please take a look. 🙏
const packageJson = findNearestPackageData(root, packageCache)?.data | ||
const name = packageJson ? getPkgName(packageJson.name) : undefined | ||
const name = | ||
packageJson && packageJson.name ? getPkgName(packageJson.name) : undefined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have findNearestMainPackageData
function that skips the package.json without name
field. I think swapping findNearestPackageData
with it matches the users expectations.
vite/packages/vite/src/node/packages.ts
Lines 161 to 162 in e8c783f
// Finds the nearest package.json with a `name` field | |
export function findNearestMainPackageData( |
Sometimes there're nested |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
resolveLibCssFilename
Description
Fix the issue when there is no package name in package.json.
which causes errors like below: