Skip to content

Commit

Permalink
fix(builtin): bugs in 0.38 found while rolling out to angular repo
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeagle committed Oct 3, 2019
1 parent 1ecb527 commit d2262c8
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 13 deletions.
16 changes: 9 additions & 7 deletions internal/linker/link_node_modules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,21 @@ def get_module_mappings(label, attrs, vars, rule_kind, srcs = [], workspace_name
elif label.workspace_root:
mr = "%s/%s" % (label.workspace_root, mr)

if mn in mappings and mappings[mn] != mr:
fail(("duplicate module mapping at %s: %s maps to both %s and %s" %
(label, mn, mappings[mn], mr)), "deps")
_debug(vars, "target %s adding module mapping %s: %s" % (label, mn, mr))

# since our module mapping is currently based on attribute names,
# allow a special one to instruct the linker that the package has no output
# directory and is therefore meant to be used as sources.
# TODO: This belongs in a different mechanism like a package.json field.
if getattr(attrs, "module_from_src", False):
mappings[mn] = ["src", mr]
mr = ["src", mr]
else:
mappings[mn] = ["bin", mr]
mr = ["bin", mr]

if mn in mappings and mappings[mn] != mr:
fail(("duplicate module mapping at %s: %s maps to both %s and %s" %
(label, mn, mappings[mn], mr)), "deps")
_debug(vars, "target %s adding module mapping %s: %s" % (label, mn, mr))

mappings[mn] = mr
return mappings

# When building a mapping for use at runtime, we need paths to be relative to
Expand Down
11 changes: 8 additions & 3 deletions internal/npm_install/generate_build_file.js

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions internal/npm_install/generate_build_file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,13 @@ function addDynamicDependencies(pkgs: Dep[], dynamic_deps = DYNAMIC_DEPS) {
return false;
}
pkgs.forEach(p => {
p._dynamicDependencies = pkgs.filter(x => !!x._moduleName && match(x._moduleName, p))
.map(dyn => `//${dyn._dir}:${dyn._name}`);
p._dynamicDependencies =
pkgs.filter(
// Filter entries like
// "_dir":"check-side-effects/node_modules/rollup-plugin-node-resolve"
x => !x._dir.includes('/node_modules/') && !!x._moduleName &&
match(x._moduleName, p))
.map(dyn => `//${dyn._dir}:${dyn._name}`);
});
}

Expand Down
2 changes: 1 addition & 1 deletion internal/npm_install/test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jasmine_node_test(
data = [
":check.js",
":goldens",
"//internal/npm_install:generate_build_file",
"//internal/npm_install:compile_generate_build_file",
"@fine_grained_goldens//:golden_files",
"@npm//unidiff",
],
Expand Down
11 changes: 11 additions & 0 deletions internal/npm_install/test/generate_build_file.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,17 @@ describe('build file generator', () => {
expect(printPackageBin(pkgs[0]))
.toContain('data = ["//some_dir:foo", "//bar:foo-plugin-bar"]');
});
it('should not include nested packages', () => {
const pkgs = [
{_name: 'foo', bin: 'foobin', _dir: 'some_dir', _moduleName: 'foo'}, {
_name: 'foo-plugin-bar',
_dir: 'top-level/node_modules/bar',
_moduleName: 'foo-plugin-bar'
}
];
addDynamicDependencies(pkgs, {});
expect(pkgs[0]._dynamicDependencies).toEqual([]);
});
});

describe('index.bzl files', () => {
Expand Down

0 comments on commit d2262c8

Please sign in to comment.