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

Use npm instead of yarn to build Theia #14481

Merged
merged 10 commits into from
Jan 8, 2025

Conversation

tsmaeder
Copy link
Contributor

@tsmaeder tsmaeder commented Nov 19, 2024

What it does

This PR rewrites the Theia build process to use npm in stead of yarn. This required a couple of changes:

Contrary to yarn, npm does not invoke the prepare scripts of workspace packages in the order of their dependencies (npm/cli#3034). So instead of relying on yarn install to invoke the necessary build scripts, we have to invoke the build process explicitly after the npm install. The build process is built on this logic:

  1. Each package has a script called "build". The goal of that target is to fully build all artifacts this repo produces. For regular Theia packages, this is just incrementally compiling the typescript sources of the package an it's dependencies, but for applications, for example, it means creating the application bundle. So calling "build" in an application package should be all that's needed in regular development
  2. To build the repo initially after check-out, there are a couple of additinal steps necesary:
    • compile build tools (re-exports package)
    • generate re-exports where applicable
    • compile all packages
    • build alll application packages
      This can be achieved by invoking npm run build in the repo root.

Fixes #13948

Contributed on behalf of STMicroelectronics

There are a couple of issues in npm that currently require manual edits of package-lock.json

How to test

Make sure we can build Theia as described above and the apps work fine.

Follow-ups

Attribution

Contributed on behalf of STMicroelectronics

Review checklist

Reminder for reviewers

@dankeboy36
Copy link
Contributor

Fixes #13948

Possible related: #775

@tsmaeder
Copy link
Contributor Author

@msujew @sdirix the PR checks now pass and it's ready to be reviewed minus doc.

Copy link
Member

@sdirix sdirix left a comment

Choose a reason for hiding this comment

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

So far it works very well.

I used npm ci to install. I tested all applications and was able to build and start all of them. I also tested watching for the browser application. Tests also completed successfully.

Linting is currently broken but this is already mentioned in the current PR description.

@theia/request: > @theia/[email protected] lint
@theia/request: > theiaext lint
@theia/request: $ eslint --cache=true --no-error-on-unmatched-pattern=true "{src,test}/**/*.{ts,tsx}"
@theia/request: /bin/sh: 1: node: not found
@theia/request: Oops! Something went wrong! :(
@theia/request: ESLint: 8.57.1
@theia/request: SyntaxError: Failed to load plugin '@theia' declared in '.eslintrc.js » ../../configs/build.eslintrc.json » ./base.eslintrc.json': Unexpected end of JSON input
@theia/request:     at JSON.parse (<anonymous>)
@theia/request:     at PackageReExports.FromPackageSync (/home/user/git/theia/dev-packages/private-re-exports/lib/package-re-exports.js:127:47)
@theia/request:     at Object.<anonymous> (/home/user/git/theia/dev-packages/private-eslint-plugin/rules/shared-dependencies.js:24:40)

@@ -1,7 +1,6 @@
root = true

[*]
insert_final_newline = true
Copy link
Member

Choose a reason for hiding this comment

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

Can we keep this? Why remove it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because we now have the preference "files.insertFinalNewline" which acomplishes the same thing.

.github/workflows/ci-cd.yml Outdated Show resolved Hide resolved
dev-packages/private-ext-scripts/package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
package.json Show resolved Hide resolved
package.json Show resolved Hide resolved
package.json Show resolved Hide resolved
dev-packages/private-ext-scripts/package.json Show resolved Hide resolved
package.json Show resolved Hide resolved
Copy link
Member

@msujew msujew left a comment

Choose a reason for hiding this comment

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

Works pretty well, but there are still a few calls to yarn littered throughout the build scripts:

There might be more. See also below.

packages/electron/package.json Show resolved Hide resolved
scripts/compile-references.js Outdated Show resolved Hide resolved
@tsmaeder tsmaeder marked this pull request as ready for review December 18, 2024 15:24
@tsmaeder tsmaeder requested a review from sdirix December 18, 2024 15:24
@tsmaeder
Copy link
Contributor Author

@JonasHelming in response to your question elsewhere, the documentation on https://theia-ide.org/ mostly uses the yeoman generator output and the theia-ide repository as examples. While the output of the generator and theia-ide still use yarn, it makes no sense to update the documentation.

@tsmaeder tsmaeder requested a review from msujew January 3, 2025 10:20
@tsmaeder
Copy link
Contributor Author

tsmaeder commented Jan 6, 2025

@msujew @sdirix could I get some love for this one, please? If we merge it, we should merge it early in the release cycle.

Copy link
Member

@msujew msujew left a comment

Choose a reason for hiding this comment

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

Looks good to me know. Everything seems to work as expected without relying on yarn.

@sdirix
Copy link
Member

sdirix commented Jan 7, 2025

Linting fails for me with

  • Node 20.18.1
  • npm 10.8.2
  • Ubuntu 22.04

It errors in all packages with errors like this:

> @theia/[email protected] lint
> theiaext lint

$ eslint --cache=true --no-error-on-unmatched-pattern=true "{src,test}/**/*.{ts,tsx}"
/bin/sh: 1: node: not found

Oops! Something went wrong! :(

ESLint: 8.57.1

SyntaxError: Failed to load plugin '@theia' declared in '.eslintrc.js » ../../configs/build.eslintrc.json » ./base.eslintrc.json': Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at PackageReExports.FromPackageSync (/home/user/Git/theia/dev-packages/private-re-exports/lib/package-re-exports.js:127:47)
    at Object.<anonymous> (/home/user/Git/theia/dev-packages/private-eslint-plugin/rules/shared-dependencies.js:24:40)
    at Module._compile (node:internal/modules/cjs/loader:1469:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1548:10)
    at Module.load (node:internal/modules/cjs/loader:1288:32)
    at Module._load (node:internal/modules/cjs/loader:1104:12)
    at Module.require (node:internal/modules/cjs/loader:1311:19)
    at require (node:internal/modules/helpers:179:18)
    at Object.<anonymous> (/home/user/Git/theia/dev-packages/private-eslint-plugin/index.js:24:28)
Exit with failure status (2): eslint --cache=true --no-error-on-unmatched-pattern=true "{src,test}/**/*.{ts,tsx}"
npm error Lifecycle script `lint` failed with error:
npm error code 2
npm error path /home/user/Git/theia/packages/core
npm error workspace @theia/[email protected]
npm error location /home/user/Git/theia/packages/core
npm error command failed
npm error command sh -c theiaext lint

Linting works for me in the current yarn based mono repo.

@msujew
Copy link
Member

msujew commented Jan 7, 2025

@sdirix I had the same issue, it's related to some cached info. You need to run git clean -xfd once before running npm i.

@sdirix
Copy link
Member

sdirix commented Jan 7, 2025

@sdirix I had the same issue, it's related to some cached info. You need to run git clean -xfd once before running npm i.

Sadly I already tried that, the issue persists. Do you know how exactly the @theia import in the eslint config resolves? It seems that this step fails for me.

@tsmaeder
Copy link
Contributor Author

tsmaeder commented Jan 7, 2025

@sdirix what's your invocation sequence for lint?

@sdirix
Copy link
Member

sdirix commented Jan 7, 2025

I tried

npm ci
npm run lint

I also tried

npm ci
npm run compile
npm run lint
npm install
npm run lint

every time preceded by git clean -dfx

I also tried

npm ci
cd packages/core
npx eslint --cache=true --no-error-on-unmatched-pattern=true "{src,test}/**/*.{ts,tsx}"

I also tried changing @theia to @theia/eslint-plugin in the eslint config and I also tried removing @theia completely in the eslint config. These are then failing with different errors.

Fixes eclipse-theia#13948

Contributed on behalf of STMicroelectronics

Signed-off-by: Thomas Mäder <[email protected]>
Signed-off-by: Thomas Mäder <[email protected]>
Signed-off-by: Thomas Mäder <[email protected]>
Signed-off-by: Thomas Mäder <[email protected]>
Copy link
Member

@sdirix sdirix left a comment

Choose a reason for hiding this comment

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

Works for me now! Thanks for the fix.

Once we merge we should do a prerelease so we can do some real world testing in our downstream repositories (which are still yarn based) to verify that they continue working.

@tsmaeder tsmaeder merged commit 0036769 into eclipse-theia:master Jan 8, 2025
12 of 13 checks passed
@github-actions github-actions bot added this to the 1.58.0 milestone Jan 8, 2025
planger added a commit to eclipsesource/theia-e2e-test-suite that referenced this pull request Jan 9, 2025
planger added a commit to eclipsesource/theia-e2e-test-suite that referenced this pull request Jan 9, 2025
eclipse-theia/theia#14481

Contributed on behalf of STMicroelectronics
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Migrate away from yarn v1
4 participants