sulu / SuluHeadlessBundle

Bundle that provides controllers and services for using Sulu as headless content management system
MIT License
45 stars 25 forks source link

missing version in package.json throws error with yarn #113

Closed DanielRuf closed 9 months ago

DanielRuf commented 2 years ago

When trying to install the dependencies of the headless front end (assets/headless) with yarn, there is an error thrown, that vendor/sulu/headless-bundle/Resources/js-website/package.json needs a version.

This can be temporarily / individually fixed locally by adding a version manually, but should be added by the sulu team.

See https://github.com/sulu/SuluHeadlessBundle/blob/0.x/Resources/js-website/package.json

alexander-schranz commented 2 years ago

We are using and testing currently only for npm but feel free to add a version 1.0.0 or whatever make sense for a none versioned package to the package.json not sure what the best value is there. Think then should it also work with yarn. Not sure if yarn does cache something based on the version. I once created an issue about the problem here for yarn https://github.com/yarnpkg/yarn/issues/6979 but seems like it never was tackled by the yarn team.

DanielRuf commented 2 years ago

Not sure if yarn does cache something based on the version

I did the following test:

grafik

As you can see it does not contain any integrity hashes, as these are normally generated on npmjs and are part of the tarball metadata on the registries.

I've tried to change a few files in js-website and also package.json, but any yarn command after this still uses 0.0.0 and the old files.

I think the cleaner approach would be npm / yarn link as this would prevent caching.

"sulu-headless-bundle": "link:../../vendor/sulu/headless-bundle/Resources/js-website",

grafik

In our setup we will inject the version 0.0.0 via composer-patches and use link:... as we mainly use yarn.

DanielRuf commented 2 years ago

But best is probably proper versioning like in the other packages for the admin area.

alexander-schranz commented 2 years ago

I'm fine to add version 0.0.0, do you want to create a pull request for it? The file: when using npm@6 should create a symlink. The file:../../ is a known not working with yarn only work with npm when using npm 6 with workaround. Thats why sulu core itself uses a preinstall script to avoid that problem. So easier would be moving from assets/website your package.json to root directory. Then file:vendor/sulu/.. works better and you do not run into this strange behaviour of npm and yarn. If yarn does here strange tests I would as said go with npm as that is what is tested and used currently in our headless bundle projects. But as it is your project code and link: behave the way you want it you can use also that.

DanielRuf commented 2 years ago

I'm not sure if it is the right solution to add 0.0.0 in general since this will probably not pick up newer changes then. So what is really needed is a complete (SemVer) versioning scheme, that you and your team sets up for this small npm package in the vendor folder.

We had to swtich back to file: protocol since some bundlers seem to have issues with symlinks.