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

Method buildPath

server/build.go:201–254  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

199}
200
201func (ctx *BuildContext) buildPath() {
202 asteriskPrefix := ""
203 if ctx.externalAll {
204 asteriskPrefix = "*"
205 }
206
207 esm := ctx.esmPath
208 if ctx.target == "types" {
209 if strings.HasSuffix(esm.SubPath, ".d.ts") {
210 ctx.path = fmt.Sprintf(
211 "/%s%s/%s%s",
212 asteriskPrefix,
213 esm.PackageId(),
214 ctx.getBuildArgsPrefix(true),
215 esm.SubPath,
216 )
217 } else {
218 ctx.path = "/" + esm.String()
219 }
220 return
221 }
222
223 name := strings.TrimSuffix(path.Base(esm.PkgName), ".js")
224 if esm.SubPath != "" {
225 if esm.SubPath == name {
226 // if the sub-module name is same as the package name
227 name = "__" + esm.SubPath
228 } else {
229 name = esm.SubPath
230 }
231 // workaround for es5-ext "../#/.." path
232 if esm.PkgName == "es5-ext" {
233 name = strings.ReplaceAll(name, "/#/", "/%23/")
234 }
235 }
236
237 if ctx.dev {
238 name += ".development"
239 }
240 switch ctx.bundleMode {
241 case BundleDeps:
242 name += ".bundle"
243 case BundleFalse:
244 name += ".nobundle"
245 }
246 ctx.path = fmt.Sprintf(
247 "/%s%s/%s%s/%s.mjs",
248 asteriskPrefix,
249 esm.PackageId(),
250 ctx.getBuildArgsPrefix(ctx.target == "types"),
251 ctx.target,
252 name,
253 )
254}
255
256func (ctx *BuildContext) buildModule(analyzeMode bool) (meta *BuildMeta, includes [][2]string, err error) {
257 if err = ctx.checkCanceled(); err != nil {

Callers 1

PathMethod · 0.95

Calls 3

getBuildArgsPrefixMethod · 0.95
PackageIdMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected