Skip to content

deps: manual upgrade to express 5.1.0 #1626

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

Merged
merged 5 commits into from
Apr 10, 2025
Merged

deps: manual upgrade to express 5.1.0 #1626

merged 5 commits into from
Apr 10, 2025

Conversation

pano9000
Copy link
Member

@pano9000 pano9000 commented Apr 4, 2025

This PR will supersede the automatically created one: #1586

Our code is already compliant with v5, and is not affected by the breaking changes described here: https://expressjs.com/en/guide/migrating-5.html

I ran their codemod command, and it did not find anything (except it strangely reformatted some unrelated code…).
So I also double-checked manually for all of the described changed topics in the migration guide.
→ nothing there :-)

with this change npm will still print a warning, due to @triliumnext/express-partial-content@"1.0.1", which needs to be updated to v5 as well, but the PR is raised TriliumNext/express-partial-content#1

once that is in, I will need to update that dependecy as well and we can get this merged.

target is: after the next stable, as confirmed here:
#1586 (comment)

@pano9000 pano9000 added this to the v0.93.0 milestone Apr 4, 2025
@pano9000 pano9000 added the dependencies PRs or issues relating to dependencies label Apr 4, 2025
@JYC333
Copy link
Member

JYC333 commented Apr 4, 2025

Merge the PR TriliumNext/express-partial-content#1. You can test this again I think.

@pano9000
Copy link
Member Author

pano9000 commented Apr 4, 2025

we will need a new released version on npm of that -> there is a CI action that will apparently do all of that, when there is a new tag created, however I don't want to "just do it" without @eliandoran having a final look over it :-)

pano9000 added 2 commits April 6, 2025 16:57
our code is already compliant with v5, and is not affected by the breaking changes described here:
https://expressjs.com/en/guide/migrating-5.html

I ran their codemod command, and it did not find anything – so I also double-checked by manually checking for all of the described changed topics in the migration guide.

with this change npm will still print a warning, due to
`@triliumnext/express-partial-content@"1.0.1"`, which needs to be updated to v5 as well
now we have full express 5 compatibility
@pano9000
Copy link
Member Author

pano9000 commented Apr 6, 2025

FYI: I've updated the @triliumnext/express-partial-content to 1.1.0 and can now do some actual testing:
I actually found out that their codemod does not check for the "Path route matching syntax" breaking change — and we actually have 2 occurrences here that are affected by it:

    apiRoute(PUT, "/api/options/:name/:value*", optionsApiRoute.updateOption);

and

    router.all("/custom/:path*", (req: Request, res: Response, _next) => {

the issue here is that the suggested way to migrate is not fully working with what I see we do on our end.

Express v4:

here we use
"/api/options/:name/:value*"

and when I trigger that via a PUT, and do some loggin of the req data (name and value), I see (e.g. here I changed locale to en):

params: {"0":"","name":"locale","value":"en"}

If I force additional paths in the PUT, it will only use the first path part as "value", e.g. with:
/api/options/locale/de/something/else

params: {"0":"/something/else","name":"locale","value":"de"}

Express v5:

here we are supposed to use /api/options/:name/*value and this gets us in trouble:
it gives us as req.params:

params: {"name":"locale","value":["de"]}

which results in an error, due to the value being in an array:

Updating option 'locale' to 'de'
Got error TypeError: SQLite3 can only bind numbers, strings, bigints, buffers, and null

same with me trying to add some fake paths as well:

params: {"name":"locale","value":["de","something","else"]}

Updating option 'locale' to 'de,something,else'
Got error TypeError: SQLite3 can only bind numbers, strings, bigints, buffers, and null

I'll work this week on getting these fixed and potentially do some extra testing on those other paths as well, just to make sure

@pano9000
Copy link
Member Author

pano9000 commented Apr 8, 2025

I have a "naive" working solution, but need chck and consider some edgecases (e.g. values with special characters -> URI encode them or not? I'll need to compare what v4 was doing and mimick accordingly)

some testing undergoing here still, should be back with an update this evening.

…value*"

the updateOption function that handles the req.param is just destructuring `const { name, value } = req.params;` and does nothing else with the path or any params.
The remaining parts of the wildcard (which can be accessed via req.param[0]) are just ignored here.

even with express v4, this would *always* just take and process the very first part of the path, in the exact wildcard's place, e.g.

`/api/options/locale/de` and
`/api/options/locale/de/test/whatever`
would *both* end up destructuring "value" from req.param as "de" (because it is in the exact place of the 'value' wildcard)

in express v5 the wildcard behaviour changes -> here req.param.value would return an array with the paths split into separate string.

but since the code previously regarded only the first part of the path -> we can just get rid of the wildcard and use a named route param

the only thing to keep in mind: if a request with more than one "value" is received, (e.g. `/api/options/locale/de/test/whatever`) -> since we don't have the wildcard anymore  -> this will turn to a 404.
IMHO that is actually desirable here though
Copy link

github-actions bot commented Apr 8, 2025

Folder/File Previous size New size Difference
/upload/TriliumNextNotes-Server-1626-merge-linux-x64.tar.xz 86.84MB +86.84MB (+100.00%)
TOTAL +86.84MB

Copy link

github-actions bot commented Apr 8, 2025

Folder/File Previous size New size Difference
/upload/TriliumNextNotes-1626-merge-linux-x64.deb 139.34MB +139.34MB (+100.00%)
/upload/TriliumNextNotes-1626-merge-linux-x64.flatpak 132.58MB +132.58MB (+100.00%)
/upload/TriliumNextNotes-1626-merge-linux-x64.rpm 147.31MB +147.31MB (+100.00%)
/upload/TriliumNextNotes-1626-merge-linux-x64.zip 178.29MB +178.29MB (+100.00%)
TOTAL +597.52MB

@pano9000 pano9000 marked this pull request as ready for review April 8, 2025 22:21
@pano9000
Copy link
Member Author

pano9000 commented Apr 8, 2025

marked PR as ready for review -> kindly also check my git commit messages for further info

@eliandoran eliandoran merged commit 9cfc083 into develop Apr 10, 2025
7 checks passed
@eliandoran eliandoran deleted the deps_express5 branch April 10, 2025 18:14
@eliandoran eliandoran restored the deps_express5 branch April 11, 2025 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies PRs or issues relating to dependencies
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants