Skip to content

Commit

Permalink
test: check that ts_library @npm strict deps work (#1577)
Browse files Browse the repository at this point in the history
Add missing coverage to verify that ts_library strict deps of @npm dependencies works

    # NB: We don't require the `@npm//semver` package for the typescript compile
    # action as the .d.ts files live in @types/semver. If the resulting
    # .js file is run downstream in a nodejs_binary rule, however, the
    # `@npm//semver` dep will be required at that point.
    # TODO: Is it desirable to automatically add @npm//semver as a transitive
    #       dep if @npm//@types/semver is a dep so that downtream nodejs_binary
    #       rules get this automatically?
  • Loading branch information
gregmagolan authored Jan 30, 2020
1 parent fe24f57 commit 7d7f85a
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@types/hammerjs": "2.0.35",
"@types/jasmine": "~3.3.13",
"@types/node": "10.12.20",
"@types/semver": "6.2.0",
"bazel_workspaces": "file:./tools/npm_packages/bazel_workspaces",
"clang-format": "1.2.2",
"conventional-changelog-cli": "^2.0.21",
Expand Down
21 changes: 20 additions & 1 deletion packages/typescript/test/strict_deps/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,17 @@ ts_library(
ts_library(
name = "parent",
srcs = ["parent.ts"],
deps = [":grandparent"],
# NB: We don't require the `@npm//semver` package for the typescript compile
# action as the .d.ts files live in @types/semver. If the resulting
# .js file is run downstream in a nodejs_binary rule, however, the
# `@npm//semver` dep will be required at that point.
# TODO: Is it desirable to automatically add @npm//semver as a transitive
# dep if @npm//@types/semver is a dep so that downtream nodejs_binary
# rules get this automatically?
deps = [
":grandparent",
"@npm//@types/semver",
],
)

ts_library(
Expand All @@ -33,3 +43,12 @@ ts_library(
],
deps = [":parent"],
)

ts_library(
name = "strict_deps_npm",
srcs = ["child2.ts"],
expected_diagnostics = [
"TS2307:child2\.ts\(2,.*transitive dependency.*not allowed",
],
deps = [":parent"],
)
2 changes: 1 addition & 1 deletion packages/typescript/test/strict_deps/child.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// The line below is a strict deps violation:
// The line below is a strict deps violation of a ts_library dep
import {Symbol} from './grandparent';

console.log(Symbol);
5 changes: 5 additions & 0 deletions packages/typescript/test/strict_deps/child2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// The line below is a strict deps violation of an @npm dep
import * as semver from 'semver';
semver.valid('1.2.3');

console.log(Symbol);
3 changes: 2 additions & 1 deletion packages/typescript/test/strict_deps/parent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as semver from 'semver';
import {Symbol} from './grandparent';
semver.valid('1.2.3');
export const x = 1;

console.log(Symbol);
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,11 @@
resolved "https://registry.yarnpkg.com/@types/selenium-webdriver/-/selenium-webdriver-3.0.16.tgz#50a4755f8e33edacd9c406729e9b930d2451902a"
integrity sha512-lMC2G0ItF2xv4UCiwbJGbnJlIuUixHrioOhNGHSCsYCJ8l4t9hMCUimCytvFv7qy6AfSzRxhRHoGa+UqaqwyeA==

"@types/semver@6.2.0":
version "6.2.0"
resolved "https://registry.yarnpkg.com/@types/semver/-/semver-6.2.0.tgz#d688d574400d96c5b0114968705366f431831e1a"
integrity sha512-1OzrNb4RuAzIT7wHSsgZRlMBlNsJl+do6UblR7JMW4oB7bbR+uBEYtUh7gEc/jM84GGilh68lSOokyM/zNUlBA==

"@types/semver@^6.0.1":
version "6.0.1"
resolved "https://registry.yarnpkg.com/@types/semver/-/semver-6.0.1.tgz#a984b405c702fa5a7ec6abc56b37f2ba35ef5af6"
Expand Down

0 comments on commit 7d7f85a

Please sign in to comment.