Skip to content

Commit e4f496f

Browse files
committed
feat: add engines when initing project
When initializing a project, the `engines` section will now be copied over from the scripts package.
1 parent a99420e commit e4f496f

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
- Add dev only installs in #32 by @Stefanuk12
1111
- Add `PESDE_HOME` variable (defaults to $HOME/.pesde) to override pesde's directory's location by @daimond113
1212
- Add `--target` argument to execute command by @daimond113
13+
- Add `engines` when initializing a project based on the scripts package's by @daimond113
1314

1415
### Fixed
1516
- Download engines in install step rather than lazily by @daimond113

src/cli/commands/init.rs

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -215,23 +215,18 @@ impl InitCommand {
215215
.pop_last()
216216
.context("scripts package not found")?;
217217

218-
let id = Arc::new(PackageId::new(PackageNames::Pesde(scripts_pkg_name), v_id));
218+
let mut file = source
219+
.read_index_file(&scripts_pkg_name, &project)
220+
.await
221+
.context("failed to read scripts package index file")?
222+
.context("scripts package not found in index")?;
219223

220-
let target = source
221-
.get_target(
222-
&pkg_ref,
223-
&GetTargetOptions {
224-
project: project.clone(),
225-
// HACK: the pesde package source doesn't use the path, so we can just use an empty one
226-
path: Path::new("").into(),
227-
id: id.clone(),
228-
// HACK: the pesde package source doesn't use the engines, so we can just use an empty map
229-
engines: Default::default(),
230-
},
231-
)
232-
.await?;
224+
let entry = file
225+
.entries
226+
.remove(&v_id)
227+
.context("failed to remove scripts package entry")?;
233228

234-
let Some(scripts) = target.scripts().filter(|s| !s.is_empty()) else {
229+
let Some(scripts) = entry.target.scripts().filter(|s| !s.is_empty()) else {
235230
anyhow::bail!("scripts package has no scripts.")
236231
};
237232

@@ -248,9 +243,9 @@ impl InitCommand {
248243
.or_insert(toml_edit::Item::Table(toml_edit::Table::new()));
249244

250245
let field = &mut dev_deps["scripts"];
251-
field["name"] = toml_edit::value(id.name().to_string());
252-
field["version"] = toml_edit::value(format!("^{}", id.version_id().version()));
253-
field["target"] = toml_edit::value(id.version_id().target().to_string());
246+
field["name"] = toml_edit::value(scripts_pkg_name.to_string());
247+
field["version"] = toml_edit::value(format!("^{}", v_id.version()));
248+
field["target"] = toml_edit::value(v_id.target().to_string());
254249

255250
for (alias, (spec, ty)) in pkg_ref.dependencies {
256251
if ty != DependencyType::Peer {
@@ -264,14 +259,18 @@ impl InitCommand {
264259
let field = &mut dev_deps[alias.as_str()];
265260
field["name"] = toml_edit::value(spec.name.to_string());
266261
field["version"] = toml_edit::value(spec.version.to_string());
267-
field["target"] = toml_edit::value(
268-
spec.target
269-
.unwrap_or_else(|| id.version_id().target())
270-
.to_string(),
271-
);
262+
field["target"] =
263+
toml_edit::value(spec.target.unwrap_or_else(|| v_id.target()).to_string());
272264
}
273265

274-
// TODO: add engines
266+
if !entry.engines.is_empty() {
267+
let engines = manifest["engines"]
268+
.or_insert(toml_edit::Item::Table(toml_edit::Table::new()));
269+
270+
for (engine, req) in entry.engines {
271+
engines[engine.to_string()] = toml_edit::value(req.to_string());
272+
}
273+
}
275274
} else {
276275
println!(
277276
"{ERROR_PREFIX}: no scripts package configured, this can cause issues with Roblox compatibility"

0 commit comments

Comments
 (0)