diff --git a/containers/build_frontend.go b/containers/build_frontend.go index fb98888f..41e10178 100644 --- a/containers/build_frontend.go +++ b/containers/build_frontend.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "strings" "dagger.io/dagger" ) @@ -16,16 +17,19 @@ func NodeVersion(d *dagger.Client, src *dagger.Directory) *dagger.Container { WithExec([]string{"cat", ".nvmrc"}) } -func CompileFrontend(d *dagger.Client, platform dagger.Platform, src *dagger.Directory, opts *YarnCacheOpts, nodeVersion string) *dagger.Directory { +func CompileFrontend(d *dagger.Client, platform dagger.Platform, src *dagger.Directory, opts *YarnCacheOpts, version, nodeVersion string) *dagger.Directory { c := NodeContainer(d, NodeImage(nodeVersion), platform). WithDirectory("/src", src). WithWorkdir("/src") c = WithYarnCache(c, opts) + ersion := strings.TrimPrefix(version, "v") + // Get the node version from the 'src' directories '.nvmrc' file. public := c. WithExec([]string{"yarn", "install", "--immutable"}). + WithExec([]string{"npm", "version", ersion, "--no-git-tag-version"}). WithExec([]string{"yarn", "run", "build"}). WithExec([]string{"yarn", "run", "plugins:build-bundled"}). Directory("/src/public") diff --git a/containers/npm_packages.go b/containers/npm_packages.go index 3a770895..458b902f 100644 --- a/containers/npm_packages.go +++ b/containers/npm_packages.go @@ -2,6 +2,7 @@ package containers import ( "fmt" + "strings" "dagger.io/dagger" ) @@ -14,10 +15,13 @@ func NPMPackages(d *dagger.Client, platform dagger.Platform, src *dagger.Directo c = WithYarnCache(c, opts) + ersion := strings.TrimPrefix(version, "v") + c = c.WithExec([]string{"mkdir", "npm-packages"}). WithExec([]string{"yarn", "install", "--immutable"}). WithExec([]string{"yarn", "run", "packages:build"}). - // TODO: We should probably start reusing the yarn pnp map if we can figure that out isntead of rerunning yarn install everywhere. + // TODO: We should probably start reusing the yarn pnp map if we can figure that out instead of rerunning yarn install everywhere. + WithExec([]string{"yarn", "run", "lerna", "version", ersion, "--exact", "--no-git-tag-version", "--no-push", "--force-publish", "-y"}). WithExec([]string{"yarn", "lerna", "exec", "--no-private", "--", "yarn", "pack", "--out", fmt.Sprintf("/src/npm-packages/%%s-%v.tgz", version)}) return c.Directory("./npm-packages") diff --git a/pipelines/package.go b/pipelines/package.go index 1cbd938e..39a0e7b8 100644 --- a/pipelines/package.go +++ b/pipelines/package.go @@ -100,7 +100,7 @@ func PackageFiles(ctx context.Context, d *dagger.Client, opts PackageOpts) (map[ } var ( - frontend = containers.CompileFrontend(d, opts.Platform, src, cacheOpts, nodeVersion) + frontend = containers.CompileFrontend(d, opts.Platform, src, cacheOpts, version, nodeVersion) npmPackages = containers.NPMPackages(d, opts.Platform, src, cacheOpts, version, nodeVersion) storybook = containers.Storybook(d, opts.Platform, src, cacheOpts, version, nodeVersion) )