The webjar-node maven handler is using the frontend maven plugin to call pnpm scripts on the packages at several steps:
build
lint
test
For now those steps are mandatory. They can easily be made optional using the --if-present flag (e.g., pnpm run --if-present lint). But in this case, devs will not be reminded that they forgot to add tests or lint since it’s going to be skipped transparently. Ideally, I would go for an option where we have to explicitly add a skip.
Option 1: Silent Skip
Skipping silently with --if-present lint is ok
Option 2: Opt In Skip with exit 0
Devs can decide to skip a step by using exit 0.
For instance:
{
"scripts": {
"build": "vite build",
"lint": "exit 0 ## Justification for why linting is skipped"
}
}
Pros:
easy and opt in
Conclusion
I would go with option 2. I’m in the process of documenting the anatomy of a npm package in XWiki.
If agreed upon, I’ll document the best practice.
For now, if you call mvn install on a maven project with no test, you won’t get an error.
But, in the case of npm, it’s going to try to call the test:unit script of the package, even if this script does not exist (unless the --if-present parameter is added).
Not exactly the same, using skipTests will completely not call the tests, while what I’m trying to achieve is to not have an error when the tests are called but with no test:unit script declared in a given package.
(side note: since the npm tests are called through maven, mvn -DskipTests will also skip the npm tests).