Skip to content

Commit

Permalink
Symlink node_modules/.cache to tempdir
Browse files Browse the repository at this point in the history
Co-authored-by: Pavel Busko <[email protected]>
  • Loading branch information
c0d1ngm0nk3y and pbusko committed Apr 12, 2024
1 parent 5a6c88e commit d467af4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
15 changes: 15 additions & 0 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"github.com/paketo-buildpacks/packit/v2/scribe"
)

const NODE_MODULES_CACHE = "node_modules_cache"

//go:generate faux --interface BuildManager --output fakes/build_manager.go
type BuildManager interface {
Resolve(workingDir string) (BuildProcess, bool, error)
Expand Down Expand Up @@ -134,6 +136,19 @@ func Build(entryResolver EntryResolver,
return packit.BuildResult{}, err
}

cacheFolder := filepath.Join(os.TempDir(), NODE_MODULES_CACHE)
linkName := filepath.Join(layer.Path, "node_modules", ".cache")

err = os.Mkdir(cacheFolder, os.ModePerm)
if err != nil {
return packit.BuildResult{}, err
}

err = os.Symlink(cacheFolder, linkName)
if err != nil {
return packit.BuildResult{}, err
}

err = linker.Link(filepath.Join(projectPath, "node_modules"), filepath.Join(layer.Path, "node_modules"))
if err != nil {
return packit.BuildResult{}, err
Expand Down
8 changes: 7 additions & 1 deletion cmd/setup-symlinks/internal/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ func Run(executablePath, appDir string, symlinkResolver npminstall.SymlinkResolv
return err
}

return createSymlink(filepath.Join(layerPath, "node_modules"), linkPath)
createSymlink(filepath.Join(layerPath, "node_modules"), linkPath)

Check failure on line 45 in cmd/setup-symlinks/internal/run.go

View workflow job for this annotation

GitHub Actions / lint

Error return value is not checked (errcheck)
if err != nil {
return err
}

cacheFolder := filepath.Join(os.TempDir(), npminstall.NODE_MODULES_CACHE)
return os.Mkdir(cacheFolder, os.ModePerm)
}

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

0 comments on commit d467af4

Please sign in to comment.