diff --git a/package.json b/package.json index a20594eafa..8b43950bbd 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/packages/typescript/test/strict_deps/BUILD b/packages/typescript/test/strict_deps/BUILD index 6db23abc05..eaaf04402f 100644 --- a/packages/typescript/test/strict_deps/BUILD +++ b/packages/typescript/test/strict_deps/BUILD @@ -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( @@ -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"], +) diff --git a/packages/typescript/test/strict_deps/child.ts b/packages/typescript/test/strict_deps/child.ts index f7bca1371a..f0ba5d9e6a 100644 --- a/packages/typescript/test/strict_deps/child.ts +++ b/packages/typescript/test/strict_deps/child.ts @@ -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); diff --git a/packages/typescript/test/strict_deps/child2.ts b/packages/typescript/test/strict_deps/child2.ts new file mode 100644 index 0000000000..b2ced6b602 --- /dev/null +++ b/packages/typescript/test/strict_deps/child2.ts @@ -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); diff --git a/packages/typescript/test/strict_deps/parent.ts b/packages/typescript/test/strict_deps/parent.ts index 6df328773d..cffa1013a1 100644 --- a/packages/typescript/test/strict_deps/parent.ts +++ b/packages/typescript/test/strict_deps/parent.ts @@ -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); diff --git a/yarn.lock b/yarn.lock index b6821b142b..b476728990 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"