Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix package.json version when building npm packages #179

Merged
merged 1 commit into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion containers/build_frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"strings"

"dagger.io/dagger"
)
Expand All @@ -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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ersion := strings.TrimPrefix(version, "v")
version := strings.TrimPrefix(version, "v")

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's intentional because it's "version" without the "v" ;)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol, maybe trimmedVersion is better 😂

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that this is not a big deal but I actually think ersion is pretty descriptive. It does look like a typo but it more concisely describes how the version is trimmed. Essentially, it is the exact same as version just with the v removed. Plus we have been using it in a lot of different places so it's probably good to keep it here for consistency.


// 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"}).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
WithExec([]string{"npm", "version", ersion, "--no-git-tag-version"}).
WithExec([]string{"npm", "version", version, "--no-git-tag-version"}).

WithExec([]string{"yarn", "run", "build"}).
WithExec([]string{"yarn", "run", "plugins:build-bundled"}).
Directory("/src/public")
Expand Down
6 changes: 5 additions & 1 deletion containers/npm_packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package containers

import (
"fmt"
"strings"

"dagger.io/dagger"
)
Expand All @@ -14,10 +15,13 @@ func NPMPackages(d *dagger.Client, platform dagger.Platform, src *dagger.Directo

c = WithYarnCache(c, opts)

ersion := strings.TrimPrefix(version, "v")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ersion := strings.TrimPrefix(version, "v")
version := 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"}).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have to do a yarn install to update the lockfile at this point I believe, because if you don't, then later steps that do yarn install --immutable will fail

Copy link
Contributor Author

@guicaulada guicaulada Sep 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there are any later steps that do yarn install --immutable, should we run yarn install --mode=update-lockfile after updating the version anyway, just to be sure?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmmmm. Since it's containerized and not using a shared volume I actually don't know if doing that would update it for everything afterwards without exporting that file so maybe for now we should just leave it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it becomes a problem later then i guess we can resolve it at that point

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
WithExec([]string{"yarn", "run", "lerna", "version", ersion, "--exact", "--no-git-tag-version", "--no-push", "--force-publish", "-y"}).
WithExec([]string{"yarn", "run", "lerna", "version", version, "--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")
Expand Down
2 changes: 1 addition & 1 deletion pipelines/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
Expand Down