diff --git a/internal/pkg_npm/packager.js b/internal/pkg_npm/packager.js index ac41b58525..7ab0d7a517 100644 --- a/internal/pkg_npm/packager.js +++ b/internal/pkg_npm/packager.js @@ -31,7 +31,14 @@ function mkdirp(p) { function copyWithReplace(src, dest, substitutions, renameBuildFiles) { mkdirp(path.dirname(dest)); - if (!isBinary(src)) { + if (fs.lstatSync(src).isDirectory()) { + const files = fs.readdirSync(src) + files.forEach((relativeChildSrc) => { + const childSrc = path.join(src, relativeChildSrc); + const childDest = path.join(dest, path.basename(childSrc)); + copyWithReplace(childSrc, childDest, substitutions, renameBuildFiles); + }); + } else if (!isBinary(src)) { let content = fs.readFileSync(src, {encoding: 'utf-8'}); substitutions.forEach(r => { const [regexp, newvalue] = r; diff --git a/internal/pkg_npm/test/BUILD.bazel b/internal/pkg_npm/test/BUILD.bazel index 7a2440044a..516def1141 100644 --- a/internal/pkg_npm/test/BUILD.bazel +++ b/internal/pkg_npm/test/BUILD.bazel @@ -1,5 +1,6 @@ load("@build_bazel_rules_nodejs//:index.bzl", "pkg_npm") load("@npm_bazel_jasmine//:index.from_src.bzl", "jasmine_node_test") +load("@npm_bazel_rollup//:index.from_src.bzl", "rollup_bundle") load("@npm_bazel_typescript//:index.from_src.bzl", "ts_library") load("//internal/node:context.bzl", "node_context_data") load("//third_party/github.com/bazelbuild/bazel-skylib:rules/write_file.bzl", "write_file") @@ -16,6 +17,15 @@ ts_library( data = ["data.json"], ) +rollup_bundle( + name = "rollup/bundle/subdirectory", + entry_points = { + "foo.ts": "index", + }, + output_dir = True, + deps = [":ts_library"], +) + pkg_npm( name = "dependent_pkg", srcs = ["dependent_file"], @@ -44,6 +54,7 @@ pkg_npm( deps = [ ":bundle.min.js", ":produces_files", + ":rollup/bundle/subdirectory", ":ts_library", "@internal_npm_package_test_vendored_external//:ts_library", ], diff --git a/internal/pkg_npm/test/pkg_npm.spec.js b/internal/pkg_npm/test/pkg_npm.spec.js index 7da7c02ce5..99e5f00727 100644 --- a/internal/pkg_npm/test/pkg_npm.spec.js +++ b/internal/pkg_npm/test/pkg_npm.spec.js @@ -51,4 +51,7 @@ describe('pkg_npm srcs', () => { // TODO(alexeagle): there isn't a way to test this yet, because the pkg_npm under test // has to live in the root of the repository in order for external/foo to appear inside it }); + it('copies entire contents of directories', + () => {expect(read('rollup/bundle/subdirectory/index.js')) + .toContain(`const a = '';\n\nexport { a }`)}); });