@@ -305,13 +305,7 @@ func (p *Package) build(buildctx *buildContext) (err error) {
305305 log .WithField ("package" , p .FullName ()).WithField ("version" , version ).Info ("build succeded" )
306306 }()
307307
308- pkgdir := p .FullName ()
309- pkgdir = strings .Replace (pkgdir , "/" , "-" , - 1 )
310- pkgdir = strings .Replace (pkgdir , ":" , "--" , - 1 )
311- pkgdir = pkgdir + "." + version
312- // components in the workspace root would otherwise start with -- which breaks a lot of shell commands
313- pkgdir = strings .TrimPrefix (pkgdir , "--" )
314-
308+ pkgdir := p .FilesystemSafeName () + "." + version
315309 builddir := filepath .Join (buildctx .BuildDir (), pkgdir )
316310 if _ , err := os .Stat (builddir ); ! os .IsNotExist (err ) {
317311 err := os .RemoveAll (builddir )
@@ -324,14 +318,16 @@ func (p *Package) build(buildctx *buildContext) (err error) {
324318 return err
325319 }
326320
327- cpargs := []string {"--parents" }
328- for _ , src := range p .Sources {
329- cpargs = append (cpargs , strings .TrimPrefix (src , p .C .Origin + "/" ))
330- }
331- cpargs = append (cpargs , builddir )
332- err = run (getRunPrefix (p ), nil , p .C .Origin , "cp" , cpargs ... )
333- if err != nil {
334- return err
321+ if len (p .Sources ) > 0 {
322+ cpargs := []string {"--parents" }
323+ for _ , src := range p .Sources {
324+ cpargs = append (cpargs , strings .TrimPrefix (src , p .C .Origin + "/" ))
325+ }
326+ cpargs = append (cpargs , builddir )
327+ err = run (getRunPrefix (p ), nil , p .C .Origin , "cp" , cpargs ... )
328+ if err != nil {
329+ return err
330+ }
335331 }
336332
337333 result , _ := buildctx .LocalCache .Location (p )
@@ -386,31 +382,44 @@ func (p *Package) buildTypescript(buildctx *buildContext, wd, result string) (er
386382 commands = append (commands , []string {"cp" , filepath .Join (p .C .Origin , cfg .TSConfig ), "." })
387383 }
388384
385+ if cfg .Packaging == TypescriptOfflineMirror {
386+ commands = append (commands , [][]string {
387+ {"mkdir" , "_mirror" },
388+ {"sh" , "-c" , "echo yarn-offline-mirror \" ./_mirror\" > .yarnrc" },
389+ }... )
390+ }
391+
389392 pkgYarnLock := "pkg-yarn.lock"
390393 for _ , deppkg := range p .GetTransitiveDependencies () {
391394 builtpkg , ok := buildctx .LocalCache .Location (deppkg )
392395 if ! ok {
393396 return PkgNotBuiltErr {deppkg }
394397 }
395398
399+ tgt := deppkg .FilesystemSafeName ()
400+ if cfg .Packaging == TypescriptOfflineMirror {
401+ fn := fmt .Sprintf ("%s.tar.gz" , tgt )
402+ commands = append (commands , []string {"cp" , builtpkg , filepath .Join ("_mirror" , fn )})
403+ builtpkg = filepath .Join (wd , "_mirror" , fn )
404+ }
405+
396406 if deppkg .Type == TypescriptPackage {
397407 cfg , ok := deppkg .Config .(TypescriptPkgConfig )
398- if ! ok || ! cfg .Library {
399- return xerrors .Errorf ("cannot depend on typescript application packages : %s" , deppkg .FullName ())
408+ if ! ok || cfg .Packaging != TypescriptLibrary {
409+ return xerrors .Errorf ("can only depend on typescript libraries : %s" , deppkg .FullName ())
400410 }
401411
402412 // make previously built package availabe through yarn lock
403413 commands = append (commands , []string {"sh" , "-c" , fmt .Sprintf ("tar Ozfx %s package/%s | sed '/resolved /c\\ resolved \" file://%s\" ' >> yarn.lock" , builtpkg , pkgYarnLock , builtpkg )})
404414 } else {
405- tgt := strings .Replace (deppkg .FullName (), "/" , "-" , - 1 )
406415 commands = append (commands , [][]string {
407416 {"mkdir" , tgt },
408417 {"tar" , "xfz" , builtpkg , "-C" , tgt },
409418 }... )
410419 }
411420 }
412421
413- if cfg .Library {
422+ if cfg .Packaging == TypescriptLibrary {
414423 // We can't modify the `yarn pack` generated tar file without runnign the risk of yarn blocking when attempting to unpack it again. Thus, we must include the pkgYarnLock in the npm
415424 // package we're building. To this end, we modify the package.json of the source package.
416425 pkgJSONFilename := filepath .Join (wd , "package.json" )
@@ -452,14 +461,27 @@ func (p *Package) buildTypescript(buildctx *buildContext, wd, result string) (er
452461 yarnMutex = "network"
453462 }
454463 yarnCache := filepath .Join (buildctx .BuildDir (), "yarn-cache" )
455- commands = append (commands , []string {"yarn" , "install" , "--mutex" , yarnMutex , "--cache-folder" , yarnCache })
456- if len (cfg .BuildCmd ) == 0 {
464+ if len (cfg .Commands .Install ) == 0 {
465+ commands = append (commands , []string {"yarn" , "install" , "--mutex" , yarnMutex , "--cache-folder" , yarnCache })
466+ } else {
467+ commands = append (commands , cfg .Commands .Install )
468+ }
469+ if len (cfg .Commands .Build ) == 0 {
457470 commands = append (commands , []string {"npx" , "tsc" })
458471 } else {
459- commands = append (commands , cfg .BuildCmd )
472+ commands = append (commands , cfg .Commands . Build )
460473 }
461474
462- if cfg .Library {
475+ if cfg .Packaging == TypescriptOfflineMirror {
476+ dst := filepath .Join ("_mirror" , fmt .Sprintf ("%s.tar.gz" , p .FilesystemSafeName ()))
477+ commands = append (commands , [][]string {
478+ {"sh" , "-c" , fmt .Sprintf ("yarn generate-lock-entry --resolved file://./%s > _mirror/content_yarn.lock" , dst )},
479+ {"sh" , "-c" , "cat yarn.lock >> _mirror/content_yarn.lock" },
480+ {"yarn" , "pack" , "--filename" , dst },
481+ {"sh" , "-c" , "#!/bin/bash\n " + `echo cd \$\(dirname \"\${BASH_SOURCE[0]}\"\) \&\& sed \'s?resolved \"file://.\*\/?resolved \"file:\/\/\'\$\(pwd\)\'\/?g\' content_yarn.lock > _mirror/get_yarn_lock.sh` },
482+ {"tar" , "cfz" , result , "-C" , "_mirror" , "." },
483+ }... )
484+ } else if cfg .Packaging == TypescriptLibrary {
463485 commands = append (commands , [][]string {
464486 {"sh" , "-c" , fmt .Sprintf ("yarn generate-lock-entry --resolved file://%s > %s" , result , pkgYarnLock )},
465487 {"yarn" , "pack" , "--filename" , result },
@@ -491,7 +513,7 @@ func (p *Package) buildGo(buildctx *buildContext, wd, result string) (err error)
491513 return PkgNotBuiltErr {dep }
492514 }
493515
494- tgt := filepath .Join ("_deps" , strings . Replace ( dep .FullName (), "/" , "-" , - 1 ))
516+ tgt := filepath .Join ("_deps" , dep .FilesystemSafeName ( ))
495517 commands = append (commands , [][]string {
496518 {"mkdir" , tgt },
497519 {"tar" , "xfz" , builtpkg , "-C" , tgt },
@@ -518,7 +540,7 @@ func (p *Package) buildGo(buildctx *buildContext, wd, result string) (err error)
518540 if ! cfg .DontCheckGoFmt {
519541 commands = append (commands , []string {"sh" , "-c" , `if [ ! $(go fmt ./... | wc -l) -eq 0 ]; then echo; echo; echo please gofmt your code; echo; echo; exit 1; fi` })
520542 }
521- if ! cfg .Library {
543+ if cfg .Packaging == GoApp {
522544 cmd := []string {"go" , "build" }
523545 cmd = append (cmd , cfg .BuildFlags ... )
524546 cmd = append (cmd , "." )
@@ -554,7 +576,7 @@ func (p *Package) buildDocker(buildctx *buildContext, wd, result string) (err er
554576 return PkgNotBuiltErr {dep }
555577 }
556578
557- tgt := strings . Replace ( dep .FullName (), "/" , "-" , - 1 )
579+ tgt := dep .FilesystemSafeName ( )
558580 commands = append (commands , [][]string {
559581 {"mkdir" , tgt },
560582 {"tar" , "xfz" , fn , "-C" , tgt },
@@ -619,7 +641,7 @@ func (p *Package) buildGeneric(buildctx *buildContext, wd, result string) (err e
619641 return PkgNotBuiltErr {dep }
620642 }
621643
622- tgt := strings . Replace ( dep .FullName (), "/" , "-" , - 1 )
644+ tgt := dep .FilesystemSafeName ( )
623645 commands = append (commands , [][]string {
624646 {"mkdir" , tgt },
625647 {"tar" , "xfz" , fn , "-C" , tgt },
0 commit comments