Skip to content

Commit c83b026

Browse files
joeljeskealexeagle
authored andcommitted
fixes #1567 Recursively copy files from subdirectories into mirrored structure in the npm archive.
1 parent a4ca6f6 commit c83b026

3 files changed

Lines changed: 22 additions & 1 deletion

File tree

internal/pkg_npm/packager.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,14 @@ function mkdirp(p) {
3131

3232
function copyWithReplace(src, dest, substitutions, renameBuildFiles) {
3333
mkdirp(path.dirname(dest));
34-
if (!isBinary(src)) {
34+
if (fs.lstatSync(src).isDirectory()) {
35+
const files = fs.readdirSync(src)
36+
files.forEach((relativeChildSrc) => {
37+
const childSrc = path.join(src, relativeChildSrc);
38+
const childDest = path.join(dest, path.basename(childSrc));
39+
copyWithReplace(childSrc, childDest, substitutions, renameBuildFiles);
40+
});
41+
} else if (!isBinary(src)) {
3542
let content = fs.readFileSync(src, {encoding: 'utf-8'});
3643
substitutions.forEach(r => {
3744
const [regexp, newvalue] = r;

internal/pkg_npm/test/BUILD.bazel

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
load("@build_bazel_rules_nodejs//:index.bzl", "pkg_npm")
22
load("@npm_bazel_jasmine//:index.from_src.bzl", "jasmine_node_test")
3+
load("@npm_bazel_rollup//:index.from_src.bzl", "rollup_bundle")
34
load("@npm_bazel_typescript//:index.from_src.bzl", "ts_library")
45
load("//internal/node:context.bzl", "node_context_data")
56
load("//third_party/github.com/bazelbuild/bazel-skylib:rules/write_file.bzl", "write_file")
@@ -16,6 +17,15 @@ ts_library(
1617
data = ["data.json"],
1718
)
1819

20+
rollup_bundle(
21+
name = "rollup/bundle/subdirectory",
22+
entry_points = {
23+
"foo.ts": "index",
24+
},
25+
output_dir = True,
26+
deps = [":ts_library"],
27+
)
28+
1929
pkg_npm(
2030
name = "dependent_pkg",
2131
srcs = ["dependent_file"],
@@ -44,6 +54,7 @@ pkg_npm(
4454
deps = [
4555
":bundle.min.js",
4656
":produces_files",
57+
":rollup/bundle/subdirectory",
4758
":ts_library",
4859
"@internal_npm_package_test_vendored_external//:ts_library",
4960
],

internal/pkg_npm/test/pkg_npm.spec.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,7 @@ describe('pkg_npm srcs', () => {
5151
// TODO(alexeagle): there isn't a way to test this yet, because the pkg_npm under test
5252
// has to live in the root of the repository in order for external/foo to appear inside it
5353
});
54+
it('copies entire contents of directories',
55+
() => {expect(read('rollup/bundle/subdirectory/index.js'))
56+
.toContain(`const a = '';\n\nexport { a }`)});
5457
});

0 commit comments

Comments
 (0)