Closed kaiyoma closed 1 year ago
From what I see, you're using pnpm. I'm not sure how it handles optionalDependencies
as I couldn't find documentation about it.
I'll explain how the SwaggerUI@5 works with npm.
SwaggerUI@5 is using swagger-client which under the hood uses ApiDOM to facilitate OpenAPI 3.1.0 definition resolution. Number of dependencies of ApiDOM are marked as optional like (tree-sitter), and if they fail to install, SwaggerUI will work just fine without them. If optional dependencies fail to install, in npm
you just get one line message related to failed optional dependency install. The overall installation will proceed successfully.
More info in: https://docs.npmjs.com/cli/v9/configuring-npm/package-json#optionaldependencies
@char0n Ah, this is very helpful, thank you! I'll raise an issue with pnpm.
I'm using yarn and it also produces very ugly logs, and it does this with any package installation or removal. Please fix this if possible. I use swagger-ui in some of my packages that are published on npmjs.com and every user sees these logs:
every user sees these logs:
I don't think every user would
Error: not found: make
You need to install make
, that error is from node-gyp
which is trying to build native modules.
ps. you can stop post install hooks from running with --ignore-scripts
. quite a few users do this already.
I note there are prebuilt binaries on github for tree-sitter anyway
https://github.com/tree-sitter/tree-sitter/releases/tag/v0.20.8
so there isn't necessarily a need for these to built on the end users computer, tree-sitter could allow these to be fetched from github on install time (there is a prebuildify plugin for that) but that won't work with --ignore-scripts
either.
Hope that helps a bit :)
I don't think every user would
@YOU54F, yes, but no. I'm running Ubuntu 22.04 and only install the programs I need as a TypeScript web developer. I understand that I can install make
, but I suspect that 99% of users who download packages from npmjs.com have the same programs as me (+/-).
Why on earth does a simple UI library require GBs of C++ tools to be installed?
It's a known documented thing in the node ecosystem for packages that require native modules.
See electrons docs
https://www.electronjs.org/docs/latest/tutorial/using-native-node-modules
I don't think every user would
@YOU54F, yes, but no. I'm running Ubuntu 22.04 and only install the programs I need as a TypeScript web developer. I understand that I can install
make
, but I suspect that 99% of users who download packages from npmjs.com have the same programs as me (+/-).
I'd argue with your stats personally, it's a thing in the javascript ecosystem.
it's not overly common, but considering your a ts web developer, I assume you've worked with electron.
https://github.com/nodejs/node-gyp
https://nodejs.org/api/addons.html
https://blog.risingstack.com/writing-native-node-js-modules/
ps. I also help maintain pact-js, we prebuild our native modules (we leverage rust code via a shared library to extend the power of our JS code) - we used to require our users to build these, but it did cause issues for a small percentage.
It was enough for me to prebuild and package the native modules into the npm package (but it inflated the package size) - it's all a set of trade-offs :(
I'm using yarn and it also produces very ugly logs, and it does this with any package installation or removal. Please fix this if possible. I use swagger-ui in some of my packages that are published on npmjs.com and every user sees these logs:
Hi @KostyaTretyak,
We've invested considerable amount of time to solve this so that we don't see any ugly long error logs. In latest versions of npm
(9.8.0), the failing optional dependency install will produce just one single overlook-able line in the install log. That's why we settled for this current solution - optionalDepedencies
that might fail to install, but overall installation will not fail.
If you don't want to see those error in your project there is a simple solution documented in swagger-client documentation:
https://github.com/swagger-api/swagger-js/blob/master/docs/usage/installation.md#installation
In yarn, selective dependency resolutions works in the same way. Inside your README file, in installation instructions sections, you'll suggest people to do the override
or resolution
(yarn) in order to avoid seeing the optional dependency installation failure.
Another way to remedy this is to disassemble the https://github.com/swagger-api/apidom/tree/main/packages/apidom-reference package (used by swagger-client/swagger-ui and causing these failed install errors) into many more packages, and then assemble those new packages back to use-case based packages, one of which will be for swagger-ui usecase, which doesn't actually need tree-sitter
. But this would require significant amount of work, it will increase the complexity of ApiDOM utilization and benefits are questionable.
IMHO concept of optionalDepedencies
exists to solve exactly the issues we're having with https://github.com/swagger-api/apidom/tree/main/packages/apidom-reference. It's unfortunate that yarn
is producing these big logs, instead of one line notice.
If you have any suggestions, I'm trilled to hear them, as unfortunately I've run out of new ideas, except for the idea of disassembling the apidom-reference
package.
@char0n, first of all, thank you for taking the time to answer me, even when I ask questions in closed issues.
If you don't want to see those error in your project there is a simple solution documented in swagger-client documentation
I tried it, but for some reason it doesn't work:
"resolutions": {
"@swagger-api/apidom-reference/@swagger-api/apidom-ns-asyncapi-2": "yarn:-@0.0.1",
"@swagger-api/apidom-reference/@swagger-api/apidom-parser-adapter-api-design-systems-json": "yarn:-@0.0.1",
"@swagger-api/apidom-reference/@swagger-api/apidom-parser-adapter-api-design-systems-yaml": "yarn:-@0.0.1",
"@swagger-api/apidom-reference/@swagger-api/apidom-parser-adapter-asyncapi-json-2": "yarn:-@0.0.1",
"@swagger-api/apidom-reference/@swagger-api/apidom-parser-adapter-asyncapi-yaml-2": "yarn:-@0.0.1",
"@swagger-api/apidom-reference/@swagger-api/apidom-parser-adapter-json": "yarn:-@0.0.1",
"@swagger-api/apidom-reference/@swagger-api/apidom-parser-adapter-openapi-json-3-0": "yarn:-@0.0.1",
"@swagger-api/apidom-reference/@swagger-api/apidom-parser-adapter-openapi-json-3-1": "yarn:-@0.0.1",
"@swagger-api/apidom-reference/@swagger-api/apidom-parser-adapter-openapi-yaml-3-0": "yarn:-@0.0.1",
"@swagger-api/apidom-reference/@swagger-api/apidom-parser-adapter-openapi-yaml-3-1": "yarn:-@0.0.1",
"@swagger-api/apidom-reference/@swagger-api/apidom-parser-adapter-yaml-1-2": "yarn:-@0.0.1"
}
And this doesn't work:
"resolutions": {
"@swagger-api/apidom-ns-asyncapi-2": "yarn:-@0.0.1",
"@swagger-api/apidom-parser-adapter-api-design-systems-json": "yarn:-@0.0.1",
"@swagger-api/apidom-parser-adapter-api-design-systems-yaml": "yarn:-@0.0.1",
"@swagger-api/apidom-parser-adapter-asyncapi-json-2": "yarn:-@0.0.1",
"@swagger-api/apidom-parser-adapter-asyncapi-yaml-2": "yarn:-@0.0.1",
"@swagger-api/apidom-parser-adapter-json": "yarn:-@0.0.1",
"@swagger-api/apidom-parser-adapter-openapi-json-3-0": "yarn:-@0.0.1",
"@swagger-api/apidom-parser-adapter-openapi-json-3-1": "yarn:-@0.0.1",
"@swagger-api/apidom-parser-adapter-openapi-yaml-3-0": "yarn:-@0.0.1",
"@swagger-api/apidom-parser-adapter-openapi-yaml-3-1": "yarn:-@0.0.1",
"@swagger-api/apidom-parser-adapter-yaml-1-2": "yarn:-@0.0.1"
}
And with npm:
in version also doesn't work.
I tried it, but for some reason it doesn't work:
@KostyaTretyak I'm not sure about yarn
resolution syntax (as I use npm
), but according to https://classic.yarnpkg.com/lang/en/docs/selective-version-resolutions/#toc-how-to-use-it it's correct. Not sure about yarn:-@0.0.1
as well, in a scene if this syntax is supported in yarn
.
Anyway this overrides/resolutions are meant for your downstream consumers (people using your package). They need to use this override to get rid of the errors. If you put in inside your package, it has no effect downstream.
Please tell me which version of swagger-ui
does not have these optional dependencies? I tried downgrading to swagger-ui@^3.0.0
but it still has those dependencies.
These optional dependencies come from https://github.com/swagger-api/apidom and https://www.npmjs.com/package/swagger-client respectively.
If you're fixated to remove the errors from you package, you https://www.npmjs.com/package/swagger-ui-dist which contains build fragments of already pre-built SwaggerU and doesn't install anything.
Here is a documentation of what each fragment is: https://github.com/swagger-api/swagger-ui/issues/7831#issue-1128241346
@char0n, first of all, thank you for taking the time to answer me, even when I ask questions in closed issues.
If you don't want to see those error in your project there is a simple solution documented in swagger-client documentation
I tried it, but for some reason it doesn't work:
"resolutions": { "@swagger-api/apidom-reference/@swagger-api/apidom-ns-asyncapi-2": "yarn:-@0.0.1", "@swagger-api/apidom-reference/@swagger-api/apidom-parser-adapter-api-design-systems-json": "yarn:-@0.0.1", "@swagger-api/apidom-reference/@swagger-api/apidom-parser-adapter-api-design-systems-yaml": "yarn:-@0.0.1", "@swagger-api/apidom-reference/@swagger-api/apidom-parser-adapter-asyncapi-json-2": "yarn:-@0.0.1", "@swagger-api/apidom-reference/@swagger-api/apidom-parser-adapter-asyncapi-yaml-2": "yarn:-@0.0.1", "@swagger-api/apidom-reference/@swagger-api/apidom-parser-adapter-json": "yarn:-@0.0.1", "@swagger-api/apidom-reference/@swagger-api/apidom-parser-adapter-openapi-json-3-0": "yarn:-@0.0.1", "@swagger-api/apidom-reference/@swagger-api/apidom-parser-adapter-openapi-json-3-1": "yarn:-@0.0.1", "@swagger-api/apidom-reference/@swagger-api/apidom-parser-adapter-openapi-yaml-3-0": "yarn:-@0.0.1", "@swagger-api/apidom-reference/@swagger-api/apidom-parser-adapter-openapi-yaml-3-1": "yarn:-@0.0.1", "@swagger-api/apidom-reference/@swagger-api/apidom-parser-adapter-yaml-1-2": "yarn:-@0.0.1" }
And this doesn't work:
"resolutions": { "@swagger-api/apidom-ns-asyncapi-2": "yarn:-@0.0.1", "@swagger-api/apidom-parser-adapter-api-design-systems-json": "yarn:-@0.0.1", "@swagger-api/apidom-parser-adapter-api-design-systems-yaml": "yarn:-@0.0.1", "@swagger-api/apidom-parser-adapter-asyncapi-json-2": "yarn:-@0.0.1", "@swagger-api/apidom-parser-adapter-asyncapi-yaml-2": "yarn:-@0.0.1", "@swagger-api/apidom-parser-adapter-json": "yarn:-@0.0.1", "@swagger-api/apidom-parser-adapter-openapi-json-3-0": "yarn:-@0.0.1", "@swagger-api/apidom-parser-adapter-openapi-json-3-1": "yarn:-@0.0.1", "@swagger-api/apidom-parser-adapter-openapi-yaml-3-0": "yarn:-@0.0.1", "@swagger-api/apidom-parser-adapter-openapi-yaml-3-1": "yarn:-@0.0.1", "@swagger-api/apidom-parser-adapter-yaml-1-2": "yarn:-@0.0.1" }
And with
npm:
in version also doesn't work.
For me adding it like this to package.json removed the error from logs. (I'm using yarn)
"resolutions": {
"@swagger-api/apidom-ns-asyncapi-2": "npm:-@0.0.1",
"@swagger-api/apidom-ns-openapi-2": "npm:-@0.0.1",
"@swagger-api/apidom-parser-adapter-api-design-systems-json": "npm:-@0.0.1",
"@swagger-api/apidom-parser-adapter-api-design-systems-yaml": "npm:-@0.0.1",
"@swagger-api/apidom-parser-adapter-asyncapi-json-2": "npm:-@0.0.1",
"@swagger-api/apidom-parser-adapter-asyncapi-yaml-2": "npm:-@0.0.1",
"@swagger-api/apidom-parser-adapter-json": "npm:-@0.0.1",
"@swagger-api/apidom-parser-adapter-openapi-json-2": "npm:-@0.0.1",
"@swagger-api/apidom-parser-adapter-openapi-yaml-2": "npm:-@0.0.1",
"@swagger-api/apidom-parser-adapter-openapi-json-3-0": "npm:-@0.0.1",
"@swagger-api/apidom-parser-adapter-openapi-json-3-1": "npm:-@0.0.1",
"@swagger-api/apidom-parser-adapter-openapi-yaml-3-0": "npm:-@0.0.1",
"@swagger-api/apidom-parser-adapter-openapi-yaml-3-1": "npm:-@0.0.1",
"@swagger-api/apidom-parser-adapter-workflows-json-1": "npm:-@0.0.1",
"@swagger-api/apidom-parser-adapter-workflows-yaml-1": "npm:-@0.0.1",
"@swagger-api/apidom-parser-adapter-yaml-1-2": "npm:-@0.0.1"
}```
Q&A (please complete the following information)
Describe the bug you're encountering
I can't install this dependency because it requires Visual C++. Why on earth does a simple UI library require GBs of C++ tools to be installed?