tim-janik / anklang

MIDI and Audio Synthesizer and Composer
https://anklang.testbit.eu/
Mozilla Public License 2.0
51 stars 3 forks source link

Unify and fixate srcdir and builddir #54

Closed tim-janik closed 1 week ago

tim-janik commented 4 months ago

Currently we have source root, build root and npm root mismatches that cause significant problems.

Many C++ projects support srcdir!=builddir (automake) or even advocate for it (cmake). Javascript (nodejs) projects generally expect srcdir==builddir, these place package.json at the root dir, which is often accompanied by a package-lock.json to recreate identical package installations. In addition, defaults for the build process are stored in a writable srcdir/config-defaults.mk file and in order to allow reliable scripting, our release creation scripts will create packages in srcdir/assets/.

Currently, the package.json script used by Anklang is stashed away in misc/package.json and copied into out/ (the default builddir) at build time. npm/bun/pnpm will then create package-lock.json and node_modules/ next to it under out/package.json, out/package-lock.json and out/node_modules/. This leads to many Javascript tools working properly only under out/. E.g. linters like eslint or tsc cannot properly deal with source files outside of the out/ hierarchy, e.g. they fail to process includes properly or flat out refuse to process files outside of the out/ hierarchy. This leads to lots of important source files having to be copied into the out/ hierarchy (usually under out/ui/) which mostly enables the Javascript ecosystem tools to work properly but creates its own set of annoyances: a) Attribution of source file errors/warnings is incorrect (so IDEs cannot directly jump to source locations), b) development tools and build scripts have to be copied into deployment locations like out/ui/, c) hot-reload watch functionality needs extra scripting to include an out of tree location, d) inplace edits of errors/warnings are easily accidentally overwritten, e) make clean may delete newly created source files that had to be created and edited under the build hierarchy in order to utilize tooling, f) file edits in the build hierarchy cannot benefit from hot reloading, g) Github bots that can check and report on outdated software packages or vulnerabilities cannot find the package.json in the project root, etc...

I.e. the more we utilize tools, libs, integrations and assets from the Javascript ecosystem, the more painful it gets to have the above mentioned separation. Given that modern Git supports multiple checkouts in arbitrary workdirs, and that upholding srcdir!=builddir separation creates increasing hurdles for working with the JS ecosystem, we should simply fix the builddir location per srcdir hierarchy, and most importantly move package.json (and therefore node_modules() to the project root, i.e. srcdir/. This will also simplify a lot of the Makefile.mk logic currently under ui/.

The transition can start with just moving package.json to the project root and adapting a handful paths. Simplification of Makefile.mk rules that currently have to jump through extra hoops, can happen incrementally after that.

tim-janik commented 1 week ago

Closing this, we now have package.json and node_modules/ in the root, which fixes most problems.