--- a/src/Pure/System/nodejs.scala Tue Sep 09 15:37:38 2025 +0200
+++ b/src/Pure/System/nodejs.scala Tue Sep 09 17:39:04 2025 +0200
@@ -14,65 +14,48 @@
val default_version = "22.17.0"
- def context(
- platform_context: Isabelle_Platform.Context = Isabelle_Platform.Context(),
- version: String = default_version
- ): Context = new Context(platform_context, version)
-
def setup(
base_dir: Path,
platform_context: Isabelle_Platform.Context = Isabelle_Platform.Context(),
version: String = default_version,
packages: List[String] = Nil
): Directory = {
- context(platform_context = platform_context, version = version)
- .setup(base_dir, packages = packages)
+ val platform = platform_context.isabelle_platform
+ val progress = platform_context.progress
+
+ val platform_name =
+ if (platform.is_windows) "win" else if (platform.is_macos) "darwin" else "linux"
+
+ val arch = if (platform.is_arm) "arm64" else "x64"
+ val full_name = "node-v" + version + "-" + platform_name + "-" + arch
+
+ val download_ext = if (platform.is_windows) "zip" else "tar.gz"
+ val download_url = "https://nodejs.org/dist/v" + version + "/" + full_name + "." + download_ext
+
+ Isabelle_System.with_tmp_file("node", ext = download_ext) { archive =>
+ progress.echo("Getting Node.js ...")
+ Isabelle_System.download_file(download_url, archive)
+
+ progress.echo("Installing node ...")
+ Isabelle_System.extract(archive, base_dir)
+ val node_dir = new Directory(platform_context, base_dir + Path.basic(full_name))
+
+ for (name <- packages) node_dir.install(name)
+
+ node_dir
+ }
}
- class Context private[Nodejs](val platform_context: Isabelle_Platform.Context, version: String) {
+ class Directory private[Nodejs](
+ val platform_context: Isabelle_Platform.Context,
+ val path: Path
+ ) {
def platform: Isabelle_Platform = platform_context.isabelle_platform
def progress: Progress = platform_context.progress
- override def toString: String =
- "node-" + version + "-" + platform.ISABELLE_PLATFORM(windows = true, apple = true)
-
- def arch: String = if (platform.is_arm) "arm64" else "x64"
-
- def platform_name: String =
- if (platform.is_windows) "win" else if (platform.is_macos) "darwin" else "linux"
-
- def full_name: String = "node-v" + version + "-" + platform_name + "-" + arch
-
- def download_ext: String = if (platform.is_windows) "zip" else "tar.gz"
-
- def download_url: String =
- "https://nodejs.org/dist/v" + version + "/" + full_name + "." + download_ext
-
- def setup(base_dir: Path, packages: List[String] = Nil): Directory = {
- Isabelle_System.with_tmp_file("node", ext = download_ext) { archive =>
- progress.echo("Getting Node.js ...")
- Isabelle_System.download_file(download_url, archive)
+ override def toString: String = path.file_name
- progress.echo("Installing node ...")
- Isabelle_System.extract(archive, base_dir)
- val node_dir = new Directory(this, base_dir + Path.basic(full_name))
-
- for (name <- packages) node_dir.install(name)
-
- node_dir
- }
- }
- }
-
- class Directory private[Nodejs](val context: Context, val path: Path) {
- override def toString: String = path.toString
-
- def platform_context: Isabelle_Platform.Context = context.platform_context
- def progress: Progress = context.progress
-
- def bin_dir: Path =
- if (platform_context.isabelle_platform.is_windows) path
- else path + Path.basic("bin")
+ def bin_dir: Path = if (platform.is_windows) path else path + Path.basic("bin")
def path_setup: String =
"export PATH=" + Bash.string(platform_context.standard_path(bin_dir)) + """:"$PATH""""