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

Package manager abstraction #420

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

Conversation

ptrdom
Copy link
Contributor

@ptrdom ptrdom commented May 5, 2022

References #417.

Main idea is to make a package manager abstraction that allows a flexible interaction with plugin's internals so that user's can extend the behavior however they wish.

TODO:

  • Implement pnpm.
  • Fix scripted tests.

@ptrdom ptrdom changed the title Package managers Package manager abstraction May 5, 2022
@ptrdom
Copy link
Contributor Author

ptrdom commented May 5, 2022

@julienrf @sjrd comments would be appreciated. Could I get some permissions to run CI at will, scripted tests are kind of clunky on my local machine. I could fix up tests that were broken prior to this PR too, but I will need to edit actual CI scripts because I have a feeling it needs some tinkering with Node/npm versions. I do not see where those AppVeyor scripts are located, but do we even need them with GitHub Actions being already in place?

@ptrdom
Copy link
Contributor Author

ptrdom commented May 5, 2022

Also, this very much breaks the backwards compatibility, but I assume that it is fine since the plugin is not v1 yet 😅 Let me know if that is not alright, there is definitely a way to stay backwards compatible, although the old design should be deprecated eventually - things like having both npm and yarn settings available simultaneously are obviously clunky.

@ptrdom
Copy link
Contributor Author

ptrdom commented May 9, 2022

@julienrf @sjrd Could you review this?

@sjrd
Copy link
Collaborator

sjrd commented May 9, 2022

I will try to find some time for it this week.

Comment on lines 581 to 643
packageManager.value match {
case aps: AddPackagesSupport =>
aps.addPackages(baseDir, installDir, log)(s"jsdom@$jsdomVersion")
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

There should be a case _ => here, which shows a clear error message to the user, through a throw new MessageOnlyException("error message here").

Comment on lines 408 to 409
val useYarn: SettingKey[Boolean] =
settingKey[Boolean]("Whether to use yarn for updates")
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should preserve all these keeps as @deprecated for compatibility reasons.
We can initialize packageManager based on the value of those deprecated settings.

*/
val useYarn: SettingKey[Boolean] =
settingKey[Boolean]("Whether to use yarn for updates")
val packageManager = SettingKey[PackageManager](
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be called jsPackageManager, to reduce the likelihood of collision with other sbt plugins.

useYarn := true
packageManager := scalajsbundler.Yarn()
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should therefore keep a test that uses the deprecated useYarn, in addition to the test that uses the new packageManager.

Comment on lines 11 to 12
npmExtraArgs in Compile := Seq("-silent"),
packageManager in Compile := Npm(installArgs = Seq("-silent"), addPackagesArgs = Seq("-silent")),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here. We'll need to keep one test that uses npmExtraArgs.

@@ -21,12 +22,10 @@ object NpmUpdateTasks {
def npmUpdate(baseDir: File,
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should keep a deprecated overload of this method for compatibility reasons, which will delegate to this one.

Also the Scaladoc needs updating.

@@ -45,18 +44,16 @@ object NpmUpdateTasks {
def npmInstallDependencies(baseDir: File,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here.

@@ -31,7 +31,8 @@ object PackageJsonTasks {
webpackVersion: String,
webpackDevServerVersion: String,
webpackCliVersion: String,
streams: Keys.TaskStreams
streams: Keys.TaskStreams,
packageManager: PackageManager
): BundlerFile.PackageJson = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here, and for the other methods below. We should keep deprecated aliases.

@@ -0,0 +1,2 @@
> fastOptJS::webpack
$ exists package-lock.json
Copy link
Collaborator

Choose a reason for hiding this comment

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

Missing EOL.

@@ -1 +1,2 @@
> fastOptJS::webpack
$ exists yarn.lock
Copy link
Collaborator

Choose a reason for hiding this comment

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

Missing EOL.

@ptrdom
Copy link
Contributor Author

ptrdom commented May 16, 2022

@sjrd Thank you for a very thorough review! I will make the changes as requested.

@ptrdom ptrdom force-pushed the package-managers branch 7 times, most recently from 4ef34f7 to e7413d9 Compare May 21, 2022 08:48
Comment on lines +24 to +29
- name: Enable Corepack
run: corepack enable
- name: Setup yarn
run: npm install -g [email protected]
run: corepack prepare [email protected] --activate
- name: Setup pnpm
run: corepack prepare [email protected] --activate
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Managing package manager installations inside and outside Corepack do not mix well, so we got to do it with Corepack only.

@ptrdom
Copy link
Contributor Author

ptrdom commented May 21, 2022

@sjrd I think I made all of the modifications you requested, PR is ready for a review. I also updated docs.

}

trait LockFileSupport {
val lockFileName: String
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would be better to convert this to a File to allow for better lockfile location customization.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Though I do not have the best idea on where to put PackageManager.Npm and PackageManager.Yarn so that baseDirectory is available during construction.

Atry added a commit to Atry/ReactToBindingHtml.scala that referenced this pull request Feb 1, 2023
Currently scalajs-bundler will always update the lock file, making working directory dirty on CI. See scalacenter/scalajs-bundler#420 and scalacenter/scalajs-bundler#406
@mims-github
Copy link

@ptrdom Thanks for this PR, would love to use pnpm with Scala.js. :)

Anything missing for this PR to be merged?

@julienrf julienrf requested a review from sjrd February 27, 2023 08:35
@nadenf
Copy link

nadenf commented Jun 29, 2023

@sjrd .. Can we request a review of this. I would be happy to add bun support as well on top of this.

Either way the JS community has much faster options than NPM right now which we should take advantage of.

@ptrdom
Copy link
Contributor Author

ptrdom commented Jun 29, 2023

I think this PR was ignored for long enough to assume that maintainers are not accepting any PRs to actually develop features, which is fine, but it would have been considerate towards community to explicitly state that.

My suggestions for plugin users who want a package manager abstraction:

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

Successfully merging this pull request may close these issues.

4 participants