Skip to content

Commit

Permalink
fixes #1567 Recursively copy files from subdirectories into mirrored …
Browse files Browse the repository at this point in the history
…structure in the npm archive.
  • Loading branch information
joeljeske authored and alexeagle committed Jan 30, 2020
1 parent a4ca6f6 commit c83b026
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
9 changes: 8 additions & 1 deletion internal/pkg_npm/packager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions internal/pkg_npm/test/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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"],
Expand Down Expand Up @@ -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",
],
Expand Down
3 changes: 3 additions & 0 deletions internal/pkg_npm/test/pkg_npm.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }`)});
});

0 comments on commit c83b026

Please sign in to comment.