MCPcopy
hub / github.com/esm-dev/esm.sh / Add

Function Add

cli/command_add.go:67–83  ·  view source on GitHub ↗

Add adds imports to "importmap" script

()

Source from the content-addressed store, hash-verified

65
66// Add adds imports to "importmap" script
67func Add() {
68 all := flag.Bool("all", false, "add all modules of the import")
69 a := flag.Bool("a", false, "add all modules of the import")
70 noPrompt := flag.Bool("no-prompt", false, "add imports without prompt")
71 noSRI := flag.Bool("no-sri", false, "do not generate SRI for the import")
72 specifiers, help := parseCommandFlags()
73
74 if help || len(specifiers) == 0 {
75 fmt.Print(addHelpMessage)
76 return
77 }
78
79 err := updateImportMap(set.New(specifiers...).Values(), *all || *a, *noPrompt, *noSRI)
80 if err != nil {
81 fmt.Println(term.Red("✖︎"), "Failed to add imports: "+err.Error())
82 }
83}
84
85func updateImportMap(specifiers []string, all bool, noPrompt bool, noSRI bool) (err error) {
86 indexHtml, exists, err := lookupClosestFile("index.html")

Callers 1

RunFunction · 0.85

Calls 4

parseCommandFlagsFunction · 0.85
updateImportMapFunction · 0.85
ValuesMethod · 0.80
ErrorMethod · 0.80

Tested by

no test coverage detected