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

fix: compile nmp library as 'commonjs' module #1666

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

vitaliy-guliy
Copy link

@vitaliy-guliy vitaliy-guliy commented Dec 23, 2024

Description of Changes

Compile generated @devfile/api node package as commonjs module instead of node:module.

It was around two years ago when the @devfile/api package was published as commonjs module https://www.npmjs.com/package/@devfile/api/v/2.2.1-alpha-1667236163?activeTab=code

Since that time all the node libraries generated by openapi-generator are being compiled as node:module.
( go to https://www.npmjs.com/package/@devfile/api?activeTab=code, open package.json and look at type property )

Both Che Dashboard and Che Code projects are compiled as commonjs.

There is a well known restriction, that node:modue cannot be included into commonjs module using import, require should be used instead.

Che Dashboard and Che Code projects both use @devfile/api. When we package dashboard and che-code with webpack, we do not have any issues ( btw, this is a reason why we didn't have the problem for a long time). But when we try to compile the project without using webpack and then run it in a development mode (browser downloads a thousand of separate files), we face a problem with loading some files from @devfile/api.

The original issue highlighting a problem eclipse-che/che#23163
A workaround after which I decided to open this PR che-incubator/che-code#472

Tests Performed

Explain what tests you personally ran to ensure the changes are functioning as expected.

How To Test

Instructions for the reviewer on how to test your changes.

Notes To Reviewer

Any notes you would like to include for the reviewer.

apply_sed 's/\"description\": \".*\"/"description": "Typescript types for devfile api"/g' $WORK_DIR/typescript-models/package.json
apply_sed 's/\"repository\": \".*\"/"repository": "devfile\/api"/g' $WORK_DIR/typescript-models/package.json
apply_sed 's/\"license\": \".*\"/"license": "Apache-2.0"/g' $WORK_DIR/typescript-models/package.json
apply_sed 's/\"@types\/bluebird\": \".*\"/"@types\/bluebird": "3.5.21"/g' $WORK_DIR/typescript-models/package.json
Copy link

Choose a reason for hiding this comment

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

Do we know if it's okay to remove

    apply_sed 's/\"@types\/bluebird\": \".*\"/"@types\/bluebird": "3.5.21"/g' $WORK_DIR/typescript-models/package.json

?

Copy link
Author

Choose a reason for hiding this comment

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

I could have deleted it by accident.
I will double check it.

Copy link
Author

Choose a reason for hiding this comment

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

I recalled why did I remove it at all, there was no dependency on bluebird in package.json.

To check, go to https://www.npmjs.com/package/@devfile/api?activeTab=code and open existing package.json

Copy link
Contributor

@svor svor left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link

openshift-ci bot commented Jan 27, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: dkwon17, svor, vitaliy-guliy

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link
Member

@michael-valdron michael-valdron left a comment

Choose a reason for hiding this comment

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

@vitaliy-guliy Thank you for your contribution!

Just have one suggestion about adding to the documentation, looks good to me otherwise.

echo "[INFO] preparing package.json"
######################################################################################################

echo "$(jq '. += {"name": "@devfile/api"}' package.json)" > package.json
Copy link
Member

Choose a reason for hiding this comment

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

With the addition of jq to this script I wonder if it makes sense to include it to the list of prerequisites? Also node though I feel like this should of been there before for generating typescript models.

Copy link
Author

Choose a reason for hiding this comment

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

If we speak about the action that builds and then publishes the typescript models, it runs on ubuntu and there is a dedicated section to install node https://github.com/devfile/api/blob/main/.github/workflows/release-typescript-models.yaml#L48-L53. So no issues with it.

If you want to build typescript models locally, you definitely need to have jq and node installed.
I think it make sense to add both jq and node to the list of prerequisites (I'll do it)

Btw, typescript models are generated in a separate container. Node is used then to build and publish the generated library.

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

Successfully merging this pull request may close these issues.

4 participants