@@ -215,23 +215,18 @@ impl InitCommand {
215
215
. pop_last ( )
216
216
. context ( "scripts package not found" ) ?;
217
217
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" ) ?;
219
223
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" ) ?;
233
228
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 {
235
230
anyhow:: bail!( "scripts package has no scripts." )
236
231
} ;
237
232
@@ -248,9 +243,9 @@ impl InitCommand {
248
243
. or_insert ( toml_edit:: Item :: Table ( toml_edit:: Table :: new ( ) ) ) ;
249
244
250
245
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 ( ) ) ;
254
249
255
250
for ( alias, ( spec, ty) ) in pkg_ref. dependencies {
256
251
if ty != DependencyType :: Peer {
@@ -264,14 +259,18 @@ impl InitCommand {
264
259
let field = & mut dev_deps[ alias. as_str ( ) ] ;
265
260
field[ "name" ] = toml_edit:: value ( spec. name . to_string ( ) ) ;
266
261
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 ( ) ) ;
272
264
}
273
265
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
+ }
275
274
} else {
276
275
println ! (
277
276
"{ERROR_PREFIX}: no scripts package configured, this can cause issues with Roblox compatibility"
0 commit comments