@@ -141,6 +141,8 @@ $resourceVersions = <|
141
141
"MessageFailure" -> "1.0.0" ,
142
142
"RelativeTimeString" -> "1.0.0" ,
143
143
"ReplaceContext" -> "1.0.0" ,
144
+ "ResourceFunctionMessage" -> "2.1.1" ,
145
+ "SecondsToQuantity" -> "1.2.0" ,
144
146
"SelectByCurrentValue" -> "1.0.1"
145
147
|> ;
146
148
@@ -471,13 +473,17 @@ importResourceFunction // beginDefinition;
471
473
importResourceFunction ::failure = "[ERROR] Failed to import resource function `1`. Aborting MX build." ;
472
474
importResourceFunction // Attributes = { HoldFirst };
473
475
476
+ importResourceFunction [ name_ String ] :=
477
+ importResourceFunction [ None , name ];
478
+
474
479
importResourceFunction [ symbol_ Symbol , name_ String ] :=
475
480
importResourceFunction [ symbol , name , Lookup [ $resourceVersions , name ] ];
476
481
477
- importResourceFunction [ symbol_ Symbol , name_ String , version_ String ] /; $mxFlag := Enclose [
482
+ importResourceFunction [ symbol_ Symbol , name_ String , version_ ] /; $mxFlag := Enclose [
478
483
Block [ { PrintTemporary },
479
- Module [ { sourceContext , targetContext , definition , replaced , newSymbol },
484
+ Module [ { sourceContext , targetContext , definition , replaced , inlined , newSymbol },
480
485
486
+ ConfirmAssert @ StringQ @ version ;
481
487
sourceContext = ConfirmBy [ ResourceFunction [ name , "Context" , ResourceVersion -> version ], StringQ ];
482
488
targetContext = $resourceFunctionContext <> name <> "`" ;
483
489
definition = ConfirmMatch [ ResourceFunction [ name , "DefinitionList" ], _ Language ` DefinitionList ];
@@ -490,21 +496,75 @@ importResourceFunction[ symbol_Symbol, name_String, version_String ] /; $mxFlag
490
496
_ Language ` DefinitionList
491
497
];
492
498
493
- ConfirmMatch [ Language ` ExtendedFullDefinition [ ] = replaced , _ Language ` DefinitionList ];
499
+ inlined = ConfirmMatch [ inlineDependentResourceFunctions @ replaced , _ Language ` DefinitionList ];
500
+
501
+ $importedResourceFunctions [ name ] = version ;
502
+ KeyDropFrom [ $dependentResourceFunctions , Keys @ $importedResourceFunctions ];
503
+
504
+ ConfirmMatch [ Language ` ExtendedFullDefinition [ ] = inlined , _ Language ` DefinitionList ];
494
505
495
506
newSymbol = ConfirmMatch [ Symbol [ targetContext <> name ], _ Symbol ? AtomQ ];
496
507
497
- ConfirmMatch [ symbol = newSymbol , newSymbol ]
508
+ importResourceFunction [ symbol , name , version ] =
509
+ If [ Unevaluated @ symbol === None ,
510
+ newSymbol ,
511
+ ConfirmMatch [ symbol = newSymbol , newSymbol ]
512
+ ]
498
513
]
499
514
],
500
515
(Message [ importResourceFunction ::failure , name ]; Abort [ ]) &
501
516
];
502
517
503
- importResourceFunction [ symbol_ Symbol , name_ String , version_ String ] :=
518
+ importResourceFunction [ symbol : Except [ None , _ Symbol ] , name_ String , version_ String ] :=
504
519
symbol := symbol = Block [ { PrintTemporary }, ResourceFunction [ name , "Function" , ResourceVersion -> version ] ];
505
520
506
521
importResourceFunction // endDefinition ;
507
522
523
+ $importedResourceFunctions = < | |> ;
524
+
525
+ (* ::**************************************************************************************************************:: *)
526
+ (* ::Subsection::Closed:: *)
527
+ (*importDependentResourceFunctions*)
528
+ importDependentResourceFunctions // beginDefinition ;
529
+
530
+ importDependentResourceFunctions [ ] :=
531
+ importDependentResourceFunctions @ Keys @ $dependentResourceFunctions ;
532
+
533
+ importDependentResourceFunctions [ { } ] :=
534
+ Null ;
535
+
536
+ importDependentResourceFunctions [ names : { __ String } ] := (
537
+ importResourceFunction /@ names ;
538
+ KeyDropFrom [ $dependentResourceFunctions , names ];
539
+ importDependentResourceFunctions @ Keys @ $dependentResourceFunctions
540
+ );
541
+
542
+ importDependentResourceFunctions // endDefinition ;
543
+
544
+ (* ::**************************************************************************************************************:: *)
545
+ (* ::Subsection::Closed:: *)
546
+ (*inlineDependentResourceFunctions*)
547
+ inlineDependentResourceFunctions // beginDefinition ;
548
+
549
+ inlineDependentResourceFunctions [ definition_ ] := ReplaceAll [
550
+ definition ,
551
+ {
552
+ HoldPattern @ ResourceFunction [ name_ String , OptionsPattern [ ] ] :> RuleCondition [
553
+ $dependentResourceFunctions [ name ] = True ;
554
+ Symbol [ $resourceFunctionContext <> name <> "`" <> name ]
555
+ ],
556
+ HoldPattern @ ResourceFunction [ name_ String , "Function" , OptionsPattern [ ] ] :> RuleCondition [
557
+ $dependentResourceFunctions [ name ] = True ;
558
+ Symbol [ $resourceFunctionContext <> name <> "`" <> name ]
559
+ ]
560
+ }
561
+ ];
562
+
563
+ inlineDependentResourceFunctions // endDefinition ;
564
+
565
+
566
+ $dependentResourceFunctions = < | |> ;
567
+
508
568
(* ::**************************************************************************************************************:: *)
509
569
(* ::Section::Closed:: *)
510
570
(*Error Handling*)
@@ -1509,6 +1569,7 @@ addToMXInitialization[
1509
1569
$cloudTextResources ;
1510
1570
$inlineExpressionRules ;
1511
1571
$releaseID ;
1572
+ importDependentResourceFunctions [ ];
1512
1573
];
1513
1574
1514
1575
(* :!CodeAnalysis::EndBlock:: *)
0 commit comments