Skip to content
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

[WIP] feat: expressjs framework #784

Draft
wants to merge 62 commits into
base: main
Choose a base branch
from

Conversation

yanksyoon
Copy link
Contributor

@yanksyoon yanksyoon commented Jan 2, 2025

  • Have you signed the CLA?

Adds support for ExpressJS framework.

Key Decisions

  • Support for bare and 24.04 only. Drop support for 22.04 (jammy)
    • Jammy comes with an old version of Node which does not support ?? operator commonly used in JS projects. This means that the projects initialized with express-generator tooling (assumed to be the case) would not work.
  • Include runtime slices in the expressjs-framework/install-app > stage-packages part.
  • Do not include user customizable part for runtime slices/packages in the template
  • Provide Ubuntu packaged Node/NPM by default, allow user to specify Node version if desired.
    • To follow the principles of Ubuntu LTS, by default use the NodeJS and NPM provided by apt/slices but allow users to customize the behavior through overriding the NPM plugin's npm-include-node and npm-node-version fields.
  • Include all paths under the app/ directory.
    • Users should not include/add paths which are not desired in the app path (e.g. .env files)

@yanksyoon yanksyoon mentioned this pull request Jan 2, 2025
1 task
@yanksyoon yanksyoon changed the title feat: expressjs framework [WIP] feat: expressjs framework Jan 2, 2025
@yanksyoon yanksyoon force-pushed the feat/expressjs-framework branch from 056fbc1 to 8afa87e Compare January 2, 2025 03:55
Copy link
Contributor

@erinecon erinecon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I took a brief look at what's in the tutorial so far, and I left two comments.

I have some other comments that I excluded because they will affect all of the tutorials. I'd rather keep the set of tutorials consistent for now and update them all in one go.

docs/tutorial/expressjs.rst Outdated Show resolved Hide resolved
docs/tutorial/expressjs.rst Outdated Show resolved Hide resolved
docs/reference/extensions/expressjs-framework.rst Outdated Show resolved Hide resolved
docs/reference/extensions/expressjs-framework.rst Outdated Show resolved Hide resolved
docs/reference/extensions/expressjs-framework.rst Outdated Show resolved Hide resolved
docs/reference/extensions/index.rst Outdated Show resolved Hide resolved
Copy link
Contributor

@erinecon erinecon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding more documentation!

docs/tutorial/expressjs.rst Outdated Show resolved Hide resolved
docs/explanation/extensions/expressjs-framework.rst Outdated Show resolved Hide resolved
docs/reference/extensions/expressjs-framework.rst Outdated Show resolved Hide resolved
docs/reference/extensions/expressjs-framework.rst Outdated Show resolved Hide resolved
docs/explanation/extensions/expressjs-framework.rst Outdated Show resolved Hide resolved
docs/explanation/extensions/expressjs-framework.rst Outdated Show resolved Hide resolved
docs/explanation/extensions/expressjs-framework.rst Outdated Show resolved Hide resolved
docs/explanation/extensions/expressjs-framework.rst Outdated Show resolved Hide resolved
docs/tutorial/expressjs.rst Outdated Show resolved Hide resolved
docs/tutorial/expressjs.rst Outdated Show resolved Hide resolved
:end-before: [docs:curl-expressjs-bare-rock-end]
:dedent: 2

Unsurprisingly, the ExpressJS application should still respond with
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@erinecon do you think we should have the "Unsuprisingly" qualifier here? Maybe some users are suprised that we got rid of a bunch of stuff and it is still working

docs/tutorial/expressjs.rst Outdated Show resolved Hide resolved
docs/tutorial/expressjs.rst Outdated Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// [docs:append-lines]
var timeRouter = require('./routes/time');
app.use('/time', timeRouter);
// [docs:append-lines-end]
export app;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And then use the start-after, end-before directive

Comment on lines +46 to +48
parts:
expressjs-framework/install-app:
npm-include-node: false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps remove this since it is the default

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And perhaps move this as the first one

Comment on lines +86 to +88
parts:
expressjs-framework/install-app:
npm-include-node: false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove this and have it before the other bare one

@@ -131,7 +131,7 @@ execute: |
retry -n 5 --wait 2 curl --fail localhost:8000/time/
# [docs:curl-time]
curl localhost:8000/time/
curl --fail localhost:8000/time/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we do this for all extensions and all curl commands please

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove this? It should get auto generated

@@ -117,7 +117,7 @@ execute: |
retry -n 5 --wait 2 curl --fail localhost:8000/time

# [docs:curl-time]
curl localhost:8000/time
curl --fail localhost:8000/time
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also for the other curls for this file

@@ -118,7 +118,7 @@ execute: |
retry -n 5 --wait 2 curl --fail localhost:8000/time
# [docs:curl-time]
curl localhost:8000/time
curl --fail localhost:8000/time
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also here for the other curls

Copy link
Contributor

@jdkandersson jdkandersson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is close now!

Comment on lines +53 to +59
@override
def get_parts_snippet(self) -> dict[str, Any]:
"""Return the parts to add to parts.

This is unused but is required by the ABC.
"""
return {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps switch the order to match the other frameworks

logpath_report=False,
)
package_json_contents = package_json_file.read_text(encoding="utf-8")
return json.loads(package_json_contents)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's check whether it is a dictionary since it could be something else. We should probably also check for invalid JSON

doc_slug="/reference/extensions/expressjs-framework",
logpath_report=False,
)
if "name" not in self._app_package_json:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's check name is a string

Comment on lines +130 to +132
"cp ${CRAFT_PART_BUILD}/.npmrc ${CRAFT_PART_INSTALL}/lib/node_modules/"
f"{self._app_name}/.npmrc\n"
f"ln -s /lib/node_modules/{self._app_name} ${{CRAFT_PART_INSTALL}}/app\n"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we document why we do this in the explanation please?

)
return install_app_part

@property
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check whether these can be functions

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we remove this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's remove all of these

docker run --name "${NAME}-container" -d -p 8137:3000 "${IMAGE}"
retry -n 5 --wait 2 curl localhost:8137
http_status=$(curl -s -o /dev/null -w "%{http_code}" localhost:8137)
[ "${http_status}" -eq 200 ]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps extend this to also customise the version of node

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's check we get the expected version of node

@pytest.mark.parametrize(
"package_json_contents, error_message",
[
("{}", "missing start script"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps include not a dict and a name not a string



@pytest.mark.usefixtures("expressjs_extension", "package_json_file")
def test_expressjs_extension_default(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's put the 4 scenarios here:

  • 24.04 base and node not customised
  • 24.04 base and node customised
  • bare base and node not customised
  • bare base and node version customised

Then we don't need the sub functions. It would probably be best to do this using parametrize

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants