-
Notifications
You must be signed in to change notification settings - Fork 524
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(typescript): support for declarationdir on ts_project (#2048)
* feat(typescript): support for declarationdir on ts_project * refactor: rename ts_library attributes to the snake_case version of their TypeScript names --outDir == out_dir --declarationDir == declaration_dir --rootDir == root_dir Note this is non-breaking since none of these attributes are on the 1.x branch
- Loading branch information
Showing
12 changed files
with
154 additions
and
24 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
36 changes: 36 additions & 0 deletions
36
packages/typescript/test/ts_project/declarationdir/BUILD.bazel
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,36 @@ | ||
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_test") | ||
load("//packages/typescript:index.bzl", "ts_project") | ||
|
||
# Ensure that subdir/a.ts produces outDir/a.js and outDir/a.d.ts | ||
SRCS = [ | ||
"subdir/a.ts", | ||
] | ||
|
||
ts_project( | ||
name = "tsconfig", | ||
srcs = SRCS, | ||
declaration = True, | ||
declaration_map = True, | ||
out_dir = "out", | ||
root_dir = "subdir", | ||
source_map = True, | ||
) | ||
|
||
filegroup( | ||
name = "types", | ||
srcs = [":tsconfig"], | ||
output_group = "types", | ||
) | ||
|
||
nodejs_test( | ||
name = "test", | ||
data = [ | ||
":tsconfig", | ||
":types", | ||
], | ||
entry_point = "verify.js", | ||
templated_args = [ | ||
"$(locations :types)", | ||
"$(locations :tsconfig)", | ||
], | ||
) |
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 @@ | ||
export const a: string = 'hello'; |
8 changes: 8 additions & 0 deletions
8
packages/typescript/test/ts_project/declarationdir/tsconfig.json
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,8 @@ | ||
{ | ||
"compilerOptions": { | ||
"sourceMap": true, | ||
"declaration": true, | ||
"declarationMap": true, | ||
"types": [] | ||
} | ||
} |
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,8 @@ | ||
const assert = require('assert'); | ||
|
||
const types_files = process.argv.slice(2, 4); | ||
const code_files = process.argv.slice(4, 6); | ||
assert.ok(types_files.some(f => f.endsWith('declarationdir/out/a.d.ts')), 'Missing a.d.ts'); | ||
assert.ok(types_files.some(f => f.endsWith('declarationdir/out/a.d.ts.map')), 'Missing a.d.ts.map'); | ||
assert.ok(code_files.some(f => f.endsWith('declarationdir/out/a.js')), 'Missing a.js'); | ||
assert.ok(code_files.some(f => f.endsWith('declarationdir/out/a.js.map')), 'Missing a.js.map'); |
37 changes: 37 additions & 0 deletions
37
packages/typescript/test/ts_project/declarationdir_with_value/BUILD.bazel
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,37 @@ | ||
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_test") | ||
load("//packages/typescript:index.bzl", "ts_project") | ||
|
||
# Ensure that subdir/a.ts produces outDir/a.js and declarationDir/a.d.ts | ||
SRCS = [ | ||
"subdir/a.ts", | ||
] | ||
|
||
ts_project( | ||
name = "tsconfig", | ||
srcs = SRCS, | ||
declaration = True, | ||
declaration_dir = "out/types", | ||
declaration_map = True, | ||
out_dir = "out/code", | ||
root_dir = "subdir", | ||
source_map = True, | ||
) | ||
|
||
filegroup( | ||
name = "types", | ||
srcs = [":tsconfig"], | ||
output_group = "types", | ||
) | ||
|
||
nodejs_test( | ||
name = "test", | ||
data = [ | ||
":tsconfig", | ||
":types", | ||
], | ||
entry_point = "verify.js", | ||
templated_args = [ | ||
"$(locations :types)", | ||
"$(locations :tsconfig)", | ||
], | ||
) |
1 change: 1 addition & 0 deletions
1
packages/typescript/test/ts_project/declarationdir_with_value/subdir/a.ts
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 @@ | ||
export const a: string = 'hello'; |
8 changes: 8 additions & 0 deletions
8
packages/typescript/test/ts_project/declarationdir_with_value/tsconfig.json
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,8 @@ | ||
{ | ||
"compilerOptions": { | ||
"sourceMap": true, | ||
"declaration": true, | ||
"declarationMap": true, | ||
"types": [] | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/typescript/test/ts_project/declarationdir_with_value/verify.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,15 @@ | ||
const assert = require('assert'); | ||
|
||
const types_files = process.argv.slice(2, 4); | ||
const code_files = process.argv.slice(4, 6); | ||
assert.ok( | ||
types_files.some(f => f.endsWith('declarationdir_with_value/out/types/a.d.ts')), | ||
'Missing a.d.ts'); | ||
assert.ok( | ||
types_files.some(f => f.endsWith('declarationdir_with_value/out/types/a.d.ts.map')), | ||
'Missing a.d.ts.map'); | ||
assert.ok( | ||
code_files.some(f => f.endsWith('declarationdir_with_value/out/code/a.js')), 'Missing a.js'); | ||
assert.ok( | ||
code_files.some(f => f.endsWith('declarationdir_with_value/out/code/a.js.map')), | ||
'Missing a.js.map'); |
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