diff --git a/cli/azd/pkg/project/framework_service_npm.go b/cli/azd/pkg/project/framework_service_npm.go index 4b6a22cce8f..31731b05583 100644 --- a/cli/azd/pkg/project/framework_service_npm.go +++ b/cli/azd/pkg/project/framework_service_npm.go @@ -130,7 +130,11 @@ func (np *npmProject) Package( if err := buildForZip( packageSource, packageDest, - buildForZipOptions{}); err != nil { + buildForZipOptions{ + excludeCallback: func(src string) ([]excludeDirEntryCondition, error) { + return []excludeDirEntryCondition{excludeNodeModules}, nil + }, + }); err != nil { return nil, fmt.Errorf("packaging for %s: %w", serviceConfig.Name, err) } diff --git a/cli/azd/pkg/project/framework_service_python.go b/cli/azd/pkg/project/framework_service_python.go index fc53f085512..e6bee2de71f 100644 --- a/cli/azd/pkg/project/framework_service_python.go +++ b/cli/azd/pkg/project/framework_service_python.go @@ -130,7 +130,11 @@ func (pp *pythonProject) Package( if err := buildForZip( packageSource, packageDest, - buildForZipOptions{}); err != nil { + buildForZipOptions{ + excludeCallback: func(src string) ([]excludeDirEntryCondition, error) { + return []excludeDirEntryCondition{excludeVirtualEnv, excludePyCache}, nil + }, + }); err != nil { return nil, fmt.Errorf("packaging for %s: %w", serviceConfig.Name, err) } diff --git a/cli/azd/pkg/project/project_utils.go b/cli/azd/pkg/project/project_utils.go index 1cd25507bef..79b2c04a4c6 100644 --- a/cli/azd/pkg/project/project_utils.go +++ b/cli/azd/pkg/project/project_utils.go @@ -55,6 +55,7 @@ type excludeDirEntryCondition func(path string, file os.FileInfo) bool // buildForZipOptions provides a set of options for doing build for zip type buildForZipOptions struct { excludeConditions []excludeDirEntryCondition + excludeCallback func(src string) ([]excludeDirEntryCondition, error) } // buildForZip is used by projects whose build strategy is to only copy the source code into a folder, which is later @@ -72,7 +73,13 @@ func buildForZip(src, dst string, options buildForZipOptions) error { // Conditionally exclude virtual environments, __pycache__, and node_modules only if .zipignore doesn't exist if !zipIgnoreExists { - options.excludeConditions = append(options.excludeConditions, excludeVirtualEnv, excludePyCache, excludeNodeModules) + if options.excludeCallback != nil { + callbackExcludes, err := options.excludeCallback(src) + if err != nil { + return fmt.Errorf("applying exclude callback: %w", err) + } + options.excludeConditions = append(options.excludeConditions, callbackExcludes...) + } } options.excludeConditions = append(options.excludeConditions, func(path string, file os.FileInfo) bool { diff --git a/cli/azd/test/functional/package_test.go b/cli/azd/test/functional/package_test.go index cbc0a7a3be0..5b73e083e58 100644 --- a/cli/azd/test/functional/package_test.go +++ b/cli/azd/test/functional/package_test.go @@ -216,16 +216,13 @@ func Test_CLI_Package_ZipIgnore(t *testing.T) { enabled: true, expectedFiles: map[string]map[string]bool{ "service1": { - "testfile.py": true, - "__pycache__/testcache.txt": false, - ".venv/pyvenv.cfg": false, - "node_modules/some_package/package.json": false, - "logs/log.txt": true, + "testfile.py": true, + "__pycache__/testcache.txt": false, + ".venv/pyvenv.cfg": false, + "logs/log.txt": true, }, "service2": { "testfile.js": true, - "__pycache__/testcache.txt": false, - ".venv/pyvenv.cfg": false, "node_modules/some_package/package.json": false, "logs/log.txt": true, }, @@ -239,16 +236,13 @@ func Test_CLI_Package_ZipIgnore(t *testing.T) { rootZipIgnore: "__pycache__\n", expectedFiles: map[string]map[string]bool{ "service1": { - "testfile.py": true, - "__pycache__/testcache.txt": false, - ".venv/pyvenv.cfg": true, - "node_modules/some_package/package.json": true, - "logs/log.txt": true, + "testfile.py": true, + "__pycache__/testcache.txt": false, + ".venv/pyvenv.cfg": true, + "logs/log.txt": true, }, "service2": { "testfile.js": true, - "__pycache__/testcache.txt": false, - ".venv/pyvenv.cfg": true, "node_modules/some_package/package.json": true, "logs/log.txt": true, }, @@ -264,16 +258,13 @@ func Test_CLI_Package_ZipIgnore(t *testing.T) { service1ZipIgnore: "__pycache__\n", expectedFiles: map[string]map[string]bool{ "service1": { - "testfile.py": true, - "__pycache__/testcache.txt": false, - ".venv/pyvenv.cfg": true, - "node_modules/some_package/package.json": true, - "logs/log.txt": false, + "testfile.py": true, + "__pycache__/testcache.txt": false, + ".venv/pyvenv.cfg": true, + "logs/log.txt": false, }, "service2": { "testfile.js": true, - "__pycache__/testcache.txt": true, - ".venv/pyvenv.cfg": true, "node_modules/some_package/package.json": true, "logs/log.txt": false, }, @@ -287,16 +278,13 @@ func Test_CLI_Package_ZipIgnore(t *testing.T) { service1ZipIgnore: "__pycache__\n", expectedFiles: map[string]map[string]bool{ "service1": { - "testfile.py": true, - "__pycache__/testcache.txt": false, - ".venv/pyvenv.cfg": true, - "node_modules/some_package/package.json": true, - "logs/log.txt": true, + "testfile.py": true, + "__pycache__/testcache.txt": false, + ".venv/pyvenv.cfg": true, + "logs/log.txt": true, }, "service2": { "testfile.js": true, - "__pycache__/testcache.txt": false, - ".venv/pyvenv.cfg": false, "node_modules/some_package/package.json": false, "logs/log.txt": true, }, diff --git a/cli/azd/test/functional/testdata/samples/dotignore/src/service1/node_modules/some_package/index.js b/cli/azd/test/functional/testdata/samples/dotignore/src/service1/node_modules/some_package/index.js deleted file mode 100644 index e5367a98907..00000000000 --- a/cli/azd/test/functional/testdata/samples/dotignore/src/service1/node_modules/some_package/index.js +++ /dev/null @@ -1,5 +0,0 @@ -// some_package/index.js - -module.exports = function() { - console.log("This is some_package!"); -}; diff --git a/cli/azd/test/functional/testdata/samples/dotignore/src/service1/node_modules/some_package/package.json b/cli/azd/test/functional/testdata/samples/dotignore/src/service1/node_modules/some_package/package.json deleted file mode 100644 index 5fdf2c80fab..00000000000 --- a/cli/azd/test/functional/testdata/samples/dotignore/src/service1/node_modules/some_package/package.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "some_package", - "version": "1.0.0", - "description": "A mock package for testing", - "main": "index.js", - "author": "", - "license": "ISC" -} diff --git a/cli/azd/test/functional/testdata/samples/dotignore/src/service2/.venv/pyvenv.cfg b/cli/azd/test/functional/testdata/samples/dotignore/src/service2/.venv/pyvenv.cfg deleted file mode 100644 index 2bc7ab42877..00000000000 --- a/cli/azd/test/functional/testdata/samples/dotignore/src/service2/.venv/pyvenv.cfg +++ /dev/null @@ -1 +0,0 @@ -home = /usr/local/bin/python diff --git a/cli/azd/test/functional/testdata/samples/dotignore/src/service2/__pycache__/testcache.txt b/cli/azd/test/functional/testdata/samples/dotignore/src/service2/__pycache__/testcache.txt deleted file mode 100644 index e69de29bb2d..00000000000