Skip to content

Commit 0b08b4f

Browse files
committed
Get build dir from config instead of cwd
1 parent 40ce9ee commit 0b08b4f

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

go/porcelain/deploy.go

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const (
4242
lfsVersionString = "version https://git-lfs.github.com/spec/v1"
4343
)
4444

45-
var ignoreInstallDirs = []string{"node_modules/", "bower_components/"}
45+
var installDirs = []string{"node_modules/", "bower_components/"}
4646

4747
type uploadType int
4848
type pointerData struct {
@@ -74,6 +74,7 @@ type DeployOptions struct {
7474
SiteID string
7575
Dir string
7676
FunctionsDir string
77+
BuildDir string
7778
LargeMediaEnabled bool
7879

7980
IsDraft bool
@@ -190,8 +191,10 @@ func (n *Netlify) DoDeploy(ctx context.Context, options *DeployOptions, deploy *
190191
largeMediaEnabled = deploy.SiteCapabilities.LargeMediaEnabled
191192
}
192193

194+
ignoreInstallDirs := options.Dir == options.BuildDir
195+
193196
context.GetLogger(ctx).Infof("Getting files info with large media flag: %v", largeMediaEnabled)
194-
files, err := walk(options.Dir, options.Observer, largeMediaEnabled)
197+
files, err := walk(options.Dir, options.Observer, largeMediaEnabled, ignoreInstallDirs)
195198
if err != nil {
196199
if options.Observer != nil {
197200
options.Observer.OnFailedWalk()
@@ -500,16 +503,10 @@ func (n *Netlify) uploadFile(ctx context.Context, d *models.Deploy, f *FileBundl
500503
}
501504
}
502505

503-
var getwd = os.Getwd
504-
505-
func walk(dir string, observer DeployObserver, useLargeMedia bool) (*deployFiles, error) {
506+
func walk(dir string, observer DeployObserver, useLargeMedia, ignoreInstallDirs bool) (*deployFiles, error) {
506507
files := newDeployFiles()
507-
cwd, err := getwd()
508-
if err != nil {
509-
return nil, err
510-
}
511508

512-
err = filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
509+
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
513510
if err != nil {
514511
return err
515512
}
@@ -521,7 +518,7 @@ func walk(dir string, observer DeployObserver, useLargeMedia bool) (*deployFiles
521518
}
522519
rel := forceSlashSeparators(osRel)
523520

524-
if ignoreFile(rel, dir == cwd) {
521+
if ignoreFile(rel, ignoreInstallDirs) {
525522
return nil
526523
}
527524

@@ -745,14 +742,14 @@ func goFile(filePath string, i os.FileInfo, observer DeployObserver) bool {
745742
return true
746743
}
747744

748-
func ignoreFile(rel string, deployFromBuildDir bool) bool {
745+
func ignoreFile(rel string, ignoreInstallDirs bool) bool {
749746
if strings.HasPrefix(rel, ".") || strings.Contains(rel, "/.") || strings.HasPrefix(rel, "__MACOS") {
750747
return !strings.HasPrefix(rel, ".well-known/")
751748
}
752-
if !deployFromBuildDir {
749+
if !ignoreInstallDirs {
753750
return false
754751
}
755-
for _, ignorePath := range ignoreInstallDirs {
752+
for _, ignorePath := range installDirs {
756753
if strings.HasPrefix(rel, ignorePath) {
757754
return true
758755
}

go/porcelain/deploy_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,16 +150,13 @@ func TestWalk_IgnoreNodeModulesInRoot(t *testing.T) {
150150
err = ioutil.WriteFile(filepath.Join(dir, "more", "node_modules", "inner-package"), []byte{}, 0644)
151151
require.Nil(t, err)
152152

153-
// When deploy directory != build directory, always deploy node_modules.
154-
getwd = func() (string, error) { return "elsewhere", nil }
155-
files, err := walk(dir, mockObserver{}, false)
153+
files, err := walk(dir, mockObserver{}, false, false)
156154
require.Nil(t, err)
157155
assert.NotNil(t, files.Files["node_modules/root-package"])
158156
assert.NotNil(t, files.Files["more/node_modules/inner-package"])
159157

160158
// When deploy directory == build directory, ignore node_modules in deploy directory root.
161-
getwd = func() (string, error) { return dir, nil }
162-
files, err = walk(dir, mockObserver{}, false)
159+
files, err = walk(dir, mockObserver{}, false, true)
163160
require.Nil(t, err)
164161
assert.Nil(t, files.Files["node_modules/root-package"])
165162
assert.NotNil(t, files.Files["more/node_modules/inner-package"])

0 commit comments

Comments
 (0)