-
Notifications
You must be signed in to change notification settings - Fork 28
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
Add source generator that reads a JSON value as a const string at compile time. (OSOE-819) #238
Comments
Hmm, very interesting! This would be especially useful for updates done by Dependabot. |
I've been looking into this issue and playing around with source generators as I've never worked on one before. The classes that will be marked with the attribute Also in order to make the package.json file accessible to the generator it would have to be marked as an "AdditionalFiles" in the .csproj as source generators do not have access to the filesystem directly. I am setting this up as a separate project within this repo for now, let me know if there are any thoughts around that. |
Partial shouldn't be an issue, nor |
Hey @Piedone, The marking of the |
Yeah, I understood it as such. Just that we publish all of our open-source projects using package.jsons on NuGet, so that'll affect their NuGet publishing (e.g. https://github.com/Lombiq/Orchard-Chart.js, https://github.com/Lombiq/Orchard-Content-Editors, https://github.com/Lombiq/Orchard-Data-Tables). |
I get build errors locally with a fresh clone of OSOCE: Repeated builds also fail. |
Considering that it works with |
Good job, @AydinE! |
Reopening, since this breaks NuGet publishing. |
Disclaimer: I'm not sure if this is the right repo for this suggestion. I don't think we have done any source generators yet, so maybe it should be a new repo if we do this. The idea ties into node/npm but it's not dependent on Node Extensions.
Problem
When you include a vendor resource in OC, it's a good idea to include the version too, for the purpose of cache busting. For example
As you can see, the version here is just a raw string. It's derived from the matching
"chart.js": "2.9.4",
in package.json. Then later you update the package file and forget to update the matching version number in the resource manifest! It's a maintenance nightmare.Solution
Create a source generator that creates a compile time constant. For instance:
Here
[ConstantFromJson(variableName, fileName, jsonPath)]
would instruct the source generator to insert string constant calledvariableName
and set its value to the first result infileName
that matchesjsonPath
. Then at compile time it will becomeprivate const ChartJsVersion = "2.9.4";
. Of course, there should be a shortcut like[ValueFromNpm("chart.js")]
as well.I looked for existing projects, but this was the only thing vaguely similar.
Alternatives
You could mark the package.json an embedded file, then read & parse it rune time at every startup.
Just writing that sentence down made me feel ill.
Jira issue
The text was updated successfully, but these errors were encountered: