-
Notifications
You must be signed in to change notification settings - Fork 810
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: leverage tree-shakeable validator imports #665
Comments
Great idea, I would like to work on a PR for this |
Hello, I made some tests and here's what I've got so far:
// We can't import with the same name since it's already used by the function below
import validatorContains from "validator/es/lib/contains"
export function contains(value: unknown, seed: string): boolean {
return typeof value === "string" && validatorContains(value, seed);
} But when I tried to run the tests, Jest complain about how the validator es lib is importing internally
I already tried following the hint of using transformIgnorePatterns: [
"/node_modules/(?!validator)"
], I really don't know what to do next, maybe someone has more insight on the matter ? note: It seem related to a problem someone already had with validatorjs validatorjs/validator.js#1208 (comment) |
It is correct, you need the newest typings to be merged in first, before you can proceed with using Have you maybe tried As for Jest, I would need to debug it to be able provide insight into what might be happening there. |
You can't do The lib expose the default export so from what I understand What we can do is: But we get the same error: |
Would this give you some pointers? jestjs/jest#9292? You are seeing it when running units on Jest, right? |
Correct I found the solution following jestjs/jest#9395 (comment) To make it work I had to make these changes: //package.json
{
...
"devDependencies": {
"@babel/preset-env": "^7.10.4",
...
} //jest.config.js
module.exports = {
transform: {
...
"^.+\\.js?$": "babel-jest"
},
...
transformIgnorePatterns: [
"node_modules/(?!validator)/"
]
}; //babel.config.json
{
"presets": ["@babel/preset-env"]
} Since it will add a dev dependencie and change the build process I would like to have the opinion of a maintainer before starting to work on the PR, I don't want to mess up the build process. |
Seems like @NoNameProvided is already working on it d797c05 |
This is now in develop. Will be released in next version. |
This'd be a huge performance improvement. Especially libphonenumer-js should be excluded, if no validator is used connected to it. @NoNameProvided do you plan to do that? |
This is released. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
At the moment when using class-validator we are pulling in entire validator.js library due to the syntax used.
I would like to propose to migrate the the tree-shakeable imports instead referenced in validator.js README: https://github.com/validatorjs/validator.js#tree-shakeable-es-imports
The text was updated successfully, but these errors were encountered: