forked from bazel-contrib/rules_nodejs
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make tsconfig default to label //:tsconfig.json
This avoids the need for users to create their own ts_library macro to follow the best-practice of having the same tsconfig.json for all libraries, and fixes the issue that it's easy to have no tsconfig applied to a ts_library if the attribute is omitted BREAKING CHANGE: ts_library targets with no tsconfig attribute will now default to //:tsconfig.json. If this breaks you, do one of these: 1) create a file at that location (in the WORKSPACE root) 2) create an alias rule in the root BUILD.bazel file like alias(name="tsconfig.json", actual="//path/to:tsconfig-something.json") 3) give an explicit tsconfig attribute to your ts_library rules Closes bazel-contrib#232 PiperOrigin-RevId: 205759471
- Loading branch information
Showing
8 changed files
with
149 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
packages/concatjs/third_party/google3/rules_typescript/internal/e2e/default_tsconfig_test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
/** | ||
* @fileoverview | ||
* This tests interactions between multiple Bazel workspaces. | ||
* | ||
* We have learned from experience in the rules_nodejs repo that it's not | ||
* practical to simply check in the nested WORKSPACE files and try to build | ||
* them, because | ||
* - it's hard to exclude them from the parent WORKSPACE - each nested workspace | ||
* must be registered there with a matching name | ||
* - testing a child workspace requires `cd` into the directory, which doesn't | ||
* fit the CI model of `bazel test ...` | ||
* | ||
* The test is written in JavaScript simply to make it more portable, so we can | ||
* run it on Windows for example. We don't use TypeScript here since we are | ||
* running outside the build system. | ||
*/ | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
const child_process = require('child_process'); | ||
const os = require('os'); | ||
|
||
const tmpdir = fs.mkdtempSync(path.join(os.tmpdir(), 'wksp')); | ||
const WORKSPACE_BOILERPLATE = ` | ||
http_archive( | ||
name = "build_bazel_rules_nodejs", | ||
urls = ["https://github.com/bazelbuild/rules_nodejs/archive/0.10.0.zip"], | ||
strip_prefix = "rules_nodejs-0.10.0", | ||
) | ||
http_archive( | ||
name = "io_bazel_rules_webtesting", | ||
urls = ["https://github.com/bazelbuild/rules_webtesting/archive/v0.2.0.zip"], | ||
strip_prefix = "rules_webtesting-0.2.0", | ||
) | ||
http_archive( | ||
name = "io_bazel_rules_go", | ||
urls = [ | ||
"http://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/0.10.3/rules_go-0.10.3.tar.gz", | ||
"https://github.com/bazelbuild/rules_go/releases/download/0.10.3/rules_go-0.10.3.tar.gz" | ||
], | ||
) | ||
local_repository( | ||
name = "build_bazel_rules_typescript", | ||
path = "${process.cwd()}", | ||
) | ||
load("@build_bazel_rules_nodejs//:defs.bzl", "node_repositories") | ||
node_repositories(package_json=[]) | ||
load("@build_bazel_rules_typescript//:defs.bzl", "ts_setup_workspace") | ||
ts_setup_workspace() | ||
`; | ||
|
||
/** | ||
* Create a file at path filename, creating parent directories as needed, under | ||
* this test's temp directory. Write the content into that file. | ||
*/ | ||
function write(filename, content) { | ||
var parents = path.dirname(path.join(tmpdir, filename)); | ||
while (path.dirname(parents) !== parents) { | ||
if (!fs.existsSync(path.join(parents))) { | ||
fs.mkdirSync(path.join(parents)); | ||
} | ||
parents = path.dirname(parents); | ||
} | ||
fs.writeFileSync(path.join(tmpdir, filename), content); | ||
} | ||
|
||
function bazel(workspace, args) { | ||
const result = child_process.spawnSync('bazel', args, { | ||
cwd: path.join(tmpdir, workspace), | ||
stdio: 'inherit', | ||
}); | ||
expect(result.status).toBe(0, 'bazel exited with non-zero exit code'); | ||
} | ||
|
||
describe('default tsconfig', () => { | ||
it(`uses the tsconfig in the workspace defining the rule, | ||
not the workspace where the rule is defined (rules_typescript), nor | ||
the workspace where the build is occurring`, | ||
() => { | ||
// Workspace 'a' can't compile with --noImplicitAny. | ||
// When workspace 'b' has a dep here, we make sure not to use the | ||
// tsconfig from workspace 'b' | ||
write('a/WORKSPACE', ` | ||
workspace(name = "a") | ||
${WORKSPACE_BOILERPLATE}`); | ||
write('a/BUILD', ` | ||
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library") | ||
ts_library( | ||
name = "a_lib", | ||
srcs=["has_implicit_any.ts"], | ||
node_modules = "@build_bazel_rules_typescript_tsc_wrapped_deps//:node_modules", | ||
visibility = ["//visibility:public"], | ||
) | ||
`); | ||
write('a/tsconfig.json', `{}`); | ||
write('a/has_implicit_any.ts', `function f(a) { | ||
console.error(a); | ||
}`); | ||
|
||
// Workspace 'b' has a default tsconfig that sets --noImplicitAny. | ||
write('b/WORKSPACE', ` | ||
workspace(name="b") | ||
local_repository(name="a", path="../a") | ||
${WORKSPACE_BOILERPLATE}`); | ||
write('b/BUILD', ` | ||
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library") | ||
exports_files(["tsconfig.json"]) | ||
ts_library( | ||
name = "b_lib", | ||
srcs = ["file.ts"], | ||
deps = ["@a//:a_lib"], | ||
node_modules = "@build_bazel_rules_typescript_tsc_wrapped_deps//:node_modules", | ||
) | ||
`); | ||
write('b/file.ts', ` | ||
f('thing'); | ||
`); | ||
write('b/tsconfig.json', `{ | ||
"compilerOptions": { | ||
"noImplicitAny": true | ||
} | ||
}`); | ||
|
||
// Now build from workspace 'b' and verify that the dep in workspace 'a' | ||
// was able to compile. | ||
bazel('b', ['build', ':all']); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters