-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(typescript): add
data
attribute
Adds the `data` attribute to `ts_project()`. This functions like most `data` attributes as defined by [common Bazel definitions](https://docs.bazel.build/versions/master/be/common-definitions.html#typical-attributes). All it really does is add the provided files to the `DefaultInfo()` runfiles object, where they will be propagated to any consuming rules.
- Loading branch information
Showing
5 changed files
with
50 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
load("//packages/jasmine:index.bzl", "jasmine_node_test") | ||
load("//packages/typescript:index.bzl", "ts_project") | ||
|
||
ts_project( | ||
name = "data", | ||
testonly = True, | ||
srcs = ["data.spec.ts"], | ||
composite = True, | ||
# Should be readable at runtime under runfiles directory. | ||
data = ["foo.txt"], | ||
extends = "//packages/typescript/test/ts_project:tsconfig-base.json", | ||
tsconfig = "tsconfig.json", | ||
deps = [ | ||
"@npm//@types/jasmine", | ||
"@npm//@types/node", | ||
], | ||
) | ||
|
||
jasmine_node_test( | ||
name = "test", | ||
srcs = [":data"], | ||
) |
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,13 @@ | ||
import {promises as fs} from 'fs'; | ||
|
||
const runfiles = require(process.env['BAZEL_NODE_RUNFILES_HELPER']!); | ||
|
||
const FOO_PATH = | ||
runfiles.resolve('build_bazel_rules_nodejs/packages/typescript/test/ts_project/data/foo.txt'); | ||
|
||
describe('data', () => { | ||
it('makes files available at runtime', async () => { | ||
const foo = await fs.readFile(FOO_PATH, {encoding: 'utf8'}); | ||
expect(foo).toBe('Foo\n'); | ||
}); | ||
}); |
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 @@ | ||
Foo |
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,10 @@ | ||
{ | ||
"extends": "../tsconfig-base.json", | ||
"compilerOptions": { | ||
"types": ["jasmine", "node"] | ||
}, | ||
"references": [ | ||
{"path": "./"} | ||
], | ||
"include": ["*.spec.ts"] | ||
} |