Skip to content

Commit

Permalink
Ignore removed workspace folders in setup-symlinks helper
Browse files Browse the repository at this point in the history
Co-authored-by: Ralf Pannemans <[email protected]>
  • Loading branch information
2 people authored and thitch97 committed Oct 11, 2023
1 parent e73a16b commit 2106142
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
13 changes: 7 additions & 6 deletions cmd/setup-symlinks/internal/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,23 @@ func Run(executablePath, appDir string, symlinkResolver npminstall.SymlinkResolv
}

func resolveWorkspaceModules(symlinkResolver npminstall.SymlinkResolver, appDir, layerPath string) error {

lockFile, err := symlinkResolver.ParseLockfile(filepath.Join(appDir, "package-lock.json"))
if err != nil {
return err
}

dir := filepath.Dir(filepath.Join(appDir, "package-lock.json"))
for _, pkg := range lockFile.Packages {
if pkg.Link {

linkPath, err := os.Readlink(filepath.Join(dir, pkg.Resolved))
linkPath, err := os.Readlink(filepath.Join(appDir, pkg.Resolved))
if err != nil {
return err
if errors.Is(err, fs.ErrNotExist) {
continue
} else {
return err
}
}

err = createSymlink(filepath.Join(layerPath, pkg.Resolved), filepath.Join(linkPath, pkg.Resolved))
err = createSymlink(filepath.Join(layerPath, pkg.Resolved), linkPath)
if err != nil {
return err
}
Expand Down
32 changes: 30 additions & 2 deletions cmd/setup-symlinks/internal/run_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package internal_test

import (
"io/fs"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -143,9 +144,7 @@ func testRun(t *testing.T, context spec.G, it spec.S) {
})

context("when appDir contains workspace packages ", func() {

it("ensures symlinks to the layer exist at launch time", func() {

err := resolver.Resolve(filepath.Join(appDir, "package-lock.json"), layerDir)
Expect(err).NotTo(HaveOccurred())

Expand Down Expand Up @@ -175,7 +174,36 @@ func testRun(t *testing.T, context spec.G, it spec.S) {
link, err = os.Readlink(link)
Expect(err).NotTo(HaveOccurred())
Expect(link).To(Equal(filepath.Join(layerDir, "module-5")))
})

it("ensures symlinks to the layer exists if the resolved path is missing", func() {
err := resolver.Resolve(filepath.Join(appDir, "package-lock.json"), layerDir)
Expect(err).NotTo(HaveOccurred())

err = os.RemoveAll(filepath.Join(appDir, "module-5"))
Expect(err).NotTo(HaveOccurred())

err = internal.Run(executablePath, appDir, resolver)
Expect(err).NotTo(HaveOccurred())

link, err := os.Readlink(filepath.Join(appDir, "src", "packages", "module-1"))
Expect(err).NotTo(HaveOccurred())
Expect(link).To(Equal(filepath.Join(tmpDir, "src", "packages", "module-1")))

link, err = os.Readlink(link)
Expect(err).NotTo(HaveOccurred())
Expect(link).To(Equal(filepath.Join(layerDir, "src", "packages", "module-1")))

link, err = os.Readlink(filepath.Join(appDir, "workspaces", "example", "module-3"))
Expect(err).NotTo(HaveOccurred())
Expect(link).To(Equal(filepath.Join(tmpDir, "workspaces", "example", "module-3")))

link, err = os.Readlink(link)
Expect(err).NotTo(HaveOccurred())
Expect(link).To(Equal(filepath.Join(layerDir, "workspaces", "example", "module-3")))

_, err = os.Readlink(filepath.Join(appDir, "module-5"))
Expect(err).To(MatchError(fs.ErrNotExist))
})
})

Expand Down

0 comments on commit 2106142

Please sign in to comment.