Skip to content

Commit 46b9211

Browse files
authored
new: Add JavaScript toolchain support. (#2079)
* Add toolchain config. * Add project. * Add host func. * Rename host data. * Add host func mocker. * Split into object. * Add clean path. * Update api. * Update IDs. * chore: Release * Update changelog. * chore: Release * Undo.
1 parent e5b4898 commit 46b9211

48 files changed

Lines changed: 655 additions & 146 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,46 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
#### 🚀 Updates
6+
7+
- Added new JavaScript ecosystem toolchain WASM plugins. This was a large feature that required
8+
extensive work, as the JavaScript ecosystem is quite unique. The following plugins are being
9+
introduced:
10+
- `unstable_javascript`
11+
- A new JavaScript specific plugin that is a superset of all JavaScript runtimes (Deno coming
12+
soon).
13+
- Implements tier 1 and 2 features, and is now in charge of defining the package manager,
14+
installing dependencies, extending the project graph (aliases and tasks), parsing
15+
lockfiles/manifests, and much more.
16+
- Supports multiple lockfiles for each package manager.
17+
- `unstable_bun` and `unstable_node`
18+
- The JavaScript runtimes only implement tier 1 and 3 features, and only exist for installing
19+
the tool into the proto toolchain. Most functionality is now in the `unstable_javascript`
20+
plugin.
21+
- Supports settings for Bun/Node execution.
22+
- `unstable_npm`, `unstable_pnpm`, and `unstable_yarn`
23+
- The JavaScript package managers only implement tier 1 and 3 features, and only exist for
24+
installing the tool into the proto toolchain. Most functionality is now in the
25+
`unstable_javascript` plugin.
26+
- Supports settings for package installation.
27+
- npm now supports `npm-shrinkwrap.json`.
28+
- Is no longer configured within `node`, and is now configured at the top-level within
29+
`.moon/toolchain.yml`.
30+
- Deprecated the `moon run --profile` option.
31+
- This option was only used by Node.js, and is now a configuration setting for the `unstable_node`
32+
toolchain.
33+
34+
#### 🧩 Plugins
35+
36+
- WASM API
37+
- Added `MoonContext.get_project_root` and `get_project_root_from_source` methods.
38+
- Added `ExtendProjectGraphInput.toolchain_config` field.
39+
- Added `ExtendTaskCommandInput.toolchain_config` and `project` fields.
40+
- Added `ExtendTaskScriptInput.toolchain_config` and `project` fields.
41+
- Added `load_toolchain_config` and `load_project_toolchain_config` functions.
42+
- Added `load_toolchain_config_by_id` host function.
43+
344
## 1.39.4
445

546
#### 🐞 Fixes

Cargo.lock

Lines changed: 8 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ clap = { version = "4.5.41", default-features = false, features = [
2828
"error-context",
2929
] }
3030
clap_complete = "4.5.55"
31-
clean-path = "0.2.1"
3231
compact_str = { version = "0.9.0", default-features = false, features = [
3332
"serde",
3433
] }
@@ -104,7 +103,7 @@ proto_core = "0.51.5"
104103
proto_pdk_api = "0.29.1"
105104
proto_pdk_test_utils = "0.39.1"
106105
system_env = "0.8.2"
107-
version_spec = "0.9.4"
106+
version_spec = "0.9.5"
108107
warpgate = "0.26.1"
109108
warpgate_api = "0.16.1"
110109
warpgate_pdk = "0.15.1"

crates/action-graph/src/action_graph_builder.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl<'query> ActionGraphBuilder<'query> {
167167
toolchain_id: &Id,
168168
allow_override: bool,
169169
) -> Option<ToolchainSpec> {
170-
if let Some(config) = project.config.toolchain.plugins.get(toolchain_id) {
170+
if let Some(config) = project.config.toolchain.get_plugin_config(toolchain_id) {
171171
if !config.is_enabled() {
172172
return None;
173173
}
@@ -182,7 +182,11 @@ impl<'query> ActionGraphBuilder<'query> {
182182
}
183183
}
184184

185-
if let Some(config) = self.app_context.toolchain_config.plugins.get(toolchain_id) {
185+
if let Some(config) = self
186+
.app_context
187+
.toolchain_config
188+
.get_plugin_config(toolchain_id)
189+
{
186190
return Some(match &config.version {
187191
Some(version) => ToolchainSpec::new(toolchain_id.to_owned(), version.to_owned()),
188192
None => ToolchainSpec::new_global(toolchain_id.to_owned()),

crates/app/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ clap = { workspace = true, features = [
5353
] }
5454
clap_complete = { workspace = true }
5555
clap_complete_nushell = "4.5.8"
56-
clean-path = { workspace = true }
5756
convert_case = { workspace = true }
5857
diff = "0.1.13"
5958
iocraft = { workspace = true }

crates/app/src/commands/docker/prune.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,11 @@ pub async fn prune_toolchains(session: &MoonSession, manifest: &DockerManifest)
128128
let output = toolchain
129129
.install_dependencies(InstallDependenciesInput {
130130
context: toolchain_registry.create_context(),
131-
packages: Some(
132-
instance
133-
.projects
134-
.iter()
135-
.flat_map(|project| project.alias.clone())
136-
.collect(),
137-
),
131+
packages: instance
132+
.projects
133+
.iter()
134+
.flat_map(|project| project.alias.clone())
135+
.collect(),
138136
production: true,
139137
project: in_project.as_ref().map(|project| project.to_fragment()),
140138
root: toolchain.to_virtual_path(&instance.deps_root),

crates/app/src/commands/init/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ mod rust;
66
use crate::session::MoonSession;
77
use bun::init_bun;
88
use clap::Args;
9-
use clean_path::Clean;
109
use iocraft::prelude::{FlexDirection, View, element};
1110
use miette::IntoDiagnostic;
12-
use moon_common::{Id, consts::CONFIG_DIRNAME, is_test_env};
11+
use moon_common::{Id, consts::CONFIG_DIRNAME, is_test_env, path::clean_components};
1312
use moon_config::{load_toolchain_config_template, load_workspace_config_template};
1413
use moon_console::{
1514
Console,
@@ -205,7 +204,7 @@ pub async fn init(session: MoonSession, args: InitArgs) -> AppResult {
205204
};
206205

207206
let options = InitOptions {
208-
dir: dest_dir.clean(),
207+
dir: clean_components(dest_dir),
209208
force: args.force,
210209
minimal: args.minimal,
211210
yes: args.yes,

crates/app/src/commands/teardown.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ pub async fn teardown(session: MoonSession) -> AppResult {
2424
.teardown_toolchain_all(|registry, toolchain| TeardownToolchainInput {
2525
configured_version: session
2626
.toolchain_config
27-
.plugins
28-
.get(toolchain.id.as_str())
27+
.get_plugin_config(toolchain.id.as_str())
2928
.and_then(|plugin| plugin.version.clone()),
3029
context: registry.create_context(),
3130
toolchain_config: registry.create_config(&toolchain.id, &session.toolchain_config),

crates/app/src/session.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use moon_console::{Console, MoonReporter, create_console_theme};
1313
use moon_env::MoonEnvironment;
1414
use moon_extension_plugin::*;
1515
use moon_feature_flags::{FeatureFlags, Flag};
16-
use moon_plugin::PluginHostData;
16+
use moon_plugin::MoonHostData;
1717
use moon_process::ProcessRegistry;
1818
use moon_project_graph::ProjectGraph;
1919
use moon_task_graph::TaskGraph;
@@ -147,9 +147,11 @@ impl MoonSession {
147147

148148
pub async fn get_extension_registry(&self) -> miette::Result<Arc<ExtensionRegistry>> {
149149
let item = self.extension_registry.get_or_init(|| {
150-
let mut registry = ExtensionRegistry::new(PluginHostData {
150+
let mut registry = ExtensionRegistry::new(MoonHostData {
151151
moon_env: Arc::clone(&self.moon_env),
152152
proto_env: Arc::clone(&self.proto_env),
153+
toolchain_config: Arc::clone(&self.toolchain_config),
154+
workspace_config: Arc::clone(&self.workspace_config),
153155
workspace_graph: Arc::new(OnceLock::new()),
154156
});
155157

@@ -180,9 +182,11 @@ impl MoonSession {
180182
pub async fn get_toolchain_registry(&self) -> miette::Result<Arc<ToolchainRegistry>> {
181183
let item = self.toolchain_registry.get_or_init(|| {
182184
let mut registry = ToolchainRegistry::new(
183-
PluginHostData {
185+
MoonHostData {
184186
moon_env: Arc::clone(&self.moon_env),
185187
proto_env: Arc::clone(&self.proto_env),
188+
toolchain_config: Arc::clone(&self.toolchain_config),
189+
workspace_config: Arc::clone(&self.workspace_config),
186190
workspace_graph: Arc::new(OnceLock::new()),
187191
},
188192
self.toolchain_config.clone(),

crates/common/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "moon_common"
3-
version = "0.1.3"
3+
version = "0.1.4"
44
edition = "2024"
55
license = "MIT"
66
description = "Common utilities."

0 commit comments

Comments
 (0)